From 3a5bd3d4e564a1b3cd56ed2cfb5258e4ded763b6 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 8 Dec 2015 14:26:51 +0100 Subject: Rename Panel to Popup Popup is a more descriptive name. Furthermore, this name change opens the door for another type called Pane. It gives the appropriate background color for the current style & theme. Change-Id: Idb91d37e807f62e870b50f0b656e84ee2d43a9fb Reviewed-by: Mitch Curtis --- src/imports/controls/ComboBox.qml | 11 +- .../doc/images/qtlabscontrols-combobox-panel.png | Bin 4969 -> 0 bytes .../doc/images/qtlabscontrols-combobox-popup.png | Bin 0 -> 4969 bytes .../snippets/qtlabscontrols-combobox-delegate.qml | 6 +- .../doc/snippets/qtlabscontrols-combobox-panel.qml | 47 --- .../doc/snippets/qtlabscontrols-combobox-popup.qml | 47 +++ .../doc/snippets/qtlabscontrols-combobox.qml | 6 +- .../controls/doc/src/qtlabscontrols-customize.qdoc | 10 +- src/imports/controls/material/ComboBox.qml | 9 +- src/imports/controls/universal/ComboBox.qml | 13 +- src/imports/templates/qtlabstemplatesplugin.cpp | 4 +- src/templates/qquickcombobox.cpp | 88 +++--- src/templates/qquickcombobox_p.h | 10 +- src/templates/qquickmenu.cpp | 7 +- src/templates/qquickmenu_p.h | 4 +- src/templates/qquickmenu_p_p.h | 4 +- src/templates/qquickoverlay.cpp | 62 ++-- src/templates/qquickoverlay_p.h | 6 +- src/templates/qquickpanel.cpp | 330 --------------------- src/templates/qquickpanel_p.h | 121 -------- src/templates/qquickpanel_p_p.h | 105 ------- src/templates/qquickpopup.cpp | 330 +++++++++++++++++++++ src/templates/qquickpopup_p.h | 121 ++++++++ src/templates/qquickpopup_p_p.h | 105 +++++++ src/templates/templates.pri | 6 +- tests/auto/controls/data/tst_combobox.qml | 52 ++-- tests/auto/menu/tst_menu.cpp | 2 +- 27 files changed, 751 insertions(+), 755 deletions(-) delete mode 100644 src/imports/controls/doc/images/qtlabscontrols-combobox-panel.png create mode 100644 src/imports/controls/doc/images/qtlabscontrols-combobox-popup.png delete mode 100644 src/imports/controls/doc/snippets/qtlabscontrols-combobox-panel.qml create mode 100644 src/imports/controls/doc/snippets/qtlabscontrols-combobox-popup.qml delete mode 100644 src/templates/qquickpanel.cpp delete mode 100644 src/templates/qquickpanel_p.h delete mode 100644 src/templates/qquickpanel_p_p.h create mode 100644 src/templates/qquickpopup.cpp create mode 100644 src/templates/qquickpopup_p.h create mode 100644 src/templates/qquickpopup_p_p.h diff --git a/src/imports/controls/ComboBox.qml b/src/imports/controls/ComboBox.qml index 7f2adcb0..3d4e5ed5 100644 --- a/src/imports/controls/ComboBox.qml +++ b/src/imports/controls/ComboBox.qml @@ -85,7 +85,7 @@ T.ComboBox { width: parent.width height: parent.height opacity: control.enabled ? 1.0 : 0.2 - color: control.pressed || panel.visible ? "#585A5C" : "#353637" + color: control.pressed || popup.visible ? "#585A5C" : "#353637" } Image { @@ -96,11 +96,10 @@ T.ComboBox { } //! [background] - //! [panel] - panel: T.Panel { - id: popup + //! [popup] + popup: T.Popup { contentItem: Rectangle { - // TODO: Panel::anchors + // TODO: Popup::anchors readonly property var above: popup.visible ? control.mapToItem(null, 0, -height + 1) : Qt.point(0, 0) readonly property var below: popup.visible ? control.mapToItem(null, 0, control.height - 1) : Qt.point(0, 0) @@ -129,5 +128,5 @@ T.ComboBox { } } } - //! [panel] + //! [popup] } diff --git a/src/imports/controls/doc/images/qtlabscontrols-combobox-panel.png b/src/imports/controls/doc/images/qtlabscontrols-combobox-panel.png deleted file mode 100644 index 0e9eacbf..00000000 Binary files a/src/imports/controls/doc/images/qtlabscontrols-combobox-panel.png and /dev/null differ diff --git a/src/imports/controls/doc/images/qtlabscontrols-combobox-popup.png b/src/imports/controls/doc/images/qtlabscontrols-combobox-popup.png new file mode 100644 index 00000000..0e9eacbf Binary files /dev/null and b/src/imports/controls/doc/images/qtlabscontrols-combobox-popup.png differ diff --git a/src/imports/controls/doc/snippets/qtlabscontrols-combobox-delegate.qml b/src/imports/controls/doc/snippets/qtlabscontrols-combobox-delegate.qml index 47c4f606..60f56940 100644 --- a/src/imports/controls/doc/snippets/qtlabscontrols-combobox-delegate.qml +++ b/src/imports/controls/doc/snippets/qtlabscontrols-combobox-delegate.qml @@ -31,12 +31,12 @@ import Qt.labs.controls 1.0 Item { id: root width: combo.width - height: combo.height + combo.panel.contentItem.height + height: combo.height + combo.popup.contentItem.height ComboBox { id: combo model: ["First", "Second", "Third"] - panel.contentItem.parent: root - panel.contentItem.y: combo.height + popup.contentItem.parent: root + popup.contentItem.y: combo.height delegate: ItemDelegate { width: combo.width text: modelData diff --git a/src/imports/controls/doc/snippets/qtlabscontrols-combobox-panel.qml b/src/imports/controls/doc/snippets/qtlabscontrols-combobox-panel.qml deleted file mode 100644 index d1788d55..00000000 --- a/src/imports/controls/doc/snippets/qtlabscontrols-combobox-panel.qml +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** 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. -** -** GNU Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import Qt.labs.controls 1.0 - -Item { - id: root - width: combo.width - height: combo.height + combo.panel.contentItem.height - ComboBox { - id: combo - model: ["First", "Second", "Third"] - panel.contentItem.parent: root - panel.contentItem.y: combo.height - } - Rectangle { - parent: combo.panel.contentItem - anchors.fill: parent - color: 'transparent' - border.color: 'red' - } -} diff --git a/src/imports/controls/doc/snippets/qtlabscontrols-combobox-popup.qml b/src/imports/controls/doc/snippets/qtlabscontrols-combobox-popup.qml new file mode 100644 index 00000000..0fea67d1 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtlabscontrols-combobox-popup.qml @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Qt.labs.controls 1.0 + +Item { + id: root + width: combo.width + height: combo.height + combo.popup.contentItem.height + ComboBox { + id: combo + model: ["First", "Second", "Third"] + popup.contentItem.parent: root + popup.contentItem.y: combo.height + } + Rectangle { + parent: combo.popup.contentItem + anchors.fill: parent + color: 'transparent' + border.color: 'red' + } +} diff --git a/src/imports/controls/doc/snippets/qtlabscontrols-combobox.qml b/src/imports/controls/doc/snippets/qtlabscontrols-combobox.qml index bac6136d..4d7fe7fd 100644 --- a/src/imports/controls/doc/snippets/qtlabscontrols-combobox.qml +++ b/src/imports/controls/doc/snippets/qtlabscontrols-combobox.qml @@ -31,13 +31,13 @@ import Qt.labs.controls 1.0 Item { id: root width: combo.width - height: combo.height + combo.panel.contentItem.height + height: combo.height + combo.popup.contentItem.height //! [1] ComboBox { id: combo model: ["First", "Second", "Third"] - panel.contentItem.parent: root - panel.contentItem.y: combo.height + popup.contentItem.parent: root + popup.contentItem.y: combo.height } //! [1] } diff --git a/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc b/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc index eb1dc71d..524cd23a 100644 --- a/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc +++ b/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc @@ -99,7 +99,7 @@ \section1 Customizing ComboBox ComboBox consists of \l {Control::background}{background}, - \l {Control::contentItem}{content item}, \l {ComboBox::panel}{panel}, + \l {Control::contentItem}{content item}, \l {ComboBox::popup}{popup}, and \l {ComboBox::delegate}{delegate}. \section3 Background @@ -114,11 +114,11 @@ \snippet ComboBox.qml contentItem - \section3 Panel + \section3 Popup - \image qtlabscontrols-combobox-panel.png + \image qtlabscontrols-combobox-popup.png - \snippet ComboBox.qml panel + \snippet ComboBox.qml popup \section3 Delegate @@ -240,7 +240,7 @@ \section1 Customizing Menu - Menu consists of a \l {Panel::}{contentItem}. + Menu consists of a \l {Popup::}{contentItem}. \section3 Content item diff --git a/src/imports/controls/material/ComboBox.qml b/src/imports/controls/material/ComboBox.qml index 035863f6..13bbdf38 100644 --- a/src/imports/controls/material/ComboBox.qml +++ b/src/imports/controls/material/ComboBox.qml @@ -109,11 +109,10 @@ T.ComboBox { } //! [background] - //! [panel] - panel: T.Panel { - id: popup + //! [popup] + popup: T.Popup { contentItem: Rectangle { - // TODO: Panel::anchors + // TODO: Popup::anchors readonly property var above: popup.visible ? control.mapToItem(null, 0, -height) : Qt.point(0, 0) readonly property var below: popup.visible ? control.mapToItem(null, 0, control.height) : Qt.point(0, 0) @@ -150,5 +149,5 @@ T.ComboBox { } } } - //! [panel] + //! [popup] } diff --git a/src/imports/controls/universal/ComboBox.qml b/src/imports/controls/universal/ComboBox.qml index 0fdcb894..9b47d76a 100644 --- a/src/imports/controls/universal/ComboBox.qml +++ b/src/imports/controls/universal/ComboBox.qml @@ -86,9 +86,9 @@ T.ComboBox { border.width: 2 // ComboBoxBorderThemeThickness border.color: !control.enabled ? control.Universal.baseLowColor : - control.pressed || panel.visible ? control.Universal.baseMediumLowColor : control.Universal.baseMediumLowColor + control.pressed || popup.visible ? control.Universal.baseMediumLowColor : control.Universal.baseMediumLowColor color: !control.enabled ? control.Universal.baseLowColor : - control.pressed || panel.visible ? control.Universal.listMediumColor : control.Universal.altMediumLowColor + control.pressed || popup.visible ? control.Universal.listMediumColor : control.Universal.altMediumLowColor Rectangle { x: 2 @@ -110,11 +110,10 @@ T.ComboBox { } //! [background] - //! [panel] - panel: T.Panel { - id: popup + //! [popup] + popup: T.Popup { contentItem: Rectangle { - // TODO: Panel::anchors + // TODO: Popup::anchors readonly property var above: popup.visible ? control.mapToItem(null, 0, control.height - height) : Qt.point(0, 0) readonly property var below: popup.visible ? control.mapToItem(null, 0, 0) : Qt.point(0, 0) @@ -138,5 +137,5 @@ T.ComboBox { } } } - //! [panel] + //! [popup] } diff --git a/src/imports/templates/qtlabstemplatesplugin.cpp b/src/imports/templates/qtlabstemplatesplugin.cpp index 5e4877f8..44a08fb3 100644 --- a/src/imports/templates/qtlabstemplatesplugin.cpp +++ b/src/imports/templates/qtlabstemplatesplugin.cpp @@ -53,7 +53,7 @@ #include #include #include -#include +#include #include #include #include @@ -103,7 +103,7 @@ void QtLabsTemplatesPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 1, 0, "Menu"); qmlRegisterType(uri, 1, 0, "MenuItem"); qmlRegisterType(uri, 1, 0, "PageIndicator"); - qmlRegisterType(uri, 1, 0, "Panel"); + qmlRegisterType(uri, 1, 0, "Popup"); qmlRegisterType(uri, 1, 0, "ProgressBar"); qmlRegisterType(uri, 1, 0, "RadioButton"); qmlRegisterType(uri, 1, 0, "RangeSlider"); diff --git a/src/templates/qquickcombobox.cpp b/src/templates/qquickcombobox.cpp index 0f56567e..7c3707a7 100644 --- a/src/templates/qquickcombobox.cpp +++ b/src/templates/qquickcombobox.cpp @@ -37,7 +37,7 @@ #include "qquickcombobox_p.h" #include "qquickcontrol_p_p.h" #include "qquickabstractbutton_p.h" -#include "qquickpanel_p.h" +#include "qquickpopup_p.h" #include #include @@ -123,12 +123,12 @@ class QQuickComboBoxPrivate : public QQuickControlPrivate public: QQuickComboBoxPrivate() : pressed(false), ownModel(false), hasDisplayText(false), hideTimer(0), highlightedIndex(-1), currentIndex(-1), delegateModel(Q_NULLPTR), - delegate(Q_NULLPTR), panel(Q_NULLPTR) { } + delegate(Q_NULLPTR), popup(Q_NULLPTR) { } - bool isPanelVisible() const; - void showPanel(); - void hidePanel(bool accept); - void togglePanel(bool accept); + bool isPopupVisible() const; + void showPopup(); + void hidePopup(bool accept); + void togglePopup(bool accept); void pressedOutside(); void itemClicked(); @@ -155,26 +155,26 @@ public: QQuickItem *pressedItem; QQmlInstanceModel *delegateModel; QQmlComponent *delegate; - QQuickPanel *panel; + QQuickPopup *popup; }; -bool QQuickComboBoxPrivate::isPanelVisible() const +bool QQuickComboBoxPrivate::isPopupVisible() const { - return panel && panel->isVisible(); + return popup && popup->isVisible(); } -void QQuickComboBoxPrivate::showPanel() +void QQuickComboBoxPrivate::showPopup() { - if (panel && !panel->isVisible()) - panel->show(); + if (popup && !popup->isVisible()) + popup->show(); setHighlightedIndex(currentIndex); } -void QQuickComboBoxPrivate::hidePanel(bool accept) +void QQuickComboBoxPrivate::hidePopup(bool accept) { Q_Q(QQuickComboBox); - if (panel && panel->isVisible()) - panel->hide(); + if (popup && popup->isVisible()) + popup->hide(); if (accept) { q->setCurrentIndex(highlightedIndex); emit q->activated(currentIndex); @@ -182,15 +182,15 @@ void QQuickComboBoxPrivate::hidePanel(bool accept) setHighlightedIndex(-1); } -void QQuickComboBoxPrivate::togglePanel(bool accept) +void QQuickComboBoxPrivate::togglePopup(bool accept) { - if (!panel) + if (!popup) return; - if (panel->isVisible()) - hidePanel(accept); + if (popup->isVisible()) + hidePopup(accept); else - showPanel(); + showPopup(); } void QQuickComboBoxPrivate::pressedOutside() @@ -207,7 +207,7 @@ void QQuickComboBoxPrivate::itemClicked() if (index != -1) { setHighlightedIndex(index); emit q->highlighted(index); - hidePanel(true); + hidePopup(true); } } @@ -246,7 +246,7 @@ void QQuickComboBoxPrivate::updateCurrentText() void QQuickComboBoxPrivate::increase() { Q_Q(QQuickComboBox); - if (isPanelVisible()) { + if (isPopupVisible()) { if (highlightedIndex < q->count() - 1) { setHighlightedIndex(highlightedIndex + 1); emit q->highlighted(highlightedIndex); @@ -262,7 +262,7 @@ void QQuickComboBoxPrivate::increase() void QQuickComboBoxPrivate::decrease() { Q_Q(QQuickComboBox); - if (isPanelVisible()) { + if (isPopupVisible()) { if (highlightedIndex > 0) { setHighlightedIndex(highlightedIndex - 1); emit q->highlighted(highlightedIndex); @@ -560,27 +560,27 @@ void QQuickComboBox::setDelegate(QQmlComponent* delegate) } /*! - \qmlproperty Panel Qt.labs.controls::ComboBox::panel + \qmlproperty Popup Qt.labs.controls::ComboBox::popup - This property holds the popup panel. + This property holds the popup. \sa {Customizing ComboBox} */ -QQuickPanel *QQuickComboBox::panel() const +QQuickPopup *QQuickComboBox::popup() const { Q_D(const QQuickComboBox); - return d->panel; + return d->popup; } -void QQuickComboBox::setPanel(QQuickPanel *panel) +void QQuickComboBox::setPopup(QQuickPopup *popup) { Q_D(QQuickComboBox); - if (d->panel != panel) { - delete d->panel; - if (panel) - QObjectPrivate::connect(panel, &QQuickPanel::pressedOutside, d, &QQuickComboBoxPrivate::pressedOutside); - d->panel = panel; - emit panelChanged(); + if (d->popup != popup) { + delete d->popup; + if (popup) + QObjectPrivate::connect(popup, &QQuickPopup::pressedOutside, d, &QQuickComboBoxPrivate::pressedOutside); + d->popup = popup; + emit popupChanged(); } } @@ -667,7 +667,7 @@ void QQuickComboBox::focusOutEvent(QFocusEvent *event) { Q_D(QQuickComboBox); QQuickItem::focusOutEvent(event); - d->hidePanel(false); + d->hidePopup(false); setPressed(false); } @@ -675,7 +675,7 @@ void QQuickComboBox::keyPressEvent(QKeyEvent *event) { Q_D(QQuickComboBox); QQuickControl::keyPressEvent(event); - if (!d->panel) + if (!d->popup) return; switch (event->key()) { @@ -686,7 +686,7 @@ void QQuickComboBox::keyPressEvent(QKeyEvent *event) break; case Qt::Key_Enter: case Qt::Key_Return: - if (d->isPanelVisible()) + if (d->isPopupVisible()) setPressed(true); event->accept(); break; @@ -709,23 +709,23 @@ void QQuickComboBox::keyReleaseEvent(QKeyEvent *event) { Q_D(QQuickComboBox); QQuickControl::keyReleaseEvent(event); - if (!d->panel || event->isAutoRepeat()) + if (!d->popup || event->isAutoRepeat()) return; switch (event->key()) { case Qt::Key_Space: - d->togglePanel(true); + d->togglePopup(true); setPressed(false); event->accept(); break; case Qt::Key_Enter: case Qt::Key_Return: - d->hidePanel(true); + d->hidePopup(true); setPressed(false); event->accept(); break; case Qt::Key_Escape: - d->hidePanel(false); + d->hidePopup(false); setPressed(false); event->accept(); break; @@ -752,9 +752,9 @@ void QQuickComboBox::mouseReleaseEvent(QMouseEvent *event) QQuickControl::mouseReleaseEvent(event); if (d->pressed) { setPressed(false); - if (!d->isPanelVisible()) + if (!d->isPopupVisible()) forceActiveFocus(Qt::MouseFocusReason); - d->togglePanel(false); + d->togglePopup(false); } } @@ -772,7 +772,7 @@ void QQuickComboBox::timerEvent(QTimerEvent *event) killTimer(d->hideTimer); d->hideTimer = 0; if (!d->pressed) - d->hidePanel(false); + d->hidePopup(false); } } diff --git a/src/templates/qquickcombobox_p.h b/src/templates/qquickcombobox_p.h index 6c80edc8..21d29714 100644 --- a/src/templates/qquickcombobox_p.h +++ b/src/templates/qquickcombobox_p.h @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE -class QQuickPanel; +class QQuickPopup; class QQmlInstanceModel; class QQuickComboBoxPrivate; @@ -69,7 +69,7 @@ class Q_LABSTEMPLATES_EXPORT QQuickComboBox : public QQuickControl Q_PROPERTY(QString displayText READ displayText WRITE setDisplayText RESET resetDisplayText NOTIFY displayTextChanged FINAL) Q_PROPERTY(QString textRole READ textRole WRITE setTextRole NOTIFY textRoleChanged FINAL) Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) - Q_PROPERTY(QQuickPanel *panel READ panel WRITE setPanel NOTIFY panelChanged FINAL) + Q_PROPERTY(QQuickPopup *popup READ popup WRITE setPopup NOTIFY popupChanged FINAL) public: explicit QQuickComboBox(QQuickItem *parent = Q_NULLPTR); @@ -100,8 +100,8 @@ public: QQmlComponent *delegate() const; void setDelegate(QQmlComponent *delegate); - QQuickPanel *panel() const; - void setPanel(QQuickPanel *panel); + QQuickPopup *popup() const; + void setPopup(QQuickPopup *popup); Q_INVOKABLE QString textAt(int index) const; Q_INVOKABLE int find(const QString &text, Qt::MatchFlags flags = Qt::MatchExactly) const; @@ -117,7 +117,7 @@ Q_SIGNALS: void displayTextChanged(); void textRoleChanged(); void delegateChanged(); - void panelChanged(); + void popupChanged(); void activated(int index); void highlighted(int index); diff --git a/src/templates/qquickmenu.cpp b/src/templates/qquickmenu.cpp index 7efc9765..27c7094d 100644 --- a/src/templates/qquickmenu.cpp +++ b/src/templates/qquickmenu.cpp @@ -36,7 +36,6 @@ #include "qquickmenu_p.h" #include "qquickmenu_p_p.h" -#include "qquickpanel_p_p.h" #include "qquickmenuitem_p.h" #include @@ -50,7 +49,7 @@ QT_BEGIN_NAMESPACE /*! \qmltype Menu - \inherits Panel + \inherits Popup \instantiates QQuickMenu \inqmlmodule Qt.labs.controls \ingroup qtlabscontrols-menus @@ -268,7 +267,7 @@ void QQuickMenuPrivate::contentData_append(QQmlListProperty *prop, QObj QQuickMenuItem *menuItem = qobject_cast(item); if (menuItem) { QObjectPrivate::connect(menuItem, &QQuickMenuItem::pressed, p, &QQuickMenuPrivate::onItemPressed); - QObject::connect(menuItem, &QQuickMenuItem::triggered, q, &QQuickPanel::hide); + QObject::connect(menuItem, &QQuickMenuItem::triggered, q, &QQuickPopup::hide); QObjectPrivate::connect(menuItem, &QQuickItem::activeFocusChanged, p, &QQuickMenuPrivate::onItemActiveFocusChanged); } } @@ -296,7 +295,7 @@ void QQuickMenuPrivate::contentData_clear(QQmlListProperty *prop) } QQuickMenu::QQuickMenu(QObject *parent) : - QQuickPanel(*(new QQuickMenuPrivate), parent) + QQuickPopup(*(new QQuickMenuPrivate), parent) { Q_D(QQuickMenu); connect(this, &QQuickMenu::pressedOutside, this, &QQuickMenu::hide); diff --git a/src/templates/qquickmenu_p.h b/src/templates/qquickmenu_p.h index cd079d4e..a9151fd7 100644 --- a/src/templates/qquickmenu_p.h +++ b/src/templates/qquickmenu_p.h @@ -50,14 +50,14 @@ #include -#include "qquickpanel_p.h" +#include "qquickpopup_p.h" QT_BEGIN_NAMESPACE class QQuickMenuItem; class QQuickMenuPrivate; -class Q_LABSTEMPLATES_EXPORT QQuickMenu : public QQuickPanel +class Q_LABSTEMPLATES_EXPORT QQuickMenu : public QQuickPopup { Q_OBJECT Q_PROPERTY(QVariant contentModel READ contentModel CONSTANT FINAL) diff --git a/src/templates/qquickmenu_p_p.h b/src/templates/qquickmenu_p_p.h index 166d184b..a5e99f1c 100644 --- a/src/templates/qquickmenu_p_p.h +++ b/src/templates/qquickmenu_p_p.h @@ -51,13 +51,13 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE class QQmlObjectModel; -class Q_LABSTEMPLATES_EXPORT QQuickMenuPrivate : public QQuickPanelPrivate, public QQuickItemChangeListener +class Q_LABSTEMPLATES_EXPORT QQuickMenuPrivate : public QQuickPopupPrivate, public QQuickItemChangeListener { Q_DECLARE_PUBLIC(QQuickMenu) diff --git a/src/templates/qquickoverlay.cpp b/src/templates/qquickoverlay.cpp index 4a00387a..84495bf0 100644 --- a/src/templates/qquickoverlay.cpp +++ b/src/templates/qquickoverlay.cpp @@ -35,14 +35,14 @@ ****************************************************************************/ #include "qquickoverlay_p.h" -#include "qquickpanel_p.h" +#include "qquickpopup_p.h" #include #include QT_BEGIN_NAMESPACE QQuickOverlay::QQuickOverlay(QQuickItem *parent) - : QQuickItem(parent), m_modalPanels(0) + : QQuickItem(parent), m_modalPopups(0) { setAcceptedMouseButtons(Qt::AllButtons); setFiltersChildMouseEvents(true); @@ -53,70 +53,70 @@ void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data) { QQuickItem::itemChange(change, data); - QQuickItem *panelItem = const_cast(data.item); - QQuickPanel *panel = Q_NULLPTR; + QQuickItem *contentItem = const_cast(data.item); + QQuickPopup *popup = Q_NULLPTR; if (change == ItemChildAddedChange || change == ItemChildRemovedChange) { - panel = qobject_cast(panelItem->parent()); + popup = qobject_cast(contentItem->parent()); setVisible(!childItems().isEmpty()); } - if (!panel) + if (!popup) return; if (change == ItemChildAddedChange) { - if (QQuickPanel *prevPanel = m_panels.value(panelItem)) { - qmlInfo(panel).nospace() << "Panel is sharing item " << panelItem << " with " << prevPanel + if (QQuickPopup *prevPopup = m_popups.value(contentItem)) { + qmlInfo(popup).nospace() << "Popup is sharing item " << contentItem << " with " << prevPopup << ". This is not supported and strange things are about to happen."; return; } - m_panels.insert(panelItem, panel); - if (panel->isModal()) - ++m_modalPanels; + m_popups.insert(contentItem, popup); + if (popup->isModal()) + ++m_modalPopups; - connect(this, &QQuickOverlay::pressed, panel, &QQuickPanel::pressedOutside); - connect(this, &QQuickOverlay::released, panel, &QQuickPanel::releasedOutside); + connect(this, &QQuickOverlay::pressed, popup, &QQuickPopup::pressedOutside); + connect(this, &QQuickOverlay::released, popup, &QQuickPopup::releasedOutside); } else if (change == ItemChildRemovedChange) { - Q_ASSERT(panel == m_panels.value(panelItem)); + Q_ASSERT(popup == m_popups.value(contentItem)); - disconnect(this, &QQuickOverlay::pressed, panel, &QQuickPanel::pressedOutside); - disconnect(this, &QQuickOverlay::released, panel, &QQuickPanel::releasedOutside); + disconnect(this, &QQuickOverlay::pressed, popup, &QQuickPopup::pressedOutside); + disconnect(this, &QQuickOverlay::released, popup, &QQuickPopup::releasedOutside); - if (panel->isModal()) - --m_modalPanels; - m_panels.remove(panelItem); + if (popup->isModal()) + --m_modalPopups; + m_popups.remove(contentItem); } } void QQuickOverlay::keyPressEvent(QKeyEvent *event) { - event->setAccepted(m_modalPanels > 0); + event->setAccepted(m_modalPopups > 0); } void QQuickOverlay::keyReleaseEvent(QKeyEvent *event) { - event->setAccepted(m_modalPanels > 0); + event->setAccepted(m_modalPopups > 0); } void QQuickOverlay::mousePressEvent(QMouseEvent *event) { - event->setAccepted(m_modalPanels > 0); + event->setAccepted(m_modalPopups > 0); emit pressed(); } void QQuickOverlay::mouseMoveEvent(QMouseEvent *event) { - event->setAccepted(m_modalPanels > 0); + event->setAccepted(m_modalPopups > 0); } void QQuickOverlay::mouseReleaseEvent(QMouseEvent *event) { - event->setAccepted(m_modalPanels > 0); + event->setAccepted(m_modalPopups > 0); emit released(); } bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event) { - if (m_modalPanels == 0) + if (m_modalPopups == 0) return false; // TODO Filter touch events if (event->type() != QEvent::MouseButtonPress) @@ -128,15 +128,15 @@ bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event) const QQuickItemPrivate *priv = QQuickItemPrivate::get(this); const QList &sortedChildren = priv->paintOrderChildItems(); for (int i = sortedChildren.count() - 1; i >= 0; --i) { - QQuickItem *panelItem = sortedChildren[i]; - if (panelItem == item) + QQuickItem *contentItem = sortedChildren[i]; + if (contentItem == item) break; - QQuickPanel *panel = m_panels.value(panelItem); - if (panel) { - emit panel->pressedOutside(); + QQuickPopup *popup = m_popups.value(contentItem); + if (popup) { + emit popup->pressedOutside(); - if (!modalBlocked && panel->isModal()) + if (!modalBlocked && popup->isModal()) modalBlocked = true; } } diff --git a/src/templates/qquickoverlay_p.h b/src/templates/qquickoverlay_p.h index c5f9b719..cdba2532 100644 --- a/src/templates/qquickoverlay_p.h +++ b/src/templates/qquickoverlay_p.h @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE -class QQuickPanel; +class QQuickPopup; class QQuickOverlay : public QQuickItem { @@ -77,8 +77,8 @@ protected: private: Q_DISABLE_COPY(QQuickOverlay) - QHash m_panels; - int m_modalPanels; + QHash m_popups; + int m_modalPopups; }; QT_END_NAMESPACE diff --git a/src/templates/qquickpanel.cpp b/src/templates/qquickpanel.cpp deleted file mode 100644 index 38f1a73c..00000000 --- a/src/templates/qquickpanel.cpp +++ /dev/null @@ -1,330 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Labs Templates module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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. -** -** 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 -** 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. -** -** 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. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickpanel_p.h" -#include "qquickpanel_p_p.h" -#include "qquickapplicationwindow_p.h" -#include "qquickoverlay_p.h" -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmltype Panel - \inherits QtObject - \instantiates QQuickPanel - \inqmlmodule Qt.labs.controls - \ingroup qtlabscontrols-popups - \brief A popup panel. - - Panel is the base type of popup-like user interface controls. -*/ - -QQuickPanelPrivate::QQuickPanelPrivate() - : QObjectPrivate() - , contentItem(Q_NULLPTR) - , overlay(Q_NULLPTR) - , focus(false) - , modal(false) - , showTransition(Q_NULLPTR) - , hideTransition(Q_NULLPTR) - , transitionManager(this) -{ } - -QQuickPanelPrivate::~QQuickPanelPrivate() -{ } - -void QQuickPanelPrivate::finalizeShowTransition() -{ - if (focus) - contentItem->setFocus(true); -} - -void QQuickPanelPrivate::finalizeHideTransition() -{ - overlay = Q_NULLPTR; - contentItem->setParentItem(Q_NULLPTR); - emit q_func()->visibleChanged(); -} - -QQuickPanelTransitionManager::QQuickPanelTransitionManager(QQuickPanelPrivate *priv) - : QQuickTransitionManager() - , state(Off) - , pp(priv) -{ } - -void QQuickPanelTransitionManager::transitionShow() -{ - if (isRunning()) - return; - QList actions; - state = Show; - transition(actions, pp->showTransition, pp->contentItem); -} - -void QQuickPanelTransitionManager::transitionHide() -{ - if (isRunning()) - return; - QList actions; - state = Hide; - transition(actions, pp->hideTransition, pp->contentItem); -} - -void QQuickPanelTransitionManager::finished() -{ - if (state == Show) - pp->finalizeShowTransition(); - else if (state == Hide) - pp->finalizeHideTransition(); - - state = Off; -} - -QQuickPanel::QQuickPanel(QObject *parent) - : QObject(*(new QQuickPanelPrivate), parent) -{ -} - -QQuickPanel::QQuickPanel(QQuickPanelPrivate &dd, QObject *parent) - : QObject(dd, parent) -{ -} - -QQuickPanel::~QQuickPanel() -{ -} - -/*! - \qmlmethod void Qt.labs.controls::Panel::show() - - Shows the panel. -*/ -void QQuickPanel::show() -{ - Q_D(QQuickPanel); - if (!d->contentItem) { - qmlInfo(this) << "no panel content to show."; - return; - } - if (d->overlay) { - // FIXME qmlInfo needs to know about QQuickWindow and/or QObject - static_cast(qmlInfo(this) << "panel already showing in window") << d->overlay->window(); - return; - } - - QQuickWindow *win = Q_NULLPTR; - QObject *p = parent(); - while (p && !win) { - if (QQuickItem *item = qobject_cast(p)) { - win = item->window(); - if (!win) - p = item->parentItem(); - } else { - win = qobject_cast(p); - if (!win) - p = p->parent(); - } - } - if (!win) { - qmlInfo(this) << "cannot find any window to show panel."; - return; - } - - if (QQuickApplicationWindow *appWin = qobject_cast(win)) { - d->overlay = static_cast(appWin->overlay()); - d->contentItem->setParentItem(d->overlay); - } else { - // FIXME Maybe try to show it somehow on that window - qmlInfo(this) << "is not in an ApplicationWindow."; - return; - } - - emit aboutToShow(); - d->transitionManager.transitionShow(); - emit visibleChanged(); -} - -/*! - \qmlmethod void Qt.labs.controls::Panel::hide() - - Hides the panel. -*/ -void QQuickPanel::hide() -{ - Q_D(QQuickPanel); - - if (!d->overlay) { - // TODO This could mean we showed the panel item on a plain QQuickWindow - qmlInfo(this) << "trying to hide non-visible Panel."; - return; - } - - d->contentItem->setFocus(false); - emit aboutToHide(); - d->transitionManager.transitionHide(); -} - -/*! - \qmlproperty Item Qt.labs.controls::Panel::contentItem - - This property holds the content item of the panel. - - The content item is the visual implementation of the panel. When the - panel is made visible, the content item is automatically reparented to - the \l {ApplicationWindow::overlay}{overlay item} of its application - window. -*/ -QQuickItem *QQuickPanel::contentItem() const -{ - Q_D(const QQuickPanel); - return d->contentItem; -} - -void QQuickPanel::setContentItem(QQuickItem *item) -{ - Q_D(QQuickPanel); - if (d->overlay) { - // FIXME qmlInfo needs to know about QQuickItem and/or QObject - static_cast(qmlInfo(this) << "cannot set content item") << item << "while Panel is visible."; - return; - } - if (d->contentItem != item) { - delete d->contentItem; - d->contentItem = item; - if (item) - QQuickItemPrivate::get(item)->isTabFence = true; - emit contentItemChanged(); - } -} - -/*! - \qmlproperty bool Qt.labs.controls::Panel::focus - - This property holds whether the panel has focus. -*/ -bool QQuickPanel::hasFocus() const -{ - Q_D(const QQuickPanel); - return d->focus; -} - -void QQuickPanel::setFocus(bool focus) -{ - Q_D(QQuickPanel); - if (d->focus == focus) - return; - d->focus = focus; - emit focusChanged(); -} - -/*! - \qmlproperty bool Qt.labs.controls::Panel::modal - - This property holds whether the panel is modal. -*/ -bool QQuickPanel::isModal() const -{ - Q_D(const QQuickPanel); - return d->modal; -} - -void QQuickPanel::setModal(bool modal) -{ - Q_D(QQuickPanel); - if (d->modal == modal) - return; - d->modal = modal; - emit modalChanged(); -} - -/*! - \qmlproperty bool Qt.labs.controls::Panel::visible - - This property holds whether the panel is visible. -*/ -bool QQuickPanel::isVisible() const -{ - Q_D(const QQuickPanel); - return d->overlay != Q_NULLPTR /*&& !d->transitionManager.isRunning()*/; -} - -/*! - \qmlproperty Transition Qt.labs.controls::Panel::showTransition - - This property holds the transition that is applied to the content item - when the panel is shown. -*/ -QQuickTransition *QQuickPanel::showTransition() const -{ - return d_func()->showTransition; -} - -void QQuickPanel::setShowTransition(QQuickTransition *t) -{ - Q_D(QQuickPanel); - if (d->showTransition == t) - return; - d->showTransition = t; - emit showTransitionChanged(); -} - -/*! - \qmlproperty Transition Qt.labs.controls::Panel::hideTransition - - This property holds the transition that is applied to the content item - when the panel is hidden. -*/ -QQuickTransition *QQuickPanel::hideTransition() const -{ - return d_func()->hideTransition; -} - -void QQuickPanel::setHideTransition(QQuickTransition *t) -{ - Q_D(QQuickPanel); - if (d->hideTransition == t) - return; - d->hideTransition = t; - emit hideTransitionChanged(); -} - -QT_END_NAMESPACE - -#include "moc_qquickpanel_p.cpp" diff --git a/src/templates/qquickpanel_p.h b/src/templates/qquickpanel_p.h deleted file mode 100644 index 6d6f4df9..00000000 --- a/src/templates/qquickpanel_p.h +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Labs Templates module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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. -** -** 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 -** 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. -** -** 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. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKPANEL_P_H -#define QQUICKPANEL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickItem; -class QQuickPanelPrivate; -class QQuickTransition; - -class Q_LABSTEMPLATES_EXPORT QQuickPanel : public QObject -{ - Q_OBJECT - Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) - Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged) - Q_PROPERTY(bool modal READ isModal WRITE setModal NOTIFY modalChanged) - Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged) - Q_PROPERTY(QQuickTransition *showTransition READ showTransition WRITE setShowTransition NOTIFY showTransitionChanged FINAL) - Q_PROPERTY(QQuickTransition *hideTransition READ showTransition WRITE setHideTransition NOTIFY hideTransitionChanged FINAL) - -public: - explicit QQuickPanel(QObject *parent = Q_NULLPTR); - ~QQuickPanel(); - - QQuickItem *contentItem() const; - void setContentItem(QQuickItem *item); - - bool hasFocus() const; - void setFocus(bool focus); - - bool isModal() const; - void setModal(bool modal); - - bool isVisible() const; - - QQuickTransition *showTransition() const; - void setShowTransition(QQuickTransition *); - - QQuickTransition *hideTransition() const; - void setHideTransition(QQuickTransition *); - -Q_SIGNALS: - void contentItemChanged(); - void focusChanged(); - void modalChanged(); - void visibleChanged(); - void showTransitionChanged(); - void hideTransitionChanged(); - - void pressedOutside(); - void releasedOutside(); - void clickedOutside(); - - void aboutToShow(); - void aboutToHide(); - - -public Q_SLOTS: - void show(); - void hide(); - -protected: - QQuickPanel(QQuickPanelPrivate &dd, QObject *parent); - -private: - Q_DISABLE_COPY(QQuickPanel) - Q_DECLARE_PRIVATE(QQuickPanel) -}; - -QT_END_NAMESPACE - -#endif // QQUICKPANEL_P_H diff --git a/src/templates/qquickpanel_p_p.h b/src/templates/qquickpanel_p_p.h deleted file mode 100644 index 42c06cd9..00000000 --- a/src/templates/qquickpanel_p_p.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Labs Templates module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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. -** -** 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 -** 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. -** -** 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. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKPANEL_P_P_H -#define QQUICKPANEL_P_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickItem; -class QQuickTransition; -class QQuickTransitionManager; -class QQuickPanel; -class QQuickPanelPrivate; -class QQuickOverlay; - -class QQuickPanelTransitionManager : public QQuickTransitionManager -{ -public: - QQuickPanelTransitionManager(QQuickPanelPrivate *); - void transitionShow(); - void transitionHide(); - -protected: - void finished() Q_DECL_OVERRIDE; - -private: - enum TransitionState { - Off, Show, Hide - }; - - TransitionState state; - QQuickPanelPrivate *pp; -}; - -class QQuickPanelPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QQuickPanel) - -public: - QQuickPanelPrivate(); - ~QQuickPanelPrivate(); - - void finalizeShowTransition(); - void finalizeHideTransition(); - - QQuickItem *contentItem; - QQuickOverlay *overlay; - bool focus; - bool modal; - QQuickTransition *showTransition; - QQuickTransition *hideTransition; - QQuickPanelTransitionManager transitionManager; -}; - -QT_END_NAMESPACE - -#endif // QQUICKPANEL_P_P_H - diff --git a/src/templates/qquickpopup.cpp b/src/templates/qquickpopup.cpp new file mode 100644 index 00000000..54ca6df2 --- /dev/null +++ b/src/templates/qquickpopup.cpp @@ -0,0 +1,330 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Templates module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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. +** +** 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 +** 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. +** +** 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. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickpopup_p.h" +#include "qquickpopup_p_p.h" +#include "qquickapplicationwindow_p.h" +#include "qquickoverlay_p.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Popup + \inherits QtObject + \instantiates QQuickPopup + \inqmlmodule Qt.labs.controls + \ingroup qtlabscontrols-popups + \brief A popup control. + + Popup is the base type of popup-like user interface controls. +*/ + +QQuickPopupPrivate::QQuickPopupPrivate() + : QObjectPrivate() + , contentItem(Q_NULLPTR) + , overlay(Q_NULLPTR) + , focus(false) + , modal(false) + , showTransition(Q_NULLPTR) + , hideTransition(Q_NULLPTR) + , transitionManager(this) +{ } + +QQuickPopupPrivate::~QQuickPopupPrivate() +{ } + +void QQuickPopupPrivate::finalizeShowTransition() +{ + if (focus) + contentItem->setFocus(true); +} + +void QQuickPopupPrivate::finalizeHideTransition() +{ + overlay = Q_NULLPTR; + contentItem->setParentItem(Q_NULLPTR); + emit q_func()->visibleChanged(); +} + +QQuickPopupTransitionManager::QQuickPopupTransitionManager(QQuickPopupPrivate *priv) + : QQuickTransitionManager() + , state(Off) + , pp(priv) +{ } + +void QQuickPopupTransitionManager::transitionShow() +{ + if (isRunning()) + return; + QList actions; + state = Show; + transition(actions, pp->showTransition, pp->contentItem); +} + +void QQuickPopupTransitionManager::transitionHide() +{ + if (isRunning()) + return; + QList actions; + state = Hide; + transition(actions, pp->hideTransition, pp->contentItem); +} + +void QQuickPopupTransitionManager::finished() +{ + if (state == Show) + pp->finalizeShowTransition(); + else if (state == Hide) + pp->finalizeHideTransition(); + + state = Off; +} + +QQuickPopup::QQuickPopup(QObject *parent) + : QObject(*(new QQuickPopupPrivate), parent) +{ +} + +QQuickPopup::QQuickPopup(QQuickPopupPrivate &dd, QObject *parent) + : QObject(dd, parent) +{ +} + +QQuickPopup::~QQuickPopup() +{ +} + +/*! + \qmlmethod void Qt.labs.controls::Popup::show() + + Shows the popup. +*/ +void QQuickPopup::show() +{ + Q_D(QQuickPopup); + if (!d->contentItem) { + qmlInfo(this) << "no popup content to show."; + return; + } + if (d->overlay) { + // FIXME qmlInfo needs to know about QQuickWindow and/or QObject + static_cast(qmlInfo(this) << "popup already showing in window") << d->overlay->window(); + return; + } + + QQuickWindow *win = Q_NULLPTR; + QObject *p = parent(); + while (p && !win) { + if (QQuickItem *item = qobject_cast(p)) { + win = item->window(); + if (!win) + p = item->parentItem(); + } else { + win = qobject_cast(p); + if (!win) + p = p->parent(); + } + } + if (!win) { + qmlInfo(this) << "cannot find any window to show popup."; + return; + } + + if (QQuickApplicationWindow *appWin = qobject_cast(win)) { + d->overlay = static_cast(appWin->overlay()); + d->contentItem->setParentItem(d->overlay); + } else { + // FIXME Maybe try to show it somehow on that window + qmlInfo(this) << "is not in an ApplicationWindow."; + return; + } + + emit aboutToShow(); + d->transitionManager.transitionShow(); + emit visibleChanged(); +} + +/*! + \qmlmethod void Qt.labs.controls::Popup::hide() + + Hides the popup. +*/ +void QQuickPopup::hide() +{ + Q_D(QQuickPopup); + + if (!d->overlay) { + // TODO This could mean we showed the popup item on a plain QQuickWindow + qmlInfo(this) << "trying to hide non-visible Popup."; + return; + } + + d->contentItem->setFocus(false); + emit aboutToHide(); + d->transitionManager.transitionHide(); +} + +/*! + \qmlproperty Item Qt.labs.controls::Popup::contentItem + + This property holds the content item of the popup. + + The content item is the visual implementation of the popup. When the + popup is made visible, the content item is automatically reparented to + the \l {ApplicationWindow::overlay}{overlay item} of its application + window. +*/ +QQuickItem *QQuickPopup::contentItem() const +{ + Q_D(const QQuickPopup); + return d->contentItem; +} + +void QQuickPopup::setContentItem(QQuickItem *item) +{ + Q_D(QQuickPopup); + if (d->overlay) { + // FIXME qmlInfo needs to know about QQuickItem and/or QObject + static_cast(qmlInfo(this) << "cannot set content item") << item << "while Popup is visible."; + return; + } + if (d->contentItem != item) { + delete d->contentItem; + d->contentItem = item; + if (item) + QQuickItemPrivate::get(item)->isTabFence = true; + emit contentItemChanged(); + } +} + +/*! + \qmlproperty bool Qt.labs.controls::Popup::focus + + This property holds whether the popup has focus. +*/ +bool QQuickPopup::hasFocus() const +{ + Q_D(const QQuickPopup); + return d->focus; +} + +void QQuickPopup::setFocus(bool focus) +{ + Q_D(QQuickPopup); + if (d->focus == focus) + return; + d->focus = focus; + emit focusChanged(); +} + +/*! + \qmlproperty bool Qt.labs.controls::Popup::modal + + This property holds whether the popup is modal. +*/ +bool QQuickPopup::isModal() const +{ + Q_D(const QQuickPopup); + return d->modal; +} + +void QQuickPopup::setModal(bool modal) +{ + Q_D(QQuickPopup); + if (d->modal == modal) + return; + d->modal = modal; + emit modalChanged(); +} + +/*! + \qmlproperty bool Qt.labs.controls::Popup::visible + + This property holds whether the popup is visible. +*/ +bool QQuickPopup::isVisible() const +{ + Q_D(const QQuickPopup); + return d->overlay != Q_NULLPTR /*&& !d->transitionManager.isRunning()*/; +} + +/*! + \qmlproperty Transition Qt.labs.controls::Popup::showTransition + + This property holds the transition that is applied to the content item + when the popup is shown. +*/ +QQuickTransition *QQuickPopup::showTransition() const +{ + return d_func()->showTransition; +} + +void QQuickPopup::setShowTransition(QQuickTransition *t) +{ + Q_D(QQuickPopup); + if (d->showTransition == t) + return; + d->showTransition = t; + emit showTransitionChanged(); +} + +/*! + \qmlproperty Transition Qt.labs.controls::Popup::hideTransition + + This property holds the transition that is applied to the content item + when the popup is hidden. +*/ +QQuickTransition *QQuickPopup::hideTransition() const +{ + return d_func()->hideTransition; +} + +void QQuickPopup::setHideTransition(QQuickTransition *t) +{ + Q_D(QQuickPopup); + if (d->hideTransition == t) + return; + d->hideTransition = t; + emit hideTransitionChanged(); +} + +QT_END_NAMESPACE + +#include "moc_qquickpopup_p.cpp" diff --git a/src/templates/qquickpopup_p.h b/src/templates/qquickpopup_p.h new file mode 100644 index 00000000..a2edbf6b --- /dev/null +++ b/src/templates/qquickpopup_p.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Templates module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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. +** +** 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 +** 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. +** +** 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. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKPOPUP_P_H +#define QQUICKPOPUP_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickItem; +class QQuickPopupPrivate; +class QQuickTransition; + +class Q_LABSTEMPLATES_EXPORT QQuickPopup : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) + Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged) + Q_PROPERTY(bool modal READ isModal WRITE setModal NOTIFY modalChanged) + Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged) + Q_PROPERTY(QQuickTransition *showTransition READ showTransition WRITE setShowTransition NOTIFY showTransitionChanged FINAL) + Q_PROPERTY(QQuickTransition *hideTransition READ showTransition WRITE setHideTransition NOTIFY hideTransitionChanged FINAL) + +public: + explicit QQuickPopup(QObject *parent = Q_NULLPTR); + ~QQuickPopup(); + + QQuickItem *contentItem() const; + void setContentItem(QQuickItem *item); + + bool hasFocus() const; + void setFocus(bool focus); + + bool isModal() const; + void setModal(bool modal); + + bool isVisible() const; + + QQuickTransition *showTransition() const; + void setShowTransition(QQuickTransition *); + + QQuickTransition *hideTransition() const; + void setHideTransition(QQuickTransition *); + +Q_SIGNALS: + void contentItemChanged(); + void focusChanged(); + void modalChanged(); + void visibleChanged(); + void showTransitionChanged(); + void hideTransitionChanged(); + + void pressedOutside(); + void releasedOutside(); + void clickedOutside(); + + void aboutToShow(); + void aboutToHide(); + + +public Q_SLOTS: + void show(); + void hide(); + +protected: + QQuickPopup(QQuickPopupPrivate &dd, QObject *parent); + +private: + Q_DISABLE_COPY(QQuickPopup) + Q_DECLARE_PRIVATE(QQuickPopup) +}; + +QT_END_NAMESPACE + +#endif // QQUICKPOPUP_P_H diff --git a/src/templates/qquickpopup_p_p.h b/src/templates/qquickpopup_p_p.h new file mode 100644 index 00000000..0997e12c --- /dev/null +++ b/src/templates/qquickpopup_p_p.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Templates module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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. +** +** 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 +** 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. +** +** 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. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKPOPUP_P_P_H +#define QQUICKPOPUP_P_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickItem; +class QQuickTransition; +class QQuickTransitionManager; +class QQuickPopup; +class QQuickPopupPrivate; +class QQuickOverlay; + +class QQuickPopupTransitionManager : public QQuickTransitionManager +{ +public: + QQuickPopupTransitionManager(QQuickPopupPrivate *); + void transitionShow(); + void transitionHide(); + +protected: + void finished() Q_DECL_OVERRIDE; + +private: + enum TransitionState { + Off, Show, Hide + }; + + TransitionState state; + QQuickPopupPrivate *pp; +}; + +class QQuickPopupPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QQuickPopup) + +public: + QQuickPopupPrivate(); + ~QQuickPopupPrivate(); + + void finalizeShowTransition(); + void finalizeHideTransition(); + + QQuickItem *contentItem; + QQuickOverlay *overlay; + bool focus; + bool modal; + QQuickTransition *showTransition; + QQuickTransition *hideTransition; + QQuickPopupTransitionManager transitionManager; +}; + +QT_END_NAMESPACE + +#endif // QQUICKPOPUP_P_P_H + diff --git a/src/templates/templates.pri b/src/templates/templates.pri index 82e1af9e..3f608eb2 100644 --- a/src/templates/templates.pri +++ b/src/templates/templates.pri @@ -26,8 +26,8 @@ HEADERS += \ $$PWD/qquickmenuitem_p.h \ $$PWD/qquickoverlay_p.h \ $$PWD/qquickpageindicator_p.h \ - $$PWD/qquickpanel_p.h \ - $$PWD/qquickpanel_p_p.h \ + $$PWD/qquickpopup_p.h \ + $$PWD/qquickpopup_p_p.h \ $$PWD/qquickpressandholdhelper_p.h \ $$PWD/qquickprogressbar_p.h \ $$PWD/qquickradiobutton_p.h \ @@ -70,7 +70,7 @@ SOURCES += \ $$PWD/qquickmenuitem.cpp \ $$PWD/qquickoverlay.cpp \ $$PWD/qquickpageindicator.cpp \ - $$PWD/qquickpanel.cpp \ + $$PWD/qquickpopup.cpp \ $$PWD/qquickpressandholdhelper.cpp \ $$PWD/qquickprogressbar.cpp \ $$PWD/qquickradiobutton.cpp \ diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index a0798842..c8b720cb 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -104,7 +104,7 @@ TestCase { compare(control.highlightedIndex, -1) compare(control.currentText, "") verify(control.delegate) - verify(control.panel) + verify(control.popup) control.destroy() } @@ -342,7 +342,7 @@ TestCase { compare(highlightedSpy.count, 0) compare(activatedSpy.count, 0) - // show panel + // show popup keyClick(Qt.Key_Space) compare(control.currentIndex, 0) @@ -400,7 +400,7 @@ TestCase { compare(highlightedSpy.signalArguments[0][0], 1) highlightedSpy.clear() - // hide panel + // hide popup keyClick(Qt.Key_Space) compare(control.currentIndex, 1) @@ -431,54 +431,54 @@ TestCase { verify(control.activeFocus) compare(control.pressed, false) - compare(control.panel.visible, false) + compare(control.popup.visible, false) - // show panel + // show popup keyPress(data.key1) compare(control.pressed, data.showPress) - compare(control.panel.visible, false) + compare(control.popup.visible, false) keyRelease(data.key1) compare(control.pressed, false) - compare(control.panel.visible, data.showPopup) + compare(control.popup.visible, data.showPopup) - // hide panel + // hide popup keyPress(data.key2) compare(control.pressed, data.hidePress) - compare(control.panel.visible, data.showPopup) + compare(control.popup.visible, data.showPopup) keyRelease(data.key2) compare(control.pressed, false) - compare(control.panel.visible, !data.hidePopup) + compare(control.popup.visible, !data.hidePopup) control.destroy() } - function test_panel() { + function test_popup() { var control = comboBox.createObject(window.contentItem, {model: 3}) verify(control) // show below mousePress(control) compare(control.pressed, true) - compare(control.panel.visible, false) + compare(control.popup.visible, false) mouseRelease(control) compare(control.pressed, false) - compare(control.panel.visible, true) - verify(control.panel.contentItem.y >= control.y) + compare(control.popup.visible, true) + verify(control.popup.contentItem.y >= control.y) // hide mouseClick(control) compare(control.pressed, false) - compare(control.panel.visible, false) + compare(control.popup.visible, false) // show above control.y = window.height - control.height mousePress(control) compare(control.pressed, true) - compare(control.panel.visible, false) + compare(control.popup.visible, false) mouseRelease(control) compare(control.pressed, false) - compare(control.panel.visible, true) - verify(control.panel.contentItem.y < control.y) + compare(control.popup.visible, true) + verify(control.popup.contentItem.y < control.y) control.destroy() } @@ -494,9 +494,9 @@ TestCase { verify(highlightedSpy.valid) mouseClick(control) - compare(control.panel.visible, true) + compare(control.popup.visible, true) - var content = control.panel.contentItem + var content = control.popup.contentItem waitForRendering(content) // press - move - release outside - not activated - not closed @@ -509,7 +509,7 @@ TestCase { mouseRelease(content, content.width * 2) compare(activatedSpy.count, 0) compare(highlightedSpy.count, 0) - compare(control.panel.visible, true) + compare(control.popup.visible, true) // press - move - release inside - activated - closed mousePress(content) @@ -521,7 +521,7 @@ TestCase { mouseRelease(content) compare(activatedSpy.count, 1) compare(highlightedSpy.count, 1) - compare(control.panel.visible, false) + compare(control.popup.visible, false) control.destroy() } @@ -530,16 +530,16 @@ TestCase { var control = comboBox.createObject(window.contentItem, {model: 3}) verify(control) - // click - gain focus - show panel + // click - gain focus - show popup mouseClick(control) verify(control.activeFocus) - compare(control.panel.visible, true) + compare(control.popup.visible, true) - // lose focus - hide panel + // lose focus - hide popup window.contentItem.forceActiveFocus() verify(window.contentItem.activeFocus) verify(!control.activeFocus) - compare(control.panel.visible, false) + compare(control.popup.visible, false) control.destroy() } diff --git a/tests/auto/menu/tst_menu.cpp b/tests/auto/menu/tst_menu.cpp index f4df7eb5..5823767a 100644 --- a/tests/auto/menu/tst_menu.cpp +++ b/tests/auto/menu/tst_menu.cpp @@ -149,7 +149,7 @@ void tst_menu::mouse() QVERIFY(window->overlay()->childItems().contains(menu->contentItem())); // Try pressing within the menu and releasing outside of it; it should close. - // TODO: won't work until QQuickPanel::releasedOutside() actually gets emitted + // TODO: won't work until QQuickPopup::releasedOutside() actually gets emitted // QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(firstItem->width() / 2, firstItem->height() / 2)); // QVERIFY(firstItem->hasActiveFocus()); // QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(0)); -- cgit v1.2.3