# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'Signature.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import * 
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 

class Ui_Signature(QMainWindow): 
    def __init__(self): 
        super().__init__() 
  
        self.setObjectName("Signature")
        self.resize(1024, 768)
        self.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.logo = QtWidgets.QLabel(self)
        self.logo.setGeometry(QtCore.QRect(730, 20, 281, 81))
        self.logo.setAutoFillBackground(False)
        self.logo.setText("")
        self.logo.setPixmap(QtGui.QPixmap("img/Logo.png"))
        self.logo.setScaledContents(True)
        self.logo.setObjectName("logo")
        self.nextButton_2 = QtWidgets.QPushButton(self)
        self.nextButton_2.setGeometry(QtCore.QRect(90, 550, 81, 81))
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.nextButton_2.setFont(font)
        self.nextButton_2.setStyleSheet("border: 4px solid darkblue;\n"
"color: darkblue;\n"
"border-radius: 25px;")
        self.nextButton_2.setIconSize(QtCore.QSize(103, 105))
        self.nextButton_2.setObjectName("nextButton_2")
        self.nextButton_3 = QtWidgets.QPushButton(self)
        self.nextButton_3.setGeometry(QtCore.QRect(860, 550, 81, 81))
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.nextButton_3.setFont(font)
        self.nextButton_3.setStyleSheet("border: 4px solid darkblue;\n"
"color: darkblue;\n"
"border-radius: 25px;")
        self.nextButton_3.setIconSize(QtCore.QSize(103, 105))
        self.nextButton_3.setObjectName("nextButton_3")
        
        self.image = QImage(self.size(), QImage.Format_RGB32) 
  
        self.image.fill(Qt.white) 
  
        self.drawing = False
        self.brushSize = 4
        self.brushColor = Qt.black 
  
        self.lastPoint = QPoint() 
        
        self.nextButton_2.clicked.connect(lambda: self.clear())
        self.nextButton_3.clicked.connect(lambda: self.save())

        self.retranslateUi(self)
        QtCore.QMetaObject.connectSlotsByName(self)
        
        self.label = QtWidgets.QLabel(self)
        self.label.setGeometry(QtCore.QRect(320, 90, 311, 41))
        font = QtGui.QFont()
        font.setPointSize(16)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.label.setText("Signature Here")

    def retranslateUi(self, Signature):
        _translate = QtCore.QCoreApplication.translate
        Signature.setWindowTitle(_translate("Signature", "Trimble"))
        self.nextButton_2.setText(_translate("Signature", "RESET"))
        self.nextButton_3.setText(_translate("Signature", "OK"))
        
        
    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton: 
            self.drawing = True
            self.lastPoint = event.pos() 
  
    def mouseMoveEvent(self, event): 
          
        if (event.buttons() & Qt.LeftButton) & self.drawing: 
              
            painter = QPainter(self.image) 
              
            painter.setPen(QPen(self.brushColor, self.brushSize,  
                            Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) 
              

            painter.drawLine(self.lastPoint, event.pos()) 
              
            self.lastPoint = event.pos() 
            self.update() 
  
    def mouseReleaseEvent(self, event): 
  
        if event.button() == Qt.LeftButton: 
            self.drawing = False
  
    def paintEvent(self, event): 
        canvasPainter = QPainter(self) 
          
        canvasPainter.drawImage(self.rect(), self.image, self.image.rect()) 
  
    def save(self): 
        self.image.save("Signature.png")
        
    def clear(self): 
        self.image.fill(Qt.white) 
        self.update() 
        


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Signature = QtWidgets.QWidget()
    ui = Ui_Signature()
    # ui.setupUi(Signature)
    # Signature.show()
    ui.show()
    sys.exit(app.exec_())
