Example #1
0
    def __init__(self, height, length, note_info):
        QGraphicsRectItem.__init__(self, 0, 0, length, height)

        self.orig_brush = QColor(note_info[3], 0, 0)
        self.hover_brush = QColor(note_info[3] + 98, 200, 100)
        self.select_brush = QColor(note_info[3] + 98, 100, 100)

        self.note = note_info
        self.length = length
        self.piano = self.scene

        self.pressed = False
        self.hovering = False
        self.moving_diff = (0,0)
        self.expand_diff = 0

        self.setAcceptHoverEvents(True)
        self.setFlag(QGraphicsItem.ItemIsMovable)
        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
        self.setPen(QPen(QColor(0,0,0,0)))
        self.setBrush(self.orig_brush)

        l = 5
        self.front = NoteExpander(l, height, self)
        self.back = NoteExpander(l, height, self)
        self.back.setPos(length - l, 0)
Example #2
0
    def __init__(self, scene):
        QGraphicsRectItem.__init__(self, QRectF(0, 0, 0, 0))

        self.setZValue(-1)
        self.hide()

        scene.addItem(self)
Example #3
0
    def __init__(self,
                 pos,
                 size,
                 type_,
                 parent=None,
                 scene=None,
                 areaBorder=2,
                 index=0,
                 textSize=50):
        QGraphicsRectItem.__init__(self, 0, 0, size.width(), size.height(),
                                   parent)
        self.setPos(pos)
        self.newEvent = IsClicked()
        self.newEvent.area = self

        #self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
        self.setFlags(QGraphicsItem.ItemIsMovable
                      | QGraphicsItem.ItemIsFocusable
                      | QGraphicsItem.ItemIsSelectable)

        ## set index label
        self.text = QGraphicsTextItem("%d" % index, self)
        self.setTextSize(textSize)

        ## TODO: How to create constants for the type?
        ## (such as constants in Qt) (enum?)
        self.kind = type_

        pen = QPen(self.color, areaBorder, Qt.SolidLine, Qt.RoundCap,
                   Qt.RoundJoin)
        self.setPen(pen)
Example #4
0
    def __init__(self, parent, x, y, w, h, item):
        self.cmptEmitter = QtCore.QObject()
        iParent = item
        '''
        self._rect = QtCore.QRectF(x,y,w,h)
        self._scene = parent
        print "self comptItem",self._scene.sceneContainer ," and",self._scene.sceneContainer.graphicsView
        self.mouseOver = False
        self.resizeHandleSize = 4.0
        self.mousePressPos = None
        self.mouseMovePos = None
        self.mouseIsPressed = False
        #self.setAcceptsHoverEvents(True)
        self.updateResizeHandles()
        '''
        if hasattr(iParent, "__iter__"):
            self.mobj = iParent[0]
        else:
            self.mobj = iParent
        self.layoutWidgetPt = parent
        QGraphicsRectItem.__init__(self, x, y, w, h)

        self.setFlag(QGraphicsItem.ItemIsMovable, True)
        self.setFlag(QGraphicsItem.ItemIsSelectable)
        #self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, 1)
        QT_VERSION = str(QtCore.QT_VERSION_STR).split('.')
        QT_MINOR_VERSION = int(QT_VERSION[1])
        if QT_MINOR_VERSION >= 6:
            #if config.QT_MINOR_VERSION >= 6:
            self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, 1)
        self.setAcceptHoverEvents(True)
        self.setToolTip(iParent.name)
Example #5
0
    def __init__(self, height, length, note_info):
        QGraphicsRectItem.__init__(self, 0, 0, length, height)

        self.setFlag(QGraphicsItem.ItemIsMovable)
        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
        self.setAcceptHoverEvents(True)

        clearpen = QPen(QColor(0,0,0,0))
        self.setPen(clearpen)
        self.orig_brush = QColor(note_info[3], 0, 0)
        self.hover_brush = QColor(note_info[3] + 100, 200, 100)
        self.select_brush = QColor(note_info[3] + 100, 100, 100)
        self.setBrush(self.orig_brush)

        self.note = note_info
        self.length = length
        self.piano = self.scene

        self.pressed = False
        self.hovering = False
        self.moving_diff = (0,0)
        self.expand_diff = 0

        l = 5
        self.front = NoteExpander(l, height, self)
        self.back = NoteExpander(l, height, self)
        self.back.setPos(length - l, 0)
