b2d1e0edbde0402211c388230b5ef55d17c13254
[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 <QTreeView>
29 #include <QPointer>
30
31 #include "actioncollection.h"
32 #include "bufferviewconfig.h"
33 #include "networkmodel.h"
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   void addActionsToMenu(QMenu *menu, const QModelIndex &index);
54   void addFilterActions(QMenu *contextMenu, const QModelIndex &index);
55
56 public slots:
57   void setRootIndexForNetworkId(const NetworkId &networkId);
58   void removeSelectedBuffers(bool permanently = false);
59   void menuActionTriggered(QAction *);
60
61 signals:
62   void removeBuffer(const QModelIndex &);
63   void removeBufferPermanently(const QModelIndex &);
64
65 protected:
66   virtual void keyPressEvent(QKeyEvent *);
67   virtual void dropEvent(QDropEvent *event);
68   virtual void rowsInserted(const QModelIndex & parent, int start, int end);
69   virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
70   virtual void wheelEvent(QWheelEvent *);
71   virtual QSize sizeHint() const;
72   virtual void focusInEvent(QFocusEvent *event) { QAbstractScrollArea::focusInEvent(event); }
73   virtual void contextMenuEvent(QContextMenuEvent *event);
74
75 private slots:
76   void joinChannel(const QModelIndex &index);
77   void toggleHeader(bool checked);
78
79   void storeExpandedState(const QModelIndex &networkIdx);
80   void setExpandedState(const QModelIndex &networkIdx);
81
82   void on_configChanged();
83   void on_layoutChanged();
84
85   void setCustomFont(const QVariant &font);
86
87 private:
88   QPointer<BufferViewConfig> _config;
89
90   enum ExpandedState {
91     WasExpanded = 0x01,
92     WasActive = 0x02
93   };
94   QHash<NetworkId, short> _expandedState;
95
96 };
97
98 // ******************************
99 //  BufferViewDelgate
100 // ******************************
101 #include <QStyledItemDelegate>
102
103 class BufferViewDelegate : public QStyledItemDelegate {
104   Q_OBJECT
105
106 public:
107   BufferViewDelegate(QObject *parent = 0);
108   bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
109
110 protected:
111   virtual void customEvent(QEvent *event);
112   virtual void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const;
113
114 private slots:
115   void colorsChanged();
116   void loadColors();
117
118 private:
119   QColor _FgColorInactiveActivity;
120   QColor _FgColorNoActivity;
121   QColor _FgColorHighlightActivity;
122   QColor _FgColorNewMessageActivity;
123   QColor _FgColorOtherActivity;
124
125   bool _updateColors;
126 };
127
128
129 // ==============================
130 //  BufferView Dock
131 // ==============================
132 class BufferViewDock : public QDockWidget {
133   Q_OBJECT
134
135 public:
136   BufferViewDock(BufferViewConfig *config, QWidget *parent);
137
138   int bufferViewId() const;
139   BufferViewConfig *config() const;
140   inline BufferView *bufferView() const { return qobject_cast<BufferView *>(widget()); }
141
142 public slots:
143   void bufferViewRenamed(const QString &newName);
144 };
145
146 #endif