示例#1
0
    def drawLines(self, qp):
        pen = QPen(Qt.black, 2, Qt.SolidLine)
        qp.setPen(pen)

        qp.drawRect(self.rect().left(),
                    self.rect().top(),
                    self.rect().width(),
                    self.rect().height())

        qp.drawLine(self.dd.x() + 155,
                    self.dd.y() + 5,
                    self.dd.x() + 250,
                    self.dd.y() + 5)
        pen.setStyle(Qt.DashLine)
        qp.setPen(pen)
        qp.drawLine(self.ud.x() + 155,
                    self.ud.y() + 5,
                    self.ud.x() + 250,
                    self.ud.y() + 5)
        pen.setStyle(Qt.SolidLine)
        pen.setColor(Qt.red)
        qp.setPen(pen)
        qp.drawLine(self.unid.x() + 155,
                    self.unid.y() + 5,
                    self.unid.x() + 250,
                    self.unid.y() + 5)
        pen.setColor(Qt.yellow)
        qp.setPen(pen)
        qp.drawRect(self.sel.x() + 155, self.sel.y(), 95, 20)
        pen.setColor(Qt.green)
        qp.setPen(pen)
        qp.drawRect(self.leaf.x() + 155, self.leaf.y(), 95, 20)
    def paint(self, canvas, is_secondary_color=False, additional_flag=False):
        pen = QPen()

        if is_secondary_color:
            pen.setColor(self.data_singleton.secondary_color)
        else:
            pen.setColor(self.data_singleton.primary_color)

        painter = QPainter(canvas.image)
        painter.setRenderHint(QPainter.Antialiasing)
        pen.setWidth(self.data_singleton.pen_size)
        pen.setStyle(Qt.SolidLine)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)

        painter.setPen(pen)

        if is_secondary_color:
            painter.setBrush(self.data_singleton.primary_color)
        else:
            painter.setBrush(self.data_singleton.secondary_color)

        if self._start_point != self._end_point:
            painter.drawRect(QRect(self._start_point, self._end_point))

        painter.end()

        canvas.edited = True
        canvas.update()
示例#3
0
    def paint(self, canvas, is_secondary_color=False, additional_flag=False):
        pen = QPen()
        pen.setWidth(self.data_singleton.pen_size)
        pen.setStyle(Qt.SolidLine)
        pen.setCapStyle(Qt.RoundCap)
        pen.setJoinStyle(Qt.RoundJoin)

        if is_secondary_color:
            pen.setBrush(self.data_singleton.secondary_color)
        else:
            pen.setBrush(self.data_singleton.primary_color)

        painter = QPainter(canvas.image)
        painter.setPen(pen)

        if self._start_point != self._end_point:
            painter.drawLine(self._start_point, self._end_point)

        if self._start_point == self._end_point:
            painter.drawPoint(self._start_point)

        painter.end()

        canvas.edited = True
        canvas.update()
示例#4
0
def default_roi_pen(dashed=True,color=Qt.green):
    pen = QPen()
    if dashed:
        pen.setStyle(Qt.DashLine)
    pen.setBrush(color)
    pen.setCapStyle(Qt.RoundCap)
    pen.setJoinStyle(Qt.RoundJoin)
    return pen
示例#5
0
    def draw(self, painter, offset, draw_mode=DRAW_MODE_NORMAL):

        if draw_mode != Bin.DRAW_MODE_RELEASE:
            # Рисуем контур контейнера
            pen = QPen()
            pen.setStyle(Qt.DashLine)
            painter.setPen(pen)
            # painter.drawRect(self.origin.x, self.origin.y, self.size.width, self.size.height)
            painter.drawRect(offset.x, offset.y, self.size.width, self.size.height)

        for image in self.images:
            # Rect(rect.origin + self.origin, rect.size, rect.pen).draw(painter=painter)
            # image.draw(painter=painter, offset=self.origin)
            image.draw(painter=painter, offset=offset)
