Example #1
0
    def __init__(self, scene, color):
        size = 10
        z = 1

        pen = QtGui.QPen(color, 0.5, QtCore.Qt.SolidLine)
        pen_bold = QtGui.QPen(color, 1.5, QtCore.Qt.SolidLine)

        self._rect = CrossRect(size, self.rect_move_to)
        self._rect.setPen(pen_bold)
        self._rect.setZValue(z)
        self._rect.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresTransformations,
                           True)
        self._rect.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
        scene.addItem(self._rect)

        self._line1 = QtWidgets.QGraphicsLineItem(-2 * size, 0, 2 * size, 0)
        self._line1.setPen(pen)
        self._line1.setZValue(z)
        self._line1.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresTransformations,
                            True)
        scene.addItem(self._line1)

        self._line2 = QtWidgets.QGraphicsLineItem(0, -2 * size, 0, 2 * size)
        self._line2.setPen(pen)
        self._line2.setZValue(z)
        self._line2.setFlag(QtWidgets.QGraphicsItem.ItemIgnoresTransformations,
                            True)
        scene.addItem(self._line2)
Example #2
0
    def draw_origin(self):
        pen = qg.QPen(qg.QColor('#e533e5'), 2)
        pen.setCosmetic(True)  # changes width depending on zoom
        pen.setJoinStyle(qc.Qt.RoundJoin)

        length = self.scene.itemsBoundingRect().width() / 16
        diameter = length / 10

        origin_item = qw.QGraphicsItemGroup()

        circle = qw.QGraphicsEllipseItem(
            qc.QRectF(-diameter / 2, -diameter / 2, diameter, diameter))
        circle.setPen(pen)
        circle.setEnabled(False)
        origin_item.addToGroup(circle)

        x_line = qw.QGraphicsLineItem(
            0,
            0,
            length,
            0,
        )
        x_line.setPen(pen)
        origin_item.addToGroup(x_line)

        y_line = qw.QGraphicsLineItem(0, 0, 0, length)
        y_line.setPen(pen)
        origin_item.addToGroup(y_line)

        origin_item.setEnabled(False)
        origin_item.setZValue(-1)
        self.scene_origin = origin_item
        self.scene.addItem(self.scene_origin)
Example #3
0
    def drawWays(self):
        # draw adjMatrix or ways?
        if self.lp:
            c = self.getCities()
            for i in range(self.N):
                for j in range(i):
                    w = self.adjMatrix[i * self.N + j]
                    if w > 10e-5:
                        x1, y1 = c[i]
                        x2, y2 = c[j]
                        item = QtWidgets.QGraphicsLineItem(x1, y1, x2, y2)
                        if w < 1 - 10e-5:
                            item.setPen(self.tourPenIncomplete)
                        else:
                            item.setPen(self.tourPen)
                        self.edgeItems.append(item)
                        self.scene.addItem(item)

                        if w != 1:
                            text = QtWidgets.QGraphicsTextItem("%.2f" % w)
                            text.setPos((x1 + x2) / 2, (y1 + y2) / 2)
                            text.setScale(2 / 1000)
                            text.setVisible(self.showValues)
                            self.textItems.append(text)
                            self.scene.addItem(text)

        else:
            # draw heuristic
            for a, b in self.getWayCoordinates():
                x1, y1 = a
                x2, y2 = b
                item = QtWidgets.QGraphicsLineItem(x1, y1, x2, y2)
                item.setPen(self.tourPen)
                self.edgeItems.append(item)
                self.scene.addItem(item)
    def plot_currentIndicator(self, indicatordata):
        pen = QtGui.QPen(QtCore.Qt.black, 2)
        for indicator in self.currentIndicator:
            self.scene.removeItem(indicator)
        self.currentIndicator.clear()
        newline = QtWidgets.QGraphicsLineItem(
            self.indi_x_trans.t(1), self.indi_y_trans.t(indicatordata[1]),
            self.indi_x_trans.t(0), self.indi_y_trans.t(indicatordata[0]))
        newline.setPen(pen)
        actionline = False
        currentindi = indicatordata[0]
        if currentindi <= 100 and indicatordata[1] > 100:
            actionline = True
            pen2 = QtGui.QPen(self.red, 2, QtCore.Qt.DashLine)
        if currentindi >= -100 and indicatordata[1] < -100:
            actionline = True
            pen2 = QtGui.QPen(self.green, 2, QtCore.Qt.DashLine)

        if actionline is True:
            x = self.indi_x_trans.t(0)
            y1 = self.height() * self.space
            y2 = self.height() - (self.height() * self.space)
            newline2 = QtWidgets.QGraphicsLineItem(x, y1, x, y2)
            newline2.setPen(pen2)
            self.scene.addItem(newline2)
            self.indicatorItems.append(newline2)

        self.scene.addItem(newline)
        self.currentIndicator.append(newline)
