コード例 #1
0
    def makeArrow(self, X, Y, yaw, obSize):
        lines = []
        startArrowX = int(X - math.cos(yaw) * obSize / 4)
        startArrowY = -int(Y - math.sin(yaw) * obSize / 4)
        endArrowX = int(X + math.cos(yaw) * obSize / 2 -
                        math.cos(yaw) * obSize / 4)
        endArrowY = -int(Y + math.sin(yaw) * obSize / 2 -
                         math.sin(yaw) * obSize / 4)
        line1 = QGraphicsLineItem(startArrowX, startArrowY, endArrowX,
                                  endArrowY)
        line1.setPen(QPen(self.black, 5))
        lines.append(line1)
        line2 = QGraphicsLineItem(
            endArrowX, endArrowY,
            endArrowX - math.cos(3.14 / 4 + yaw) * obSize / 4,
            endArrowY + math.sin(3.14 / 4 + yaw) * obSize / 4)

        line2.setPen(QPen(self.black, 5))
        lines.append(line2)
        line3 = QGraphicsLineItem(
            endArrowX, endArrowY,
            endArrowX - math.cos(3.14 / 4 - yaw) * obSize / 4,
            endArrowY - math.sin(3.14 / 4 - yaw) * obSize / 4)

        line3.setPen(QPen(self.black, 5))
        lines.append(line3)
        return lines
コード例 #2
0
    def __drawPoint(self, x, y, index):
        #横线
        line1 = QGraphicsLineItem()
        line1.setPen(self.pen)
        line1.setLine(x - self.lineRadius, y, x + self.lineRadius, y)

        #竖线
        line2 = QGraphicsLineItem()
        line2.setPen(self.pen)
        line2.setLine(x, y - self.lineRadius, x, y + self.lineRadius)

        #文字说明
        text = QGraphicsTextItem()
        text.setDefaultTextColor(Qt.blue)
        text.setFont(self.font)

        text.setPlainText(self.pointsName[index])
        text.setPos(x, y)

        #放到组中
        pointGroup = QGraphicsItemGroup()
        pointGroup.addToGroup(line1)
        pointGroup.addToGroup(line2)
        pointGroup.addToGroup(text)

        #显示
        if self.pointsItem[index] is not None:
            self.scene.removeItem(self.pointsItem[index])

        #保存到字典
        self.pointsItem[index] = pointGroup
        #显示该点
        self.scene.addItem(self.pointsItem[index])
コード例 #3
0
ファイル: ViewPair.py プロジェクト: sgiy/crypto-trader
    def __init__(self, parent):
        super().__init__(parent)
        self.setRenderHint(QPainter.Antialiasing)
        self.chart = self.chart()
        self.chart.legend().setVisible(False)
        self._chart_loaded = False

        self._chart_horizontal_line = QGraphicsLineItem(0, 0, 0, 0)
        pen = self._chart_horizontal_line.pen()
        pen.setStyle(Qt.DashLine)
        self._chart_horizontal_line.setPen(pen)
        self.scene().addItem(self._chart_horizontal_line)
        self._chart_vertical_line = QGraphicsLineItem(0, 0, 0, 0)
        self._chart_vertical_line.setPen(pen)
        self.scene().addItem(self._chart_vertical_line)

        self._chart_tooltip = QGraphicsTextItem("")
        self._chart_tooltip.setPos(100, 20)
        self.scene().addItem(self._chart_tooltip)

        self._chart_crosshair = QGraphicsTextItem("")
        self._chart_crosshair.setPos(600, 20)
        self.scene().addItem(self._chart_crosshair)

        margins = self.chart.margins()
        margins.setTop(margins.top() + 80)
        self.chart.setMargins(margins)
コード例 #4
0
    def mouseMoveEvent(self, event, image_item):
        if self._aiming:
            if self._helpLines is not None and self._helpLines.scene(
            ) is not None:
                self._scene.removeItem(self._helpLines)

            self._helpLines = QGraphicsItemGroup()
            group = self._helpLines

            verticalHelpLine = QGraphicsLineItem(event.scenePos().x(), 0,
                                                 event.scenePos().x(),
                                                 self._scene.height())
            horizontalHelpLine = QGraphicsLineItem(0,
                                                   event.scenePos().y(),
                                                   self._scene.width(),
                                                   event.scenePos().y())

            horizontalHelpLine.setPen(self._helpLinesPen)
            verticalHelpLine.setPen(self._helpLinesPen)

            group.addToGroup(verticalHelpLine)
            group.addToGroup(horizontalHelpLine)

            self._scene.addItem(self._helpLines)
        else:
            if self._item is not None:
                assert self._init_pos is not None
                rect = QRectF(self._init_pos, event.scenePos()).normalized()
                self._item.setRect(rect)

        event.accept()
