diff options
Diffstat (limited to 'src/controls/qquickmenu.cpp')
| -rw-r--r-- | src/controls/qquickmenu.cpp | 111 |
1 files changed, 59 insertions, 52 deletions
diff --git a/src/controls/qquickmenu.cpp b/src/controls/qquickmenu.cpp index 3c243ba36..67682ad34 100644 --- a/src/controls/qquickmenu.cpp +++ b/src/controls/qquickmenu.cpp @@ -1,34 +1,37 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Controls module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL3$ +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** Foundation and appearing in the file LICENSE.LGPL3 included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later 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 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -256,7 +259,8 @@ QT_BEGIN_NAMESPACE */ QQuickMenu1::QQuickMenu1(QObject *parent) - : QQuickMenuText(parent, QQuickMenuItemType::Menu), + : QQuickMenuText1(parent, QQuickMenuItemType1::Menu), + m_platformMenu(0), m_itemsCount(0), m_selectedIndex(-1), m_parentWindow(0), @@ -272,12 +276,14 @@ QQuickMenu1::QQuickMenu1(QObject *parent) { connect(this, SIGNAL(__textChanged()), this, SIGNAL(titleChanged())); - m_platformMenu = QGuiApplicationPrivate::platformTheme()->createPlatformMenu(); - if (m_platformMenu) { - connect(m_platformMenu, SIGNAL(aboutToShow()), this, SIGNAL(aboutToShow())); - connect(m_platformMenu, SIGNAL(aboutToHide()), this, SLOT(hideMenu())); - if (platformItem()) - platformItem()->setMenu(m_platformMenu); + if (QGuiApplication::platformName() != QStringLiteral("xcb")) { // QTBUG-51372 + m_platformMenu = QGuiApplicationPrivate::platformTheme()->createPlatformMenu(); + if (m_platformMenu) { + connect(m_platformMenu, SIGNAL(aboutToShow()), this, SIGNAL(aboutToShow())); + connect(m_platformMenu, SIGNAL(aboutToHide()), this, SLOT(hideMenu())); + if (platformItem()) + platformItem()->setMenu(m_platformMenu); + } } if (const QFont *font = QGuiApplicationPrivate::platformTheme()->font(QPlatformTheme::MenuItemFont)) m_font = *const_cast<QFont*>(font); @@ -286,7 +292,7 @@ QQuickMenu1::QQuickMenu1(QObject *parent) QQuickMenu1::~QQuickMenu1() { while (!m_menuItems.empty()) { - QQuickMenuBase *item = m_menuItems.takeFirst(); + QQuickMenuBase1 *item = m_menuItems.takeFirst(); if (item) item->setParentMenu(0); } @@ -307,7 +313,7 @@ void QQuickMenu1::syncParentMenuBar() void QQuickMenu1::setVisible(bool v) { - QQuickMenuBase::setVisible(v); + QQuickMenuBase1::setVisible(v); if (m_platformMenu) { m_platformMenu->setVisible(v); syncParentMenuBar(); @@ -316,7 +322,7 @@ void QQuickMenu1::setVisible(bool v) void QQuickMenu1::setEnabled(bool e) { - QQuickMenuText::setEnabled(e); + QQuickMenuText1::setEnabled(e); if (m_platformMenu) { m_platformMenu->setEnabled(e); syncParentMenuBar(); @@ -327,7 +333,7 @@ void QQuickMenu1::updateText() { if (m_platformMenu) m_platformMenu->setText(this->text()); - QQuickMenuText::updateText(); + QQuickMenuText1::updateText(); } void QQuickMenu1::setMinimumWidth(int w) @@ -427,7 +433,7 @@ void QQuickMenu1::__popup(const QRectF &targetRect, int atItemIndex, MenuType me setPopupVisible(true); - QQuickMenuBase *atItem = menuItemAtIndex(atItemIndex); + QQuickMenuBase1 *atItem = menuItemAtIndex(atItemIndex); QQuickWindow *quickWindow = findParentWindow(); QPoint renderOffset; @@ -452,7 +458,7 @@ void QQuickMenu1::__popup(const QRectF &targetRect, int atItemIndex, MenuType me m_platformMenu->setMenuType(QPlatformMenu::MenuType(menuType)); m_platformMenu->showPopup(parentWindow, globalTargetRect.toRect(), atItem ? atItem->platformItem() : 0); } else { - m_popupWindow = new QQuickMenuPopupWindow(this); + m_popupWindow = new QQuickMenuPopupWindow1(this); if (visualItem()) m_popupWindow->setParentItem(visualItem()); else @@ -522,11 +528,11 @@ void QQuickMenu1::hideMenu() m_parentWindow = 0; } -QQuickMenuPopupWindow *QQuickMenu1::topMenuPopup() const +QQuickMenuPopupWindow1 *QQuickMenu1::topMenuPopup() const { - QQuickMenuPopupWindow *topMenuWindow = m_popupWindow; + QQuickMenuPopupWindow1 *topMenuWindow = m_popupWindow; while (topMenuWindow) { - QQuickMenuPopupWindow *pw = qobject_cast<QQuickMenuPopupWindow *>(topMenuWindow->transientParent()); + QQuickMenuPopupWindow1 *pw = qobject_cast<QQuickMenuPopupWindow1 *>(topMenuWindow->transientParent()); if (!pw) return topMenuWindow; topMenuWindow = pw; @@ -545,7 +551,7 @@ void QQuickMenu1::__dismissMenu() { if (m_platformMenu) { m_platformMenu->dismiss(); - } else if (QQuickMenuPopupWindow *topPopup = topMenuPopup()) { + } else if (QQuickMenuPopupWindow1 *topPopup = topMenuPopup()) { topPopup->dismissPopup(); } } @@ -558,7 +564,7 @@ void QQuickMenu1::windowVisibleChanged(bool v) { if (!v) { if (m_popupWindow) { - QQuickMenuPopupWindow *parentMenuPopup = qobject_cast<QQuickMenuPopupWindow *>(m_popupWindow->transientParent()); + QQuickMenuPopupWindow1 *parentMenuPopup = qobject_cast<QQuickMenuPopupWindow1 *>(m_popupWindow->transientParent()); if (parentMenuPopup) { parentMenuPopup->setMouseGrabEnabled(true); parentMenuPopup->setKeyboardGrabEnabled(true); @@ -599,7 +605,7 @@ void QQuickMenu1::destroyMenuPopup() void QQuickMenu1::destroyAllMenuPopups() { if (m_triggerCount > 0) return; - QQuickMenuPopupWindow *popup = topMenuPopup(); + QQuickMenuPopupWindow1 *popup = topMenuPopup(); if (popup) popup->setToBeDeletedLater(); } @@ -636,9 +642,9 @@ void QQuickMenu1::__dismissAndDestroy() void QQuickMenu1::itemIndexToListIndex(int itemIndex, int *listIndex, int *containerIndex) const { *listIndex = -1; - QQuickMenuItemContainer *container = 0; + QQuickMenuItemContainer1 *container = 0; while (itemIndex >= 0 && ++*listIndex < m_menuItems.count()) - if ((container = qobject_cast<QQuickMenuItemContainer *>(m_menuItems[*listIndex]))) + if ((container = qobject_cast<QQuickMenuItemContainer1 *>(m_menuItems[*listIndex]))) itemIndex -= container->items().count(); else --itemIndex; @@ -654,7 +660,7 @@ int QQuickMenu1::itemIndexForListIndex(int listIndex) const int index = 0; int i = 0; while (i < listIndex && i < m_menuItems.count()) - if (QQuickMenuItemContainer *container = qobject_cast<QQuickMenuItemContainer *>(m_menuItems[i++])) + if (QQuickMenuItemContainer1 *container = qobject_cast<QQuickMenuItemContainer1 *>(m_menuItems[i++])) index += container->items().count(); else ++index; @@ -662,16 +668,16 @@ int QQuickMenu1::itemIndexForListIndex(int listIndex) const return index; } -QQuickMenuBase *QQuickMenu1::nextMenuItem(QQuickMenu1::MenuItemIterator *it) const +QQuickMenuBase1 *QQuickMenu1::nextMenuItem(QQuickMenu1::MenuItemIterator *it) const { if (it->containerIndex != -1) { - QQuickMenuItemContainer *container = qobject_cast<QQuickMenuItemContainer *>(m_menuItems[it->index]); + QQuickMenuItemContainer1 *container = qobject_cast<QQuickMenuItemContainer1 *>(m_menuItems[it->index]); if (++it->containerIndex < container->items().count()) return container->items()[it->containerIndex]; } if (++it->index < m_menuItems.count()) { - if (QQuickMenuItemContainer *container = qobject_cast<QQuickMenuItemContainer *>(m_menuItems[it->index])) { + if (QQuickMenuItemContainer1 *container = qobject_cast<QQuickMenuItemContainer1 *>(m_menuItems[it->index])) { it->containerIndex = 0; return container->items()[0]; } else { @@ -683,20 +689,20 @@ QQuickMenuBase *QQuickMenu1::nextMenuItem(QQuickMenu1::MenuItemIterator *it) con return 0; } -QQuickMenuBase *QQuickMenu1::menuItemAtIndex(int index) const +QQuickMenuBase1 *QQuickMenu1::menuItemAtIndex(int index) const { if (0 <= index && index < m_itemsCount) { if (!m_containersCount) { return m_menuItems[index]; } else if (m_containersCount == 1 && m_menuItems.count() == 1) { - QQuickMenuItemContainer *container = qobject_cast<QQuickMenuItemContainer *>(m_menuItems[0]); + QQuickMenuItemContainer1 *container = qobject_cast<QQuickMenuItemContainer1 *>(m_menuItems[0]); return container->items()[index]; } else { int containerIndex; int i; itemIndexToListIndex(index, &i, &containerIndex); if (containerIndex != -1) { - QQuickMenuItemContainer *container = qobject_cast<QQuickMenuItemContainer *>(m_menuItems[i]); + QQuickMenuItemContainer1 *container = qobject_cast<QQuickMenuItemContainer1 *>(m_menuItems[i]); return container->items()[containerIndex]; } else { return m_menuItems[i]; @@ -707,7 +713,7 @@ QQuickMenuBase *QQuickMenu1::menuItemAtIndex(int index) const return 0; } -bool QQuickMenu1::contains(QQuickMenuBase *item) +bool QQuickMenu1::contains(QQuickMenuBase1 *item) { if (item->container()) return item->container()->items().contains(item); @@ -715,7 +721,7 @@ bool QQuickMenu1::contains(QQuickMenuBase *item) return m_menuItems.contains(item); } -int QQuickMenu1::indexOfMenuItem(QQuickMenuBase *item) const +int QQuickMenu1::indexOfMenuItem(QQuickMenuBase1 *item) const { if (!item) return -1; @@ -751,17 +757,17 @@ void QQuickMenu1::addSeparator() void QQuickMenu1::insertSeparator(int index) { - QQuickMenuSeparator *item = new QQuickMenuSeparator(this); + QQuickMenuSeparator1 *item = new QQuickMenuSeparator1(this); insertItem(index, item); } -void QQuickMenu1::insertItem(int index, QQuickMenuBase *menuItem) +void QQuickMenu1::insertItem(int index, QQuickMenuBase1 *menuItem) { if (!menuItem) return; int itemIndex; if (m_containersCount) { - QQuickMenuItemContainer *container = menuItem->parent() != this ? m_containers[menuItem->parent()] : 0; + QQuickMenuItemContainer1 *container = menuItem->parent() != this ? m_containers[menuItem->parent()] : 0; if (container) { container->insertItem(index, menuItem); itemIndex = itemIndexForListIndex(m_menuItems.indexOf(container)) + index; @@ -778,13 +784,13 @@ void QQuickMenu1::insertItem(int index, QQuickMenuBase *menuItem) emit itemsChanged(); } -void QQuickMenu1::removeItem(QQuickMenuBase *menuItem) +void QQuickMenu1::removeItem(QQuickMenuBase1 *menuItem) { if (!menuItem) return; menuItem->setParentMenu(0); - QQuickMenuItemContainer *container = menuItem->parent() != this ? m_containers[menuItem->parent()] : 0; + QQuickMenuItemContainer1 *container = menuItem->parent() != this ? m_containers[menuItem->parent()] : 0; if (container) container->removeItem(menuItem); else @@ -809,7 +815,7 @@ void QQuickMenu1::clear() m_itemsCount = 0; } -void QQuickMenu1::setupMenuItem(QQuickMenuBase *item, int platformIndex) +void QQuickMenu1::setupMenuItem(QQuickMenuBase1 *item, int platformIndex) { item->setParentMenu(this); if (m_platformMenu) { @@ -824,17 +830,18 @@ void QQuickMenu1::setupMenuItem(QQuickMenuBase *item, int platformIndex) void QQuickMenu1::append_menuItems(QQuickMenuItems *list, QObject *o) { if (QQuickMenu1 *menu = qobject_cast<QQuickMenu1 *>(list->object)) { - if (QQuickMenuBase *menuItem = qobject_cast<QQuickMenuBase *>(o)) { + if (QQuickMenuBase1 *menuItem = qobject_cast<QQuickMenuBase1 *>(o)) { menu->m_menuItems.append(menuItem); menu->setupMenuItem(menuItem); } else { - QQuickMenuItemContainer *menuItemContainer = new QQuickMenuItemContainer(menu); + QQuickMenuItemContainer1 *menuItemContainer = new QQuickMenuItemContainer1(menu); menu->m_menuItems.append(menuItemContainer); menu->m_containers.insert(o, menuItemContainer); menuItemContainer->setParentMenu(menu); ++menu->m_containersCount; - foreach (QObject *child, o->children()) { - if (QQuickMenuBase *item = qobject_cast<QQuickMenuBase *>(child)) { + const auto children = o->children(); + for (QObject *child : children) { + if (QQuickMenuBase1 *item = qobject_cast<QQuickMenuBase1 *>(child)) { menuItemContainer->insertItem(-1, item); menu->setupMenuItem(item); } |
