port tabbar to new animation api.

svn path=/trunk/KDE/kdelibs/; revision=1078747
This commit is contained in:
Igor Trindade Oliveira 2010-01-22 19:31:42 +00:00
parent d42e7f8b7b
commit 157711c581
2 changed files with 59 additions and 35 deletions

View File

@ -28,10 +28,12 @@
#include <QIcon> #include <QIcon>
#include <QStyleOption> #include <QStyleOption>
#include <QPainter> #include <QPainter>
#include <QSequentialAnimationGroup>
#include <kdebug.h> #include <kdebug.h>
#include <plasma/animator.h> #include <plasma/animator.h>
#include <plasma/animations/animation.h>
#include <plasma/theme.h> #include <plasma/theme.h>
#include "private/nativetabbar_p.h" #include "private/nativetabbar_p.h"
@ -87,6 +89,8 @@ public:
void updateTabWidgetMode(); void updateTabWidgetMode();
void slidingCompleted(QGraphicsItem *item); void slidingCompleted(QGraphicsItem *item);
void slidingNewPageCompleted();
void slidingOldPageCompleted();
void shapeChanged(const KTabBar::Shape shape); void shapeChanged(const KTabBar::Shape shape);
void setPalette(); void setPalette();
@ -103,6 +107,9 @@ public:
QGraphicsWidget *newPage; QGraphicsWidget *newPage;
int oldPageAnimId; int oldPageAnimId;
int newPageAnimId; int newPageAnimId;
Animation *oldPageAnim;
Animation *newPageAnim;
QSequentialAnimationGroup *animGroup;
bool customFont; bool customFont;
}; };
@ -139,20 +146,25 @@ void TabBarPrivate::updateTabWidgetMode()
tabWidgetMode = tabWidget; tabWidgetMode = tabWidget;
} }
void TabBarPrivate::slidingCompleted(QGraphicsItem *item) void TabBarPrivate::slidingNewPageCompleted()
{ {
if (item == oldPage || item == newPage) { qDebug()<<"yuup";
if (item == newPage) { tabWidgetLayout->addItem(newPage);
tabWidgetLayout->addItem(newPage); newPageAnimId = -1;
newPageAnimId = -1; mainLayout->invalidate();
mainLayout->invalidate(); emit q->currentChanged(currentIndex);
emit q->currentChanged(currentIndex);
} else { q->setFlags(0);
oldPageAnimId = -1; }
item->hide();
} void TabBarPrivate::slidingOldPageCompleted()
q->setFlags(0); {
} qDebug()<<"blurp";
QGraphicsWidget *item = newPageAnim->targetWidget();
oldPageAnimId = -1;
item->hide();
q->setFlags(0);
} }
void TabBarPrivate::shapeChanged(const QTabBar::Shape shape) void TabBarPrivate::shapeChanged(const QTabBar::Shape shape)
@ -236,12 +248,20 @@ TabBar::TabBar(QGraphicsWidget *parent)
d->tabBarLayout->setContentsMargins(0,0,0,0); d->tabBarLayout->setContentsMargins(0,0,0,0);
//d->tabBarLayout->setStretchFactor(d->tabProxy, 2); //d->tabBarLayout->setStretchFactor(d->tabProxy, 2);
d->newPageAnim = Animator::create(Animator::SlideAnimation);
d->oldPageAnim = Animator::create(Animator::SlideAnimation);
d->animGroup = new QSequentialAnimationGroup(this);
d->animGroup->addAnimation(d->newPageAnim);
d->animGroup->addAnimation(d->oldPageAnim);
connect(d->tabProxy->native, SIGNAL(currentChanged(int)), connect(d->tabProxy->native, SIGNAL(currentChanged(int)),
this, SLOT(setCurrentIndex(int))); this, SLOT(setCurrentIndex(int)));
connect(d->tabProxy->native, SIGNAL(shapeChanged(QTabBar::Shape)), connect(d->tabProxy->native, SIGNAL(shapeChanged(QTabBar::Shape)),
this, SLOT(shapeChanged(QTabBar::Shape))); this, SLOT(shapeChanged(QTabBar::Shape)));
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)), connect(d->newPageAnim, SIGNAL(finished()), this, SLOT(slidingNewPageCompleted()));
this, SLOT(slidingCompleted(QGraphicsItem*))); connect(d->oldPageAnim, SIGNAL(finished()), this, SLOT(slidingOldPageCompleted()));
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), connect(Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SLOT(setPalette())); this, SLOT(setPalette()));
} }
@ -349,16 +369,12 @@ void TabBar::setCurrentIndex(int index)
setFlags(QGraphicsItem::ItemClipsChildrenToShape); setFlags(QGraphicsItem::ItemClipsChildrenToShape);
//if an animation was in rogress hide everything to avoid an inconsistent state //if an animation was in rogress hide everything to avoid an inconsistent state
if (d->newPageAnimId != -1 || d->oldPageAnimId != -1) {
if (d->animGroup->state() != QAbstractAnimation::Stopped) {
foreach (QGraphicsWidget *page, d->pages) { foreach (QGraphicsWidget *page, d->pages) {
page->hide(); page->hide();
} }
if (d->newPageAnimId != -1) { d->animGroup->stop();
Animator::self()->stopItemMovement(d->newPageAnimId);
}
if (d->oldPageAnimId != -1) {
Animator::self()->stopItemMovement(d->oldPageAnimId);
}
} }
if (d->newPage) { if (d->newPage) {
@ -381,20 +397,27 @@ void TabBar::setCurrentIndex(int index)
if (index > d->currentIndex) { if (index > d->currentIndex) {
d->newPage->setPos(d->oldPage->geometry().topRight()); d->newPage->setPos(d->oldPage->geometry().topRight());
d->newPageAnimId = Animator::self()->moveItem( d->newPageAnim->setProperty("movementDirection", Animation::MoveAny);
d->newPage, Plasma::Animator::SlideOutMovement, d->newPageAnim->setProperty("distancePointF", d->oldPage->pos());
d->oldPage->pos().toPoint()); d->newPageAnim->setTargetWidget(d->newPage);
d->oldPageAnimId = Animator::self()->moveItem(
d->oldPage, Plasma::Animator::SlideOutMovement, d->oldPageAnim->setProperty("movementDirection", Animation::MoveAny);
beforeCurrentGeom.topLeft()); d->oldPageAnim->setProperty("distancePointF", beforeCurrentGeom.topLeft());
d->oldPageAnim->setTargetWidget(d->oldPage);
d->animGroup->start();
} else { } else {
d->newPage->setPos(beforeCurrentGeom.topLeft()); d->newPage->setPos(beforeCurrentGeom.topLeft());
d->newPageAnimId = Animator::self()->moveItem( d->newPageAnim->setProperty("movementDirection", Animation::MoveAny);
d->newPage, Plasma::Animator::SlideOutMovement, d->newPageAnim->setProperty("distancePointF", d->oldPage->pos());
d->oldPage->pos().toPoint()); d->newPageAnim->setTargetWidget(d->newPage);
d->oldPageAnimId = Animator::self()->moveItem(
d->oldPage, Plasma::Animator::SlideOutMovement, d->oldPageAnim->setProperty("movementDirection", Animation::MoveAny);
d->oldPage->geometry().topRight().toPoint()); d->oldPageAnim->setProperty("distancePointF",
d->oldPage->geometry().topRight());
d->oldPageAnim->setTargetWidget(d->oldPage);
d->animGroup->start();
} }
} else { } else {
d->tabWidgetLayout->addItem(d->newPage); d->tabWidgetLayout->addItem(d->newPage);

View File

@ -233,7 +233,8 @@ private:
friend class TabBarPrivate; friend class TabBarPrivate;
Q_PRIVATE_SLOT(d, void slidingCompleted(QGraphicsItem *item)) Q_PRIVATE_SLOT(d, void slidingNewPageCompleted())
Q_PRIVATE_SLOT(d, void slidingOldPageCompleted())
Q_PRIVATE_SLOT(d, void shapeChanged(const QTabBar::Shape shape)) Q_PRIVATE_SLOT(d, void shapeChanged(const QTabBar::Shape shape))
Q_PRIVATE_SLOT(d, void setPalette()) Q_PRIVATE_SLOT(d, void setPalette())
}; };