Fix a regression that would show some wrong context menu entries in some cases
[quassel.git] / src / uisupport / bufferviewfilter.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 BUFFERVIEWFILTER_H_
22 #define BUFFERVIEWFILTER_H_
23
24 #include <QAction>
25 #include <QColor>
26 #include <QDropEvent>
27 #include <QFlags>
28 #include <QPixmap>
29 #include <QPointer>
30 #include <QSet>
31 #include <QSortFilterProxyModel>
32
33 #include "types.h"
34 #include "bufferviewconfig.h"
35
36 /*****************************************
37  * Buffer View Filter
38  *****************************************/
39 class BufferViewFilter : public QSortFilterProxyModel {
40   Q_OBJECT
41
42 public:
43   enum Mode {
44     NoActive = 0x01,
45     NoInactive = 0x02,
46     SomeNets = 0x04,
47     AllNets = 0x08,
48     NoChannels = 0x10,
49     NoQueries = 0x20,
50     NoServers = 0x40,
51     FullCustom = 0x80
52   };
53   Q_DECLARE_FLAGS(Modes, Mode)
54
55   BufferViewFilter(QAbstractItemModel *model, BufferViewConfig *config = 0);
56
57   virtual Qt::ItemFlags flags(const QModelIndex &index) const;
58   virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
59
60   QVariant data(const QModelIndex &index, int role) const;
61   QVariant icon(const QModelIndex &index) const;
62   QVariant foreground(const QModelIndex &index) const;
63   QVariant checkedState(const QModelIndex &index) const;
64
65   bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
66   bool setCheckedState(const QModelIndex &index, Qt::CheckState state);
67
68   void setConfig(BufferViewConfig *config);
69   inline BufferViewConfig *config() const { return _config; }
70
71   virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
72
73   QList<QAction *> actions(const QModelIndex &index);
74
75 public slots:
76   void checkPreviousCurrentForRemoval(const QModelIndex &current, const QModelIndex &previous);
77   void checkItemForRemoval(const QModelIndex &index) { checkItemsForRemoval(index, index); }
78   void checkItemsForRemoval(const QModelIndex &topLeft, const QModelIndex &bottomRight);
79
80 protected:
81   bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
82   bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
83   bool bufferLessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
84   bool networkLessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
85   virtual void customEvent(QEvent *event);
86
87 signals:
88   void _dataChanged(const QModelIndex &source_topLeft, const QModelIndex &source_bottomRight);
89   void configChanged();
90
91 private slots:
92   void configInitialized();
93   void showUserStateIconsChanged();
94   void enableEditMode(bool enable);
95
96 private:
97   QPointer<BufferViewConfig> _config;
98   Qt::SortOrder _sortOrder;
99
100   QColor _FgColorInactiveActivity;
101   QColor _FgColorNoActivity;
102   QColor _FgColorHighlightActivity;
103   QColor _FgColorNewMessageActivity;
104   QColor _FgColorOtherActivity;
105
106   QPixmap _userOfflineIcon;
107   QPixmap _userAwayIcon;
108   QPixmap _userOnlineIcon;
109   bool _showUserStateIcons;
110
111   bool _editMode;
112   QAction _enableEditMode;
113   QSet<BufferId> _toAdd;
114   QSet<BufferId> _toTempRemove;
115   QSet<BufferId> _toRemove;
116
117   void loadColors();
118
119   bool filterAcceptBuffer(const QModelIndex &) const;
120   bool filterAcceptNetwork(const QModelIndex &) const;
121   void addBuffer(const BufferId &) const;
122   static bool bufferIdLessThan(const BufferId &, const BufferId &);
123 };
124 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferViewFilter::Modes)
125
126 #endif // BUFFERVIEWFILTER_H_