From f5f4eed5092d6e3daeb300a0bbfa7dafcc39c64b Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Fri, 20 Nov 2015 15:24:20 +0100 Subject: [PATCH] ui: extended color scheme and added new color scheme bad_rainbow * added color scheme template * define fill, border, text, icon and hatching colors for each node with states normal and focus * define colors for each edge with states normal and focus * use default node and edge colors when no type specific ones are defined * use normal colors for nodes and edges when no focused are defined * allow nodes and edges to imitate look of others with "like" tag * added style for bundle * added style for count circle --- bin/app/data/color_scheme_template.xml | 241 +++++++++++++ bin/app/data/color_schemes/bad_rainbow.xml | 323 ++++++++++++++++++ bin/app/data/color_schemes/bright.xml | 179 +++++----- bin/app/data/color_schemes/dark.xml | 185 ++++++---- src/app/qt/element/QtAutocompletionList.cpp | 3 +- src/app/qt/element/QtSmartSearchBox.cpp | 16 +- src/app/qt/graphics/QtStraightLineItem.cpp | 17 +- src/app/qt/graphics/QtStraightLineItem.h | 4 +- src/app/qt/view/graphElements/QtGraphEdge.cpp | 4 +- src/app/qt/view/graphElements/QtGraphNode.cpp | 12 +- .../view/graphElements/QtGraphNodeAccess.cpp | 2 +- .../view/graphElements/QtGraphNodeBundle.cpp | 9 +- .../graphElements/QtGraphNodeExpandToggle.cpp | 2 +- src/lib/component/view/GraphViewStyle.cpp | 173 +++++----- src/lib/component/view/GraphViewStyle.h | 24 +- src/lib/settings/ColorScheme.cpp | 69 +++- src/lib/settings/ColorScheme.h | 18 +- 17 files changed, 997 insertions(+), 284 deletions(-) create mode 100644 bin/app/data/color_scheme_template.xml create mode 100644 bin/app/data/color_schemes/bad_rainbow.xml diff --git a/bin/app/data/color_scheme_template.xml b/bin/app/data/color_scheme_template.xml new file mode 100644 index 00000000..3ca3629a --- /dev/null +++ b/bin/app/data/color_scheme_template.xml @@ -0,0 +1,241 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <text></text> + <normal></normal> + <hover></hover> + <press></press> + <icon></icon> + + + + + + + + + + + + + <text></text> + <background></background> + <hover></hover> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bin/app/data/color_schemes/bad_rainbow.xml b/bin/app/data/color_schemes/bad_rainbow.xml new file mode 100644 index 00000000..62003ecb --- /dev/null +++ b/bin/app/data/color_schemes/bad_rainbow.xml @@ -0,0 +1,323 @@ + + + + + #494949 + + + + + #3D3D3D + #808080 + #B1B1B1 + + + + #3D3D3D + #A0A0A0 + #CCCCCC + #FFFFFF + + + + + #B1B1B1 + #CCCCCC + + + #406D4D + #4E855E + + + #7D2724 + #8C2B29 + + + + + + #494949 + + + #CCCCCC + + + <text>black</text> + <normal>#CCCCCC</normal> + <hover>#BBBBBB</hover> + <press>#AAAAAA</press> + <icon>black</icon> + + + + #C4C4C4 + #494949 + + + + + #494949 + + + <text>#A0A0A0</text> + <background>transparent</background> + <hover>#2F2F2F</hover> + + + + #C4C4C4 + #494949 + + + + #C4C4C4 + #00A0B6 + #00A0B6 + #FF4A52 + #A0A0A4 + #EE7326 + #D663D6 + #FBBA00 + + + + + + transparent + transparent + + + #B2B2B2 + transparent + + + #B2B2B2 + #4A4A4A + + + + + transparent + transparent + + + transparent + transparent + + + transparent + transparent + + + + + transparent + #A0FF0000 + + + transparent + #FFFF0000 + + + transparent + #FFFF0000 + + + + + + + + #494949 + + + + + #807F80 + + + #FFFFFF + + + #3D3D3D + + + #3D3D3D + + + #494949 + + + + + + #20FFFFFF + #FFFFFF + + + #FFFFFF + + + #FFFFFF + + + + type + + + type + + + type + + + type + + + type + + + + + #FBBA00 + #FFD05A + + + transparent + #FFFFFF + + + + function + + + + + #00A0B6 + #3BAFB2 + + + transparent + #FFFFFF + + + + global_variable + + + global_variable + + + + + #00000000 + + + #78282D + + + + undefined + + + + + #4E82F6 + #7FA9F4 + + + #20FFFFFF + #FFFFFF + + + + file + + + + + #CCCCCC + + + + + #494949 + + + #80FFFFFF + #FFFFFF + + + #FFFFFF + + + #FFFFFF + + + + + #494949 + + + #CCCCCC + + + #CCCCCC + + + + + + #797979 + + + + #CC5E89 + + + + #FBBA00 + + + + #2A6484 + + + + #C1305D + + + #C1305D + + + #C1305D + + + #C1305D + + + + #4E82F6 + + + #4E82F6 + + + + #5D5D5D + #6D6D6D + + + + + + #F7F7F7 + #777777 + + diff --git a/bin/app/data/color_schemes/bright.xml b/bin/app/data/color_schemes/bright.xml index da21c92f..16b3e59f 100644 --- a/bin/app/data/color_schemes/bright.xml +++ b/bin/app/data/color_schemes/bright.xml @@ -134,154 +134,169 @@ - black white - #3C3C3C - black - white + + + #ededed + + + #3C3C3C + + + black + + + black + + + white + + + - #ededed - #ededed + + #203C3C3C + #3C3C3C + - #ededed - #ededed + type - #ededed - #ededed + type - #ededed - #ededed + type - #ededed - #ededed + type - #ededed - #ededed + type - #F4D07D - #F4BC3D + + #F4D07D + #F4BC3D + + + transparent + #3C3C3C + - #F4D07D - #F4BC3D + function - - #7BB5D4 - #42A1D4 - - #7BB5D4 - #42A1D4 + + #7BB5D4 + #42A1D4 + + + transparent + #3C3C3C + + + global_variable + - #7BB5D4 - #42A1D4 + global_variable - #CC8D91 - #CC8D91 + + #00000000 + + + #CC8D91 + - #CC8D91 - #CC8D91 + undefined - #DDD - #CCC + + #DDD + #CCC + + + #203C3C3C + #3C3C3C + - - #DDD - #CCC + file + + + + white + + + + + white + + + #803C3C3C + #3C3C3C + + + + + white + + + #7C7C7C + + + #5C5C5C + + - + #878787 - #878787 - - - #878787 - #878787 - - - #878787 - #878787 - - - #878787 - #878787 - - - #878787 - #878787 - - - #878787 - #878787 - + #CC5E89 - #CC5E89 #F4BC3D - #F4BC3D #3190BA - #3190BA #C1305D - #C1305D - #C1305D - #C1305D + template_parameter - #C1305D - #C1305D + template_parameter - #C1305D - #C1305D + template_parameter - #C1305D - #C1305D + template_parameter - - #878787 - #878787 - - #EEE - #DDD + #DDD - - #878787 - #878787 - diff --git a/bin/app/data/color_schemes/dark.xml b/bin/app/data/color_schemes/dark.xml index 6893e025..faa794a4 100644 --- a/bin/app/data/color_schemes/dark.xml +++ b/bin/app/data/color_schemes/dark.xml @@ -134,154 +134,191 @@ - #F7F7F7 - #C3C3C3 #272728 - #F7F7F7 - #272728 + + + #4D4D4D + + + #C3C3C3 + + + #F7F7F7 + + + #F7F7F7 + + + #272728 + + + - #4D4D4D - #4D4D4D + + #20C3C3C3 + #C3C3C3 + - #4D4D4D - #4D4D4D + + #20C3C3C3 + #C3C3C3 + - #4D4D4D - #4D4D4D + + #20C3C3C3 + #C3C3C3 + - #4D4D4D - #4D4D4D + + #20C3C3C3 + #C3C3C3 + - #4D4D4D - #4D4D4D + + #20C3C3C3 + #C3C3C3 + - #4D4D4D - #4D4D4D + + #20C3C3C3 + #C3C3C3 + - #7A681F - #9C8528 + + #7A681F + #9C8528 + + + transparent + #C3C3C3 + - #7A681F - #9C8528 + function - - #21516B - #2A6484 - - #21516B - #2A6484 + + #21516B + #2A6484 + + + transparent + #C3C3C3 + + + global_variable + - #21516B - #2A6484 + global_variable> - #78282D - #78282D + + #00000000 + + + #78282D + - #78282D - #78282D + undefined - #1B564E - #247368 + + #1B564E + #247368 + + + #20C3C3C3 + #C3C3C3 + - - #1B564E - #247368 + file + + + + #272728 + + + + + #272728 + + + #80C3C3C3 + #C3C3C3 + + + + + #272728 + + + #C3C3C3 + + + #F7F7F7 + + - + #797979 - #797979 - - - #797979 - #797979 - - - #797979 - #797979 - - - #797979 - #797979 - - - #797979 - #797979 - - - #797979 - #797979 - + #CC5E89 - #CC5E89 #9C8528 - #9C8528 #2A6484 - #2A6484 #C1305D - #C1305D #C1305D - #C1305D #C1305D - #C1305D #C1305D - #C1305D #C1305D - #C1305D #247368 - #247368 + + #247368 + #5D5D5D - #6D6D6D + #6D6D6D - - #247368 - #247368 - diff --git a/src/app/qt/element/QtAutocompletionList.cpp b/src/app/qt/element/QtAutocompletionList.cpp index 247f26b6..4e6c44cd 100644 --- a/src/app/qt/element/QtAutocompletionList.cpp +++ b/src/app/qt/element/QtAutocompletionList.cpp @@ -3,6 +3,7 @@ #include #include +#include "component/view/GraphViewStyle.h" #include "settings/ApplicationSettings.h" #include "settings/ColorScheme.h" @@ -106,7 +107,7 @@ void QtAutocompletionDelegate::paint(QPainter* painter, const QStyleOptionViewIt Node::NodeType nodeType = static_cast(index.sibling(index.row(), index.column() + 3).data().toInt()); if (type.size()) { - color = QColor(scheme->getNodeTypeColor(nodeType).c_str()); + color = QColor(GraphViewStyle::getNodeColor(Node::getTypeString(nodeType), false).fill.c_str()); } else { diff --git a/src/app/qt/element/QtSmartSearchBox.cpp b/src/app/qt/element/QtSmartSearchBox.cpp index 3f554df7..d87688de 100644 --- a/src/app/qt/element/QtSmartSearchBox.cpp +++ b/src/app/qt/element/QtSmartSearchBox.cpp @@ -13,6 +13,7 @@ #include "utility/utility.h" #include "utility/utilityString.h" +#include "component/view/GraphViewStyle.h" #include "qt/element/QtAutocompletionList.h" #include "settings/ColorScheme.h" @@ -603,8 +604,7 @@ void QtSmartSearchBox::updateElements() m_elements.clear(); ColorScheme* scheme = ColorScheme::getInstance().get(); - - std::string textColor = scheme->getColor("search/field/text"); + std::string searchTextColor = scheme->getColor("search/field/text"); for (const SearchMatch& match : m_matches) { @@ -616,12 +616,16 @@ void QtSmartSearchBox::updateElements() std::string color; std::string hoverColor; + std::string textColor = searchTextColor; + std::string textHoverColor = searchTextColor; if (match.searchType == SearchMatch::SEARCH_TOKEN) { element->setObjectName(QString::fromStdString("search_element_" + match.getNodeTypeAsString())); - color = scheme->getNodeTypeColor(match.nodeType); - hoverColor = scheme->getNodeTypeColor(match.nodeType, "hover"); + color = GraphViewStyle::getNodeColor(Node::getTypeString(match.nodeType), false).fill; + hoverColor = GraphViewStyle::getNodeColor(Node::getTypeString(match.nodeType), true).fill; + textColor = GraphViewStyle::getNodeColor(Node::getTypeString(match.nodeType), false).text; + textHoverColor = GraphViewStyle::getNodeColor(Node::getTypeString(match.nodeType), true).text; } else { @@ -633,8 +637,8 @@ void QtSmartSearchBox::updateElements() } std::stringstream css; - css << "QPushButton {border: none; padding: 0px 4px; background-color:" << color << "; color:" << textColor << ";} "; - css << "QPushButton:hover { background-color:" << hoverColor << ";} "; + css << "QPushButton { border: none; padding: 0px 4px; background-color:" << color << "; color:" << textColor << ";} "; + css << "QPushButton:hover { background-color:" << hoverColor << "; color:" << textHoverColor << ";} "; element->setStyleSheet(css.str().c_str()); diff --git a/src/app/qt/graphics/QtStraightLineItem.cpp b/src/app/qt/graphics/QtStraightLineItem.cpp index b9334f90..108cd005 100644 --- a/src/app/qt/graphics/QtStraightLineItem.cpp +++ b/src/app/qt/graphics/QtStraightLineItem.cpp @@ -7,7 +7,6 @@ #include "utility/utility.h" #include "qt/graphics/QtCountCircleItem.h" -#include "settings/ColorScheme.h" QtStraightLineItem::QtStraightLineItem(QGraphicsItem* parent) : QGraphicsLineItem(parent) @@ -25,7 +24,8 @@ QtStraightLineItem::~QtStraightLineItem() } void QtStraightLineItem::updateLine( - Vec4i ownerRect, Vec4i targetRect, int number, GraphViewStyle::EdgeStyle style, bool showArrow + Vec4i ownerRect, Vec4i targetRect, int number, + GraphViewStyle::EdgeStyle style, GraphViewStyle::NodeStyle countStyle, bool showArrow ){ prepareGeometryChange(); @@ -101,15 +101,10 @@ void QtStraightLineItem::updateLine( m_arrowRight->hide(); } - QColor color(style.color.c_str()); + this->setPen(QPen(QBrush(style.color.c_str()), style.width, Qt::SolidLine, Qt::RoundCap)); - this->setPen(QPen(QBrush(color), style.width, Qt::SolidLine, Qt::RoundCap)); + m_circle->setStyle(countStyle.color.fill.c_str(), countStyle.color.text.c_str(), countStyle.color.border.c_str(), 1); - color = color.darker(110); - - 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)); + m_arrowLeft->setPen(QPen(QBrush(countStyle.color.border.c_str()), 1, Qt::SolidLine, Qt::RoundCap)); + m_arrowRight->setPen(QPen(QBrush(countStyle.color.border.c_str()), 1, Qt::SolidLine, Qt::RoundCap)); } diff --git a/src/app/qt/graphics/QtStraightLineItem.h b/src/app/qt/graphics/QtStraightLineItem.h index 6f6cee54..5d9fe8cb 100644 --- a/src/app/qt/graphics/QtStraightLineItem.h +++ b/src/app/qt/graphics/QtStraightLineItem.h @@ -16,7 +16,9 @@ public: QtStraightLineItem(QGraphicsItem* parent); virtual ~QtStraightLineItem(); - void updateLine(Vec4i ownerRect, Vec4i targetRect, int number, GraphViewStyle::EdgeStyle style, bool showArrow); + void updateLine( + Vec4i ownerRect, Vec4i targetRect, int number, + GraphViewStyle::EdgeStyle style, GraphViewStyle::NodeStyle countStyle, bool showArrow); private: QtCountCircleItem* m_circle; diff --git a/src/app/qt/view/graphElements/QtGraphEdge.cpp b/src/app/qt/view/graphElements/QtGraphEdge.cpp index 9bd9d1da..c3ee3603 100644 --- a/src/app/qt/view/graphElements/QtGraphEdge.cpp +++ b/src/app/qt/view/graphElements/QtGraphEdge.cpp @@ -91,8 +91,10 @@ void QtGraphEdge::updateLine() owner.swap(target); } + GraphViewStyle::NodeStyle countStyle = GraphViewStyle::getStyleOfCountCircle(); + dynamic_cast(m_child)->updateLine( - owner->getBoundingRect(), target->getBoundingRect(), m_weight, style, showArrow); + owner->getBoundingRect(), target->getBoundingRect(), m_weight, style, countStyle, showArrow); } else { diff --git a/src/app/qt/view/graphElements/QtGraphNode.cpp b/src/app/qt/view/graphElements/QtGraphNode.cpp index e8af64cf..9e2d4bef 100644 --- a/src/app/qt/view/graphElements/QtGraphNode.cpp +++ b/src/app/qt/view/graphElements/QtGraphNode.cpp @@ -345,7 +345,7 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style) QPen pen(Qt::transparent); if (style.borderWidth > 0) { - pen.setColor(style.borderColor.c_str()); + pen.setColor(style.color.border.c_str()); pen.setWidthF(style.borderWidth); if (style.borderDashed) { @@ -354,16 +354,16 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style) } m_rect->setPen(pen); - m_rect->setBrush(QBrush(style.color.c_str())); + m_rect->setBrush(QBrush(style.color.fill.c_str())); qreal radius = style.cornerRadius; m_rect->setRadius(radius); - if (style.hatchingColor.size()) + if (style.hasHatching) { QtDeviceScaledPixmap pattern("data/gui/graph_view/images/pattern.png"); pattern.scaleToHeight(10); - QPixmap pixmap = utility::colorizePixmap(pattern.pixmap(), style.hatchingColor.c_str()); + QPixmap pixmap = utility::colorizePixmap(pattern.pixmap(), style.color.hatching.c_str()); if (!m_undefinedRect) { @@ -384,7 +384,7 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style) QtDeviceScaledPixmap pixmap(QString::fromStdString(style.iconPath)); pixmap.scaleToHeight(style.iconSize); - m_icon = new QGraphicsPixmapItem(utility::colorizePixmap(pixmap.pixmap(), style.iconColor.c_str()), this); + m_icon = new QGraphicsPixmapItem(utility::colorizePixmap(pixmap.pixmap(), style.color.icon.c_str()), this); m_icon->setPos(style.iconOffset.x, style.iconOffset.y); } @@ -396,6 +396,6 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style) } m_text->setFont(font); - m_text->setBrush(QBrush(style.textColor.c_str())); + m_text->setBrush(QBrush(style.color.text.c_str())); m_text->setPos(style.iconOffset.x + style.iconSize + style.textOffset.x, style.textOffset.y); } diff --git a/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp b/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp index eaaaad24..f9c76d19 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp +++ b/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp @@ -56,7 +56,7 @@ void QtGraphNodeAccess::updateStyle() m_text->setPos(style.textOffset.x + m_accessIconSize + 3, style.textOffset.x + m_accessIconSize + 2 - style.fontSize); m_accessIcon->setPos(style.textOffset.x, style.textOffset.y); - m_accessIcon->setPixmap(utility::colorizePixmap(m_accessIcon->pixmap(), style.iconColor.c_str())); + m_accessIcon->setPixmap(utility::colorizePixmap(m_accessIcon->pixmap(), style.color.icon.c_str())); } void QtGraphNodeAccess::hideLabel() diff --git a/src/app/qt/view/graphElements/QtGraphNodeBundle.cpp b/src/app/qt/view/graphElements/QtGraphNodeBundle.cpp index a4dd55ee..6a34d20c 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeBundle.cpp +++ b/src/app/qt/view/graphElements/QtGraphNodeBundle.cpp @@ -7,7 +7,6 @@ #include "component/view/GraphViewStyle.h" #include "qt/graphics/QtCountCircleItem.h" -#include "settings/ColorScheme.h" QtGraphNodeBundle::QtGraphNodeBundle(Id tokenId, size_t nodeCount, std::string name) : QtGraphNode() @@ -49,11 +48,11 @@ void QtGraphNodeBundle::updateStyle() m_circle->setPosition(Vec2f(m_rect->rect().right() - 3, m_rect->rect().top() + 3)); - ColorScheme* scheme = ColorScheme::getInstance().get(); + GraphViewStyle::NodeStyle accessStyle = GraphViewStyle::getStyleOfCountCircle(); m_circle->setStyle( - scheme->getColor("graph/background").c_str(), - scheme->getColor("graph/text").c_str(), - scheme->getColor("graph/text").c_str(), + accessStyle.color.fill.c_str(), + accessStyle.color.text.c_str(), + accessStyle.color.border.c_str(), style.borderWidth ); } diff --git a/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.cpp b/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.cpp index c8248602..85ccb5fc 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.cpp +++ b/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.cpp @@ -73,5 +73,5 @@ void QtGraphNodeExpandToggle::updateStyle() (m_invisibleSubNodeCount == 0 ? m_rect->rect().height() / 2 - 2 : m_rect->rect().height() - 7) ); - m_icon->setPixmap(utility::colorizePixmap(m_icon->pixmap(), style.iconColor.c_str())); + m_icon->setPixmap(utility::colorizePixmap(m_icon->pixmap(), style.color.icon.c_str())); } diff --git a/src/lib/component/view/GraphViewStyle.cpp b/src/lib/component/view/GraphViewStyle.cpp index 9188126b..d5c9d0e7 100644 --- a/src/lib/component/view/GraphViewStyle.cpp +++ b/src/lib/component/view/GraphViewStyle.cpp @@ -6,6 +6,21 @@ #include "settings/ApplicationSettings.h" #include "settings/ColorScheme.h" +int GraphViewStyle::s_gridCellSize = 5; +int GraphViewStyle::s_gridCellPadding = 10; + +std::map GraphViewStyle::s_charWidths; +std::map GraphViewStyle::s_charHeights; + +std::shared_ptr GraphViewStyle::s_impl; + +int GraphViewStyle::s_fontSize; +std::string GraphViewStyle::s_fontName; +float GraphViewStyle::s_zoomFactor; + +std::map GraphViewStyle::s_nodeColors; +std::map GraphViewStyle::s_edgeColors; + GraphViewStyle::NodeMargins::NodeMargins() : left(0) , right(0) @@ -27,6 +42,7 @@ GraphViewStyle::NodeStyle::NodeStyle() , fontSize(0) , fontBold(false) , iconSize(0) + , hasHatching(false) { } @@ -67,6 +83,9 @@ void GraphViewStyle::loadStyleSettings() s_charWidths.clear(); s_charHeights.clear(); + + s_nodeColors.clear(); + s_edgeColors.clear(); } float GraphViewStyle::getCharWidthForNodeType(Node::NodeType type) @@ -169,9 +188,9 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType margins.bottom = 15; break; - case Node::NODE_FILE: case Node::NODE_ENUM: case Node::NODE_TYPEDEF: + case Node::NODE_FILE: case Node::NODE_MACRO: margins.iconWidth = s_fontSize + 11; case Node::NODE_TYPE: @@ -255,19 +274,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( ){ NodeStyle style; - ColorScheme* scheme = ColorScheme::getInstance().get(); - - if (isActive || isFocused) - { - style.color = scheme->getNodeTypeColor(type, "hover"); - } - else - { - style.color = scheme->getNodeTypeColor(type); - } - - style.textColor = scheme->getColor("graph/text"); - style.borderColor = scheme->getColor("graph/border"); + style.color = getNodeColor(Node::getTypeString(type), isActive || isFocused); style.fontName = getFontNameForNodeType(type); style.fontSize = getFontSizeForNodeType(type); @@ -278,10 +285,6 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( style.borderDashed = true; case Node::NODE_NAMESPACE: - style.borderColor = style.color; - style.color = "#00000000"; - style.borderWidth = 1; - style.cornerRadius = 20; style.textOffset.x = 15; @@ -294,6 +297,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( case Node::NODE_ENUM: case Node::NODE_TYPEDEF: case Node::NODE_TEMPLATE_PARAMETER_TYPE: + case Node::NODE_FILE: case Node::NODE_MACRO: if (hasChildren) { @@ -307,26 +311,6 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( style.textOffset.x = 8; style.textOffset.y = 8; } - - if (isActive) - { - style.borderWidth = 2; - } - else if (isFocused) - { - style.borderWidth = 1; - } - else - { - style.borderWidth = 1; - style.borderColor = style.borderColor.replace(0, 1, "#20"); - } - break; - - case Node::NODE_FILE: - style.cornerRadius = 10; - style.textOffset.x = 6; - style.textOffset.y = 9; break; case Node::NODE_FUNCTION: @@ -337,23 +321,24 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( style.cornerRadius = 8; style.textOffset.x = 5; style.textOffset.y = 3; - - if (isActive) - { - style.borderWidth = 2; - } break; } + if (isActive) + { + style.borderWidth = 2; + } + else + { + style.borderWidth = 1; + } + if (isActive || isFocused) { style.fontBold = true; } - if (!defined) - { - style.hatchingColor = scheme->getColor("graph/hatching"); - } + style.hasHatching = !defined; addIcon(type, hasChildren, &style); @@ -364,12 +349,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfAccessNode() { NodeStyle style; - ColorScheme* scheme = ColorScheme::getInstance().get(); - - style.color = scheme->getColor("graph/background"); - style.textColor = scheme->getColor("graph/text"); - style.iconColor = scheme->getColor("graph/icon"); - style.borderColor = "#00000000"; + style.color = getNodeColor("access", false); style.cornerRadius = 12; @@ -387,12 +367,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfExpandToggleNode() { NodeStyle style; - ColorScheme* scheme = ColorScheme::getInstance().get(); - - style.color = scheme->getColor("graph/background"); - style.textColor = scheme->getColor("graph/text"); - style.iconColor = scheme->getColor("graph/icon"); - style.borderColor = "#00000000"; + style.color = getNodeColor("access", false); style.cornerRadius = 100; @@ -402,10 +377,24 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfExpandToggleNode() return style; } +GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfCountCircle() +{ + NodeStyle style; + + style.color = getNodeColor("count_number", false); + + style.fontName = getFontNameOfExpandToggleNode(); + style.fontSize = getFontSizeOfCountCircle(); + + return style; +} + GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfBundleNode(bool isFocused) { NodeStyle style = getStyleForNodeType(Node::NODE_CLASS, true, false, isFocused, false); + style.color = getNodeColor("bundle", isFocused); + addIcon(Node::NODE_ENUM, false, &style); style.iconPath = "data/gui/graph_view/images/bundle.png"; @@ -431,14 +420,7 @@ GraphViewStyle::EdgeStyle GraphViewStyle::getStyleForEdgeType(Edge::EdgeType typ style.originOffset.y = -1; style.targetOffset.y = 1; - if (isActive) - { - style.color = ColorScheme::getInstance()->getEdgeTypeColor(type, "hover"); - } - else - { - style.color = ColorScheme::getInstance()->getEdgeTypeColor(type); - } + style.color = getEdgeColor(Edge::getTypeString(type), isActive || isFocused); switch (type) { @@ -512,6 +494,50 @@ float GraphViewStyle::getZoomFactor() return s_zoomFactor; } +const GraphViewStyle::NodeColor& GraphViewStyle::getNodeColor(const std::string& typeStr, bool focus) +{ + std::string type = focus ? typeStr + "focus" : typeStr; + std::map::const_iterator it = s_nodeColors.find(type); + + if (it != s_nodeColors.end()) + { + return it->second; + } + + NodeColor color; + ColorScheme* scheme = ColorScheme::getInstance().get(); + ColorScheme::ColorState state = focus ? ColorScheme::FOCUS : ColorScheme::NORMAL; + + color.fill = scheme->getNodeTypeColor(typeStr, "fill", state); + color.border = scheme->getNodeTypeColor(typeStr, "border", state); + color.text = scheme->getNodeTypeColor(typeStr, "text", state); + color.icon = scheme->getNodeTypeColor(typeStr, "icon", state); + color.hatching = scheme->getNodeTypeColor(typeStr, "hatching", state); + + s_nodeColors.emplace(type, color); + + return s_nodeColors.find(type)->second; +} + +const std::string& GraphViewStyle::getEdgeColor(const std::string& typeStr, bool focus) +{ + std::string type = focus ? typeStr + "focus" : typeStr; + std::map::const_iterator it = s_edgeColors.find(type); + + if (it != s_edgeColors.end()) + { + return it->second; + } + + ColorScheme* scheme = ColorScheme::getInstance().get(); + ColorScheme::ColorState state = focus ? ColorScheme::FOCUS : ColorScheme::NORMAL; + std::string color = scheme->getEdgeTypeColor(typeStr, state); + + s_edgeColors.emplace(type, color); + + return s_edgeColors.find(type)->second; +} + void GraphViewStyle::addIcon(Node::NodeType type, bool hasChildren, NodeStyle* style) { switch (type) @@ -545,17 +571,4 @@ void GraphViewStyle::addIcon(Node::NodeType type, bool hasChildren, NodeStyle* s } style->iconOffset.y = 9; - style->iconColor = ColorScheme::getInstance()->getColor("graph/icon"); } - -int GraphViewStyle::s_gridCellSize = 5; -int GraphViewStyle::s_gridCellPadding = 10; - -std::map GraphViewStyle::s_charWidths; -std::map GraphViewStyle::s_charHeights; - -std::shared_ptr GraphViewStyle::s_impl; - -int GraphViewStyle::s_fontSize; -std::string GraphViewStyle::s_fontName; -float GraphViewStyle::s_zoomFactor; diff --git a/src/lib/component/view/GraphViewStyle.h b/src/lib/component/view/GraphViewStyle.h index 9fea3f3c..38fc5743 100644 --- a/src/lib/component/view/GraphViewStyle.h +++ b/src/lib/component/view/GraphViewStyle.h @@ -35,19 +35,24 @@ public: int iconWidth; }; + struct NodeColor + { + std::string fill; + std::string border; + std::string text; + std::string icon; + std::string hatching; + }; + struct NodeStyle { NodeStyle(); - std::string color; - std::string textColor; - std::string iconColor; - std::string hatchingColor; + NodeColor color; int cornerRadius; int borderWidth; - std::string borderColor; bool borderDashed; std::string fontName; @@ -59,6 +64,8 @@ public: std::string iconPath; Vec2i iconOffset; size_t iconSize; + + bool hasHatching; }; struct EdgeStyle @@ -108,6 +115,7 @@ public: static NodeStyle getStyleForNodeType(Node::NodeType type, bool defined, bool isActive, bool isFocused, bool hasChildren); static NodeStyle getStyleOfAccessNode(); static NodeStyle getStyleOfExpandToggleNode(); + static NodeStyle getStyleOfCountCircle(); static NodeStyle getStyleOfBundleNode(bool isFocused); static EdgeStyle getStyleForEdgeType(Edge::EdgeType type, bool isActive, bool isFocused); @@ -118,6 +126,9 @@ public: static float getZoomFactor(); + static const NodeColor& getNodeColor(const std::string& typeStr, bool focus); + static const std::string& getEdgeColor(const std::string& typeStr, bool focus); + static int s_gridCellSize; static int s_gridCellPadding; @@ -132,6 +143,9 @@ private: static int s_fontSize; static std::string s_fontName; static float s_zoomFactor; + + static std::map s_nodeColors; + static std::map s_edgeColors; }; #endif // GRAPH_VIEW_STYLE_H diff --git a/src/lib/settings/ColorScheme.cpp b/src/lib/settings/ColorScheme.cpp index 74a336fc..a603ac24 100644 --- a/src/lib/settings/ColorScheme.cpp +++ b/src/lib/settings/ColorScheme.cpp @@ -18,19 +18,63 @@ ColorScheme::~ColorScheme() std::string ColorScheme::getColor(const std::string& key) const { - return getValue(key, "#FFFFFF"); + return getValue(key, ""); } -std::string ColorScheme::getNodeTypeColor(Node::NodeType type, const std::string& state) const +std::string ColorScheme::getNodeTypeColor(Node::NodeType type, const std::string& key, ColorState state) const { - std::string path = "graph/node/" + Node::getTypeString(type) + "/" + state; - return getValue(path, "#FFFFFF"); + return getNodeTypeColor(Node::getTypeString(type), key, state); } -std::string ColorScheme::getEdgeTypeColor(Edge::EdgeType type, const std::string& state) const +std::string ColorScheme::getNodeTypeColor(const std::string& typeStr, const std::string& key, ColorState state) const { - std::string path = "graph/edge/" + Edge::getTypeString(type) + "/" + state; - return getValue(path, "#FFFFFF"); + std::string type = getValue("graph/node/" + typeStr + "/like", typeStr); + std::string color = getValue("graph/node/" + type + "/" + key + "/" + stateToString(state), ""); + + if (!color.size() && state != NORMAL) + { + color = getValue("graph/node/" + type + "/" + key + "/" + stateToString(NORMAL), ""); + } + + if (!color.size()) + { + color = getValue("graph/node/default/" + key + "/" + stateToString(state), ""); + } + + if (!color.size() && state != NORMAL) + { + color = getValue("graph/node/default/" + key + "/" + stateToString(NORMAL), "#FFFFFF"); + } + + return color; +} + +std::string ColorScheme::getEdgeTypeColor(Edge::EdgeType type, ColorState state) const +{ + return getEdgeTypeColor(Edge::getTypeString(type), state); +} + +std::string ColorScheme::getEdgeTypeColor(const std::string& typeStr, ColorState state) const +{ + std::string type = getValue("graph/edge/" + typeStr + "/like", typeStr); + std::string color = getValue("graph/edge/" + type + "/" + stateToString(state), ""); + + if (!color.size() && state != NORMAL) + { + color = getValue("graph/edge/" + type + "/" + stateToString(NORMAL), ""); + } + + if (!color.size()) + { + color = getValue("graph/edge/default/" + stateToString(state), ""); + } + + if (!color.size() && state != NORMAL) + { + color = getValue("graph/edge/default/" + stateToString(NORMAL), "#FFFFFF"); + } + + return color; } std::string ColorScheme::getSearchTypeColor(const std::string& searchTypeName, const std::string& state) const @@ -47,3 +91,14 @@ std::string ColorScheme::getSyntaxColor(const std::string& key) const ColorScheme::ColorScheme() { } + +std::string ColorScheme::stateToString(ColorState state) +{ + switch (state) + { + case NORMAL: return "normal"; + case FOCUS: return "focus"; + } + + return ""; +} diff --git a/src/lib/settings/ColorScheme.h b/src/lib/settings/ColorScheme.h index 8fae027d..24c10de6 100644 --- a/src/lib/settings/ColorScheme.h +++ b/src/lib/settings/ColorScheme.h @@ -1,21 +1,31 @@ #ifndef COLOR_SCHEME_H #define COLOR_SCHEME_H -#include "data/graph/Node.h" #include "data/graph/Edge.h" +#include "data/graph/Node.h" #include "settings/Settings.h" class ColorScheme : public Settings { public: + enum ColorState + { + NORMAL, + FOCUS + }; + static std::shared_ptr getInstance(); virtual ~ColorScheme(); std::string getColor(const std::string& key) const; - std::string getNodeTypeColor(Node::NodeType type, const std::string& state = "normal") const; - std::string getEdgeTypeColor(Edge::EdgeType type, const std::string& state = "normal") const; + std::string getNodeTypeColor(Node::NodeType type, const std::string& key, ColorState state) const; + std::string getNodeTypeColor(const std::string& typeStr, const std::string& key, ColorState state) const; + + std::string getEdgeTypeColor(Edge::EdgeType type, ColorState state) const; + std::string getEdgeTypeColor(const std::string& typeStr, ColorState state) const; + std::string getSearchTypeColor(const std::string& searchTypeName, const std::string& state = "normal") const; std::string getSyntaxColor(const std::string& key) const; @@ -25,6 +35,8 @@ protected: void operator=(const ColorScheme&); static std::shared_ptr s_instance; + + static std::string stateToString(ColorState state); }; #endif // COLOR_SCHEME_H