| 1 | // Copyright (C) 2016 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 QWIDGET_H |
| 5 | #define QWIDGET_H |
| 6 | |
| 7 | #include <QtWidgets/qtwidgetsglobal.h> |
| 8 | #include <QtGui/qwindowdefs.h> |
| 9 | #include <QtCore/qobject.h> |
| 10 | #include <QtCore/qmargins.h> |
| 11 | #if QT_CONFIG(action) |
| 12 | #include <QtGui/qaction.h> |
| 13 | #endif |
| 14 | #include <QtGui/qpaintdevice.h> |
| 15 | #include <QtGui/qpalette.h> |
| 16 | #include <QtGui/qfont.h> |
| 17 | #include <QtGui/qfontmetrics.h> |
| 18 | #include <QtGui/qfontinfo.h> |
| 19 | #include <QtWidgets/qsizepolicy.h> |
| 20 | #include <QtGui/qregion.h> |
| 21 | #include <QtGui/qbrush.h> |
| 22 | #include <QtGui/qcursor.h> |
| 23 | #if QT_CONFIG(shortcut) |
| 24 | # include <QtGui/qkeysequence.h> |
| 25 | #endif |
| 26 | |
| 27 | #ifdef QT_INCLUDE_COMPAT |
| 28 | #include <QtGui/qevent.h> |
| 29 | #endif |
| 30 | |
| 31 | QT_BEGIN_NAMESPACE |
| 32 | |
| 33 | |
| 34 | class QLayout; |
| 35 | class QStyle; |
| 36 | class QAction; |
| 37 | class QVariant; |
| 38 | class QWindow; |
| 39 | class QActionEvent; |
| 40 | class QMouseEvent; |
| 41 | class QWheelEvent; |
| 42 | class QHoverEvent; |
| 43 | class QKeyEvent; |
| 44 | class QEnterEvent; |
| 45 | class QFocusEvent; |
| 46 | class QPaintEvent; |
| 47 | class QMoveEvent; |
| 48 | class QResizeEvent; |
| 49 | class QCloseEvent; |
| 50 | class ; |
| 51 | class QInputMethodEvent; |
| 52 | class QTabletEvent; |
| 53 | class QDragEnterEvent; |
| 54 | class QDragMoveEvent; |
| 55 | class QDragLeaveEvent; |
| 56 | class QDropEvent; |
| 57 | class QScreen; |
| 58 | class QShowEvent; |
| 59 | class QHideEvent; |
| 60 | class QIcon; |
| 61 | class QBackingStore; |
| 62 | class QPlatformWindow; |
| 63 | class QLocale; |
| 64 | class QGraphicsProxyWidget; |
| 65 | class QGraphicsEffect; |
| 66 | class QRasterWindowSurface; |
| 67 | class QUnifiedToolbarSurface; |
| 68 | class QPixmap; |
| 69 | #ifndef QT_NO_DEBUG_STREAM |
| 70 | class QDebug; |
| 71 | #endif |
| 72 | |
| 73 | class QWidgetData |
| 74 | { |
| 75 | public: |
| 76 | WId winid; |
| 77 | uint widget_attributes; |
| 78 | Qt::WindowFlags window_flags; |
| 79 | uint window_state : 4; |
| 80 | uint focus_policy : 4; |
| 81 | uint sizehint_forced :1; |
| 82 | uint is_closing :1; |
| 83 | uint in_show : 1; |
| 84 | uint in_set_window_state : 1; |
| 85 | mutable uint fstrut_dirty : 1; |
| 86 | uint : 3; |
| 87 | uint window_modality : 2; |
| 88 | uint in_destructor : 1; |
| 89 | uint unused : 13; |
| 90 | QRect crect; |
| 91 | mutable QPalette pal; |
| 92 | QFont fnt; |
| 93 | QRect wrect; |
| 94 | }; |
| 95 | |
| 96 | class QWidgetPrivate; |
| 97 | |
| 98 | class Q_WIDGETS_EXPORT QWidget : public QObject, public QPaintDevice |
| 99 | { |
| 100 | Q_OBJECT |
| 101 | Q_DECLARE_PRIVATE(QWidget) |
| 102 | |
| 103 | Q_PROPERTY(bool modal READ isModal) |
| 104 | Q_PROPERTY(Qt::WindowModality windowModality READ windowModality WRITE setWindowModality) |
| 105 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) |
| 106 | Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry) |
| 107 | Q_PROPERTY(QRect frameGeometry READ frameGeometry) |
| 108 | Q_PROPERTY(QRect normalGeometry READ normalGeometry) |
| 109 | Q_PROPERTY(int x READ x) |
| 110 | Q_PROPERTY(int y READ y) |
| 111 | Q_PROPERTY(QPoint pos READ pos WRITE move DESIGNABLE false STORED false) |
| 112 | Q_PROPERTY(QSize frameSize READ frameSize) |
| 113 | Q_PROPERTY(QSize size READ size WRITE resize DESIGNABLE false STORED false) |
| 114 | Q_PROPERTY(int width READ width) |
| 115 | Q_PROPERTY(int height READ height) |
| 116 | Q_PROPERTY(QRect rect READ rect) |
| 117 | Q_PROPERTY(QRect childrenRect READ childrenRect) |
| 118 | Q_PROPERTY(QRegion childrenRegion READ childrenRegion) |
| 119 | Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy) |
| 120 | Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize) |
| 121 | Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize) |
| 122 | Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth STORED false |
| 123 | DESIGNABLE false) |
| 124 | Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight STORED false |
| 125 | DESIGNABLE false) |
| 126 | Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth STORED false |
| 127 | DESIGNABLE false) |
| 128 | Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight STORED false |
| 129 | DESIGNABLE false) |
| 130 | Q_PROPERTY(QSize sizeIncrement READ sizeIncrement WRITE setSizeIncrement) |
| 131 | Q_PROPERTY(QSize baseSize READ baseSize WRITE setBaseSize) |
| 132 | Q_PROPERTY(QPalette palette READ palette WRITE setPalette) |
| 133 | Q_PROPERTY(QFont font READ font WRITE setFont) |
| 134 | #ifndef QT_NO_CURSOR |
| 135 | Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor) |
| 136 | #endif |
| 137 | Q_PROPERTY(bool mouseTracking READ hasMouseTracking WRITE setMouseTracking) |
| 138 | Q_PROPERTY(bool tabletTracking READ hasTabletTracking WRITE setTabletTracking) |
| 139 | Q_PROPERTY(bool isActiveWindow READ isActiveWindow) |
| 140 | Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy) |
| 141 | Q_PROPERTY(bool focus READ hasFocus) |
| 142 | Q_PROPERTY(Qt::ContextMenuPolicy contextMenuPolicy READ contextMenuPolicy WRITE setContextMenuPolicy) |
| 143 | Q_PROPERTY(bool updatesEnabled READ updatesEnabled WRITE setUpdatesEnabled DESIGNABLE false) |
| 144 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible DESIGNABLE false) |
| 145 | Q_PROPERTY(bool minimized READ isMinimized) |
| 146 | Q_PROPERTY(bool maximized READ isMaximized) |
| 147 | Q_PROPERTY(bool fullScreen READ isFullScreen) |
| 148 | Q_PROPERTY(QSize sizeHint READ sizeHint) |
| 149 | Q_PROPERTY(QSize minimumSizeHint READ minimumSizeHint) |
| 150 | Q_PROPERTY(bool acceptDrops READ acceptDrops WRITE setAcceptDrops) |
| 151 | Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle NOTIFY windowTitleChanged) |
| 152 | Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon NOTIFY windowIconChanged) |
| 153 | Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText NOTIFY windowIconTextChanged) // deprecated |
| 154 | Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity) |
| 155 | Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified) |
| 156 | #if QT_CONFIG(tooltip) |
| 157 | Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip) |
| 158 | Q_PROPERTY(int toolTipDuration READ toolTipDuration WRITE setToolTipDuration) |
| 159 | #endif |
| 160 | #if QT_CONFIG(statustip) |
| 161 | Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip) |
| 162 | #endif |
| 163 | #if QT_CONFIG(whatsthis) |
| 164 | Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis) |
| 165 | #endif |
| 166 | #if QT_CONFIG(accessibility) |
| 167 | Q_PROPERTY(QString accessibleName READ accessibleName WRITE setAccessibleName) |
| 168 | Q_PROPERTY(QString accessibleDescription READ accessibleDescription WRITE setAccessibleDescription) |
| 169 | #endif |
| 170 | Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection) |
| 171 | QDOC_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags) |
| 172 | Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground) |
| 173 | #ifndef QT_NO_STYLE_STYLESHEET |
| 174 | Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet) |
| 175 | #endif |
| 176 | Q_PROPERTY(QLocale locale READ locale WRITE setLocale RESET unsetLocale) |
| 177 | Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath) |
| 178 | Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints) |
| 179 | |
| 180 | #if QT_CONFIG(action) |
| 181 | #if 0 |
| 182 | // ### TODO: make this work (requires SFINAE-friendly connect()) |
| 183 | template <typename...Args> |
| 184 | using compatible_action_slot_args = std::void_t< |
| 185 | decltype(QObject::connect(std::declval<QAction*>(), &QAction::triggered, |
| 186 | std::declval<Args>()...)) |
| 187 | >; |
| 188 | #else |
| 189 | // good-enough compromise for now |
| 190 | template <typename...Args> |
| 191 | using compatible_action_slot_args = std::enable_if_t<std::conjunction_v< |
| 192 | #if QT_CONFIG(shortcut) |
| 193 | std::disjunction< |
| 194 | std::is_same<Args, Qt::ConnectionType>, |
| 195 | std::negation<std::is_convertible<Args, QKeySequence>> |
| 196 | >..., |
| 197 | #endif |
| 198 | std::negation<std::is_convertible<Args, QIcon>>..., |
| 199 | std::negation<std::is_convertible<Args, const char*>>..., |
| 200 | std::negation<std::is_convertible<Args, QString>>... |
| 201 | >>; |
| 202 | #endif |
| 203 | #endif // QT_CONFIG(action) |
| 204 | |
| 205 | public: |
| 206 | enum RenderFlag { |
| 207 | DrawWindowBackground = 0x1, |
| 208 | DrawChildren = 0x2, |
| 209 | IgnoreMask = 0x4 |
| 210 | }; |
| 211 | Q_DECLARE_FLAGS(RenderFlags, RenderFlag) |
| 212 | |
| 213 | explicit QWidget(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); |
| 214 | ~QWidget(); |
| 215 | |
| 216 | int devType() const override; |
| 217 | |
| 218 | WId winId() const; |
| 219 | void createWinId(); // internal, going away |
| 220 | inline WId internalWinId() const { return data->winid; } |
| 221 | WId effectiveWinId() const; |
| 222 | |
| 223 | // GUI style setting |
| 224 | QStyle *style() const; |
| 225 | void setStyle(QStyle *); |
| 226 | // Widget types and states |
| 227 | |
| 228 | #if QT_DEPRECATED_SINCE(6, 1) |
| 229 | QT_DEPRECATED_VERSION_X_6_1("Use isWindow()" ) |
| 230 | bool isTopLevel() const; |
| 231 | #endif |
| 232 | bool isWindow() const; |
| 233 | |
| 234 | bool isModal() const; |
| 235 | Qt::WindowModality windowModality() const; |
| 236 | void setWindowModality(Qt::WindowModality windowModality); |
| 237 | |
| 238 | bool isEnabled() const; |
| 239 | bool isEnabledTo(const QWidget *) const; |
| 240 | |
| 241 | public Q_SLOTS: |
| 242 | void setEnabled(bool); |
| 243 | void setDisabled(bool); |
| 244 | void setWindowModified(bool); |
| 245 | |
| 246 | // Widget coordinates |
| 247 | |
| 248 | public: |
| 249 | QRect frameGeometry() const; |
| 250 | const QRect &geometry() const; |
| 251 | QRect normalGeometry() const; |
| 252 | |
| 253 | int x() const; |
| 254 | int y() const; |
| 255 | QPoint pos() const; |
| 256 | QSize frameSize() const; |
| 257 | QSize size() const; |
| 258 | inline int width() const; |
| 259 | inline int height() const; |
| 260 | inline QRect rect() const; |
| 261 | QRect childrenRect() const; |
| 262 | QRegion childrenRegion() const; |
| 263 | |
| 264 | QSize minimumSize() const; |
| 265 | QSize maximumSize() const; |
| 266 | int minimumWidth() const; |
| 267 | int minimumHeight() const; |
| 268 | int maximumWidth() const; |
| 269 | int maximumHeight() const; |
| 270 | void setMinimumSize(const QSize &); |
| 271 | void setMinimumSize(int minw, int minh); |
| 272 | void setMaximumSize(const QSize &); |
| 273 | void setMaximumSize(int maxw, int maxh); |
| 274 | void setMinimumWidth(int minw); |
| 275 | void setMinimumHeight(int minh); |
| 276 | void setMaximumWidth(int maxw); |
| 277 | void setMaximumHeight(int maxh); |
| 278 | |
| 279 | #ifdef Q_QDOC |
| 280 | void setupUi(QWidget *widget); |
| 281 | #endif |
| 282 | |
| 283 | QSize sizeIncrement() const; |
| 284 | void setSizeIncrement(const QSize &); |
| 285 | void setSizeIncrement(int w, int h); |
| 286 | QSize baseSize() const; |
| 287 | void setBaseSize(const QSize &); |
| 288 | void setBaseSize(int basew, int baseh); |
| 289 | |
| 290 | void setFixedSize(const QSize &); |
| 291 | void setFixedSize(int w, int h); |
| 292 | void setFixedWidth(int w); |
| 293 | void setFixedHeight(int h); |
| 294 | |
| 295 | // Widget coordinate mapping |
| 296 | |
| 297 | QPointF mapToGlobal(const QPointF &) const; |
| 298 | QPoint mapToGlobal(const QPoint &) const; |
| 299 | QPointF mapFromGlobal(const QPointF &) const; |
| 300 | QPoint mapFromGlobal(const QPoint &) const; |
| 301 | QPointF mapToParent(const QPointF &) const; |
| 302 | QPoint mapToParent(const QPoint &) const; |
| 303 | QPointF mapFromParent(const QPointF &) const; |
| 304 | QPoint mapFromParent(const QPoint &) const; |
| 305 | QPointF mapTo(const QWidget *, const QPointF &) const; |
| 306 | QPoint mapTo(const QWidget *, const QPoint &) const; |
| 307 | QPointF mapFrom(const QWidget *, const QPointF &) const; |
| 308 | QPoint mapFrom(const QWidget *, const QPoint &) const; |
| 309 | |
| 310 | QWidget *window() const; |
| 311 | QWidget *nativeParentWidget() const; |
| 312 | inline QWidget *topLevelWidget() const { return window(); } |
| 313 | |
| 314 | // Widget appearance functions |
| 315 | const QPalette &palette() const; |
| 316 | void setPalette(const QPalette &); |
| 317 | |
| 318 | void setBackgroundRole(QPalette::ColorRole); |
| 319 | QPalette::ColorRole backgroundRole() const; |
| 320 | |
| 321 | void setForegroundRole(QPalette::ColorRole); |
| 322 | QPalette::ColorRole foregroundRole() const; |
| 323 | |
| 324 | const QFont &font() const; |
| 325 | void setFont(const QFont &); |
| 326 | QFontMetrics fontMetrics() const; |
| 327 | QFontInfo fontInfo() const; |
| 328 | |
| 329 | #ifndef QT_NO_CURSOR |
| 330 | QCursor cursor() const; |
| 331 | void setCursor(const QCursor &); |
| 332 | void unsetCursor(); |
| 333 | #endif |
| 334 | |
| 335 | void setMouseTracking(bool enable); |
| 336 | bool hasMouseTracking() const; |
| 337 | bool underMouse() const; |
| 338 | |
| 339 | void setTabletTracking(bool enable); |
| 340 | bool hasTabletTracking() const; |
| 341 | |
| 342 | void setMask(const QBitmap &); |
| 343 | void setMask(const QRegion &); |
| 344 | QRegion mask() const; |
| 345 | void clearMask(); |
| 346 | |
| 347 | void render(QPaintDevice *target, const QPoint &targetOffset = QPoint(), |
| 348 | const QRegion &sourceRegion = QRegion(), |
| 349 | RenderFlags renderFlags = RenderFlags(DrawWindowBackground | DrawChildren)); |
| 350 | |
| 351 | void render(QPainter *painter, const QPoint &targetOffset = QPoint(), |
| 352 | const QRegion &sourceRegion = QRegion(), |
| 353 | RenderFlags renderFlags = RenderFlags(DrawWindowBackground | DrawChildren)); |
| 354 | |
| 355 | Q_INVOKABLE QPixmap grab(const QRect &rectangle = QRect(QPoint(0, 0), QSize(-1, -1))); |
| 356 | |
| 357 | #if QT_CONFIG(graphicseffect) |
| 358 | QGraphicsEffect *graphicsEffect() const; |
| 359 | void setGraphicsEffect(QGraphicsEffect *effect); |
| 360 | #endif // QT_CONFIG(graphicseffect) |
| 361 | |
| 362 | #ifndef QT_NO_GESTURES |
| 363 | void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags()); |
| 364 | void ungrabGesture(Qt::GestureType type); |
| 365 | #endif |
| 366 | |
| 367 | public Q_SLOTS: |
| 368 | void setWindowTitle(const QString &); |
| 369 | #ifndef QT_NO_STYLE_STYLESHEET |
| 370 | void setStyleSheet(const QString& styleSheet); |
| 371 | #endif |
| 372 | public: |
| 373 | #ifndef QT_NO_STYLE_STYLESHEET |
| 374 | QString styleSheet() const; |
| 375 | #endif |
| 376 | QString windowTitle() const; |
| 377 | void setWindowIcon(const QIcon &icon); |
| 378 | QIcon windowIcon() const; |
| 379 | void setWindowIconText(const QString &); |
| 380 | QString windowIconText() const; |
| 381 | void setWindowRole(const QString &); |
| 382 | QString windowRole() const; |
| 383 | void setWindowFilePath(const QString &filePath); |
| 384 | QString windowFilePath() const; |
| 385 | |
| 386 | void setWindowOpacity(qreal level); |
| 387 | qreal windowOpacity() const; |
| 388 | |
| 389 | bool isWindowModified() const; |
| 390 | #if QT_CONFIG(tooltip) |
| 391 | void setToolTip(const QString &); |
| 392 | QString toolTip() const; |
| 393 | void setToolTipDuration(int msec); |
| 394 | int toolTipDuration() const; |
| 395 | #endif |
| 396 | #if QT_CONFIG(statustip) |
| 397 | void setStatusTip(const QString &); |
| 398 | QString statusTip() const; |
| 399 | #endif |
| 400 | #if QT_CONFIG(whatsthis) |
| 401 | void setWhatsThis(const QString &); |
| 402 | QString whatsThis() const; |
| 403 | #endif |
| 404 | #if QT_CONFIG(accessibility) |
| 405 | QString accessibleName() const; |
| 406 | void setAccessibleName(const QString &name); |
| 407 | QString accessibleDescription() const; |
| 408 | void setAccessibleDescription(const QString &description); |
| 409 | #endif |
| 410 | |
| 411 | void setLayoutDirection(Qt::LayoutDirection direction); |
| 412 | Qt::LayoutDirection layoutDirection() const; |
| 413 | void unsetLayoutDirection(); |
| 414 | |
| 415 | void setLocale(const QLocale &locale); |
| 416 | QLocale locale() const; |
| 417 | void unsetLocale(); |
| 418 | |
| 419 | inline bool isRightToLeft() const { return layoutDirection() == Qt::RightToLeft; } |
| 420 | inline bool isLeftToRight() const { return layoutDirection() == Qt::LeftToRight; } |
| 421 | |
| 422 | public Q_SLOTS: |
| 423 | inline void setFocus() { setFocus(Qt::OtherFocusReason); } |
| 424 | |
| 425 | public: |
| 426 | bool isActiveWindow() const; |
| 427 | void activateWindow(); |
| 428 | void clearFocus(); |
| 429 | |
| 430 | void setFocus(Qt::FocusReason reason); |
| 431 | Qt::FocusPolicy focusPolicy() const; |
| 432 | void setFocusPolicy(Qt::FocusPolicy policy); |
| 433 | bool hasFocus() const; |
| 434 | static void setTabOrder(QWidget *, QWidget *); |
| 435 | static void setTabOrder(std::initializer_list<QWidget *> widgets); |
| 436 | void setFocusProxy(QWidget *); |
| 437 | QWidget *focusProxy() const; |
| 438 | Qt::ContextMenuPolicy () const; |
| 439 | void (Qt::ContextMenuPolicy policy); |
| 440 | |
| 441 | // Grab functions |
| 442 | void grabMouse(); |
| 443 | #ifndef QT_NO_CURSOR |
| 444 | void grabMouse(const QCursor &); |
| 445 | #endif |
| 446 | void releaseMouse(); |
| 447 | void grabKeyboard(); |
| 448 | void releaseKeyboard(); |
| 449 | #ifndef QT_NO_SHORTCUT |
| 450 | int grabShortcut(const QKeySequence &key, Qt::ShortcutContext context = Qt::WindowShortcut); |
| 451 | void releaseShortcut(int id); |
| 452 | void setShortcutEnabled(int id, bool enable = true); |
| 453 | void setShortcutAutoRepeat(int id, bool enable = true); |
| 454 | #endif |
| 455 | static QWidget *mouseGrabber(); |
| 456 | static QWidget *keyboardGrabber(); |
| 457 | |
| 458 | // Update/refresh functions |
| 459 | inline bool updatesEnabled() const; |
| 460 | void setUpdatesEnabled(bool enable); |
| 461 | |
| 462 | #if QT_CONFIG(graphicsview) |
| 463 | QGraphicsProxyWidget *graphicsProxyWidget() const; |
| 464 | #endif |
| 465 | |
| 466 | public Q_SLOTS: |
| 467 | void update(); |
| 468 | void repaint(); |
| 469 | |
| 470 | public: |
| 471 | inline void update(int x, int y, int w, int h); |
| 472 | void update(const QRect&); |
| 473 | void update(const QRegion&); |
| 474 | |
| 475 | void repaint(int x, int y, int w, int h); |
| 476 | void repaint(const QRect &); |
| 477 | void repaint(const QRegion &); |
| 478 | |
| 479 | public Q_SLOTS: |
| 480 | // Widget management functions |
| 481 | |
| 482 | virtual void setVisible(bool visible); |
| 483 | void setHidden(bool hidden); |
| 484 | void show(); |
| 485 | void hide(); |
| 486 | |
| 487 | void showMinimized(); |
| 488 | void showMaximized(); |
| 489 | void showFullScreen(); |
| 490 | void showNormal(); |
| 491 | |
| 492 | bool close(); |
| 493 | void raise(); |
| 494 | void lower(); |
| 495 | |
| 496 | public: |
| 497 | void stackUnder(QWidget*); |
| 498 | void move(int x, int y); |
| 499 | void move(const QPoint &); |
| 500 | void resize(int w, int h); |
| 501 | void resize(const QSize &); |
| 502 | inline void setGeometry(int x, int y, int w, int h); |
| 503 | void setGeometry(const QRect &); |
| 504 | QByteArray saveGeometry() const; |
| 505 | bool restoreGeometry(const QByteArray &geometry); |
| 506 | void adjustSize(); |
| 507 | bool isVisible() const; |
| 508 | bool isVisibleTo(const QWidget *) const; |
| 509 | inline bool isHidden() const; |
| 510 | |
| 511 | bool isMinimized() const; |
| 512 | bool isMaximized() const; |
| 513 | bool isFullScreen() const; |
| 514 | |
| 515 | Qt::WindowStates windowState() const; |
| 516 | void setWindowState(Qt::WindowStates state); |
| 517 | void overrideWindowState(Qt::WindowStates state); |
| 518 | |
| 519 | virtual QSize sizeHint() const; |
| 520 | virtual QSize minimumSizeHint() const; |
| 521 | |
| 522 | QSizePolicy sizePolicy() const; |
| 523 | void setSizePolicy(QSizePolicy); |
| 524 | inline void setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical); |
| 525 | virtual int heightForWidth(int) const; |
| 526 | virtual bool hasHeightForWidth() const; |
| 527 | |
| 528 | QRegion visibleRegion() const; |
| 529 | |
| 530 | void setContentsMargins(int left, int top, int right, int bottom); |
| 531 | void setContentsMargins(const QMargins &margins); |
| 532 | QMargins contentsMargins() const; |
| 533 | |
| 534 | QRect contentsRect() const; |
| 535 | |
| 536 | public: |
| 537 | QLayout *layout() const; |
| 538 | void setLayout(QLayout *); |
| 539 | void updateGeometry(); |
| 540 | |
| 541 | void setParent(QWidget *parent); |
| 542 | void setParent(QWidget *parent, Qt::WindowFlags f); |
| 543 | |
| 544 | void scroll(int dx, int dy); |
| 545 | void scroll(int dx, int dy, const QRect&); |
| 546 | |
| 547 | // Misc. functions |
| 548 | |
| 549 | QWidget *focusWidget() const; |
| 550 | QWidget *nextInFocusChain() const; |
| 551 | QWidget *previousInFocusChain() const; |
| 552 | |
| 553 | // drag and drop |
| 554 | bool acceptDrops() const; |
| 555 | void setAcceptDrops(bool on); |
| 556 | |
| 557 | #ifndef QT_NO_ACTION |
| 558 | //actions |
| 559 | void addAction(QAction *action); |
| 560 | void addActions(const QList<QAction*> &actions); |
| 561 | void insertActions(QAction *before, const QList<QAction*> &actions); |
| 562 | void insertAction(QAction *before, QAction *action); |
| 563 | void removeAction(QAction *action); |
| 564 | QList<QAction*> actions() const; |
| 565 | |
| 566 | // convenience action factories |
| 567 | QAction *addAction(const QString &text); |
| 568 | QAction *addAction(const QIcon &icon, const QString &text); |
| 569 | QAction *addAction(const QString &text, const QObject *receiver, |
| 570 | const char *member, Qt::ConnectionType type = Qt::AutoConnection); |
| 571 | QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, |
| 572 | const char *member, Qt::ConnectionType type = Qt::AutoConnection); |
| 573 | template <typename...Args, typename = compatible_action_slot_args<Args...>> |
| 574 | QAction *addAction(const QString &text, Args&&...args) |
| 575 | { |
| 576 | QAction *result = addAction(text); |
| 577 | connect(result, &QAction::triggered, std::forward<Args>(args)...); |
| 578 | return result; |
| 579 | } |
| 580 | template <typename...Args, typename = compatible_action_slot_args<Args...>> |
| 581 | QAction *addAction(const QIcon &icon, const QString &text, Args&&...args) |
| 582 | { |
| 583 | QAction *result = addAction(icon, text); |
| 584 | connect(result, &QAction::triggered, std::forward<Args>(args)...); |
| 585 | return result; |
| 586 | } |
| 587 | |
| 588 | #if QT_CONFIG(shortcut) |
| 589 | QAction *addAction(const QString &text, const QKeySequence &shortcut); |
| 590 | QAction *addAction(const QIcon &icon, const QString &text, const QKeySequence &shortcut); |
| 591 | QAction *addAction(const QString &text, const QKeySequence &shortcut, |
| 592 | const QObject *receiver, const char *member, |
| 593 | Qt::ConnectionType type = Qt::AutoConnection); |
| 594 | QAction *addAction(const QIcon &icon, const QString &text, const QKeySequence &shortcut, |
| 595 | const QObject *receiver, const char *member, |
| 596 | Qt::ConnectionType type = Qt::AutoConnection); |
| 597 | |
| 598 | template <typename...Args, typename = compatible_action_slot_args<Args...>> |
| 599 | QAction *addAction(const QString &text, const QKeySequence &shortcut, Args&&...args) |
| 600 | { |
| 601 | QAction *result = addAction(text, shortcut); |
| 602 | connect(result, &QAction::triggered, std::forward<Args>(args)...); |
| 603 | return result; |
| 604 | } |
| 605 | template <typename...Args, typename = compatible_action_slot_args<Args...>> |
| 606 | QAction *addAction(const QIcon &icon, const QString &text, const QKeySequence &shortcut, Args&&...args) |
| 607 | { |
| 608 | QAction *result = addAction(icon, text, shortcut); |
| 609 | connect(result, &QAction::triggered, std::forward<Args>(args)...); |
| 610 | return result; |
| 611 | } |
| 612 | #endif // QT_CONFIG(shortcut) |
| 613 | #endif // QT_NO_ACTION |
| 614 | |
| 615 | QWidget *parentWidget() const; |
| 616 | |
| 617 | void setWindowFlags(Qt::WindowFlags type); |
| 618 | inline Qt::WindowFlags windowFlags() const; |
| 619 | void setWindowFlag(Qt::WindowType, bool on = true); |
| 620 | void overrideWindowFlags(Qt::WindowFlags type); |
| 621 | |
| 622 | inline Qt::WindowType windowType() const; |
| 623 | |
| 624 | static QWidget *find(WId); |
| 625 | inline QWidget *childAt(int x, int y) const; |
| 626 | QWidget *childAt(const QPoint &p) const; |
| 627 | QWidget *childAt(const QPointF &p) const; |
| 628 | |
| 629 | void setAttribute(Qt::WidgetAttribute, bool on = true); |
| 630 | inline bool testAttribute(Qt::WidgetAttribute) const; |
| 631 | |
| 632 | QPaintEngine *paintEngine() const override; |
| 633 | |
| 634 | void ensurePolished() const; |
| 635 | |
| 636 | bool isAncestorOf(const QWidget *child) const; |
| 637 | |
| 638 | #ifdef QT_KEYPAD_NAVIGATION |
| 639 | bool hasEditFocus() const; |
| 640 | void setEditFocus(bool on); |
| 641 | #endif |
| 642 | |
| 643 | bool autoFillBackground() const; |
| 644 | void setAutoFillBackground(bool enabled); |
| 645 | |
| 646 | QBackingStore *backingStore() const; |
| 647 | |
| 648 | QWindow *windowHandle() const; |
| 649 | QScreen *screen() const; |
| 650 | void setScreen(QScreen *); |
| 651 | |
| 652 | static QWidget *createWindowContainer(QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags()); |
| 653 | |
| 654 | Q_SIGNALS: |
| 655 | void windowTitleChanged(const QString &title); |
| 656 | void windowIconChanged(const QIcon &icon); |
| 657 | void windowIconTextChanged(const QString &iconText); |
| 658 | void (const QPoint &pos); |
| 659 | |
| 660 | protected: |
| 661 | // Event handlers |
| 662 | bool event(QEvent *event) override; |
| 663 | virtual void mousePressEvent(QMouseEvent *event); |
| 664 | virtual void mouseReleaseEvent(QMouseEvent *event); |
| 665 | virtual void mouseDoubleClickEvent(QMouseEvent *event); |
| 666 | virtual void mouseMoveEvent(QMouseEvent *event); |
| 667 | #if QT_CONFIG(wheelevent) |
| 668 | virtual void wheelEvent(QWheelEvent *event); |
| 669 | #endif |
| 670 | virtual void keyPressEvent(QKeyEvent *event); |
| 671 | virtual void keyReleaseEvent(QKeyEvent *event); |
| 672 | virtual void focusInEvent(QFocusEvent *event); |
| 673 | virtual void focusOutEvent(QFocusEvent *event); |
| 674 | virtual void enterEvent(QEnterEvent *event); |
| 675 | virtual void leaveEvent(QEvent *event); |
| 676 | virtual void paintEvent(QPaintEvent *event); |
| 677 | virtual void moveEvent(QMoveEvent *event); |
| 678 | virtual void resizeEvent(QResizeEvent *event); |
| 679 | virtual void closeEvent(QCloseEvent *event); |
| 680 | #ifndef QT_NO_CONTEXTMENU |
| 681 | virtual void (QContextMenuEvent *event); |
| 682 | #endif |
| 683 | #if QT_CONFIG(tabletevent) |
| 684 | virtual void tabletEvent(QTabletEvent *event); |
| 685 | #endif |
| 686 | #ifndef QT_NO_ACTION |
| 687 | virtual void actionEvent(QActionEvent *event); |
| 688 | #endif |
| 689 | |
| 690 | #if QT_CONFIG(draganddrop) |
| 691 | virtual void dragEnterEvent(QDragEnterEvent *event); |
| 692 | virtual void dragMoveEvent(QDragMoveEvent *event); |
| 693 | virtual void dragLeaveEvent(QDragLeaveEvent *event); |
| 694 | virtual void dropEvent(QDropEvent *event); |
| 695 | #endif |
| 696 | |
| 697 | virtual void showEvent(QShowEvent *event); |
| 698 | virtual void hideEvent(QHideEvent *event); |
| 699 | |
| 700 | virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result); |
| 701 | |
| 702 | // Misc. protected functions |
| 703 | virtual void changeEvent(QEvent *); |
| 704 | |
| 705 | int metric(PaintDeviceMetric) const override; |
| 706 | void initPainter(QPainter *painter) const override; |
| 707 | QPaintDevice *redirected(QPoint *offset) const override; |
| 708 | QPainter *sharedPainter() const override; |
| 709 | |
| 710 | virtual void inputMethodEvent(QInputMethodEvent *); |
| 711 | public: |
| 712 | virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const; |
| 713 | |
| 714 | Qt::InputMethodHints inputMethodHints() const; |
| 715 | void setInputMethodHints(Qt::InputMethodHints hints); |
| 716 | |
| 717 | protected Q_SLOTS: |
| 718 | void updateMicroFocus(Qt::InputMethodQuery query = Qt::ImQueryAll); |
| 719 | protected: |
| 720 | |
| 721 | void create(WId = 0, bool initializeWindow = true, |
| 722 | bool destroyOldWindow = true); |
| 723 | void destroy(bool destroyWindow = true, |
| 724 | bool destroySubWindows = true); |
| 725 | |
| 726 | friend class QDataWidgetMapperPrivate; // for access to focusNextPrevChild |
| 727 | virtual bool focusNextPrevChild(bool next); |
| 728 | inline bool focusNextChild() { return focusNextPrevChild(next: true); } |
| 729 | inline bool focusPreviousChild() { return focusNextPrevChild(next: false); } |
| 730 | |
| 731 | protected: |
| 732 | QWidget(QWidgetPrivate &d, QWidget* parent, Qt::WindowFlags f); |
| 733 | private: |
| 734 | void setBackingStore(QBackingStore *store); |
| 735 | |
| 736 | bool testAttribute_helper(Qt::WidgetAttribute) const; |
| 737 | |
| 738 | QLayout *takeLayout(); |
| 739 | |
| 740 | friend class QBackingStoreDevice; |
| 741 | friend class QWidgetRepaintManager; |
| 742 | friend class QApplication; |
| 743 | friend class QApplicationPrivate; |
| 744 | friend class QGuiApplication; |
| 745 | friend class QGuiApplicationPrivate; |
| 746 | friend class QBaseApplication; |
| 747 | friend class QPainter; |
| 748 | friend class QPainterPrivate; |
| 749 | friend class QPixmap; // for QPixmap::fill() |
| 750 | friend class QFontMetrics; |
| 751 | friend class QFontInfo; |
| 752 | friend class QLayout; |
| 753 | friend class QWidgetItem; |
| 754 | friend class QWidgetItemV2; |
| 755 | friend class QX11PaintEngine; |
| 756 | friend class QWin32PaintEngine; |
| 757 | friend class QShortcutPrivate; |
| 758 | friend class QWindowSurface; |
| 759 | friend class QGraphicsProxyWidget; |
| 760 | friend class QGraphicsProxyWidgetPrivate; |
| 761 | friend class QStyleSheetStyle; |
| 762 | friend struct QWidgetExceptionCleaner; |
| 763 | friend class QWidgetWindow; |
| 764 | friend class QAccessibleWidget; |
| 765 | friend class QAccessibleTable; |
| 766 | friend class QAccessibleTabButton; |
| 767 | #ifndef QT_NO_GESTURES |
| 768 | friend class QGestureManager; |
| 769 | friend class QWinNativePanGestureRecognizer; |
| 770 | #endif // QT_NO_GESTURES |
| 771 | friend class QWidgetEffectSourcePrivate; |
| 772 | |
| 773 | friend Q_WIDGETS_EXPORT QWidgetData *qt_qwidget_data(QWidget *widget); |
| 774 | friend Q_WIDGETS_EXPORT QWidgetPrivate *qt_widget_private(QWidget *widget); |
| 775 | |
| 776 | private: |
| 777 | Q_DISABLE_COPY(QWidget) |
| 778 | Q_PRIVATE_SLOT(d_func(), void _q_showIfNotHidden()) |
| 779 | Q_PRIVATE_SLOT(d_func(), QWindow *_q_closestWindowHandle()) |
| 780 | |
| 781 | QWidgetData *data; |
| 782 | }; |
| 783 | |
| 784 | Q_DECLARE_OPERATORS_FOR_FLAGS(QWidget::RenderFlags) |
| 785 | |
| 786 | #ifndef Q_QDOC |
| 787 | template <> inline QWidget *qobject_cast<QWidget*>(QObject *o) |
| 788 | { |
| 789 | if (!o || !o->isWidgetType()) return nullptr; |
| 790 | return static_cast<QWidget*>(o); |
| 791 | } |
| 792 | template <> inline const QWidget *qobject_cast<const QWidget*>(const QObject *o) |
| 793 | { |
| 794 | if (!o || !o->isWidgetType()) return nullptr; |
| 795 | return static_cast<const QWidget*>(o); |
| 796 | } |
| 797 | #endif // !Q_QDOC |
| 798 | |
| 799 | inline QWidget *QWidget::childAt(int ax, int ay) const |
| 800 | { return childAt(p: QPointF(ax, ay)); } |
| 801 | |
| 802 | inline Qt::WindowType QWidget::windowType() const |
| 803 | { return static_cast<Qt::WindowType>((data->window_flags & Qt::WindowType_Mask).toInt()); } |
| 804 | inline Qt::WindowFlags QWidget::windowFlags() const |
| 805 | { return data->window_flags; } |
| 806 | |
| 807 | #if QT_DEPRECATED_SINCE(6, 1) |
| 808 | inline bool QWidget::isTopLevel() const |
| 809 | { return bool(windowType() & Qt::Window); } |
| 810 | #endif |
| 811 | |
| 812 | inline bool QWidget::isWindow() const |
| 813 | { return bool(windowType() & Qt::Window); } |
| 814 | |
| 815 | inline bool QWidget::isEnabled() const |
| 816 | { return !testAttribute(Qt::WA_Disabled); } |
| 817 | |
| 818 | inline bool QWidget::isModal() const |
| 819 | { return data->window_modality != Qt::NonModal; } |
| 820 | |
| 821 | inline int QWidget::minimumWidth() const |
| 822 | { return minimumSize().width(); } |
| 823 | |
| 824 | inline int QWidget::minimumHeight() const |
| 825 | { return minimumSize().height(); } |
| 826 | |
| 827 | inline int QWidget::maximumWidth() const |
| 828 | { return maximumSize().width(); } |
| 829 | |
| 830 | inline int QWidget::maximumHeight() const |
| 831 | { return maximumSize().height(); } |
| 832 | |
| 833 | inline void QWidget::setMinimumSize(const QSize &s) |
| 834 | { setMinimumSize(minw: s.width(),minh: s.height()); } |
| 835 | |
| 836 | inline void QWidget::setMaximumSize(const QSize &s) |
| 837 | { setMaximumSize(maxw: s.width(),maxh: s.height()); } |
| 838 | |
| 839 | inline void QWidget::setSizeIncrement(const QSize &s) |
| 840 | { setSizeIncrement(w: s.width(),h: s.height()); } |
| 841 | |
| 842 | inline void QWidget::setBaseSize(const QSize &s) |
| 843 | { setBaseSize(basew: s.width(),baseh: s.height()); } |
| 844 | |
| 845 | inline const QFont &QWidget::font() const |
| 846 | { return data->fnt; } |
| 847 | |
| 848 | inline QFontMetrics QWidget::fontMetrics() const |
| 849 | { return QFontMetrics(data->fnt); } |
| 850 | |
| 851 | inline QFontInfo QWidget::fontInfo() const |
| 852 | { return QFontInfo(data->fnt); } |
| 853 | |
| 854 | inline void QWidget::setMouseTracking(bool enable) |
| 855 | { setAttribute(Qt::WA_MouseTracking, on: enable); } |
| 856 | |
| 857 | inline bool QWidget::hasMouseTracking() const |
| 858 | { return testAttribute(Qt::WA_MouseTracking); } |
| 859 | |
| 860 | inline bool QWidget::underMouse() const |
| 861 | { return testAttribute(Qt::WA_UnderMouse); } |
| 862 | |
| 863 | inline void QWidget::setTabletTracking(bool enable) |
| 864 | { setAttribute(Qt::WA_TabletTracking, on: enable); } |
| 865 | |
| 866 | inline bool QWidget::hasTabletTracking() const |
| 867 | { return testAttribute(Qt::WA_TabletTracking); } |
| 868 | |
| 869 | inline bool QWidget::updatesEnabled() const |
| 870 | { return !testAttribute(Qt::WA_UpdatesDisabled); } |
| 871 | |
| 872 | inline void QWidget::update(int ax, int ay, int aw, int ah) |
| 873 | { update(QRect(ax, ay, aw, ah)); } |
| 874 | |
| 875 | inline bool QWidget::isVisible() const |
| 876 | { return testAttribute(Qt::WA_WState_Visible); } |
| 877 | |
| 878 | inline bool QWidget::isHidden() const |
| 879 | { return testAttribute(Qt::WA_WState_Hidden); } |
| 880 | |
| 881 | inline void QWidget::move(int ax, int ay) |
| 882 | { move(QPoint(ax, ay)); } |
| 883 | |
| 884 | inline void QWidget::resize(int w, int h) |
| 885 | { resize(QSize(w, h)); } |
| 886 | |
| 887 | inline void QWidget::setGeometry(int ax, int ay, int aw, int ah) |
| 888 | { setGeometry(QRect(ax, ay, aw, ah)); } |
| 889 | |
| 890 | inline QRect QWidget::rect() const |
| 891 | { return QRect(0,0,data->crect.width(),data->crect.height()); } |
| 892 | |
| 893 | inline const QRect &QWidget::geometry() const |
| 894 | { return data->crect; } |
| 895 | |
| 896 | inline QSize QWidget::size() const |
| 897 | { return data->crect.size(); } |
| 898 | |
| 899 | inline int QWidget::width() const |
| 900 | { return data->crect.width(); } |
| 901 | |
| 902 | inline int QWidget::height() const |
| 903 | { return data->crect.height(); } |
| 904 | |
| 905 | inline QWidget *QWidget::parentWidget() const |
| 906 | { return static_cast<QWidget *>(QObject::parent()); } |
| 907 | |
| 908 | inline void QWidget::setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver) |
| 909 | { setSizePolicy(QSizePolicy(hor, ver)); } |
| 910 | |
| 911 | inline bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const |
| 912 | { |
| 913 | if (attribute < int(8*sizeof(uint))) |
| 914 | return data->widget_attributes & (1<<attribute); |
| 915 | return testAttribute_helper(attribute); |
| 916 | } |
| 917 | |
| 918 | #define QWIDGETSIZE_MAX ((1<<24)-1) |
| 919 | |
| 920 | #ifndef QT_NO_DEBUG_STREAM |
| 921 | Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QWidget *); |
| 922 | #endif |
| 923 | |
| 924 | QT_END_NAMESPACE |
| 925 | |
| 926 | #endif // QWIDGET_H |
| 927 | |