File indexing completed on 2025-04-27 04:08:14
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2012 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "ColorImageProvider.h" 0008 0009 ColorImageProvider::ColorImageProvider() 0010 : QQuickImageProvider(QQuickImageProvider::Pixmap) 0011 { 0012 } 0013 0014 QPixmap ColorImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) 0015 { 0016 int width = 100; 0017 int height = 50; 0018 0019 if ( size ) 0020 *size = QSize(width, height); 0021 QPixmap pixmap(requestedSize.width() > 0 ? requestedSize.width() : width, 0022 requestedSize.height() > 0 ? requestedSize.height() : height); 0023 if (QColor::isValidColor(id)) 0024 { 0025 pixmap.fill(QColor(id).rgba()); 0026 } 0027 else 0028 { 0029 QList<QString> elements = id.split(","); 0030 if (elements.count() == 4) 0031 pixmap.fill(QColor::fromRgbF(elements.at(0).toFloat(), elements.at(1).toFloat(), elements.at(2).toFloat(), elements.at(3).toFloat())); 0032 if (elements.count() == 3) 0033 pixmap.fill(QColor::fromRgbF(elements.at(0).toFloat(), elements.at(1).toFloat(), elements.at(2).toFloat())); 0034 } 0035 return pixmap; 0036 }