예제 #1
0
 def get_lines(self, box):
     center = box.center()
     right = box.right()
     top = box.top()
     left = box.left()
     bottom = box.bottom()
     if self.corner == 'topLeft':
         return [
             QtCore.QLine(center, QtCore.QPoint(right, center.y())),
             QtCore.QLine(center, QtCore.QPoint(center.x(), bottom))
         ]
     if self.corner == 'topRight':
         return [
             QtCore.QLine(center, QtCore.QPoint(left, center.y())),
             QtCore.QLine(center, QtCore.QPoint(center.x(), bottom))
         ]
     if self.corner == 'bottomRight':
         return [
             QtCore.QLine(center, QtCore.QPoint(left, center.y())),
             QtCore.QLine(center, QtCore.QPoint(center.x(), top))
         ]
     if self.corner == 'bottomLeft':
         return [
             QtCore.QLine(center, QtCore.QPoint(right, center.y())),
             QtCore.QLine(center, QtCore.QPoint(center.x(), top))
         ]
예제 #2
0
    def paintEvent(self, event):

        painter = QtGui.QPainter(self)
        rect = event.rect()

        if self.color0 != self.color1:

            # draw checkerboard if colours differ
            checkSize = 6

            min = imath.V2i(rect.x() / checkSize, rect.y() / checkSize)
            max = imath.V2i(1 + (rect.x() + rect.width()) / checkSize,
                            1 + (rect.y() + rect.height()) / checkSize)

            for x in range(min.x, max.x):
                for y in range(min.y, max.y):
                    if (x + y) % 2:
                        painter.fillRect(
                            QtCore.QRectF(x * checkSize, y * checkSize,
                                          checkSize, checkSize), self.color0)
                    else:
                        painter.fillRect(
                            QtCore.QRectF(x * checkSize, y * checkSize,
                                          checkSize, checkSize), self.color1)

        else:

            # otherwise just draw a flat colour cos it'll be quicker
            painter.fillRect(
                QtCore.QRectF(rect.x(), rect.y(),
                              rect.x() + rect.width(),
                              rect.y() + rect.height()), self.color0)

        if self.borderColor is not None:
            w = self.width()
            h = self.height()
            pen = QtGui.QPen(self.borderColor)
            lines = [
                QtCore.QLine(0, 0, 0, h),
                QtCore.QLine(w, 0, w, h),
            ]
            if self.__borderTop:
                lines.append(QtCore.QLine(0, 0, w, 0))
            if self.__borderBottom:
                lines.append(QtCore.QLine(0, h, w, h))
            pen.setWidth(4)
            painter.setPen(pen)
            painter.drawLines(lines)