Example #6
0
 def __init__(self, ax, ay, w, h):
     QGraphicsRectItem.__init__(self)
     self.top = ay
     self.bottom = ay+h
     self.left = ax
     self.height = h
     self.width = w
     self.setRect(ax, ay, w, h)
     self.setBrush(QColor.fromRgb(99, 66, 33))
Example #7
0
 def __init__(self, parent, x, y, w, h, item):
     QGraphicsRectItem.__init__(self, x, y, w, h, parent)
     self.mobj = item
     self.setFlag(QGraphicsItem.ItemIsMovable, True)
     self.setFlag(QGraphicsItem.ItemIsSelectable)
     self.setAcceptHoverEvents(True)
     self.setToolTip(self.mobj.name)
     if config.QT_MINOR_VERSION >= 6:
         self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, 1)
Example #8
0
 def __init__(self, width, height, parent):
     QGraphicsRectItem.__init__(self, 0, 0, width, height, parent)
     self.setPen(QPen(QColor(0,0,0,80)))
     self.width = width
     self.height = height
     self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
     self.setAcceptHoverEvents(True)
     self.hover_brush = QColor(200, 0, 0)
     self.click_brush = QColor(255, 100, 100)
     self.pressed = False
Example #9
0
    def __init__(self, rect, parent, cursor, updateCB):
        QGraphicsRectItem.__init__(self, rect, parent)
        self.setFlag(QGraphicsItem.ItemIsMovable)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
        self.setPen(Qt.red)
        self.setBrush(QBrush(Qt.red, Qt.SolidPattern))
        self.update = updateCB

        if cursor is not None:
            self.setCursor(cursor)
Example #10
0
    def __init__(self, rect, parent=None, scene=None):
        #QGraphicsRectItem.__init__(self, rect, parent, scene)
        QGraphicsRectItem.__init__(self, rect, parent)
        if scene is not None: scene.addItem(self)

        self.setAcceptHoverEvents(True)
        self.setAcceptTouchEvents(True)
        #self.setAcceptedMouseButtons(Qt.LeftButton)
        self.setCursorHover()
        self.setCursorGrab()
Example #11
0
    def __init__(self, row, col):
        QGraphicsRectItem.__init__(self)
        self.row = row
        self.col = col
        self.setRect(0, 0, 20, 20)

        self.setBrush(QColor(0, 128, 0))

        self.setX(self.row * 20)
        self.setY(self.col * 20)
Example #12
0
 def __init__(self, width, height, parent):
     QGraphicsRectItem.__init__(self, 0, 0, width, height, parent)
     self.setPen(QPen(QColor(0, 0, 0, 80)))
     self.width = width
     self.height = height
     self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
     self.setAcceptHoverEvents(True)
     self.hover_brush = QColor(200, 0, 0)
     self.click_brush = QColor(255, 100, 100)
     self.pressed = False
Example #13
0
    def __init__(self, length, height, parent):
        QGraphicsRectItem.__init__(self, 0, 0, length, height, parent)
        self.parent = parent
        self.orig_brush = QColor(0, 0, 0, 0)
        self.hover_brush = QColor(200, 200, 200)
        self.stretch = False

        self.setAcceptHoverEvents(True)
        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
        self.setPen(QPen(QColor(0,0,0,0)))
Example #14
0
 def __init__(self, x, y, c):
     super(CarreMosaiQ, self).__init__(0, 0, c, c)
     QGraphicsRectItem.__init__(self, 0, 0, c, c)
     self.setPos(x, y)
     self.setPen(CarreMosaiQ._pen)
     couleur = QColor(*(randint(*PLAGE_COULEURS) for _ in 'RGB'))
     self.brush = QBrush(couleur)
     self.setBrush(self.brush)
     self.setAcceptHoverEvents(True)
     self.setCursor(Qt.PointingHandCursor)
     CarreMosaiQ.nbInstances += 1
Example #15
0
    def __init__(self, length, height, parent):
        QGraphicsRectItem.__init__(self, 0, 0, length, height, parent)
        self.parent = parent
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
        self.setAcceptHoverEvents(True)

        clearpen = QPen(QColor(0,0,0,0))
        self.setPen(clearpen)

        self.orig_brush = QColor(0, 0, 0, 0)
        self.hover_brush = QColor(200, 200, 200)
        self.stretch = False
Example #16
0
    def __init__(self, x, y, number, scene):
        QGraphicsRectItem.__init__(self)
        self.setRect(x, y, 50, 50)
        self.setBrush(QBrush(QColor(50, 50, 50)))
        self.setPen(QPen(QColor("black")))
        self.__x = x
        self.__y = y
        self.setZValue(3)

        self.number = QGraphicsTextItem(str(number))
        self.number.setPos(x, y)
        self.number.setZValue(10)
        scene.addItem(self.number)
