Make BufferView compile
[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();
56
57   signals:
58     void removeBuffer(const QModelIndex &);
59
60   protected:
61     virtual void keyPressEvent(QKeyEvent *);
62     virtual void rowsInserted(const QModelIndex & parent, int start, int end);
63     virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
64     virtual void wheelEvent(QWheelEvent *);
65     virtual QSize sizeHint() const;
66     virtual void focusInEvent(QFocusEvent *event) { QAbstractScrollArea::focusInEvent(event); }
67     virtual void contextMenuEvent(QContextMenuEvent *event);
68
69   private slots:
70     void joinChannel(const QModelIndex &index);
71     void toggleHeader(bool checked);
72     //  void showContextMenu(const QPoint &);
73     void layoutChanged();
74
75   private:
76     enum ItemActiveState {
77       InactiveState = 0x01,
78       ActiveState = 0x02
79     };
80   public:
81     Q_DECLARE_FLAGS(ItemActiveStates, ItemActiveState);
82
83   private:
84     QPointer<BufferViewConfig> _config;
85
86     QAction _connectNetAction;
87     QAction _disconnectNetAction;
88     QAction _joinChannelAction;
89
90     QAction _joinBufferAction;
91     QAction _partBufferAction;
92     QAction _hideBufferAction;
93     QAction _removeBufferAction;
94     QAction _ignoreListAction;
95
96     QAction _hideJoinAction;
97     QAction _hidePartAction;
98     QAction _hideKillAction;
99     QAction _hideQuitAction;
100     QAction _hideModeAction;
101
102     bool checkRequirements(const QModelIndex &index,
103                            ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState) | QFlags<ItemActiveState>(InactiveState));
104     void addItemToMenu(QAction &action, QMenu &menu, const QModelIndex &index,
105                        ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState) | QFlags<ItemActiveState>(InactiveState));
106     void addItemToMenu(QAction &action, QMenu &menu, bool condition = true);
107     void addItemToMenu(QMenu &subMenu, QMenu &menu, const QModelIndex &index,
108                        ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState) | QFlags<ItemActiveState>(InactiveState));
109     void addSeparatorToMenu(QMenu &menu, const QModelIndex &index,
110                             ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState) | QFlags<ItemActiveState>(InactiveState));
111     QMenu *createHideEventsSubMenu(QMenu &menu);
112 };
113 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferView::ItemActiveStates);
114
115
116 // ==============================
117 //  BufferView Dock
118 // ==============================
119 class BufferViewDock : public QDockWidget {
120     Q_OBJECT
121
122   public:
123     BufferViewDock(BufferViewConfig *config, QWidget *parent);
124     BufferViewDock(QWidget *parent);
125
126   public slots:
127     void bufferViewRenamed(const QString &newName);
128 };
129
130 #endif
131