use qpropertyanimation: massively simplify the code

svn path=/trunk/KDE/kdelibs/; revision=1057438
This commit is contained in:
Marco Martin 2009-12-02 12:23:56 +00:00
parent b007e59e40
commit db8ece1921
2 changed files with 10 additions and 32 deletions

View File

@ -29,7 +29,7 @@
#include <QPainter> #include <QPainter>
#include <QPalette> #include <QPalette>
#include <QTextDocument> #include <QTextDocument>
#include <QTimeLine> #include <QPropertyAnimation>
#ifdef Q_WS_X11 #ifdef Q_WS_X11
#include <QX11Info> #include <QX11Info>
#include <netwm.h> #include <netwm.h>
@ -135,7 +135,6 @@ class ToolTipPrivate
: text(0), : text(0),
imageLabel(0), imageLabel(0),
preview(0), preview(0),
timeline(0),
direction(Plasma::Up), direction(Plasma::Up),
autohide(true) autohide(true)
{ } { }
@ -145,9 +144,7 @@ class ToolTipPrivate
WindowPreview *preview; WindowPreview *preview;
FrameSvg *background; FrameSvg *background;
QWeakPointer<QObject> source; QWeakPointer<QObject> source;
QTimeLine *timeline; QPropertyAnimation *animation;
QPoint to;
QPoint from;
Plasma::Direction direction; Plasma::Direction direction;
bool autohide; bool autohide;
}; };
@ -163,6 +160,10 @@ ToolTip::ToolTip(QWidget *parent)
d->imageLabel = new QLabel(this); d->imageLabel = new QLabel(this);
d->imageLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft); d->imageLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
d->animation = new QPropertyAnimation(this, "pos", this);
d->animation->setEasingCurve(QEasingCurve::InOutQuad);
d->animation->setDuration(250);
d->background = new FrameSvg(this); d->background = new FrameSvg(this);
d->background->setImagePath("widgets/tooltip"); d->background->setImagePath("widgets/tooltip");
d->background->setEnabledBorders(FrameSvg::AllBorders); d->background->setEnabledBorders(FrameSvg::AllBorders);
@ -319,33 +320,11 @@ void ToolTip::moveTo(const QPoint &to)
return; return;
} }
d->from = QPoint(); if (d->animation->state() == QAbstractAnimation::Running) {
d->to = to; d->animation->stop();
if (!d->timeline) {
d->timeline = new QTimeLine(250, this);
d->timeline->setFrameRange(0, 10);
d->timeline->setCurveShape(QTimeLine::EaseInCurve);
connect(d->timeline, SIGNAL(valueChanged(qreal)), this, SLOT(animateMove(qreal)));
} }
d->animation->setEndValue(to);
d->timeline->stop(); d->animation->start();
d->timeline->start();
}
void ToolTip::animateMove(qreal progress)
{
if (d->from.isNull()) {
d->from = pos();
}
if (qFuzzyCompare(progress, qreal(1.0))) {
move(d->to);
return;
}
move(d->from.x() + ((d->to.x() - d->from.x()) * progress),
d->from.y() + ((d->to.y() - d->from.y()) * progress));
} }
void ToolTip::resizeEvent(QResizeEvent *e) void ToolTip::resizeEvent(QResizeEvent *e)

View File

@ -67,7 +67,6 @@ protected:
private Q_SLOTS: private Q_SLOTS:
void updateTheme(); void updateTheme();
void animateMove(qreal);
private: private:
ToolTipPrivate * const d; ToolTipPrivate * const d;