Skip to content

Commit

Permalink
QMenuBar: Get rid of QMenuBarPrivate::nativeMenuBar
Browse files Browse the repository at this point in the history
Instead of trying to keep that variable in sync with platformMenuBar
state, just check whether platformMenuBar exists instead.

Now QMenuBar::isNativeMenuBar() is more reliable, and will not return
true if the QPA plugin provides no platform menu bar.

Also, remove useless restrictions for code using isNativeMenuBar().
That method is available on all platforms for a long time, not only on
macOS or WinCE.

This makes sure local menus do not appear if global menus are available,
and setVisible(true) is called.

Change-Id: I7a5944c64376b4714a38ad981089df8a151c3403
Task-number: QTBUG-54793
Reviewed-by: J-P Nurmi <[email protected]>
Reviewed-by: Shawn Rutledge <[email protected]>
  • Loading branch information
mitya57 authored and ec1oud committed Sep 15, 2016
1 parent f4eefce commit 835d7cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
28 changes: 4 additions & 24 deletions src/widgets/widgets/qmenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,13 +1010,11 @@ void QMenuBar::paintEvent(QPaintEvent *e)
*/
void QMenuBar::setVisible(bool visible)
{
#if defined(Q_OS_MAC) || defined(Q_OS_WINCE)
if (isNativeMenuBar()) {
if (!visible)
QWidget::setVisible(false);
return;
}
#endif
QWidget::setVisible(visible);
}

Expand Down Expand Up @@ -1559,11 +1557,7 @@ QRect QMenuBar::actionGeometry(QAction *act) const
QSize QMenuBar::minimumSizeHint() const
{
Q_D(const QMenuBar);
#if defined(Q_OS_MAC) || defined(Q_OS_WINCE)
const bool as_gui_menubar = !isNativeMenuBar();
#else
const bool as_gui_menubar = true;
#endif

ensurePolished();
QSize ret(0, 0);
Expand Down Expand Up @@ -1615,12 +1609,7 @@ QSize QMenuBar::minimumSizeHint() const
QSize QMenuBar::sizeHint() const
{
Q_D(const QMenuBar);
#if defined(Q_OS_MAC) || defined(Q_OS_WINCE)
const bool as_gui_menubar = !isNativeMenuBar();
#else
const bool as_gui_menubar = true;
#endif


ensurePolished();
QSize ret(0, 0);
Expand Down Expand Up @@ -1673,11 +1662,7 @@ QSize QMenuBar::sizeHint() const
int QMenuBar::heightForWidth(int) const
{
Q_D(const QMenuBar);
#if defined(Q_OS_MAC) || defined(Q_OS_WINCE)
const bool as_gui_menubar = !isNativeMenuBar();
#else
const bool as_gui_menubar = true;
#endif

const_cast<QMenuBarPrivate*>(d)->updateGeometries();
int height = 0;
Expand Down Expand Up @@ -1822,10 +1807,8 @@ QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const
void QMenuBar::setNativeMenuBar(bool nativeMenuBar)
{
Q_D(QMenuBar);
if (d->nativeMenuBar == -1 || (nativeMenuBar != bool(d->nativeMenuBar))) {
d->nativeMenuBar = nativeMenuBar;

if (!d->nativeMenuBar) {
if (nativeMenuBar != bool(d->platformMenuBar)) {
if (!nativeMenuBar) {
delete d->platformMenuBar;
d->platformMenuBar = 0;
} else {
Expand All @@ -1834,18 +1817,15 @@ void QMenuBar::setNativeMenuBar(bool nativeMenuBar)
}

updateGeometry();
if (!d->nativeMenuBar && parentWidget())
if (!nativeMenuBar && parentWidget())
setVisible(true);
}
}

bool QMenuBar::isNativeMenuBar() const
{
Q_D(const QMenuBar);
if (d->nativeMenuBar == -1) {
return !QApplication::instance()->testAttribute(Qt::AA_DontUseNativeMenuBar);
}
return d->nativeMenuBar;
return bool(d->platformMenuBar);
}

/*!
Expand Down
4 changes: 1 addition & 3 deletions src/widgets/widgets/qmenubar_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class QMenuBarPrivate : public QWidgetPrivate
public:
QMenuBarPrivate() : itemsDirty(0), currentAction(0), mouseDown(0),
closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0),
nativeMenuBar(-1), doChildEffects(false), platformMenuBar(0)
doChildEffects(false), platformMenuBar(0)

#ifdef Q_OS_WINCE
, wce_menubar(0), wceClassicMenu(false)
Expand Down Expand Up @@ -102,8 +102,6 @@ class QMenuBarPrivate : public QWidgetPrivate
uint keyboardState : 1, altPressed : 1;
QPointer<QWidget> keyboardFocusWidget;


int nativeMenuBar : 3; // Only has values -1, 0, and 1
//firing of events
void activateAction(QAction *, QAction::ActionEvent);

Expand Down

0 comments on commit 835d7cf

Please sign in to comment.