Example #5
0
    def drawAGrid(self,
                  DeltaX=10,
                  DeltaY=10,
                  Height=200,
                  Width=200,
                  CenterX=0,
                  CenterY=0,
                  Pen=None,
                  Brush=None,
                  SubGrid=None):
        """
        This makes a grid for reference.  No snapping to grid enabled.
        :param DeltaX: grid spacing in x direction
        :param DeltaY: grid spacing in y direction
        :param Height: height of grid (y)
        :param Width: width of grid (x)
        :param CenterX: center of grid (x, in scene coords)
        :param CenterY: center of grid (y, in scene coords)
        :param Pen: pen for grid lines
        :param Brush: brush for background
        :param SubGrid: subdivide the grid (not currently working)
        :return: nothing
        """
        height = self.scene.sceneRect().height() if Height is None else Height
        width = self.scene.sceneRect().width() if Width is None else Width
        left = self.scene.sceneRect().left() if CenterX is None else (
            CenterX - width / 2.0)
        right = self.scene.sceneRect().right() if CenterX is None else (
            CenterX + width / 2.0)
        top = self.scene.sceneRect().top() if CenterY is None else (
            CenterY - height / 2.0)
        bottom = self.scene.sceneRect().bottom() if CenterY is None else (
            CenterY + height / 2.0)
        Dx = DeltaX
        Dy = DeltaY
        pen = qtg.QPen() if Pen is None else Pen

        # make the background rectangle first
        if Brush is not None:
            rect = qtw.QGraphicsRectItem(left, top, width, height)
            rect.setBrush(Brush)
            rect.setPen(pen)
            self.scene.addItem(rect)
        # draw the vertical grid lines
        x = left
        while x <= right:
            lVert = qtw.QGraphicsLineItem(x, top, x, bottom)
            lVert.setPen(pen)
            self.scene.addItem(lVert)
            x += Dx
        # draw the horizontal grid lines
        y = top
        while y <= bottom:
            lHor = qtw.QGraphicsLineItem(left, y, right, y)
            lHor.setPen(pen)
            self.scene.addItem(lHor)
            y += Dy
Example #6
0
 def __init__(self, scene, x0, y0, xf, yf, pen):
     self._scene = scene
     mid_x, mid_y = self._midpoint(x0, y0, xf, yf)
     self.line1 = QtWidgets.QGraphicsLineItem(x0, y0, mid_x, mid_y)
     self.line2 = QtWidgets.QGraphicsLineItem(mid_x, mid_y, xf, yf)
     self.line1.setPen(pen)
     self.line2.setPen(pen)
     self._scene.addItem(self.line1)
     self._scene.addItem(self.line2)
Example #7
0
 def __init__(self, parent):
     super(AxesGraphicsItem, self).__init__(parent)
     linePen = QtGui.QPen()
     linePen.setColor(QtCore.Qt.red)
     linePen.setWidth(2)
     linePen.setCosmetic(True)
     self.line1 = QtWidgets.QGraphicsLineItem(-1000, 0, 1000, 0, self)
     self.line1.setPen(linePen)
     self.line2 = QtWidgets.QGraphicsLineItem(0, -1000, 0, 1000, self)
     self.line2.setPen(linePen)
     self.setZValue(1000000)
