QmlDesigner: Add image info to content library texture tooltip

Fixes: QDS-8489
Change-Id: I1afbf91ad12839cc93a46f0a608ab3bda135b76b
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2022-12-16 13:23:23 +02:00
parent 4a5359cb86
commit e4af787ff6
3 changed files with 25 additions and 1 deletions

View File

@@ -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
}
}
}

View File

@@ -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)
{

View File

@@ -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;