Qt 4.8
qgraphicswidget_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui 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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 other Qt classes. This header file may change from version to
51 // 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 
65 
66 class QGraphicsLayout;
68 
69 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
70 
72 {
74 public:
76  : margins(0),
77  layout(0),
80  inSetGeometry(0),
81  polished(0),
82  inSetPos(0),
86  focusNext(0),
87  focusPrev(0),
88  windowFlags(0),
89  windowData(0),
90  setWindowFrameMargins(false),
92  { }
93  virtual ~QGraphicsWidgetPrivate();
94 
95  void init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags);
96  qreal titleBarHeight(const QStyleOptionTitleBar &options) const;
97 
98  // Margins
99  enum {Left, Top, Right, Bottom};
100  mutable qreal *margins;
101  void ensureMargins() const;
102 
103  void fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene = 0);
105 
106  // Layouts
109  void resolveLayoutDirection();
110  void _q_relayout();
111 
112  // Style
115  void setPalette_helper(const QPalette &palette);
116  void resolvePalette(uint inheritedMask);
117  void updatePalette(const QPalette &palette);
121  void setFont_helper(const QFont &font);
122  void resolveFont(uint inheritedMask);
123  void updateFont(const QFont &font);
124  QFont naturalWidgetFont() const;
125 
126  // Window specific
128  void adjustWindowFlags(Qt::WindowFlags *wFlags);
134  bool hasDecoration() const;
135 
136  // Private Properties
137  qreal width() const;
138  void setWidth(qreal);
139  void resetWidth();
140 
141  qreal height() const;
142  void setHeight(qreal);
143  void resetHeight();
144  void setGeometryFromSetPos();
145 
146  // State
148  {
149  int bit = -1;
150  switch (att) {
151  case Qt::WA_SetLayoutDirection: bit = 0; break;
152  case Qt::WA_RightToLeft: bit = 1; break;
153  case Qt::WA_SetStyle: bit = 2; break;
154  case Qt::WA_Resized: bit = 3; break;
155  case Qt::WA_DeleteOnClose: bit = 4; break;
156  case Qt::WA_NoSystemBackground: bit = 5; break;
157  case Qt::WA_OpaquePaintEvent: bit = 6; break;
158  case Qt::WA_SetPalette: bit = 7; break;
159  case Qt::WA_SetFont: bit = 8; break;
160  case Qt::WA_WindowPropagation: bit = 9; break;
161  default: break;
162  }
163  return bit;
164  }
165  inline void setAttribute(Qt::WidgetAttribute att, bool value)
166  {
167  int bit = attributeToBitIndex(att);
168  if (bit == -1) {
169  qWarning("QGraphicsWidget::setAttribute: unsupported attribute %d", int(att));
170  return;
171  }
172  if (value)
173  attributes |= (1 << bit);
174  else
175  attributes &= ~(1 << bit);
176  }
177  inline bool testAttribute(Qt::WidgetAttribute att) const
178  {
179  int bit = attributeToBitIndex(att);
180  if (bit == -1)
181  return false;
182  return (attributes & (1 << bit)) != 0;
183  }
184  // 32 bits
191  quint32 padding : 2; // feel free to use
192 
193  // Focus
197 
198  // Windows
199  Qt::WindowFlags windowFlags;
200  struct WindowData {
209  : hoveredSubControl(QStyle::SC_None)
210  , grabbedSection(Qt::NoSection)
211  , buttonMouseOver(false)
212  , buttonSunken(false)
213  {}
214  } *windowData;
215  void ensureWindowData();
216 
219  void ensureWindowFrameMargins() const;
220 
221 #ifndef QT_NO_ACTION
223 #endif
224 };
225 
226 #endif
227 
229 
230 #endif //QGRAPHICSWIDGET_P_H
231 
QPalette naturalWidgetPalette() const
void setFont_helper(const QFont &font)
void windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent *event)
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
double qreal
Definition: qglobal.h:1193
QGraphicsWidget * focusPrev
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
Qt::WindowFrameSection grabbedSection
Qt::WindowFlags windowFlags
struct QGraphicsWidgetPrivate::WindowData * windowData
Qt::FocusPolicy focusPolicy
qreal titleBarHeight(const QStyleOptionTitleBar &options) const
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
void resolveFont(uint inheritedMask)
void adjustWindowFlags(Qt::WindowFlags *wFlags)
The QStyleOptionTitleBar class is used to describe the parameters for drawing a title bar...
Definition: qstyleoption.h:816
QGraphicsWidget * focusNext
void ensureWindowFrameMargins() const
Ensures that windowFrameMargins is allocated.
void windowFrameMousePressEvent(QGraphicsSceneMouseEvent *event)
QGraphicsLayout * layout
The QString class provides a Unicode character string.
Definition: qstring.h:83
void updateFont(const QFont &font)
QList< QAction * > actions
WidgetAttribute
Definition: qnamespace.h:376
void resolvePalette(uint inheritedMask)
void updatePalette(const QPalette &palette)
void windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent *event)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void setLayout_helper(QGraphicsLayout *l)
void fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene=0)
LayoutDirection
Definition: qnamespace.h:1580
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
void initStyleOptionTitleBar(QStyleOptionTitleBar *option)
void ensureMargins() const
Ensures that margins is allocated.
void setLayoutDirection_helper(Qt::LayoutDirection direction)
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
void windowFrameMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
unsigned int quint32
Definition: qglobal.h:938
void windowFrameMouseMoveEvent(QGraphicsSceneMouseEvent *event)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
FocusPolicy
Definition: qnamespace.h:181
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
QFactoryLoader * l
bool testAttribute(Qt::WidgetAttribute att) const
void ensureWindowData()
Ensures that windowData is allocated.
int attributeToBitIndex(Qt::WidgetAttribute att) const
void setPalette_helper(const QPalette &palette)
WindowFrameSection
Definition: qnamespace.h:1716
void setAttribute(Qt::WidgetAttribute att, bool value)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags)
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
Qt::LayoutDirection direction
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61