Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickpopup.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
14#if QT_CONFIG(quicktemplates2_container)
15#include "qquickdialog_p.h"
16#endif
17
18#include <QtCore/qloggingcategory.h>
19#include <QtQml/qqmlinfo.h>
20#include <QtQuick/qquickitem.h>
21#include <QtQuick/private/qquickaccessibleattached_p.h>
22#include <QtQuick/private/qquickattachedpropertypropagator_p.h>
23#include <QtQuick/private/qquicktransition_p.h>
24#include <QtQuick/private/qquickitem_p.h>
25#include <qpa/qplatformintegration.h>
26#include <private/qguiapplication_p.h>
27
29
30Q_STATIC_LOGGING_CATEGORY(lcDimmer, "qt.quick.controls.popup.dimmer")
31Q_STATIC_LOGGING_CATEGORY(lcQuickPopup, "qt.quick.controls.popup")
32
33/*!
34 \qmltype Popup
35 \inherits QtObject
36//! \nativetype QQuickPopup
37 \inqmlmodule QtQuick.Controls
38 \since 5.7
39 \ingroup qtquickcontrols-popups
40 \ingroup qtquickcontrols-focusscopes
41 \brief Base type of popup-like user interface controls.
42
43 Popup is the base type of popup-like user interface controls. It can be
44 used with \l Window or \l ApplicationWindow.
45
46 \qml
47 import QtQuick.Window
48 import QtQuick.Controls
49
50 ApplicationWindow {
51 id: window
52 width: 400
53 height: 400
54 visible: true
55
56 Button {
57 text: "Open"
58 onClicked: popup.open()
59 }
60
61 Popup {
62 id: popup
63 x: 100
64 y: 100
65 width: 200
66 height: 300
67 modal: true
68 focus: true
69 closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
70 }
71 }
72 \endqml
73
74 Popup does not provide a layout of its own, but requires you to position
75 its contents, for instance by creating a \l RowLayout or a \l ColumnLayout.
76
77 Items declared as children of a Popup are automatically parented to the
78 Popups's \l contentItem. Items created dynamically need to be explicitly
79 parented to the contentItem.
80
81 \section1 Popup Layout
82
83 The following diagram illustrates the layout of a popup within a window:
84
85 \image qtquickcontrols-popup.png
86 {Popup window overlaying content}
87
88 The \l implicitWidth and \l implicitHeight of a popup are typically based
89 on the implicit sizes of the background and the content item plus any insets
90 and paddings. These properties determine how large the popup will be when no
91 explicit \l width or \l height is specified.
92
93 The geometry of the \l contentItem is determined by the padding. The following
94 example reserves 10px padding between the boundaries of the popup and its content:
95
96 \code
97 Popup {
98 padding: 10
99
100 contentItem: Text {
101 text: "Content"
102 }
103 }
104 \endcode
105
106 The \l background item fills the entire width and height of the popup,
107 unless insets or an explicit size have been given for it.
108
109 Negative insets can be used to make the background larger than the popup.
110 The following example uses negative insets to place a shadow outside the
111 popup's boundaries:
112
113 \code
114 Popup {
115 topInset: -2
116 leftInset: -2
117 rightInset: -6
118 bottomInset: -6
119
120 background: BorderImage {
121 source: ":/images/shadowed-background.png"
122 }
123 }
124 \endcode
125
126 \section1 Popup type
127
128 Since Qt 6.8, some popups, such as \l Menu, offer three different implementations,
129 depending on the platform. You can choose which one you prefer by setting \l popupType.
130
131 Whether a popup will be able to use the preferred type depends on the platform.
132 \c Popup.Item is supported on all platforms, but \c Popup.Window and \c Popup.Native
133 are normally only supported on desktop platforms. Additionally, if a popup is a
134 \l Menu inside a \l {Native menu bars}{native menubar}, the menu will be native as
135 well. And if the menu is a sub-menu inside another menu, the parent (or root) menu
136 will decide the type.
137
138 \section2 Showing a popup as an item
139
140 By setting \l popupType to \c Popup.Item, the popup will \e not be shown as a separate
141 window, but as an item inside the same scene as the parent. This item is parented
142 to that scene's \l{Overlay::overlay}{overlay}, and styled to look like an actual window.
143
144 This option is especially useful on platforms that doesn't support multiple windows.
145 This was also the only option before Qt 6.8.
146
147 In order to ensure that a popup is displayed above other items in the
148 scene, it is recommended to use ApplicationWindow. ApplicationWindow also
149 provides background dimming effects.
150
151 \section2 Showing a popup as a separate window
152
153 By setting \l popupType to \c Popup.Window, the popup will be shown inside a top-level
154 \l {QQuickWindow}{window} configured with the \l Qt::Popup flag. Using a window to show a
155 popup has the advantage that the popup will float on top of the parent window, and
156 can be placed outside of its geometry. The popup will otherwise look the same as when
157 using \c Popup.Item, that is, it will use the same QML delegates and styling as
158 when using \c Popup.Item.
159
160 \note If the platform doesn't support \c Popup.Window, \c Popup.Item will be used as fallback.
161
162 \section2 Showing a native popup
163
164 By setting \l popupType to \c Popup.Native, the popup will be shown using a platform
165 native popup window. This window, and all its contents, will be rendered by the
166 platform, and not by QML. This means that the QML delegates assigned to the popup
167 will \e not be used for rendering. If you for example
168 use this option on a \l Menu, it will be implemented using platform-specific
169 menu APIs. This will normally make the popup look and feel more native than for example
170 \c Popup.Window, but at the same time, suffer from platform limitations and differences
171 related to appearance and behavior. Such limitations are documented in more detail
172 in the subclasses that are affected, such as for a
173 \l {Limitations when using native menus}{Menu}).
174
175 \note If the platform doesn't support \c Popup.Native, \c Popup.Window will be used as fallback.
176
177 \section1 Popup Sizing
178
179 If only a single item is used within a Popup, it will resize to fit the
180 implicit size of its contained item. This makes it particularly suitable
181 for use together with layouts.
182
183 \code
184 Popup {
185 ColumnLayout {
186 anchors.fill: parent
187 CheckBox { text: qsTr("E-mail") }
188 CheckBox { text: qsTr("Calendar") }
189 CheckBox { text: qsTr("Contacts") }
190 }
191 }
192 \endcode
193
194 Sometimes there might be two items within the popup:
195
196 \code
197 Popup {
198 SwipeView {
199 // ...
200 }
201 PageIndicator {
202 anchors.horizontalCenter: parent.horizontalCenter
203 anchors.bottom: parent.bottom
204 }
205 }
206 \endcode
207
208 In this case, Popup cannot calculate a sensible implicit size. Since we're
209 anchoring the \l PageIndicator over the \l SwipeView, we can simply set the
210 content size to the view's implicit size:
211
212 \code
213 Popup {
214 contentWidth: view.implicitWidth
215 contentHeight: view.implicitHeight
216
217 SwipeView {
218 id: view
219 // ...
220 }
221 PageIndicator {
222 anchors.horizontalCenter: parent.horizontalCenter
223 anchors.bottom: parent.bottom
224 }
225 }
226 \endcode
227
228 \note When using \l {Showing a popup as an item}{popup items}, the popup's
229 \l{contentItem}{content item} gets parented to the \l{Overlay::}{overlay},
230 and does not live within the popup's parent. Because of that, a \l{Item::}
231 {scale} applied to the tree in which the popup lives does not apply to the
232 visual popup. To make the popup of e.g. a \l{ComboBox} follow the scale of
233 the combobox, apply the same scale to the \l{Overlay::}{overlay} as well:
234
235 \code
236 Window {
237 property double scaleFactor: 2.0
238
239 Scale {
240 id: scale
241 xScale: scaleFactor
242 yScale: scaleFactor
243 }
244 Item {
245 id: scaledContent
246 transform: scale
247
248 ComboBox {
249 id: combobox
250 // ...
251 }
252 }
253
254 Overlay.overlay.transform: scale
255 }
256 \endcode
257
258 \section1 Popup Positioning
259
260 Similar to items in Qt Quick, Popup's \l x and \l y coordinates are
261 relative to its parent. This means that opening a popup that is a
262 child of a \l Button, for example, will cause the popup to be positioned
263 relative to the button.
264
265 \include qquickoverlay-popup-parent.qdocinc
266
267 Another way to center a popup in the window regardless of its parent item
268 is to use \l {anchors.centerIn}:
269
270 \snippet qtquickcontrols-popup.qml centerIn
271
272 To ensure that the popup is positioned within the bounds of the enclosing
273 window, the \l margins property can be set to a non-negative value.
274
275 \section1 Using the overlay
276
277 In cases where \l {Showing a popup as an item}{popup windows} are not being used,
278 Popup sets its contentItem's \l{qtquick-visualcanvas-visualparent.html}{visual parent}
279 to be the window's \l {Overlay::overlay}{overlay}, in order to ensure that
280 the popup appears in front of everything else in the scene. Its main task is to
281 intercept events to prevent delivery to items under a \l modal popup, and to close
282 the popup according to its \l closePolicy.
283
284 In some cases, it might be useful to put an item in front of a popup,
285 such as a \l [QML QtVirtualKeyboard] {InputPanel} {virtual keyboard}.
286 This can currently only be done by setting the item's parent to the overlay,
287 and ensuring that the item is stacked before any popup item, which a positive
288 \l z value ensures.
289
290 It's generally not recommended to use the overlay in this way, since the overlay wasn't
291 designed for this purpose, and the behavior won't be consistent when changing the \l popupType.
292
293 \omit
294 This shouldn't be a snippet, since we don't want VKB to be a dependency to controls.
295 \endomit
296 \qml
297 Popup {
298 id: popup
299 visible: true
300 anchors.centerIn: parent
301 margins: 10
302 closePolicy: Popup.CloseOnEscape
303 ColumnLayout {
304 TextField {
305 placeholderText: qsTr("Username")
306 }
307 TextField {
308 placeholderText: qsTr("Password")
309 echoMode: TextInput.Password
310 }
311 }
312 }
313 InputPanel {
314 parent: Overlay.overlay
315 width: parent.width
316 y: popup.y + popup.topMargin + (window.activeFocusItem?.y ?? 0) + (window.activeFocusItem?.height ?? 0)
317 z: 1
318 }
319 \endqml
320
321 \section1 Popup Transitions
322
323 After the exit transition is finished, these properties will be reset to
324 their values before the enter transition is started.
325
326 \list
327 \li \l opacity
328 \li \l scale
329 \endlist
330
331 This allows the built-in styles to animate on these properties without losing any explicitly
332 defined value.
333
334 \section1 Back/Escape Event Handling
335
336 By default, a Popup will close if:
337 \list
338 \li It has \l activeFocus,
339 \li Its \l closePolicy is \c {Popup.CloseOnEscape}, and
340 \li The user presses the key sequence for QKeySequence::Cancel (typically
341 the Escape key)
342 \endlist
343
344 To prevent this from happening, either:
345
346 \list
347 \li Don't give the popup \l focus.
348 \li Set the popup's \l closePolicy to a value that does not include
349 \c {Popup.CloseOnEscape}.
350 \li Handle \l {Keys}' \l {Keys::}{escapePressed} signal in a child item of
351 the popup so that it gets the event before the Popup.
352 \endlist
353
354 \sa {Popup Controls}, {Customizing Popup}, ApplicationWindow
355
356 \section1 Property Propagation
357
358 Popup inherits fonts, palettes and attached properties through its parent
359 window, not its
360 \l {Concepts - Visual Parent in Qt Quick#Visual Parent}{object or visual parent}:
361
362 \snippet qtquickcontrols-popup-property-propagation.qml file
363
364 \image qtquickcontrols-basic-popup-property-propagation.png
365 {Diagram showing popup property inheritance}
366
367 In addition, popups do not propagate their properties to child popups. This
368 behavior is modelled on Qt Widgets, where a \c Qt::Popup widget is a
369 top-level window. Top-level windows do not propagate their properties to
370 child windows.
371
372 Certain derived types like ComboBox are typically implemented in such a way
373 that the popup is considered an integral part of the control, and as such,
374 may inherit things like attached properties. For example, in the
375 \l {Material Style}{Material style} ComboBox, the theme and other attached
376 properties are explicitly inherited by the Popup from the ComboBox itself:
377
378 \code
379 popup: T.Popup {
380 // ...
381
382 Material.theme: control.Material.theme
383 Material.accent: control.Material.accent
384 Material.primary: control.Material.primary
385 }
386 \endcode
387
388 So, to ensure that a child popup has the same property values as its parent
389 popup, explicitly set those properties:
390
391 \code
392 Popup {
393 id: parentPopup
394 // ...
395
396 Popup {
397 palette: parentPopup.palette
398 }
399 }
400 \endcode
401
402 \section1 Polish Behavior of Closed Popups
403
404 When a popup is closed, it has no associated window, and neither do its
405 child items. This means that any child items will not be
406 \l {QQuickItem::polish}{polished} until the popup is shown. For this
407 reason, you cannot, for example, rely on a \l ListView within a closed
408 \c Popup to update its \c count property:
409
410 \code
411 import QtQuick
412 import QtQuick.Controls
413
414 ApplicationWindow {
415 width: 640
416 height: 480
417 visible: true
418
419 SomeModel {
420 id: someModel
421 }
422
423 Button {
424 text: view.count
425 onClicked: popup.open()
426 }
427
428 Popup {
429 id: popup
430 width: 400
431 height: 400
432 contentItem: ListView {
433 id: view
434 model: someModel
435 delegate: Label {
436 text: display
437
438 required property string display
439 }
440 }
441 }
442 }
443 \endcode
444
445 In the example above, the Button's text will not update when rows are added
446 to or removed from \c someModel after \l {Component::completed}{component
447 completion} while the popup is closed.
448
449 Instead, a \c count property can be added to \c SomeModel that is updated
450 whenever the \l {QAbstractItemModel::}{rowsInserted}, \l
451 {QAbstractItemModel::}{rowsRemoved}, and \l
452 {QAbstractItemModel::}{modelReset} signals are emitted. The \c Button can
453 then bind this property to its \c text.
454*/
455
456/*!
457 \qmlsignal void QtQuick.Controls::Popup::opened()
458
459 This signal is emitted when the popup is opened.
460
461 \sa aboutToShow()
462*/
463
464/*!
465 \qmlsignal void QtQuick.Controls::Popup::closed()
466
467 This signal is emitted when the popup is closed.
468
469 \sa aboutToHide()
470*/
471
472/*!
473 \qmlsignal void QtQuick.Controls::Popup::aboutToShow()
474
475 This signal is emitted when the popup is about to show.
476
477 \sa opened()
478*/
479
480/*!
481 \qmlsignal void QtQuick.Controls::Popup::aboutToHide()
482
483 This signal is emitted when the popup is about to hide.
484
485 \sa closed()
486*/
487
488QQuickItem *QQuickPopup::findParentItem() const
489{
490 QObject *obj = parent();
491 while (obj) {
492 QQuickItem *item = qobject_cast<QQuickItem *>(obj);
493 if (item)
494 return item;
495 obj = obj->parent();
496 }
497 return nullptr;
498}
499
500const QQuickPopup::ClosePolicy QQuickPopupPrivate::DefaultClosePolicy = QQuickPopup::CloseOnEscape | QQuickPopup::CloseOnPressOutside;
501
502QQuickPopupPrivate::QQuickPopupPrivate()
503 : transitionManager(this)
504{
505}
506
507void QQuickPopupPrivate::init()
508{
509 Q_Q(QQuickPopup);
510 popupItem = new QQuickPopupItem(q);
511 popupItem->setVisible(false);
512 QObject::connect(popupItem, &QQuickControl::paddingChanged, q, &QQuickPopup::paddingChanged);
513 QObject::connect(popupItem, &QQuickControl::backgroundChanged, q, &QQuickPopup::backgroundChanged);
514 QObject::connect(popupItem, &QQuickControl::contentItemChanged, q, &QQuickPopup::contentItemChanged);
515 QObject::connect(popupItem, &QQuickControl::implicitContentWidthChanged, q, &QQuickPopup::implicitContentWidthChanged);
516 QObject::connect(popupItem, &QQuickControl::implicitContentHeightChanged, q, &QQuickPopup::implicitContentHeightChanged);
517 QObject::connect(popupItem, &QQuickControl::implicitBackgroundWidthChanged, q, &QQuickPopup::implicitBackgroundWidthChanged);
518 QObject::connect(popupItem, &QQuickControl::implicitBackgroundHeightChanged, q, &QQuickPopup::implicitBackgroundHeightChanged);
519}
520
521void QQuickPopupPrivate::closeOrReject()
522{
523 Q_Q(QQuickPopup);
524#if QT_CONFIG(quicktemplates2_container)
525 if (QQuickDialog *dialog = qobject_cast<QQuickDialog*>(q))
526 dialog->reject();
527 else
528#endif
529 q->close();
530 touchId = -1;
531}
532
533bool QQuickPopupPrivate::tryClose(const QPointF &pos, QQuickPopup::ClosePolicy flags)
534{
535 if (!interactive)
536 return false;
537
538 static const QQuickPopup::ClosePolicy outsideFlags = QQuickPopup::CloseOnPressOutside | QQuickPopup::CloseOnReleaseOutside;
539 static const QQuickPopup::ClosePolicy outsideParentFlags = QQuickPopup::CloseOnPressOutsideParent | QQuickPopup::CloseOnReleaseOutsideParent;
540
541 const bool onOutside = closePolicy & (flags & outsideFlags);
542 const bool onOutsideParent = closePolicy & (flags & outsideParentFlags);
543
544 if ((onOutside && outsidePressed) || (onOutsideParent && outsideParentPressed)) {
545 if (!contains(pos) && (!dimmer || dimmer->contains(dimmer->mapFromScene(pos)))) {
546 if (!onOutsideParent || !parentItem || !parentItem->contains(parentItem->mapFromScene(pos))) {
547 closeOrReject();
548 return true;
549 }
550 }
551 }
552 return false;
553}
554
555bool QQuickPopupPrivate::contains(const QPointF &scenePos) const
556{
557 return popupItem->contains(popupItem->mapFromScene(scenePos));
558}
559
560static QQuickItem *findRootOfOverlaySubtree(QQuickItem *source, const QQuickOverlay *overlay)
561{
562 QQuickItem *sourceAncestor = source;
563 while (sourceAncestor) {
564 QQuickItem *parentItem = sourceAncestor->parentItem();
565 if (parentItem == overlay)
566 return sourceAncestor;
567 sourceAncestor = parentItem;
568 }
569 // Not an ancestor of the overlay.
570 return nullptr;
571}
572
573bool QQuickPopupPrivate::belongsToOverlayChildAbove(QQuickItem *item) const
574{
575 auto *overlay = QQuickOverlay::overlay(window, parentItem);
576 Q_ASSERT(overlay);
577 const auto paintOrderChildItems = QQuickOverlayPrivate::get(overlay)->paintOrderChildItems();
578 return paintOrderChildItems.indexOf(findRootOfOverlaySubtree(item, overlay))
579 > paintOrderChildItems.indexOf(popupItem);
580}
581
582#if QT_CONFIG(quicktemplates2_multitouch)
583bool QQuickPopupPrivate::acceptTouch(const QTouchEvent::TouchPoint &point)
584{
585 if (point.id() == touchId)
586 return true;
587
588 if (touchId == -1 && point.state() != QEventPoint::Released) {
589 touchId = point.id();
590 return true;
591 }
592
593 return false;
594}
595#endif
596
597bool QQuickPopupPrivate::blockInput(QQuickItem *item, const QPointF &point) const
598{
599 // don't propagate events within the popup beyond the overlay
600 if (popupItem->contains(popupItem->mapFromScene(point))
601 && item == QQuickOverlay::overlay(window, parentItem)) {
602 return true;
603 }
604
605 // don't block presses and releases
606 // a) outside a non-modal popup,
607 // b) to popup children/content, or
608 // c) outside a modal popups's background dimming
609
610 return modal && ((popupItem != item) && !popupItem->isAncestorOf(item)) && (!dimmer || dimmer->contains(dimmer->mapFromScene(point)));
611}
612
613bool QQuickPopupPrivate::handlePress(QQuickItem *item, const QPointF &point, ulong timestamp)
614{
615 Q_UNUSED(timestamp);
616 pressPoint = point;
617 outsidePressed = !contains(point);
618
619 if (outsidePressed && parentItem) {
620 // Note that the parentItem (e.g a menuBarItem, in case of a MenuBar) will
621 // live inside another window when using popup windows. We therefore need to
622 // map to and from global.
623 const QPointF globalPoint = item->mapToGlobal(item->mapFromScene(point));
624 const QPointF localPoint = parentItem->mapFromGlobal(globalPoint);
625 outsideParentPressed = !parentItem->contains(localPoint);
626 }
627
628 tryClose(point, QQuickPopup::CloseOnPressOutside | QQuickPopup::CloseOnPressOutsideParent);
629 return blockInput(item, point);
630}
631
632bool QQuickPopupPrivate::handleMove(QQuickItem *item, const QPointF &point, ulong timestamp)
633{
634 Q_UNUSED(timestamp);
635 return blockInput(item, point);
636}
637
638bool QQuickPopupPrivate::handleRelease(QQuickItem *item, const QEventPoint &point)
639{
640 const QPointF scenePosition = point.scenePosition();
641 if (item != popupItem && !contains(pressPoint))
642 tryClose(scenePosition, QQuickPopup::CloseOnReleaseOutside | QQuickPopup::CloseOnReleaseOutsideParent);
643 pressPoint = QPointF();
644 outsidePressed = false;
645 outsideParentPressed = false;
646 touchId = -1;
647 return blockInput(item, scenePosition);
648}
649
650void QQuickPopupPrivate::handleUngrab()
651{
652 Q_Q(QQuickPopup);
653 QQuickOverlay *overlay = QQuickOverlay::overlay(window, parentItem);
654 if (overlay) {
655 QQuickOverlayPrivate *p = QQuickOverlayPrivate::get(overlay);
656 if (p->mouseGrabberPopup == q)
657 p->mouseGrabberPopup = nullptr;
658 }
659 pressPoint = QPointF();
660 touchId = -1;
661}
662
663bool QQuickPopupPrivate::handleMouseEvent(QQuickItem *item, QMouseEvent *event)
664{
665 switch (event->type()) {
666 case QEvent::MouseButtonPress:
667 return handlePress(item, event->scenePosition(), event->timestamp());
668 case QEvent::MouseMove:
669 return handleMove(item, event->scenePosition(), event->timestamp());
670 case QEvent::MouseButtonRelease:
671 return handleRelease(item, event->point(0));
672 default:
673 Q_UNREACHABLE_RETURN(false);
674 }
675}
676
677bool QQuickPopupPrivate::handleHoverEvent(QQuickItem *item, QHoverEvent *event)
678{
679 switch (event->type()) {
680 case QEvent::HoverEnter:
681 case QEvent::HoverMove:
682 case QEvent::HoverLeave:
683 return blockInput(item, event->scenePosition());
684 default:
685 Q_UNREACHABLE_RETURN(false);
686 }
687}
688
689QMarginsF QQuickPopupPrivate::windowInsets() const
690{
691 Q_Q(const QQuickPopup);
692 // If the popup has negative insets, it means that its background is pushed
693 // outside the bounds of the popup. This is fine when the popup is an item in the
694 // scene (Popup.Item), but will result in the background being clipped when using
695 // a window (Popup.Window). To avoid this, the window will been made bigger than
696 // the popup (according to the insets), to also include the part that ends up
697 // outside (which is usually a drop-shadow).
698 // Note that this also means that we need to take those extra margins into account
699 // whenever we resize or position the menu, so that the top-left of the popup ends
700 // up at the requested position, and not the top-left of the window.
701
702 const auto *popupItemPrivate = QQuickControlPrivate::get(popupItem);
703 if (!usePopupWindow() || (popupItemPrivate->background.isExecuting() && popupItemPrivate->background->clip())) {
704 // Items in the scene are allowed to draw out-of-bounds, so we don't
705 // need to do anything if we're not using popup windows. The same is
706 // also true for popup windows if the background is clipped.
707 return {0, 0, 0, 0};
708 }
709
710 return {
711 q->leftInset() < 0 ? -q->leftInset() : 0,
712 q->topInset() < 0 ? -q->topInset() : 0,
713 q->rightInset() < 0 ? -q->rightInset() : 0,
714 q->bottomInset() < 0 ? -q->bottomInset() : 0
715 };
716}
717
718QPointF QQuickPopupPrivate::windowInsetsTopLeft() const
719{
720 const QMarginsF windowMargins = windowInsets();
721 return {windowMargins.left(), windowMargins.top()};
722}
723
724void QQuickPopupPrivate::setEffectivePosFromWindowPos(const QPointF &windowPos)
725{
726 // Popup operates internally with three different positions; requested
727 // position, effective position, and window position. The first is the
728 // position requested by the application, and the second is where the popup
729 // is actually placed. The reason for placing it on a different position than
730 // the one requested, is to keep it inside the window (in case of Popup.Item),
731 // or the screen (in case of Popup.Window).
732 // Additionally, since a popup can set Qt::FramelessWindowHint and draw the
733 // window frame from the background delegate, the effective position in that
734 // case is adjusted to be the top-left corner of the background delegate, rather
735 // than the top-left corner of the window. This allowes the background delegate
736 // to render a drop-shadow between the edge of the window and the background frame.
737 // Finally, the window position is the actual position of the window, including
738 // any drop-shadow effects. This posision can be calculated by taking
739 // the effective position and subtract the dropShadowOffset().
740 Q_Q(QQuickPopup);
741 const QPointF oldEffectivePos = effectivePos;
742 effectivePos = windowPos + windowInsetsTopLeft();
743 if (!qFuzzyCompare(oldEffectivePos.x(), effectivePos.x()))
744 emit q->xChanged();
745 if (!qFuzzyCompare(oldEffectivePos.y(), effectivePos.y()))
746 emit q->yChanged();
747}
748
749#if QT_CONFIG(quicktemplates2_multitouch)
750bool QQuickPopupPrivate::handleTouchEvent(QQuickItem *item, QTouchEvent *event)
751{
752 switch (event->type()) {
753 case QEvent::TouchBegin:
754 case QEvent::TouchUpdate:
755 case QEvent::TouchEnd:
756 for (const QTouchEvent::TouchPoint &point : event->points()) {
757 if (event->type() != QEvent::TouchEnd && !acceptTouch(point))
758 return blockInput(item, point.position());
759
760 switch (point.state()) {
761 case QEventPoint::Pressed:
762 return handlePress(item, point.scenePosition(), event->timestamp());
763 case QEventPoint::Updated:
764 return handleMove(item, point.scenePosition(), event->timestamp());
765 case QEventPoint::Released:
766 return handleRelease(item, point);
767 default:
768 break;
769 }
770 }
771 break;
772
773 case QEvent::TouchCancel:
774 handleUngrab();
775 break;
776
777 default:
778 break;
779 }
780
781 return false;
782}
783#endif
784
785bool QQuickPopupPrivate::prepareEnterTransition()
786{
787 Q_Q(QQuickPopup);
788 if (!window) {
789 qmlWarning(q) << "cannot find any window to open popup in.";
790 return false;
791 }
792
793 if (transitionState == EnterTransition && transitionManager.isRunning())
794 return false;
795
796 if (transitionState != EnterTransition) {
797 const QPointer<QQuickItem> lastActiveFocusItem = window->activeFocusItem();
798 visible = true;
799 adjustPopupItemParentAndWindow();
800 if (dim)
801 createOverlay();
802 showDimmer();
803 emit q->aboutToShow();
804 transitionState = EnterTransition;
805 getPositioner()->setParentItem(parentItem);
806 emit q->visibleChanged();
807
808 // Popup windows live in their own window with their own focus chain, so the
809 // parent window keeps its activeFocusItem and nothing needs to be saved.
810 if (lastActiveFocusItem && !usePopupWindow()) {
811 this->lastActiveFocusItem = lastActiveFocusItem;
812 if (auto *overlay = QQuickOverlay::overlay(window, parentItem)) {
813 auto *overlayPrivate = QQuickOverlayPrivate::get(overlay);
814 if (overlayPrivate->lastActiveFocusItem.isNull() && !popupItem->isAncestorOf(lastActiveFocusItem)) {
815 overlayPrivate->lastActiveFocusItem = lastActiveFocusItem;
816 overlayPrivate->lastActiveFocusItemPopup = q;
817 }
818 }
819 }
820
821 if (focus)
822 popupItem->setFocus(true, Qt::PopupFocusReason);
823 }
824 return true;
825}
826
827bool QQuickPopupPrivate::prepareExitTransition()
828{
829 Q_Q(QQuickPopup);
830 if (transitionState == ExitTransition && transitionManager.isRunning())
831 return false;
832
833 Q_ASSERT(popupItem);
834
835 // We need to cache the original scale and opacity values so we can reset it after
836 // the exit transition is done so they have the original values again
837 prevScale = popupItem->scale();
838 prevOpacity = popupItem->opacity();
839
840 if (transitionState != ExitTransition) {
841 // The setFocus(false) call below removes any active focus before we're
842 // able to check it in finalizeExitTransition.
843 if (!hadActiveFocusBeforeExitTransition) {
844 const auto *da = QQuickItemPrivate::get(popupItem)->deliveryAgentPrivate();
845 hadActiveFocusBeforeExitTransition = popupItem->hasActiveFocus() || (da && da->focusTargetItem() == popupItem);
846 }
847 if (focus)
848 popupItem->setFocus(false, Qt::PopupFocusReason);
849 transitionState = ExitTransition;
850 hideDimmer();
851 emit q->aboutToHide();
852 emit q->openedChanged();
853 }
854 return true;
855}
856
857void QQuickPopupPrivate::finalizeEnterTransition()
858{
859 Q_Q(QQuickPopup);
860 transitionState = NoTransition;
861 reposition();
862 emit q->openedChanged();
863 opened();
864}
865
866void QQuickPopupPrivate::finalizeExitTransition()
867{
868 Q_Q(QQuickPopup);
869 getPositioner()->setParentItem(nullptr);
870 if (popupItem) {
871 popupItem->setParentItem(nullptr);
872 popupItem->setVisible(false);
873 }
874 destroyDimmer();
875
876 if (auto *overlay = QQuickOverlay::overlay(window, parentItem)) {
877 auto *overlayPrivate = QQuickOverlayPrivate::get(overlay);
878 const auto stackingOrderPopups = overlayPrivate->stackingOrderPopups();
879 // Reset the last active focus item in the overlay when this popup exit
880 bool resetLastActiveFocusItem = (overlayPrivate->lastActiveFocusItemPopup == q);
881 if (resetLastActiveFocusItem) {
882 /**
883 * Check for popups in the stack that:
884 * 1. Are not in an exit transition.
885 * 2. Contain a saved last active focus item (from the window).
886 * If found, update the overlay's focus reference to this item and
887 * prevent a reset. This ensures focus returns to the correct
888 * pre-popup element once the window clears.
889 */
890 for (auto popup : stackingOrderPopups) {
891 if (QQuickPopupPrivate::get(popup)->transitionState != ExitTransition) {
892 if (auto savedFocusItem = QQuickPopupPrivate::get(popup)->lastActiveFocusItem) {
893 if (!qobject_cast<QQuickRootItem *>(savedFocusItem) && savedFocusItem != popupItem
894 && !popupItem->isAncestorOf(savedFocusItem)) {
895 overlayPrivate->lastActiveFocusItem = savedFocusItem;
896 }
897 overlayPrivate->lastActiveFocusItemPopup = popup;
898 resetLastActiveFocusItem = false;
899 break;
900 }
901 }
902 }
903 }
904
905 // An in-scene popup opened from inside a popup window lives in that popup window's
906 // overlay. If that popup is closing too, don't restore focus into its window. Doing so
907 // would set `focus` on its popupItem again, after being cleared in prepareExitTransition().
908 bool hostPopupClosing = false;
909 if (auto *hostWindow = qobject_cast<QQuickPopupWindow *>(window)) {
910 if (QQuickPopup *hostPopup = hostWindow->popup()) {
911 hostPopupClosing = !hostPopup->isVisible()
912 || QQuickPopupPrivate::get(hostPopup)->transitionState == ExitTransition;
913 }
914 }
915
916 // Restore focus to the next popup in chain, or to the window content if there are no other popups open.
917 // Only necessary when popupType: Popup.Item.
918 if (hadActiveFocusBeforeExitTransition && !usePopupWindow() && !hostPopupClosing) {
919 QQuickPopup *nextFocusPopup = nullptr;
920 for (auto popup : stackingOrderPopups) {
921 // only pick a popup that is focused but has not already been activated
922 if (QQuickPopupPrivate::get(popup)->transitionState != ExitTransition
923 && popup->hasFocus() && !popup->hasActiveFocus()) {
924 nextFocusPopup = popup;
925 break;
926 }
927 }
928 if (nextFocusPopup) {
929 nextFocusPopup->forceActiveFocus(Qt::PopupFocusReason);
930 } else {
931 auto *appWindow = qobject_cast<QQuickApplicationWindow*>(window);
932 auto *contentItem = appWindow ? appWindow->contentItem() : window->contentItem();
933 if (!contentItem->scopedFocusItem()
934 && !overlayPrivate->lastActiveFocusItem.isNull()) {
935 // The last active focus item may have lost focus not just for
936 // itself but for its entire focus chain, so force active focus.
937 overlayPrivate->lastActiveFocusItem->forceActiveFocus(Qt::OtherFocusReason);
938 } else {
939 contentItem->setFocus(true, Qt::PopupFocusReason);
940 }
941 }
942 }
943
944 // Clear the overlay's saved focus if this popup was the one that set it
945 if (resetLastActiveFocusItem || stackingOrderPopups.isEmpty()) {
946 overlayPrivate->lastActiveFocusItem = nullptr;
947 overlayPrivate->lastActiveFocusItemPopup = nullptr;
948 }
949 }
950
951 visible = false;
952 adjustPopupItemParentAndWindow();
953 transitionState = NoTransition;
954 hadActiveFocusBeforeExitTransition = false;
955 lastActiveFocusItem = nullptr;
956 emit q->visibleChanged();
957 emit q->closed();
958#if QT_CONFIG(accessibility)
959 const auto type = q->effectiveAccessibleRole() == QAccessible::PopupMenu
960 ? QAccessible::PopupMenuEnd
961 : QAccessible::DialogEnd;
962 QAccessibleEvent ev(q->popupItem(), type);
963 QAccessible::updateAccessibility(&ev);
964#endif
965 if (popupItem) {
966 popupItem->setScale(prevScale);
967 popupItem->setOpacity(prevOpacity);
968 }
969}
970
971void QQuickPopupPrivate::opened()
972{
973 Q_Q(QQuickPopup);
974 emit q->opened();
975#if QT_CONFIG(accessibility)
976 const auto type = q->effectiveAccessibleRole() == QAccessible::PopupMenu
977 ? QAccessible::PopupMenuStart
978 : QAccessible::DialogStart;
979 QAccessibleEvent ev(q->popupItem(), type);
980 QAccessible::updateAccessibility(&ev);
981#endif
982}
983
984Qt::WindowFlags QQuickPopupPrivate::popupWindowFlags() const
985{
986 return windowFlags;
987}
988
989void QQuickPopupPrivate::setPopupWindowFlags(Qt::WindowFlags flags)
990{
991 windowFlags = flags;
992}
993
994QMarginsF QQuickPopupPrivate::getMargins() const
995{
996 Q_Q(const QQuickPopup);
997 return QMarginsF(q->leftMargin(), q->topMargin(), q->rightMargin(), q->bottomMargin());
998}
999
1000void QQuickPopupPrivate::setTopMargin(qreal value, bool reset)
1001{
1002 Q_Q(QQuickPopup);
1003 qreal oldMargin = q->topMargin();
1004 topMargin = value;
1005 hasTopMargin = !reset;
1006 if ((!reset && !qFuzzyCompare(oldMargin, value)) || (reset && !qFuzzyCompare(oldMargin, margins))) {
1007 emit q->topMarginChanged();
1008 q->marginsChange(QMarginsF(leftMargin, topMargin, rightMargin, bottomMargin),
1009 QMarginsF(leftMargin, oldMargin, rightMargin, bottomMargin));
1010 }
1011}
1012
1013void QQuickPopupPrivate::setLeftMargin(qreal value, bool reset)
1014{
1015 Q_Q(QQuickPopup);
1016 qreal oldMargin = q->leftMargin();
1017 leftMargin = value;
1018 hasLeftMargin = !reset;
1019 if ((!reset && !qFuzzyCompare(oldMargin, value)) || (reset && !qFuzzyCompare(oldMargin, margins))) {
1020 emit q->leftMarginChanged();
1021 q->marginsChange(QMarginsF(leftMargin, topMargin, rightMargin, bottomMargin),
1022 QMarginsF(oldMargin, topMargin, rightMargin, bottomMargin));
1023 }
1024}
1025
1026void QQuickPopupPrivate::setRightMargin(qreal value, bool reset)
1027{
1028 Q_Q(QQuickPopup);
1029 qreal oldMargin = q->rightMargin();
1030 rightMargin = value;
1031 hasRightMargin = !reset;
1032 if ((!reset && !qFuzzyCompare(oldMargin, value)) || (reset && !qFuzzyCompare(oldMargin, margins))) {
1033 emit q->rightMarginChanged();
1034 q->marginsChange(QMarginsF(leftMargin, topMargin, rightMargin, bottomMargin),
1035 QMarginsF(leftMargin, topMargin, oldMargin, bottomMargin));
1036 }
1037}
1038
1039void QQuickPopupPrivate::setBottomMargin(qreal value, bool reset)
1040{
1041 Q_Q(QQuickPopup);
1042 qreal oldMargin = q->bottomMargin();
1043 bottomMargin = value;
1044 hasBottomMargin = !reset;
1045 if ((!reset && !qFuzzyCompare(oldMargin, value)) || (reset && !qFuzzyCompare(oldMargin, margins))) {
1046 emit q->bottomMarginChanged();
1047 q->marginsChange(QMarginsF(leftMargin, topMargin, rightMargin, bottomMargin),
1048 QMarginsF(leftMargin, topMargin, rightMargin, oldMargin));
1049 }
1050}
1051
1052/*!
1053 \since QtQuick.Controls 2.5 (Qt 5.12)
1054 \qmlproperty Item QtQuick.Controls::Popup::anchors.centerIn
1055
1056 Anchors provide a way to position an item by specifying its
1057 relationship with other items.
1058
1059 A common use case is to center a popup within its parent. One way to do
1060 this is with the \l[QtQuick]{Item::}{x} and \l[QtQuick]{Item::}{y} properties. Anchors offer
1061 a more convenient approach:
1062
1063 \qml
1064 Pane {
1065 // ...
1066
1067 Popup {
1068 anchors.centerIn: parent
1069 }
1070 }
1071 \endqml
1072
1073 It is also possible to center the popup in the window by using \l Overlay:
1074
1075 \snippet qtquickcontrols-popup.qml centerIn
1076
1077 This makes it easy to center a popup in the window from any component.
1078
1079 \note Popups can only be centered within their immediate parent or
1080 the window overlay; trying to center in other items will produce a warning.
1081
1082 \sa {Popup Positioning}, {Item::}{anchors}, {Using Qt Quick Controls types
1083 in property declarations}
1084*/
1085QQuickPopupAnchors *QQuickPopupPrivate::getAnchors()
1086{
1087 Q_Q(QQuickPopup);
1088 if (!anchors)
1089 anchors = new QQuickPopupAnchors(q);
1090 return anchors;
1091}
1092
1093QQuickPopupPositioner *QQuickPopupPrivate::getPositioner()
1094{
1095 Q_Q(QQuickPopup);
1096 if (!positioner)
1097 positioner = new QQuickPopupPositioner(q);
1098 return positioner;
1099}
1100
1101
1103{
1104 Q_OBJECT
1105public:
1107 : m_func(func)
1108 {
1109 w->installEventFilter(this);
1110 }
1111protected:
1114 if (event->type() == QEvent::Expose)
1115 m_func();
1116 return false;
1117 }
1118private:
1119 std::function<void()> m_func;
1120};
1121
1123{
1125 observer->disconnect();
1126 observer->deleteLater();
1127 }
1128};
1130
1131/*!
1132 \internal
1133 A popup's position is meant to be relative to its nearest parent item.
1134 If this item exists in another window, the position needs to be mapped between the windows.
1135 We use mapToGlobal(QPointF) to figure out where to position the popup window.
1136 However, if mapToGlobal(QPointF) is called before the parent window is exposed,
1137 it will on Windows and X11 assume that the parent windows position is (0,0).
1138 This means that the popup window's position will usually be wrong, when it's
1139 opened at the same time as the parent window.
1140 To work around this issue, we wait for the parent window to be exposed, before opening the popup window.
1141 */
1142void openPopup(QQuickPopupPrivate *d)
1143{
1144#if defined(Q_OS_MACOS)
1145 d->transitionManager.transitionEnter();
1146#else
1147 const auto callPrepareEnterTransition = [d]() {
1148 d->transitionManager.transitionEnter();
1149 std::ignore = s_windowExposedObserver.release();
1150 };
1151 if (d->usePopupWindow() && d->window->isVisible() && !d->window->isExposed())
1152 s_windowExposedObserver.reset(new QWindowExposedObserver(d->window, callPrepareEnterTransition));
1153 else
1154 callPrepareEnterTransition();
1155#endif
1156}
1157
1158void QQuickPopupPrivate::setWindow(QQuickWindow *newWindow)
1159{
1160 Q_Q(QQuickPopup);
1161 if (window == newWindow)
1162 return;
1163
1164 if (window) {
1165 QQuickOverlay *overlay = QQuickOverlay::overlay(window, parentItem);
1166 if (overlay)
1167 QQuickOverlayPrivate::get(overlay)->removePopup(q);
1168
1169 // Interacting with Popups in async Loaders (QTBUG-139306) would cause crashes
1170 // because the popup's window was null. We can avoid this by unparenting the popupItem,
1171 // which removes it from stackingOrderPopups and hence excludes it from receiving events.
1172 if (!newWindow && popupItem)
1173 popupItem->setParentItem(nullptr);
1174 }
1175
1176 window = newWindow;
1177
1178 if (newWindow) {
1179 QQuickOverlay *overlay = QQuickOverlay::overlay(newWindow, parentItem);
1180 if (overlay)
1181 QQuickOverlayPrivate::get(overlay)->addPopup(q);
1182
1183 QQuickControlPrivate *p = QQuickControlPrivate::get(popupItem);
1184 p->resolveFont();
1185 if (QQuickApplicationWindow *appWindow = qobject_cast<QQuickApplicationWindow *>(newWindow))
1186 p->updateLocale(appWindow->locale(), false); // explicit=false
1187 }
1188
1189 emit q->windowChanged(newWindow);
1190
1191 if (complete && visible && window)
1192 openPopup(this);
1193}
1194
1195void QQuickPopupPrivate::itemDestroyed(QQuickItem *item)
1196{
1197 Q_Q(QQuickPopup);
1198 if (item == parentItem)
1199 q->setParentItem(nullptr);
1200}
1201
1202void QQuickPopupPrivate::reposition()
1203{
1204 getPositioner()->reposition();
1205}
1206
1207QPalette QQuickPopupPrivate::defaultPalette() const
1208{
1209 return QQuickTheme::palette(QQuickTheme::System);
1210}
1211
1212QQuickPopup::PopupType QQuickPopupPrivate::resolvedPopupType() const
1213{
1214 // Whether or not the resolved popup type ends up the same as the preferred popup type
1215 // depends on platform capabilities, the popup subclass, and sometimes also the location
1216 // of the popup in the parent hierarchy (menus). This function can therefore be overridden
1217 // to return the actual popup type that should be used, based on the knowledge the popup
1218 // has just before it's about to be shown.
1219
1220 // PopupType::Native is not directly supported by QQuickPopup (only by subclasses).
1221 // So for that case, we fall back to use PopupType::Window, if supported.
1222 if (popupType == QQuickPopup::PopupType::Window
1223 || popupType == QQuickPopup::PopupType::Native) {
1224 if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::Capability::MultipleWindows))
1225 return QQuickPopup::PopupType::Window;
1226 }
1227
1228 return QQuickPopup::PopupType::Item;
1229}
1230
1231bool QQuickPopupPrivate::usePopupWindow() const
1232{
1233 return resolvedPopupType() == QQuickPopup::PopupType::Window;
1234}
1235
1236void QQuickPopupPrivate::adjustPopupItemParentAndWindow()
1237{
1238 Q_Q(QQuickPopup);
1239 QQuickOverlay *overlay = QQuickOverlay::overlay(window, parentItem);
1240
1241 if (visible && popupWindowDirty) {
1242 popupItem->setParentItem(overlay);
1243 if (popupWindow) {
1244 popupWindow->deleteLater();
1245 popupWindow = nullptr;
1246 }
1247 popupWindowDirty = false;
1248 }
1249
1250 if (usePopupWindow()) {
1251 if (visible) {
1252 if (!popupWindow) {
1253 QWindow *ancestor = window;
1254 while (ancestor->parent())
1255 ancestor = ancestor->parent();
1256 popupWindow = new QQuickPopupWindow(q, ancestor);
1257 // Changing the visual parent can cause the popup item's implicit width/height to change.
1258 // We store the initial size here first, to ensure that we're resizing the window to the correct size.
1259 QMarginsF effectiveInsets = windowInsets();
1260#if QT_CONFIG(wayland)
1261 // On wayland the inset is added by the window through custom margins.
1262 if (QGuiApplication::platformName().startsWith(QLatin1String("wayland")))
1263 effectiveInsets = QMarginsF();
1264#endif
1265 const qreal initialWidth = popupItem->width() + effectiveInsets.left() + effectiveInsets.right();
1266 const qreal initialHeight = popupItem->height() + effectiveInsets.top() + effectiveInsets.bottom();
1267 popupItem->setParentItem(popupWindow->contentItem());
1268 popupWindow->resize(qCeil(initialWidth), qCeil(initialHeight));
1269 if (popupWndModality != Qt::NonModal)
1270 popupWindow->setModality(popupWndModality);
1271 else
1272 popupWindow->setModality(modal ? Qt::ApplicationModal : Qt::NonModal);
1273 popupItem->resetTitle();
1274 popupWindow->setTitle(title);
1275 }
1276 popupItem->setParentItem(popupWindow->contentItem());
1277 popupItem->forceActiveFocus(Qt::PopupFocusReason);
1278#if QT_CONFIG(wayland)
1279 // On wayland a Qt::Popup is grabbing by default.
1280 if (QGuiApplication::platformName().startsWith(QLatin1String("wayland")))
1281 popupWindow->setFlag(Qt::WindowDoesNotAcceptFocus, !q->hasFocus());
1282#endif
1283 }
1284 if (popupWindow && popupWindow->transientParent()) {
1285 if (qobject_cast<QQuickWindow *>(popupWindow->transientParent())) {
1286 auto *transientParentPriv = QQuickWindowPrivate::get(qobject_cast<QQuickWindow *>(popupWindow->transientParent()));
1287 if (!transientParentPriv->inDestructor)
1288 popupWindow->setVisible(visible);
1289 } else {
1290 popupWindow->setVisible(visible);
1291 }
1292 }
1293 } else {
1294 if (visible) {
1295 popupItem->setParentItem(overlay);
1296 const auto popupStack = QQuickOverlayPrivate::get(overlay)->stackingOrderPopups();
1297 // if there is a stack of popups, and the current top popup item belongs to an
1298 // ancestor of this popup, then make sure that this popup's item is at the top
1299 // of the stack.
1300 const QQuickPopup *topPopup = popupStack.isEmpty() ? nullptr : popupStack.first();
1301 const QObject *ancestor = q;
1302 while (ancestor && topPopup) {
1303 if (ancestor == topPopup)
1304 break;
1305 ancestor = ancestor->parent();
1306 }
1307 if (topPopup && topPopup != q && ancestor) {
1308 QQuickItem *topPopupItem = popupStack.first()->popupItem();
1309 popupItem->stackAfter(topPopupItem);
1310 // If the popup doesn't have an explicit z value set, set it to be at least as
1311 // high as the current top popup item so that later opened popups are on top.
1312 if (!hasZ)
1313 popupItem->setZ(qMax(topPopupItem->z(), popupItem->z()));
1314 }
1315 q->setModal((popupWndModality != Qt::NonModal) || modal);
1316 }
1317
1318 popupItem->setTitle(title);
1319 }
1320 popupItem->setVisible(visible);
1321}
1322
1323QQuickItem *QQuickPopupPrivate::createDimmer(QQmlComponent *component, QQuickPopup *popup, QQuickItem *parent) const
1324{
1325 QQuickItem *item = nullptr;
1326 if (component) {
1327 QQmlContext *context = component->creationContext();
1328 if (!context)
1329 context = qmlContext(popup);
1330 item = qobject_cast<QQuickItem*>(component->beginCreate(context));
1331 }
1332
1333 // when there is no overlay component available (with plain QQuickWindow),
1334 // use a plain QQuickItem as a fallback to block hover events
1335 if (!item && popup->isModal())
1336 item = new QQuickItem;
1337
1338 if (item) {
1339 item->setParentItem(parent);
1340 if (resolvedPopupType() != QQuickPopup::PopupType::Window)
1341 item->stackBefore(popup->popupItem());
1342 item->setZ(popup->z());
1343 // needed for the virtual keyboard to set a containment mask on the dimmer item
1344 qCDebug(lcDimmer) << "dimmer" << item << "registered with" << parent;
1345 parent->setProperty("_q_dimmerItem", QVariant::fromValue<QQuickItem*>(item));
1346 if (popup->isModal()) {
1347 item->setAcceptedMouseButtons(Qt::AllButtons);
1348#if QT_CONFIG(cursor)
1349 item->setCursor(Qt::ArrowCursor);
1350#endif
1351#if QT_CONFIG(quicktemplates2_hover)
1352 // TODO: switch to QStyleHints::useHoverEffects in Qt 5.8
1353 item->setAcceptHoverEvents(true);
1354 // item->setAcceptHoverEvents(QGuiApplication::styleHints()->useHoverEffects());
1355 // connect(QGuiApplication::styleHints(), &QStyleHints::useHoverEffectsChanged, item, &QQuickItem::setAcceptHoverEvents);
1356#endif
1357 }
1358 if (component)
1359 component->completeCreate();
1360 }
1361 qCDebug(lcDimmer) << "finished creating dimmer from component" << component
1362 << "for popup" << popup << "with parent" << parent << "- item is:" << item;
1363 return item;
1364}
1365
1366void QQuickPopupPrivate::createOverlay()
1367{
1368 Q_Q(QQuickPopup);
1369 QQuickOverlay *overlay = QQuickOverlay::overlay(window, parentItem);
1370 if (!overlay)
1371 return;
1372
1373 QQmlComponent *component = nullptr;
1374 QQuickOverlayAttached *overlayAttached = qobject_cast<QQuickOverlayAttached *>(qmlAttachedPropertiesObject<QQuickOverlay>(q, false));
1375 if (overlayAttached)
1376 component = modal ? overlayAttached->modal() : overlayAttached->modeless();
1377
1378 if (!component)
1379 component = modal ? overlay->modal() : overlay->modeless();
1380
1381 if (!dimmer) {
1382 dimmer = createDimmer(component, q, overlay);
1383 if (!dimmer)
1384 return;
1385 // We cannot update explicitDimmerOpacity when dimmer's opacity changes,
1386 // as it is expected to do so when we fade the dimmer in and out in
1387 // show/hideDimmer, and any binding of the dimmer's opacity will be
1388 // implicitly broken anyway.
1389 explicitDimmerOpacity = dimmer->opacity();
1390 // initially fully transparent, showDimmer fades the dimmer in.
1391 dimmer->setOpacity(0);
1392 if (q->isVisible())
1393 showDimmer();
1394 }
1395 resizeDimmer();
1396}
1397
1398void QQuickPopupPrivate::destroyDimmer()
1399{
1400 if (dimmer) {
1401 qCDebug(lcDimmer) << "destroying dimmer" << dimmer;
1402 if (QObject *dimmerParentItem = dimmer->parentItem()) {
1403 if (dimmerParentItem->property("_q_dimmerItem").value<QQuickItem*>() == dimmer)
1404 dimmerParentItem->setProperty("_q_dimmerItem", QVariant());
1405 }
1406 dimmer->setParentItem(nullptr);
1407 dimmer->deleteLater();
1408 dimmer = nullptr;
1409 }
1410}
1411
1412void QQuickPopupPrivate::toggleOverlay()
1413{
1414 destroyDimmer();
1415 if (dim)
1416 createOverlay();
1417}
1418
1419void QQuickPopupPrivate::updateContentPalettes(const QPalette& parentPalette)
1420{
1421 // Inherit parent palette to all child objects
1422 if (providesPalette())
1423 inheritPalette(parentPalette);
1424 // Inherit parent palette to items within popup (such as headers and footers)
1425 QQuickItemPrivate::get(popupItem)->updateChildrenPalettes(parentPalette);
1426}
1427
1428void QQuickPopupPrivate::updateChildrenPalettes(const QPalette& parentPalette)
1429{
1430 updateContentPalettes(parentPalette);
1431}
1432
1433void QQuickPopupPrivate::showDimmer()
1434{
1435 // use QQmlProperty instead of QQuickItem::setOpacity() to trigger QML Behaviors
1436 if (dim && dimmer)
1437 QQmlProperty::write(dimmer, QStringLiteral("opacity"), explicitDimmerOpacity);
1438}
1439
1440void QQuickPopupPrivate::hideDimmer()
1441{
1442 // use QQmlProperty instead of QQuickItem::setOpacity() to trigger QML Behaviors
1443 if (dim && dimmer)
1444 QQmlProperty::write(dimmer, QStringLiteral("opacity"), 0.0);
1445}
1446
1447void QQuickPopupPrivate::resizeDimmer()
1448{
1449 if (!dimmer)
1450 return;
1451
1452 const QQuickOverlay *overlay = QQuickOverlay::overlay(window, parentItem);
1453
1454 qreal w = overlay ? overlay->width() : 0;
1455 qreal h = overlay ? overlay->height() : 0;
1456 dimmer->setSize(QSizeF(w, h));
1457}
1458
1459QQuickPopupTransitionManager::QQuickPopupTransitionManager(QQuickPopupPrivate *popup)
1460 : popup(popup)
1461{
1462}
1463
1464void QQuickPopupTransitionManager::transitionEnter()
1465{
1466 if (popup->transitionState == QQuickPopupPrivate::ExitTransition)
1467 cancel();
1468
1469 if (!popup->prepareEnterTransition())
1470 return;
1471
1472 if (popup->window)
1473 transition(popup->enterActions, popup->enter, popup->q_func());
1474 else
1475 finished();
1476}
1477
1478void QQuickPopupTransitionManager::transitionExit()
1479{
1480 if (!popup->prepareExitTransition())
1481 return;
1482
1483 if (popup->window)
1484 transition(popup->exitActions, popup->exit, popup->q_func());
1485 else
1486 finished();
1487}
1488
1489void QQuickPopupTransitionManager::finished()
1490{
1491 if (popup->transitionState == QQuickPopupPrivate::EnterTransition)
1492 popup->finalizeEnterTransition();
1493 else if (popup->transitionState == QQuickPopupPrivate::ExitTransition)
1494 popup->finalizeExitTransition();
1495}
1496
1497QQuickPopup::QQuickPopup(QObject *parent)
1498 : QObject(*(new QQuickPopupPrivate), parent)
1499{
1500 Q_D(QQuickPopup);
1501 d->init();
1502 // By default, allow popup to move beyond window edges
1503 d->relaxEdgeConstraint = true;
1504}
1505
1506QQuickPopup::QQuickPopup(QQuickPopupPrivate &dd, QObject *parent)
1507 : QObject(dd, parent)
1508{
1509 Q_D(QQuickPopup);
1510 d->init();
1511}
1512
1513QQuickPopup::~QQuickPopup()
1514{
1515 Q_D(QQuickPopup);
1516 d->inDestructor = true;
1517
1518 QQuickItem *currentContentItem = d->popupItem->d_func()->contentItem.data();
1519 if (currentContentItem) {
1520 disconnect(currentContentItem, &QQuickItem::childrenChanged,
1521 this, &QQuickPopup::contentChildrenChanged);
1522 }
1523
1524 setParentItem(nullptr);
1525
1526 // If the popup is destroyed before the exit transition finishes,
1527 // the necessary cleanup (removing modal dimmers that block mouse events,
1528 // emitting closed signal, etc.) won't happen. That's why we do it manually here.
1529 if (d->transitionState == QQuickPopupPrivate::ExitTransition && d->transitionManager.isRunning())
1530 d->finalizeExitTransition();
1531
1532 delete d->popupItem;
1533 d->popupItem = nullptr;
1534 delete d->positioner;
1535 d->positioner = nullptr;
1536 if (d->popupWindow)
1537 delete d->popupWindow;
1538 d->popupWindow = nullptr;
1539}
1540
1541/*!
1542 \qmlmethod void QtQuick.Controls::Popup::open()
1543
1544 Opens the popup.
1545
1546 \sa visible
1547*/
1548void QQuickPopup::open()
1549{
1550 setVisible(true);
1551}
1552
1553/*!
1554 \qmlmethod void QtQuick.Controls::Popup::close()
1555
1556 Closes the popup.
1557
1558 \sa visible
1559*/
1560void QQuickPopup::close()
1561{
1562 setVisible(false);
1563}
1564
1565/*!
1566 \qmlproperty real QtQuick.Controls::Popup::x
1567
1568 This property holds the x-coordinate of the popup.
1569
1570 \sa y, z
1571*/
1572qreal QQuickPopup::x() const
1573{
1574 return d_func()->effectivePos.x();
1575}
1576
1577void QQuickPopup::setX(qreal x)
1578{
1579 Q_D(QQuickPopup);
1580 setPosition(QPointF(x, d->y));
1581}
1582
1583/*!
1584 \qmlproperty real QtQuick.Controls::Popup::y
1585
1586 This property holds the y-coordinate of the popup.
1587
1588 \sa x, z
1589*/
1590qreal QQuickPopup::y() const
1591{
1592 return d_func()->effectivePos.y();
1593}
1594
1595void QQuickPopup::setY(qreal y)
1596{
1597 Q_D(QQuickPopup);
1598 setPosition(QPointF(d->x, y));
1599}
1600
1601QPointF QQuickPopup::position() const
1602{
1603 return d_func()->effectivePos;
1604}
1605
1606void QQuickPopup::setPosition(const QPointF &pos)
1607{
1608 Q_D(QQuickPopup);
1609 const bool xChange = !qFuzzyCompare(d->x, pos.x());
1610 const bool yChange = !qFuzzyCompare(d->y, pos.y());
1611 if (!xChange && !yChange)
1612 return;
1613
1614 d->x = pos.x();
1615 d->y = pos.y();
1616 if (d->popupItem->isVisible()) {
1617 d->reposition();
1618 } else {
1619 if (xChange)
1620 emit xChanged();
1621 if (yChange)
1622 emit yChanged();
1623 }
1624}
1625
1626/*!
1627 \qmlproperty real QtQuick.Controls::Popup::z
1628
1629 This property holds the z-value of the popup. Z-value determines
1630 the stacking order of popups.
1631
1632 If two visible popups have the same z-value, the last one that
1633 was opened will be on top.
1634
1635 If a popup has no explicitly set z-value when opened, and is a child
1636 of an already open popup, then it will be stacked on top of its parent.
1637 This ensures that children are never hidden under their parents.
1638
1639 If the popup has its own window, the z-value will determine the window
1640 stacking order instead.
1641
1642 The default z-value is \c 0.
1643
1644 \sa x, y
1645*/
1646qreal QQuickPopup::z() const
1647{
1648 Q_D(const QQuickPopup);
1649 return d->popupItem->z();
1650}
1651
1652void QQuickPopup::setZ(qreal z)
1653{
1654 Q_D(QQuickPopup);
1655 d->hasZ = true;
1656 bool previousZ = d->popupWindow ? d->popupWindow->z() : d->popupItem->z();
1657 if (qFuzzyCompare(z, previousZ))
1658 return;
1659 if (d->popupWindow)
1660 d->popupWindow->setZ(z);
1661 else
1662 d->popupItem->setZ(z);
1663 emit zChanged();
1664}
1665
1666void QQuickPopup::resetZ()
1667{
1668 Q_D(QQuickPopup);
1669 setZ(0);
1670 d->hasZ = false;
1671}
1672
1673/*!
1674 \qmlproperty real QtQuick.Controls::Popup::width
1675
1676 This property holds the width of the popup.
1677*/
1678qreal QQuickPopup::width() const
1679{
1680 Q_D(const QQuickPopup);
1681 return d->popupItem->width();
1682}
1683
1684void QQuickPopup::setWidth(qreal width)
1685{
1686 Q_D(QQuickPopup);
1687 d->hasWidth = true;
1688
1689 // QQuickPopupWindow::setWidth() triggers a window resize event.
1690 // This will cause QQuickPopupWindow::resizeEvent() to resize
1691 // the popupItem. QQuickPopupItem::geometryChanged() calls QQuickPopup::geometryChange(),
1692 // which emits widthChanged().
1693
1694 if (d->popupWindow)
1695 d->popupWindow->setWidth(width + d->windowInsets().left() + d->windowInsets().right());
1696 else
1697 d->popupItem->setWidth(width);
1698}
1699
1700void QQuickPopup::resetWidth()
1701{
1702 Q_D(QQuickPopup);
1703 if (!d->hasWidth)
1704 return;
1705
1706 d->hasWidth = false;
1707 d->popupItem->resetWidth();
1708 if (d->popupItem->isVisible())
1709 d->reposition();
1710}
1711
1712/*!
1713 \qmlproperty real QtQuick.Controls::Popup::height
1714
1715 This property holds the height of the popup.
1716*/
1717qreal QQuickPopup::height() const
1718{
1719 Q_D(const QQuickPopup);
1720 return d->popupItem->height();
1721}
1722
1723void QQuickPopup::setHeight(qreal height)
1724{
1725 Q_D(QQuickPopup);
1726 d->hasHeight = true;
1727
1728 // QQuickPopupWindow::setHeight() triggers a window resize event.
1729 // This will cause QQuickPopupWindow::resizeEvent() to resize
1730 // the popupItem. QQuickPopupItem::geometryChanged() calls QQuickPopup::geometryChange(),
1731 // which emits heightChanged().
1732
1733 if (d->popupWindow)
1734 d->popupWindow->setHeight(height + d->windowInsets().top() + d->windowInsets().bottom());
1735 else
1736 d->popupItem->setHeight(height);
1737}
1738
1739void QQuickPopup::resetHeight()
1740{
1741 Q_D(QQuickPopup);
1742 if (!d->hasHeight)
1743 return;
1744
1745 d->hasHeight = false;
1746 d->popupItem->resetHeight();
1747 if (d->popupItem->isVisible())
1748 d->reposition();
1749}
1750
1751/*!
1752 \qmlproperty real QtQuick.Controls::Popup::implicitWidth
1753
1754 This property holds the implicit width of the popup.
1755*/
1756qreal QQuickPopup::implicitWidth() const
1757{
1758 Q_D(const QQuickPopup);
1759 return d->popupItem->implicitWidth();
1760}
1761
1762void QQuickPopup::setImplicitWidth(qreal width)
1763{
1764 Q_D(QQuickPopup);
1765 d->popupItem->setImplicitWidth(width);
1766}
1767
1768/*!
1769 \qmlproperty real QtQuick.Controls::Popup::implicitHeight
1770
1771 This property holds the implicit height of the popup.
1772*/
1773qreal QQuickPopup::implicitHeight() const
1774{
1775 Q_D(const QQuickPopup);
1776 return d->popupItem->implicitHeight();
1777}
1778
1779void QQuickPopup::setImplicitHeight(qreal height)
1780{
1781 Q_D(QQuickPopup);
1782 d->popupItem->setImplicitHeight(height);
1783}
1784
1785/*!
1786 \qmlproperty real QtQuick.Controls::Popup::contentWidth
1787
1788 This property holds the content width. It is used for calculating the
1789 total implicit width of the Popup.
1790
1791 For more information, see \l {Popup Sizing}.
1792
1793 \sa contentHeight
1794*/
1795qreal QQuickPopup::contentWidth() const
1796{
1797 Q_D(const QQuickPopup);
1798 return d->popupItem->contentWidth();
1799}
1800
1801void QQuickPopup::setContentWidth(qreal width)
1802{
1803 Q_D(QQuickPopup);
1804 d->popupItem->setContentWidth(width);
1805}
1806
1807/*!
1808 \qmlproperty real QtQuick.Controls::Popup::contentHeight
1809
1810 This property holds the content height. It is used for calculating the
1811 total implicit height of the Popup.
1812
1813 For more information, see \l {Popup Sizing}.
1814
1815 \sa contentWidth
1816*/
1817qreal QQuickPopup::contentHeight() const
1818{
1819 Q_D(const QQuickPopup);
1820 return d->popupItem->contentHeight();
1821}
1822
1823void QQuickPopup::setContentHeight(qreal height)
1824{
1825 Q_D(QQuickPopup);
1826 d->popupItem->setContentHeight(height);
1827}
1828
1829/*!
1830 \qmlproperty real QtQuick.Controls::Popup::availableWidth
1831 \readonly
1832
1833 This property holds the width available to the \l contentItem after
1834 deducting horizontal padding from the \l {Item::}{width} of the popup.
1835
1836 \sa padding, leftPadding, rightPadding
1837*/
1838qreal QQuickPopup::availableWidth() const
1839{
1840 Q_D(const QQuickPopup);
1841 return d->popupItem->availableWidth();
1842}
1843
1844/*!
1845 \qmlproperty real QtQuick.Controls::Popup::availableHeight
1846 \readonly
1847
1848 This property holds the height available to the \l contentItem after
1849 deducting vertical padding from the \l {Item::}{height} of the popup.
1850
1851 \sa padding, topPadding, bottomPadding
1852*/
1853qreal QQuickPopup::availableHeight() const
1854{
1855 Q_D(const QQuickPopup);
1856 return d->popupItem->availableHeight();
1857}
1858
1859/*!
1860 \since QtQuick.Controls 2.1 (Qt 5.8)
1861 \qmlproperty real QtQuick.Controls::Popup::spacing
1862
1863 This property holds the spacing.
1864
1865 Spacing is useful for popups that have multiple or repetitive building
1866 blocks. For example, some styles use spacing to determine the distance
1867 between the header, content, and footer of \l Dialog. Spacing is not
1868 enforced by Popup, so each style may interpret it differently, and some
1869 may ignore it altogether.
1870*/
1871qreal QQuickPopup::spacing() const
1872{
1873 Q_D(const QQuickPopup);
1874 return d->popupItem->spacing();
1875}
1876
1877void QQuickPopup::setSpacing(qreal spacing)
1878{
1879 Q_D(QQuickPopup);
1880 d->popupItem->setSpacing(spacing);
1881}
1882
1883void QQuickPopup::resetSpacing()
1884{
1885 setSpacing(0);
1886}
1887
1888/*!
1889 \qmlproperty real QtQuick.Controls::Popup::margins
1890
1891 This property holds the distance between the edges of the popup and the
1892 edges of its window.
1893
1894 A popup with negative margins is not pushed within the bounds
1895 of the enclosing window. The default value is \c -1.
1896
1897 \sa topMargin, leftMargin, rightMargin, bottomMargin, {Popup Layout}
1898*/
1899qreal QQuickPopup::margins() const
1900{
1901 Q_D(const QQuickPopup);
1902 return d->margins;
1903}
1904
1905void QQuickPopup::setMargins(qreal margins)
1906{
1907 Q_D(QQuickPopup);
1908 if (qFuzzyCompare(d->margins, margins))
1909 return;
1910 QMarginsF oldMargins(leftMargin(), topMargin(), rightMargin(), bottomMargin());
1911 d->margins = margins;
1912 emit marginsChanged();
1913 QMarginsF newMargins(leftMargin(), topMargin(), rightMargin(), bottomMargin());
1914 if (!qFuzzyCompare(newMargins.top(), oldMargins.top()))
1915 emit topMarginChanged();
1916 if (!qFuzzyCompare(newMargins.left(), oldMargins.left()))
1917 emit leftMarginChanged();
1918 if (!qFuzzyCompare(newMargins.right(), oldMargins.right()))
1919 emit rightMarginChanged();
1920 if (!qFuzzyCompare(newMargins.bottom(), oldMargins.bottom()))
1921 emit bottomMarginChanged();
1922 marginsChange(newMargins, oldMargins);
1923}
1924
1925void QQuickPopup::resetMargins()
1926{
1927 setMargins(-1);
1928}
1929
1930/*!
1931 \qmlproperty real QtQuick.Controls::Popup::topMargin
1932
1933 This property holds the distance between the top edge of the popup and
1934 the top edge of its window.
1935
1936 A popup with a negative top margin is not pushed within the top edge
1937 of the enclosing window. The default value is \c -1.
1938
1939 \sa margins, bottomMargin, {Popup Layout}
1940*/
1941qreal QQuickPopup::topMargin() const
1942{
1943 Q_D(const QQuickPopup);
1944 if (d->hasTopMargin)
1945 return d->topMargin;
1946 return d->margins;
1947}
1948
1949void QQuickPopup::setTopMargin(qreal margin)
1950{
1951 Q_D(QQuickPopup);
1952 d->setTopMargin(margin);
1953}
1954
1955void QQuickPopup::resetTopMargin()
1956{
1957 Q_D(QQuickPopup);
1958 d->setTopMargin(-1, true);
1959}
1960
1961/*!
1962 \qmlproperty real QtQuick.Controls::Popup::leftMargin
1963
1964 This property holds the distance between the left edge of the popup and
1965 the left edge of its window.
1966
1967 A popup with a negative left margin is not pushed within the left edge
1968 of the enclosing window. The default value is \c -1.
1969
1970 \sa margins, rightMargin, {Popup Layout}
1971*/
1972qreal QQuickPopup::leftMargin() const
1973{
1974 Q_D(const QQuickPopup);
1975 if (d->hasLeftMargin)
1976 return d->leftMargin;
1977 return d->margins;
1978}
1979
1980void QQuickPopup::setLeftMargin(qreal margin)
1981{
1982 Q_D(QQuickPopup);
1983 d->setLeftMargin(margin);
1984}
1985
1986void QQuickPopup::resetLeftMargin()
1987{
1988 Q_D(QQuickPopup);
1989 d->setLeftMargin(-1, true);
1990}
1991
1992/*!
1993 \qmlproperty real QtQuick.Controls::Popup::rightMargin
1994
1995 This property holds the distance between the right edge of the popup and
1996 the right edge of its window.
1997
1998 A popup with a negative right margin is not pushed within the right edge
1999 of the enclosing window. The default value is \c -1.
2000
2001 \sa margins, leftMargin, {Popup Layout}
2002*/
2003qreal QQuickPopup::rightMargin() const
2004{
2005 Q_D(const QQuickPopup);
2006 if (d->hasRightMargin)
2007 return d->rightMargin;
2008 return d->margins;
2009}
2010
2011void QQuickPopup::setRightMargin(qreal margin)
2012{
2013 Q_D(QQuickPopup);
2014 d->setRightMargin(margin);
2015}
2016
2017void QQuickPopup::resetRightMargin()
2018{
2019 Q_D(QQuickPopup);
2020 d->setRightMargin(-1, true);
2021}
2022
2023/*!
2024 \qmlproperty real QtQuick.Controls::Popup::bottomMargin
2025
2026 This property holds the distance between the bottom edge of the popup and
2027 the bottom edge of its window.
2028
2029 A popup with a negative bottom margin is not pushed within the bottom edge
2030 of the enclosing window. The default value is \c -1.
2031
2032 \sa margins, topMargin, {Popup Layout}
2033*/
2034qreal QQuickPopup::bottomMargin() const
2035{
2036 Q_D(const QQuickPopup);
2037 if (d->hasBottomMargin)
2038 return d->bottomMargin;
2039 return d->margins;
2040}
2041
2042void QQuickPopup::setBottomMargin(qreal margin)
2043{
2044 Q_D(QQuickPopup);
2045 d->setBottomMargin(margin);
2046}
2047
2048void QQuickPopup::resetBottomMargin()
2049{
2050 Q_D(QQuickPopup);
2051 d->setBottomMargin(-1, true);
2052}
2053
2054/*!
2055 \qmlproperty real QtQuick.Controls::Popup::padding
2056
2057 This property holds the default padding.
2058
2059 \include qquickpopup-padding.qdocinc
2060
2061 \sa availableWidth, availableHeight, topPadding, leftPadding, rightPadding, bottomPadding
2062*/
2063qreal QQuickPopup::padding() const
2064{
2065 Q_D(const QQuickPopup);
2066 return d->popupItem->padding();
2067}
2068
2069void QQuickPopup::setPadding(qreal padding)
2070{
2071 Q_D(QQuickPopup);
2072 d->popupItem->setPadding(padding);
2073}
2074
2075void QQuickPopup::resetPadding()
2076{
2077 Q_D(QQuickPopup);
2078 d->popupItem->resetPadding();
2079}
2080
2081/*!
2082 \qmlproperty real QtQuick.Controls::Popup::topPadding
2083
2084 This property holds the top padding. Unless explicitly set, the value
2085 is equal to \c verticalPadding.
2086
2087 \include qquickpopup-padding.qdocinc
2088
2089 \sa padding, bottomPadding, verticalPadding, availableHeight
2090*/
2091qreal QQuickPopup::topPadding() const
2092{
2093 Q_D(const QQuickPopup);
2094 return d->popupItem->topPadding();
2095}
2096
2097void QQuickPopup::setTopPadding(qreal padding)
2098{
2099 Q_D(QQuickPopup);
2100 d->popupItem->setTopPadding(padding);
2101}
2102
2103void QQuickPopup::resetTopPadding()
2104{
2105 Q_D(QQuickPopup);
2106 d->popupItem->resetTopPadding();
2107}
2108
2109/*!
2110 \qmlproperty real QtQuick.Controls::Popup::leftPadding
2111
2112 This property holds the left padding. Unless explicitly set, the value
2113 is equal to \c horizontalPadding.
2114
2115 \include qquickpopup-padding.qdocinc
2116
2117 \sa padding, rightPadding, horizontalPadding, availableWidth
2118*/
2119qreal QQuickPopup::leftPadding() const
2120{
2121 Q_D(const QQuickPopup);
2122 return d->popupItem->leftPadding();
2123}
2124
2125void QQuickPopup::setLeftPadding(qreal padding)
2126{
2127 Q_D(QQuickPopup);
2128 d->popupItem->setLeftPadding(padding);
2129}
2130
2131void QQuickPopup::resetLeftPadding()
2132{
2133 Q_D(QQuickPopup);
2134 d->popupItem->resetLeftPadding();
2135}
2136
2137/*!
2138 \qmlproperty real QtQuick.Controls::Popup::rightPadding
2139
2140 This property holds the right padding. Unless explicitly set, the value
2141 is equal to \c horizontalPadding.
2142
2143 \include qquickpopup-padding.qdocinc
2144
2145 \sa padding, leftPadding, horizontalPadding, availableWidth
2146*/
2147qreal QQuickPopup::rightPadding() const
2148{
2149 Q_D(const QQuickPopup);
2150 return d->popupItem->rightPadding();
2151}
2152
2153void QQuickPopup::setRightPadding(qreal padding)
2154{
2155 Q_D(QQuickPopup);
2156 d->popupItem->setRightPadding(padding);
2157}
2158
2159void QQuickPopup::resetRightPadding()
2160{
2161 Q_D(QQuickPopup);
2162 d->popupItem->resetRightPadding();
2163}
2164
2165/*!
2166 \qmlproperty real QtQuick.Controls::Popup::bottomPadding
2167
2168 This property holds the bottom padding. Unless explicitly set, the value
2169 is equal to \c verticalPadding.
2170
2171 \include qquickpopup-padding.qdocinc
2172
2173 \sa padding, topPadding, verticalPadding, availableHeight
2174*/
2175qreal QQuickPopup::bottomPadding() const
2176{
2177 Q_D(const QQuickPopup);
2178 return d->popupItem->bottomPadding();
2179}
2180
2181void QQuickPopup::setBottomPadding(qreal padding)
2182{
2183 Q_D(QQuickPopup);
2184 d->popupItem->setBottomPadding(padding);
2185}
2186
2187void QQuickPopup::resetBottomPadding()
2188{
2189 Q_D(QQuickPopup);
2190 d->popupItem->resetBottomPadding();
2191}
2192
2193/*!
2194 \qmlproperty Locale QtQuick.Controls::Popup::locale
2195
2196 This property holds the locale of the popup.
2197
2198 \sa mirrored, {LayoutMirroring}{LayoutMirroring}
2199*/
2200QLocale QQuickPopup::locale() const
2201{
2202 Q_D(const QQuickPopup);
2203 return d->popupItem->locale();
2204}
2205
2206void QQuickPopup::setLocale(const QLocale &locale)
2207{
2208 Q_D(QQuickPopup);
2209 d->popupItem->setLocale(locale);
2210}
2211
2212void QQuickPopup::resetLocale()
2213{
2214 Q_D(QQuickPopup);
2215 d->popupItem->resetLocale();
2216}
2217
2218/*!
2219 \since QtQuick.Controls 2.3 (Qt 5.10)
2220 \qmlproperty bool QtQuick.Controls::Popup::mirrored
2221 \readonly
2222
2223 This property holds whether the popup is mirrored.
2224
2225 This property is provided for convenience. A popup is considered mirrored
2226 when its visual layout direction is right-to-left; that is, when using a
2227 right-to-left locale.
2228
2229 \sa locale, {Right-to-left User Interfaces}
2230*/
2231bool QQuickPopup::isMirrored() const
2232{
2233 Q_D(const QQuickPopup);
2234 return d->popupItem->isMirrored();
2235}
2236
2237/*!
2238 \qmlproperty font QtQuick.Controls::Popup::font
2239
2240 This property holds the font currently set for the popup.
2241
2242 Popup propagates explicit font properties to its children. If you change a specific
2243 property on a popup's font, that property propagates to all of the popup's children,
2244 overriding any system defaults for that property.
2245
2246 \code
2247 Popup {
2248 font.family: "Courier"
2249
2250 Column {
2251 Label {
2252 text: qsTr("This will use Courier...")
2253 }
2254
2255 Switch {
2256 text: qsTr("... and so will this")
2257 }
2258 }
2259 }
2260 \endcode
2261
2262 \sa Control::font, ApplicationWindow::font
2263*/
2264QFont QQuickPopup::font() const
2265{
2266 Q_D(const QQuickPopup);
2267 return d->popupItem->font();
2268}
2269
2270void QQuickPopup::setFont(const QFont &font)
2271{
2272 Q_D(QQuickPopup);
2273 d->popupItem->setFont(font);
2274}
2275
2276void QQuickPopup::resetFont()
2277{
2278 Q_D(QQuickPopup);
2279 d->popupItem->resetFont();
2280}
2281
2282QQuickWindow *QQuickPopup::window() const
2283{
2284 Q_D(const QQuickPopup);
2285 return d->window;
2286}
2287
2288QQuickItem *QQuickPopup::popupItem() const
2289{
2290 Q_D(const QQuickPopup);
2291 return d->popupItem;
2292}
2293
2294/*!
2295 \qmlproperty Item QtQuick.Controls::Popup::parent
2296
2297 This property holds the parent item.
2298*/
2299QQuickItem *QQuickPopup::parentItem() const
2300{
2301 Q_D(const QQuickPopup);
2302 return d->parentItem;
2303}
2304
2305void QQuickPopup::setParentItem(QQuickItem *parent)
2306{
2307 Q_D(QQuickPopup);
2308 if (d->parentItem == parent)
2309 return;
2310
2311 if (d->parentItem) {
2312 QObjectPrivate::disconnect(d->parentItem, &QQuickItem::windowChanged, d, &QQuickPopupPrivate::setWindow);
2313 QQuickItemPrivate::get(d->parentItem)->removeItemChangeListener(d, QQuickItemPrivate::Destroyed);
2314 }
2315 d->parentItem = parent;
2316 QQuickPopupPositioner *positioner = d->getPositioner();
2317 if (positioner->parentItem())
2318 positioner->setParentItem(parent);
2319 if (parent) {
2320 QObjectPrivate::connect(parent, &QQuickItem::windowChanged, d, &QQuickPopupPrivate::setWindow);
2321 QQuickItemPrivate::get(d->parentItem)->addItemChangeListener(d, QQuickItemPrivate::Destroyed);
2322 } else if (d->inDestructor) {
2323 d->destroyDimmer();
2324 } else {
2325 // Reset transition manager state when its parent window destroyed
2326 if (!d->window && d->transitionManager.isRunning()) {
2327 if (d->transitionState == QQuickPopupPrivate::EnterTransition)
2328 d->finalizeEnterTransition();
2329 else if (d->transitionState == QQuickPopupPrivate::ExitTransition)
2330 d->finalizeExitTransition();
2331 }
2332 // NOTE: if setParentItem is called from the dtor, this bypasses virtual dispatch and calls
2333 // QQuickPopup::close() directly
2334 close();
2335 }
2336 d->setWindow(parent ? parent->window() : nullptr);
2337 emit parentChanged();
2338}
2339
2340void QQuickPopup::resetParentItem()
2341{
2342 if (QQuickWindow *window = qobject_cast<QQuickWindow *>(parent()))
2343 setParentItem(window->contentItem());
2344 else
2345 setParentItem(findParentItem());
2346}
2347
2348/*!
2349 \qmlproperty Item QtQuick.Controls::Popup::background
2350
2351 This property holds the background item.
2352
2353 \note If the background item has no explicit size specified, it automatically
2354 follows the popup's size. In most cases, there is no need to specify
2355 width or height for a background item.
2356
2357 \note Most popups use the implicit size of the background item to calculate
2358 the implicit size of the popup itself. If you replace the background item
2359 with a custom one, you should also consider providing a sensible implicit
2360 size for it (unless it is an item like \l Image which has its own implicit
2361 size).
2362
2363 \sa {Customizing Popup}
2364*/
2365QQuickItem *QQuickPopup::background() const
2366{
2367 Q_D(const QQuickPopup);
2368 return d->popupItem->background();
2369}
2370
2371void QQuickPopup::setBackground(QQuickItem *background)
2372{
2373 Q_D(QQuickPopup);
2374 // The __notCustomizable property won't be on "this" when the popup item's setBackground function
2375 // is called, so it won't warn. That's why we do a check here.
2376 QQuickControlPrivate::warnIfCustomizationNotSupported(this, background, QStringLiteral("background"));
2377 d->popupItem->setBackground(background);
2378}
2379
2380/*!
2381 \qmlproperty Item QtQuick.Controls::Popup::contentItem
2382
2383 This property holds the content item of the popup.
2384
2385 The content item is the visual implementation of the popup. When the
2386 popup is made visible, the content item is automatically reparented to
2387 the \l {Overlay::overlay}{overlay item}.
2388
2389 \note The content item is automatically resized to fit within the
2390 \l padding of the popup.
2391
2392 \note Most popups use the implicit size of the content item to calculate
2393 the implicit size of the popup itself. If you replace the content item
2394 with a custom one, you should also consider providing a sensible implicit
2395 size for it (unless it is an item like \l Text which has its own implicit
2396 size).
2397
2398 \sa {Customizing Popup}
2399*/
2400QQuickItem *QQuickPopup::contentItem() const
2401{
2402 Q_D(const QQuickPopup);
2403 return d->popupItem->contentItem();
2404}
2405
2406void QQuickPopup::setContentItem(QQuickItem *item)
2407{
2408 Q_D(QQuickPopup);
2409 // See comment in setBackground for why we do this.
2410 QQuickControlPrivate::warnIfCustomizationNotSupported(this, item, QStringLiteral("contentItem"));
2411 QQuickItem *oldContentItem = d->complete ? d->popupItem->d_func()->contentItem.data()
2412 : nullptr;
2413 if (oldContentItem)
2414 disconnect(oldContentItem, &QQuickItem::childrenChanged, this, &QQuickPopup::contentChildrenChanged);
2415 d->popupItem->setContentItem(item);
2416 if (d->complete) {
2417 QQuickItem *newContentItem = d->popupItem->d_func()->contentItem.data();
2418 if (newContentItem)
2419 connect(newContentItem, &QQuickItem::childrenChanged, this, &QQuickPopup::contentChildrenChanged);
2420 if (oldContentItem != newContentItem)
2421 emit contentChildrenChanged();
2422 }
2423}
2424
2425/*!
2426 \qmlproperty list<QtObject> QtQuick.Controls::Popup::contentData
2427 \qmldefault
2428
2429 This property holds the list of content data.
2430
2431 The list contains all objects that have been declared in QML as children
2432 of the popup.
2433
2434 \note Unlike \c contentChildren, \c contentData does include non-visual QML
2435 objects.
2436
2437 \sa Item::data, contentChildren
2438*/
2439QQmlListProperty<QObject> QQuickPopupPrivate::contentData()
2440{
2441 QQuickControlPrivate *p = QQuickControlPrivate::get(popupItem);
2442 if (!p->contentItem)
2443 p->executeContentItem();
2444 return QQmlListProperty<QObject>(popupItem->contentItem(), nullptr,
2445 QQuickItemPrivate::data_append,
2446 QQuickItemPrivate::data_count,
2447 QQuickItemPrivate::data_at,
2448 QQuickItemPrivate::data_clear);
2449}
2450
2451/*!
2452 \qmlproperty list<Item> QtQuick.Controls::Popup::contentChildren
2453
2454 This property holds the list of content children.
2455
2456 The list contains all items that have been declared in QML as children
2457 of the popup.
2458
2459 \note Unlike \c contentData, \c contentChildren does not include non-visual
2460 QML objects.
2461
2462 \sa Item::children, contentData
2463*/
2464QQmlListProperty<QQuickItem> QQuickPopupPrivate::contentChildren()
2465{
2466 return QQmlListProperty<QQuickItem>(popupItem->contentItem(), nullptr,
2467 QQuickItemPrivate::children_append,
2468 QQuickItemPrivate::children_count,
2469 QQuickItemPrivate::children_at,
2470 QQuickItemPrivate::children_clear);
2471}
2472
2473/*!
2474 \qmlproperty bool QtQuick.Controls::Popup::clip
2475
2476 This property holds whether clipping is enabled. The default value is \c false.
2477 Clipping only works when the popup isn't in its own window.
2478*/
2479bool QQuickPopup::clip() const
2480{
2481 Q_D(const QQuickPopup);
2482 return d->popupItem->clip() && !d->usePopupWindow();
2483}
2484
2485void QQuickPopup::setClip(bool clip)
2486{
2487 Q_D(QQuickPopup);
2488 if (clip == d->popupItem->clip() || d->usePopupWindow())
2489 return;
2490 d->popupItem->setClip(clip);
2491 emit clipChanged();
2492}
2493
2494/*!
2495 \qmlproperty bool QtQuick.Controls::Popup::focus
2496
2497 This property holds whether the popup wants focus.
2498
2499 When the popup actually receives focus, \l activeFocus will be \c true.
2500 For more information, see \l {Keyboard Focus in Qt Quick}.
2501
2502 The default value is \c false.
2503
2504 \sa activeFocus
2505*/
2506bool QQuickPopup::hasFocus() const
2507{
2508 Q_D(const QQuickPopup);
2509 return d->focus;
2510}
2511
2512void QQuickPopup::setFocus(bool focus)
2513{
2514 Q_D(QQuickPopup);
2515 if (d->focus == focus)
2516 return;
2517 d->focus = focus;
2518 emit focusChanged();
2519}
2520
2521/*!
2522 \qmlproperty bool QtQuick.Controls::Popup::activeFocus
2523 \readonly
2524
2525 This property holds whether the popup has active focus.
2526
2527 \sa focus, {Keyboard Focus in Qt Quick}
2528*/
2529bool QQuickPopup::hasActiveFocus() const
2530{
2531 Q_D(const QQuickPopup);
2532 return d->popupItem->hasActiveFocus();
2533}
2534
2535/*!
2536 \qmlproperty bool QtQuick.Controls::Popup::modal
2537
2538 This property holds whether the popup is modal.
2539
2540 Modal popups often have a distinctive background dimming effect defined
2541 in \l {Overlay::modal}{Overlay.modal}, and do not allow press
2542 or release events through to items beneath them. For example, if the user
2543 accidentally clicks outside of a popup, any item beneath that popup at
2544 the location of the click will not receive the event.
2545
2546 On desktop platforms, it is common for modal popups to be closed only when
2547 the escape key is pressed. To achieve this behavior, set
2548 \l closePolicy to \c Popup.CloseOnEscape. By default, \c closePolicy
2549 is set to \c {Popup.CloseOnEscape | Popup.CloseOnPressOutside}, which
2550 means that clicking outside of a modal popup will close it.
2551
2552 The default value is \c false.
2553
2554 \sa dim
2555*/
2556bool QQuickPopup::isModal() const
2557{
2558 Q_D(const QQuickPopup);
2559 return d->modal;
2560}
2561
2562void QQuickPopup::setModal(bool modal)
2563{
2564 Q_D(QQuickPopup);
2565 if (d->modal == modal)
2566 return;
2567 d->modal = modal;
2568 d->popupWindowDirty = true;
2569 if (d->complete && d->visible)
2570 d->toggleOverlay();
2571 emit modalChanged();
2572
2573 if (!d->hasDim) {
2574 setDim(modal);
2575 d->hasDim = false;
2576 }
2577}
2578
2579/*!
2580 \qmlproperty bool QtQuick.Controls::Popup::dim
2581
2582 This property holds whether the popup dims the background.
2583
2584 Unless explicitly set, this property follows the value of \l modal. To
2585 return to the default value, set this property to \c undefined.
2586
2587 \sa modal, {Overlay::modeless}{Overlay.modeless}
2588*/
2589bool QQuickPopup::dim() const
2590{
2591 Q_D(const QQuickPopup);
2592 return d->dim;
2593}
2594
2595void QQuickPopup::setDim(bool dim)
2596{
2597 Q_D(QQuickPopup);
2598 d->hasDim = true;
2599
2600 if (d->dim == dim)
2601 return;
2602
2603 d->dim = dim;
2604 if (d->complete && d->visible)
2605 d->toggleOverlay();
2606 emit dimChanged();
2607}
2608
2609void QQuickPopup::resetDim()
2610{
2611 Q_D(QQuickPopup);
2612 if (!d->hasDim)
2613 return;
2614
2615 setDim(d->modal);
2616 d->hasDim = false;
2617}
2618
2619/*!
2620 \qmlproperty bool QtQuick.Controls::Popup::visible
2621
2622 This property holds whether the popup is visible. The default value is \c false.
2623
2624 \sa open(), close(), opened
2625*/
2626bool QQuickPopup::isVisible() const
2627{
2628 Q_D(const QQuickPopup);
2629 return d->visible && d->popupItem->isVisible();
2630}
2631
2632void QQuickPopup::setVisible(bool visible)
2633{
2634 Q_D(QQuickPopup);
2635 // During an exit transition, d->visible == true until the transition has completed.
2636 // Therefore, this guard must not return early if setting visible to true while
2637 // d->visible is true.
2638 if (d->visible && visible && d->transitionState != QQuickPopupPrivate::ExitTransition)
2639 return;
2640
2641 if (!d->visible && !visible)
2642 return;
2643
2644 if (!d->complete || (visible && !d->window)) {
2645 d->visible = visible;
2646 return;
2647 }
2648
2649 if (visible && !parentItem()) {
2650 qmlWarning(this) << "cannot show popup: parent is null";
2651 return;
2652 }
2653
2654 if (visible)
2655 openPopup(d);
2656 else
2657 d->transitionManager.transitionExit();
2658}
2659
2660/*!
2661 \since QtQuick.Controls 2.3 (Qt 5.10)
2662 \qmlproperty bool QtQuick.Controls::Popup::enabled
2663
2664 This property holds whether the popup is enabled. The default value is \c true.
2665
2666 \sa visible, Item::enabled
2667*/
2668bool QQuickPopup::isEnabled() const
2669{
2670 Q_D(const QQuickPopup);
2671 return d->popupItem->isEnabled();
2672}
2673
2674void QQuickPopup::setEnabled(bool enabled)
2675{
2676 Q_D(QQuickPopup);
2677 d->popupItem->setEnabled(enabled);
2678}
2679
2680/*!
2681 \since QtQuick.Controls 2.3 (Qt 5.10)
2682 \qmlproperty bool QtQuick.Controls::Popup::opened
2683
2684 This property holds whether the popup is fully open. The popup is considered opened
2685 when it's visible and neither the \l enter nor \l exit transitions are running.
2686
2687 \sa open(), close(), visible
2688*/
2689bool QQuickPopup::isOpened() const
2690{
2691 Q_D(const QQuickPopup);
2692 return d->transitionState == QQuickPopupPrivate::NoTransition && isVisible();
2693}
2694
2695/*!
2696 \qmlproperty real QtQuick.Controls::Popup::opacity
2697
2698 This property holds the opacity of the popup. Opacity is specified as a number between
2699 \c 0.0 (fully transparent) and \c 1.0 (fully opaque). The default value is \c 1.0.
2700
2701 \sa visible
2702*/
2703qreal QQuickPopup::opacity() const
2704{
2705 Q_D(const QQuickPopup);
2706 return d->popupItem->opacity();
2707}
2708
2709void QQuickPopup::setOpacity(qreal opacity)
2710{
2711 Q_D(QQuickPopup);
2712 d->popupItem->setOpacity(opacity);
2713}
2714
2715/*!
2716 \qmlproperty real QtQuick.Controls::Popup::scale
2717
2718 This property holds the scale factor of the popup. The default value is \c 1.0.
2719
2720 A scale of less than \c 1.0 causes the popup to be rendered at a smaller size,
2721 and a scale greater than \c 1.0 renders the popup at a larger size. Negative
2722 scales are not supported.
2723*/
2724qreal QQuickPopup::scale() const
2725{
2726 Q_D(const QQuickPopup);
2727 return d->popupItem->scale();
2728}
2729
2730void QQuickPopup::setScale(qreal scale)
2731{
2732 Q_D(QQuickPopup);
2733 if (qFuzzyCompare(scale, d->popupItem->scale()))
2734 return;
2735 d->popupItem->setScale(scale);
2736 emit scaleChanged();
2737}
2738
2739/*!
2740 \qmlproperty enumeration QtQuick.Controls::Popup::closePolicy
2741
2742 This property determines the circumstances under which the popup closes.
2743 The flags can be combined to allow several ways of closing the popup.
2744
2745 The available values are:
2746 \value Popup.NoAutoClose The popup will only close when manually instructed to do so.
2747 \value Popup.CloseOnPressOutside The popup will close when the mouse is pressed outside of it.
2748 \value Popup.CloseOnPressOutsideParent The popup will close when the mouse is pressed outside of its parent.
2749 \value Popup.CloseOnReleaseOutside The popup will close when the mouse is released outside of it.
2750 \value Popup.CloseOnReleaseOutsideParent The popup will close when the mouse is released outside of its parent.
2751 \value Popup.CloseOnEscape The popup will close when the escape key is pressed while the popup
2752 has active focus.
2753 \value Popup.CloseMultiple When using multiple nested popups, only the top-most popup closes on each outside
2754 click by default. When the closing popup has this flag set, the next popup in the stack is also
2755 checked: if the click position was outside it too, it closes as well. This cascade
2756 continues down the stack until all popups have closed, a popup whose bounds contain
2757 the click position is reached, or a popup without \c CloseMultiple is closed. Must
2758 be combined with at least one \c {CloseOnPress*} or \c {CloseOnRelease*} flag.
2759
2760 The default value is \c {Popup.CloseOnEscape | Popup.CloseOnPressOutside}.
2761
2762 \note There is a known limitation that the \c Popup.CloseOnReleaseOutside
2763 and \c Popup.CloseOnReleaseOutsideParent policies only work with
2764 \l modal popups.
2765*/
2766QQuickPopup::ClosePolicy QQuickPopup::closePolicy() const
2767{
2768 Q_D(const QQuickPopup);
2769 return d->closePolicy;
2770}
2771
2772void QQuickPopup::setClosePolicy(ClosePolicy policy)
2773{
2774 Q_D(QQuickPopup);
2775 d->hasClosePolicy = true;
2776 if (d->closePolicy == policy)
2777 return;
2778 d->closePolicy = policy;
2779 emit closePolicyChanged();
2780}
2781
2782void QQuickPopup::resetClosePolicy()
2783{
2784 Q_D(QQuickPopup);
2785 setClosePolicy(QQuickPopupPrivate::DefaultClosePolicy);
2786 d->hasClosePolicy = false;
2787}
2788
2789/*!
2790 \qmlproperty enumeration QtQuick.Controls::Popup::transformOrigin
2791
2792 This property holds the origin point for transformations in enter and exit transitions.
2793
2794 Nine transform origins are available, as shown in the image below.
2795 The default transform origin is \c Popup.Center.
2796
2797 \image qtquickcontrols-popup-transformorigin.png
2798 {Popup demonstrating transform origin points}
2799
2800 \sa enter, exit, Item::transformOrigin
2801*/
2802QQuickPopup::TransformOrigin QQuickPopup::transformOrigin() const
2803{
2804 Q_D(const QQuickPopup);
2805 return static_cast<TransformOrigin>(d->popupItem->transformOrigin());
2806}
2807
2808void QQuickPopup::setTransformOrigin(TransformOrigin origin)
2809{
2810 Q_D(QQuickPopup);
2811 d->popupItem->setTransformOrigin(static_cast<QQuickItem::TransformOrigin>(origin));
2812}
2813
2814/*!
2815 \qmlproperty Transition QtQuick.Controls::Popup::enter
2816
2817 This property holds the transition that is applied to the popup item
2818 when the popup is opened and enters the screen.
2819
2820 The following example animates the opacity of the popup when it enters
2821 the screen:
2822 \code
2823 Popup {
2824 enter: Transition {
2825 NumberAnimation { property: "opacity"; from: 0.0; to: 1.0 }
2826 }
2827 }
2828 \endcode
2829
2830 \sa exit
2831*/
2832QQuickTransition *QQuickPopup::enter() const
2833{
2834 Q_D(const QQuickPopup);
2835 return d->enter;
2836}
2837
2838void QQuickPopup::setEnter(QQuickTransition *transition)
2839{
2840 Q_D(QQuickPopup);
2841 if (d->enter == transition)
2842 return;
2843 d->enter = transition;
2844 emit enterChanged();
2845}
2846
2847/*!
2848 \qmlproperty Transition QtQuick.Controls::Popup::exit
2849
2850 This property holds the transition that is applied to the popup item
2851 when the popup is closed and exits the screen.
2852
2853 The following example animates the opacity of the popup when it exits
2854 the screen:
2855 \code
2856 Popup {
2857 exit: Transition {
2858 NumberAnimation { property: "opacity"; from: 1.0; to: 0.0 }
2859 }
2860 }
2861 \endcode
2862
2863 \sa enter
2864*/
2865QQuickTransition *QQuickPopup::exit() const
2866{
2867 Q_D(const QQuickPopup);
2868 return d->exit;
2869}
2870
2871void QQuickPopup::setExit(QQuickTransition *transition)
2872{
2873 Q_D(QQuickPopup);
2874 if (d->exit == transition)
2875 return;
2876 d->exit = transition;
2877 emit exitChanged();
2878}
2879
2880/*!
2881 \since QtQuick.Controls 2.5 (Qt 5.12)
2882 \qmlproperty real QtQuick.Controls::Popup::horizontalPadding
2883
2884 This property holds the horizontal padding. Unless explicitly set, the value
2885 is equal to \c padding.
2886
2887 \include qquickpopup-padding.qdocinc
2888
2889 \sa padding, leftPadding, rightPadding, verticalPadding
2890*/
2891qreal QQuickPopup::horizontalPadding() const
2892{
2893 Q_D(const QQuickPopup);
2894 return d->popupItem->horizontalPadding();
2895}
2896
2897void QQuickPopup::setHorizontalPadding(qreal padding)
2898{
2899 Q_D(QQuickPopup);
2900 d->popupItem->setHorizontalPadding(padding);
2901}
2902
2903void QQuickPopup::resetHorizontalPadding()
2904{
2905 Q_D(QQuickPopup);
2906 d->popupItem->resetHorizontalPadding();
2907}
2908
2909/*!
2910 \since QtQuick.Controls 2.5 (Qt 5.12)
2911 \qmlproperty real QtQuick.Controls::Popup::verticalPadding
2912
2913 This property holds the vertical padding. Unless explicitly set, the value
2914 is equal to \c padding.
2915
2916 \include qquickpopup-padding.qdocinc
2917
2918 \sa padding, topPadding, bottomPadding, horizontalPadding
2919*/
2920qreal QQuickPopup::verticalPadding() const
2921{
2922 Q_D(const QQuickPopup);
2923 return d->popupItem->verticalPadding();
2924}
2925
2926void QQuickPopup::setVerticalPadding(qreal padding)
2927{
2928 Q_D(QQuickPopup);
2929 d->popupItem->setVerticalPadding(padding);
2930}
2931
2932void QQuickPopup::resetVerticalPadding()
2933{
2934 Q_D(QQuickPopup);
2935 d->popupItem->resetVerticalPadding();
2936}
2937
2938/*!
2939 \since QtQuick.Controls 2.5 (Qt 5.12)
2940 \qmlproperty real QtQuick.Controls::Popup::implicitContentWidth
2941 \readonly
2942
2943 This property holds the implicit content width.
2944
2945 The value is calculated based on the content children.
2946
2947 \sa implicitContentHeight, implicitBackgroundWidth
2948*/
2949qreal QQuickPopup::implicitContentWidth() const
2950{
2951 Q_D(const QQuickPopup);
2952 return d->popupItem->implicitContentWidth();
2953}
2954
2955/*!
2956 \since QtQuick.Controls 2.5 (Qt 5.12)
2957 \qmlproperty real QtQuick.Controls::Popup::implicitContentHeight
2958 \readonly
2959
2960 This property holds the implicit content height.
2961
2962 The value is calculated based on the content children.
2963
2964 \sa implicitContentWidth, implicitBackgroundHeight
2965*/
2966qreal QQuickPopup::implicitContentHeight() const
2967{
2968 Q_D(const QQuickPopup);
2969 return d->popupItem->implicitContentHeight();
2970}
2971
2972/*!
2973 \since QtQuick.Controls 2.5 (Qt 5.12)
2974 \qmlproperty real QtQuick.Controls::Popup::implicitBackgroundWidth
2975 \readonly
2976
2977 This property holds the implicit background width.
2978
2979 The value is equal to \c {background ? background.implicitWidth : 0}.
2980
2981 \sa implicitBackgroundHeight, implicitContentWidth
2982*/
2983qreal QQuickPopup::implicitBackgroundWidth() const
2984{
2985 Q_D(const QQuickPopup);
2986 return d->popupItem->implicitBackgroundWidth();
2987}
2988
2989/*!
2990 \since QtQuick.Controls 2.5 (Qt 5.12)
2991 \qmlproperty real QtQuick.Controls::Popup::implicitBackgroundHeight
2992 \readonly
2993
2994 This property holds the implicit background height.
2995
2996 The value is equal to \c {background ? background.implicitHeight : 0}.
2997
2998 \sa implicitBackgroundWidth, implicitContentHeight
2999*/
3000qreal QQuickPopup::implicitBackgroundHeight() const
3001{
3002 Q_D(const QQuickPopup);
3003 return d->popupItem->implicitBackgroundHeight();
3004}
3005
3006/*!
3007 \since QtQuick.Controls 2.5 (Qt 5.12)
3008 \qmlproperty real QtQuick.Controls::Popup::topInset
3009
3010 This property holds the top inset for the background.
3011
3012 \sa {Popup Layout}, bottomInset
3013*/
3014qreal QQuickPopup::topInset() const
3015{
3016 Q_D(const QQuickPopup);
3017 return d->popupItem->topInset();
3018}
3019
3020void QQuickPopup::setTopInset(qreal inset)
3021{
3022 Q_D(QQuickPopup);
3023 d->popupItem->setTopInset(inset);
3024}
3025
3026void QQuickPopup::resetTopInset()
3027{
3028 Q_D(QQuickPopup);
3029 d->popupItem->resetTopInset();
3030}
3031
3032/*!
3033 \since QtQuick.Controls 2.5 (Qt 5.12)
3034 \qmlproperty real QtQuick.Controls::Popup::leftInset
3035
3036 This property holds the left inset for the background.
3037
3038 \sa {Popup Layout}, rightInset
3039*/
3040qreal QQuickPopup::leftInset() const
3041{
3042 Q_D(const QQuickPopup);
3043 return d->popupItem->leftInset();
3044}
3045
3046void QQuickPopup::setLeftInset(qreal inset)
3047{
3048 Q_D(QQuickPopup);
3049 d->popupItem->setLeftInset(inset);
3050}
3051
3052void QQuickPopup::resetLeftInset()
3053{
3054 Q_D(QQuickPopup);
3055 d->popupItem->resetLeftInset();
3056}
3057
3058/*!
3059 \since QtQuick.Controls 2.5 (Qt 5.12)
3060 \qmlproperty real QtQuick.Controls::Popup::rightInset
3061
3062 This property holds the right inset for the background.
3063
3064 \sa {Popup Layout}, leftInset
3065*/
3066qreal QQuickPopup::rightInset() const
3067{
3068 Q_D(const QQuickPopup);
3069 return d->popupItem->rightInset();
3070}
3071
3072void QQuickPopup::setRightInset(qreal inset)
3073{
3074 Q_D(QQuickPopup);
3075 d->popupItem->setRightInset(inset);
3076}
3077
3078void QQuickPopup::resetRightInset()
3079{
3080 Q_D(QQuickPopup);
3081 d->popupItem->resetRightInset();
3082}
3083
3084/*!
3085 \since QtQuick.Controls 2.5 (Qt 5.12)
3086 \qmlproperty real QtQuick.Controls::Popup::bottomInset
3087
3088 This property holds the bottom inset for the background.
3089
3090 \sa {Popup Layout}, topInset
3091*/
3092qreal QQuickPopup::bottomInset() const
3093{
3094 Q_D(const QQuickPopup);
3095 return d->popupItem->bottomInset();
3096}
3097
3098void QQuickPopup::setBottomInset(qreal inset)
3099{
3100 Q_D(QQuickPopup);
3101 d->popupItem->setBottomInset(inset);
3102}
3103
3104void QQuickPopup::resetBottomInset()
3105{
3106 Q_D(QQuickPopup);
3107 d->popupItem->resetBottomInset();
3108}
3109
3110
3111/*!
3112 \qmlproperty enumeration QtQuick.Controls::Popup::popupType
3113 \since 6.8
3114
3115 This property determines the type of popup that is preferred.
3116
3117 Available options:
3118 \value Item The popup will be embedded into the
3119 \l{Showing a popup as an item}{same scene as the parent},
3120 without the use of a separate window.
3121 \value Window The popup will be presented in a \l {Popup type}
3122 {separate window}. If the platform doesn't support
3123 multiple windows, \c Popup.Item will be used instead.
3124 \value Native The popup will be native to the platform. If the
3125 platform doesn't support native popups, \c Popup.Window
3126 will be used instead.
3127
3128 Whether a popup will be able to use the preferred type depends on the platform.
3129 \c Popup.Item is supported on all platforms, but \c Popup.Window and \c Popup.Native
3130 are normally only supported on desktop platforms. Additionally, if a popup is a
3131 \l Menu inside a \l {Native menu bars}{native menubar}, the menu will be native as
3132 well. And if the menu is a sub-menu inside another menu, the parent (or root) menu
3133 will decide the type.
3134
3135 The default value is usually \c Popup.Item, with some exceptions, mentioned above.
3136 This might change in future versions of Qt, for certain styles and platforms that benefit
3137 from using other popup types.
3138 If you always want to use native menus for all styles on macOS, for example, you can do:
3139
3140 \code
3141 Menu {
3142 popupType: Qt.platform.os === "osx" ? Popup.Native : Popup.Window
3143 }
3144 \endcode
3145
3146 Also, if you choose to customize a popup (by for example changing any of the
3147 delegates), you should consider setting the popup type to be \c Popup.Window
3148 as well. This will ensure that your changes will be visible on all platforms
3149 and for all styles. Otherwise, when native menus are being used, the delegates
3150 will \e not be used for rendering.
3151
3152 \sa {Popup type}
3153*/
3154QQuickPopup::PopupType QQuickPopup::popupType() const
3155{
3156 Q_D(const QQuickPopup);
3157 return d->popupType;
3158}
3159
3160void QQuickPopup::setPopupType(PopupType popupType)
3161{
3162 Q_D(QQuickPopup);
3163 if (d->popupType == popupType)
3164 return;
3165
3166 d->popupType = popupType;
3167
3168 emit popupTypeChanged();
3169}
3170
3171/*!
3172 \since QtQuick.Controls 2.3 (Qt 5.10)
3173 \qmlproperty palette QtQuick.Controls::Popup::palette
3174
3175 This property holds the palette currently set for the popup.
3176
3177 Popup propagates explicit palette properties to its children. If you change a specific
3178 property on a popup's palette, that property propagates to all of the popup's children,
3179 overriding any system defaults for that property.
3180
3181 \code
3182 Popup {
3183 palette.text: "red"
3184
3185 Column {
3186 Label {
3187 text: qsTr("This will use red color...")
3188 }
3189
3190 Switch {
3191 text: qsTr("... and so will this")
3192 }
3193 }
3194 }
3195 \endcode
3196
3197 \b {See also}: \l Item::palette, \l Window::palette, \l ColorGroup,
3198 \l [QML] {Palette}
3199*/
3200
3201bool QQuickPopup::filtersChildMouseEvents() const
3202{
3203 Q_D(const QQuickPopup);
3204 return d->popupItem->filtersChildMouseEvents();
3205}
3206
3207void QQuickPopup::setFiltersChildMouseEvents(bool filter)
3208{
3209 Q_D(QQuickPopup);
3210 d->popupItem->setFiltersChildMouseEvents(filter);
3211}
3212
3213/*!
3214 \qmlmethod void QtQuick.Controls::Popup::forceActiveFocus(enumeration reason = Qt.OtherFocusReason)
3215
3216 Forces active focus on the popup with the given \a reason.
3217
3218 This method sets focus on the popup and ensures that all ancestor
3219 \l FocusScope objects in the object hierarchy are also given \l focus.
3220
3221 \sa activeFocus, Qt::FocusReason
3222*/
3223void QQuickPopup::forceActiveFocus(Qt::FocusReason reason)
3224{
3225 Q_D(QQuickPopup);
3226 d->popupItem->forceActiveFocus(reason);
3227}
3228
3229void QQuickPopup::classBegin()
3230{
3231 Q_D(QQuickPopup);
3232 d->complete = false;
3233 QQmlContext *context = qmlContext(this);
3234 if (context)
3235 QQmlEngine::setContextForObject(d->popupItem, context);
3236 d->popupItem->classBegin();
3237}
3238
3239void QQuickPopup::componentComplete()
3240{
3241 Q_D(QQuickPopup);
3242 qCDebug(lcQuickPopup) << "componentComplete" << this;
3243 if (!parentItem())
3244 resetParentItem();
3245
3246 d->complete = true;
3247 d->popupItem->setObjectName(QQmlMetaType::prettyTypeName(this));
3248 d->popupItem->componentComplete();
3249
3250 if (auto currentContentItem = d->popupItem->d_func()->contentItem.data()) {
3251 connect(currentContentItem, &QQuickItem::childrenChanged,
3252 this, &QQuickPopup::contentChildrenChanged);
3253 }
3254
3255 if (d->visible && d->window)
3256 openPopup(d);
3257}
3258
3259bool QQuickPopup::isComponentComplete() const
3260{
3261 Q_D(const QQuickPopup);
3262 return d->complete;
3263}
3264
3265bool QQuickPopup::childMouseEventFilter(QQuickItem *child, QEvent *event)
3266{
3267 Q_UNUSED(child);
3268 Q_UNUSED(event);
3269 return false;
3270}
3271
3272void QQuickPopup::focusInEvent(QFocusEvent *event)
3273{
3274 event->accept();
3275}
3276
3277void QQuickPopup::focusOutEvent(QFocusEvent *event)
3278{
3279 event->accept();
3280}
3281
3282void QQuickPopup::keyPressEvent(QKeyEvent *event)
3283{
3284 Q_D(QQuickPopup);
3285 if (!hasActiveFocus())
3286 return;
3287
3288#if QT_CONFIG(shortcut)
3289 if (d->closePolicy.testFlag(QQuickPopup::CloseOnEscape)
3290 && (event->matches(QKeySequence::Cancel)
3291#if defined(Q_OS_ANDROID)
3292 || event->key() == Qt::Key_Back
3293#endif
3294 )) {
3295 event->accept();
3296 if (d->interactive)
3297 d->closeOrReject();
3298 return;
3299 }
3300#endif
3301
3302 if (hasActiveFocus() && (event->key() == Qt::Key_Tab || event->key() == Qt::Key_Backtab)) {
3303 event->accept();
3304 QQuickItemPrivate::focusNextPrev(d->popupItem, event->key() == Qt::Key_Tab);
3305 }
3306}
3307
3308void QQuickPopup::keyReleaseEvent(QKeyEvent *event)
3309{
3310 event->accept();
3311}
3312
3313void QQuickPopup::mousePressEvent(QMouseEvent *event)
3314{
3315 Q_D(QQuickPopup);
3316 event->setAccepted(d->handleMouseEvent(d->popupItem, event));
3317}
3318
3319void QQuickPopup::mouseMoveEvent(QMouseEvent *event)
3320{
3321 Q_D(QQuickPopup);
3322 event->setAccepted(d->handleMouseEvent(d->popupItem, event));
3323}
3324
3325void QQuickPopup::mouseReleaseEvent(QMouseEvent *event)
3326{
3327 Q_D(QQuickPopup);
3328 event->setAccepted(d->handleMouseEvent(d->popupItem, event));
3329}
3330
3331void QQuickPopup::mouseDoubleClickEvent(QMouseEvent *event)
3332{
3333 event->accept();
3334}
3335
3336void QQuickPopup::mouseUngrabEvent()
3337{
3338 Q_D(QQuickPopup);
3339 d->handleUngrab();
3340}
3341
3342
3343/*!
3344 \internal
3345
3346 Called whenever the window receives a Wheel/Hover/Mouse/Touch/Tablet event,
3347 and has an active popup (with popupType: Popup.Item) in its scene.
3348
3349 The purpose is to close popups when the press/release event happened outside of it,
3350 and the closePolicy allows for it to happen.
3351
3352 If the function is called from childMouseEventFilter, then the return value of this
3353 function will determine whether the event will be filtered, or delivered to \a item.
3354*/
3355bool QQuickPopup::overlayEvent(QQuickItem *item, QEvent *event)
3356{
3357 Q_D(QQuickPopup);
3358
3359 // The overlay will normally call this function for each active popup, assuming there is no active mouse grabber.
3360 // If \a item doesn't belong to any of these popups, but exists in an overlay subtree, we shouldn't filter the event,
3361 // since the item is supposed to be independent of any active popups.
3362 if (d->belongsToOverlayChildAbove(item))
3363 return false;
3364
3365 switch (event->type()) {
3366 case QEvent::KeyPress:
3367 case QEvent::KeyRelease:
3368 case QEvent::MouseMove:
3369 case QEvent::Wheel:
3370 if (d->modal)
3371 event->accept();
3372 return d->modal;
3373 case QEvent::DragEnter:
3374 case QEvent::DragMove:
3375 case QEvent::DragLeave:
3376 case QEvent::Drop:
3377 // ignore() so that the OS sees Qt::IgnoreAction and renders the "not allowed" cursor
3378 // within the drag image. accept() would only change the window cursor after the drag ends: too late.
3379 if (d->modal)
3380 event->ignore();
3381 return d->modal;
3382#if QT_CONFIG(tabletevent)
3383 case QEvent::TabletPress:
3384 case QEvent::TabletMove:
3385 case QEvent::TabletRelease:
3386 if (d->modal)
3387 event->accept();
3388 return d->modal;
3389#endif
3390#if QT_CONFIG(quicktemplates2_multitouch)
3391 case QEvent::TouchBegin:
3392 case QEvent::TouchUpdate:
3393 case QEvent::TouchEnd:
3394 return d->handleTouchEvent(item, static_cast<QTouchEvent *>(event));
3395#endif
3396 case QEvent::HoverEnter:
3397 case QEvent::HoverMove:
3398 case QEvent::HoverLeave:
3399 return d->handleHoverEvent(item, static_cast<QHoverEvent *>(event));
3400
3401 case QEvent::MouseButtonPress:
3402 case QEvent::MouseButtonRelease:
3403 return d->handleMouseEvent(item, static_cast<QMouseEvent *>(event));
3404
3405 default:
3406 return false;
3407 }
3408}
3409
3410#if QT_CONFIG(quicktemplates2_multitouch)
3411void QQuickPopup::touchEvent(QTouchEvent *event)
3412{
3413 Q_D(QQuickPopup);
3414 event->setAccepted(d->handleTouchEvent(d->popupItem, event));
3415}
3416
3417void QQuickPopup::touchUngrabEvent()
3418{
3419 Q_D(QQuickPopup);
3420 d->handleUngrab();
3421}
3422#endif
3423
3424#if QT_CONFIG(wheelevent)
3425void QQuickPopup::wheelEvent(QWheelEvent *event)
3426{
3427 event->accept();
3428}
3429#endif
3430
3431#if QT_CONFIG(quick_draganddrop)
3432void QQuickPopup::dragMoveEvent(QDragMoveEvent *event)
3433{
3434 event->accept();
3435}
3436
3437void QQuickPopup::dragLeaveEvent(QDragLeaveEvent *event)
3438{
3439 event->accept();
3440}
3441
3442void QQuickPopup::dropEvent(QDropEvent *event)
3443{
3444 event->accept();
3445}
3446
3447void QQuickPopup::dragEnterEvent(QDragEnterEvent *event)
3448{
3449 event->ignore(); // OS shows "forbidden" cursor as part of drag image
3450}
3451#endif
3452
3453void QQuickPopup::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
3454{
3455 Q_UNUSED(newItem);
3456 Q_UNUSED(oldItem);
3457}
3458
3459void QQuickPopup::contentSizeChange(const QSizeF &newSize, const QSizeF &oldSize)
3460{
3461 qCDebug(lcQuickPopup) << "contentSizeChange called on" << this << "with newSize" << newSize << "oldSize" << oldSize;
3462 if (!qFuzzyCompare(newSize.width(), oldSize.width()))
3463 emit contentWidthChanged();
3464 if (!qFuzzyCompare(newSize.height(), oldSize.height()))
3465 emit contentHeightChanged();
3466}
3467
3468void QQuickPopup::fontChange(const QFont &newFont, const QFont &oldFont)
3469{
3470 Q_UNUSED(newFont);
3471 Q_UNUSED(oldFont);
3472 emit fontChanged();
3473}
3474
3475void QQuickPopup::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
3476{
3477 Q_D(QQuickPopup);
3478 qCDebug(lcQuickPopup) << "geometryChange called on" << this << "with newGeometry" << newGeometry << "oldGeometry" << oldGeometry;
3479 if (!d->usePopupWindow())
3480 d->reposition();
3481 if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width())) {
3482 emit widthChanged();
3483 emit availableWidthChanged();
3484 }
3485 if (!qFuzzyCompare(newGeometry.height(), oldGeometry.height())) {
3486 emit heightChanged();
3487 emit availableHeightChanged();
3488 }
3489}
3490
3491void QQuickPopup::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &)
3492{
3493 switch (change) {
3494 case QQuickItem::ItemActiveFocusHasChanged:
3495 emit activeFocusChanged();
3496 break;
3497 case QQuickItem::ItemOpacityHasChanged:
3498 emit opacityChanged();
3499 break;
3500 default:
3501 break;
3502 }
3503}
3504
3505void QQuickPopup::localeChange(const QLocale &newLocale, const QLocale &oldLocale)
3506{
3507 Q_UNUSED(newLocale);
3508 Q_UNUSED(oldLocale);
3509 emit localeChanged();
3510}
3511
3512void QQuickPopup::marginsChange(const QMarginsF &newMargins, const QMarginsF &oldMargins)
3513{
3514 Q_D(QQuickPopup);
3515 Q_UNUSED(newMargins);
3516 Q_UNUSED(oldMargins);
3517 d->reposition();
3518}
3519
3520void QQuickPopup::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding)
3521{
3522 const bool tp = !qFuzzyCompare(newPadding.top(), oldPadding.top());
3523 const bool lp = !qFuzzyCompare(newPadding.left(), oldPadding.left());
3524 const bool rp = !qFuzzyCompare(newPadding.right(), oldPadding.right());
3525 const bool bp = !qFuzzyCompare(newPadding.bottom(), oldPadding.bottom());
3526
3527 if (tp)
3528 emit topPaddingChanged();
3529 if (lp)
3530 emit leftPaddingChanged();
3531 if (rp)
3532 emit rightPaddingChanged();
3533 if (bp)
3534 emit bottomPaddingChanged();
3535
3536 if (lp || rp) {
3537 emit horizontalPaddingChanged();
3538 emit availableWidthChanged();
3539 }
3540 if (tp || bp) {
3541 emit verticalPaddingChanged();
3542 emit availableHeightChanged();
3543 }
3544}
3545
3546void QQuickPopup::spacingChange(qreal newSpacing, qreal oldSpacing)
3547{
3548 Q_UNUSED(newSpacing);
3549 Q_UNUSED(oldSpacing);
3550 emit spacingChanged();
3551}
3552
3553void QQuickPopup::insetChange(const QMarginsF &newInset, const QMarginsF &oldInset)
3554{
3555 if (!qFuzzyCompare(newInset.top(), oldInset.top()))
3556 emit topInsetChanged();
3557 if (!qFuzzyCompare(newInset.left(), oldInset.left()))
3558 emit leftInsetChanged();
3559 if (!qFuzzyCompare(newInset.right(), oldInset.right()))
3560 emit rightInsetChanged();
3561 if (!qFuzzyCompare(newInset.bottom(), oldInset.bottom()))
3562 emit bottomInsetChanged();
3563}
3564
3565QFont QQuickPopup::defaultFont() const
3566{
3567 return QQuickTheme::font(QQuickTheme::System);
3568}
3569
3570#if QT_CONFIG(accessibility)
3571QAccessible::Role QQuickPopup::effectiveAccessibleRole() const
3572{
3573 auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, false);
3574
3575 auto role = QAccessible::NoRole;
3576 if (auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
3577 role = accessibleAttached->role();
3578 if (role == QAccessible::NoRole)
3579 role = accessibleRole();
3580
3581 return role;
3582}
3583
3584QAccessible::Role QQuickPopup::accessibleRole() const
3585{
3586 return QAccessible::Dialog;
3587}
3588
3589void QQuickPopup::accessibilityActiveChanged(bool active)
3590{
3591 Q_UNUSED(active);
3592}
3593#endif
3594
3595QString QQuickPopup::accessibleName() const
3596{
3597 Q_D(const QQuickPopup);
3598 return d->popupItem->accessibleName();
3599}
3600
3601void QQuickPopup::maybeSetAccessibleName(const QString &name)
3602{
3603 Q_D(QQuickPopup);
3604 d->popupItem->maybeSetAccessibleName(name);
3605}
3606
3607QVariant QQuickPopup::accessibleProperty(const char *propertyName)
3608{
3609 Q_D(const QQuickPopup);
3610 return d->popupItem->accessibleProperty(propertyName);
3611}
3612
3613bool QQuickPopup::setAccessibleProperty(const char *propertyName, const QVariant &value)
3614{
3615 Q_D(QQuickPopup);
3616 return d->popupItem->setAccessibleProperty(propertyName, value);
3617}
3618
3619void QQuickPopup::setWindowModality(const Qt::WindowModality modality)
3620{
3621 Q_D(QQuickPopup);
3622 d->popupWndModality = modality;
3623}
3624
3625QQuickItem *QQuickPopup::safeAreaAttachmentItem()
3626{
3627 return popupItem();
3628}
3629
3630QQuickItem *QQuickPopup::attacheeItem() const
3631{
3632 return popupItem();
3633}
3634
3635QtPrivate::QQuickAttachedPropertyPropagator *QQuickPopup::attachedParent(
3636 const QMetaObject *ourAttachedType) const
3637{
3638 auto *popupWindow = popupItem()->window();
3639 qCDebug(lcAttachedPropertyPropagator).noquote() << "- attachee is a popup; checking its window"
3640 << popupWindow;
3641 auto *object = QtPrivate::QQuickAttachedPropertyPropagator::attachedObject(
3642 ourAttachedType, popupWindow);
3643 if (object)
3644 return object;
3645
3646 if (qobject_cast<QQuickPopupWindow *>(popupWindow)) {
3647 qCDebug(lcAttachedPropertyPropagator).noquote() << "- checking its window's transientParent"
3648 << popupWindow->transientParent();
3649 return QtPrivate::QQuickAttachedPropertyPropagator::attachedObject(ourAttachedType,
3650 popupWindow->transientParent());
3651 }
3652
3653 return {};
3654}
3655
3656QT_END_NAMESPACE
3657
3658#include "qquickpopup.moc"
3659#include "moc_qquickpopup_p.cpp"
Combined button and popup list for selecting options.
static std::unique_ptr< QWindowExposedObserver, ObserverDeleter > s_windowExposedObserver
static QQuickItem * findRootOfOverlaySubtree(QQuickItem *source, const QQuickOverlay *overlay)
void openPopup(QQuickPopupPrivate *d)
void operator()(QWindowExposedObserver *observer)