Skip to content

fix: small scene shifts when switching pages#1220

Merged
kaamui merged 2 commits intoOpenBoard-org:devfrom
letsfindaway:fix-scene-shift
Feb 12, 2025
Merged

fix: small scene shifts when switching pages#1220
kaamui merged 2 commits intoOpenBoard-org:devfrom
letsfindaway:fix-scene-shift

Conversation

@letsfindaway
Copy link
Copy Markdown
Collaborator

@letsfindaway letsfindaway commented Feb 5, 2025

This PR fixes the small shift of scenes when switching pages initially reported in #1009. Even if the effects of this problem depend on the Qt version use, it is an unclean procedure in the OpenBoard code that causes this.

There are two methods to move the visible region of a QGraphicsView:

  • We can change the value of the horizontal and vertical scroll bar. These values are integers, so we can only move by pixels.
  • Or we can change the transformation matrix of the view. This is the transformation from scene coordinates to view coordinates and everything is floating point here.

OpenBoard uses both, and that is not a good idea:

  • When using the Hand tool, only the transform is changed.
  • When using the zoom, transform and scrollbar values are changed.
  • When using the mouse wheel, only the scrollbar values are changed.
  • When switching pages, the viewport center is saved and a combination of centerOn() (changing scrollbar values) and translate() (changing transformation) is used to restore it.

Even with this PR scrollbar values and transformations are used, but they are clearly separated. A first idea of using transformations only was skipped, because the scroll area of the QGraphicsView cannot be guaranteed to never scroll. E.g. the mouse wheel produces an event, which is processed by the scroll area and affects the scrollbar values.

To remember the position and zoom factor of a scene, a SceneViewState is used which already provides the necessary information. It was however not consistently used.

Here is a list of tests I have successfully performed with the updated code:

  • Switch pages with prev/next
  • Switch pages with first/last
  • Switch pages with thumbnails
  • Switch pages using Document mode
  • Switch zoomed page
  • Switch page moved by hand tool
  • Switch page scrolled by wheel
  • Clear page
  • Double-click and long-click with hand
  • perform all tests with second display
  • Perform all tests with Qt5 and Qt6

Technical details of the changes:

  • visible scene area is affected by scene transformation and the view scrollbar values
  • clearly separate changes to those two
  • save and restore both using the SceneViewState
  • UBBoardController:
    • always use centerRestore when re-centering a scene
    • UBBoardController::centerOn only affect transformation
    • fix keeping the scene point when zooming
    • save scrollbars and transform in persistViewPositionOnCurrentScene
    • add a restoreViewPositionOnCurrentScene
    • save and restore view position in setActiveDocumentScene
    • remove redundant saveViewState
  • UBGraphicsScene:
    • remove no longer used lastCenter and setLastCenter
    • remove associated no longer used SceneViewState functions

@kaamui
Copy link
Copy Markdown
Member

kaamui commented Feb 11, 2025

Hi @letsfindaway,

could you please rebase this PR to the current state of the dev branch please ?

Thank you

- visible scene area is affected by scene transformation and
  the view scrollbar values
- clearly separate changes to those two
- save and restore both using the SceneViewState
- UBBoardController:
  - always use centerRestore when re-centering a scene
  - UBBoardController::centerOn only affect transformation
  - fix keeping the scene point when zooming
  - save scrollbars and transform in persistViewPositionOnCurrentScene
  - add a restoreViewPositionOnCurrentScene
  - save and restore view position in setActiveDocumentScene
  - remove redundant saveViewState
- UBGraphicsScene:
  - remove no longer used lastCenter and setLastCenter
  - remove associated no longer used SceneViewState functions
- remove unnecessary includes in UBBoardController
- make getter functions const in  UBBoardController
- re-add and improve workaround for foreground not repainted
  after scrolling on Qt5
- use transform instead of viewportTransform when retrieving
  scaling factor (same result on both, but cleaner and faster)
- add comment explaining calculations in UBBoardController::zoom
- widen nullptr guard in UBBoardController::updateSystemScaleFactor
- remove duplicate definition of UBBoardController::activeScene
- improve initialization in UBGraphicsScene::SceneViewState
@letsfindaway
Copy link
Copy Markdown
Collaborator Author

Hi @letsfindaway,

could you please rebase this PR to the current state of the dev branch please ?

Thank you

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants