forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;});
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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 {};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -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;
|
||||
};
|
||||
}
|
||||
}
|
@@ -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());
|
||||
|
@@ -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
|
||||
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user