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