move nativetabbar to the new animation api

svn path=/trunk/KDE/kdelibs/; revision=1077713
This commit is contained in:
Igor Trindade Oliveira 2010-01-20 18:38:37 +00:00
parent 36cda82e22
commit 291f30e9f9
2 changed files with 38 additions and 13 deletions

View File

@ -28,6 +28,8 @@
#include <QApplication> #include <QApplication>
#include <QStyleOption> #include <QStyleOption>
#include <QToolButton> #include <QToolButton>
#include <QPropertyAnimation>
#include <QWeakPointer>
#include <QGradient> #include <QGradient>
#include <QLinearGradient> #include <QLinearGradient>
@ -85,6 +87,7 @@ public:
KIcon closeIcon; KIcon closeIcon;
int animationId; int animationId;
QWeakPointer<QPropertyAnimation> anim;
QRect currentAnimRect; QRect currentAnimRect;
QRect startAnimRect; QRect startAnimRect;
@ -131,6 +134,7 @@ NativeTabBar::NativeTabBar(QWidget *parent)
NativeTabBar::~NativeTabBar() NativeTabBar::~NativeTabBar()
{ {
d->anim.clear();
delete d; delete d;
} }
@ -385,28 +389,47 @@ void NativeTabBar::tabLayoutChange()
void NativeTabBar::startAnimation() void NativeTabBar::startAnimation()
{ {
d->storeLastIndex(); d->storeLastIndex();
Plasma::Animator::self()->customAnimation(
10, 150, Plasma::Animator::EaseInOutCurve, this, "onValueChanged"); QPropertyAnimation *anim = d->anim.data();
if (anim) {
anim->stop();
d->anim.clear();
}
anim = new QPropertyAnimation(this, "onValueChanged", this);
d->anim = anim;
anim->setDuration(150);
QRect rect = tabRect(currentIndex());
QRect lastRect = d->startAnimRect.isNull() ? tabRect(lastIndex())
: d->startAnimRect;
int x = isHorizontal() ? (int)(lastRect.x() - (lastRect.x() - rect.x())) : rect.x();
int y = isHorizontal() ? rect.y() : (int)(lastRect.y() - (lastRect.y() - rect.y()));
QSizeF sz = lastRect.size() - (lastRect.size() - rect.size());
d->currentAnimRect = QRect(x, y, (int)(sz.width()), (int)(sz.height()));
anim->setStartValue(lastRect);
anim->setEndValue(d->currentAnimRect);
anim->start(QAbstractAnimation::DeleteWhenStopped);
} }
void NativeTabBar::onValueChanged(qreal value) void NativeTabBar::setOnValueChanged(QRectF value)
{ {
if ((d->animProgress = value) == 1.0) { if (value == d->anim.data()->endValue()) {
d->animProgress = 1;
animationFinished(); animationFinished();
return; return;
} }
// animation rect d->currentAnimRect = value.toRect();
QRect rect = tabRect(currentIndex());
QRect lastRect = d->startAnimRect.isNull() ? tabRect(lastIndex())
: d->startAnimRect;
int x = isHorizontal() ? (int)(lastRect.x() - value * (lastRect.x() - rect.x())) : rect.x();
int y = isHorizontal() ? rect.y() : (int)(lastRect.y() - value * (lastRect.y() - rect.y()));
QSizeF sz = lastRect.size() - value * (lastRect.size() - rect.size());
d->currentAnimRect = QRect(x, y, (int)(sz.width()), (int)(sz.height()));
update(); update();
} }
QRectF NativeTabBar::onValueChanged() const
{
return d->currentAnimRect;
}
void NativeTabBar::animationFinished() void NativeTabBar::animationFinished()
{ {
d->startAnimRect = QRect(); d->startAnimRect = QRect();

View File

@ -31,6 +31,7 @@ class NativeTabBarPrivate;
class NativeTabBar : public KTabBar class NativeTabBar : public KTabBar
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QRectF onValueChanged READ onValueChanged WRITE setOnValueChanged)
public: public:
NativeTabBar(QWidget *parent = 0); NativeTabBar(QWidget *parent = 0);
@ -61,7 +62,8 @@ protected:
protected slots: protected slots:
void animationFinished(); void animationFinished();
void startAnimation(); void startAnimation();
void onValueChanged(qreal val); void setOnValueChanged(QRectF val);
QRectF onValueChanged() const;
Q_SIGNALS: Q_SIGNALS:
void sizeHintChanged(); void sizeHintChanged();