summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2013-09-18 15:22:48 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-18 15:22:48 +0200
commitd1eb4b192a5a6dcad1a96e23f9224d0a0dc9142e (patch)
tree0cbfae4fa85fb8f10009998f844732d7b8ea6dc8
parentdb242f2c458b87d71056ee71f46a8cd0a1b02a9c (diff)
parent46f3cc477fc00aae887f085e063d6cb10bfdcd4c (diff)
downloadqtquickcontrols-d1eb4b192a5a6dcad1a96e23f9224d0a0dc9142e.tar.gz
Merge "Merge branch 'stable' into dev" into refs/staging/dev
-rw-r--r--examples/quick/controls/gallery/main.qml18
-rw-r--r--src/controls/ApplicationWindow.qml2
-rw-r--r--src/controls/Menu.qml59
-rw-r--r--src/controls/MenuBar.qml62
-rw-r--r--src/controls/Private/qquickstyleitem.cpp3
-rw-r--r--src/controls/SpinBox.qml5
-rw-r--r--src/controls/Styles/Desktop/MenuBarStyle.qml7
-rw-r--r--src/controls/Styles/Desktop/MenuStyle.qml7
-rw-r--r--src/controls/TabView.qml37
-rw-r--r--src/controls/qquickaction.cpp37
-rw-r--r--src/controls/qquickmenu.cpp4
-rw-r--r--src/controls/qquickmenu_p.h4
-rw-r--r--src/controls/qquickmenuitem.cpp9
-rw-r--r--src/controls/qquickmenuitem_p.h3
-rw-r--r--src/controls/qquickmenupopupwindow.cpp28
-rw-r--r--src/controls/qquickmenupopupwindow_p.h3
-rw-r--r--tests/auto/controls/data/tst_spinbox.qml10
-rw-r--r--tests/auto/controls/data/tst_tabview.qml22
18 files changed, 275 insertions, 45 deletions
diff --git a/examples/quick/controls/gallery/main.qml b/examples/quick/controls/gallery/main.qml
index 3da3aa01..4631b37c 100644
--- a/examples/quick/controls/gallery/main.qml
+++ b/examples/quick/controls/gallery/main.qml
@@ -111,20 +111,20 @@ ApplicationWindow {
Action {
id: a1
- text: "Align Left"
+ text: "Align &Left"
checkable: true
Component.onCompleted: checked = true
}
Action {
id: a2
- text: "Center"
+ text: "&Center"
checkable: true
}
Action {
id: a3
- text: "Align Right"
+ text: "Align &Right"
checkable: true
}
}
@@ -138,18 +138,18 @@ ApplicationWindow {
MenuItem { action: pasteAction }
MenuSeparator {}
Menu {
- title: "Text Format"
+ title: "Text &Format"
MenuItem { action: a1 }
MenuItem { action: a2 }
MenuItem { action: a3 }
MenuSeparator { }
- MenuItem { text: "Allow Hyphenation"; checkable: true }
+ MenuItem { text: "Allow &Hyphenation"; checkable: true }
}
Menu {
- title: "Font Style"
- MenuItem { text: "Bold"; checkable: true }
- MenuItem { text: "Italic"; checkable: true }
- MenuItem { text: "Underline"; checkable: true }
+ title: "Font &Style"
+ MenuItem { text: "&Bold"; checkable: true }
+ MenuItem { text: "&Italic"; checkable: true }
+ MenuItem { text: "&Underline"; checkable: true }
}
}
diff --git a/src/controls/ApplicationWindow.qml b/src/controls/ApplicationWindow.qml
index 52acc3f8..dbbfbdaa 100644
--- a/src/controls/ApplicationWindow.qml
+++ b/src/controls/ApplicationWindow.qml
@@ -133,6 +133,8 @@ Window {
id: backgroundItem
anchors.fill: parent
+ Keys.forwardTo: [menuBar.__contentItem]
+
Item {
id: contentArea
anchors.top: toolBarArea.bottom
diff --git a/src/controls/Menu.qml b/src/controls/Menu.qml
index 1e230ea8..4c3bc1be 100644
--- a/src/controls/Menu.qml
+++ b/src/controls/Menu.qml
@@ -133,7 +133,7 @@ MenuPrivate {
property Component style: Qt.createComponent(Settings.style + "/MenuStyle.qml", root)
/*! \internal */
- property var __menuBar: null
+ property var __parentContentItem: __parentMenu.__contentItem
/*! \internal */
property int __currentIndex: -1
/*! \internal */
@@ -144,6 +144,8 @@ MenuPrivate {
sourceComponent: __menuComponent
active: !root.__isNative && root.__popupVisible
focus: true
+ Keys.forwardTo: item ? [item, root.__parentContentItem] : []
+ property bool altPressed: root.__parentContentItem ? root.__parentContentItem.altPressed : false
}
/*! \internal */
@@ -174,14 +176,30 @@ MenuPrivate {
}
focus: true
- Keys.forwardTo: __menuBar ? [__menuBar] : []
+ property var mnemonicsMap: ({})
+
+ Keys.onPressed: {
+ var item = null
+ if (!(event.modifiers & Qt.AltModifier)
+ && (item = mnemonicsMap[event.text.toUpperCase()])) {
+ if (item.isSubmenu) {
+ root.__currentIndex = item.menuItemIndex
+ item.showSubMenu(true)
+ item.menuItem.__currentIndex = 0
+ } else {
+ triggerAndDismiss(item)
+ }
+ event.accepted = true
+ } else {
+ event.accepted = false
+ }
+ }
+
Keys.onEscapePressed: root.__dismissMenu()
Keys.onDownPressed: {
- if (root.__currentIndex < 0) {
- root.__currentIndex = 0
- return
- }
+ if (root.__currentIndex < 0)
+ root.__currentIndex = -1
for (var i = root.__currentIndex + 1;
i < root.items.length && !canBeHovered(i); i++)
@@ -204,13 +222,13 @@ MenuPrivate {
}
Keys.onLeftPressed: {
- if (root.__parentMenu)
+ if ((event.accepted = root.__parentMenu.hasOwnProperty("title")))
__closeMenu()
}
Keys.onRightPressed: {
var item = itemsRepeater.itemAt(root.__currentIndex)
- if (item && item.isSubmenu) {
+ if ((event.accepted = (item && item.isSubmenu))) {
item.showSubMenu(true)
item.menuItem.__currentIndex = 0
}
@@ -220,8 +238,9 @@ MenuPrivate {
Keys.onReturnPressed: menuFrameLoader.triggerAndDismiss()
Keys.onEnterPressed: menuFrameLoader.triggerAndDismiss()
- function triggerAndDismiss() {
- var item = itemsRepeater.itemAt(root.__currentIndex)
+ function triggerAndDismiss(item) {
+ if (!item)
+ item = itemsRepeater.itemAt(root.__currentIndex)
if (item && !item.isSeparator) {
root.__dismissMenu()
if (!item.isSubmenu)
@@ -258,7 +277,15 @@ MenuPrivate {
if (!currentItem || !currentItem.contains(Qt.point(pos.x - currentItem.x, pos.y - currentItem.y))) {
if (currentItem && !pressed && currentItem.isSubmenu)
currentItem.closeSubMenu()
- currentItem = column.childAt(pos.x, pos.y)
+ var itemUnderMouse = column.childAt(pos.x, pos.y)
+ if (itemUnderMouse) {
+ currentItem = itemUnderMouse
+ } else if (currentItem) {
+ var itemItem = currentItem.item
+ if (!itemItem.contains(itemItem.mapFromItem(column, pos)))
+ currentItem = null
+ }
+
if (currentItem) {
root.__currentIndex = currentItem.menuItemIndex
if (currentItem.isSubmenu && !currentItem.menuItem.__popupVisible)
@@ -286,6 +313,7 @@ MenuPrivate {
readonly property bool isSubmenu: !!menuItem && menuItem.type === MenuItemType.Menu
property bool selected: !isSeparator && root.__currentIndex === index
property string text: isSubmenu ? menuItem.title : !isSeparator ? menuItem.text : ""
+ property bool showUnderlined: __contentItem.altPressed
property int menuItemIndex: index
@@ -324,7 +352,14 @@ MenuPrivate {
}
}
- Component.onCompleted: menuItem.__visualItem = menuItemLoader
+ Component.onCompleted: {
+ menuItem.__visualItem = menuItemLoader
+
+ var title = text
+ var ampersandPos = title.indexOf("&")
+ if (ampersandPos !== -1)
+ menuFrameLoader.mnemonicsMap[title[ampersandPos + 1].toUpperCase()] = menuItemLoader
+ }
}
}
diff --git a/src/controls/MenuBar.qml b/src/controls/MenuBar.qml
index 85944d23..0a7585f6 100644
--- a/src/controls/MenuBar.qml
+++ b/src/controls/MenuBar.qml
@@ -82,6 +82,8 @@ MenuBarPrivate {
sourceComponent: __menuBarComponent
active: !root.__isNative
focus: true
+ Keys.forwardTo: [item]
+ property bool altPressed: item ? item.altPressed : false
}
/*! \internal */
@@ -118,7 +120,51 @@ MenuBarPrivate {
value: menuMouseArea.z - 1
}
- focus: openedMenuIndex !== -1
+ focus: true
+
+ property bool altPressed: false
+ property bool altPressedAgain: false
+ property var mnemonicsMap: ({})
+
+ Keys.onPressed: {
+ var action = null
+ if (event.key === Qt.Key_Alt) {
+ if (!altPressed)
+ altPressed = true
+ else
+ altPressedAgain = true
+ } else if (altPressed && (action = mnemonicsMap[event.text.toUpperCase()])) {
+ preselectMenuItem = true
+ action.trigger()
+ event.accepted = true
+ }
+ }
+
+ function dismissActiveFocus(event, reason) {
+ if (reason) {
+ altPressedAgain = false
+ altPressed = false
+ openedMenuIndex = -1
+ root.__contentItem.parent.forceActiveFocus()
+ } else {
+ event.accepted = false
+ }
+ }
+
+ Keys.onReleased: dismissActiveFocus(event, altPressedAgain && openedMenuIndex === -1)
+ Keys.onEscapePressed: dismissActiveFocus(event, openedMenuIndex === -1)
+
+ function maybeOpenFirstMenu(event) {
+ if (altPressed && openedMenuIndex === -1) {
+ preselectMenuItem = true
+ openedMenuIndex = 0
+ } else {
+ event.accepted = false
+ }
+ }
+
+ Keys.onUpPressed: maybeOpenFirstMenu(event)
+ Keys.onDownPressed: maybeOpenFirstMenu(event)
Keys.onLeftPressed: {
if (openedMenuIndex > 0) {
@@ -128,7 +174,7 @@ MenuBarPrivate {
}
Keys.onRightPressed: {
- if (openedMenuIndex < root.menus.length - 1) {
+ if (openedMenuIndex !== -1 && openedMenuIndex < root.menus.length - 1) {
preselectMenuItem = true
openedMenuIndex++
}
@@ -179,6 +225,7 @@ MenuBarPrivate {
property var menuItem: modelData
property bool selected: menuMouseArea.hoveredItem === menuItemLoader
property bool sunken: menuItem.__popupVisible || menuBarLoader.openedMenuIndex === index
+ property bool showUnderlined: menuBarLoader.altPressed
sourceComponent: menuBarLoader.menuItemStyle
property int menuItemIndex: index
@@ -208,9 +255,18 @@ MenuBarPrivate {
}
}
+ Connections {
+ target: menuItem.__action
+ onTriggered: menuBarLoader.openedMenuIndex = menuItemIndex
+ }
+
Component.onCompleted: {
menuItem.__visualItem = menuItemLoader
- menuItem.__menuBar = menuBarLoader
+
+ var title = menuItem.title
+ var ampersandPos = title.indexOf("&")
+ if (ampersandPos !== -1)
+ menuBarLoader.mnemonicsMap[title[ampersandPos + 1].toUpperCase()] = menuItem.__action
}
}
}
diff --git a/src/controls/Private/qquickstyleitem.cpp b/src/controls/Private/qquickstyleitem.cpp
index 50a48f0e..4101f90f 100644
--- a/src/controls/Private/qquickstyleitem.cpp
+++ b/src/controls/Private/qquickstyleitem.cpp
@@ -318,7 +318,6 @@ void QQuickStyleItem::initStyleOption()
if (!m_styleoption)
m_styleoption = new QStyleOptionTab();
-
QStyleOptionTab *opt = qstyleoption_cast<QStyleOptionTab*>(m_styleoption);
opt->text = text();
@@ -396,6 +395,7 @@ void QQuickStyleItem::initStyleOption()
QStyleOptionMenuItem *opt = qstyleoption_cast<QStyleOptionMenuItem*>(m_styleoption);
opt->text = text();
opt->menuItemType = QStyleOptionMenuItem::Normal;
+ setProperty("_q_showUnderlined", m_hints["showUnderlined"].toBool());
if (const QFont *font = QGuiApplicationPrivate::platformTheme()->font(QPlatformTheme::MenuBarFont)) {
opt->font = *font;
@@ -443,6 +443,7 @@ void QQuickStyleItem::initStyleOption()
}
if (m_properties["icon"].canConvert<QIcon>())
opt->icon = m_properties["icon"].value<QIcon>();
+ setProperty("_q_showUnderlined", m_hints["showUnderlined"].toBool());
if (const QFont *font = QGuiApplicationPrivate::platformTheme()->font(m_itemType == ComboBoxItem ? QPlatformTheme::ComboMenuItemFont : QPlatformTheme::MenuFont)) {
opt->font = *font;
diff --git a/src/controls/SpinBox.qml b/src/controls/SpinBox.qml
index 473fe6db..b062ffe5 100644
--- a/src/controls/SpinBox.qml
+++ b/src/controls/SpinBox.qml
@@ -229,8 +229,9 @@ Control {
validator: SpinBoxValidator {
id: validator
- onTextChanged: input.text = validator.text
- Component.onCompleted: input.text = validator.text
+ property bool ready: false // Delay validation until all properties are ready
+ onTextChanged: if (ready) input.text = validator.text
+ Component.onCompleted: {input.text = validator.text ; ready = true}
}
onAccepted: {
input.text = validator.text
diff --git a/src/controls/Styles/Desktop/MenuBarStyle.qml b/src/controls/Styles/Desktop/MenuBarStyle.qml
index 41098972..a8b389c1 100644
--- a/src/controls/Styles/Desktop/MenuBarStyle.qml
+++ b/src/controls/Styles/Desktop/MenuBarStyle.qml
@@ -51,6 +51,8 @@ Style {
width: implicitWidth + 2 * (pixelMetric("menubarhmargin") + pixelMetric("menubarpanelwidth"))
height: implicitHeight + 2 * (pixelMetric("menubarvmargin") + pixelMetric("menubarpanelwidth"))
+ pixelMetric("spacebelowmenubar")
+
+ Accessible.role: Accessible.MenuBar
}
property Component menuItem: StyleItem {
@@ -66,5 +68,10 @@ Style {
enabled: menuItem.enabled
selected: (parent && parent.selected) || sunken
sunken: parent && parent.sunken
+
+ hints: { "showUnderlined": showUnderlined }
+
+ Accessible.role: Accessible.MenuItem
+ Accessible.name: StyleHelpers.removeMnemonics(text)
}
}
diff --git a/src/controls/Styles/Desktop/MenuStyle.qml b/src/controls/Styles/Desktop/MenuStyle.qml
index 2e3296b6..b1f5e9cf 100644
--- a/src/controls/Styles/Desktop/MenuStyle.qml
+++ b/src/controls/Styles/Desktop/MenuStyle.qml
@@ -65,6 +65,8 @@ Style {
}
color: __syspal.window
}
+
+ Accessible.role: Accessible.PopupMenu
}
property Component menuItem: StyleItem {
@@ -81,6 +83,8 @@ Style {
selected: !!parent && parent.selected
on: !!menuItem && !!menuItem["checkable"] && menuItem.checked
+ hints: { "showUnderlined": showUnderlined }
+
properties: {
"checkable": !!menuItem && !!menuItem["checkable"],
"exclusive": !!menuItem && !!menuItem["exclusiveGroup"],
@@ -88,5 +92,8 @@ Style {
"isSubmenu": isSubmenu,
"icon": !!menuItem && menuItem.__icon
}
+
+ Accessible.role: Accessible.MenuItem
+ Accessible.name: StyleHelpers.removeMnemonics(text)
}
}
diff --git a/src/controls/TabView.qml b/src/controls/TabView.qml
index e8dd9be8..696c6b3f 100644
--- a/src/controls/TabView.qml
+++ b/src/controls/TabView.qml
@@ -95,12 +95,16 @@ FocusScope {
Returns the newly added tab.
*/
function insertTab(index, title, component) {
- var tab = tabcomp.createObject(stack)
+ // 'loader' parent is a pending workaround while waiting for:
+ // https://codereview.qt-project.org/#change,65788
+ var tab = tabcomp.createObject(loader)
tab.sourceComponent = component
- tab.parent = stack
tab.title = title
- tab.__inserted = true
+ // insert at appropriate index first, then set the parent to
+ // avoid onChildrenChanged appending it to the end of the list
__tabs.insert(index, {tab: tab})
+ tab.__inserted = true
+ tab.parent = stack
__setOpacities()
return tab
}
@@ -203,8 +207,17 @@ FocusScope {
property int frameWidth
property string style
+ property bool completed: false
- Component.onCompleted: addTabs(stack.children)
+ Component.onCompleted: {
+ addTabs(stack.children)
+ completed = true
+ }
+
+ onChildrenChanged: {
+ if (completed)
+ stack.addTabs(stack.children)
+ }
function addTabs(tabs) {
var tabAdded = false
@@ -212,12 +225,11 @@ FocusScope {
var tab = tabs[i]
if (!tab.__inserted && tab.Accessible.role === Accessible.LayeredPane) {
tab.__inserted = true
- if (tab.parent === root) {
- tab.parent = stack
- // a tab added dynamically by Component::createObject() and passing the
- // tab view as a parent should also get automatically removed when destructed
+ // reparent tabs created dynamically by createObject(tabView)
+ tab.parent = stack
+ // a dynamically added tab should also get automatically removed when destructed
+ if (completed)
tab.Component.onDestruction.connect(stack.onDynamicTabDestroyed.bind(tab))
- }
__tabs.append({tab: tab})
tabAdded = true
}
@@ -227,9 +239,10 @@ FocusScope {
}
function onDynamicTabDestroyed() {
- for (var i = 0; i < stack.children.length; ++i) {
- if (this === stack.children[i]) {
- root.removeTab(i)
+ for (var i = 0; i < __tabs.count; ++i) {
+ if (__tabs.get(i).tab === this) {
+ __tabs.remove(i, 1)
+ __setOpacities()
break
}
}
diff --git a/src/controls/qquickaction.cpp b/src/controls/qquickaction.cpp
index cfd0b4fa..0d77eb32 100644
--- a/src/controls/qquickaction.cpp
+++ b/src/controls/qquickaction.cpp
@@ -41,6 +41,7 @@
#include "qquickaction_p.h"
#include "qquickexclusivegroup_p.h"
+#include "qquickmenuitem_p.h"
#include <QtGui/qguiapplication.h>
#include <QtQuick/qquickitem.h>
@@ -214,6 +215,8 @@ void QQuickAction::setText(const QString &text)
emit textChanged();
}
+namespace {
+
bool qShortcutContextMatcher(QObject *o, Qt::ShortcutContext context)
{
switch (context) {
@@ -237,6 +240,38 @@ bool qShortcutContextMatcher(QObject *o, Qt::ShortcutContext context)
return false;
}
+bool qMnemonicContextMatcher(QObject *o, Qt::ShortcutContext context)
+{
+ switch (context) {
+ case Qt::ApplicationShortcut:
+ return true;
+ case Qt::WindowShortcut: {
+ QObject *w = o;
+ while (w && !w->isWindowType()) {
+ w = w->parent();
+ if (QQuickItem * item = qobject_cast<QQuickItem*>(w))
+ w = item->window();
+ else if (QQuickMenuBase *mb = qobject_cast<QQuickMenuBase *>(w)) {
+ QQuickItem *vi = mb->visualItem();
+ if (vi && vi->isVisible())
+ w = vi->window();
+ else
+ break; // Non visible menu objects don't get mnemonic match
+ }
+ }
+ if (w && w == QGuiApplication::focusWindow())
+ return true;
+ }
+ case Qt::WidgetShortcut:
+ case Qt::WidgetWithChildrenShortcut:
+ break;
+ }
+
+ return false;
+}
+
+} // namespace
+
QVariant QQuickAction::shortcut() const
{
return m_shortcut.toString(QKeySequence::NativeText);
@@ -278,7 +313,7 @@ void QQuickAction::setMnemonicFromText(const QString &text)
if (!m_mnemonic.isEmpty()) {
Qt::ShortcutContext context = Qt::WindowShortcut;
- QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(this, m_mnemonic, context, qShortcutContextMatcher);
+ QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(this, m_mnemonic, context, qMnemonicContextMatcher);
}
}
diff --git a/src/controls/qquickmenu.cpp b/src/controls/qquickmenu.cpp
index b4ceb730..62e7a7bd 100644
--- a/src/controls/qquickmenu.cpp
+++ b/src/controls/qquickmenu.cpp
@@ -404,8 +404,10 @@ void QQuickMenu::__popup(qreal x, qreal y, int atItemIndex)
void QQuickMenu::setMenuContentItem(QQuickItem *item)
{
- if (m_menuContentItem != item)
+ if (m_menuContentItem != item) {
m_menuContentItem = item;
+ emit menuContentItemChanged();
+ }
}
void QQuickMenu::setPopupVisible(bool v)
diff --git a/src/controls/qquickmenu_p.h b/src/controls/qquickmenu_p.h
index 54f7451b..f15e6caa 100644
--- a/src/controls/qquickmenu_p.h
+++ b/src/controls/qquickmenu_p.h
@@ -68,11 +68,12 @@ class QQuickMenu : public QQuickMenuText
Q_PROPERTY(int __selectedIndex READ selectedIndex WRITE setSelectedIndex NOTIFY __selectedIndexChanged)
Q_PROPERTY(bool __popupVisible READ popupVisible NOTIFY popupVisibleChanged)
- Q_PROPERTY(QQuickItem *__contentItem READ menuContentItem WRITE setMenuContentItem)
+ Q_PROPERTY(QQuickItem *__contentItem READ menuContentItem WRITE setMenuContentItem NOTIFY menuContentItemChanged)
Q_PROPERTY(int __minimumWidth READ minimumWidth WRITE setMinimumWidth)
Q_PROPERTY(QFont __font READ font WRITE setFont)
Q_PROPERTY(qreal __xOffset READ xOffset WRITE setXOffset)
Q_PROPERTY(qreal __yOffset READ yOffset WRITE setYOffset)
+ Q_PROPERTY(QQuickAction *__action READ action CONSTANT)
public:
Q_INVOKABLE void popup();
@@ -98,6 +99,7 @@ Q_SIGNALS:
void __selectedIndexChanged();
void __menuClosed();
void popupVisibleChanged();
+ void menuContentItemChanged();
public:
QQuickMenu(QObject *parent = 0);
diff --git a/src/controls/qquickmenuitem.cpp b/src/controls/qquickmenuitem.cpp
index a6325020..b9475e97 100644
--- a/src/controls/qquickmenuitem.cpp
+++ b/src/controls/qquickmenuitem.cpp
@@ -55,6 +55,8 @@ QQuickMenuBase::QQuickMenuBase(QObject *parent)
: QObject(parent), m_visible(true), m_parentMenu(0), m_container(0), m_visualItem(0)
{
m_platformItem = QGuiApplicationPrivate::platformTheme()->createPlatformMenuItem();
+ if (m_platformItem)
+ m_platformItem->setRole(QPlatformMenuItem::TextHeuristicRole);
}
QQuickMenuBase::~QQuickMenuBase()
@@ -82,6 +84,13 @@ void QQuickMenuBase::setVisible(bool v)
}
}
+QObject *QQuickMenuBase::parentMenuOrMenuBar() const
+{
+ if (!m_parentMenu)
+ return parent();
+ return m_parentMenu;
+}
+
QQuickMenu *QQuickMenuBase::parentMenu() const
{
return m_parentMenu;
diff --git a/src/controls/qquickmenuitem_p.h b/src/controls/qquickmenuitem_p.h
index 2751c25b..a0c70832 100644
--- a/src/controls/qquickmenuitem_p.h
+++ b/src/controls/qquickmenuitem_p.h
@@ -78,7 +78,7 @@ class QQuickMenuBase: public QObject
Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
Q_PROPERTY(QQuickMenuItemType::MenuItemType type READ type CONSTANT)
- Q_PROPERTY(QQuickMenu *__parentMenu READ parentMenu CONSTANT)
+ Q_PROPERTY(QObject *__parentMenu READ parentMenuOrMenuBar CONSTANT)
Q_PROPERTY(bool __isNative READ isNative CONSTANT)
Q_PROPERTY(QQuickItem *__visualItem READ visualItem WRITE setVisualItem)
@@ -93,6 +93,7 @@ public:
virtual void setVisible(bool);
QQuickMenu *parentMenu() const;
+ QObject *parentMenuOrMenuBar() const;
virtual void setParentMenu(QQuickMenu *parentMenu);
QQuickMenuItemContainer *container() const;
diff --git a/src/controls/qquickmenupopupwindow.cpp b/src/controls/qquickmenupopupwindow.cpp
index 19d85de0..a1839296 100644
--- a/src/controls/qquickmenupopupwindow.cpp
+++ b/src/controls/qquickmenupopupwindow.cpp
@@ -42,14 +42,15 @@
#include "qquickmenupopupwindow_p.h"
#include <qguiapplication.h>
+#include <qpa/qwindowsysteminterface.h>
#include <qquickitem.h>
#include <QtGui/QScreen>
QT_BEGIN_NAMESPACE
QQuickMenuPopupWindow::QQuickMenuPopupWindow(QWindow *parent) :
- QQuickWindow(parent), m_mouseMoved(false), m_itemAt(0),
- m_parentItem(0), m_menuContentItem(0)
+ QQuickWindow(parent), m_mouseMoved(false), m_needsActivatedEvent(true),
+ m_itemAt(0), m_parentItem(0), m_menuContentItem(0)
{
setFlags(Qt::Popup);
setModality(Qt::WindowModal);
@@ -241,4 +242,27 @@ void QQuickMenuPopupWindow::forwardEventToTransientParent(QMouseEvent *e)
}
}
+void QQuickMenuPopupWindow::exposeEvent(QExposeEvent *e)
+{
+ if (isExposed() && m_needsActivatedEvent) {
+ m_needsActivatedEvent = false;
+ QWindowSystemInterface::handleWindowActivated(this, Qt::PopupFocusReason);
+ } else if (!isExposed() && !m_needsActivatedEvent) {
+ m_needsActivatedEvent = true;
+ if (QWindow *tp = transientParent())
+ QWindowSystemInterface::handleWindowActivated(tp, Qt::PopupFocusReason);
+ }
+ QQuickWindow::exposeEvent(e);
+}
+
+void QQuickMenuPopupWindow::hideEvent(QHideEvent *e)
+{
+ if (QWindow *tp = !m_needsActivatedEvent ? transientParent() : 0) {
+ m_needsActivatedEvent = true;
+ QWindowSystemInterface::handleWindowActivated(tp, Qt::PopupFocusReason);
+ }
+
+ QQuickWindow::hideEvent(e);
+}
+
QT_END_NAMESPACE
diff --git a/src/controls/qquickmenupopupwindow_p.h b/src/controls/qquickmenupopupwindow_p.h
index 30a71fb2..4407fdec 100644
--- a/src/controls/qquickmenupopupwindow_p.h
+++ b/src/controls/qquickmenupopupwindow_p.h
@@ -81,11 +81,14 @@ protected:
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
+ void exposeEvent(QExposeEvent *);
+ void hideEvent(QHideEvent *);
private:
void forwardEventToTransientParent(QMouseEvent *);
bool m_mouseMoved;
+ bool m_needsActivatedEvent;
QQuickItem *m_itemAt;
QPointF m_oldItemPos;
QQuickItem *m_parentItem;
diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml
index df7a5eb1..67dd3dba 100644
--- a/tests/auto/controls/data/tst_spinbox.qml
+++ b/tests/auto/controls/data/tst_spinbox.qml
@@ -87,6 +87,16 @@ Item {
spinbox.destroy()
}
+ function test_initial_value() {
+ var spinbox = Qt.createQmlObject('import QtQuick.Controls 1.0; SpinBox {decimals: 3 ; value: 0.25}', container, '')
+ compare(spinbox.value, 0.25)
+ spinbox.destroy()
+
+ spinbox = Qt.createQmlObject('import QtQuick.Controls 1.0; SpinBox {value: 0.25 ; decimals: 3}', container, '')
+ compare(spinbox.value, 0.25)
+ spinbox.destroy()
+ }
+
function test_keyboard_input_data() {
return [
{tag: "1", input: [Qt.Key_1], value: 1},
diff --git a/tests/auto/controls/data/tst_tabview.qml b/tests/auto/controls/data/tst_tabview.qml
index 980b1f16..9405f793 100644
--- a/tests/auto/controls/data/tst_tabview.qml
+++ b/tests/auto/controls/data/tst_tabview.qml
@@ -223,6 +223,28 @@ TestCase {
tabView.destroy()
}
+ function test_dynamicModel() {
+ var test_tabView = ' \
+ import QtQuick 2.1; \
+ import QtQuick.Controls 1.0; \
+ TabView { \
+ id: tabView; \
+ property alias repeater: repeater; \
+ Repeater { id: repeater; Tab { } } \
+ } '
+
+ var tabView = Qt.createQmlObject(test_tabView, testCase, '')
+ compare(tabView.count, 0)
+
+ tabView.repeater.model = 4
+ compare(tabView.count, 4)
+
+ tabView.repeater.model = 0
+ compare(tabView.count, 0)
+
+ tabView.destroy()
+ }
+
function test_mousePressOnTabBar() {
var test_tabView = 'import QtQuick 2.1; \
import QtQuick.Controls 1.1; \