From c343b860d839829dc82e14b627afd015968838c6 Mon Sep 17 00:00:00 2001
From: Felix Goding <felgo673@student.liu.se>
Date: Wed, 29 Apr 2020 09:57:31 +0200
Subject: [PATCH] Add ability to zoom and move workspace by dragging it

---
 b_asic/GUI/improved_main_window.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/b_asic/GUI/improved_main_window.py b/b_asic/GUI/improved_main_window.py
index 5f81b8fc..2db960d6 100644
--- a/b_asic/GUI/improved_main_window.py
+++ b/b_asic/GUI/improved_main_window.py
@@ -32,7 +32,6 @@ class MainWindow(QMainWindow):
         self.setWindowIcon(QIcon('small_logo.png'))
         self.scene = None
         self.init_ui()
-
         self.add_counter = 0
         self.sub_counter = 0
         self.mul_counter = 0
@@ -48,11 +47,10 @@ class MainWindow(QMainWindow):
         self.input_counter = 0
         self.output_counter = 0
         self.reg_counter = 0
-        
+        self.zoom = 1
         self.operationList = []
         self.signalList = []
         self.pressed_button = []
-
         self.source = None
 
     def init_ui(self):
@@ -63,9 +61,16 @@ class MainWindow(QMainWindow):
 
     def create_graphics_view(self):
         self.scene = QGraphicsScene()
-        graphic_view = QGraphicsView(self.scene, self)
-        graphic_view.setRenderHint(QPainter.Antialiasing)
-        graphic_view.setGeometry(250, 40, 600, 520)
+        self.graphic_view = QGraphicsView(self.scene, self)
+        self.graphic_view.setRenderHint(QPainter.Antialiasing)
+        self.graphic_view.setGeometry(250, 40, 600, 520)
+        self.graphic_view.setDragMode(QGraphicsView.ScrollHandDrag)
+
+    def wheelEvent(self, event):
+        old_zoom = self.zoom
+        self.zoom += event.angleDelta().y()/2500
+        self.graphic_view.scale(self.zoom, self.zoom)
+        self.zoom = old_zoom
 
     def exit_app(self, checked):
         QApplication.quit()
@@ -120,7 +125,6 @@ class MainWindow(QMainWindow):
         self.scene.addWidget(self.addition_operation)
         self.operationList.append(self.addition_operation)
         self.addition_operation.connectionRequested.connect(self.connectButton)
-    
         self.operationList.append(self.addition_operation)
         self.add_ports(self.addition_operation)
 
-- 
GitLab