コード例 #5
0
    def initialize(self) -> None:
        """
        Method to initialize the display of this item

        :return: None
        """
        op = self.sceneBoundingRect().center()
        self.setTransformOriginPoint(op)
        self.setRotation(self.angle)
        cx, cy = self.center
        r1, r2 = self.height / 2, self.width / 2
        # Draw major axis
        major_axis = QGraphicsLineItem(-r2, 0, r2, 0)
        major_axis.setPos(cx, cy)
        major_axis.setParentItem(self)
        # Draw minor axis
        minor_axis = QGraphicsLineItem(-r1, 0, r1, 0)
        minor_axis.setPos(cx, cy)
        minor_axis.setParentItem(self)
        minor_axis.setRotation(90)
        rect = EditingRectangle(self.x, self.y, self.center[0], self.center[1],
                                self.width, self.height)
        rect.setTransformOriginPoint(rect.sceneBoundingRect().center())
        rect.setRotation(self.angle)
        self.indicators.extend([
            major_axis,
            minor_axis,
        ])
        self.edit_rect = rect
        self.rect = self.boundingRect()
        self.edit_rect.activate(False)
        self.setEnabled(False)
コード例 #6
0
    def __init__(self, position, angle, arrow_size, value, unit):
        super(StressRepresentation, self).__init__()
        arrow_line = QLineF()
        arrow_line.setP1(position)
        arrow_line.setLength(arrow_size)
        arrow_line.setAngle(angle)
        arrow = QGraphicsLineItem()
        arrow.setLine(arrow_line)
        self.addToGroup(arrow)

        arrow_head1_line = QLineF()
        arrow_head1_line.setP1(arrow_line.p1())
        arrow_head1_line.setLength(arrow_size / 4)
        arrow_head1_line.setAngle(arrow_line.angle() + 45)
        arrow_head1 = QGraphicsLineItem()
        arrow_head1.setLine(arrow_head1_line)
        self.addToGroup(arrow_head1)

        arrow_head2_line = QLineF()
        arrow_head2_line.setP1(arrow_line.p1())
        arrow_head2_line.setLength(arrow_size / 4)
        arrow_head2_line.setAngle(arrow_line.angle() - 45)
        arrow_head2 = QGraphicsLineItem()
        arrow_head2.setLine(arrow_head2_line)
        self.addToGroup(arrow_head2)

        text = QGraphicsTextItem()
        text.setPlainText(f'{str(value)}{unit}')
        text.setPos(arrow_line.p2())
        self.addToGroup(text)

        self._set_color()
コード例 #7
0
    def __init__(self, *args, **kwargs):
        super(ChartView, self).__init__(*args, **kwargs)
        self.resize(800, 600)
        self.setRenderHint(QPainter.Antialiasing)  # 抗锯齿
        # 自定义x轴label
        self.category = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
        self.initChart()

        # 提示widget
        self.toolTipWidget = GraphicsProxyWidget(self._chart)

        # line
        self.lineItem = QGraphicsLineItem(self._chart)
        pen = QPen(Qt.gray)
        pen.setWidth(1)

        self.lineItem.setPen(pen)
        self.lineItem.setZValue(996)
        self.lineItem.hide()

        self.lineItemX = QGraphicsLineItem(self._chart)
        penx = QPen(Qt.gray)
        penx.setWidth(1)
        self.lineItemX.setPen(penx)
        self.lineItemX.setZValue(997)
        self.lineItemX.hide()

        # 一些固定计算,减少mouseMoveEvent中的计算量
        # 获取x和y轴的最小最大值
        axisX, axisY = self._chart.axisX(), self._chart.axisY()
        self.min_x, self.max_x = axisX.min(), axisX.max()
        self.min_y, self.max_y = axisY.min(), axisY.max()
コード例 #8
0
 def create_fromDB(self,pos_list=[],obj_type=""):      
     if obj_type =="rois":
         num_rois = len(pos_list)
         for i in range(num_rois):
             points = pos_list[i]
             rect=QGraphicsRectItem()
             rect.setPen(QPen(Qt.green))
             rect.setRect(points[0],points[1],points[2],points[3])
             self.rectgroup.addToGroup(rect)
         self.scene.addItem(self.rectgroup)
     elif obj_type =="vector1":
         num_vec = len(pos_list)
         for i in range(num_vec):
             points = pos_list[i]
             vec=QGraphicsLineItem()
             vec.setPen(QPen(Qt.green))
             vec.setLine(points[0],points[1],points[2],points[3])
             self.linegroup.addToGroup(vec)
         self.scene.addItem(self.linegroup)
     elif obj_type =="vector2":
         num_vec = len(pos_list)
         for i in range(num_vec):
             points = pos_list[i]
             vec=QGraphicsLineItem()
             vec.setPen(QPen(Qt.green))
             vec.setLine(points[0],points[1],points[2],points[3])
             self.linegroup2.addToGroup(vec)
         self.scene.addItem(self.linegroup2)
