[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    KDE/kdelibs/plasma/widgets
From:       Marco Martin <notmart () gmail ! com>
Date:       2009-09-24 20:40:16
Message-ID: 1253824816.636218.11887.nullmailer () svn ! kde ! org
[Download RAW message or body]

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 <plasma/widgets/scrollbar.h>
 #include <plasma/widgets/svgwidget.h>
+#include <plasma/animator.h>
 #include <plasma/svg.h>
 
 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
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic