From 1d99e9762e3771e6084f1d62490f7407e752d548 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Fri, 10 Feb 2012 19:12:32 +0300 Subject: [PATCH] Implemented auto-scrolling for ticket 499 --- src/gui/UBDocumentThumbnailWidget.cpp | 47 ++++++++++++++++++++++++--- src/gui/UBDocumentThumbnailWidget.h | 5 +++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/gui/UBDocumentThumbnailWidget.cpp b/src/gui/UBDocumentThumbnailWidget.cpp index 788ae05d..debeb9a1 100644 --- a/src/gui/UBDocumentThumbnailWidget.cpp +++ b/src/gui/UBDocumentThumbnailWidget.cpp @@ -26,9 +26,10 @@ UBDocumentThumbnailWidget::UBDocumentThumbnailWidget(QWidget* parent) : UBThumbnailWidget(parent) , mDropCaretRectItem(0) , mClosestDropItem(0) - , mDragEnabled(true) + , mDragEnabled(true), mScrollMagnitude(0) { - // NOOP + mScrollTimer = new QTimer(this); + connect(mScrollTimer, SIGNAL(timeout()), this, SLOT(autoScroll())); } @@ -96,13 +97,43 @@ void UBDocumentThumbnailWidget::dragEnterEvent(QDragEnterEvent *event) void UBDocumentThumbnailWidget::dragLeaveEvent(QDragLeaveEvent *event) { Q_UNUSED(event); + if (mScrollTimer->isActive()) + { + mScrollMagnitude = 0; + mScrollTimer->stop(); + } deleteDropCaret(); } +void UBDocumentThumbnailWidget::autoScroll() +{ + this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude); +} + void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event) { - QList pixmapItems; - foreach (QGraphicsItem *item, scene()->items(mapToScene(frameRect()))) + QRect boundingFrame = frameRect(); + //setting up automatic scrolling + const int SCROLL_DISTANCE = 16; + int bottomDist = boundingFrame.bottom() - event->pos().y(), topDist = boundingFrame.top() - event->pos().y(); + if(qAbs(bottomDist) <= SCROLL_DISTANCE) + { + mScrollMagnitude = (SCROLL_DISTANCE - bottomDist)*4; + if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); + } + else if(qAbs(topDist) <= SCROLL_DISTANCE) + { + mScrollMagnitude = (- SCROLL_DISTANCE - topDist)*4; + if(verticalScrollBar()->isVisible() && !mScrollTimer->isActive()) mScrollTimer->start(100); + } + else + { + mScrollMagnitude = 0; + mScrollTimer->stop(); + } + + QList pixmapItems; + foreach (QGraphicsItem *item, scene()->items(mapToScene(boundingFrame))) { UBSceneThumbnailPixmap* sceneItem = dynamic_cast(item); if (sceneItem) @@ -161,9 +192,15 @@ void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event) event->acceptProposedAction(); } + void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event) { - deleteDropCaret(); + if (mScrollTimer->isActive()) + { + mScrollMagnitude = 0; + mScrollTimer->stop(); + } + deleteDropCaret(); if (mClosestDropItem) { diff --git a/src/gui/UBDocumentThumbnailWidget.h b/src/gui/UBDocumentThumbnailWidget.h index 2d24688f..adfe7c2d 100644 --- a/src/gui/UBDocumentThumbnailWidget.h +++ b/src/gui/UBDocumentThumbnailWidget.h @@ -41,6 +41,9 @@ class UBDocumentThumbnailWidget: public UBThumbnailWidget signals: void sceneDropped(UBDocumentProxy* proxy, int source, int target); + private slots: + void autoScroll(); + protected: virtual void mouseMoveEvent(QMouseEvent *event); @@ -57,6 +60,8 @@ class UBDocumentThumbnailWidget: public UBThumbnailWidget UBSceneThumbnailPixmap *mClosestDropItem; bool mDropIsRight; bool mDragEnabled; + QTimer* mScrollTimer; + int mScrollMagnitude; }; #endif /* UBDOCUMENTTHUMBNAILWIDGET_H_ */