| 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 QGRAPHICSITEM_H
|
|---|
| 43 | #define QGRAPHICSITEM_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtCore/qglobal.h>
|
|---|
| 46 | #include <QtCore/qobject.h>
|
|---|
| 47 | #include <QtCore/qvariant.h>
|
|---|
| 48 | #include <QtCore/qrect.h>
|
|---|
| 49 | #include <QtGui/qpainterpath.h>
|
|---|
| 50 | #include <QtGui/qpixmap.h>
|
|---|
| 51 |
|
|---|
| 52 | class tst_QGraphicsItem;
|
|---|
| 53 |
|
|---|
| 54 | QT_BEGIN_HEADER
|
|---|
| 55 |
|
|---|
| 56 | QT_BEGIN_NAMESPACE
|
|---|
| 57 |
|
|---|
| 58 | QT_MODULE(Gui)
|
|---|
| 59 |
|
|---|
| 60 | #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
|
|---|
| 61 |
|
|---|
| 62 | class QBrush;
|
|---|
| 63 | class QCursor;
|
|---|
| 64 | class QFocusEvent;
|
|---|
| 65 | class QGraphicsItemGroup;
|
|---|
| 66 | class QGraphicsSceneContextMenuEvent;
|
|---|
| 67 | class QGraphicsSceneDragDropEvent;
|
|---|
| 68 | class QGraphicsSceneEvent;
|
|---|
| 69 | class QGraphicsSceneHoverEvent;
|
|---|
| 70 | class QGraphicsSceneMouseEvent;
|
|---|
| 71 | class QGraphicsSceneWheelEvent;
|
|---|
| 72 | class QGraphicsScene;
|
|---|
| 73 | class QGraphicsWidget;
|
|---|
| 74 | class QInputMethodEvent;
|
|---|
| 75 | class QKeyEvent;
|
|---|
| 76 | class QMatrix;
|
|---|
| 77 | class QMenu;
|
|---|
| 78 | class QPainter;
|
|---|
| 79 | class QPen;
|
|---|
| 80 | class QPointF;
|
|---|
| 81 | class QRectF;
|
|---|
| 82 | class QStyleOptionGraphicsItem;
|
|---|
| 83 |
|
|---|
| 84 | class QGraphicsItemPrivate;
|
|---|
| 85 | class Q_GUI_EXPORT QGraphicsItem
|
|---|
| 86 | {
|
|---|
| 87 | public:
|
|---|
| 88 | enum GraphicsItemFlag {
|
|---|
| 89 | ItemIsMovable = 0x1,
|
|---|
| 90 | ItemIsSelectable = 0x2,
|
|---|
| 91 | ItemIsFocusable = 0x4,
|
|---|
| 92 | ItemClipsToShape = 0x8,
|
|---|
| 93 | ItemClipsChildrenToShape = 0x10,
|
|---|
| 94 | ItemIgnoresTransformations = 0x20,
|
|---|
| 95 | ItemIgnoresParentOpacity = 0x40,
|
|---|
| 96 | ItemDoesntPropagateOpacityToChildren = 0x80,
|
|---|
| 97 | ItemStacksBehindParent = 0x100
|
|---|
| 98 | };
|
|---|
| 99 | Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag)
|
|---|
| 100 |
|
|---|
| 101 | enum GraphicsItemChange {
|
|---|
| 102 | ItemPositionChange,
|
|---|
| 103 | ItemMatrixChange,
|
|---|
| 104 | ItemVisibleChange,
|
|---|
| 105 | ItemEnabledChange,
|
|---|
| 106 | ItemSelectedChange,
|
|---|
| 107 | ItemParentChange,
|
|---|
| 108 | ItemChildAddedChange,
|
|---|
| 109 | ItemChildRemovedChange,
|
|---|
| 110 | ItemTransformChange,
|
|---|
| 111 | ItemPositionHasChanged,
|
|---|
| 112 | ItemTransformHasChanged,
|
|---|
| 113 | ItemSceneChange,
|
|---|
| 114 | ItemVisibleHasChanged,
|
|---|
| 115 | ItemEnabledHasChanged,
|
|---|
| 116 | ItemSelectedHasChanged,
|
|---|
| 117 | ItemParentHasChanged,
|
|---|
| 118 | ItemSceneHasChanged,
|
|---|
| 119 | ItemCursorChange,
|
|---|
| 120 | ItemCursorHasChanged,
|
|---|
| 121 | ItemToolTipChange,
|
|---|
| 122 | ItemToolTipHasChanged,
|
|---|
| 123 | ItemFlagsChange,
|
|---|
| 124 | ItemFlagsHaveChanged,
|
|---|
| 125 | ItemZValueChange,
|
|---|
| 126 | ItemZValueHasChanged,
|
|---|
| 127 | ItemOpacityChange,
|
|---|
| 128 | ItemOpacityHasChanged
|
|---|
| 129 | };
|
|---|
| 130 |
|
|---|
| 131 | enum CacheMode {
|
|---|
| 132 | NoCache,
|
|---|
| 133 | ItemCoordinateCache,
|
|---|
| 134 | DeviceCoordinateCache
|
|---|
| 135 | };
|
|---|
| 136 |
|
|---|
| 137 | QGraphicsItem(QGraphicsItem *parent = 0
|
|---|
| 138 | #ifndef Q_QDOC
|
|---|
| 139 | // obsolete argument
|
|---|
| 140 | , QGraphicsScene *scene = 0
|
|---|
| 141 | #endif
|
|---|
| 142 | );
|
|---|
| 143 | virtual ~QGraphicsItem();
|
|---|
| 144 |
|
|---|
| 145 | QGraphicsScene *scene() const;
|
|---|
| 146 |
|
|---|
| 147 | QGraphicsItem *parentItem() const;
|
|---|
| 148 | QGraphicsItem *topLevelItem() const;
|
|---|
| 149 | QGraphicsWidget *parentWidget() const;
|
|---|
| 150 | QGraphicsWidget *topLevelWidget() const;
|
|---|
| 151 | QGraphicsWidget *window() const;
|
|---|
| 152 | void setParentItem(QGraphicsItem *parent);
|
|---|
| 153 | QList<QGraphicsItem *> children() const; // ### obsolete
|
|---|
| 154 | QList<QGraphicsItem *> childItems() const;
|
|---|
| 155 | bool isWidget() const;
|
|---|
| 156 | bool isWindow() const;
|
|---|
| 157 |
|
|---|
| 158 | QGraphicsItemGroup *group() const;
|
|---|
| 159 | void setGroup(QGraphicsItemGroup *group);
|
|---|
| 160 |
|
|---|
| 161 | GraphicsItemFlags flags() const;
|
|---|
| 162 | void setFlag(GraphicsItemFlag flag, bool enabled = true);
|
|---|
| 163 | void setFlags(GraphicsItemFlags flags);
|
|---|
| 164 |
|
|---|
| 165 | CacheMode cacheMode() const;
|
|---|
| 166 | void setCacheMode(CacheMode mode, const QSize &cacheSize = QSize());
|
|---|
| 167 |
|
|---|
| 168 | #ifndef QT_NO_TOOLTIP
|
|---|
| 169 | QString toolTip() const;
|
|---|
| 170 | void setToolTip(const QString &toolTip);
|
|---|
| 171 | #endif
|
|---|
| 172 |
|
|---|
| 173 | #ifndef QT_NO_CURSOR
|
|---|
| 174 | QCursor cursor() const;
|
|---|
| 175 | void setCursor(const QCursor &cursor);
|
|---|
| 176 | bool hasCursor() const;
|
|---|
| 177 | void unsetCursor();
|
|---|
| 178 | #endif
|
|---|
| 179 |
|
|---|
| 180 | bool isVisible() const;
|
|---|
| 181 | bool isVisibleTo(const QGraphicsItem *parent) const;
|
|---|
| 182 | void setVisible(bool visible);
|
|---|
| 183 | inline void hide() { setVisible(false); }
|
|---|
| 184 | inline void show() { setVisible(true); }
|
|---|
| 185 |
|
|---|
| 186 | bool isEnabled() const;
|
|---|
| 187 | void setEnabled(bool enabled);
|
|---|
| 188 |
|
|---|
| 189 | bool isSelected() const;
|
|---|
| 190 | void setSelected(bool selected);
|
|---|
| 191 |
|
|---|
| 192 | bool acceptDrops() const;
|
|---|
| 193 | void setAcceptDrops(bool on);
|
|---|
| 194 |
|
|---|
| 195 | qreal opacity() const;
|
|---|
| 196 | qreal effectiveOpacity() const;
|
|---|
| 197 | void setOpacity(qreal opacity);
|
|---|
| 198 |
|
|---|
| 199 | Qt::MouseButtons acceptedMouseButtons() const;
|
|---|
| 200 | void setAcceptedMouseButtons(Qt::MouseButtons buttons);
|
|---|
| 201 |
|
|---|
| 202 | bool acceptsHoverEvents() const; // obsolete
|
|---|
| 203 | void setAcceptsHoverEvents(bool enabled); // obsolete
|
|---|
| 204 | bool acceptHoverEvents() const;
|
|---|
| 205 | void setAcceptHoverEvents(bool enabled);
|
|---|
| 206 |
|
|---|
| 207 | bool handlesChildEvents() const;
|
|---|
| 208 | void setHandlesChildEvents(bool enabled);
|
|---|
| 209 |
|
|---|
| 210 | bool hasFocus() const;
|
|---|
| 211 | void setFocus(Qt::FocusReason focusReason = Qt::OtherFocusReason);
|
|---|
| 212 | void clearFocus();
|
|---|
| 213 |
|
|---|
| 214 | void grabMouse();
|
|---|
| 215 | void ungrabMouse();
|
|---|
| 216 | void grabKeyboard();
|
|---|
| 217 | void ungrabKeyboard();
|
|---|
| 218 |
|
|---|
| 219 | // Positioning in scene coordinates
|
|---|
| 220 | QPointF pos() const;
|
|---|
| 221 | inline qreal x() const { return pos().x(); }
|
|---|
| 222 | inline qreal y() const { return pos().y(); }
|
|---|
| 223 | QPointF scenePos() const;
|
|---|
| 224 | void setPos(const QPointF &pos);
|
|---|
| 225 | inline void setPos(qreal x, qreal y);
|
|---|
| 226 | inline void moveBy(qreal dx, qreal dy) { setPos(pos().x() + dx, pos().y() + dy); }
|
|---|
| 227 |
|
|---|
| 228 | void ensureVisible(const QRectF &rect = QRectF(), int xmargin = 50, int ymargin = 50);
|
|---|
| 229 | inline void ensureVisible(qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50);
|
|---|
| 230 |
|
|---|
| 231 | // Local transformation
|
|---|
| 232 | QMatrix matrix() const;
|
|---|
| 233 | QMatrix sceneMatrix() const;
|
|---|
| 234 | void setMatrix(const QMatrix &matrix, bool combine = false);
|
|---|
| 235 | void resetMatrix();
|
|---|
| 236 | QTransform transform() const;
|
|---|
| 237 | QTransform sceneTransform() const;
|
|---|
| 238 | QTransform deviceTransform(const QTransform &viewportTransform) const;
|
|---|
| 239 | QTransform itemTransform(const QGraphicsItem *other, bool *ok = 0) const;
|
|---|
| 240 | void setTransform(const QTransform &matrix, bool combine = false);
|
|---|
| 241 | void resetTransform();
|
|---|
| 242 |
|
|---|
|
|---|