effect UIs ported to nodes
This commit is contained in:
+28
-12
@@ -10,33 +10,55 @@
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QPainter>
|
||||
|
||||
const int kRoundedRectRadius = 5;
|
||||
|
||||
NodeUI::NodeUI() :
|
||||
central_widget_(this)
|
||||
central_widget_(nullptr)
|
||||
{
|
||||
setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
}
|
||||
|
||||
NodeUI::~NodeUI()
|
||||
{
|
||||
if (scene() != nullptr) {
|
||||
scene()->removeItem(proxy_);
|
||||
scene()->removeItem(this);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeUI::AddToScene(QGraphicsScene *scene)
|
||||
{
|
||||
scene->addItem(this);
|
||||
|
||||
QGraphicsProxyWidget* proxy = scene->addWidget(¢ral_widget_);
|
||||
proxy->setPos(pos());
|
||||
proxy->setParentItem(this);
|
||||
if (central_widget_ != nullptr) {
|
||||
proxy_ = scene->addWidget(central_widget_);
|
||||
proxy_->setPos(pos() + QPoint(kRoundedRectRadius, kRoundedRectRadius));
|
||||
proxy_->setParentItem(this);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeUI::Resize(const QSize &s)
|
||||
{
|
||||
QRectF rectangle = rect();
|
||||
|
||||
rectangle.setSize(s);
|
||||
rectangle.setSize(s + 2 * QSize(kRoundedRectRadius, kRoundedRectRadius));
|
||||
|
||||
path_ = QPainterPath();
|
||||
path_.addRoundedRect(rectangle, kRoundedRectRadius, kRoundedRectRadius);
|
||||
|
||||
setRect(rectangle);
|
||||
}
|
||||
|
||||
void NodeUI::SetWidget(QWidget *widget)
|
||||
{
|
||||
central_widget_ = widget;
|
||||
}
|
||||
|
||||
void NodeUI::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget)
|
||||
|
||||
QPalette palette = qApp->palette();
|
||||
|
||||
if (option->state & QStyle::State_Selected) {
|
||||
@@ -45,11 +67,5 @@ void NodeUI::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
|
||||
painter->setPen(palette.base().color());
|
||||
}
|
||||
painter->setBrush(palette.window());
|
||||
|
||||
QRectF r = rect();
|
||||
r.setX(r.x() - 1);
|
||||
r.setY(r.y() - 1);
|
||||
r.setRight(r.right() + 1);
|
||||
r.setBottom(r.bottom() + 1);
|
||||
painter->drawRect(r);
|
||||
painter->drawPath(path_);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user