SVN commit 1027814 by mart: ensureRectVisible() a rect in internal widget coordinates will cause an animated scroll until the rect becomes visible it should not collide with kinetic scroll since the anim is stopped as soon as amouse or wheel event is triggered CCMAIL:plasma-devel@kde.org M +42 -1 scrollwidget.cpp M +8 -0 scrollwidget.h --- trunk/KDE/kdelibs/plasma/widgets/scrollwidget.cpp #1027813:1027814 @@ -32,6 +32,7 @@ //Plasma #include #include +#include #include namespace Plasma @@ -47,7 +48,8 @@ bottomBorder(0), leftBorder(0), rightBorder(0), - dragging(false) + dragging(false), + animId(0) { } @@ -181,6 +183,7 @@ Qt::ScrollBarPolicy horizontalScrollBarPolicy; QString styleSheet; bool dragging; + int animId; }; @@ -261,7 +264,33 @@ return d->verticalScrollBarPolicy; } +void ScrollWidget::ensureRectVisible(const QRectF &rect) +{ + QRectF viewRect = d->scrollingWidget->boundingRect(); + QRectF mappedRect = d->widget->mapToItem(d->scrollingWidget, rect).boundingRect(); + if (viewRect.contains(mappedRect)) { + return; + } + QPointF delta(0, 0); + + if (mappedRect.top() < 0) { + delta.setY(-mappedRect.top()); + } else if (mappedRect.bottom() > viewRect.bottom()) { + delta.setY(viewRect.bottom() - mappedRect.bottom()); + } + + if (mappedRect.left() < 0) { + delta.setX(-mappedRect.left()); + } else if (mappedRect.right() > viewRect.right()) { + delta.setY(viewRect.right() - mappedRect.right()); + } + + d->animId = Animator::self()->moveItem( + d->widget, Plasma::Animator::SlideOutMovement, + (d->widget->pos() + delta).toPoint()); +} + void ScrollWidget::setStyleSheet(const QString &styleSheet) { d->styleSheet = styleSheet; @@ -311,12 +340,20 @@ return; } + if (d->animId) { + Animator::self()->stopItemMovement(d->animId); + } + d->mouseMoveEvent(event); QGraphicsWidget::mouseMoveEvent(event); } void ScrollWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) { + if (d->animId) { + Animator::self()->stopItemMovement(d->animId); + } + event->accept(); d->mousePressEvent(event); } @@ -328,6 +365,10 @@ void ScrollWidget::wheelEvent(QGraphicsSceneWheelEvent *event) { + if (d->animId) { + Animator::self()->stopItemMovement(d->animId); + } + event->accept(); d->wheelReleaseEvent( event ); } --- trunk/KDE/kdelibs/plasma/widgets/scrollwidget.h #1027813:1027814 @@ -96,6 +96,14 @@ Qt::ScrollBarPolicy verticalScrollBarPolicy() const; /** + * Scroll the view until the given rectangle is visible + * + * @param rect rect we want visible, in coordinates mapped to the inner widget + * @since 4.4 + */ + void ensureRectVisible(const QRectF &rect); + + /** * Sets the stylesheet used to control the visual display of this ScrollWidget * * @arg stylesheet a CSS string _______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel