diff options
author | Blaine | 2020-06-10 19:54:37 +0530 |
---|---|---|
committer | Blaine | 2020-06-10 19:54:37 +0530 |
commit | a8f63cfd34be8c42917f560db8d0f37598fb47c6 (patch) | |
tree | 037a5af5abbaab914ef7967c807be85cb692eea6 /src | |
parent | 45d43b577803f2907fdc099d34bc21d9b7b9653c (diff) | |
download | Chemical-PFD-a8f63cfd34be8c42917f560db8d0f37598fb47c6.tar.gz Chemical-PFD-a8f63cfd34be8c42917f560db8d0f37598fb47c6.tar.bz2 Chemical-PFD-a8f63cfd34be8c42917f560db8d0f37598fb47c6.zip |
landscape mode
Diffstat (limited to 'src')
-rw-r--r-- | src/main/python/utils/canvas.py | 24 | ||||
-rw-r--r-- | src/main/python/utils/dialogs.py | 19 | ||||
-rw-r--r-- | src/main/python/utils/fileWindow.py | 2 | ||||
-rw-r--r-- | src/main/python/utils/toolbar.py | 9 | ||||
-rw-r--r-- | src/main/python/utils/undo.py | 6 |
5 files changed, 43 insertions, 17 deletions
diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index 3f9cee5..66d38e8 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -16,13 +16,14 @@ class canvas(QWidget): for context menu and dialogs. """ - def __init__(self, parent=None, size= 'A4', ppi= '72' , parentMdiArea = None, parentFileWindow = None): + def __init__(self, parent=None, size= 'A4', ppi= '72' , parentMdiArea = None, parentFileWindow = None, landscape=False): super(canvas, self).__init__(parent) #Store values for the canvas dimensions for ease of access, these are here just to be # manipulated by the setters and getters self._ppi = ppi self._canvasSize = size + self._landscape = landscape # self.setFixedSize(parent.size()) #Create area for the graphic items to be placed, this is just here right now for the future # when we will draw items on this, this might be changed if QGraphicScene is subclassed. @@ -104,22 +105,33 @@ class canvas(QWidget): @property def canvasSize(self): return self._canvasSize + @property def ppi(self): return self._ppi + @property + def landscape(self): + return self._landscape + @canvasSize.setter def canvasSize(self, size): self._canvasSize = size if self.painter: - self.resizeView(*paperSizes[self.canvasSize][self.ppi]) + self.resizeView(*(sorted(paperSizes[self.canvasSize][self.ppi], reverse = self.landscape))) @ppi.setter def ppi(self, ppi): self._ppi = ppi if self.painter: - self.resizeView(*paperSizes[self.canvasSize][self.ppi]) - + self.resizeView(*(sorted(paperSizes[self.canvasSize][self.ppi], reverse = self.landscape))) + + @landscape.setter + def landscape(self, bool): + self._landscape = bool + if self.painter: + self.resizeView(*(sorted(paperSizes[self.canvasSize][self.ppi], reverse = self.landscape))) + #following 2 methods are defined for correct pickling of the scene. may be changed to json or xml later so as # to not have a binary file. def __getstate__(self) -> dict: @@ -129,12 +141,14 @@ class canvas(QWidget): "canvasSize": self._canvasSize, "ObjectName": self.objectName(), "symbols": [i for i in self.painter.items() if isinstance(i, shapes.NodeItem)], - "lines": sorted([i for i in self.painter.items() if isinstance(i, shapes.Line)], key = lambda x: 1 if x.refLine else 0) + "lines": sorted([i for i in self.painter.items() if isinstance(i, shapes.Line)], key = lambda x: 1 if x.refLine else 0), + "landscape": self.landscape } def __setstate__(self, dict): self._ppi = dict['ppi'] self._canvasSize = dict['canvasSize'] + self.landscape = dict['landscape'] self.setObjectName(dict['ObjectName']) for item in dict['symbols']: diff --git a/src/main/python/utils/dialogs.py b/src/main/python/utils/dialogs.py index fa3b5f1..79685c5 100644 --- a/src/main/python/utils/dialogs.py +++ b/src/main/python/utils/dialogs.py @@ -1,12 +1,16 @@ -from PyQt5.QtWidgets import QDialog, QPushButton, QFormLayout, QComboBox, QLabel, QMessageBox, QDialogButtonBox, QHBoxLayout -from .data import sheetDimensionList, ppiList +from PyQt5.QtWidgets import (QCheckBox, QComboBox, QDialog, QDialogButtonBox, + QFormLayout, QHBoxLayout, QLabel, QMessageBox, + QPushButton) + +from .data import ppiList, sheetDimensionList + class paperDims(QDialog): """ Utility dialog box to adjust the current canvas's dimensions, might return just dimensions later so that sizes do not need to be imported in every other module. """ - def __init__(self, parent=None, size='A4', ppi='72', name='Canvas Size'): + def __init__(self, parent=None, size='A4', ppi='72', name='Canvas Size', landscape=False): super(paperDims, self).__init__(parent) #store initial values to show currently set value, also updated when changed. these are returned at EOL @@ -36,6 +40,10 @@ class paperDims(QDialog): dialogBoxLayout.setWidget(1, QFormLayout.LabelRole, ppiLabel) dialogBoxLayout.setWidget(1, QFormLayout.FieldRole, ppiComboBox) + self.landscapeCheckBox = QCheckBox('&Landscape Mode') + self.landscapeCheckBox.setChecked(landscape) + dialogBoxLayout.setWidget(2, QFormLayout.SpanningRole, self.landscapeCheckBox) + # add ok and cancel buttons buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self) buttonBox.accepted.connect(self.accept) @@ -50,7 +58,8 @@ class paperDims(QDialog): super(paperDims, self).exec_() self.deleteLater() #remove from memory #if ok was pressed return value else return None - return (self.returnCanvasSize, self.returnCanvasPPI) if self.result() else None + print(self.landscapeCheckBox.isChecked()) + return (self.returnCanvasSize, self.returnCanvasPPI, self.landscapeCheckBox.isChecked()) if self.result() else None class sideViewSwitchDialog(QDialog): """ @@ -107,4 +116,4 @@ def showUndoDialog(undoView, parent): layout = QHBoxLayout(dialogBox) layout.addWidget(undoView) dialogBox.setWindowTitle("Undo Stack") - dialogBox.show()
\ No newline at end of file + dialogBox.show() diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index 663a7f3..e0f5652 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -123,7 +123,7 @@ class fileWindow(QMdiSubWindow): def adjustCanvasDialog(self): #helper context menu function to the context menu dialog box currentTab = self.tabber.currentWidget() - result = dialogs.paperDims(self, currentTab._canvasSize, currentTab._ppi, currentTab.objectName()).exec_() + result = dialogs.paperDims(self, currentTab._canvasSize, currentTab._ppi, currentTab.objectName(), currentTab.landscape).exec_() if result is not None: currentTab.painter.undoStack.push(resizeCommand(result, currentTab, self)) diff --git a/src/main/python/utils/toolbar.py b/src/main/python/utils/toolbar.py index 39b251a..ffb0896 100644 --- a/src/main/python/utils/toolbar.py +++ b/src/main/python/utils/toolbar.py @@ -82,14 +82,17 @@ class toolbar(QDockWidget): self.layout.setDirection(QBoxLayout.TopToBottom) # here so that a horizontal toolbar can be implemented later # self.setFixedHeight(self.height()) #span available height width = self.width() - QApplication.style().pixelMetric(QStyle.PM_ScrollBarExtent) - for _, label in self.toolbarLabelDict.items(): - label.setFixedWidth(self.width()) + # the following line, sets the required height for the current width, so that blank space doesnt occur self.diagAreaWidget.setMinimumHeight(self.diagAreaLayout.heightForWidth(width)) self.setMinimumWidth(.17*parent.width()) #12% of parent width # self.setMinimumWidth(self.diagAreaLayout.minimumSize().width()) #12% of parent width self.diagAreaWidget.setLayout(self.diagAreaLayout) self.diagArea.setWidget(self.diagAreaWidget) + + for _, label in self.toolbarLabelDict.items(): + label.setFixedSize(width, 20) + def toolbarItems(self, itemClasses): #helper functions to create required buttons @@ -161,7 +164,7 @@ class sectionLabel(QLabel): self.setStyleSheet(""" QLabel{ background-color: #E6E6E3; - border: 1px solid black; + border: 2px solid gray; border-left: 0px; background-clip: padding; } diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py index b060550..8426494 100644 --- a/src/main/python/utils/undo.py +++ b/src/main/python/utils/undo.py @@ -95,15 +95,15 @@ class resizeCommand(QUndoCommand): def __init__(self, new, canvas, widget, parent = None): super(resizeCommand, self).__init__(parent) self.parent = canvas - self.old = self.parent.canvasSize, self.parent.ppi + self.old = self.parent.canvasSize, self.parent.ppi, self.parent.landscape self.new = new self.widget = widget self.setText(f'Change canvas dimensions to {new[0]} at {new[1]} ppi') def undo(self): - self.parent.canvasSize, self.parent.ppi = self.old + self.parent.canvasSize, self.parent.ppi, self.parent.landscape = self.old self.widget.resizeHandler() def redo(self): - self.parent.canvasSize, self.parent.ppi = self.new + self.parent.canvasSize, self.parent.ppi, self.parent.landscape = self.new self.widget.resizeHandler()
\ No newline at end of file |