diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/controls/MenuBar.qml | 27 | ||||
| -rw-r--r-- | src/controls/Styles/Base/MenuBarStyle.qml | 3 | ||||
| -rw-r--r-- | src/controls/qquickmenubar.cpp | 19 | ||||
| -rw-r--r-- | src/controls/qquickmenubar_p.h | 7 |
4 files changed, 39 insertions, 17 deletions
diff --git a/src/controls/MenuBar.qml b/src/controls/MenuBar.qml index 1896151f4..52b9cb423 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 66b3e10a7..11b8069c5 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 daf647dce..d3503f89c 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 fe62e4d0a..50a3cd4b3 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 *); |
