1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
26 #include <QDockWidget>
27 #include <QModelIndex>
28 #include <QStyledItemDelegate>
31 #include "actioncollection.h"
32 #include "bufferviewconfig.h"
33 #include "networkmodel.h"
34 #include "treeviewtouch.h"
37 /*****************************************
38 * The TreeView showing the Buffers
39 *****************************************/
40 class BufferView : public TreeViewTouch
50 BufferView(QWidget *parent = 0);
53 void setModel(QAbstractItemModel *model);
54 void setFilteredModel(QAbstractItemModel *model, BufferViewConfig *config);
56 void setConfig(BufferViewConfig *config);
57 inline BufferViewConfig *config() { return _config; }
59 void addActionsToMenu(QMenu *menu, const QModelIndex &index);
60 void addFilterActions(QMenu *contextMenu, const QModelIndex &index);
62 void selectFirstBuffer();
65 void setRootIndexForNetworkId(const NetworkId &networkId);
66 void removeSelectedBuffers(bool permanently = false);
67 void menuActionTriggered(QAction *);
69 void previousBuffer();
70 void hideCurrentBuffer();
71 void filterTextChanged(const QString& filterString);
72 void changeHighlight(Direction direction);
73 void selectHighlighted();
74 void clearHighlight();
77 void removeBuffer(const QModelIndex &);
78 void removeBufferPermanently(const QModelIndex &);
81 virtual void dropEvent(QDropEvent *event);
82 virtual void rowsInserted(const QModelIndex &parent, int start, int end);
83 virtual void wheelEvent(QWheelEvent *);
84 virtual QSize sizeHint() const;
85 virtual void focusInEvent(QFocusEvent *event) { QAbstractScrollArea::focusInEvent(event); }
86 virtual void contextMenuEvent(QContextMenuEvent *event);
88 #if QT_VERSION < 0x050000
89 virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
91 virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
95 void joinChannel(const QModelIndex &index);
96 void toggleHeader(bool checked);
99 * Expand all active networks and collapse inactive ones unless manually changed
101 * Applies to all networks. Shouldn't need called except during initialization.
103 void setExpandedState();
106 * Save the current display state of the given network
108 * Tracks expanded or collapsed and active or inactive.
110 * @see setExpandedState()
111 * @param[in] networkIdx QModelIndex of the root network to store
113 void storeExpandedState(const QModelIndex &networkIdx);
116 * Set the display state of the given network according to network status and manual changes
118 * Expands if active or previously expanded, collapses if inactive or previously collapsed.
120 * @see storeExpandedState()
121 * @param[in] networkIdx QModelIndex of the root network to update
123 void setExpandedState(const QModelIndex &networkIdx);
125 void on_configChanged();
126 void on_layoutChanged();
128 void changeBuffer(Direction direction);
131 QPointer<BufferViewConfig> _config;
137 QHash<NetworkId, short> _expandedState;
138 QModelIndex _currentHighlight;
142 // ******************************
143 // BufferViewDelegate
144 // ******************************
146 class BufferViewDelegate : public QStyledItemDelegate
151 BufferViewDelegate(QObject *parent = 0);
152 bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override;
154 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
157 QModelIndex currentHighlight;
160 void customEvent(QEvent *event) override;
164 // ==============================
166 // ==============================
167 class BufferViewDock : public QDockWidget
170 Q_PROPERTY(bool active READ isActive WRITE setActive STORED true)
173 BufferViewDock(BufferViewConfig *config, QWidget *parent);
175 int bufferViewId() const;
176 BufferViewConfig *config() const;
177 inline BufferView *bufferView() const { return qobject_cast<BufferView *>(widget()); }
178 inline bool isActive() const { return _active; }
179 void setWidget(QWidget *newWidget);
180 void setLocked(bool locked);
181 QWidget *widget() const { return _childWidget; }
183 void activateFilter();
186 void setActive(bool active = true);
189 virtual bool eventFilter(QObject *object, QEvent *event);
190 virtual void focusInEvent(QFocusEvent*event) { qDebug() << event; }
193 void bufferViewRenamed(const QString &newName);
195 void configChanged();
196 void onFilterReturnPressed();
199 QWidget *_childWidget;
201 QPointer<QWidget> _oldFocusItem; // QPointer in case the old item gets deleted
202 QLineEdit *_filterEdit;