diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 86215350f..90224e3ad 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -87,6 +87,10 @@ MainWindow::MainWindow(QWidget *parent) view = new VMainGraphicsView(); ui->LayoutView->addWidget(view); view->setScene(currentScene); + + sceneDraw->setTransform(view->transform()); + sceneDetails->setTransform(view->transform()); + connect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding); policy.setHorizontalStretch(12); @@ -880,24 +884,38 @@ void MainWindow::keyPressEvent ( QKeyEvent * event ) QMainWindow::keyPressEvent ( event ); } +void MainWindow::SaveCurrentScene() +{ + /*Save transform*/ + currentScene->setTransform(view->transform()); + /*Save scroll bars value for previous scene.*/ + QScrollBar *horScrollBar = view->horizontalScrollBar(); + currentScene->setHorScrollBar(horScrollBar->value()); + QScrollBar *verScrollBar = view->verticalScrollBar(); + currentScene->setVerScrollBar(verScrollBar->value()); +} + +void MainWindow::RestoreCurrentScene() +{ + /*Set transform for current scene*/ + view->setTransform(currentScene->transform()); + /*Set value for current scene scroll bar.*/ + QScrollBar *horScrollBar = view->horizontalScrollBar(); + horScrollBar->setValue(currentScene->getHorScrollBar()); + QScrollBar *verScrollBar = view->verticalScrollBar(); + verScrollBar->setValue(currentScene->getVerScrollBar()); +} + void MainWindow::ActionDraw(bool checked) { if (checked) { ui->actionDetails->setChecked(false); - /*Save scroll bars value for previous scene.*/ - QScrollBar *horScrollBar = view->horizontalScrollBar(); - currentScene->setHorScrollBar(horScrollBar->value()); - QScrollBar *verScrollBar = view->verticalScrollBar(); - currentScene->setVerScrollBar(verScrollBar->value()); + SaveCurrentScene(); currentScene = sceneDraw; view->setScene(currentScene); - /*Set value for current scene scroll bar.*/ - horScrollBar = view->horizontalScrollBar(); - horScrollBar->setValue(currentScene->getHorScrollBar()); - verScrollBar = view->verticalScrollBar(); - verScrollBar->setValue(currentScene->getVerScrollBar()); + RestoreCurrentScene(); mode = Draw::Calculation; comboBoxDraws->setEnabled(true); @@ -918,19 +936,11 @@ void MainWindow::ActionDetails(bool checked) if (checked) { ui->actionDraw->setChecked(false); - /*Save scroll bars value for previous scene.*/ - QScrollBar *horScrollBar = view->horizontalScrollBar(); - currentScene->setHorScrollBar(horScrollBar->value()); - QScrollBar *verScrollBar = view->verticalScrollBar(); - currentScene->setVerScrollBar(verScrollBar->value()); + SaveCurrentScene(); currentScene = sceneDetails; view->setScene(sceneDetails); - /*Set value for current scene scroll bar.*/ - horScrollBar = view->horizontalScrollBar(); - horScrollBar->setValue(currentScene->getHorScrollBar()); - verScrollBar = view->verticalScrollBar(); - verScrollBar->setValue(currentScene->getVerScrollBar()); + RestoreCurrentScene(); currentDrawIndex = comboBoxDraws->currentIndex();//save current pattern peace comboBoxDraws->setCurrentIndex(comboBoxDraws->count()-1); diff --git a/src/mainwindow.h b/src/mainwindow.h index 875f1097c..04f775398 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -537,6 +537,8 @@ private: * @param enable */ void SetEnableTool(bool enable); + void SaveCurrentScene(); + void RestoreCurrentScene(); /** * */ diff --git a/src/widgets/vmaingraphicsscene.cpp b/src/widgets/vmaingraphicsscene.cpp index 95c1a41b2..9bb9d9abd 100644 --- a/src/widgets/vmaingraphicsscene.cpp +++ b/src/widgets/vmaingraphicsscene.cpp @@ -31,10 +31,10 @@ #include VMainGraphicsScene::VMainGraphicsScene() - :QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1){} + :QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()){} VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent) - :QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1){} + :QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()){} void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { @@ -48,6 +48,16 @@ void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event) QGraphicsScene::mousePressEvent(event); } +QTransform VMainGraphicsScene::transform() const +{ + return _transform; +} + +void VMainGraphicsScene::setTransform(const QTransform &transform) +{ + _transform = transform; +} + void VMainGraphicsScene::ChoosedItem(qint64 id, const Scene::Scenes &type) { emit ChoosedObject(id, type); diff --git a/src/widgets/vmaingraphicsscene.h b/src/widgets/vmaingraphicsscene.h index cee01c006..c0574caf9 100644 --- a/src/widgets/vmaingraphicsscene.h +++ b/src/widgets/vmaingraphicsscene.h @@ -69,6 +69,8 @@ public: * @param value */ inline void setVerScrollBar(const qint32 &value) {verScrollBar = value;} + QTransform transform() const; + void setTransform(const QTransform &transform); public slots: /** * @brief ChoosedItem @@ -127,6 +129,7 @@ private: * @brief scaleFactor */ qreal scaleFactor; + QTransform _transform; }; #endif // VMAINGRAPHICSSCENE_H