diff options
author | Marco Bubke <marco.bubke@qt.io> | 2020-09-16 13:44:43 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2020-10-16 10:01:21 +0000 |
commit | d1b0c12d6b6c4698492851716b3931bc9cae5fd3 (patch) | |
tree | 9aa7d8fddbafced065e392b84939c59d6ae8726e /share/qtcreator | |
parent | 58e612c85fb8320fd99a28d573372220cbfe309a (diff) |
QmlDesigner: Add image cache
The image cache is saving images and icon of this images in a sqlite
database. If there are no images they are generated in the backgound.
The icons are fetched by item library.
Task-number: QDS-2782
Task-number: QDS-2783
Task-number: QDS-2858
Change-Id: I5a32cccfef7f8fd8eb78902605a09f5da18ce88e
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'share/qtcreator')
13 files changed, 215 insertions, 8 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/commands/captureddatacommand.h b/share/qtcreator/qml/qmlpuppet/commands/captureddatacommand.h index 6c3715dd5f..0d3bbba7b7 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/captureddatacommand.h +++ b/share/qtcreator/qml/qmlpuppet/commands/captureddatacommand.h @@ -151,8 +151,19 @@ public: qint32 nodeId = -1; }; + CapturedDataCommand() = default; + + CapturedDataCommand(QVector<StateData> &&stateData) + : stateData{std::move(stateData)} + {} + + CapturedDataCommand(QImage &&image) + : image{std::move(image)} + {} + friend QDataStream &operator<<(QDataStream &out, const CapturedDataCommand &command) { + out << command.image; out << command.stateData; return out; @@ -160,12 +171,14 @@ public: friend QDataStream &operator>>(QDataStream &in, CapturedDataCommand &command) { + in >> command.image; in >> command.stateData; return in; } public: + QImage image; QVector<StateData> stateData; }; diff --git a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h index 841cd8561e..b4ffb74903 100644 --- a/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h +++ b/share/qtcreator/qml/qmlpuppet/interfaces/nodeinstanceserverinterface.h @@ -86,6 +86,7 @@ public: virtual void requestModelNodePreviewImage(const RequestModelNodePreviewImageCommand &command) = 0; virtual void changeLanguage(const ChangeLanguageCommand &command) = 0; virtual void changePreviewImageSize(const ChangePreviewImageSizeCommand &command) = 0; + virtual void dispatchCommand(const QVariant &) {} virtual void benchmark(const QString &) {} diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/instances.pri b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/instances.pri index 85de00c5ff..448a67c913 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/instances.pri +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/instances.pri @@ -9,6 +9,7 @@ HEADERS += $$PWD/qt5nodeinstanceserver.h \ $$PWD/capturenodeinstanceserverdispatcher.h \ $$PWD/capturescenecreatedcommand.h \ $$PWD/nodeinstanceserverdispatcher.h \ + $$PWD/qt5captureimagenodeinstanceserver.h \ $$PWD/qt5capturepreviewnodeinstanceserver.h \ $$PWD/qt5testnodeinstanceserver.h \ $$PWD/qt5informationnodeinstanceserver.h \ @@ -33,11 +34,13 @@ HEADERS += $$PWD/qt5nodeinstanceserver.h \ $$PWD/layoutnodeinstance.h \ $$PWD/qt3dpresentationnodeinstance.h \ $$PWD/quick3dnodeinstance.h \ - $$PWD/quick3dtexturenodeinstance.h + $$PWD/quick3dtexturenodeinstance.h \ + SOURCES += $$PWD/qt5nodeinstanceserver.cpp \ $$PWD/capturenodeinstanceserverdispatcher.cpp \ $$PWD/nodeinstanceserverdispatcher.cpp \ + $$PWD/qt5captureimagenodeinstanceserver.cpp \ $$PWD/qt5capturepreviewnodeinstanceserver.cpp \ $$PWD/qt5testnodeinstanceserver.cpp \ $$PWD/qt5informationnodeinstanceserver.cpp \ diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.cpp index dd9c42c5bd..eb5aae6a7e 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/nodeinstanceserverdispatcher.cpp @@ -25,6 +25,7 @@ #include "nodeinstanceserverdispatcher.h" +#include "qt5captureimagenodeinstanceserver.h" #include "qt5capturepreviewnodeinstanceserver.h" #include "qt5informationnodeinstanceserver.h" #include "qt5rendernodeinstanceserver.h" @@ -183,6 +184,8 @@ std::unique_ptr<NodeInstanceServer> createNodeInstanceServer( { if (serverName == "capturemode") return std::make_unique<Qt5CapturePreviewNodeInstanceServer>(nodeInstanceClient); + else if (serverName == "captureiconmode") + return std::make_unique<Qt5CaptureImageNodeInstanceServer>(nodeInstanceClient); else if (serverName == "rendermode") return std::make_unique<Qt5RenderNodeInstanceServer>(nodeInstanceClient); else if (serverName == "editormode") diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5captureimagenodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5captureimagenodeinstanceserver.cpp new file mode 100644 index 0000000000..d24c4e5552 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5captureimagenodeinstanceserver.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 "qt5captureimagenodeinstanceserver.h" +#include "servernodeinstance.h" + +#include <captureddatacommand.h> +#include <createscenecommand.h> +#include <nodeinstanceclientinterface.h> + +#include <QImage> +#include <QQuickItem> +#include <QQuickView> + +namespace QmlDesigner { + +namespace { + +QImage renderImage(ServerNodeInstance rootNodeInstance) +{ + rootNodeInstance.updateDirtyNodeRecursive(); + + QSize previewImageSize = rootNodeInstance.boundingRect().size().toSize(); + if (previewImageSize.isEmpty()) + previewImageSize = {640, 480}; + + if (previewImageSize.width() > 800 || previewImageSize.height() > 800) + previewImageSize.scale({800, 800}, Qt::KeepAspectRatio); + + QImage previewImage = rootNodeInstance.renderPreviewImage(previewImageSize); + + return previewImage; +} +} // namespace + +void Qt5CaptureImageNodeInstanceServer::collectItemChangesAndSendChangeCommands() +{ + static bool inFunction = false; + + if (!rootNodeInstance().holdsGraphical()) { + nodeInstanceClient()->capturedData(CapturedDataCommand{}); + return; + } + + if (!inFunction) { + inFunction = true; + + auto rooNodeInstance = rootNodeInstance(); + rooNodeInstance.rootQuickItem()->setClip(true); + + DesignerSupport::polishItems(quickView()); + + QImage image = renderImage(rooNodeInstance); + + nodeInstanceClient()->capturedData(CapturedDataCommand{std::move(image)}); + + slowDownRenderTimer(); + inFunction = false; + } +} + +} // namespace diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5captureimagenodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5captureimagenodeinstanceserver.h new file mode 100644 index 0000000000..7c26e47a87 --- /dev/null +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5captureimagenodeinstanceserver.h @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** 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 <qt5previewnodeinstanceserver.h> + +namespace QmlDesigner { + +class Qt5CaptureImageNodeInstanceServer : public Qt5PreviewNodeInstanceServer +{ +public: + explicit Qt5CaptureImageNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) + : Qt5PreviewNodeInstanceServer(nodeInstanceClient) + {} + +protected: + void collectItemChangesAndSendChangeCommands() override; + +private: +}; + +} // namespace QmlDesigner diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5capturepreviewnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5capturepreviewnodeinstanceserver.cpp index c70ef76afe..7fb87defb0 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5capturepreviewnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5capturepreviewnodeinstanceserver.cpp @@ -100,7 +100,7 @@ void Qt5CapturePreviewNodeInstanceServer::collectItemChangesAndSendChangeCommand stateInstance.deactivateState(); } - nodeInstanceClient()->capturedData(CapturedDataCommand{stateDatas}); + nodeInstanceClient()->capturedData(CapturedDataCommand{std::move(stateDatas)}); slowDownRenderTimer(); inFunction = false; diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceclientproxy.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceclientproxy.cpp index 64b6eb409c..93e6e786cd 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceclientproxy.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5nodeinstanceclientproxy.cpp @@ -28,6 +28,7 @@ #include <QCoreApplication> #include "capturenodeinstanceserverdispatcher.h" +#include "qt5captureimagenodeinstanceserver.h" #include "qt5capturepreviewnodeinstanceserver.h" #include "qt5informationnodeinstanceserver.h" #include "qt5previewnodeinstanceserver.h" @@ -92,6 +93,9 @@ Qt5NodeInstanceClientProxy::Qt5NodeInstanceClientProxy(QObject *parent) : } else if (QCoreApplication::arguments().at(2) == QLatin1String("capturemode")) { setNodeInstanceServer(std::make_unique<Qt5CapturePreviewNodeInstanceServer>(this)); initializeSocket(); + } else if (QCoreApplication::arguments().at(2) == QLatin1String("captureiconmode")) { + setNodeInstanceServer(std::make_unique<Qt5CaptureImageNodeInstanceServer>(this)); + initializeSocket(); } } diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp index bfaff0eea8..1f54bffdbd 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp @@ -566,7 +566,7 @@ QRectF QuickItemNodeInstance::boundingRectWithStepChilds(QQuickItem *parentItem) boundingRect = boundingRect.united(QRectF(QPointF(0, 0), size())); - foreach (QQuickItem *childItem, parentItem->childItems()) { + for (QQuickItem *childItem : parentItem->childItems()) { if (!nodeInstanceServer()->hasInstanceForObject(childItem)) { QRectF transformedRect = childItem->mapRectToItem(parentItem, boundingRectWithStepChilds(childItem)); if (isRectangleSane(transformedRect)) @@ -574,6 +574,9 @@ QRectF QuickItemNodeInstance::boundingRectWithStepChilds(QQuickItem *parentItem) } } + if (boundingRect.isEmpty()) + QRectF{0, 0, 640, 480}; + return boundingRect; } diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppetmain.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppetmain.cpp index 98df3de295..1f94bc3e59 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppetmain.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/qml2puppetmain.cpp @@ -42,9 +42,11 @@ #endif #ifdef Q_OS_WIN -#include <windows.h> +#include <Windows.h> #endif +namespace { + int internalMain(QGuiApplication *application) { QCoreApplication::setOrganizationName("QtProject"); @@ -138,6 +140,7 @@ int internalMain(QGuiApplication *application) return application->exec(); } +} // namespace int main(int argc, char *argv[]) { diff --git a/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemDelegate.qml b/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemDelegate.qml index 1cbec5d802..b7bc9b0b58 100644 --- a/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemDelegate.qml +++ b/share/qtcreator/qmldesigner/itemLibraryQmlSources/ItemDelegate.qml @@ -46,8 +46,6 @@ Item { width: itemLibraryIconWidth // to be set in Qml context height: itemLibraryIconHeight // to be set in Qml context source: itemLibraryIconPath // to be set by model - - cache: false // Allow thumbnail to be dynamically updated } Text { @@ -71,10 +69,11 @@ Item { renderType: Text.NativeRendering } - ToolTipArea { + ImagePreviewTooltipArea { id: mouseRegion + anchors.fill: parent - tooltip: itemName + onPressed: { rootView.startDragAndDrop(mouseRegion, itemLibraryEntry) } diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ImagePreviewTooltipArea.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ImagePreviewTooltipArea.qml new file mode 100644 index 0000000000..51194cc3cb --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/ImagePreviewTooltipArea.qml @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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. +** +****************************************************************************/ + +import QtQuick 2.1 +import HelperWidgets 2.0 +import QtQuick.Layouts 1.0 + +MouseArea { + id: mouseArea + + onExited: tooltipBackend.hideTooltip() + onCanceled: tooltipBackend.hideTooltip() + onClicked: forceActiveFocus() + + hoverEnabled: true + + Timer { + interval: 1000 + running: mouseArea.containsMouse + onTriggered: { + tooltipBackend.componentName = itemName + tooltipBackend.componentPath = componentPath + tooltipBackend.showTooltip() + } + } +} diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/qmldir b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/qmldir index 59573217c5..0da6489551 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/qmldir +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/qmldir @@ -47,3 +47,4 @@ ExpressionTextField 2.0 ExpressionTextField.qml MarginSection 2.0 MarginSection.qml HorizontalScrollBar 2.0 HorizontalScrollBar.qml VerticalScrollBar 2.0 VerticalScrollBar.qml +ImagePreviewTooltipArea 2.0 ImagePreviewTooltipArea.qml |