File indexing completed on 2024-05-12 16:28:12
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 QAbstractItemModel *ColorSchemer::model() const 0016 { 0017 return c->model(); 0018 } 0019 0020 void ColorSchemer::apply(int idx) 0021 { 0022 c->activateScheme(c->model()->index(idx, 0)); 0023 } 0024 0025 void ColorSchemer::apply(const QString &name) 0026 { 0027 c->activateScheme(c->indexForScheme(name)); 0028 } 0029 0030 int ColorSchemer::indexForScheme(const QString &name) const 0031 { 0032 auto index = c->indexForScheme(name).row(); 0033 if (index == -1) { 0034 index = 0; 0035 } 0036 return index; 0037 } 0038 0039 QString ColorSchemer::nameForIndex(int index) const 0040 { 0041 return c->model()->data(c->model()->index(index, 0), Qt::DisplayRole).toString(); 0042 }