示例#6
0
 def paint(self, painter, _, ___):
     ''' Draw the comment symbol '''
     rect = self.boundingRect()
     pen = QPen()
     pen.setStyle(Qt.DashLine)
     pen.setColor(Qt.darkGray)
     painter.setPen(pen)
     x, y, w, h = rect.x(), rect.y(), rect.width(), rect.height()
     if self.on_the_right:
         painter.drawLines([QPoint(w, y), QPoint(x, y),
                            QPoint(x, y), QPoint(x, h),
                            QPoint(x, h), QPoint(w, h)])
     else:
         painter.drawLines([QPoint(x, y), QPoint(w, y),
                            QPoint(w, y), QPoint(w, h),
                            QPoint(w, h), QPoint(x, h)])
示例#7
0
class BaseObject(QGraphicsPathItem):
    """
    Subclass of `QGraphicsPathItem`_

    TOWRITE

    """

    Type = OBJ_TYPE_BASE

    def __init__(self, parent=None):
        """
        Default class constructor.

        :param `parent`: Pointer to a parent widget instance.
        :type `parent`: `QGraphicsItem`_
        """
        super(BaseObject, self).__init__(parent)

        qDebug("BaseObject Constructor()")

        self.objPen = QPen()        # QPen objPen;
        self.lwtPen = QPen()        # QPen lwtPen;
        self.objLine = QLineF()     # QLineF objLine;
        self.objRubberMode = int()  # int objRubberMode;
        self.objRubberPoints = {}   # QHash<QString, QPointF> objRubberPoints;
        self.objRubberTexts = {}    # QHash<QString, QString> objRubberTexts;
        self.objID = int()          # qint64 objID;

        self.objPen.setCapStyle(Qt.RoundCap)
        self.objPen.setJoinStyle(Qt.RoundJoin)
        self.lwtPen.setCapStyle(Qt.RoundCap)
        self.lwtPen.setJoinStyle(Qt.RoundJoin)

        self.objID = QDateTime.currentMSecsSinceEpoch()


    def __del__(self):
        """Class destructor."""
        qDebug("BaseObject Destructor()")

    def type(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: int
        """
        return self.Type

    def setObjectColor(self, color):
        """
        TOWRITE

        :param `color`: TOWRITE
        :type `color`: `QColor`_
        """
        self.objPen.setColor(color)
        self.lwtPen.setColor(color)

    def setObjectColorRGB(self, rgb):
        """
        TOWRITE

        :param `rgb`: TOWRITE
        :type `rgb`: `QRgb`_
        """
        self.objPen.setColor(QColor(rgb))
        self.lwtPen.setColor(QColor(rgb))

    def setObjectLineType(self, lineType):
        """
        TOWRITE

        :param `rgb`: TOWRITE
        :type `rgb`: Qt.PenStyle
        """
        self.objPen.setStyle(lineType)
        self.lwtPen.setStyle(lineType)

    def setObjectLineWeight(self, lineWeight):
        """
        TOWRITE

        :param `lineWeight`: TOWRITE
        :type `lineWeight`: qreal
        """
        self.objPen.setWidthF(0)  # NOTE: The objPen will always be cosmetic

        if lineWeight < 0:
            if lineWeight == OBJ_LWT_BYLAYER:
                self.lwtPen.setWidthF(0.35)  # TODO: getLayerLineWeight
            elif lineWeight == OBJ_LWT_BYBLOCK:
                self.lwtPen.setWidthF(0.35)  # TODO: getBlockLineWeight
            else:
                QMessageBox.warning(0, QObject.tr("Error - Negative Lineweight"),
                                       QObject.tr("Lineweight: %f" % lineWeight))
                qDebug("Lineweight cannot be negative! Inverting sign.")
                self.lwtPen.setWidthF(-lineWeight)
        else:
            self.lwtPen.setWidthF(lineWeight)

    def objectRubberPoint(self, key):
        """
        TOWRITE

        :param `key`: TOWRITE
        :type `key`: QString
        :rtype: `QPointF`_
        """
        if key in self.objRubberPoints:       # if(objRubberTexts.contains(key))
            return self.objRubberPoints[key]  #     return objRubberTexts.value(key);

        gscene = self.scene()  # QGraphicsScene* gscene = scene()
        if gscene:
            return self.scene().property("SCENE_QSNAP_POINT")  # .toPointF()
        return QPointF()

    def objectRubberText(self, key):
        """
        TOWRITE

        :param `key`: TOWRITE
        :type `key`: QString
        :rtype: QString
        """
        if key in self.objRubberTexts:       # if(objRubberTexts.contains(key))
            return self.objRubberTexts[key]  #     return objRubberTexts.value(key);
        return ""  # QString()

    def boundingRect(self):
        """
        TOWRITE

        :rtype: `QRectF`_
        """
        # If gripped, force this object to be drawn even if it is offscreen
        if self.objectRubberMode() == OBJ_RUBBER_GRIP:
            return self.scene().sceneRect()
        return self.path().boundingRect()

    def drawRubberLine(self, rubLine, painter=None, colorFromScene=''):
        """
        TOWRITE

        :param `rubLine`: TOWRITE
        :type `rubLine`: `QLineF`_
        :param `painter`: TOWRITE
        :type `painter`: `QPainter`_
        :param `colorFromScene`: TOWRITE
        :type `colorFromScene`: str
        """
        if painter:
            objScene = self.scene()  # QGraphicsScene* objScene = scene();
            if not objScene:
                return
            colorPen = self.objPen  # QPen colorPen = objPen
            colorPen.setColor(QColor(objScene.property(colorFromScene)))  # .toUInt()))
            painter.setPen(colorPen)
            painter.drawLine(rubLine)
            painter.setPen(self.objPen)

    def realRender(self, painter, renderPath):  # TODO/PORT: Still needs work.
        """
        TOWRITE

        :param `painter`: TOWRITE
        :type `painter`: `QPainter`_
        :param `renderPath`: TOWRITE
        :type `renderPath`: `QPainterPath`_
        """
        color1 = self.objectColor()  #QColor  # lighter color
        color2 = color1.darker(150)  #QColor  # darker color

        # If we have a dark color, lighten it
        darkness = color1.lightness() #int
        threshold = 32 #int   #TODO: This number may need adjusted or maybe just add it to settings.
        if darkness < threshold:
            color2 = color1
            if not darkness:
                color1 = QColor(threshold, threshold, threshold)  # lighter() does not affect pure black
            else :
                color1 = color2.lighter(100 + threshold)

        count = renderPath.elementCount()  # int
        for i in range(0, count - 1):  # for(int i = 0; i < count-1; ++i);

            elem = renderPath.elementAt(i)      # QPainterPath::Element
            next = renderPath.elementAt(i + 1)  # QPainterPath::Element

            if next.isMoveTo():
                continue

            elemPath = QPainterPath()
            elemPath.moveTo(elem.x, elem.y)
            elemPath.lineTo(next.x, next.y)

            renderPen = QPen(QColor(0, 0, 0, 0))
            renderPen.setWidthF(0)
            painter.setPen(renderPen)
            stroker = QPainterPathStroker()
            stroker.setWidth(0.35)
            stroker.setCapStyle(Qt.RoundCap)
            stroker.setJoinStyle(Qt.RoundJoin)
            realPath = stroker.createStroke(elemPath)  # QPainterPath
            painter.drawPath(realPath)

            grad = QLinearGradient(elemPath.pointAtPercent(0.5), elemPath.pointAtPercent(0.0))
            grad.setColorAt(0, color1)
            grad.setColorAt(1, color2)
            grad.setSpread(QGradient.ReflectSpread)

            painter.fillPath(realPath, QBrush(grad))

    def objectID(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: int
        """
        return self.objID

    def objectPen(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: `QPen`_
        """
        return self.objPen

    def objectColor(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: `QColor`_
        """
        return self.objPen.color()

    def objectColorRGB(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: int
        """
        return self.objPen.color().rgb()

    def objectLineType(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: Qt.PenStyle
        """
        return self.objPen.style()

    def objectLineWeight(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: float
        """
        return self.lwtPen.widthF()

    def objectPath(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: `QPainterPath`_
        """
        return self.path()

    def objectRubberMode(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: int
        """
        return self.objRubberMode

    def rect(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: `QRectF`_
        """
        return self.path().boundingRect()

    # pythonic setRect overload
    @signature(QPointF)
    def setRectFromRect(self, r):
        """
        TOWRITE

        :param `r`: TOWRITE
        :type `r`: QPointF
        """
        p = QPainterPath()
        p.addRect(r)
        self.setPath(p)

    # pythonic setRect overload
    @signature(float, float, float, float)
    def setRectFromXYWH(self, x, y, w, h):
        """
        TOWRITE

        :param `x`: TOWRITE
        :type `x`: qreal
        :param `y`: TOWRITE
        :type `y`: qreal
        :param `w`: TOWRITE
        :type `w`: qreal
        :param `h`: TOWRITE
        :type `h`: qreal
        """
        p = QPainterPath()
        p.addRect(x, y, w, h)
        self.setPath(p)

    @overloaded(setRectFromRect, setRectFromXYWH)
    def setRect(self, *args):
        """ TOWRITE """
        pass

    def line(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: `QLineF`_
        """
        return self.objLine

    # pythonic setLine overload
    @signature(QPointF)
    def setLineFromLine(self, li):
        """
        TOWRITE

        :param `li`: TOWRITE
        :type `li`: QPointF
        """
        p = QPainterPath()
        p.moveTo(li.p1())
        p.lineTo(li.p2())
        self.setPath(p)
        self.objLine = li

    # pythonic setLine overload
    @signature(float, float, float, float)
    def setLineFromXXYY(self, x1, y1, x2, y2):
        """
        TOWRITE

        :param `x1`: TOWRITE
        :type `x1`: qreal
        :param `y1`: TOWRITE
        :type `y1`: qreal
        :param `x2`: TOWRITE
        :type `x2`: qreal
        :param `y2`: TOWRITE
        :type `y2`: qreal
        """
        p = QPainterPath()
        p.moveTo(x1, y1)
        p.lineTo(x2, y2)
        self.setPath(p)
        self.objLine.setLine(x1, y1, x2, y2)

    @overloaded(setLineFromLine, setLineFromXXYY)
    def setLine(self, *args):
        """ TOWRITE """
        pass

    def setObjectPath(self, p):
        """
        TOWRITE

        :param `p`: TOWRITE
        :type `p`: `QPainterPath`_
        """
        self.setPath(p)

    def setObjectRubberMode(self, mode):
        """
        TOWRITE

        :param `mode`: TOWRITE
        :type `mode`: int
        """
        self.objRubberMode = mode

    def setObjectRubberPoint(self, key, point):
        """
        TOWRITE

        :param `key`: TOWRITE
        :type `key`: str
        :param `point`: TOWRITE
        :type `point`: `QPointF`_
        """
        self.objRubberPoints[key] = point  # .insert(key, point)

    def setObjectRubberText(self, key, txt):
        """
        TOWRITE

        :param `key`: TOWRITE
        :type `key`: str
        :param `txt`: TOWRITE
        :type `txt`: str
        """
        self.objRubberTexts[key] = txt  # .insert(key, txt)

    def shape(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: `QPainterPath`_
        """
        return self.path()

    def vulcanize(self):
        """ TOWRITE """
        raise NotImplementedError

    def mouseSnapPoint(self, mousePoint):
        """
        TOWRITE

        :param `mousePoint`: TOWRITE
        :type `mousePoint`: `QPointF`_
        :return: TOWRITE
        :rtype: `QPointF`_
        """
        raise NotImplementedError

    def allGripPoints(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: list[`QPointF`_]
        """
        raise NotImplementedError

    def gripEdit(self, before, after):
        """
        TOWRITE

        :param `before`: TOWRITE
        :type `before`: `QPointF`_
        :param `after`: TOWRITE
        :type `after`: `QPointF`_
        """
        raise NotImplementedError

    def lineWeightPen(self):
        """
        TOWRITE

        :return: TOWRITE
        :rtype: `QPen`_
        """
        return self.lwtPen
示例#8
0
 def drawLines(self, qp):
     pen = QPen(Qt.black, 2, Qt.SolidLine)
     qp.setPen(pen)
     # Can be used to test drawing lines between specific actions. Keep for now.
     #ifrom = self.mapToTree(self.needsLine[0][0])
     #ito = self.mapToTree(self.needsLine[0][1])
     #qp.drawLine(ifrom.x(), ifrom.y(), ito.x(), ito.y())
     alternate = True
     #print self.op.lastButtonPressed
     if self.op.lastButtonPressed is not None:
         pen.setColor(Qt.yellow)
         qp.setPen(pen)
         qp.drawRect(
             self.mapToTree(self.op.lastButtonPressed).x(),
             self.mapToTree(self.op.lastButtonPressed).y(),
             self.buttons[self.op.lastButtonPressed].rect().width(),
             self.buttons[self.op.lastButtonPressed].rect().height())
         pen.setColor(Qt.black)
         qp.setPen(pen)
     for line in self.needsLine:
         width0 = self.buttons[line[0]].rect().width()
         height0 = self.buttons[line[0]].rect().height()
         width1 = self.buttons[line[1]].rect().width()
         height1 = self.buttons[line[1]].rect().height()
         ifrom = self.mapToTree(line[0])
         ito = self.mapToTree(line[1])
         if len(self.table[line[0]]) == 1 or len(self.table[line[1]]) == 1:
             pen.setColor(Qt.green)
             qp.setPen(pen)
             if len(self.table[line[0]]) == 1:
                 if line[0] in self.op.subtree or line[
                         0] == self.op.lastButtonPressed:
                     qp.drawRect(ifrom.x() - 2,
                                 ifrom.y() - 2, width0 + 4, height0 + 4)
                 else:
                     qp.drawRect(ifrom.x(), ifrom.y(), width0, height0)
             if len(self.table[line[1]]) == 1:
                 if line[1] in self.op.subtree:
                     qp.drawRect(ito.x() - 2,
                                 ito.y() - 2, width1 + 4, height1 + 4)
                 else:
                     qp.drawRect(ito.x(), ito.y(), width1, height1)
             pen.setColor(Qt.black)
             qp.setPen(pen)
         if line[0] in self.op.subtree or line[1] in self.op.subtree:
             pen.setColor(Qt.red)
             qp.setPen(pen)
             if line[0] in self.op.subtree and line[
                     0] != self.op.lastButtonPressed:  # and len(self.table[line[0]])>1:
                 qp.drawRect(ifrom.x(), ifrom.y(), width0, height0)
             if line[1] in self.op.subtree and line[
                     1] != self.op.lastButtonPressed:  # and len(self.table[line[1]])>1:
                 qp.drawRect(ito.x(), ito.y(), width1, height1)
         if self.op.needsRefresh:
             self.update()
             self.op.needsRefresh = False
         if self.mapped[line[0]] <= self.mapped[line[1]]:
             qp.drawLine(ifrom.x() + (width0 / 2),
                         ifrom.y() + (height0 / 2),
                         ito.x() + (width1 / 2),
                         ito.y() + (height1 / 2))
         else:
             pen.setStyle(Qt.DashLine)
             qp.setPen(pen)
             qp.drawLine(ifrom.x() + (width0 / 2),
                         ifrom.y() + (height0 / 2),
                         ito.x() + (width1 / 2),
                         ito.y() + (height1 / 2))
             #if alternate:
             #	qp.drawArc(QRectF(ito.x(), ito.y()+1, width0, ifrom.y()-ito.y()), 90*16, 180*16)
             #	alternate=False
             #else:
             #	qp.drawArc(QRectF(ito.x(), ito.y()+1, width0, ifrom.y()-ito.y()), 270*16, 180*16)
             #	alternate=True
             pen.setStyle(Qt.SolidLine)
         pen.setColor(Qt.black)
         qp.setPen(pen)
示例#9
0
class SelectBox(QRubberBand):
    """
    Subclass of `QRubberBand`_

    TOWRITE

    """
    def __init__(self, s, parent=None):
        """
        Default class constructor.

        :param `s`: TOWRITE
        :type `s`: QRubberBand.Shape
        :param `parent`: Pointer to a parent widget instance.
        :type `parent`: `QWidget`_
        """
        super(SelectBox, self).__init__(parent)

        # private
        self._leftBrushColor = QColor()
        self._rightBrushColor = QColor()
        self._leftPenColor = QColor()
        self._rightPenColor = QColor()
        self._alpha = 255  # quint8  #: TODO: what is the initial int?

        self._dirBrush = QBrush()
        self._leftBrush = QBrush()
        self._rightBrush = QBrush()

        self._dirPen = QPen()
        self._leftPen = QPen()
        self._rightPen = QPen()

        self._boxDir = False  #: TODO: is this initial bool value right?

        # Default values
        self.setColors(QColor(Qt.darkGreen), QColor(Qt.green),
                       QColor(Qt.darkBlue), QColor(Qt.blue), 32)

    def setDirection(self, dir):
        """
        TOWRITE

        :param `dir`: TOWRITE
        :type `dir`: int
        """
        if not dir:
            self._dirPen = self._leftPen
            self._dirBrush = self._leftBrush
        else:
            self._dirPen = self._rightPen
            self._dirBrush = self._rightBrush
        self._boxDir = dir

    def setColors(self, colorL, fillL, colorR, fillR, newAlpha):
        """
        TOWRITE

        :param `colorL`: TOWRITE
        :type `colorL`: `QColor`_
        :param `fillL`: TOWRITE
        :type `fillL`: `QColor`_
        :param `colorR`: TOWRITE
        :type `colorR`: `QColor`_
        :param `fillR`: TOWRITE
        :type `fillR`: `QColor`_
        :param `newAlpha`: TOWRITE
        :type `newAlpha`: int
        """
        qDebug("SelectBox setColors()")
        self._alpha = newAlpha

        self._leftPenColor = colorL  # TODO: allow customization
        self._leftBrushColor = QColor(fillL.red(), fillL.green(), fillL.blue(),
                                      alpha)
        self._rightPenColor = colorR  # TODO: allow customization
        self._rightBrushColor = QColor(fillR.red(), fillR.green(),
                                       fillR.blue(), alpha)

        self._leftPen.setColor(self._leftPenColor)
        self._leftPen.setStyle(Qt.DashLine)
        self._leftBrush.setStyle(Qt.SolidPattern)
        self._leftBrush.setColor(self._leftBrushColor)

        self._rightPen.setColor(self._rightPenColor)
        self._rightPen.setStyle(Qt.SolidLine)
        self._rightBrush.setStyle(Qt.SolidPattern)
        self._rightBrush.setColor(self._rightBrushColor)

        if not self._boxDir:
            self._dirPen = self._leftPen
            self._dirBrush = self._leftBrush
        else:
            self._dirPen = self._rightPen
            self._dirBrush = self._rightBrush

        self.forceRepaint()

    def paintEvent(self, event):
        """
        Handles the ``paintEvent`` event for :class:`SelectBox`.

        :param `event`: A `QPaintEvent`_ to be processed.
        """
        painter = QPainter(self)
        painter.setPen(self._dirPen)
        width, height = self.width(), self.height()
        painter.fillRect(0, 0, width - 1, height - 1, self._dirBrush)
        painter.drawRect(0, 0, width - 1, height - 1)

    def forceRepaint(self):
        """
        Force repaint the rubberband.

        .. NOTE:: HACK: Take that QRubberBand!
        """
        # HACK: Take that QRubberBand!
        hack = self.size()  # QSize
        self.resize(hack + QSize(1, 1))
        self.resize(hack)
示例#10
0
class SelectBox(QRubberBand):
    """
    Subclass of `QRubberBand`_

    TOWRITE

    """
    def __init__(self, s, parent=None):
        """
        Default class constructor.

        :param `s`: TOWRITE
        :type `s`: QRubberBand.Shape
        :param `parent`: Pointer to a parent widget instance.
        :type `parent`: `QWidget`_
        """
        super(SelectBox, self).__init__(s, parent)

        # private
        self._leftBrushColor = QColor()
        self._rightBrushColor = QColor()
        self._leftPenColor = QColor()
        self._rightPenColor = QColor()
        self._alpha = 255  # quint8  #: TODO: what is the initial int?

        self._dirBrush = QBrush()
        self._leftBrush = QBrush()
        self._rightBrush = QBrush()

        self._dirPen = QPen()
        self._leftPen = QPen()
        self._rightPen = QPen()

        self._boxDir = False  #: TODO: is this initial bool value right?

        # Default values
        self.setColors(QColor(Qt.darkGreen), QColor(Qt.green), QColor(Qt.darkBlue), QColor(Qt.blue), 32)

    def paintEvent(self, event):
        """
        Handles the ``paintEvent`` event for :class:`SelectBox`.

        :param `event`: A `QPaintEvent`_ to be processed.
        """
        painter = QPainter(self)
        painter.setPen(self._dirPen)
        width, height = self.width(), self.height()
        painter.fillRect(0, 0, width - 1, height - 1, self._dirBrush)
        painter.drawRect(0, 0, width - 1, height - 1)

    def forceRepaint(self):
        """
        Force repaint the rubberband.

        .. NOTE:: HACK: Take that QRubberBand!
        """
        # HACK: Take that QRubberBand!
        hack = self.size()  # QSize
        self.resize(hack + QSize(1, 1))
        self.resize(hack)

    # Slots ------------------------------------------------------------------

    @Slot(int)
    def setDirection(self, dir):
        """
        TOWRITE

        :param `dir`: TOWRITE
        :type `dir`: int
        """
        if not dir:
            self._dirPen = self._leftPen
            self._dirBrush = self._leftBrush
        else:
            self._dirPen = self._rightPen
            self._dirBrush = self._rightBrush
        self._boxDir = dir

    @Slot(QColor, QColor, QColor, QColor, int)
    def setColors(self, colorL, fillL, colorR, fillR, newAlpha):
        """
        TOWRITE

        :param `colorL`: TOWRITE
        :type `colorL`: `QColor`_
        :param `fillL`: TOWRITE
        :type `fillL`: `QColor`_
        :param `colorR`: TOWRITE
        :type `colorR`: `QColor`_
        :param `fillR`: TOWRITE
        :type `fillR`: `QColor`_
        :param `newAlpha`: TOWRITE
        :type `newAlpha`: int
        """
        qDebug("SelectBox setColors()")
        self._alpha = newAlpha

        self._leftPenColor = colorL  # TODO: allow customization
        self._leftBrushColor = QColor(fillL.red(), fillL.green(), fillL.blue(), self._alpha)
        self._rightPenColor = colorR  # TODO: allow customization
        self._rightBrushColor = QColor(fillR.red(), fillR.green(), fillR.blue(), self._alpha)

        self._leftPen.setColor(self._leftPenColor)
        self._leftPen.setStyle(Qt.DashLine)
        self._leftBrush.setStyle(Qt.SolidPattern)
        self._leftBrush.setColor(self._leftBrushColor)

        self._rightPen.setColor(self._rightPenColor)
        self._rightPen.setStyle(Qt.SolidLine)
        self._rightBrush.setStyle(Qt.SolidPattern)
        self._rightBrush.setColor(self._rightBrushColor)

        if not self._boxDir:
            self._dirPen = self._leftPen
            self._dirBrush = self._leftBrush
        else:
            self._dirPen = self._rightPen
            self._dirBrush = self._rightBrush

        self.forceRepaint()