def drawLines(self, qp): pen = qt.QPen(qt.Qt.green, 2, qt.Qt.SolidLine) if self.state == 0: pen.setColor(qt.Qt.black) qp.setPen(pen) qp.setFont(qt.QFont("Arial", 30)) qp.drawText(qt.QPointF(325, 60), self.LT_Text) elif self.state == 1: pen.setColor(qt.Qt.black) qp.setPen(pen) qp.setFont(qt.QFont("Arial", 30)) qp.drawText(qt.QPointF(325, 60), self.RT_Text) elif self.state == 2: pen.setColor(qt.Qt.black) qp.setPen(pen) qp.setFont(qt.QFont("Arial", 30)) qp.drawText(qt.QPointF(325, 60), self.LB_Text) elif self.state == 3: pen.setColor(qt.Qt.black) qp.setPen(pen) qp.setFont(qt.QFont("Arial", 30)) qp.drawText(qt.QPointF(325, 60), self.RB_Text) elif self.state == 4: pen.setColor(qt.Qt.black) qp.setPen(pen) qp.setFont(qt.QFont("Arial", 30)) qp.drawText(qt.QPointF(325, 60), self.Quit_Text)
def drawLines(self, qp): pen = qt.QPen(qt.Qt.red, 2, qt.Qt.SolidLine) qp.setPen(pen) qp.drawLine(0, self.horizontal, 300, self.horizontal) qp.setPen(pen) qp.drawLine(self.vertical, 50, self.vertical, 330) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.black) qp.setPen(pen) qp.drawLine(0, 50, 300, 50) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.black) qp.setPen(pen) qp.drawLine(0, 50, 0, 90) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.black) qp.setPen(pen) qp.drawLine(0, 330, 40, 330) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.black) qp.setPen(pen) qp.drawLine(0, 290, 0, 330) #pen.setStyle(qt.Qt.DashLine) #pen.setColor(qt.Qt.black) #qp.setPen(pen) #qp.drawLine(300, 0, 260, 0) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.black) qp.setPen(pen) qp.drawLine(300, 50, 300, 90) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.black) qp.setPen(pen) qp.drawLine(300, 290, 300, 330) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.black) qp.setPen(pen) qp.drawLine(300, 330, 260, 330)
def revealPixmap(self, xy): """fill a pixmap with an image that has a reveal pattern at xy with the fg drawn over the bg""" # Get QImages for the two layers bgVTKImage = self.layerLogics['B'].GetImageData() fgVTKImage = self.layerLogics['F'].GetImageData() bgQImage = qt.QImage() fgQImage = qt.QImage() slicer.qMRMLUtils().vtkImageDataToQImage(bgVTKImage, bgQImage) slicer.qMRMLUtils().vtkImageDataToQImage(fgVTKImage, fgQImage) # get the geometry of the focal point (xy) and images # noting that vtk has the origin at the bottom left and qt has # it at the top left. yy is the flipped version of y imageWidth = bgQImage.width() imageHeight = bgQImage.height() x, y = xy yy = imageHeight - y # # make a generally transparent image, # then fill quadrants with the fg image # overlayImage = qt.QImage(imageWidth, imageHeight, qt.QImage().Format_ARGB32) overlayImage.fill(0) halfWidth = imageWidth / 2 halfHeight = imageHeight / 2 topLeft = qt.QRect(0, 0, x, yy) bottomRight = qt.QRect(x, yy, imageWidth - x - 1, imageHeight - yy - 1) self.painter.begin(overlayImage) self.painter.drawImage(topLeft, fgQImage, topLeft) self.painter.drawImage(bottomRight, fgQImage, bottomRight) self.painter.end() # draw the bg and fg on top of gray background compositePixmap = qt.QPixmap(self.width, self.height) compositePixmap.fill(self.gray) self.painter.begin(compositePixmap) self.painter.drawImage(-1 * (x - self.width / 2), -1 * (yy - self.height / 2), bgQImage) self.painter.drawImage(-1 * (x - self.width / 2), -1 * (yy - self.height / 2), overlayImage) self.painter.end() if self.scale: compositePixmap = self.scalePixmap(compositePixmap) # draw a border around the pixmap self.painter.begin(compositePixmap) self.pen = qt.QPen() self.color = qt.QColor("#FF0") self.color.setAlphaF(0.3) self.pen.setColor(self.color) self.pen.setWidth(5) self.pen.setStyle(3) # dotted line (Qt::DotLine) self.painter.setPen(self.pen) rect = qt.QRect(1, 1, self.width - 2, self.height - 2) self.painter.drawRect(rect) self.painter.end() return compositePixmap
def drawLines(self, qp): pen = qt.QPen(qt.Qt.white, 1, qt.Qt.DashLine) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.white) qp.setPen(pen) qp.drawText( qt.QPointF(100, 40), "Template Coordinate: %s,%s Needle Insertion Depth:%s millimeters" % (self.indexX, self.indexY, self.ndepth)) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.white) qp.setPen(pen) qp.drawLine(self.mousePointX1, self.mousePointY1, self.mousePointX2, self.mousePointY2) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.white) qp.setPen(pen) qp.drawLine(self.mousePointX1, self.mousePointY1, self.mousePointX3, self.mousePointY3) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.white) qp.setPen(pen) qp.drawLine(self.mousePointX3, self.mousePointY3, self.mousePointX4, self.mousePointY4) #pen.setStyle(qt.Qt.DashLine) #pen.setColor(qt.Qt.white) #qp.setPen(pen) #qp.drawLine(40, 290, 40, 330) #pen.setStyle(qt.Qt.DashLine) #pen.setColor(qt.Qt.black) #qp.setPen(pen) #qp.drawLine(300, 0, 260, 0) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.white) qp.setPen(pen) qp.drawLine(self.mousePointX2, self.mousePointY2, self.mousePointX4, self.mousePointY4) pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.white) qp.setPen(pen) qp.drawLine(self.mousePointX1, self.mousePointY1, self.mousePointX2, self.mousePointY2) #pen.setStyle(qt.Qt.DashLine) #pen.setColor(qt.Qt.white) #qp.setPen(pen) #qp.drawLine(340, 290, 340, 330) #pen.setStyle(qt.Qt.DashLine) #pen.setColor(qt.Qt.white) #qp.setPen(pen) #qp.drawLine(340, 330, 300, 330) #End of Line Drawing #pen.setColor(qt.Qt.white) #qp.setPen(pen) #qp.setFont(qt.QFont("Arial", 12)); #qp.drawText(qt.QPointF(163, 47), self.text_info) self.blink = self.blink + 1 if self.blink % 2 == 0: pen.setColor(qt.Qt.green) qp.setPen(pen) qp.setFont(qt.QFont("Arial", 15 * self.scale)) qp.drawText( qt.QPointF((self.scale * self.vertical) - 5 * self.scale, (self.scale * self.horizontal) + 4 * self.scale), "X") else: pen.setColor(qt.Qt.black) qp.setPen(pen) qp.setFont(qt.QFont("Arial", 15 * self.scale)) qp.drawText( qt.QPointF((self.scale * self.vertical) - 5 * self.scale, (self.scale * self.horizontal) + 4 * self.scale), "X") #Beginning of Hole Indicators A textList = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N' ] numberList = [ '-7', '-6', '-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5', '6', '7' ] for n in range(0, 14): i = 1.0 * n pen.setColor(qt.Qt.white) qp.setPen(pen) qp.setFont(qt.QFont("Arial", 12)) qp.drawText( qt.QPointF( self.LetterOriginX - 15 - self.LetterSpacingHorizontal * i, self.LetterOriginY - self.LetterSpacingVertical * i), textList[n]) for n in range(0, 14): i = 1.0 * n pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.white) qp.setPen(pen) qp.drawLine( self.mousePointX1 - self.LetterSpacingHorizontal * i, self.mousePointY1 - self.LetterSpacingVertical * i, self.mousePointX2 - self.RightSideHoleSpacingHorizontal * i, self.mousePointY2 - self.RightSideHoleSpacingVertical * i) #Vertical for n in range(0, 15): i = 1.0 * n pen.setColor(qt.Qt.white) qp.setPen(pen) qp.setFont(qt.QFont("Arial", 12)) qp.drawText( qt.QPointF( self.NumberOriginX - 10 - self.NumberSpacingHorizontal * i, self.NumberOriginY + 10 - self.NumberSpacingVertical * i), numberList[n]) for n in range(0, 15): i = 1.0 * n self.VertX1 = self.mousePointX1 - self.NumberSpacingHorizontal * i self.VertY1 = self.mousePointY1 - self.NumberSpacingVertical * i self.VertX2 = self.mousePointX3 - self.bottomHoleSpacingHorizontal * i self.VertY2 = self.mousePointY3 - self.bottomHoleSpacingVertical * i #self.VertSlope= ((self.VertY2-self.VertY1)/(self.VertX2-self.VertX1)) # self.VertFinderLine= self.VertSlope*self.VertX1 pen.setStyle(qt.Qt.DashLine) pen.setColor(qt.Qt.white) qp.setPen(pen) qp.drawLine(self.VertX1, self.VertY1, self.VertX2, self.VertY2) #Beginning of Line Drawing pen.setStyle(qt.Qt.SolidLine) pen.setColor(qt.Qt.green) pen.setWidth(2) qp.setPen(pen) qp.drawLine( self.mousePointX1 - self.LetterSpacingHorizontal * self.horizontal, self.mousePointY1 - self.LetterSpacingVertical * self.horizontal, self.mousePointX2 - self.RightSideHoleSpacingHorizontal * self.horizontal, self.mousePointY2 - self.RightSideHoleSpacingVertical * self.horizontal) #qp.drawLine(self.scale * 40, self.scale * self.horizontal, self.scale * 340, self.scale * self.horizontal) qp.setPen(pen) #qp.drawLine(self.scale * self.vertical, self.scale * 50, self.scale * self.vertical, self.scale * 330) self.VertX1 = self.mousePointX1 - self.NumberSpacingHorizontal * self.vertical self.VertY1 = self.mousePointY1 - self.NumberSpacingVertical * self.vertical self.VertX2 = self.mousePointX3 - self.bottomHoleSpacingHorizontal * self.vertical self.VertY2 = self.mousePointY3 - self.bottomHoleSpacingVertical * self.vertical qp.drawLine(self.VertX1, self.VertY1, self.VertX2, self.VertY2)