vcl/inc/qt5/QtInstanceButton.hxx | 6 +++--- vcl/qt5/QtInstanceButton.cxx | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-)
New commits: commit a441ba3f8eaff31c9d4ffdfbd0a251cdd838659c Author: Michael Weghorn <[email protected]> AuthorDate: Thu Dec 19 22:05:14 2024 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Fri Dec 20 07:15:01 2024 +0100 tdf#130857 qt weld: Use pointer to QAbstractButton base QtInstanceButton doesn't make use of any QPushButton methods beyond what the QAbstractButton base class already provides. Switch QtInstanceButton::m_pButton from QPushButton to QAbstractButton, which will also allow subclassing QtInstanceButton (for a weld::ToggleButton or weld::MenuButton implementation) and reusing the existing logic with other QAbstractButton subclasses if that turns out to be useful. Change-Id: Ice45b0390f2f37dfb9a96f4e943ab036a294c376 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178847 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/inc/qt5/QtInstanceButton.hxx b/vcl/inc/qt5/QtInstanceButton.hxx index c25342e0bc83..d8a285b61615 100644 --- a/vcl/inc/qt5/QtInstanceButton.hxx +++ b/vcl/inc/qt5/QtInstanceButton.hxx @@ -12,14 +12,14 @@ #include "QtInstanceWidget.hxx" #include <QtCore/QObject> -#include <QtWidgets/QPushButton> +#include <QtWidgets/QAbstractButton> class QtInstanceButton : public QtInstanceWidget, public virtual weld::Button { - QPushButton* m_pButton; + QAbstractButton* m_pButton; public: - QtInstanceButton(QPushButton* pButton); + QtInstanceButton(QAbstractButton* pButton); virtual void set_label(const OUString& rText) override; virtual void set_image(VirtualDevice* pDevice) override; diff --git a/vcl/qt5/QtInstanceButton.cxx b/vcl/qt5/QtInstanceButton.cxx index 1f1e61ca4640..0424062a73c1 100644 --- a/vcl/qt5/QtInstanceButton.cxx +++ b/vcl/qt5/QtInstanceButton.cxx @@ -12,17 +12,17 @@ #include <vcl/qt/QtUtils.hxx> // Name of QObject property to indicate whether a click handler -// was set on the QPushButton: If that property is set and has a value +// was set on the button: If that property is set and has a value // of true, then a custom click handler is set, otherwise not. const char* const PROPERTY_CLICK_HANDLER_SET = "click-handler-set"; -QtInstanceButton::QtInstanceButton(QPushButton* pButton) +QtInstanceButton::QtInstanceButton(QAbstractButton* pButton) : QtInstanceWidget(pButton) , m_pButton(pButton) { assert(m_pButton); - connect(m_pButton, &QPushButton::clicked, this, &QtInstanceButton::buttonClicked); + connect(m_pButton, &QAbstractButton::clicked, this, &QtInstanceButton::buttonClicked); } void QtInstanceButton::set_label(const OUString& rText) commit 4a7247ac6c89f6e163c0086c46706f5226dc3d78 Author: Michael Weghorn <[email protected]> AuthorDate: Thu Dec 19 21:11:53 2024 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Fri Dec 20 07:14:54 2024 +0100 tdf#130857 qt weld: Implement QtInstanceButton::set_image Change-Id: I326ae219732a5cb389368dbc0566e9f27ce9a66d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178846 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/qt5/QtInstanceButton.cxx b/vcl/qt5/QtInstanceButton.cxx index 382d7f2bb853..1f1e61ca4640 100644 --- a/vcl/qt5/QtInstanceButton.cxx +++ b/vcl/qt5/QtInstanceButton.cxx @@ -39,14 +39,19 @@ void QtInstanceButton::set_label(const OUString& rText) m_pButton->setText(toQString(rText)); } -void QtInstanceButton::set_image(VirtualDevice* /*pDevice*/) +void QtInstanceButton::set_image(VirtualDevice* pDevice) { - assert(false && "Not implemented yet"); + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { + if (pDevice) + m_pButton->setIcon(toQPixmap(*pDevice)); + }); } -void QtInstanceButton::set_image(const css::uno::Reference<css::graphic::XGraphic>& /*rImage*/) +void QtInstanceButton::set_image(const css::uno::Reference<css::graphic::XGraphic>& rImage) { - assert(false && "Not implemented yet"); + SolarMutexGuard g; + GetQtInstance().RunInMainThread([&] { m_pButton->setIcon(toQPixmap(rImage)); }); } void QtInstanceButton::set_from_icon_name(const OUString& rIconName)
