persist view position on each scene of a document (only during session)

preferencesAboutTextFull
Clément Fauconnier 7 years ago
parent 34b9365928
commit 773dab5cf7
  1. 22
      src/board/UBBoardController.cpp
  2. 1
      src/board/UBBoardController.h
  3. 5
      src/core/UBApplicationController.cpp
  4. 10
      src/domain/UBGraphicsScene.cpp
  5. 19
      src/domain/UBGraphicsScene.h
  6. 2
      src/gui/UBBoardThumbnailsView.cpp

@ -503,6 +503,7 @@ void UBBoardController::stylusToolDoubleClicked(int tool)
else if (tool == UBStylusTool::Hand)
{
centerRestore();
mActiveScene->setLastCenter(QPointF(0,0));
}
}
@ -511,6 +512,7 @@ void UBBoardController::stylusToolDoubleClicked(int tool)
void UBBoardController::addScene()
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
persistViewPositionOnCurrentScene();
persistCurrentScene(false,true);
UBDocumentContainer::addPage(mActiveSceneIndex + 1);
@ -790,6 +792,8 @@ void UBBoardController::clearScene()
{
freezeW3CWidgets(true);
mActiveScene->clearContent(UBGraphicsScene::clearItemsAndAnnotations);
mActiveScene->setLastCenter(QPointF(0,0));
mControlView->centerOn(mActiveScene->lastCenter());
updateActionStates();
}
}
@ -959,14 +963,23 @@ void UBBoardController::handScroll(qreal dx, qreal dy)
emit controlViewportChanged();
}
void UBBoardController::persistViewPositionOnCurrentScene()
{
QRect rect = mControlView->rect();
QPoint center(rect.x() + rect.width() / 2, rect.y() + rect.height() / 2);
QPointF viewRelativeCenter = mControlView->mapToScene(center);
mActiveScene->setLastCenter(viewRelativeCenter);
}
void UBBoardController::previousScene()
{
if (mActiveSceneIndex > 0)
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
persistViewPositionOnCurrentScene();
persistCurrentScene();
setActiveDocumentScene(mActiveSceneIndex - 1);
mControlView->centerOn(mActiveScene->lastCenter());
QApplication::restoreOverrideCursor();
}
@ -979,8 +992,10 @@ void UBBoardController::nextScene()
if (mActiveSceneIndex < selectedDocument()->pageCount() - 1)
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
persistViewPositionOnCurrentScene();
persistCurrentScene();
setActiveDocumentScene(mActiveSceneIndex + 1);
mControlView->centerOn(mActiveScene->lastCenter());
QApplication::restoreOverrideCursor();
}
@ -993,8 +1008,10 @@ void UBBoardController::firstScene()
if (mActiveSceneIndex > 0)
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
persistViewPositionOnCurrentScene();
persistCurrentScene();
setActiveDocumentScene(0);
mControlView->centerOn(mActiveScene->lastCenter());
QApplication::restoreOverrideCursor();
}
@ -1007,8 +1024,10 @@ void UBBoardController::lastScene()
if (mActiveSceneIndex < selectedDocument()->pageCount() - 1)
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
persistViewPositionOnCurrentScene();
persistCurrentScene();
setActiveDocumentScene(selectedDocument()->pageCount() - 1);
mControlView->centerOn(mActiveScene->lastCenter());
QApplication::restoreOverrideCursor();
}
@ -2093,7 +2112,8 @@ void UBBoardController::saveViewState()
{
mActiveScene->setViewState(UBGraphicsScene::SceneViewState(currentZoom(),
mControlView->horizontalScrollBar()->value(),
mControlView->verticalScrollBar()->value()));
mControlView->verticalScrollBar()->value(),
mActiveScene->lastCenter()));
}
}

@ -159,6 +159,7 @@ class UBBoardController : public UBDocumentContainer
return mSystemScaleFactor;
}
qreal currentZoom();
void persistViewPositionOnCurrentScene();
void persistCurrentScene(bool isAnAutomaticBackup = false, bool forceImmediateSave = false);
void showNewVersionAvailable(bool automatic, const UBVersion &installedVersion, const UBSoftwareUpdate &softwareUpdate);
void setBoxing(QRect displayRect);

@ -233,15 +233,12 @@ void UBApplicationController::adjustDisplayView()
tr.scale(scaleFactor, scaleFactor);
QRect rect = mControlView->rect();
QPoint center(rect.x() + rect.width() / 2, rect.y() + rect.height() / 2);
QTransform recentTransform = mDisplayView->transform();
if (recentTransform != tr)
mDisplayView->setTransform(tr);
mDisplayView->centerOn(mControlView->mapToScene(center));
mDisplayView->centerOn(UBApplication::boardController->activeScene()->lastCenter());
}
}

@ -385,6 +385,16 @@ void UBGraphicsScene::selectionChangedProcessing()
}
}
void UBGraphicsScene::setLastCenter(QPointF center)
{
mViewState.setLastSceneCenter(center);
}
QPointF UBGraphicsScene::lastCenter()
{
return mViewState.lastSceneCenter();
}
bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pressure)
{
bool accepted = false;

@ -156,7 +156,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
UBGraphicsW3CWidgetItem* addW3CWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0));
void addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, const QPointF& pPos = QPointF(0, 0));
QPointF lastCenter();
void setLastCenter(QPointF center);
UBGraphicsMediaItem* addMedia(const QUrl& pMediaFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0));
UBGraphicsMediaItem* addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0));
@ -256,15 +257,29 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
zoomFactor = 1;
horizontalPosition = 0;
verticalPostition = 0;
mLastSceneCenter = QPointF();
}
SceneViewState(qreal pZoomFactor, int pHorizontalPosition, int pVerticalPostition)
SceneViewState(qreal pZoomFactor, int pHorizontalPosition, int pVerticalPostition, QPointF sceneCenter = QPointF())// 1595/1605
{
zoomFactor = pZoomFactor;
horizontalPosition = pHorizontalPosition;
verticalPostition = pVerticalPostition;
mLastSceneCenter = sceneCenter;
}
QPointF lastSceneCenter() // Save Scene Center to replace the view when the scene becomes active
{
return mLastSceneCenter;
}
void setLastSceneCenter(QPointF center)
{
mLastSceneCenter = center;
}
QPointF mLastSceneCenter;
qreal zoomFactor;
int horizontalPosition;
int verticalPostition;

@ -197,8 +197,10 @@ void UBBoardThumbnailsView::mousePressEvent(QMouseEvent *event)
if (item)
{
UBApplication::boardController->persistViewPositionOnCurrentScene();
UBApplication::boardController->persistCurrentScene();
UBApplication::boardController->setActiveDocumentScene(item->sceneIndex());
UBApplication::boardController->centerOn(UBApplication::boardController->activeScene()->lastCenter());
}
QGraphicsView::mousePressEvent(event);

Loading…
Cancel
Save