KColorScheme

kcolorschememanager.h
1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef KCOLORSCHEMEMANAGER_H
9#define KCOLORSCHEMEMANAGER_H
10
11#include <kcolorscheme_export.h>
12
13#include <QObject>
14#include <memory>
15
17class QGuiApplication;
18class QModelIndex;
19class QIcon;
20
21class KActionMenu;
22class KColorSchemeManagerPrivate;
23
24/**
25 * @class KColorSchemeManager kcolorschememanager.h KColorSchemeManager
26 *
27 * A small helper to get access to all available color schemes and activating a scheme in the
28 * QApplication. This is useful for applications which want to provide a selection of custom color
29 * schemes to their user. For example it is very common for photo and painting applications to use
30 * a dark color scheme even if the default is a light scheme. Since version 5.67 it also allows
31 * going back to following the system color scheme.
32 *
33 * The model() member function provides access to the KColorSchemeModel that the KColorSchemeManager uses
34 * which holds all the available color schemes. A possible usage looks like the following:
35 *
36 * @code
37 * KColorSchemeManager *schemes = new KColorSchemeManager(this);
38 * QListView *view = new QListView(this);
39 * view->setModel(schemes->model());
40 * connect(view, &QListView::activated, schemes, &KColorSchemeManager::activateScheme);
41 * @endcode
42 *
43 * A convenience function that creates a KActionMenu that contains and activates color schemes exists
44 * in KColorSchemeMenu::createMenu
45 *
46 * By default KColorSchemeManager remembers the activated color scheme and restores it on the next
47 * start of the application. Use setAutosaveChanges() to change this behavior.
48 *
49 * @see KColorSchemeMenu::createMenu, KColorSchemeModel
50 *
51 * @since 5.0
52 */
53class KCOLORSCHEME_EXPORT KColorSchemeManager : public QObject
54{
55 Q_OBJECT
56public:
57#if KCOLORSCHEME_ENABLE_DEPRECATED_SINCE(6, 6)
58 KCOLORSCHEME_DEPRECATED_VERSION(6, 6, "Use KColorSchemeManager::instance()")
59 explicit KColorSchemeManager(QObject *parent = nullptr);
60#endif
61
62 ~KColorSchemeManager() override;
63
64 /**
65 * A QAbstractItemModel of all available color schemes.
66 *
67 * The model provides the name of the scheme in Qt::DisplayRole, a preview
68 * in Qt::DelegateRole and the full path to the scheme file in Qt::UserRole. The system theme
69 * has an empty Qt::UserRole.
70 *
71 * @return Model of all available color schemes.
72 * @see KColorSchemeModel
73 */
74 QAbstractItemModel *model() const;
75
76 /**
77 * Returns the model index for the scheme with the given @p id. If no such
78 * scheme exists an invalid index is returned. If you pass an empty string the index
79 * returned is equivalent to going back to following the system scheme.
80 * @see model
81 *
82 * @since 6.6
83 */
84 QModelIndex indexForSchemeId(const QString &id) const;
85
86 /**
87 * Returns the model index for the scheme with the given @p name. If no such
88 * scheme exists an invalid index is returned. If you pass an empty
89 * string the index that is equivalent to going back to following the system scheme is returned
90 * for versions 5.67 and newer.
91 * @see model
92 */
93 QModelIndex indexForScheme(const QString &name) const;
94
95 /**
96 * Saves the color scheme to config file. The scheme is saved by default whenever it's changed.
97 * Use this method when autosaving is turned off, see setAutosaveChanges().
98 *
99 * @since 5.89
100 */
101 void saveSchemeToConfigFile(const QString &schemeName) const;
102 /**
103 * Sets color scheme autosaving. Default value is @c true.
104 * If this is set to @c false, the scheme is not going to be remembered when the
105 * application is restarted.
106 *
107 * @param autosaveChanges Enables/Disables autosaving of the color scheme.
108 * @since 5.89
109 */
110 void setAutosaveChanges(bool autosaveChanges);
111
112 /**
113 * Returns the id of the currently active scheme or an empty string if the default
114 * scheme is active.
115 *
116 * @since 5.107
117 */
118 QString activeSchemeId() const;
119
120 /**
121 * Returns the name of the currently active scheme or an empty string if the default
122 * scheme is active.
123 *
124 * @since 6.6
125 */
126 QString activeSchemeName() const;
127
128 /**
129 * Returns the manager for the current application instance.
130 * If no instance is existing, it will be constructed.
131 * Must be called after construction of the gui application instance.
132 *
133 * @return color scheme manager for the current application instance
134 *
135 * @since 6.6
136 */
137 static KColorSchemeManager *instance();
138
139public Q_SLOTS:
140 /**
141 * @brief Activates the KColorScheme identified by the provided @p index.
142 *
143 * Installs the KColorScheme as the QApplication's QPalette.
144 *
145 * @param index The index for the KColorScheme to activate.
146 * The index must reference the QAbstractItemModel provided by @link model @endlink. Since
147 * version 5.67 passing an invalid index activates the system scheme.
148 * @see model()
149 */
150 void activateScheme(const QModelIndex &index);
151
152private:
153 class KCOLORSCHEME_NO_EXPORT GuardApplicationConstructor
154 {
155 };
156 KCOLORSCHEME_NO_EXPORT explicit KColorSchemeManager(GuardApplicationConstructor, QGuiApplication *app);
157 KCOLORSCHEME_NO_EXPORT void init();
158
159 std::unique_ptr<KColorSchemeManagerPrivate> const d;
160};
161
162#endif
A small helper to get access to all available color schemes and activating a scheme in the QApplicati...
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:51 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.