diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-11-03 18:20:15 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-11-03 19:20:42 +0100 |
commit | 6c88fe58a6037d252f40bf00aa5052b0f724a862 (patch) | |
tree | 9afdf0b638bc89e5e71eeac7b3c06ed53831e45b /src/quicktemplates2/qquickpopup.cpp | |
parent | 83cbe4e899d2d22e923bdc10e90f91ef106edf58 (diff) | |
parent | 3f646aca34c25f7cc36df2f988790bb238026422 (diff) |
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts:
src/imports/controls/BusyIndicator.qml
src/imports/controls/ProgressBar.qml
src/quicktemplates2/qquickpopup.cpp
src/quicktemplates2/qquickpopup_p_p.h
src/quicktemplates2/qquickstackview.cpp
Change-Id: I9a1028a991de9fc3e26d3f973106301e9ada631c
Diffstat (limited to 'src/quicktemplates2/qquickpopup.cpp')
-rw-r--r-- | src/quicktemplates2/qquickpopup.cpp | 203 |
1 files changed, 183 insertions, 20 deletions
diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index a7927d19..5155b339 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -56,16 +56,16 @@ QT_BEGIN_NAMESPACE \inqmlmodule QtQuick.Controls \since 5.7 \ingroup qtquickcontrols2-popups - \brief The base type of popup-like user interface controls. + \brief Base type of popup-like user interface controls. Popup is the base type of popup-like user interface controls. It can be - used with Window or ApplicationWindow. + used with \l Window or \l ApplicationWindow. \qml import QtQuick.Window 2.2 import QtQuick.Controls 2.1 - Window { + ApplicationWindow { id: window width: 400 height: 400 @@ -93,8 +93,79 @@ QT_BEGIN_NAMESPACE scene, it is recommended to use ApplicationWindow. ApplicationWindow also provides background dimming effects. - Popup lays out its content in a similar fashion to \l Control. For more - information, see the \l {Control Layout} section of the documentation. + Popup does not provide a layout of its own, but requires you to position + its contents, for instance by creating a \l RowLayout or a \l ColumnLayout. + + Items declared as children of a Popup are automatically parented to the + Popups's \l contentItem. Items created dynamically need to be explicitly + parented to the contentItem. + + \section1 Popup Layout + + The following diagram illustrates the layout of a typical popup: + + \image qtquickcontrols2-popup.png + + The \l implicitWidth and \l implicitHeight of a popup are typically based + on the implicit sizes of the background and the content item plus any + \l padding. These properties determine how large the popup will be when no + explicit \l width or \l height is specified. + + The \l background item fills the entire width and height of the popup, + unless an explicit size has been given for it. + + The geometry of the \l contentItem is determined by the \l padding. + + \section1 Popup Sizing + + If only a single item is used within a Popup, it will resize to fit the + implicit size of its contained item. This makes it particularly suitable + for use together with layouts. + + \code + Popup { + ColumnLayout { + anchors.fill: parent + CheckBox { text: qsTr("E-mail") } + CheckBox { text: qsTr("Calendar") } + CheckBox { text: qsTr("Contacts") } + } + } + \endcode + + Sometimes there might be two items within the popup: + + \code + Popup { + SwipeView { + // ... + } + PageIndicator { + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + } + } + \endcode + + In this case, Popup cannot calculate a sensible implicit size. Since we're + anchoring the \l PageIndicator over the \l SwipeView, we can simply set the + content size to the view's implicit size: + + \code + Popup { + contentWidth: view.implicitWidth + contentHeight: view.implicitHeight + + SwipeView { + id: view + // ... + } + PageIndicator { + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + } + } + \endcode \sa {Popup Controls}, {Customizing Popup}, ApplicationWindow */ @@ -424,6 +495,7 @@ QQuickPopup::~QQuickPopup() { Q_D(QQuickPopup); setParentItem(nullptr); + d->popupItem->ungrabShortcut(); delete d->popupItem; } @@ -643,8 +715,9 @@ void QQuickPopup::setImplicitHeight(qreal height) This property holds the content width. It is used for calculating the total implicit width of the Popup. - \note If only a single item is used within the Popup, the implicit width - of its contained item is used as the content width. + For more information, see \l {Popup Sizing}. + + \sa contentHeight */ qreal QQuickPopup::contentWidth() const { @@ -668,8 +741,9 @@ void QQuickPopup::setContentWidth(qreal width) This property holds the content height. It is used for calculating the total implicit height of the Popup. - \note If only a single item is used within the Popup, the implicit height - of its contained item is used as the content height. + For more information, see \l {Popup Sizing}. + + \sa contentWidth */ qreal QQuickPopup::contentHeight() const { @@ -1071,6 +1145,28 @@ void QQuickPopup::resetLocale() \qmlproperty font QtQuick.Controls::Popup::font This property holds the font currently set for the popup. + + Popup propagates explicit font properties to its children. If you change a specific + property on a popup's font, that property propagates to all of the popup's children, + overriding any system defaults for that property. + + \code + Popup { + font.family: "Courier" + + Column { + Label { + text: qsTr("This will use Courier...") + } + + Switch { + text: qsTr("... and so will this") + } + } + } + \endcode + + \sa Control::font, ApplicationWindow::font */ QFont QQuickPopup::font() const { @@ -1410,7 +1506,10 @@ void QQuickPopup::setVisible(bool visible) /*! \qmlproperty real QtQuick.Controls::Popup::opacity - This property holds the opacity of the popup. The default value is \c 1.0. + This property holds the opacity of the popup. Opacity is specified as a number between + \c 0.0 (fully transparent) and \c 1.0 (fully opaque). The default value is \c 1.0. + + \sa visible */ qreal QQuickPopup::opacity() const { @@ -1428,6 +1527,10 @@ void QQuickPopup::setOpacity(qreal opacity) \qmlproperty real QtQuick.Controls::Popup::scale This property holds the scale factor of the popup. The default value is \c 1.0. + + A scale of less than \c 1.0 causes the popup to be rendered at a smaller size, + and a scale greater than \c 1.0 renders the popup at a larger size. A negative + scale causes the popup to be mirrored when rendered. */ qreal QQuickPopup::scale() const { @@ -1473,6 +1576,12 @@ void QQuickPopup::setClosePolicy(ClosePolicy policy) if (d->closePolicy == policy) return; d->closePolicy = policy; + if (isVisible()) { + if (policy & QQuickPopup::CloseOnEscape) + d->popupItem->grabShortcut(); + else + d->popupItem->ungrabShortcut(); + } emit closePolicyChanged(); } @@ -1503,8 +1612,20 @@ void QQuickPopup::setTransformOrigin(TransformOrigin origin) /*! \qmlproperty Transition QtQuick.Controls::Popup::enter - This property holds the transition that is applied to the content item + This property holds the transition that is applied to the popup item when the popup is opened and enters the screen. + + The following example animates the opacity of the popup when it enters + the screen: + \code + Popup { + enter: Transition { + NumberAnimation { property: "opacity"; from: 0.0; to: 1.0 } + } + } + \endcode + + \sa exit */ QQuickTransition *QQuickPopup::enter() const { @@ -1524,8 +1645,20 @@ void QQuickPopup::setEnter(QQuickTransition *transition) /*! \qmlproperty Transition QtQuick.Controls::Popup::exit - This property holds the transition that is applied to the content item + This property holds the transition that is applied to the popup item when the popup is closed and exits the screen. + + The following example animates the opacity of the popup when it exits + the screen: + \code + Popup { + exit: Transition { + NumberAnimation { property: "opacity"; from: 1.0; to: 0.0 } + } + } + \endcode + + \sa enter */ QQuickTransition *QQuickPopup::exit() const { @@ -1617,12 +1750,6 @@ void QQuickPopup::keyPressEvent(QKeyEvent *event) if (hasActiveFocus() && (event->key() == Qt::Key_Tab || event->key() == Qt::Key_Backtab)) QQuickItemPrivate::focusNextPrev(d->popupItem, event->key() == Qt::Key_Tab); - - if (event->key() != Qt::Key_Escape && event->key() != Qt::Key_Back) - return; - - if (d->closePolicy.testFlag(CloseOnEscape)) - close(); } void QQuickPopup::keyReleaseEvent(QKeyEvent *event) @@ -1719,7 +1846,7 @@ void QQuickPopup::geometryChanged(const QRectF &newGeometry, const QRectF &oldGe void QQuickPopup::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) { - Q_UNUSED(data); + Q_D(QQuickPopup); switch (change) { case QQuickItem::ItemActiveFocusHasChanged: @@ -1728,6 +1855,13 @@ void QQuickPopup::itemChange(QQuickItem::ItemChange change, const QQuickItem::It case QQuickItem::ItemOpacityHasChanged: emit opacityChanged(); break; + case QQuickItem::ItemVisibleHasChanged: + if (isComponentComplete() && d->closePolicy & CloseOnEscape) { + if (data.boolValue) + d->popupItem->grabShortcut(); + else + d->popupItem->ungrabShortcut(); + } default: break; } @@ -1785,8 +1919,37 @@ QFont QQuickPopup::defaultFont() const #ifndef QT_NO_ACCESSIBILITY QAccessible::Role QQuickPopup::accessibleRole() const { - return QAccessible::LayeredPane; + return QAccessible::Dialog; +} + +void QQuickPopup::accessibilityActiveChanged(bool active) +{ + Q_UNUSED(active); } #endif // QT_NO_ACCESSIBILITY +QString QQuickPopup::accessibleName() const +{ + Q_D(const QQuickPopup); + return d->popupItem->accessibleName(); +} + +void QQuickPopup::setAccessibleName(const QString &name) +{ + Q_D(QQuickPopup); + d->popupItem->setAccessibleName(name); +} + +QVariant QQuickPopup::accessibleProperty(const char *propertyName) +{ + Q_D(const QQuickPopup); + return d->popupItem->accessibleProperty(propertyName); +} + +bool QQuickPopup::setAccessibleProperty(const char *propertyName, const QVariant &value) +{ + Q_D(QQuickPopup); + return d->popupItem->setAccessibleProperty(propertyName, value); +} + QT_END_NAMESPACE |