From e4af787ff6c301c95851aac91796412b1d3ffe35 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Fri, 16 Dec 2022 13:23:23 +0200 Subject: [PATCH] QmlDesigner: Add image info to content library texture tooltip Fixes: QDS-8489 Change-Id: I1afbf91ad12839cc93a46f0a608ab3bda135b76b Reviewed-by: Reviewed-by: Thomas Hartmann --- .../ContentLibraryTexture.qml | 17 +++++++++++++++++ .../contentlibrary/contentlibrarytexture.cpp | 7 ++++++- .../contentlibrary/contentlibrarytexture.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexture.qml b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexture.qml index d6c24d4b2af..494bebd07cc 100644 --- a/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexture.qml +++ b/share/qtcreator/qmldesigner/contentLibraryQmlSource/ContentLibraryTexture.qml @@ -23,6 +23,7 @@ Image { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton + hoverEnabled: true onPressed: (mouse) => { if (mouse.button === Qt.LeftButton) @@ -31,4 +32,20 @@ Image { root.showContextMenu() } } + + ToolTip { + visible: mouseArea.containsMouse + // contentWidth is not calculated correctly by the toolTip (resulting in a wider tooltip than + // needed). Using a helper Text to calculate the correct width + contentWidth: helperText.width + bottomInset: -2 + text: modelData.textureToolTip + delay: 1000 + + Text { + id: helperText + text: modelData.textureToolTip + visible: false + } + } } diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp index 288e04aaff6..84cd0f98362 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.cpp @@ -3,12 +3,17 @@ #include "contentlibrarytexture.h" +#include "imageutils.h" + namespace QmlDesigner { ContentLibraryTexture::ContentLibraryTexture(QObject *parent, const QString &path, const QUrl &icon) : QObject(parent) , m_path(path) - , m_icon(icon) {} + , m_icon(icon) +{ + m_toolTip = QLatin1String("%1\n%2").arg(path.split('/').last(), ImageUtils::imageInfo(path)); +} bool ContentLibraryTexture::filter(const QString &searchText) { diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h index 88d50158325..468dfea09e4 100644 --- a/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h +++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibrarytexture.h @@ -13,6 +13,7 @@ class ContentLibraryTexture : public QObject Q_OBJECT Q_PROPERTY(QString texturePath MEMBER m_path CONSTANT) + Q_PROPERTY(QString textureToolTip MEMBER m_toolTip CONSTANT) Q_PROPERTY(QUrl textureIcon MEMBER m_icon CONSTANT) Q_PROPERTY(bool textureVisible MEMBER m_visible NOTIFY textureVisibleChanged) @@ -29,6 +30,7 @@ signals: private: QString m_path; + QString m_toolTip; QUrl m_icon; bool m_visible = true;