diff --git a/share/qtcreator/qml/qmlpuppet/mockfiles/IconGizmo.qml b/share/qtcreator/qml/qmlpuppet/mockfiles/IconGizmo.qml index b42bf4cc2ce..0d9641fa724 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 9a956c67236..434c5f5c804 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 86bebf19d28..9255e77ddef 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 9a5be562e3c..755aef73e25 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 00000000000..2e5a2b0d0a0 --- /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: : + 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 00000000000..e4833e3b20d --- /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 + +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 4331e35ddc8..798baa61acb 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 #include @@ -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 24a2b90351a..f3548e19edb 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 5ca88541b00..8a264579012 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",