ui: new style for bundle node
This commit is contained in:
@@ -33,6 +33,8 @@ add_files(
|
||||
|
||||
qt/graphics/QtAngledLineItem.cpp
|
||||
qt/graphics/QtAngledLineItem.h
|
||||
qt/graphics/QtCountCircleItem.cpp
|
||||
qt/graphics/QtCountCircleItem.h
|
||||
qt/graphics/QtRoundedRectItem.cpp
|
||||
qt/graphics/QtRoundedRectItem.h
|
||||
qt/graphics/QtStraightLineItem.cpp
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "qt/graphics/QtCountCircleItem.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QFontMetrics>
|
||||
#include <QPen>
|
||||
|
||||
#include "component/view/GraphViewStyle.h"
|
||||
|
||||
QtCountCircleItem::QtCountCircleItem(QGraphicsItem* parent)
|
||||
: QtRoundedRectItem(parent)
|
||||
{
|
||||
this->setRadius(100);
|
||||
this->setAcceptHoverEvents(true);
|
||||
|
||||
QFont font;
|
||||
font.setFamily(GraphViewStyle::getFontNameOfExpandToggleNode().c_str());
|
||||
font.setPixelSize(GraphViewStyle::getFontSizeOfCountCircle());
|
||||
font.setWeight(QFont::Normal);
|
||||
|
||||
m_number = new QGraphicsSimpleTextItem(this);
|
||||
m_number->setFont(font);
|
||||
}
|
||||
|
||||
QtCountCircleItem::~QtCountCircleItem()
|
||||
{
|
||||
}
|
||||
|
||||
void QtCountCircleItem::setPosition(const Vec2f& pos)
|
||||
{
|
||||
qreal radius = getRadius();
|
||||
this->setRect(pos.x - radius, pos.y - radius, 2 * radius, 2 * radius);
|
||||
|
||||
m_number->setPos(
|
||||
pos.x - radius + 5,
|
||||
pos.y - QFontMetrics(m_number->font()).height() / 2
|
||||
);
|
||||
}
|
||||
|
||||
void QtCountCircleItem::setNumber(size_t number)
|
||||
{
|
||||
QString numberStr = QString::number(number);
|
||||
m_number->setText(numberStr);
|
||||
|
||||
qreal radius = QFontMetrics(m_number->font()).width(numberStr) / 2 + 5;
|
||||
this->setRadius(radius);
|
||||
|
||||
QPointF center = this->rect().center();
|
||||
this->setPosition(Vec2f(center.x(), center.y()));
|
||||
}
|
||||
|
||||
void QtCountCircleItem::setStyle(QColor color, QColor fontColor, QColor borderColor, size_t borderWidth)
|
||||
{
|
||||
this->setBrush(color);
|
||||
this->setPen(QPen(borderColor, borderWidth));
|
||||
|
||||
m_number->setBrush(fontColor);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef QT_COUNT_CIRCLE_ITEM_H
|
||||
#define QT_COUNT_CIRCLE_ITEM_H
|
||||
|
||||
#include "utility/math/Vector2.h"
|
||||
|
||||
#include "qt/graphics/QtRoundedRectItem.h"
|
||||
|
||||
class QtCountCircleItem
|
||||
: public QtRoundedRectItem
|
||||
{
|
||||
public:
|
||||
QtCountCircleItem(QGraphicsItem* parent);
|
||||
virtual ~QtCountCircleItem();
|
||||
|
||||
void setPosition(const Vec2f& pos);
|
||||
void setNumber(size_t number);
|
||||
void setStyle(QColor color, QColor fontColor, QColor borderColor, size_t borderWidth);
|
||||
|
||||
private:
|
||||
QGraphicsSimpleTextItem* m_number;
|
||||
};
|
||||
|
||||
#endif // QT_COUNT_CIRCLE_ITEM_H
|
||||
@@ -41,6 +41,11 @@ void QtRoundedRectItem::setShadowEnabled(bool enabled)
|
||||
}
|
||||
}
|
||||
|
||||
qreal QtRoundedRectItem::getRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
void QtRoundedRectItem::setRadius(qreal radius)
|
||||
{
|
||||
m_radius = radius;
|
||||
|
||||
@@ -14,6 +14,8 @@ public:
|
||||
|
||||
void setShadow(QColor color, int blurRadius);
|
||||
void setShadowEnabled(bool enabled);
|
||||
|
||||
qreal getRadius() const;
|
||||
void setRadius(qreal radius);
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#include "qt/graphics/QtStraightLineItem.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QFontMetrics>
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
#include "utility/math/Vector2.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
#include "qt/graphics/QtRoundedRectItem.h"
|
||||
#include "qt/graphics/QtCountCircleItem.h"
|
||||
#include "settings/ColorScheme.h"
|
||||
|
||||
QtStraightLineItem::QtStraightLineItem(QGraphicsItem* parent)
|
||||
@@ -15,21 +14,7 @@ QtStraightLineItem::QtStraightLineItem(QGraphicsItem* parent)
|
||||
{
|
||||
this->setAcceptHoverEvents(true);
|
||||
|
||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
||||
|
||||
m_circle = new QtRoundedRectItem(this);
|
||||
m_circle->setRadius(100);
|
||||
m_circle->setBrush(QBrush(scheme->getColor("graph/background").c_str()));
|
||||
m_circle->setAcceptHoverEvents(true);
|
||||
|
||||
QFont font;
|
||||
font.setFamily(GraphViewStyle::getFontNameOfExpandToggleNode().c_str());
|
||||
font.setPixelSize(GraphViewStyle::getFontSizeOfExpandToggleNode());
|
||||
font.setWeight(QFont::Normal);
|
||||
|
||||
m_number = new QGraphicsSimpleTextItem(this);
|
||||
m_number->setFont(font);
|
||||
m_number->setBrush(QBrush(scheme->getColor("graph/text").c_str()));
|
||||
m_circle = new QtCountCircleItem(this);
|
||||
|
||||
m_arrowLeft = new QGraphicsLineItem(this);
|
||||
m_arrowRight = new QGraphicsLineItem(this);
|
||||
@@ -90,8 +75,10 @@ void QtStraightLineItem::updateLine(
|
||||
this->setLine(oc.x, oc.y, tc.x, tc.y);
|
||||
|
||||
Vec2f mid = (op + tp) / 2;
|
||||
m_circle->setPosition(mid);
|
||||
m_circle->setNumber(number);
|
||||
|
||||
size_t radius = GraphViewStyle::getFontSizeOfExpandToggleNode();
|
||||
size_t radius = m_circle->getRadius();
|
||||
|
||||
if (showArrow)
|
||||
{
|
||||
@@ -114,23 +101,14 @@ void QtStraightLineItem::updateLine(
|
||||
m_arrowRight->hide();
|
||||
}
|
||||
|
||||
m_circle->setRect(mid.x - radius, mid.y - radius, 2 * radius, 2 * radius);
|
||||
|
||||
QString numberStr = QString::number(number);
|
||||
m_number->setText(numberStr);
|
||||
m_number->setPos(
|
||||
mid.x - QFontMetrics(m_number->font()).width(numberStr) / 2,
|
||||
mid.y - QFontMetrics(m_number->font()).height() / 2
|
||||
);
|
||||
|
||||
|
||||
QColor color(style.color.c_str());
|
||||
|
||||
this->setPen(QPen(QBrush(color), style.width, Qt::SolidLine, Qt::RoundCap));
|
||||
|
||||
color = color.darker(110);
|
||||
|
||||
m_circle->setPen(QPen(color, 2));
|
||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
||||
m_circle->setStyle(scheme->getColor("graph/background").c_str(), scheme->getColor("graph/text").c_str(), color, 2);
|
||||
|
||||
m_arrowLeft->setPen(QPen(QBrush(color), 2, Qt::SolidLine, Qt::RoundCap));
|
||||
m_arrowRight->setPen(QPen(QBrush(color), 2, Qt::SolidLine, Qt::RoundCap));
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "component/view/GraphViewStyle.h"
|
||||
|
||||
class QtRoundedRectItem;
|
||||
class QtCountCircleItem;
|
||||
|
||||
class QtStraightLineItem
|
||||
: public QGraphicsLineItem
|
||||
@@ -19,8 +19,7 @@ public:
|
||||
void updateLine(Vec4i ownerRect, Vec4i targetRect, int number, GraphViewStyle::EdgeStyle style, bool showArrow);
|
||||
|
||||
private:
|
||||
QtRoundedRectItem* m_circle;
|
||||
QGraphicsSimpleTextItem* m_number;
|
||||
QtCountCircleItem* m_circle;
|
||||
|
||||
QGraphicsLineItem* m_arrowLeft;
|
||||
QGraphicsLineItem* m_arrowRight;
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#include "qt/view/graphElements/QtGraphNodeBundle.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
#include "utility/messaging/type/MessageGraphNodeBundleSplit.h"
|
||||
|
||||
#include "component/view/GraphViewStyle.h"
|
||||
#include "qt/graphics/QtRoundedRectItem.h"
|
||||
#include "qt/graphics/QtCountCircleItem.h"
|
||||
#include "settings/ColorScheme.h"
|
||||
|
||||
QtGraphNodeBundle::QtGraphNodeBundle(Id tokenId, size_t nodeCount, std::string name)
|
||||
: QtGraphNode()
|
||||
, m_tokenId(tokenId)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << nodeCount << " " << name;
|
||||
this->setName(ss.str());
|
||||
this->setName(name);
|
||||
|
||||
m_circle = new QtCountCircleItem(this);
|
||||
m_circle->setNumber(nodeCount);
|
||||
|
||||
this->setAcceptHoverEvents(true);
|
||||
}
|
||||
@@ -45,18 +45,15 @@ void QtGraphNodeBundle::updateStyle()
|
||||
GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleOfBundleNode(m_isHovering);
|
||||
setStyle(style);
|
||||
|
||||
if (!m_undefinedRect)
|
||||
{
|
||||
m_undefinedRect = new QtRoundedRectItem(this);
|
||||
setSize(getSize());
|
||||
m_undefinedRect->moveBy(7, 7);
|
||||
}
|
||||
m_circle->setPosition(Vec2f(m_rect->rect().right() - 3, m_rect->rect().top() + 3));
|
||||
|
||||
m_undefinedRect->setPen(m_rect->pen());
|
||||
m_undefinedRect->setBrush(m_rect->brush());
|
||||
m_undefinedRect->setRadius(style.cornerRadius);
|
||||
m_undefinedRect->setZValue(-1);
|
||||
m_rect->setZValue(0);
|
||||
ColorScheme* scheme = ColorScheme::getInstance().get();
|
||||
m_circle->setStyle(
|
||||
scheme->getColor("graph/background").c_str(),
|
||||
scheme->getColor("graph/text").c_str(),
|
||||
scheme->getColor("graph/text").c_str(),
|
||||
style.borderWidth
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "qt/view/graphElements/QtGraphNode.h"
|
||||
|
||||
class QtCountCircleItem;
|
||||
|
||||
class QtGraphNodeBundle
|
||||
: public QtGraphNode
|
||||
{
|
||||
@@ -23,6 +25,7 @@ protected:
|
||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
|
||||
|
||||
private:
|
||||
QtCountCircleItem* m_circle;
|
||||
Id m_tokenId;
|
||||
};
|
||||
|
||||
|
||||
@@ -704,7 +704,7 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const
|
||||
}
|
||||
else if (node.isBundleNode())
|
||||
{
|
||||
width = margins.charWidth * (node.name.size() + 1 + utility::digits(node.bundledNodes.size()));
|
||||
width = margins.charWidth * node.name.size();
|
||||
}
|
||||
|
||||
// Horizontal layouting is currently not used, but left in place for experimentation.
|
||||
|
||||
@@ -134,6 +134,11 @@ size_t GraphViewStyle::getFontSizeOfExpandToggleNode()
|
||||
return s_fontSize - 5;
|
||||
}
|
||||
|
||||
size_t GraphViewStyle::getFontSizeOfCountCircle()
|
||||
{
|
||||
return s_fontSize - 3;
|
||||
}
|
||||
|
||||
std::string GraphViewStyle::getFontNameForNodeType(Node::NodeType type)
|
||||
{
|
||||
return s_fontName;
|
||||
|
||||
@@ -98,6 +98,7 @@ public:
|
||||
static size_t getFontSizeForNodeType(Node::NodeType type);
|
||||
static size_t getFontSizeOfAccessNode();
|
||||
static size_t getFontSizeOfExpandToggleNode();
|
||||
static size_t getFontSizeOfCountCircle();
|
||||
|
||||
static std::string getFontNameForNodeType(Node::NodeType type);
|
||||
static std::string getFontNameOfAccessNode();
|
||||
|
||||
Reference in New Issue
Block a user