Example #8
0
 def __init__(self, x1, x2, y1, y2, lineThickness, grFaktor, parent=None):
     QtWidgets.QGraphicsItemGroup.__init__(self)
     self.parent = parent
     correction = 0.85
     rx = (x1 - x2)
     ry = (y1 - y2)
     nx = rx / max(sqrt(rx**2 + ry**2), 0.1)
     ny = ry / max(sqrt(rx**2 + ry**2), 0.1)
     mx1 = (
         x1 + x2
     ) * 0.5 - ny * grFaktor * correction - 0.5 * nx * grFaktor * correction
     my1 = (
         y1 + y2
     ) * 0.5 + nx * grFaktor * correction - 0.5 * ny * grFaktor * correction
     mx2 = (
         x1 + x2
     ) * 0.5 + ny * grFaktor * correction - 0.5 * nx * grFaktor * correction
     my2 = (
         y1 + y2
     ) * 0.5 - nx * grFaktor * correction - 0.5 * ny * grFaktor * correction
     mx3 = (
         x1 + x2
     ) * 0.5 + ny * grFaktor * correction + 0.5 * nx * grFaktor * correction
     my3 = (
         y1 + y2
     ) * 0.5 - nx * grFaktor * correction + 0.5 * ny * grFaktor * correction
     mx4 = (
         x1 + x2
     ) * 0.5 - ny * grFaktor * correction + 0.5 * nx * grFaktor * correction
     my4 = (
         y1 + y2
     ) * 0.5 + nx * grFaktor * correction + 0.5 * ny * grFaktor * correction
     circle = QtWidgets.QGraphicsEllipseItem((x1 + x2) * 0.5 - grFaktor,
                                             (y1 + y2) * 0.5 - grFaktor,
                                             2.0 * grFaktor,
                                             2.0 * grFaktor,
                                             parent=parent)
     circle.setPen(
         QtGui.QPen(QtGui.QColor(255, 0, 0, 255), lineThickness,
                    QtCore.Qt.SolidLine))
     circle.setBrush(
         QtGui.QBrush(QtGui.QColor(255, 255, 255, 255),
                      QtCore.Qt.SolidPattern))
     line1 = QtWidgets.QGraphicsLineItem(mx1, my1, mx3, my3)
     line1.setPen(
         QtGui.QPen(QtGui.QColor(255, 0, 0, 255), lineThickness,
                    QtCore.Qt.SolidLine))
     line2 = QtWidgets.QGraphicsLineItem(mx2, my2, mx4, my4)
     line2.setPen(
         QtGui.QPen(QtGui.QColor(255, 0, 0, 255), lineThickness,
                    QtCore.Qt.SolidLine))
     self.addToGroup(circle)
     self.addToGroup(line1)
     self.addToGroup(line2)
    def plot_frame(self):
        width = self.width() - 8
        height = self.height() - 8
        y_trans = Translator(0, 1, 0, self.height())
        x_trans = Translator(0, 1, 0, width)

        textItems = []
        x = x_trans.t(1 - self.widthspace) + 10
        y1 = y_trans.t(self.space)
        self.scene.addLine(0, y1, x, y1, QtGui.QPen(QtCore.Qt.DashLine))
        self.top_text = TextPairWidget()
        self.top_text.setup_Widget(x)
        self.top_text.set_Widget(posY=y1)
        textItems += self.top_text.get_TextItems()

        y2 = y_trans.t(self.space + self.chartsize)
        self.scene.addLine(0, y2, x, y2, QtGui.QPen(QtCore.Qt.DashLine))
        self.bot_text = TextPairWidget()
        self.bot_text.setup_Widget(x)
        self.bot_text.set_Widget(posY=y2)
        textItems += self.bot_text.get_TextItems()

        self.current_text = TextPairWidget()
        self.current_text.setup_Widget(x, maxY=[y1, y2])
        self.current_text.set_Widget(posY=200)
        textItems += self.current_text.get_TextItems()

        self.indi_y_trans = Translator(
            150, -150,
            self.height() * (self.chartsize + (self.space * 2)),
            self.height() - (self.height() * self.space))

        y = self.indi_y_trans.t(100)
        inditop_text = QtWidgets.QGraphicsTextItem('100')
        inditop_text.setPos(x, y - 10)
        inditop_line = QtWidgets.QGraphicsLineItem(0, y, x, y)
        #self.scene.addItem(inditop_text)
        self.scene.addItem(inditop_line)

        y = self.indi_y_trans.t(-100)
        indibot_text = QtWidgets.QGraphicsTextItem('-100')
        indibot_text.setPos(x, y - 10)
        indibot_line = QtWidgets.QGraphicsLineItem(0, y, x, y)
        #self.scene.addItem(indibot_text)
        self.scene.addItem(indibot_line)

        for item in textItems:
            self.scene.addItem(item)

        self.scene.addLine(0, 0, width, 0)
        self.scene.addLine(0, height, width, height)
        self.scene.addLine(0, 0, 0, height)
        self.scene.addLine(width, 0, width, height)
