From 45846eea8c57133cf2075e3c393d2765081cbaff Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Mon, 20 Apr 2009 15:24:26 +0200 Subject: remove QItemAnimation and add the interpolator for QColor --- bin/snapshot | 1 + src/corelib/animation/qpropertyanimation.h | 1 - src/corelib/animation/qvariantanimation.h | 3 +- src/gui/animation/animation.pri | 7 +- src/gui/animation/qguivariantanimation.cpp | 79 +++++++ src/gui/animation/qitemanimation.cpp | 361 ----------------------------- src/gui/animation/qitemanimation.h | 111 --------- src/gui/animation/qitemanimation_p.h | 83 ------- 8 files changed, 82 insertions(+), 564 deletions(-) create mode 100644 src/gui/animation/qguivariantanimation.cpp delete mode 100644 src/gui/animation/qitemanimation.cpp delete mode 100644 src/gui/animation/qitemanimation.h delete mode 100644 src/gui/animation/qitemanimation_p.h diff --git a/bin/snapshot b/bin/snapshot index 6ccaba7..fa9a2ac 100644 --- a/bin/snapshot +++ b/bin/snapshot @@ -39,6 +39,7 @@ my @files = ( "corelib/animation/qsequentialanimationgroup.cpp", "corelib/animation/qsequentialanimationgroup.h", "corelib/animation/qsequentialanimationgroup_p.h", + "gui/animation/qguivariantanimation.cpp", "corelib/statemachine/statemachine.pri", "corelib/statemachine/qabstractstate.cpp", "corelib/statemachine/qabstractstate.h", diff --git a/src/corelib/animation/qpropertyanimation.h b/src/corelib/animation/qpropertyanimation.h index e5d5305..b619256 100644 --- a/src/corelib/animation/qpropertyanimation.h +++ b/src/corelib/animation/qpropertyanimation.h @@ -47,7 +47,6 @@ #else # include #endif -#include QT_BEGIN_HEADER diff --git a/src/corelib/animation/qvariantanimation.h b/src/corelib/animation/qvariantanimation.h index 7ce597f..69dbbf3 100644 --- a/src/corelib/animation/qvariantanimation.h +++ b/src/corelib/animation/qvariantanimation.h @@ -49,8 +49,7 @@ # include # include #endif -#include -#include +#include #include #include diff --git a/src/gui/animation/animation.pri b/src/gui/animation/animation.pri index 3092117..27763ca 100644 --- a/src/gui/animation/animation.pri +++ b/src/gui/animation/animation.pri @@ -1,8 +1,3 @@ # Qt gui animation module -HEADERS += \ - animation/qitemanimation.h \ - animation/qitemanimation_p.h - -SOURCES += \ - animation/qitemanimation.cpp +SOURCES += animation/qguivariantanimation.cpp diff --git a/src/gui/animation/qguivariantanimation.cpp b/src/gui/animation/qguivariantanimation.cpp new file mode 100644 index 0000000..46ba251 --- /dev/null +++ b/src/gui/animation/qguivariantanimation.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT_NO_ANIMATION + +QT_BEGIN_NAMESPACE + +#ifdef QT_EXPERIMENTAL_SOLUTION +# include "qvariantanimation.h" +# include "qvariantanimation_p.h" +#else +#include +#include +#endif + + +template<> Q_INLINE_TEMPLATE QColor _q_interpolate(const QColor &f,const QColor &t, qreal progress) +{ + return QColor(_q_interpolate(f.red(), t.red(), progress), + _q_interpolate(f.green(), t.green(), progress), + _q_interpolate(f.blue(), t.blue(), progress), + _q_interpolate(f.alpha(), t.alpha(), progress)); +} + +static int qRegisterGuiGetInterpolator() +{ + qRegisterAnimationInterpolator(_q_interpolateVariant); + return 1; +} +Q_CONSTRUCTOR_FUNCTION(qRegisterGuiGetInterpolator) + +static int qUnregisterGuiGetInterpolator() +{ + qRegisterAnimationInterpolator(0); + return 1; +} +Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator) + +QT_END_NAMESPACE + +#endif //QT_NO_ANIMATION diff --git a/src/gui/animation/qitemanimation.cpp b/src/gui/animation/qitemanimation.cpp deleted file mode 100644 index 484b386..0000000 --- a/src/gui/animation/qitemanimation.cpp +++ /dev/null @@ -1,361 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/*! - \class QItemAnimation - \brief The QItemAnimation class animates properties for QGraphicsItem - \since 4.5 - \ingroup animation - \preliminary - - This class is part of {The Animation Framework}. You can use QItemAnimation - by itself as a simple animation class, or as part of more complex - animations through QAnimationGroup. - - The most common way to use QItemAnimation is to construct an instance - of it by passing a pointer to a QGraphicsItem and the property you - would like to animate to QItemAnimation's constructor. - - The start value of the animation is optional. If you do not set any start - value, the animation will operate on the target's current property value - at the point when the animation was started. You can call setStartValue() - to set the start value, and setEndValue() to set the target value for - the animated property. - - You can choose to assign a target item by either calling setTargetItem() - or by passing a QGraphicsItem pointer to QVariantAnimation's constructor. - - \sa QVariantAnimation, QAnimationGroup, {The Animation Framework} -*/ - - -#ifndef QT_NO_ANIMATION - -#include "qitemanimation.h" -#include "qitemanimation_p.h" - -#include -#ifdef QT_EXPERIMENTAL_SOLUTION -#include "qanimationgroup.h" -#else -#include -#endif -#include - - -QT_BEGIN_NAMESPACE - -typedef QPair QItemAnimationPair; -typedef QHash QItemAnimationHash; -Q_GLOBAL_STATIC(QItemAnimationHash, _q_runningAnimations) -Q_GLOBAL_STATIC_WITH_ARGS(QMutex, guardHashLock, (QMutex::Recursive) ) - -void QItemAnimationPrivate::initDefaultStartValue() -{ - if (target && !defaultStartValue.isValid() && (atBeginning() || atEnd())) { - switch (propertyName) - { - case QItemAnimation::Position: - setDefaultStartValue(target->pos()); - break; - case QItemAnimation::Opacity: - setDefaultStartValue(target->opacity()); - break; - case QItemAnimation::RotationX: - setDefaultStartValue(target->xRotation()); - break; - case QItemAnimation::RotationY: - setDefaultStartValue(target->yRotation()); - break; - case QItemAnimation::RotationZ: - setDefaultStartValue(target->zRotation()); - break; - case QItemAnimation::ScaleFactorX: - setDefaultStartValue(target->xScale()); - break; - case QItemAnimation::ScaleFactorY: - setDefaultStartValue(target->yScale()); - break; - default: - break; - } - } -} - - -/*! - Construct a QItemAnimation object. \a parent is passed to QObject's - constructor. -*/ - -QItemAnimation::QItemAnimation(QObject *parent) : QVariantAnimation(*new QItemAnimationPrivate, parent) -{ -} - -/*! - Construct a QItemAnimation object. \a parent is passed to QObject's - constructor. The animation changes the property \a propertyName on \a - target. The default duration is 250ms. - - \sa targetItem, propertyName -*/ - -QItemAnimation::QItemAnimation(QGraphicsItem *target, PropertyName p, QObject *parent) : QVariantAnimation(*new QItemAnimationPrivate, parent) -{ - Q_D(QItemAnimation); - d->target = target; - d->propertyName = p; -} - -/*! - Destroys the QPropertyAnimation instance. - */ -QItemAnimation::~QItemAnimation() -{ - stop(); -} - -/*! - \property QItemAnimation::targetItem - \brief the target Graphics Item for this animation. - - This property defines the target item for this animation. - - \sa targetItem - */ - -QGraphicsItem *QItemAnimation::targetItem() const -{ - Q_D(const QItemAnimation); - return d->target; -} - -void QItemAnimation::setTargetItem(QGraphicsItem *item) -{ - Q_D(QItemAnimation); - d->target = item; -} - -/*! - \property QItemAnimation::propertyName - \brief the target property for this animation - - This property defines the target property for this animation. The - property is required for the animation to operate. - */ -QItemAnimation::PropertyName QItemAnimation::propertyName() const -{ - Q_D(const QItemAnimation); - return d->propertyName; -} - -void QItemAnimation::setPropertyName(PropertyName p) -{ - Q_D(QItemAnimation); - d->propertyName = p; -} - -/*! - This static function returns the list of running animations on \a item. - If item is 0, then it returns all QItemAnimations running on all QGraphicsItem. - */ -QList QItemAnimation::runningAnimations(QGraphicsItem *item) -{ - QMutexLocker locker(guardHashLock()); - QList animList = _q_runningAnimations()->values(); - if (item == 0) - return animList; - - QList ret; - - for (QList::const_iterator it = animList.constBegin(); it != animList.constEnd(); ++it) { - if ((*it)->targetItem() == item) - ret += *it; - } - - return ret; -} - -/*! - This static function returns the running animations on \a item and on \a property. - \a prop. - */ -QItemAnimation* QItemAnimation::runningAnimation(QGraphicsItem *item, PropertyName prop) -{ - QMutexLocker locker(guardHashLock()); - return _q_runningAnimations()->value(qMakePair(item, prop), 0 /*default value*/); -} - -/*! - \reimp - */ -bool QItemAnimation::event(QEvent *event) -{ - return QVariantAnimation::event(event); -} - -/*! - \reimp - */ -void QItemAnimation::updateCurrentValue(const QVariant &value) -{ - Q_D(QItemAnimation); - if (!d->target || d->state == Stopped) - return; - - switch (d->propertyName) - { - case Position: - d->target->setPos(qVariantValue(value)); - break; - case Opacity: - d->target->setOpacity(qVariantValue(value)); - break; - case RotationX: - d->target->setXRotation(qVariantValue(value)); - break; - case RotationY: - d->target->setYRotation(qVariantValue(value)); - break; - case RotationZ: - d->target->setZRotation(qVariantValue(value)); - break; - case ScaleFactorX: - d->target->setXScale(qVariantValue(value)); - break; - case ScaleFactorY: - d->target->setYScale(qVariantValue(value)); - break; - default: - qWarning("The property you're trying to animate is not managed by the item"); - break; - } -} - - -/*! - \reimp -*/ -void QItemAnimation::updateState(QAbstractAnimation::State oldState, - QAbstractAnimation::State newState) -{ - Q_D(QItemAnimation); - QVariantAnimation::updateState(oldState, newState); - QMutexLocker locker(guardHashLock()); - QItemAnimationHash *hash = _q_runningAnimations(); - QItemAnimationPair key(d->target, d->propertyName); - - //let's try to convert start and target values according to the type of the proerty - //we're animating - if (newState != Stopped) { - int type = QVariant::Invalid; - switch (d->propertyName) - { - case Position: - type = QVariant::PointF; - break; - case Opacity: - case RotationX: - case RotationY: - case RotationZ: - case ScaleFactorX: - case ScaleFactorY: - type = qMetaTypeId(); - break; - case None: - default: - break; - - } - if (type != QVariant::Invalid) { - d->convertValues(type); - } - } - - if (newState == Running) { - if (hash->contains(key)) { - QItemAnimation *oldAnim = hash->value(key); - if (oldAnim != this) { - //we try to stop the top level group - QAbstractAnimation *current = oldAnim; - while(current->group() && current->state() != Stopped) current = current->group(); - current->stop(); - } - } - hash->insert(key, this); - // Initialize start value - d->initDefaultStartValue(); - - } else if (hash->value(key) == this) { - hash->remove(key); - } -} - -///TODO: should be placed somewhere else (in its own file) -template<> Q_INLINE_TEMPLATE QColor _q_interpolate(const QColor &f,const QColor &t, qreal progress) -{ - return QColor(_q_interpolate(f.red(), t.red(), progress), - _q_interpolate(f.green(), t.green(), progress), - _q_interpolate(f.blue(), t.blue(), progress), - _q_interpolate(f.alpha(), t.alpha(), progress)); -} - - - -static int qRegisterGuiGetInterpolator() -{ - qRegisterAnimationInterpolator(_q_interpolateVariant); - return 1; -} -Q_CONSTRUCTOR_FUNCTION(qRegisterGuiGetInterpolator) - -static int qUnregisterGuiGetInterpolator() -{ - qRegisterAnimationInterpolator(0); - return 1; -} -Q_DESTRUCTOR_FUNCTION(qUnregisterGuiGetInterpolator) - -QT_END_NAMESPACE - -#include "moc_qitemanimation.cpp" - -#endif //QT_NO_ANIMATION diff --git a/src/gui/animation/qitemanimation.h b/src/gui/animation/qitemanimation.h deleted file mode 100644 index d630fe7..0000000 --- a/src/gui/animation/qitemanimation.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QITEMANIMATION_H -#define QITEMANIMATION_H - -#if defined(QT_EXPERIMENTAL_SOLUTION) -# include "qvariantanimation.h" -#else -# include -#endif - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_ANIMATION - -class QGraphicsItem; - -class QItemAnimationPrivate; -class Q_GUI_EXPORT QItemAnimation : public QVariantAnimation -{ -public: - enum PropertyName - { - None, //default - Position, - Opacity, - RotationX, - RotationY, - RotationZ, - ScaleFactorX, - ScaleFactorY - }; - - Q_OBJECT - Q_PROPERTY(PropertyName propertyName READ propertyName WRITE setPropertyName) - Q_PROPERTY(QGraphicsItem* targetItem READ targetItem WRITE setTargetItem) /*NOTIFY targetItemChanged*/ - -public: - QItemAnimation(QObject *parent = 0); - QItemAnimation(QGraphicsItem *target, PropertyName p = None, QObject *parent = 0); - ~QItemAnimation(); - - QGraphicsItem *targetItem() const; - void setTargetItem(QGraphicsItem *item); - - PropertyName propertyName() const; - void setPropertyName(PropertyName); - - static QList runningAnimations(QGraphicsItem *item = 0); - static QItemAnimation* runningAnimation(QGraphicsItem *item, PropertyName prop); - -protected: - bool event(QEvent *event); - void updateCurrentValue(const QVariant &value); - void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState); - -private: - Q_DISABLE_COPY(QItemAnimation) - Q_DECLARE_PRIVATE(QItemAnimation) -}; - -#endif //QT_NO_ANIMATION - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif //QITEMANIMATION_H diff --git a/src/gui/animation/qitemanimation_p.h b/src/gui/animation/qitemanimation_p.h deleted file mode 100644 index 027c199..0000000 --- a/src/gui/animation/qitemanimation_p.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QITEMANIMATION_P_H -#define QITEMANIMATION_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of QIODevice. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qitemanimation.h" - -#if defined(QT_EXPERIMENTAL_SOLUTION) -#include "qvariantanimation_p.h" -#else -#include "private/qvariantanimation_p.h" -#endif - -QT_BEGIN_NAMESPACE - -class QItemAnimationPrivate : public QVariantAnimationPrivate -{ - Q_DECLARE_PUBLIC(QItemAnimation) -public: - QItemAnimationPrivate() : propertyName(QItemAnimation::None), - target(0) - { - } - - void initDefaultStartValue(); - - QItemAnimation::PropertyName propertyName; - QGraphicsItem *target; -}; - -QT_END_NAMESPACE - -#endif //QITEMANIMATION_P_H -- cgit v0.12