Esempio n. 1
0
 def draw_ticks(self, rectspace, painter):
     '''
     draws the ticks of the axis
     '''
     painter.save()
     painter.scale(
         ((self.width() - self.side_space * 2) / (len(self.freq_value))), 1)
     # Skalieren auf Anzahl der Werte
     painter.setPen(QtGui.QPen(QtGui.QBrush(QtCore.Qt.black), 0))
     start_point = 0
     #Schleife für x-Achse
     for _ in range(0, len(self.db_value), 1):
         painter.drawLine(
             QtCore.QLineF(start_point + (rectspace / 2), 0,
                           start_point + (rectspace / 2), 3))
         #x achse einheiten striche
         start_point = start_point + rectspace
     painter.restore()
     painter.save()
     painter.scale(1,
                   -((self.height() - self.side_space * 2) / self.y_anzahl))
     # Skalieren auf Anzahl der Werte
     painter.setPen(QtGui.QPen(QtGui.QBrush(QtCore.Qt.black), 0))
     y_axis = 0
     anzahl_striche = 5
     for _ in range(0, anzahl_striche):
         painter.drawLine(QtCore.QLineF(-5, y_axis, 0, y_axis))
         #y achse einheiten striche
         y_axis = y_axis + self.y_anzahl / (anzahl_striche - 1)
     painter.restore()
Esempio n. 2
0
 def genererlinedroite(self, index=0):
     if self.nbchild(self.listwid[index].name) > 0:
         maxx = 0 
         miny = 1000000
         minx = 1000000
         for i in range(len(self.listwid)):
             if self.listwid[i].parent == self.listwid[index].name:
                 centre = self.listwid[i].wid.windowFrameGeometry().center()
                 top = self.listwid[i].wid.windowFrameGeometry().topLeft()
                 if centre.x() < minx:
                     minx = centre.x()
                 if centre.x() > maxx:
                     maxx = centre.x()
                 if top.y() < miny:
                     miny = top.y()
         posybar = (miny + self.listwid[index].wid.windowFrameGeometry().bottomLeft().y())//2
         minbar = QtCore.QPointF(minx, posybar)
         maxbar =  QtCore.QPointF(maxx, posybar)
         self.listline.append(QtGui.QGraphicsLineItem(QtCore.QLineF(self.listwid[index].wid.windowFrameGeometry().center(), QtCore.QPointF(self.listwid[index].wid.windowFrameGeometry().center().x(), posybar))))
         self.listline.append(QtGui.QGraphicsLineItem(QtCore.QLineF(minbar, maxbar)))
         for i in range(len(self.listwid)):
             if self.listwid[i].parent == self.listwid[index].name:
                 centre = self.listwid[i].wid.windowFrameGeometry().center()
                 self.listline.append(QtGui.QGraphicsLineItem(QtCore.QLineF(centre, QtCore.QPointF(centre.x(), posybar))))
                 self.genererlinedroite(i)
Esempio n. 3
0
    def addLink(self, orig, dest):
        planetFrom = orig
        planetTo = dest

        if orig > dest:
            planetFrom = dest
            planetTo = orig

        line = QtCore.QLineF(self.control_points[planetFrom].x,
                             self.control_points[planetFrom].y,
                             self.control_points[planetTo].x,
                             self.control_points[planetTo].y)
        for link in self.links:
            for dest in self.links[link]:
                otherLine = QtCore.QLineF(self.control_points[link].x,
                                          self.control_points[link].y,
                                          self.control_points[dest].x,
                                          self.control_points[dest].y)
                intersection = QtCore.QPointF()

                if otherLine.intersect(line, intersection) == 1:
                    if line.p1() != intersection and line.p2() != intersection:
                        return

        if planetFrom in self.links:
            if not planetTo in self.links[planetFrom]:
                self.links[planetFrom].append(planetTo)
        else:
            self.links[planetFrom] = [planetTo]
Esempio n. 4
0
    def __init__(self, parent):
        self.parent = parent

        sizex = 2000
        sizey = 2000

        self.space_size = QtGui.QVector3D(sizex, sizey, 0)

        self.COLOR_FACTIONS = self.parent.COLOR_FACTIONS

        self.star_field = []
        self.control_points = {}
        self.links = {}

        self.sectors = {}

        p1 = QtCore.QPointF(-self.space_size.x() - 50,
                            -self.space_size.y() - 50)
        p2 = QtCore.QPointF(-self.space_size.x() - 50,
                            self.space_size.y() + 50)
        p3 = QtCore.QPointF(self.space_size.x() + 50, self.space_size.y() + 50)
        p4 = QtCore.QPointF(self.space_size.x() + 50,
                            -self.space_size.y() - 50)

        line1 = QtCore.QLineF(p1, p2)
        line2 = QtCore.QLineF(p2, p3)
        line3 = QtCore.QLineF(p3, p4)
        line4 = QtCore.QLineF(p4, p1)

        self.boundLines = [line1, line2, line3, line4]

        self.finalPolys = {}
