diff options
author | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2009-08-17 11:50:47 (GMT) |
---|---|---|
committer | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2009-08-17 11:50:47 (GMT) |
commit | 17d6f2a59fe2b170087cdf7074807c6a2dce1043 (patch) | |
tree | 64af0faa3146cd516b9887c9344ebd03408bafcc /src/gui/graphicsview | |
parent | 103334ced3b0cb6e69a1ed3075d9b81e591f37e9 (diff) | |
parent | 3d50220423b96a84f1ca4c0f5ef9246345aad359 (diff) | |
download | Qt-17d6f2a59fe2b170087cdf7074807c6a2dce1043.zip Qt-17d6f2a59fe2b170087cdf7074807c6a2dce1043.tar.gz Qt-17d6f2a59fe2b170087cdf7074807c6a2dce1043.tar.bz2 |
Merge commit 'qt/master' into kinetic-graphicseffect
Diffstat (limited to 'src/gui/graphicsview')
44 files changed, 199 insertions, 193 deletions
diff --git a/src/gui/graphicsview/qgraphicsgridlayout.cpp b/src/gui/graphicsview/qgraphicsgridlayout.cpp index d11df26..ee7048f 100644 --- a/src/gui/graphicsview/qgraphicsgridlayout.cpp +++ b/src/gui/graphicsview/qgraphicsgridlayout.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsgridlayout.h b/src/gui/graphicsview/qgraphicsgridlayout.h index b9db03e..9551e87 100644 --- a/src/gui/graphicsview/qgraphicsgridlayout.h +++ b/src/gui/graphicsview/qgraphicsgridlayout.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 38b80fc..66f5f22 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -1179,6 +1179,9 @@ QGraphicsItem::QGraphicsItem(QGraphicsItemPrivate &dd, QGraphicsItem *parent, Destroys the QGraphicsItem and all its children. If this item is currently associated with a scene, the item will be removed from the scene before it is deleted. + + \note It is more efficient to remove the item from the QGraphicsScene before + destroying the item. */ QGraphicsItem::~QGraphicsItem() { @@ -1192,10 +1195,12 @@ QGraphicsItem::~QGraphicsItem() Q_ASSERT(d_ptr->children.isEmpty()); } - if (d_ptr->scene) + if (d_ptr->scene) { d_ptr->scene->d_func()->removeItemHelper(this); - else + } else { + d_ptr->resetFocusProxy(); d_ptr->setParentItemHelper(0); + } delete d_ptr->graphicsEffect; if (d_ptr->transformData) { @@ -2187,11 +2192,10 @@ qreal QGraphicsItem::effectiveOpacity() const void QGraphicsItem::setOpacity(qreal opacity) { // Notify change. - const QVariant newOpacityVariant(itemChange(ItemOpacityChange, double(opacity))); - qreal newOpacity = newOpacityVariant.toDouble(); + const QVariant newOpacityVariant(itemChange(ItemOpacityChange, opacity)); - // Normalize. - newOpacity = qBound<qreal>(0.0, newOpacity, 1.0); + // Normalized opacity + qreal newOpacity = qBound(qreal(0), newOpacityVariant.toReal(), qreal(1)); // No change? Done. if (newOpacity == d_ptr->opacity) @@ -2723,13 +2727,11 @@ void QGraphicsItem::setFocusProxy(QGraphicsItem *item) } QGraphicsItem *lastFocusProxy = d_ptr->focusProxy; + if (lastFocusProxy) + lastFocusProxy->d_ptr->focusProxyRefs.removeOne(&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); - } + if (item) + item->d_ptr->focusProxyRefs << &d_ptr->focusProxy; } /*! @@ -3806,8 +3808,8 @@ qreal QGraphicsItem::zValue() const */ void QGraphicsItem::setZValue(qreal z) { - const QVariant newZVariant(itemChange(ItemZValueChange, double(z))); - qreal newZ = qreal(newZVariant.toDouble()); + const QVariant newZVariant(itemChange(ItemZValueChange, z)); + qreal newZ = newZVariant.toReal(); if (newZ == d_ptr->z) return; @@ -4736,6 +4738,19 @@ void QGraphicsItemPrivate::clearSubFocus() /*! \internal + Sets the focusProxy pointer to 0 for all items that have this item as their + focusProxy. ### Qt 5: Use QPointer instead. +*/ +void QGraphicsItemPrivate::resetFocusProxy() +{ + for (int i = 0; i < focusProxyRefs.size(); ++i) + *focusProxyRefs.at(i) = 0; + focusProxyRefs.clear(); +} + +/*! + \internal + Tells us if it is a proxy widget */ bool QGraphicsItemPrivate::isProxyWidget() const diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index 58f1c36..fdf9463 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 4763a4f..a6f833c 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -403,6 +403,7 @@ public: void setSubFocus(); void clearSubFocus(); + void resetFocusProxy(); inline QTransform transformToParent() const; inline void ensureSortedChildren(); @@ -425,6 +426,7 @@ public: int siblingIndex; int depth; QGraphicsItem *focusProxy; + QList<QGraphicsItem **> focusProxyRefs; QGraphicsItem *subFocusItem; Qt::InputMethodHints imHints; diff --git a/src/gui/graphicsview/qgraphicsitemanimation.cpp b/src/gui/graphicsview/qgraphicsitemanimation.cpp index e9a9df2..0d7a3c6 100644 --- a/src/gui/graphicsview/qgraphicsitemanimation.cpp +++ b/src/gui/graphicsview/qgraphicsitemanimation.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsitemanimation.h b/src/gui/graphicsview/qgraphicsitemanimation.h index 189b3f6..29221e5 100644 --- a/src/gui/graphicsview/qgraphicsitemanimation.h +++ b/src/gui/graphicsview/qgraphicsitemanimation.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicslayout.cpp b/src/gui/graphicsview/qgraphicslayout.cpp index dbfb407..3f039c6 100644 --- a/src/gui/graphicsview/qgraphicslayout.cpp +++ b/src/gui/graphicsview/qgraphicslayout.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicslayout.h b/src/gui/graphicsview/qgraphicslayout.h index 7c758bc..d7e087b 100644 --- a/src/gui/graphicsview/qgraphicslayout.h +++ b/src/gui/graphicsview/qgraphicslayout.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicslayout_p.cpp b/src/gui/graphicsview/qgraphicslayout_p.cpp index 83bf14b..b93e2d8 100644 --- a/src/gui/graphicsview/qgraphicslayout_p.cpp +++ b/src/gui/graphicsview/qgraphicslayout_p.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicslayout_p.h b/src/gui/graphicsview/qgraphicslayout_p.h index 0d053bb..2ad853b 100644 --- a/src/gui/graphicsview/qgraphicslayout_p.h +++ b/src/gui/graphicsview/qgraphicslayout_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicslayoutitem.cpp b/src/gui/graphicsview/qgraphicslayoutitem.cpp index e280162..83e4888 100644 --- a/src/gui/graphicsview/qgraphicslayoutitem.cpp +++ b/src/gui/graphicsview/qgraphicslayoutitem.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicslayoutitem.h b/src/gui/graphicsview/qgraphicslayoutitem.h index 85a5f07..44c1c0f 100644 --- a/src/gui/graphicsview/qgraphicslayoutitem.h +++ b/src/gui/graphicsview/qgraphicslayoutitem.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicslayoutitem_p.h b/src/gui/graphicsview/qgraphicslayoutitem_p.h index 96f0712..5bda3ca 100644 --- a/src/gui/graphicsview/qgraphicslayoutitem_p.h +++ b/src/gui/graphicsview/qgraphicslayoutitem_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicslinearlayout.cpp b/src/gui/graphicsview/qgraphicslinearlayout.cpp index 3b037cf..c0ff00e 100644 --- a/src/gui/graphicsview/qgraphicslinearlayout.cpp +++ b/src/gui/graphicsview/qgraphicslinearlayout.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicslinearlayout.h b/src/gui/graphicsview/qgraphicslinearlayout.h index f469680..4d6c944 100644 --- a/src/gui/graphicsview/qgraphicslinearlayout.h +++ b/src/gui/graphicsview/qgraphicslinearlayout.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsproxywidget.cpp b/src/gui/graphicsview/qgraphicsproxywidget.cpp index 5fac6cf..784ee0e 100644 --- a/src/gui/graphicsview/qgraphicsproxywidget.cpp +++ b/src/gui/graphicsview/qgraphicsproxywidget.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsproxywidget.h b/src/gui/graphicsview/qgraphicsproxywidget.h index 01b5033..32be9e4 100644 --- a/src/gui/graphicsview/qgraphicsproxywidget.h +++ b/src/gui/graphicsview/qgraphicsproxywidget.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsproxywidget_p.h b/src/gui/graphicsview/qgraphicsproxywidget_p.h index fbc9f6c..e2be89c 100644 --- a/src/gui/graphicsview/qgraphicsproxywidget_p.h +++ b/src/gui/graphicsview/qgraphicsproxywidget_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 7d0876f..e4a02e2 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -495,11 +495,7 @@ 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); - } + item->d_ptr->resetFocusProxy(); // Remove from parent, or unregister from toplevels. if (QGraphicsItem *parentItem = item->parentItem()) { diff --git a/src/gui/graphicsview/qgraphicsscene.h b/src/gui/graphicsview/qgraphicsscene.h index 67a2983..26cb1c2 100644 --- a/src/gui/graphicsview/qgraphicsscene.h +++ b/src/gui/graphicsview/qgraphicsscene.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsscene_bsp.cpp b/src/gui/graphicsview/qgraphicsscene_bsp.cpp index fb4b9a4..d554b7b 100644 --- a/src/gui/graphicsview/qgraphicsscene_bsp.cpp +++ b/src/gui/graphicsview/qgraphicsscene_bsp.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsscene_bsp_p.h b/src/gui/graphicsview/qgraphicsscene_bsp_p.h index 4cac64a..e0e4791 100644 --- a/src/gui/graphicsview/qgraphicsscene_bsp_p.h +++ b/src/gui/graphicsview/qgraphicsscene_bsp_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index 64ee785..7beae20 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -131,7 +131,6 @@ public: QGraphicsWidget *activeWindow; int activationRefCount; void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason); - QMultiHash<QGraphicsItem *, QGraphicsItem *> focusProxyReverseMap; QList<QGraphicsWidget *> popupWidgets; void addPopup(QGraphicsWidget *widget); @@ -282,9 +281,9 @@ static inline void _q_adjustRect(QRectF *rect) { Q_ASSERT(rect); if (!rect->width()) - rect->adjust(-0.00001, 0, 0.00001, 0); + rect->adjust(qreal(-0.00001), 0, qreal(0.00001), 0); if (!rect->height()) - rect->adjust(0, -0.00001, 0, 0.00001); + rect->adjust(0, qreal(-0.00001), 0, qreal(0.00001)); } static inline QRectF adjustedItemBoundingRect(const QGraphicsItem *item) diff --git a/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp b/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp index 55a493d..4dccde9 100644 --- a/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp +++ b/src/gui/graphicsview/qgraphicsscenebsptreeindex.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtGui module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h b/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h index 2293a8e..27c499d 100644 --- a/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h +++ b/src/gui/graphicsview/qgraphicsscenebsptreeindex_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicssceneevent.cpp b/src/gui/graphicsview/qgraphicssceneevent.cpp index 92af0cc..b89d6ba 100644 --- a/src/gui/graphicsview/qgraphicssceneevent.cpp +++ b/src/gui/graphicsview/qgraphicssceneevent.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicssceneevent.h b/src/gui/graphicsview/qgraphicssceneevent.h index b38e757..7dc9ac2 100644 --- a/src/gui/graphicsview/qgraphicssceneevent.h +++ b/src/gui/graphicsview/qgraphicssceneevent.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicssceneindex.cpp b/src/gui/graphicsview/qgraphicssceneindex.cpp index ab5ca85..37a2fc3 100644 --- a/src/gui/graphicsview/qgraphicssceneindex.cpp +++ b/src/gui/graphicsview/qgraphicssceneindex.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtGui module of the Qt Toolkit. ** @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicssceneindex_p.h b/src/gui/graphicsview/qgraphicssceneindex_p.h index 37dffb8..d922036 100644 --- a/src/gui/graphicsview/qgraphicssceneindex_p.h +++ b/src/gui/graphicsview/qgraphicssceneindex_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsscenelinearindex.cpp b/src/gui/graphicsview/qgraphicsscenelinearindex.cpp index 52bbc79..132b1a6 100644 --- a/src/gui/graphicsview/qgraphicsscenelinearindex.cpp +++ b/src/gui/graphicsview/qgraphicsscenelinearindex.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsscenelinearindex_p.h b/src/gui/graphicsview/qgraphicsscenelinearindex_p.h index 1f3d58b..6181bf0 100644 --- a/src/gui/graphicsview/qgraphicsscenelinearindex_p.h +++ b/src/gui/graphicsview/qgraphicsscenelinearindex_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicstransform.cpp b/src/gui/graphicsview/qgraphicstransform.cpp index 778cd94..95f137d 100644 --- a/src/gui/graphicsview/qgraphicstransform.cpp +++ b/src/gui/graphicsview/qgraphicstransform.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -73,18 +73,14 @@ QGraphicsTransform can be used together with QGraphicsItem::setTransform(), QGraphicsItem::setRotation(), and QGraphicsItem::setScale(). - \sa QGraphicsItem::transform(), QGraphicsScale, QGraphicsRotation, QGraphicsRotation3D + \sa QGraphicsItem::transform(), QGraphicsScale, QGraphicsRotation */ #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 +#include <QtCore/qmath.h> QT_BEGIN_NAMESPACE @@ -330,9 +326,17 @@ void QGraphicsScale::applyTo(QTransform *transform) const /*! \class QGraphicsRotation - \brief The QGraphicsRotation class provides a rotation transformation. + \brief The QGraphicsRotation class provides a rotation transformation around + a given axis. \since 4.6 + You can provide the desired axis by assigning a QVector3D to the axis property + or by passing a member if Qt::Axis to the setAxis convenience function. + By default the axis is (0, 0, 1) i.e., rotation around the Z axis. + + The angle property, which is provided by QGraphicsRotation, now + describes the number of degrees to rotate around this axis. + QGraphicsRotation provides certain parameters to help control how the rotation should be applied. @@ -346,17 +350,28 @@ void QGraphicsScale::applyTo(QTransform *transform) const provide rotation angles exceeding (-360, 360) degrees, for instance to animate how an item rotates several times. + Note: the final rotation is the combined effect of a rotation in + 3D space followed by a projection back to 2D. If several rotations + are performed in succession, they will not behave as expected unless + they were all around the Z axis. + \sa QGraphicsTransform, QGraphicsItem::setRotation(), QTransform::rotate() */ +#define VECTOR_FOR_AXIS_X QVector3D(1, 0, 0) +#define VECTOR_FOR_AXIS_Y QVector3D(0, 1, 0) +#define VECTOR_FOR_AXIS_Z QVector3D(0, 0, 1) + + class QGraphicsRotationPrivate : public QGraphicsTransformPrivate { public: QGraphicsRotationPrivate() - : angle(0) {} + : angle(0), axis(VECTOR_FOR_AXIS_Z), simpleAxis(Qt::ZAxis) {} QPointF origin; - qreal originY; qreal angle; + QVector3D axis; + int simpleAxis; }; /*! @@ -368,14 +383,6 @@ QGraphicsRotation::QGraphicsRotation(QObject *parent) } /*! - \internal -*/ -QGraphicsRotation::QGraphicsRotation(QGraphicsRotationPrivate &p, QObject *parent) - : QGraphicsTransform(p, parent) -{ -} - -/*! Destroys the graphics rotation. */ QGraphicsRotation::~QGraphicsRotation() @@ -432,19 +439,6 @@ void QGraphicsRotation::setAngle(qreal angle) } /*! - \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. @@ -461,109 +455,127 @@ void QGraphicsRotation::applyTo(QTransform *t) const */ /*! - \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 + \property QGraphicsRotation::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 + which is aligned with the Z axis. If you provide another axis, + QGraphicsRotation 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() +QVector3D QGraphicsRotation::axis() const { - Q_D(QGraphicsRotation3D); + Q_D(const QGraphicsRotation); return d->axis; } -void QGraphicsRotation3D::setAxis(const QVector3D &axis) +void QGraphicsRotation::setAxis(const QVector3D &axis) { - Q_D(QGraphicsRotation3D); - d->axis = axis; + Q_D(QGraphicsRotation); + if (d->axis == axis) + return; + d->axis = axis; + if (axis == VECTOR_FOR_AXIS_X) { + d->simpleAxis = Qt::XAxis; + } else if (axis == VECTOR_FOR_AXIS_Y) { + d->simpleAxis = Qt::YAxis; + } else if (axis == VECTOR_FOR_AXIS_Z) { + d->simpleAxis = Qt::ZAxis; + } else { + d->simpleAxis = -1; // no predefined axis + } update(); + emit axisChanged(); +} + +/*! + \fn void QGraphicsRotation::setAxis(Qt::Axis axis) + + Convenience function to set the axis to \a axis. +*/ + +void QGraphicsRotation::setAxis(Qt::Axis axis) +{ + switch (axis) + { + case Qt::XAxis: + setAxis(VECTOR_FOR_AXIS_X); + break; + case Qt::YAxis: + setAxis(VECTOR_FOR_AXIS_Y); + break; + case Qt::ZAxis: + setAxis(VECTOR_FOR_AXIS_Z); + break; + } } + +const qreal deg2rad = qreal(0.017453292519943295769); // pi/180 static const qreal inv_dist_to_plane = 1. / 1024.; /*! \reimp */ -void QGraphicsRotation3D::applyTo(QTransform *t) const +void QGraphicsRotation::applyTo(QTransform *t) const { - Q_D(const QGraphicsRotation3D); + Q_D(const QGraphicsRotation); - if (d->angle == 0. || - (d->axis.z() == 0. && d->axis.y() == 0 && d->axis.x() == 0)) + qreal a = d->angle; + + if (a == 0.) return; - qreal rad = d->angle * 2. * M_PI / 360.; - qreal c = ::cos(rad); - qreal s = ::sin(rad); + if (d->simpleAxis != -1) { + //that's an optimization for simple axis + t->translate(d->origin.x(), d->origin.y()); + t->rotate(a, Qt::Axis(d->simpleAxis)); + t->translate(-d->origin.x(), -d->origin.y()); + return; + } qreal x = d->axis.x(); qreal y = d->axis.y(); qreal z = d->axis.z(); + if (x == 0. && y == 0 && z == 0) + return; + + qreal c, s; + if (a == 90. || a == -270.) { + s = 1.; + c = 0.; + } else if (a == 270. || a == -90.) { + s = -1.; + c = 0.; + } else if (a == 180.) { + s = 0.; + c = -1.; + } else { + qreal b = deg2rad*a; + s = qSin(b); + c = qCos(b); + } + qreal len = x * x + y * y + z * z; if (len != 1.) { - len = 1./::sqrt(len); + len = 1. / qSqrt(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 = 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() + \fn void QGraphicsRotation::axisChanged() This signal is emitted whenever the axis of the object changes. */ diff --git a/src/gui/graphicsview/qgraphicstransform.h b/src/gui/graphicsview/qgraphicstransform.h index d7c07d0..8ccc258 100644 --- a/src/gui/graphicsview/qgraphicstransform.h +++ b/src/gui/graphicsview/qgraphicstransform.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -117,6 +117,7 @@ class Q_GUI_EXPORT QGraphicsRotation : public QGraphicsTransform Q_PROPERTY(QPointF origin READ origin WRITE setOrigin NOTIFY originChanged) Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged) + Q_PROPERTY(QVector3D axis READ axis WRITE setAxis NOTIFY axisChanged) public: QGraphicsRotation(QObject *parent = 0); ~QGraphicsRotation(); @@ -127,39 +128,19 @@ public: 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(); + QVector3D axis() const; void setAxis(const QVector3D &axis); + void setAxis(Qt::Axis axis); void applyTo(QTransform *transform) const; Q_SIGNALS: + void originChanged(); + void angleChanged(); void axisChanged(); private: - Q_DECLARE_PRIVATE(QGraphicsRotation3D) + Q_DECLARE_PRIVATE(QGraphicsRotation) }; QT_END_NAMESPACE diff --git a/src/gui/graphicsview/qgraphicstransform_p.h b/src/gui/graphicsview/qgraphicstransform_p.h index 2d36eda..2c563e4 100644 --- a/src/gui/graphicsview/qgraphicstransform_p.h +++ b/src/gui/graphicsview/qgraphicstransform_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -55,6 +55,8 @@ #include "private/qobject_p.h" +QT_BEGIN_NAMESPACE + class QGraphicsItem; class QGraphicsTransformPrivate : public QObjectPrivate { @@ -70,4 +72,6 @@ public: static void updateItem(QGraphicsItem *item); }; +QT_END_NAMESPACE + #endif // QGRAPHICSTRANSFORM_P_H diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index ca55f2e..91e654c 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -493,8 +493,8 @@ void QGraphicsViewPrivate::centerView(QGraphicsView::ViewportAnchor anchor) // Last scene pos: lastMouseMoveScenePoint // Current mouse pos: QPointF transformationDiff = q->mapToScene(viewport->rect().center()) - - q->mapToScene(q->mapFromGlobal(QCursor::pos())); - q->centerOn(lastMouseMoveScenePoint + transformationDiff);; + - q->mapToScene(viewport->mapFromGlobal(QCursor::pos())); + q->centerOn(lastMouseMoveScenePoint + transformationDiff); } else { q->centerOn(lastCenterPoint); } @@ -2209,8 +2209,7 @@ QPolygonF QGraphicsView::mapToScene(const QRect &rect) const QPointF br = scrollOffset + r.bottomRight(); QPointF bl = scrollOffset + r.bottomLeft(); - QPolygonF poly; - poly.resize(4); + QPolygonF poly(4); if (!d->identityMatrix) { QTransform x = d->matrix.inverted(); poly[0] = x.map(tl); @@ -2313,8 +2312,7 @@ QPolygon QGraphicsView::mapFromScene(const QRectF &rect) const br -= scrollOffset; bl -= scrollOffset; - QPolygon poly; - poly.resize(4); + QPolygon poly(4); poly[0] = tl.toPoint(); poly[1] = tr.toPoint(); poly[2] = br.toPoint(); @@ -3647,8 +3645,7 @@ QRectF QGraphicsViewPrivate::mapToScene(const QRectF &rect) const QPointF br = scrollOffset + rect.bottomRight(); QPointF bl = scrollOffset + rect.bottomLeft(); - QPolygonF poly; - poly.resize(4); + QPolygonF poly(4); if (!identityMatrix) { QTransform x = matrix.inverted(); poly[0] = x.map(tl); diff --git a/src/gui/graphicsview/qgraphicsview.h b/src/gui/graphicsview/qgraphicsview.h index 1285e45..0558051 100644 --- a/src/gui/graphicsview/qgraphicsview.h +++ b/src/gui/graphicsview/qgraphicsview.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicsview_p.h b/src/gui/graphicsview/qgraphicsview_p.h index 62a2b84..bdf5ddd 100644 --- a/src/gui/graphicsview/qgraphicsview_p.h +++ b/src/gui/graphicsview/qgraphicsview_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 3ea80ce..64881b5 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicswidget.h b/src/gui/graphicsview/qgraphicswidget.h index d03a637..62b353a 100644 --- a/src/gui/graphicsview/qgraphicswidget.h +++ b/src/gui/graphicsview/qgraphicswidget.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicswidget_p.cpp b/src/gui/graphicsview/qgraphicswidget_p.cpp index 8eac063..6d7e44a 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.cpp +++ b/src/gui/graphicsview/qgraphicswidget_p.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgraphicswidget_p.h b/src/gui/graphicsview/qgraphicswidget_p.h index 92e520a..0e1fe46 100644 --- a/src/gui/graphicsview/qgraphicswidget_p.h +++ b/src/gui/graphicsview/qgraphicswidget_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp index 630b23a..5ad6ac9 100644 --- a/src/gui/graphicsview/qgridlayoutengine.cpp +++ b/src/gui/graphicsview/qgridlayoutengine.cpp @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/gui/graphicsview/qgridlayoutengine_p.h b/src/gui/graphicsview/qgridlayoutengine_p.h index 6f3dd16..8f3eb13 100644 --- a/src/gui/graphicsview/qgridlayoutengine_p.h +++ b/src/gui/graphicsview/qgridlayoutengine_p.h @@ -34,7 +34,7 @@ ** 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. +** contact the sales department at http://qt.nokia.com/contact. ** $QT_END_LICENSE$ ** ****************************************************************************/ |