def getLines(vertices):
    lines = [
        QtWidgets.QGraphicsLineItem(vertices[0][0], vertices[0][1],
                                    vertices[1][0], vertices[1][1]),
        QtWidgets.QGraphicsLineItem(vertices[0][0], vertices[0][1],
                                    vertices[2][0], vertices[2][1]),
        QtWidgets.QGraphicsLineItem(vertices[1][0], vertices[1][1],
                                    vertices[2][0], vertices[2][1])
    ]
    for each in lines:
        each.setPen(QtGui.QPen(QtCore.Qt.red, 1))
    return lines
    def drawGrid(self):
        scale_bar = QtWidgets.QGraphicsRectItem(0, 0, self.grid_width,
                                                self.note_height, self.piano)
        scale_bar.setPos(self.piano_width, 0)
        scale_bar.setBrush(QtGui.QColor(100, 100, 100))
        clearpen = QtGui.QPen(QtGui.QColor(0, 0, 0, 0))
        for i in range(self.end_octave - self.start_octave,
                       self.start_octave - self.start_octave, -1):
            for j in range(self.notes_in_octave, 0, -1):
                scale_bar = QtWidgets.QGraphicsRectItem(
                    0, 0, self.grid_width, self.note_height, self.piano)
                scale_bar.setPos(
                    self.piano_width,
                    self.note_height * j + self.octave_height * (i - 1))
                scale_bar.setPen(clearpen)
                if j % 2 == 0:
                    scale_bar.setBrush(QtGui.QColor(120, 120, 120))
                else:
                    scale_bar.setBrush(QtGui.QColor(100, 100, 100))

        measure_pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 120), 3)
        half_measure_pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 40), 2)
        line_pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 40))
        for i in range(0, int(self.num_measures) + 1):
            measure = QtWidgets.QGraphicsLineItem(
                0, 0, 0,
                self.piano_height + self.header_height - measure_pen.width(),
                self.header)
            measure.setPos(self.measure_width * i, 0.5 * measure_pen.width())
            measure.setPen(measure_pen)
            if i < self.num_measures:
                number = QtWidgets.QGraphicsSimpleTextItem(
                    '%d' % (i + 1), self.header)
                number.setPos(self.measure_width * i + 5, 2)
                number.setBrush(QtCore.Qt.white)
                for j in self.frange(
                        0, self.time_sig[0] * self.grid_div / self.time_sig[1],
                        1.):
                    line = QtWidgets.QGraphicsLineItem(0, 0, 0,
                                                       self.piano_height,
                                                       self.header)
                    line.setZValue(1.0)
                    line.setPos(self.measure_width * i + self.value_width * j,
                                self.header_height)
                    if j == self.time_sig[0] * self.grid_div / self.time_sig[
                            1] / 2.0:
                        line.setPen(half_measure_pen)
                    else:
                        line.setPen(line_pen)
Example #12
0
    def add_axis(self):
        line_length = self.scale * self.count_marks

        x_min, x_max = -line_length, line_length
        y = self.center.y()
        line_x = QtWidgets.QGraphicsLineItem()
        line_x.setLine(x_min, y, x_max, y)

        y_min, y_max = -line_length, line_length
        x = self.center.x()
        line_y = QtWidgets.QGraphicsLineItem()
        line_y.setLine(x, y_min, x, y_max)

        self.addItem(line_x)
        self.addItem(line_y)