コード例 #9
0
    def drawGrid(self):
        black_notes = [2,4,6,9,11]
        scale_bar = QGraphicsRectItem(0, 0, self.grid_width, self.note_height, self.piano)
        scale_bar.setPos(self.piano_width, 0)
        scale_bar.setBrush(QColor(100,100,100))
        clearpen = QPen(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 = 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 not in black_notes:
                    scale_bar.setBrush(QColor(120,120,120))
                else:
                    scale_bar.setBrush(QColor(100,100,100))

        measure_pen = QPen(QColor(0, 0, 0, 120), 3)
        half_measure_pen = QPen(QColor(0, 0, 0, 40), 2)
        line_pen = QPen(QColor(0, 0, 0, 40))
        for i in range(0, int(self.num_measures) + 1):
            measure = 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 = QGraphicsSimpleTextItem('%d' % (i + 1), self.header)
                number.setPos(self.measure_width * i + 5, 2)
                number.setBrush(Qt.white)
                for j in self.frange(0, self.time_sig[0]*self.grid_div/self.time_sig[1], 1.):
                    line = 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)
コード例 #10
0
    def refresh(self):
        if not self.items():
            return
        super().refresh()
        
        for i in self.items():
            if isinstance(i, QGraphicsLineItem):
                self.removeItem(i)


        hull = self.hull_method(self.point_model.points)
        pts = hull + [hull[0]]


        point_items = list(filter(lambda i: isinstance(i, PointGraphicsItem), self.items()))
        for p in point_items:
            p.setBrush(Qt.blue)

        min_point = min(point_items, key=lambda p:p.x())
        min_point.setBrush(Qt.green)

        for i in range(len(pts)-1):
            dx, dy = pts[i+1].x - pts[i].x, pts[i+1].y - pts[i].y
            line = QGraphicsLineItem(pts[i+1].x, pts[i+1].y, pts[i+1].x+dx, pts[i+1].y+dy)
            pen = QPen()
            pen.setStyle(Qt.DashLine)
            line.setPen(pen)
            line.setZValue(-2)
            self.addItem(line)
            h_line = QGraphicsLineItem(pts[i].x, pts[i].y, pts[i+1].x, pts[i+1].y)
            h_line.setPen(Qt.red)
            h_line.setZValue(-1)


        self.enumeratePoints()
