KColorSchemeManager Class

A small helper to get access to all available color schemes and activating a scheme in the QApplication. More...

Header: #include <KColorSchemeManager>
CMake: find_package(KF6 REQUIRED COMPONENTS ColorScheme)
target_link_libraries(mytarget PRIVATE KF6::ColorScheme)
Since: KColorScheme 5.0

Public Functions

(since KColorScheme 5.107) QString activeSchemeId() const
(since KColorScheme 6.6) QString activeSchemeName() const
QModelIndex indexForScheme(const QString &name) const
(since KColorScheme 6.6) QModelIndex indexForSchemeId(const QString &id) const
QAbstractItemModel *model() const
(since KColorScheme 5.89) void saveSchemeToConfigFile(const QString &schemeName) const
(since KColorScheme 5.89) void setAutosaveChanges(bool autosaveChanges)

Public Slots

void activateScheme(const QModelIndex &index)

Static Public Members

(since KColorScheme 6.6) KColorSchemeManager *instance()

Detailed Description

This is useful for applications which want to provide a selection of custom color schemes to their user. For example it is very common for photo and painting applications to use a dark color scheme even if the default is a light scheme. Since version 5.67 it also allows going back to following the system color scheme.

The model() member function provides access to the KColorSchemeModel that the KColorSchemeManager uses which holds all the available color schemes. A possible usage looks like the following:

KColorSchemeManager *schemes = new KColorSchemeManager(this);
QListView *view = new QListView(this);
view->setModel(schemes->model());
connect(view, &QListView::activated, schemes, &KColorSchemeManager::activateScheme);

A convenience function that creates a KActionMenu that contains and activates color schemes exists in KColorSchemeMenu::createMenu

By default KColorSchemeManager remembers the activated color scheme and restores it on the next start of the application. Use setAutosaveChanges() to change this behavior.

See also KColorSchemeMenu::createMenu and KColorSchemeModel.

Member Function Documentation

[slot] void KColorSchemeManager::activateScheme(const QModelIndex &index)

Activates the KColorScheme identified by the provided index.

Installs the KColorScheme as the QApplication's QPalette.

index The index for the KColorScheme to activate. The index must reference the QAbstractItemModel provided by model(). Since version 5.67 passing an invalid index activates the system scheme.

See also model().

[since KColorScheme 5.107] QString KColorSchemeManager::activeSchemeId() const

Returns the id of the currently active scheme or an empty string if the default scheme is active.

This function was introduced in KColorScheme 5.107.

[since KColorScheme 6.6] QString KColorSchemeManager::activeSchemeName() const

Returns the name of the currently active scheme or an empty string if the default scheme is active.

This function was introduced in KColorScheme 6.6.

QModelIndex KColorSchemeManager::indexForScheme(const QString &name) const

Returns the model index for the scheme with the given name. If no such scheme exists an invalid index is returned. If you pass an empty string the index that is equivalent to going back to following the system scheme is returned for versions 5.67 and newer.

See also model.

[since KColorScheme 6.6] QModelIndex KColorSchemeManager::indexForSchemeId(const QString &id) const

Returns the model index for the scheme with the given id. If no such scheme exists an invalid index is returned. If you pass an empty string the index returned is equivalent to going back to following the system scheme.

This function was introduced in KColorScheme 6.6.

See also model.

[static, since KColorScheme 6.6] KColorSchemeManager *KColorSchemeManager::instance()

Returns the manager for the current application instance. If no instance is existing, it will be constructed. Must be called after construction of the gui application instance.

Returns color scheme manager for the current application instance

This function was introduced in KColorScheme 6.6.

QAbstractItemModel *KColorSchemeManager::model() const

A QAbstractItemModel of all available color schemes.

The model provides the name of the scheme in Qt::DisplayRole, a preview in Qt::DelegateRole and the full path to the scheme file in Qt::UserRole. The system theme has an empty Qt::UserRole.

Returns Model of all available color schemes.

See also KColorSchemeModel.

[since KColorScheme 5.89] void KColorSchemeManager::saveSchemeToConfigFile(const QString &schemeName) const

Saves the color scheme to config file. The scheme is saved by default whenever it's changed. Use this method when autosaving is turned off, see setAutosaveChanges().

This function was introduced in KColorScheme 5.89.

[since KColorScheme 5.89] void KColorSchemeManager::setAutosaveChanges(bool autosaveChanges)

Sets color scheme autosaving. Default value is true. If this is set to false, the scheme is not going to be remembered when the application is restarted.

autosaveChanges Enables/Disables autosaving of the color scheme.

This function was introduced in KColorScheme 5.89.