def __init__(self, node, text, secondaryText="", icon=None, parent=None): super(NodeHeader, self).__init__(parent) self._node = node self.setSizePolicy( QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)) layout = QtWidgets.QGraphicsLinearLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.setOrientation(QtCore.Qt.Horizontal) self.setLayout(layout) self.headerIcon = HeaderPixmap(pixmap=icon or "", parent=self) layout.addItem(self.headerIcon) if not icon: self.headerIcon.hide() self._createLabels(text, secondaryText, layout) layout.addStretch(1) headerButton = NodeHeaderButton(size=12, color=node.model.headerButtonColor()) headerButton.stateChanged.connect(self.headerButtonStateChanged.emit) layout.addItem(headerButton) layout.setAlignment(headerButton, QtCore.Qt.AlignCenter | QtCore.Qt.AlignCenter)
def __init__(self, orientation=QtCore.Qt.Vertical, parent=None): super(ItemContainer, self).__init__(parent=parent) self.setSizePolicy( QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)) layout = QtWidgets.QGraphicsLinearLayout() layout.setSpacing(2) layout.setContentsMargins(0, 0, 0, 0) layout.setOrientation(orientation) self.setLayout(layout)
def __init__(self, color, edgeColor, highlightColor, ioType, parent=None): super(Plug, self).__init__(parent=parent) size = QtCore.QSizeF(self._diameter, self._diameter) self.ioType = "" self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)) self.setPreferredSize(size) self.setWindowFrameMargins(0, 0, 0, 0) self._defaultPen = QtGui.QPen(edgeColor, 2.5) self._hoverPen = QtGui.QPen(highlightColor, 3.0) self._defaultBrush = QtGui.QBrush(color) self._currentBrush = QtGui.QBrush(color) self.setAcceptHoverEvents(True)
def __init__(self, parent=None): super(CrossSquare, self).__init__(parent) size = QtCore.QSizeF(Plug._diameter, Plug._diameter) self.expanded = False self.isElement = False self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)) self.setPreferredSize(size) self.setWindowFrameMargins(0, 0, 0, 0) self.hide() self.lines = [QtCore.QLineF(QtCore.QPoint(Plug._diameter * 0.5, 3.0), QtCore.QPoint(Plug._diameter * 0.5, Plug._diameter - 3.0)), QtCore.QLineF(QtCore.QPoint(3.0, Plug._diameter * 0.5), QtCore.QPoint(Plug._diameter - 3.0, Plug._diameter * 0.5)) ]
def __init__(self, node, text, parent=None): super(NodeHeader, self).__init__(parent) self._node = node self.setSizePolicy( QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)) layout = QtWidgets.QGraphicsLinearLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.setOrientation(QtCore.Qt.Horizontal) self.setLayout(layout) self._createLabel(text, layout) layout.addStretch(1)
def _createLabel(self, primary, parentLayout): container = graphicitems.ItemContainer(QtCore.Qt.Vertical, parent=self) container.setSizePolicy( QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)) self._titleWidget = graphicitems.GraphicsText(primary, self) self._titleWidget.setTextFlags( QtWidgets.QGraphicsItem.ItemIsSelectable & QtWidgets.QGraphicsItem.ItemIsFocusable & QtWidgets.QGraphicsItem.ItemIsMovable) self._titleWidget.font = QtGui.QFont("Roboto-Bold.ttf", 8) container.addItem(self._titleWidget, QtCore.Qt.AlignCenter | QtCore.Qt.AlignTop) parentLayout.addItem(container)
def __init__(self, objectModel, position=(0, 0, 0)): super(GraphicsNode, self).__init__() self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable, True) self.setSizePolicy( QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)) self.setMinimumWidth(objectModel.minimumWidth()) self.setMinimumHeight(objectModel.minimumHeight()) self.model = objectModel self.backgroundColour = QtGui.QBrush(self.model.backgroundColour()) self.cornerRounding = self.model.cornerRounding() self.setZValue(1) self.setPos(position)
def __init__(self, text, *args, **kwargs): super(TextContainer, self).__init__(*args, **kwargs) self.setSizePolicy( QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)) layout = QtWidgets.QGraphicsLinearLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.setOrientation(QtCore.Qt.Horizontal) self.setLayout(layout) self.title = GraphicsText(text, parent=self) layout.addItem(self.title) layout.setAlignment(self.title, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop)
def __init__(self, text, parent=None): super(GraphicsText, self).__init__(parent=parent) self._previousText = text self._item = QtWidgets.QGraphicsTextItem(text, parent=self) self._item.setDefaultTextColor(self._color) self._item.setFont(self._font) self._item.document().contentsChanged.connect(self.onTextChanged) self.setPreferredSize(self.size) self.setSizePolicy( QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)) self._item.setFlags(QtWidgets.QGraphicsItem.ItemIsSelectable | QtWidgets.QGraphicsItem.ItemIsFocusable | QtWidgets.QGraphicsItem.ItemIsMovable) self._item.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction) option = self._item.document().defaultTextOption() option.setWrapMode(QtGui.QTextOption.NoWrap) self._item.document().setDefaultTextOption(option) self.allowHoverHighlight = False self.setAcceptHoverEvents(True) self.adjustSize()
def __init__(self, objectModel, ioType, acceptsContextMenu=False, parent=None): super(Panel, self).__init__(parent=parent) self.model = objectModel self.ioType = ioType layout = QtWidgets.QGraphicsLinearLayout(parent=self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(1) layout.setOrientation(QtCore.Qt.Vertical) self.attributeContainer = graphicitems.ItemContainer(parent=self) layout.addItem(self.attributeContainer) self.setSizePolicy( QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)) self.acceptsContextMenu = acceptsContextMenu self.setLayout(layout) self.setFlags(self.flags() & QtCore.Qt.ItemIsSelectable) self.setZValue(100) self.refresh()