|
- #include "item.h"
- #include <QPainter>
- #include <QStyleOptionGraphicsItem>
-
- Item::Item(const QString &type, QGraphicsItem *parent)
- : QGraphicsObject(parent), type_(type)
- {
- if (type == "常开") color_ = Qt::blue;
- else if (type == "常闭") color_ = Qt::red;
- else if (type == "比较指令") color_ = Qt::green;
- else color_ = Qt::darkYellow;
-
- setFlags(QGraphicsItem::ItemIsMovable |
- QGraphicsItem::ItemIsSelectable |
- QGraphicsItem::ItemSendsGeometryChanges);
- }
-
- QRectF Item::boundingRect() const
- {
- return QRectF(0, 0, 80, 40);
- }
-
- void Item::paint(QPainter *painter,
- const QStyleOptionGraphicsItem *,
- QWidget *)
- {
- painter->setBrush(color_.lighter(150));
- painter->setPen(QPen(color_, 2));
- painter->drawRoundedRect(boundingRect(), 5, 5);
-
- painter->setPen(Qt::black);
- painter->drawText(boundingRect(), Qt::AlignCenter, type_);
- }
|