a8231d920c9bdcd43b55a668954005f5f8c30935
[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 "bufferviewconfig.h"
32 #include "networkmodel.h"
33
34 #include "types.h"
35
36 /*****************************************
37  * The TreeView showing the Buffers
38  *****************************************/
39 class BufferView : public QTreeView {
40   Q_OBJECT
41
42 public:
43   BufferView(QWidget *parent = 0);
44   void init();
45   
46   void setModel(QAbstractItemModel *model);
47   void setFilteredModel(QAbstractItemModel *model, BufferViewConfig *config);
48   virtual void setSelectionModel(QItemSelectionModel *selectionModel);
49   
50   void setConfig(BufferViewConfig *config);
51   inline BufferViewConfig *config() { return _config; }
52
53 public slots:
54   void setRootIndexForNetworkId(const NetworkId &networkId);
55   void removeSelectedBuffers(bool permanently = false);
56   
57 signals:
58   void removeBuffer(const QModelIndex &);
59   void removeBufferPermanently(const QModelIndex &);
60   
61 protected:
62   virtual void keyPressEvent(QKeyEvent *);
63   virtual void rowsInserted(const QModelIndex & parent, int start, int end);
64   virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
65   virtual void wheelEvent(QWheelEvent *);
66   virtual QSize sizeHint() const;
67   virtual void focusInEvent(QFocusEvent *event) { QAbstractScrollArea::focusInEvent(event); }
68   virtual void contextMenuEvent(QContextMenuEvent *event);
69
70 private slots:
71   void joinChannel(const QModelIndex &index);
72   void toggleHeader(bool checked);
73
74   void on_collapse(const QModelIndex &index);
75   void on_expand(const QModelIndex &index);
76   void on_configChanged();
77
78 private:
79   enum ItemActiveState {
80     InactiveState = 0x01,
81     ActiveState = 0x02
82   };
83
84 public:
85   Q_DECLARE_FLAGS(ItemActiveStates, ItemActiveState)
86   QAction showChannelList;
87
88 private:
89   QPointer<BufferViewConfig> _config;
90   
91   QAction _connectNetAction;
92   QAction _disconnectNetAction;
93   QAction _joinChannelAction;
94   
95   QAction _joinBufferAction;
96   QAction _partBufferAction;
97   QAction _hideBufferTemporarilyAction;
98   QAction _hideBufferPermanentlyAction;
99   QAction _removeBufferAction;
100   QAction _ignoreListAction;
101   
102   QAction _hideJoinAction;
103   QAction _hidePartAction;
104   QAction _hideQuitAction;
105   QAction _hideModeAction;
106
107   QHash<NetworkId, bool> _expandedState;
108
109   void storeExpandedState(NetworkId networkId, bool expanded);
110
111   bool checkRequirements(const QModelIndex &index,
112                          ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState) | QFlags<ItemActiveState>(InactiveState));
113   void addItemToMenu(QAction &action, QMenu &menu, const QModelIndex &index,
114                      ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState) | QFlags<ItemActiveState>(InactiveState));
115   void addItemToMenu(QAction &action, QMenu &menu, bool condition = true);
116   void addItemToMenu(QMenu &subMenu, QMenu &menu, const QModelIndex &index,
117                      ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState) | QFlags<ItemActiveState>(InactiveState));
118   void addSeparatorToMenu(QMenu &menu, const QModelIndex &index,
119                           ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState) | QFlags<ItemActiveState>(InactiveState));
120   QMenu *createHideEventsSubMenu(QMenu &menu, BufferId bufferId);
121 };
122 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferView::ItemActiveStates)
123
124
125 // ==============================
126 //  BufferView Dock
127 // ==============================
128 class BufferViewDock : public QDockWidget {
129   Q_OBJECT
130
131 public:
132   BufferViewDock(BufferViewConfig *config, QWidget *parent);
133   BufferViewDock(QWidget *parent);
134                                  
135 public slots:
136   void bufferViewRenamed(const QString &newName);
137 };
138
139 #endif
140