From 70283f761070131dff2d4db38e654182a7468470 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Wed, 9 Sep 2015 11:48:16 +0200 Subject: [PATCH] ui: new style for bundle node --- src/app/CMakeLists.txt | 2 + src/app/qt/graphics/QtCountCircleItem.cpp | 57 +++++++++++++++++++ src/app/qt/graphics/QtCountCircleItem.h | 23 ++++++++ src/app/qt/graphics/QtRoundedRectItem.cpp | 5 ++ src/app/qt/graphics/QtRoundedRectItem.h | 2 + src/app/qt/graphics/QtStraightLineItem.cpp | 38 +++---------- src/app/qt/graphics/QtStraightLineItem.h | 5 +- .../view/graphElements/QtGraphNodeBundle.cpp | 31 +++++----- .../qt/view/graphElements/QtGraphNodeBundle.h | 3 + .../component/controller/GraphController.cpp | 2 +- src/lib/component/view/GraphViewStyle.cpp | 5 ++ src/lib/component/view/GraphViewStyle.h | 1 + 12 files changed, 123 insertions(+), 51 deletions(-) create mode 100644 src/app/qt/graphics/QtCountCircleItem.cpp create mode 100644 src/app/qt/graphics/QtCountCircleItem.h diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index bbd76ed2..14254eab 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -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 diff --git a/src/app/qt/graphics/QtCountCircleItem.cpp b/src/app/qt/graphics/QtCountCircleItem.cpp new file mode 100644 index 00000000..3e409a15 --- /dev/null +++ b/src/app/qt/graphics/QtCountCircleItem.cpp @@ -0,0 +1,57 @@ +#include "qt/graphics/QtCountCircleItem.h" + +#include +#include +#include + +#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); +} diff --git a/src/app/qt/graphics/QtCountCircleItem.h b/src/app/qt/graphics/QtCountCircleItem.h new file mode 100644 index 00000000..ee812ebe --- /dev/null +++ b/src/app/qt/graphics/QtCountCircleItem.h @@ -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 diff --git a/src/app/qt/graphics/QtRoundedRectItem.cpp b/src/app/qt/graphics/QtRoundedRectItem.cpp index b5001642..795e55db 100644 --- a/src/app/qt/graphics/QtRoundedRectItem.cpp +++ b/src/app/qt/graphics/QtRoundedRectItem.cpp @@ -41,6 +41,11 @@ void QtRoundedRectItem::setShadowEnabled(bool enabled) } } +qreal QtRoundedRectItem::getRadius() const +{ + return m_radius; +} + void QtRoundedRectItem::setRadius(qreal radius) { m_radius = radius; diff --git a/src/app/qt/graphics/QtRoundedRectItem.h b/src/app/qt/graphics/QtRoundedRectItem.h index 93dd4ed9..b3122e4b 100644 --- a/src/app/qt/graphics/QtRoundedRectItem.h +++ b/src/app/qt/graphics/QtRoundedRectItem.h @@ -14,6 +14,8 @@ public: void setShadow(QColor color, int blurRadius); void setShadowEnabled(bool enabled); + + qreal getRadius() const; void setRadius(qreal radius); private: diff --git a/src/app/qt/graphics/QtStraightLineItem.cpp b/src/app/qt/graphics/QtStraightLineItem.cpp index 1c7bcac1..b9334f90 100644 --- a/src/app/qt/graphics/QtStraightLineItem.cpp +++ b/src/app/qt/graphics/QtStraightLineItem.cpp @@ -1,13 +1,12 @@ #include "qt/graphics/QtStraightLineItem.h" -#include -#include +#include #include #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)); diff --git a/src/app/qt/graphics/QtStraightLineItem.h b/src/app/qt/graphics/QtStraightLineItem.h index 7d99ac60..6f6cee54 100644 --- a/src/app/qt/graphics/QtStraightLineItem.h +++ b/src/app/qt/graphics/QtStraightLineItem.h @@ -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; diff --git a/src/app/qt/view/graphElements/QtGraphNodeBundle.cpp b/src/app/qt/view/graphElements/QtGraphNodeBundle.cpp index e87cb239..8322dd08 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeBundle.cpp +++ b/src/app/qt/view/graphElements/QtGraphNodeBundle.cpp @@ -1,22 +1,22 @@ #include "qt/view/graphElements/QtGraphNodeBundle.h" -#include - #include #include #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 + ); } diff --git a/src/app/qt/view/graphElements/QtGraphNodeBundle.h b/src/app/qt/view/graphElements/QtGraphNodeBundle.h index a3029097..d253d67e 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeBundle.h +++ b/src/app/qt/view/graphElements/QtGraphNodeBundle.h @@ -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; }; diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index bd2235d0..c967b5ca 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -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. diff --git a/src/lib/component/view/GraphViewStyle.cpp b/src/lib/component/view/GraphViewStyle.cpp index cb330060..54c3f11e 100644 --- a/src/lib/component/view/GraphViewStyle.cpp +++ b/src/lib/component/view/GraphViewStyle.cpp @@ -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; diff --git a/src/lib/component/view/GraphViewStyle.h b/src/lib/component/view/GraphViewStyle.h index a6f0bf27..bc221f92 100644 --- a/src/lib/component/view/GraphViewStyle.h +++ b/src/lib/component/view/GraphViewStyle.h @@ -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();