Esempio n. 5
0
    def __init__(self, tf, parent=None):
        QtGui.QGraphicsScene.__init__(self, parent)
        self._tf_items = []
        poly = TransferFunctionPolygon()
        poly.setup()
        self._tf_poly = poly
        self.addItem(poly)
        self.create_tf_items(tf)
        #current scale
        self._sx = 1.0
        self._sy = 1.0
        # Add outlines
        line_color = QtGui.QColor(200, 200, 200)
        pen = QtGui.QPen(line_color)
        ps = [
            QtCore.QPointF(0.0, 0.0),
            QtCore.QPointF(1.0, 0.0),
            QtCore.QPointF(1.0, 1.0),
            QtCore.QPointF(0.0, 1.0)
        ]
        outline = QtGui.QPolygonF(ps)
        self.addPolygon(outline, pen)

        for i in xrange(51):
            u = float(i) / 50.0
            self.addLine(QtCore.QLineF(u, 0.0, u, 1.0), pen)
            self.addLine(QtCore.QLineF(0.0, u, 1.0, u), pen)
Esempio n. 6
0
    def point_changed(self, pt, finished):

        self.poly.setPoint(self.pts.index(pt), pt.pos().toPoint())

        ps = self.poly.size()

        # TODO what to do with shuffled points? should be fixed...
        for i in range(2, ps + 2):

            line1 = QtCore.QLineF(self.poly.point(i - 2),
                                  self.poly.point((i - 1) % ps))
            line2 = QtCore.QLineF(self.poly.point((i - 1) % ps),
                                  self.poly.point(i % ps))

            a1 = line1.angle()
            a2 = line2.angle()

            d = a2 - a1

            if d < 0:
                d = 360 + d

            if d < 315 and d > 180:

                self.convex = False
                break
        else:
            self.convex = True

        self.__update_desc_pos()
        self.update()

        if finished and self.convex and self.polygon_changed is not None:
            self.polygon_changed(self.get_poly_points())
Esempio n. 7
0
    def resizeFromData(self):
        # Do nothing if no fit exists.
        if len(self.data.fitdata.residuals.values) == 0:
            return

        timeModifier = self.width / float(self.data.timeSpan)
        residualsModifier = self.height / float(
            self.data.fitdata.residuals.span)
        lastTime = None
        lastResidual = None
        children = self.child.childItems()
        for t in range(
                0,
                self.data.fitTimePointer[1] - self.data.fitTimePointer[0] + 1):
            time = (self.data.time[self.data.fitTimePointer[0] + t] -
                    self.data.minTime) * timeModifier
            residual = self.height - (
                self.data.fitdata.residuals.values[t] -
                self.data.fitdata.residuals.min) * residualsModifier
            if lastTime is not None:
                line = QtCore.QLineF(lastTime, lastResidual, time, residual)
                children[t - 1].setLine(line)
            lastTime = time
            lastResidual = residual

        # Update zero line
        oldLine = children[-1].line()
        line = QtCore.QLineF(oldLine.x1(), oldLine.y1(), self.width,
                             oldLine.y2())
        children[-1].setLine(line)
 def mouseMoveEvent(self, event):
     super(PhotoViewer, self).mouseMoveEvent(event)
     for varI in range(len(self.lineItem)):
         self._scene.removeItem(self.lineItem[0])
         del self.lineItem[0]
     if self.boolSetPath:
         position = self.mapToScene(event.pos(
         ))  #QtCore.QPointF(event.pos()) - item.rectF.center()
         if self.bbStart:
             wh = position - QtCore.QPointF(self.globalItem[-1].rect().x(),
                                            self.globalItem[-1].rect().y())
             self.globalItem[-1].setRect(self.globalItem[-1].rect().x(),
                                         self.globalItem[-1].rect().y(),
                                         wh.x(), wh.y())
         else:
             self.lineItem.append(
                 QtGui.QGraphicsLineItem(
                     QtCore.QLineF(
                         QtCore.QPointF(position.x(), 0),
                         QtCore.QPointF(
                             position.x(),
                             self._photo.pixmap().rect().height()))))
             self.lineItem[0].setPen(
                 QtGui.QPen(QtCore.Qt.cyan, 0.5, QtCore.Qt.DashLine))
             self._scene.addItem(self.lineItem[0])
             self.lineItem.append(
                 QtGui.QGraphicsLineItem(
                     QtCore.QLineF(
                         QtCore.QPointF(0, position.y()),
                         QtCore.QPointF(self._photo.pixmap().rect().width(),
                                        position.y()))))
             self.lineItem[-1].setPen(
                 QtGui.QPen(QtCore.Qt.cyan, 0.5, QtCore.Qt.DashLine))
             self._scene.addItem(self.lineItem[-1])
         self._scene.update()
