Implemented auto-scrolling for ticket 499

preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent 70a204a920
commit 1d99e9762e
  1. 43
      src/gui/UBDocumentThumbnailWidget.cpp
  2. 5
      src/gui/UBDocumentThumbnailWidget.h

@ -26,9 +26,10 @@ UBDocumentThumbnailWidget::UBDocumentThumbnailWidget(QWidget* parent)
: UBThumbnailWidget(parent) : UBThumbnailWidget(parent)
, mDropCaretRectItem(0) , mDropCaretRectItem(0)
, mClosestDropItem(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) void UBDocumentThumbnailWidget::dragLeaveEvent(QDragLeaveEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
if (mScrollTimer->isActive())
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
deleteDropCaret(); deleteDropCaret();
} }
void UBDocumentThumbnailWidget::autoScroll()
{
this->verticalScrollBar()->setValue(this->verticalScrollBar()->value() + mScrollMagnitude);
}
void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event) void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event)
{ {
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<UBSceneThumbnailPixmap*> pixmapItems; QList<UBSceneThumbnailPixmap*> pixmapItems;
foreach (QGraphicsItem *item, scene()->items(mapToScene(frameRect()))) foreach (QGraphicsItem *item, scene()->items(mapToScene(boundingFrame)))
{ {
UBSceneThumbnailPixmap* sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(item); UBSceneThumbnailPixmap* sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(item);
if (sceneItem) if (sceneItem)
@ -161,8 +192,14 @@ void UBDocumentThumbnailWidget::dragMoveEvent(QDragMoveEvent *event)
event->acceptProposedAction(); event->acceptProposedAction();
} }
void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event) void UBDocumentThumbnailWidget::dropEvent(QDropEvent *event)
{ {
if (mScrollTimer->isActive())
{
mScrollMagnitude = 0;
mScrollTimer->stop();
}
deleteDropCaret(); deleteDropCaret();
if (mClosestDropItem) if (mClosestDropItem)

@ -41,6 +41,9 @@ class UBDocumentThumbnailWidget: public UBThumbnailWidget
signals: signals:
void sceneDropped(UBDocumentProxy* proxy, int source, int target); void sceneDropped(UBDocumentProxy* proxy, int source, int target);
private slots:
void autoScroll();
protected: protected:
virtual void mouseMoveEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event);
@ -57,6 +60,8 @@ class UBDocumentThumbnailWidget: public UBThumbnailWidget
UBSceneThumbnailPixmap *mClosestDropItem; UBSceneThumbnailPixmap *mClosestDropItem;
bool mDropIsRight; bool mDropIsRight;
bool mDragEnabled; bool mDragEnabled;
QTimer* mScrollTimer;
int mScrollMagnitude;
}; };
#endif /* UBDOCUMENTTHUMBNAILWIDGET_H_ */ #endif /* UBDOCUMENTTHUMBNAILWIDGET_H_ */

Loading…
Cancel
Save