Commit 37bb01c6 authored by Nate Graham's avatar Nate Graham 🔩
Browse files

Define animated smooth scroll durations in a central location

This will make it easy to adjust the durations in the future.
parent 37bf29d5
......@@ -176,6 +176,12 @@ public:
double lastSourceLocationViewportNormalizedX;
double lastSourceLocationViewportNormalizedY;
int controlWheelAccumulatedDelta;
// for everything except PgUp/PgDn and scroll to arbitrary locations
int smoothScrollShortDuration;
// for PgUp/PgDn and scroll to arbitrary locations
int smoothScrollLongDuration;
// auto scroll
int scrollIncrement;
QTimer *autoScrollTimer;
......@@ -330,6 +336,8 @@ PageView::PageView(QWidget *parent, Okular::Document *document)
d->lastSourceLocationViewportNormalizedX = 0.0;
d->lastSourceLocationViewportNormalizedY = 0.0;
d->controlWheelAccumulatedDelta = 0;
d->smoothScrollShortDuration = 100;
d->smoothScrollLongDuration = d->smoothScrollShortDuration * 2;
d->scrollIncrement = 0;
d->autoScrollTimer = nullptr;
d->annotator = nullptr;
......@@ -1886,7 +1894,7 @@ void PageView::keyPressEvent(QKeyEvent *e)
int next_page = d->document->currentPage() - viewColumns();
d->document->setViewportPage(next_page);
} else {
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(-horizontalScrollBar()->singleStep(), 0), 100);
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(-horizontalScrollBar()->singleStep(), 0), d->smoothScrollShortDuration);
}
break;
case Qt::Key_Right:
......@@ -1896,7 +1904,7 @@ void PageView::keyPressEvent(QKeyEvent *e)
int next_page = d->document->currentPage() + viewColumns();
d->document->setViewportPage(next_page);
} else {
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(horizontalScrollBar()->singleStep(), 0), 100);
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(horizontalScrollBar()->singleStep(), 0), d->smoothScrollShortDuration);
}
break;
case Qt::Key_Escape:
......@@ -4023,7 +4031,7 @@ void PageView::scrollTo(int x, int y, bool smoothMove)
d->blockPixmapsRequest = true;
if (smoothMove)
d->scroller->scrollTo(QPoint(x, y));
d->scroller->scrollTo(QPoint(x, y), d->smoothScrollLongDuration);
else
d->scroller->scrollTo(QPoint(x, y), 0);
......@@ -4745,10 +4753,10 @@ void PageView::slotScrollUp(int nSteps)
// if in single page mode and at the top of the screen, go to \ page
if (Okular::Settings::viewContinuous() || verticalScrollBar()->value() > verticalScrollBar()->minimum()) {
if (nSteps) {
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(0, -100 * nSteps), 100);
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(0, -100 * nSteps), d->smoothScrollShortDuration);
} else {
if (d->scroller->finalPosition().y() > verticalScrollBar()->minimum())
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(0, -verticalScrollBar()->rect().height()));
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(0, -verticalScrollBar()->rect().height()), d->smoothScrollLongDuration);
}
} else if (d->document->currentPage() > 0) {
// more optimized than document->setPrevPage and then move view to bottom
......@@ -4767,10 +4775,10 @@ void PageView::slotScrollDown(int nSteps)
// if in single page mode and at the bottom of the screen, go to next page
if (Okular::Settings::viewContinuous() || verticalScrollBar()->value() < verticalScrollBar()->maximum()) {
if (nSteps) {
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(0, 100 * nSteps), 100);
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(0, 100 * nSteps), d->smoothScrollShortDuration);
} else {
if (d->scroller->finalPosition().y() < verticalScrollBar()->maximum())
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(0, verticalScrollBar()->rect().height()));
d->scroller->scrollTo(d->scroller->finalPosition() + QPoint(0, verticalScrollBar()->rect().height()), d->smoothScrollLongDuration);
}
} else if ((int)d->document->currentPage() < d->items.count() - 1) {
// more optimized than document->setNextPage and then move view to top
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment