From 5a170c4f7250bcc505cb875ab38637e25bcea4a1 Mon Sep 17 00:00:00 2001
From: Tao Zhong <taozhongimd@gmail.com>
Date: Mon, 7 Jan 2019 17:25:31 +0100
Subject: [PATCH] Add Zoom Windows

---
 forms/mainwindow.ui |  9 +++++++++
 src/GraphicView.cpp | 19 +++++++++++++++++++
 src/GraphicView.h   |  3 +++
 src/mainWindow.cpp  |  9 +++++++--
 src/mainWindow.h    |  1 +
 5 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui
index 91eed28..a51e0c1 100644
--- a/forms/mainwindow.ui
+++ b/forms/mainwindow.ui
@@ -71,6 +71,7 @@
     <addaction name="actionObjectsnap"/>
     <addaction name="separator"/>
     <addaction name="actionBack_to_Origin"/>
+    <addaction name="actionZoom_Windows"/>
    </widget>
    <widget class="QMenu" name="menuEdit">
     <property name="title">
@@ -721,6 +722,14 @@
     <string>Meta+O</string>
    </property>
   </action>
+  <action name="actionZoom_Windows">
+   <property name="text">
+    <string>Zoom Windows</string>
+   </property>
+   <property name="shortcut">
+    <string>Meta+W</string>
+   </property>
+  </action>
  </widget>
  <resources>
   <include location="../Resources/resources.qrc"/>
diff --git a/src/GraphicView.cpp b/src/GraphicView.cpp
index 86985c6..facce61 100644
--- a/src/GraphicView.cpp
+++ b/src/GraphicView.cpp
@@ -67,6 +67,7 @@ jpsGraphicsView::jpsGraphicsView(QWidget* parent, jpsDatamanager *datamanager):Q
     statDoor=false;
     statExit=false;
     _statHLine=false;
+    statzoomwindows=false;
     _statCopy=0;
     statLandmark=false;
     markedLandmark=nullptr;
@@ -520,6 +521,19 @@ void jpsGraphicsView::mouseReleaseEvent(QMouseEvent *event)
                     emit RegionDefCompleted();
                     _regionDef=false;
                 }
+                else if(statzoomwindows)
+                {
+                    this->fitInView(currentSelectRect->rect(),Qt::KeepAspectRatio);
+                    gl_scale_f=1/this->transform().m11();
+
+                    //translations
+                    QPointF old_pos;
+                    old_pos.setX(pos.x()+translation_x);
+                    old_pos.setY(pos.y()+translation_y);
+                    translations(old_pos);
+
+                    statzoomwindows=false;
+                }
                 else
                 {
                     // Select lines by creating a rect with the cursor
@@ -1994,3 +2008,8 @@ void jpsGraphicsView::ScaleLines(const double &factor)
     }
 
 }
+
+void jpsGraphicsView::selectedWindows()
+{
+    statzoomwindows=true;
+}
diff --git a/src/GraphicView.h b/src/GraphicView.h
index 71217a8..40419ac 100644
--- a/src/GraphicView.h
+++ b/src/GraphicView.h
@@ -96,6 +96,7 @@ public:
     void AutoZoom();
     qreal CalcGridSize();
     void ShowOrigin();
+    void selectedWindows();
 
 
     //Catch lines, points and intersections
@@ -243,6 +244,8 @@ private:
     ActionStack _undoStack;
     ActionStack _redoStack;
 
+    //View
+    bool statzoomwindows;
 
 signals:
     void mouse_moved();
diff --git a/src/mainWindow.cpp b/src/mainWindow.cpp
index fe87b01..3a76dd9 100644
--- a/src/mainWindow.cpp
+++ b/src/mainWindow.cpp
@@ -145,7 +145,6 @@ MWindow :: MWindow() {
     connect(actionDoor,SIGNAL(triggered(bool)),this,SLOT(dis_selectMode()));
     connect(actionExit,SIGNAL(triggered(bool)),this,SLOT(dis_selectMode()));
     connect(actionScale,SIGNAL(triggered(bool)),this,SLOT(enableScale()));
-
     // Tab View
     connect(actionRotate_90_deg_clockwise,SIGNAL(triggered(bool)),this,SLOT(rotate()));
     connect(actionShow_Point_of_Origin,SIGNAL(triggered(bool)),this,SLOT(ShowOrigin()));
@@ -837,5 +836,11 @@ void MWindow::on_actionNew_Inifile_triggered()
 
 void MWindow::on_actionBack_to_Origin_triggered()
 {
-    mview->centerOn(0,0);
+    mview->centerOn(QPoint(0,0)); //TODO: Ensure in any situation
+}
+
+void MWindow::on_actionZoom_Windows_triggered()
+{
+    en_selectMode();
+    mview->selectedWindows();
 }
diff --git a/src/mainWindow.h b/src/mainWindow.h
index a9272a8..0e04208 100644
--- a/src/mainWindow.h
+++ b/src/mainWindow.h
@@ -168,6 +168,7 @@ private slots:
     QMap<QString, QString> loadSettings();
     void on_actionNew_Inifile_triggered();
     void on_actionBack_to_Origin_triggered();
+    void on_actionZoom_Windows_triggered();
 };
 
 #endif // MAINWINDOW_H
-- 
GitLab