From 4c715a9c74bd871dfdea203238e6b7b72a3a736c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 18 Jan 2016 13:17:12 +0100 Subject: QQuickUniversalImageProvider -> QQuickColorImageProvider Share the same implementation with the upcoming iOS style. Change-Id: I495296832ba57a7c067eb9070ebc5b513d5e0d18 Reviewed-by: Mitch Curtis --- src/controls/controls.pri | 2 + src/controls/qquickcolorimageprovider.cpp | 80 +++++++++++++++++++++++++++++++ src/controls/qquickcolorimageprovider_p.h | 68 ++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 src/controls/qquickcolorimageprovider.cpp create mode 100644 src/controls/qquickcolorimageprovider_p.h (limited to 'src/controls') diff --git a/src/controls/controls.pri b/src/controls/controls.pri index 005ee839..7aa9447f 100644 --- a/src/controls/controls.pri +++ b/src/controls/controls.pri @@ -1,4 +1,5 @@ HEADERS += \ + $$PWD/qquickcolorimageprovider_p.h \ $$PWD/qquickproxytheme_p.h \ $$PWD/qquickstyle_p.h \ $$PWD/qquickstyleselector_p.h \ @@ -6,6 +7,7 @@ HEADERS += \ $$PWD/qquickpaddedrectangle_p.h SOURCES += \ + $$PWD/qquickcolorimageprovider.cpp \ $$PWD/qquickproxytheme.cpp \ $$PWD/qquickstyle.cpp \ $$PWD/qquickstyleselector.cpp \ diff --git a/src/controls/qquickcolorimageprovider.cpp b/src/controls/qquickcolorimageprovider.cpp new file mode 100644 index 00000000..582b73ed --- /dev/null +++ b/src/controls/qquickcolorimageprovider.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickcolorimageprovider_p.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QQuickColorImageProvider::QQuickColorImageProvider(const QString &path) + : QQuickImageProvider(Image), m_path(path) +{ +} + +QImage QQuickColorImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) +{ + Q_UNUSED(requestedSize); + + int sep = id.indexOf(QLatin1Char('/')); + QString name = id.left(sep); + QString color = id.mid(sep + 1); + qreal dpr = qApp->primaryScreen()->devicePixelRatio(); + QString file = qt_findAtNxFile(m_path + QLatin1Char('/') + name + QStringLiteral(".png"), dpr); + + QImage image(file); + if (image.isNull()) { + qWarning() << "QQuickColorImageProvider: unknown id:" << id; + return QImage(); + } + + if (size) + *size = image.size(); + + if (!color.isEmpty()) { + QPainter painter(&image); + painter.setCompositionMode(QPainter::CompositionMode_SourceIn); + painter.fillRect(image.rect(), QColor(color)); + } + + return image; +} + +QT_END_NAMESPACE diff --git a/src/controls/qquickcolorimageprovider_p.h b/src/controls/qquickcolorimageprovider_p.h new file mode 100644 index 00000000..2d2d3094 --- /dev/null +++ b/src/controls/qquickcolorimageprovider_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKCOLORIMAGEPROVIDER_P_H +#define QQUICKCOLORIMAGEPROVIDER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +QT_BEGIN_NAMESPACE + +class QQuickColorImageProvider : public QQuickImageProvider +{ +public: + QQuickColorImageProvider(const QString &path); + + QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) Q_DECL_OVERRIDE; + +private: + QString m_path; +}; + +QT_END_NAMESPACE + +#endif // QQUICKOCOLORIMAGEPROVIDER_P_H -- cgit v1.2.3