Example #13
0
    def cityClicked(self, idx, undo=False):
        if self.currentMethod != "Manual" or self.finishedFirst:
            return

        if undo:
            if len(self.manualTour) < 2:
                return
            self.scene.removeItem(self.edgeItems.pop())
            self.removeWay((self.manualTour[-2], self.manualTour[-1]))
            self.manualTour.pop()
            self.citySelected = self.manualTour[-1]

        elif self.citySelected is None:
            c = self.getCities()
            self.currentLine = QtWidgets.QGraphicsLineItem(QtCore.QLineF(QtCore.QPointF(*c[idx]), self.cursorPosition))
            self.currentLine.setPen(self.tourPen)
            self.scene.addItem(self.currentLine)
            self.manualTour = [idx]
            self.citySelected = idx
        else:
            edge = (self.citySelected, idx)
            if idx not in self.manualTour:
                self.manualTour.append(idx)
                self.addWay(edge)
                # close to the last city
                if len(self.manualTour) == self.N:
                    self.addWay((self.manualTour[-1], self.manualTour[0]))
                    self.finishedFirst = True
                    self.scene.removeItem(self.currentLine)
                self.updateWays()

                self.citySelected = idx

        self.tourChange.emit(" ".join(map(str, self.manualTour)))
        self.update()
Example #14
0
    def mousePressEvent(self, event):
        self.begin = self.end = event.scenePos()
        self.item = self.itemAt(self.begin, QtGui.QTransform())
        if self.item:
            if self.tool == 'erase':
                self.removeItem(self.item)

            elif self.tool == "move":
                self.offset = self.begin - self.item.pos()

        elif self.tool == 'rectangle':
            self.rect = QtWidgets.QGraphicsRectItem(self.begin.x(),
                                                    self.begin.y(), 0, 0)

        elif self.tool == 'ellipse':
            self.ellipse = QtWidgets.QGraphicsEllipseItem(
                self.begin.x(), self.begin.y(), 0, 0)

        elif self.tool == 'line':
            self.line = QtWidgets.QGraphicsLineItem(self.begin.x(),
                                                    self.begin.y(),
                                                    self.end.x(), self.end.y())

        elif self.tool == 'polygon':
            c = event.scenePos()
            self.polyRects.append(
                QtWidgets.QGraphicsRectItem(c.x() - 10,
                                            c.y() - 10, 20, 20))
            self.addItem(self.polyRects[-1])
            self.polygon.append(c)
Example #15
0
 def initLayout(self):
     self.boxCornerItems = []
     for i in range(8):
         corner = QtWidgets.QGraphicsEllipseItem()
         corner.setRect(-4, -4, 8, 8)
         corner.setZValue(2.0)
         pen = corner.pen()
         pen.setWidth(1)
         if i < 4:
             pen.setColor(QtGui.QColor(0, 0, 255))
             corner.setPen(pen)
             corner.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 255)))
         else:
             pen.setColor(QtGui.QColor(0, 255, 0))
             corner.setPen(pen)
             corner.setBrush(QtGui.QBrush(QtGui.QColor(0, 255, 0)))
         self.graphicsScene.addItem(corner)
         self.boxCornerItems.append(corner)
     self.boxLineItems = []
     for i in range(12):
         line = QtWidgets.QGraphicsLineItem()
         pen = line.pen()
         pen.setWidth(3)
         if i < 4:
             pen.setColor(QtGui.QColor(0, 0, 255))
         elif i < 8:
             pen.setColor(QtGui.QColor(0, 255, 0))
         else:
             pen.setColor(QtGui.QColor(255, 0, 0))
         line.setPen(pen)
         line.setZValue(2.0 - float(i) / 12.0)
         self.graphicsScene.addItem(line)
         self.boxLineItems.append(line)
     self.updateLayout()
