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
63QT_REQUIRE_CONFIG(graphicsview);
64
65QT_BEGIN_NAMESPACE
66
67class QGraphicsLayout;
68class QStyleOptionTitleBar;
69
70class QGraphicsWidgetPrivate : public QGraphicsItemPrivate
71{
72 Q_DECLARE_PUBLIC(QGraphicsWidget)
73public:
74 QGraphicsWidgetPrivate();
75 virtual ~QGraphicsWidgetPrivate();
76
77 void init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags);
78 qreal titleBarHeight(const QStyleOptionTitleBar &options) const;
79
80 // Margins
81 enum {Left, Top, Right, Bottom};
82 mutable qreal *margins;
83 void ensureMargins() const;
84
85 void fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene = nullptr);
86 void setLayout_helper(QGraphicsLayout *l);
87
88 // Layouts
89 QGraphicsLayout *layout;
90 void setLayoutDirection_helper(Qt::LayoutDirection direction);
91 void resolveLayoutDirection();
92
93 // Style
94 QPalette palette;
95 uint inheritedPaletteResolveMask;
96 void setPalette_helper(const QPalette &palette);
97 void resolvePalette(uint inheritedMask) override;
98 void updatePalette(const QPalette &palette);
99 QPalette naturalWidgetPalette() const;
100 QFont font;
101 uint inheritedFontResolveMask;
102 void setFont_helper(const QFont &font);
103 void resolveFont(uint inheritedMask) override;
104 void updateFont(const QFont &font);
105 QFont naturalWidgetFont() const;
106
107 // Window specific
108 void initStyleOptionTitleBar(QStyleOptionTitleBar *option);
109 void adjustWindowFlags(Qt::WindowFlags *wFlags);
110 void windowFrameMouseReleaseEvent(QGraphicsSceneMouseEvent *event);
111 void windowFrameMousePressEvent(QGraphicsSceneMouseEvent *event);
112 void windowFrameMouseMoveEvent(QGraphicsSceneMouseEvent *event);
113 void windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent *event);
114 void windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent *event);
115 bool hasDecoration() const;
116
117 // Private Properties
118 qreal width() const override;
119 void setWidth(qreal) override;
120 void resetWidth() override;
121
122 qreal height() const override;
123 void setHeight(qreal) override;
124 void resetHeight() override;
125 void setGeometryFromSetPos();
126
127 // State
128 inline int attributeToBitIndex(Qt::WidgetAttribute att) const
129 {
130 int bit = -1;
131 switch (att) {
132 case Qt::WA_SetLayoutDirection: bit = 0; break;
133 case Qt::WA_RightToLeft: bit = 1; break;
134 case Qt::WA_SetStyle: bit = 2; break;
135 case Qt::WA_Resized: bit = 3; break;
136 case Qt::WA_DeleteOnClose: bit = 4; break;
137 case Qt::WA_NoSystemBackground: bit = 5; break;
138 case Qt::WA_OpaquePaintEvent: bit = 6; break;
139 case Qt::WA_SetPalette: bit = 7; break;
140 case Qt::WA_SetFont: bit = 8; break;
141 case Qt::WA_WindowPropagation: bit = 9; break;
142 default: break;
143 }
144 return bit;
145 }
146 inline void setAttribute(Qt::WidgetAttribute att, bool value)
147 {
148 int bit = attributeToBitIndex(att);
149 if (bit == -1) {
150 qWarning("QGraphicsWidget::setAttribute: unsupported attribute %d", int(att));
151 return;
152 }
153 if (value)
154 attributes |= (1 << bit);
155 else
156 attributes &= ~(1 << bit);
157 }
158 inline bool testAttribute(Qt::WidgetAttribute att) const
159 {
160 int bit = attributeToBitIndex(att);
161 if (bit == -1)
162 return false;
163 return (attributes & (1 << bit)) != 0;
164 }
165 quint32 attributes : 10;
166 quint32 inSetGeometry : 1;
167 quint32 polished: 1;
168 quint32 inSetPos : 1;
169 quint32 autoFillBackground : 1;
170
171 // Focus
172 Qt::FocusPolicy focusPolicy;
173 QGraphicsWidget *focusNext;
174 QGraphicsWidget *focusPrev;
175
176 // Windows
177 Qt::WindowFlags windowFlags;
178 struct WindowData {
179 QString windowTitle;
180 QStyle::SubControl hoveredSubControl;
181 Qt::WindowFrameSection grabbedSection;
182 uint buttonMouseOver : 1;
183 uint buttonSunken : 1;
184 QRectF startGeometry;
185 QRect buttonRect;
186 WindowData()
187 : hoveredSubControl(QStyle::SC_None)
188 , grabbedSection(Qt::NoSection)
189 , buttonMouseOver(false)
190 , buttonSunken(false)
191 {}
192 } *windowData;
193 void ensureWindowData();
194
195 bool setWindowFrameMargins;
196 mutable qreal *windowFrameMargins;
197 void ensureWindowFrameMargins() const;
198
199#ifndef QT_NO_ACTION
200 QList<QAction *> actions;
201#endif
202};
203
204QT_END_NAMESPACE
205
206#endif //QGRAPHICSWIDGET_P_H
207
208