Fix genversion error in unclean build directories
[quassel.git] / src / uisupport / bufferview.h
1 /***************************************************************************
2  *   Copyright (C) 2005-09 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 <QStyledItemDelegate>
29 #include <QTreeView>
30 #include <QPointer>
31
32 #include "actioncollection.h"
33 #include "bufferviewconfig.h"
34 #include "networkmodel.h"
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   void addFilterActions(QMenu *contextMenu, const QModelIndex &index);
56
57 public slots:
58   void setRootIndexForNetworkId(const NetworkId &networkId);
59   void removeSelectedBuffers(bool permanently = false);
60   void menuActionTriggered(QAction *);
61
62 signals:
63   void removeBuffer(const QModelIndex &);
64   void removeBufferPermanently(const QModelIndex &);
65
66 protected:
67   virtual void keyPressEvent(QKeyEvent *);
68   virtual void dropEvent(QDropEvent *event);
69   virtual void rowsInserted(const QModelIndex & parent, int start, int end);
70   virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
71   virtual void wheelEvent(QWheelEvent *);
72   virtual QSize sizeHint() const;
73   virtual void focusInEvent(QFocusEvent *event) { QAbstractScrollArea::focusInEvent(event); }
74   virtual void contextMenuEvent(QContextMenuEvent *event);
75
76 private slots:
77   void joinChannel(const QModelIndex &index);
78   void toggleHeader(bool checked);
79
80   void storeExpandedState(const QModelIndex &networkIdx);
81   void setExpandedState(const QModelIndex &networkIdx);
82
83   void on_configChanged();
84   void on_layoutChanged();
85
86 private:
87   QPointer<BufferViewConfig> _config;
88
89   enum ExpandedState {
90     WasExpanded = 0x01,
91     WasActive = 0x02
92   };
93   QHash<NetworkId, short> _expandedState;
94
95 };
96
97 // ******************************
98 //  BufferViewDelgate
99 // ******************************
100
101 class BufferViewDelegate : public QStyledItemDelegate {
102   Q_OBJECT
103
104 public:
105   BufferViewDelegate(QObject *parent = 0);
106   bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
107
108 protected:
109   virtual void customEvent(QEvent *event);
110 };
111
112 // ==============================
113 //  BufferView Dock
114 // ==============================
115 class BufferViewDock : public QDockWidget {
116   Q_OBJECT
117
118 public:
119   BufferViewDock(BufferViewConfig *config, QWidget *parent);
120
121   int bufferViewId() const;
122   BufferViewConfig *config() const;
123   inline BufferView *bufferView() const { return qobject_cast<BufferView *>(widget()); }
124
125 public slots:
126   void bufferViewRenamed(const QString &newName);
127 };
128
129 #endif