vcl/inc/qt5/QtBuilder.hxx | 2 vcl/inc/qt5/QtInstanceMenu.hxx | 8 ++ vcl/qt5/QtBuilder.cxx | 32 +++++++--- vcl/qt5/QtInstanceMenu.cxx | 131 ++++++++++++++++++++++++++++++++++------- 4 files changed, 143 insertions(+), 30 deletions(-)
New commits: commit 429a6f64506b7256c3939bc2464d6d0edc393f47 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Dec 20 22:06:35 2024 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Dec 21 09:30:11 2024 +0100 tdf#130857 qt weld: Ignore "GtkCellRendererPixbuf" objects VclBuilder also doesn't seem to have any particular handling for that, just like for "GtkCellRendererText", so return early instead of asserting further down that this case isn't handled yet. Change-Id: Idf2a490fb944ac2596f64b96c6e3693fad894935 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178969 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index d56c96168eb6..6cfe11612b00 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -118,7 +118,8 @@ QObject* QtBuilder::makeObject(QObject* pParent, std::u16string_view sName, std: return nullptr; // nothing to do for these - if (sName == u"GtkCellRendererText" || sName == u"GtkTreeSelection") + if (sName == u"GtkCellRendererPixbuf" || sName == u"GtkCellRendererText" + || sName == u"GtkTreeSelection") return nullptr; QWidget* pParentWidget = qobject_cast<QWidget*>(pParent); commit 3d96c29132f06ddcd6292654be233b8d17895e3e Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Dec 20 22:03:45 2024 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Dec 21 09:29:58 2024 +0100 tdf#130857 qt weld: Implement basic menu logic Implement basic logic related to menus: * Creating menus and simple menu items in QtBuilder. * Setting and retrieving misc properties for menu items in QtInstanceMenu. Use the QObject::objectName property [1] to hold the ID for menus and menu items. Introduce a PROPERTY_ACTION_NAME to hold the action name/command name for menu items. This property gets set for the corresponding QAction objects. [1] https://doc.qt.io/qt-6/qobject.html#objectName-prop Change-Id: Ic866377e42202bde6d1f8bd215829ff99a4b682a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178968 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/vcl/inc/qt5/QtBuilder.hxx b/vcl/inc/qt5/QtBuilder.hxx index d962a26c983b..0aefd50cd5ab 100644 --- a/vcl/inc/qt5/QtBuilder.hxx +++ b/vcl/inc/qt5/QtBuilder.hxx @@ -84,7 +84,7 @@ public: virtual bool isHorizontalTabControl(QObject* pObject) override; - virtual QMenu* createMenu(const OUString& rID) override; + virtual QMenu* createMenu(const OUString& rId) override; virtual void insertMenuObject(QMenu* pParent, QMenu* pSubMenu, const OUString& rClass, const OUString& rID, stringmap& rProps, stringmap& rAtkProps, accelmap& rAccels) override; diff --git a/vcl/inc/qt5/QtInstanceMenu.hxx b/vcl/inc/qt5/QtInstanceMenu.hxx index 3133351cf005..a4194a159edd 100644 --- a/vcl/inc/qt5/QtInstanceMenu.hxx +++ b/vcl/inc/qt5/QtInstanceMenu.hxx @@ -47,7 +47,13 @@ public: virtual int n_children() const override; - virtual OUString get_id(int pos) const override; + virtual OUString get_id(int nPos) const override; + + static void setActionName(QAction& rAction, const OUString& rActionName); + +private: + // get action with the given ID + 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/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index b03bd8a9646c..d56c96168eb6 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -12,6 +12,7 @@ #include <QtDoubleSpinBox.hxx> #include <QtExpander.hxx> #include <QtInstanceLinkButton.hxx> +#include <QtInstanceMenu.hxx> #include <QtInstanceMessageDialog.hxx> #include <QtInstanceNotebook.hxx> #include <QtTools.hxx> @@ -568,16 +569,32 @@ bool QtBuilder::isHorizontalTabControl(QObject* pObject) || ePosition == QTabWidget::TabPosition::South; } -QMenu* QtBuilder::createMenu(const OUString&) +QMenu* QtBuilder::createMenu(const OUString& rId) { - assert(false && "Not implemented yet"); - return nullptr; + QMenu* pMenu = new QMenu; + pMenu->setObjectName(toQString(rId)); + return pMenu; } -void QtBuilder::insertMenuObject(QMenu*, QMenu*, const OUString&, const OUString&, stringmap&, - stringmap&, accelmap&) +void QtBuilder::insertMenuObject(QMenu* pParent, QMenu* pSubMenu, const OUString& rClass, + const OUString& rID, stringmap& rProps, stringmap&, accelmap&) { - assert(false && "Not implemented yet"); + assert(!pSubMenu && "Handling not implemented yet"); + (void)pSubMenu; + + if (rClass == "GtkMenuItem") + { + const OUString sLabel = extractLabel(rProps); + QAction* pAction = pParent->addAction(toQString(sLabel)); + pAction->setObjectName(toQString(rID)); + + const OUString sActionName(extractActionName(rProps)); + QtInstanceMenu::setActionName(*pAction, sActionName); + } + else + { + assert(false && "Not implemented yet"); + } } void QtBuilder::applyAtkProperties(QObject* pObject, const stringmap& rProperties, bool) diff --git a/vcl/qt5/QtInstanceMenu.cxx b/vcl/qt5/QtInstanceMenu.cxx index c998342aab1d..1effb5913667 100644 --- a/vcl/qt5/QtInstanceMenu.cxx +++ b/vcl/qt5/QtInstanceMenu.cxx @@ -11,8 +11,13 @@ #include <QtInstanceMenu.moc> #include <QtInstance.hxx> +#include <QtTools.hxx> #include <vcl/svapp.hxx> +#include <vcl/qt/QtUtils.hxx> + +// Property for storing an action name in a menu item +const char* const PROPERTY_ACTION_NAME = "action-name"; QtInstanceMenu::QtInstanceMenu(QMenu* pMenu) : m_pMenu(pMenu) @@ -26,37 +31,84 @@ OUString QtInstanceMenu::popup_at_rect(weld::Widget*, const tools::Rectangle&, w return OUString(); } -void QtInstanceMenu::set_sensitive(const OUString&, bool) +void QtInstanceMenu::set_sensitive(const OUString& rIdent, bool bSensitive) { - assert(false && "Not implemented yet"); + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + if (QAction* pAction = getAction(rIdent)) + pAction->setEnabled(bSensitive); + }); } -bool QtInstanceMenu::get_sensitive(const OUString&) const +bool QtInstanceMenu::get_sensitive(const OUString& rIdent) const { - assert(false && "Not implemented yet"); - return false; + SolarMutexGuard g; + + bool bSensitive = false; + GetQtInstance().RunInMainThread([&] { + if (QAction* pAction = getAction(rIdent)) + bSensitive = pAction->isEnabled(); + }); + + return bSensitive; } -void QtInstanceMenu::set_label(const OUString&, const OUString&) +void QtInstanceMenu::set_label(const OUString& rIdent, const OUString& rLabel) { - assert(false && "Not implemented yet"); + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + if (QAction* pAction = getAction(rIdent)) + pAction->setText(toQString(rLabel)); + }); } -OUString QtInstanceMenu::get_label(const OUString&) const +OUString QtInstanceMenu::get_label(const OUString& rIdent) const { - assert(false && "Not implemented yet"); - return OUString(); + SolarMutexGuard g; + + OUString sLabel; + GetQtInstance().RunInMainThread([&] { + if (QAction* pAction = getAction(rIdent)) + sLabel = toOUString(pAction->text()); + }); + + return sLabel; } -void QtInstanceMenu::set_active(const OUString&, bool) { assert(false && "Not implemented yet"); } +void QtInstanceMenu::set_active(const OUString& rIdent, bool bActive) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + if (QAction* pAction = getAction(rIdent)) + pAction->setChecked(bActive); + }); +} -bool QtInstanceMenu::get_active(const OUString&) const +bool QtInstanceMenu::get_active(const OUString& rIdent) const { - assert(false && "Not implemented yet"); - return false; + SolarMutexGuard g; + + bool bActive = false; + GetQtInstance().RunInMainThread([&] { + if (QAction* pAction = getAction(rIdent)) + bActive = pAction->isChecked(); + }); + + return bActive; } -void QtInstanceMenu::set_visible(const OUString&, bool) { assert(false && "Not implemented yet"); } +void QtInstanceMenu::set_visible(const OUString& rIdent, bool bVisible) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + if (QAction* pAction = getAction(rIdent)) + pAction->setVisible(bVisible); + }); +} void QtInstanceMenu::insert(int, const OUString&, const OUString&, const OUString*, VirtualDevice*, const css::uno::Reference<css::graphic::XGraphic>&, TriState) @@ -69,7 +121,15 @@ void QtInstanceMenu::set_item_help_id(const OUString&, const OUString&) assert(false && "Not implemented yet"); } -void QtInstanceMenu::remove(const OUString&) { assert(false && "Not implemented yet"); } +void QtInstanceMenu::remove(const OUString& rId) +{ + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + if (QAction* pAction = getAction(rId)) + m_pMenu->removeAction(pAction); + }); +} void QtInstanceMenu::clear() { @@ -84,14 +144,43 @@ void QtInstanceMenu::insert_separator(int, const OUString&) int QtInstanceMenu::n_children() const { - assert(false && "Not implemented yet"); - return 0; + SolarMutexGuard g; + + int nChildCount = 0; + GetQtInstance().RunInMainThread([&] { nChildCount = m_pMenu->actions().size(); }); + + return nChildCount; } -OUString QtInstanceMenu::get_id(int) const +OUString QtInstanceMenu::get_id(int nPos) const { - assert(false && "Not implemented yet"); - return OUString(); + SolarMutexGuard g; + + OUString sId; + GetQtInstance().RunInMainThread([&] { + QList<QAction*> aActions = m_pMenu->actions(); + if (nPos < aActions.size()) + sId = toOUString(aActions.at(nPos)->objectName()); + }); + + return sId; +} + +void QtInstanceMenu::setActionName(QAction& rAction, const OUString& rActionName) +{ + rAction.setProperty(PROPERTY_ACTION_NAME, toQString(rActionName)); +} + +QAction* QtInstanceMenu::getAction(const OUString& rIdent) const +{ + QList<QAction*> aActions = m_pMenu->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: */