Skip to content

Commit

Permalink
Measurefactor and import added
Browse files Browse the repository at this point in the history
  • Loading branch information
Smit Patel committed Mar 30, 2022
1 parent 32ce4eb commit e6d8112
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
17 changes: 16 additions & 1 deletion drawApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from PyQt6 import QtCore
from PyQt6 import QtGui
from PyQt6 import QtWidgets # QtWidgets for QApplication
from PyQt6.QtGui import QPen
from PyQt6.QtGui import QPixmap, QImage
import fitz

from menuBar import MenuBar
from toolBar import ToolBar
Expand Down Expand Up @@ -106,6 +107,20 @@ def clear(self):
self.__v.update()

# methods for changing pixel sizes
# import pdf and convert to image
def importPDF(self):
filePath, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Import PDF", "",
"PDF(*.pdf);;All Files(*.*) ")
if filePath == "":
return

doc = fitz.open(filePath)
page = doc.loadPage(0) # number of page
pix = page.get_pixmap(alpha=False)
pm = QPixmap.fromImage(QImage.fromData(pix.tobytes(output="png")))
pm = self.__dc.addPixmap(pm)
pm.setPos(0, 0)
self.__v.update()


# create pyqt5 app
Expand Down
17 changes: 6 additions & 11 deletions drawingBoard.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def __init__(self, *args, **kwargs):
self.setRenderHint(QtGui.QPainter.RenderHint.Antialiasing | QtGui.QPainter.RenderHint.TextAntialiasing
)
self.setHorizontalScrollBarPolicy(
QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
QtCore.Qt.ScrollBarPolicy.ScrollBarAsNeeded)
self.setVerticalScrollBarPolicy(
QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
QtCore.Qt.ScrollBarPolicy.ScrollBarAsNeeded)

def wheelEvent(self, event):

Expand All @@ -41,11 +41,12 @@ def wheelEvent(self, event):
return super().wheelEvent(event)

def setScrollMode(self, mode):

if mode:
self.setDragMode(QGraphicsView.DragMode.RubberBandDrag)
self.setTransformationAnchor(
QGraphicsView.ViewportAnchor.AnchorUnderMouse)

self.setDragMode(QGraphicsView.DragMode.ScrollHandDrag)
self.setResizeAnchor(QGraphicsView.ViewportAnchor.AnchorUnderMouse)
else:
self.setDragMode(QGraphicsView.DragMode.NoDrag)
self.setTransformationAnchor(
Expand Down Expand Up @@ -80,7 +81,7 @@ def __init__(self, toolBar):
menuAction = QtGui.QAction(action, self)
self.__menu.addAction(menuAction)
menuAction.triggered.connect(self.__contextActionStep)
self.setSceneRect(0, 0, 250, 250)
self.setSceneRect(0, 0, 5000, 5000)

def __contextActionStep(self, action):
if self.sender().text() == "Delete":
Expand Down Expand Up @@ -118,8 +119,6 @@ def __contextActionStep(self, action):
for i, tup in enumerate(self.__addedItems):
tup[0].setZValue(i)
self.__selectedItem = None
for tup in self.__addedItems:
tup[0].setPen(tup[1])
self.update()

def contextMenuEvent(self, event):
Expand All @@ -133,12 +132,8 @@ def mousePressEvent(self, event):
# make drawing flag true
self.drawing = True
if not self.drawing:
for tup in self.__addedItems:
tup[0].setPen(tup[1])
self.__selectedItem = self.itemAt(
event.scenePos(), QtGui.QTransform())
if self.__selectedItem:
self.__selectedItem.setPen(self.__selectionPen)
return super().mousePressEvent(event)

# method for tracking mouse activity
Expand Down
9 changes: 9 additions & 0 deletions menuBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ def __init__(self, windowMenu, parentWindow):
fileMenu.addAction(clearAction)
# adding action to the clear
clearAction.triggered.connect(parentWindow.clear)

# creating import action
importAction = QtGui.QAction("Import", parentWindow)
# adding short cut to the import action
importAction.setShortcut("Ctrl + I")
# adding import to the file menu
fileMenu.addAction(importAction)
# adding action to the import
importAction.triggered.connect(parentWindow.importPDF)
10 changes: 7 additions & 3 deletions toolBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def __initWidgets(self):
self.__sizeGrp = QtWidgets.QGroupBox("Pen Size")
self.__drawShapeGrp = QtWidgets.QGroupBox("Draw Shape")
self.__measureSystemGrp = QtWidgets.QGroupBox("Measure System")
self.__empFactor = QtWidgets.QDoubleSpinBox()
self.__empFactor.setMinimum(1.0)

self.selectedItem = "line"
# self.selectedItem = "line"
self.__measureSystem = MeasureSystem.Metric

def __arrageWidgets(self):
Expand All @@ -47,6 +49,7 @@ def __arrageWidgets(self):
self.__sizeGrp.setLayout(QtWidgets.QGridLayout())
self.__measureSystemGrp.setLayout(QtWidgets.QGridLayout())
self.__drawShapeGrp.setLayout(QtWidgets.QGridLayout())

for i, color in enumerate(self.__colors):
w = QtWidgets.QPushButton(parent=self.__colorGrp)
w.setObjectName(color)
Expand Down Expand Up @@ -85,6 +88,7 @@ def __arrageWidgets(self):
w.setChecked(True)
self.__measureSystemGrp.layout().addWidget(w, i//2, i % 2)
layout.addWidget(self.__measureSystemGrp)
layout.addWidget(self.__empFactor)

layout.addStretch(1)

Expand Down Expand Up @@ -141,13 +145,13 @@ def __setMeasureSystem(self):

def pix2Met(self, pix):
if self.__measureSystem == MeasureSystem.Metric:
v = 2.54*pix/self.__dpi
v = self.__empFactor.value()*2.54*pix/self.__dpi
if v > 100:
text = "{}m {:.2f}cm".format(v//100, v - 100 * (v//100))
else:
text = "{:.2f}cm".format(v)
if self.__measureSystem == MeasureSystem.Imperial:
v = pix/self.__dpi
v = self.__empFactor.value()*pix/self.__dpi
if v > 12:
text = "{}ft {:.2f}in".format(v//12, v - 12 * (v//12))
else:
Expand Down

0 comments on commit e6d8112

Please sign in to comment.