Node *item = new Node(m_selectedJFIName.c_str(), 2);
addItem(item);
Node *item = new Node(m_selectedJFIName.c_str(), 2);
addItem(item);
To copy to clipboard, switch view to plain text mode
{
public:
virtual ~Node();
private:
QList<QGraphicsRectItem *> m_inports;
};
class Node : public QGraphicsTextItem
{
public:
Node(std::string text, int nports=2, QGraphicsItem *parent = 0);
virtual ~Node();
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
private:
QGraphicsTextItem *m_text;
QList<QGraphicsRectItem *> m_inports;
QGraphicsRectItem *m_outport;
};
To copy to clipboard, switch view to plain text mode
{
int tick = boundingRect().width()/(nports+1);
for (int i=0; i<nports; ++i) {
iport->setZValue(1);
m_inports.push_back(iport);
}
m_outport->setZValue(1);
}
Node::~Node()
{
while (!m_inports.isEmpty())
delete m_inports.takeFirst();
if (m_outport) {
delete m_outport;
m_outport = 0;
}
if (m_text) {
delete m_text;
m_text = 0;
}
}
QRectF Node
::boundingRect() const {
t2.setHeight(t.height()+10);
t2.setWidth(t.width()+10);
return t2;
}
{
t2.setHeight(t.height()+10);
t2.setWidth(t.width()+10);
path.addEllipse(t2);
return path;
}
{
painter
->setPen
(QPen(Qt
::black,
1));
painter->drawRoundedRect(0, 0, boundingRect().width(),
boundingRect().height(), 5, 5);
int count = m_inports.count();
for (int i=0; i<count; ++i) {
m_inports.at(i)->paint(painter, option, widget);
}
m_outport->paint(painter, option, widget);
}
Node::Node(std::string text, int nports, QGraphicsItem *parent)
: QGraphicsTextItem(text.c_str(), parent)
{
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
int tick = boundingRect().width()/(nports+1);
for (int i=0; i<nports; ++i) {
QGraphicsRectItem *iport = new QGraphicsRectItem(QRectF((i+1)*tick, -10, 10, 10));
iport->setZValue(1);
m_inports.push_back(iport);
}
m_outport = new QGraphicsRectItem(QRectF(40, 27, 10, 10));
m_outport->setZValue(1);
}
Node::~Node()
{
while (!m_inports.isEmpty())
delete m_inports.takeFirst();
if (m_outport) {
delete m_outport;
m_outport = 0;
}
if (m_text) {
delete m_text;
m_text = 0;
}
}
QRectF Node::boundingRect() const
{
const QRectF t = QGraphicsTextItem::boundingRect();
QRectF t2;
t2.setHeight(t.height()+10);
t2.setWidth(t.width()+10);
return t2;
}
QPainterPath Node::shape() const
{
const QRectF t = QGraphicsTextItem::boundingRect();
QRectF t2;
t2.setHeight(t.height()+10);
t2.setWidth(t.width()+10);
QPainterPath path;
path.addEllipse(t2);
return path;
}
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(QPen(Qt::black, 1));
painter->drawRoundedRect(0, 0, boundingRect().width(),
boundingRect().height(), 5, 5);
QGraphicsTextItem::paint(painter, option, widget);
int count = m_inports.count();
for (int i=0; i<count; ++i) {
m_inports.at(i)->paint(painter, option, widget);
}
m_outport->paint(painter, option, widget);
}
To copy to clipboard, switch view to plain text mode
Bookmarks