vcl/qt5/QtMenu.cxx |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

New commits:
commit 3f8c6e73bc23d3295ea97f204745cf1869272c66
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Jun 24 10:27:04 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Jul 8 11:33:26 2022 +0200

    tdf#149680 qt: Open native popup menu at given position
    
    Calculate the position at which to open the popup
    menu from the passed window and rectangle, rather
    than always opening the native popup menu at the
    cursor position.
    
    The commit message in
    
        commit 1e0b16f8695498e4eea7c2208aabf7e7664ce749
        Date:   Wed Feb 12 08:07:42 2020 +0100
    
            tdf#128921 tdf#130341 tdf#122053 qt5: Native PopupMenus
    
    which had implemented native poup menus, already said:
    
    > 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: If1a44b6d53f3dcd6fa7ceec0738219f11cfc22c4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136356
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    (cherry picked from commit ee3976f2c613f9015477ab327996c074e8516f9d)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136707
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit fc5edcf8c02ce81715a3db7c58e9b6d4a9a3b796)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136855
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/vcl/qt5/QtMenu.cxx b/vcl/qt5/QtMenu.cxx
index 9400f5e129bf..0646c9232d5d 100644
--- a/vcl/qt5/QtMenu.cxx
+++ b/vcl/qt5/QtMenu.cxx
@@ -676,15 +676,19 @@ void QtMenu::ShowCloseButton(bool bShow)
         pButton->hide();
 }
 
-bool QtMenu::ShowNativePopupMenu(FloatingWindow*, const tools::Rectangle&,
+bool QtMenu::ShowNativePopupMenu(FloatingWindow* pWin, const tools::Rectangle& 
rRect,
                                  FloatWinPopupFlags nFlags)
 {
     assert(mpQMenu);
     DoFullMenuUpdate(mpVCLMenu);
     mpQMenu->setTearOffEnabled(bool(nFlags & 
FloatWinPopupFlags::AllowTearOff));
 
-    const QPoint aPos = QCursor::pos();
-    mpQMenu->exec(aPos);
+    const VclPtr<vcl::Window> xParent = 
pWin->ImplGetWindowImpl()->mpRealParent;
+    const QtFrame* pFrame = static_cast<QtFrame*>(xParent->ImplGetFrame());
+    assert(pFrame);
+    const tools::Rectangle aFloatRect = 
FloatingWindow::ImplConvertToAbsPos(xParent, rRect);
+    const QRect aRect = toQRect(aFloatRect, 1 / pFrame->devicePixelRatioF());
+    mpQMenu->exec(aRect.topLeft());
 
     return true;
 }

Reply via email to