summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview/qgraphicsitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/graphicsview/qgraphicsitem.cpp')
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp767
1 files changed, 412 insertions, 355 deletions
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;