File indexing completed on 2024-04-28 04:49:06

0001 /*
0002    SPDX-FileCopyrightText: 2022 (c) Tranter Madi <trmdi@yandex.com>
0003 
0004    SPDX-License-Identifier: LGPL-3.0-or-later
0005  */
0006 
0007 #include "colorschemepreviewimageprovider.h"
0008 
0009 #include <KColorSchemeManager>
0010 
0011 #include <QIcon>
0012 #include <QModelIndex>
0013 
0014 ColorSchemePreviewImageProvider::ColorSchemePreviewImageProvider(KColorSchemeManager *schemes)
0015     : QQuickImageProvider(QQuickImageProvider::Pixmap), mSchemes(schemes)
0016 {
0017 }
0018 
0019 QPixmap ColorSchemePreviewImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
0020 {
0021     if (!mSchemes) {
0022         return QPixmap();
0023     }
0024     QModelIndex index = mSchemes->indexForScheme(id);
0025 
0026     // the id of the default entry must be set to an empty string
0027     if (!index.isValid()) {
0028         index = mSchemes->indexForScheme(QStringLiteral(""));
0029     }
0030     return mSchemes->model()->data(index, Qt::DecorationRole).value<QIcon>().pixmap(requestedSize);
0031 }