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
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
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 ****************************
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 ****************************
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 void setWindowIconText_sys(const QString &cap);
403 void setWindowIconText_helper(const QString &cap);
404 void setWindowTitle_sys(const QString &cap);
405 void setWindowFilePath_sys(const QString &filePath);
406
407#ifndef QT_NO_CURSOR
408 void setCursor_sys(const QCursor &cursor);
409 void unsetCursor_sys();
410#endif
411
412 void setWindowTitle_helper(const QString &cap);
413 void setWindowFilePath_helper(const QString &filePath);
414 void setWindowModified_helper();
415 virtual void setWindowFlags(Qt::WindowFlags windowFlags);
416
417 bool setMinimumSize_helper(int &minw, int &minh);
418 bool setMaximumSize_helper(int &maxw, int &maxh);
419 void setConstraints_sys();
420 bool pointInsideRectAndMask(const QPointF &) const;
421 QWidget *childAt_helper(const QPointF &, bool) const;
422 QWidget *childAtRecursiveHelper(const QPointF &p, bool) const;
423 void updateGeometry_helper(bool forceUpdate);
424
425 void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
426 void setLayoutItemMargins(int left, int top, int right, int bottom);
427 void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = nullptr);
428
429 void updateContentsRect();
430 QMargins safeAreaMargins() const;
431
432 // aboutToDestroy() is called just before the contents of
433 // QWidget::destroy() is executed. It's used to signal QWidget
434 // sub-classes that their internals are about to be released.
435 virtual void aboutToDestroy() {}
436
437 // customization point for widget re-creation to deal with different RHI types
438 virtual void recreate()
439 {
440 Q_Q(QWidget);
441 q->destroy();
442 q->create();
443 }
444
445 inline QWidget *effectiveFocusWidget() {
446 QWidget *w = q_func();
447 while (w->focusProxy())
448 w = w->focusProxy();
449 return w;
450 }
451
452 void setModal_sys();
453
454 // These helper functions return the (available) geometry for the screen
455 // the widget is on, and takes care if this one is embedded in a QGraphicsView.
456 static QWidget *parentGraphicsView(const QWidget *widget)
457 {
458#if QT_CONFIG(graphicsview)
459 QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
460 //It's embedded if it has an ancestor
461 if (ancestorProxy) {
462 if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != nullptr) {
463 if (!ancestorProxy->scene()->views().empty()) {
464 return ancestorProxy->scene()->views().at(0);
465 }
466 }
467 }
468#else
469 Q_UNUSED(widget);
470#endif
471 return nullptr;
472 }
473
474 static QRect screenGeometry(const QWidget *widget)
475 {
476 return screenGeometry(widget, QPoint(), false);
477 }
478
479 static QRect availableScreenGeometry(const QWidget *widget)
480 {
481 return availableScreenGeometry(widget, QPoint(), false);
482 }
483
484 static QScreen *screen(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
485 {
486 while (QWidget *view = parentGraphicsView(widget))
487 widget = view;
488
489 QScreen *screen = nullptr;
490 if (hasPosition)
491 screen = widget->screen()->virtualSiblingAt(globalPosition);
492 if (!screen)
493 screen = widget->screen();
494
495 return screen;
496 }
497
498 static QRect screenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
499 {
500 return screen(widget, globalPosition, hasPosition)->geometry();
501 }
502
503 static QRect availableScreenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
504 {
505 return screen(widget, globalPosition, hasPosition)->availableGeometry();
506 }
507
508 inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
509 {
510 Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
511 redirectDev = replacement;
512 redirectOffset = offset;
513 }
514
515 inline QPaintDevice *redirected(QPoint *offset) const
516 {
517 if (offset)
518 *offset = redirectDev ? redirectOffset : QPoint();
519 return redirectDev;
520 }
521
522 inline void restoreRedirected()
523 { redirectDev = nullptr; }
524
525 inline void enforceNativeChildren()
526 {
527 if (!extra)
528 createExtra();
529
530 if (extra->nativeChildrenForced)
531 return;
532 extra->nativeChildrenForced = 1;
533
534 for (int i = 0; i < children.size(); ++i) {
535 if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
536 child->setAttribute(Qt::WA_NativeWindow);
537 }
538 }
539
540 inline bool nativeChildrenForced() const
541 {
542 return extra ? extra->nativeChildrenForced : false;
543 }
544
545 inline QRect effectiveRectFor(const QRegion &region) const
546 {
547 return effectiveRectFor(region.boundingRect());
548 }
549
550 inline QRect effectiveRectFor(const QRect &rect) const
551 {
552#if QT_CONFIG(graphicseffect)
553 if (graphicsEffect && graphicsEffect->isEnabled())
554 return graphicsEffect->boundingRectFor(rect).toAlignedRect();
555#endif // QT_CONFIG(graphicseffect)
556 return rect;
557 }
558
559 QSize adjustedSize() const;
560
561 inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
562 {
563 if (button == Qt::LeftButton)
564 handleSoftwareInputPanel(clickCausedFocus);
565 }
566
567 inline void handleSoftwareInputPanel(bool clickCausedFocus = false)
568 {
569 Q_Q(QWidget);
570 if (qApp->autoSipEnabled()) {
571 QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
572 q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel, nullptr, q));
573 if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
574 QGuiApplication::inputMethod()->show();
575 }
576 }
577 }
578
579 void setWSGeometry();
580
581 inline QPoint mapToWS(const QPoint &p) const
582 { return p - data.wrect.topLeft(); }
583
584 inline QPoint mapFromWS(const QPoint &p) const
585 { return p + data.wrect.topLeft(); }
586
587 inline QRect mapToWS(const QRect &r) const
588 { return r.translated(-data.wrect.topLeft()); }
589
590 inline QRect mapFromWS(const QRect &r) const
591 { return r.translated(data.wrect.topLeft()); }
592
593 virtual QObject *focusObject();
594
595 virtual QPlatformBackingStoreRhiConfig rhiConfig() const { return {}; }
596
597 // Note that textureRight may be null, as it's only used in stereoscopic rendering
598 struct TextureData {
599 QRhiTexture *textureLeft = nullptr;
600 QRhiTexture *textureRight = nullptr;
601 };
602
603 virtual TextureData texture() const { return {}; }
604 virtual QPlatformTextureList::Flags textureListFlags() {
605 Q_Q(QWidget);
606 return q->testAttribute(Qt::WA_AlwaysStackOnTop)
607 ? QPlatformTextureList::StacksOnTop
608 : QPlatformTextureList::Flags();
609 }
610 virtual QImage grabFramebuffer() { return QImage(); }
611 virtual void beginBackingStorePainting() { }
612 virtual void endBackingStorePainting() { }
613 virtual void beginCompose() { }
614 virtual void endCompose() { }
615 void setRenderToTexture() { renderToTexture = true; setTextureChildSeen(); }
616 void setTextureChildSeen()
617 {
618 Q_Q(QWidget);
619 if (textureChildSeen)
620 return;
621 textureChildSeen = 1;
622
623 if (!q->isWindow()) {
624 QWidget *parent = q->parentWidget();
625 if (parent)
626 get(parent)->setTextureChildSeen();
627 }
628 }
629 static void sendComposeStatus(QWidget *w, bool end);
630 // Called on setViewport().
631 virtual void initializeViewportFramebuffer() { }
632 // When using a QOpenGLWidget as viewport with QAbstractScrollArea, resize events are
633 // filtered away from the widget. This is fine for QGLWidget but bad for QOpenGLWidget
634 // since the fbo must be resized. We need an alternative way to notify.
635 virtual void resizeViewportFramebuffer() { }
636 // Called after each paint event.
637 virtual void resolveSamples() { }
638
639 // These two are used in QGraphicsView for supporting stereoscopic rendering with a
640 // QOpenGLWidget viewport.
641 virtual bool isStereoEnabled() { return false; } // Called in QGraphicsView::setupViewport
642 virtual bool toggleStereoTargetBuffer() { return false; } // Called in QGraphicsView::paintEvent
643
644 static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent);
645
646 std::string flagsForDumping() const override;
647
648 QWidget *closestParentWidgetWithWindowHandle() const;
649
650 // Variables.
651 // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
652 std::unique_ptr<QWExtra> extra;
653 QWidget *focus_next;
654 QWidget *focus_prev;
655 QWidget *focus_child;
656 QLayout *layout;
657 QRegion *needsFlush;
658 QPaintDevice *redirectDev;
659 QWidgetItemV2 *widgetItem;
660 QPaintEngine *extraPaintEngine;
661 mutable const QMetaObject *polished;
662 QGraphicsEffect *graphicsEffect;
663#if QT_CONFIG(label)
664 // labels for which this widget is the buddy widget
665 QVarLengthArray<QLabel *, 1> labels;
666#endif
667 // All widgets are added into the allWidgets set. Once
668 // they receive a window id they are also added to the mapper.
669 // This should just ensure that all widgets are deleted by QApplication
670 static QWidgetMapper *mapper;
671 static QWidgetSet *allWidgets;
672#if !defined(QT_NO_IM)
673 Qt::InputMethodHints imHints;
674#endif
675
676 // Implicit pointers (shared_null/shared_empty).
677 QRegion opaqueChildren;
678 QRegion dirty;
679#if QT_CONFIG(tooltip)
680 QString toolTip;
681 int toolTipDuration;
682#endif
683#if QT_CONFIG(statustip)
684 QString statusTip;
685#endif
686#if QT_CONFIG(whatsthis)
687 QString whatsThis;
688#endif
689#if QT_CONFIG(accessibility)
690 QString accessibleName;
691 QString accessibleDescription;
692 QString accessibleIdentifier;
693#endif
694
695 // Other variables.
696 uint directFontResolveMask;
697 uint inheritedFontResolveMask;
698 decltype(std::declval<QPalette>().resolveMask()) directPaletteResolveMask;
699 QPalette::ResolveMask inheritedPaletteResolveMask;
700 short leftmargin;
701 short topmargin;
702 short rightmargin;
703 short bottommargin;
704 signed char leftLayoutItemMargin;
705 signed char topLayoutItemMargin;
706 signed char rightLayoutItemMargin;
707 signed char bottomLayoutItemMargin;
708 static int instanceCounter; // Current number of widget instances
709 static int maxInstances; // Maximum number of widget instances
710 Qt::HANDLE hd;
711 QWidgetData data;
712 QSizePolicy size_policy;
713 QLocale locale;
714 QPoint redirectOffset;
715#ifndef QT_NO_ACTION
716 QList<QAction*> actions;
717#endif
718#ifndef QT_NO_GESTURES
719 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext;
720#endif
721
722 // Bit fields.
723 uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
724 QPalette::ColorRole fg_role : 8;
725 QPalette::ColorRole bg_role : 8;
726 uint dirtyOpaqueChildren : 1;
727 uint isOpaque : 1;
728 uint retainSizeWhenHiddenChanged : 1;
729 uint inDirtyList : 1;
730 uint isScrolled : 1;
731 uint isMoved : 1;
732 uint usesDoubleBufferedGLContext : 1;
733 uint mustHaveWindowHandle : 1;
734 uint renderToTexture : 1;
735 uint textureChildSeen : 1;
736#ifndef QT_NO_IM
737 uint inheritsInputMethodHints : 1;
738#endif
739 uint renderToTextureReallyDirty : 1;
740 uint usesRhiFlush : 1;
741 uint childrenHiddenByWState : 1;
742 uint childrenShownByExpose : 1;
743 uint dontSetExplicitShowHide : 1;
744 uint inheritStyleRecursionGuard : 1;
745
746 // *************************** Focus abstraction ************************************
747 enum class FocusDirection {
748 Previous,
749 Next,
750 };
751
752 enum class FocusChainRemovalRule {
753 EnsureFocusOut = 0x01,
754 AssertConsistency = 0x02,
755 };
756 Q_DECLARE_FLAGS(FocusChainRemovalRules, FocusChainRemovalRule)
757
758 // Getters
759 QWidget *nextPrevElementInFocusChain(FocusDirection direction) const;
760
761 // manipulators
762 bool removeFromFocusChain(FocusChainRemovalRules rules = FocusChainRemovalRules(),
763 FocusDirection direction = FocusDirection::Next);
764 bool insertIntoFocusChain(FocusDirection direction, QWidget *position);
765 static bool insertIntoFocusChain(const QWidgetList &toBeInserted, FocusDirection direction, QWidget *position);
766 bool insertIntoFocusChainBefore(QWidget *position)
767 { return insertIntoFocusChain(FocusDirection::Previous, position); }
768 bool insertIntoFocusChainAfter(QWidget *position)
769 { return insertIntoFocusChain(FocusDirection::Next, position); }
770 static QWidgetList takeFromFocusChain(QWidget *from, QWidget *to,
771 FocusDirection direction = FocusDirection::Next);
772 void reparentFocusChildren(FocusDirection direction);
773 QWidget *determineLastFocusChild(QWidget *noFurtherThan);
774
775 // Initialization and tests
776 void initFocusChain();
777 bool isInFocusChain() const;
778 bool isFocusChainConsistent() const;
779
780 // *************************** Platform specific ************************************
781#if defined(Q_OS_WIN)
782 uint noPaintOnScreen : 1; // see qwidget.cpp ::paintEngine()
783#elif defined(Q_OS_MACOS)
784 void macUpdateSizeAttribute();
785#endif
786 void setNetWmWindowTypes(bool skipIfMissing = false);
787
788 bool stealKeyboardGrab(bool grab);
789 bool stealMouseGrab(bool grab);
790 bool hasChildWithFocusPolicy(Qt::FocusPolicy policy, const QWidget *excludeChildrenOf = nullptr) const;
791};
792
793Q_DECLARE_OPERATORS_FOR_FLAGS(QWidgetPrivate::DrawWidgetFlags)
794
795struct QWidgetPaintContext
796{
797 inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, QWidgetPrivate::DrawWidgetFlags f,
798 QPainter *p, QWidgetRepaintManager *rpm)
799 : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), repaintManager(rpm), painter(nullptr) {}
800
801 QPaintDevice *pdev;
802 QRegion rgn;
803 QPoint offset;
804 QWidgetPrivate::DrawWidgetFlags flags;
805 QPainter *sharedPainter;
806 QWidgetRepaintManager *repaintManager;
807 QPainter *painter;
808};
809
810#if QT_CONFIG(graphicseffect)
811class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
812{
813public:
814 QWidgetEffectSourcePrivate(QWidget *widget)
815 : QGraphicsEffectSourcePrivate(), m_widget(widget), context(nullptr), updateDueToGraphicsEffect(false)
816 {}
817
818 void detach() override
819 { m_widget->d_func()->graphicsEffect = nullptr; }
820
821 const QGraphicsItem *graphicsItem() const override
822 { return nullptr; }
823
824 const QWidget *widget() const override
825 { return m_widget; }
826
827 void update() override
828 {
829 updateDueToGraphicsEffect = true;
830 m_widget->update();
831 updateDueToGraphicsEffect = false;
832 }
833
834 bool isPixmap() const override
835 { return false; }
836
837 void effectBoundingRectChanged() override
838 {
839 // ### This function should take a rect parameter; then we can avoid
840 // updating too much on the parent widget.
841 if (QWidget *parent = m_widget->parentWidget())
842 parent->update();
843 else
844 update();
845 }
846
847 const QStyleOption *styleOption() const override
848 { return nullptr; }
849
850 QRect deviceRect() const override
851 { return m_widget->window()->rect(); }
852
853 QRectF boundingRect(Qt::CoordinateSystem system) const override;
854 void draw(QPainter *p) override;
855 QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset,
856 QGraphicsEffect::PixmapPadMode mode) const override;
857
858 QWidget *m_widget;
859 QWidgetPaintContext *context;
860 QTransform lastEffectTransform;
861 bool updateDueToGraphicsEffect;
862};
863#endif // QT_CONFIG(graphicseffect)
864
865inline QWExtra *QWidgetPrivate::extraData() const
866{
867 return extra.get();
868}
869
870inline QTLWExtra *QWidgetPrivate::topData() const
871{
872 const_cast<QWidgetPrivate *>(this)->createTLExtra();
873 return extra->topextra.get();
874}
875
876inline QTLWExtra *QWidgetPrivate::maybeTopData() const
877{
878 return extra ? extra->topextra.get() : nullptr;
879}
880
881inline QPainter *QWidgetPrivate::sharedPainter() const
882{
883 Q_Q(const QWidget);
884 QTLWExtra *x = q->window()->d_func()->maybeTopData();
885 return x ? x->sharedPainter : nullptr;
886}
887
888inline void QWidgetPrivate::setSharedPainter(QPainter *painter)
889{
890 Q_Q(QWidget);
891 QTLWExtra *x = q->window()->d_func()->topData();
892 x->sharedPainter = painter;
893}
894
895inline bool QWidgetPrivate::pointInsideRectAndMask(const QPointF &p) const
896{
897 Q_Q(const QWidget);
898
899 // Use QRectF::contains so that (0, -0.1) isn't in, with p.toPoint() it would be in.
900 // The -1 on right and bottom matches QRect semantics:
901 // (160,160) isn't contained in QRect(0, 0, 160, 160)
902 QRect r = q->rect();
903 r.setRight(qMax(-1, r.right() - 1));
904 r.setBottom(qMax(-1, r.bottom() - 1));
905
906 return r.toRectF().contains(p)
907 && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
908 || extra->mask.contains(p.toPoint() /* incorrect for the -0.1 case */));
909}
910
911inline QWidgetRepaintManager *QWidgetPrivate::maybeRepaintManager() const
912{
913 Q_Q(const QWidget);
914 QTLWExtra *x = q->window()->d_func()->maybeTopData();
915 return x ? x->repaintManager.get() : nullptr;
916}
917
918QT_END_NAMESPACE
919
920#endif // QWIDGET_P_H
friend class QPaintEngine
Definition qpainter.h:438
const QRegion & region() const
Definition qwidget_p.h:84
QUpdateLaterEvent(const QRegion &paintRegion)
Definition qwidget_p.h:79
\inmodule QtWidgets
Definition qwidget_p.h:184
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE int 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:173
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