Save and restore transformation for each scene.

--HG--
branch : develop
This commit is contained in:
dismine 2014-01-11 16:09:44 +02:00
parent e5247cf323
commit 4b2db9a95d
4 changed files with 47 additions and 22 deletions

View File

@ -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);

View File

@ -537,6 +537,8 @@ private:
* @param enable
*/
void SetEnableTool(bool enable);
void SaveCurrentScene();
void RestoreCurrentScene();
/**
*
*/

View File

@ -31,10 +31,10 @@
#include <QtWidgets>
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);

View File

@ -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