Beispiel #1
0
class FuncItem(KineticsDisplayItem):
    name = constants.ITEM
    """Class for displaying Functions"""
    #fontMetrics = None
    font = QtGui.QFont(KineticsDisplayItem.defaultFontName)
    font.setPointSize(KineticsDisplayItem.defaultFontSize)
    fontMetrics = QtGui.QFontMetrics(font)

    def __init__(self, mobj, parent):
        super(FuncItem, self).__init__(mobj, parent)
        self.setFlag(QGraphicsItem.ItemIsMovable, True)
        iconmap_file = (os.path.join(config.settings[config.KEY_ICON_DIR],
                                     'classIcon/Function.png'))
        self.funcImage = QtGui.QImage(iconmap_file).scaled(15, 33)
        self.bg = QGraphicsRectItem(self)
        self.bg.setAcceptHoverEvents(True)
        self.gobj = QGraphicsPixmapItem(
            QtGui.QPixmap.fromImage(self.funcImage), self.bg)
        self.gobj.setAcceptHoverEvents(True)
        self.gobj.mobj = self.mobj
        funcdoc = (moose.element(self.mobj.path)).expr
        self.gobj.setToolTip(funcdoc)

    def setDisplayProperties(self, x, y, textcolor, bgcolor):
        """Set the display properties of this item."""
        poolt = ["ZombieBufPool", "BufPool", "ZombiePool", "Pool"]
        if self.gobj.mobj.parent.className in poolt:
            self.setGeometry(0, 30,
                             self.gobj.boundingRect().width(),
                             self.gobj.boundingRect().height())
        else:
            self.setGeometry(x, y,
                             self.gobj.boundingRect().width(),
                             self.gobj.boundingRect().height())
        self.bg.setBrush(QtGui.QBrush(bgcolor))
        self.setFlag(QGraphicsItem.ItemIsMovable, False)

    def refresh(self, scale):
        pass

    def boundingRect(self):
        ''' reimplimenting boundingRect for redrawning '''
        return QtCore.QRectF(0, 0,
                             self.gobj.boundingRect().width(),
                             self.gobj.boundingRect().height())

    def updateSlot(self):
        return None

    def updateColor(self, bgcolor):
        return None

    def updateRect(self, ratio):
        return None

    def returnColor(self):
        return (self.bg.brush().color())

    def updateValue(self, gobj, funcdoc='Not Available'):
        self.gobj.setToolTip(funcdoc)
    def on_actItem_Rect(self):  # 添加一个矩形  _triggered
        rect = QRectF(-50, -25, 100, 50)
        item = QGraphicsRectItem(rect)  # x,y 为左上角的图元局部坐标,图元中心点为0,0
        item.rect = rect
        item.setFlags(QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable)
        item.brush = Qt.yellow
        item.setBrush(QBrush(item.brush))
        item.style = Qt.SolidLine
        #item.setTransform(QTransform())
        self.view.frontZ = self.view.frontZ + 1
        item.setZValue(self.view.frontZ)
        item.setPos(-50 + (QtCore.qrand() % 100), -50 + (QtCore.qrand() % 100))
        self.view.seqNum = self.view.seqNum + 1
        item.setData(self.view.ItemId, self.view.seqNum)
        item.setData(self.view.ItemDesciption, "矩形")

        self.scene.addItem(item)
        self.scene.clearSelection()
        item.setSelected(True)
Beispiel #3
0
class PoolItem(KineticsDisplayItem):
    name = constants.ITEM
    """Class for displaying pools. Uses a QGraphicsSimpleTextItem to
    display the name."""
    #fontMetrics = None
    font = QtGui.QFont(KineticsDisplayItem.defaultFontName)
    font.setPointSize(KineticsDisplayItem.defaultFontSize)
    fontMetrics = QtGui.QFontMetrics(font)

    def __init__(self, mobj, parent):
        KineticsDisplayItem.__init__(self, mobj, parent)
        self.bg = QGraphicsRectItem(self)
        self.bg.setAcceptHoverEvents(True)
        self.gobj = QtGui.QGraphicsSimpleTextItem(self.mobj.name, self.bg)
        self.gobj.mobj = self.mobj
        self._conc = self.mobj.conc
        self._n = self.mobj.n
        doc = "Conc\t: " + str(self._conc) + "\nn\t: " + str(self._n)
        self.gobj.setToolTip(doc)
        self.gobj.setFont(PoolItem.font)
        if not PoolItem.fontMetrics:
            PoolItem.fontMetrics = QtGui.QFontMetrics(self.gobj.font())
        self.bg.setRect(
            0, 0,
            self.gobj.boundingRect().width() +
            PoolItem.fontMetrics.width('  '),
            self.gobj.boundingRect().height())
        self.bg.setPen(Qt.QColor(0, 0, 0, 0))
        self.gobj.setPos(PoolItem.fontMetrics.width(' '), 0)

    def setDisplayProperties(self, x, y, textcolor, bgcolor):
        """Set the display properties of this item."""
        self.setGeometry(
            x, y,
            self.gobj.boundingRect().width() + PoolItem.fontMetrics.width(''),
            self.gobj.boundingRect().height())
        self.bg.setBrush(QtGui.QBrush(bgcolor))

    def refresh(self, scale):
        fontsize = KineticsDisplayItem.defaultFontSize * scale
        font = QtGui.QFont(KineticsDisplayItem.defaultFontName)
        if (fontsize < 1):
            fontsize = self.gobj.font().pointSize()
        font.setPointSize(fontsize)
        #self.gobj.setFont(PoolItem.font)
        self.gobj.setFont(font)

    def boundingRect(self):
        ''' reimplimenting boundingRect for redrawning '''
        return QtCore.QRectF(
            0, 0,
            self.gobj.boundingRect().width() +
            PoolItem.fontMetrics.width('  '),
            self.gobj.boundingRect().height())

    def updateSlot(self):
        #This func will adjust the background color with respect to text size
        self.gobj.setText(self.mobj.name)
        self.bg.setRect(
            0, 0,
            self.gobj.boundingRect().width() +
            PoolItem.fontMetrics.width('  '),
            self.gobj.boundingRect().height())
        self.setGeometry(
            self.pos().x(),
            self.pos().y(),
            self.gobj.boundingRect().width() + PoolItem.fontMetrics.width(''),
            self.gobj.boundingRect().height())

    def updateColor(self, bgcolor):
        self.bg.setBrush(QtGui.QBrush(QtGui.QColor(bgcolor)))

    def updateRect(self, ratio=1.0):
        width = self.gobj.boundingRect().width() + PoolItem.fontMetrics.width(
            ' ')
        height = self.gobj.boundingRect().height()
        adjustw = width * ratio
        adjusth = height * ratio
        self.bg.setRect(width / 2 - abs(adjustw / 2),
                        height / 2 - abs(adjusth / 2), adjustw, adjusth)

    def returnColor(self):
        return (self.bg.brush().color())

    def updateValue(self, gobj):
        self._gobj = gobj
        if (isinstance(self._gobj, moose.PoolBase)):
            self._conc = self.mobj.conc
            self._n = self.mobj.n
            doc = "Conc\t: " + str(self._conc) + "\nn\t: " + str(self._n)
            self.gobj.setToolTip(doc)