Esempio n. 9
0
    def refreshLine(self):
        Lines = self.items()
        Line = [x for x in Lines if isinstance(x, QtGui.QGraphicsLineItem)]
        for i in range(len(Line)):
            self.scene().removeItem(Line[i])

        start = QtCore.QPoint(-self.viewport().width() / 2,
                              self.viewport().height() / 2)
        end = self.breakList[0].rect().center() + self.breakList[0].pos()
        self.scene().addItem(QtGui.QGraphicsLineItem(QtCore.QLineF(start,
                                                                   end)))

        for i in range(len(self.breakList) - 1):
            start = self.breakList[i].rect().center() + self.breakList[i].pos()
            end = self.breakList[i +
                                 1].rect().center() + self.breakList[i +
                                                                     1].pos()
            self.scene().addItem(
                QtGui.QGraphicsLineItem(QtCore.QLineF(start, end)))

        start = self.breakList[-1].rect().center() + self.breakList[-1].pos()
        end = QtCore.QPoint(self.viewport().width() / 2,
                            -self.viewport().height() / 2)
        self.scene().addItem(QtGui.QGraphicsLineItem(QtCore.QLineF(start,
                                                                   end)))
Esempio n. 10
0
    def paint(self, painter, option, widget=None):
        """
        Draw the representation.
        """
        if (self.source.collidesWithItem(self.dest)):
            return
        painter.setRenderHint(QtGui.QPainter.Antialiasing,
                              options["smoothing"])

        if self.device_type == "Wireless_Connection":
            pen = QtGui.QPen()
            pen.setDashPattern([10, 10])
            painter.setPen(pen)

        painter.drawLine(self.line())

        if self.isSelected():
            painter.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.DashLine))

            baseLine = QtCore.QLineF(0, 0, 1, 0)
            myLine = QtCore.QLineF(self.line())
            angle = math.radians(myLine.angle(baseLine))
            myLine.translate(4.0 * math.sin(angle), 4.0 * math.cos(angle))
            painter.drawLine(myLine)
            myLine.translate(-8.0 * math.sin(angle), -8.0 * math.cos(angle))
            painter.drawLine(myLine)
Esempio n. 11
0
    def update(self):
        # Remove the old axis.
        self.removeFromGroup(self.child)
        self.scene().removeItem(self.child)
        self.child = QtGui.QGraphicsItemGroup()
        self.child.setParentItem(self)

        line = QtGui.QGraphicsLineItem(QtCore.QLineF(0, 0, self.width, 0))
        line.setParentItem(self.child)

        # Calculate and draw tics.
        timeSpan = float(self.maxTime - self.minTime)
        bigTicSpan = float(1e10)
        while math.fmod(timeSpan, bigTicSpan) == timeSpan:
            bigTicSpan /= 10
        if timeSpan / bigTicSpan < 2:
            bigTicSpan /= 10
        ticSpan = bigTicSpan / 10
        ticTime = self.minTime - math.fmod(self.minTime, ticSpan)
        if ticTime < self.minTime:
            ticTime += ticSpan
        bigTicTime = self.minTime + bigTicSpan - math.fmod(
            self.minTime, bigTicSpan)
        count = 10 - int((bigTicTime - self.minTime) / ticSpan)
        time = ticTime
        maxValuesHeight = 0
        while time < self.maxTime:
            ticlen = 10
            ticx = ((time - self.minTime) * self.width) / timeSpan
            if count % 10 == 0:
                # Normalize time
                diff = math.fmod(time, ticSpan)
                time = time - diff
                if diff > ticSpan / 2.0:
                    time = time + ticSpan
                elif -diff > ticSpan / 2.0:
                    time = time - ticSpan

                text = QtGui.QGraphicsTextItem(str(time))
                text.setFont(variables.timeAxisValuesFont.value())
                text.setPos(ticx - text.boundingRect().width() / 2, 13)
                maxValuesHeight = max(maxValuesHeight,
                                      text.boundingRect().height())
                text.setParentItem(self.child)

                ticlen = 15

            tic = QtGui.QGraphicsLineItem(QtCore.QLineF(ticx, 0, ticx, ticlen))
            tic.setParentItem(self.child)
            time += ticSpan
            count += 1

        # Sets and displays axis label.
        if variables.timeAxisCaptionEnabled.value():
            text = QtGui.QGraphicsTextItem(variables.timeAxisCaption.value())
            text.setFont(variables.timeAxisCaptionFont.value())
            text.setPos(self.width - text.boundingRect().width(),
                        maxValuesHeight)
            text.setParentItem(self.child)
