tdf#130857 qt weld: Extract helper method to set button image

Extract a QtInstanceButton::setImage helper and call it
from all 3 QtInstanceButton::set_image variants to deduplicate
the logic a bit and allow modifying things in one place in
an upcoming commit that will automatically adjust the icon size
as necessary.

Change-Id: I324f8a0f06516c296710d651c42fa5a58ff0053f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205127
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn
2026-05-13 07:22:16 +02:00
parent 22c1323208
commit 355bf1f6fb
2 changed files with 14 additions and 12 deletions
+3
View File
@@ -40,6 +40,9 @@ public:
QAbstractButton& getButton() const;
private:
void setImage(const QPixmap& rPixmap);
private slots:
void buttonClicked();
};
+11 -12
View File
@@ -34,28 +34,27 @@ void QtInstanceButton::set_label(const OUString& rText)
[&] { m_pButton->setText(vclToQtStringWithAccelerator(rText)); });
}
void QtInstanceButton::set_image(VirtualDevice* pDevice)
void QtInstanceButton::setImage(const QPixmap& rPixmap)
{
SolarMutexGuard g;
GetQtInstance().RunInMainThread([&] {
if (pDevice)
m_pButton->setIcon(toQPixmap(*pDevice));
});
GetQtInstance().RunInMainThread([&] { m_pButton->setIcon(rPixmap); });
}
void QtInstanceButton::set_image(VirtualDevice* pDevice)
{
if (pDevice)
setImage(toQPixmap(*pDevice));
}
void QtInstanceButton::set_image(const css::uno::Reference<css::graphic::XGraphic>& rImage)
{
SolarMutexGuard g;
GetQtInstance().RunInMainThread([&] { m_pButton->setIcon(toQPixmap(rImage)); });
setImage(toQPixmap(rImage));
}
void QtInstanceButton::set_from_icon_name(const OUString& rIconName)
{
SolarMutexGuard g;
GetQtInstance().RunInMainThread([&] {
QPixmap aIcon = loadQPixmapIcon(rIconName);
m_pButton->setIcon(aIcon);
});
setImage(loadQPixmapIcon(rIconName));
}
OUString QtInstanceButton::get_label() const