Fix compiler warnings
[quassel.git] / src / uisupport / bufferview.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2010 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   enum Direction {
45     Forward = 1,
46     Backward = -1
47   };
48
49   BufferView(QWidget *parent = 0);
50   void init();
51
52   void setModel(QAbstractItemModel *model);
53   void setFilteredModel(QAbstractItemModel *model, BufferViewConfig *config);
54   virtual void setSelectionModel(QItemSelectionModel *selectionModel);
55
56   void setConfig(BufferViewConfig *config);
57   inline BufferViewConfig *config() { return _config; }
58
59   void addActionsToMenu(QMenu *menu, const QModelIndex &index);
60   void addFilterActions(QMenu *contextMenu, const QModelIndex &index);
61
62 public slots:
63   void setRootIndexForNetworkId(const NetworkId &networkId);
64   void removeSelectedBuffers(bool permanently = false);
65   void menuActionTriggered(QAction *);
66   void nextBuffer();
67   void previousBuffer();
68
69 signals:
70   void removeBuffer(const QModelIndex &);
71   void removeBufferPermanently(const QModelIndex &);
72
73 protected:
74   virtual void keyPressEvent(QKeyEvent *);
75   virtual void dropEvent(QDropEvent *event);
76   virtual void rowsInserted(const QModelIndex & parent, int start, int end);
77   virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
78   virtual void wheelEvent(QWheelEvent *);
79   virtual QSize sizeHint() const;
80   virtual void focusInEvent(QFocusEvent *event) { QAbstractScrollArea::focusInEvent(event); }
81   virtual void contextMenuEvent(QContextMenuEvent *event);
82
83 private slots:
84   void joinChannel(const QModelIndex &index);
85   void toggleHeader(bool checked);
86
87   void storeExpandedState(const QModelIndex &networkIdx);
88   void setExpandedState(const QModelIndex &networkIdx);
89
90   void on_configChanged();
91   void on_layoutChanged();
92
93   void changeBuffer(Direction direction);
94
95 private:
96   QPointer<BufferViewConfig> _config;
97
98   enum ExpandedState {
99     WasExpanded = 0x01,
100     WasActive = 0x02
101   };
102   QHash<NetworkId, short> _expandedState;
103
104 };
105
106 // ******************************
107 //  BufferViewDelgate
108 // ******************************
109
110 class BufferViewDelegate : public QStyledItemDelegate {
111   Q_OBJECT
112
113 public:
114   BufferViewDelegate(QObject *parent = 0);
115   bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
116
117 protected:
118   virtual void customEvent(QEvent *event);
119 };
120
121 // ==============================
122 //  BufferView Dock
123 // ==============================
124 class BufferViewDock : public QDockWidget {
125   Q_OBJECT
126   Q_PROPERTY(bool active READ isActive WRITE setActive STORED true)
127
128 public:
129   BufferViewDock(BufferViewConfig *config, QWidget *parent);
130
131   int bufferViewId() const;
132   BufferViewConfig *config() const;
133   inline BufferView *bufferView() const { return qobject_cast<BufferView *>(widget()); }
134   inline bool isActive() const { return _active; }
135
136 public slots:
137   void setActive(bool active = true);
138
139 private slots:
140   void bufferViewRenamed(const QString &newName);
141   void updateTitle();
142
143 private:
144
145   bool _active;
146   QString _title;
147 };
148
149 #endif