Changeset View
Changeset View
Standalone View
Standalone View
kcms/colors/colorsmodel.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2007 Matthew Woehlke <mw_triad@users.sourceforge.net> | ||||
3 | * Copyright (C) 2007 Jeremy Whiting <jpwhiting@kde.org> | ||||
4 | * Copyright (C) 2016 Olivier Churlaud <olivier@churlaud.com> | ||||
5 | * Copyright (C) 2019 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
6 | * | ||||
7 | * This program is free software; you can redistribute it and/or | ||||
8 | * modify it under the terms of the GNU General Public License as | ||||
9 | * published by the Free Software Foundation; either version 2 of | ||||
10 | * the License or (at your option) version 3 or any later version | ||||
11 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
12 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
13 | * defined in Section 14 of version 3 of the license. | ||||
14 | * | ||||
15 | * This program is distributed in the hope that it will be useful, | ||||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
18 | * GNU General Public License for more details. | ||||
19 | * | ||||
20 | * You should have received a copy of the GNU General Public License | ||||
21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
22 | */ | ||||
23 | | ||||
24 | #pragma once | ||||
25 | | ||||
26 | #include <QAbstractListModel> | ||||
27 | #include <QString> | ||||
28 | #include <QPalette> | ||||
29 | #include <QVector> | ||||
30 | | ||||
31 | struct ColorsModelData | ||||
32 | { | ||||
33 | QString display; | ||||
34 | QString schemeName; | ||||
35 | QPalette palette; | ||||
36 | bool removable; | ||||
37 | bool pendingDeletion; | ||||
38 | }; | ||||
39 | Q_DECLARE_TYPEINFO(ColorsModelData, Q_MOVABLE_TYPE); | ||||
40 | | ||||
41 | class ColorsModel : public QAbstractListModel | ||||
42 | { | ||||
43 | Q_OBJECT | ||||
44 | | ||||
45 | Q_PROPERTY(QString selectedScheme READ selectedScheme WRITE setSelectedScheme NOTIFY selectedSchemeChanged) | ||||
46 | Q_PROPERTY(int selectedSchemeIndex READ selectedSchemeIndex NOTIFY selectedSchemeIndexChanged) | ||||
47 | | ||||
48 | public: | ||||
49 | ColorsModel(QObject *parent); | ||||
50 | ~ColorsModel() override; | ||||
51 | | ||||
52 | enum Roles { | ||||
53 | SchemeNameRole = Qt::UserRole + 1, | ||||
54 | PaletteRole, | ||||
55 | RemovableRole, | ||||
56 | PendingDeletionRole | ||||
57 | }; | ||||
58 | | ||||
59 | int rowCount(const QModelIndex &parent) const override; | ||||
60 | QVariant data(const QModelIndex &index, int role) const override; | ||||
61 | bool setData(const QModelIndex &index, const QVariant &value, int role) override; | ||||
62 | QHash<int, QByteArray> roleNames() const override; | ||||
63 | | ||||
64 | QString selectedScheme() const; | ||||
65 | void setSelectedScheme(const QString &scheme); | ||||
66 | | ||||
67 | int indexOfScheme(const QString &scheme) const; | ||||
68 | int selectedSchemeIndex() const; | ||||
69 | | ||||
70 | QStringList pendingDeletions() const; | ||||
71 | void removeItemsPendingDeletion(); | ||||
72 | | ||||
73 | void load(); | ||||
74 | | ||||
75 | Q_SIGNALS: | ||||
76 | void selectedSchemeChanged(const QString &scheme); | ||||
77 | void selectedSchemeIndexChanged(); | ||||
78 | | ||||
79 | void pendingDeletionsChanged(); | ||||
80 | | ||||
81 | private: | ||||
82 | QString m_selectedScheme; | ||||
83 | | ||||
84 | QVector<ColorsModelData> m_data; | ||||
85 | | ||||
86 | }; |