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
4#ifndef QQUICKPOPUP_P_H
5#define QQUICKPOPUP_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qobject.h>
19#include <QtCore/qmargins.h>
20#include <QtGui/qevent.h>
21#include <QtCore/qlocale.h>
22#include <QtGui/qfont.h>
23#include <QtGui/qpalette.h>
24#include <QtQuickTemplates2/private/qtquicktemplates2global_p.h>
25#include <QtQml/qqml.h>
26#include <QtQml/qqmllist.h>
27#include <QtQml/qqmlparserstatus.h>
28#include <QtQuick/qquickitem.h>
29
30#if QT_CONFIG(accessibility)
31#include <QtGui/qaccessible.h>
32#endif
33
34QT_BEGIN_NAMESPACE
35
36class QQuickWindow;
37class QQuickPopupAnchors;
38class QQuickPopupPrivate;
39class QQuickTransition;
40
41class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickPopup : public QObject, public QQmlParserStatus
42{
43 Q_OBJECT
44 Q_INTERFACES(QQmlParserStatus)
45 Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL)
46 Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL)
47 Q_PROPERTY(qreal z READ z WRITE setZ RESET resetZ NOTIFY zChanged FINAL)
48 Q_PROPERTY(qreal width READ width WRITE setWidth RESET resetWidth NOTIFY widthChanged FINAL)
49 Q_PROPERTY(qreal height READ height WRITE setHeight RESET resetHeight NOTIFY heightChanged FINAL)
50 Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged FINAL)
51 Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged FINAL)
52 Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged FINAL)
53 Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged FINAL)
54 Q_PROPERTY(qreal availableWidth READ availableWidth NOTIFY availableWidthChanged FINAL)
55 Q_PROPERTY(qreal availableHeight READ availableHeight NOTIFY availableHeightChanged FINAL)
56 Q_PROPERTY(qreal margins READ margins WRITE setMargins RESET resetMargins NOTIFY marginsChanged FINAL)
57 Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin RESET resetTopMargin NOTIFY topMarginChanged FINAL)
58 Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin RESET resetLeftMargin NOTIFY leftMarginChanged FINAL)
59 Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin RESET resetRightMargin NOTIFY rightMarginChanged FINAL)
60 Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin RESET resetBottomMargin NOTIFY bottomMarginChanged FINAL)
61 Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged FINAL)
62 Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged FINAL)
63 Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged FINAL)
64 Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged FINAL)
65 Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged FINAL)
66 Q_PROPERTY(QLocale locale READ locale WRITE setLocale RESET resetLocale NOTIFY localeChanged FINAL)
67 Q_PROPERTY(QFont font READ font WRITE setFont RESET resetFont NOTIFY fontChanged FINAL)
68 Q_PROPERTY(QQuickItem *parent READ parentItem WRITE setParentItem RESET resetParentItem NOTIFY parentChanged FINAL)
69 Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL)
70 Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL)
71 Q_PRIVATE_PROPERTY(QQuickPopup::d_func(), QQmlListProperty<QObject> contentData READ contentData)
72 Q_PRIVATE_PROPERTY(QQuickPopup::d_func(), QQmlListProperty<QQuickItem> contentChildren READ contentChildren NOTIFY contentChildrenChanged FINAL)
73 Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged FINAL)
74 Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
75 Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
76 Q_PROPERTY(bool modal READ isModal WRITE setModal NOTIFY modalChanged FINAL)
77 Q_PROPERTY(bool dim READ dim WRITE setDim RESET resetDim NOTIFY dimChanged FINAL)
78 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
79 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
80 Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged FINAL)
81 Q_PROPERTY(ClosePolicy closePolicy READ closePolicy WRITE setClosePolicy RESET resetClosePolicy NOTIFY closePolicyChanged FINAL)
82 Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin FINAL)
83 Q_PROPERTY(QQuickTransition *enter READ enter WRITE setEnter NOTIFY enterChanged FINAL)
84 Q_PROPERTY(QQuickTransition *exit READ exit WRITE setExit NOTIFY exitChanged FINAL)
85 // 2.1 (Qt 5.8)
86 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL REVISION(2, 1))
87 // 2.3 (Qt 5.10)
88 Q_PROPERTY(bool opened READ isOpened NOTIFY openedChanged FINAL REVISION(2, 3))
89 Q_PROPERTY(bool mirrored READ isMirrored NOTIFY mirroredChanged FINAL REVISION(2, 3))
90 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL REVISION(2, 3))
91 Q_PRIVATE_PROPERTY(QQuickPopup::d_func(), QQuickPalette *palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged REVISION(2, 3))
92 // 2.5 (Qt 5.12)
93 Q_PROPERTY(qreal horizontalPadding READ horizontalPadding WRITE setHorizontalPadding RESET resetHorizontalPadding NOTIFY horizontalPaddingChanged FINAL)
94 Q_PROPERTY(qreal verticalPadding READ verticalPadding WRITE setVerticalPadding RESET resetVerticalPadding NOTIFY verticalPaddingChanged FINAL)
95 Q_PRIVATE_PROPERTY(QQuickPopup::d_func(), QQuickPopupAnchors *anchors READ getAnchors DESIGNABLE false CONSTANT FINAL REVISION(2, 5))
96 Q_PROPERTY(qreal implicitContentWidth READ implicitContentWidth NOTIFY implicitContentWidthChanged FINAL REVISION(2, 5))
97 Q_PROPERTY(qreal implicitContentHeight READ implicitContentHeight NOTIFY implicitContentHeightChanged FINAL REVISION(2, 5))
98 Q_PROPERTY(qreal implicitBackgroundWidth READ implicitBackgroundWidth NOTIFY implicitBackgroundWidthChanged FINAL REVISION(2, 5))
99 Q_PROPERTY(qreal implicitBackgroundHeight READ implicitBackgroundHeight NOTIFY implicitBackgroundHeightChanged FINAL REVISION(2, 5))
100 Q_PROPERTY(qreal topInset READ topInset WRITE setTopInset RESET resetTopInset NOTIFY topInsetChanged FINAL REVISION(2, 5))
101 Q_PROPERTY(qreal leftInset READ leftInset WRITE setLeftInset RESET resetLeftInset NOTIFY leftInsetChanged FINAL REVISION(2, 5))
102 Q_PROPERTY(qreal rightInset READ rightInset WRITE setRightInset RESET resetRightInset NOTIFY rightInsetChanged FINAL REVISION(2, 5))
103 Q_PROPERTY(qreal bottomInset READ bottomInset WRITE setBottomInset RESET resetBottomInset NOTIFY bottomInsetChanged FINAL REVISION(2, 5))
104 Q_CLASSINFO("DeferredPropertyNames", "background,contentItem")
105 Q_CLASSINFO("DefaultProperty", "contentData")
106 QML_NAMED_ELEMENT(Popup)
107 QML_ADDED_IN_VERSION(2, 0)
108
109public:
110 explicit QQuickPopup(QObject *parent = nullptr);
111 ~QQuickPopup();
112
113 qreal x() const;
114 void setX(qreal x);
115
116 qreal y() const;
117 void setY(qreal y);
118
119 QPointF position() const;
120 void setPosition(const QPointF &pos);
121
122 qreal z() const;
123 void setZ(qreal z);
124 void resetZ();
125
126 qreal width() const;
127 void setWidth(qreal width);
128 void resetWidth();
129
130 qreal height() const;
131 void setHeight(qreal height);
132 void resetHeight();
133
134 qreal implicitWidth() const;
135 void setImplicitWidth(qreal width);
136
137 qreal implicitHeight() const;
138 void setImplicitHeight(qreal height);
139
140 qreal contentWidth() const;
141 void setContentWidth(qreal width);
142
143 qreal contentHeight() const;
144 void setContentHeight(qreal height);
145
146 qreal availableWidth() const;
147 qreal availableHeight() const;
148
149 qreal margins() const;
150 void setMargins(qreal margins);
151 void resetMargins();
152
153 qreal topMargin() const;
154 void setTopMargin(qreal margin);
155 void resetTopMargin();
156
157 qreal leftMargin() const;
158 void setLeftMargin(qreal margin);
159 void resetLeftMargin();
160
161 qreal rightMargin() const;
162 void setRightMargin(qreal margin);
163 void resetRightMargin();
164
165 qreal bottomMargin() const;
166 void setBottomMargin(qreal margin);
167 void resetBottomMargin();
168
169 qreal padding() const;
170 void setPadding(qreal padding);
171 void resetPadding();
172
173 qreal topPadding() const;
174 void setTopPadding(qreal padding);
175 void resetTopPadding();
176
177 qreal leftPadding() const;
178 void setLeftPadding(qreal padding);
179 void resetLeftPadding();
180
181 qreal rightPadding() const;
182 void setRightPadding(qreal padding);
183 void resetRightPadding();
184
185 qreal bottomPadding() const;
186 void setBottomPadding(qreal padding);
187 void resetBottomPadding();
188
189 QLocale locale() const;
190 void setLocale(const QLocale &locale);
191 void resetLocale();
192
193 QFont font() const;
194 void setFont(const QFont &font);
195 void resetFont();
196
197 QQuickWindow *window() const;
198 QQuickItem *popupItem() const;
199
200 QQuickItem *parentItem() const;
201 void setParentItem(QQuickItem *parent);
202 void resetParentItem();
203
204 QQuickItem *background() const;
205 void setBackground(QQuickItem *background);
206
207 QQuickItem *contentItem() const;
208 void setContentItem(QQuickItem *item);
209
210 bool clip() const;
211 void setClip(bool clip);
212
213 bool hasFocus() const;
214 void setFocus(bool focus);
215
216 bool hasActiveFocus() const;
217
218 bool isModal() const;
219 void setModal(bool modal);
220
221 bool dim() const;
222 void setDim(bool dim);
223 void resetDim();
224
225 bool isVisible() const;
226 virtual void setVisible(bool visible);
227
228 qreal opacity() const;
229 void setOpacity(qreal opacity);
230
231 qreal scale() const;
232 void setScale(qreal scale);
233
234 enum ClosePolicyFlag {
235 NoAutoClose = 0x00,
236 CloseOnPressOutside = 0x01,
237 CloseOnPressOutsideParent = 0x02,
238 CloseOnReleaseOutside = 0x04,
239 CloseOnReleaseOutsideParent = 0x08,
240 CloseOnEscape = 0x10
241 };
242 Q_DECLARE_FLAGS(ClosePolicy, ClosePolicyFlag)
243 Q_FLAG(ClosePolicy)
244
245 ClosePolicy closePolicy() const;
246 void setClosePolicy(ClosePolicy policy);
247 void resetClosePolicy();
248
249 // keep in sync with Item.TransformOrigin
250 enum TransformOrigin {
251 TopLeft, Top, TopRight,
252 Left, Center, Right,
253 BottomLeft, Bottom, BottomRight
254 };
255 Q_ENUM(TransformOrigin)
256
257 TransformOrigin transformOrigin() const;
258 void setTransformOrigin(TransformOrigin);
259
260 QQuickTransition *enter() const;
261 void setEnter(QQuickTransition *transition);
262
263 QQuickTransition *exit() const;
264 void setExit(QQuickTransition *transition);
265
266 bool filtersChildMouseEvents() const;
267 void setFiltersChildMouseEvents(bool filter);
268
269 Q_INVOKABLE void forceActiveFocus(Qt::FocusReason reason = Qt::OtherFocusReason);
270
271 // 2.1 (Qt 5.8)
272 qreal spacing() const;
273 void setSpacing(qreal spacing);
274 void resetSpacing();
275
276 // 2.3 (Qt 5.10)
277 bool isOpened() const;
278 bool isMirrored() const;
279
280 bool isEnabled() const;
281 void setEnabled(bool enabled);
282
283 // 2.5 (Qt 5.12)
284 qreal horizontalPadding() const;
285 void setHorizontalPadding(qreal padding);
286 void resetHorizontalPadding();
287
288 qreal verticalPadding() const;
289 void setVerticalPadding(qreal padding);
290 void resetVerticalPadding();
291
292 qreal implicitContentWidth() const;
293 qreal implicitContentHeight() const;
294
295 qreal implicitBackgroundWidth() const;
296 qreal implicitBackgroundHeight() const;
297
298 qreal topInset() const;
299 void setTopInset(qreal inset);
300 void resetTopInset();
301
302 qreal leftInset() const;
303 void setLeftInset(qreal inset);
304 void resetLeftInset();
305
306 qreal rightInset() const;
307 void setRightInset(qreal inset);
308 void resetRightInset();
309
310 qreal bottomInset() const;
311 void setBottomInset(qreal inset);
312 void resetBottomInset();
313
314public Q_SLOTS:
315 void open();
316 void close();
317
318Q_SIGNALS:
319 void opened();
320 void closed();
321 void aboutToShow();
322 void aboutToHide();
323 void xChanged();
324 void yChanged();
325 void zChanged();
326 void widthChanged();
327 void heightChanged();
328 void implicitWidthChanged();
329 void implicitHeightChanged();
330 void contentWidthChanged();
331 void contentHeightChanged();
332 void availableWidthChanged();
333 void availableHeightChanged();
334 void marginsChanged();
335 void topMarginChanged();
336 void leftMarginChanged();
337 void rightMarginChanged();
338 void bottomMarginChanged();
339 void paddingChanged();
340 void topPaddingChanged();
341 void leftPaddingChanged();
342 void rightPaddingChanged();
343 void bottomPaddingChanged();
344 void fontChanged();
345 void localeChanged();
346 void parentChanged();
347 void backgroundChanged();
348 void contentItemChanged();
349 void contentChildrenChanged();
350 void clipChanged();
351 void focusChanged();
352 void activeFocusChanged();
353 void modalChanged();
354 void dimChanged();
355 void visibleChanged();
356 void opacityChanged();
357 void scaleChanged();
358 void closePolicyChanged();
359 void enterChanged();
360 void exitChanged();
361 void windowChanged(QQuickWindow *window);
362 // 2.1 (Qt 5.8)
363 Q_REVISION(2, 1) void spacingChanged();
364 // 2.3 (Qt 5.10)
365 Q_REVISION(2, 3) void openedChanged();
366 Q_REVISION(2, 3) void mirroredChanged();
367 Q_REVISION(2, 3) void enabledChanged();
368 Q_REVISION(2, 3) void paletteChanged();
369 Q_REVISION(2, 3) void paletteCreated();
370 // 2.5 (Qt 5.12)
371 Q_REVISION(2, 5) void horizontalPaddingChanged();
372 Q_REVISION(2, 5) void verticalPaddingChanged();
373 Q_REVISION(2, 5) void implicitContentWidthChanged();
374 Q_REVISION(2, 5) void implicitContentHeightChanged();
375 Q_REVISION(2, 5) void implicitBackgroundWidthChanged();
376 Q_REVISION(2, 5) void implicitBackgroundHeightChanged();
377 Q_REVISION(2, 5) void topInsetChanged();
378 Q_REVISION(2, 5) void leftInsetChanged();
379 Q_REVISION(2, 5) void rightInsetChanged();
380 Q_REVISION(2, 5) void bottomInsetChanged();
381
382protected:
383 QQuickPopup(QQuickPopupPrivate &dd, QObject *parent);
384
385 void classBegin() override;
386 void componentComplete() override;
387 bool isComponentComplete() const;
388
389 virtual bool childMouseEventFilter(QQuickItem *child, QEvent *event);
390 virtual void focusInEvent(QFocusEvent *event);
391 virtual void focusOutEvent(QFocusEvent *event);
392 virtual void keyPressEvent(QKeyEvent *event);
393 virtual void keyReleaseEvent(QKeyEvent *event);
394 virtual void mousePressEvent(QMouseEvent *event);
395 virtual void mouseMoveEvent(QMouseEvent *event);
396 virtual void mouseReleaseEvent(QMouseEvent *event);
397 virtual void mouseDoubleClickEvent(QMouseEvent *event);
398 virtual void mouseUngrabEvent();
399 virtual bool overlayEvent(QQuickItem *item, QEvent *event);
400#if QT_CONFIG(quicktemplates2_multitouch)
401 virtual void touchEvent(QTouchEvent *event);
402 virtual void touchUngrabEvent();
403#endif
404#if QT_CONFIG(wheelevent)
405 virtual void wheelEvent(QWheelEvent *event);
406#endif
407
408 virtual void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem);
409 virtual void contentSizeChange(const QSizeF &newSize, const QSizeF &oldSize);
410 virtual void fontChange(const QFont &newFont, const QFont &oldFont);
411 virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry);
412 virtual void localeChange(const QLocale &newLocale, const QLocale &oldLocale);
413 virtual void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data);
414 virtual void marginsChange(const QMarginsF &newMargins, const QMarginsF &oldMargins);
415 virtual void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding);
416 virtual void spacingChange(qreal newSpacing, qreal oldSpacing);
417 virtual void insetChange(const QMarginsF &newInset, const QMarginsF &oldInset);
418
419 virtual QFont defaultFont() const;
420
421#if QT_CONFIG(accessibility)
422 QAccessible::Role effectiveAccessibleRole() const;
423private:
424 virtual QAccessible::Role accessibleRole() const;
425protected:
426 virtual void accessibilityActiveChanged(bool active);
427#endif
428
429 QString accessibleName() const;
430 void maybeSetAccessibleName(const QString &name);
431
432 QVariant accessibleProperty(const char *propertyName);
433 bool setAccessibleProperty(const char *propertyName, const QVariant &value);
434
435private:
436 Q_DISABLE_COPY(QQuickPopup)
437 Q_DECLARE_PRIVATE(QQuickPopup)
438 friend class QQuickPopupItem;
439 friend class QQuickOverlay;
440 friend class QQuickOverlayPrivate;
441};
442
443Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickPopup::ClosePolicy)
444
445QT_END_NAMESPACE
446
447QML_DECLARE_TYPE(QQuickPopup)
448
449#endif // QQUICKPOPUP_P_H
450

source code of qtdeclarative/src/quicktemplates/qquickpopup_p.h