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
qwidget_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 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
5#ifndef QWIDGET_P_H
6#define QWIDGET_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
14// file may change from version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19
20
21#include <QtWidgets/private/qtwidgetsglobal_p.h>
22#include "QtWidgets/qwidget.h"
23#if QT_CONFIG(label)
24#include <QtWidgets/qlabel.h>
25#endif
26#include "private/qobject_p.h"
27#include "QtCore/qrect.h"
28#include "QtCore/qlocale.h"
29#include "QtCore/qset.h"
30#include "QtGui/qregion.h"
31#include "QtGui/qinputmethod.h"
32#include "QtGui/qsurfaceformat.h"
33#include "QtGui/qscreen.h"
34#include "QtWidgets/qsizepolicy.h"
35#include "QtWidgets/qstyle.h"
36#include "QtWidgets/qapplication.h"
37#if QT_CONFIG(graphicseffect)
38#include <private/qgraphicseffect_p.h>
39#endif
40#if QT_CONFIG(graphicsview)
41#include "QtWidgets/qgraphicsproxywidget.h"
42#include "QtWidgets/qgraphicsscene.h"
43#include "QtWidgets/qgraphicsview.h"
44#endif
45#include <private/qgesture_p.h>
46#include <qpa/qplatformbackingstore.h>
47#include <QtGui/private/qbackingstorerhisupport_p.h>
48#include <private/qapplication_p.h>
49
50#include <QtCore/qpointer.h>
51
52#include <vector>
53#include <memory>
54
56
57Q_DECLARE_LOGGING_CATEGORY(lcWidgetPainting);
59
60// Extra QWidget data
61// - to minimize memory usage for members that are seldom used.
62// - top-level widgets have extra extra data to reduce cost further
63class QWidgetWindow;
64class QPaintEngine;
65class QPixmap;
66class QWidgetRepaintManager;
67class QGraphicsProxyWidget;
68class QWidgetItemV2;
69
70class QStyle;
71
72// implemented in qshortcut.cpp
73bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context);
74void qSendWindowChangeToTextureChildrenRecursively(QWidget *widget, QEvent::Type eventType);
75
77{
78public:
79 explicit QUpdateLaterEvent(const QRegion& paintRegion)
81 {
82 }
83
84 inline const QRegion &region() const { return m_region; }
85
86protected:
87 friend class QApplication;
88 friend class QApplicationPrivate;
90};
91
92struct QTLWExtra {
93 // *************************** Cross-platform variables *****************************
94
95 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
96 std::unique_ptr<QIcon> icon; // widget icon
98 QBackingStore *backingStore;
101
102 // Implicit pointers (shared_null).
103 QString caption; // widget caption
104 QString iconText; // widget icon text
105 QString role; // widget role
106 QString filePath; // widget file path
107
108 // Other variables.
109 short incw, inch; // size increments
110 short basew, baseh; // base sizes
111 // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
113 QRect normalGeometry; // used by showMin/maximized/FullScreen
114 Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
115 QPointer<QScreen> initialScreen; // Screen when passing a QDesktop[Screen]Widget as parent.
116
118
119 // *************************** Cross-platform bit fields ****************************
120 uint opacity : 8;
122 uint sizeAdjusted : 1;
123 uint embedded : 1;
125};
126
127struct QWExtra {
128 // *************************** Cross-platform variables *****************************
129
130 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
131 void *glContext; // if the widget is hijacked by QGLWindowSurface
132 std::unique_ptr<QTLWExtra> topextra; // only useful for TLWs
133#if QT_CONFIG(graphicsview)
134 QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
135#endif
136#ifndef QT_NO_CURSOR
138#endif
141
142 // Implicit pointers (shared_empty/shared_null).
143 QRegion mask; // widget mask
145
146 // Other variables.
148 qint32 minh; // minimum size
150 qint32 maxh; // maximum size
154
155 // *************************** Cross-platform bit fields ****************************
161 uint hasMask : 1;
163};
164
165/*!
166 \internal
167
168 Returns \c true if \a p or any of its parents enable the
169 Qt::BypassGraphicsProxyWidget window flag. Used in QWidget::show() and
170 QWidget::setParent() to determine whether it's necessary to embed the
171 widget into a QGraphicsProxyWidget or not.
172*/
173static inline bool bypassGraphicsProxyWidget(const QWidget *p)
174{
175 while (p) {
176 if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
177 return true;
178 p = p->parentWidget();
179 }
180 return false;
181}
182
183class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate
184{
185 Q_DECLARE_PUBLIC(QWidget)
186 Q_GADGET
187
188public:
189 // *************************** Cross-platform ***************************************
190 enum DrawWidgetFlag {
191 DrawAsRoot = 0x01,
192 DrawPaintOnScreen = 0x02,
193 DrawRecursive = 0x04,
194 DrawInvisible = 0x08,
195 DontSubtractOpaqueChildren = 0x10,
196 DontDrawOpaqueChildren = 0x20,
197 DontDrawNativeChildren = 0x40,
198 DontSetCompositionMode = 0x80,
199 UseEffectRegionBounds = 0x100
200 };
201 Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag)
202 Q_FLAG(DrawWidgetFlags)
203
204 enum Direction {
205 DirectionNorth = 0x01,
206 DirectionEast = 0x10,
207 DirectionSouth = 0x02,
208 DirectionWest = 0x20
209 };
210 Q_ENUM(Direction)
211
212 // Functions.
213 explicit QWidgetPrivate(decltype(QObjectPrivateVersion) = QObjectPrivateVersion);
214 ~QWidgetPrivate();
215
216 static QWidgetPrivate *get(QWidget *w) { return w->d_func(); }
217 static const QWidgetPrivate *get(const QWidget *w) { return w->d_func(); }
218
219 static void checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry,
220 int frameHeight);
221
222 QWExtra *extraData() const;
223 QTLWExtra *topData() const;
224 QTLWExtra *maybeTopData() const;
225 QPainter *sharedPainter() const;
226 void setSharedPainter(QPainter *painter);
227 QWidgetRepaintManager *maybeRepaintManager() const;
228
229 QRhi *rhi() const;
230
231 enum class WindowHandleMode {
232 Direct,
233 Closest,
234 TopLevel
235 };
236 QWindow *windowHandle(WindowHandleMode mode = WindowHandleMode::Direct) const;
237 QWindow *_q_closestWindowHandle() const; // Private slot in QWidget
238
239 QScreen *associatedScreen() const;
240
241 template <typename T>
242 void repaint(T t);
243
244 template <typename T>
245 void update(T t);
246
247 void init(QWidget *desktopWidget, Qt::WindowFlags f);
248 void create();
249 void createRecursively();
250 void createWinId();
251
252 bool setScreenForPoint(const QPoint &pos);
253 bool setScreen(QScreen *screen);
254
255 void createTLExtra();
256 void createExtra();
257 void deleteExtra();
258 void createSysExtra();
259 void deleteSysExtra();
260 void createTLSysExtra();
261 void deleteTLSysExtra();
262 void updateSystemBackground();
263 void propagatePaletteChange();
264
265 void setPalette_helper(const QPalette &);
266 void resolvePalette();
267 QPalette naturalWidgetPalette(QPalette::ResolveMask inheritedMask) const;
268
269 void setMask_sys(const QRegion &);
270
271 void raise_sys();
272 void lower_sys();
273 void stackUnder_sys(QWidget *);
274
275 QWidget *deepestFocusProxy() const;
276 void setFocus_sys();
277 void updateFocusChild();
278
279 void updateFont(const QFont &);
280 inline void setFont_helper(const QFont &font) {
281 if (directFontResolveMask == font.resolveMask() && data.fnt == font)
282 return;
283 updateFont(font);
284 }
285 QFont localFont() const;
286 void resolveFont();
287 QFont naturalWidgetFont(uint inheritedMask) const;
288
289 void setLayoutDirection_helper(Qt::LayoutDirection);
290 void resolveLayoutDirection();
291
292 void setLocale_helper(const QLocale &l, bool forceUpdate = false);
293 void resolveLocale();
294
295 void setStyle_helper(QStyle *newStyle, bool propagate);
296 void inheritStyle();
297
298 void setUpdatesEnabled_helper(bool );
299
300 bool updateBrushOrigin(QPainter *, const QBrush &brush) const;
301 void paintBackground(QPainter *, const QRegion &, DrawWidgetFlags flags = DrawAsRoot) const;
302 bool isAboutToShow() const;
303 QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
304 void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
305 QWidget::RenderFlags renderFlags);
306 void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
307 QWidget::RenderFlags renderFlags);
308 void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags,
309 QPainter *sharedPainter = nullptr, QWidgetRepaintManager *repaintManager = nullptr);
310 void sendPaintEvent(const QRegion &toBePainted);
311
312
313 void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
314 const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags,
315 QPainter *sharedPainter, QWidgetRepaintManager *repaintManager);
316
317#if QT_CONFIG(graphicsview)
318 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
319#endif
320 bool shouldPaintOnScreen() const;
321 void paintOnScreen(const QRegion &rgn);
322
323 QRect clipRect() const;
324 QRegion clipRegion() const;
325 void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion &region);
326 void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
327 void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = nullptr,
328 bool alsoNonOpaque = false) const;
329 void clipToEffectiveMask(QRegion &region) const;
330 void updateIsOpaque();
331 void setOpaque(bool opaque);
332 void updateIsTranslucent();
333#if QT_CONFIG(graphicseffect)
334 void invalidateGraphicsEffectsRecursively();
335#endif // QT_CONFIG(graphicseffect)
336
337 const QRegion &getOpaqueChildren() const;
338 void setDirtyOpaqueRegion();
339
340 bool close();
341 enum CloseMode {
342 CloseNoEvent,
343 CloseWithEvent,
344 CloseWithSpontaneousEvent
345 };
346 Q_ENUM(CloseMode)
347 bool handleClose(CloseMode mode);
348
349 void setWindowIcon_helper();
350 void setWindowIcon_sys();
351 void setWindowOpacity_sys(qreal opacity);
352 void adjustQuitOnCloseAttribute();
353
354 void scrollChildren(int dx, int dy);
355 void moveRect(const QRect &, int dx, int dy);
356 void scrollRect(const QRect &, int dx, int dy);
357 void invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
358
359 template <class T>
360 void invalidateBackingStore(const T &);
361
362 QRegion overlappedRegion(const QRect &rect, bool breakAfterFirst = false) const;
363 bool isOverlapped(const QRect &rect) const { return !overlappedRegion(rect, true).isEmpty(); }
364 void syncBackingStore();
365 void syncBackingStore(const QRegion &region);
366
367 bool shouldDiscardSyncRequest() const;
368
369 // tells the input method about the widgets transform
370 void updateWidgetTransform(QEvent *event);
371
372 void reparentFocusWidgets(QWidget *oldtlw);
373
374 void setWinId(WId);
375 void showChildren(bool spontaneous);
376 void hideChildren(bool spontaneous);
377 void setParent_sys(QWidget *parent, Qt::WindowFlags);
378 void reparentWidgetWindows(QWidget *parentWithWindow, Qt::WindowFlags windowFlags = {});
379 void reparentWidgetWindowChildren(QWidget *parentWithWindow);
380 void scroll_sys(int dx, int dy);
381 void scroll_sys(int dx, int dy, const QRect &r);
382 void deactivateWidgetCleanup();
383 void setGeometry_sys(int, int, int, int, bool);
384 void fixPosIncludesFrame();
385 void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
386 void activateChildLayoutsRecursively();
387 void show_recursive();
388 void show_helper();
389 void show_sys();
390 void hide_sys();
391 void hide_helper();
392 bool isExplicitlyHidden() const;
393 void _q_showIfNotHidden();
394 virtual void setVisible(bool);
395
396 void setEnabled_helper(bool);
397 static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = nullptr);
398
399 void updateFrameStrut();
400 QRect frameStrut() const;
401
402#ifdef QT_KEYPAD_NAVIGATION
403 static bool navigateToDirection(Direction direction);
404 static QWidget *widgetInNavigationDirection(Direction direction);
405 static bool canKeypadNavigate(Qt::Orientation orientation);
406 static bool inTabWidget(QWidget *widget);
407#endif
408
409 void setWindowIconText_sys(const QString &cap);
410 void setWindowIconText_helper(const QString &cap);
411 void setWindowTitle_sys(const QString &cap);
412 void setWindowFilePath_sys(const QString &filePath);
413
414#ifndef QT_NO_CURSOR
415 void setCursor_sys(const QCursor &cursor);
416 void unsetCursor_sys();
417#endif
418
419 void setWindowTitle_helper(const QString &cap);
420 void setWindowFilePath_helper(const QString &filePath);
421 void setWindowModified_helper();
422 virtual void setWindowFlags(Qt::WindowFlags windowFlags);
423
424 bool setMinimumSize_helper(int &minw, int &minh);
425 bool setMaximumSize_helper(int &maxw, int &maxh);
426 void setConstraints_sys();
427 bool pointInsideRectAndMask(const QPointF &) const;
428 QWidget *childAt_helper(const QPointF &, bool) const;
429 QWidget *childAtRecursiveHelper(const QPointF &p, bool) const;
430 void updateGeometry_helper(bool forceUpdate);
431
432 void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
433 void setLayoutItemMargins(int left, int top, int right, int bottom);
434 void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = nullptr);
435
436 void updateContentsRect();
437 QMargins safeAreaMargins() const;
438
439 // aboutToDestroy() is called just before the contents of
440 // QWidget::destroy() is executed. It's used to signal QWidget
441 // sub-classes that their internals are about to be released.
442 virtual void aboutToDestroy() {}
443
444 inline QWidget *effectiveFocusWidget() {
445 QWidget *w = q_func();
446 while (w->focusProxy())
447 w = w->focusProxy();
448 return w;
449 }
450
451 void setModal_sys();
452
453 // These helper functions return the (available) geometry for the screen
454 // the widget is on, and takes care if this one is embedded in a QGraphicsView.
455 static QWidget *parentGraphicsView(const QWidget *widget)
456 {
457#if QT_CONFIG(graphicsview)
458 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
459 //It's embedded if it has an ancestor
460 if (ancestorProxy) {
461 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != nullptr) {
462 if (!ancestorProxy->scene()->views().empty()) {
463 return ancestorProxy->scene()->views().at(0);
464 }
465 }
466 }
467#else
468 Q_UNUSED(widget);
469#endif
470 return nullptr;
471 }
472
473 static QRect screenGeometry(const QWidget *widget)
474 {
475 return screenGeometry(widget, QPoint(), false);
476 }
477
478 static QRect availableScreenGeometry(const QWidget *widget)
479 {
480 return availableScreenGeometry(widget, QPoint(), false);
481 }
482
483 static QScreen *screen(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
484 {
485 while (QWidget *view = parentGraphicsView(widget))
486 widget = view;
487
488 QScreen *screen = nullptr;
489 if (hasPosition)
490 screen = widget->screen()->virtualSiblingAt(globalPosition);
491 if (!screen)
492 screen = widget->screen();
493
494 return screen;
495 }
496
497 static QRect screenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
498 {
499 return screen(widget, globalPosition, hasPosition)->geometry();
500 }
501
502 static QRect availableScreenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
503 {
504 return screen(widget, globalPosition, hasPosition)->availableGeometry();
505 }
506
507 inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
508 {
509 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
510 redirectDev = replacement;
511 redirectOffset = offset;
512 }
513
514 inline QPaintDevice *redirected(QPoint *offset) const
515 {
516 if (offset)
517 *offset = redirectDev ? redirectOffset : QPoint();
518 return redirectDev;
519 }
520
521 inline void restoreRedirected()
522 { redirectDev = nullptr; }
523
524 inline void enforceNativeChildren()
525 {
526 if (!extra)
527 createExtra();
528
529 if (extra->nativeChildrenForced)
530 return;
531 extra->nativeChildrenForced = 1;
532
533 for (int i = 0; i < children.size(); ++i) {
534 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
535 child->setAttribute(Qt::WA_NativeWindow);
536 }
537 }
538
539 inline bool nativeChildrenForced() const
540 {
541 return extra ? extra->nativeChildrenForced : false;
542 }
543
544 inline QRect effectiveRectFor(const QRegion &region) const
545 {
546 return effectiveRectFor(region.boundingRect());
547 }
548
549 inline QRect effectiveRectFor(const QRect &rect) const
550 {
551#if QT_CONFIG(graphicseffect)
552 if (graphicsEffect && graphicsEffect->isEnabled())
553 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
554#endif // QT_CONFIG(graphicseffect)
555 return rect;
556 }
557
558 QSize adjustedSize() const;
559
560 inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
561 {
562 if (button == Qt::LeftButton)
563 handleSoftwareInputPanel(clickCausedFocus);
564 }
565
566 inline void handleSoftwareInputPanel(bool clickCausedFocus = false)
567 {
568 Q_Q(QWidget);
569 if (qApp->autoSipEnabled()) {
570 QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
571 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel, nullptr, q));
572 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
573 QGuiApplication::inputMethod()->show();
574 }
575 }
576 }
577
578 void setWSGeometry();
579
580 inline QPoint mapToWS(const QPoint &p) const
581 { return p - data.wrect.topLeft(); }
582
583 inline QPoint mapFromWS(const QPoint &p) const
584 { return p + data.wrect.topLeft(); }
585
586 inline QRect mapToWS(const QRect &r) const
587 { return r.translated(-data.wrect.topLeft()); }
588
589 inline QRect mapFromWS(const QRect &r) const
590 { return r.translated(data.wrect.topLeft()); }
591
592 virtual QObject *focusObject();
593
594 virtual QPlatformBackingStoreRhiConfig rhiConfig() const { return {}; }
595
596 // Note that textureRight may be null, as it's only used in stereoscopic rendering
597 struct TextureData {
598 QRhiTexture *textureLeft = nullptr;
599 QRhiTexture *textureRight = nullptr;
600 };
601
602 virtual TextureData texture() const { return {}; }
603 virtual QPlatformTextureList::Flags textureListFlags() {
604 Q_Q(QWidget);
605 return q->testAttribute(Qt::WA_AlwaysStackOnTop)
606 ? QPlatformTextureList::StacksOnTop
607 : QPlatformTextureList::Flags();
608 }
609 virtual QImage grabFramebuffer() { return QImage(); }
610 virtual void beginBackingStorePainting() { }
611 virtual void endBackingStorePainting() { }
612 virtual void beginCompose() { }
613 virtual void endCompose() { }
614 void setRenderToTexture() { renderToTexture = true; setTextureChildSeen(); }
615 void setTextureChildSeen()
616 {
617 Q_Q(QWidget);
618 if (textureChildSeen)
619 return;
620 textureChildSeen = 1;
621
622 if (!q->isWindow()) {
623 QWidget *parent = q->parentWidget();
624 if (parent)
625 get(parent)->setTextureChildSeen();
626 }
627 }
628 static void sendComposeStatus(QWidget *w, bool end);
629 // Called on setViewport().
630 virtual void initializeViewportFramebuffer() { }
631 // When using a QOpenGLWidget as viewport with QAbstractScrollArea, resize events are
632 // filtered away from the widget. This is fine for QGLWidget but bad for QOpenGLWidget
633 // since the fbo must be resized. We need an alternative way to notify.
634 virtual void resizeViewportFramebuffer() { }
635 // Called after each paint event.
636 virtual void resolveSamples() { }
637
638 // These two are used in QGraphicsView for supporting stereoscopic rendering with a
639 // QOpenGLWidget viewport.
640 virtual bool isStereoEnabled() { return false; } // Called in QGraphicsView::setupViewport
641 virtual bool toggleStereoTargetBuffer() { return false; } // Called in QGraphicsView::paintEvent
642
643 static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent);
644
645 std::string flagsForDumping() const override;
646
647 QWidget *closestParentWidgetWithWindowHandle() const;
648
649 // Variables.
650 // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
651 std::unique_ptr<QWExtra> extra;
652 QWidget *focus_next;
653 QWidget *focus_prev;
654 QWidget *focus_child;
655 QLayout *layout;
656 QRegion *needsFlush;
657 QPaintDevice *redirectDev;
658 QWidgetItemV2 *widgetItem;
659 QPaintEngine *extraPaintEngine;
660 mutable const QMetaObject *polished;
661 QGraphicsEffect *graphicsEffect;
662#if QT_CONFIG(label)
663 // labels for which this widget is the buddy widget
664 QVarLengthArray<QLabel *, 1> labels;
665#endif
666 // All widgets are added into the allWidgets set. Once
667 // they receive a window id they are also added to the mapper.
668 // This should just ensure that all widgets are deleted by QApplication
669 static QWidgetMapper *mapper;
670 static QWidgetSet *allWidgets;
671#if !defined(QT_NO_IM)
672 Qt::InputMethodHints imHints;
673#endif
674#ifdef QT_KEYPAD_NAVIGATION
675 static QPointer<QWidget> editingWidget;
676#endif
677
678 // Implicit pointers (shared_null/shared_empty).
679 QRegion opaqueChildren;
680 QRegion dirty;
681#if QT_CONFIG(tooltip)
682 QString toolTip;
683 int toolTipDuration;
684#endif
685#if QT_CONFIG(statustip)
686 QString statusTip;
687#endif
688#if QT_CONFIG(whatsthis)
689 QString whatsThis;
690#endif
691#if QT_CONFIG(accessibility)
692 QString accessibleName;
693 QString accessibleDescription;
694 QString accessibleIdentifier;
695#endif
696
697 // Other variables.
698 uint directFontResolveMask;
699 uint inheritedFontResolveMask;
700 decltype(std::declval<QPalette>().resolveMask()) directPaletteResolveMask;
701 QPalette::ResolveMask inheritedPaletteResolveMask;
702 short leftmargin;
703 short topmargin;
704 short rightmargin;
705 short bottommargin;
706 signed char leftLayoutItemMargin;
707 signed char topLayoutItemMargin;
708 signed char rightLayoutItemMargin;
709 signed char bottomLayoutItemMargin;
710 static int instanceCounter; // Current number of widget instances
711 static int maxInstances; // Maximum number of widget instances
712 Qt::HANDLE hd;
713 QWidgetData data;
714 QSizePolicy size_policy;
715 QLocale locale;
716 QPoint redirectOffset;
717#ifndef QT_NO_ACTION
718 QList<QAction*> actions;
719#endif
720#ifndef QT_NO_GESTURES
721 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
722#endif
723
724 // Bit fields.
725 uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
726 QPalette::ColorRole fg_role : 8;
727 QPalette::ColorRole bg_role : 8;
728 uint dirtyOpaqueChildren : 1;
729 uint isOpaque : 1;
730 uint retainSizeWhenHiddenChanged : 1;
731 uint inDirtyList : 1;
732 uint isScrolled : 1;
733 uint isMoved : 1;
734 uint usesDoubleBufferedGLContext : 1;
735 uint mustHaveWindowHandle : 1;
736 uint renderToTexture : 1;
737 uint textureChildSeen : 1;
738#ifndef QT_NO_IM
739 uint inheritsInputMethodHints : 1;
740#endif
741 uint renderToTextureReallyDirty : 1;
742 uint usesRhiFlush : 1;
743 uint childrenHiddenByWState : 1;
744 uint childrenShownByExpose : 1;
745 uint dontSetExplicitShowHide : 1;
746 uint inheritStyleRecursionGuard : 1;
747
748 // *************************** Focus abstraction ************************************
749 enum class FocusDirection {
750 Previous,
751 Next,
752 };
753
754 enum class FocusChainRemovalRule {
755 EnsureFocusOut = 0x01,
756 AssertConsistency = 0x02,
757 };
758 Q_DECLARE_FLAGS(FocusChainRemovalRules, FocusChainRemovalRule)
759
760 // Getters
761 QWidget *nextPrevElementInFocusChain(FocusDirection direction) const;
762
763 // manipulators
764 bool removeFromFocusChain(FocusChainRemovalRules rules = FocusChainRemovalRules(),
765 FocusDirection direction = FocusDirection::Next);
766 bool insertIntoFocusChain(FocusDirection direction, QWidget *position);
767 static bool insertIntoFocusChain(const QWidgetList &toBeInserted, FocusDirection direction, QWidget *position);
768 bool insertIntoFocusChainBefore(QWidget *position)
769 { return insertIntoFocusChain(FocusDirection::Previous, position); }
770 bool insertIntoFocusChainAfter(QWidget *position)
771 { return insertIntoFocusChain(FocusDirection::Next, position); }
772 static QWidgetList takeFromFocusChain(QWidget *from, QWidget *to,
773 FocusDirection direction = FocusDirection::Next);
774 void reparentFocusChildren(FocusDirection direction);
775 QWidget *determineLastFocusChild(QWidget *noFurtherThan);
776
777 // Initialization and tests
778 void initFocusChain();
779 bool isInFocusChain() const;
780 bool isFocusChainConsistent() const;
781
782 // *************************** Platform specific ************************************
783#if defined(Q_OS_WIN)
784 uint noPaintOnScreen : 1; // see qwidget.cpp ::paintEngine()
785#elif defined(Q_OS_MAC)
786 void macUpdateSizeAttribute();
787#endif
788 void setNetWmWindowTypes(bool skipIfMissing = false);
789
790 bool stealKeyboardGrab(bool grab);
791 bool stealMouseGrab(bool grab);
792 bool hasChildWithFocusPolicy(Qt::FocusPolicy policy, const QWidget *excludeChildrenOf = nullptr) const;
793};
794
795Q_DECLARE_OPERATORS_FOR_FLAGS(QWidgetPrivate::DrawWidgetFlags)
796
797struct QWidgetPaintContext
798{
799 inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, QWidgetPrivate::DrawWidgetFlags f,
800 QPainter *p, QWidgetRepaintManager *rpm)
801 : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), repaintManager(rpm), painter(nullptr) {}
802
803 QPaintDevice *pdev;
804 QRegion rgn;
805 QPoint offset;
806 QWidgetPrivate::DrawWidgetFlags flags;
807 QPainter *sharedPainter;
808 QWidgetRepaintManager *repaintManager;
809 QPainter *painter;
810};
811
812#if QT_CONFIG(graphicseffect)
813class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
814{
815public:
816 QWidgetEffectSourcePrivate(QWidget *widget)
817 : QGraphicsEffectSourcePrivate(), m_widget(widget), context(nullptr), updateDueToGraphicsEffect(false)
818 {}
819
820 void detach() override
821 { m_widget->d_func()->graphicsEffect = nullptr; }
822
823 const QGraphicsItem *graphicsItem() const override
824 { return nullptr; }
825
826 const QWidget *widget() const override
827 { return m_widget; }
828
829 void update() override
830 {
831 updateDueToGraphicsEffect = true;
832 m_widget->update();
833 updateDueToGraphicsEffect = false;
834 }
835
836 bool isPixmap() const override
837 { return false; }
838
839 void effectBoundingRectChanged() override
840 {
841 // ### This function should take a rect parameter; then we can avoid
842 // updating too much on the parent widget.
843 if (QWidget *parent = m_widget->parentWidget())
844 parent->update();
845 else
846 update();
847 }
848
849 const QStyleOption *styleOption() const override
850 { return nullptr; }
851
852 QRect deviceRect() const override
853 { return m_widget->window()->rect(); }
854
855 QRectF boundingRect(Qt::CoordinateSystem system) const override;
856 void draw(QPainter *p) override;
857 QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset,
858 QGraphicsEffect::PixmapPadMode mode) const override;
859
860 QWidget *m_widget;
861 QWidgetPaintContext *context;
862 QTransform lastEffectTransform;
863 bool updateDueToGraphicsEffect;
864};
865#endif // QT_CONFIG(graphicseffect)
866
867inline QWExtra *QWidgetPrivate::extraData() const
868{
869 return extra.get();
870}
871
872inline QTLWExtra *QWidgetPrivate::topData() const
873{
874 const_cast<QWidgetPrivate *>(this)->createTLExtra();
875 return extra->topextra.get();
876}
877
878inline QTLWExtra *QWidgetPrivate::maybeTopData() const
879{
880 return extra ? extra->topextra.get() : nullptr;
881}
882
883inline QPainter *QWidgetPrivate::sharedPainter() const
884{
885 Q_Q(const QWidget);
886 QTLWExtra *x = q->window()->d_func()->maybeTopData();
887 return x ? x->sharedPainter : nullptr;
888}
889
890inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
891{
892 Q_Q(QWidget);
893 QTLWExtra *x = q->window()->d_func()->topData();
894 x->sharedPainter = painter;
895}
896
897inline bool QWidgetPrivate::pointInsideRectAndMask(const QPointF &p) const
898{
899 Q_Q(const QWidget);
900
901 // Use QRectF::contains so that (0, -0.1) isn't in, with p.toPoint() it would be in.
902 // The -1 on right and bottom matches QRect semantics:
903 // (160,160) isn't contained in QRect(0, 0, 160, 160)
904 QRect r = q->rect();
905 r.setRight(qMax(-1, r.right() - 1));
906 r.setBottom(qMax(-1, r.bottom() - 1));
907
908 return r.toRectF().contains(p)
909 && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
910 || extra->mask.contains(p.toPoint() /* incorrect for the -0.1 case */));
911}
912
913inline QWidgetRepaintManager *QWidgetPrivate::maybeRepaintManager() const
914{
915 Q_Q(const QWidget);
916 QTLWExtra *x = q->window()->d_func()->maybeTopData();
917 return x ? x->repaintManager.get() : nullptr;
918}
919
920QT_END_NAMESPACE
921
922#endif // QWIDGET_P_H
friend class QWidget
Definition qpainter.h:431
friend class QPaintEngine
Definition qpainter.h:437
The QStyleFactory class creates QStyle objects.
const QRegion & region() const
Definition qwidget_p.h:84
QUpdateLaterEvent(const QRegion &paintRegion)
Definition qwidget_p.h:79
void setNativeWindowVisibility(bool visible)
QObject * focusObject() const override
Returns the QObject that will be the final receiver of events tied focus, such as key events.
void handleMoveEvent(QMoveEvent *)
void handleMouseEvent(QMouseEvent *)
void handleFocusInEvent(QFocusEvent *)
void handleResizeEvent(QResizeEvent *)
void handleEnterLeaveEvent(QEvent *)
void handleTouchEvent(QTouchEvent *)
static void focusNextPrevChild(QWidget *widget, bool next)
void handleKeyEvent(QKeyEvent *)
void handleContextMenuEvent(QContextMenuEvent *)
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override
Override this to handle platform dependent events.
bool event(QEvent *) override
Override this to handle any event (ev) sent to the window.
void handleExposeEvent(QExposeEvent *)
void closeEvent(QCloseEvent *) override
Override this to handle close events (ev).
void handleNonClientAreaMouseEvent(QMouseEvent *)
void handleGestureEvent(QNativeGestureEvent *)
void handleWindowStateChangedEvent(QWindowStateChangeEvent *event)
QWidget * widget() const
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
Q_GLOBAL_STATIC(DefaultRoleNames, qDefaultRoleNames, { { Qt::DisplayRole, "display" }, { Qt::DecorationRole, "decoration" }, { Qt::EditRole, "edit" }, { Qt::ToolTipRole, "toolTip" }, { Qt::StatusTipRole, "statusTip" }, { Qt::WhatsThisRole, "whatsThis" }, }) const QHash< int
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
static int uiEffectToFlag(Qt::UIEffect effect)
static void initResources()
void qt_init_tooltip_palette()
static void ungrabMouseForPopup(QWidget *popup)
static void ungrabKeyboardForPopup(QWidget *popup)
Q_TRACE_POINT(qtwidgets, QApplication_notify_entry, QObject *receiver, QEvent *event, QEvent::Type type)
Q_WIDGETS_EXPORT bool qt_tryModalHelper(QWidget *widget, QWidget **rettop)
int qt_antialiasing_threshold
bool qt_in_tab_key_event
static bool popupGrabOk
void qRegisterWidgetsVariant()
static void grabForPopup(QWidget *popup)
QWidget * qt_tlw_for_window(QWindow *wnd)
Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
bool qt_try_modal(QWidget *widget, QEvent::Type type)
void qt_qpa_set_cursor(QWidget *w, bool force)
Definition qwidget.cpp:5073
QHash< QByteArray, QFont > FontHash
QClipboard * qt_clipboard
Q_TRACE_POINT(qtcore, QCoreApplication_notify_exit, bool consumed, bool filtered)
Q_TRACE_METADATA(qtcore, "ENUM { AUTO, RANGE User ... MaxUser } QEvent::Type;")
Q_TRACE_PREFIX(qtcore, "#include <qcoreevent.h>")
#define qApp
Q_CORE_EXPORT void qt_call_post_routines()
Q_CONSTINIT Q_GUI_EXPORT bool qt_is_tty_app
#define CHECK_QAPP_INSTANCE(...)
void qSendWindowChangeToTextureChildrenRecursively(QWidget *widget, QEvent::Type eventType)
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
#define QWIDGETSIZE_MAX
Definition qwidget.h:922
Q_DECLARE_LOGGING_CATEGORY(lcWidgetShowHide)
QPointer< QWindow > qt_last_mouse_receiver
QRect frameStrut
Definition qwidget_p.h:112
QString role
Definition qwidget_p.h:105
QString iconText
Definition qwidget_p.h:104
QString caption
Definition qwidget_p.h:103
QPointer< QScreen > initialScreen
Definition qwidget_p.h:115
std::unique_ptr< QWidgetRepaintManager > repaintManager
Definition qwidget_p.h:97
uint posIncludesFrame
Definition qwidget_p.h:121
QRect normalGeometry
Definition qwidget_p.h:113
Qt::WindowFlags savedFlags
Definition qwidget_p.h:114
QPainter * sharedPainter
Definition qwidget_p.h:99
uint explicitContentsMarginsRespectsSafeArea
Definition qwidget_p.h:124
std::unique_ptr< QIcon > icon
Definition qwidget_p.h:96
uint opacity
Definition qwidget_p.h:120
std::vector< std::unique_ptr< QPlatformTextureList > > widgetTextures
Definition qwidget_p.h:117
uint sizeAdjusted
Definition qwidget_p.h:122
short baseh
Definition qwidget_p.h:110
QBackingStore * backingStore
Definition qwidget_p.h:98
QString filePath
Definition qwidget_p.h:106
short inch
Definition qwidget_p.h:109
short basew
Definition qwidget_p.h:110
QWidgetWindow * window
Definition qwidget_p.h:100
uint embedded
Definition qwidget_p.h:123
short incw
Definition qwidget_p.h:109
uint hasMask
Definition qwidget_p.h:161
uint hasWindowContainer
Definition qwidget_p.h:162
QString styleSheet
Definition qwidget_p.h:144
QRegion mask
Definition qwidget_p.h:143
qint32 minw
Definition qwidget_p.h:147
QSize staticContentsSize
Definition qwidget_p.h:153
QPointer< QWidget > focus_proxy
Definition qwidget_p.h:140
uint inRenderWithPainter
Definition qwidget_p.h:160
qint32 maxh
Definition qwidget_p.h:150
quint16 customDpiY
Definition qwidget_p.h:152
uint nativeChildrenForced
Definition qwidget_p.h:159
quint16 customDpiX
Definition qwidget_p.h:151
std::unique_ptr< QTLWExtra > topextra
Definition qwidget_p.h:132
void * glContext
Definition qwidget_p.h:131
std::unique_ptr< QCursor > curs
Definition qwidget_p.h:137
uint explicitMinSize
Definition qwidget_p.h:156
uint autoFillBackground
Definition qwidget_p.h:158
QPointer< QStyle > style
Definition qwidget_p.h:139
uint explicitMaxSize
Definition qwidget_p.h:157
qint32 maxw
Definition qwidget_p.h:149
qint32 minh
Definition qwidget_p.h:148