def addPort(self, name, hasInput=False, hasOutput=False, flags=0): port = QNEPort(self) port.setName(name) port.setCanConnect(hasInput, hasOutput) port.setNEBlock(self) port.setPortFlags(flags) innerSize = port.innerSize() width = innerSize.width() height = innerSize.height() if width > self.width - self.horzMargin: self.width = width + self.horzMargin self.height += height path = QPainterPath() path.addRoundedRect(-self.width / 2, -self.height / 2, self.width, self.height, 5, 5) self.setPath(path) y = -self.height / 2 + self.vertMargin + port.radius() for port_ in self.childItems(): if port_.type() != QNEPort.Type: continue port_.setPos(-self.width / 2 - port.radius(), y) port_.setWidth(self.width) y += port_.innerSize().height() return port
def __init__(self, parent): super(QNEBlock, self).__init__(parent) self.m_nodeEditor = None self.m_name = "" self.m_uuid = "" self.normalBrush = QApplication.palette().dark() normalColor = self.normalBrush.color() normalColor.setAlphaF(0.8) self.normalBrush.setColor(normalColor) self.selectedBrush = QApplication.palette().light() selectedColor = self.selectedBrush.color() selectedColor.setAlphaF(0.8) self.selectedBrush.setColor(selectedColor) self.pen = QPen(QApplication.palette().text().color(), 1) path = QPainterPath() path.addRoundedRect(-50, -15, 100, 30, 5, 5) self.setPath(path) self.setBrush(self.normalBrush) self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable) self.effect = QGraphicsDropShadowEffect(None) self.effect.setBlurRadius(8) self.effect.setOffset(2, 2) self.setGraphicsEffect(self.effect) self.horzMargin = 20 self.vertMargin = 5 self.width = self.horzMargin self.height = self.vertMargin
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 addPort(self, name, isOutput = False, flags = 0, ptr = None): port = QNEPort(self) port.setName(name) port.setIsOutput(isOutput) port.setNEBlock(self) port.setPortFlags(flags) port.setPtr(ptr) fontmetrics = QFontMetrics(self.scene().font()); width = fontmetrics.width(name) height = fontmetrics.height() if width > self.width - self.horzMargin: self.width = width + self.horzMargin self.height += height path = QPainterPath() path.addRoundedRect(-self.width/2, -self.height/2, self.width, self.height, 5, 5) self.setPath(path) y = -self.height / 2 + self.vertMargin + port.radius() for port_ in self.childItems(): if port_.type() != QNEPort.Type: continue if port_.isOutput(): port_.setPos(self.width/2 + port.radius(), y) else: port_.setPos(-self.width/2 - port.radius(), y) y += height; return port
def __init__(self, x1, y1, x2, y2, rgb, parent=None): #OVERLOADED IMPL?# DimLeaderObject::DimLeaderObject(DimLeaderObject* obj, QGraphicsItem* parent) : BaseObject(parent) """ Default class constructor. :param `x1`: TOWRITE :type `x1`: qreal :param `y1`: TOWRITE :type `y1`: qreal :param `x2`: TOWRITE :type `x2`: qreal :param `y2`: TOWRITE :type `y2`: qreal :param `rgb`: TOWRITE :type `rgb`: QRgb :param `parent`: TOWRITE :type `parent`: `QGraphicsItem`_ """ super(DimLeaderObject, self).__init__(parent) qDebug("DimLeaderObject Constructor()") self.curved = bool() self.filled = bool() self.lineStylePath = QPainterPath() self.arrowStylePath = QPainterPath() self.arrowStyleAngle = float() # qreal self.arrowStyleLength = float() # qreal self.lineStyleAngle = float() # qreal self.lineStyleLength = float() # qreal self.init(x1, y1, x2, y2, rgb, Qt.SolidLine) # TODO: getCurrentLineType
def __init__(self, parent, scene, view): super(QNodesEditor, self).__init__(parent) self.scene = scene self.scene.installEventFilter(self) gridSize = 25 gridMap = QPixmap(gridSize,gridSize) gridPainter = QPainter(gridMap) gridPainter.fillRect(0,0,gridSize,gridSize, QApplication.palette().window().color().darker(103)) gridPainter.fillRect(1,1,gridSize-2,gridSize-2, QApplication.palette().window()) gridPainter.end() self.scene.setBackgroundBrush( QBrush(gridMap) ) originSize = 50 originItem = QGraphicsPathItem() path = QPainterPath() path.moveTo(0,-originSize) path.lineTo(0,originSize) path.moveTo(-originSize,0) path.lineTo(originSize,0) originItem.setPath(path) originItem.setPen(QPen(QApplication.palette().window().color().darker(110),2)) originItem.setZValue(-2) self.scene.addItem(originItem) self.view = view self.view.setDragMode(QGraphicsView.RubberBandDrag) self.view.setRenderHint(QPainter.Antialiasing) self.connection = None
def set_shape(self, width, height): ''' Define the bouding rectangle of the JOIN symbol ''' circ = min(width, height) path = QPainterPath() path.addEllipse(0, 0, circ, circ) self.setPath(path) super(Join, self).set_shape(width, height)
class SelectedMineral: def __init__(self, parent, code, persistent = False): self.parent = parent self.persistent = persistent self.isActive = True # maybe to delete self.code = code self.name = self.parent.qtColorsNames[self.code][0] self.color = self.parent.qtColorsNames[self.code][1] self.painterPath = QPainterPath() self.verts, self.edges = parent.fetchMineral(self.code) if not self.verts: self.isActive = False # TODO: try to make it static or abstract in the future def project(self, projector, alef=19, bet=30): self.points = {} projector.setupProjectionMatrix(alef, bet) for k, v in self.verts.iteritems(): self.points[k] = projector.project(v).tolist() for edge in self.edges.values(): p1 = self.points[edge[0]] p2 = self.points[edge[1]] self.painterPath.moveTo(p1[0], p1[1]) self.painterPath.lineTo(p2[0], p2[1])
def animate(self, shapes): self.start_signal.emit() time.sleep(self.start_delay) self.running = True self.ended = False max_radius = [] original_clips = [] centers = [] animating_radius = [] inc_rate = [] for s in shapes: # Setting max of width or height as radius, ergo "circular" reveal, # not "oval" reveal target = max(s.width, s.height) max_radius.append(target) # Starting from the zero reaching the max animating_radius.append(0) # Getting the original masks; Used in case of cancelation original_clips.append(s.clip) # Center of the shape, considering margin centers.append(QPoint((s.width / 2) + s.margin_start, (s.height / 2) + s.margin_top)) # Calculating the increase rate using the good ol' formula inc_rate.append((target / self.fps) * (1000 / self.duration)) while self.running or self.paused: if self.canceled: for i, s in enumerate(shapes): s.clip = original_clips[i] self.cancel_signal.emit() return elif self.ended: self.end_signal.emit() return elif self.paused: # Handling the pause self.pause_signal.emit() while not self.paused: pass self.resume_signal.emit() else: # Setting FPS from the animator time.sleep(1 / self.fps) completed = False for i, s in enumerate(shapes): if animating_radius[i] < max_radius[i]: path = QPainterPath() path.addEllipse(centers[i], animating_radius[i], animating_radius[i]) s.clip = path s.update() QApplication.processEvents() animating_radius[i] += inc_rate[i] else: completed = True # No need to check on every iteration, duration is same so # all objects are gonna end at the same time if completed: self.end_signal.emit() self.started = False self.ended = True return
def objectSavePath(self): """ TOWRITE :rtype: `QPainterPath`_ """ path = QPainterPath() path.lineTo(self.objectDeltaX(), self.objectDeltaY()) return path
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 set_shape(self, width, height): ''' Compute the polygon to fit in width, height ''' path = QPainterPath() path.lineTo(width, 0) path.lineTo(width, height) path.lineTo(0, height) path.lineTo(0, 0) self.setPath(path) super(Task, self).set_shape(width, height)
def objectSavePath(self): """ TOWRITE :rtype: `QPainterPath`_ """ path = QPainterPath() path.addRect(-0.00000001, -0.00000001, 0.00000002, 0.00000002) return path
def set_shape(self, width, height): ''' Define polygon points to draw the symbol ''' path = QPainterPath() path.moveTo(width / 2, 0) path.lineTo(width, height / 2) path.lineTo(width / 2, height) path.lineTo(0, height / 2) path.lineTo(width / 2, 0) self.setPath(path) super(Decision, 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 __init__(self, pos, edge): ''' Set the original control point - with color, shape ''' path = QPainterPath() path.addEllipse(pos.x() - 5, pos.y() - 5, 10, 10) super(Controlpoint, self).__init__(path, parent=edge) self.setPen(QColor(50, 100, 120, 200)) self.setBrush(QColor(200, 200, 210, 120)) self.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable) self.edge = edge self.hide()
def fillEllipse( self, painter, x, y, size, brush, ): path = QPainterPath() path.addEllipse(x, y, size, size) painter.fillPath(path, brush)
def set_shape(self, width, height): ''' Compute the polygon to fit in width, height ''' self.setPen(QPen(Qt.blue)) self.textbox_alignment = Qt.AlignLeft | Qt.AlignTop path = QPainterPath() path.moveTo(0, 0) path.lineTo(0, height) #path.moveTo(0, height / 2) #path.lineTo(width, height / 2) self.setPath(path) super(Input, self).set_shape(width, height)
def setLineFromLine(self, li): """ TOWRITE :param `li`: TOWRITE :type `li`: QPointF """ p = QPainterPath() p.moveTo(li.p1()) p.lineTo(li.p2()) self.setPath(p) self.objLine = li
def updatePath(self): path = QPainterPath() path.moveTo(self.pos1) dx = self.pos2.x() - self.pos1.x() dy = self.pos2.y() - self.pos1.y() ctr1 = QPointF(self.pos1.x() + dx * 0.25, self.pos1.y() + dy * 0.1) ctr2 = QPointF(self.pos1.x() + dx * 0.75, self.pos1.y() + dy * 0.9) path.cubicTo(ctr1, ctr2, self.pos2) self.setPath(path)
def shape(self): bound = QPainterPath() rotMatrix = QTransform().rotate(self.angle) poly = QPolygonF([ QPointF(0, 0), QPointF(self.w, 0), QPointF(self.w, self.h), QPointF(0, self.h), ]) poly = rotMatrix.map(poly) bound.addPolygon(poly) return bound
def set_shape(self, width, height): ''' Compute the polygon to fit in width, height ''' path = QPainterPath() path.addRoundedRect(0, 0, width, height, height / 4, height) if self.nested_scene and self.is_composite(): # Distinguish composite states with dash line self.setPen(QPen(Qt.DashLine)) else: self.setPen(QPen(Qt.SolidLine)) self.setPath(path) super(State, self).set_shape(width, height)
def __init__(self, parent): super(QNEOutputPort, self).__init__(parent) self.parent = parent self.setPen(self.parent.pen()) self.setBrush(self.parent.brush()) radius_ = parent.radius_ path = QPainterPath() path.addEllipse(0, -radius_, 2 * radius_, 2 * radius_) self.setPath(path)
def __init__(self, parent): super(QNEOutputPort, self).__init__(parent) self.parent = parent self.setPen(self.parent.pen()) self.setBrush(self.parent.brush()) radius_ = parent.radius_ path = QPainterPath() path.addEllipse(0, -radius_, 2*radius_, 2*radius_) self.setPath(path)
def setPortFlags(self, flags): self.m_portFlags = flags if self.m_portFlags & self.TypePort: font = self.scene().font() font.setItalic(True) self.label.setFont(font) self.setPath(QPainterPath()) elif self.m_portFlags & self.NamePort: font = self.scene().font() font.setBold(True) self.label.setFont(font) self.setPath(QPainterPath())
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 glass_path(scene, x, y, w, h, colr): qp = QPainterPath() qp.addRoundedRect(x, y, w, h, 5, 5) gradient = QLinearGradient(0, +0, 0, 1) gradient.setCoordinateMode(QGradient.ObjectBoundingMode) gradient.setColorAt(0, colr) gradient.setColorAt(1, colr.lighter(150)) brush = QBrush(gradient) item = QGraphicsPathItem() item.setPath(qp) item.setBrush(brush) scene.addItem(item) # Draw glass reflection glass = QPainterPath() r = 3 glass.addRoundedRect(x + r, y + r, w - 2 * r, 2 * r, r, r) gradient = QLinearGradient(0, +0, 0, 1) gradient.setCoordinateMode(QGradient.ObjectBoundingMode) gradient.setColorAt(0, QColor(255, 255, 255, 188)) gradient.setColorAt(1, QColor(255, 255, 255, 0)) brush = QBrush(gradient) item = QGraphicsPathItem() item.setPath(glass) item.setBrush(brush) item.setPen(QPen(Qt.transparent)) scene.addItem(item)
def paint(self, painter, styleOption, widget): ''' Reimplemented to paint elements in alternating colors ''' path = self.path() # alias pathEnd = None i = 0 while True: try: element = path.elementAt(i) # print type(element), element.type if element.isMoveTo(): pathEnd = QPointF(element.x, element.y) i+=1 elif element.isCurveTo(): # Gather curve data, since is spread across elements of type curveElementData cp1 = QPointF(element.x, element.y) element = path.elementAt(i+1) cp2 = QPointF(element.x, element.y) element = path.elementAt(i+2) newEnd = QPointF(element.x, element.y) # create a subpath, since painter has no drawCubic method subpath=QPainterPath() subpath.moveTo(pathEnd) subpath.cubicTo(cp1, cp2, newEnd) painter.drawPath(subpath) pathEnd = newEnd i+=3 else: print "unhandled path element", element.type i+=1 """ TODO: if SegmentStringss contain lines (w/o Direction ControlPoints) !!! We don't use QPathElements of type Line elif element.isLineTo(): newEnd = QPointF(element.x, element.y) painter.drawLine(pathEnd, newEnd) pathEnd = newEnd i+=1 """ if i >= path.elementCount(): break except Exception as inst: print inst break # Alternate colors if i%2 == 1: painter.setPen(Qt.blue) else: painter.setPen(Qt.red)
def _draw_indicator(self, event, qp): cx, cy, w, r = self._get_geometry(event) pen = qp.pen() pen.setWidth(3) pen.setColor(Qt.black) qp.setPen(pen) qp.setBrush(Qt.black) ro = r - 10 cx, cy = r + 5, r + 5 qp.translate(cx, cy) qp.rotate(self.indicator) path = QPainterPath() path.moveTo(-2, 0) path.lineTo(0, -ro) path.lineTo(2, 0) qp.drawPath(path) cr = 10 cr2 = cr / 2.0 qp.drawEllipse(-cr2, -cr2, cr, cr)
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 setCanConnect(self, hasInput, hasOutput): self.hasInput_ = hasInput self.hasOutput_ = hasOutput if self.hasOutput_: self.outputPort.setVisible(True) else: self.outputPort.setVisible(False) path = QPainterPath() if self.hasInput_: path.addEllipse(0, -self.radius_, 2*self.radius_, 2*self.radius_) else: pass self.setPath(path)
def __init__(self, parent): super(QNEBlock, self).__init__(parent) path = QPainterPath() path.addRoundedRect(-50, -15, 100, 30, 5, 5); self.setPath(path) self.setPen(QPen(Qt.darkGreen)) self.setBrush(Qt.green) self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable) self.horzMargin = 20 self.vertMargin = 5 self.width = self.horzMargin self.height = self.vertMargin
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 __init__(self, strng, x, y, rgb, parent=None): #OVERLOADED IMPL?# TextSingleObject::TextSingleObject(TextSingleObject* obj, QGraphicsItem* parent) : BaseObject(parent) """ Default class constructor. :param `strng`: TOWRITE :type `strng`: QString :param `x`: TOWRITE :type `x`: qreal :param `y`: TOWRITE :type `y`: qreal :param `rgb`: TOWRITE :type `rgb`: QRgb :param `parent`: TOWRITE :type `parent`: `QGraphicsItem`_ """ super(TextSingleObject, self).__init__(parent) qDebug("TextSingleObject Constructor()") self.objText = str() self.objTextFont = str() self.objTextJustify = str() self.objTextSize = float() # qreal self.objTextBold = bool() self.objTextItalic = bool() self.objTextUnderline = bool() self.objTextStrikeOut = bool() self.objTextOverline = bool() self.objTextBackward = bool() self.objTextUpsideDown = bool() self.objTextPath = QPainterPath() self.init(str, x, y, rgb, Qt.SolidLine) # TODO: getCurrentLineType
def objectSavePath(self): """ TOWRITE :rtype: `QPainterPath`_ """ path = QPainterPath() r = self.rect() # QRectF path.arcMoveTo(r, 0) path.arcTo(r, 0, 360) s = self.scale() # qreal trans = QTransform() trans.rotate(self.rotation()) trans.scale(s, s) return trans.map(path)
def setCanConnect(self, hasInput, hasOutput): self.hasInput_ = hasInput self.hasOutput_ = hasOutput if self.hasOutput_: self.outputPort.setVisible(True) else: self.outputPort.setVisible(False) path = QPainterPath() if self.hasInput_: path.addEllipse(0, -self.radius_, 2 * self.radius_, 2 * self.radius_) else: pass self.setPath(path)
def reshape(self): ''' Update the connection or arrow shape ''' shape = QPainterPath() shape.moveTo(self.start_point) for point in self.middle_points: shape.lineTo(point) shape.lineTo(self.end_point) # If required draw an arrow head (e.g. in SDL NEXTSTATE and JOIN) if self.child.arrow_head: self.draw_arrow_head(shape, origin='head', kind=self.child.arrow_head) if self.child.arrow_tail: shape.moveTo(shape.pointAtPercent(0)) self.draw_arrow_head(shape, origin='tail', kind=self.child.arrow_head) self.setPath(shape)
def reshape(self): ''' Update the connection shape - redefined: if the last element of a branch is e.g. a nextstate, don't join the connection point ''' if self.parentItem().terminal_symbol: self.setPath(QPainterPath()) else: super(JoinConnection, self).reshape()
def draw_edge(self, painter, option, edge, lane_offset): from_y = 0.5 + lane_offset to_y = 1 + from_y pen = QPen(self.edge_color(edge.color), self.edge_thickness, Qt.SolidLine, Qt.FlatCap, Qt.RoundJoin) painter.setPen(pen) if edge.from_lane == edge.to_lane: line_x = edge.from_lane + 0.5 painter.drawLine(QPointF(line_x, from_y), QPointF(line_x, to_y)) else: from_x = edge.from_lane + 0.5 to_x = edge.to_lane + 0.5 path = QPainterPath() path.moveTo(QPointF(from_x, from_y)) path.cubicTo(from_x, from_y + 0.5, to_x, to_y - 0.5, to_x, to_y) painter.drawPath(path)
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 setLineFromXXYY(self, x1, y1, x2, y2): """ TOWRITE :param `x1`: TOWRITE :type `x1`: qreal :param `y1`: TOWRITE :type `y1`: qreal :param `x2`: TOWRITE :type `x2`: qreal :param `y2`: TOWRITE :type `y2`: qreal """ p = QPainterPath() p.moveTo(x1, y1) p.lineTo(x2, y2) self.setPath(p) self.objLine.setLine(x1, y1, x2, y2)
def italic_block(self, start, width, h): slope = 0.3 # The QPoint below are ordered this way : # 1__2 # / / # 4__3 pts = [] pts.append(QPointF(start + h*slope,2)) pts.append(QPointF(start + h*slope + width,2)) pts.append(QPointF(start + 1 + width,h-1)) pts.append(QPointF(start + 1,h-1)) pts.append(pts[0]) # Closes the path qpp = QPainterPath() qpp.addPolygon(QPolygonF(pts)) return qpp
def updatePath(self): """ TOWRITE """ path = QPainterPath() r = self.rect() # QRectF path.arcMoveTo(r, 0) path.arcTo(r, 0, 360) # NOTE: Reverse the path so that the inside area isn't considered part of the ellipse path.arcTo(r, 0, -360) self.setObjectPath(path)
def __init__(self, scene): ''' Initialize the game ''' self.scene = scene scene.scene_left.connect(self.quit_scene) self.rocket = Rocket() self.width = self.scene.sceneRect().width() self.height = self.scene.sceneRect().height() self.screen_bottom = self.height - self.rocket.boundingRect().height() scene.addItem(self.rocket) # Compute random land points random.seed() p1 = QPointF(0.0, random.uniform(0.0, self.height)) p2 = QPointF(random.uniform(0.0, self.width / 4.0), random.uniform(0.0, self.height)) p3 = QPointF(random.uniform(p2.x(), 2 * self.width / 3.0), self.height) p4 = QPointF(p3.x() + 40.0, self.height) p5 = QPointF(self.width, random.uniform(0.0, self.height)) path = QPainterPath(p1) slope = (p2.y() - p1.y()) / (p2.x() - p1.x()) sign = 3 for point in range(int((p2.x() - p1.x()) / 5)): sign = -sign x = p1.x() + point * 5 path.lineTo(x, slope * x + sign) path.lineTo(p2) path.lineTo(p3) path.lineTo(p4) path.lineTo(p5) scene.addPath(path) # Initialize the music try: self.music = phonon.Phonon.createPlayer( phonon.Phonon.MusicCategory, phonon.Phonon.MediaSource(':/lander.mp3')) except NameError: LOG.warning('Could not initialise phonon') # Initialize the animation for the translation of the rocket self.animation = QtCore.QPropertyAnimation(self.rocket, "position") self.rocket_position = None # Initialize the animation for the rotation of the rocket self.rotation = QtCore.QPropertyAnimation(self.rocket, "angle") # Catch the key events to add user interaction: self.scene.keyPressEvent = lambda x: self.key(x) # updateCurrentTime is called by Qt when time changes self.animation.updateCurrentTime = lambda x: self.time_progress(x) # Connect signal sent at end of animation self.animation.finished.connect(self.animation_finished)
def realRender(self, painter, renderPath): # TODO/PORT: Still needs work. """ TOWRITE :param `painter`: TOWRITE :type `painter`: `QPainter`_ :param `renderPath`: TOWRITE :type `renderPath`: `QPainterPath`_ """ color1 = self.objectColor() #QColor # lighter color color2 = color1.darker(150) #QColor # darker color # If we have a dark color, lighten it darkness = color1.lightness() #int threshold = 32 #int #TODO: This number may need adjusted or maybe just add it to settings. if darkness < threshold: color2 = color1 if not darkness: color1 = QColor(threshold, threshold, threshold) # lighter() does not affect pure black else : color1 = color2.lighter(100 + threshold) count = renderPath.elementCount() # int for i in range(0, count - 1): # for(int i = 0; i < count-1; ++i); elem = renderPath.elementAt(i) # QPainterPath::Element next = renderPath.elementAt(i + 1) # QPainterPath::Element if next.isMoveTo(): continue elemPath = QPainterPath() elemPath.moveTo(elem.x, elem.y) elemPath.lineTo(next.x, next.y) renderPen = QPen(QColor(0, 0, 0, 0)) renderPen.setWidthF(0) painter.setPen(renderPen) stroker = QPainterPathStroker() stroker.setWidth(0.35) stroker.setCapStyle(Qt.RoundCap) stroker.setJoinStyle(Qt.RoundJoin) realPath = stroker.createStroke(elemPath) # QPainterPath painter.drawPath(realPath) grad = QLinearGradient(elemPath.pointAtPercent(0.5), elemPath.pointAtPercent(0.0)) grad.setColorAt(0, color1) grad.setColorAt(1, color2) grad.setSpread(QGradient.ReflectSpread) painter.fillPath(realPath, QBrush(grad))
def __init__(self, parent): super(QNEPort, self).__init__(parent) self.label = QGraphicsTextItem(self) self.radius_ = 4 self.margin = 3 path = QPainterPath() path.addEllipse(-self.radius_, -self.radius_, 2*self.radius_, 2*self.radius_); self.setPath(path) self.setPen(QPen(Qt.darkRed)) self.setBrush(Qt.red) self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges) self.m_portFlags = 0 self.isOutput_ = False self.m_block = None self.m_connections = []