QMenuBar cleanup

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2016-11-09 13:34:59 +00:00
parent 4663dcf97b
commit 2817bf1ce1
13 changed files with 65 additions and 630 deletions

View file

@ -407,9 +407,8 @@ public:
AA_DontShowIconsInMenus = 1,
AA_NativeWindows = 2,
AA_DontCreateNativeWidgetSiblings = 3,
AA_DontUseNativeMenuBar = 4,
AA_X11InitThreads = 5,
AA_CaptureMultimediaKeys = 6,
AA_X11InitThreads = 4,
AA_CaptureMultimediaKeys = 5,
// Add new attributes before this line
AA_AttributeCount

View file

@ -126,9 +126,6 @@
widgets stay non-native unless specifically set by the
Qt::WA_NativeWindow attribute.
\value AA_DontUseNativeMenuBar All menubars created while this attribute is
set to true won't be used as a native menubar.
\value AA_X11InitThreads Calls XInitThreads() as part of the QApplication
construction in order to make Xlib calls thread-safe. This
attribute must be set before QApplication is constructed.

View file

@ -571,20 +571,6 @@ void QCoreApplication::setAttribute(Qt::ApplicationAttribute attribute, bool on)
QCoreApplicationPrivate::attribs |= 1 << attribute;
else
QCoreApplicationPrivate::attribs &= ~(1 << attribute);
#ifdef Q_OS_MAC
// Turn on the no native menubar here, since we used to
// do this implicitly. We DO NOT flip it off if someone sets
// it to false.
// Ideally, we'd have magic that would be something along the lines of
// "follow MacPluginApplication" unless explicitly set.
// Considering this attribute isn't only at the beginning
// it's unlikely it will ever be a problem, but I want
// to have the behavior documented here.
if (attribute == Qt::AA_MacPluginApplication && on
&& !testAttribute(Qt::AA_DontUseNativeMenuBar)) {
setAttribute(Qt::AA_DontUseNativeMenuBar, true);
}
#endif
}
/*!

View file

@ -603,12 +603,6 @@ QDesignerPropertySheet::QDesignerPropertySheet(QObject *object, QObject *parent)
setVisible(createFakeProperty(QLatin1String("windowOpacity"), double(1.0)), false);
if (qobject_cast<const QToolBar *>(d->m_object)) { // prevent toolbars from being dragged off
createFakeProperty(QLatin1String("floatable"), QVariant(true));
} else {
if (qobject_cast<const QMenuBar *>(d->m_object)) {
// Keep the menu bar editable in the form even if a native menu bar is used.
const bool nativeMenuBarDefault = !qApp->testAttribute(Qt::AA_DontUseNativeMenuBar);
createFakeProperty(QLatin1String("nativeMenuBar"), QVariant(nativeMenuBarDefault));
}
}
if (d->m_canHaveLayoutAttributes) {
static const QString layoutGroup = QLatin1String("Layout");

View file

@ -661,13 +661,7 @@ bool QShortcutMap::correctContext(const QShortcutEntry &item) const {
bool QShortcutMap::correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window) const
{
bool visible = w->isVisible();
#ifdef Q_WS_MAC
if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w))
visible = true;
#endif
if (!visible || !w->isEnabled())
if (!w->isVisible() || !w->isEnabled())
return false;
if (context == Qt::ApplicationShortcut)
@ -724,13 +718,7 @@ bool QShortcutMap::correctWidgetContext(Qt::ShortcutContext context, QWidget *w,
#ifndef QT_NO_GRAPHICSVIEW
bool QShortcutMap::correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window) const
{
bool visible = w->isVisible();
#ifdef Q_WS_MAC
if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w))
visible = true;
#endif
if (!visible || !w->isEnabled() || !w->scene())
if (!w->isVisible() || !w->isEnabled() || !w->scene())
return false;
if (context == Qt::ApplicationShortcut) {

View file

@ -1,108 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QABSTRACTPLATFORMMENUBAR_P_H
#define QABSTRACTPLATFORMMENUBAR_P_H
#include <qfactoryinterface.h>
#include <qglobal.h>
#include <qplugin.h>
#ifndef QT_NO_MENUBAR
QT_BEGIN_NAMESPACE
class QAction;
class QActionEvent;
class QEvent;
class QMenuBar;
class QObject;
class QWidget;
class QAbstractPlatformMenuBar;
struct QPlatformMenuBarFactoryInterface : public QFactoryInterface
{
virtual QAbstractPlatformMenuBar *create() = 0;
};
#define QPlatformMenuBarFactoryInterface_iid "com.nokia.qt.QPlatformMenuBarFactoryInterface"
Q_DECLARE_INTERFACE(QPlatformMenuBarFactoryInterface, QPlatformMenuBarFactoryInterface_iid)
/*!
The platform-specific implementation of a menubar
*/
class QAbstractPlatformMenuBar
{
public:
virtual ~QAbstractPlatformMenuBar() {}
virtual void init(QMenuBar *) = 0;
virtual void setVisible(bool visible) = 0;
virtual void actionEvent(QActionEvent *) = 0;
virtual void handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow) = 0;
virtual bool allowCornerWidgets() const = 0;
virtual void popupAction(QAction *) = 0;
virtual void setNativeMenuBar(bool) = 0;
virtual bool isNativeMenuBar() const = 0;
/*!
Return true if the native menubar is capable of listening to the
shortcut keys. If false is returned, QMenuBar will trigger actions on
shortcut itself.
*/
virtual bool shortcutsHandledByNativeMenuBar() const = 0;
virtual bool menuBarEventFilter(QObject *, QEvent *event) = 0;
};
QT_END_NAMESPACE
#endif // QT_NO_MENUBAR
#endif // QABSTRACTPLATFORMMENUBAR_P_H

