def _draw_serie(self, painter, ndx_serie, color): serie = self.data[ndx_serie] #mainlog.debug(serie) fill_color = QColor(color) fill_color.setAlpha(64) brush = QBrush(fill_color) pen = QPen() pen.setCapStyle(Qt.SquareCap) pen.setColor(color) qp = QPainterPath() painter.setPen(pen) for i in range(len(serie)): x, y_top, y_below = self._item_coordinates(i) h = max(1, float(y_top - y_below - 1)) qp.addRect( x, float(self.y_base-y_top), float(self.bar_width), h) painter.fillPath(qp,brush) painter.drawPath(qp) #mainlog.debug("Drawing peak values, juste before {}".format(self._peak_values)) if self._peak_values: #mainlog.debug("Drawing peak values") self._draw_peak_values(painter, self._peak_values )
def setupPaint(self): """Offscreen rather than onscreen redraw (few changes).""" path = QPainterPath() if self.data.isInput: path.addEllipse( self.pinW / 2, self.pinW / 2, self.bodyW, self.bodyW) else: path.addRect( 3 * self.pinW / 2 + 1, self.pinW / 2, self.bodyW, self.bodyW) path.addPath(self.pinPath) self.setPath(path) self.name.setVisible(self.showName) self.name.setText(self.data.name) br = self.mapToScene(self.boundingRect()) w = self.boundingRect().width() h = self.boundingRect().height() realX = min([i.x() for i in br]) realY = min([i.y() for i in br]) self.name.setPos(self.mapFromScene( realX, realY + (w if self.rotation() % 180 else h) + 1)) self.value.setText( str(int(self.data.value)) if self.data.value is not None else 'E') self.value.setPos(self.mapFromScene(realX + w / 3, realY + h / 3)) self.value.setBrush(QColor('green' if self.data.value else 'red')) self.update() # Force onscreen redraw after changes.
def __init__(self, pos, edge, symbol): ''' Create the point - as a small, lightblue box ''' super(Connectionpoint, self).__init__(pos, edge=edge) path = QPainterPath() path.addRect(0, 0, 10, 10) self.setPath(path) self.setPos(pos.x() - 5, pos.y() - 5) # Symbol actually owning the connection point self.symbol = symbol
def objectSavePath(self): """ TOWRITE :rtype: `QPainterPath`_ """ path = QPainterPath() path.addRect(-0.00000001, -0.00000001, 0.00000002, 0.00000002) return path
def shape(self): """ Returns the shape of this item as a QPainterPath in local coordinates. """ path = QPainterPath() path.addRect(self.rect()) if self.isSelected(): for shape in self.handles.values(): path.addEllipse(shape) return path
def set_shape(self, width, height): ''' Compute the polygon to fit in width, height ''' path = QPainterPath() path.addRect(0, 0, width, height) path.moveTo(7, 0) path.lineTo(7, height) path.moveTo(width - 7, 0) path.lineTo(width - 7, height) self.setPath(path) super(ProcedureCall, self).set_shape(width, height)
def setRectFromRect(self, r): """ TOWRITE :param `r`: TOWRITE :type `r`: QPointF """ p = QPainterPath() p.addRect(r) self.setPath(p)
def paintEvent(self, event): cX = self.parent.leftMargin + self.scaleMarkLen cY = self.parent.topMargin + self.scaleMarkLen worldX = self.parent.chunkX*16 worldZ = self.parent.chunkZ*16 painter = QPainter() path = QPainterPath() painter.begin(self) painter.save() #painter.setFont(QFont('Arial Narrow', 8)) #QFont.Bold # draw scale x = cX y = cY painter.rotate(-90) for i in range(16): fr = QRectF(-y, x, self.scaleMarkLen, self.edgeLen) painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555') painter.drawRect(fr) #fr = QRectF(-y - 16*self.edgeLen - self.scaleMarkLen, x, self.scaleMarkLen, self.edgeLen) #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555') #painter.drawRect(fr) x += self.edgeLen painter.rotate(90) x = self.parent.leftMargin y = cY for i in range(16): fr = QRectF(x, y, self.scaleMarkLen, self.edgeLen) painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555') painter.drawRect(fr) #fr = QRectF(x + self.scaleMarkLen + 16*self.edgeLen, y, self.scaleMarkLen, self.edgeLen) #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555') #painter.drawRect(fr) y += self.edgeLen x = cX y = cY for i in range(16): for j in range(16): path.addRect(x, y, self.edgeLen, self.edgeLen) fr = QRectF(x, y, self.edgeLen, self.edgeLen) #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555') x += self.edgeLen x = cX y += self.edgeLen painter.drawPath(path) painter.restore() painter.end() del painter
def updatePath(self): """ TOWRITE """ path = QPainterPath() r = self.rect() # QRectF # Add the center point. path.addRect(-0.00000001, -0.00000001, 0.00000002, 0.00000002) # Add the circle. path.arcMoveTo(r, 0) path.arcTo(r, 0, 360) # NOTE: Reverse the path so that the inside area isn't considered part of the circle. path.arcTo(r, 0, -360) self.setObjectPath(path)
def setRectFromXYWH(self, x, y, w, h): """ TOWRITE :param `x`: TOWRITE :type `x`: qreal :param `y`: TOWRITE :type `y`: qreal :param `w`: TOWRITE :type `w`: qreal :param `h`: TOWRITE :type `h`: qreal """ p = QPainterPath() p.addRect(x, y, w, h) self.setPath(p)
def paintEvent(self, event): painter = QPainter(self) # Фон painter_path = QPainterPath() painter_path.addRect(0, 0, self.width() - 1, self.height() - 1) painter.fillPath(painter_path, QBrush(QImage(':/main/background.png'))) if self.image: painter.drawText(10, 20, str(self.image.draw_scale)) painter.setTransform(QTransform(). scale(self.image.draw_scale, self.image.draw_scale). translate(self.image.draw_offset.x(), self.image.draw_offset.y())) old_pen = painter.pen() new_pen = QPen() new_pen.setColor(QColor(0, 150, 0)) painter.setPen(new_pen) self.image.draw(painter) painter.setPen(old_pen)
def paintEvent(self, event): painter = QPainter(self) # Фон painter_path = QPainterPath() painter_path.addRect(0, 0, self.width() - 1, self.height() - 1) painter.fillPath(painter_path, QBrush(QImage(':/main/background.png'))) if self.image: painter.drawText(10, 20, str(self.image.draw_scale)) painter.setTransform(QTransform().scale( self.image.draw_scale, self.image.draw_scale).translate(self.image.draw_offset.x(), self.image.draw_offset.y())) old_pen = painter.pen() new_pen = QPen() new_pen.setColor(QColor(0, 150, 0)) painter.setPen(new_pen) self.image.draw(painter) painter.setPen(old_pen)
def paintEvent(self, event): cX = self.parent.lytLeftMargin + self.scaleMarkLen cY = self.parent.lytTopMargin + self.scaleMarkLen worldX = self.parent.presenter.showChunkX*16 worldZ = self.parent.presenter.showChunkZ*16 painter = QPainter() path = QPainterPath() painter.begin(self) painter.save() #painter.setFont(QFont('Arial Narrow', 8)) #QFont.Bold # draw scale x = cX y = cY painter.rotate(-90) for i in range(16): fr = QRectF(-y, x, self.scaleMarkLen, self.edgeLen) painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, str(worldX)) #painter.drawRect(fr) #fr = QRectF(-y - 16*self.edgeLen - self.scaleMarkLen, x, self.scaleMarkLen, self.edgeLen) #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555') #painter.drawRect(fr) x += self.edgeLen worldX += 1 painter.rotate(90) x = self.parent.lytLeftMargin y = cY for i in range(16): fr = QRectF(x, y, self.scaleMarkLen, self.edgeLen) painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, str(worldZ)) #painter.drawRect(fr) #fr = QRectF(x + self.scaleMarkLen + 16*self.edgeLen, y, self.scaleMarkLen, self.edgeLen) #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555') #painter.drawRect(fr) y += self.edgeLen worldZ += 1 x = cX y = cY for i in range(16): for j in range(16): path.addRect(x, y, self.edgeLen, self.edgeLen) #fr = QRectF(x, y, self.edgeLen, self.edgeLen) #painter.drawText(fr, Qt.AlignHCenter | Qt.AlignVCenter, '-5555') x += self.edgeLen x = cX y += self.edgeLen painter.drawPath(path) slice_ = self.parent.presenter.getSlice(self.parent.presenter.elevation) x = cX y = cY bru = QBrush() #path1 = QPainterPath() for i in range(16): for j in range(16): if slice_[i][j] in self.parent.selectedMinerals.list_: lePen = painter.pen() newPen = QPen(bru, 3) newPen.setColor(self.parent.selectedMinerals.getColor(slice_[i][j])) painter.setPen(newPen) painter.drawRect(x, y, self.edgeLen, self.edgeLen) painter.setPen(lePen) x += self.edgeLen x = cX y += self.edgeLen painter.restore() painter.end() del painter
def updateLeader(self): """ TOWRITE """ arrowStyle = Closed # int # TODO: Make this customizable arrowStyleAngle = 15.0 # qreal # TODO: Make this customizable arrowStyleLength = 1.0 # qreal # TODO: Make this customizable self.lineStyleAngle = 45.0 # qreal # TODO: Make this customizable self.lineStyleLength = 1.0 # qreal # TODO: Make this customizable lyne = self.line() # QLineF angle = lyne.angle() # qreal ap0 = lyne.p1() # QPointF lp0 = lyne.p2() # QPointF # Arrow lynePerp = QLineF(lyne.pointAt(arrowStyleLength / lyne.length()), lp0) lynePerp.setAngle(angle + 90) lyne1 = QLineF(ap0, lp0) lyne2 = QLineF(ap0, lp0) lyne1.setAngle(angle + arrowStyleAngle) lyne2.setAngle(angle - arrowStyleAngle) # ap1 = QPointF() # ap2 = QPointF() _, ap1 = lynePerp.intersect(lyne1) _, ap2 = lynePerp.intersect(lyne2) # Math Diagram # .(ap1) .(lp1) # /| /| # / | / | # / | / | # / | / | # / | / | # / | / | # / | / | # / | / | # /+(aSA) | /+(lSA) | # (ap0)./__(aSL)__|__________(lp0)./__(lSL)__| # \ -(aSA) | \ -(lSA) | # \ | \ | # \ | \ | # \ | \ | # \ | \ | # \ | \ | # \ | \ | # \ | \ | # \ | \ | # \| \| # .(ap2) .(lp2) if arrowStyle == Open: arrowStylePath = QPainterPath() arrowStylePath.moveTo(ap1) arrowStylePath.lineTo(ap0) arrowStylePath.lineTo(ap2) arrowStylePath.lineTo(ap0) arrowStylePath.lineTo(ap1) elif arrowStyle == Closed: arrowStylePath = QPainterPath() arrowStylePath.moveTo(ap1) arrowStylePath.lineTo(ap0) arrowStylePath.lineTo(ap2) arrowStylePath.lineTo(ap1) elif arrowStyle == Dot: arrowStylePath = QPainterPath() arrowStylePath.addEllipse(ap0, arrowStyleLength, arrowStyleLength) elif arrowStyle == Box: arrowStylePath = QPainterPath() side = QLineF(ap1, ap2).length() # qreal ar0 = QRectF(0, 0, side, side) ar0.moveCenter(ap0) arrowStylePath.addRect(ar0) elif arrowStyle == Tick: pass #TODO/PORT# Is this supposed to be empty? lineStylePath = QPainterPath() lineStylePath.moveTo(ap0) lineStylePath.lineTo(lp0)
def _draw_serie(self, painter, ndx_serie, color): last_item = len(self.data) - 1 serie = self.data[ndx_serie] serie_below = [0] * len(self.data[last_item]) if ndx_serie < len(self.data) - 1: serie_below = self.data[ndx_serie + 1] fill_color = QColor(color) fill_color.setAlpha(64) brush = QBrush(fill_color) pen = QPen() pen.setCapStyle(Qt.SquareCap) pen.setColor(color) for i in range(len(serie)): x, y_top, y_below = self._item_coordinates(ndx_serie, i) qp = QPainterPath() h = float(y_top - y_below - 1) if h > 0: qp.addRect(x, float(self.y_base - y_top), float(self.bar_width), h) painter.fillPath(qp, brush) if self.ndx_best_serie == ndx_serie and ( self.best_serie_intra_ndx is None or (self.best_serie_intra_ndx >= 0 and self.best_serie_intra_ndx == i)): pen.setWidth(3) else: pen.setWidth(1) painter.setPen(pen) painter.drawPath(qp) if ndx_serie == self.ndx_best_serie: fm = painter.fontMetrics() pen.setWidth(1) painter.setPen(pen) serie_below = None if ndx_serie < len(self.data) - 1: serie_below = self.data[ndx_serie + 1] for i in range(len(serie)): if (self.best_serie_intra_ndx == i) or self.best_serie_intra_ndx is None: x, y_top, y_below = self._item_coordinates(ndx_serie, i) l_len = 15 v = serie[i] if serie_below: v = v - serie_below[i] v = str(int(v)) bb = fm.boundingRect(v) pen.setColor(color) y = 0 if i < len(serie) - 1: # small diagonal going top, right painter.drawLine(x + self.bar_width, self.y_base - y_top, x + self.bar_width + l_len, self.y_base - (y_top + l_len)) x = x + self.bar_width + l_len y = y_top + l_len else: # small diagonal going top, left painter.drawLine(x, self.y_base - y_top, x - l_len, self.y_base - (y_top - l_len)) x = x - l_len - bb.width() y = y_top - l_len bb.moveTo(int(x), int(self.y_base - y - bb.height())) brush = QBrush(Qt.GlobalColor.red) bb.adjust(-2, +2, +4, +4) bb.adjust(-2, -2, +2, +2) painter.fillRect(bb, brush) bb.adjust(+2, +2, -2, -2) painter.drawRect(bb) pen.setColor(Qt.GlobalColor.white) painter.setPen(pen) painter.drawText(x, self.y_base - y, str(int(v)))
def set_shape(self, width, height): ''' Set a box - actual shape is computed in the paint function ''' path = QPainterPath() path.addRect(0, 0, width, height) self.setPath(path) super(Comment, self).set_shape(width, height)
def paintEvent(self, event): # print self.height() s = (self.target_angle - self.angle) * 0.09 self.angle += s if math.fabs(self.angle - self.target_angle) < 0.001: self.angle = self.target_angle self.timer.stop() painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) qp = QPainterPath() width = min(self.height(), (self.width() / 2)) height = self.height() # center x = self.width() / 2 big_radius = 1000 y = big_radius + 10 small_radius = big_radius - 15 ac = math.atan(float(self.width()) / 2.0 / float(big_radius)) / math.pi * 180.0 * 0.95 qp.arcMoveTo(x - big_radius, y - big_radius, 2 * big_radius, 2 * big_radius, 90 - ac) qp.arcTo(x - big_radius, y - big_radius, 2 * big_radius, 2 * big_radius, 90 - ac, 2 * ac) qp.arcTo(x - small_radius, y - small_radius, 2 * small_radius, 2 * small_radius, 90 + ac, -2 * ac) qp.arcTo(x - big_radius, y - big_radius, 2 * big_radius, 2 * big_radius, 90 - ac, 0) # qp.lineTo(x+big_radius,y) grange = ac * 2.0 / 360.0 # Centered on 0, starting at angle 90-ac, counterclockwise self.gradient = QConicalGradient(0, 0, 90 - ac - 1) if self.gradient_type == 1: self.gradient.setColorAt(0, Qt.GlobalColor.red) self.gradient.setColorAt(0.1, Qt.GlobalColor.yellow) self.gradient.setColorAt(0.2, Qt.GlobalColor.green) self.gradient.setColorAt(0.5, Qt.GlobalColor.green) self.gradient.setColorAt(0.5, Qt.GlobalColor.green) elif self.gradient_type == 2: self.gradient.setColorAt(0, Qt.GlobalColor.green) self.gradient.setColorAt(0.6 * grange, Qt.GlobalColor.yellow) self.gradient.setColorAt(1 * grange, Qt.GlobalColor.red) elif self.gradient_type == 3: self.gradient.setColorAt(0 * grange, Qt.GlobalColor.red) self.gradient.setColorAt(0.05 * grange, Qt.GlobalColor.yellow) self.gradient.setColorAt(0.1 * grange, Qt.GlobalColor.green) self.gradient.setColorAt(0.4 * grange, Qt.GlobalColor.green) self.gradient.setColorAt(0.45 * grange, Qt.GlobalColor.yellow) self.gradient.setColorAt(0.5 * grange, Qt.GlobalColor.red) self.gradient.setCenter(x, y) painter.fillPath(qp, QBrush(self.gradient)) pen = QPen() pen.setColor(Qt.GlobalColor.black) pen.setWidth(max(1, int(1 * self.width() / 300))) painter.setPen(pen) painter.drawPath(qp) qp = QPainterPath() #qp.moveTo(0,0) #qp.lineTo(x,y) #qp.lineTo(self.width(),0) angle = 0 ac = math.atan(float(self.width()) / 2.0 / float(big_radius)) * 0.95 if self.direction == self.UNIDIRECTIONAL: angle = math.pi / 2 + ac * (1 - 2 * self.angle) elif self.direction == self.BIDIRECTIONAL: angle = math.pi / 2 - self.angle * ac length = big_radius + 10 short_length = small_radius - 10 qp.moveTo(x + math.cos(angle) * short_length, y - math.sin(angle) * short_length) qp.lineTo(x + math.cos(angle) * length, y - math.sin(angle) * length) pen = QPen() pen.setCapStyle(Qt.RoundCap) pen.setColor(Qt.GlobalColor.black) pen.setWidth(max(3, int(3 * width / 300))) painter.setPen(pen) painter.drawPath(qp) qp = QPainterPath() delta = self.width() * 0.025 # print "{}-{} {} c:{}".format(x,y,delta,math.cos(angle)) qp.moveTo(x + delta + math.cos(angle) * short_length, y + delta - math.sin(angle) * short_length) qp.lineTo(x + delta + math.cos(angle) * length, y + delta - math.sin(angle) * length) pen = QPen() pen.setCapStyle(Qt.RoundCap) pen.setColor(QColor.fromRgbF(0, 0, 0, 0.3)) pen.setWidth(max(3, int(3 * width / 300))) painter.setPen(pen) painter.drawPath(qp) qp = QPainterPath() qp.addRect(0, 0, self.width(), self.height()) painter.drawPath(qp)