QtBase  v6.3.1
qwidget_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2020 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QWIDGET_P_H
41 #define QWIDGET_P_H
42 
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists for the convenience
48 // of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
49 // file may change from version to version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 
55 
56 #include <QtWidgets/private/qtwidgetsglobal_p.h>
57 #include "QtWidgets/qwidget.h"
58 #include "private/qobject_p.h"
59 #include "QtCore/qrect.h"
60 #include "QtCore/qlocale.h"
61 #include "QtCore/qset.h"
62 #include "QtGui/qregion.h"
63 #include "QtGui/qinputmethod.h"
64 #include "QtGui/qopengl.h"
65 #include "QtGui/qsurfaceformat.h"
66 #include "QtGui/qscreen.h"
67 #include "QtWidgets/qsizepolicy.h"
68 #include "QtWidgets/qstyle.h"
69 #include "QtWidgets/qapplication.h"
70 #if QT_CONFIG(graphicseffect)
71 #include <private/qgraphicseffect_p.h>
72 #endif
73 #if QT_CONFIG(graphicsview)
74 #include "QtWidgets/qgraphicsproxywidget.h"
75 #include "QtWidgets/qgraphicsscene.h"
76 #include "QtWidgets/qgraphicsview.h"
77 #endif
78 #include <private/qgesture_p.h>
79 #include <qpa/qplatformbackingstore.h>
80 
81 #include <vector>
82 #include <memory>
83 
85 
86 Q_DECLARE_LOGGING_CATEGORY(lcWidgetPainting);
87 
88 // Extra QWidget data
89 // - to minimize memory usage for members that are seldom used.
90 // - top-level widgets have extra extra data to reduce cost further
91 class QWidgetWindow;
92 class QPaintEngine;
93 class QPixmap;
96 class QWidgetItemV2;
97 class QOpenGLContext;
98 
99 class QStyle;
100 
101 class QUnifiedToolbarSurface;
102 
103 // implemented in qshortcut.cpp
105 
106 class QUpdateLaterEvent : public QEvent
107 {
108 public:
109  explicit QUpdateLaterEvent(const QRegion& paintRegion)
110  : QEvent(UpdateLater), m_region(paintRegion)
111  {
112  }
113 
115  {
116  }
117 
118  inline const QRegion &region() const { return m_region; }
119 
120 protected:
122 };
123 
124 struct QTLWExtra {
125  // *************************** Cross-platform variables *****************************
126 
127  // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
128  std::unique_ptr<QIcon> icon; // widget icon
129  std::unique_ptr<QWidgetRepaintManager> repaintManager;
133 #ifndef QT_NO_OPENGL
134  mutable std::unique_ptr<QOpenGLContext> shareContext;
135 #endif
136 
137  // Implicit pointers (shared_null).
138  QString caption; // widget caption
139  QString iconText; // widget icon text
140  QString role; // widget role
141  QString filePath; // widget file path
142 
143  // Other variables.
144  short incw, inch; // size increments
145  short basew, baseh; // base sizes
146  // frame strut, don't use these directly, use QWidgetPrivate::frameStrut() instead.
148  QRect normalGeometry; // used by showMin/maximized/FullScreen
149  Qt::WindowFlags savedFlags; // Save widget flags while showing fullscreen
150  QScreen *initialScreen; // Screen when passing a QDesktop[Screen]Widget as parent.
151 
152 #ifndef QT_NO_OPENGL
153  std::vector<std::unique_ptr<QPlatformTextureList>> widgetTextures;
154 #endif
155 
156  // *************************** Cross-platform bit fields ****************************
161 };
162 
163 struct QWExtra {
164  // *************************** Cross-platform variables *****************************
165 
166  // Regular pointers (keep them together to avoid gaps on 64 bits architectures).
167  void *glContext; // if the widget is hijacked by QGLWindowSurface
168  std::unique_ptr<QTLWExtra> topextra; // only useful for TLWs
169 #if QT_CONFIG(graphicsview)
170  QGraphicsProxyWidget *proxyWidget; // if the widget is embedded
171 #endif
172 #ifndef QT_NO_CURSOR
173  std::unique_ptr<QCursor> curs;
174 #endif
177 
178  // Implicit pointers (shared_empty/shared_null).
179  QRegion mask; // widget mask
181 
182  // Other variables.
184  qint32 minh; // minimum size
186  qint32 maxh; // maximum size
190 
191  // *************************** Cross-platform bit fields ****************************
199 };
200 
209 static inline bool bypassGraphicsProxyWidget(const QWidget *p)
210 {
211  while (p) {
212  if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
213  return true;
214  p = p->parentWidget();
215  }
216  return false;
217 }
218 
219 class Q_WIDGETS_EXPORT QWidgetPrivate : public QObjectPrivate
220 {
221  Q_DECLARE_PUBLIC(QWidget)
222  Q_GADGET
223 
224 public:
225  // *************************** Cross-platform ***************************************
227  DrawAsRoot = 0x01,
228  DrawPaintOnScreen = 0x02,
229  DrawRecursive = 0x04,
230  DrawInvisible = 0x08,
231  DontSubtractOpaqueChildren = 0x10,
232  DontDrawOpaqueChildren = 0x20,
233  DontDrawNativeChildren = 0x40,
234  DontSetCompositionMode = 0x80,
235  UseEffectRegionBounds = 0x100
236  };
237  Q_DECLARE_FLAGS(DrawWidgetFlags, DrawWidgetFlag)
238  Q_FLAG(DrawWidgetFlags)
239 
240  enum Direction {
241  DirectionNorth = 0x01,
242  DirectionEast = 0x10,
243  DirectionSouth = 0x02,
244  DirectionWest = 0x20
245  };
247 
248  // Functions.
250  ~QWidgetPrivate();
251 
252  static QWidgetPrivate *get(QWidget *w) { return w->d_func(); }
253  static const QWidgetPrivate *get(const QWidget *w) { return w->d_func(); }
254 
255  QWExtra *extraData() const;
256  QTLWExtra *topData() const;
257  QTLWExtra *maybeTopData() const;
258  QPainter *sharedPainter() const;
259  void setSharedPainter(QPainter *painter);
260  QWidgetRepaintManager *maybeRepaintManager() const;
261 
262  enum class WindowHandleMode {
263  Direct,
264  Closest,
265  TopLevel
266  };
267  QWindow *windowHandle(WindowHandleMode mode = WindowHandleMode::Direct) const;
268  QWindow *_q_closestWindowHandle() const; // Private slot in QWidget
269 
270  QScreen *associatedScreen() const;
271 
272  template <typename T>
273  void repaint(T t);
274 
275  template <typename T>
276  void update(T t);
277 
278  void init(QWidget *desktopWidget, Qt::WindowFlags f);
279  void create();
280  void createRecursively();
281  void createWinId();
282 
283  bool setScreenForPoint(const QPoint &pos);
284  bool setScreen(QScreen *screen);
285 
286  void createTLExtra();
287  void createExtra();
288  void deleteExtra();
289  void createSysExtra();
290  void deleteSysExtra();
291  void createTLSysExtra();
292  void deleteTLSysExtra();
293  void updateSystemBackground();
294  void propagatePaletteChange();
295 
296  void setPalette_helper(const QPalette &);
297  void resolvePalette();
298  QPalette naturalWidgetPalette(QPalette::ResolveMask inheritedMask) const;
299 
300  void setMask_sys(const QRegion &);
301 
302  void raise_sys();
303  void lower_sys();
304  void stackUnder_sys(QWidget *);
305 
306  QWidget *deepestFocusProxy() const;
307  void setFocus_sys();
308  void updateFocusChild();
309 
310  void updateFont(const QFont &);
311  inline void setFont_helper(const QFont &font) {
312  if (directFontResolveMask == font.resolveMask() && data.fnt == font)
313  return;
314  updateFont(font);
315  }
316  QFont localFont() const;
317  void resolveFont();
318  QFont naturalWidgetFont(uint inheritedMask) const;
319 
320  void setLayoutDirection_helper(Qt::LayoutDirection);
321  void resolveLayoutDirection();
322 
323  void setLocale_helper(const QLocale &l, bool forceUpdate = false);
324  void resolveLocale();
325 
326  void setStyle_helper(QStyle *newStyle, bool propagate);
327  void inheritStyle();
328 
329  void setUpdatesEnabled_helper(bool );
330 
331  bool updateBrushOrigin(QPainter *, const QBrush &brush) const;
332  void paintBackground(QPainter *, const QRegion &, DrawWidgetFlags flags = DrawAsRoot) const;
333  bool isAboutToShow() const;
334  QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
335  void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion,
336  QWidget::RenderFlags renderFlags);
337  void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion,
338  QWidget::RenderFlags renderFlags);
339  void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags,
340  QPainter *sharedPainter = nullptr, QWidgetRepaintManager *repaintManager = nullptr);
341  void sendPaintEvent(const QRegion &toBePainted);
342 
343 
344  void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& children, int index,
345  const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags,
347 
348 #if QT_CONFIG(graphicsview)
349  static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin);
350 #endif
351  bool shouldPaintOnScreen() const;
352  void paintOnScreen(const QRegion &rgn);
353 
354  QRect clipRect() const;
355  QRegion clipRegion() const;
356  void setSystemClip(QPaintEngine *paintEngine, qreal devicePixelRatio, const QRegion &region);
357  void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const;
358  void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove = nullptr,
359  bool alsoNonOpaque = false) const;
360  void clipToEffectiveMask(QRegion &region) const;
361  void updateIsOpaque();
362  void setOpaque(bool opaque);
363  void updateIsTranslucent();
364 #if QT_CONFIG(graphicseffect)
365  void invalidateGraphicsEffectsRecursively();
366 #endif // QT_CONFIG(graphicseffect)
367 
368  const QRegion &getOpaqueChildren() const;
369  void setDirtyOpaqueRegion();
370 
371  bool close();
372  enum CloseMode {
375  CloseWithSpontaneousEvent
376  };
377  Q_ENUM(CloseMode)
378  bool handleClose(CloseMode mode);
379 
380  void setWindowIcon_helper();
381  void setWindowIcon_sys();
382  void setWindowOpacity_sys(qreal opacity);
383  void adjustQuitOnCloseAttribute();
384 
385  void scrollChildren(int dx, int dy);
386  void moveRect(const QRect &, int dx, int dy);
387  void scrollRect(const QRect &, int dx, int dy);
388  void invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
389 
390  template <class T>
391  void invalidateBackingStore(const T &);
392 
393  QRegion overlappedRegion(const QRect &rect, bool breakAfterFirst = false) const;
394  bool isOverlapped(const QRect &rect) const { return !overlappedRegion(rect, true).isEmpty(); }
395  void syncBackingStore();
396  void syncBackingStore(const QRegion &region);
397 
398  bool shouldDiscardSyncRequest() const;
399 
400  // tells the input method about the widgets transform
401  void updateWidgetTransform(QEvent *event);
402 
403  void reparentFocusWidgets(QWidget *oldtlw);
404 
405  void setWinId(WId);
406  void showChildren(bool spontaneous);
407  void hideChildren(bool spontaneous);
408  void setParent_sys(QWidget *parent, Qt::WindowFlags);
409  void scroll_sys(int dx, int dy);
410  void scroll_sys(int dx, int dy, const QRect &r);
411  void deactivateWidgetCleanup();
412  void setGeometry_sys(int, int, int, int, bool);
413  void fixPosIncludesFrame();
414  void sendPendingMoveAndResizeEvents(bool recursive = false, bool disableUpdates = false);
415  void activateChildLayoutsRecursively();
416  void show_recursive();
417  void show_helper();
418  void show_sys();
419  void hide_sys();
420  void hide_helper();
421  void _q_showIfNotHidden();
422  void setVisible(bool);
423 
424  void setEnabled_helper(bool);
425  static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = nullptr);
426 
427  void updateFrameStrut();
428  QRect frameStrut() const;
429 
430 #ifdef QT_KEYPAD_NAVIGATION
431  static bool navigateToDirection(Direction direction);
432  static QWidget *widgetInNavigationDirection(Direction direction);
433  static bool canKeypadNavigate(Qt::Orientation orientation);
434  static bool inTabWidget(QWidget *widget);
435 #endif
436 
437  void setWindowIconText_sys(const QString &cap);
438  void setWindowIconText_helper(const QString &cap);
439  void setWindowTitle_sys(const QString &cap);
440  void setWindowFilePath_sys(const QString &filePath);
441 
442 #ifndef QT_NO_CURSOR
443  void setCursor_sys(const QCursor &cursor);
444  void unsetCursor_sys();
445 #endif
446 
447  void setWindowTitle_helper(const QString &cap);
448  void setWindowFilePath_helper(const QString &filePath);
449  void setWindowModified_helper();
450  virtual void setWindowFlags(Qt::WindowFlags windowFlags);
451 
452  bool setMinimumSize_helper(int &minw, int &minh);
453  bool setMaximumSize_helper(int &maxw, int &maxh);
454  void setConstraints_sys();
455  bool pointInsideRectAndMask(const QPoint &) const;
456  QWidget *childAt_helper(const QPoint &, bool) const;
457  QWidget *childAtRecursiveHelper(const QPoint &p, bool) const;
458  void updateGeometry_helper(bool forceUpdate);
459 
460  void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const;
461  void setLayoutItemMargins(int left, int top, int right, int bottom);
462  void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = nullptr);
463 
464  void updateContentsRect();
465  QMargins safeAreaMargins() const;
466 
467  // aboutToDestroy() is called just before the contents of
468  // QWidget::destroy() is executed. It's used to signal QWidget
469  // sub-classes that their internals are about to be released.
470  virtual void aboutToDestroy() {}
471 
473  QWidget *w = q_func();
474  while (w->focusProxy())
475  w = w->focusProxy();
476  return w;
477  }
478 
479  void setModal_sys();
480 
481  // These helper functions return the (available) geometry for the screen
482  // the widget is on, and takes care if this one is embedded in a QGraphicsView.
484  {
485 #if QT_CONFIG(graphicsview)
486  QGraphicsProxyWidget *ancestorProxy = widget->d_func()->nearestGraphicsProxyWidget(widget);
487  //It's embedded if it has an ancestor
488  if (ancestorProxy) {
489  if (!bypassGraphicsProxyWidget(widget) && ancestorProxy->scene() != nullptr) {
490  if (!ancestorProxy->scene()->views().empty()) {
491  return ancestorProxy->scene()->views().at(0);
492  }
493  }
494  }
495 #else
496  Q_UNUSED(widget);
497 #endif
498  return nullptr;
499  }
500 
502  {
503  return screenGeometry(widget, QPoint(), false);
504  }
505 
507  {
508  return availableScreenGeometry(widget, QPoint(), false);
509  }
510 
511  static QScreen *screen(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
512  {
513  while (QWidget *view = parentGraphicsView(widget))
514  widget = view;
515 
516  QScreen *screen = nullptr;
517  if (hasPosition)
518  screen = widget->screen()->virtualSiblingAt(globalPosition);
519  if (!screen)
520  screen = widget->screen();
521 
522  return screen;
523  }
524 
525  static QRect screenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
526  {
527  return screen(widget, globalPosition, hasPosition)->geometry();
528  }
529 
530  static QRect availableScreenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition = true)
531  {
532  return screen(widget, globalPosition, hasPosition)->availableGeometry();
533  }
534 
535  inline void setRedirected(QPaintDevice *replacement, const QPoint &offset)
536  {
537  Q_ASSERT(q_func()->testAttribute(Qt::WA_WState_InPaintEvent));
538  redirectDev = replacement;
539  redirectOffset = offset;
540  }
541 
543  {
544  if (offset)
545  *offset = redirectDev ? redirectOffset : QPoint();
546  return redirectDev;
547  }
548 
549  inline void restoreRedirected()
550  { redirectDev = nullptr; }
551 
552  inline void enforceNativeChildren()
553  {
554  if (!extra)
555  createExtra();
556 
557  if (extra->nativeChildrenForced)
558  return;
559  extra->nativeChildrenForced = 1;
560 
561  for (int i = 0; i < children.size(); ++i) {
562  if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
563  child->setAttribute(Qt::WA_NativeWindow);
564  }
565  }
566 
567  inline bool nativeChildrenForced() const
568  {
569  return extra ? extra->nativeChildrenForced : false;
570  }
571 
572  inline QRect effectiveRectFor(const QRegion &region) const
573  {
574  return effectiveRectFor(region.boundingRect());
575  }
576 
577  inline QRect effectiveRectFor(const QRect &rect) const
578  {
579 #if QT_CONFIG(graphicseffect)
580  if (graphicsEffect && graphicsEffect->isEnabled())
581  return graphicsEffect->boundingRectFor(rect).toAlignedRect();
582 #endif // QT_CONFIG(graphicseffect)
583  return rect;
584  }
585 
586  QSize adjustedSize() const;
587 
588  inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
589  {
590  if (button == Qt::LeftButton)
591  handleSoftwareInputPanel(clickCausedFocus);
592  }
593 
594  inline void handleSoftwareInputPanel(bool clickCausedFocus = false)
595  {
596  Q_Q(QWidget);
597  if (qApp->autoSipEnabled()) {
599  q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
600  if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
602  }
603  }
604  }
605 
606  void setWSGeometry();
607 
608  inline QPoint mapToWS(const QPoint &p) const
609  { return p - data.wrect.topLeft(); }
610 
611  inline QPoint mapFromWS(const QPoint &p) const
612  { return p + data.wrect.topLeft(); }
613 
614  inline QRect mapToWS(const QRect &r) const
615  { return r.translated(-data.wrect.topLeft()); }
616 
617  inline QRect mapFromWS(const QRect &r) const
618  { return r.translated(data.wrect.topLeft()); }
619 
620  QOpenGLContext *shareContext() const;
621 
622  virtual QObject *focusObject() { return nullptr; }
623 
624 #ifndef QT_NO_OPENGL
625  virtual GLuint textureId() const { return 0; }
627  Q_Q(QWidget);
628  return q->testAttribute(Qt::WA_AlwaysStackOnTop)
631  }
632  virtual QImage grabFramebuffer() { return QImage(); }
633  virtual void beginBackingStorePainting() { }
634  virtual void endBackingStorePainting() { }
635  virtual void beginCompose() { }
636  virtual void endCompose() { }
637  void setRenderToTexture() { renderToTexture = true; setTextureChildSeen(); }
639  {
640  Q_Q(QWidget);
641  if (textureChildSeen)
642  return;
643  textureChildSeen = 1;
644 
645  if (!q->isWindow()) {
646  QWidget *parent = q->parentWidget();
647  if (parent)
648  get(parent)->setTextureChildSeen();
649  }
650  }
651  static void sendComposeStatus(QWidget *w, bool end);
652  // Called on setViewport().
653  virtual void initializeViewportFramebuffer() { }
654  // When using a QOpenGLWidget as viewport with QAbstractScrollArea, resize events are
655  // filtered away from the widget. This is fine for QGLWidget but bad for QOpenGLWidget
656  // since the fbo must be resized. We need an alternative way to notify.
657  virtual void resizeViewportFramebuffer() { }
658  // Called after each paint event.
659  virtual void resolveSamples() { }
660 #endif
661 
662  static void setWidgetParentHelper(QObject *widgetAsObject, QObject *newParent);
663 
664  // Variables.
665  // Regular pointers (keep them together to avoid gaps on 64 bit architectures).
666  std::unique_ptr<QWExtra> extra;
675  mutable const QMetaObject *polished;
677  // All widgets are added into the allWidgets set. Once
678  // they receive a window id they are also added to the mapper.
679  // This should just ensure that all widgets are deleted by QApplication
682 #if !defined(QT_NO_IM)
683  Qt::InputMethodHints imHints;
684 #endif
685 #ifdef QT_KEYPAD_NAVIGATION
686  static QPointer<QWidget> editingWidget;
687 #endif
688 
689  // Implicit pointers (shared_null/shared_empty).
692 #if QT_CONFIG(tooltip)
693  QString toolTip;
694  int toolTipDuration;
695 #endif
696 #if QT_CONFIG(statustip)
697  QString statusTip;
698 #endif
699 #if QT_CONFIG(whatsthis)
700  QString whatsThis;
701 #endif
702 #ifndef QT_NO_ACCESSIBILITY
705 #endif
706 
707  // Other variables.
710  decltype(std::declval<QPalette>().resolveMask()) directPaletteResolveMask;
711  QPalette::ResolveMask inheritedPaletteResolveMask;
712  short leftmargin;
713  short topmargin;
714  short rightmargin;
715  short bottommargin;
716  signed char leftLayoutItemMargin;
717  signed char topLayoutItemMargin;
718  signed char rightLayoutItemMargin;
719  signed char bottomLayoutItemMargin;
720  static int instanceCounter; // Current number of widget instances
721  static int maxInstances; // Maximum number of widget instances
722  Qt::HANDLE hd;
724  QSizePolicy size_policy;
725  QLocale locale;
726  QPoint redirectOffset;
727 #ifndef QT_NO_ACTION
729 #endif
730 #ifndef QT_NO_GESTURES
732 #endif
733 
734  // Bit fields.
735  uint high_attributes[4]; // the low ones are in QWidget::widget_attributes
748 #ifndef QT_NO_IM
750 #endif
751 #ifndef QT_NO_OPENGL
754 #endif
757 
758  // *************************** Platform specific ************************************
759 #if defined(Q_OS_WIN)
760  uint noPaintOnScreen : 1; // see qwidget.cpp ::paintEngine()
761 #elif defined(Q_OS_MAC)
762  void macUpdateSizeAttribute();
763 #endif
764  void setNetWmWindowTypes(bool skipIfMissing = false);
765 
766  bool stealKeyboardGrab(bool grab);
767  bool stealMouseGrab(bool grab);
768 };
769 
770 Q_DECLARE_OPERATORS_FOR_FLAGS(QWidgetPrivate::DrawWidgetFlags)
771 
773 {
774  inline QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, QWidgetPrivate::DrawWidgetFlags f,
776  : pdev(d), rgn(r), offset(o), flags(f), sharedPainter(p), repaintManager(rpm), painter(nullptr) {}
777 
781  QWidgetPrivate::DrawWidgetFlags flags;
785 };
786 
787 #if QT_CONFIG(graphicseffect)
788 class QWidgetEffectSourcePrivate : public QGraphicsEffectSourcePrivate
789 {
790 public:
791  QWidgetEffectSourcePrivate(QWidget *widget)
792  : QGraphicsEffectSourcePrivate(), m_widget(widget), context(nullptr), updateDueToGraphicsEffect(false)
793  {}
794 
795  void detach() override
796  { m_widget->d_func()->graphicsEffect = nullptr; }
797 
798  const QGraphicsItem *graphicsItem() const override
799  { return nullptr; }
800 
801  const QWidget *widget() const override
802  { return m_widget; }
803 
804  void update() override
805  {
806  updateDueToGraphicsEffect = true;
807  m_widget->update();
808  updateDueToGraphicsEffect = false;
809  }
810 
811  bool isPixmap() const override
812  { return false; }
813 
814  void effectBoundingRectChanged() override
815  {
816  // ### This function should take a rect parameter; then we can avoid
817  // updating too much on the parent widget.
818  if (QWidget *parent = m_widget->parentWidget())
819  parent->update();
820  else
821  update();
822  }
823 
824  const QStyleOption *styleOption() const override
825  { return nullptr; }
826 
827  QRect deviceRect() const override
828  { return m_widget->window()->rect(); }
829 
830  QRectF boundingRect(Qt::CoordinateSystem system) const override;
831  void draw(QPainter *p) override;
833  QGraphicsEffect::PixmapPadMode mode) const override;
834 
835  QWidget *m_widget;
837  QTransform lastEffectTransform;
838  bool updateDueToGraphicsEffect;
839 };
840 #endif // QT_CONFIG(graphicseffect)
841 
843 {
844  return extra.get();
845 }
846 
848 {
849  const_cast<QWidgetPrivate *>(this)->createTLExtra();
850  return extra->topextra.get();
851 }
852 
854 {
855  return extra ? extra->topextra.get() : nullptr;
856 }
857 
859 {
860  Q_Q(const QWidget);
861  QTLWExtra *x = q->window()->d_func()->maybeTopData();
862  return x ? x->sharedPainter : nullptr;
863 }
864 
866 {
867  Q_Q(QWidget);
868  QTLWExtra *x = q->window()->d_func()->topData();
869  x->sharedPainter = painter;
870 }
871 
873 {
874  Q_Q(const QWidget);
875  return q->rect().contains(p) && (!extra || !extra->hasMask || q->testAttribute(Qt::WA_MouseNoMask)
876  || extra->mask.contains(p));
877 }
878 
880 {
881  Q_Q(const QWidget);
882  QTLWExtra *x = q->window()->d_func()->maybeTopData();
883  return x ? x->repaintManager.get() : nullptr;
884 }
885 
887 
888 #endif // QWIDGET_P_H
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
QWidgetRepaintManager * repaintManager(QWidget &widget)
The QBackingStore class provides a drawing area for QWindow.
Definition: qbackingstore.h:60
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:66
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:81
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
@ UpdateLater
Definition: qcoreevent.h:127
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
uint resolveMask() const
Definition: qfont.h:274
The QGraphicsEffect class is the base class for all graphics effects.
virtual const QStyleOption * styleOption() const =0
virtual bool isPixmap() const =0
virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset=nullptr, QGraphicsEffect::PixmapPadMode mode=QGraphicsEffect::PadToTransparentBorder) const =0
virtual const QGraphicsItem * graphicsItem() const =0
virtual QRectF boundingRect(Qt::CoordinateSystem system) const =0
virtual const QWidget * widget() const =0
virtual void draw(QPainter *p)=0
virtual QRect deviceRect() const =0
virtual void effectBoundingRectChanged()=0
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:83
QGraphicsScene * scene() const
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene.
QList< QGraphicsView * > views() const
static QInputMethod * inputMethod()
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:73
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:62
bool empty() const noexcept
Definition: qlist.h:697
const_reference at(qsizetype i) const noexcept
Definition: qlist.h:457
The QMargins class defines the four margins of a rectangle.
Definition: qmargins.h:52
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
ExtraData * extraData
Definition: qobject_p.h:414
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:368
The QOpenGLContext class represents a native OpenGL context, enabling OpenGL rendering on a QSurface.
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:87
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:82
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:55
quint64 ResolveMask
Definition: qpalette.h:146
The QPixmap class is an off-screen image representation that can be used as a paint device.
Definition: qpixmap.h:63
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
constexpr QRect translated(int dx, int dy) const noexcept
Definition: qrect.h:288
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:63
QRect boundingRect() const noexcept
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition: qscreen.h:68
QRect availableGeometry
the screen's available geometry in pixels
Definition: qscreen.h:82
QRect geometry
the screen's geometry in pixels
Definition: qscreen.h:81
QScreen * virtualSiblingAt(QPoint point)
Definition: qscreen.cpp:716
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition: qsizepolicy.h:54
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition: qstyle.h:65
@ SH_RequestSoftwareInputPanel
Definition: qstyle.h:714
RequestSoftwareInputPanel
Definition: qstyle.h:612
@ RSIP_OnMouseClick
Definition: qstyle.h:614
SubElement
Definition: qstyle.h:278
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:75
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:56
QUpdateLaterEvent(const QRegion &paintRegion)
Definition: qwidget_p.h:109
const QRegion & region() const
Definition: qwidget_p.h:118
QRegion m_region
Definition: qwidget_p.h:121
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
QScreen * screen() const
Definition: qwidget.cpp:2508
uint mustHaveWindowHandle
Definition: qwidget_p.h:745
uint inDirtyList
Definition: qwidget_p.h:741
uint dirtyOpaqueChildren
Definition: qwidget_p.h:738
const QMetaObject * polished
Definition: qwidget_p.h:675
QTLWExtra * maybeTopData() const
Definition: qwidget_p.h:853
QRegion * needsFlush
Definition: qwidget_p.h:671
uint inheritedFontResolveMask
Definition: qwidget_p.h:709
QWidget * focus_next
Definition: qwidget_p.h:667
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
Definition: qwidget_p.h:731
bool isOverlapped(const QRect &rect) const
Definition: qwidget_p.h:394
QRect mapFromWS(const QRect &r) const
Definition: qwidget_p.h:617
QList< QAction * > actions
Definition: qwidget_p.h:728
void createTLExtra()
Definition: qwidget.cpp:1574
uint usesDoubleBufferedGLContext
Definition: qwidget_p.h:744
uint childrenHiddenByWState
Definition: qwidget_p.h:755
virtual void beginBackingStorePainting()
Definition: qwidget_p.h:633
static const QWidgetPrivate * get(const QWidget *w)
Definition: qwidget_p.h:253
uint childrenShownByExpose
Definition: qwidget_p.h:756
virtual QImage grabFramebuffer()
Definition: qwidget_p.h:632
uint renderToTextureReallyDirty
Definition: qwidget_p.h:752
virtual void endBackingStorePainting()
Definition: qwidget_p.h:634
QRect effectiveRectFor(const QRect &rect) const
Definition: qwidget_p.h:577
QPaintDevice * redirectDev
Definition: qwidget_p.h:672
static QWidgetMapper * mapper
Definition: qwidget_p.h:680
void restoreRedirected()
Definition: qwidget_p.h:549
QString accessibleDescription
Definition: qwidget_p.h:704
void setSharedPainter(QPainter *painter)
Definition: qwidget_p.h:865
QPaintDevice * redirected(QPoint *offset) const
Definition: qwidget_p.h:542
uint retainSizeWhenHiddenChanged
Definition: qwidget_p.h:740
virtual QObject * focusObject()
Definition: qwidget_p.h:622
QPalette::ColorRole bg_role
Definition: qwidget_p.h:737
uint inheritsInputMethodHints
Definition: qwidget_p.h:749
QPoint mapFromWS(const QPoint &p) const
Definition: qwidget_p.h:611
QPoint mapToWS(const QPoint &p) const
Definition: qwidget_p.h:608
static QWidgetPrivate * get(QWidget *w)
Definition: qwidget_p.h:252
QWidgetRepaintManager * maybeRepaintManager() const
Definition: qwidget_p.h:879
void handleSoftwareInputPanel(bool clickCausedFocus=false)
Definition: qwidget_p.h:594
virtual void aboutToDestroy()
Definition: qwidget_p.h:470
QPaintEngine * extraPaintEngine
Definition: qwidget_p.h:674
static QRect screenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition=true)
Definition: qwidget_p.h:525
std::unique_ptr< QWExtra > extra
Definition: qwidget_p.h:666
bool nativeChildrenForced() const
Definition: qwidget_p.h:567
QRect mapToWS(const QRect &r) const
Definition: qwidget_p.h:614
virtual void resizeViewportFramebuffer()
Definition: qwidget_p.h:657
QWidget * effectiveFocusWidget()
Definition: qwidget_p.h:472
void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
Definition: qwidget_p.h:588
QRegion dirty
Definition: qwidget_p.h:691
QGraphicsEffect * graphicsEffect
Definition: qwidget_p.h:676
uint textureChildSeen
Definition: qwidget_p.h:747
QString accessibleName
Definition: qwidget_p.h:703
void setRedirected(QPaintDevice *replacement, const QPoint &offset)
Definition: qwidget_p.h:535
static QRect availableScreenGeometry(const QWidget *widget, const QPoint &globalPosition, bool hasPosition=true)
Definition: qwidget_p.h:530
virtual GLuint textureId() const
Definition: qwidget_p.h:625
QWidget * focus_child
Definition: qwidget_p.h:669
QPalette::ColorRole fg_role
Definition: qwidget_p.h:736
virtual void beginCompose()
Definition: qwidget_p.h:635
QRegion opaqueChildren
Definition: qwidget_p.h:690
bool pointInsideRectAndMask(const QPoint &) const
Definition: qwidget_p.h:872
QWidgetItemV2 * widgetItem
Definition: qwidget_p.h:673
virtual void resolveSamples()
Definition: qwidget_p.h:659
static QWidget * parentGraphicsView(const QWidget *widget)
Definition: qwidget_p.h:483
void enforceNativeChildren()
Definition: qwidget_p.h:552
QWExtra * extraData() const
Definition: qwidget_p.h:842
void setRenderToTexture()
Definition: qwidget_p.h:637
static QRect screenGeometry(const QWidget *widget)
Definition: qwidget_p.h:501
uint renderToTexture
Definition: qwidget_p.h:746
QRect effectiveRectFor(const QRegion &region) const
Definition: qwidget_p.h:572
QWidget * focus_prev
Definition: qwidget_p.h:668
virtual void initializeViewportFramebuffer()
Definition: qwidget_p.h:653
uint renderToTextureComposeActive
Definition: qwidget_p.h:753
QTLWExtra * topData() const
Definition: qwidget_p.h:847
QPainter * sharedPainter() const
Definition: qwidget_p.h:858
uint directFontResolveMask
Definition: qwidget_p.h:708
virtual QPlatformTextureList::Flags textureListFlags()
Definition: qwidget_p.h:626
Qt::InputMethodHints imHints
Definition: qwidget_p.h:683
void setFont_helper(const QFont &font)
Definition: qwidget_p.h:311
static QScreen * screen(const QWidget *widget, const QPoint &globalPosition, bool hasPosition=true)
Definition: qwidget_p.h:511
static QRect availableScreenGeometry(const QWidget *widget)
Definition: qwidget_p.h:506
void setTextureChildSeen()
Definition: qwidget_p.h:638
virtual void endCompose()
Definition: qwidget_p.h:636
QLayout * layout
Definition: qwidget_p.h:670
static QWidgetSet * allWidgets
Definition: qwidget_p.h:681
The QWindow class represents a window in the underlying windowing system.
Definition: qwindow.h:99
QOpenGLWidget * widget
[1]
QPushButton * button
[2]
QCursor cursor
rect
[4]
direction
QStyleOptionButton opt
int const char * version
Definition: zlib.h:814
Definition: qnamespace.h:55
MouseButton
Definition: qnamespace.h:81
@ LeftButton
Definition: qnamespace.h:83
@ WA_AlwaysStackOnTop
Definition: qnamespace.h:436
@ WA_NativeWindow
Definition: qnamespace.h:403
@ WA_WState_InPaintEvent
Definition: qnamespace.h:354
@ WA_MouseNoMask
Definition: qnamespace.h:363
LayoutDirection
Definition: qnamespace.h:1462
Orientation
Definition: qnamespace.h:123
void * HANDLE
Definition: qnamespace.h:1561
CoordinateSystem
Definition: qnamespace.h:1615
@ BypassGraphicsProxyWidget
Definition: qnamespace.h:268
ShortcutContext
Definition: qnamespace.h:1313
Definition: brush.cpp:52
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld init[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
#define qApp
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition: qflags.h:210
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition: qflags.h:227
Flags
unsigned short quint16
Definition: qglobal.h:286
int qint32
Definition: qglobal.h:287
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
unsigned int uint
Definition: qglobal.h:334
@ QObjectPrivateVersion
Definition: qobject_p.h:86
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLboolean r
[2]
GLfloat GLfloat GLfloat w
[0]
GLuint index
[2]
GLuint GLuint end
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLfloat GLfloat f
GLint left
GLint GLint bottom
GLenum target
GLbitfield flags
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
typedef GLuint(GL_APIENTRYP PFNGLGETDEBUGMESSAGELOGKHRPROC)(GLuint count
GLsizei GLsizei GLchar * source
struct _cl_event * event
Definition: qopenglext.h:2998
GLdouble GLdouble t
[9]
Definition: qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition: qopenglext.h:259
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
GLenum cap
Definition: qopenglext.h:8893
#define Q_ASSERT(cond)
Definition: qrandom.cpp:84
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_FLAG(x)
Definition: qtmetamacros.h:105
#define Q_GADGET
Definition: qtmetamacros.h:193
QWidget * qobject_cast< QWidget * >(QObject *o)
Definition: qwidget.h:819
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcWidgetPainting)
bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
QT_BEGIN_NAMESPACE typedef QHash< WId, QWidget * > QWidgetMapper
Definition: qwindowdefs.h:104
Q_UNUSED(salary)
[21]
QScreen * screen
[1]
Definition: main.cpp:76
QObject::connect nullptr
QLayoutItem * child
[0]
QPainter painter(this)
[7]
myWidget render(this)
QQuickView * view
[0]
view create()
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:165
QRect frameStrut
Definition: qwidget_p.h:147
QString role
Definition: qwidget_p.h:140
QString iconText
Definition: qwidget_p.h:139
QString caption
Definition: qwidget_p.h:138
std::unique_ptr< QWidgetRepaintManager > repaintManager
Definition: qwidget_p.h:129
std::unique_ptr< QOpenGLContext > shareContext
Definition: qwidget_p.h:134
uint posIncludesFrame
Definition: qwidget_p.h:158
QRect normalGeometry
Definition: qwidget_p.h:148
Qt::WindowFlags savedFlags
Definition: qwidget_p.h:149
QPainter * sharedPainter
Definition: qwidget_p.h:131
std::unique_ptr< QIcon > icon
Definition: qwidget_p.h:128
uint opacity
Definition: qwidget_p.h:157
std::vector< std::unique_ptr< QPlatformTextureList > > widgetTextures
Definition: qwidget_p.h:153
uint sizeAdjusted
Definition: qwidget_p.h:159
short baseh
Definition: qwidget_p.h:145
QScreen * initialScreen
Definition: qwidget_p.h:150
QBackingStore * backingStore
Definition: qwidget_p.h:130
QString filePath
Definition: qwidget_p.h:141
short inch
Definition: qwidget_p.h:144
short basew
Definition: qwidget_p.h:145
QWidgetWindow * window
Definition: qwidget_p.h:132
uint embedded
Definition: qwidget_p.h:160
short incw
Definition: qwidget_p.h:144
uint hasMask
Definition: qwidget_p.h:197
uint hasWindowContainer
Definition: qwidget_p.h:198
QString styleSheet
Definition: qwidget_p.h:180
QRegion mask
Definition: qwidget_p.h:179
qint32 minw
Definition: qwidget_p.h:183
QSize staticContentsSize
Definition: qwidget_p.h:189
QPointer< QWidget > focus_proxy
Definition: qwidget_p.h:176
uint inRenderWithPainter
Definition: qwidget_p.h:196
qint32 maxh
Definition: qwidget_p.h:186
quint16 customDpiY
Definition: qwidget_p.h:188
uint nativeChildrenForced
Definition: qwidget_p.h:195
quint16 customDpiX
Definition: qwidget_p.h:187
std::unique_ptr< QTLWExtra > topextra
Definition: qwidget_p.h:168
void * glContext
Definition: qwidget_p.h:167
std::unique_ptr< QCursor > curs
Definition: qwidget_p.h:173
uint explicitMinSize
Definition: qwidget_p.h:192
uint autoFillBackground
Definition: qwidget_p.h:194
QPointer< QStyle > style
Definition: qwidget_p.h:175
uint explicitMaxSize
Definition: qwidget_p.h:193
qint32 maxw
Definition: qwidget_p.h:185
qint32 minh
Definition: qwidget_p.h:184
QWidgetRepaintManager * repaintManager
Definition: qwidget_p.h:783
QPainter * painter
Definition: qwidget_p.h:784
QWidgetPaintContext(QPaintDevice *d, const QRegion &r, const QPoint &o, QWidgetPrivate::DrawWidgetFlags f, QPainter *p, QWidgetRepaintManager *rpm)
Definition: qwidget_p.h:774
QPaintDevice * pdev
Definition: qwidget_p.h:778
QWidgetPrivate::DrawWidgetFlags flags
Definition: qwidget_p.h:781
QPainter * sharedPainter
Definition: qwidget_p.h:782
Definition: main.cpp:38
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
Direction
Definition: main.cpp:217