1// Copyright (C) 2016 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
4#ifndef QGRAPHICSWIDGET_P_H
5#define QGRAPHICSWIDGET_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include <private/qobject_p.h>
20#include "qgraphicsitem_p.h"
21#include "qgraphicswidget.h"
22#include <QtGui/qfont.h>
23#include <QtGui/qpalette.h>
24#include <QtWidgets/qsizepolicy.h>
25#include <QtWidgets/qstyle.h>
26
27#include <memory>
28
29QT_REQUIRE_CONFIG(graphicsview);
30
31QT_BEGIN_NAMESPACE
32
33class QGraphicsLayout;
34class QStyleOptionTitleBar;
35
36class QGraphicsWidgetPrivate : public QGraphicsItemPrivate
37{
38 Q_DECLARE_PUBLIC(QGraphicsWidget)
39public:
40 QGraphicsWidgetPrivate();
41 virtual ~QGraphicsWidgetPrivate();
42
43 void init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags);
44 qreal titleBarHeight(const QStyleOptionTitleBar &options) const;
45
46 // Margins
47 mutable std::unique_ptr<QMarginsF> margins;
48 void ensureMargins() const;
49
50 void fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene = nullptr);
51 void setLayout_helper(QGraphicsLayout *l);
52
53 // Layouts
54 QGraphicsLayout *layout;
55 void setLayoutDirection_helper(Qt::LayoutDirection direction);
56 void resolveLayoutDirection();
57
58 // Style
59 QPalette palette;
60 uint inheritedPaletteResolveMask;
61 void setPalette_helper(const QPalette &palette);
62 void resolvePalette(uint inheritedMask) override;
63 void updatePalette(const QPalette &palette);
64 QPalette naturalWidgetPalette() const;
65 QFont font;
66 uint inheritedFontResolveMask;
67 void setFont_helper(const QFont &font);
68 void resolveFont(uint inheritedMask) override;
69 void updateFont(const QFont &font);
70 QFont naturalWidgetFont() const;
71
72 // Window specific
73 void initStyleOptionTitleBar(QStyleOptionTitleBar *option);
74 void adjustWindowFlags(Qt::WindowFlags *wFlags);
75 void windowFrameMouseReleaseEvent(QGraphicsSceneMouseEvent *event);
76 void windowFrameMousePressEvent(QGraphicsSceneMouseEvent *event);
77 void windowFrameMouseMoveEvent(QGraphicsSceneMouseEvent *event);
78 void windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent *event);
79 void windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent *event);
80 bool hasDecoration() const;
81
82 // Private Properties
83 qreal width() const override;
84 void setWidth(qreal) override;
85 void resetWidth() override;
86
87 qreal height() const override;
88 void setHeight(qreal) override;
89 void resetHeight() override;
90 void setGeometryFromSetPos();
91
92 // State
93 inline int attributeToBitIndex(Qt::WidgetAttribute att) const
94 {
95 int bit = -1;
96 switch (att) {
97 case Qt::WA_SetLayoutDirection: bit = 0; break;
98 case Qt::WA_RightToLeft: bit = 1; break;
99 case Qt::WA_SetStyle: bit = 2; break;
100 case Qt::WA_Resized: bit = 3; break;
101 case Qt::WA_DeleteOnClose: bit = 4; break;
102 case Qt::WA_NoSystemBackground: bit = 5; break;
103 case Qt::WA_OpaquePaintEvent: bit = 6; break;
104 case Qt::WA_SetPalette: bit = 7; break;
105 case Qt::WA_SetFont: bit = 8; break;
106 case Qt::WA_WindowPropagation: bit = 9; break;
107 default: break;
108 }
109 return bit;
110 }
111 inline void setAttribute(Qt::WidgetAttribute att, bool value)
112 {
113 int bit = attributeToBitIndex(att);
114 if (bit == -1) {
115 qWarning(msg: "QGraphicsWidget::setAttribute: unsupported attribute %d", int(att));
116 return;
117 }
118 if (value)
119 attributes |= (1 << bit);
120 else
121 attributes &= ~(1 << bit);
122 }
123 inline bool testAttribute(Qt::WidgetAttribute att) const
124 {
125 int bit = attributeToBitIndex(att);
126 if (bit == -1)
127 return false;
128 return (attributes & (1 << bit)) != 0;
129 }
130 quint32 attributes : 10;
131 quint32 inSetGeometry : 1;
132 quint32 polished: 1;
133 quint32 inSetPos : 1;
134 quint32 autoFillBackground : 1;
135
136 // Focus
137 Qt::FocusPolicy focusPolicy;
138 QGraphicsWidget *focusNext;
139 QGraphicsWidget *focusPrev;
140
141 // Windows
142 Qt::WindowFlags windowFlags;
143 struct WindowData {
144 QString windowTitle;
145 QStyle::SubControl hoveredSubControl;
146 Qt::WindowFrameSection grabbedSection;
147 uint buttonMouseOver : 1;
148 uint buttonSunken : 1;
149 QRectF startGeometry;
150 QRect buttonRect;
151 WindowData()
152 : hoveredSubControl(QStyle::SC_None)
153 , grabbedSection(Qt::NoSection)
154 , buttonMouseOver(false)
155 , buttonSunken(false)
156 {}
157 };
158 std::unique_ptr<WindowData> windowData;
159 void ensureWindowData();
160
161 bool setWindowFrameMargins;
162 mutable std::unique_ptr<QMarginsF> windowFrameMargins;
163 void ensureWindowFrameMargins() const;
164
165#ifndef QT_NO_ACTION
166 QList<QAction *> actions;
167#endif
168};
169
170QT_END_NAMESPACE
171
172#endif //QGRAPHICSWIDGET_P_H
173
174

source code of qtbase/src/widgets/graphicsview/qgraphicswidget_p.h