mscArrowHead.py 2.65 KB
Newer Older
Maxime Perrotin's avatar
Maxime Perrotin committed
1 2 3 4 5 6 7 8
#******************************************************************************
# /*
# * TASTE Msc Diagram Editor
# * http://taste.tuxfamily.org/
# *
# *  This file is part of TASTE Msc Editor.
# *
# *  Foobar is free software: you can redistribute it and/or modify
Maxime Perrotin's avatar
Maxime Perrotin committed
9
# *  it under the terms of the GNU Lesser General Public License as published by
Maxime Perrotin's avatar
Maxime Perrotin committed
10 11 12 13 14 15
# *  the Free Software Foundation, either version 3 of the License, or
# *  (at your option) any later version.
# *
# *  Foobar is distributed in the hope that it will be useful,
# *  (but WITHOUT ANY WARRANTY; without even the implied warranty of
# *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Maxime Perrotin's avatar
Maxime Perrotin committed
16
# *  GNU Lesser General Public License for more details.
Maxime Perrotin's avatar
Maxime Perrotin committed
17
# *
Maxime Perrotin's avatar
Maxime Perrotin committed
18
# *  You should have received a copy of the GNU Lesser General Public License
Maxime Perrotin's avatar
Maxime Perrotin committed
19 20 21 22 23 24 25 26 27
# *  along with TASTE Msc Editor.  If not, see
# *  <http://www.gnu.org/licenses/>.
# *
# *  Copyright (c) 2012 Angel Esquinas <aesquina@datsi.fi.upm.es>
# *
# *
# */
#******************************************************************************
from PySide.QtCore import Qt
28
from PySide.QtGui import QPen, QPainterPath, QGraphicsPathItem, QPainter
Maxime Perrotin's avatar
Maxime Perrotin committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80


class MscArrowHead(QGraphicsPathItem):
    '''
    classdocs
    '''
    def __init__(self, parent=None, width=15):
        '''
        Constructor
        '''
        super(MscArrowHead, self).__init__(parent)
        self.width = width
        self.height = (2 * width) / 3.0
        self.drawOriginX = - self.width
        self.drawOriginY = - (self.height / 2.0)

        self.color = Qt.black
        self.pen = QPen(self.color)

        self.setPen(self.pen)
        self.setBrush(self.color)

        path = QPainterPath()
        self.updatePath()

    def setColor(self, color):
        self.color = color
        self.pen.setColor(self.color)
        self.setBrush(self.color)

    def updatePath(self):
        path = self.path()
        path.lineTo(-self.width, -(self.height / 2))
        path.lineTo(-self.width, self.height / 2)
        path.lineTo(0, 0)
        self.setPath(path)

    def setWidth(self, width):
        ''' Set arrow head width '''
        self.prepareGeometryChange()
        self.width = width
        self.drawOriginX = self.width
        self.drawOriginY = - (self.height / 2.0)
        self.updatePath()

    def setHeight(self, height):
        ''' Set arrow head heigth '''
        self.prepareGeometryChange()
        self.height = height
        self.drawOriginX = self.width
        self.drawOriginY = - (self.height / 2.0)
        self.updatePath()
81 82 83 84

    def paint(self, painter, option, widget):
        painter.setRenderHint(QPainter.Antialiasing, True)
        super(MscArrowHead, self).paint(painter, option, widget)