aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Edmundson <[email protected]>2017-01-25 12:03:39 +0000
committerDavid Edmundson <[email protected]>2017-01-25 12:17:22 +0000
commitbac5a39f01a88edd1a1165d3f3d08507742367fe (patch)
tree0648ccc34f6d2d294065b4822bcd951ffdc323d1
parent026277d1f0e383ac759c4f931f3fd04af11002ba (diff)
Add workaround for QMenuBar::setVisible bug in 5.7.0
Summary: QMenuBar::setVisible() only checks isNativeMenuBar on OS X leading to both the normal in-appmenu and the platform menu both being visible - especially as KXmlGui explicitly has a setVisible call. This only affects Qt 5.7.0. For Qt < 5.7.0 we don't have any DBusMenu support. For Qt >= 5.7.1 the problem is fixed. This patch adds a (horrible) event filter on any QMenuBar's and blocks any setVisible calls. Qt 5.7.0 void QMenuBar::setVisible(bool visible) { if (isNativeMenuBar()) { if (!visible) QWidget::setVisible(false); return; } QWidget::setVisible(visible); } Qt 5.7.1 void QMenuBar::setVisible(bool visible) { if (isNativeMenuBar()) { if (!visible) QWidget::setVisible(false); return; } QWidget::setVisible(visible); } BUG: 375498 Test Plan: Ran on a system with Qt 5.7.0 No longer get double menus Reviewers: #plasma Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D4276
-rw-r--r--src/platformtheme/qdbusmenubar.cpp42
-rw-r--r--src/platformtheme/qdbusmenubar_p.h2
2 files changed, 44 insertions, 0 deletions
diff --git a/src/platformtheme/qdbusmenubar.cpp b/src/platformtheme/qdbusmenubar.cpp
index 30a52ee..8c3f324 100644
--- a/src/platformtheme/qdbusmenubar.cpp
+++ b/src/platformtheme/qdbusmenubar.cpp
@@ -39,6 +39,10 @@
#include "qdbusmenubar_p.h"
+#if QT_VERSION == QT_VERSION_CHECK(5,7,0)
+#include <QApplication>
+#include <QMenuBar>
+ #endif
QT_BEGIN_NAMESPACE
@@ -58,6 +62,44 @@ QDBusMenuBar::QDBusMenuBar()
m_menuAdaptor, &QDBusMenuAdaptor::ItemsPropertiesUpdated);
connect(m_menu, &QDBusPlatformMenu::updated,
m_menuAdaptor, &QDBusMenuAdaptor::LayoutUpdated);
+ /*Qt 5.7.0 contains a nasty bug
+ *
+ * QMenuBar::setVisible() only checks isNativeMenuBar on OS X
+ * leading to the menu always being visible.
+ * Initial creation of the menubar does work properly however.
+ *
+ * This patch finds QMenuBars and blocks show events
+ *
+ * This is fixed in 5.7.1
+ */
+
+ #if QT_VERSION == QT_VERSION_CHECK(5,7,0)
+ if (!QApplication::instance()) {
+ return;
+ }
+ //Platform menu bars are created from within QMenuBar therefore we know it exists when
+ //this method is run. By putting it in here, we don't need any invasive event filtering that affects non menubar users
+ for (QWidget *widget: QApplication::allWidgets()) {
+ if (auto menubar = qobject_cast<QMenuBar*>(widget)) {
+ menubar->installEventFilter(this);
+ }
+ }
+ #endif
+}
+
+bool QDBusMenuBar::eventFilter(QObject *watched, QEvent *event) {
+//see ctor
+#if QT_VERSION == QT_VERSION_CHECK(5,7,0)
+ if (event->type() == QEvent::ShowToParent) {
+ if (auto menubar = qobject_cast<QMenuBar*>(watched)) {
+ if (menubar->platformMenuBar() == this) {
+ menubar->hide();
+ }
+ return true;
+ }
+ }
+#endif
+ return QPlatformMenuBar::eventFilter(watched, event);
}
QDBusMenuBar::~QDBusMenuBar()
diff --git a/src/platformtheme/qdbusmenubar_p.h b/src/platformtheme/qdbusmenubar_p.h
index 63c6104..0ac0979 100644
--- a/src/platformtheme/qdbusmenubar_p.h
+++ b/src/platformtheme/qdbusmenubar_p.h
@@ -92,6 +92,8 @@ public:
Q_SIGNALS:
void windowChanged(QWindow *newWindow, QWindow *oldWindow);
+protected:
+ bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
private:
QDBusPlatformMenu *m_menu;
QDBusMenuAdaptor *m_menuAdaptor;