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_ */