began node viewer for dag insight
This commit is contained in:
@@ -20,41 +20,66 @@
|
||||
|
||||
#include "nodeviewitem.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QBrush>
|
||||
#include <QFontMetrics>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
|
||||
#include "ui/icons/icons.h"
|
||||
|
||||
const int kNodeViewItemBorderWidth = 2;
|
||||
const int kNodeViewItemWidth = 250;
|
||||
const int kNodeViewItemPadding = 5;
|
||||
const int kNodeViewItemTextPadding = 4;
|
||||
const int kNodeViewItemIconPadding = 12;
|
||||
|
||||
NodeViewItem::NodeViewItem(QGraphicsItem *parent) :
|
||||
QGraphicsRectItem(parent),
|
||||
node_(nullptr)
|
||||
{
|
||||
// Set flags for this widget
|
||||
setFlag(QGraphicsItem::ItemIsMovable);
|
||||
setFlag(QGraphicsItem::ItemIsSelectable);
|
||||
|
||||
// Use the current default font height to size this widget
|
||||
QFont f;
|
||||
QFontMetrics fm(f);
|
||||
|
||||
setRect(0, 0, kNodeViewItemWidth, fm.height() + kNodeViewItemPadding * 2);
|
||||
setRect(0, 0, kNodeViewItemWidth, fm.height() + kNodeViewItemTextPadding * 2);
|
||||
|
||||
// FIXME: Magic "number"/magic "color" - allow this to be editable by the user
|
||||
SetColor(QColor(32, 32, 128));
|
||||
}
|
||||
|
||||
void NodeViewItem::SetColor(const QColor &color)
|
||||
{
|
||||
color_ = color;
|
||||
|
||||
// Create a light gradient based on this color
|
||||
UpdateGradient();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void NodeViewItem::SetNode(Node *n)
|
||||
{
|
||||
node_ = n;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
Node *NodeViewItem::node()
|
||||
{
|
||||
return node_;
|
||||
}
|
||||
|
||||
void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget)
|
||||
|
||||
// Set up border, which will change color if selected
|
||||
QPen pen;
|
||||
|
||||
pen.setWidth(kNodeViewItemBorderWidth);
|
||||
|
||||
if (option->state & QStyle::State_Selected) {
|
||||
pen.setColor(qApp->palette().highlight().color());
|
||||
pen.setColor(widget->palette().highlight().color());
|
||||
} else {
|
||||
// FIXME: Not configurable?
|
||||
pen.setColor(Qt::black);
|
||||
@@ -62,16 +87,37 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
|
||||
// Draw rect
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(qApp->palette().window());
|
||||
painter->setBrush(brush());
|
||||
painter->drawRect(rect());
|
||||
|
||||
|
||||
// Draw text
|
||||
if (node_ != nullptr) {
|
||||
painter->setPen(qApp->palette().text().color());
|
||||
// FIXME: The text is always drawn white assuming the color will be dark - the intention is to provide preset
|
||||
// colors that will always be dark for the user to choose, so this value can stay white.
|
||||
painter->setPen(Qt::white);
|
||||
|
||||
// Draw the expand icon
|
||||
QRectF icon_rect = rect();
|
||||
icon_rect.adjust(kNodeViewItemIconPadding,
|
||||
kNodeViewItemIconPadding,
|
||||
-kNodeViewItemIconPadding,
|
||||
-kNodeViewItemIconPadding);
|
||||
olive::icon::TriRight.paint(painter, icon_rect.toRect(), Qt::AlignLeft | Qt::AlignVCenter);
|
||||
|
||||
// Draw the text in a rect (the rect is sized around text already in the constructor)
|
||||
QRectF text_rect = rect();
|
||||
text_rect.adjust(kNodeViewItemPadding, kNodeViewItemPadding, -kNodeViewItemPadding, -kNodeViewItemPadding);
|
||||
text_rect.adjust(kNodeViewItemIconPadding + icon_rect.height() + kNodeViewItemTextPadding,
|
||||
kNodeViewItemTextPadding,
|
||||
-kNodeViewItemTextPadding,
|
||||
-kNodeViewItemTextPadding);
|
||||
painter->drawText(text_rect, Qt::AlignTop | Qt::AlignLeft, node_->Name());
|
||||
}
|
||||
}
|
||||
|
||||
void NodeViewItem::UpdateGradient()
|
||||
{
|
||||
QLinearGradient grad(QPointF(0, rect().top()), QPointF(0, rect().bottom()));
|
||||
grad.setColorAt(0, color_.lighter(175));
|
||||
grad.setColorAt(1, color_);
|
||||
setBrush(grad);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user