Skip to content
Snippets Groups Projects
Commit a555ea21 authored by Jacob Wahlman's avatar Jacob Wahlman :ok_hand: Committed by Adam Jakobsson
Browse files

Resolve "Resize GUI Window"

parent a99172b8
No related branches found
No related tags found
2 merge requests!67WIP: B-ASIC version 1.0.0 hotfix,!65B-ASIC version 1.0.0
...@@ -26,6 +26,8 @@ class DragButton(QPushButton): ...@@ -26,6 +26,8 @@ class DragButton(QPushButton):
self.operation_path_name = operation_path_name self.operation_path_name = operation_path_name
self.clicked = 0 self.clicked = 0
self.pressed = False self.pressed = False
self._mouse_press_pos = None
self._mouse_move_pos = None
super(DragButton, self).__init__(self._window) super(DragButton, self).__init__(self._window)
def contextMenuEvent(self, event): def contextMenuEvent(self, event):
...@@ -35,20 +37,18 @@ class DragButton(QPushButton): ...@@ -35,20 +37,18 @@ class DragButton(QPushButton):
properties.triggered.connect(self.show_properties_window) properties.triggered.connect(self.show_properties_window)
menu.exec_(self.cursor().pos()) menu.exec_(self.cursor().pos())
def show_properties_window(self): def show_properties_window(self, event):
self.properties_window = PropertiesWindow(self, self.__window) self.properties_window = PropertiesWindow(self, self._window)
self.properties_window.show() self.properties_window.show()
def add_label(self, label): def add_label(self, label):
self.label = label self.label = label
def mousePressEvent(self, event): def mousePressEvent(self, event):
self._mouse_press_pos = None
self._mouse_move_pos = None
if event.button() == Qt.LeftButton: if event.button() == Qt.LeftButton:
self._mouse_press_pos = event.globalPos() self._mouse_press_pos = event.pos()
self._mouse_move_pos = event.globalPos() self._mouse_move_pos = event.pos()
for signal in self._window.signalList: for signal in self._window.signalList:
signal.update() signal.update()
...@@ -77,20 +77,14 @@ class DragButton(QPushButton): ...@@ -77,20 +77,14 @@ class DragButton(QPushButton):
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):
if event.buttons() == Qt.LeftButton: if event.buttons() == Qt.LeftButton:
cur_pos = self.mapToGlobal(self.pos()) self.move(self.mapToParent(event.pos() - self._mouse_press_pos))
global_pos = event.globalPos()
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._window.update() self._window.update()
super(DragButton, self).mouseMoveEvent(event) super(DragButton, self).mouseMoveEvent(event)
def mouseReleaseEvent(self, event): def mouseReleaseEvent(self, event):
if self._mouse_press_pos is not None: 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: if moved.manhattanLength() > 3:
event.ignore() event.ignore()
return return
......
...@@ -26,6 +26,10 @@ QGraphicsProxyWidget ...@@ -26,6 +26,10 @@ QGraphicsProxyWidget
from PyQt5.QtCore import Qt, QSize from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QIcon, QFont, QPainter, QPen, QBrush, QKeySequence from PyQt5.QtGui import QIcon, QFont, QPainter, QPen, QBrush, QKeySequence
MIN_WIDTH_SCENE = 600
MIN_HEIGHT_SCENE = 520
@decorate_class(handle_error) @decorate_class(handle_error)
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
def __init__(self): def __init__(self):
...@@ -68,19 +72,25 @@ class MainWindow(QMainWindow): ...@@ -68,19 +72,25 @@ class MainWindow(QMainWindow):
self.create_graphics_view() self.create_graphics_view()
def create_graphics_view(self): def create_graphics_view(self):
self.scene = QGraphicsScene() self.scene = QGraphicsScene(self)
self.graphic_view = QGraphicsView(self.scene, self) self.graphic_view = QGraphicsView(self.scene, self)
self.graphic_view.setRenderHint(QPainter.Antialiasing) self.graphic_view.setRenderHint(QPainter.Antialiasing)
self.graphic_view.setGeometry(250, 40, 600, 520) self.graphic_view.setGeometry(self.ui.operation_box.width(), 0, self.width(), self.height())
self.graphic_view.setDragMode(QGraphicsView.ScrollHandDrag) self.graphic_view.setDragMode(QGraphicsView.ScrollHandDrag)
def resizeEvent(self, event):
self.ui.operation_box.setGeometry(10, 10, self.ui.operation_box.width(), self.height())
self.graphic_view.setGeometry(self.ui.operation_box.width() + 20, 0, self.width() - self.ui.operation_box.width() - 20, self.height())
super(MainWindow, self).resizeEvent(event)
def wheelEvent(self, event): def wheelEvent(self, event):
old_zoom = self.zoom if event.modifiers() == Qt.ControlModifier:
self.zoom += event.angleDelta().y()/2500 old_zoom = self.zoom
self.graphic_view.scale(self.zoom, self.zoom) self.zoom += event.angleDelta().y()/2500
self.zoom = old_zoom self.graphic_view.scale(self.zoom, self.zoom)
self.zoom = old_zoom
def view_operation_names(self): def view_operation_names(self, event):
if self.check_show_names.isChecked(): if self.check_show_names.isChecked():
self.is_show_names = True self.is_show_names = True
else: else:
......
...@@ -20,7 +20,6 @@ class PortButton(QPushButton): ...@@ -20,7 +20,6 @@ class PortButton(QPushButton):
menu.exec_(self.cursor().pos()) menu.exec_(self.cursor().pos())
def mousePressEvent(self, event): def mousePressEvent(self, event):
if event.button() == Qt.LeftButton: if event.button() == Qt.LeftButton:
self.clicked += 1 self.clicked += 1
if self.clicked == 1: if self.clicked == 1:
...@@ -29,11 +28,11 @@ class PortButton(QPushButton): ...@@ -29,11 +28,11 @@ class PortButton(QPushButton):
self.window.pressed_ports.append(self) self.window.pressed_ports.append(self)
elif self.clicked == 2: elif self.clicked == 2:
self.setStyleSheet("background-color: white") self.setStyleSheet("background-color: white")
self.pressed = False self.pressed = False
self.clicked = 0 self.clicked = 0
self.window.pressed_ports.remove(self) self.window.pressed_ports.remove(self)
super(PortButton, self).mousePressEvent(event) super(PortButton, self).mousePressEvent(event)
def mouseReleaseEvent(self, event): def mouseReleaseEvent(self, event):
super(PortButton, self).mouseReleaseEvent(event) super(PortButton, self).mouseReleaseEvent(event)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment