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