Implemented auto-scrolling for ticket 499

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

@ -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<UBSceneThumbnailPixmap*> 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<UBSceneThumbnailPixmap*> pixmapItems;
foreach (QGraphicsItem *item, scene()->items(mapToScene(boundingFrame)))
{
UBSceneThumbnailPixmap* sceneItem = dynamic_cast<UBSceneThumbnailPixmap*>(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)
{

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

Loading…
Cancel
Save