diff options
author | pravindalve | 2020-06-12 12:49:53 +0530 |
---|---|---|
committer | GitHub | 2020-06-12 12:49:53 +0530 |
commit | 7d2d686209e3c0cf7e869088f14678ce309fe7dd (patch) | |
tree | feb418bd92e1da5f6caf0dbe8a1fe93439813e70 /src/main/python/utils/canvas.py | |
parent | b70d765b41d9de58cbe9411b8420a44a7e1f10e2 (diff) | |
parent | d3bb58bc5d77b02d2102c6a59151cff6beee662f (diff) | |
download | Chemical-PFD-7d2d686209e3c0cf7e869088f14678ce309fe7dd.tar.gz Chemical-PFD-7d2d686209e3c0cf7e869088f14678ce309fe7dd.tar.bz2 Chemical-PFD-7d2d686209e3c0cf7e869088f14678ce309fe7dd.zip |
Merge pull request #18 from Blakeinstein/master
side view + canvas overhaul
Diffstat (limited to 'src/main/python/utils/canvas.py')
-rw-r--r-- | src/main/python/utils/canvas.py | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index f37d1f8..480a2e1 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,53 +31,32 @@ class canvas(QWidget): #set layout and background color self.painter = customScene() self.painter.setBackgroundBrush(QBrush(Qt.white)) #set white background - - 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.setScene(self.painter) #set initial paper size for the scene 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) - + 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) - - # use the available mdi area, also add padding - prect = self.parentMdiArea.rect() - width = width + 20 - height = height + 60 - - # add scrollbar size to width and height if they are visible, avoids clipping - if self.view.verticalScrollBar().isVisible(): - width += self.style().pixelMetric(QStyle.PM_ScrollBarExtent) - if self.view.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) - + 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): """ |