Example #16
0
    def mouseMoveEvent(self, event):
        # print("Scene.mouseMoveEvent()")
        self.end = event.scenePos()
        width = self.end.x() - self.begin.x()
        height = self.end.y() - self.begin.y()

        if self.item and self.tool == "move":

            self.item.setPos(event.scenePos() - self.offset)

        if self.tool == 'rectangle':
            self.removeItem(self.rect)
            self.rect = QtWidgets.QGraphicsRectItem(self.begin.x(),
                                                    self.begin.y(), width,
                                                    height)
            self.rect.setPen(self.pen)
            self.rect.setBrush(self.brush)
            self.addItem(self.rect)

        elif self.tool == 'ellipse':
            self.removeItem(self.ellipse)
            self.ellipse = QtWidgets.QGraphicsEllipseItem(
                self.begin.x(), self.begin.y(), width, height)
            self.ellipse.setPen(self.pen)
            self.ellipse.setBrush(self.brush)
            self.addItem(self.ellipse)

        elif self.tool == 'line':
            self.removeItem(self.line)
            self.line = QtWidgets.QGraphicsLineItem(self.begin.x(),
                                                    self.begin.y(),
                                                    self.end.x(), self.end.y())
            self.line.setPen(self.pen)
            self.addItem(self.line)
Example #17
0
    def mouseMoveEvent(self, event):
        if event.buttons() != QtCore.Qt.LeftButton:
            super().mouseMoveEvent(event)
            return

        start = self.start_pos
        stop = event.scenePos()
        if self.mode == GraphicsScene.Mode.Draw_line:
            if self.item_to_draw is None:
                self.item_to_draw = QtWidgets.QGraphicsLineItem()
                self.addItem(self.item_to_draw)
                self.item_to_draw.setPen(self.path_pen)

            self.current_obj = QtCore.QLineF(start, stop)
            self.item_to_draw.setLine(self.current_obj)

        elif self.mode == GraphicsScene.Mode.Draw_area:
            if self.item_to_draw is None:
                self.item_to_draw = QtWidgets.QGraphicsRectItem()
                self.addItem(self.item_to_draw)
                self.item_to_draw.setPen(self.path_pen)

            top, bottom = (stop.y(), start.y()) if start.y() > stop.y() else (start.y(), stop.y())
            left, right = (stop.x(), start.x()) if start.x() > stop.x() else (start.x(), stop.x())
            self.current_obj = QtCore.QRectF(QtCore.QPointF(left, top), QtCore.QPointF(right, bottom))
            self.item_to_draw.setRect(self.current_obj)
        else:
            super().mouseMoveEvent(event)
Example #18
0
    def mousePressEvent(self, mouseEvent):
        if (mouseEvent.button() != QtCore.Qt.LeftButton):
            return

        if self.myMode == self.InsertItem:
            item = DiagramItem(self.myItemType, self.myItemMenu)
            item.setBrush(self.myItemColor)
            self.addItem(item)
            item.setPos(mouseEvent.scenePos())
            self.itemInserted.emit(item)
        elif self.myMode == self.InsertLine:
            self.line = QtWidgets.QGraphicsLineItem(
                QtCore.QLineF(mouseEvent.scenePos(), mouseEvent.scenePos()))
            self.line.setPen(QtGui.QPen(self.myLineColor, 2))
            self.addItem(self.line)
        elif self.myMode == self.InsertText:
            textItem = DiagramTextItem()
            textItem.setFont(self.myFont)
            textItem.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction)
            textItem.setZValue(1000.0)
            textItem.lostFocus.connect(self.editorLostFocus)
            textItem.selectedChange.connect(self.itemSelected)
            self.addItem(textItem)
            textItem.setDefaultTextColor(self.myTextColor)
            textItem.setPos(mouseEvent.scenePos())
            self.textInserted.emit(textItem)

        super(DiagramScene, self).mousePressEvent(mouseEvent)