View file

@ -65,9 +65,6 @@
#include "qmenu_p.h"
#include "qmenubar_p.h"
#include "qdebug.h"
#ifdef Q_WS_X11
#include "qmenubar_x11_p.h"
#endif
QT_BEGIN_NAMESPACE
@ -167,11 +164,7 @@ void QMenuBarPrivate::updateGeometries()
return;
int q_width = q->width()-(q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q)*2);
int q_start = -1;
if(
#ifdef Q_WS_X11
platformMenuBar->allowCornerWidgets() &&
#endif
(leftWidget || rightWidget)) {
if(leftWidget || rightWidget) {
int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q)
+ q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q);
int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q)
@ -196,23 +189,13 @@ void QMenuBarPrivate::updateGeometries()
calcActionRects(q_width, q_start);
currentAction = 0;
#ifndef QT_NO_SHORTCUT
if(
#ifdef Q_WS_X11
!platformMenuBar->shortcutsHandledByNativeMenuBar() &&
#endif
itemsDirty) {
if(itemsDirty) {
for(int j = 0; j < shortcutIndexMap.size(); ++j)
q->releaseShortcut(shortcutIndexMap.value(j));
shortcutIndexMap.resize(0); // faster than clear
for(int i = 0; i < actions.count(); i++)
shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text())));
}
#endif
#ifdef Q_WS_X11
if(q->isNativeMenuBar()) {//nothing to see here folks, move along..
itemsDirty = false;
return;
}
#endif
itemsDirty = false;
@ -718,10 +701,6 @@ void QMenuBarPrivate::init()
Q_Q(QMenuBar);
q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
q->setAttribute(Qt::WA_CustomWhatsThis);
#ifdef Q_WS_X11
platformMenuBar = qt_guiPlatformMenuBarFactory()->create();
platformMenuBar->init(q);
#endif
q->setBackgroundRole(QPalette::Button);
oldWindow = oldParent = 0;
@ -1024,19 +1003,6 @@ void QMenuBar::paintEvent(QPaintEvent *e)
style()->drawControl(QStyle::CE_MenuBarEmptyArea, &menuOpt, &p, this);
}
/*!
\reimp
*/
void QMenuBar::setVisible(bool visible)
{
#ifdef Q_WS_X11
Q_D(QMenuBar);
d->platformMenuBar->setVisible(visible);
#else
QWidget::setVisible(visible);
#endif // Q_WS_X11
}
/*!
\reimp
*/
@ -1226,9 +1192,6 @@ void QMenuBar::actionEvent(QActionEvent *e)
{
Q_D(QMenuBar);
d->itemsDirty = true;
#ifdef Q_WS_X11
d->platformMenuBar->actionEvent(e);
#endif
if(e->type() == QEvent::ActionAdded) {
connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered()));
@ -1304,10 +1267,6 @@ void QMenuBarPrivate::handleReparent()
newWindow->installEventFilter(q);
}
#ifdef Q_WS_X11
platformMenuBar->handleReparent(oldParent, newParent, oldWindow, newWindow);
#endif
oldParent = newParent;
oldWindow = newWindow;
}
@ -1405,11 +1364,6 @@ bool QMenuBar::event(QEvent *e)
bool QMenuBar::eventFilter(QObject *object, QEvent *event)
{
Q_D(QMenuBar);
#ifdef Q_WS_X11
if (d->platformMenuBar->menuBarEventFilter(object, event)) {
return true;
}
#endif
if (object == parent() && object) {
if (event->type() == QEvent::ParentChange) //GrandparentChange
d->handleReparent();
@ -1495,11 +1449,6 @@ QRect QMenuBar::actionGeometry(QAction *act) const
QSize QMenuBar::minimumSizeHint() const
{
Q_D(const QMenuBar);
#if defined(Q_WS_X11)
const bool as_gui_menubar = !isNativeMenuBar();
#else
const bool as_gui_menubar = true;
#endif
ensurePolished();
QSize ret(0, 0);
@ -1508,19 +1457,16 @@ QSize QMenuBar::minimumSizeHint() const
const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);
int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);
int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);
if(as_gui_menubar) {
int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
d->calcActionRects(w - (2 * fw), 0);
for (int i = 0; ret.isNull() && i < d->actions.count(); ++i)
ret = d->actionRects.at(i).size();
if (!d->extension->isHidden())
ret += QSize(d->extension->sizeHint().width(), 0);
ret += QSize(2*fw + hmargin, 2*fw + vmargin);
}
int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
d->calcActionRects(w - (2 * fw), 0);
for (int i = 0; ret.isNull() && i < d->actions.count(); ++i)
ret = d->actionRects.at(i).size();
if (!d->extension->isHidden())
ret += QSize(d->extension->sizeHint().width(), 0);
ret += QSize(2*fw + hmargin, 2*fw + vmargin);
int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
#ifdef Q_WS_X11
if (d->platformMenuBar->allowCornerWidgets()) {
#endif
if(d->leftWidget) {
QSize sz = d->leftWidget->minimumSizeHint();
ret.setWidth(ret.width() + sz.width());
@ -1533,22 +1479,16 @@ QSize QMenuBar::minimumSizeHint() const
if(sz.height() + margin > ret.height())
ret.setHeight(sz.height() + margin);
}
#ifdef Q_WS_X11
}
#endif
if(as_gui_menubar) {
QStyleOptionMenuItem opt;
opt.rect = rect();
opt.menuRect = rect();
opt.state = QStyle::State_None;
opt.menuItemType = QStyleOptionMenuItem::Normal;
opt.checkType = QStyleOptionMenuItem::NotCheckable;
opt.palette = palette();
return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt,
ret.expandedTo(QApplication::globalStrut()),
this));
}
return ret;
QStyleOptionMenuItem opt;
opt.rect = rect();
opt.menuRect = rect();
opt.state = QStyle::State_None;
opt.menuItemType = QStyleOptionMenuItem::Normal;
opt.checkType = QStyleOptionMenuItem::NotCheckable;
opt.palette = palette();
return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt,
ret.expandedTo(QApplication::globalStrut()),
this));
}
/*!
@ -1557,12 +1497,6 @@ QSize QMenuBar::minimumSizeHint() const
QSize QMenuBar::sizeHint() const
{
Q_D(const QMenuBar);
#if defined(Q_WS_X11)
const bool as_gui_menubar = !isNativeMenuBar();
#else
const bool as_gui_menubar = true;
#endif
ensurePolished();
QSize ret(0, 0);
@ -1571,21 +1505,18 @@ QSize QMenuBar::sizeHint() const
const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);
int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);
int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);
if(as_gui_menubar) {
const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
d->calcActionRects(w - (2 * fw), 0);
for (int i = 0; i < d->actionRects.count(); ++i) {
const QRect &actionRect = d->actionRects.at(i);
ret = ret.expandedTo(QSize(actionRect.x() + actionRect.width(), actionRect.y() + actionRect.height()));
}
//the action geometries already contain the top and left
//margins. So we only need to add those from right and bottom.
ret += QSize(fw + hmargin, fw + vmargin);
const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width();
d->calcActionRects(w - (2 * fw), 0);
for (int i = 0; i < d->actionRects.count(); ++i) {
const QRect &actionRect = d->actionRects.at(i);
ret = ret.expandedTo(QSize(actionRect.x() + actionRect.width(), actionRect.y() + actionRect.height()));
}
//the action geometries already contain the top and left
//margins. So we only need to add those from right and bottom.
ret += QSize(fw + hmargin, fw + vmargin);
int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
#ifdef Q_WS_X11
if(d->platformMenuBar->allowCornerWidgets()) {
#endif
if(d->leftWidget) {
QSize sz = d->leftWidget->sizeHint();
ret.setWidth(ret.width() + sz.width());
@ -1598,22 +1529,17 @@ QSize QMenuBar::sizeHint() const
if(sz.height() + margin > ret.height())
ret.setHeight(sz.height() + margin);
}
#ifdef Q_WS_X11
}
#endif
if(as_gui_menubar) {
QStyleOptionMenuItem opt;
opt.rect = rect();
opt.menuRect = rect();
opt.state = QStyle::State_None;
opt.menuItemType = QStyleOptionMenuItem::Normal;
opt.checkType = QStyleOptionMenuItem::NotCheckable;
opt.palette = palette();
return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt,
ret.expandedTo(QApplication::globalStrut()),
this));
}
return ret;
QStyleOptionMenuItem opt;
opt.rect = rect();
opt.menuRect = rect();
opt.state = QStyle::State_None;
opt.menuItemType = QStyleOptionMenuItem::Normal;
opt.checkType = QStyleOptionMenuItem::NotCheckable;
opt.palette = palette();
return (style()->sizeFromContents(QStyle::CT_MenuBar, &opt,
ret.expandedTo(QApplication::globalStrut()),
this));
}
/*!
@ -1622,46 +1548,33 @@ QSize QMenuBar::sizeHint() const
int QMenuBar::heightForWidth(int) const
{
Q_D(const QMenuBar);
#if defined(Q_WS_X11)
const bool as_gui_menubar = !isNativeMenuBar();
#else
const bool as_gui_menubar = true;
#endif
const_cast<QMenuBarPrivate*>(d)->updateGeometries();
int height = 0;
const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this);
int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this);
int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this);
if(as_gui_menubar) {
for (int i = 0; i < d->actionRects.count(); ++i)
height = qMax(height, d->actionRects.at(i).height());
if (height) //there is at least one non-null item
height += spaceBelowMenuBar;
height += 2*fw;
height += 2*vmargin;
}
for (int i = 0; i < d->actionRects.count(); ++i)
height = qMax(height, d->actionRects.at(i).height());
if (height) //there is at least one non-null item
height += spaceBelowMenuBar;
height += 2*fw;
height += 2*vmargin;
int margin = 2*vmargin + 2*fw + spaceBelowMenuBar;
#ifdef Q_WS_X11
if(d->platformMenuBar->allowCornerWidgets()) {
#endif
if(d->leftWidget)
height = qMax(d->leftWidget->sizeHint().height() + margin, height);
if(d->rightWidget)
height = qMax(d->rightWidget->sizeHint().height() + margin, height);
#ifdef Q_WS_X11
}
#endif
if(as_gui_menubar) {
QStyleOptionMenuItem opt;
opt.init(this);
opt.menuRect = rect();
opt.state = QStyle::State_None;
opt.menuItemType = QStyleOptionMenuItem::Normal;
opt.checkType = QStyleOptionMenuItem::NotCheckable;
return style()->sizeFromContents(QStyle::CT_MenuBar, &opt, QSize(0, height), this).height(); //not pretty..
}
return height;
QStyleOptionMenuItem opt;
opt.init(this);
opt.menuRect = rect();
opt.state = QStyle::State_None;
opt.menuItemType = QStyleOptionMenuItem::Normal;
opt.checkType = QStyleOptionMenuItem::NotCheckable;
return style()->sizeFromContents(QStyle::CT_MenuBar, &opt, QSize(0, height), this).height(); //not pretty..
}
/*!
@ -1671,15 +1584,8 @@ void QMenuBarPrivate::_q_internalShortcutActivated(int id)
{
Q_Q(QMenuBar);
QAction *act = actions.at(id);
#ifdef Q_WS_X11
if (q->isNativeMenuBar()) {
platformMenuBar->popupAction(act);
} else {
#endif
setCurrentAction(act, true, true);
#ifdef Q_WS_X11
}
#endif
setCurrentAction(act, true, true);
if (act && !act->menu()) {
activateAction(act, QAction::Trigger);
//100 is the same as the default value in QPushButton::animateClick
@ -1765,18 +1671,10 @@ void QMenuBar::setCornerWidget(QWidget *w, Qt::Corner corner)
return;
}
#ifdef Q_WS_X11
if(!d->platformMenuBar->allowCornerWidgets()) {
d->updateCornerWidgetToolBar();
} else {
#endif
if (w) {
w->setParent(this);
w->installEventFilter(this);
}
#ifdef Q_WS_X11
}
#endif
d->_q_updateLayout();
}
@ -1807,49 +1705,6 @@ QWidget *QMenuBar::cornerWidget(Qt::Corner corner) const
return w;
}
/*!
\property QMenuBar::nativeMenuBar
\brief Whether or not a menubar will be used as a native menubar on platforms that support it
\since 4.6
This property specifies whether or not the menubar should be used as a native menubar on platforms
that support it. The currently supported platforms are Mac OS X and Windows CE. On these platforms
if this property is true, the menubar is used in the native menubar and is not in the window of
its parent, if false the menubar remains in the window. On other platforms the value of this
attribute has no effect.
The default is to follow whether the Qt::AA_DontUseNativeMenuBar attribute
is set for the application. Explicitly settings this property overrides
the presence (or abscence) of the attribute.
\sa void-qt-mac-set-native-menubar-bool-enable
*/
void QMenuBar::setNativeMenuBar(bool nativeMenuBar)
{
Q_D(QMenuBar);
#ifdef Q_WS_X11
d->platformMenuBar->setNativeMenuBar(nativeMenuBar);
#else
if (d->nativeMenuBar == -1 || (nativeMenuBar != bool(d->nativeMenuBar))) {
d->nativeMenuBar = nativeMenuBar;
}
#endif // Q_WS_X11
}
bool QMenuBar::isNativeMenuBar() const
{
Q_D(const QMenuBar);
#ifdef Q_WS_X11
return d->platformMenuBar->isNativeMenuBar();
#else
if (d->nativeMenuBar == -1) {
return !QApplication::instance()->testAttribute(Qt::AA_DontUseNativeMenuBar);
}
return d->nativeMenuBar;
#endif
}
/*!
\fn void QMenuBar::triggered(QAction *action)

View file

@ -105,9 +105,6 @@ public:
bool isNativeMenuBar() const;
void setNativeMenuBar(bool nativeMenuBar);
public Q_SLOTS:
virtual void setVisible(bool visible);
Q_SIGNALS:
void triggered(QAction *action);
void hovered(QAction *action);

View file

@ -57,10 +57,6 @@
#include "qwidget_p.h"
#include "qbasictimer.h"
#ifdef Q_WS_X11
#include "qabstractplatformmenubar_p.h"
#endif
QT_BEGIN_NAMESPACE
#ifndef QT_NO_MENUBAR
@ -72,21 +68,11 @@ class QMenuBarPrivate : public QWidgetPrivate
public:
QMenuBarPrivate() : itemsDirty(0), currentAction(0), mouseDown(0),
closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0)
#ifndef Q_WS_X11
, nativeMenuBar(-1)
#endif
, doChildEffects(false)
#ifdef Q_WS_X11
, platformMenuBar(0)
#endif
{ }
~QMenuBarPrivate()
{
#ifdef Q_WS_X11
delete platformMenuBar;
#endif
}
{ }
void init();
QAction *getNextAction(const int start, const int increment) const;
@ -117,9 +103,6 @@ public:
uint keyboardState : 1, altPressed : 1;
QPointer<QWidget> keyboardFocusWidget;
#ifndef Q_WS_X11
int nativeMenuBar : 3; // Only has values -1, 0, and 1
#endif
//firing of events
void activateAction(QAction *, QAction::ActionEvent);
@ -148,9 +131,6 @@ public:
QPointer<QAction> defaultAction;
QBasicTimer autoReleaseTimer;
#ifdef Q_WS_X11
QAbstractPlatformMenuBar *platformMenuBar;
#endif
#ifdef Q_WS_X11
void updateCornerWidgetToolBar();

View file

@ -1,141 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qmenubar_x11_p.h"
#ifndef QT_NO_MENUBAR
#include "qapplication.h"
#include "qdebug.h"
#include "qevent.h"
#include "qmenu.h"
#include "qmenubar.h"
#include <qfactoryloader_p.h>
QT_BEGIN_NAMESPACE
QX11MenuBar::~QX11MenuBar()
{
}
void QX11MenuBar::init(QMenuBar *_menuBar)
{
nativeMenuBar = -1;
menuBar = _menuBar;
}
void QX11MenuBar::setVisible(bool visible)
{
menuBar->QWidget::setVisible(visible);
}
void QX11MenuBar::actionEvent(QActionEvent *e)
{
Q_UNUSED(e);
}
void QX11MenuBar::handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow)
{
Q_UNUSED(oldParent)
Q_UNUSED(newParent)
Q_UNUSED(oldWindow)
Q_UNUSED(newWindow)
}
bool QX11MenuBar::allowCornerWidgets() const
{
return true;
}
void QX11MenuBar::popupAction(QAction *)
{
}
void QX11MenuBar::setNativeMenuBar(bool value)
{
if (nativeMenuBar == -1 || (value != bool(nativeMenuBar))) {
nativeMenuBar = value;
}
}
bool QX11MenuBar::isNativeMenuBar() const
{
return false;
}
bool QX11MenuBar::shortcutsHandledByNativeMenuBar() const
{
return false;
}
bool QX11MenuBar::menuBarEventFilter(QObject *, QEvent *)
{
return false;
}
struct QX11MenuBarFactory : public QPlatformMenuBarFactoryInterface
{
QAbstractPlatformMenuBar *create() { return new QX11MenuBar; }
virtual QStringList keys() const { return QStringList(); }
};
QPlatformMenuBarFactoryInterface *qt_guiPlatformMenuBarFactory()
{
static QPlatformMenuBarFactoryInterface *factory = 0;
if (!factory) {
#ifndef QT_NO_LIBRARY
QFactoryLoader loader(QPlatformMenuBarFactoryInterface_iid, QLatin1String("/menubar"));
factory = qobject_cast<QPlatformMenuBarFactoryInterface *>(loader.instance(QLatin1String("default")));
#endif // QT_NO_LIBRARY
if(!factory) {
static QX11MenuBarFactory def;
factory = &def;
}
}
return factory;
}
QT_END_NAMESPACE
#endif // QT_NO_MENUBAR

View file

@ -1,87 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QX11MENUBAR_P_H
#define QX11MENUBAR_P_H
#ifndef QT_NO_MENUBAR
#include "qabstractplatformmenubar_p.h"
QT_BEGIN_NAMESPACE
class QMenuBar;
class QX11MenuBar : public QAbstractPlatformMenuBar
{
public:
~QX11MenuBar();
virtual void init(QMenuBar *);
virtual void setVisible(bool visible);
virtual void actionEvent(QActionEvent *e);
virtual void handleReparent(QWidget *oldParent, QWidget *newParent, QWidget *oldWindow, QWidget *newWindow);
virtual bool allowCornerWidgets() const;
virtual void popupAction(QAction*);
virtual void setNativeMenuBar(bool);
virtual bool isNativeMenuBar() const;
virtual bool shortcutsHandledByNativeMenuBar() const;
virtual bool menuBarEventFilter(QObject *, QEvent *event);
private:
QMenuBar *menuBar;
int nativeMenuBar : 3; // Only has values -1, 0, and 1
};
QPlatformMenuBarFactoryInterface *qt_guiPlatformMenuBarFactory();
QT_END_NAMESPACE
#endif // QT_NO_MENUBAR
#endif /* QX11MENUBAR_P_H */