Esempio n. 12
0
    def ArrangeData(self):
        '''
        create self.Graph which contains the data that should be shown on the monitor
        :return:
        '''

        self.Graph={}

        for k in self.data.keys():
            data=self.data[k]
            start=data.index.tolist()[-self.period]

            self.Graph[k]=data[data.index>=start]

        Max=[]
        Min=[]
        for v in self.Graph.values():

            for c in ['x','y']:
                Max.append(max(v[c].tolist()))
                Min.append(min(v[c].tolist()))

        MaxValue=max(Max)-100
        MinValue=min(Min)-100

        edge=max([abs(MaxValue),abs(MinValue)])*1.1

        halfY=(self.height()-self.highedge-self.lowedge)/2
        halfX=(self.width()-self.leftedge-self.rightedge)/2

        for v in self.Graph.keys():
            graph=self.Graph[v]
            points=[]
            for i in graph.index:

                x=(graph.get_value(i,'x')-100)/edge*halfX
                y=(graph.get_value(i,'y')-100)/edge*halfY

                points.append(QtCore.QPointF(x,y))


            self.Graph[v].insert(3,'QPoint',points)


        rect=QtCore.QRectF(QtCore.QPointF(halfX,halfY),
                           QtCore.QPointF(-halfX,-halfY))

        cdepth=100
        calpha=35
        self.BackGround={
            'back':rect,
            'x':QtCore.QLineF(-halfX,0,halfX,0),
            'y':QtCore.QLineF(0,-halfY,0,halfY),
            'leftup':[QtCore.QRectF(QtCore.QPointF(-halfX,halfY),QtCore.QPointF(0,0)),QtGui.QColor(0,cdepth,cdepth,calpha)],
            'rightup':[QtCore.QRectF(QtCore.QPointF(halfX,halfY),QtCore.QPointF(0,0)),QtGui.QColor(cdepth,0,cdepth,calpha)],
            'leftdown':[QtCore.QRectF(QtCore.QPointF(-halfX,-halfY),QtCore.QPointF(0,0)),QtGui.QColor(cdepth,cdepth,0,calpha)],
            'rightdown':[QtCore.QRectF(QtCore.QPointF(halfX,-halfY),QtCore.QPointF(0,0)),QtGui.QColor(cdepth,cdepth,cdepth,calpha)]

        }
    def __init__(self, line_or_point, follows=None):
        super(GuideLine, self).__init__(follows)

        if isinstance(line_or_point, QtCore.QLineF):
            self.line = line_or_point
        elif follows is not None:
            self.line = QtCore.QLineF(self.prevGuide.endPos(), line_or_point)
        else:
            self.line = QtCore.QLineF(QtCore.QPointF(0, 0), line_or_point)
Esempio n. 14
0
 def undirectionLine(self, x1, y1, x2, y2):
     Line = QtCore.QLineF(x1, y1, x2, y2)
     Line.setLength(10)
     F1 = Line.p2()
     Line = QtCore.QLineF(x2, y2, x1, y1)
     Line.setLength(10)
     F2 = Line.p2()
     Line = QtCore.QLineF(F1, F2)
     self.addLine(Line)
Esempio n. 15
0
    def drawBackground(self, painter, rect):
        """
        override to drawBackground method to draw custom background
        :param painter: painter object
        :param rect: view rectangle
        :return: None
        """
        painter.fillRect(rect, self._background_color)

        left = int(rect.left()) - (int(rect.left()) % self._grid_size)
        top = int(rect.top()) - (int(rect.top()) % self._grid_size)

        # Draw horizontal fine lines
        grid_lines = []
        painter.setPen(self._grid_penS)
        y = float(top)
        while y < float(rect.bottom()):
            grid_lines.append(QtCore.QLineF(rect.left(), y, rect.right(), y))
            y += self._grid_size
        painter.drawLines(grid_lines)

        # Draw vertical lines
        grid_lines = []
        painter.setPen(self._grid_penL)
        x = float(left)
        while x < float(rect.right()):
            grid_lines.append(QtCore.QLineF(x, rect.top(), x, rect.bottom()))
            x += self._grid_size
        painter.drawLines(grid_lines)

        # Draw thick grid
        left = int(rect.left()) - (int(rect.left()) % self._grid_size_course)
        top = int(rect.top()) - (int(rect.top()) % self._grid_size_course)

        # Draw vertical thick lines
        grid_lines = []
        painter.setPen(self._grid_penL)
        x = left
        while x < rect.right():
            grid_lines.append(QtCore.QLineF(x, rect.top(), x, rect.bottom()))
            x += self._grid_size_course
        painter.drawLines(grid_lines)

        # Draw horizontal thick lines
        grid_lines = []
        painter.setPen(self._grid_penL)
        y = top
        while y < rect.bottom():
            grid_lines.append(QtCore.QLineF(rect.left(), y, rect.right(), y))
            y += self._grid_size_course
        painter.drawLines(grid_lines)

        return super(GraphView, self).drawBackground(painter, rect)
