Implement wheel scrolling and add a way of disabling overshoot.
plus some doc cleanups. svn path=/trunk/KDE/kdelibs/; revision=1104868
This commit is contained in:
parent
82702e7043
commit
3c0cffc506
@ -642,6 +642,37 @@ public:
|
||||
lastPosTime = QTime();
|
||||
}
|
||||
|
||||
void handleWheelEvent(QGraphicsSceneWheelEvent *event)
|
||||
{
|
||||
if (!widget.data())
|
||||
return;
|
||||
|
||||
QPointF start = widget.data()->pos();
|
||||
QPointF end = start;
|
||||
qreal step = event->delta()/3;
|
||||
|
||||
//At some point we should switch to
|
||||
// step = QApplication::wheelScrollLines() *
|
||||
// (event->delta()/120) *
|
||||
// scrollBar->singleStep();
|
||||
// which gives us exactly the number of lines to scroll but the issue
|
||||
// is that at this point we don't have any clue what a "line" is and if
|
||||
// we make it a pixel then scrolling by 3 (default) pixels will be
|
||||
// very painful
|
||||
if(event->orientation() == Qt::Vertical) {
|
||||
end += QPointF(0, step);
|
||||
} else if (event->orientation() == Qt::Horizontal) {
|
||||
end += QPointF(step, 0);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
directMoveAnimation->setStartValue(start);
|
||||
directMoveAnimation->setEndValue(end);
|
||||
directMoveAnimation->setDuration(200);
|
||||
directMoveAnimation->start();
|
||||
}
|
||||
|
||||
qreal minXExtent() const
|
||||
{
|
||||
if (alignment & Qt::AlignLeft)
|
||||
@ -1110,11 +1141,13 @@ void ScrollWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void ScrollWidget::wheelEvent(QGraphicsSceneWheelEvent *)
|
||||
void ScrollWidget::wheelEvent(QGraphicsSceneWheelEvent *event)
|
||||
{
|
||||
if (!d->widget) {
|
||||
return;
|
||||
}
|
||||
d->handleWheelEvent(event);
|
||||
event->accept();
|
||||
}
|
||||
|
||||
bool ScrollWidget::eventFilter(QObject *watched, QEvent *event)
|
||||
@ -1209,6 +1242,8 @@ bool ScrollWidget::sceneEventFilter(QGraphicsItem *i, QEvent *e)
|
||||
case QEvent::GraphicsSceneMouseRelease:
|
||||
d->handleMouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent*>(e));
|
||||
break;
|
||||
case QEvent::GraphicsSceneWheel:
|
||||
d->handleWheelEvent(static_cast<QGraphicsSceneWheelEvent*>(e));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -1232,6 +1267,16 @@ Qt::Alignment Plasma::ScrollWidget::alignment() const
|
||||
return d->alignment;
|
||||
}
|
||||
|
||||
void ScrollWidget::setOverShoot(bool enable)
|
||||
{
|
||||
d->hasOvershoot = enable;
|
||||
}
|
||||
|
||||
bool ScrollWidget::hasOverShoot() const
|
||||
{
|
||||
return d->hasOvershoot;
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
|
||||
|
@ -51,6 +51,7 @@ class PLASMA_EXPORT ScrollWidget : public QGraphicsWidget
|
||||
Q_PROPERTY(QRectF viewportGeometry READ viewportGeometry)
|
||||
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
|
||||
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
|
||||
Q_PROPERTY(bool overShoot READ hasOverShoot WRITE setOverShoot)
|
||||
|
||||
public:
|
||||
|
||||
@ -84,14 +85,30 @@ public:
|
||||
* Sets the alignment for the inner widget.
|
||||
* It is only meaningful if the inner widget is smaller
|
||||
* than the viewport.
|
||||
* @since 4.5
|
||||
*/
|
||||
void setAlignment(Qt::Alignment align);
|
||||
|
||||
/**
|
||||
* @return currently set alignment for the inner widget
|
||||
* @return currently set alignment for the inner widget
|
||||
* @since 4.5
|
||||
*/
|
||||
Qt::Alignment alignment() const;
|
||||
|
||||
/**
|
||||
* Tells the scrollwidget whether the widget can scroll a little
|
||||
* beyond its boundaries and then automatically snap back or
|
||||
* whether the widget scrolling always stops at the edges.
|
||||
* @since 4.5
|
||||
*/
|
||||
void setOverShoot(bool enable);
|
||||
|
||||
/**
|
||||
* @return true if overshoot is enabled
|
||||
* @since 4.5
|
||||
*/
|
||||
bool hasOverShoot() const;
|
||||
|
||||
/**
|
||||
* Sets the horizontal scrollbar policy
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user