qa: Avoid deprecation warnings for QList/QSet conversions
[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 <QButtonGroup>
25 #include <QStyledItemDelegate>
26
27 #include "clientignorelistmanager.h"
28 #include "ignorelistmodel.h"
29 #include "settingspage.h"
30
31 #include "ui_ignorelisteditdlg.h"
32 #include "ui_ignorelistsettingspage.h"
33
34 class QEvent;
35 class QPainter;
36 class QAbstractItemModel;
37
38 // the delegate is used to draw the checkbox in column 0
39 class IgnoreListDelegate : public QStyledItemDelegate
40 {
41     Q_OBJECT
42
43 public:
44     IgnoreListDelegate(QWidget* parent = nullptr)
45         : QStyledItemDelegate(parent)
46     {}
47     void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
48     bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
49 };
50
51 class IgnoreListEditDlg : public QDialog
52 {
53     Q_OBJECT
54
55 public:
56     IgnoreListEditDlg(const IgnoreListManager::IgnoreListItem& item, QWidget* parent = nullptr, 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 class IgnoreListSettingsPage : public SettingsPage
75 {
76     Q_OBJECT
77
78 public:
79     IgnoreListSettingsPage(QWidget* parent = nullptr);
80     ~IgnoreListSettingsPage() override;
81     inline bool hasDefaults() const override { return false; }
82     inline bool needsCoreConnection() const override { return true; }
83     void editIgnoreRule(const QString& ignoreRule);
84
85 public slots:
86     void save() override;
87     void load() override;
88     void defaults() override;
89     void newIgnoreRule(const QString& rule = {});
90
91 private slots:
92     void enableDialog(bool);
93     void deleteSelectedIgnoreRule();
94     void editSelectedIgnoreRule();
95     void selectionChanged(const QItemSelection& selection, const QItemSelection&);
96
97 private:
98     IgnoreListDelegate* _delegate;
99     Ui::IgnoreListSettingsPage ui;
100     IgnoreListModel _ignoreListModel;
101 };
102
103 #endif  // IGNORELISTSETTINGSPAGE_H