diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2020-03-30 16:37:42 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2020-03-31 07:39:16 +0000 |
commit | e0751d56d0994617a58a9e4ec903e76b36cd4f20 (patch) | |
tree | 40e0aeeab11735d0a08eda7e77f8a4e55e140bfb | |
parent | 704d0eb8827b9f458fed8b9ddb98373965245b61 (diff) | |
download | qt-creator-e0751d56d0994617a58a9e4ec903e76b36cd4f20.tar.gz |
QmlDesigner: Colorize light gizmos
Light gizmo icons and models are now colored based on the light color.
Image provider is used instead of simpler ColorOverlay component,
as ColorOverlay doesn't properly handle transparency when rendered
offscreen in puppet.
Change-Id: If6af915bca9bea2cb48ac23ac6c5ba46dc150e3b
Fixes: QDS-1733
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
9 files changed, 135 insertions, 22 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/IconGizmo.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/IconGizmo.qml index b42bf4cc2c..0d9641fa72 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/IconGizmo.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/IconGizmo.qml @@ -25,7 +25,6 @@ import QtQuick 2.0 import QtQuick3D 1.15 -import QtGraphicalEffects 1.12 Item { id: iconGizmo @@ -45,7 +44,6 @@ Item { } property alias iconSource: iconImage.source - //property alias overlayColor: colorOverlay.color signal positionCommit() signal clicked(Node node, bool multi) @@ -91,15 +89,6 @@ Item { acceptedButtons: Qt.LeftButton } } -// ColorOverlay doesn't work correctly with hidden windows so commenting it out for now -// ColorOverlay { -// id: colorOverlay -// anchors.fill: parent -// cached: true -// source: iconImage -// color: "#00000000" -// opacity: 0.6 -// } } } } diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/LightGizmo.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/LightGizmo.qml index 9a956c6723..434c5f5c80 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/LightGizmo.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/LightGizmo.qml @@ -30,19 +30,17 @@ IconGizmo { id: lightGizmo property Model lightModel: null + property color overlayColor: targetNode ? targetNode.color : "transparent" iconSource: targetNode ? targetNode instanceof DirectionalLight - ? "qrc:///qtquickplugin/mockfiles/images/directional_light_gradient.png" + ? "image://IconGizmoImageProvider/directional_light_gradient.png:" + overlayColor : targetNode instanceof AreaLight - ? "qrc:///qtquickplugin/mockfiles/images/area_light_gradient.png" + ? "image://IconGizmoImageProvider/area_light_gradient.png:" + overlayColor : targetNode instanceof PointLight - ? "qrc:///qtquickplugin/mockfiles/images/point_light_gradient.png" - : "qrc:///qtquickplugin/mockfiles/images/spot_light_gradient.png" - : "qrc:///qtquickplugin/mockfiles/images/point_light_gradient.png" - - // ColorOverlay doesn't work correctly with hidden windows so commenting it out for now - //overlayColor: targetNode ? targetNode.color : "transparent" + ? "image://IconGizmoImageProvider/point_light_gradient.png:" + overlayColor + : "image://IconGizmoImageProvider/spot_light_gradient.png:" + overlayColor + : "image://IconGizmoImageProvider/point_light_gradient.png:" + overlayColor function connectModel(model) { @@ -57,6 +55,9 @@ IconGizmo { model.targetNode = targetNode; model.targetNode = Qt.binding(function() {return targetNode;}); + model.color = lightGizmo.overlayColor; + model.color = Qt.binding(function() {return lightGizmo.overlayColor;}); + model.visible = visible; model.visible = Qt.binding(function() {return visible;}); } diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/LightModel.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/LightModel.qml index 86bebf19d2..9255e77dde 100644 --- a/share/qtcreator/qml/qmlpuppet/mockfiles/LightModel.qml +++ b/share/qtcreator/qml/qmlpuppet/mockfiles/LightModel.qml @@ -35,6 +35,7 @@ Model { property Node targetNode: null property Node scene: null property bool selected: false + property color color function updateGeometry() { @@ -49,7 +50,7 @@ Model { materials: [ DefaultMaterial { id: defaultMaterial - emissiveColor: lightModel.selected ? "#FF0000" : "#555555" + emissiveColor: lightModel.selected ? lightModel.color : "#555555" lighting: DefaultMaterial.NoLighting cullMode: Material.NoCulling } diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri index 9a5be562e3..755aef73e2 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/editor3d.pri @@ -4,7 +4,8 @@ HEADERS += $$PWD/generalhelper.h \ $$PWD/lightgeometry.h \ $$PWD/gridgeometry.h \ $$PWD/selectionboxgeometry.h \ - $$PWD/linegeometry.h + $$PWD/linegeometry.h \ + $$PWD/icongizmoimageprovider.h SOURCES += $$PWD/generalhelper.cpp \ $$PWD/mousearea3d.cpp \ @@ -12,4 +13,5 @@ SOURCES += $$PWD/generalhelper.cpp \ $$PWD/lightgeometry.cpp \ $$PWD/gridgeometry.cpp \ $$PWD/selectionboxgeometry.cpp \ - $$PWD/linegeometry.cpp + $$PWD/linegeometry.cpp \ + $$PWD/icongizmoimageprovider.cpp diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/icongizmoimageprovider.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/icongizmoimageprovider.cpp new file mode 100644 index 0000000000..2e5a2b0d0a --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/icongizmoimageprovider.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "icongizmoimageprovider.h" + +namespace QmlDesigner { +namespace Internal { + +IconGizmoImageProvider::IconGizmoImageProvider() + : QQuickImageProvider(QQuickImageProvider::Image) +{ +} + +QImage IconGizmoImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) +{ + // id format: <file name>:<color name> + QStringList parts = id.split(':'); + if (parts.size() == 2) { + QImage image(QStringLiteral("://qtquickplugin/mockfiles/images/%1").arg(parts[0])); + + // Recolorize non-transparent image pixels + QColor targetColor(parts[1]); + int r = targetColor.red(); + int g = targetColor.green(); + int b = targetColor.blue(); + int size = image.sizeInBytes(); + uchar *byte = image.bits(); + for (int i = 0; i < size; i += 4) { + // Skip if alpha is zero + if (*(byte + 3) != 0) { + // Average between target color and current color + *byte = uchar((int(*byte) + b) / 2); + ++byte; + *byte = uchar((int(*byte) + g) / 2); + ++byte; + *byte = uchar((int(*byte) + r) / 2); + ++byte; + // Preserve alpha + ++byte; + } else { + byte += 4; + } + } + return image; + } else { + return {}; + } +} + +} +} diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/icongizmoimageprovider.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/icongizmoimageprovider.h new file mode 100644 index 0000000000..e4833e3b20 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/editor3d/icongizmoimageprovider.h @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include <QtQuick/qquickimageprovider.h> + +namespace QmlDesigner { +namespace Internal { + +class IconGizmoImageProvider : public QQuickImageProvider +{ +public: + IconGizmoImageProvider(); + + QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override; +}; +} +} diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index 4331e35ddc..798baa61ac 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -71,6 +71,7 @@ #include "../editor3d/gridgeometry.h" #include "../editor3d/selectionboxgeometry.h" #include "../editor3d/linegeometry.h" +#include "../editor3d/icongizmoimageprovider.h" #include <designersupportdelegate.h> #include <qmlprivategate.h> @@ -114,6 +115,8 @@ void Qt5InformationNodeInstanceServer::createEditView3D() QObject::connect(helper, &QmlDesigner::Internal::GeneralHelper::toolStateChanged, this, &Qt5InformationNodeInstanceServer::handleToolStateChanged); engine()->rootContext()->setContextProperty("_generalHelper", helper); + engine()->addImageProvider(QLatin1String("IconGizmoImageProvider"), + new QmlDesigner::Internal::IconGizmoImageProvider); m_3dHelper = helper; m_editView3D = new QQuickView(quickView()->engine(), quickView()); diff --git a/src/tools/qml2puppet/CMakeLists.txt b/src/tools/qml2puppet/CMakeLists.txt index 24a2b90351..f3548e19ed 100644 --- a/src/tools/qml2puppet/CMakeLists.txt +++ b/src/tools/qml2puppet/CMakeLists.txt @@ -118,6 +118,7 @@ extend_qtc_executable(qml2puppet gridgeometry.cpp gridgeometry.h selectionboxgeometry.cpp selectionboxgeometry.h linegeometry.cpp linegeometry.h + icongizmoimageprovider.cpp icongizmoimageprovider.h ) extend_qtc_executable(qml2puppet diff --git a/src/tools/qml2puppet/qml2puppet.qbs b/src/tools/qml2puppet/qml2puppet.qbs index 5ca88541b0..8a26457901 100644 --- a/src/tools/qml2puppet/qml2puppet.qbs +++ b/src/tools/qml2puppet/qml2puppet.qbs @@ -217,6 +217,8 @@ QtcTool { "editor3d/selectionboxgeometry.h", "editor3d/linegeometry.cpp", "editor3d/linegeometry.h", + "editor3d/icongizmoimageprovider.cpp", + "editor3d/icongizmoimageprovider.h", "iconrenderer/iconrenderer.cpp", "iconrenderer/iconrenderer.h", "qml2puppetmain.cpp", |