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