[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 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
|
---|
[561] | 50 | // of other Qt classes. This header file may change from version to
|
---|
| 51 | // version without notice, or even be removed.
|
---|
[2] | 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 |
|
---|
[561] | 71 | class QGraphicsWidgetPrivate : public QGraphicsItemPrivate
|
---|
[2] | 72 | {
|
---|
| 73 | Q_DECLARE_PUBLIC(QGraphicsWidget)
|
---|
| 74 | public:
|
---|
| 75 | QGraphicsWidgetPrivate()
|
---|
[561] | 76 | : margins(0),
|
---|
[2] | 77 | layout(0),
|
---|
| 78 | inheritedPaletteResolveMask(0),
|
---|
| 79 | inheritedFontResolveMask(0),
|
---|
| 80 | inSetGeometry(0),
|
---|
| 81 | polished(0),
|
---|
| 82 | inSetPos(0),
|
---|
[846] | 83 | autoFillBackground(0),
|
---|
[2] | 84 | focusPolicy(Qt::NoFocus),
|
---|
| 85 | focusNext(0),
|
---|
| 86 | focusPrev(0),
|
---|
| 87 | windowFlags(0),
|
---|
[561] | 88 | windowData(0),
|
---|
[2] | 89 | setWindowFrameMargins(false),
|
---|
[561] | 90 | windowFrameMargins(0)
|
---|
[2] | 91 | { }
|
---|
[561] | 92 | virtual ~QGraphicsWidgetPrivate();
|
---|
[2] | 93 |
|
---|
| 94 | void init(QGraphicsItem *parentItem, Qt::WindowFlags wFlags);
|
---|
| 95 | qreal titleBarHeight(const QStyleOptionTitleBar &options) const;
|
---|
| 96 |
|
---|
| 97 | // Margins
|
---|
[561] | 98 | enum {Left, Top, Right, Bottom};
|
---|
| 99 | mutable qreal *margins;
|
---|
| 100 | void ensureMargins() const;
|
---|
[2] | 101 |
|
---|
[561] | 102 | void fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene = 0);
|
---|
[2] | 103 | void setLayout_helper(QGraphicsLayout *l);
|
---|
| 104 |
|
---|
| 105 | // Layouts
|
---|
| 106 | QGraphicsLayout *layout;
|
---|
| 107 | void setLayoutDirection_helper(Qt::LayoutDirection direction);
|
---|
| 108 | void resolveLayoutDirection();
|
---|
| 109 |
|
---|
| 110 | // Style
|
---|
| 111 | QPalette palette;
|
---|
| 112 | uint inheritedPaletteResolveMask;
|
---|
| 113 | void setPalette_helper(const QPalette &palette);
|
---|
| 114 | void resolvePalette(uint inheritedMask);
|
---|
| 115 | void updatePalette(const QPalette &palette);
|
---|
| 116 | QPalette naturalWidgetPalette() const;
|
---|
| 117 | QFont font;
|
---|
| 118 | uint inheritedFontResolveMask;
|
---|
| 119 | void setFont_helper(const QFont &font);
|
---|
| 120 | void resolveFont(uint inheritedMask);
|
---|
| 121 | void updateFont(const QFont &font);
|
---|
| 122 | QFont naturalWidgetFont() const;
|
---|
| 123 |
|
---|
| 124 | // Window specific
|
---|
| 125 | void initStyleOptionTitleBar(QStyleOptionTitleBar *option);
|
---|
| 126 | void adjustWindowFlags(Qt::WindowFlags *wFlags);
|
---|
| 127 | void windowFrameMouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
---|
| 128 | void windowFrameMousePressEvent(QGraphicsSceneMouseEvent *event);
|
---|
| 129 | void windowFrameMouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
---|
| 130 | void windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
---|
| 131 | void windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
---|
| 132 | bool hasDecoration() const;
|
---|
| 133 |
|
---|
[846] | 134 | // Private Properties
|
---|
| 135 | qreal width() const;
|
---|
| 136 | void setWidth(qreal);
|
---|
| 137 | void resetWidth();
|
---|
| 138 |
|
---|
| 139 | qreal height() const;
|
---|
| 140 | void setHeight(qreal);
|
---|
| 141 | void resetHeight();
|
---|
[769] | 142 | void setGeometryFromSetPos();
|
---|
| 143 |
|
---|
[2] | 144 | // State
|
---|
| 145 | inline int attributeToBitIndex(Qt::WidgetAttribute att) const
|
---|
| 146 | {
|
---|
| 147 | int bit = -1;
|
---|
| 148 | switch (att) {
|
---|
| 149 | case Qt::WA_SetLayoutDirection: bit = 0; break;
|
---|
| 150 | case Qt::WA_RightToLeft: bit = 1; break;
|
---|
| 151 | case Qt::WA_SetStyle: bit = 2; break;
|
---|
| 152 | case Qt::WA_Resized: bit = 3; break;
|
---|
| 153 | case Qt::WA_DeleteOnClose: bit = 4; break;
|
---|
| 154 | case Qt::WA_NoSystemBackground: bit = 5; break;
|
---|
| 155 | case Qt::WA_OpaquePaintEvent: bit = 6; break;
|
---|
| 156 | case Qt::WA_SetPalette: bit = 7; break;
|
---|
| 157 | case Qt::WA_SetFont: bit = 8; break;
|
---|
| 158 | case Qt::WA_WindowPropagation: bit = 9; break;
|
---|
| 159 | default: break;
|
---|
| 160 | }
|
---|
| 161 | return bit;
|
---|
| 162 | }
|
---|
| 163 | inline void setAttribute(Qt::WidgetAttribute att, bool value)
|
---|
| 164 | {
|
---|
| 165 | int bit = attributeToBitIndex(att);
|
---|
| 166 | if (bit == -1) {
|
---|
| 167 | qWarning("QGraphicsWidget::setAttribute: unsupported attribute %d", int(att));
|
---|
| 168 | return;
|
---|
| 169 | }
|
---|
| 170 | if (value)
|
---|
| 171 | attributes |= (1 << bit);
|
---|
| 172 | else
|
---|
| 173 | attributes &= ~(1 << bit);
|
---|
| 174 | }
|
---|
| 175 | inline bool testAttribute(Qt::WidgetAttribute att) const
|
---|
| 176 | {
|
---|
| 177 | int bit = attributeToBitIndex(att);
|
---|
| 178 | if (bit == -1)
|
---|
| 179 | return false;
|
---|
| 180 | return (attributes & (1 << bit)) != 0;
|
---|
| 181 | }
|
---|
| 182 | quint32 attributes : 10;
|
---|
| 183 | quint32 inSetGeometry : 1;
|
---|
| 184 | quint32 polished: 1;
|
---|
| 185 | quint32 inSetPos : 1;
|
---|
[846] | 186 | quint32 autoFillBackground : 1;
|
---|
[2] | 187 |
|
---|
| 188 | // Focus
|
---|
| 189 | Qt::FocusPolicy focusPolicy;
|
---|
| 190 | QGraphicsWidget *focusNext;
|
---|
| 191 | QGraphicsWidget *focusPrev;
|
---|
| 192 |
|
---|
| 193 | // Windows
|
---|
| 194 | Qt::WindowFlags windowFlags;
|
---|
[561] | 195 | struct WindowData {
|
---|
| 196 | QString windowTitle;
|
---|
| 197 | QStyle::SubControl hoveredSubControl;
|
---|
| 198 | Qt::WindowFrameSection grabbedSection;
|
---|
| 199 | uint buttonMouseOver : 1;
|
---|
| 200 | uint buttonSunken : 1;
|
---|
| 201 | QRectF startGeometry;
|
---|
| 202 | QRect buttonRect;
|
---|
| 203 | WindowData()
|
---|
| 204 | : hoveredSubControl(QStyle::SC_None)
|
---|
| 205 | , grabbedSection(Qt::NoSection)
|
---|
| 206 | , buttonMouseOver(false)
|
---|
| 207 | , buttonSunken(false)
|
---|
| 208 | {}
|
---|
| 209 | } *windowData;
|
---|
| 210 | void ensureWindowData();
|
---|
[2] | 211 |
|
---|
| 212 | bool setWindowFrameMargins;
|
---|
[561] | 213 | mutable qreal *windowFrameMargins;
|
---|
| 214 | void ensureWindowFrameMargins() const;
|
---|
[2] | 215 |
|
---|
| 216 | #ifndef QT_NO_ACTION
|
---|
| 217 | QList<QAction *> actions;
|
---|
| 218 | #endif
|
---|
| 219 | };
|
---|
| 220 |
|
---|
| 221 | #endif //!defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
|
---|
| 222 |
|
---|
| 223 | QT_END_NAMESPACE
|
---|
| 224 |
|
---|
| 225 | #endif //QGRAPHICSWIDGET_P_H
|
---|
| 226 |
|
---|