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

svn path=/trunk/KDE/kdelibs/; revision=1027814
This commit is contained in:
Marco Martin 2009-09-24 20:40:16 +00:00
parent bb11bbf81b
commit a4d591e6fd
2 changed files with 50 additions and 1 deletions

View File

@ -32,6 +32,7 @@
//Plasma //Plasma
#include <plasma/widgets/scrollbar.h> #include <plasma/widgets/scrollbar.h>
#include <plasma/widgets/svgwidget.h> #include <plasma/widgets/svgwidget.h>
#include <plasma/animator.h>
#include <plasma/svg.h> #include <plasma/svg.h>
namespace Plasma namespace Plasma
@ -47,7 +48,8 @@ public:
bottomBorder(0), bottomBorder(0),
leftBorder(0), leftBorder(0),
rightBorder(0), rightBorder(0),
dragging(false) dragging(false),
animId(0)
{ {
} }
@ -181,6 +183,7 @@ public:
Qt::ScrollBarPolicy horizontalScrollBarPolicy; Qt::ScrollBarPolicy horizontalScrollBarPolicy;
QString styleSheet; QString styleSheet;
bool dragging; bool dragging;
int animId;
}; };
@ -261,6 +264,32 @@ Qt::ScrollBarPolicy ScrollWidget::verticalScrollBarPolicy() const
return d->verticalScrollBarPolicy; 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) void ScrollWidget::setStyleSheet(const QString &styleSheet)
{ {
@ -311,12 +340,20 @@ void ScrollWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
return; return;
} }
if (d->animId) {
Animator::self()->stopItemMovement(d->animId);
}
d->mouseMoveEvent(event); d->mouseMoveEvent(event);
QGraphicsWidget::mouseMoveEvent(event); QGraphicsWidget::mouseMoveEvent(event);
} }
void ScrollWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) void ScrollWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (d->animId) {
Animator::self()->stopItemMovement(d->animId);
}
event->accept(); event->accept();
d->mousePressEvent(event); d->mousePressEvent(event);
} }
@ -328,6 +365,10 @@ void ScrollWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void ScrollWidget::wheelEvent(QGraphicsSceneWheelEvent *event) void ScrollWidget::wheelEvent(QGraphicsSceneWheelEvent *event)
{ {
if (d->animId) {
Animator::self()->stopItemMovement(d->animId);
}
event->accept(); event->accept();
d->wheelReleaseEvent( event ); d->wheelReleaseEvent( event );
} }

View File

@ -95,6 +95,14 @@ public:
*/ */
Qt::ScrollBarPolicy verticalScrollBarPolicy() const; 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 * Sets the stylesheet used to control the visual display of this ScrollWidget
* *