File indexing completed on 2024-05-12 05:04:17

0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #include "colorschemer.h"
0005 
0006 #include <KColorSchemeManager>
0007 
0008 ColorSchemer::ColorSchemer(QObject *parent)
0009     : QObject(parent)
0010     , c(new KColorSchemeManager(this))
0011 {
0012 }
0013 
0014 ColorSchemer &ColorSchemer::instance()
0015 {
0016     static ColorSchemer colorSchemer;
0017     return colorSchemer;
0018 }
0019 
0020 QAbstractItemModel *ColorSchemer::model() const
0021 {
0022     return c->model();
0023 }
0024 
0025 void ColorSchemer::apply(int idx)
0026 {
0027     c->activateScheme(c->model()->index(idx, 0));
0028 }
0029 
0030 void ColorSchemer::apply(const QString &name)
0031 {
0032     c->activateScheme(c->indexForScheme(name));
0033 }
0034 
0035 int ColorSchemer::indexForScheme(const QString &name) const
0036 {
0037     auto index = c->indexForScheme(name).row();
0038     if (index == -1) {
0039         index = 0;
0040     }
0041     return index;
0042 }
0043 
0044 QString ColorSchemer::nameForIndex(int index) const
0045 {
0046     return c->model()->data(c->model()->index(index, 0), Qt::DisplayRole).toString();
0047 }
0048 
0049 #include "moc_colorschemer.cpp"