This patch forward the "stateChanged" signal emitted from the private kinetic scroll animation all the way to Plasma::ScrollWidget, which then forwards this signal to its childs. This enables an object which derives from Plasma::ScrollWidget to know the kinetic scrolling animation state.

Patch by Bruno Abinader

svn path=/trunk/KDE/kdelibs/; revision=1064768
This commit is contained in:
Marco Martin 2009-12-21 18:36:39 +00:00
parent 09fc589dce
commit fdae3f0d59
7 changed files with 68 additions and 4 deletions

View File

@ -23,6 +23,7 @@
#include <QtGui/QImage>
#include <QtCore/QObject>
#include <QtCore/QAbstractAnimation>
#include <plasma/plasma_export.h>
@ -201,6 +202,8 @@ Q_SIGNALS:
void movementFinished(QGraphicsItem *item);
void elementAnimationFinished(int id);
void customAnimationFinished(int id);
void scrollStateChanged(QGraphicsWidget *widget, QAbstractAnimation::State newState,
QAbstractAnimation::State oldState);
protected:
void timerEvent(QTimerEvent *event);
@ -214,7 +217,10 @@ private:
Q_PRIVATE_SLOT(d, void movingItemDestroyed(QObject*))
Q_PRIVATE_SLOT(d, void animatedElementDestroyed(QObject*))
Q_PRIVATE_SLOT(d, void customAnimReceiverDestroyed(QObject*))
Q_PRIVATE_SLOT(d, void scrollStateChanged(QAbstractAnimation::State,
QAbstractAnimation::State))
friend class AnimatorPrivate;
AnimatorPrivate * const d;
};

View File

@ -40,8 +40,9 @@ namespace Plasma
static const int MIN_TICK_RATE_INT = 10;
static const qreal MIN_TICK_RATE = 10;
AnimatorPrivate::AnimatorPrivate()
: driver(0),
AnimatorPrivate::AnimatorPrivate(Animator *parent)
: q(parent),
driver(0),
animId(0),
timerId(0)
{
@ -117,6 +118,18 @@ void AnimatorPrivate::performMovement(qreal amount, const MovementState *state)
}
}
void AnimatorPrivate::scrollStateChanged(QAbstractAnimation::State newState,
QAbstractAnimation::State oldState)
{
KineticScrolling *scroll = qobject_cast<KineticScrolling*>(q->sender());
if (!scroll) {
kDebug() << "Could not find KineticScrolling object";
return;
}
emit q->scrollStateChanged(scrollingManagers.key(scroll), newState, oldState);
}
class AnimatorSingleton
{
public:
@ -132,7 +145,7 @@ Animator *Animator::self()
Animator::Animator(QObject *parent)
: QObject(parent),
d(new AnimatorPrivate)
d(new AnimatorPrivate(this))
{
d->init(this);
}
@ -752,12 +765,18 @@ void Animator::registerScrollingManager(QGraphicsWidget *widget)
if (!d->scrollingManagers.contains(widget)) {
KineticScrolling *scroll = new KineticScrolling(widget);
d->scrollingManagers.insert(widget, scroll);
connect(scroll,
SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), this,
SLOT(scrollStateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
}
}
void Animator::unregisterScrollingManager(QGraphicsWidget *widget)
{
if (d->scrollingManagers.contains(widget)) {
disconnect(d->scrollingManagers.value(widget),
SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), this,
SLOT(scrollStateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
d->scrollingManagers.value(widget)->deleteLater();
d->scrollingManagers.remove(widget);
}

View File

@ -90,10 +90,12 @@ struct CustomAnimationState
char *slot;
};
class Animator;
class AnimatorPrivate
{
public:
AnimatorPrivate();
AnimatorPrivate(Animator *parent);
~AnimatorPrivate();
qreal calculateProgress(int time, int duration, Animator::CurveShape curve);
@ -107,6 +109,10 @@ class AnimatorPrivate
void animatedElementDestroyed(QObject*);
void customAnimReceiverDestroyed(QObject*);
void scrollStateChanged(QAbstractAnimation::State newState,
QAbstractAnimation::State oldState);
Animator *q;
AnimationDriver *driver;
int animId;
int timerId;

View File

@ -349,6 +349,9 @@ void KineticScrolling::setWidget(QGraphicsWidget *parent)
if (d->parent) {
d->parent->removeEventFilter(this);
disconnect(d->scrollAnimation, SIGNAL(finished()), this, SLOT(overshoot()));
disconnect(d->scrollAnimation,
SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), this,
SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
delete d->scrollAnimation;
}
@ -358,6 +361,9 @@ void KineticScrolling::setWidget(QGraphicsWidget *parent)
d->scrollAnimation = new QPropertyAnimation(parent, "scrollPosition", parent);
connect(d->scrollAnimation, SIGNAL(finished()), this, SLOT(overshoot()));
connect(d->scrollAnimation,
SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), this,
SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
d->scrollAnimation->setEasingCurve(QEasingCurve::OutCirc);
if (parent) {

View File

@ -28,6 +28,7 @@ class QGraphicsSceneWheelEvent;
class QKeyEvent;
#include <QObject>
#include <QPointF>
#include <QtCore/QAbstractAnimation>
namespace Plasma
@ -43,6 +44,10 @@ public:
~KineticScrolling();
void setWidget(QGraphicsWidget *parent);
Q_SIGNALS:
void stateChanged(QAbstractAnimation::State newState,
QAbstractAnimation::State oldState);
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);

View File

@ -285,6 +285,14 @@ public:
dragHandles.remove(static_cast<QGraphicsWidget *>(destroyed));
}
void scrollStateChanged(QGraphicsWidget *widget, QAbstractAnimation::State newState,
QAbstractAnimation::State oldState)
{
if (widget == q) {
emit q->scrollStateChanged(newState, oldState);
}
}
ScrollWidget *q;
QGraphicsWidget *scrollingWidget;
QWeakPointer<QGraphicsWidget> widget;
@ -338,6 +346,11 @@ void ScrollWidget::setWidget(QGraphicsWidget *widget)
d->widget = widget;
Plasma::Animator::self()->registerScrollingManager(this);
connect(Plasma::Animator::self(),
SIGNAL(scrollStateChanged(QGraphicsWidget *, QAbstractAnimation::State,
QAbstractAnimation::State)), this,
SLOT(scrollStateChanged(QGraphicsWidget *, QAbstractAnimation::State,
QAbstractAnimation::State)));
//it's not good it's setting a size policy here, but it's done to be retrocompatible with older applications
if (widget) {

View File

@ -20,6 +20,7 @@
#ifndef PLASMA_SCROLLWIDGET_H
#define PLASMA_SCROLLWIDGET_H
#include <QtCore/QAbstractAnimation>
#include <QtGui/QGraphicsWidget>
#include <plasma/plasma_export.h>
@ -181,6 +182,10 @@ public:
*/
QWidget *nativeWidget() const;
Q_SIGNALS:
void scrollStateChanged(QAbstractAnimation::State newState,
QAbstractAnimation::State oldState);
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
@ -202,6 +207,10 @@ private:
Q_PRIVATE_SLOT(d, void makeItemVisible())
Q_PRIVATE_SLOT(d, void cleanupDragHandles(QObject *destroyed))
Q_PRIVATE_SLOT(d, void adjustScrollbars())
Q_PRIVATE_SLOT(d, void scrollStateChanged(QGraphicsWidget *, QAbstractAnimation::State,
QAbstractAnimation::State))
friend class ScrollWidgetPrivate;
};
} // namespace Plasma