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 __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 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 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 set_shape(self, width, height): ''' Compute the polygon to fit in width, height ''' path = QPainterPath() path.addRoundedRect(0, 0, width, height, height / 2, height / 2) path.moveTo(min(width / 2, height / 2), 0) path.lineTo(min(width / 2, height / 2), height) path.moveTo(max(width / 2, width - height / 2), 0) path.lineTo(max(width / 2, width - height / 2), height) self.setPath(path) super(Start, self).set_shape(width, height)
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(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 set_shape(self, width, height): ''' Compute the polygon to fit in width, height ''' path = QPainterPath() path.addRoundedRect(0, 0, width, height, height / 2, height / 2) self.setPath(path) super(Start, self).set_shape(width, height)