src: Yearly copyright bump
[quassel.git] / src / qtui / settingspages / ignorelistsettingspage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 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  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #ifndef IGNORELISTSETTINGSPAGE_H
22 #define IGNORELISTSETTINGSPAGE_H
23
24 #include <QStyledItemDelegate>
25 #include <QButtonGroup>
26
27 #include "settingspage.h"
28 #include "ui_ignorelistsettingspage.h"
29 #include "ui_ignorelisteditdlg.h"
30 #include "ignorelistmodel.h"
31 #include "clientignorelistmanager.h"
32
33 class QEvent;
34 class QPainter;
35 class QAbstractItemModel;
36
37 // the delegate is used to draw the checkbox in column 0
38 class IgnoreListDelegate : public QStyledItemDelegate
39 {
40     Q_OBJECT
41
42 public:
43     IgnoreListDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {}
44     void paint(QPainter *painter, const QStyleOptionViewItem &option,
45         const QModelIndex &index) const;
46     bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,
47         const QModelIndex &index);
48 };
49
50
51 class IgnoreListEditDlg : public QDialog
52 {
53     Q_OBJECT
54
55 public:
56     IgnoreListEditDlg(const IgnoreListManager::IgnoreListItem &item, QWidget *parent = 0, bool enabled = false);
57     inline IgnoreListManager::IgnoreListItem ignoreListItem() { return _ignoreListItem; }
58     void enableOkButton(bool state);
59
60 private slots:
61     void widgetHasChanged();
62     void aboutToAccept() { _ignoreListItem = _clonedIgnoreListItem; }
63
64 private:
65     IgnoreListManager::IgnoreListItem _ignoreListItem;
66     IgnoreListManager::IgnoreListItem _clonedIgnoreListItem;
67     bool _hasChanged;
68     Ui::IgnoreListEditDlg ui;
69     QButtonGroup _typeButtonGroup;
70     QButtonGroup _strictnessButtonGroup;
71     QButtonGroup _scopeButtonGroup;
72 };
73
74
75 class IgnoreListSettingsPage : public SettingsPage
76 {
77     Q_OBJECT
78
79 public:
80     IgnoreListSettingsPage(QWidget *parent = 0);
81     ~IgnoreListSettingsPage();
82     virtual inline bool hasDefaults() const { return false; }
83     virtual inline bool needsCoreConnection() const { return true; }
84     void editIgnoreRule(const QString &ignoreRule);
85
86 public slots:
87     void save();
88     void load();
89     void defaults();
90     void newIgnoreRule(QString rule = QString());
91
92 private slots:
93     void enableDialog(bool);
94     void deleteSelectedIgnoreRule();
95     void editSelectedIgnoreRule();
96     void selectionChanged(const QItemSelection &selection, const QItemSelection &);
97
98 private:
99     IgnoreListDelegate *_delegate;
100     Ui::IgnoreListSettingsPage ui;
101     IgnoreListModel _ignoreListModel;
102 };
103
104
105 #endif //IGNORELISTSETTINGSPAGE_H