summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-12-21 00:17:05 +0100
committerMichael Weghorn <m.weghorn@posteo.de>2024-12-21 09:31:30 +0100
commit78872b270dfca6cfa25e3e08a5539362f60f1174 (patch)
tree7f92b27fc5e99d3f8efbc6e3a70a1e4e560fc54c
parent0f3cf3091666ef393e189b539aa9a808e168df81 (diff)
tdf#130857 qt weld: Implement most QtInstanceMenuButton methods
The QToolButton::menu methods to retrieve the menu doesn't exist in the QAbstractButton base class, so let QtInstanceMenuButton take a QToolButton pointer. Implement the menu item related methods in line with the corresponding QtInstanceMenu methods. Change-Id: I4d97f528fe112ba3b94069ce0173a5b63a415ffe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178973 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Tested-by: Jenkins
-rw-r--r--vcl/inc/qt5/QtInstanceMenuButton.hxx10
-rw-r--r--vcl/qt5/QtInstanceBuilder.cxx2
-rw-r--r--vcl/qt5/QtInstanceMenuButton.cxx96
3 files changed, 91 insertions, 17 deletions
diff --git a/vcl/inc/qt5/QtInstanceMenuButton.hxx b/vcl/inc/qt5/QtInstanceMenuButton.hxx
index 097811945392..1388bf29f688 100644
--- a/vcl/inc/qt5/QtInstanceMenuButton.hxx
+++ b/vcl/inc/qt5/QtInstanceMenuButton.hxx
@@ -11,12 +11,16 @@
#include "QtInstanceToggleButton.hxx"
+#include <QtWidgets/QToolButton>
+
class QtInstanceMenuButton : public QtInstanceToggleButton, public virtual weld::MenuButton
{
Q_OBJECT
+ QToolButton* m_pToolButton;
+
public:
- QtInstanceMenuButton(QAbstractButton* pButton);
+ QtInstanceMenuButton(QToolButton* pButton);
virtual void insert_item(int pos, const OUString& rId, const OUString& rStr,
const OUString* pIconName, VirtualDevice* pImageSurface,
@@ -32,6 +36,10 @@ public:
virtual void set_item_visible(const OUString& rIdent, bool bVisible) override;
virtual void set_popover(weld::Widget* pPopover) override;
+
+private:
+ QMenu& getMenu() const;
+ QAction* getAction(const OUString& rIdent) const;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index 899acaa7e75d..fffe30e94d04 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -208,7 +208,7 @@ std::unique_ptr<weld::Button> QtInstanceBuilder::weld_button(const OUString& rId
std::unique_ptr<weld::MenuButton> QtInstanceBuilder::weld_menu_button(const OUString& rId)
{
- QAbstractButton* pButton = m_xBuilder->get<QAbstractButton>(rId);
+ QToolButton* pButton = m_xBuilder->get<QToolButton>(rId);
std::unique_ptr<weld::MenuButton> xRet(pButton ? std::make_unique<QtInstanceMenuButton>(pButton)
: nullptr);
return xRet;
diff --git a/vcl/qt5/QtInstanceMenuButton.cxx b/vcl/qt5/QtInstanceMenuButton.cxx
index cde0312183e3..8223e65b80ca 100644
--- a/vcl/qt5/QtInstanceMenuButton.cxx
+++ b/vcl/qt5/QtInstanceMenuButton.cxx
@@ -10,10 +10,17 @@
#include <QtInstanceMenuButton.hxx>
#include <QtInstanceMenuButton.moc>
-QtInstanceMenuButton::QtInstanceMenuButton(QAbstractButton* pButton)
+#include <QtTools.hxx>
+
+#include <vcl/qt/QtUtils.hxx>
+
+#include <QtWidgets/QMenu>
+
+QtInstanceMenuButton::QtInstanceMenuButton(QToolButton* pButton)
: QtInstanceToggleButton(pButton)
+ , m_pToolButton(pButton)
{
- assert(pButton);
+ assert(m_pToolButton);
}
void QtInstanceMenuButton::insert_item(int, const OUString&, const OUString&, const OUString*,
@@ -27,36 +34,95 @@ void QtInstanceMenuButton::insert_separator(int, const OUString&)
assert(false && "Not implemented yet");
}
-void QtInstanceMenuButton::remove_item(const OUString&) { assert(false && "Not implemented yet"); }
+void QtInstanceMenuButton::remove_item(const OUString& rId)
+{
+ SolarMutexGuard g;
-void QtInstanceMenuButton::clear() { assert(false && "Not implemented yet"); }
+ GetQtInstance().RunInMainThread([&] {
+ if (QAction* pAction = getAction(rId))
+ getMenu().removeAction(pAction);
+ });
+}
-void QtInstanceMenuButton::set_item_sensitive(const OUString&, bool)
+void QtInstanceMenuButton::clear()
{
- assert(false && "Not implemented yet");
+ SolarMutexGuard g;
+
+ GetQtInstance().RunInMainThread([&] { getMenu().clear(); });
}
-void QtInstanceMenuButton::set_item_active(const OUString&, bool)
+void QtInstanceMenuButton::set_item_sensitive(const OUString& rIdent, bool bSensitive)
{
- assert(false && "Not implemented yet");
+ SolarMutexGuard g;
+
+ GetQtInstance().RunInMainThread([&] {
+ if (QAction* pAction = getAction(rIdent))
+ pAction->setEnabled(bSensitive);
+ });
}
-void QtInstanceMenuButton::set_item_label(const OUString&, const OUString&)
+void QtInstanceMenuButton::set_item_active(const OUString& rIdent, bool bActive)
{
- assert(false && "Not implemented yet");
+ SolarMutexGuard g;
+
+ GetQtInstance().RunInMainThread([&] {
+ if (QAction* pAction = getAction(rIdent))
+ pAction->setChecked(bActive);
+ });
}
-OUString QtInstanceMenuButton::get_item_label(const OUString&) const
+void QtInstanceMenuButton::set_item_label(const OUString& rIdent, const OUString& rLabel)
{
- assert(false && "Not implemented yet");
- return OUString();
+ SolarMutexGuard g;
+
+ GetQtInstance().RunInMainThread([&] {
+ if (QAction* pAction = getAction(rIdent))
+ pAction->setText(toQString(rLabel));
+ });
}
-void QtInstanceMenuButton::set_item_visible(const OUString&, bool)
+OUString QtInstanceMenuButton::get_item_label(const OUString& rIdent) const
{
- assert(false && "Not implemented yet");
+ SolarMutexGuard g;
+
+ OUString sLabel;
+ GetQtInstance().RunInMainThread([&] {
+ if (QAction* pAction = getAction(rIdent))
+ sLabel = toOUString(pAction->text());
+ });
+
+ return sLabel;
+}
+
+void QtInstanceMenuButton::set_item_visible(const OUString& rIdent, bool bVisible)
+{
+ SolarMutexGuard g;
+
+ GetQtInstance().RunInMainThread([&] {
+ if (QAction* pAction = getAction(rIdent))
+ pAction->setVisible(bVisible);
+ });
}
void QtInstanceMenuButton::set_popover(weld::Widget*) { assert(false && "Not implemented yet"); }
+QMenu& QtInstanceMenuButton::getMenu() const
+{
+ QMenu* pMenu = m_pToolButton->menu();
+ assert(pMenu);
+ return *pMenu;
+}
+
+QAction* QtInstanceMenuButton::getAction(const OUString& rIdent) const
+{
+ QList<QAction*> aActions = getMenu().actions();
+ for (QAction* pAction : aActions)
+ {
+ if (pAction && pAction->objectName() == toQString(rIdent))
+ return pAction;
+ }
+
+ return nullptr;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */