From 1733040ea57cda24c72e1019c2c415d01355be61 Mon Sep 17 00:00:00 2001
From: Jacob Wahlman <jacwa448@student.liu.se>
Date: Mon, 4 May 2020 13:39:24 +0200
Subject: [PATCH] fixed lag when dragging

---
 b_asic/GUI/drag_button.py | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/b_asic/GUI/drag_button.py b/b_asic/GUI/drag_button.py
index 6d8b4ad7..7506caa6 100644
--- a/b_asic/GUI/drag_button.py
+++ b/b_asic/GUI/drag_button.py
@@ -28,8 +28,8 @@ class DragButton(QPushButton):
     def mousePressEvent(self, event):
 
         if event.button() == Qt.LeftButton:
-            self._mouse_press_pos = event.globalPos()
-            self._mouse_move_pos = event.globalPos()
+            self._mouse_press_pos = event.pos()
+            self._mouse_move_pos = event.pos()
 
             for signal in self._window.signalList:
                 signal.update()
@@ -58,23 +58,14 @@ class DragButton(QPushButton):
 
     def mouseMoveEvent(self, event):
         if event.buttons() == Qt.LeftButton:
-            cur_pos = self.mapToGlobal(self.pos())
-            global_pos = event.globalPos()
-            if self._mouse_move_pos is None:
-                self._mouse_move_pos = global_pos
-
-            diff = global_pos - self._mouse_move_pos
-            new_pos = self.mapFromGlobal(cur_pos + diff)
-            self.move(new_pos)
-
-            self._mouse_move_pos = global_pos
+            self.move(self.mapToParent(event.pos() - self._mouse_press_pos))
 
         self._window.update()
         super(DragButton, self).mouseMoveEvent(event)
 
     def mouseReleaseEvent(self, event):
         if self._mouse_press_pos is not None:
-            moved = event.globalPos() - self._mouse_press_pos
+            moved = event.pos() - self._mouse_press_pos
             if moved.manhattanLength() > 3:
                 event.ignore()
                 return
-- 
GitLab