mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-25 02:45:38 +00:00
Fix forms when inertially scrolling
`setViewport` automatically adds an item to the history if it finds that it moved for more than a page, which we don't want to do when automatically scrolling, as with inertial scrolling. This commit adds a new function `setViewportWithHistory()` which takes an argument to optionally avoid preserving history. This avoids breaking ABI. The new history-less functionality is used when inertially scrolling. BUG: 421354 FIXED-IN: 1.11.2
This commit is contained in:
parent
601e96037c
commit
bdb2df773d
|
@ -3445,19 +3445,8 @@ void Document::setPrevPage()
|
|||
setViewport( DocumentViewport( (*d->m_viewportIterator).pageNumber - 1 ) );
|
||||
}
|
||||
*/
|
||||
void Document::setViewportPage(int page, DocumentObserver *excludeObserver, bool smoothMove)
|
||||
{
|
||||
// clamp page in range [0 ... numPages-1]
|
||||
if (page < 0)
|
||||
page = 0;
|
||||
else if (page > (int)d->m_pagesVector.count())
|
||||
page = d->m_pagesVector.count() - 1;
|
||||
|
||||
// make a viewport from the page and broadcast it
|
||||
setViewport(DocumentViewport(page), excludeObserver, smoothMove);
|
||||
}
|
||||
|
||||
void Document::setViewport(const DocumentViewport &viewport, DocumentObserver *excludeObserver, bool smoothMove)
|
||||
void Document::setViewportWithHistory(const DocumentViewport &viewport, DocumentObserver *excludeObserver, bool smoothMove, bool updateHistory)
|
||||
{
|
||||
if (!viewport.isValid()) {
|
||||
qCDebug(OkularCoreDebug) << "invalid viewport:" << viewport.toString();
|
||||
|
@ -3477,7 +3466,7 @@ void Document::setViewport(const DocumentViewport &viewport, DocumentObserver *e
|
|||
const int oldPageNumber = oldViewport.pageNumber;
|
||||
|
||||
// set internal viewport taking care of history
|
||||
if (oldViewport.pageNumber == viewport.pageNumber || !oldViewport.isValid()) {
|
||||
if (oldViewport.pageNumber == viewport.pageNumber || !oldViewport.isValid() || !updateHistory) {
|
||||
// if page is unchanged save the viewport at current position in queue
|
||||
oldViewport = viewport;
|
||||
} else {
|
||||
|
@ -3506,6 +3495,24 @@ void Document::setViewport(const DocumentViewport &viewport, DocumentObserver *e
|
|||
}
|
||||
}
|
||||
|
||||
void Document::setViewportPage(int page, DocumentObserver *excludeObserver, bool smoothMove)
|
||||
{
|
||||
// clamp page in range [0 ... numPages-1]
|
||||
if (page < 0)
|
||||
page = 0;
|
||||
else if (page > (int)d->m_pagesVector.count())
|
||||
page = d->m_pagesVector.count() - 1;
|
||||
|
||||
// make a viewport from the page and broadcast it
|
||||
setViewport(DocumentViewport(page), excludeObserver, smoothMove);
|
||||
}
|
||||
|
||||
void Document::setViewport(const DocumentViewport &viewport, DocumentObserver *excludeObserver, bool smoothMove)
|
||||
{
|
||||
// set viewport, updating history
|
||||
setViewportWithHistory(viewport, excludeObserver, smoothMove, true);
|
||||
}
|
||||
|
||||
void Document::setZoom(int factor, DocumentObserver *excludeObserver)
|
||||
{
|
||||
// notify change to all other (different from id) observers
|
||||
|
|
|
@ -431,6 +431,17 @@ public:
|
|||
*/
|
||||
void setViewport(const DocumentViewport &viewport, DocumentObserver *excludeObserver = nullptr, bool smoothMove = false);
|
||||
|
||||
/**
|
||||
* Sets the current document viewport to the given @p viewport.
|
||||
* BCI TODO: merge with setViewport, adding a parameter "bool updateHistory = true"
|
||||
*
|
||||
* @param viewport The document viewport.
|
||||
* @param excludeObserver The observer which shouldn't be effected by this change.
|
||||
* @param smoothMove Whether the move shall be animated smoothly.
|
||||
* @param updateHistory Whether to consider the change of viewport for the history navigation
|
||||
*/
|
||||
void setViewportWithHistory(const DocumentViewport &viewport, DocumentObserver *excludeObserver = nullptr, bool smoothMove = false, bool updateHistory = true);
|
||||
|
||||
/**
|
||||
* Sets the current document viewport to the next viewport in the
|
||||
* viewport history.
|
||||
|
|
|
@ -4360,7 +4360,7 @@ static void slotRequestPreloadPixmap(Okular::DocumentObserver *observer, const P
|
|||
void PageView::slotRequestVisiblePixmaps(int newValue)
|
||||
{
|
||||
// if requests are blocked (because raised by an unwanted event), exit
|
||||
if (d->blockPixmapsRequest || d->scroller->state() == QScroller::Scrolling)
|
||||
if (d->blockPixmapsRequest)
|
||||
return;
|
||||
|
||||
// precalc view limits for intersecting with page coords inside the loop
|
||||
|
@ -4503,7 +4503,8 @@ void PageView::slotRequestVisiblePixmaps(int newValue)
|
|||
newViewport.rePos.normalizedX = focusedX;
|
||||
newViewport.rePos.normalizedY = focusedY;
|
||||
// set the viewport to other observers
|
||||
d->document->setViewport(newViewport, this);
|
||||
// do not update history if the viewport is autoscrolling
|
||||
d->document->setViewportWithHistory(newViewport, this, false, d->scroller->state() == QScroller::Scrolling);
|
||||
}
|
||||
d->document->setVisiblePageRects(visibleRects, this);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue