summaryrefslogtreecommitdiff
path: root/vcl/qt5
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2020-02-12 08:07:42 +0100
committerAdolfo Jayme Barrientos <fitojb@ubuntu.com>2020-02-19 11:56:11 +0100
commitceb2f69e0ef2381ce6ed8c65ea45e72aa86cda56 (patch)
tree415745be41ca0a33e5df2fa5756f026c3e675161 /vcl/qt5
parentfc464ae2441a17f465682420d969ae59d24eacc0 (diff)
tdf#128921 tdf#130341 tdf#122053 qt5: Native PopupMenus
This implements native PopupMenus for the qt5 VCL plugin, which not only gives them the native look and feel, but also makes context menus faster (tdf#128921), accessible (e.g. to the Orca screen reader, tdf#122053), and makes them work for a case in Base's relationship dialog where entries in the non-native context menu were not selectable/clickable (tdf#130341). For now, this always shows the popup menu at cursor position, which can be changed by taking the Rectangle passed to 'Qt5Menu::ShowNativePopupMenu' into account if there should be any need. Change-Id: Ie52cbc682acacb92716ff51e8bf7f1ab07d34cf0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88512 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> (cherry picked from commit 1e0b16f8695498e4eea7c2208aabf7e7664ce749) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88491 Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Diffstat (limited to 'vcl/qt5')
-rw-r--r--vcl/qt5/Qt5Menu.cxx34
1 files changed, 32 insertions, 2 deletions
diff --git a/vcl/qt5/Qt5Menu.cxx b/vcl/qt5/Qt5Menu.cxx
index dd5c9895273e..2a3147fa14b8 100644
--- a/vcl/qt5/Qt5Menu.cxx
+++ b/vcl/qt5/Qt5Menu.cxx
@@ -23,6 +23,9 @@
#include <strings.hrc>
#include <bitmaps.hlst>
+#include <vcl/floatwin.hxx>
+#include <window.h>
+
Qt5Menu::Qt5Menu(bool bMenuBar)
: mpVCLMenu(nullptr)
, mpParentSalMenu(nullptr)
@@ -76,8 +79,15 @@ void Qt5Menu::InsertMenuItem(Qt5MenuItem* pSalMenuItem, unsigned nPos)
[pSalMenuItem] { slotMenuAboutToHide(pSalMenuItem); });
}
}
- else if (mpQMenu)
+ else
{
+ if (!mpQMenu)
+ {
+ // no QMenu set, instantiate own one
+ mpOwnedQMenu.reset(new QMenu);
+ mpQMenu = mpOwnedQMenu.get();
+ }
+
if (pSalMenuItem->mpSubMenu)
{
// submenu
@@ -147,7 +157,9 @@ void Qt5Menu::InsertMenuItem(Qt5MenuItem* pSalMenuItem, unsigned nPos)
UpdateActionGroupItem(pSalMenuItem);
- pAction->setShortcut(toQString(nAccelKey.GetName(GetFrame()->GetWindow())));
+ const Qt5Frame* pFrame = GetFrame();
+ if (pFrame)
+ pAction->setShortcut(toQString(nAccelKey.GetName(pFrame->GetWindow())));
connect(pAction, &QAction::triggered, this,
[pSalMenuItem] { slotMenuTriggered(pSalMenuItem); });
@@ -441,6 +453,11 @@ void Qt5Menu::DoFullMenuUpdate(Menu* pMenuBar)
Qt5MenuItem* pSalMenuItem = GetItemAtPos(nItem);
InsertMenuItem(pSalMenuItem, nItem);
SetItemImage(nItem, pSalMenuItem, pSalMenuItem->maImage);
+ const bool bShowDisabled
+ = bool(pMenuBar->GetMenuFlags() & MenuFlags::AlwaysShowDisabledEntries)
+ || !bool(pMenuBar->GetMenuFlags() & MenuFlags::HideDisabledEntries);
+ const bool bVisible = bShowDisabled || mpVCLMenu->IsItemEnabled(pSalMenuItem->mnId);
+ pSalMenuItem->getAction()->setVisible(bVisible);
if (pSalMenuItem->mpSubMenu != nullptr)
{
@@ -650,6 +667,19 @@ void Qt5Menu::ShowCloseButton(bool bShow)
pButton->hide();
}
+bool Qt5Menu::ShowNativePopupMenu(FloatingWindow*, const tools::Rectangle&,
+ FloatWinPopupFlags nFlags)
+{
+ assert(mpQMenu);
+ DoFullMenuUpdate(mpVCLMenu);
+ mpQMenu->setTearOffEnabled(bool(nFlags & FloatWinPopupFlags::AllowTearOff));
+
+ const QPoint aPos = QCursor::pos();
+ mpQMenu->exec(aPos);
+
+ return true;
+}
+
Qt5MenuItem::Qt5MenuItem(const SalItemParams* pItemData)
: mpParentMenu(nullptr)
, mpSubMenu(nullptr)