View file

@ -146,14 +146,3 @@ set(GUI_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/widgets/qplaintextedit.cpp
${CMAKE_CURRENT_SOURCE_DIR}/widgets/qprintpreviewwidget.cpp
)
if(WITH_X11 AND X11_FOUND)
set(GUI_HEADERS
${GUI_HEADERS}
${CMAKE_CURRENT_SOURCE_DIR}/widgets/qabstractplatformmenubar_p.h
)
set(GUI_SOURCES
${GUI_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/widgets/qmenubar_x11.cpp
)
endif()

View file

@ -407,9 +407,6 @@ void QDesignerWorkbench::switchToDockedMode()
switchToNeutralMode();
#ifdef Q_WS_X11
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, false);
#endif
QDesignerToolWindow *widgetBoxWrapper = widgetBoxToolWindow();
widgetBoxWrapper->action()->setVisible(true);
widgetBoxWrapper->setWindowTitle(tr("Widget Box"));
@ -471,22 +468,11 @@ void QDesignerWorkbench::switchToTopLevelMode()
// The widget box is special, it gets the menubar and gets to be the main widget.
m_core->setTopLevel(widgetBoxWrapper);
#ifdef Q_WS_X11
// For now the appmenu protocol does not make it possible to associate a
// menubar with all application windows. This means in top level mode you
// can only reach the menubar when the widgetbox window is active. Since
// this is quite inconvenient, better not use the native menubar in this
// configuration and keep the menubar in the widgetbox window.
QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
#endif
#ifndef Q_WS_MAC
widgetBoxWrapper->setMenuBar(m_globalMenuBar);
widgetBoxWrapper->action()->setVisible(false);
widgetBoxWrapper->setCloseEventPolicy(MainWindowBase::EmitCloseEventSignal);
qDesigner->setMainWindow(widgetBoxWrapper);
widgetBoxWrapper->setWindowTitle(MainWindowBase::mainWindowTitle());
#endif
const QDesignerSettings settings(m_core);
m_topLevelData.toolbars = MainWindowBase::createToolBars(m_actionManager, false);