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 QModelIndex;
18class QIcon;
19
20class KActionMenu;
21class KColorSchemeManagerPrivate;
22
23/**
24 * @class KColorSchemeManager kcolorschememanager.h KColorSchemeManager
25 *
26 * A small helper to get access to all available color schemes and activating a scheme in the
27 * QApplication. This is useful for applications which want to provide a selection of custom color
28 * schemes to their user. For example it is very common for photo and painting applications to use
29 * a dark color scheme even if the default is a light scheme. Since version 5.67 it also allows
30 * going back to following the system color scheme.
31 *
32 * The model() member function provides access to the KColorSchemeModel that the KColorSchemeManager uses
33 * which holds all the available color schemes. A possible usage looks like the following:
34 *
35 * @code
36 * KColorSchemeManager *schemes = new KColorSchemeManager(this);
37 * QListView *view = new QListView(this);
38 * view->setModel(schemes->model());
39 * connect(view, &QListView::activated, schemes, &KColorSchemeManager::activateScheme);
40 * @endcode
41 *
42 * A convenience function that creates a KActionMenu that contains and activates color schemes exists
43 * in KColorSchemeMenu::createMenu
44 *
45 * By default KColorSchemeManager remembers the activated color scheme and restores it on the next
46 * start of the application. Use setAutosaveChanges() to change this behavior.
47 *
48 * @see KColorSchemeMenu::createMenu, KColorSchemeModel
49 *
50 * @since 5.0
51 */
52class KCOLORSCHEME_EXPORT KColorSchemeManager : public QObject
53{
54 Q_OBJECT
55public:
56 explicit KColorSchemeManager(QObject *parent = nullptr);
57 ~KColorSchemeManager() override;
58
59 /**
60 * A QAbstractItemModel of all available color schemes.
61 *
62 * The model provides the name of the scheme in Qt::DisplayRole, a preview
63 * in Qt::DelegateRole and the full path to the scheme file in Qt::UserRole. The system theme
64 * has an empty Qt::UserRole.
65 *
66 * @return Model of all available color schemes.
67 * @see KColorSchemeModel
68 */
69 QAbstractItemModel *model() const;
70 /**
71 * Returns the model index for the scheme with the given @p name. If no such
72 * scheme exists an invalid index is returned. If you pass an empty
73 * string the index that is equivalent to going back to following the system scheme is returned
74 * for versions 5.67 and newer.
75 * @see model
76 */
77 QModelIndex indexForScheme(const QString &name) const;
78
79 /**
80 * Saves the color scheme to config file. The scheme is saved by default whenever it's changed.
81 * Use this method when autosaving is turned off, see setAutosaveChanges().
82 *
83 * @since 5.89
84 */
85 void saveSchemeToConfigFile(const QString &schemeName) const;
86 /**
87 * Sets color scheme autosaving. Default value is @c true.
88 * If this is set to @c false, the scheme is not going to be remembered when the
89 * application is restarted.
90 *
91 * @param autosaveChanges Enables/Disables autosaving of the color scheme.
92 * @since 5.89
93 */
94 void setAutosaveChanges(bool autosaveChanges);
95
96 /**
97 * Returns the id of the currently active scheme or an empty string if the default
98 * scheme is active.
99 *
100 * @since 5.107
101 */
102 QString activeSchemeId() const;
103
104public Q_SLOTS:
105 /**
106 * @brief Activates the KColorScheme identified by the provided @p index.
107 *
108 * Installs the KColorScheme as the QApplication's QPalette.
109 *
110 * @param index The index for the KColorScheme to activate.
111 * The index must reference the QAbstractItemModel provided by @link model @endlink. Since
112 * version 5.67 passing an invalid index activates the system scheme.
113 * @see model()
114 */
115 void activateScheme(const QModelIndex &index);
116
117private:
118 std::unique_ptr<KColorSchemeManagerPrivate> const d;
119};
120
121#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 Fri May 17 2024 11:50:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.