File indexing completed on 2024-04-21 04:59:19

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