From b2bb69732a42a8ac64d91913e66e71627a077824 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 19 Oct 2009 22:10:25 +0000 Subject: [PATCH] provide the Animator::registerScrollingManager(qgraphicsidget) function. the animator creates a kineticscroll and associates it with the widget. in this way we can use kineticscroll outside of libplasma with a single call. svn path=/trunk/KDE/kdelibs/; revision=1037751 --- animator.h | 20 ++++++++++++++++++++ deprecated/animator.cpp | 19 +++++++++++++++++++ private/kineticscroll.cpp | 7 +++++-- private/kineticscroll_p.h | 2 +- widgets/scrollwidget.cpp | 5 ++--- widgets/webview.cpp | 6 +++--- 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/animator.h b/animator.h index 580e52355..66b9cd2b9 100644 --- a/animator.h +++ b/animator.h @@ -27,6 +27,7 @@ #include class QGraphicsItem; +class QGraphicsWidget; class QTimeLine; namespace Plasma @@ -159,6 +160,25 @@ public: */ KDE_DEPRECATED Q_INVOKABLE bool isAnimating() const; + /** + * Register a widget as a scrolling widget. + * The widget will get animate scrolling with mouse dragging and mouse wheel. + * It must provide + * scrollValue, viewportGeometry and pageSize properties + * + * @param widget the widget that offers a scrolling behaviour + * @since 4.4 + */ + void registerScrollingManager(QGraphicsWidget *widget); + + /** + * unregister the scrolling manager of a certain widget + * + * @param widget the widget we don't want no longer animated + * @since 4.4 + */ + void unregisterScrollingManager(QGraphicsWidget *widget); + Q_SIGNALS: void animationFinished(QGraphicsItem *item, Plasma::Animator::Animation anim); void movementFinished(QGraphicsItem *item); diff --git a/deprecated/animator.cpp b/deprecated/animator.cpp index 397818878..05f5091de 100644 --- a/deprecated/animator.cpp +++ b/deprecated/animator.cpp @@ -31,6 +31,7 @@ #include #include "animationdriver.h" +#include "private/kineticscroll_p.h" namespace Plasma { @@ -194,6 +195,8 @@ class AnimatorPrivateDeprecated QSet movingItemsToDelete; QSet animatedElementsToDelete; QSet customAnimsToDelete; + + QHash scrollingManagers; }; class AnimatorSingleton @@ -828,6 +831,22 @@ void AnimatorPrivateDeprecated::cleanupStates() customAnimsToDelete.clear(); } +void Animator::registerScrollingManager(QGraphicsWidget *widget) +{ + if (!d->scrollingManagers.contains(widget)) { + KineticScrolling *scroll = new KineticScrolling(widget); + d->scrollingManagers.insert(widget, scroll); + } +} + +void Animator::unregisterScrollingManager(QGraphicsWidget *widget) +{ + if (d->scrollingManagers.contains(widget)) { + d->scrollingManagers.value(widget)->deleteLater(); + d->scrollingManagers.remove(widget); + } +} + } // namespace Plasma #include <../animator.moc> diff --git a/private/kineticscroll.cpp b/private/kineticscroll.cpp index 605ef65f0..f0a128162 100644 --- a/private/kineticscroll.cpp +++ b/private/kineticscroll.cpp @@ -126,9 +126,10 @@ public: }; -KineticScrolling::KineticScrolling(): d(0) +KineticScrolling::KineticScrolling(QGraphicsWidget *parent) + : d(new KineticScrollingPrivate) { - d = new KineticScrollingPrivate; + setWidget(parent); } KineticScrolling::~KineticScrolling() @@ -355,6 +356,8 @@ void KineticScrolling::setWidget(QGraphicsWidget *parent) d->parent->removeEventFilter(this); } + setParent(parent); + d->parent = parent; if (parent) { diff --git a/private/kineticscroll_p.h b/private/kineticscroll_p.h index 6ea6bc108..5845201ce 100644 --- a/private/kineticscroll_p.h +++ b/private/kineticscroll_p.h @@ -38,7 +38,7 @@ class KineticScrolling: public QObject { Q_OBJECT public: - KineticScrolling(); + KineticScrolling(QGraphicsWidget *parent); ~KineticScrolling(); void setWidget(QGraphicsWidget *parent); diff --git a/widgets/scrollwidget.cpp b/widgets/scrollwidget.cpp index 73fe580b0..58b347354 100644 --- a/widgets/scrollwidget.cpp +++ b/widgets/scrollwidget.cpp @@ -18,7 +18,6 @@ */ #include "scrollwidget.h" -#include "private/kineticscroll_p.h" //Qt #include #include @@ -39,7 +38,7 @@ namespace Plasma { -class ScrollWidgetPrivate: public KineticScrolling +class ScrollWidgetPrivate { public: ScrollWidgetPrivate(ScrollWidget *parent) @@ -275,7 +274,7 @@ void ScrollWidget::setWidget(QGraphicsWidget *widget) } d->widget = widget; - d->setWidget(this); + Plasma::Animator::self()->registerScrollingManager(this); widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); widget->setParentItem(d->scrollingWidget); widget->setPos(QPoint(0,0)); diff --git a/widgets/webview.cpp b/widgets/webview.cpp index 1d7c161b9..0eaaea299 100644 --- a/widgets/webview.cpp +++ b/widgets/webview.cpp @@ -37,12 +37,12 @@ #include "plasma/widgets/webview.h" -#include "plasma/private/kineticscroll_p.h" +#include "plasma/animator.h" namespace Plasma { -class WebViewPrivate : public KineticScrolling +class WebViewPrivate { public: WebViewPrivate(WebView *parent) @@ -69,7 +69,7 @@ WebView::WebView(QGraphicsItem *parent) { d->page = 0; d->loaded = false; - d->setWidget(this); + Plasma::Animator::self()->registerScrollingManager(this); setAcceptsHoverEvents(true); setFlags(QGraphicsItem::ItemIsFocusable);