コード例 #11
0
    def __init__(self):
        super(KLineChartView, self).__init__()
        self.setRenderHint(QPainter.Antialiasing)  # 抗锯齿
        self._chart = QChart(title='蜡烛图悬浮提示')
        self.stocks = read_tick_data()
        self.category = [
            trade_date[4:] for trade_date in self.stocks['trade_date']
        ]
        self._count = len(self.category)
        self.resize(800, 300)

        self.init_chart()

        self.toolTipWidget = GraphicsProxyWidget(self._chart)

        # 鼠标跟踪的十字线
        self.lineItem_h = QGraphicsLineItem(self._chart)
        self.lineItem_v = QGraphicsLineItem(self._chart)
        pen = QPen()
        pen.setStyle(Qt.DotLine)
        pen.setColor(QColor(Qt.gray))
        pen.setWidth(2)
        self.lineItem_h.setPen(pen)
        self.lineItem_v.setPen(pen)
        self.lineItem_h.setZValue(100)
        self.lineItem_v.setZValue(100)
        self.lineItem_h.hide()
        self.lineItem_v.hide()

        # 坐标轴上最大最小的值
        # x 轴是
        self.min_x, self.max_x = 0, len(self._chart.axisX().categories())
        self.min_y, self.max_y = self._chart.axisY().min(), self._chart.axisY(
        ).max()
        # y 轴最高点坐标
        self.point_y_max = self._chart.mapToPosition(
            QPointF(self.min_x, self.max_y))
        # x 轴最高点坐标
        self.point_x_max = self._chart.mapToPosition(
            QPointF(self.max_x, self.min_y))
        # self.point_x_min = self._chart.mapToPosition(QPointF(self.min_x, self.min_y))

        # 计算x轴单个cate的宽度,用来处理横线不能画到边界
        self.x_width = (self.point_x_max.x() - self.point_y_max.x()) / len(
            self.category)
        self.x_x_min = self.point_y_max.x() - self.x_width / 2
        self.x_x_max = self.point_x_max.x() - self.x_width / 2

        # 中间位置,用来判断TipWidget放在哪里
        mid_date = self.stocks['trade_date'].iloc[len(
            self.stocks['trade_date']) // 2]
        self.mid_x = float(
            time.mktime(
                datetime.datetime.strptime(str(mid_date),
                                           '%Y%m%d').timetuple()))
        self.left_pos = self.point_y_max
        self.right_pos = self._chart.mapToPosition(
            QPointF(self.max_x, self.max_y))
コード例 #12
0
    def draw_line(self):
        line_pen = QPen(Qt.black, 2)
        item = QGraphicsLineItem(0, self.h, self.w, self.h)
        item.setPen(line_pen)
        self.scene.addItem(item)

        item = QGraphicsLineItem(self.w, 0, self.w, self.h)
        item.setPen(line_pen)
        self.scene.addItem(item)
コード例 #13
0
 def __init__(self):
     super(painter, self).__init__()
     self.setFixedSize(self.width, self.height + self.textLineHeight)
     self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
     self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
     self.scene = QGraphicsScene()
     self.setScene(self.scene)
     if len(sys.argv) >= 2:
         if sys.argv[2] == "MLX90641":
             self.blurRaduis = 25
             self.ChipType = "MLX90641"
         elif sys.argv[2] == "MLX90640":
             self.blurRaduis = 50
             self.ChipType = "MLX90640"
     # center het text item
     self.centerTextItem = QGraphicsTextItem()
     self.centerTextItem.setPos(self.width / 2 - self.fontSize, 0)
     self.centerTextItem.setZValue(self.baseZValue + 1)
     self.scene.addItem(self.centerTextItem)
     # center anchor item
     centerX = self.width / 2
     centerY = self.height / 2
     self.ellipseItem = QGraphicsEllipseItem(0, 0, self.ellipseRadius * 2,
                                             self.ellipseRadius * 2)
     self.horLineItem = QGraphicsLineItem(0, 0, self.anchorLineSize, 0)
     self.verLineItem = QGraphicsLineItem(0, 0, 0, self.anchorLineSize)
     self.ellipseItem.setPos(centerX - self.ellipseRadius,
                             centerY - self.ellipseRadius)
     self.horLineItem.setPos(centerX - self.anchorLineSize / 2, centerY)
     self.verLineItem.setPos(centerX, centerY - self.anchorLineSize / 2)
     self.ellipseItem.setPen(QColor(Qt.white))
     self.horLineItem.setPen(QColor(Qt.white))
     self.verLineItem.setPen(QColor(Qt.white))
     self.ellipseItem.setZValue(self.baseZValue + 1)
     self.horLineItem.setZValue(self.baseZValue + 1)
     self.verLineItem.setZValue(self.baseZValue + 1)
     self.scene.addItem(self.ellipseItem)
     self.scene.addItem(self.horLineItem)
     self.scene.addItem(self.verLineItem)
     # camera item
     self.cameraBuffer = QPixmap(self.width,
                                 self.height + self.textLineHeight)
     self.cameraItem = QGraphicsPixmapItem()
     if self.useBlur:
         self.gusBlurEffect = QGraphicsBlurEffect()
         self.gusBlurEffect.setBlurRadius(self.blurRaduis)
         self.cameraItem.setGraphicsEffect(self.gusBlurEffect)
     self.cameraItem.setPos(0, 0)
     self.cameraItem.setZValue(self.baseZValue)
     self.scene.addItem(self.cameraItem)
     # het text item
     self.hetTextBuffer = QPixmap(self.width, self.textLineHeight)
     self.hetTextItem = QGraphicsPixmapItem()
     self.hetTextItem.setPos(0, self.height)
     self.hetTextItem.setZValue(self.baseZValue)
     self.scene.addItem(self.hetTextItem)
コード例 #14
0
ファイル: main.py プロジェクト: ikegami5/VisibleGraph
	def __init__(self, vertex):
		super().__init__(vertex.circle)
		self.topLeft = QPointF(vertex.x() - 8, vertex.y() - 8)
		self.topRight = QPointF(vertex.x() + 8, vertex.y() - 8)
		self.bottomLeft = QPointF(vertex.x() - 8, vertex.y() + 8)
		self.bottomRight = QPointF(vertex.x() + 8, vertex.y() + 8)
		self.line1 = QGraphicsLineItem(QLineF(self.topLeft, self.bottomRight), self)
		self.line2 = QGraphicsLineItem(QLineF(self.topRight, self.bottomLeft), self)
		self.vertex = vertex
		self.setVisible(False)
コード例 #15
0
ファイル: crosshair.py プロジェクト: cool-fosh/OptoStim
    def __init__(self, parent=None):
        super().__init__(parent)
        self.horizontal_line = QGraphicsLineItem()
        self.vertical_line = QGraphicsLineItem()

        self.horizontal_line.setLine(0, 1080 / 2, 1920, 1080 / 2)
        self.vertical_line.setLine(1920 / 2, 0, 1920 / 2, 1080)

        self.pen = QPen(Qt.white)
        self.horizontal_line.setPen(self.pen)
        self.vertical_line.setPen(self.pen)
コード例 #16
0
ファイル: QComposer.py プロジェクト: Oribow/Anki-MoreStrategy
    def draw(self, nextDown, x, y):
        self.nextDown = nextDown
        self.x = x
        self.y = y

        # remove old stuff
        for c in self.childItems():
            c.setParentItem(None)
        # just draw me at x, y
        self.setPos(x, y)
        # if self.isDrawingDirty:

        self.drawBase()
        if self.aItem != None:
            self.uiFactory.beginRootLayout(x, y, ITEM_SIZE, self)
            self.aItem.item.onComposerDraw(self.uiFactory, self.aItem.amount,
                                           self.getMinAmount(),
                                           self.getMaxAmount())
            self.uiFactory.endRootLayout()

        orgX = x
        orgY = y
        lastX = x
        lastY = y

        for child in self.children:
            if nextDown:
                nextX = orgX
                nextY = y + ITEM_SIZE + ITEM_SPACE
            else:
                nextX = x + ITEM_SIZE + ITEM_SPACE
                nextY = orgY

            # draw connection between children
            if nextDown:
                QGraphicsLineItem(lastX + ITEM_SIZE_HALF - orgX,
                                  lastY + ITEM_SIZE - orgY,
                                  nextX + ITEM_SIZE_HALF - orgX,
                                  nextY + ITEM_SIZE - orgY, self)
            else:
                QGraphicsLineItem(lastX + ITEM_SIZE - orgX,
                                  lastY + ITEM_SIZE_HALF - orgY, nextX - orgX,
                                  nextY + ITEM_SIZE_HALF - orgY, self)

            tmpX, tmpY = child.draw(not nextDown, nextX, nextY)
            if tmpX > x:
                x = tmpX
            if tmpY > y:
                y = tmpY
            lastX = nextX
            lastY = nextY

        return x, y
コード例 #17
0
ファイル: coordinate_system.py プロジェクト: Soosang-9/Dusan
    def __init__(self):
        QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.round = 50

        # set range.
        self.gScene = QGraphicsScene(0, 0,
                                     self.ui.graphicsView.width() - 5,
                                     self.ui.graphicsView.height() - 5,
                                     self.ui.graphicsView)
        print 'graphics View x %f', self.ui.graphicsView.width()
        print 'graphics View y %f', self.ui.graphicsView.height()
        self.ui.graphicsView.setScene(self.gScene)

        # test circle
        self.circle = QGraphicsEllipseItem()
        red = QBrush(Qt.red)
        pen = QPen(Qt.black)
        pen.setWidth(6)

        # test line
        self.x_line = QGraphicsLineItem(self.gScene.width() / 2, 0,
                                        self.gScene.width() / 2,
                                        self.gScene.height())
        self.gScene.addItem(self.x_line)
        self.y_line = QGraphicsLineItem(0,
                                        self.gScene.width() / 2,
                                        self.gScene.height(),
                                        self.gScene.width() / 2)
        self.gScene.addItem(self.y_line)

        #self.circle2 = DrawCircles(int(self.gScene.width()/2), int(self.gScene.height()/2))
        #self.gScene.addItem(self.circle2)

        print 'gScene View x %f', self.gScene.width() / 2
        print 'gScene View y %f', self.gScene.height() / 2

        self.circle = self.gScene.addEllipse(
            self.gScene.width() / 2 - self.round,
            self.gScene.height() / 2 - self.round, self.round * 2,
            self.round * 2, pen, red)

        # check Item argv.
        self.g_item = QGraphicsRectItem(self.gScene.width() / 2,
                                        self.gScene.height() / 2, 100, 100)
        self.gScene.addItem(self.g_item)
        self.g1_item = QGraphicsRectItem(self.gScene.width() / 2,
                                         self.gScene.height() / 2, 100, 100)
        self.gScene.addItem(self.g1_item)
        # self.gScene.addItem(self.circles)
        self.show()
コード例 #18
0
ファイル: image_viewer.py プロジェクト: appstarbd/CvStudio
 def _create_grid_lines(self):
     pen_color = QColor(255, 255, 255, 255)
     pen = QPen(pen_color)
     pen.setWidth(2)
     pen.setStyle(QtCore.Qt.DotLine)
     self.vline = QGraphicsLineItem()
     self.vline.setVisible(False)
     self.vline.setPen(pen)
     self.hline = QGraphicsLineItem()
     self.hline.setVisible(False)
     self.hline.setPen(pen)
     self._scene.addItem(self.vline)
     self._scene.addItem(self.hline)
コード例 #19
0
    def __init__(self, parent=None):
        super(ASCGraphicsView, self).__init__(parent)
        self.scene = QGraphicsScene(self)

        self.raw_img_item = QGraphicsPixmapItem()
        self.raw_img_item.setZValue(0)
        self.anno_img_item = QGraphicsPixmapItem()
        self.anno_img_item.setZValue(1)

        self.cross_bar_v_line_item = QGraphicsLineItem()
        self.cross_bar_h_line_item = QGraphicsLineItem()
        self.cross_bar_v_line_item.setZValue(100)
        self.cross_bar_h_line_item.setZValue(100)
        self.cross_bar_v_line_item.setPen(
            QPen(Qt.blue, 0, Qt.DotLine, Qt.FlatCap, Qt.RoundJoin))
        self.cross_bar_h_line_item.setPen(
            QPen(Qt.blue, 0, Qt.DotLine, Qt.FlatCap, Qt.RoundJoin))

        self.paint_brush_circle_item = QGraphicsEllipseItem()
        self.paint_brush_rect_item = QGraphicsPolygonItem()
        self.paint_brush_circle_item.setZValue(10)
        self.paint_brush_rect_item.setZValue(11)
        self.paint_brush_circle_item.setVisible(False)
        self.paint_brush_rect_item.setVisible(False)
        self.paint_brush_circle_item.setPen(
            QPen(Qt.red, 0, Qt.DotLine, Qt.FlatCap, Qt.RoundJoin))
        self.paint_brush_rect_item.setPen(
            QPen(Qt.red, 0, Qt.DotLine, Qt.FlatCap, Qt.RoundJoin))

        self.scene.addItem(self.raw_img_item)
        self.scene.addItem(self.anno_img_item)
        self.scene.addItem(self.cross_bar_v_line_item)
        self.scene.addItem(self.cross_bar_h_line_item)
        self.scene.addItem(self.paint_brush_circle_item)
        self.scene.addItem(self.paint_brush_rect_item)

        self.setScene(self.scene)
        self.setViewport(QOpenGLWidget())

        self._last_button_press = Qt.NoButton
        self._last_pos_middle_button = None
        self._last_pos_right_button = None

        self._brush_stats = {'type': BRUSH_TYPE_NO_BRUSH, 'size': 5}

        self.setResizeAnchor(QGraphicsView.AnchorViewCenter)

        self.slice_scroll_bar = None
        self.image_size = None
        self.is_valid = False
コード例 #20
0
ファイル: quickhull.py プロジェクト: OGKG/CGApp
    def drawHlrLines(self):
        hlr = self.algorithm.stageResults[1]
        for h, l, r in hlr:
            pen = QPen()
            pen.setStyle(Qt.PenStyle.DashLine)

            lh_line = QGraphicsLineItem(l.x, l.y, h.x, h.y)
            lh_line.setPen(pen)
            lh_line.setZValue(-1)
            rh_line = QGraphicsLineItem(r.x, r.y, h.x, h.y)
            rh_line.setPen(pen)
            rh_line.setZValue(-1)
            self.addItem(lh_line)
            self.addItem(rh_line)
コード例 #21
0
    def make_cursor(self):
        pen = QPen(QColor(0, 255, 0))
        h_line = QGraphicsLineItem(-10, 0, 10, 0)
        v_line = QGraphicsLineItem(0, -10, 0, 10)

        pen.setWidth(1)
        h_line.setPen(pen)
        v_line.setPen(pen)

        self.point_cursor = QGraphicsItemGroup()
        self.point_cursor.addToGroup(h_line)
        self.point_cursor.addToGroup(v_line)
        self.point_cursor.setZValue(1)
        self.point_cursor.setVisible(False)
        self.scene().addItem(self.point_cursor)
コード例 #22
0
    def connect_relation(self, x, y, type):
        ver_line = QGraphicsLineItem(self.en_shape)
        horz_line = QGraphicsLineItem(self.en_shape)
        ver_line.setLine(
            QLineF(self.rel_orgn.x(), self.rel_orgn.y(), self.rel_orgn.x(),
                   y - self.en_shape.y()))
        horz_line.setLine(
            QLineF(ver_line.line().x2(),
                   ver_line.line().y2(), x - self.en_shape.x(),
                   y - self.en_shape.y()))

        self.rel_orgn.setX(self.rel_orgn.x() + self.orgn_step)
        if (type == 'p'):
            ver_line.setPen(QPen(Qt.black, 3, Qt.DashLine))
            horz_line.setPen(QPen(Qt.black, 3, Qt.DashLine))
コード例 #23
0
    def moveTo(self, pos):
        #data coordinates
        oldX, oldY = self.pos.x(), self.pos.y()
        x, y = pos.x(), pos.y()

        line = QGraphicsLineItem(oldX, oldY, x, y)
        line.setPen(
            QPen(QBrush(Qt.white), self.brushSize, Qt.SolidLine, Qt.RoundCap,
                 Qt.RoundJoin))
        self.scene.addItem(line)
        self._hasMoved = True

        #update bounding Box
        if not self.bb.isValid():
            self.bb = QRect(QPoint(oldX, oldY), QSize(1, 1))
        #grow bounding box
        self.bb.setLeft(
            min(self.bb.left(), max(0, x - self.brushSize // 2 - 1)))
        self.bb.setRight(
            max(self.bb.right(),
                min(self.sliceRect[0] - 1, x + self.brushSize // 2 + 1)))
        self.bb.setTop(min(self.bb.top(), max(0, y - self.brushSize // 2 - 1)))
        self.bb.setBottom(
            max(self.bb.bottom(),
                min(self.sliceRect[1] - 1, y + self.brushSize // 2 + 1)))

        #update/move position
        self.pos = pos
コード例 #24
0
ファイル: diagramscene.py プロジェクト: vinsvanfer/Examples
    def mousePressEvent(self, mouseEvent):
        if (mouseEvent.button() != 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 = QGraphicsLineItem(QLineF(mouseEvent.scenePos(),
                    mouseEvent.scenePos()))
            self.line.setPen(QPen(self.myLineColor, 2))
            self.addItem(self.line)
        elif self.myMode == self.InsertText:
            textItem = DiagramTextItem()
            textItem.setFont(self.myFont)
            textItem.setTextInteractionFlags(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)
コード例 #25
0
ファイル: test_03.py プロジェクト: BeiChenYx/Qt5Notebook
    def __init__(self, *args, **kwargs):
        super(ChartView, self).__init__(*args, **kwargs)
        self.resize(800, 600)
        self.setRenderHint(QPainter.Antialiasing)  # 抗锯齿
        self.initChart()

        # 提示widget
        self.toolTipWidget = GraphicsProxyWidget(self._chart)

        # line 宽度需要调整
        self.lineItem = QGraphicsLineItem(self._chart)
        pen = QPen(Qt.gray)
        self.lineItem.setPen(pen)
        self.lineItem.setZValue(998)
        self.lineItem.hide()

        # 一些固定计算,减少mouseMoveEvent中的计算量
        # 获取x和y轴的最小最大值
        axisX, axisY = self._chart.axisX(), self._chart.axisY()
        self.category_len = len(axisX.categories())
        self.min_x, self.max_x = -0.5, self.category_len - 0.5
        self.min_y, self.max_y = axisY.min(), axisY.max()
        # 坐标系中左上角顶点
        self.point_top = self._chart.mapToPosition(
            QPointF(self.min_x, self.max_y))
コード例 #26
0
    def __init__(self, *args, **kwargs):
        super(ChartView, self).__init__(*args, **kwargs)
        self.resize(800, 600)
        self.setRenderHint(QPainter.Antialiasing)  # 抗锯齿
        self.initChart()

        self.toolTipWidget = GraphicsProxyWidget(self._chart)

        # line
        self.lineItem = QGraphicsLineItem(self._chart)
        self.lineItem.setZValue(998)
        self.lineItem.hide()

        # 一些固定计算,减少mouseMoveEvent中的计算量
        # 获取x和y轴的最小最大值
        axisX, axisY = self._chart.axisX(), self._chart.axisY()
        self.min_x, self.max_x = axisX.min(), axisX.max()
        self.min_y, self.max_y = axisY.min(), axisY.max()
        # 坐标系中左上角顶点
        self.point_top = self._chart.mapToPosition(
            QPointF(self.min_x, self.max_y))
        # 坐标原点坐标
        self.point_bottom = self._chart.mapToPosition(
            QPointF(self.min_x, self.min_y))
        self.step_x = (self.max_x - self.min_x) / (axisX.tickCount() - 1)
コード例 #27
0
 def drawPlayHead(self):
     self.play_head = QGraphicsLineItem(self.piano_width,
                                        self.header_height,
                                        self.piano_width, self.total_height)
     self.play_head.setPen(QPen(QColor(255, 255, 255, 50), 2))
     self.play_head.setZValue(1.)
     self.addItem(self.play_head)
コード例 #28
0
ファイル: RecordsetWindow.py プロジェクト: yxw027/OpenIMU
    def __init__(self, manager, recordset: list, parent=None):
        super().__init__(parent=parent)
        self.UI = Ui_frmRecordsets()
        self.UI.setupUi(self)

        # Internal lists
        self.sensors = {}           # List of sensors objects
        self.sensors_items = {}     # List of QAction corresponding to each sensors
        self.sensors_graphs = {}    # List of graph corresponding to each sensor graph
        self.sensors_location = []  # List of sensors location in this recordset
        self.sensors_blocks = {}    # Sensor blocks - each block of data for each sensor

        # Variables
        self.time_pixmap = False    # Flag used to check if we need to repaint the timeline or not
        self.zoom_level = 1         # Current timeview zoom level

        # Manually created UI objects
        self.time_bar = QGraphicsLineItem()         # Currently selected timestamp bar
        self.selection_rec = QGraphicsRectItem()    # Section rectangle
        self.sensors_menu = QMenu(self.UI.btnNewGraph)
        self.UI.btnNewGraph.setMenu(self.sensors_menu)

        # Data access informations
        self.dbMan = manager
        self.recordsets = recordset

        # Init temporal browser
        self.timeScene = QGraphicsScene()
        self.UI.graphTimeline.setScene(self.timeScene)
        self.UI.graphTimeline.fitInView(self.timeScene.sceneRect())
        self.UI.graphTimeline.time_clicked.connect(self.timeview_clicked)
        self.UI.graphTimeline.time_selected.connect(self.timeview_selected)
        self.UI.scrollTimeline.valueChanged.connect(self.timeview_scroll)

        # Init temporal sensor list
        self.timeSensorsScene = QGraphicsScene()
        self.UI.graphSensorsTimeline.setScene(self.timeSensorsScene)
        self.UI.graphSensorsTimeline.fitInView(self.timeSensorsScene.sceneRect(), Qt.KeepAspectRatio)

        # Update general informations about recordsets
        self.update_recordset_infos()

        # Load sensors for that recordset
        self.load_sensors()

        # Connect signals to slots
        self.UI.btnClearSelection.clicked.connect(self.on_timeview_clear_selection_requested)
        self.UI.btnTimeZoomSelection.clicked.connect(self.on_timeview_zoom_selection_requested)
        self.UI.btnZoomReset.clicked.connect(self.on_timeview_zoom_reset_requested)
        self.UI.btnDisplayTimeline.clicked.connect(self.on_timeview_show_hide_requested)
        self.UI.btnTileHorizontal.clicked.connect(self.tile_graphs_horizontally)
        self.UI.btnTileVertical.clicked.connect(self.tile_graphs_vertically)
        self.UI.btnTileAuto.clicked.connect(self.tile_graphs_auto)
        self.sensors_menu.triggered.connect(self.sensor_graph_selected)

        # Initial UI state
        self.UI.btnZoomReset.setEnabled(False)
        self.UI.btnTimeZoomSelection.setEnabled(False)
        self.UI.btnClearSelection.setEnabled(False)
        self.update_tile_buttons_state()
コード例 #29
0
    def __init__(self, manager):
        """Summary

        Args:
            manager (TYPE): Description
        """
        super(AbstractSliceTool, self).__init__(parent=manager.viewroot)
        """ Pareting to viewroot to prevent orphan _line_item from occuring
        """
        self.sgv = None
        self.manager = manager
        self._active = False
        self._last_location = None
        self._line_item = QGraphicsLineItem(self)
        self._line_item.hide()
        self._vhi = None

        self.hide()
        self.is_started = False
        self.angles = [math.radians(x) for x in range(0, 360, 30)]
        self.vectors = self.setVectors()
        self.part_item = None

        self.vhi_hint_item = QGraphicsEllipseItem(_DEFAULT_RECT, self)
        self.vhi_hint_item.setPen(_MOD_PEN)
        self.vhi_hint_item.setZValue(styles.ZPARTITEM)
コード例 #30
0
ファイル: image_viewer.py プロジェクト: appstarbd/CvStudio
    def __init__(self, parent=None):
        super(ImageViewer, self).__init__(parent)
        self.setRenderHints(QPainter.Antialiasing
                            | QPainter.SmoothPixmapTransform)
        #self.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
        self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
        self.setDragMode(QGraphicsView.ScrollHandDrag)
        #self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        #self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
        self._scene = ImageViewerScene(self)
        self.setScene(self._scene)
        self._create_grid()
        self._create_grid_lines()
        self._pixmap = None
        self._selection_mode = SELECTION_MODE.NONE

        # polygon selection
        _polygon_guide_line_pen = QPen(QtGui.QColor(235, 72, 40))
        _polygon_guide_line_pen.setWidth(2)
        _polygon_guide_line_pen.setStyle(QtCore.Qt.DotLine)
        self._polygon_guide_line = QGraphicsLineItem()
        self._polygon_guide_line.setVisible(False)
        self._polygon_guide_line.setPen(_polygon_guide_line_pen)
        self._scene.addItem(self._polygon_guide_line)
        self._current_polygon = None
        # rectangle selection
        self._box_origin = QPoint()
        self._box_picker = QRubberBand(QRubberBand.Rectangle, self)

        # free selection
        self._current_free_path = None
        self._is_drawing = False
        self._last_point_drawn = QPoint()
        self._current_label = None