1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QGRAPHICSWIDGET_P_H
|
---|
43 | #define QGRAPHICSWIDGET_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists for the convenience
|
---|
50 | // of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
|
---|
51 | // file may change from version to version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include <private/qobject_p.h>
|
---|
57 | #include "qgraphicsitem_p.h"
|
---|
58 | #include "qgraphicswidget.h"
|
---|
59 | #include <QtGui/qfont.h>
|
---|
60 | #include <QtGui/qpalette.h>
|
---|
61 | #include <QtGui/qsizepolicy.h>
|
---|
62 | #include <QtGui/qstyle.h>
|
---|
63 |
|
---|
64 | QT_BEGIN_NAMESPACE
|
---|
65 |
|
---|
66 | class QGraphicsLayout;
|
---|
67 | class QStyleOptionTitleBar;
|
---|
68 |
|
---|
69 | #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
|
---|
70 |
|
---|
71 | class Q_GUI_EXPORT QGraphicsWidgetPrivate : public QGraphicsItemPrivate
|
---|
72 | {
|
---|
73 | Q_DECLARE_PUBLIC(QGraphicsWidget)
|
---|
74 | public:
|
---|
75 | QGraphicsWidgetPrivate()
|
---|
76 | : leftMargin(0),
|
---|
77 | topMargin(0),
|
---|
78 | rightMargin(0),
|
---|
79 | bottomMargin(0),
|
---|
80 | leftLayoutItemMargin(0),
|
---|
81 | topLayoutItemMargin(0),
|
---|
82 | rightLayoutItemMargin(0),
|
---|
83 | bottomLayoutItemMargin(0),
|
---|
84 | layout(0),
|
---|
85 | inheritedPaletteResolveMask(0),
|
---|
86 | inheritedFontResolveMask(0),
|
---|
87 | inSetGeometry(0),
|
---|
88 | polished(0),
|
---|
89 | inSetPos(0),
|
---|
90 | focusPolicy(Qt::NoFocus),
|
---|
91 | focusNext(0),
|
---|
92 | focusPrev(0),
|
---|
93 | focusChild(0),
|
---|
94 | windowFlags(0),
|
---|
95 | hoveredSubControl(QStyle::SC_None),
|
---|
96 | grabbedSection(Qt::NoSection),
|
---|
97 | buttonMouseOver(false),
|
---|
98 | buttonSunken(false),
|
---|
99 | setWindowFrameMargins(false),
|
---|
100 | leftWindowFrameMargin(0),
|
---|
101 | topWindowFrameMargin(0),
|
---|
102 | rightWindowFrameMargin(0),
|
---|
103 | bottomWindowFrameMargin(0)
|
---|
104 | { }
|
---|
105 |
|
---|
106 | void init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags);
|
---|
107 | qreal titleBarHeight(const QStyleOptionTitleBar &options) const;
|
---|
108 |
|
---|
109 | // Margins
|
---|
110 | qreal leftMargin;
|
---|
111 | qreal topMargin;
|
---|
112 | qreal rightMargin;
|
---|
113 | qreal bottomMargin;
|
---|
114 | QRectF contentsRect;
|
---|
115 |
|
---|
116 | // Layout item margins
|
---|
117 | void getLayoutItemMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
|
---|
118 | void setLayoutItemMargins(qreal left, qreal top, qreal right, qreal bottom);
|
---|
119 | void setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt = 0);
|
---|
120 |
|
---|
121 | void fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *newScene = 0);
|
---|
122 | void setLayout_helper(QGraphicsLayout *l);
|
---|
123 |
|
---|
124 | qreal leftLayoutItemMargin;
|
---|
125 | qreal topLayoutItemMargin;
|
---|
126 | qreal rightLayoutItemMargin;
|
---|
127 | qreal bottomLayoutItemMargin;
|
---|
128 |
|
---|
129 | // Layouts
|
---|
130 | QGraphicsLayout *layout;
|
---|
131 | void setLayoutDirection_helper(Qt::LayoutDirection direction);
|
---|
132 | void resolveLayoutDirection();
|
---|
133 |
|
---|
134 | // Style
|
---|
135 | QPalette palette;
|
---|
136 | uint inheritedPaletteResolveMask;
|
---|
137 | void setPalette_helper(const QPalette &palette);
|
---|
138 | void resolvePalette(uint inheritedMask);
|
---|
139 | void updatePalette(const QPalette &palette);
|
---|
140 | QPalette naturalWidgetPalette() const;
|
---|
141 | QFont font;
|
---|
142 | uint inheritedFontResolveMask;
|
---|
143 | void setFont_helper(const QFont &font);
|
---|
144 | void resolveFont(uint inheritedMask);
|
---|
145 | void updateFont(const QFont &font);
|
---|
146 | QFont naturalWidgetFont() const;
|
---|
147 |
|
---|
148 | // Window specific
|
---|
149 | void initStyleOptionTitleBar(QStyleOptionTitleBar *option);
|
---|
150 | void adjustWindowFlags(Qt::WindowFlags *wFlags);
|
---|
151 | void windowFrameMouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
---|
152 | void windowFrameMousePressEvent(QGraphicsSceneMouseEvent *event);
|
---|
153 | void windowFrameMouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
---|
154 | void windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
---|
155 | void windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
---|
156 | bool hasDecoration() const;
|
---|
157 |
|
---|
158 | // State
|
---|
159 | inline int attributeToBitIndex(Qt::WidgetAttribute att) const
|
---|
160 | {
|
---|
161 | int bit = -1;
|
---|
162 | switch (att) {
|
---|
163 | case Qt::WA_SetLayoutDirection: bit = 0; break;
|
---|
164 | case Qt::WA_RightToLeft: bit = 1; break;
|
---|
165 | case Qt::WA_SetStyle: bit = 2; break;
|
---|
166 | case Qt::WA_Resized: bit = 3; break;
|
---|
167 | case Qt::WA_DeleteOnClose: bit = 4; break;
|
---|
168 | case Qt::WA_NoSystemBackground: bit = 5; break;
|
---|
169 | case Qt::WA_OpaquePaintEvent: bit = 6; break;
|
---|
170 | case Qt::WA_SetPalette: bit = 7; break;
|
---|
171 | case Qt::WA_SetFont: bit = 8; break;
|
---|
172 | case Qt::WA_WindowPropagation: bit = 9; break;
|
---|
173 | default: break;
|
---|
174 | }
|
---|
175 | return bit;
|
---|
176 | }
|
---|
177 | inline void setAttribute(Qt::WidgetAttribute att, bool value)
|
---|
178 | {
|
---|
179 | int bit = attributeToBitIndex(att);
|
---|
180 | if (bit == -1) {
|
---|
181 | qWarning("QGraphicsWidget::setAttribute: unsupported attribute %d", int(att));
|
---|
182 | return;
|
---|
183 | }
|
---|
184 | if (value)
|
---|
185 | attributes |= (1 << bit);
|
---|
186 | else
|
---|
187 | attributes &= ~(1 << bit);
|
---|
188 | }
|
---|
189 | inline bool testAttribute(Qt::WidgetAttribute att) const
|
---|
190 | {
|
---|
191 | int bit = attributeToBitIndex(att);
|
---|
192 | if (bit == -1)
|
---|
193 | return false;
|
---|
194 | return (attributes & (1 << bit)) != 0;
|
---|
195 | }
|
---|
196 | quint32 attributes : 10;
|
---|
197 | quint32 inSetGeometry : 1;
|
---|
198 | quint32 polished: 1;
|
---|
199 | quint32 inSetPos : 1;
|
---|
200 |
|
---|
201 | // Focus
|
---|
202 | Qt::FocusPolicy focusPolicy;
|
---|
203 | QGraphicsWidget *focusNext;
|
---|
204 | QGraphicsWidget *focusPrev;
|
---|
205 | QGraphicsWidget *focusChild;
|
---|
206 | void setFocusWidget();
|
---|
207 | void clearFocusWidget();
|
---|
208 |
|
---|
209 | // Windows
|
---|
210 | Qt::WindowFlags windowFlags;
|
---|
211 | QString windowTitle;
|
---|
212 | QStyle::SubControl hoveredSubControl;
|
---|
213 | Qt::WindowFrameSection grabbedSection;
|
---|
214 | uint buttonMouseOver : 1;
|
---|
215 | uint buttonSunken : 1;
|
---|
216 | QPointF mouseDelta; // to compensate for small error when interactively resizing
|
---|
217 | QRectF startGeometry;
|
---|
218 | QRect buttonRect;
|
---|
219 |
|
---|
220 | bool setWindowFrameMargins;
|
---|
221 | qreal leftWindowFrameMargin;
|
---|
222 | qreal topWindowFrameMargin;
|
---|
223 | qreal rightWindowFrameMargin;
|
---|
224 | qreal bottomWindowFrameMargin;
|
---|
225 |
|
---|
226 | #ifndef QT_NO_ACTION
|
---|
227 | QList<QAction *> actions;
|
---|
228 | #endif
|
---|
229 | };
|
---|
230 |
|
---|
231 | #endif //!defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
|
---|
232 |
|
---|
233 | QT_END_NAMESPACE
|
---|
234 |
|
---|
235 | #endif //QGRAPHICSWIDGET_P_H
|
---|
236 |
|
---|