Example #19
0
    def _InitUI(self):
        self.setFiltersChildEvents(False)
        oFrom = QtWidgets.QGraphicsEllipseItem()
        oTo = QtWidgets.QGraphicsRectItem()
        oLine = QtWidgets.QGraphicsLineItem()

        self.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable)
        pen = oFrom.pen()
        pen.setWidth(2)
        pen.setColor(QColor(0, 160, 230))
        oFrom.setPen(pen)
        oTo.setPen(pen)
        oLine.setPen(pen)

        oFrom.setBrush(QColor(247, 160, 57))
        oTo.setBrush(QColor(247, 160, 57))

        self.addToGroup(oFrom)
        self.addToGroup(oTo)
        self.addToGroup(oLine)

        length = 50
        oFrom.setRect(QRectF(-length/2, -length/2, length, length))
        oTo.setRect(QRectF(-length/2, -length/2, length, length))

        oFrom.setPos(80, 80)
        oTo.setPos(200, 150)
        oLine.setLine(QLineF(oFrom.pos(), oTo.pos()))
Example #20
0
    def drawLine(self, endX, endY, width, scene):
        """First, remove the existing line item, if any, from the graphics
        scene. Then create a new line item whose start point coordinates are
        the coordinates of initialPoint, whose end point coordinates are
        (endX, endY), and with pen width width. Add the newly created line
        to scene, a QGraphicsScene. 
        """

        # if this reference line already has a line attribute, remove it from
        # the graphics scene
        if self.line:
            scene.removeItem(self.line)

        # set a minimum pen width
        if width < 1:
            width = 1

        # create a QGraphicsLineItem with the appropriate start and end
        # coordinates
        startX = self.initialPoint.rect().center().x()
        startY = self.initialPoint.rect().center().y()
        self.line = QtWidgets.QGraphicsLineItem(startX, startY, endX, endY)

        # create a pen for the line using the reference line colour
        linePen = QtGui.QPen(constants.REFLINECOLOR)
        # set the width of the pen to width
        linePen.setWidth(width)
        # set the newly created pen as the line's pen
        self.line.setPen(linePen)

        # add the line to the graphics scene
        scene.addItem(self.line)
Example #21
0
    def mouseMoveEvent(self, event):

        # disable middle-mouse button press
        if event.button() == QtCore.Qt.MiddleButton:
            self.draw = False
            return

        # call parent event
        super(AnnotationScene, self).mouseMoveEvent(event)

        # if in drawing mode
        if self.draw:

            # add to points
            p = event.scenePos().toPoint()

            # clip to image size
            x, y = self.clip_to_image(p.x(), p.y())

            self.points.append(x)
            self.points.append(y)

            # current line
            l = QtWidgets.QGraphicsLineItem(
                QtCore.QLineF(self.points[-4], self.points[-3],
                              self.points[-2], self.points[-1]))
            l.setPen(self.pen)
            self.lines.append(l)

            #   draw current line
            self.addItem(self.lines[-1])
 def plot_currentCandle(self, candles):
     candleswidth = self.width() / len(candles) * self.candleWidth
     self.__calculate_chart_translations(candles)
     for candle in self.currentCandle:
         self.scene.removeItem(candle)
     self.currentCandle.clear()
     candle = candles[0]
     graphic = self.__get_candleGraphic(candle, candleswidth, 0)
     graphic[2].setWidth(1)
     graphic[2].setStyle(QtCore.Qt.DashLine)
     y = self.chart_y_trans.t(candle.close)
     newline2 = QtWidgets.QGraphicsLineItem(
         0,
         int(y),
         self.width() - (self.width() * self.widthspace),
         int(y),
     )
     newline2.setPen(graphic[2])
     change = ((candle.close - candle.open) / candle.open) * 100
     self.current_text.set_Widget(price=candle.close,
                                  precentage=change,
                                  posY=y)
     self.currentCandle.append(newline2)
     self.currentCandle.append(graphic[0])
     self.currentCandle.append(graphic[1])
     self.scene.addItem(newline2)
     self.scene.addItem(graphic[0])
     self.scene.addItem(graphic[1])