Esempio n. 16
0
	def circGate(self,gateId,qbset):

		beg = 80
		xsp = 50
		ysp = 40

		for i in range (0,len(qbset)):
		 	if qbset[i]+1 > self.drawMaxQ:
			    self.drawMaxQ = qbset[i]+1

		pen = QtGui.QPen(QtCore.Qt.black)
		qubits = 50
		for i in range(0,qubits):
			self.qcircuit.addLine(QtCore.QLineF(beg+xsp*self.circTick,i*40+12,beg+xsp*(self.circTick+1),i*40+12),pen)
		
		penG = QtGui.QPen(QtCore.Qt.gray)
		fill = QtGui.QBrush(QtCore.Qt.cyan)
		rsz = 24
		csz = 14
		if gateId < 9:
			qbt = qbset[0]
			self.qcircuit.addRect(QtCore.QRectF(beg+xsp*self.circTick,ysp*qbt,rsz,rsz),penG,fill)
			t = self.qcircuit.addText(self.gateNames[gateId])
			t.setPos(beg+xsp*self.circTick+4,ysp*qbt)
		elif gateId == 9:
			qbc1 = qbset[0]
			qbt = qbset[1]
			self.qcircuit.addLine(QtCore.QLineF(beg+xsp*self.circTick+5+7,ysp*qbc1+5+7,beg+xsp*self.circTick+12,ysp*qbt+12),penG)
			self.qcircuit.addEllipse(QtCore.QRectF(beg+xsp*self.circTick+(rsz-csz)/2,ysp*qbc1+(rsz-csz)/2,csz,csz),penG,QtCore.Qt.black)
			self.qcircuit.addRect(QtCore.QRectF(beg+xsp*self.circTick,ysp*qbt,rsz,rsz),penG,fill)
			t = self.qcircuit.addText("X")
			t.setPos(beg+xsp*self.circTick+4,ysp*qbt)
		elif gateId == 11:
			qbc2 = qbset[0]
			qbc1 = qbset[1]
			qbt = qbset[2]
			self.qcircuit.addLine(QtCore.QLineF(beg+xsp*self.circTick+5+7,ysp*qbc1+5+7,beg+xsp*self.circTick+12,ysp*qbt+12),penG)
			self.qcircuit.addLine(QtCore.QLineF(beg+xsp*self.circTick+5+7,ysp*qbc2+5+7,beg+xsp*self.circTick+12,ysp*qbt+12),penG)
			self.qcircuit.addEllipse(QtCore.QRectF(beg+xsp*self.circTick+(rsz-csz)/2,ysp*qbc1+(rsz-csz)/2,csz,csz),penG,QtCore.Qt.black)
			self.qcircuit.addEllipse(QtCore.QRectF(beg+xsp*self.circTick+(rsz-csz)/2,ysp*qbc2+(rsz-csz)/2,csz,csz),penG,QtCore.Qt.black)
			self.qcircuit.addRect(QtCore.QRectF(beg+xsp*self.circTick,ysp*qbt,rsz,rsz),penG,fill)
			t = self.qcircuit.addText("X")
			t.setPos(beg+xsp*self.circTick+4,ysp*qbt)
		elif gateId >= 12:		# Display
			if gateId == 13:
				fill = QtGui.QBrush(QtCore.Qt.green)
			self.qcircuit.addRect(QtCore.QRectF(beg+xsp*self.circTick,ysp*0,rsz,ysp*int(self.drawMaxQ-1)+rsz),penG,fill)
			for qbt in range(0,int(self.drawMaxQ)):
				t = self.qcircuit.addText(self.gateNames[gateId])
				t.setPos(beg+xsp*self.circTick+1,ysp*qbt)
		pen.setStyle(QtCore.Qt.DotLine)
		self.qcircuit.addLine(QtCore.QLineF(beg+xsp*self.circTick-xsp/4,0,beg+xsp*self.circTick-xsp/4,ysp*qubits-ysp/4),pen)
		self.circTick = self.circTick + 1   # allow parallel scheduling
