a98f41ff1de8f7c8d640561673ec97a76df19206
[quassel.git] / src / uisupport / bufferview.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef BUFFERVIEW_H_
22 #define BUFFERVIEW_H_
23
24 #include <QAction>
25 #include <QMenu>
26 #include <QDockWidget>
27 #include <QModelIndex>
28 #include <QTreeView>
29 #include <QPointer>
30
31 #include "actioncollection.h"
32 #include "bufferviewconfig.h"
33 #include "networkmodel.h"
34
35 #include "types.h"
36
37 /*****************************************
38  * The TreeView showing the Buffers
39  *****************************************/
40 class BufferView : public QTreeView {
41   Q_OBJECT
42
43 public:
44   BufferView(QWidget *parent = 0);
45   void init();
46
47   void setModel(QAbstractItemModel *model);
48   void setFilteredModel(QAbstractItemModel *model, BufferViewConfig *config);
49   virtual void setSelectionModel(QItemSelectionModel *selectionModel);
50
51   void setConfig(BufferViewConfig *config);
52   inline BufferViewConfig *config() { return _config; }
53
54   void addActionsToMenu(QMenu *menu, const QModelIndex &index);
55
56 public slots:
57   void setRootIndexForNetworkId(const NetworkId &networkId);
58   void removeSelectedBuffers(bool permanently = false);
59
60 signals:
61   void removeBuffer(const QModelIndex &);
62   void removeBufferPermanently(const QModelIndex &);
63
64 protected:
65   virtual void keyPressEvent(QKeyEvent *);
66   virtual void rowsInserted(const QModelIndex & parent, int start, int end);
67   virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
68   virtual void wheelEvent(QWheelEvent *);
69   virtual QSize sizeHint() const;
70   virtual void focusInEvent(QFocusEvent *event) { QAbstractScrollArea::focusInEvent(event); }
71   virtual void contextMenuEvent(QContextMenuEvent *event);
72
73 private slots:
74   void joinChannel(const QModelIndex &index);
75   void toggleHeader(bool checked);
76   void actionTriggered(QAction *);
77
78   void on_collapse(const QModelIndex &index);
79   void on_expand(const QModelIndex &index);
80   void on_configChanged();
81
82 private:
83   enum ItemActiveState {
84     InactiveState = 0x01,
85     ActiveState = 0x02
86   };
87
88 public:
89   Q_DECLARE_FLAGS(ItemActiveStates, ItemActiveState)
90   QAction showChannelList;
91
92 private:
93   QPointer<BufferViewConfig> _config;
94   ActionCollection _menuActions;
95   QModelIndex _menuIndex;
96   QHash<NetworkId, bool> _expandedState;
97
98   void storeExpandedState(NetworkId networkId, bool expanded);
99   void setupMenuActions();
100   bool checkRequirements(const QModelIndex &index,
101                           ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
102   void addItemToMenu(QAction *action, QMenu *menu, const QModelIndex &index,
103                      ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
104   void addItemToMenu(QAction *action, QMenu *menu, bool condition = true);
105   void addItemToMenu(QMenu *subMenu, QMenu *menu, const QModelIndex &index,
106                      ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
107   void addSeparatorToMenu(QMenu *menu, const QModelIndex &index,
108                           ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
109   QMenu *createHideEventsSubMenu(QMenu *menu, BufferId bufferId);
110 };
111 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferView::ItemActiveStates)
112
113
114 // ==============================
115 //  BufferView Dock
116 // ==============================
117 class BufferViewDock : public QDockWidget {
118   Q_OBJECT
119
120 public:
121   BufferViewDock(BufferViewConfig *config, QWidget *parent);
122   BufferViewDock(QWidget *parent);
123
124   inline BufferView *bufferView() const { return qobject_cast<BufferView *>(widget()); }
125
126 public slots:
127   void bufferViewRenamed(const QString &newName);
128 };
129
130 #endif