summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2014-09-12 13:53:46 +0200
committerJ-P Nurmi <jpnurmi@digia.com>2014-09-15 11:42:48 +0200
commit238af2de1322007d0b74a9c9174e00024bf1cc1c (patch)
treecaaa2864a18603d47127312680c49207ead44013
parent84d99bccfb7c627d83abe3c52a5a9d035f90c8d1 (diff)
downloadqtquickcontrols-238af2de1322007d0b74a9c9174e00024bf1cc1c.tar.gz
Let MenuBarStyle control whether a native menubar is used
Change-Id: I1daecf82421ffa330d050430d6e54e4cc0122913 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
-rw-r--r--src/controls/MenuBar.qml27
-rw-r--r--src/controls/Styles/Base/MenuBarStyle.qml3
-rw-r--r--src/controls/qquickmenubar.cpp19
-rw-r--r--src/controls/qquickmenubar_p.h7
4 files changed, 39 insertions, 17 deletions
diff --git a/src/controls/MenuBar.qml b/src/controls/MenuBar.qml
index 1896151f..52b9cb42 100644
--- a/src/controls/MenuBar.qml
+++ b/src/controls/MenuBar.qml
@@ -84,6 +84,11 @@ MenuBarPrivate {
property Component style: Qt.createComponent(Settings.style + "/MenuBarStyle.qml", root)
/*! \internal */
+ property QtObject __style: styleLoader.item
+
+ __isNative: !__style.hasOwnProperty("__isNative") || __style.__isNative
+
+ /*! \internal */
__contentItem: Loader {
id: topLoader
sourceComponent: __menuBarComponent
@@ -92,6 +97,16 @@ MenuBarPrivate {
Keys.forwardTo: [item]
width: parent && active ? parent.width : 0
property bool altPressed: item ? item.__altPressed : false
+
+ Loader {
+ id: styleLoader
+ property alias __control: topLoader.item
+ sourceComponent: root.style
+ onStatusChanged: {
+ if (status === Loader.Error)
+ console.error("Failed to load Style for", root)
+ }
+ }
}
/*! \internal */
@@ -104,16 +119,6 @@ MenuBarPrivate {
visible: status === Loader.Ready
sourceComponent: d.style ? d.style.background : undefined
- Loader {
- id: styleLoader
- property alias __control: menuBarLoader
- sourceComponent: root.style
- onStatusChanged: {
- if (status === Loader.Error)
- console.error("Failed to load Style for", root)
- }
- }
-
width: root.__contentItem.width
height: Math.max(row.height + d.heightPadding, item ? item.implicitHeight : 0)
@@ -127,7 +132,7 @@ MenuBarPrivate {
QtObject {
id: d
- property Style style: styleLoader.item
+ property Style style: __style
property int openedMenuIndex: -1
property bool preselectMenuItem: false
diff --git a/src/controls/Styles/Base/MenuBarStyle.qml b/src/controls/Styles/Base/MenuBarStyle.qml
index 66b3e10a..11b8069c 100644
--- a/src/controls/Styles/Base/MenuBarStyle.qml
+++ b/src/controls/Styles/Base/MenuBarStyle.qml
@@ -124,4 +124,7 @@ Style {
The font of the control.
*/
property font font
+
+ /*! \internal */
+ property bool __isNative: true
}
diff --git a/src/controls/qquickmenubar.cpp b/src/controls/qquickmenubar.cpp
index daf647dc..d3503f89 100644
--- a/src/controls/qquickmenubar.cpp
+++ b/src/controls/qquickmenubar.cpp
@@ -63,9 +63,8 @@ QT_BEGIN_NAMESPACE
*/
QQuickMenuBar::QQuickMenuBar(QObject *parent)
- : QObject(parent), m_contentItem(0), m_parentWindow(0)
+ : QObject(parent), m_platformMenuBar(0), m_contentItem(0), m_parentWindow(0)
{
- m_platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar();
}
QQuickMenuBar::~QQuickMenuBar()
@@ -77,11 +76,25 @@ QQmlListProperty<QQuickMenu> QQuickMenuBar::menus()
return QQmlListProperty<QQuickMenu>(this, 0, &QQuickMenuBar::append_menu, &QQuickMenuBar::count_menu, &QQuickMenuBar::at_menu, 0);
}
-bool QQuickMenuBar::isNative()
+bool QQuickMenuBar::isNative() const
{
return m_platformMenuBar != 0;
}
+void QQuickMenuBar::setNative(bool native)
+{
+ bool wasNative = isNative();
+ if (native) {
+ if (!m_platformMenuBar)
+ m_platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar();
+ } else {
+ delete m_platformMenuBar;
+ m_platformMenuBar = 0;
+ }
+ if (isNative() != wasNative)
+ emit nativeChanged();
+}
+
void QQuickMenuBar::setContentItem(QQuickItem *item)
{
if (item != m_contentItem) {
diff --git a/src/controls/qquickmenubar_p.h b/src/controls/qquickmenubar_p.h
index fe62e4d0..50a3cd4b 100644
--- a/src/controls/qquickmenubar_p.h
+++ b/src/controls/qquickmenubar_p.h
@@ -53,11 +53,11 @@ class QQuickMenuBar: public QObject
Q_PROPERTY(QQuickItem *__contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged)
Q_PROPERTY(QQuickWindow *__parentWindow READ parentWindow WRITE setParentWindow)
- Q_PROPERTY(bool __isNative READ isNative CONSTANT)
+ Q_PROPERTY(bool __isNative READ isNative WRITE setNative NOTIFY nativeChanged)
Q_SIGNALS:
void menusChanged();
-
+ void nativeChanged();
void contentItemChanged();
public:
@@ -66,7 +66,8 @@ public:
QQmlListProperty<QQuickMenu> menus();
- bool isNative();
+ bool isNative() const;
+ void setNative(bool native);
QQuickItem *contentItem() const { return m_contentItem; }
void setContentItem(QQuickItem *);