[Libreoffice-commits] core.git: vcl/inc vcl/qt5

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Wed May 15 21:27:01 UTC 2019


 vcl/inc/qt5/Qt5Menu.hxx |    3 +++
 vcl/qt5/Qt5Menu.cxx     |   23 ++++++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

New commits:
commit a348806baf31b4072f02886d142ac6c3e1bba665
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Mon May 6 17:18:56 2019 +0200
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Wed May 15 23:25:37 2019 +0200

    Qt5 don't unconditionally disconnect close button
    
    Change-Id: Ibfa4d493ed752a03554020c6ab06bfc38745d97d
    Reviewed-on: https://gerrit.libreoffice.org/71871
    Tested-by: Jenkins
    Reviewed-by: Aleksei Nikiforov <darktemplar at basealt.ru>
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/vcl/inc/qt5/Qt5Menu.hxx b/vcl/inc/qt5/Qt5Menu.hxx
index 76d865b263ff..cf60ee2c0bb7 100644
--- a/vcl/inc/qt5/Qt5Menu.hxx
+++ b/vcl/inc/qt5/Qt5Menu.hxx
@@ -18,6 +18,7 @@
 class MenuItemList;
 class QAction;
 class QActionGroup;
+class QPushButton;
 class QMenu;
 class QMenuBar;
 class Qt5MenuItem;
@@ -34,6 +35,8 @@ private:
     bool mbMenuBar;
     QMenuBar* mpQMenuBar;
     QMenu* mpQMenu;
+    QPushButton* mpCloseButton;
+    QMetaObject::Connection maCloseButtonConnection;
 
     void DoFullMenuUpdate(Menu* pMenuBar);
     static void NativeItemText(OUString& rItemText);
diff --git a/vcl/qt5/Qt5Menu.cxx b/vcl/qt5/Qt5Menu.cxx
index 5bfaefa9b931..733b1505b49c 100644
--- a/vcl/qt5/Qt5Menu.cxx
+++ b/vcl/qt5/Qt5Menu.cxx
@@ -30,6 +30,7 @@ Qt5Menu::Qt5Menu(bool bMenuBar)
     , mbMenuBar(bMenuBar)
     , mpQMenuBar(nullptr)
     , mpQMenu(nullptr)
+    , mpCloseButton(nullptr)
 {
 }
 
@@ -411,7 +412,17 @@ void Qt5Menu::SetFrame(const SalFrame* pFrame)
     {
         mpQMenuBar = pMainWindow->menuBar();
         if (mpQMenuBar)
+        {
             mpQMenuBar->clear();
+            QPushButton* pButton
+                = static_cast<QPushButton*>(mpQMenuBar->cornerWidget(Qt::TopRightCorner));
+            if (pButton && ((mpCloseButton != pButton) || !maCloseButtonConnection))
+            {
+                maCloseButtonConnection
+                    = connect(pButton, &QPushButton::clicked, this, &Qt5Menu::slotCloseDocument);
+                mpCloseButton = pButton;
+            }
+        }
 
         mpQMenu = nullptr;
 
@@ -622,19 +633,13 @@ void Qt5Menu::ShowCloseButton(bool bShow)
         pButton->setFlat(true);
         pButton->setToolTip(toQString(VclResId(SV_HELPTEXT_CLOSEDOCUMENT)));
         mpQMenuBar->setCornerWidget(pButton, Qt::TopRightCorner);
+        maCloseButtonConnection
+            = connect(pButton, &QPushButton::clicked, this, &Qt5Menu::slotCloseDocument);
+        mpCloseButton = pButton;
     }
 
     if (bShow)
-    {
-        // The mpQMenuBar is used in multiple Qt5Menu. If one Qt5Menu is deleted, the clicked button
-        // connection is severed. The reconnect could be handled in SetFrame, but ShowCloseButton is
-        // called so seldomly, that I decided to keep the reconnect in this function in one place. As
-        // we don't know the connection state, we unconditionally remove it, so slotCloseDocument
-        // isn't called multiple times on click.
-        pButton->disconnect(SIGNAL(clicked(bool)));
-        connect(pButton, &QPushButton::clicked, this, &Qt5Menu::slotCloseDocument);
         pButton->show();
-    }
     else
         pButton->hide();
 }


More information about the Libreoffice-commits mailing list