Exemple #1
0
class FloatingActionButton(QPushButton):
    def __init__(self,
                 color=QColor(243, 40, 109, 255),
                 radius=50,
                 icon="plus.png",
                 parent=None):
        super(FloatingActionButton, self).__init__(parent)
        if icon:
            self.pixmap = QPixmap(icon)
        self.setMouseTracking(True)
        self.effect = QGraphicsDropShadowEffect(self.parent())
        self.effect.setXOffset(4)
        self.effect.setBlurRadius(4)
        self.effect.setColor(QColor(0, 0, 0, 40))
        self.setGraphicsEffect(self.effect)
        self.color = color
        self.radius = radius
        self.resize(self.radius + 1, self.radius + 1)
        self.setMaximumSize(self.size())
        self.setMinimumSize(self.size())
        self.effect_size = self.radius

    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.HighQualityAntialiasing)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setRenderHint(QPainter.SmoothPixmapTransform)
        painter.setBrush(self.color)
        if self.effect_size == self.radius:
            painter.drawEllipse(1, 1, self.radius - 1, self.radius - 1)
            painter.drawPixmap(QRect(14, 14, self.radius / 2, self.radius / 2),
                               self.pixmap)
        else:
            painter.drawEllipse(self.width() / 2,
                                self.height() / 2, self.effect_size,
                                self.effect_size)
        painter.end()

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.animate()

    def animate(self):
        while self.effect_size > 1:
            self.effect_size -= 2
            self.repaint()
            time.sleep(0.008)
Exemple #2
0
def createGlowEffect(parent=None, color=GLOW_COLOR, radius=16, offset=1):
    """
  @param* parent  QWidget
  @param* color  QColor or str or None
  @param* radius  int
  @param* offset  int
  @return  QGraphicsEffect
  """
    #if skos.MAC: # graphics effect on mac is not observable
    #  return None
    #from pyeffects import GraphicsTextShadowEffect
    #ret = GraphicsTextShadowEffect(parent)
    ret = QGraphicsDropShadowEffect(parent)
    ret.setBlurRadius(radius)
    ret.setOffset(offset)
    if color:
        if not isinstance(color, QColor):
            color = QColor(color)
        ret.setColor(color)
    return ret
Exemple #3
0
class FloatingActionButton(QPushButton):
    def __init__(self, color=QColor(243, 40, 109, 255), radius=50, icon="plus.png", parent=None):
        super(FloatingActionButton, self).__init__(parent)
        if icon:
            self.pixmap = QPixmap(icon)
        self.setMouseTracking(True)
        self.effect = QGraphicsDropShadowEffect(self.parent())
        self.effect.setXOffset(4)
        self.effect.setBlurRadius(4)
        self.effect.setColor(QColor(0, 0, 0, 40))
        self.setGraphicsEffect(self.effect)
        self.color = color
        self.radius = radius
        self.resize(self.radius + 1, self.radius + 1)
        self.setMaximumSize(self.size())
        self.setMinimumSize(self.size())
        self.effect_size = self.radius

    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.HighQualityAntialiasing)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setRenderHint(QPainter.SmoothPixmapTransform)
        painter.setBrush(self.color)
        if self.effect_size == self.radius:
            painter.drawEllipse(1, 1, self.radius - 1, self.radius - 1)
            painter.drawPixmap(QRect(14, 14, self.radius / 2, self.radius / 2), self.pixmap)
        else:
            painter.drawEllipse(self.width() / 2, self.height() / 2, self.effect_size, self.effect_size)
        painter.end()

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.animate()

    def animate(self):
        while self.effect_size > 1:
            self.effect_size -= 2
            self.repaint()
            time.sleep(0.008)
Exemple #4
0
class QNEBlock(QGraphicsPathItem):
    (Type) = (QGraphicsItem.UserType + 3)

    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 __del__(self):
        #print("Del QNEBlock")
        pass

    def delete(self):
        for port in self.ports():
            for connection in port.connections():
                connection.delete()
            port.delete()
        if self.scene():
            self.scene().removeItem(self)

    def paint(self, painter, option, widget):
        if self.isSelected():
            painter.setBrush(self.selectedBrush)
        else:
            painter.setBrush(self.normalBrush)
        painter.setPen(self.pen)

        painter.drawPath(self.path())

    def itemChange(self, change, value):
        if change == QGraphicsItem.ItemSelectedHasChanged:
            self.setZValue(1 if value else 0)

        return value

    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 addNonePort(self, name):
        self.addPort(name, False, False)

    def addInputPort(self, name):
        self.addPort(name, True, False)

    def addOutputPort(self, name):
        self.addPort(name, False, True)

    def addInputOutputPort(self, name):
        self.addPort(name, True, True)

    def addNonePorts(self, names):
        for name in names:
            self.addNonePort(name)

    def addInputPorts(self, names):
        for name in names:
            self.addInputPort(name)

    def addOutputPorts(self, names):
        for name in names:
            self.addOutputPort(name)

    def addInputOutputPorts(self, names):
        for name in names:
            self.addInputOutputPort(name)

    def clone(self):
        block = QNEBlock(None)
        self.scene().addItem(block)

        for port_ in self.childItems():
            block.addPort(port_.portName(), port_.hasInput(),
                          port_.hasOutput(), port_.portFlags())

        return block

    def ports(self):
        result = []
        for port_ in self.childItems():
            if port_.type() == QNEPort.Type:
                result.append(port_)

        return result

    def type(self):
        return self.Type

    def setName(self, name):
        self.m_name = name

    def name(self):
        return self.m_name

    def setUuid(self, uuid):
        self.m_uuid = uuid

    def uuid(self):
        return self.m_uuid

    def setNodeEditor(self, editor):
        self.m_nodeEditor = editor

    def nodeEditor(self):
        return self.m_nodeEditor