summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-04-15 09:28:09 +0200
committerLiang Qi <liang.qi@theqtcompany.com>2015-04-15 09:28:09 +0200
commitcb6ccf9fee26c5a2b7f3946b7ffc05430b7be3ff (patch)
tree6de74ca46c389328696831bcc74cd5aff6756fee
parentded73ee2ae8aa333894ab11ce2297e755ec03f3e (diff)
parentde9145dcd904068256e28e130fdfda2e8014efe8 (diff)
Merge remote-tracking branch 'origin/5.4' into 5.5
Conflicts: src/controls/qquickmenupopupwindow_p.h Change-Id: Ic935bb56f5df70645eea30c890759f5980d68fe4
-rw-r--r--src/controls/ComboBox.qml1
-rw-r--r--src/controls/Menu.qml17
-rw-r--r--src/controls/MenuBar.qml9
-rw-r--r--src/controls/Private/EditMenu_base.qml6
-rw-r--r--src/controls/Private/MenuContentItem.qml15
-rw-r--r--src/controls/qquickmenu.cpp46
-rw-r--r--src/controls/qquickmenu_p.h5
-rw-r--r--src/controls/qquickmenupopupwindow.cpp15
-rw-r--r--src/controls/qquickmenupopupwindow_p.h5
9 files changed, 91 insertions, 28 deletions
diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml
index 7de1b7385..509a4b3d8 100644
--- a/src/controls/ComboBox.qml
+++ b/src/controls/ComboBox.qml
@@ -626,6 +626,7 @@ Control {
function toggleShow() {
if (popup.__popupVisible) {
popup.__dismissMenu()
+ popup.__destroyAllMenuPopups()
} else {
if (items[__selectedIndex])
items[__selectedIndex].checked = true
diff --git a/src/controls/Menu.qml b/src/controls/Menu.qml
index 0cee85a6a..b85008eb4 100644
--- a/src/controls/Menu.qml
+++ b/src/controls/Menu.qml
@@ -151,13 +151,24 @@ MenuPrivate {
property int __currentIndex: -1
/*! \internal */
on__MenuClosed: __currentIndex = -1
+ on__MenuPopupDestroyed: contentLoader.active = false
+ onPopupVisibleChanged: {
+ if (__popupVisible)
+ contentLoader.active = true
+ }
/*! \internal */
__contentItem: Loader {
- sourceComponent: MenuContentItem {
- __menu: root
+ id: contentLoader
+ Component {
+ id: menuContent
+ MenuContentItem {
+ __menu: root
+ }
}
- active: !root.__isNative && root.__popupVisible
+
+ sourceComponent: root.__isNative ? null : menuContent
+ active: false
focus: true
Keys.forwardTo: item ? [item, root.__parentContentItem] : []
property bool altPressed: root.__parentContentItem ? root.__parentContentItem.altPressed : false
diff --git a/src/controls/MenuBar.qml b/src/controls/MenuBar.qml
index f1f702f6e..86a345faf 100644
--- a/src/controls/MenuBar.qml
+++ b/src/controls/MenuBar.qml
@@ -198,7 +198,7 @@ MenuBarPrivate {
Keys.onLeftPressed: {
if (d.openedMenuIndex > 0) {
var idx = d.openedMenuIndex - 1
- while (idx >= 0 && !root.menus[idx].enabled)
+ while (idx >= 0 && !(root.menus[idx].enabled && root.menus[idx].visible))
idx--
if (idx >= 0) {
d.preselectMenuItem = true
@@ -212,7 +212,7 @@ MenuBarPrivate {
Keys.onRightPressed: {
if (d.openedMenuIndex !== -1 && d.openedMenuIndex < root.menus.length - 1) {
var idx = d.openedMenuIndex + 1
- while (idx < root.menus.length && !root.menus[idx].enabled)
+ while (idx < root.menus.length && !(root.menus[idx].enabled && root.menus[idx].visible))
idx++
if (idx < root.menus.length) {
d.preselectMenuItem = true
@@ -266,8 +266,9 @@ MenuBarPrivate {
menuBarLoader.height - d.heightPadding, 0, 0), 0)
if (d.preselectMenuItem)
__menuItem.__currentIndex = 0
- } else {
- __menuItem.__closeMenu()
+ } else if (__menuItem.__popupVisible) {
+ __menuItem.__dismissMenu()
+ __menuItem.__destroyAllMenuPopups()
}
}
}
diff --git a/src/controls/Private/EditMenu_base.qml b/src/controls/Private/EditMenu_base.qml
index c242e596e..e44ff5992 100644
--- a/src/controls/Private/EditMenu_base.qml
+++ b/src/controls/Private/EditMenu_base.qml
@@ -160,9 +160,11 @@ Item {
input.activate()
if (control.menu) {
- getMenuInstance().__dismissMenu();
+ var menu = getMenuInstance();
+ menu.__dismissMenu();
+ menu.__destroyAllMenuPopups();
var menuPos = mapToItem(null, mouse.x, mouse.y)
- getMenuInstance().__popup(Qt.rect(menuPos.x, menuPos.y, 0, 0), -1, MenuPrivate.EditMenu);
+ menu.__popup(Qt.rect(menuPos.x, menuPos.y, 0, 0), -1, MenuPrivate.EditMenu);
}
}
}
diff --git a/src/controls/Private/MenuContentItem.qml b/src/controls/Private/MenuContentItem.qml
index 62b8d1cb7..6006f8d89 100644
--- a/src/controls/Private/MenuContentItem.qml
+++ b/src/controls/Private/MenuContentItem.qml
@@ -41,7 +41,7 @@ import QtQuick.Controls.Styles 1.1
Loader {
id: menuFrameLoader
- property var __menu: root
+ property var __menu
visible: status === Loader.Ready
width: content.width + (d.style ? d.style.padding.left + d.style.padding.right : 0)
@@ -67,7 +67,7 @@ Loader {
function canBeHovered(index) {
var item = content.menuItemAt(index)
- if (item && item.styleData.type !== MenuItemType.Separator && item.styleData.enabled) {
+ if (item && item.visible && item.styleData.type !== MenuItemType.Separator && item.styleData.enabled) {
__menu.__currentIndex = index
return true
}
@@ -85,6 +85,7 @@ Loader {
__menu.__dismissMenu()
if (item.styleData.type !== MenuItemType.Menu)
item.__menuItem.trigger()
+ __menu.__destroyAllMenuPopups()
}
}
}
@@ -128,8 +129,10 @@ Loader {
}
Keys.onLeftPressed: {
- if ((event.accepted = __menu.__parentMenu.hasOwnProperty("title")))
- __closeMenu()
+ if ((event.accepted = __menu.__parentMenu.hasOwnProperty("title"))) {
+ __menu.__closeMenu()
+ __menu.__destroyMenuPopup()
+ }
}
Keys.onRightPressed: {
@@ -227,8 +230,10 @@ Loader {
id: closeMenuTimer
interval: 1
onTriggered: {
- if (__menu.__currentIndex !== __menuItemIndex)
+ if (__menu.__currentIndex !== __menuItemIndex) {
__menuItem.__closeMenu()
+ __menuItem.__destroyMenuPopup()
+ }
}
}
diff --git a/src/controls/qquickmenu.cpp b/src/controls/qquickmenu.cpp
index b55675236..c476c5f32 100644
--- a/src/controls/qquickmenu.cpp
+++ b/src/controls/qquickmenu.cpp
@@ -431,6 +431,7 @@ void QQuickMenu::__popup(const QRectF &targetRect, int atItemIndex, MenuType men
connect(m_popupWindow, SIGNAL(visibleChanged(bool)), this, SLOT(windowVisibleChanged(bool)));
connect(m_popupWindow, SIGNAL(geometryChanged()), this, SIGNAL(__popupGeometryChanged()));
+ connect(m_popupWindow, SIGNAL(willBeDeletedLater()), this, SLOT(clearPopupWindow()));
m_popupWindow->setPosition(targetRect.x() + m_xOffset + renderOffset.x(),
targetRect.y() + targetRect.height() + m_yOffset + renderOffset.y());
@@ -471,34 +472,57 @@ void QQuickMenu::__closeMenu()
emit __menuClosed();
}
+QQuickMenuPopupWindow *QQuickMenu::topMenuPopup() const
+{
+ QQuickMenuPopupWindow *topMenuWindow = m_popupWindow;
+ while (topMenuWindow) {
+ QQuickMenuPopupWindow *pw = qobject_cast<QQuickMenuPopupWindow *>(topMenuWindow->transientParent());
+ if (!pw)
+ return topMenuWindow;
+ topMenuWindow = pw;
+ }
+
+ return 0;
+}
+
void QQuickMenu::__dismissMenu()
{
if (m_platformMenu) {
m_platformMenu->dismiss();
- } else {
- QQuickMenuPopupWindow *topMenuWindow = m_popupWindow;
- while (topMenuWindow) {
- QQuickMenuPopupWindow *pw = qobject_cast<QQuickMenuPopupWindow *>(topMenuWindow->transientParent());
- if (!pw)
- topMenuWindow->dismissPopup();
- topMenuWindow = pw;
- }
+ } else if (QQuickMenuPopupWindow *topPopup = topMenuPopup()) {
+ topPopup->dismissPopup();
}
}
void QQuickMenu::windowVisibleChanged(bool v)
{
if (!v) {
- if (qobject_cast<QQuickMenuPopupWindow *>(m_popupWindow->transientParent())) {
+ if (m_popupWindow && qobject_cast<QQuickMenuPopupWindow *>(m_popupWindow->transientParent())) {
m_popupWindow->transientParent()->setMouseGrabEnabled(true);
m_popupWindow->transientParent()->setKeyboardGrabEnabled(true);
}
- m_popupWindow->deleteLater();
- m_popupWindow = 0;
__closeMenu();
}
}
+void QQuickMenu::clearPopupWindow()
+{
+ m_popupWindow = 0;
+ emit __menuPopupDestroyed();
+}
+
+void QQuickMenu::__destroyMenuPopup()
+{
+ if (m_popupWindow)
+ m_popupWindow->setToBeDeletedLater();
+}
+
+void QQuickMenu::__destroyAllMenuPopups() {
+ QQuickMenuPopupWindow *popup = topMenuPopup();
+ if (popup)
+ popup->setToBeDeletedLater();
+}
+
void QQuickMenu::itemIndexToListIndex(int itemIndex, int *listIndex, int *containerIndex) const
{
*listIndex = -1;
diff --git a/src/controls/qquickmenu_p.h b/src/controls/qquickmenu_p.h
index 10a2d55fc..b468828cb 100644
--- a/src/controls/qquickmenu_p.h
+++ b/src/controls/qquickmenu_p.h
@@ -91,6 +91,8 @@ public:
public Q_SLOTS:
void __closeMenu();
void __dismissMenu();
+ void __destroyMenuPopup();
+ void __destroyAllMenuPopups();
Q_SIGNALS:
void itemsChanged();
@@ -98,6 +100,7 @@ Q_SIGNALS:
void __selectedIndexChanged();
void __menuClosed();
+ void __menuPopupDestroyed();
void popupVisibleChanged();
void __popupGeometryChanged();
void menuContentItemChanged();
@@ -143,6 +146,7 @@ protected Q_SLOTS:
void setMenuContentItem(QQuickItem *);
void setPopupVisible(bool);
+ void clearPopupWindow();
void updateText();
void windowVisibleChanged(bool);
@@ -150,6 +154,7 @@ protected Q_SLOTS:
private:
QQuickWindow *findParentWindow();
void syncParentMenuBar();
+ QQuickMenuPopupWindow *topMenuPopup() const;
int itemIndexForListIndex(int listIndex) const;
void itemIndexToListIndex(int, int *, int *) const;
diff --git a/src/controls/qquickmenupopupwindow.cpp b/src/controls/qquickmenupopupwindow.cpp
index c43ea233d..e28e63b17 100644
--- a/src/controls/qquickmenupopupwindow.cpp
+++ b/src/controls/qquickmenupopupwindow.cpp
@@ -86,12 +86,21 @@ void QQuickMenuPopupWindow::setParentWindow(QWindow *effectiveParentWindow, QQui
setTransientParent(effectiveParentWindow);
m_logicalParentWindow = parentWindow;
if (parentWindow) {
- connect(parentWindow, SIGNAL(destroyed()), this, SLOT(dismissPopup()));
- if (QQuickMenuPopupWindow *pw = qobject_cast<QQuickMenuPopupWindow *>(parentWindow))
+ if (QQuickMenuPopupWindow *pw = qobject_cast<QQuickMenuPopupWindow *>(parentWindow)) {
connect(pw, SIGNAL(popupDismissed()), this, SLOT(dismissPopup()));
+ connect(pw, SIGNAL(willBeDeletedLater()), this, SLOT(setToBeDeletedLater()));
+ } else {
+ connect(parentWindow, SIGNAL(destroyed()), this, SLOT(deleteLater()));
+ }
}
}
+void QQuickMenuPopupWindow::setToBeDeletedLater()
+{
+ deleteLater();
+ emit willBeDeletedLater();
+}
+
void QQuickMenuPopupWindow::setGeometry(int posx, int posy, int w, int h)
{
QWindow *pw = transientParent();
@@ -99,7 +108,7 @@ void QQuickMenuPopupWindow::setGeometry(int posx, int posy, int w, int h)
pw = parentItem()->window();
if (!pw)
pw = this;
- QRect g = pw->screen()->virtualGeometry();
+ QRect g = pw->screen()->geometry();
if (posx + w > g.right()) {
if (qobject_cast<QQuickMenuPopupWindow *>(transientParent())) {
diff --git a/src/controls/qquickmenupopupwindow_p.h b/src/controls/qquickmenupopupwindow_p.h
index 4f970c2aa..8c10f2554 100644
--- a/src/controls/qquickmenupopupwindow_p.h
+++ b/src/controls/qquickmenupopupwindow_p.h
@@ -57,11 +57,16 @@ public:
void setParentItem(QQuickItem *);
QQuickMenu *menu() const;
+public Q_SLOTS:
+ void setToBeDeletedLater();
protected Q_SLOTS:
void updateSize();
void updatePosition();
+Q_SIGNALS:
+ void willBeDeletedLater();
+
protected:
void exposeEvent(QExposeEvent *);
bool shouldForwardEventAfterDismiss(QMouseEvent *) const;