add dptr to rotation

svn path=/trunk/KDE/kdelibs/; revision=1036200
This commit is contained in:
Igor Trindade Oliveira 2009-10-16 19:52:43 +00:00
parent cbb1a5e686
commit 84b8265322
2 changed files with 54 additions and 26 deletions

View File

@ -26,54 +26,80 @@
namespace Plasma
{
RotationAnimation::RotationAnimation(qint8 reference, const Qt::Axis &axis, const qreal &angle)
: m_angle(angle), m_axis(axis), m_reference(reference)
class RotationAnimationPrivate {
public:
RotationAnimationPrivate()
{
}
~RotationAnimationPrivate()
{
}
QGraphicsRotation *rotation;
qreal angle;
Qt::Axis axis;
qint8 reference;
};
RotationAnimation::RotationAnimation(const qint8 &reference, const Qt::Axis &axis, const qreal &angle)
: d(new RotationAnimationPrivate)
{
d->angle = angle;
d->axis = axis;
d->reference = reference;
d->rotation = new QGraphicsRotation(this);
}
RotationAnimation::~RotationAnimation()
{
delete d;
}
Qt::Axis RotationAnimation::axis() const
{
return m_axis;
return d->axis;
}
void RotationAnimation::setAxis(const Qt::Axis &axis)
{
m_axis = axis;
d->axis = axis;
}
qint8 RotationAnimation::reference() const
{
return m_reference;
return d->reference;
}
void RotationAnimation::setReference(const qint8 reference)
void RotationAnimation::setReference(const qint8 &reference)
{
m_reference = reference;
d->reference = reference;
}
qreal RotationAnimation::angle() const
{
return m_angle;
return d->angle;
}
void RotationAnimation::setAngle(const qreal &angle)
{
m_angle = angle;
d->angle = angle;
}
QPropertyAnimation *RotationAnimation::render(QObject *parent)
{
Q_UNUSED(parent);
QGraphicsWidget *m_object = getAnimatedObject();
QGraphicsRotation *rotation = new QGraphicsRotation(m_object);
QVector3D vector(0, 0, 0);
const qreal widgetWidth = m_object->size().width();
const qreal widgetHeight = m_object->size().height();
if (m_axis == Qt::XAxis) {
switch(m_reference) {
if (d->axis == Qt::XAxis) {
switch(d->reference) {
case Center:
vector.setY(widgetHeight/2);
break;
@ -84,8 +110,8 @@ QPropertyAnimation *RotationAnimation::render(QObject *parent)
vector.setY(widgetHeight);
break;
}
} else if(m_axis == Qt::YAxis) {
switch(m_reference) {
} else if(d->axis == Qt::YAxis) {
switch(d->reference) {
case Center:
vector.setX(widgetWidth/2);
break;
@ -96,8 +122,8 @@ QPropertyAnimation *RotationAnimation::render(QObject *parent)
vector.setX(widgetWidth);
break;
}
}else if (m_axis == Qt::ZAxis) {
switch(m_reference) {
}else if (d->axis == Qt::ZAxis) {
switch(d->reference) {
case Center:
vector.setX(widgetWidth/2);
vector.setY(widgetHeight/2);
@ -125,16 +151,16 @@ QPropertyAnimation *RotationAnimation::render(QObject *parent)
}
}
rotation->setOrigin(vector);
rotation->setAxis(m_axis);
d->rotation->setOrigin(vector);
d->rotation->setAxis(d->axis);
QList<QGraphicsTransform *> transformation;
transformation.append(rotation);
transformation.append(d->rotation);
m_object->setTransformations(transformation);
QPropertyAnimation *rotationAnimation= new QPropertyAnimation(rotation,
QPropertyAnimation *rotationAnimation= new QPropertyAnimation(d->rotation,
"angle", m_object);
rotationAnimation->setEndValue(m_angle);
rotationAnimation->setEndValue(d->angle);
rotationAnimation->setDuration(getDuration());
return rotationAnimation;

View File

@ -27,6 +27,8 @@
namespace Plasma {
class RotationAnimationPrivate;
class PLASMA_EXPORT RotationAnimation : public Animation
{
Q_OBJECT
@ -44,7 +46,9 @@ class PLASMA_EXPORT RotationAnimation : public Animation
};
public:
RotationAnimation(qint8 reference = Center, const Qt::Axis &axis = Qt::ZAxis, const qreal &angle = 180);
RotationAnimation(const qint8 &reference = Center,
const Qt::Axis &axis = Qt::ZAxis, const qreal &angle = 180);
~RotationAnimation();
QPropertyAnimation* render(QObject* parent = 0);
@ -52,14 +56,12 @@ class PLASMA_EXPORT RotationAnimation : public Animation
void setAxis(const Qt::Axis &axis);
qint8 reference() const;
void setReference(qint8 reference);
void setReference(const qint8 &reference);
qreal angle() const;
void setAngle(const qreal &angle);
private:
qreal m_angle;
Qt::Axis m_axis;
qint8 m_reference;
RotationAnimationPrivate *const d;
};
} // Plasma