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 <qpa/qplatformbackingstore.h>
46#include <QtGui/private/qbackingstorerhisupport_p.h>
47#include <private/qapplication_p.h>
48
49#include <QtCore/qpointer.h>
50
51#include <vector>
52#include <memory>
53
55
58
59// Extra QWidget data
60// - to minimize memory usage for members that are seldom used.
61// - top-level widgets have extra extra data to reduce cost further
62class QWidgetWindow;
63class QPaintEngine;
64class QPixmap;
65class QWidgetRepaintManager;
66class QGraphicsProxyWidget;
67class QWidgetItemV2;
68
69class QStyle;
70
71// implemented in qshortcut.cpp
72bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context);
73void qSendWindowChangeToTextureChildrenRecursively(QWidget *widget, QEvent::Type eventType);
74
76{
77public:
78 explicit QUpdateLaterEvent(const QRegion& paintRegion)
80 {
81 }
82
83 inline const QRegion &region() const { return m_region; }
84
85protected:
86 friend class QApplication;
87 friend class QApplicationPrivate;
89};
90
91struct QTLWExtra {
92 // *************************** Cross-platform variables *****************************
93
94 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
95 std::unique_ptr<QIcon> icon; // widget icon
100
101 // Implicit pointers (shared_null).
102 QString caption; // widget caption
103 QString iconText; // widget icon text
104 QString role; // widget role
105 QString filePath; // widget file path
106
107 // Other variables.
108 short incw, inch; // size increments
109 short basew, baseh; // base sizes
110 // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
112 QRect normalGeometry; // used by showMin/maximized/FullScreen
113 Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
114 QPointer<QScreen> initialScreen; // Screen when passing a QDesktop[Screen]Widget as parent.
115
117
118 // *************************** Cross-platform bit fields ****************************
124};
125
126struct QWExtra {
127 // *************************** Cross-platform variables *****************************
128
129 // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
130 void *glContext; // if the widget is hijacked by QGLWindowSurface
131 std::unique_ptr<QTLWExtra> topextra; // only useful for TLWs
132#if QT_CONFIG(graphicsview)
133 QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
134#endif
135#ifndef QT_NO_CURSOR
137#endif
140
141 // Implicit pointers (shared_empty/shared_null).
142 QRegion mask; // widget mask
144
145 // Other variables.
147 qint32 minh; // minimum size
149 qint32 maxh; // maximum size
153
154 // *************************** Cross-platform bit fields ****************************
162};
163
164/*!
165 \internal
166
167 Returns \c true if \a p or any of its parents enable the
168 Qt::BypassGraphicsProxyWidget window flag. Used in QWidget::show() and
169 QWidget::setParent() to determine whether it's necessary to embed the
170 widget into a QGraphicsProxyWidget or not.
171*/
172static inline bool bypassGraphicsProxyWidget(const QWidget *p)
173{
174 while (p) {
175 if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
176 return true;
177 p = p->parentWidget();
178 }
179 return false;
180}
181
182class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate
183{
184 Q_DECLARE_PUBLIC(QWidget)
185 Q_GADGET
186
187public:
188 // *************************** Cross-platform ***************************************
189 enum DrawWidgetFlag {
190 DrawAsRoot = 0x01,
191 DrawPaintOnScreen = 0x02,
192 DrawRecursive = 0x04,
193 DrawInvisible = 0x08,
194 DontSubtractOpaqueChildren = 0x10,
195 DontDrawOpaqueChildren = 0x20,
196 DontDrawNativeChildren = 0x40,
197 DontSetCompositionMode = 0x80,
198 UseEffectRegionBounds = 0x100
199 };
200 Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag)
201 Q_FLAG(DrawWidgetFlags)
202
203 enum Direction {
204 DirectionNorth = 0x01,
205 DirectionEast = 0x10,
206 DirectionSouth = 0x02,
207 DirectionWest = 0x20
208 };
209 Q_ENUM(Direction)
210
211 // Functions.
212 explicit QWidgetPrivate(decltype(QObjectPrivateVersion) = QObjectPrivateVersion);
213 ~QWidgetPrivate();
214
215 static QWidgetPrivate *get(QWidget *w) { return w->d_func(); }
216 static const QWidgetPrivate *get(const QWidget *w) { return w->d_func(); }
217
218 static void checkRestoredGeometry(const QRect &availableGeometry, QRect *restoredGeometry,
219 int frameHeight);
220
221 QWExtra *extraData() const;
222 QTLWExtra *topData() const;
223 QTLWExtra *maybeTopData() const;
224 QPainter *sharedPainter() const;
225 void setSharedPainter(QPainter *painter);
226 QWidgetRepaintManager *maybeRepaintManager() const;
227
228 QRhi *rhi() const;
229
230 enum class WindowHandleMode {
231 Direct,
232 Closest,
233 TopLevel
234 };
235 QWindow *windowHandle(WindowHandleMode mode = WindowHandleMode::Direct) const;
236 QWindow *_q_closestWindowHandle() const; // Private slot in QWidget
237
238 QScreen *associatedScreen() const;
239
240 template <typename T>
241 void repaint(T t);
242
243 template <typename T>
244 void update(T t);
245
246 void init(QWidget *desktopWidget, Qt::WindowFlags f);
247 void create();
248 void createRecursively();
249 void createWinId();
250
251 bool setScreenForPoint(const QPoint &pos);
252 bool setScreen(QScreen *screen);
253
254 void createTLExtra();
255 void createExtra();
256 void deleteExtra();
257 void createSysExtra();
258 void deleteSysExtra();
259 void createTLSysExtra();
260 void deleteTLSysExtra();
261 void updateSystemBackground();
262 void propagatePaletteChange();
263
264 void setPalette_helper(const QPalette &);
265 void resolvePalette();
266 QPalette naturalWidgetPalette(QPalette::ResolveMask inheritedMask) const;
267
268 void setMask_sys(const QRegion &);
269
270 void raise_sys();
271 void lower_sys();
272 void stackUnder_sys(QWidget *);
273
274 QWidget *deepestFocusProxy() const;
275 void setFocus_sys();
276 void updateFocusChild();
277
278 void updateFont(const QFont &);
279 inline void setFont_helper(const QFont &font) {
280 if (directFontResolveMask == font.resolveMask() && data.fnt == font)
281 return;
282 updateFont(font);
283 }
284 QFont localFont() const;
285 void resolveFont();
286 QFont naturalWidgetFont(uint inheritedMask) const;
287
288 void setLayoutDirection_helper(Qt::LayoutDirection);
289 void resolveLayoutDirection();
290
291 void setLocale_helper(const QLocale &l, bool forceUpdate = false);
292 void resolveLocale();
293
294 void setStyle_helper(QStyle *newStyle, bool propagate);
295 void inheritStyle();
296
297 void setUpdatesEnabled_helper(bool );
298
299 bool updateBrushOrigin(QPainter *, const QBrush &brush) const;
300 void paintBackground(QPainter *, const QRegion &, DrawWidgetFlags flags = DrawAsRoot) const;
301 bool isAboutToShow() const;
302 QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
303 void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
304 QWidget::RenderFlags renderFlags);
305 void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
306 QWidget::RenderFlags renderFlags);
307 void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags,
308 QPainter *sharedPainter = nullptr, QWidgetRepaintManager *repaintManager = nullptr);
309 void sendPaintEvent(const QRegion &toBePainted);
310
311
312 void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
313 const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags,
314 QPainter *sharedPainter, QWidgetRepaintManager *repaintManager);
315
316#if QT_CONFIG(graphicsview)
317 static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
318#endif
319 bool shouldPaintOnScreen() const;
320 void paintOnScreen(const QRegion &rgn);
321
322 QRect clipRect() const;
323 QRegion clipRegion() const;
324 void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion &region);
325 void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
326 void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = nullptr,
327 bool alsoNonOpaque = false) const;
328 void clipToEffectiveMask(QRegion &region) const;
329 void updateIsOpaque();
330 void setOpaque(bool opaque);
331 void updateIsTranslucent();
332#if QT_CONFIG(graphicseffect)
333 void invalidateGraphicsEffectsRecursively();
334#endif // QT_CONFIG(graphicseffect)
335
336 const QRegion &getOpaqueChildren() const;
337 void setDirtyOpaqueRegion();
338
339 bool close();
340 enum CloseMode {
341 CloseNoEvent,
342 CloseWithEvent,
343 CloseWithSpontaneousEvent
344 };
345 Q_ENUM(CloseMode)
346 bool handleClose(CloseMode mode);
347
348 void setWindowIcon_helper();
349 void setWindowIcon_sys();
350 void setWindowOpacity_sys(qreal opacity);
351 void adjustQuitOnCloseAttribute();
352
353 void scrollChildren(int dx, int dy);
354 void moveRect(const QRect &, int dx, int dy);
355 void scrollRect(const QRect &, int dx, int dy);
356 void invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
357
358 template <class T>
359 void invalidateBackingStore(const T &);
360
361 QRegion overlappedRegion(const QRect &rect, bool breakAfterFirst = false) const;
362 bool isOverlapped(const QRect &rect) const { return !overlappedRegion(rect, true).isEmpty(); }
363 void syncBackingStore();
364 void syncBackingStore(const QRegion &region);
365
366 bool shouldDiscardSyncRequest() const;
367
368 // tells the input method about the widgets transform
369 void updateWidgetTransform(QEvent *event);
370
371 void reparentFocusWidgets(QWidget *oldtlw);
372
373 void setWinId(WId);
374 void showChildren(bool spontaneous);
375 void hideChildren(bool spontaneous);
376 void setParent_sys(QWidget *parent, Qt::WindowFlags);
377 void reparentWidgetWindows(QWidget *parentWithWindow, Qt::WindowFlags windowFlags = {});
378 void reparentWidgetWindowChildren(QWidget *parentWithWindow);
379 void scroll_sys(int dx, int dy);
380 void scroll_sys(int dx, int dy, const QRect &r);
381 void deactivateWidgetCleanup();
382 void setGeometry_sys(int, int, int, int, bool);
383 void fixPosIncludesFrame();
384 void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
385 void activateChildLayoutsRecursively();
386 void show_recursive();
387 void show_helper();
388 void show_sys();
389 void hide_sys();
390 void hide_helper();
391 bool isExplicitlyHidden() const;
392 void _q_showIfNotHidden();
393 virtual void setVisible(bool);
394
395 void setEnabled_helper(bool);
396 static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = nullptr);
397
398 void updateFrameStrut();
399 QRect frameStrut() const;
400
401 void setWindowIconText_sys(const QString &cap);
402 void setWindowIconText_helper(const QString &cap);
403 void setWindowTitle_sys(const QString &cap);
404 void setWindowFilePath_sys(const QString &filePath);
405
406#ifndef QT_NO_CURSOR
407 void setCursor_sys(const QCursor &cursor);
408 void unsetCursor_sys();
409#endif
410
411 void setWindowTitle_helper(const QString &cap);
412 void setWindowFilePath_helper(const QString &filePath);
413 void setWindowModified_helper();
414 virtual void setWindowFlags(Qt::WindowFlags windowFlags);
415
416 bool setMinimumSize_helper(int &minw, int &minh);
417 bool setMaximumSize_helper(int &maxw, int &maxh);
418 void setConstraints_sys();
419 bool pointInsideRectAndMask(const QPointF &) const;
420 QWidget *childAt_helper(const QPointF &, bool) const;
421 QWidget *childAtRecursiveHelper(const QPointF &p, bool) const;
422 void updateGeometry_helper(bool forceUpdate);
423
424 void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
425 void setLayoutItemMargins(int left, int top, int right, int bottom);
426 void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = nullptr);
427
428 void updateContentsRect();
429 QMargins safeAreaMargins() const;
430
431 // aboutToDestroy() is called just before the contents of
432 // QWidget::destroy() is executed. It's used to signal QWidget
433 // sub-classes that their internals are about to be released.
434 virtual void aboutToDestroy() {}
435
436 // customization point for widget re-creation to deal with different RHI types
437 virtual void recreate()
438 {
439 Q_Q(QWidget);
440 q->destroy();
441 q->create();
442 }
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
675 // Implicit pointers (shared_null/shared_empty).
676 QRegion opaqueChildren;
677 QRegion dirty;
678#if QT_CONFIG(tooltip)
679 QString toolTip;
680 std::chrono::milliseconds toolTipDuration;
681#endif
682#if QT_CONFIG(statustip)
683 QString statusTip;
684#endif
685#if QT_CONFIG(whatsthis)
686 QString whatsThis;
687#endif
688#if QT_CONFIG(accessibility)
689 QString accessibleName;
690 QString accessibleDescription;
691 QString accessibleIdentifier;
692#endif
693
694 // Other variables.
695 uint directFontResolveMask;
696 uint inheritedFontResolveMask;
697 decltype(std::declval<QPalette>().resolveMask()) directPaletteResolveMask;
698 QPalette::ResolveMask inheritedPaletteResolveMask;
699 short leftmargin;
700 short topmargin;
701 short rightmargin;
702 short bottommargin;
703 signed char leftLayoutItemMargin;
704 signed char topLayoutItemMargin;
705 signed char rightLayoutItemMargin;
706 signed char bottomLayoutItemMargin;
707 static int instanceCounter; // Current number of widget instances
708 static int maxInstances; // Maximum number of widget instances
709 Qt::HANDLE hd;
710 QWidgetData data;
711 QSizePolicy size_policy;
712 QLocale locale;
713 QPoint redirectOffset;
714#if QT_CONFIG(action)
715 QList<QAction*> actions;
716#endif
717#ifndef QT_NO_GESTURES
718 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
719#endif
720
721 // Bit fields.
722 uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
723 QPalette::ColorRole fg_role : 8;
724 QPalette::ColorRole bg_role : 8;
725 uint dirtyOpaqueChildren : 1;
726 uint isOpaque : 1;
727 uint retainSizeWhenHiddenChanged : 1;
728 uint inDirtyList : 1;
729 uint isScrolled : 1;
730 uint isMoved : 1;
731 uint usesDoubleBufferedGLContext : 1;
732 uint mustHaveWindowHandle : 1;
733 uint renderToTexture : 1;
734 uint textureChildSeen : 1;
735#ifndef QT_NO_IM
736 uint inheritsInputMethodHints : 1;
737#endif
738 uint renderToTextureReallyDirty : 1;
739 uint usesRhiFlush : 1;
740 uint childrenHiddenByWState : 1;
741 uint childrenShownByExpose : 1;
742 uint dontSetExplicitShowHide : 1;
743 uint inheritStyleRecursionGuard : 1;
744
745 // *************************** Focus abstraction ************************************
746 enum class FocusDirection {
747 Previous,
748 Next,
749 };
750
751 enum class FocusChainRemovalRule {
752 EnsureFocusOut = 0x01,
753 AssertConsistency = 0x02,
754 };
755 Q_DECLARE_FLAGS(FocusChainRemovalRules, FocusChainRemovalRule)
756
757 // Getters
758 QWidget *nextPrevElementInFocusChain(FocusDirection direction) const;
759
760 // manipulators
761 bool removeFromFocusChain(FocusChainRemovalRules rules = FocusChainRemovalRules(),
762 FocusDirection direction = FocusDirection::Next);
763 bool insertIntoFocusChain(FocusDirection direction, QWidget *position);
764 static bool insertIntoFocusChain(const QWidgetList &toBeInserted, FocusDirection direction, QWidget *position);
765 bool insertIntoFocusChainBefore(QWidget *position)
766 { return insertIntoFocusChain(FocusDirection::Previous, position); }
767 bool insertIntoFocusChainAfter(QWidget *position)
768 { return insertIntoFocusChain(FocusDirection::Next, position); }
769 static QWidgetList takeFromFocusChain(QWidget *from, QWidget *to,
770 FocusDirection direction = FocusDirection::Next);
771 void reparentFocusChildren(FocusDirection direction);
772 QWidget *determineLastFocusChild(QWidget *noFurtherThan);
773
774 // Initialization and tests
775 void initFocusChain();
776 bool isInFocusChain() const;
777 bool isFocusChainConsistent() const;
778
779 // *************************** Platform specific ************************************
780#if defined(Q_OS_WIN)
781 uint noPaintOnScreen : 1; // see qwidget.cpp ::paintEngine()
782#elif defined(Q_OS_MACOS)
783 void macUpdateSizeAttribute();
784#endif
785 void setNetWmWindowTypes(bool skipIfMissing = false);
786
787 bool stealKeyboardGrab(bool grab);
788 bool stealMouseGrab(bool grab);
789 bool hasChildWithFocusPolicy(Qt::FocusPolicy policy, const QWidget *excludeChildrenOf = nullptr) const;
790};
791
792Q_DECLARE_OPERATORS_FOR_FLAGS(QWidgetPrivate::DrawWidgetFlags)
793
794struct QWidgetPaintContext
795{
796 inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, QWidgetPrivate::DrawWidgetFlags f,
797 QPainter *p, QWidgetRepaintManager *rpm)
798 : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), repaintManager(rpm), painter(nullptr) {}
799
800 QPaintDevice *pdev;
801 QRegion rgn;
802 QPoint offset;
803 QWidgetPrivate::DrawWidgetFlags flags;
804 QPainter *sharedPainter;
805 QWidgetRepaintManager *repaintManager;
806 QPainter *painter;
807};
808
809#if QT_CONFIG(graphicseffect)
810class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
811{
812public:
813 QWidgetEffectSourcePrivate(QWidget *widget)
814 : QGraphicsEffectSourcePrivate(), m_widget(widget), context(nullptr), updateDueToGraphicsEffect(false)
815 {}
816
817 void detach() override
818 { m_widget->d_func()->graphicsEffect = nullptr; }
819
820 const QGraphicsItem *graphicsItem() const override
821 { return nullptr; }
822
823 const QWidget *widget() const override
824 { return m_widget; }
825
826 void update() override
827 {
828 updateDueToGraphicsEffect = true;
829 m_widget->update();
830 updateDueToGraphicsEffect = false;
831 }
832
833 bool isPixmap() const override
834 { return false; }
835
836 void effectBoundingRectChanged() override
837 {
838 // ### This function should take a rect parameter; then we can avoid
839 // updating too much on the parent widget.
840 if (QWidget *parent = m_widget->parentWidget())
841 parent->update();
842 else
843 update();
844 }
845
846 const QStyleOption *styleOption() const override
847 { return nullptr; }
848
849 QRect deviceRect() const override
850 { return m_widget->window()->rect(); }
851
852 QRectF boundingRect(Qt::CoordinateSystem system) const override;
853 void draw(QPainter *p) override;
854 QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset,
855 QGraphicsEffect::PixmapPadMode mode) const override;
856
857 QWidget *m_widget;
858 QWidgetPaintContext *context;
859 QTransform lastEffectTransform;
860 bool updateDueToGraphicsEffect;
861};
862#endif // QT_CONFIG(graphicseffect)
863
864inline QWExtra *QWidgetPrivate::extraData() const
865{
866 return extra.get();
867}
868
869inline QTLWExtra *QWidgetPrivate::topData() const
870{
871 const_cast<QWidgetPrivate *>(this)->createTLExtra();
872 return extra->topextra.get();
873}
874
875inline QTLWExtra *QWidgetPrivate::maybeTopData() const
876{
877 return extra ? extra->topextra.get() : nullptr;
878}
879
880inline QPainter *QWidgetPrivate::sharedPainter() const
881{
882 Q_Q(const QWidget);
883 QTLWExtra *x = q->window()->d_func()->maybeTopData();
884 return x ? x->sharedPainter : nullptr;
885}
886
887inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
888{
889 Q_Q(QWidget);
890 QTLWExtra *x = q->window()->d_func()->topData();
891 x->sharedPainter = painter;
892}
893
894inline bool QWidgetPrivate::pointInsideRectAndMask(const QPointF &p) const
895{
896 Q_Q(const QWidget);
897
898 // Use QRectF::contains so that (0, -0.1) isn't in, with p.toPoint() it would be in.
899 // The -1 on right and bottom matches QRect semantics:
900 // (160,160) isn't contained in QRect(0, 0, 160, 160)
901 QRect r = q->rect();
902 r.setRight(qMax(-1, r.right() - 1));
903 r.setBottom(qMax(-1, r.bottom() - 1));
904
905 return r.toRectF().contains(p)
906 && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
907 || extra->mask.contains(p.toPoint() /* incorrect for the -0.1 case */));
908}
909
910inline QWidgetRepaintManager *QWidgetPrivate::maybeRepaintManager() const
911{
912 Q_Q(const QWidget);
913 QTLWExtra *x = q->window()->d_func()->maybeTopData();
914 return x ? x->repaintManager.get() : nullptr;
915}
916
917QT_END_NAMESPACE
918
919#endif // QWIDGET_P_H
friend class QPaintEngine
Definition qpainter.h:438
const QRegion & region() const
Definition qwidget_p.h:83
QUpdateLaterEvent(const QRegion &paintRegion)
Definition qwidget_p.h:78
\inmodule QtWidgets
Definition qwidget_p.h:183
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE std::optional< QPlatformTheme::DialogType > themeDialogType(const QDialog *dialog)
Definition qdialog.cpp:46
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcQIORing)
bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
Q_DECLARE_LOGGING_CATEGORY(lcWidgetShowHide)
void qSendWindowChangeToTextureChildrenRecursively(QWidget *widget, QEvent::Type eventType)
static bool bypassGraphicsProxyWidget(const QWidget *p)
Definition qwidget_p.h:172
QRect frameStrut
Definition qwidget_p.h:111
QString role
Definition qwidget_p.h:104
QString iconText
Definition qwidget_p.h:103
QString caption
Definition qwidget_p.h:102
QPointer< QScreen > initialScreen
Definition qwidget_p.h:114
std::unique_ptr< QWidgetRepaintManager > repaintManager
Definition qwidget_p.h:96
uint posIncludesFrame
Definition qwidget_p.h:120
QRect normalGeometry
Definition qwidget_p.h:112
Qt::WindowFlags savedFlags
Definition qwidget_p.h:113
QPainter * sharedPainter
Definition qwidget_p.h:98
uint explicitContentsMarginsRespectsSafeArea
Definition qwidget_p.h:123
std::unique_ptr< QIcon > icon
Definition qwidget_p.h:95
uint opacity
Definition qwidget_p.h:119
std::vector< std::unique_ptr< QPlatformTextureList > > widgetTextures
Definition qwidget_p.h:116
uint sizeAdjusted
Definition qwidget_p.h:121
short baseh
Definition qwidget_p.h:109
QBackingStore * backingStore
Definition qwidget_p.h:97
QString filePath
Definition qwidget_p.h:105
short inch
Definition qwidget_p.h:108
short basew
Definition qwidget_p.h:109
QWidgetWindow * window
Definition qwidget_p.h:99
uint embedded
Definition qwidget_p.h:122
short incw
Definition qwidget_p.h:108
uint hasMask
Definition qwidget_p.h:160
uint hasWindowContainer
Definition qwidget_p.h:161
QString styleSheet
Definition qwidget_p.h:143
QRegion mask
Definition qwidget_p.h:142
qint32 minw
Definition qwidget_p.h:146
QSize staticContentsSize
Definition qwidget_p.h:152
QPointer< QWidget > focus_proxy
Definition qwidget_p.h:139
uint inRenderWithPainter
Definition qwidget_p.h:159
qint32 maxh
Definition qwidget_p.h:149
quint16 customDpiY
Definition qwidget_p.h:151
uint nativeChildrenForced
Definition qwidget_p.h:158
quint16 customDpiX
Definition qwidget_p.h:150
std::unique_ptr< QTLWExtra > topextra
Definition qwidget_p.h:131
void * glContext
Definition qwidget_p.h:130
std::unique_ptr< QCursor > curs
Definition qwidget_p.h:136
uint explicitMinSize
Definition qwidget_p.h:155
uint autoFillBackground
Definition qwidget_p.h:157
QPointer< QStyle > style
Definition qwidget_p.h:138
uint explicitMaxSize
Definition qwidget_p.h:156
qint32 maxw
Definition qwidget_p.h:148
qint32 minh
Definition qwidget_p.h:147