Esempio n. 17
0
    def paint(self, painter, option, widget=None):
        if (self.myStartItem.collidesWithItem(self.myEndItem)):
            return

        myStartItem = self.myStartItem
        myEndItem = self.myEndItem
        myColor = self.myColor
        myPen = self.pen()
        myPen.setColor(self.myColor)
        arrowSize = 20.0
        painter.setPen(myPen)
        painter.setBrush(self.myColor)

        centerLine = QtCore.QLineF(myStartItem.pos(), myEndItem.pos())
        endPolygon = myEndItem.polygon()
        p1 = endPolygon.first() + myEndItem.pos()

        intersectPoint = QtCore.QPointF()
        for i in endPolygon:
            p2 = i + myEndItem.pos()
            polyLine = QtCore.QLineF(p1, p2)
            intersectType = polyLine.intersect(centerLine, intersectPoint)
            if intersectType == QtCore.QLineF.BoundedIntersection:
                break
            p1 = p2

        self.setLine(QtCore.QLineF(intersectPoint, myStartItem.pos()))
        line = self.line()

        angle = math.acos(line.dx() / line.length())
        if line.dy() >= 0:
            angle = (math.pi * 2.0) - angle

        arrowP1 = line.p1() + QtCore.QPointF(
            math.sin(angle + math.pi / 3.0) * arrowSize,
            math.cos(angle + math.pi / 3) * arrowSize)
        arrowP2 = line.p1() + QtCore.QPointF(
            math.sin(angle + math.pi - math.pi / 3.0) * arrowSize,
            math.cos(angle + math.pi - math.pi / 3.0) * arrowSize)

        self.arrowHead.clear()
        for point in [line.p1(), arrowP1, arrowP2]:
            self.arrowHead.append(point)

        painter.drawLine(line)
        painter.drawPolygon(self.arrowHead)
        if self.isSelected():
            painter.setPen(QtGui.QPen(myColor, 1, QtCore.Qt.DashLine))
            myLine = QtCore.QLineF(line)
            myLine.translate(0, 4.0)
            painter.drawLine(myLine)
            myLine.translate(0, -8.0)
            painter.drawLine(myLine)
Esempio n. 18
0
    def drawBackground(self, painter, rect):
        self.setBackgroundBrush(QtCore.Qt.white)

        pen = QtGui.QPen(QtGui.QColor("grey"))
        pen.setWidth(1)
        painter.setPen(pen)

        line1 = QtCore.QLineF(0, 0, 0, self.height())
        line2 = QtCore.QLineF(0, self.height(), self.width(), self.height())
        line3 = QtCore.QLineF(self.width(), self.height(), self.width(), 0)
        line4 = QtCore.QLineF(self.width(), 0, 0, 0)
        painter.drawLines([line1, line2, line3, line4])
Esempio n. 19
0
 def _drawrubberrect(self,spt,ept):
     #在鼠标绘图上绘制橡皮线,橡皮线使用的世界坐标
     pixpainter=PyQt4.QtGui.QPainter(self.mouseviewpix)
     pixpainter.setWindow(0, 0, self.width(), self.height())
     pixpainter.setWorldMatrixEnabled(True)
     pixpainter.setWorldTransform(self.transform1)
     oldpen = pixpainter.pen()
     pixpainter.setPen(self._graphcfg.crossline)
     pixpainter.drawLine(QtCore.QLineF(spt[0],spt[1],ept[0],spt[1]))
     pixpainter.drawLine(QtCore.QLineF(ept[0],spt[1],ept[0],ept[1]))
     pixpainter.drawLine(QtCore.QLineF(ept[0],ept[1],spt[0],ept[1]))
     pixpainter.drawLine(QtCore.QLineF(spt[0],ept[1],spt[0],spt[1]))
     pixpainter.setPen(oldpen)
     pixpainter.end()
Esempio n. 20
0
 def on_state_moved(self, name):
     name = str(name)
     sw = self._states_dict[name]
     x = sw.x() + sw.widget().width() / 2
     y = sw.y() + sw.widget().height() / 2
     if name in self._transition_source_dict:
         for line in self._transition_source_dict[name]:
             l = line.line()
             new_l = QtCore.QLineF(x, y, l.x2(), l.y2())
             line.setLine(new_l)
     if name in self._transition_target_dict:
         for line in self._transition_target_dict[name]:
             l = line.line()
             new_l = QtCore.QLineF(l.x1(), l.y1(), x, y)
             line.setLine(new_l)
Esempio n. 21
0
    def drawBackground(self, painter, rect):
        left = int(rect.left()) - (int(rect.left()) % self.gridSize)
        right = int(rect.right())
        top = int(rect.top()) - (int(rect.top()) % self.gridSize)
        bottom = int(rect.bottom())

        lines = []

        for x in range(left, right, self.gridSize):
            lines.append(QtCore.QLineF(x, rect.top(), x, rect.bottom()))
        for y in range(top, bottom, self.gridSize):
            lines.append(QtCore.QLineF(rect.left(), y, rect.right(), y))
        painter.setRenderHint(QtGui.QPainter.Antialiasing, False)
        painter.setPen(QtGui.QPen(QtCore.Qt.gray, 0))
        painter.drawLines(lines)
