QPA menu abstraction, originally based on Morten's work
Create a QPA abstraction for native menus, derived from the Cocoa support in 4.8, but with the expectation to support other platforms too. Update the QtWidget QMenu and QMenuBar code to maintain their QPA equivalents if they exist. Change-Id: Id605de3da8811dc832bf48b35f9107778ad320ff Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
This commit is contained in:
parent
864e996384
commit
1f55af8e54
@ -25,6 +25,7 @@ HEADERS += \
|
|||||||
kernel/qplatformcursor.h \
|
kernel/qplatformcursor.h \
|
||||||
kernel/qplatformclipboard.h \
|
kernel/qplatformclipboard.h \
|
||||||
kernel/qplatformnativeinterface.h \
|
kernel/qplatformnativeinterface.h \
|
||||||
|
kernel/qplatformmenu.h \
|
||||||
kernel/qsurfaceformat.h \
|
kernel/qsurfaceformat.h \
|
||||||
kernel/qguiapplication.h \
|
kernel/qguiapplication.h \
|
||||||
kernel/qguiapplication_p.h \
|
kernel/qguiapplication_p.h \
|
||||||
@ -79,6 +80,7 @@ SOURCES += \
|
|||||||
kernel/qplatformcursor_qpa.cpp \
|
kernel/qplatformcursor_qpa.cpp \
|
||||||
kernel/qplatformclipboard_qpa.cpp \
|
kernel/qplatformclipboard_qpa.cpp \
|
||||||
kernel/qplatformnativeinterface_qpa.cpp \
|
kernel/qplatformnativeinterface_qpa.cpp \
|
||||||
|
kernel/qplatformmenu_qpa.cpp \
|
||||||
kernel/qsessionmanager_qpa.cpp \
|
kernel/qsessionmanager_qpa.cpp \
|
||||||
kernel/qsurfaceformat.cpp \
|
kernel/qsurfaceformat.cpp \
|
||||||
kernel/qguiapplication.cpp \
|
kernel/qguiapplication.cpp \
|
||||||
|
115
src/gui/kernel/qplatformmenu.h
Executable file
115
src/gui/kernel/qplatformmenu.h
Executable file
@ -0,0 +1,115 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author James Turner <james.turner@kdab.com>
|
||||||
|
** Contact: http://www.qt-project.org/
|
||||||
|
**
|
||||||
|
** This file is part of the QtGui module of the Qt Toolkit.
|
||||||
|
**
|
||||||
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** This file may be used under the terms of the GNU Lesser General Public
|
||||||
|
** License version 2.1 as published by the Free Software Foundation and
|
||||||
|
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||||
|
** file. Please review the following information to ensure the GNU Lesser
|
||||||
|
** General Public License version 2.1 requirements will be met:
|
||||||
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt 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.
|
||||||
|
**
|
||||||
|
** Other Usage
|
||||||
|
** Alternatively, this file may be used in accordance with the terms and
|
||||||
|
** conditions contained in a signed written agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
**
|
||||||
|
**
|
||||||
|
**
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** $QT_END_LICENSE$
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef QPLATFORMMENU_H
|
||||||
|
#define QPLATFORMMENU_H
|
||||||
|
|
||||||
|
#include <QtCore/qglobal.h>
|
||||||
|
#include <QtCore/qpointer.h>
|
||||||
|
#include <QtGui/QFont>
|
||||||
|
#include <QtGui/QKeySequence>
|
||||||
|
|
||||||
|
QT_BEGIN_HEADER
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class QPlatformMenu;
|
||||||
|
class Q_GUI_EXPORT QPlatformMenuItem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
// copied from, and must stay in sync with, QAction menu roles.
|
||||||
|
enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
|
||||||
|
AboutRole, PreferencesRole, QuitRole };
|
||||||
|
|
||||||
|
virtual void setTag(quintptr tag);
|
||||||
|
virtual quintptr tag() const;
|
||||||
|
|
||||||
|
virtual void setText(const QString &text);
|
||||||
|
virtual void setIcon(const QImage &icon);
|
||||||
|
virtual void setMenu(QPlatformMenu *menu);
|
||||||
|
virtual void setVisible(bool isVisible);
|
||||||
|
virtual void setIsSeparator(bool isSeparator);
|
||||||
|
virtual void setFont(const QFont &font);
|
||||||
|
virtual void setRole(MenuRole role);
|
||||||
|
virtual void setChecked(bool isChecked);
|
||||||
|
virtual void setShortcut(const QKeySequence& shortcut);
|
||||||
|
virtual void setEnabled(bool enabled);
|
||||||
|
Q_SIGNALS:
|
||||||
|
void activated();
|
||||||
|
void hovered();
|
||||||
|
};
|
||||||
|
|
||||||
|
class Q_GUI_EXPORT QPlatformMenu : public QPlatformMenuItem // Some (but not all) of the PlatformMenuItem API applies to QPlatformMenu as well.
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
virtual void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before);
|
||||||
|
virtual void removeMenuItem(QPlatformMenuItem *menuItem);
|
||||||
|
virtual void syncMenuItem(QPlatformMenuItem *menuItem);
|
||||||
|
virtual void syncSeparatorsCollapsible(bool enable);
|
||||||
|
|
||||||
|
virtual QPlatformMenuItem *menuItemAt(int position) const;
|
||||||
|
virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const;
|
||||||
|
Q_SIGNALS:
|
||||||
|
void aboutToShow();
|
||||||
|
void aboutToHide();
|
||||||
|
};
|
||||||
|
|
||||||
|
class Q_GUI_EXPORT QPlatformMenuBar : public QPlatformMenu
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
virtual void insertMenu(QPlatformMenu *menu, QPlatformMenu *before);
|
||||||
|
virtual void removeMenu(QPlatformMenu *menu);
|
||||||
|
virtual void syncMenu(QPlatformMenuItem *menuItem);
|
||||||
|
virtual void handleReparent(QWindow *newParentWindow);
|
||||||
|
|
||||||
|
virtual QPlatformMenu *menuForTag(quintptr tag) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
QT_END_HEADER
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
132
src/widgets/kernel/qplatformmenu_qpa.cpp → src/gui/kernel/qplatformmenu_qpa.cpp
Normal file → Executable file
132
src/widgets/kernel/qplatformmenu_qpa.cpp → src/gui/kernel/qplatformmenu_qpa.cpp
Normal file → Executable file
@ -1,9 +1,9 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author James Turner <james.turner@kdab.com>
|
||||||
** Contact: http://www.qt-project.org/
|
** Contact: http://www.qt-project.org/
|
||||||
**
|
**
|
||||||
** This file is part of the QtWidgets module of the Qt Toolkit.
|
** This file is part of the QtGui module of the Qt Toolkit.
|
||||||
**
|
**
|
||||||
** $QT_BEGIN_LICENSE:LGPL$
|
** $QT_BEGIN_LICENSE:LGPL$
|
||||||
** GNU Lesser General Public License Usage
|
** GNU Lesser General Public License Usage
|
||||||
@ -43,71 +43,119 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
/*!
|
void QPlatformMenuItem::setText(const QString &text)
|
||||||
\class QPlatformMenuAction
|
|
||||||
\since 5.0
|
|
||||||
\internal
|
|
||||||
\preliminary
|
|
||||||
\ingroup qpa
|
|
||||||
|
|
||||||
\brief The QPlatformMenuAction class provides an abstraction for menu actions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
QPlatformMenuAction::~QPlatformMenuAction()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
void QPlatformMenuItem::setIcon(const QImage &icon)
|
||||||
\class QPlatformMenu
|
|
||||||
\since 5.0
|
|
||||||
\internal
|
|
||||||
\preliminary
|
|
||||||
\ingroup qpa
|
|
||||||
|
|
||||||
\brief The QPlatformMenu class provides an abstraction for menus.
|
|
||||||
*/
|
|
||||||
QPlatformMenu::QPlatformMenu()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QPlatformMenu::~QPlatformMenu()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QPlatformMenu::setMenuEnabled(bool enable)
|
void QPlatformMenuItem::setMenu(QPlatformMenu *menu)
|
||||||
{
|
{
|
||||||
Q_UNUSED(enable);
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenuItem::setVisible(bool isVisible)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenuItem::setIsSeparator(bool isSeparator)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenuItem::setFont(const QFont &font)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenuItem::setRole(QPlatformMenuItem::MenuRole role)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenuItem::setChecked(bool isChecked)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenuItem::setShortcut(const QKeySequence& shortcut)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenuItem::setEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenuItem::setTag(quintptr tag)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
quintptr QPlatformMenuItem::tag() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem* before)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenu::removeMenuItem(QPlatformMenuItem *menuItem)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenu::syncMenuItem(QPlatformMenuItem *menuItem)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QPlatformMenu::syncSeparatorsCollapsible(bool enable)
|
void QPlatformMenu::syncSeparatorsCollapsible(bool enable)
|
||||||
{
|
{
|
||||||
Q_UNUSED(enable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
QPlatformMenuItem* QPlatformMenu::menuItemAt(int position) const
|
||||||
\class QPlatformMenuBar
|
{
|
||||||
\since 5.0
|
return 0;
|
||||||
\internal
|
}
|
||||||
\preliminary
|
|
||||||
\ingroup qpa
|
|
||||||
|
|
||||||
\brief The QPlatformMenuBar class provides an abstraction for menu bars.
|
QPlatformMenuItem* QPlatformMenu::menuItemForTag(quintptr tag) const
|
||||||
*/
|
{
|
||||||
QPlatformMenuBar::QPlatformMenuBar()
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenuBar::insertMenu(QPlatformMenu *menuItem, QPlatformMenu* before)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPlatformMenuBar::~QPlatformMenuBar()
|
void QPlatformMenuBar::removeMenu(QPlatformMenu *menuItem)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QPlatformMenuBar::handleReparent(QWidget *newParent)
|
void QPlatformMenuBar::syncMenu(QPlatformMenuItem *menuItem)
|
||||||
{
|
{
|
||||||
Q_UNUSED(newParent);
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QPlatformMenuBar::handleReparent(QWindow *newParentWindow)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QPlatformMenu *QPlatformMenuBar::menuForTag(quintptr tag) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(tag);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
@ -61,6 +61,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
class QMenu;
|
class QMenu;
|
||||||
class QMenuBar;
|
class QMenuBar;
|
||||||
|
class QPlatformMenuItem;
|
||||||
class QPlatformMenu;
|
class QPlatformMenu;
|
||||||
class QPlatformMenuBar;
|
class QPlatformMenuBar;
|
||||||
class QPlatformDialogHelper;
|
class QPlatformDialogHelper;
|
||||||
@ -163,8 +164,9 @@ public:
|
|||||||
|
|
||||||
virtual ~QPlatformTheme();
|
virtual ~QPlatformTheme();
|
||||||
|
|
||||||
virtual QPlatformMenu *createPlatformMenu(QMenu *menu = 0) const;
|
virtual QPlatformMenuItem* createPlatformMenuItem() const;
|
||||||
virtual QPlatformMenuBar *createPlatformMenuBar(QMenuBar *menuBar = 0) const;
|
virtual QPlatformMenu* createPlatformMenu() const;
|
||||||
|
virtual QPlatformMenuBar* createPlatformMenuBar() const;
|
||||||
|
|
||||||
virtual bool usePlatformNativeDialog(DialogType type) const;
|
virtual bool usePlatformNativeDialog(DialogType type) const;
|
||||||
virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const;
|
virtual QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const;
|
||||||
|
@ -109,18 +109,6 @@ QPlatformTheme::~QPlatformTheme()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPlatformMenu *QPlatformTheme::createPlatformMenu(QMenu *menu) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(menu);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPlatformMenuBar *QPlatformTheme::createPlatformMenuBar(QMenuBar *menuBar) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(menuBar);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QPlatformTheme::usePlatformNativeDialog(DialogType type) const
|
bool QPlatformTheme::usePlatformNativeDialog(DialogType type) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(type);
|
Q_UNUSED(type);
|
||||||
@ -183,4 +171,19 @@ QVariant QPlatformTheme::themeHint(ThemeHint hint) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPlatformMenuItem *QPlatformTheme::createPlatformMenuItem() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPlatformMenu *QPlatformTheme::createPlatformMenu() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPlatformMenuBar *QPlatformTheme::createPlatformMenuBar() const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -17,8 +17,6 @@ OBJECTIVE_SOURCES += main.mm \
|
|||||||
qcocoamenuloader.mm \
|
qcocoamenuloader.mm \
|
||||||
qcocoaapplicationdelegate.mm \
|
qcocoaapplicationdelegate.mm \
|
||||||
qcocoaapplication.mm \
|
qcocoaapplication.mm \
|
||||||
qcocoamenu.mm \
|
|
||||||
qmenu_mac.mm \
|
|
||||||
qcocoahelpers.mm \
|
qcocoahelpers.mm \
|
||||||
qmultitouch_mac.mm \
|
qmultitouch_mac.mm \
|
||||||
qcocoaaccessibilityelement.mm \
|
qcocoaaccessibilityelement.mm \
|
||||||
@ -51,8 +49,6 @@ HEADERS += qcocoaintegration.h \
|
|||||||
qcocoamenuloader.h \
|
qcocoamenuloader.h \
|
||||||
qcocoaapplicationdelegate.h \
|
qcocoaapplicationdelegate.h \
|
||||||
qcocoaapplication.h \
|
qcocoaapplication.h \
|
||||||
qcocoamenu.h \
|
|
||||||
qmenu_mac.h \
|
|
||||||
qcocoahelpers.h \
|
qcocoahelpers.h \
|
||||||
qmultitouch_mac_p.h \
|
qmultitouch_mac_p.h \
|
||||||
qcocoaaccessibilityelement.h \
|
qcocoaaccessibilityelement.h \
|
||||||
|
@ -49,7 +49,6 @@
|
|||||||
#include "qcocoahelpers.h"
|
#include "qcocoahelpers.h"
|
||||||
#include "qcocoaapplication.h"
|
#include "qcocoaapplication.h"
|
||||||
#include "qcocoaapplicationdelegate.h"
|
#include "qcocoaapplicationdelegate.h"
|
||||||
#include "qmenu_mac.h"
|
|
||||||
#include "qcocoafiledialoghelper.h"
|
#include "qcocoafiledialoghelper.h"
|
||||||
#include "qcocoatheme.h"
|
#include "qcocoatheme.h"
|
||||||
#include "qcocoainputcontext.h"
|
#include "qcocoainputcontext.h"
|
||||||
|
@ -41,7 +41,6 @@
|
|||||||
|
|
||||||
#include "qcocoamenuloader.h"
|
#include "qcocoamenuloader.h"
|
||||||
|
|
||||||
#include "qmenu_mac.h"
|
|
||||||
#include "qcocoahelpers.h"
|
#include "qcocoahelpers.h"
|
||||||
|
|
||||||
#include <QtCore/private/qcore_mac_p.h>
|
#include <QtCore/private/qcore_mac_p.h>
|
||||||
@ -272,15 +271,17 @@ void qt_mac_loadMenuNib(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader)
|
|||||||
|
|
||||||
- (void)qtUpdateMenubar
|
- (void)qtUpdateMenubar
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
QCocoaMenuBar::macUpdateMenuBarImmediatly();
|
QCocoaMenuBar::macUpdateMenuBarImmediatly();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)qtTranslateApplicationMenu
|
- (void)qtTranslateApplicationMenu
|
||||||
{
|
{
|
||||||
|
|
||||||
qDebug() << "qtTranslateApplicationMenu";
|
qDebug() << "qtTranslateApplicationMenu";
|
||||||
|
#if 0
|
||||||
#ifndef QT_NO_TRANSLATION
|
//#ifndef QT_NO_TRANSLATION
|
||||||
[servicesItem setTitle: QCFString::toNSString(qt_mac_applicationmenu_string(0))];
|
[servicesItem setTitle: QCFString::toNSString(qt_mac_applicationmenu_string(0))];
|
||||||
[hideItem setTitle: QCFString::toNSString(qt_mac_applicationmenu_string(1).arg(qt_mac_applicationName()))];
|
[hideItem setTitle: QCFString::toNSString(qt_mac_applicationmenu_string(1).arg(qt_mac_applicationName()))];
|
||||||
[hideAllOthersItem setTitle: QCFString::toNSString(qt_mac_applicationmenu_string(2))];
|
[hideAllOthersItem setTitle: QCFString::toNSString(qt_mac_applicationmenu_string(2))];
|
||||||
@ -293,6 +294,7 @@ void qt_mac_loadMenuNib(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader)
|
|||||||
|
|
||||||
- (IBAction)qtDispatcherToQAction:(id)sender
|
- (IBAction)qtDispatcherToQAction:(id)sender
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
//
|
//
|
||||||
//QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData);
|
//QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData);
|
||||||
NSMenuItem *item = static_cast<NSMenuItem *>(sender);
|
NSMenuItem *item = static_cast<NSMenuItem *>(sender);
|
||||||
@ -304,6 +306,7 @@ void qt_mac_loadMenuNib(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader)
|
|||||||
// normal QApplication::quit().
|
// normal QApplication::quit().
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)orderFrontCharacterPalette:(id)sender
|
- (void)orderFrontCharacterPalette:(id)sender
|
||||||
|
@ -54,9 +54,6 @@ public:
|
|||||||
QCocoaTheme();
|
QCocoaTheme();
|
||||||
~QCocoaTheme();
|
~QCocoaTheme();
|
||||||
|
|
||||||
QPlatformMenu *createPlatformMenu(QMenu *menu = 0) const;
|
|
||||||
QPlatformMenuBar *createPlatformMenuBar(QMenuBar *menuBar = 0) const;
|
|
||||||
|
|
||||||
bool usePlatformNativeDialog(DialogType dialogType) const;
|
bool usePlatformNativeDialog(DialogType dialogType) const;
|
||||||
QPlatformDialogHelper *createPlatformDialogHelper(DialogType dialogType) const;
|
QPlatformDialogHelper *createPlatformDialogHelper(DialogType dialogType) const;
|
||||||
|
|
||||||
|
@ -41,7 +41,8 @@
|
|||||||
|
|
||||||
#include "qcocoatheme.h"
|
#include "qcocoatheme.h"
|
||||||
|
|
||||||
#include "qmenu_mac.h"
|
#include <QVariant>
|
||||||
|
|
||||||
#include "qcocoacolordialoghelper.h"
|
#include "qcocoacolordialoghelper.h"
|
||||||
#include "qcocoafiledialoghelper.h"
|
#include "qcocoafiledialoghelper.h"
|
||||||
#include "qcocoafontdialoghelper.h"
|
#include "qcocoafontdialoghelper.h"
|
||||||
@ -62,17 +63,6 @@ QCocoaTheme::~QCocoaTheme()
|
|||||||
delete m_systemPalette;
|
delete m_systemPalette;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPlatformMenu *QCocoaTheme::createPlatformMenu(QMenu *menu) const
|
|
||||||
{
|
|
||||||
return new QCocoaMenu(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
QPlatformMenuBar *QCocoaTheme::createPlatformMenuBar(QMenuBar *menuBar) const
|
|
||||||
{
|
|
||||||
return new QCocoaMenuBar(menuBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool QCocoaTheme::usePlatformNativeDialog(DialogType dialogType) const
|
bool QCocoaTheme::usePlatformNativeDialog(DialogType dialogType) const
|
||||||
{
|
{
|
||||||
if (dialogType == QPlatformTheme::FileDialog)
|
if (dialogType == QPlatformTheme::FileDialog)
|
||||||
|
@ -36,8 +36,7 @@ HEADERS += \
|
|||||||
kernel/qsoftkeymanager_p.h \
|
kernel/qsoftkeymanager_p.h \
|
||||||
kernel/qsoftkeymanager_common_p.h \
|
kernel/qsoftkeymanager_common_p.h \
|
||||||
kernel/qdesktopwidget_qpa_p.h \
|
kernel/qdesktopwidget_qpa_p.h \
|
||||||
kernel/qwidgetwindow_qpa_p.h \
|
kernel/qwidgetwindow_qpa_p.h
|
||||||
kernel/qplatformmenu.h
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
kernel/qaction.cpp \
|
kernel/qaction.cpp \
|
||||||
@ -66,8 +65,8 @@ SOURCES += \
|
|||||||
kernel/qapplication_qpa.cpp \
|
kernel/qapplication_qpa.cpp \
|
||||||
kernel/qdesktopwidget_qpa.cpp \
|
kernel/qdesktopwidget_qpa.cpp \
|
||||||
kernel/qwidget_qpa.cpp \
|
kernel/qwidget_qpa.cpp \
|
||||||
kernel/qwidgetwindow_qpa.cpp \
|
kernel/qwidgetwindow_qpa.cpp
|
||||||
kernel/qplatformmenu_qpa.cpp
|
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
false:!x11:mac {
|
false:!x11:mac {
|
||||||
@ -75,7 +74,7 @@ false:!x11:mac {
|
|||||||
kernel/qclipboard_mac.cpp \
|
kernel/qclipboard_mac.cpp \
|
||||||
kernel/qmime_mac.cpp \
|
kernel/qmime_mac.cpp \
|
||||||
kernel/qt_mac.cpp \
|
kernel/qt_mac.cpp \
|
||||||
kernel/qkeymapper_mac.cpp
|
kernel/qkeymapper_mac.cpp
|
||||||
|
|
||||||
OBJECTIVE_HEADERS += \
|
OBJECTIVE_HEADERS += \
|
||||||
qcocoawindow_mac_p.h \
|
qcocoawindow_mac_p.h \
|
||||||
|
@ -90,7 +90,8 @@ class Q_WIDGETS_EXPORT QAction : public QObject
|
|||||||
Q_PROPERTY(Priority priority READ priority WRITE setPriority)
|
Q_PROPERTY(Priority priority READ priority WRITE setPriority)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum MenuRole { NoRole, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
|
// note this is copied into qplatformmenu.h, which must stay in sync
|
||||||
|
enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
|
||||||
AboutRole, PreferencesRole, QuitRole };
|
AboutRole, PreferencesRole, QuitRole };
|
||||||
enum SoftKeyRole {
|
enum SoftKeyRole {
|
||||||
NoSoftKey, PositiveSoftKey, NegativeSoftKey, SelectSoftKey };
|
NoSoftKey, PositiveSoftKey, NegativeSoftKey, SelectSoftKey };
|
||||||
|
@ -1,94 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
**
|
|
||||||
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
|
||||||
** Contact: http://www.qt-project.org/
|
|
||||||
**
|
|
||||||
** This file is part of the QtGui module of the Qt Toolkit.
|
|
||||||
**
|
|
||||||
** $QT_BEGIN_LICENSE:LGPL$
|
|
||||||
** GNU Lesser General Public License Usage
|
|
||||||
** This file may be used under the terms of the GNU Lesser General Public
|
|
||||||
** License version 2.1 as published by the Free Software Foundation and
|
|
||||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
|
||||||
** file. Please review the following information to ensure the GNU Lesser
|
|
||||||
** General Public License version 2.1 requirements will be met:
|
|
||||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
||||||
**
|
|
||||||
** In addition, as a special exception, Nokia gives you certain additional
|
|
||||||
** rights. These rights are described in the Nokia Qt 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.
|
|
||||||
**
|
|
||||||
** Other Usage
|
|
||||||
** Alternatively, this file may be used in accordance with the terms and
|
|
||||||
** conditions contained in a signed written agreement between you and Nokia.
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**
|
|
||||||
**
|
|
||||||
** $QT_END_LICENSE$
|
|
||||||
**
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef QPLATFORMMENU_H
|
|
||||||
#define QPLATFORMMENU_H
|
|
||||||
|
|
||||||
#include <QtCore/qglobal.h>
|
|
||||||
#include <QtCore/qpointer.h>
|
|
||||||
#include <QtWidgets/qaction.h>
|
|
||||||
|
|
||||||
QT_BEGIN_HEADER
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
|
|
||||||
class QMenuPrivate;
|
|
||||||
class Q_WIDGETS_EXPORT QPlatformMenuAction
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~QPlatformMenuAction();
|
|
||||||
QPointer<QAction> action;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Q_WIDGETS_EXPORT QPlatformMenu {
|
|
||||||
public:
|
|
||||||
QPlatformMenu();
|
|
||||||
virtual ~QPlatformMenu();
|
|
||||||
|
|
||||||
virtual bool merged(const QAction *action) const = 0;
|
|
||||||
|
|
||||||
virtual void addAction(QAction *action, QAction *before) = 0;
|
|
||||||
virtual void removeAction(QAction *action) = 0;
|
|
||||||
virtual void syncAction(QAction *action) = 0;
|
|
||||||
|
|
||||||
virtual void setMenuEnabled(bool enable);
|
|
||||||
virtual void syncSeparatorsCollapsible(bool enable);
|
|
||||||
};
|
|
||||||
|
|
||||||
class Q_WIDGETS_EXPORT QPlatformMenuBar {
|
|
||||||
public:
|
|
||||||
QPlatformMenuBar();
|
|
||||||
virtual ~QPlatformMenuBar();
|
|
||||||
|
|
||||||
virtual void addAction(QAction *action, QAction *before = 0) = 0;
|
|
||||||
virtual void syncAction(QAction *action) = 0;
|
|
||||||
virtual void removeAction(QAction *action) = 0;
|
|
||||||
|
|
||||||
virtual void handleReparent(QWidget *newParent);
|
|
||||||
};
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
QT_END_HEADER
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -154,7 +154,11 @@ void QMenuPrivate::init()
|
|||||||
scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone;
|
scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
platformMenu = QGuiApplicationPrivate::platformTheme()->createPlatformMenu(q);
|
platformMenu = QGuiApplicationPrivate::platformTheme()->createPlatformMenu();
|
||||||
|
if (platformMenu) {
|
||||||
|
QObject::connect(platformMenu, SIGNAL(aboutToShow()), q, SIGNAL(aboutToShow()));
|
||||||
|
QObject::connect(platformMenu, SIGNAL(aboutToHide()), q, SIGNAL(aboutToHide()));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef QT_SOFTKEYS_ENABLED
|
#ifdef QT_SOFTKEYS_ENABLED
|
||||||
selectAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::SelectSoftKey, Qt::Key_Select, q);
|
selectAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::SelectSoftKey, Qt::Key_Select, q);
|
||||||
@ -2300,7 +2304,7 @@ void QMenu::changeEvent(QEvent *e)
|
|||||||
d->tornPopup->setEnabled(isEnabled());
|
d->tornPopup->setEnabled(isEnabled());
|
||||||
d->menuAction->setEnabled(isEnabled());
|
d->menuAction->setEnabled(isEnabled());
|
||||||
if (d->platformMenu)
|
if (d->platformMenu)
|
||||||
d->platformMenu->setMenuEnabled(isEnabled());
|
d->platformMenu->setEnabled(isEnabled());
|
||||||
}
|
}
|
||||||
QWidget::changeEvent(e);
|
QWidget::changeEvent(e);
|
||||||
}
|
}
|
||||||
@ -2822,6 +2826,25 @@ QMenu::timerEvent(QTimerEvent *e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem* item)
|
||||||
|
{
|
||||||
|
item->setText(action->text());
|
||||||
|
item->setIsSeparator(action->isSeparator());
|
||||||
|
// item->setIcon(action->icon());
|
||||||
|
item->setVisible(action->isVisible());
|
||||||
|
item->setShortcut(action->shortcut());
|
||||||
|
item->setChecked(action->isChecked());
|
||||||
|
item->setFont(action->font());
|
||||||
|
item->setRole((QPlatformMenuItem::MenuRole) action->menuRole());
|
||||||
|
item->setEnabled(action->isEnabled());
|
||||||
|
|
||||||
|
if (action->menu()) {
|
||||||
|
item->setMenu(action->menu()->platformMenu());
|
||||||
|
} else {
|
||||||
|
item->setMenu(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
*/
|
*/
|
||||||
@ -2854,12 +2877,24 @@ void QMenu::actionEvent(QActionEvent *e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (d->platformMenu) {
|
if (d->platformMenu) {
|
||||||
if (e->type() == QEvent::ActionAdded)
|
if (e->type() == QEvent::ActionAdded) {
|
||||||
d->platformMenu->addAction(e->action(), e->before());
|
QPlatformMenuItem *menuItem =
|
||||||
else if (e->type() == QEvent::ActionRemoved)
|
QGuiApplicationPrivate::platformTheme()->createPlatformMenuItem();
|
||||||
d->platformMenu->removeAction(e->action());
|
menuItem->setTag(reinterpret_cast<quintptr>(e->action()));
|
||||||
else if (e->type() == QEvent::ActionChanged)
|
QObject::connect(menuItem, SIGNAL(activated()), e->action(), SLOT(trigger()));
|
||||||
d->platformMenu->syncAction(e->action());
|
copyActionToPlatformItem(e->action(), menuItem);
|
||||||
|
QPlatformMenuItem* beforeItem = d->platformMenu->menuItemForTag(reinterpret_cast<quintptr>(e->before()));
|
||||||
|
d->platformMenu->insertMenuItem(menuItem, beforeItem);
|
||||||
|
} else if (e->type() == QEvent::ActionRemoved) {
|
||||||
|
QPlatformMenuItem *menuItem = d->platformMenu->menuItemForTag(reinterpret_cast<quintptr>(e->action()));
|
||||||
|
d->platformMenu->removeMenuItem(menuItem);
|
||||||
|
} else if (e->type() == QEvent::ActionChanged) {
|
||||||
|
QPlatformMenuItem *menuItem = d->platformMenu->menuItemForTag(reinterpret_cast<quintptr>(e->action()));
|
||||||
|
copyActionToPlatformItem(e->action(), menuItem);
|
||||||
|
d->platformMenu->syncMenuItem(menuItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
d->platformMenu->syncSeparatorsCollapsible(d->collapsibleSeparators);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR)
|
#if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR)
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
#include <qwhatsthis.h>
|
#include <qwhatsthis.h>
|
||||||
#include <qpa/qplatformtheme.h>
|
#include <qpa/qplatformtheme.h>
|
||||||
#include "private/qguiapplication_p.h"
|
#include "private/qguiapplication_p.h"
|
||||||
|
#include "qplatformintegration_qpa.h"
|
||||||
|
|
||||||
#ifndef QT_NO_MENUBAR
|
#ifndef QT_NO_MENUBAR
|
||||||
|
|
||||||
@ -719,7 +720,7 @@ void QMenuBarPrivate::init()
|
|||||||
q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
|
q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
|
||||||
q->setAttribute(Qt::WA_CustomWhatsThis);
|
q->setAttribute(Qt::WA_CustomWhatsThis);
|
||||||
|
|
||||||
platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar(q);
|
platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar();
|
||||||
|
|
||||||
if (platformMenuBar)
|
if (platformMenuBar)
|
||||||
q->hide();
|
q->hide();
|
||||||
@ -1238,6 +1239,14 @@ void QMenuBar::leaveEvent(QEvent *)
|
|||||||
d->setCurrentAction(0);
|
d->setCurrentAction(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPlatformMenu *getPlatformMenu(QAction *action)
|
||||||
|
{
|
||||||
|
if (!action || !action->menu())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return action->menu()->platformMenu();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
*/
|
*/
|
||||||
@ -1254,12 +1263,52 @@ void QMenuBar::actionEvent(QActionEvent *e)
|
|||||||
#endif
|
#endif
|
||||||
if (!nativeMenuBar)
|
if (!nativeMenuBar)
|
||||||
return;
|
return;
|
||||||
if(e->type() == QEvent::ActionAdded)
|
|
||||||
nativeMenuBar->addAction(e->action(), e->before());
|
if (e->type() == QEvent::ActionAdded) {
|
||||||
else if(e->type() == QEvent::ActionRemoved)
|
QPlatformMenu *menu = getPlatformMenu(e->action());
|
||||||
nativeMenuBar->removeAction(e->action());
|
if (menu) {
|
||||||
else if(e->type() == QEvent::ActionChanged)
|
QPlatformMenu* beforeMenu = NULL;
|
||||||
nativeMenuBar->syncAction(e->action());
|
for (int beforeIndex = d->indexOf(e->action()) + 1;
|
||||||
|
!beforeMenu && (beforeIndex < actions().size());
|
||||||
|
++beforeIndex)
|
||||||
|
{
|
||||||
|
beforeMenu = getPlatformMenu(actions().at(beforeIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
menu->setTag(reinterpret_cast<quintptr>(e->action()));
|
||||||
|
menu->setText(e->action()->text());
|
||||||
|
d->platformMenuBar->insertMenu(menu, beforeMenu);
|
||||||
|
}
|
||||||
|
} else if (e->type() == QEvent::ActionRemoved) {
|
||||||
|
QPlatformMenu *menu = getPlatformMenu(e->action());
|
||||||
|
if (menu)
|
||||||
|
d->platformMenuBar->removeMenu(menu);
|
||||||
|
} else if (e->type() == QEvent::ActionChanged) {
|
||||||
|
QPlatformMenu* cur = d->platformMenuBar->menuForTag(reinterpret_cast<quintptr>(e->action()));
|
||||||
|
QPlatformMenu *menu = getPlatformMenu(e->action());
|
||||||
|
|
||||||
|
// the menu associated with the action can change, need to
|
||||||
|
// remove and/or insert the new platform menu
|
||||||
|
if (menu != cur) {
|
||||||
|
if (cur)
|
||||||
|
d->platformMenuBar->removeMenu(cur);
|
||||||
|
if (menu) {
|
||||||
|
menu->setTag(reinterpret_cast<quintptr>(e->action()));
|
||||||
|
|
||||||
|
QPlatformMenu* beforeMenu = NULL;
|
||||||
|
for (int beforeIndex = d->indexOf(e->action()) + 1;
|
||||||
|
!beforeMenu && (beforeIndex < actions().size());
|
||||||
|
++beforeIndex)
|
||||||
|
{
|
||||||
|
beforeMenu = getPlatformMenu(actions().at(beforeIndex));
|
||||||
|
}
|
||||||
|
d->platformMenuBar->insertMenu(menu, beforeMenu);
|
||||||
|
}
|
||||||
|
} else if (menu) {
|
||||||
|
menu->setText(e->action()->text());
|
||||||
|
d->platformMenuBar->syncMenu(menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(e->type() == QEvent::ActionAdded) {
|
if(e->type() == QEvent::ActionAdded) {
|
||||||
@ -1339,8 +1388,17 @@ void QMenuBarPrivate::handleReparent()
|
|||||||
oldParent = newParent;
|
oldParent = newParent;
|
||||||
oldWindow = newWindow;
|
oldWindow = newWindow;
|
||||||
|
|
||||||
if (platformMenuBar)
|
if (platformMenuBar) {
|
||||||
platformMenuBar->handleReparent(newParent);
|
if (newWindow) {
|
||||||
|
// force the underlying platform window to be created, since
|
||||||
|
// the platform menubar needs it (and we have no other way to
|
||||||
|
// discover when the platform window is created)
|
||||||
|
newWindow->createWinId();
|
||||||
|
platformMenuBar->handleReparent(newWindow->windowHandle());
|
||||||
|
} else {
|
||||||
|
platformMenuBar->handleReparent(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_WINCE
|
#ifdef Q_OS_WINCE
|
||||||
if (qt_wince_is_mobile() && wce_menubar)
|
if (qt_wince_is_mobile() && wce_menubar)
|
||||||
@ -1804,7 +1862,7 @@ void QMenuBar::setNativeMenuBar(bool nativeMenuBar)
|
|||||||
d->platformMenuBar = 0;
|
d->platformMenuBar = 0;
|
||||||
} else {
|
} else {
|
||||||
if (!d->platformMenuBar)
|
if (!d->platformMenuBar)
|
||||||
d->platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar(this);
|
d->platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
|
|
||||||
#include "QtWidgets/qstyleoption.h"
|
#include "QtWidgets/qstyleoption.h"
|
||||||
#include <private/qmenu_p.h> // Mac needs what in this file!
|
#include <private/qmenu_p.h> // Mac needs what in this file!
|
||||||
|
#include <qpa/qplatformmenu.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -145,6 +146,8 @@ public:
|
|||||||
QBasicTimer autoReleaseTimer;
|
QBasicTimer autoReleaseTimer;
|
||||||
QPlatformMenuBar *platformMenuBar;
|
QPlatformMenuBar *platformMenuBar;
|
||||||
|
|
||||||
|
inline int indexOf(QAction *act) const { return q_func()->actions().indexOf(act); }
|
||||||
|
|
||||||
#ifdef Q_OS_WINCE
|
#ifdef Q_OS_WINCE
|
||||||
void wceCreateMenuBar(QWidget *);
|
void wceCreateMenuBar(QWidget *);
|
||||||
void wceDestroyMenuBar();
|
void wceDestroyMenuBar();
|
||||||
|
Loading…
Reference in New Issue
Block a user