Example #17
0
    def __init__(self, rect, parent, label):
        QGraphicsRectItem.__init__(self, rect, parent=parent)
        self.setFlag(QGraphicsItem.ItemIsMovable)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
        self.setPen(Qt.red)
        self.resizeHandleSize = 4.0

        self.updateResizeHandles()

        self.label = label

        self.labelsCombo = QGraphicsTextItem(self.label, self)
        self.labelsCombo.setDefaultTextColor(Qt.red)
        self.labelsCombo.setPos(self.rect().bottomLeft() + QPointF(0, 5.0))
    def __init__(self,x,y,h,w, scene=None,parent=None, editor=None):
        """"
        This class implements the resizable rectangle item which is dispalied on the scene
         x y should be the original positions in scene coordinates
         h,w are the height and the width of the rectangle
        """
        
        self._editor = editor

        QGraphicsRectItem.__init__(self,0,0,w,h,parent=parent)
        self.Signaller=QGraphicsResizableRectSignaller(parent=parent)

        scene.addItem(self)

        #Default Appearence Properties
        self._fontColor=QColor(255, 255, 255)
        self._fontSize=10
        self._lineWidth=1

        ##Note: need to do like this because the x,y of the graphics item fix the position
        # of the zero relative to the scene
        self.moveBy(x,y)

        #Flags
        self.setFlag(QGraphicsItem.ItemIsMovable,True  )
        self.setFlag(QGraphicsItem.ItemIsSelectable,True)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges ,True)

        self.setAcceptHoverEvents(True)
        self.setAcceptedMouseButtons(Qt.LeftButton | Qt.RightButton)


        self._resizeHandles=[]

        # A bit of flags
        self._hovering=False
        self._normalColor   = QColor(0, 0, 255)
        self.updateColor()
        self._has_moved=False
        self._selected=False
        self._dbg=False
        self._setupTextItem()
        self._isFixed = False

        self.initHandles()
        self.hideHandles()


        self.setToolTip("Hold CTRL to drag the box")
Example #19
0
    def __init__(self, id, label, parent = 0):
        QGraphicsRectItem.__init__(self, parent)
        #1x1 rectangle with top left at origin:
        self.setRect(0.0, 0.0, 1.0, 1.0)
        #shut off the outline:
        self.setPen(QPen(Qt.NoPen))

        self.__center_x = 0.0
        self.__center_y = 0.0
        self.__width = 1.0
        self.__height = 1.0

        self.__id = id

        self.__label = label
        self.__label_scale = 1.0
Example #20
0
    def __init__(self, obj, parent=None, scene=None,\
                 brush=QBrush(), pen=QPen(Qt.blue, 0, Qt.SolidLine)) :
        """Adds QGraphics(Rect)Item to the scene. 

        Parameters

        obj : QPointF or shape type e.g. QRectF
              obj is QPointF - shape parameters are defined at first mouse click
              obj is QRectF - it will be drawn as is
        """
        logger.debug('In DragRect')

        rect = obj if isinstance(obj, QRectF) else\
               QRectF(obj, obj + QPointF(5,5)) if isinstance(obj, QPointF) else\
               None
        if rect is None:
            logger.warning('DragRect - wrong init object type:', str(obj))
            return

        self._dragtype = RECT
        parent_for_base = None
        QGraphicsRectItem.__init__(self, rect, parent_for_base)
        #DragBase.__init__(self, parent, brush, pen) # is called inside QGraphicsRectItem

        logger.debug('In DragRect - superclass initialization is done')

        if isinstance(obj, QPointF):
            self._drag_mode = ADD
            logger.debug('set elf._drag_mode = ADD, ADD:%d  _drag_mode:%d' %
                         (ADD, self._drag_mode))

        if scene is not None: scene.addItem(self)

        if self._drag_mode == ADD:
            self.grabMouse()  # makes available mouseMoveEvent
            logger.debug('In DragRect mode grabMouse()')

        self.setAcceptHoverEvents(True)
        #self.setAcceptTouchEvents(True)
        self.setAcceptedMouseButtons(Qt.LeftButton)

        self.setPen(self._pen_pos)
        self.setBrush(self._brush)

        # Flags: ItemIsPanel, ItemClipsChildrenToShape, ItemIsSelectable,
        # ItemIsMovable, itemClipsToShape, ItemSendsScenePositionChanges
        self.setFlags(self.ItemIsSelectable)
