vcl/inc/qt5/QtInstanceMenu.hxx | 11 ++++++++-- vcl/inc/qt5/QtInstanceWidget.hxx | 4 +-- vcl/qt5/QtInstanceMenu.cxx | 42 +++++++++++++++++++++++++++++++++++++-- vcl/qt5/QtInstanceWidget.cxx | 8 +++---- 4 files changed, 55 insertions(+), 10 deletions(-)
New commits: commit 0e55e6a4ee0c1f194787420ad0a56e219ff3d854 Author: Michael Weghorn <[email protected]> AuthorDate: Tue Dec 9 23:38:19 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Wed Dec 10 17:41:50 2025 +0100 tdf#130857 qt weld: Implement logic to show menu item help on F1 Similar to how commit 2ef9880f97de6629ddef12eb788123ab4be1ec83 Author: Michael Weghorn <[email protected]> Date: Sun Jul 30 01:59:31 2023 +0200 tdf#156376 qt: Open help for focused native menu entry on F1 did for e.g. for the main window menu, also implement the logic to open the help for the current weld::Menu entry when F1 is pressed. In QtInstanceMenu::set_item_help_id, set the corresponding property for the menu entry's QAction. Keep track of the current/last active menu item in QtInstanceMenu::m_pCurrentAction, and open the help for that action's help ID if it's non-empty. This will be used e.g. for the following scenario once support for that dialog will be declared: * start Writer * "File" -> "Templates" -> "Manage Templates" * enable the "List View" by clicking on the corresponding button * select an entry and right-click on it to open the context menu * navigate between entries and press F1 while an entry is h highlighted to open the help page specific to the currently highlighted entry (More is missing to be able to eventually declare support for that dialog, but this makes opening the corresponding help page work in a corresponding local WIP branch.) Change-Id: I906a779c33bdf1812ad5fd1590fe45096d53fe70 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195343 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/vcl/inc/qt5/QtInstanceMenu.hxx b/vcl/inc/qt5/QtInstanceMenu.hxx index e861868148dd..e77b188fc56b 100644 --- a/vcl/inc/qt5/QtInstanceMenu.hxx +++ b/vcl/inc/qt5/QtInstanceMenu.hxx @@ -9,16 +9,19 @@ #pragma once -#include <QtWidgets/QMenu> - #include <vcl/weld.hxx> +#include <QtCore/QPointer> +#include <QtWidgets/QMenu> + class QtInstanceMenu : public QObject, public virtual weld::Menu { Q_OBJECT QMenu* m_pMenu; + QPointer<QAction> m_pCurrentAction; + public: QtInstanceMenu(QMenu* pMenu); @@ -55,6 +58,10 @@ private: void insertAction(QAction& rAction, const OUString& rId, int nPos); // get action with the given ID QAction* getAction(const OUString& rIdent) const; + +private Q_SLOTS: + void menuActionHovered(QAction* pAction); + void showHelp(); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/qt5/QtInstanceMenu.cxx b/vcl/qt5/QtInstanceMenu.cxx index 6df66cf2c2bc..c84b84fe0a64 100644 --- a/vcl/qt5/QtInstanceMenu.cxx +++ b/vcl/qt5/QtInstanceMenu.cxx @@ -15,9 +15,16 @@ #include <QtTools.hxx> #include <tools/debug.hxx> +#include <vcl/help.hxx> #include <vcl/svapp.hxx> #include <vcl/qt/QtUtils.hxx> +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include <QtGui/QShortcut> +#else +#include <QtWidgets/QShortcut> +#endif + // Property for storing an action name in a menu item const char* const PROPERTY_ACTION_NAME = "action-name"; @@ -25,6 +32,13 @@ QtInstanceMenu::QtInstanceMenu(QMenu* pMenu) : m_pMenu(pMenu) { assert(m_pMenu); + + // connect slots in order to show help for current entry on F1 + connect(m_pMenu, &QMenu::hovered, this, &QtInstanceMenu::menuActionHovered); + QKeySequence sequence(QKeySequence::HelpContents); + QShortcut* pQShortcut = new QShortcut(sequence, m_pMenu); + connect(pQShortcut, &QShortcut::activated, this, &QtInstanceMenu::showHelp); + connect(pQShortcut, &QShortcut::activatedAmbiguously, this, &QtInstanceMenu::showHelp); } OUString QtInstanceMenu::popup_at_rect(weld::Widget* pParent, const tools::Rectangle& rRect, @@ -158,9 +172,14 @@ void QtInstanceMenu::insert(int nPos, const OUString& rId, const OUString& rStr, }); } -void QtInstanceMenu::set_item_help_id(const OUString&, const OUString&) +void QtInstanceMenu::set_item_help_id(const OUString& rIdent, const OUString& rHelpId) { - assert(false && "Not implemented yet"); + SolarMutexGuard g; + + GetQtInstance().RunInMainThread([&] { + if (QAction* pAction = getAction(rIdent)) + QtInstanceWidget::setHelpId(*pAction, rHelpId); + }); } void QtInstanceMenu::remove(const OUString& rId) @@ -246,4 +265,23 @@ QAction* QtInstanceMenu::getAction(const OUString& rIdent) const return nullptr; } +void QtInstanceMenu::menuActionHovered(QAction* pAction) { m_pCurrentAction = pAction; } + +void QtInstanceMenu::showHelp() +{ + SolarMutexGuard aGuard; + + GetQtInstance().RunInMainThread([&] { + if (!m_pCurrentAction) + return; + + const OUString sHelpId = QtInstanceWidget::getHelpId(*m_pCurrentAction); + if (sHelpId.isEmpty()) + return; + + if (Help* pHelp = Application::GetHelp()) + pHelp->Start(sHelpId); + }); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ commit 4eee8669215e0257d654c7c4653449154cf8315a Author: Michael Weghorn <[email protected]> AuthorDate: Tue Dec 9 21:44:40 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Wed Dec 10 17:41:41 2025 +0100 tdf#130857 qt weld: Switch QWidget to QObject param In order to get or set properties, QObject is sufficient [1]. Therefore, switch param to that type instead of the QWidget subclass. This will allow reusing it for QAction params in QtInstanceMenu. [1] https://doc.qt.io/qt-6/qobject.html#property Change-Id: I599a885fd8c089015f87f092013d84e132a37807 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195342 Reviewed-by: Michael Weghorn <[email protected]> Tested-by: Jenkins diff --git a/vcl/inc/qt5/QtInstanceWidget.hxx b/vcl/inc/qt5/QtInstanceWidget.hxx index ea953358ad3a..4c50be6aabd4 100644 --- a/vcl/inc/qt5/QtInstanceWidget.hxx +++ b/vcl/inc/qt5/QtInstanceWidget.hxx @@ -181,8 +181,8 @@ public: void setFont(vcl::Font rFont); - static OUString getHelpId(QWidget& rWidget); - static void setHelpId(QWidget& rWidget, const OUString& rHelpId); + static OUString getHelpId(QObject& rObject); + static void setHelpId(QObject& rObject, const OUString& rHelpId); protected: virtual bool handleToolTipEvent(const QHelpEvent& rHelpEvent); diff --git a/vcl/qt5/QtInstanceWidget.cxx b/vcl/qt5/QtInstanceWidget.cxx index fa6e4afb8b07..e765272d341e 100644 --- a/vcl/qt5/QtInstanceWidget.cxx +++ b/vcl/qt5/QtInstanceWidget.cxx @@ -350,13 +350,13 @@ void QtInstanceWidget::setFont(vcl::Font rFont) GetQtInstance().RunInMainThread([&] { getQWidget()->setFont(toQtFont(rFont)); }); } -OUString QtInstanceWidget::getHelpId(QWidget& rWidget) +OUString QtInstanceWidget::getHelpId(QObject& rObject) { SolarMutexGuard g; OUString sHelpId; GetQtInstance().RunInMainThread([&] { - const QVariant aHelpIdVariant = rWidget.property(PROPERTY_HELP_ID); + const QVariant aHelpIdVariant = rObject.property(PROPERTY_HELP_ID); if (!aHelpIdVariant.isValid()) return; @@ -367,11 +367,11 @@ OUString QtInstanceWidget::getHelpId(QWidget& rWidget) return sHelpId; } -void QtInstanceWidget::setHelpId(QWidget& rWidget, const OUString& rHelpId) +void QtInstanceWidget::setHelpId(QObject& rObject, const OUString& rHelpId) { SolarMutexGuard g; GetQtInstance().RunInMainThread( - [&] { rWidget.setProperty(PROPERTY_HELP_ID, toQString(rHelpId)); }); + [&] { rObject.setProperty(PROPERTY_HELP_ID, toQString(rHelpId)); }); } void QtInstanceWidget::set_help_id(const OUString& rHelpId) { setHelpId(*getQWidget(), rHelpId); }
