summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-10-28 22:29:25 +0100
committerMichael Weghorn <m.weghorn@posteo.de>2024-10-29 07:46:24 +0100
commitcd2e3087642bb2849a089fb121f7b2c581fe0f00 (patch)
treeac2db449453a0685ce033c7b9b6d6de3262afb07
parent6bf7069f72255518d7abc52d4756cddbffbe6512 (diff)
tdf#130857 qt weld: Set button image set in .ui file
Implement logic to set the image for a button, as specified via the "image" property for the "GtkButton" object in the .ui file. Similar to how VclBuilder::makeObject does it, extract an icon name and load an image using that one for "GtkImage" obejcts. Add another static `toQPixmap` variant that takes an Image parameter and use that one for conversion. For buttons, if the "image" property is set, get the corresponding QLabel object, get the pixmap from that one and set an icon in the button from that. With this in place, when opening the "Help" -> "About LibreOfficeDev" dialog in a WIP branch adding "cui/ui/aboutdialog.ui" to the list of .ui files in QtInstanceBuilder::IsUIFileSupported, the button to copy the version information now shows the corresponding icon when using the qt6 VCL plugin. Change-Id: If87866d7ab935cbc4162fb513074eefda22c981a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175761 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
-rw-r--r--include/vcl/qt/QtUtils.hxx4
-rw-r--r--vcl/inc/qt5/QtBuilder.hxx2
-rw-r--r--vcl/qt5/QtBuilder.cxx27
3 files changed, 29 insertions, 4 deletions
diff --git a/include/vcl/qt/QtUtils.hxx b/include/vcl/qt/QtUtils.hxx
index 95f31e97ce63..368424a8cbe7 100644
--- a/include/vcl/qt/QtUtils.hxx
+++ b/include/vcl/qt/QtUtils.hxx
@@ -42,13 +42,15 @@ inline QPixmap toQPixmap(const BitmapEx& rBitmapEx)
return aPixmap;
}
+inline QPixmap toQPixmap(const Image& rImage) { return toQPixmap(rImage.GetBitmapEx()); }
+
inline QPixmap toQPixmap(const css::uno::Reference<css::graphic::XGraphic>& rImage)
{
if (!rImage.is())
return QPixmap();
Image aImage(rImage);
- return toQPixmap(aImage.GetBitmapEx());
+ return toQPixmap(aImage);
}
inline QPixmap loadQPixmapIcon(const OUString& rIconName)
diff --git a/vcl/inc/qt5/QtBuilder.hxx b/vcl/inc/qt5/QtBuilder.hxx
index ad7569b77a11..ccc199ec4c16 100644
--- a/vcl/inc/qt5/QtBuilder.hxx
+++ b/vcl/inc/qt5/QtBuilder.hxx
@@ -71,7 +71,7 @@ public:
virtual void set_response(std::u16string_view sID, short nResponse) override;
private:
- static void setProperties(QObject* obj, stringmap& rProps);
+ void setProperties(QObject* obj, stringmap& rProps);
static QWidget* windowForObject(QObject* pObject);
static QDialogButtonBox* findButtonBox(QDialog* pDialog);
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index a655e351117b..a25f419a915b 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -187,7 +187,14 @@ QObject* QtBuilder::makeObject(QObject* pParent, std::u16string_view sName, cons
}
else if (sName == u"GtkImage")
{
- pObject = new QLabel(pParentWidget);
+ QLabel* pLabel = new QLabel(pParentWidget);
+ const OUString sIconName = extractIconName(rMap);
+ if (!sIconName.isEmpty())
+ {
+ const Image aImage = loadThemeImage(sIconName);
+ pLabel->setPixmap(toQPixmap(aImage));
+ }
+ pObject = pLabel;
}
else if (sName == u"GtkLabel")
{
@@ -473,8 +480,24 @@ void QtBuilder::setProperties(QObject* pObject, stringmap& rProps)
{
for (auto const & [ rKey, rValue ] : rProps)
{
- if (rKey == u"label")
+ if (rKey == u"image")
+ {
+ QLabel* pImageLabel = get<QLabel>(rValue);
+ assert(pImageLabel && "Button has non-existent image set");
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ pButton->setIcon(QIcon(pImageLabel->pixmap()));
+#else
+ pButton->setIcon(QIcon(pImageLabel->pixmap(Qt::ReturnByValue)));
+#endif
+ // parentless GtkImage in .ui file is only used for setting button
+ // image, so the object is no longer needed after doing so
+ if (!pImageLabel->parent())
+ pImageLabel->deleteLater();
+ }
+ else if (rKey == u"label")
+ {
pButton->setText(convertAccelerator(rValue));
+ }
}
}
}