Esempio n. 22
0
    def paint(self, painter, option, widget=None):
        #if (self.myStartItem.collidesWithItem(self.myEndItem)):
        #return

        myStartItem = self.myStartItem
        myEndItem = self.myEndItem
        myPen = self.pen()
        myPen.setColor(self.myColor)
        arrowSize = 6.0
        painter.setPen(myPen)
        painter.setBrush(self.myColor)

        centerLine = QtCore.QLineF(myStartItem.pos(), myEndItem.pos())
        endPolygon = myEndItem.polygon()
        p1 = endPolygon.first() + myEndItem.pos()

        intersectPoint = QtCore.QPointF()
        for i in endPolygon:
            p2 = i + myEndItem.pos()
            polyLine = QtCore.QLineF(p1, p2)
            intersectType = polyLine.intersect(centerLine, intersectPoint)
            if intersectType == QtCore.QLineF.BoundedIntersection:
                break
            p1 = p2

        self.setLine(QtCore.QLineF(intersectPoint, myStartItem.pos()))
        line = self.line()

        if line.length(
        ) == 0:  #division by zero might occur if arrow has no length
            return
        angle = math.acos(line.dx() / line.length())
        if line.dy() >= 0:
            angle = (math.pi * 2.0) - angle

        arrowP1 = line.p1() + QtCore.QPointF(
            math.sin(angle + math.pi / 3.0) * arrowSize,
            math.cos(angle + math.pi / 3) * arrowSize)
        arrowP2 = line.p1() + QtCore.QPointF(
            math.sin(angle + math.pi - math.pi / 3.0) * arrowSize,
            math.cos(angle + math.pi - math.pi / 3.0) * arrowSize)

        self.arrowHead.clear()
        for point in [line.p1(), arrowP1, arrowP2]:
            self.arrowHead.append(point)

        painter.drawLine(line)
        painter.drawPolygon(self.arrowHead)
Esempio n. 23
0
    def __init__(self, source, dest):

        QtGui.QGraphicsItem.__init__(self)

        self.setAcceptedMouseButtons(Qt.NoButton)
        self.source = source
        self.dest = dest
        self.commit = source.commit
        self.setZValue(-2)

        dest_pt = Commit.item_bbox.center()

        self.source_pt = self.mapFromItem(self.source, dest_pt)
        self.dest_pt = self.mapFromItem(self.dest, dest_pt)
        self.line = QtCore.QLineF(self.source_pt, self.dest_pt)

        width = self.dest_pt.x() - self.source_pt.x()
        height = self.dest_pt.y() - self.source_pt.y()
        rect = QtCore.QRectF(self.source_pt, QtCore.QSizeF(width, height))
        self.bound = rect.normalized()

        # Choose a new color for new branch edges
        if self.source.x() < self.dest.x():
            color = EdgeColor.next()
            line = Qt.SolidLine
        elif self.source.x() != self.dest.x():
            color = EdgeColor.current()
            line = Qt.SolidLine
        else:
            color = EdgeColor.current()
            line = Qt.SolidLine

        self.pen = QtGui.QPen(color, 4.0, line, Qt.SquareCap, Qt.RoundJoin)
    def _update_xy(self):
        # Update the plotted embedding coordinates
        if self.plotdata is None:
            return

        item = self.plotdata.mainitem
        coords = self.plotdata.embedding_coords
        radius = numpy.max(numpy.linalg.norm(coords, axis=1))
        coords = coords / radius
        if self.jitter > 0:
            _, factor = self.JitterAmount[self.jitter]
            coords = coords + self.plotdata.jittervec * factor

        item.setData(x=coords[:, 0], y=coords[:, 1],
                     brush=self.plotdata.brushdata,
                     pen=self.plotdata.pendata,
                     size=self.plotdata.sizedata,
                     symbol=self.plotdata.shapedata,
                     data=numpy.flatnonzero(self.plotdata.validmask)
                     )

        for anchor, item in zip(self.plotdata.anchors,
                                self.plotdata.axisitems):
            item.setLine(QtCore.QLineF(0, 0, *anchor))

        for (x, y), item in zip(coords, self.plotdata.labelitems):
            item.setPos(x, y)
Esempio n. 25
0
    def calculate_forces(self):

        # Sum up all forces pushing this item away.
        xvel = 0.0
        yvel = 0.0

        line = QtCore.QLineF(self.next_pos, self.pos())
        dx = line.dx()
        dy = line.dy()
        l = math.sqrt(math.pow(dx, 2) + math.pow(dy, 2))
        # l = 2.0 * (dx * dx + dy * dy)
        if l > 0:
            xvel -= (dx * self.speed) / l
            yvel -= (dy * self.speed) / l
        if l < 10:
            self.calculate_next_pos()

        scene_rect = self.scene().sceneRect()
        self.newPos = self.pos() + QtCore.QPointF(xvel, yvel)
        self.newPos.setX(
            min(max(self.newPos.x(),
                    scene_rect.left() + 10),
                scene_rect.right() - 10))
        self.newPos.setY(
            min(max(self.newPos.y(),
                    scene_rect.top() + 10),
                scene_rect.bottom() - 10))
