Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Drop unused KColorSchemeManager fork
Nicolas Fellae06fcc16023b
diff --git a/libs/widgetutils/CMakeLists.txt b/libs/widgetutils/CMakeLists.txtindex 3f27e42316..20ea77ae1d 100644--- a/libs/widgetutils/CMakeLists.txt+++ b/libs/widgetutils/CMakeLists.txt@@ -51,7 +51,6 @@ set(kritawidgetutils_LIB_SRCSKisScreenMigrationTracker.cppconfig/kcolorscheme.cpp- config/kcolorschememanager.cppconfig/khelpclient.cppconfig/klanguagebutton.cppconfig/krecentfilesaction.cppdiff --git a/libs/widgetutils/config/kcolorschememanager.cpp b/libs/widgetutils/config/kcolorschememanager.cppdeleted file mode 100644index 69603138be..0000000000--- a/libs/widgetutils/config/kcolorschememanager.cpp+++ /dev/null@@ -1,189 +0,0 @@-/* This file is part of the KDE project- * SPDX-FileCopyrightText: 2013 Martin Gräßlin <[email protected]>- *- * SPDX-License-Identifier: LGPL-2.0-or-later- */-#include "kcolorschememanager.h"-#include "kcolorschememanager_p.h"--#include <kactionmenu.h>-#include <kconfiggroup.h>-#include <kcolorscheme.h>-#include <ksharedconfig.h>--#include <QApplication>-#include <QDir>-#include <QFileInfo>-#include <QPainter>-#include <QActionGroup>--#include <KoResourcePaths.h>--KColorSchemeManagerPrivate::KColorSchemeManagerPrivate()- : model(new KColorSchemeModel())-{-}--KColorSchemeModel::KColorSchemeModel(QObject *parent)- : QAbstractListModel(parent)-{- init();-}--KColorSchemeModel::~KColorSchemeModel()-{-}--int KColorSchemeModel::rowCount(const QModelIndex &parent) const-{- if (parent.isValid()) {- return 0;- }- return m_data.count();-}--QVariant KColorSchemeModel::data(const QModelIndex &index, int role) const-{- if (!index.isValid() || (index.row() >= m_data.count())) {- return QVariant();- }-- switch (role) {- case Qt::DisplayRole:- return m_data.at(index.row()).name;- case Qt::DecorationRole:- return m_data.at(index.row()).preview;- case Qt::UserRole:- return m_data.at(index.row()).path;- default:- return QVariant();- }-}--void KColorSchemeModel::init()-{- beginResetModel();- m_data.clear();-- const QStringList dirs = KoResourcePaths::findDirs(QStringLiteral("color-schemes"));- QStringList schemeFiles;- Q_FOREACH (const QString &dir, dirs) {- const QStringList fileNames = QDir(dir).entryList(QStringList() << QStringLiteral("*.colors"));- Q_FOREACH (const QString &file, fileNames) {- schemeFiles << dir + '/' + file;- }- }- Q_FOREACH (const QString &schemeFile, schemeFiles) {- KSharedConfigPtr config = KSharedConfig::openConfig(schemeFile);- KConfigGroup group(config, QStringLiteral("General"));- const QString name = group.readEntry("Name", QFileInfo(schemeFile).completeBaseName());- const KColorSchemeModelData data = {name, schemeFile, createPreview(schemeFile)};- m_data.append(data);- }- std::sort(m_data.begin(), m_data.end(), [](const KColorSchemeModelData & first, const KColorSchemeModelData & second) {- return first.name < second.name;- });- endResetModel();-}--QIcon KColorSchemeModel::createPreview(const QString &path)-{- KSharedConfigPtr schemeConfig = KSharedConfig::openConfig(path);- QIcon result;- KColorScheme activeWindow(QPalette::Active, KColorScheme::Window, schemeConfig);- KColorScheme activeButton(QPalette::Active, KColorScheme::Button, schemeConfig);- KColorScheme activeView(QPalette::Active, KColorScheme::View, schemeConfig);- KColorScheme activeSelection(QPalette::Active, KColorScheme::Selection, schemeConfig);-- auto pixmap = [&](int size) {- QPixmap pix(size, size);- pix.fill(Qt::black);- QPainter p;- p.begin(&pix);- const int itemSize = size / 2 - 1;- p.fillRect(1, 1, itemSize, itemSize, activeWindow.background());- p.fillRect(1 + itemSize, 1, itemSize, itemSize, activeButton.background());- p.fillRect(1, 1 + itemSize, itemSize, itemSize, activeView.background());- p.fillRect(1 + itemSize, 1 + itemSize, itemSize, itemSize, activeSelection.background());- p.end();- result.addPixmap(pix);- };- // 16x16- pixmap(16);- // 24x24- pixmap(24);-- return result;-}--KColorSchemeManager::KColorSchemeManager(QObject *parent)- : QObject(parent)- , d(new KColorSchemeManagerPrivate)-{-}--KColorSchemeManager::~KColorSchemeManager()-{-}--QAbstractItemModel *KColorSchemeManager::model() const-{- return d->model.data();-}--QModelIndex KColorSchemeManager::indexForScheme(const QString &name) const-{- for (int i = 0; i < d->model->rowCount(); ++i) {- QModelIndex index = d->model->index(i);- if (index.data().toString() == name) {- return index;- }- }- return QModelIndex();-}--KActionMenu *KColorSchemeManager::createSchemeSelectionMenu(const QIcon &icon, const QString &name, const QString &selectedSchemeName, QObject *parent)-{- KActionMenu *menu = new KActionMenu(icon, name, parent);- QActionGroup *group = new QActionGroup(menu);- connect(group, &QActionGroup::triggered, [](QAction * action) {- // hint for the style to synchronize the color scheme with the window manager/compositor- qApp->setProperty("KDE_COLOR_SCHEME_PATH", action->data());- qApp->setPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig(action->data().toString())));- });- for (int i = 0; i < d->model->rowCount(); ++i) {- QModelIndex index = d->model->index(i);- QAction *action = new QAction(index.data(Qt::DecorationRole).value<QIcon>(), index.data().toString(), menu);- action->setData(index.data(Qt::UserRole));- action->setActionGroup(group);- action->setCheckable(true);- if (index.data().toString() == selectedSchemeName) {- action->setChecked(true);- }- menu->addAction(action);- }- return menu;-}--KActionMenu *KColorSchemeManager::createSchemeSelectionMenu(const QString &text, const QString &selectedSchemeName, QObject *parent)-{- return createSchemeSelectionMenu(QIcon(), text, selectedSchemeName, parent);-}--KActionMenu *KColorSchemeManager::createSchemeSelectionMenu(const QString &selectedSchemeName, QObject *parent)-{- return createSchemeSelectionMenu(QIcon(), QString(), selectedSchemeName, parent);-}--void KColorSchemeManager::activateScheme(const QModelIndex &index)-{- if (!index.isValid()) {- return;- }- if (index.model() != d->model.data()) {- return;- }- // hint for the style to synchronize the color scheme with the window manager/compositor- qApp->setProperty("KDE_COLOR_SCHEME_PATH", index.data(Qt::UserRole));- qApp->setPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig(index.data(Qt::UserRole).toString())));-}diff --git a/libs/widgetutils/config/kcolorschememanager.h b/libs/widgetutils/config/kcolorschememanager.hdeleted file mode 100644index 88a53dc7ed..0000000000--- a/libs/widgetutils/config/kcolorschememanager.h+++ /dev/null@@ -1,108 +0,0 @@-/* This file is part of the KDE project- * SPDX-FileCopyrightText: 2013 Martin Gräßlin <[email protected]>- *- * SPDX-License-Identifier: LGPL-2.0-or-later- */-#ifndef KCOLORSCHEMEMANAGER_H-#define KCOLORSCHEMEMANAGER_H--#include <kritawidgetutils_export.h>--#include <QObject>--class QAbstractItemModel;--class KActionMenu;-class KColorSchemeManagerPrivate;--/**- * A small helper to get access to all available color schemes and activating a scheme in the- * QApplication. 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.- *- * The KColorSchemeManager provides access to a QAbstractItemModel which holds all the available- * schemes. A possible usage looks like the following:- *- * @code- * KColorSchemeManager *schemes = new KColorSchemeManager(this);- * QListView *view = new QListView(this);- * view->setModel(schemes->model());- * connect(view, &QListView::activated, schemes, &KColorSchemeManager::activateScheme);- * @endcode- *- * In addition the KColorSchemeManager also provides the possibility to create a KActionMenu populated- * with all the available color schemes in an action group. If one of the actions is selected the- * scheme is applied instantly:- *- * @code- * QToolButton *button = new QToolButton();- * KColorSchemeManager *schemes = new KColorSchemeManager(this);- * KActionMenu *menu = schemes->createSchemeSelectionMenu(QStringLiteral("Oxygen"), button);- * button->setMenu(menu->menu());- * @endcode- *- * @since 5.0- */-class KRITAWIDGETUTILS_EXPORT KColorSchemeManager : public QObject-{- Q_OBJECT-public:- explicit KColorSchemeManager(QObject *parent = 0);- ~KColorSchemeManager() override;-- /**- * 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.- *- * @return Model of all available color schemes.- */- QAbstractItemModel *model() const;- /**- * Returns the model index for the scheme with the given @p name. If no such- * scheme exists an invalid index is returned.- * @see model- */- QModelIndex indexForScheme(const QString &name) const;-- /**- * Creates a KActionMenu populated with all the available color schemes.- * All actions are in an action group and when one of the actions is triggered the scheme- * referenced by this action is activated.- *- * The color scheme with the same name as @p selectedSchemeName will be checked. If none- * of the available color schemes has the same name, no action will be checked.- *- * The KActionMenu will not be updated in case the installed color schemes change. It's the- * task of the user of the KActionMenu to monitor for changes if required.- *- * @param icon The icon to use for the KActionMenu- * @param text The text to use for the KActionMenu- * @param selectedSchemeName The name of the color scheme to select- * @param parent The parent of the KActionMenu- * @return KActionMenu populated with all available color schemes.- * @see activateScheme- */- KActionMenu *createSchemeSelectionMenu(const QIcon &icon, const QString &text, const QString &selectedSchemeName, QObject *parent);- KActionMenu *createSchemeSelectionMenu(const QString &text, const QString &selectedSchemeName, QObject *parent);- KActionMenu *createSchemeSelectionMenu(const QString &selectedSchemeName, QObject *parent);--public Q_SLOTS:- /**- * @brief Activates the KColorScheme identified by the provided @p index.- *- * Installs the KColorScheme as the QApplication's QPalette.- *- * @param index The index for the KColorScheme to activate.- * The index must reference the QAbstractItemModel provided by @c model- * @see model- */- void activateScheme(const QModelIndex &index);--private:- QScopedPointer<KColorSchemeManagerPrivate> d;-};--#endifdiff --git a/libs/widgetutils/config/kcolorschememanager_p.h b/libs/widgetutils/config/kcolorschememanager_p.hdeleted file mode 100644index 295f3061ef..0000000000--- a/libs/widgetutils/config/kcolorschememanager_p.h+++ /dev/null@@ -1,41 +0,0 @@-/* This file is part of the KDE project- * SPDX-FileCopyrightText: 2013 Martin Gräßlin <[email protected]>- *- * SPDX-License-Identifier: LGPL-2.0-or-later- */-#ifndef KCOLORSCHEMEMANAGER_P_H-#define KCOLORSCHEMEMANAGER_P_H--#include <QAbstractListModel>-#include <QIcon>--struct KColorSchemeModelData {- QString name;- QString path;- QIcon preview;-};--class KColorSchemeModel : public QAbstractListModel-{- Q_OBJECT-public:- explicit KColorSchemeModel(QObject *parent = 0);- ~KColorSchemeModel() override;- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;- int rowCount(const QModelIndex &parent = QModelIndex()) const override;--private:- void init();- QIcon createPreview(const QString &path);- QVector<KColorSchemeModelData> m_data;-};--class KColorSchemeManagerPrivate-{-public:- KColorSchemeManagerPrivate();-- QScopedPointer<KColorSchemeModel> model;-};--#endif