Example #23
0
    def mouseMoveEvent(self, event):
        # disable middle-mouse button press
        if event.button() == QtCore.Qt.MiddleButton:
            self.state = None
            return

        # Call parent's event handler
        super(AnnotationObject, self).mouseMoveEvent(event)
        # self.setSelected(True)

        if self.state == 'modify':
            # Modifying the contour -> collecting points
            p = event.scenePos().toPoint()
            self.modified_points += [p.x(), p.y()]

            # current line
            l = QtWidgets.QGraphicsLineItem(
                QtCore.QLineF(self.modified_points[-4],
                              self.modified_points[-3],
                              self.modified_points[-2],
                              self.modified_points[-1]))
            l.setPen(self.pen())
            self.lines.append(l)

            #   draw current line
            self.scene().addItem(self.lines[-1])
Example #24
0
    def make_arrow_obj(self):

        r_2 = QtCore.QPointF(self.scale_factor * self.p2[0], self.scale_factor * self.p2[1])
        r_1 = QtCore.QPointF(self.scale_factor * self.p1[0], self.scale_factor * self.p1[1])

        r_vec = r_2 - r_1
        r_mag = np.sqrt((r_2.x() - r_1.x()) ** 2 + (r_2.y() - r_1.y()) ** 2)
        factor = self.r / (r_mag * 2)

        k_2 = r_1 + (1 - factor) * r_vec

        theta = np.pi / 4

        l_3 = - factor * QtCore.QPointF(r_vec.x() * np.cos(theta) + r_vec.y() * np.sin(theta), - r_vec.x() * np.sin(theta) + r_vec.y() * np.cos(theta))
        l_3 = k_2 + l_3
        l_4 = - factor * QtCore.QPointF(r_vec.x() * np.cos(-theta) + r_vec.y() * np.sin(-theta), - r_vec.x() * np.sin(-theta) + r_vec.y() * np.cos(-theta))
        l_4 = k_2 + l_4

        tri_2 = (k_2, l_3, l_4)

        poly_2 = QtGui.QPolygonF(tri_2)

        line = QtWidgets.QGraphicsLineItem(self.scale_factor * self.p1[0],
                                           self.scale_factor * self.p1[1],
                                           self.scale_factor * self.p2[0],
                                           self.scale_factor * self.p2[1])
        head_2 = QtWidgets.QGraphicsPolygonItem(poly_2)

        self.addToGroup(line)
        self.addToGroup(head_2)
        self.setZValue(-1)
Example #25
0
 def initLine(self):
     self.line = QtWidgets.QGraphicsLineItem(self)
     pen = self.line.pen()
     pen.setWidth(3)
     pen.setStyle(Qt.DashDotLine)
     pen.setColor(self.source.pen().color())
     self.line.setPen(pen)
     self.updateLine()
 def drawPlayHead(self):
     self.play_head = QtWidgets.QGraphicsLineItem(self.piano_width,
                                                  self.header_height,
                                                  self.piano_width,
                                                  self.total_height)
     self.play_head.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255, 50), 2))
     self.play_head.setZValue(1.)
     self.addItem(self.play_head)
Example #27
0
    def __init__(self, col, view):
        x1 = col[0] * 2.6
        y1 = col[1] * 2.6
        x2 = col[2] * 2.6
        y2 = col[3] * 2.6

        line = QtWidgets.QGraphicsLineItem(x1, -y1, x2, -y2)
        view.AddItem(line)
Example #28
0
 def set_vertical_line(self, x):
     x = self.mapToPosition(QPointF(x, 0)).x()
     try:
         self.line.setLine(x, 0, x, 999)
     except AttributeError:
         line = QtWidgets.QGraphicsLineItem(x, 0, x, 999)
         self.widget.scene().addItem(line)
         self.line = line
Example #29
0
 def get_q_line_item(self):
     l = QtWidgets.QGraphicsLineItem()
     l.setLine(self.p1.x() * self.magnification,
               self.p1.y() * self.magnification,
               self.p2.x() * self.magnification,
               self.p2.y() * self.magnification)
     #l.setPen(self.pen)
     #self.item_group.addToGroup(l)
     return l
Example #30
0
    def make_arrow_obj(self):

        line = QtWidgets.QGraphicsLineItem(self.scale_factor * self.p1[0],
                                           self.scale_factor * self.p1[1],
                                           self.scale_factor * self.p2[0],
                                           self.scale_factor * self.p2[1])

        self.addToGroup(line)
        self.setZValue(-1)