summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/graphicsview.pri4
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp767
-rw-r--r--src/gui/graphicsview/qgraphicsitem.h57
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h55
-rw-r--r--src/gui/graphicsview/qgraphicslayoutitem.cpp4
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp242
-rw-r--r--src/gui/graphicsview/qgraphicsscene.h5
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h2
-rw-r--r--src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp11
-rw-r--r--src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h13
-rw-r--r--src/gui/graphicsview/qgraphicssceneevent.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicsscenelinearindex.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicsscenelinearindex_p.h14
-rw-r--r--src/gui/graphicsview/qgraphicstransform.cpp573
-rw-r--r--src/gui/graphicsview/qgraphicstransform.h169
-rw-r--r--src/gui/graphicsview/qgraphicstransform_p.h73
-rw-r--r--src/gui/graphicsview/qgraphicsview.cpp24
-rw-r--r--src/gui/graphicsview/qgraphicswidget.cpp42
-rw-r--r--src/gui/graphicsview/qgraphicswidget.h8
-rw-r--r--src/gui/graphicsview/qgraphicswidget_p.cpp34
-rw-r--r--src/gui/graphicsview/qgraphicswidget_p.h4
21 files changed, 1521 insertions, 584 deletions
diff --git a/src/gui/graphicsview/graphicsview.pri b/src/gui/graphicsview/graphicsview.pri
index 0c0747e50..9d232e451 100644
--- a/src/gui/graphicsview/graphicsview.pri
+++ b/src/gui/graphicsview/graphicsview.pri
@@ -16,12 +16,13 @@ HEADERS += graphicsview/qgraphicsgridlayout.h \
graphicsview/qgraphicssceneevent.h \
graphicsview/qgraphicssceneindex_p.h \
graphicsview/qgraphicsscenelinearindex_p.h \
+ graphicsview/qgraphicstransform.h \
+ graphicsview/qgraphicstransform_p.h \
graphicsview/qgraphicsview.h \
graphicsview/qgraphicsview_p.h \
graphicsview/qgraphicswidget.h \
graphicsview/qgraphicswidget_p.h \
graphicsview/qgridlayoutengine_p.h
-
SOURCES += graphicsview/qgraphicsgridlayout.cpp \
graphicsview/qgraphicsitem.cpp \
graphicsview/qgraphicsitemanimation.cpp \
@@ -36,6 +37,7 @@ SOURCES += graphicsview/qgraphicsgridlayout.cpp \
graphicsview/qgraphicssceneevent.cpp \
graphicsview/qgraphicssceneindex.cpp \
graphicsview/qgraphicsscenelinearindex.cpp \
+ graphicsview/qgraphicstransform.cpp \
graphicsview/qgraphicsview.cpp \
graphicsview/qgraphicswidget.cpp \
graphicsview/qgraphicswidget_p.cpp \
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index cb0418c70..75d6ead29 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -135,38 +135,39 @@
\section1 Transformation
- QGraphicsItem supports affine transformations in addition to its base
- position, pos(). To change the item's transformation, you can pass
- a transformation matrix to setTransform()
-
- Item transformations accumulate from parent to child, so if both a
- parent and child item are rotated 90 degrees, the child's total
- transformation will be 180 degrees. Similarly, if the item's
- parent is scaled to 2x its original size, its children will also
- be twice as large. An item's transformation does not affect its
- own local geometry; all geometry functions (e.g., contains(),
- update(), and all the mapping functions) still operate in local
- coordinates. For convenience, QGraphicsItem provides the functions
- sceneTransform(), which returns the item's total transformation
+ QGraphicsItem supports projective transformations in addition to its base
+ position, pos(). There are several ways to change an item's transformation.
+ For simple transformations, you can call either of the convenience
+ functions setRotation() or setScale(), or you can pass any transformation
+ matrix to setTransform(). For advanced transformation control you also have
+ the option of setting several combined transformations by calling
+ setTransformations().
+
+ Item transformations accumulate from parent to child, so if both a parent
+ and child item are rotated 90 degrees, the child's total transformation
+ will be 180 degrees. Similarly, if the item's parent is scaled to 2x its
+ original size, its children will also be twice as large. An item's
+ transformation does not affect its own local geometry; all geometry
+ functions (e.g., contains(), update(), and all the mapping functions) still
+ operate in local coordinates. For convenience, QGraphicsItem provides the
+ functions sceneTransform(), which returns the item's total transformation
matrix (including its position and all parents' positions and
- transformations), and scenePos(), which returns its position in
- scene coordinates. To reset an item's matrix, call
- resetTransform().
+ transformations), and scenePos(), which returns its position in scene
+ coordinates. To reset an item's matrix, call resetTransform().
- Another way to apply transformation to an item is to use the , or
- set the different transformation properties (transformOrigin,
- x/y/zRotation, x/yScale, horizontal/verticalShear). Those
- properties come in addition to the base transformation
+ Certain transformation operations produce a different outcome depending on
+ the order in which they are applied. For example, if you scale an
+ transform, and then rotate it, you may get a different result than if the
+ transform was rotated first. However, the order you set the transformation
+ properties on QGraphicsItem does not affect the resulting transformation;
+ QGraphicsItem always applies the properties in a fixed, defined order:
- The order you set the transformation properties does not affect
- the resulting transformation The resulting transformation is
- always computed in the following order
-
- \code
- [Origin] [Base] [RotateX] [RotateY] [RotateZ] [Shear] [Scale] [-Origin]
- \endcode
-
- Where [Base] is the stransformation set by setTransform
+ \list
+ \o The item's base transform is applied (transform())
+ \o The item's transformations list is applied in order (transformations())
+ \o The item is rotated relative to its transform origin point (rotation(), transformOriginPoint())
+ \o The item is scaled relative to its transform origin point (scale(), transformOriginPoint())
+ \endlist
\section1 Painting
@@ -303,13 +304,12 @@
drop shadow effects and for decoration objects that follow the parent
item's geometry without drawing on top of it.
- \value ItemUsesExtendedStyleOption The item makes use of either
- QStyleOptionGraphicsItem::exposedRect or QStyleOptionGraphicsItem::matrix.
+ \value ItemUsesExtendedStyleOption The item makes use of either the
+ exposedRect or matrix member of the QStyleOptionGraphicsItem. Implementers
+ of QGraphicsItem subclasses should set that flag if this data is required.
By default, the exposedRect is initialized to the item's boundingRect and
the matrix is untransformed. Enable this flag for more fine-grained values.
- Note that QStyleOptionGraphicsItem::levelOfDetail is unaffected by this flag
- and is always initialized to 1.
- Use QStyleOptionGraphicsItem::levelOfDetailFromTransform for a more
+ Use QStyleOptionGraphicsItem::levelOfDetailFromTransform() for a more
fine-grained value.
\value ItemHasNoContents The item does not paint anything (i.e., calling
@@ -327,6 +327,10 @@
\value ItemAcceptsInputMethod The item supports input methods typically
used for Asian languages.
This flag was introduced in Qt 4.6.
+
+ \value ItemAutoDetectsFocusProxy The item will assign any child that
+ gains input focus as its focus proxy. See also focusProxy().
+ This flag was introduced in Qt 4.6.
*/
/*!
@@ -909,12 +913,12 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent)
scene->d_func()->index->itemChange(q, QGraphicsItem::ItemParentChange, newParentVariant);
}
- if (QGraphicsWidget *w = isWidget ? static_cast<QGraphicsWidget *>(q) : q->parentWidget()) {
- // Update the child focus chain; when reparenting a widget that has a
+ QGraphicsItem *lastSubFocusItem = subFocusItem;
+ if (subFocusItem) {
+ // Update the child focus chain; when reparenting an item that has a
// focus child, ensure that that focus child clears its focus child
// chain from our parents before it's reparented.
- if (QGraphicsWidget *focusChild = w->focusWidget())
- focusChild->clearFocus();
+ subFocusItem->clearFocus();
}
// We anticipate geometry changes. If the item is deleted, it will be
@@ -1002,6 +1006,21 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent)
resolveDepth(parent ? parent->d_ptr->depth : -1);
dirtySceneTransform = 1;
+ // Restore the sub focus chain.
+ if (lastSubFocusItem)
+ lastSubFocusItem->d_ptr->setSubFocus();
+
+ // Auto-update focus proxy. The closest parent that detects
+ // focus proxies is updated as the proxy gains or loses focus.
+ QGraphicsItem *p = newParent;
+ while (p) {
+ if (p->d_ptr->flags & QGraphicsItem::ItemAutoDetectsFocusProxy) {
+ p->setFocusProxy(q);
+ break;
+ }
+ p = p->d_ptr->parent;
+ }
+
// Deliver post-change notification
q->itemChange(QGraphicsItem::ItemParentHasChanged, newParentVariant);
@@ -1179,6 +1198,13 @@ QGraphicsItem::~QGraphicsItem()
else
d_ptr->setParentItemHelper(0);
+ if (d_ptr->transformData) {
+ for(int i = 0; i < d_ptr->transformData->graphicsTransforms.size(); ++i) {
+ QGraphicsTransform *t = d_ptr->transformData->graphicsTransforms.at(i);
+ static_cast<QGraphicsTransformPrivate *>(t->d_ptr)->item = 0;
+ delete t;
+ }
+ }
delete d_ptr->transformData;
delete d_ptr;
@@ -1237,7 +1263,7 @@ void QGraphicsItem::setGroup(QGraphicsItemGroup *group)
Returns a pointer to this item's parent item. If this item does not have a
parent, 0 is returned.
- \sa setParentItem(), children()
+ \sa setParentItem(), childItems()
*/
QGraphicsItem *QGraphicsItem::parentItem() const
{
@@ -1260,7 +1286,7 @@ QGraphicsItem *QGraphicsItem::topLevelItem() const
}
/*!
- \since 4.4
+ \since 4.6
Returns a pointer to the item's parent, cast to a QGraphicsObject. returns 0 if the parent item
is not a QGraphicsObject.
@@ -1353,7 +1379,7 @@ const QGraphicsObject *QGraphicsItem::toGraphicsObject() const
the parent. You should not \l{QGraphicsScene::addItem()}{add} the
item to the scene yourself.
- \sa parentItem(), children()
+ \sa parentItem(), childItems()
*/
void QGraphicsItem::setParentItem(QGraphicsItem *parent)
{
@@ -2298,10 +2324,10 @@ bool QGraphicsItem::acceptsHoverEvents() const
stays "hovered" until the cursor leaves its area, including its
children's areas.
- If a parent item handles child events (setHandlesChildEvents()), it will
- receive hover move, drag move, and drop events as the cursor passes
- through its children, but it does not receive hover enter and hover leave,
- nor drag enter and drag leave events on behalf of its children.
+ If a parent item handles child events, it will receive hover move,
+ drag move, and drop events as the cursor passes through its
+ children, but it does not receive hover enter and hover leave, nor
+ drag enter and drag leave events on behalf of its children.
A QGraphicsWidget with window decorations will accept hover events
regardless of the value of acceptHoverEvents().
@@ -2332,8 +2358,8 @@ void QGraphicsItem::setAcceptsHoverEvents(bool enabled)
/*! \since 4.6
- Returns true if an item accepts touch events (QTouchEvent); otherwise, returns false. By
- default, items do not accept touch events.
+ Returns true if an item accepts \l{QTouchEvent}{touch events};
+ otherwise, returns false. By default, items do not accept touch events.
\sa setAcceptTouchEvents()
*/
@@ -2345,7 +2371,7 @@ bool QGraphicsItem::acceptTouchEvents() const
/*!
\since 4.6
- If \a enabled is true, this item will accept touch events;
+ If \a enabled is true, this item will accept \l{QTouchEvent}{touch events};
otherwise, it will ignore them. By default, items do not accept
touch events.
*/
@@ -2361,6 +2387,8 @@ void QGraphicsItem::setAcceptTouchEvents(bool enabled)
}
/*!
+ \since 4.6
+
Returns true if this item filters child events (i.e., all events
intended for any of its children are instead sent to this item);
otherwise, false is returned.
@@ -2375,13 +2403,15 @@ bool QGraphicsItem::filtersChildEvents() const
}
/*!
+ \since 4.6
+
If \a enabled is true, this item is set to filter all events for
all its children (i.e., all events intented for any of its
children are instead sent to this item); otherwise, if \a enabled
is false, this item will only handle its own events. The default
value is false.
- \sa filtersChildEvents()
+ \sa filtersChildEvents()
*/
void QGraphicsItem::setFiltersChildEvents(bool enabled)
{
@@ -2444,73 +2474,166 @@ void QGraphicsItem::setHandlesChildEvents(bool enabled)
}
/*!
- Returns true if this item has keyboard input focus; otherwise, returns
- false.
+ Returns true if this item or its \l{focusProxy()}{focus proxy} has keyboard
+ input focus; otherwise, returns false.
- \sa QGraphicsScene::focusItem(), setFocus(), QGraphicsScene::setFocusItem()
+ \sa focusItem(), setFocus(), QGraphicsScene::setFocusItem()
*/
bool QGraphicsItem::hasFocus() const
{
+ if (d_ptr->focusProxy)
+ return d_ptr->focusProxy->hasFocus();
return (d_ptr->scene && d_ptr->scene->focusItem() == this);
}
/*!
Gives keyboard input focus to this item. The \a focusReason argument will
- be passed into any focus event generated by this function; it is used to
- give an explanation of what caused the item to get focus.
+ be passed into any \l{QFocusEvent}{focus event} generated by this function;
+ it is used to give an explanation of what caused the item to get focus.
- Only items that set the ItemIsFocusable flag can accept keyboard focus.
+ Only enabled items that set the ItemIsFocusable flag can accept keyboard
+ focus.
- If this item is not visible (i.e., isVisible() returns false), not
- enabled, not associated with a scene, or if it already has input focus,
- this function will do nothing.
+ If this item is not visible, or not associated with a scene, it will not
+ gain immediate input focus. However, it will be registered as the preferred
+ focus item for its subtree of items, should it later become visible.
- As a result of calling this function, this item will receive a focus in
- event with \a focusReason. If another item already has focus, that item
- will first receive a focus out event indicating that it has lost input
- focus.
+ As a result of calling this function, this item will receive a
+ \l{focusInEvent()}{focus in event} with \a focusReason. If another item
+ already has focus, that item will first receive a \l{focusOutEvent()}
+ {focus out event} indicating that it has lost input focus.
- \sa clearFocus(), hasFocus()
+ \sa clearFocus(), hasFocus(), focusItem(), focusProxy()
*/
void QGraphicsItem::setFocus(Qt::FocusReason focusReason)
{
- if (!d_ptr->scene || !isEnabled() || hasFocus() || !(d_ptr->flags & ItemIsFocusable))
+ // Disabled / unfocusable items cannot accept focus.
+ if (!isEnabled() || !(d_ptr->flags & QGraphicsItem::ItemIsFocusable))
+ return;
+
+ // Find focus proxy.
+ QGraphicsItem *f = this;
+ while (f->d_ptr->focusProxy)
+ f = f->d_ptr->focusProxy;
+
+ // Return if it already has focus.
+ if (d_ptr->scene && d_ptr->scene->focusItem() == f)
return;
- if (isVisible()) {
- // Visible items immediately gain focus from scene.
- d_ptr->scene->setFocusItem(this, focusReason);
- } else if (d_ptr->isWidget) {
- // Just set up subfocus.
- static_cast<QGraphicsWidget *>(this)->d_func()->setFocusWidget();
+
+ // Update the child focus chain.
+ d_ptr->setSubFocus();
+
+ // Update the scene's focus item.
+ if (d_ptr->scene) {
+ QGraphicsWidget *w = window();
+ if (!w || w->isActiveWindow()) {
+ // Visible items immediately gain focus from scene.
+ d_ptr->scene->d_func()->setFocusItemHelper(f, focusReason);
+ }
}
}
/*!
Takes keyboard input focus from the item.
- If it has focus, a focus out event is sent to this item to tell it that it
- is about to lose the focus.
+ If it has focus, a \l{focusOutEvent()}{focus out event} is sent to this item
+ to tell it that it is about to lose the focus.
Only items that set the ItemIsFocusable flag, or widgets that set an
appropriate focus policy, can accept keyboard focus.
- \sa setFocus(), QGraphicsWidget::focusPolicy
+ \sa setFocus(), hasFocus(), QGraphicsWidget::focusPolicy
*/
void QGraphicsItem::clearFocus()
{
if (!d_ptr->scene)
return;
- if (d_ptr->isWidget) {
- // Invisible widget items with focus must explicitly clear subfocus.
- static_cast<QGraphicsWidget *>(this)->d_func()->clearFocusWidget();
- }
- if (d_ptr->scene->focusItem() == this) {
+ // Invisible items with focus must explicitly clear subfocus.
+ d_ptr->clearSubFocus();
+ if (hasFocus()) {
// If this item has the scene's input focus, clear it.
d_ptr->scene->setFocusItem(0);
}
}
/*!
+ \since 4.6
+
+ Returns this item's focus proxy, or 0 if this item has no
+ focus proxy.
+
+ \sa setFocusProxy(), ItemAutoDetectsFocusProxy, setFocus(), hasFocus()
+*/
+QGraphicsItem *QGraphicsItem::focusProxy() const
+{
+ return d_ptr->focusProxy;
+}
+
+/*!
+ \since 4.6
+
+ Sets the item's focus proxy to \a item.
+
+ If an item has a focus proxy, the focus proxy will receive
+ input focus when the item gains input focus. The item itself
+ will still have focus (i.e., hasFocus() will return true),
+ but only the focus proxy will receive the keyboard input.
+
+ A focus proxy can itself have a focus proxy, and so on. In
+ such case, keyboard input will be handled by the outermost
+ focus proxy.
+
+ The focus proxy \a item must belong to the same scene as
+ this item.
+
+ \sa focusProxy(), ItemAutoDetectsFocusProxy, setFocus(), hasFocus()
+*/
+void QGraphicsItem::setFocusProxy(QGraphicsItem *item)
+{
+ if (item == d_ptr->focusProxy)
+ return;
+ if (item == this) {
+ qWarning("QGraphicsItem::setFocusProxy: cannot assign self as focus proxy");
+ return;
+ }
+ if (item) {
+ if (item->d_ptr->scene != d_ptr->scene) {
+ qWarning("QGraphicsItem::setFocusProxy: focus proxy must be in same scene");
+ return;
+ }
+ for (QGraphicsItem *f = item->focusProxy(); f != 0; f = f->focusProxy()) {
+ if (f == this) {
+ qWarning("QGraphicsItem::setFocusProxy: %p is already in the focus proxy chain", item);
+ return;
+ }
+ }
+ }
+
+ QGraphicsItem *lastFocusProxy = d_ptr->focusProxy;
+ d_ptr->focusProxy = item;
+ if (d_ptr->scene) {
+ if (lastFocusProxy)
+ d_ptr->scene->d_func()->focusProxyReverseMap.remove(lastFocusProxy, this);
+ if (item)
+ d_ptr->scene->d_func()->focusProxyReverseMap.insert(item, this);
+ }
+}
+
+/*!
+ \since 4.6
+
+ If this item, a child or descendant of this item currently has input
+ focus, this function will return a pointer to that item. If
+ no descendant has input focus, 0 is returned.
+
+ \sa hasFocus(), setFocus(), QWidget::focusWidget()
+*/
+QGraphicsItem *QGraphicsItem::focusItem() const
+{
+ return d_ptr->subFocusItem;
+}
+
+/*!
\since 4.4
Grabs the mouse input.
@@ -2645,7 +2768,7 @@ void QGraphicsItem::ungrabKeyboard()
For convenience, you can also call scenePos() to determine the
item's position in scene coordinates, regardless of its parent.
- \sa x(), y(), setPos(), matrix(), {The Graphics View Coordinate System}
+ \sa x(), y(), setPos(), transform(), {The Graphics View Coordinate System}
*/
QPointF QGraphicsItem::pos() const
{
@@ -2661,10 +2784,12 @@ QPointF QGraphicsItem::pos() const
*/
/*!
- Set's the \a x coordinate of the item's position. Equivalent to
- calling setPos(x, y()).
+ \since 4.6
+
+ Set's the \a x coordinate of the item's position. Equivalent to
+ calling setPos(x, y()).
- \sa x(), setPos()
+ \sa x(), setPos()
*/
void QGraphicsItem::setX(qreal x)
{
@@ -2680,10 +2805,12 @@ void QGraphicsItem::setX(qreal x)
*/
/*!
- Set's the \a y coordinate of the item's position. Equivalent to
- calling setPos(x(), y).
+ \since 4.6
+
+ Set's the \a y coordinate of the item's position. Equivalent to
+ calling setPos(x(), y).
- \sa x(), setPos()
+ \sa x(), setPos()
*/
void QGraphicsItem::setY(qreal y)
{
@@ -2843,11 +2970,10 @@ QMatrix QGraphicsItem::matrix() const
Returns this item's transformation matrix.
- Either the one set by setTransform, or the resulting transformation from
- all the transfmation properties
-
- If no matrix or transformation property has been set, the
- identity matrix is returned.
+ The transformation matrix is combined with the item's rotation(), scale()
+ and transformations() into a combined transformations for the item.
+
+ The default transformation matrix is an identity matrix.
\sa setTransform(), sceneTransform()
*/
@@ -2861,333 +2987,182 @@ QTransform QGraphicsItem::transform() const
/*!
\since 4.6
- Returns the rotation around the X axis.
+ Returns the clockwise rotation, in degrees, around the Z axis. The default
+ value is 0 (i.e., the item is not rotated).
- The default is 0
+ The rotation is combined with the item's scale(), transform() and
+ transformations() to map the item's coordinate system to the parent item.
- \warning The value doesn't take in account any rotation set with
- the setTransform() method.
-
- \sa setXRotation(), {Transformations}
+ \sa setRotation(), transformOriginPoint(), {Transformations}
*/
-qreal QGraphicsItem::xRotation() const
+qreal QGraphicsItem::rotation() const
{
if (!d_ptr->transformData)
return 0;
- return d_ptr->transformData->xRotation;
-}
-
-/*!
- \since 4.6
-
- Sets the rotation around the X axis to \a angle degrees.
-
- \warning The value doesn't take in account any rotation set with the setTransform() method.
-
- \sa xRotation(), setTransformOrigin(), {Transformations}
-*/
-void QGraphicsItem::setXRotation(qreal angle)
-{
- prepareGeometryChange();
- if (!d_ptr->transformData)
- d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
- d_ptr->transformData->xRotation = angle;
- d_ptr->transformData->onlyTransform = false;
- d_ptr->dirtySceneTransform = 1;
+ return d_ptr->transformData->rotation;
}
/*!
\since 4.6
- Returns the rotation around the Y axis.
-
- The default is 0
-
- \warning The value doesn't take in account any rotation set with the setTransform() method.
-
- \sa setYRotation(), {Transformations}
-*/
-qreal QGraphicsItem::yRotation() const
-{
- if (!d_ptr->transformData)
- return 0;
- return d_ptr->transformData->yRotation;
-}
-
-/*!
- \since 4.6
+ Sets the clockwise rotation \a angle, in degrees, around the Z axis. The
+ default value is 0 (i.e., the item is not rotated). Assigning a negative
+ value will rotate the item counter-clockwise. Normally the rotation angle
+ is in the range (-360, 360), but it's also possible to assign values
+ outside of this range (e.g., a rotation of 370 degrees is the same as a
+ rotation of 10 degrees).
- Sets the rotation around the Y axis to \a angle degrees.
+ The item is rotated around its transform origin point, which by default
+ is (0, 0). You can select a different transformation origin by calling
+ setTransformOriginPoint().
- \warning The value doesn't take in account any rotation set with the setTransform() method.
+ The rotation is combined with the item's scale(), transform() and
+ transformations() to map the item's coordinate system to the parent item.
- \sa yRotation(), setTransformOrigin() {Transformations}
+ \sa rotation(), setTransformOriginPoint(), {Transformations}
*/
-void QGraphicsItem::setYRotation(qreal angle)
+void QGraphicsItem::setRotation(qreal angle)
{
prepareGeometryChange();
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
- d_ptr->transformData->yRotation = angle;
+ d_ptr->transformData->rotation = angle;
d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
-}
-
-/*!
- \since 4.6
- Returns the rotation around the Z axis.
-
- The default is 0
-
- \warning The value doesn't take in account any rotation set with the setTransform() method.
-
- \sa setZRotation(), {Transformations}
-*/
-qreal QGraphicsItem::zRotation() const
-{
- if (!d_ptr->transformData)
- return 0;
- return d_ptr->transformData->zRotation;
+ if (d_ptr->isObject)
+ emit static_cast<QGraphicsObject *>(this)->rotationChanged();
}
/*!
\since 4.6
- Sets the rotation around the Z axis to \a angle degrees.
-
- \warning The value doesn't take in account any rotation set with the setTransform() method.
-
- \sa zRotation(), setTransformOrigin(), {Transformations}
-*/
-void QGraphicsItem::setZRotation(qreal angle)
-{
- prepareGeometryChange();
- if (!d_ptr->transformData)
- d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
- d_ptr->transformData->zRotation = angle;
- d_ptr->transformData->onlyTransform = false;
- d_ptr->dirtySceneTransform = 1;
-}
-
-/*!
- \since 4.6
+ Returns the scale factor of the item. The default scale factor is 1.0
+ (i.e., the item is not scaled).
- This convenience function set the rotation angles around the 3 axes
- to \a x, \a y and \a z.
+ The scale is combined with the item's rotation(), transform() and
+ transformations() to map the item's coordinate system to the parent item.
- \sa setXRotation(), setYRotation(), setZRotation(), {Transformations}
+ \sa setScale(), rotation(), {Transformations}
*/
-void QGraphicsItem::setRotation(qreal x, qreal y, qreal z)
+qreal QGraphicsItem::scale() const
{
- prepareGeometryChange();
if (!d_ptr->transformData)
- d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
- d_ptr->transformData->xRotation = x;
- d_ptr->transformData->yRotation = y;
- d_ptr->transformData->zRotation = z;
- d_ptr->transformData->onlyTransform = false;
- d_ptr->dirtySceneTransform = 1;
+ return 1.;
+ return d_ptr->transformData->scale;
}
/*!
\since 4.6
- Returns the scale factor on the X axis.
+ Sets the scale \a factor of the item. The default scale factor is 1.0
+ (i.e., the item is not scaled). A scale factor of 0.0 will collapse the
+ item to a single point. If you provide a negative scale factor, the
+ item will be flipped and mirrored (i.e., rotated 180 degrees).
- The default is 1
+ The item is scaled around its transform origin point, which by default
+ is (0, 0). You can select a different transformation origin by calling
+ setTransformOriginPoint().
- \warning The value doesn't take in account any scaling set with the setTransform() method.
+ The scale is combined with the item's rotation(), transform() and
+ transformations() to map the item's coordinate system to the parent item.
- \sa setXScale(), {Transformations}
+ \sa scale(), setTransformOriginPoint(), {Transformations}
*/
-qreal QGraphicsItem::xScale() const
-{
- if (!d_ptr->transformData)
- return 1;
- return d_ptr->transformData->xScale;
-}
-
-/*!
- \since 4.6
-
- Sets the scale factor on the X axis to \a factor.
-
- \warning The value doesn't take in account any scaling set with the setTransform() method.
-
- \sa xScale(), setTransformOrigin(), {Transformations}
-*/
-void QGraphicsItem::setXScale(qreal factor)
+void QGraphicsItem::setScale(qreal factor)
{
prepareGeometryChange();
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
- d_ptr->transformData->xScale = factor;
+ d_ptr->transformData->scale = factor;
d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
-}
-
-/*!
- \since 4.6
-
- Returns the scale factor on the Y axis.
-
- The default is 1
-
- \warning The value doesn't take in account any scaling set with the setTransform() method.
-
- \sa setYScale(), {Transformations}
-*/
-qreal QGraphicsItem::yScale() const
-{
- if (!d_ptr->transformData)
- return 1;
- return d_ptr->transformData->yScale;
-}
-
-/*!
- \since 4.6
-
- Sets the scale factor on the Y axis to \a factor.
- \warning The value doesn't take in account any scaling set with the setTransform() method.
-
- \sa yScale(), setTransformOrigin(), {Transformations}
-*/
-void QGraphicsItem::setYScale(qreal factor)
-{
- prepareGeometryChange();
- if (!d_ptr->transformData)
- d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
- d_ptr->transformData->yScale = factor;
- d_ptr->transformData->onlyTransform = false;
- d_ptr->dirtySceneTransform = 1;
+ if (d_ptr->isObject)
+ emit static_cast<QGraphicsObject *>(this)->scaleChanged();
}
-/*!
- \since 4.6
-
- This convenience function set the scaling factors on X and Y axis to \a sx and \a sy.
-
- \warning The value doesn't take in account any scaling set with the setTransform() method.
-
- \sa setXScale(), setYScale(), {Transformations}
-*/
-void QGraphicsItem::setScale(qreal sx, qreal sy)
-{
- prepareGeometryChange();
- if (!d_ptr->transformData)
- d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
- d_ptr->transformData->xScale = sx;
- d_ptr->transformData->yScale = sy;
- d_ptr->transformData->onlyTransform = false;
- d_ptr->dirtySceneTransform = 1;
-}
/*!
\since 4.6
- Returns the horizontal shear.
+ Returns a list of graphics transforms that currently apply to this item.
- The default is 0
+ QGraphicsTransform is for applying and controlling a chain of individual
+ transformation operations on an item. It's particularily useful in
+ animations, where each transform operation needs to be interpolated
+ independently, or differently.
- \warning The value doesn't take in account any shearing set with the setTransform() method.
+ The transformations are combined with the item's rotation(), scale() and
+ transform() to map the item's coordinate system to the parent item.
- \sa setHorizontalShear(), {Transformations}
+ \sa scale(), rotation(), transformOriginPoint(), {Transformations}
*/
-qreal QGraphicsItem::horizontalShear() const
+QList<QGraphicsTransform *> QGraphicsItem::transformations() const
{
if (!d_ptr->transformData)
- return 0;
- return d_ptr->transformData->horizontalShear;
+ return QList<QGraphicsTransform *>();
+ return d_ptr->transformData->graphicsTransforms;
}
/*!
\since 4.6
- Sets the horizontal shear to \a shear.
-
- \warning The value doesn't take in account any shearing set with the setTransform() method.
-
- \sa horizontalShear(), {Transformations}
-*/
-void QGraphicsItem::setHorizontalShear(qreal shear)
-{
- prepareGeometryChange();
- if (!d_ptr->transformData)
- d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
- d_ptr->transformData->horizontalShear = shear;
- d_ptr->transformData->onlyTransform = false;
- d_ptr->dirtySceneTransform = 1;
-}
-
-/*!
- \since 4.6
+ Sets a list of graphics \a transformations (QGraphicsTransform) that
+ currently apply to this item.
- Returns the vertical shear.
+ If all you want is to rotate or scale an item, you should call setRotation()
+ or setScale() instead. If you want to set an arbitrary transformation on
+ an item, you can call setTransform().
- The default is 0
+ QGraphicsTransform is for applying and controlling a chain of individual
+ transformation operations on an item. It's particularily useful in
+ animations, where each transform operation needs to be interpolated
+ independently, or differently.
- \warning The value doesn't take in account any shearing set with the setTransform() method.
+ The transformations are combined with the item's rotation(), scale() and
+ transform() to map the item's coordinate system to the parent item.
- \sa setHorizontalShear(), {Transformations}
+ \sa scale(), setTransformOriginPoint(), {Transformations}
*/
-qreal QGraphicsItem::verticalShear() const
-{
- if (!d_ptr->transformData)
- return 0;
- return d_ptr->transformData->verticalShear;
-}
-
-/*!
- \since 4.6
-
- Sets the vertical shear to \a shear.
-
- \warning The value doesn't take in account any shearing set with the setTransform() method.
-
- \sa verticalShear(), {Transformations}
-*/
-void QGraphicsItem::setVerticalShear(qreal shear)
+void QGraphicsItem::setTransformations(const QList<QGraphicsTransform *> &transformations)
{
prepareGeometryChange();
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
- d_ptr->transformData->verticalShear = shear;
+ d_ptr->transformData->graphicsTransforms = transformations;
+ for (int i = 0; i < transformations.size(); ++i)
+ transformations.at(i)->d_func()->setItem(this);
d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
/*!
- \since 4.6
-
- This convenience function sets the horizontal shear to \a sh and the vertical shear to \a sv.
-
- \warning The value doesn't take in account any shearing set with the setTransform() method.
-
- \sa setHorizontalShear(), setVerticalShear()
+ \internal
*/
-void QGraphicsItem::setShear(qreal sh, qreal sv)
+void QGraphicsItemPrivate::appendGraphicsTransform(QGraphicsTransform *t)
{
- prepareGeometryChange();
- if (!d_ptr->transformData)
- d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
- d_ptr->transformData->horizontalShear = sh;
- d_ptr->transformData->verticalShear = sv;
- d_ptr->transformData->onlyTransform = false;
- d_ptr->dirtySceneTransform = 1;
+ if (!transformData)
+ transformData = new QGraphicsItemPrivate::TransformData;
+ if (!transformData->graphicsTransforms.contains(t))
+ transformData->graphicsTransforms.append(t);
+
+ Q_Q(QGraphicsItem);
+ t->d_func()->setItem(q);
+ transformData->onlyTransform = false;
+ dirtySceneTransform = 1;
}
/*!
\since 4.6
- Returns the origin point used for transformation in item coordinate.
+ Returns the origin point for the transformation in item coordinates.
The default is QPointF(0,0).
- \sa setTransformOrigin(), {Transformations}
+ \sa setTransformOriginPoint(), {Transformations}
*/
-QPointF QGraphicsItem::transformOrigin() const
+QPointF QGraphicsItem::transformOriginPoint() const
{
if (!d_ptr->transformData)
return QPointF(0,0);
@@ -3197,11 +3172,11 @@ QPointF QGraphicsItem::transformOrigin() const
/*!
\since 4.6
- Sets the \a origin for transformation in item coordinate
+ Sets the \a origin point for the transformation in item coordinates.
- \sa transformOrigin(), {Transformations}
+ \sa transformOriginPoint(), {Transformations}
*/
-void QGraphicsItem::setTransformOrigin(const QPointF &origin)
+void QGraphicsItem::setTransformOriginPoint(const QPointF &origin)
{
prepareGeometryChange();
if (!d_ptr->transformData)
@@ -3213,15 +3188,15 @@ void QGraphicsItem::setTransformOrigin(const QPointF &origin)
}
/*!
- \fn void QGraphicsItem::setTransformOrigin(qreal x, qreal y)
+ \fn void QGraphicsItem::setTransformOriginPoint(qreal x, qreal y)
\since 4.6
\overload
- Sets the origin for the transformation to the point
- composed of \a x and \a y.
-
- \sa setTransformOrigin(), {Transformations}
+ Sets the origin point for the transformation in item coordinates.
+ This is equivalent to calling setTransformOriginPoint(QPointF(\a x, \a y)).
+
+ \sa setTransformOriginPoint(), {Transformations}
*/
@@ -3498,9 +3473,11 @@ void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine)
to map an item coordiate to a scene coordinate, or mapFromScene() to map
from scene coordinates to item coordinates.
- \warning using this function doesnt affect the value of the transformation properties
+ The transformation matrix is combined with the item's rotation(), scale()
+ and transformations() into a combined transformation that maps the item's
+ coordinate system to its parent.
- \sa transform(), setRotation(), setScale(), setShear(), setTransformOrigin(), {The Graphics View Coordinate System}, {Transformations}
+ \sa transform(), setRotation(), setScale(), setTransformOriginPoint(), {The Graphics View Coordinate System}, {Transformations}
*/
void QGraphicsItem::setTransform(const QTransform &matrix, bool combine)
{
@@ -3557,7 +3534,8 @@ void QGraphicsItem::resetTransform()
/*!
\obsolete
- Use setZRotation() instead
+
+ Use setRotation() instead
Rotates the current item transformation \a angle degrees clockwise around
its origin. To translate around an arbitrary point (x, y), you need to
@@ -3567,8 +3545,6 @@ void QGraphicsItem::resetTransform()
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 6
- \warning using this functionhas no effect on the zRotation value
-
\sa setTransform(), transform(), scale(), shear(), translate()
*/
void QGraphicsItem::rotate(qreal angle)
@@ -3578,6 +3554,7 @@ void QGraphicsItem::rotate(qreal angle)
/*!
\obsolete
+
Use setScale() instead
Scales the current item transformation by (\a sx, \a sy) around its
@@ -3588,8 +3565,6 @@ void QGraphicsItem::rotate(qreal angle)
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 7
- \warning using this function has no effect on the xScale or yScale value
-
\sa setTransform(), transform()
*/
void QGraphicsItem::scale(qreal sx, qreal sy)
@@ -3599,11 +3574,10 @@ void QGraphicsItem::scale(qreal sx, qreal sy)
/*!
\obsolete
- Use setShear instead.
- Shears the current item transformation by (\a sh, \a sv).
+ Use setTransform() instead.
- \warning using this function has no effect on the horizontalShear or verticalShear value
+ Shears the current item transformation by (\a sh, \a sv).
\sa setTransform(), transform()
*/
@@ -3614,7 +3588,8 @@ void QGraphicsItem::shear(qreal sh, qreal sv)
/*!
\obsolete
- Use setPos() or setTransformOrigin() instead.
+
+ Use setPos() or setTransformOriginPoint() instead.
Translates the current item transformation by (\a dx, \a dy).
@@ -4596,6 +4571,34 @@ void QGraphicsItemPrivate::ensureSceneTransform()
/*!
\internal
+*/
+void QGraphicsItemPrivate::setSubFocus()
+{
+ // Update focus child chain.
+ QGraphicsItem *item = q_ptr;
+ QGraphicsItem *parent = item;
+ bool hidden = !visible;
+ do {
+ parent->d_func()->subFocusItem = item;
+ } while (!parent->isWindow() && (parent = parent->d_ptr->parent) && (!hidden || !parent->d_func()->visible));
+}
+
+/*!
+ \internal
+*/
+void QGraphicsItemPrivate::clearSubFocus()
+{
+ // Reset focus child chain.
+ QGraphicsItem *parent = q_ptr;
+ do {
+ if (parent->d_ptr->subFocusItem != q_ptr)
+ break;
+ parent->d_ptr->subFocusItem = 0;
+ } while (!parent->isWindow() && (parent = parent->d_ptr->parent));
+}
+
+/*!
+ \internal
Tells us if it is a proxy widget
*/
@@ -5961,7 +5964,7 @@ void QGraphicsItem::dropEvent(QGraphicsSceneDragDropEvent *event)
focus in events for this item. The default implementation calls
ensureVisible().
- \sa focusOutEvent(), sceneEvent()
+ \sa focusOutEvent(), sceneEvent(), setFocus()
*/
void QGraphicsItem::focusInEvent(QFocusEvent *event)
{
@@ -5972,7 +5975,7 @@ void QGraphicsItem::focusInEvent(QFocusEvent *event)
This event handler, for event \a event, can be reimplemented to receive
focus out events for this item. The default implementation does nothing.
- \sa focusInEvent(), sceneEvent()
+ \sa focusInEvent(), sceneEvent(), setFocus()
*/
void QGraphicsItem::focusOutEvent(QFocusEvent *event)
{
@@ -6710,6 +6713,41 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent
\sa pos()
*/
+/*!
+ \property QGraphicsObject::rotation
+ This property holds the rotation of the item in degrees.
+
+ This specifies how many degrees to rotate the item around its transformOrigin.
+ The default rotation is 0 degrees (i.e. not rotated at all).
+*/
+
+/*!
+ \fn QGraphicsObject::rotationChanged()
+
+ This signal gets emitted whenever the roation of the item changes.
+*/
+
+/*!
+ \property QGraphicsObject::scale
+ This property holds the scale of the item.
+
+ A scale of less than 1 means the item will be displayed smaller than
+ normal, and a scale of greater than 1 means the item will be
+ displayed larger than normal. A negative scale means the item will
+ be mirrored.
+
+ By default, items are displayed at a scale of 1 (i.e. at their
+ normal size).
+
+ Scaling is from the item's transformOrigin.
+*/
+
+/*!
+ \fn void QGraphicsObject::scaleChanged()
+
+ This signal is emitted when the scale of the item changes.
+*/
+
/*!
\property QGraphicsObject::enabled
@@ -6749,6 +6787,25 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent
\sa visible
*/
+/*!
+ \fn const QObjectList &QGraphicsObject::children() const
+ \internal
+
+ This function returns the same value as QObject::children(). It's
+ provided to differentiate between the obsolete member
+ QGraphicsItem::children() and QObject::children(). QGraphicsItem now
+ provides childItems() instead.
+*/
+
+/*!
+ \property QGraphicsObject::transformOriginPoint
+ \brief the transformation origin
+
+ This property sets a specific point in the items coordiante system as the
+ origin for scale and rotation.
+
+ \sa scale, rotation, QGraphicsItem::transformOriginPoint()
+*/
/*!
@@ -9632,13 +9689,10 @@ QVariant QGraphicsSimpleTextItem::extension(const QVariant &variant) const
setParentItem().
The boundingRect() function of QGraphicsItemGroup returns the
- bounding rectangle of all items in the item group. In addition,
- item groups have handlesChildEvents() enabled by default, so all
- events sent to a member of the group go to the item group (i.e.,
- selecting one item in a group will select them all).
- QGraphicsItemGroup ignores the ItemIgnoresTransformations flag on its
- children (i.e., with respect to the geometry of the group item, the
- children are treated as if they were transformable).
+ bounding rectangle of all items in the item group.
+ QGraphicsItemGroup ignores the ItemIgnoresTransformations flag on
+ its children (i.e., with respect to the geometry of the group
+ item, the children are treated as if they were transformable).
There are two ways to construct an item group. The easiest and
most common approach is to pass a list of items (e.g., all
@@ -9969,6 +10023,9 @@ QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag flag)
case QGraphicsItem::ItemAcceptsInputMethod:
str = "ItemAcceptsInputMethod";
break;
+ case QGraphicsItem::ItemAutoDetectsFocusProxy:
+ str = "ItemAutoDetectsFocusProxy";
+ break;
}
debug << str;
return debug;
diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h
index a3076224b..b94fb970a 100644
--- a/src/gui/graphicsview/qgraphicsitem.h
+++ b/src/gui/graphicsview/qgraphicsitem.h
@@ -71,6 +71,7 @@ class QGraphicsSceneHoverEvent;
class QGraphicsSceneMouseEvent;
class QGraphicsSceneWheelEvent;
class QGraphicsScene;
+class QGraphicsTransform;
class QGraphicsWidget;
class QInputMethodEvent;
class QKeyEvent;
@@ -99,7 +100,8 @@ public:
ItemUsesExtendedStyleOption = 0x200,
ItemHasNoContents = 0x400,
ItemSendsGeometryChanges = 0x800,
- ItemAcceptsInputMethod = 0x1000
+ ItemAcceptsInputMethod = 0x1000,
+ ItemAutoDetectsFocusProxy = 0x2000
// NB! Don't forget to increase the d_ptr->flags bit field by 1 when adding a new flag.
};
Q_DECLARE_FLAGS(GraphicsItemFlags, GraphicsItemFlag)
@@ -226,6 +228,11 @@ public:
void setFocus(Qt::FocusReason focusReason = Qt::OtherFocusReason);
void clearFocus();
+ QGraphicsItem *focusProxy() const;
+ void setFocusProxy(QGraphicsItem *item);
+
+ QGraphicsItem *focusItem() const;
+
void grabMouse();
void ungrabMouse();
void grabKeyboard();
@@ -262,34 +269,19 @@ public:
void shear(qreal sh, qreal sv); // ### obsolete
void translate(qreal dx, qreal dy); // ### obsolete
- qreal xRotation() const;
- void setXRotation(qreal angle);
-
- qreal yRotation() const;
- void setYRotation(qreal angle);
-
- qreal zRotation() const;
- void setZRotation(qreal angle);
- void setRotation(qreal x, qreal y, qreal z);
+ void setRotation(qreal angle);
+ qreal rotation() const;
- qreal xScale() const;
- void setXScale(qreal factor);
+ void setScale(qreal scale);
+ qreal scale() const;
- qreal yScale() const;
- void setYScale(qreal factor);
- void setScale(qreal sx, qreal sy);
+ QList<QGraphicsTransform *> transformations() const;
+ void setTransformations(const QList<QGraphicsTransform *> &transformations);
- qreal horizontalShear() const;
- void setHorizontalShear(qreal shear);
-
- qreal verticalShear() const;
- void setVerticalShear(qreal shear);
- void setShear(qreal sh, qreal sv);
-
- QPointF transformOrigin() const;
- void setTransformOrigin(const QPointF &origin);
- inline void setTransformOrigin(qreal x, qreal y)
- { setTransformOrigin(QPointF(x,y)); }
+ QPointF transformOriginPoint() const;
+ void setTransformOriginPoint(const QPointF &origin);
+ inline void setTransformOriginPoint(qreal x, qreal y)
+ { setTransformOriginPoint(QPointF(x,y)); }
virtual void advance(int phase);
@@ -450,6 +442,7 @@ private:
friend class QGraphicsSceneIndexPrivate;
friend class QGraphicsSceneBspTreeIndex;
friend class QGraphicsSceneBspTreeIndexPrivate;
+ friend class QGraphicsTransformPrivate;
friend class ::tst_QGraphicsItem;
friend bool qt_closestLeaf(const QGraphicsItem *, const QGraphicsItem *);
friend bool qt_closestItemFirst(const QGraphicsItem *, const QGraphicsItem *);
@@ -515,9 +508,19 @@ class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem
Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
Q_PROPERTY(qreal z READ zValue WRITE setZValue NOTIFY zChanged)
+ Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
+ Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
+ Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint WRITE setTransformOriginPoint)
public:
QGraphicsObject(QGraphicsItem *parent = 0);
+ // ### Qt 5: Disambiguate
+#ifdef Q_NO_USING_KEYWORD
+ const QObjectList &children() const { return QObject::children(); }
+#else
+ using QObject::children;
+#endif
+
Q_SIGNALS:
void parentChanged();
void opacityChanged();
@@ -526,6 +529,8 @@ Q_SIGNALS:
void xChanged();
void yChanged();
void zChanged();
+ void rotationChanged();
+ void scaleChanged();
protected:
QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene);
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index 472963468..5c3622be2 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -57,6 +57,8 @@
#include "qset.h"
#include "qpixmapcache.h"
#include "qgraphicsview_p.h"
+#include "qgraphicstransform.h"
+#include "qgraphicstransform_p.h"
#include <QtCore/qpoint.h>
@@ -122,6 +124,8 @@ public:
index(-1),
siblingIndex(-1),
depth(0),
+ focusProxy(0),
+ subFocusItem(0),
acceptedMouseButtons(0x1f),
visible(1),
explicitlyHidden(0),
@@ -190,7 +194,7 @@ public:
void combineTransformToParent(QTransform *x, const QTransform *viewTransform = 0) const;
void combineTransformFromParent(QTransform *x, const QTransform *viewTransform = 0) const;
- void updateSceneTransformFromParent();
+ virtual void updateSceneTransformFromParent();
// ### Qt 5: Remove. Workaround for reimplementation added after Qt 4.4.
virtual QVariant inputMethodQueryHelper(Qt::InputMethodQuery query) const;
@@ -198,6 +202,7 @@ public:
void setPosHelper(const QPointF &pos);
void setTransformHelper(const QTransform &transform);
+ void appendGraphicsTransform(QGraphicsTransform *t);
void setVisibleHelper(bool newVisible, bool explicitly, bool update = true);
void setEnabledHelper(bool newEnabled, bool explicitly, bool update = true);
bool discardUpdateRequest(bool ignoreClipping = false, bool ignoreVisibleBit = false,
@@ -390,6 +395,9 @@ public:
|| (childrenCombineOpacity() && isFullyTransparent());
}
+ void setSubFocus();
+ void clearSubFocus();
+
inline QTransform transformToParent() const;
inline void ensureSortedChildren();
@@ -409,6 +417,8 @@ public:
int index;
int siblingIndex;
int depth;
+ QGraphicsItem *focusProxy;
+ QGraphicsItem *subFocusItem;
// Packed 32 bytes
quint32 acceptedMouseButtons : 5;
@@ -438,7 +448,7 @@ public:
// New 32 bits
quint32 fullUpdatePending : 1;
- quint32 flags : 12;
+ quint32 flags : 14;
quint32 dirtyChildrenBoundingRect : 1;
quint32 paintedViewBoundingRectsNeedRepaint : 1;
quint32 dirtySceneTransform : 1;
@@ -451,54 +461,45 @@ public:
quint32 acceptedTouchBeginEvent : 1;
quint32 filtersDescendantEvents : 1;
quint32 sceneTransformTranslateOnly : 1;
- quint32 unused : 7; // feel free to use
+ quint32 unused : 5; // feel free to use
// Optional stacking order
int globalStackingOrder;
QGraphicsItem *q_ptr;
};
-struct QGraphicsItemPrivate::TransformData {
+struct QGraphicsItemPrivate::TransformData
+{
QTransform transform;
- qreal xScale;
- qreal yScale;
- qreal xRotation;
- qreal yRotation;
- qreal zRotation;
- qreal horizontalShear;
- qreal verticalShear;
+ qreal scale;
+ qreal rotation;
qreal xOrigin;
qreal yOrigin;
+ QList<QGraphicsTransform *> graphicsTransforms;
bool onlyTransform;
TransformData() :
- xScale(1.0), yScale(1.0), xRotation(0.0), yRotation(0.0), zRotation(0.0),
- horizontalShear(0.0), verticalShear(0.0), xOrigin(0.0), yOrigin(0.0),
+ scale(1.0), rotation(0.0),
+ xOrigin(0.0), yOrigin(0.0),
onlyTransform(true)
- {}
+ { }
QTransform computedFullTransform(QTransform *postmultiplyTransform = 0) const
{
if (onlyTransform) {
- if (!postmultiplyTransform)
- return transform;
- if (postmultiplyTransform->isIdentity())
+ if (!postmultiplyTransform || postmultiplyTransform->isIdentity())
return transform;
if (transform.isIdentity())
return *postmultiplyTransform;
- QTransform x(transform);
- x *= *postmultiplyTransform;
- return x;
+ return transform * *postmultiplyTransform;
}
QTransform x(transform);
- if (xOrigin != 0 || yOrigin != 0)
- x *= QTransform::fromTranslate(xOrigin, yOrigin);
- x.rotate(xRotation, Qt::XAxis);
- x.rotate(yRotation, Qt::YAxis);
- x.rotate(zRotation, Qt::ZAxis);
- x.shear(horizontalShear, verticalShear);
- x.scale(xScale, yScale);
+ for (int i = 0; i < graphicsTransforms.size(); ++i)
+ graphicsTransforms.at(i)->applyTo(&x);
+ x.translate(xOrigin, yOrigin);
+ x.rotate(rotation, Qt::ZAxis);
+ x.scale(scale, scale);
x.translate(-xOrigin, -yOrigin);
if (postmultiplyTransform)
x *= *postmultiplyTransform;
diff --git a/src/gui/graphicsview/qgraphicslayoutitem.cpp b/src/gui/graphicsview/qgraphicslayoutitem.cpp
index 656af3372..e28016246 100644
--- a/src/gui/graphicsview/qgraphicslayoutitem.cpp
+++ b/src/gui/graphicsview/qgraphicslayoutitem.cpp
@@ -808,6 +808,8 @@ bool QGraphicsLayoutItem::isLayout() const
}
/*!
+ \since 4.6
+
Returns whether a layout should delete this item in its destructor.
If its true, then the layout will delete it. If its false, then it is
assumed that another object has the ownership of it, and the layout won't
@@ -834,6 +836,8 @@ bool QGraphicsLayoutItem::ownedByLayout() const
return d_func()->ownedByLayout;
}
/*!
+ \since 4.6
+
Sets whether a layout should delete this item in its destructor or not.
\a ownership must be true to in order for the layout to delete it.
\sa ownedByLayout()
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index 6b6080b1d..a846cf680 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -484,6 +484,8 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
index->removeItem(item);
}
+ item->d_ptr->clearSubFocus();
+
if (!item->d_ptr->inDestructor && item == tabFocusFirst) {
QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
widget->d_func()->fixFocusChainBeforeReparenting(0, 0);
@@ -491,6 +493,13 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
item->d_func()->scene = 0;
+ // Unregister focus proxy.
+ QMultiHash<QGraphicsItem *, QGraphicsItem *>::iterator it = focusProxyReverseMap.find(item);
+ while (it != focusProxyReverseMap.end() && it.key() == item) {
+ it.value()->d_ptr->focusProxy = 0;
+ it = focusProxyReverseMap.erase(it);
+ }
+
// Remove from parent, or unregister from toplevels.
if (QGraphicsItem *parentItem = item->parentItem()) {
if (parentItem->scene()) {
@@ -559,6 +568,70 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item)
/*!
\internal
*/
+void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item,
+ Qt::FocusReason focusReason)
+{
+ Q_Q(QGraphicsScene);
+ if (item == focusItem)
+ return;
+
+ // Clear focus if asked to set focus on something that can't
+ // accept input focus.
+ if (item && (!(item->flags() & QGraphicsItem::ItemIsFocusable)
+ || !item->isVisible() || !item->isEnabled())) {
+ item = 0;
+ }
+
+ // Set focus on the scene if an item requests focus.
+ if (item) {
+ q->setFocus(focusReason);
+ if (item == focusItem)
+ return;
+ }
+
+ // Auto-update focus proxy. The closest parent that detects
+ // focus proxies is updated as the proxy gains or loses focus.
+ if (item) {
+ QGraphicsItem *p = item->d_ptr->parent;
+ while (p) {
+ if (p->d_ptr->flags & QGraphicsItem::ItemAutoDetectsFocusProxy) {
+ p->setFocusProxy(item);
+ break;
+ }
+ p = p->d_ptr->parent;
+ }
+ }
+
+ if (focusItem) {
+ QFocusEvent event(QEvent::FocusOut, focusReason);
+ lastFocusItem = focusItem;
+ focusItem = 0;
+ sendEvent(lastFocusItem, &event);
+
+ if (lastFocusItem
+ && (lastFocusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
+ // Reset any visible preedit text
+ QInputMethodEvent imEvent;
+ sendEvent(lastFocusItem, &imEvent);
+
+ // Close any external input method panel
+ for (int i = 0; i < views.size(); ++i)
+ views.at(i)->inputContext()->reset();
+ }
+ }
+
+ if (item) {
+ focusItem = item;
+ QFocusEvent event(QEvent::FocusIn, focusReason);
+ sendEvent(item, &event);
+ }
+
+ updateInputMethodSensitivityInViews();
+}
+
+/*!
+ \internal
+*/
void QGraphicsScenePrivate::addPopup(QGraphicsWidget *widget)
{
Q_ASSERT(widget);
@@ -1587,10 +1660,16 @@ QList<QGraphicsItem *> QGraphicsScene::items(Qt::SortOrder order) const
}
/*!
+ \obsolete
+
Returns all visible items at position \a pos in the scene. The items are
listed in descending stacking order (i.e., the first item in the list is the
top-most item, and the last item is the bottom-most item).
+ This function is deprecated and returns incorrect results if the scene
+ contains items that ignore transformations. Use the overload that takes
+ a QTransform instead.
+
\sa itemAt()
*/
QList<QGraphicsItem *> QGraphicsScene::items(const QPointF &pos) const
@@ -1600,9 +1679,8 @@ QList<QGraphicsItem *> QGraphicsScene::items(const QPointF &pos) const
}
/*!
- \fn QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rectangle, Qt::ItemSelectionMode mode) const
-
\overload
+ \obsolete
Returns all visible items that, depending on \a mode, are either inside or
intersect with the specified \a rectangle.
@@ -1610,19 +1688,28 @@ QList<QGraphicsItem *> QGraphicsScene::items(const QPointF &pos) const
The default value for \a mode is Qt::IntersectsItemShape; all items whose
exact shape intersects with or is contained by \a rectangle are returned.
+ This function is deprecated and returns incorrect results if the scene
+ contains items that ignore transformations. Use the overload that takes
+ a QTransform instead.
+
\sa itemAt()
*/
-QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rect, Qt::ItemSelectionMode mode) const
+QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rectangle, Qt::ItemSelectionMode mode) const
{
Q_D(const QGraphicsScene);
- return d->index->items(rect, mode, Qt::AscendingOrder);
+ return d->index->items(rectangle, mode, Qt::AscendingOrder);
}
/*!
\fn QList<QGraphicsItem *> QGraphicsScene::items(qreal x, qreal y, qreal w, qreal h, Qt::ItemSelectionMode mode) const
+ \obsolete
\since 4.3
This convenience function is equivalent to calling items(QRectF(\a x, \a y, \a w, \a h), \a mode).
+
+ This function is deprecated and returns incorrect results if the scene
+ contains items that ignore transformations. Use the overload that takes
+ a QTransform instead.
*/
/*!
@@ -1641,6 +1728,7 @@ QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rect, Qt::ItemSelecti
/*!
\overload
+ \obsolete
Returns all visible items that, depending on \a mode, are either inside or
intersect with the polygon \a polygon.
@@ -1648,6 +1736,10 @@ QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rect, Qt::ItemSelecti
The default value for \a mode is Qt::IntersectsItemShape; all items whose
exact shape intersects with or is contained by \a polygon are returned.
+ This function is deprecated and returns incorrect results if the scene
+ contains items that ignore transformations. Use the overload that takes
+ a QTransform instead.
+
\sa itemAt()
*/
QList<QGraphicsItem *> QGraphicsScene::items(const QPolygonF &polygon, Qt::ItemSelectionMode mode) const
@@ -1658,6 +1750,7 @@ QList<QGraphicsItem *> QGraphicsScene::items(const QPolygonF &polygon, Qt::ItemS
/*!
\overload
+ \obsolete
Returns all visible items that, depending on \a path, are either inside or
intersect with the path \a path.
@@ -1665,6 +1758,10 @@ QList<QGraphicsItem *> QGraphicsScene::items(const QPolygonF &polygon, Qt::ItemS
The default value for \a mode is Qt::IntersectsItemShape; all items whose
exact shape intersects with or is contained by \a path are returned.
+ This function is deprecated and returns incorrect results if the scene
+ contains items that ignore transformations. Use the overload that takes
+ a QTransform instead.
+
\sa itemAt()
*/
QList<QGraphicsItem *> QGraphicsScene::items(const QPainterPath &path, Qt::ItemSelectionMode mode) const
@@ -1790,11 +1887,18 @@ QList<QGraphicsItem *> QGraphicsScene::collidingItems(const QGraphicsItem *item,
}
/*!
+ \overload
+ \obsolete
+
Returns the topmost visible item at the specified \a position, or 0 if
there are no items at this position.
\note The topmost item is the one with the highest Z-value.
+ This function is deprecated and returns incorrect results if the scene
+ contains items that ignore transformations. Use the overload that takes
+ a QTransform instead.
+
\sa items(), collidingItems(), QGraphicsItem::setZValue()
*/
QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position) const
@@ -1804,7 +1908,6 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position) const
}
/*!
- \overload
\since 4.6
Returns the topmost visible item at the specified \a position, or 0
@@ -1825,8 +1928,26 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform
}
/*!
+ \fn QGraphicsScene::itemAt(qreal x, qreal y, const QTransform &deviceTransform) const
+ \overload
+ \since 4.6
+
+ Returns the topmost item at the position specified by (\a x, \a
+ y), or 0 if there are no items at this position.
+
+ \a deviceTransform is the transformation that applies to the view, and needs to
+ be provided if the scene contains items that ignore transformations.
+
+ This convenience function is equivalent to calling \c
+ {itemAt(QPointF(x, y), deviceTransform)}.
+
+ \note The topmost item is the one with the highest Z-value.
+*/
+
+/*!
\fn QGraphicsScene::itemAt(qreal x, qreal y) const
\overload
+ \obsolete
Returns the topmost item at the position specified by (\a x, \a
y), or 0 if there are no items at this position.
@@ -1834,6 +1955,10 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform
This convenience function is equivalent to calling \c
{itemAt(QPointF(x, y))}.
+ This function is deprecated and returns incorrect results if the scene
+ contains items that ignore transformations. Use the overload that takes
+ a QTransform instead.
+
\note The topmost item is the one with the highest Z-value.
*/
@@ -1874,21 +1999,42 @@ QPainterPath QGraphicsScene::selectionArea() const
}
/*!
+ \since 4.6
+
Sets the selection area to \a path. All items within this area are
immediately selected, and all items outside are unselected. You can get
the list of all selected items by calling selectedItems().
+ \a deviceTransform is the transformation that applies to the view, and needs to
+ be provided if the scene contains items that ignore transformations.
+
For an item to be selected, it must be marked as \e selectable
(QGraphicsItem::ItemIsSelectable).
\sa clearSelection(), selectionArea()
*/
+void QGraphicsScene::setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform)
+{
+ setSelectionArea(path, Qt::IntersectsItemShape, deviceTransform);
+}
+
+/*!
+ \obsolete
+ \overload
+
+ Sets the selection area to \a path.
+
+ This function is deprecated and leads to incorrect results if the scene
+ contains items that ignore transformations. Use the overload that takes
+ a QTransform instead.
+*/
void QGraphicsScene::setSelectionArea(const QPainterPath &path)
{
- setSelectionArea(path, Qt::IntersectsItemShape);
+ setSelectionArea(path, Qt::IntersectsItemShape, QTransform());
}
/*!
+ \obsolete
\overload
\since 4.3
@@ -2210,6 +2356,15 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
// Deliver post-change notification
item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant);
+ // Auto-activate the first inactive window if the scene is active.
+ if (d->activationRefCount > 0 && !d->activeWindow && item->isWindow())
+ setActiveWindow(static_cast<QGraphicsWidget *>(item));
+
+ // Ensure that newly added items that have subfocus set, gain
+ // focus automatically if there isn't a focus item already.
+ if (!d->focusItem && item->focusItem())
+ item->focusItem()->setFocus();
+
d->updateInputMethodSensitivityInViews();
}
@@ -2524,49 +2679,10 @@ QGraphicsItem *QGraphicsScene::focusItem() const
void QGraphicsScene::setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason)
{
Q_D(QGraphicsScene);
- if (item == d->focusItem)
- return;
- if (item && (!(item->flags() & QGraphicsItem::ItemIsFocusable)
- || !item->isVisible() || !item->isEnabled())) {
- item = 0;
- }
-
- if (item) {
- setFocus(focusReason);
- if (item == d->focusItem)
- return;
- }
-
- if (d->focusItem) {
- QFocusEvent event(QEvent::FocusOut, focusReason);
- d->lastFocusItem = d->focusItem;
- d->focusItem = 0;
- d->sendEvent(d->lastFocusItem, &event);
-
- if (d->lastFocusItem
- && (d->lastFocusItem->flags() & QGraphicsItem::ItemAcceptsInputMethod)) {
- // Reset any visible preedit text
- QInputMethodEvent imEvent;
- d->sendEvent(d->lastFocusItem, &imEvent);
-
- // Close any external input method panel
- for (int i = 0; i < d->views.size(); ++i)
- d->views.at(i)->inputContext()->reset();
- }
- }
-
- if (item) {
- if (item->isWidget()) {
- // Update focus child chain.
- static_cast<QGraphicsWidget *>(item)->d_func()->setFocusWidget();
- }
-
- d->focusItem = item;
- QFocusEvent event(QEvent::FocusIn, focusReason);
- d->sendEvent(item, &event);
- }
-
- d->updateInputMethodSensitivityInViews();
+ if (item)
+ item->setFocus(focusReason);
+ else
+ d->setFocusItemHelper(item, focusReason);
}
/*!
@@ -2621,13 +2737,17 @@ void QGraphicsScene::clearFocus()
/*!
\property QGraphicsScene::stickyFocus
- \brief whether or not clicking the scene will clear focus
+ \brief whether clicking into the scene background will clear focus
- If this property is false (the default), then clicking on the scene
- background or on an item that does not accept focus, will clear
- focus. Otherwise, focus will remain unchanged.
+ \since 4.6
+
+ In a QGraphicsScene with stickyFocus set to true, focus will remain
+ unchanged when the user clicks into the scene background or on an item
+ that does not accept focus. Otherwise, focus will be cleared.
- The focus change happens in response to a mouse press. You can reimplement
+ By default, this property is false.
+
+ Focus changes in response to a mouse press. You can reimplement
mousePressEvent() in a subclass of QGraphicsScene to toggle this property
based on where the user has clicked.
@@ -3360,7 +3480,7 @@ void QGraphicsScene::helpEvent(QGraphicsSceneHelpEvent *helpEvent)
text = toolTipItem->toolTip();
point = helpEvent->screenPos();
}
- QToolTip::showText(point, text);
+ QToolTip::showText(point, text, helpEvent->widget());
helpEvent->setAccepted(!text.isEmpty());
#endif
}
@@ -3459,8 +3579,7 @@ void QGraphicsScenePrivate::leaveScene()
{
Q_Q(QGraphicsScene);
#ifndef QT_NO_TOOLTIP
- // Remove any tooltips
- QToolTip::showText(QPoint(), QString());
+ QToolTip::hideText();
#endif
// Send HoverLeave events to all existing hover items, topmost first.
QGraphicsView *senderWidget = qobject_cast<QGraphicsView *>(q->sender());
@@ -3563,6 +3682,13 @@ void QGraphicsScene::keyReleaseEvent(QKeyEvent *keyEvent)
void QGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
Q_D(QGraphicsScene);
+ if (d->mouseGrabberItems.isEmpty()) {
+ // Dispatch hover events
+ QGraphicsSceneHoverEvent hover;
+ _q_hoverFromMouseEvent(&hover, mouseEvent);
+ d->dispatchHoverEvent(&hover);
+ }
+
d->mousePressEventHandler(mouseEvent);
}
@@ -4601,7 +4727,7 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
background has been drawn, and before the foreground has been
drawn. All painting is done in \e scene coordinates. Before
drawing each item, the painter must be transformed using
- QGraphicsItem::sceneMatrix().
+ QGraphicsItem::sceneTransform().
The \a options parameter is the list of style option objects for
each item in \a items. The \a numItems parameter is the number of
diff --git a/src/gui/graphicsview/qgraphicsscene.h b/src/gui/graphicsview/qgraphicsscene.h
index d790f90ab..c0c6e75f4 100644
--- a/src/gui/graphicsview/qgraphicsscene.h
+++ b/src/gui/graphicsview/qgraphicsscene.h
@@ -182,8 +182,9 @@ public:
QList<QGraphicsItem *> selectedItems() const;
QPainterPath selectionArea() const;
- void setSelectionArea(const QPainterPath &path);
- void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode);
+ void setSelectionArea(const QPainterPath &path); // ### obsolete
+ void setSelectionArea(const QPainterPath &path, const QTransform &deviceTransform);
+ void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode); // ### obsolete
void setSelectionArea(const QPainterPath &path, Qt::ItemSelectionMode mode, const QTransform &deviceTransform);
QGraphicsItemGroup *createItemGroup(const QList<QGraphicsItem *> &items);
diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h
index 9a91accbf..a4bbdd2aa 100644
--- a/src/gui/graphicsview/qgraphicsscene_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_p.h
@@ -130,6 +130,8 @@ public:
QGraphicsWidget *tabFocusFirst;
QGraphicsWidget *activeWindow;
int activationRefCount;
+ void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason);
+ QMultiHash<QGraphicsItem *, QGraphicsItem *> focusProxyReverseMap;
QList<QGraphicsWidget *> popupWidgets;
void addPopup(QGraphicsWidget *widget);
diff --git a/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp b/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp
index c409a9ecc..07d23b72e 100644
--- a/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp
+++ b/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp
@@ -75,6 +75,8 @@
\sa QGraphicsScene, QGraphicsView, QGraphicsSceneIndex
*/
+#include <QtCore/qglobal.h>
+
#ifndef QT_NO_GRAPHICSVIEW
#include <private/qgraphicsscene_p.h>
@@ -523,7 +525,7 @@ QGraphicsSceneBspTreeIndex::~QGraphicsSceneBspTreeIndex()
}
/*!
- \reimp
+ \internal
Clear the all the BSP index.
*/
void QGraphicsSceneBspTreeIndex::clear()
@@ -564,7 +566,7 @@ void QGraphicsSceneBspTreeIndex::removeItem(QGraphicsItem *item)
}
/*!
- \reimp
+ \internal
Update the BSP when the \a item 's bounding rect has changed.
*/
void QGraphicsSceneBspTreeIndex::prepareBoundingRectChange(const QGraphicsItem *item)
@@ -680,7 +682,7 @@ void QGraphicsSceneBspTreeIndex::setBspTreeDepth(int depth)
}
/*!
- \reimp
+ \internal
This method react to the \a rect change of the scene and
reset the BSP tree index.
@@ -693,11 +695,10 @@ void QGraphicsSceneBspTreeIndex::updateSceneRect(const QRectF &rect)
}
/*!
- \reimp
+ \internal
This method react to the \a change of the \a item and use the \a value to
update the BSP tree if necessary.
-
*/
void QGraphicsSceneBspTreeIndex::itemChange(const QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
diff --git a/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h b/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h
index ed5fa8eec..2293a8e1f 100644
--- a/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h
+++ b/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h
@@ -53,11 +53,7 @@
#ifndef QGRAPHICSBSPTREEINDEX_H
#define QGRAPHICSBSPTREEINDEX_H
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Gui)
+#include <QtCore/qglobal.h>
#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
@@ -65,10 +61,11 @@ QT_MODULE(Gui)
#include "qgraphicsitem_p.h"
#include "qgraphicsscene_bsp_p.h"
-#include <QtCore/qglobal.h>
#include <QtCore/qrect.h>
#include <QtCore/qlist.h>
+QT_BEGIN_NAMESPACE
+
static const int QGRAPHICSSCENE_INDEXTIMER_TIMEOUT = 2000;
class QGraphicsScene;
@@ -204,10 +201,8 @@ static inline bool QRectF_intersects(const QRectF &s, const QRectF &r)
return !(t1 >= b2 || t2 >= b1);
}
-#endif // QT_NO_GRAPHICSVIEW
-
QT_END_NAMESPACE
-QT_END_HEADER
+#endif // QT_NO_GRAPHICSVIEW
#endif // QGRAPHICSBSPTREEINDEX_H
diff --git a/src/gui/graphicsview/qgraphicssceneevent.cpp b/src/gui/graphicsview/qgraphicssceneevent.cpp
index 53019f2e1..92af0ccbb 100644
--- a/src/gui/graphicsview/qgraphicssceneevent.cpp
+++ b/src/gui/graphicsview/qgraphicssceneevent.cpp
@@ -1476,7 +1476,7 @@ void QGraphicsSceneDragDropEvent::acceptProposedAction()
/*!
Returns the action that was performed in this drag and drop.
This should be set by the receiver of the drop and is
- returned by QDrag::start().
+ returned by QDrag::exec().
\sa setDropAction(), acceptProposedAction()
*/
diff --git a/src/gui/graphicsview/qgraphicsscenelinearindex.cpp b/src/gui/graphicsview/qgraphicsscenelinearindex.cpp
index 45cf70212..52bbc79b4 100644
--- a/src/gui/graphicsview/qgraphicsscenelinearindex.cpp
+++ b/src/gui/graphicsview/qgraphicsscenelinearindex.cpp
@@ -77,7 +77,7 @@
/*!
\fn void QGraphicsSceneLinearIndex::clear()
- \reimp
+ \internal
Clear the all the BSP index.
*/
diff --git a/src/gui/graphicsview/qgraphicsscenelinearindex_p.h b/src/gui/graphicsview/qgraphicsscenelinearindex_p.h
index 3dbbc6346..1f3d58bcc 100644
--- a/src/gui/graphicsview/qgraphicsscenelinearindex_p.h
+++ b/src/gui/graphicsview/qgraphicsscenelinearindex_p.h
@@ -53,13 +53,7 @@
// We mean it.
//
-#include <QtCore/qlist.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Gui)
+#include <QtCore/qglobal.h>
#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
@@ -68,6 +62,12 @@ QT_MODULE(Gui)
#include <QtGui/qgraphicsitem.h>
#include <private/qgraphicssceneindex_p.h>
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
class Q_AUTOTEST_EXPORT QGraphicsSceneLinearIndex : public QGraphicsSceneIndex
{
Q_OBJECT
diff --git a/src/gui/graphicsview/qgraphicstransform.cpp b/src/gui/graphicsview/qgraphicstransform.cpp
new file mode 100644
index 000000000..890aff74a
--- /dev/null
+++ b/src/gui/graphicsview/qgraphicstransform.cpp
@@ -0,0 +1,573 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \class QGraphicsTransform
+ \brief The QGraphicsTransform class is an abstract base class for building
+ advanced transformations on QGraphicsItems.
+ \since 4.6
+
+ As an alternative to QGraphicsItem::transform, QGraphicsTransform lets you
+ create and control advanced transformations that can be configured
+ independently using specialized properties.
+
+ QGraphicsItem allows you to assign any number of QGraphicsTransform
+ instances to one QGraphicsItem. Each QGraphicsTransform is applied in
+ order, one at a time, to the QGraphicsItem it's assigned to.
+
+ QGraphicsTransform is particularily useful for animations. Whereas
+ QGraphicsItem::setTransform() lets you assign any transform directly to an
+ item, there is no direct way to interpolate between two different
+ transformations (e.g., when transitioning between two states, each for
+ which the item has a different arbitrary transform assigned). Using
+ QGraphicsTransform you can interpolate the property values of each
+ independent transformation. The resulting operation is then combined into a
+ single transform which is applied to QGraphicsItem.
+
+ If you want to create your own configurable transformation, you can create
+ a subclass of QGraphicsTransform (or any or the existing subclasses), and
+ reimplement the pure virtual applyTo() function, which takes a pointer to a
+ QTransform. Each operation you would like to apply should be exposed as
+ properties (e.g., customTransform->setVerticalShear(2.5)). Inside you
+ reimplementation of applyTo(), you can modify the provided transform
+ respectively.
+
+ QGraphicsTransform can be used together with QGraphicsItem::setTransform(),
+ QGraphicsItem::setRotation(), and QGraphicsItem::setScale().
+
+ \sa QGraphicsItem::transform(), QGraphicsScale, QGraphicsRotation, QGraphicsRotation3D
+*/
+
+#include "qgraphicstransform.h"
+#include "qgraphicsitem_p.h"
+#include "qgraphicstransform_p.h"
+#include <QDebug>
+
+#include <math.h>
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+QT_BEGIN_NAMESPACE
+
+void QGraphicsTransformPrivate::setItem(QGraphicsItem *i)
+{
+ if (item == i)
+ return;
+
+ if (item) {
+ Q_Q(QGraphicsTransform);
+ QGraphicsItemPrivate *d_ptr = item->d_ptr;
+
+ item->prepareGeometryChange();
+ Q_ASSERT(d_ptr->transformData);
+ d_ptr->transformData->graphicsTransforms.removeAll(q);
+ d_ptr->dirtySceneTransform = 1;
+ item = 0;
+ }
+
+ item = i;
+}
+
+void QGraphicsTransformPrivate::updateItem(QGraphicsItem *item)
+{
+ item->prepareGeometryChange();
+ item->d_ptr->dirtySceneTransform = 1;
+}
+
+/*!
+ Constructs a new QGraphicsTransform with the given \a parent.
+*/
+QGraphicsTransform::QGraphicsTransform(QObject *parent)
+ : QObject(*new QGraphicsTransformPrivate, parent)
+{
+}
+
+/*!
+ Destroys the graphics transform.
+*/
+QGraphicsTransform::~QGraphicsTransform()
+{
+ Q_D(QGraphicsTransform);
+ d->setItem(0);
+}
+
+/*!
+ \internal
+*/
+QGraphicsTransform::QGraphicsTransform(QGraphicsTransformPrivate &p, QObject *parent)
+ : QObject(p, parent)
+{
+}
+
+/*!
+ Applies this transformation to an identity transform, and returns the
+ resulting transform.
+
+ This is equivalent to passing an identity transform to applyTo().
+
+ \sa applyTo()
+*/
+QTransform QGraphicsTransform::transform() const
+{
+ QTransform t;
+ applyTo(&t);
+ return t;
+}
+
+/*!
+ \fn void QGraphicsTransform::applyTo(QTransform *transform) const
+
+ This pure virtual method has to be reimplemented in derived classes.
+
+ It applies this transformation to \a transform.
+
+ \sa QGraphicsItem::transform()
+*/
+
+/*!
+ Notifies that this transform operation has changed its parameters in such a
+ way that applyTo() will return a different result than before.
+
+ When implementing you own custom graphics transform, you must call this
+ function every time you change a parameter, to let QGraphicsItem know that
+ its transformation needs to be updated.
+
+ \sa applyTo()
+*/
+void QGraphicsTransform::update()
+{
+ Q_D(QGraphicsTransform);
+ if (d->item)
+ d->updateItem(d->item);
+}
+
+/*!
+ \class QGraphicsScale
+ \brief The QGraphicsScale class provides a scale transformation.
+ \since 4.6
+
+ QGraphicsScene provides certain parameters to help control how the scale
+ should be applied.
+
+ The origin is the point that the item is scaled from (i.e., it stays fixed
+ relative to the parent as the rest of the item grows). By default the
+ origin is QPointF(0, 0).
+
+ The two parameters xScale and yScale describe the scale factors to apply in
+ horizontal and vertical direction. They can take on any value, including 0
+ (to collapse the item to a point) or negativate value. A negative xScale
+ value will mirror the item horizontally. A negative yScale value will flip
+ the item vertically.
+
+ \sa QGraphicsTransform, QGraphicsItem::setScale(), QTransform::scale()
+*/
+
+class QGraphicsScalePrivate : public QGraphicsTransformPrivate
+{
+public:
+ QGraphicsScalePrivate()
+ : xScale(1), yScale(1) {}
+ QPointF origin;
+ qreal xScale;
+ qreal yScale;
+};
+
+/*!
+ Constructs an empty QGraphicsScale object with the given \a parent.
+*/
+QGraphicsScale::QGraphicsScale(QObject *parent)
+ : QGraphicsTransform(*new QGraphicsScalePrivate, parent)
+{
+}
+
+/*!
+ Destroys the graphics scale.
+*/
+QGraphicsScale::~QGraphicsScale()
+{
+}
+
+/*!
+ \property QGraphicsScale::origin
+ \brief The QGraphicsScene class provides the origin of the scale.
+
+ All scaling will be done relative to this point (i.e., this point
+ will stay fixed, relative to the parent, when the item is scaled).
+
+ \sa xScale, yScale
+*/
+QPointF QGraphicsScale::origin() const
+{
+ Q_D(const QGraphicsScale);
+ return d->origin;
+}
+void QGraphicsScale::setOrigin(const QPointF &point)
+{
+ Q_D(QGraphicsScale);
+ d->origin = point;
+ update();
+ emit originChanged();
+}
+
+/*!
+ \property QGraphicsScale::xScale
+ \brief the horizontal scale factor.
+
+ The scale factor can be any real number; the default value is 1.0. If you
+ set the factor to 0.0, the item will be collapsed to a single point. If you
+ provide a negative value, the item will be mirrored horizontally around its
+ origin.
+
+ \sa yScale, origin
+*/
+qreal QGraphicsScale::xScale() const
+{
+ Q_D(const QGraphicsScale);
+ return d->xScale;
+}
+void QGraphicsScale::setXScale(qreal scale)
+{
+ Q_D(QGraphicsScale);
+ if (d->xScale == scale)
+ return;
+ d->xScale = scale;
+ update();
+ emit scaleChanged();
+}
+
+/*!
+ \property QGraphicsScale::yScale
+ \brief the vertical scale factor.
+
+ The scale factor can be any real number; the default value is 1.0. If you
+ set the factor to 0.0, the item will be collapsed to a single point. If you
+ provide a negative value, the item will be flipped vertically around its
+ origin.
+
+ \sa xScale, origin
+*/
+qreal QGraphicsScale::yScale() const
+{
+ Q_D(const QGraphicsScale);
+ return d->yScale;
+}
+void QGraphicsScale::setYScale(qreal scale)
+{
+ Q_D(QGraphicsScale);
+ if (d->yScale == scale)
+ return;
+ d->yScale = scale;
+ update();
+ emit scaleChanged();
+}
+
+/*!
+ \reimp
+*/
+void QGraphicsScale::applyTo(QTransform *transform) const
+{
+ Q_D(const QGraphicsScale);
+ transform->translate(d->origin.x(), d->origin.y());
+ transform->scale(d->xScale, d->yScale);
+ transform->translate(-d->origin.x(), -d->origin.y());
+}
+
+/*!
+ \fn QGraphicsScale::originChanged()
+
+ QGraphicsScale emits this signal when its origin changes.
+
+ \sa QGraphicsScale::origin
+*/
+
+/*!
+ \fn QGraphicsScale::scaleChanged()
+
+ This signal is emitted whenever the xScale or yScale of the object
+ changes.
+
+ \sa QGraphicsScale::xScale, QGraphicsScale::yScale
+*/
+
+/*!
+ \class QGraphicsRotation
+ \brief The QGraphicsRotation class provides a rotation transformation.
+ \since 4.6
+
+ QGraphicsRotation provides certain parameters to help control how the
+ rotation should be applied.
+
+ The origin is the point that the item is rotated around (i.e., it stays
+ fixed relative to the parent as the rest of the item is rotated). By
+ default the origin is QPointF(0, 0).
+
+ The angle property provides the number of degrees to rotate the item
+ clockwise around the origin. This value also be negative, indicating a
+ counter-clockwise rotation. For animation purposes it may also be useful to
+ provide rotation angles exceeding (-360, 360) degrees, for instance to
+ animate how an item rotates several times.
+
+ \sa QGraphicsTransform, QGraphicsItem::setRotation(), QTransform::rotate()
+*/
+
+class QGraphicsRotationPrivate : public QGraphicsTransformPrivate
+{
+public:
+ QGraphicsRotationPrivate()
+ : angle(0) {}
+ QPointF origin;
+ qreal originY;
+ qreal angle;
+};
+
+/*!
+ Constructs a new QGraphicsRotation with the given \a parent.
+*/
+QGraphicsRotation::QGraphicsRotation(QObject *parent)
+ : QGraphicsTransform(*new QGraphicsRotationPrivate, parent)
+{
+}
+
+/*!
+ \internal
+*/
+QGraphicsRotation::QGraphicsRotation(QGraphicsRotationPrivate &p, QObject *parent)
+ : QGraphicsTransform(p, parent)
+{
+}
+
+/*!
+ Destroys the graphics rotation.
+*/
+QGraphicsRotation::~QGraphicsRotation()
+{
+}
+
+/*!
+ \property QGraphicsRotation::origin
+ \brief the origin of the rotation.
+
+ All rotations will be done relative to this point (i.e., this point
+ will stay fixed, relative to the parent, when the item is rotated).
+
+ \sa angle
+*/
+QPointF QGraphicsRotation::origin() const
+{
+ Q_D(const QGraphicsRotation);
+ return d->origin;
+}
+void QGraphicsRotation::setOrigin(const QPointF &point)
+{
+ Q_D(QGraphicsRotation);
+ d->origin = point;
+ update();
+ emit originChanged();
+}
+
+/*!
+ \property QGraphicsRotation::angle
+ \brief the angle for clockwise rotation, in degrees.
+
+ The angle can be any real number; the default value is 0.0. A value of 180
+ will rotate 180 degrees, clockwise. If you provide a negative number, the
+ item will be rotated counter-clockwise. Normally the rotation angle will be
+ in the range (-360, 360), but you can also provide numbers outside of this
+ range (e.g., a angle of 370 degrees gives the same result as 10 degrees).
+
+ \sa origin
+*/
+qreal QGraphicsRotation::angle() const
+{
+ Q_D(const QGraphicsRotation);
+ return d->angle;
+}
+void QGraphicsRotation::setAngle(qreal angle)
+{
+ Q_D(QGraphicsRotation);
+ if (d->angle == angle)
+ return;
+ d->angle = angle;
+ update();
+ emit angleChanged();
+}
+
+/*!
+ \reimp
+*/
+void QGraphicsRotation::applyTo(QTransform *t) const
+{
+ Q_D(const QGraphicsRotation);
+ if (d->angle) {
+ t->translate(d->origin.x(), d->origin.y());
+ t->rotate(d->angle);
+ t->translate(-d->origin.x(), -d->origin.y());
+ }
+}
+
+/*!
+ \fn QGraphicsRotation::originChanged()
+
+ This signal is emitted whenever the origin has changed.
+
+ \sa QGraphicsRotation::origin
+*/
+
+/*!
+ \fn void QGraphicsRotation::angleChanged()
+
+ This signal is emitted whenever the angle has changed.
+
+ \sa QGraphicsRotation::angle
+*/
+
+/*!
+ \class QGraphicsRotation3D
+ \brief The QGraphicsRotation3D class provides rotation in 3 dimensions.
+ \since 4.6
+
+ QGraphicsRotation3D extends QGraphicsRotation with the ability to rotate
+ around a given axis.
+
+ You can provide the desired axis by assigning a QVector3D to the axis
+ property. The angle property, which is provided by QGraphicsRotation, now
+ describes the number of degrees to rotate around this axis.
+
+ By default the axis is (0, 0, 1), giving QGraphicsRotation3D the same
+ default behavior as QGraphicsRotation (i.e., rotation around the Z axis).
+
+ \sa QGraphicsTransform, QGraphicsItem::setRotation(), QTransform::rotate()
+*/
+
+class QGraphicsRotation3DPrivate : public QGraphicsRotationPrivate
+{
+public:
+ QGraphicsRotation3DPrivate() {}
+
+ QVector3D axis;
+};
+
+/*!
+ Constructs a new QGraphicsRotation3D with the given \a parent.
+*/
+QGraphicsRotation3D::QGraphicsRotation3D(QObject *parent)
+ : QGraphicsRotation(*new QGraphicsRotation3DPrivate, parent)
+{
+}
+
+/*!
+ Destroys the 3D graphics rotation.
+*/
+QGraphicsRotation3D::~QGraphicsRotation3D()
+{
+}
+
+/*!
+ \property QGraphicsRotation3D::axis
+ \brief a rotation axis, specified by a vector in 3D space.
+
+ This can be any axis in 3D space. By default the axis is (0, 0, 1),
+ which is aligned with the Z axis and provides the same behavior
+ for the rotation angle as QGraphicsRotation. If you provide another
+ axis, QGraphicsRotation3D will provide a transformation that rotates
+ around this axis. For example, if you would like to rotate an item
+ around its X axis, you could pass (1, 0, 0) as the axis.
+
+ \sa QTransform, QGraphicsRotation::angle
+*/
+QVector3D QGraphicsRotation3D::axis()
+{
+ Q_D(QGraphicsRotation3D);
+ return d->axis;
+}
+void QGraphicsRotation3D::setAxis(const QVector3D &axis)
+{
+ Q_D(QGraphicsRotation3D);
+ d->axis = axis;
+ update();
+}
+
+static const qreal inv_dist_to_plane = 1. / 1024.;
+
+/*!
+ \reimp
+*/
+void QGraphicsRotation3D::applyTo(QTransform *t) const
+{
+ Q_D(const QGraphicsRotation3D);
+
+ if (d->angle == 0. ||
+ (d->axis.z() == 0. && d->axis.y() == 0 && d->axis.x() == 0))
+ return;
+
+ qreal rad = d->angle * 2. * M_PI / 360.;
+ qreal c = ::cos(rad);
+ qreal s = ::sin(rad);
+
+ qreal x = d->axis.x();
+ qreal y = d->axis.y();
+ qreal z = d->axis.z();
+
+ qreal len = x * x + y * y + z * z;
+ if (len != 1.) {
+ len = 1./::sqrt(len);
+ x *= len;
+ y *= len;
+ z *= len;
+ }
+
+ t->translate(d->origin.x(), d->origin.y());
+ *t = QTransform(x*x*(1-c)+c, x*y*(1-c)-z*s, x*z*(1-c)+y*s*inv_dist_to_plane,
+ y*x*(1-c)+z*s, y*y*(1-c)+c, y*z*(1-c)-x*s*inv_dist_to_plane,
+ 0, 0, 1) * *t;
+ t->translate(-d->origin.x(), -d->origin.y());
+}
+
+/*!
+ \fn void QGraphicsRotation3D::axisChanged()
+
+ This signal is emitted whenever the axis of the object changes.
+*/
+
+#include "moc_qgraphicstransform.cpp"
+
+QT_END_NAMESPACE
diff --git a/src/gui/graphicsview/qgraphicstransform.h b/src/gui/graphicsview/qgraphicstransform.h
new file mode 100644
index 000000000..d7c07d023
--- /dev/null
+++ b/src/gui/graphicsview/qgraphicstransform.h
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGRAPHICSTRANSFORM_H
+#define QGRAPHICSTRANSFORM_H
+
+#include <QtCore/QObject>
+#include <QtGui/QTransform>
+#include <QtGui/QVector3D>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+class QGraphicsItem;
+class QGraphicsTransformPrivate;
+
+class Q_GUI_EXPORT QGraphicsTransform : public QObject
+{
+ Q_OBJECT
+public:
+ QGraphicsTransform(QObject *parent = 0);
+ ~QGraphicsTransform();
+
+ QTransform transform() const;
+ virtual void applyTo(QTransform *transform) const = 0;
+
+protected Q_SLOTS:
+ void update();
+
+protected:
+ QGraphicsTransform(QGraphicsTransformPrivate &p, QObject *parent);
+
+private:
+ friend class QGraphicsItem;
+ friend class QGraphicsItemPrivate;
+ Q_DECLARE_PRIVATE(QGraphicsTransform)
+};
+
+class QGraphicsScalePrivate;
+
+class Q_GUI_EXPORT QGraphicsScale : public QGraphicsTransform
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QPointF origin READ origin WRITE setOrigin NOTIFY originChanged)
+ Q_PROPERTY(qreal xScale READ xScale WRITE setXScale NOTIFY scaleChanged)
+ Q_PROPERTY(qreal yScale READ yScale WRITE setYScale NOTIFY scaleChanged)
+public:
+ QGraphicsScale(QObject *parent = 0);
+ ~QGraphicsScale();
+
+ QPointF origin() const;
+ void setOrigin(const QPointF &point);
+
+ qreal xScale() const;
+ void setXScale(qreal);
+
+ qreal yScale() const;
+ void setYScale(qreal);
+
+ void applyTo(QTransform *transform) const;
+
+Q_SIGNALS:
+ void originChanged();
+ void scaleChanged();
+
+private:
+ Q_DECLARE_PRIVATE(QGraphicsScale)
+};
+
+class QGraphicsRotationPrivate;
+
+class Q_GUI_EXPORT QGraphicsRotation : public QGraphicsTransform
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QPointF origin READ origin WRITE setOrigin NOTIFY originChanged)
+ Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged)
+public:
+ QGraphicsRotation(QObject *parent = 0);
+ ~QGraphicsRotation();
+
+ QPointF origin() const;
+ void setOrigin(const QPointF &point);
+
+ qreal angle() const;
+ void setAngle(qreal);
+
+ void applyTo(QTransform *transform) const;
+
+Q_SIGNALS:
+ void originChanged();
+ void angleChanged();
+
+protected:
+ QGraphicsRotation(QGraphicsRotationPrivate &p, QObject *parent);
+private:
+ Q_DECLARE_PRIVATE(QGraphicsRotation)
+};
+
+class QGraphicsRotation3DPrivate;
+
+class Q_GUI_EXPORT QGraphicsRotation3D : public QGraphicsRotation
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QVector3D axis READ axis WRITE setAxis NOTIFY axisChanged)
+public:
+ QGraphicsRotation3D(QObject *parent = 0);
+ ~QGraphicsRotation3D();
+
+ QVector3D axis();
+ void setAxis(const QVector3D &axis);
+
+ void applyTo(QTransform *transform) const;
+
+Q_SIGNALS:
+ void axisChanged();
+
+private:
+ Q_DECLARE_PRIVATE(QGraphicsRotation3D)
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QFXTRANSFORM_H
diff --git a/src/gui/graphicsview/qgraphicstransform_p.h b/src/gui/graphicsview/qgraphicstransform_p.h
new file mode 100644
index 000000000..2d36edae2
--- /dev/null
+++ b/src/gui/graphicsview/qgraphicstransform_p.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://www.qtsoftware.com/contact.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGRAPHICSTRANSFORM_P_H
+#define QGRAPHICSTRANSFORM_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
+// file may change from version to version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qobject_p.h"
+
+class QGraphicsItem;
+
+class QGraphicsTransformPrivate : public QObjectPrivate {
+public:
+ Q_DECLARE_PUBLIC(QGraphicsTransform)
+
+ QGraphicsTransformPrivate()
+ : QObjectPrivate(), item(0) {}
+
+ QGraphicsItem *item;
+
+ void setItem(QGraphicsItem *item);
+ static void updateItem(QGraphicsItem *item);
+};
+
+#endif // QGRAPHICSTRANSFORM_P_H
diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp
index 1cea8db61..ca55f2e96 100644
--- a/src/gui/graphicsview/qgraphicsview.cpp
+++ b/src/gui/graphicsview/qgraphicsview.cpp
@@ -97,8 +97,8 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
setViewport(new QGLWidget). QGraphicsView takes ownership of the viewport
widget.
- QGraphicsView supports affine transformations, using QMatrix. You can
- either pass a matrix to setMatrix(), or you can call one of the
+ QGraphicsView supports affine transformations, using QTransform. You can
+ either pass a matrix to setTransform(), or you can call one of the
convenience functions rotate(), scale(), translate() or shear(). The most
two common transformations are scaling, which is used to implement
zooming, and rotation. QGraphicsView keeps the center of the view fixed
@@ -1583,7 +1583,7 @@ void QGraphicsView::setSceneRect(const QRectF &rect)
Returns the current transformation matrix for the view. If no current
transformation is set, the identity matrix is returned.
- \sa setMatrix(), rotate(), scale(), shear(), translate()
+ \sa setMatrix(), transform(), rotate(), scale(), shear(), translate()
*/
QMatrix QGraphicsView::matrix() const
{
@@ -1615,7 +1615,7 @@ QMatrix QGraphicsView::matrix() const
a view coordinate to a floating point scene coordinate, or mapFromScene()
to map from floating point scene coordinates to view coordinates.
- \sa matrix(), rotate(), scale(), shear(), translate()
+ \sa matrix(), setTransform(), rotate(), scale(), shear(), translate()
*/
void QGraphicsView::setMatrix(const QMatrix &matrix, bool combine)
{
@@ -1624,6 +1624,8 @@ void QGraphicsView::setMatrix(const QMatrix &matrix, bool combine)
/*!
Resets the view transformation matrix to the identity matrix.
+
+ \sa resetTransform()
*/
void QGraphicsView::resetMatrix()
{
@@ -1633,7 +1635,7 @@ void QGraphicsView::resetMatrix()
/*!
Rotates the current view transformation \a angle degrees clockwise.
- \sa setMatrix(), matrix(), scale(), shear(), translate()
+ \sa setTransform(), transform(), scale(), shear(), translate()
*/
void QGraphicsView::rotate(qreal angle)
{
@@ -1646,7 +1648,7 @@ void QGraphicsView::rotate(qreal angle)
/*!
Scales the current view transformation by (\a sx, \a sy).
- \sa setMatrix(), matrix(), rotate(), shear(), translate()
+ \sa setTransform(), transform(), rotate(), shear(), translate()
*/
void QGraphicsView::scale(qreal sx, qreal sy)
{
@@ -1659,7 +1661,7 @@ void QGraphicsView::scale(qreal sx, qreal sy)
/*!
Shears the current view transformation by (\a sh, \a sv).
- \sa setMatrix(), matrix(), rotate(), scale(), translate()
+ \sa setTransform(), transform(), rotate(), scale(), translate()
*/
void QGraphicsView::shear(qreal sh, qreal sv)
{
@@ -1672,7 +1674,7 @@ void QGraphicsView::shear(qreal sh, qreal sv)
/*!
Translates the current view transformation by (\a dx, \a dy).
- \sa setMatrix(), matrix(), rotate(), shear()
+ \sa setTransform(), transform(), rotate(), shear()
*/
void QGraphicsView::translate(qreal dx, qreal dy)
{
@@ -1830,7 +1832,7 @@ void QGraphicsView::ensureVisible(const QGraphicsItem *item, int xmargin, int ym
If \a rect is empty, or if the viewport is too small, this
function will do nothing.
- \sa setMatrix(), ensureVisible(), centerOn()
+ \sa setTransform(), ensureVisible(), centerOn()
*/
void QGraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRatioMode)
{
@@ -3129,7 +3131,7 @@ void QGraphicsView::mouseReleaseEvent(QMouseEvent *event)
}
} else
#endif
- if (d->dragMode == QGraphicsView::ScrollHandDrag) {
+ if (d->dragMode == QGraphicsView::ScrollHandDrag && event->button() == Qt::LeftButton) {
#ifndef QT_NO_CURSOR
// Restore the open hand cursor. ### There might be items
// under the mouse that have a valid cursor at this time, so
@@ -3552,6 +3554,8 @@ QTransform QGraphicsView::viewportTransform() const
}
/*!
+ \since 4.6
+
Returns true if the view is transformed (i.e., a non-identity transform
has been assigned, or the scrollbars are adjusted).
diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp
index 86c0b4866..3ea80cedb 100644
--- a/src/gui/graphicsview/qgraphicswidget.cpp
+++ b/src/gui/graphicsview/qgraphicswidget.cpp
@@ -1716,49 +1716,18 @@ void QGraphicsWidget::setFocusPolicy(Qt::FocusPolicy policy)
/*!
If this widget, a child or descendant of this widget currently has input
focus, this function will return a pointer to that widget. If
- no descendant has input focus, 0 is returned.
+ no descendant widget has input focus, 0 is returned.
- \sa QWidget::focusWidget()
+ \sa QGraphicsItem::focusItem(), QWidget::focusWidget()
*/
QGraphicsWidget *QGraphicsWidget::focusWidget() const
{
Q_D(const QGraphicsWidget);
- return d->focusChild;
+ if (d->subFocusItem && d->subFocusItem->d_ptr->isWidget)
+ return static_cast<QGraphicsWidget *>(d->subFocusItem);
+ return 0;
}
-/*! \property QGraphicsWidget::horizontalShear
- \brief This property holds the horizontal shear value for the item.
- */
-
-/*! \property QGraphicsWidget::transformOrigin
- \brief This property holds the origin point used for transformations
- in item coordinates.
- */
-
-/*! \property QGraphicsWidget::verticalShear
- \brief This property holds the vertical shear value for the item.
- */
-
-/*! \property QGraphicsWidget::xRotation
- \brief This property holds the value for rotation around the x axis.
- */
-
-/*! \property QGraphicsWidget::xScale
- \brief This property holds the scale factor for the x axis.
- */
-
-/*! \property QGraphicsWidget::yRotation
- \brief This property holds the value for rotation around the y axis.
- */
-
-/*! \property QGraphicsWidget::yScale
- \brief This property holds the scale factor for the y axis.
- */
-
-/*! \property QGraphicsWidget::zRotation
- \brief This property holds the value for rotation around the z axis.
- */
-
#ifndef QT_NO_SHORTCUT
/*!
\since 4.5
@@ -2284,6 +2253,7 @@ bool QGraphicsWidget::close()
#ifdef Q_NO_USING_KEYWORD
/*!
\fn const QObjectList &QGraphicsWidget::children() const
+ \internal
This function returns the same value as QObject::children(). It's
provided to differentiate between the obsolete member
diff --git a/src/gui/graphicsview/qgraphicswidget.h b/src/gui/graphicsview/qgraphicswidget.h
index b72ec9f3a..d03a637b5 100644
--- a/src/gui/graphicsview/qgraphicswidget.h
+++ b/src/gui/graphicsview/qgraphicswidget.h
@@ -77,14 +77,6 @@ class Q_GUI_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphicsLay
Q_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
- Q_PROPERTY(QPointF transformOrigin READ transformOrigin WRITE setTransformOrigin)
- Q_PROPERTY(qreal xRotation READ xRotation WRITE setXRotation)
- Q_PROPERTY(qreal yRotation READ yRotation WRITE setYRotation)
- Q_PROPERTY(qreal zRotation READ zRotation WRITE setZRotation)
- Q_PROPERTY(qreal xScale READ xScale WRITE setXScale)
- Q_PROPERTY(qreal yScale READ yScale WRITE setYScale)
- Q_PROPERTY(qreal horizontalShear READ horizontalShear WRITE setHorizontalShear)
- Q_PROPERTY(qreal verticalShear READ verticalShear WRITE setVerticalShear)
public:
QGraphicsWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
~QGraphicsWidget();
diff --git a/src/gui/graphicsview/qgraphicswidget_p.cpp b/src/gui/graphicsview/qgraphicswidget_p.cpp
index c9212f7af..8eac063ae 100644
--- a/src/gui/graphicsview/qgraphicswidget_p.cpp
+++ b/src/gui/graphicsview/qgraphicswidget_p.cpp
@@ -626,34 +626,6 @@ bool QGraphicsWidgetPrivate::hasDecoration() const
return (windowFlags & Qt::Window) && (windowFlags & Qt::WindowTitleHint);
}
-/*!
- \internal
-*/
-void QGraphicsWidgetPrivate::setFocusWidget()
-{
- // Update focus child chain.
- QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(q_ptr);
- QGraphicsWidget *parent = widget;
- bool hidden = !visible;
- do {
- parent->d_func()->focusChild = widget;
- } while (!parent->isWindow() && (parent = parent->parentWidget()) && (!hidden || !parent->d_func()->visible));
-}
-
-/*!
- \internal
-*/
-void QGraphicsWidgetPrivate::clearFocusWidget()
-{
- // Reset focus child chain.
- QGraphicsWidget *parent = static_cast<QGraphicsWidget *>(q_ptr);
- do {
- if (parent->d_func()->focusChild != q_ptr)
- break;
- parent->d_func()->focusChild = 0;
- } while (!parent->isWindow() && (parent = parent->parentWidget()));
-}
-
/**
* is called after a reparent has taken place to fix up the focus chain(s)
*/
@@ -670,12 +642,6 @@ void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *new
QGraphicsWidget *firstOld = 0;
bool wasPreviousNew = true;
-
- if (focusChild) {
- // Ensure that the current focus child doesn't leave pointers around
- // before reparenting.
- focusChild->clearFocus();
- }
while (w != q) {
bool isCurrentNew = q->isAncestorOf(w);
diff --git a/src/gui/graphicsview/qgraphicswidget_p.h b/src/gui/graphicsview/qgraphicswidget_p.h
index 0c34baa2e..92e520a86 100644
--- a/src/gui/graphicsview/qgraphicswidget_p.h
+++ b/src/gui/graphicsview/qgraphicswidget_p.h
@@ -83,7 +83,6 @@ public:
focusPolicy(Qt::NoFocus),
focusNext(0),
focusPrev(0),
- focusChild(0),
windowFlags(0),
windowData(0),
setWindowFrameMargins(false),
@@ -178,9 +177,6 @@ public:
Qt::FocusPolicy focusPolicy;
QGraphicsWidget *focusNext;
QGraphicsWidget *focusPrev;
- QGraphicsWidget *focusChild;
- void setFocusWidget();
- void clearFocusWidget();
// Windows
Qt::WindowFlags windowFlags;