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 ***************************************************************************/
23 #include "uisupport-export.h"
26 #include <QDockWidget>
28 #include <QModelIndex>
30 #include <QStyledItemDelegate>
32 #include "actioncollection.h"
33 #include "bufferviewconfig.h"
34 #include "networkmodel.h"
35 #include "treeviewtouch.h"
38 /*****************************************
39 * The TreeView showing the Buffers
40 *****************************************/
41 class UISUPPORT_EXPORT BufferView : public TreeViewTouch
52 BufferView(QWidget* parent = nullptr);
55 void setModel(QAbstractItemModel* model) override;
56 void setFilteredModel(QAbstractItemModel* model, BufferViewConfig* config);
58 void setConfig(BufferViewConfig* config);
59 inline BufferViewConfig* config() { return _config; }
61 void addActionsToMenu(QMenu* menu, const QModelIndex& index);
62 void addFilterActions(QMenu* contextMenu, const QModelIndex& index);
64 void selectFirstBuffer();
67 void setRootIndexForNetworkId(const NetworkId& networkId);
68 void removeSelectedBuffers(bool permanently = false);
69 void menuActionTriggered(QAction*);
71 void previousBuffer();
72 void hideCurrentBuffer();
73 void filterTextChanged(const QString& filterString);
74 void changeHighlight(Direction direction);
75 void selectHighlighted();
76 void clearHighlight();
79 void removeBuffer(const QModelIndex&);
80 void removeBufferPermanently(const QModelIndex&);
83 void dropEvent(QDropEvent* event) override;
84 void rowsInserted(const QModelIndex& parent, int start, int end) override;
85 void wheelEvent(QWheelEvent*) override;
86 QSize sizeHint() const override;
87 void focusInEvent(QFocusEvent* event) override { QAbstractScrollArea::focusInEvent(event); }
88 void contextMenuEvent(QContextMenuEvent* event) override;
90 void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles) override;
93 void joinChannel(const QModelIndex& index);
94 void toggleHeader(bool checked);
97 * Expand all active networks and collapse inactive ones unless manually changed
99 * Applies to all networks. Shouldn't need called except during initialization.
101 void setExpandedState();
104 * Save the current display state of the given network
106 * Tracks expanded or collapsed and active or inactive.
108 * @see setExpandedState()
109 * @param[in] networkIdx QModelIndex of the root network to store
111 void storeExpandedState(const QModelIndex& networkIdx);
114 * Set the display state of the given network according to network status and manual changes
116 * Expands if active or previously expanded, collapses if inactive or previously collapsed.
118 * @see storeExpandedState()
119 * @param[in] networkIdx QModelIndex of the root network to update
121 void setExpandedState(const QModelIndex& networkIdx);
123 void on_configChanged();
124 void on_layoutChanged();
126 void changeBuffer(Direction direction);
129 QPointer<BufferViewConfig> _config;
136 QHash<NetworkId, short> _expandedState;
137 QModelIndex _currentHighlight;
140 // ******************************
141 // BufferViewDelegate
142 // ******************************
144 class BufferViewDelegate : public QStyledItemDelegate
149 BufferViewDelegate(QObject* parent = nullptr);
150 bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
152 void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
155 QModelIndex currentHighlight;
158 void customEvent(QEvent* event) override;
161 // ==============================
163 // ==============================
164 class UISUPPORT_EXPORT BufferViewDock : public QDockWidget
167 Q_PROPERTY(bool active READ isActive WRITE setActive STORED true)
170 BufferViewDock(BufferViewConfig* config, QWidget* parent);
172 int bufferViewId() const;
173 BufferViewConfig* config() const;
174 inline BufferView* bufferView() const { return qobject_cast<BufferView*>(widget()); }
175 inline bool isActive() const { return _active; }
176 void setWidget(QWidget* newWidget);
177 void setLocked(bool locked);
178 QWidget* widget() const { return _childWidget; }
180 void activateFilter();
183 void setActive(bool active = true);
186 bool eventFilter(QObject* object, QEvent* event) override;
187 void focusInEvent(QFocusEvent* event) override { qDebug() << event; }
190 void bufferViewRenamed(const QString& newName);
192 void configChanged();
193 void onFilterReturnPressed();
196 QWidget* _childWidget;
198 QPointer<QWidget> _oldFocusItem; // QPointer in case the old item gets deleted
199 QLineEdit* _filterEdit;