Example #21
0
    def __init__(self, x, y, h, w, scene=None, parent=None, editor=None):
        """"
        This class implements the resizable rectangle item which is dispalied on the scene
         x y should be the original positions in scene coordinates
         h,w are the height and the width of the rectangle
        """

        self._editor = editor

        QGraphicsRectItem.__init__(self, 0, 0, w, h, parent=parent)
        self.Signaller = QGraphicsResizableRectSignaller(parent=parent)

        scene.addItem(self)

        # Default Appearence Properties
        self._fontColor = QColor(255, 255, 255)
        self._fontSize = 10
        self._lineWidth = 1

        ##Note: need to do like this because the x,y of the graphics item fix the position
        # of the zero relative to the scene
        self.moveBy(x, y)

        # Flags
        self.setFlag(QGraphicsItem.ItemIsMovable, True)
        self.setFlag(QGraphicsItem.ItemIsSelectable, True)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)

        self.setAcceptHoverEvents(True)
        self.setAcceptedMouseButtons(Qt.LeftButton | Qt.RightButton)

        self._resizeHandles = []

        # A bit of flags
        self._hovering = False
        self._normalColor = QColor(0, 0, 255)
        self.updateColor()
        self._has_moved = False
        self._selected = False
        self._dbg = False
        self._setupTextItem()
        self._isFixed = False

        self.initHandles()
        self.hideHandles()

        self.setToolTip("Hold CTRL to drag the box")
Example #22
0
    def __init__(self, width, height, note, parent):
        QGraphicsRectItem.__init__(self, 0, 0, width, height, parent)

        self.width = width
        self.height = height
        self.note = note
        self.piano = self.scene
        self.hovered = False
        self.pressed = False

        self.click_brush = QColor(255, 100, 100)
        self.hover_brush = QColor(200, 0, 0)
        self.orig_brush = None

        self.setAcceptHoverEvents(True)
        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.setPen(QPen(QColor(0,0,0,80)))
Example #23
0
    def __init__(self, parent=None, channel=None, rect=None, **kwargs):
        QGraphicsRectItem.__init__(self, **kwargs)
        self.setAcceptHoverEvents(True)
        self.setAcceptedMouseButtons(Qt.NoButton)
        self.__channel = None

        if rect is None:
            rect = QRectF(0, 0, 20, 20)

        self.setRect(rect)

        if channel:
            self.setChannel(channel)

        self.__shadow = QGraphicsDropShadowEffect(blurRadius=5,
                                                  offset=QPointF(0, 0))
        self.setGraphicsEffect(self.__shadow)
        self.__shadow.setEnabled(False)
Example #24
0
    def __init__(self, x, y):
        QGraphicsRectItem.__init__(self, 0, 0, self.WIDTH, self.HEIGHT)

        self.isAlive = True
        self.hp = 100

        self.setPos(x - self.WIDTH / 2, y - self.HEIGHT / 2)

        self.point = 0
        self.needGoTo = QVector2D(0, 0)
        self.moveX = 0
        self.moveY = 0

        self.actuallyX = self.x()
        self.actuallyY = self.y()

        if self.point <= len(self.PATH) - 1:
            needGoTo = self.PATH[self.point]
            self.initGoTo(needGoTo[0], needGoTo[1])
Example #25
0
    def __init__(self, obj, parent=None, scene=None,\
                 brush=QBrush(), pen=QPen(Qt.blue, 0, Qt.SolidLine)) :
        """Adds QGraphics(Rect)Item to the scene. 

        Parameters

        obj : QPointF or shape type e.g. QRectF
              obj is QPointF - shape parameters are defined at first mouse click
              obj is QRectF - it will be drawn as is
        """
        DragBase.__init__(self, parent, brush, pen)

        rect = None
        if isinstance(obj, QPointF):
            rect = QRectF(obj, obj + QPointF(5, 5))
            self._mode = ADD

        elif isinstance(obj, QRectF):
            rect = obj

        else:
            print('DragRect - wrong init object type:', str(obj))
        parent_for_base = None
        QGraphicsRectItem.__init__(self, rect, parent_for_base)
        if scene is not None: scene.addItem(self)

        if self._mode == ADD:
            self.grabMouse()  # makes available mouseMoveEvent

        self.setAcceptHoverEvents(True)
        #self.setAcceptTouchEvents(True)
        self.setAcceptedMouseButtons(Qt.LeftButton)

        self.setPen(self._pen_pos)
        self.setBrush(self._brush)

        # Flags: ItemIsPanel, ItemClipsChildrenToShape, ItemIsSelectable,
        # ItemIsMovable, itemClipsToShape, ItemSendsScenePositionChanges
        self.setFlags(self.ItemIsSelectable)
