From 530a2c5f1038d6ee280aaf99f47483a27ce7fbbd Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 11 Jun 2020 21:49:18 +0530 Subject: replace canvas from qwidget to qgraphicsview --- src/main/python/utils/canvas.py | 35 +++++++++++++++-------------------- src/main/python/utils/fileWindow.py | 2 ++ src/main/resources/base/app.qss | 3 +++ 3 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index f37d1f8..3c7ac67 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -1,7 +1,7 @@ from PyQt5.QtCore import Qt, QPointF from PyQt5.QtGui import QBrush, QPalette from PyQt5.QtWidgets import (QFileDialog, QApplication, QHBoxLayout, QMenu, - QTabWidget, QWidget, QSpacerItem, QStyle) + QTabWidget, QWidget, QSpacerItem, QStyle,) from . import dialogs from .graphics import customView, customScene @@ -10,14 +10,14 @@ from .app import shapeGrips, lines import shapes -class canvas(QWidget): +class canvas(customView): """ Defines the work area for a single sheet. Contains a QGraphicScene along with necessary properties for context menu and dialogs. """ def __init__(self, parent=None, size= 'A0', ppi= '72' , parentMdiArea = None, parentFileWindow = None, landscape=True): - super(canvas, self).__init__(parent) + super(canvas, self).__init__(parent=parent) #Store values for the canvas dimensions for ease of access, these are here just to be # manipulated by the setters and getters @@ -31,13 +31,13 @@ class canvas(QWidget): #set layout and background color self.painter = customScene() self.painter.setBackgroundBrush(QBrush(Qt.white)) #set white background + self.setScene = self.painter + # self = customView(self.painter, self) #create a viewport for the canvas board - self.view = customView(self.painter, self) #create a viewport for the canvas board - - self.layout = QHBoxLayout(self) #create the layout of the canvas, the canvas could just subclass QGView instead - self.layout.addWidget(self.view, alignment=Qt.AlignCenter) - self.layout.setContentsMargins(0, 0, 0, 0) - self.setLayout(self.layout) + # self.layout = QHBoxLayout(self) #create the layout of the canvas, the canvas could just subclass QGView instead + # self.layout.addWidget(self, alignment=Qt.AlignCenter) + # self.layout.setContentsMargins(0, 0, 0, 0) + # self.setLayout(self.layout) #set initial paper size for the scene self.painter.setSceneRect(0, 0, *paperSizes[self._canvasSize][self._ppi]) @@ -51,29 +51,24 @@ class canvas(QWidget): def adjustView(self): #utitily to adjust current diagram view width, height = self.dimensions - frameWidth = self.view.frameWidth() + frameWidth = self.frameWidth() #update view size - self.view.setSceneRect(0, 0, width - frameWidth*2, height) + self.setSceneRect(0, 0, width - frameWidth*2, height) # use the available mdi area, also add padding prect = self.parentMdiArea.rect() - width = width + 20 - height = height + 60 + width = width + height = height # add scrollbar size to width and height if they are visible, avoids clipping - if self.view.verticalScrollBar().isVisible(): + if self.verticalScrollBar().isVisible(): width += self.style().pixelMetric(QStyle.PM_ScrollBarExtent) - if self.view.horizontalScrollBar().isVisible(): + if self.horizontalScrollBar().isVisible(): height += self.style().pixelMetric(QStyle.PM_ScrollBarExtent) #if view is visible use half of available width - factor = 2 if self.parentFileWindow.sideViewTab is not None else 1 #use minimum width required to fit the view - width = min((prect.width() - 60)//factor, width) - height = min(prect.height() - 120, height) #set view dims - self.view.setFixedWidth(width) - self.view.setFixedHeight(height) def resizeEvent(self, event): #overloaded function to also view size on window update diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index 28a576e..01710fb 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -74,6 +74,7 @@ class fileWindow(QMdiSubWindow): def resizeHandler(self): # resize Handler to handle resize cases. parentRect = self.mdiArea().size() + print(parentRect) current = self.tabber.currentWidget() width, height = current.dimensions @@ -82,6 +83,7 @@ class fileWindow(QMdiSubWindow): width = parentRect.width() height = parentRect.height() self.moveSideViewCloseButton() + self.sideView.setSceneRect(0, 0, self.size().width()//2 - self.sideView.frameWidth(), self.size().height()//2) else: width = min(parentRect.width(), width + 100) diff --git a/src/main/resources/base/app.qss b/src/main/resources/base/app.qss index a733a50..1a4fc7e 100644 --- a/src/main/resources/base/app.qss +++ b/src/main/resources/base/app.qss @@ -256,3 +256,6 @@ customTabWidget::pane { padding: 1px; background-color: #E6E6E3; } +canvas{ + bottom: -20px; +} \ No newline at end of file -- cgit From ffff3aba43422ccb74ead3b288bbf1935f7e52ac Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 11 Jun 2020 21:53:05 +0530 Subject: restore scroll bars on side View --- src/main/python/utils/canvas.py | 21 --------------------- src/main/python/utils/fileWindow.py | 2 +- 2 files changed, 1 insertion(+), 22 deletions(-) (limited to 'src') diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index 3c7ac67..fd06fb7 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -32,12 +32,6 @@ class canvas(customView): self.painter = customScene() self.painter.setBackgroundBrush(QBrush(Qt.white)) #set white background self.setScene = self.painter - # self = customView(self.painter, self) #create a viewport for the canvas board - - # self.layout = QHBoxLayout(self) #create the layout of the canvas, the canvas could just subclass QGView instead - # self.layout.addWidget(self, alignment=Qt.AlignCenter) - # self.layout.setContentsMargins(0, 0, 0, 0) - # self.setLayout(self.layout) #set initial paper size for the scene self.painter.setSceneRect(0, 0, *paperSizes[self._canvasSize][self._ppi]) @@ -55,21 +49,6 @@ class canvas(customView): #update view size self.setSceneRect(0, 0, width - frameWidth*2, height) - # use the available mdi area, also add padding - prect = self.parentMdiArea.rect() - width = width - height = height - - # add scrollbar size to width and height if they are visible, avoids clipping - if self.verticalScrollBar().isVisible(): - width += self.style().pixelMetric(QStyle.PM_ScrollBarExtent) - if self.horizontalScrollBar().isVisible(): - height += self.style().pixelMetric(QStyle.PM_ScrollBarExtent) - - #if view is visible use half of available width - #use minimum width required to fit the view - #set view dims - def resizeEvent(self, event): #overloaded function to also view size on window update self.adjustView() diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index 01710fb..2ef68c6 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -83,7 +83,7 @@ class fileWindow(QMdiSubWindow): width = parentRect.width() height = parentRect.height() self.moveSideViewCloseButton() - self.sideView.setSceneRect(0, 0, self.size().width()//2 - self.sideView.frameWidth(), self.size().height()//2) + self.sideView.resize(self.size().width()//2 - self.sideView.frameWidth(), self.size().height()) else: width = min(parentRect.width(), width + 100) -- cgit From 6ac91c9a9fc3adc2ed23e396ab718cba3e21a188 Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 11 Jun 2020 22:46:00 +0530 Subject: side view fixed --- src/main/python/utils/canvas.py | 7 +++--- src/main/python/utils/fileWindow.py | 46 ++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index fd06fb7..674d27c 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -41,17 +41,18 @@ class canvas(customView): def resizeView(self, w, h): #helper function to resize canvas self.painter.setSceneRect(0, 0, w, h) - + def adjustView(self): #utitily to adjust current diagram view width, height = self.dimensions frameWidth = self.frameWidth() #update view size self.setSceneRect(0, 0, width - frameWidth*2, height) - + def resizeEvent(self, event): #overloaded function to also view size on window update - self.adjustView() + # self.adjustView() + pass def setCanvasSize(self, size): """ diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index 2ef68c6..6fee493 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -2,7 +2,7 @@ from PyQt5.QtCore import Qt, pyqtSignal, QPoint from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import (QFileDialog, QHBoxLayout, QMdiSubWindow, QMenu, QPushButton, QSizePolicy, - QSplitter, QWidget, QStyle) + QSplitter, QWidget, QStyle, QSizePolicy) from os import path from . import dialogs from .graphics import customView @@ -38,8 +38,17 @@ class fileWindow(QMdiSubWindow): self.mainWidget = QWidget(self) layout = QHBoxLayout(self.mainWidget) self.createSideViewArea() #create the side view objects + + left = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) + left.setHorizontalStretch(1) + self.tabber.setSizePolicy(left) + + right = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) + right.setHorizontalStretch(1) + self.sideView.setSizePolicy(right) + layout.addWidget(self.tabber) - layout.addWidget(self.splitter) + # layout.addWidget(self.splitter) layout.addWidget(self.sideView) self.mainWidget.setLayout(layout) self.setWidget(self.mainWidget) @@ -57,7 +66,7 @@ class fileWindow(QMdiSubWindow): def createSideViewArea(self): #creates the side view widgets and sets them to invisible - self.splitter = QSplitter(Qt.Vertical ,self) + # self.splitter = QSplitter(Qt.Vertical ,self) self.sideView = customView(parent = self) self.sideView.setInteractive(False) self.sideViewCloseButton = QPushButton('×', self.sideView) @@ -66,36 +75,26 @@ class fileWindow(QMdiSubWindow): self.sideViewCloseButton.setFixedSize(20, 20) self.moveSideViewCloseButton() self.sideViewCloseButton.clicked.connect(lambda: setattr(self, 'sideViewTab', None)) - self.splitter.setVisible(False) + # self.splitter.setVisible(False) self.sideView.setVisible(False) self.sideView.setContextMenuPolicy(Qt.CustomContextMenu) self.sideView.customContextMenuRequested.connect(self.sideViewContextMenu) + self.sideView.resize(self.width()//2 - self.sideView.frameWidth(), self.height()) def resizeHandler(self): # resize Handler to handle resize cases. parentRect = self.mdiArea().size() - print(parentRect) current = self.tabber.currentWidget() width, height = current.dimensions - - # if side view is visible, set width to maximum possible, else use minimum requirement - if self.sideViewTab: - width = parentRect.width() - height = parentRect.height() - self.moveSideViewCloseButton() - self.sideView.resize(self.size().width()//2 - self.sideView.frameWidth(), self.size().height()) - - else: - width = min(parentRect.width(), width + 100) - height = min(parentRect.height(), height + 200) + width = min(parentRect.width(), width + 100) + height = min(parentRect.height(), height + 150) if len(self.parent().parent().subWindowList()) > 1: height -= 20 - # set element dimensions + # set element dimensions self.setFixedSize(width, height) - self.tabber.resize(width, height) - self.tabber.currentWidget().adjustView() + current.adjustView() def contextMenu(self, point): #function to display the right click menu at point of right click @@ -120,16 +119,15 @@ class fileWindow(QMdiSubWindow): def sideViewToggle(self): #Function checks if current side view tab is set, and toggles view as required if self.sideViewTab: - self.splitter.setVisible(True) + # self.splitter.setVisible(True) self.sideView.setVisible(True) self.sideView.setScene(self.tabber.currentWidget().painter) - self.moveSideViewCloseButton() self.resizeHandler() return True else: - self.splitter.setVisible(False) - self.sideView.setVisible(False) - self.resizeHandler() + # self.splitter.setVisible(False) + self.sideView.setVisible(False) + self.resizeHandler() return False def moveSideViewCloseButton(self): -- cgit From 737961c33741348a79987efbad35cf78c8d3a613 Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 11 Jun 2020 22:47:40 +0530 Subject: fixed typo --- src/main/python/utils/canvas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index 674d27c..88e3c43 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -31,7 +31,7 @@ class canvas(customView): #set layout and background color self.painter = customScene() self.painter.setBackgroundBrush(QBrush(Qt.white)) #set white background - self.setScene = self.painter + self.setScene(self.painter) #set initial paper size for the scene self.painter.setSceneRect(0, 0, *paperSizes[self._canvasSize][self._ppi]) -- cgit From c0412bcf3853abeb6911c82aaf35125c25529277 Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 11 Jun 2020 22:53:36 +0530 Subject: fixed context menu --- src/main/python/shapes/shapes.py | 6 +++--- src/main/python/utils/canvas.py | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index e0263ab..6d06cba 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -525,10 +525,10 @@ class NodeItem(QGraphicsSvgItem): :return: """ contextMenu = QMenu() - addLableAction = contextMenu.addAction("add Label") - # addLableAction.triggered.connect(self.addLabel) + addLabelAction = contextMenu.addAction("add Label") + # addLabelAction.triggered.connect(self.addLabel) action = contextMenu.exec_(event.screenPos()) - if action == addLableAction: + if action == addLabelAction: self.label = ItemLabel(event.scenePos(), self) def __getstate__(self): diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index 88e3c43..480a2e1 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -37,7 +37,11 @@ class canvas(customView): self.painter.setSceneRect(0, 0, *paperSizes[self._canvasSize][self._ppi]) self.parentMdiArea = parentMdiArea self.parentFileWindow = parentFileWindow + self.customContextMenuRequested.connect(self.sideViewContextMenu) + def sideViewContextMenu(self, pos): + self.parentFileWindow.sideViewContextMenu(self.mapTo(self.parentFileWindow, pos)) + def resizeView(self, w, h): #helper function to resize canvas self.painter.setSceneRect(0, 0, w, h) -- cgit From b073940397bd4397636550a05fe8c4b9b6d9b156 Mon Sep 17 00:00:00 2001 From: Blaine Date: Fri, 12 Jun 2020 11:39:33 +0530 Subject: fix minor cases on sizing --- src/main/python/utils/fileWindow.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index 6fee493..6d35437 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -86,8 +86,14 @@ class fileWindow(QMdiSubWindow): parentRect = self.mdiArea().size() current = self.tabber.currentWidget() width, height = current.dimensions - width = min(parentRect.width(), width + 100) - height = min(parentRect.height(), height + 150) + + if self.sideViewTab: + width2, height2 = self.sideViewTab.dimensions + width = min(parentRect.width(), width + width2) + height = min(parentRect.height(), height + height2) + else: + width = min(parentRect.width(), width + 100) + height = min(parentRect.height(), height + 150) if len(self.parent().parent().subWindowList()) > 1: height -= 20 -- cgit From b6440473d81679a4329c5f2d08bc3e42e93ee7f8 Mon Sep 17 00:00:00 2001 From: Blaine Date: Fri, 12 Jun 2020 11:50:35 +0530 Subject: stylize view --- src/main/resources/base/app.qss | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/main/resources/base/app.qss b/src/main/resources/base/app.qss index 1a4fc7e..de53c26 100644 --- a/src/main/resources/base/app.qss +++ b/src/main/resources/base/app.qss @@ -258,4 +258,10 @@ customTabWidget::pane { } canvas{ bottom: -20px; +} + +customTabWidget customView { + border-width: 0px; + padding: 5px; + border-radius: 2px; } \ No newline at end of file -- cgit From d3bb58bc5d77b02d2102c6a59151cff6beee662f Mon Sep 17 00:00:00 2001 From: Blaine Date: Fri, 12 Jun 2020 12:36:23 +0530 Subject: change section Label color --- src/main/resources/base/app.qss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/resources/base/app.qss b/src/main/resources/base/app.qss index de53c26..e0b5140 100644 --- a/src/main/resources/base/app.qss +++ b/src/main/resources/base/app.qss @@ -211,7 +211,7 @@ QToolButton:checked { } sectionLabel{ - border-color: #BBD0E9; + border-color: #00B8B8; border-style: solid; border-width: 0px 0px 2px 0px; padding-bottom: 3px; -- cgit