cut 3.3.0
Loading...
Searching...
No Matches
QePalettesModel.hpp
1#ifndef QEPALETTESMODEL_HPP
2#define QEPALETTESMODEL_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 "QePalette.hpp"
29#include <QAbstractListModel>
30#include <QString>
31#include <QVector>
32#include <QAction>
33#include <cstddef>
34
35struct QePalettesModelData
36{
37 QString display;
38 QString schemeName;
39 QePalette palette;
40 QColor activeTitleBarBackground;
41 QColor activeTitleBarForeground;
42 bool removable;
43 bool pendingDeletion;
44};
45Q_DECLARE_TYPEINFO(QePalettesModelData, Q_MOVABLE_TYPE);
46
47class QePalettesModel : public QAbstractListModel
48{
49 Q_OBJECT
50
51 Q_PROPERTY(QString selectedScheme READ selectedScheme WRITE setSelectedScheme NOTIFY selectedSchemeChanged)
52 Q_PROPERTY(int selectedSchemeIndex READ selectedSchemeIndex NOTIFY selectedSchemeIndexChanged)
53
54public:
55 QePalettesModel();
56 QePalettesModel(QObject *parent);
57 ~QePalettesModel() override;
58
59 enum Roles {
60 SchemeNameRole = Qt::UserRole + 1,
61 PaletteRole,
62 // Colors which aren't in QPalette
63 ActiveTitleBarBackgroundRole,
64 ActiveTitleBarForegroundRole,
65 RemovableRole,
66 PendingDeletionRole
67 };
68
69 int rowCount(const QModelIndex &parent) const override;
70 QVariant data(const QModelIndex &index, int role) const override;
71 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
72 QHash<int, QByteArray> roleNames() const override;
73 QePalette getPalette(int row);
74
75 QString selectedScheme() const;
76 void setSelectedScheme(const QString &scheme);
77
78 int indexOfScheme(const QString &scheme) const;
79 int selectedSchemeIndex() const;
80
81 QStringList pendingDeletions() const;
82 void removeItemsPendingDeletion();
83
84 void load();
85
86 QAction* colorSchemeMenu();
87
88public slots:
89 void handle_colorSchemesMenuEntry_triggered();
90
91
92signals:
93 void selectedSchemeChanged(const QString &scheme);
94 void selectedSchemeIndexChanged();
95 void pendingDeletionsChanged();
96
97private:
98 QString m_selectedScheme;
99 QVector<QePalettesModelData> m_data;
100 QAction* m_colors_scheme_menu;
101
102 QVariant readKdeSetting(const QString &key, QString file);
103 void readKdeSystemPalette(QString file, QePalette *pal);
104
105};
106
107#endif