diff options
author | Blaine | 2020-05-01 14:30:08 +0530 |
---|---|---|
committer | Blaine | 2020-05-01 14:30:08 +0530 |
commit | 0f9e183d9f174888dd4c15922e5a038a6467afc2 (patch) | |
tree | e04aa12a5e1604de49fa6ec83a895be784f7300c /src | |
parent | 3a5155d2ec9455ba474fc1f4d55f65f02dfd54f6 (diff) | |
download | Chemical-PFD-0f9e183d9f174888dd4c15922e5a038a6467afc2.tar.gz Chemical-PFD-0f9e183d9f174888dd4c15922e5a038a6467afc2.tar.bz2 Chemical-PFD-0f9e183d9f174888dd4c15922e5a038a6467afc2.zip |
implement side view widget
Diffstat (limited to 'src')
-rw-r--r-- | src/main/python/main.py | 2 | ||||
-rw-r--r-- | src/main/python/utils/canvas.py | 16 | ||||
-rw-r--r-- | src/main/python/utils/fileWindow.py | 89 |
3 files changed, 69 insertions, 38 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py index 5971403..abdb822 100644 --- a/src/main/python/main.py +++ b/src/main/python/main.py @@ -55,7 +55,7 @@ class appWindow(QMainWindow): self.mainWidget.setLayout(mainLayout) self.setCentralWidget(self.mainWidget) self.resize(1280, 720) #set collapse dim - self.setWindowState(Qt.WindowMaximized) #launch maximized + # self.setWindowState(Qt.WindowMaximized) #launch maximized def createToolbar(self): #place holder for toolbar with fixed width, layout may change diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index 2c99ff2..418a95e 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -33,13 +33,16 @@ class canvas(QWidget): 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) - #set layout and background color self.setLayout(self.layout) + #set layout and background color self.painter.setSceneRect(0, 0, *paperSizes[self.canvasSize][self.ppi]) # ensure that the scene is always aligned on the left, instead of being # centered (the default) # self.view.setAlignment(Qt.AlignLeft|Qt.AlignTop) + + self.parentMdiArea = self.parent().parentWidget().parentWidget().parentWidget().parentWidget() + self.parentFileWindow = self.parent().parentWidget().parentWidget() def resizeView(self, w, h): #helper function to resize canvas @@ -54,7 +57,8 @@ class canvas(QWidget): self.view.setSceneRect(0, 0, width - frameWidth*2, height) # give the view some time to adjust itself - prect = self.parent().parentWidget().parentWidget().parentWidget().rect() + prect = self.parentMdiArea.rect() + # prect = self.parent().parent().size() width = width + 20 height = height + 60 @@ -62,8 +66,12 @@ class canvas(QWidget): width += self.style().pixelMetric(QStyle.PM_ScrollBarExtent) if self.view.horizontalScrollBar().isVisible(): height += self.style().pixelMetric(QStyle.PM_ScrollBarExtent) - self.view.setFixedWidth(min(prect.width() - 20, width)) - self.view.setFixedHeight(min(prect.height() - 60, height)) + + # factor = 2 if self.parentFileWindow.sideViewTab is not None else 1 + width = min(prect.width() - 20, width) # // factor + height = min(prect.height() - 60, height) # // factor + self.view.setFixedWidth(width) + self.view.setFixedHeight(height) # self.resize(width + frameWidth * 2, height + frameWidth * 2) def resizeEvent(self, event): diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index ae5ff85..6b3c754 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -1,7 +1,7 @@ import pickle from PyQt5.QtCore import Qt, pyqtSignal -from PyQt5.QtWidgets import QMdiSubWindow, QFileDialog, QMenu, QSizePolicy +from PyQt5.QtWidgets import QMdiSubWindow, QFileDialog, QMenu, QSizePolicy, QWidget, QHBoxLayout, QSplitter, QGraphicsView from . import dialogs from .canvas import canvas @@ -16,9 +16,10 @@ class fileWindow(QMdiSubWindow): fileMinimized = pyqtSignal(QMdiSubWindow) def __init__(self, parent = None, title = 'New Project', size = 'A4', ppi = '72'): super(fileWindow, self).__init__(parent) - + self._sideViewTab = None + self.index = None + self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) - self.index = None #Uses a custom QTabWidget that houses a custom new Tab Button, used to house the seperate # diagrams inside a file self.tabber = customTabWidget(self) @@ -26,22 +27,29 @@ class fileWindow(QMdiSubWindow): self.tabber.tabCloseRequested.connect(self.closeTab) # Show save alert on tab close self.tabber.currentChanged.connect(self.changeTab) # placeholder just to detect tab change self.tabber.plusClicked.connect(self.newDiagram) #connect the new tab button to add a new tab - # self.tabber.setContentsMargins(0, 1, 1, 1) + #assign layout to widget - self.setWidget(self.tabber) + self.mainWidget = QWidget(self) + layout = QHBoxLayout(self.mainWidget) + layout.addWidget(self.tabber) + self.splitter = QSplitter(Qt.Vertical ,self) + layout.addWidget(self.splitter) + self.sideView = QGraphicsView(self) + layout.addWidget(self.sideView) + + self.mainWidget.setLayout(layout) + self.setWidget(self.mainWidget) self.setWindowTitle(title) #This is done so that a right click menu is shown on right click self.setContextMenuPolicy(Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.contextMenu) - # self.windowStateChanged.connect(self.stateChange) - self.setAttribute(Qt.WA_DeleteOnClose, True) self.setWindowFlag(Qt.CustomizeWindowHint, True) self.setWindowFlag(Qt.WindowMinimizeButtonHint, False) self.setWindowFlag(Qt.WindowMaximizeButtonHint, False) - + def changeTab(self, currentIndex): #placeholder function to detect tab change self.resizeHandler() @@ -64,20 +72,18 @@ 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 + 200) + if self.sideViewTab: + width = parentRect.width() + height = parentRect.height() + else: + width = min(parentRect.width(), width + 100) + height = min(parentRect.height(), height + 200) # width = parentRect.width() # height = parentRect.height() self.setFixedSize(width, height) self.tabber.resize(width, height) self.tabber.currentWidget().adjustView() - - def contextMenu(self, point): - #function to display the right click menu at point of right click - menu = QMenu("Context Menu", self) - menu.addAction("Adjust Canvas", self.adjustCanvasDialog) - menu.exec_(self.mapToGlobal(point)) - + def adjustCanvasDialog(self): #helper function to the context menu dialog box currentTab = self.tabber.currentWidget() @@ -88,21 +94,38 @@ class fileWindow(QMdiSubWindow): else: return None - # def stateChange(self, oldState, newState): - # if newState == Qt.WindowMinimized: - # print("a") - # self.setVisible(False) - # elif newState == Qt.WindowMaximized: - # print("b") - # parentRect = self.mdiArea().size() - # self.setFixedSize(parentRect.width(), parentRect.height()) - # self.tabber.resize(parentRect.width(), parentRect.height()) - # self.tabber.currentWidget().adjustView() - # else: - # if oldState == Qt.WindowMinimized or oldState == Qt.WindowMaximized: - # print("c") - # self.resizeHandler() - + def contextMenu(self, point): + #function to display the right click menu at point of right click + menu = QMenu("Context Menu", self) + menu.addAction("Adjust Canvas", self.adjustCanvasDialog) + menu.addAction("View Side-By-Side", self.sideViewMode) + menu.exec_(self.mapToGlobal(point)) + + def sideViewMode(self): + self.sideViewTab = self.tabber.currentWidget() + + def sideViewToggle(self): + if self.sideViewTab: + self.splitter.setVisible(True) + self.sideView.setVisible(True) + self.sideView.setScene(self.tabber.currentWidget().painter) + self.resizeHandler() + return True + else: + self.splitter.setVisible(False) + self.sideView.setVisible(False) + self.resizeHandler() + return False + + @property + def sideViewTab(self): + return self._sideViewTab + + @sideViewTab.setter + def sideViewTab(self, tab): + self._sideViewTab = None if tab == self.sideViewTab else tab + return self.sideViewToggle() + @property def tabList(self): #returns a list of tabs in the given window @@ -146,6 +169,6 @@ class fileWindow(QMdiSubWindow): def __setstate__(self, dict): self.__init__(title = dict['ObjectName']) for i in dict['tabs']: - diagram = canvas(self.tabber, size = dict['canvasSize'], ppi = dict['ppi']) + diagram = canvas(self.tabber, size = dict['canvasSize'], ppi = dict['ppi'], fileWindow = self) diagram.__setstate__(i) self.tabber.addTab(diagram, i['ObjectName']) |