use an eventfilter instead to have to manually forward each event,
should be less error prone and require less api svn path=/trunk/KDE/kdelibs/; revision=1035740
This commit is contained in:
parent
731474d470
commit
c4b42df8e8
@ -21,6 +21,7 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
#include <QtCore/qglobal.h>
|
#include <QtCore/qglobal.h>
|
||||||
#include <QtCore/qmetatype.h>
|
#include <QtCore/qmetatype.h>
|
||||||
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QGraphicsSceneWheelEvent>
|
#include <QGraphicsSceneWheelEvent>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
@ -60,7 +61,9 @@ public:
|
|||||||
overshoot(20),
|
overshoot(20),
|
||||||
bounceFlag(0),
|
bounceFlag(0),
|
||||||
hasOvershoot(true),
|
hasOvershoot(true),
|
||||||
friction(0.8)
|
parent(0),
|
||||||
|
friction(0.8),
|
||||||
|
forwardingEvent(false)
|
||||||
{
|
{
|
||||||
maximum = 100 + overshoot;
|
maximum = 100 + overshoot;
|
||||||
minimum = -overshoot;
|
minimum = -overshoot;
|
||||||
@ -112,11 +115,12 @@ public:
|
|||||||
QPointF cposition;
|
QPointF cposition;
|
||||||
char bounceFlag;
|
char bounceFlag;
|
||||||
bool hasOvershoot;
|
bool hasOvershoot;
|
||||||
QObject *parent;
|
QGraphicsWidget *parent;
|
||||||
QRectF viewportGeometry;
|
QRectF viewportGeometry;
|
||||||
QSizeF contentsSize;
|
QSizeF contentsSize;
|
||||||
int maximum, minimum;
|
int maximum, minimum;
|
||||||
qreal friction;
|
qreal friction;
|
||||||
|
bool forwardingEvent;
|
||||||
|
|
||||||
QTime t;
|
QTime t;
|
||||||
};
|
};
|
||||||
@ -335,9 +339,57 @@ void KineticScrolling::doneOvershoot(void)
|
|||||||
|
|
||||||
void KineticScrolling::setWidget(QGraphicsWidget *parent)
|
void KineticScrolling::setWidget(QGraphicsWidget *parent)
|
||||||
{
|
{
|
||||||
|
if (d->parent) {
|
||||||
|
d->parent->removeEventFilter(this);
|
||||||
|
}
|
||||||
|
|
||||||
d->parent = parent;
|
d->parent = parent;
|
||||||
|
|
||||||
|
if (parent) {
|
||||||
|
d->parent->installEventFilter(this);
|
||||||
|
}
|
||||||
/* TODO: add a new property in plasma::ScrollWidget 'hasOvershoot' */
|
/* TODO: add a new property in plasma::ScrollWidget 'hasOvershoot' */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KineticScrolling::eventFilter(QObject *watched, QEvent *event)
|
||||||
|
{
|
||||||
|
if (d->forwardingEvent) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool notBlocked = true;
|
||||||
|
if (d->parent && d->parent->scene()) {
|
||||||
|
d->forwardingEvent = true;
|
||||||
|
notBlocked = d->parent->scene()->sendEvent(d->parent, event);
|
||||||
|
d->forwardingEvent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!notBlocked || ((event->type() != QEvent::GraphicsSceneMousePress && event->isAccepted()) && (event->type() != QEvent::GraphicsSceneWheel && event->isAccepted()))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
|
||||||
|
QGraphicsSceneWheelEvent *we = static_cast<QGraphicsSceneWheelEvent *>(event);
|
||||||
|
|
||||||
|
switch (event->type()) {
|
||||||
|
case QEvent::GraphicsSceneMousePress:
|
||||||
|
mousePressEvent(me);
|
||||||
|
break;
|
||||||
|
case QEvent::GraphicsSceneMouseRelease:
|
||||||
|
mouseReleaseEvent(me);
|
||||||
|
break;
|
||||||
|
case QEvent::GraphicsSceneMouseMove:
|
||||||
|
mouseMoveEvent(me);
|
||||||
|
break;
|
||||||
|
case QEvent::GraphicsSceneWheel:
|
||||||
|
wheelReleaseEvent(we);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
|
||||||
|
@ -40,11 +40,14 @@ class KineticScrolling: public QObject
|
|||||||
public:
|
public:
|
||||||
KineticScrolling();
|
KineticScrolling();
|
||||||
~KineticScrolling();
|
~KineticScrolling();
|
||||||
|
void setWidget(QGraphicsWidget *parent);
|
||||||
|
|
||||||
|
protected:
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void wheelReleaseEvent(QGraphicsSceneWheelEvent *event);
|
void wheelReleaseEvent(QGraphicsSceneWheelEvent *event);
|
||||||
void setWidget(QGraphicsWidget *parent);
|
|
||||||
private:
|
private:
|
||||||
KineticScrollingPrivate *d;
|
KineticScrollingPrivate *d;
|
||||||
void timerEvent(QTimerEvent *event);
|
void timerEvent(QTimerEvent *event);
|
||||||
@ -54,6 +57,9 @@ private:
|
|||||||
void startAnimationTimer(int interval);
|
void startAnimationTimer(int interval);
|
||||||
void doneOvershoot(void);
|
void doneOvershoot(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setKineticScrollValue(QPointF value);
|
void setKineticScrollValue(QPointF value);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user