Example #26
0
    def __init__(self, pos, size, type_, parent = None, scene = None,
                 areaBorder = 2, index = 0, textSize = 50):
        QGraphicsRectItem.__init__(self, 0, 0, size.width(), size.height(),
                                   parent)
        self.setPos(pos)
        self.newEvent = IsClicked()
        self.newEvent.area = self

        #self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
        self.setFlags(QGraphicsItem.ItemIsMovable |
            QGraphicsItem.ItemIsFocusable |
            QGraphicsItem.ItemIsSelectable)

        ## set index label
        self.text = QGraphicsTextItem("%d" % index, self)
        self.setTextSize(textSize)

        ## TODO: How to create constants for the type?
        ## (such as constants in Qt) (enum?)
        self.kind = type_

        pen = QPen(self.color, areaBorder, Qt.SolidLine,
                   Qt.RoundCap, Qt.RoundJoin)
        self.setPen(pen)
Example #27
0
    def __init__(self,
                 letter,
                 points,
                 coords,
                 scale,
                 on_position_change=None,
                 move_to_rack=None,
                 parent=None):
        QGraphicsRectItem.__init__(self, MARGIN, MARGIN,
                                   SQUARE_SIZE - 2 * MARGIN,
                                   SQUARE_SIZE - 2 * MARGIN, parent)
        if on_position_change:
            self.on_position_change = on_position_change
        if move_to_rack:
            self.move_to_rack = move_to_rack

        self.setFlag(QGraphicsItem.ItemIsMovable, True)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)
        self.points = points
        self.letter = letter

        self.scale = scale
        self.setScale(self.scale)
        self.setZValue(3)

        self.setPen(QPen(YELLOW2, 0))
        self.setBrush(QBrush(YELLOW))

        tile_letter = letter.upper()
        self.letter_item = QGraphicsSimpleTextItem(tile_letter, self)

        self.font = QFont("Verdana", 20)
        if not points:
            self.font.setBold(True)
        font_metrics = QFontMetrics(self.font)
        height = font_metrics.height()
        width = font_metrics.width(tile_letter)

        self.letter_item.setX((SQUARE_SIZE - width) / 2 - MARGIN)
        self.letter_item.setY((SQUARE_SIZE - height) / 2 - MARGIN)
        self.letter_item.setFont(self.font)
        self.letter_item.setBrush(QBrush(SEA_GREEN))

        self.shadow = QGraphicsRectItem(MARGIN * 2, MARGIN * 2, SQUARE_SIZE,
                                        SQUARE_SIZE, self)
        self.shadow.setFlag(QGraphicsItem.ItemStacksBehindParent)
        self.shadow.setBrush(QBrush(TRANSPARENT_BLACK))
        self.shadow.setPen(QPen(TRANSPARENT, 0))
        self.shadow.hide()

        self.setPos(coords.x * SQUARE_SIZE * scale,
                    coords.y * SQUARE_SIZE * scale)
        self.coords = None
        self.update_coords()

        self.old_position = None
        self.old_coords = None

        self.is_placed = False

        if points:
            self.add_points()
Example #28
0
 def __init__(self, x, y):
     QGraphicsRectItem.__init__(self, 0, 0, self.WIDTH, self.WIDTH)
     self.setPos(x, y)
     self.tower = None
Example #29
0
 def __init__(self, clearable_text_face, *arg, **karg):
     QGraphicsRectItem.__init__(self, *arg, **karg)
     self.clearable_text_face = clearable_text_face
Example #30
0
 def __init__(self, slide, ax, ay):
     QGraphicsRectItem.__init__(self)
     self.setRect(ax, ay, 30, 10)
     self.setBrush(QColor.fromRgb(180, 50, 230))
     self.pushed = False
     self.slide = slide
Example #31
0
 def __init__(self, x, y, w, h, parent=None, title=None):
     QGraphicsRectItem.__init__(self, x, y, w, h, parent)
     self.setBrush(Qt.white)
     self.setAcceptHoverEvents(True)
     self._title = title
Example #32
0
 def __init__(self, x, y, w, h, parent=None, title=None):
     QGraphicsRectItem.__init__(self, x, y, w, h, parent)
     self.setBrush(Qt.white)
     self.setAcceptHoverEvents(True)
     self._title = title