Esempio n. 26
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 = QtGui.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)
Esempio n. 27
0
    def isNeedReverse(self, edge):
        height, width = self.segmentMap.shape

        step = 3
        posDirCount = 0
        totalCount = len(edge) / step
        for i in range(totalCount):
            idx = i * step
            pt1 = QtCore.QPointF(edge[idx][1], edge[idx][0])
            idx = (i + 1) * step
            if (idx >= len(edge)):
                idx = -1
            pt2 = QtCore.QPointF(edge[idx][1], edge[idx][0])

            line1 = QtCore.QLineF(pt1, pt2)
            line1 = line1.normalVector()
            pt3 = line1.p2()
            pt3.setX(min(max(pt3.x(), 0), width - 1))
            pt3.setY(min(max(pt3.y(), 0), height - 1))

            pt4 = QtCore.QPointF(line1.x1() - line1.dx(),
                                 line1.y1() - line1.dy())
            pt4.setX(min(max(pt4.x(), 0), width - 1))
            pt4.setY(min(max(pt4.y(), 0), height - 1))

            if (self.segmentMap[int(pt3.y()), int(pt3.x())] >=
                    self.segmentMap[int(pt4.y()), int(pt4.x())]):
                posDirCount += 1
        ratio = float(posDirCount) / np.ceil(float(totalCount))
        # If ratio greater than the threshold, we dont need to reverse the edge
        if (ratio > 0.3):
            return False
        else:
            return True
Esempio n. 28
0
    def paintEvent(self, e):
        import math
        qp = QtGui.QPainter()
        qp.begin(self)
        qp.setBrush(QtGui.QColor('#000000'))

        line = QtCore.QLineF(100, 200, 200, 200)

        theta = math.pi / 8

        qp.drawLine(line)

        d = 5

        lineAngle = math.atan2(line.dy(), line.dx())
        h = math.fabs(d / math.cos(lineAngle))

        angle1 = math.pi + lineAngle + theta
        angle2 = math.pi + lineAngle - theta

        P1 = QtCore.QPointF(line.x2() + math.cos(angle1) * h,
                            line.y2() + math.sin(angle1) * h)
        P2 = QtCore.QPointF(line.x2() + math.cos(angle2) * h,
                            line.y2() + math.sin(angle2) * h)

        qp.drawPolygon(line.p2(), P1, P2)

        qp.end()
Esempio n. 29
0
    def paint(self, painter, option, widget):
        if not self.source or not self.dest:
            return

        # Draw the line itself.
        line = QtCore.QLineF(self.sourcePoint, self.destPoint)

        if line.length() == 0.0:
            return

        painter.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine,
                QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
        painter.drawLine(line)

        # Draw the arrows if there's enough room.
        angle = math.acos(line.dx() / line.length())
        if line.dy() >= 0:
            angle = Edge.TwoPi - angle

        sourceArrowP1 = self.sourcePoint + QtCore.QPointF(math.sin(angle + Edge.Pi / 3) * self.arrowSize,
                                                          math.cos(angle + Edge.Pi / 3) * self.arrowSize)
        sourceArrowP2 = self.sourcePoint + QtCore.QPointF(math.sin(angle + Edge.Pi - Edge.Pi / 3) * self.arrowSize,
                                                          math.cos(angle + Edge.Pi - Edge.Pi / 3) * self.arrowSize);   
        destArrowP1 = self.destPoint + QtCore.QPointF(math.sin(angle - Edge.Pi / 3) * self.arrowSize,
                                                      math.cos(angle - Edge.Pi / 3) * self.arrowSize)
        destArrowP2 = self.destPoint + QtCore.QPointF(math.sin(angle - Edge.Pi + Edge.Pi / 3) * self.arrowSize,
                                                      math.cos(angle - Edge.Pi + Edge.Pi / 3) * self.arrowSize)

        painter.setBrush(QtCore.Qt.black)
        painter.drawPolygon(QtGui.QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2]))
        painter.drawPolygon(QtGui.QPolygonF([line.p2(), destArrowP1, destArrowP2]))
Esempio n. 30
0
 def mouseMoveEvent(self, mouseEvent):
     if self.myMode == self.InsertLine and self.line:
         newLine = QtCore.QLineF(self.line.line().p1(),
                                 mouseEvent.scenePos())
         self.line.setLine(newLine)
     elif self.myMode == self.MoveItem:
         super(DiagramScene, self).mouseMoveEvent(mouseEvent)