QtBase  v6.3.1
qgraphicswidget_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 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 QGRAPHICSWIDGET_P_H
41 #define QGRAPHICSWIDGET_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 other Qt classes. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtWidgets/private/qtwidgetsglobal_p.h>
55 #include <private/qobject_p.h>
56 #include "qgraphicsitem_p.h"
57 #include "qgraphicswidget.h"
58 #include <QtGui/qfont.h>
59 #include <QtGui/qpalette.h>
60 #include <QtWidgets/qsizepolicy.h>
61 #include <QtWidgets/qstyle.h>
62 
63 #include <memory>
64 
65 QT_REQUIRE_CONFIG(graphicsview);
66 
68 
69 class QGraphicsLayout;
71 
73 {
74  Q_DECLARE_PUBLIC(QGraphicsWidget)
75 public:
77  virtual ~QGraphicsWidgetPrivate();
78 
79  void init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags);
80  qreal titleBarHeight(const QStyleOptionTitleBar &options) const;
81 
82  // Margins
83  mutable std::unique_ptr<QMarginsF> margins;
84  void ensureMargins() const;
85 
86  void fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene = nullptr);
88 
89  // Layouts
93 
94  // Style
97  void setPalette_helper(const QPalette &palette);
98  void resolvePalette(uint inheritedMask) override;
99  void updatePalette(const QPalette &palette);
103  void setFont_helper(const QFont &font);
104  void resolveFont(uint inheritedMask) override;
105  void updateFont(const QFont &font);
106  QFont naturalWidgetFont() const;
107 
108  // Window specific
110  void adjustWindowFlags(Qt::WindowFlags *wFlags);
116  bool hasDecoration() const;
117 
118  // Private Properties
119  qreal width() const override;
120  void setWidth(qreal) override;
121  void resetWidth() override;
122 
123  qreal height() const override;
124  void setHeight(qreal) override;
125  void resetHeight() override;
126  void setGeometryFromSetPos();
127 
128  // State
130  {
131  int bit = -1;
132  switch (att) {
133  case Qt::WA_SetLayoutDirection: bit = 0; break;
134  case Qt::WA_RightToLeft: bit = 1; break;
135  case Qt::WA_SetStyle: bit = 2; break;
136  case Qt::WA_Resized: bit = 3; break;
137  case Qt::WA_DeleteOnClose: bit = 4; break;
138  case Qt::WA_NoSystemBackground: bit = 5; break;
139  case Qt::WA_OpaquePaintEvent: bit = 6; break;
140  case Qt::WA_SetPalette: bit = 7; break;
141  case Qt::WA_SetFont: bit = 8; break;
142  case Qt::WA_WindowPropagation: bit = 9; break;
143  default: break;
144  }
145  return bit;
146  }
147  inline void setAttribute(Qt::WidgetAttribute att, bool value)
148  {
149  int bit = attributeToBitIndex(att);
150  if (bit == -1) {
151  qWarning("QGraphicsWidget::setAttribute: unsupported attribute %d", int(att));
152  return;
153  }
154  if (value)
155  attributes |= (1 << bit);
156  else
157  attributes &= ~(1 << bit);
158  }
159  inline bool testAttribute(Qt::WidgetAttribute att) const
160  {
161  int bit = attributeToBitIndex(att);
162  if (bit == -1)
163  return false;
164  return (attributes & (1 << bit)) != 0;
165  }
171 
172  // Focus
176 
177  // Windows
178  Qt::WindowFlags windowFlags;
179  struct WindowData {
188  : hoveredSubControl(QStyle::SC_None)
192  {}
193  };
194  std::unique_ptr<WindowData> windowData;
195  void ensureWindowData();
196 
198  mutable std::unique_ptr<QMarginsF> windowFrameMargins;
199  void ensureWindowFrameMargins() const;
200 
201 #ifndef QT_NO_ACTION
203 #endif
204 };
205 
207 
208 #endif //QGRAPHICSWIDGET_P_H
209 
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:83
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
void setAttribute(Qt::WidgetAttribute att, bool value)
void windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent *event)
void setFont_helper(const QFont &font)
QGraphicsWidget * focusPrev
void windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent *event)
std::unique_ptr< QMarginsF > margins
void setWidth(qreal) override
void ensureWindowFrameMargins() const
QGraphicsLayout * layout
void updatePalette(const QPalette &palette)
QList< QAction * > actions
void setLayoutDirection_helper(Qt::LayoutDirection direction)
Qt::WindowFlags windowFlags
qreal height() const override
std::unique_ptr< WindowData > windowData
void windowFrameMouseMoveEvent(QGraphicsSceneMouseEvent *event)
Qt::FocusPolicy focusPolicy
bool testAttribute(Qt::WidgetAttribute att) const
qreal titleBarHeight(const QStyleOptionTitleBar &options) const
void updateFont(const QFont &font)
void resolveFont(uint inheritedMask) override
void fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene=nullptr)
void setHeight(qreal) override
void init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags)
void initStyleOptionTitleBar(QStyleOptionTitleBar *option)
QPalette naturalWidgetPalette() const
void setPalette_helper(const QPalette &palette)
qreal width() const override
void windowFrameMousePressEvent(QGraphicsSceneMouseEvent *event)
void resolvePalette(uint inheritedMask) override
std::unique_ptr< QMarginsF > windowFrameMargins
void setLayout_helper(QGraphicsLayout *l)
void adjustWindowFlags(Qt::WindowFlags *wFlags)
QGraphicsWidget * focusNext
int attributeToBitIndex(Qt::WidgetAttribute att) const
void windowFrameMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:55
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
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
SubControl
Definition: qstyle.h:383
the position of the selected tab in relation to this tab
Definition: qstyleoption.h:630
direction
Definition: qnamespace.h:55
WidgetAttribute
Definition: qnamespace.h:307
@ WA_SetLayoutDirection
Definition: qnamespace.h:348
@ WA_SetPalette
Definition: qnamespace.h:328
@ WA_WindowPropagation
Definition: qnamespace.h:374
@ WA_RightToLeft
Definition: qnamespace.h:347
@ WA_Resized
Definition: qnamespace.h:333
@ WA_SetStyle
Definition: qnamespace.h:381
@ WA_NoSystemBackground
Definition: qnamespace.h:316
@ WA_SetFont
Definition: qnamespace.h:329
@ WA_OpaquePaintEvent
Definition: qnamespace.h:312
@ WA_DeleteOnClose
Definition: qnamespace.h:346
LayoutDirection
Definition: qnamespace.h:1462
FocusPolicy
Definition: qnamespace.h:131
WindowFrameSection
Definition: qnamespace.h:1597
@ NoSection
Definition: qnamespace.h:1598
EGLOutputLayerEXT EGLint EGLAttrib value
unsigned int quint32
Definition: qglobal.h:288
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
unsigned int uint
Definition: qglobal.h:334
QT_REQUIRE_CONFIG(graphicsview)
#define qWarning
Definition: qlogging.h:179
struct _cl_event * event
Definition: qopenglext.h:2998
GLuint GLenum option
Definition: qopenglext.h:5929
Qt::WindowFrameSection grabbedSection