diff --git a/bin/app/data/gui/graph_view/images/bundle.png b/bin/app/data/gui/graph_view/images/bundle.png new file mode 100644 index 00000000..850c2735 Binary files /dev/null and b/bin/app/data/gui/graph_view/images/bundle.png differ diff --git a/bin/app/data/gui/graph_view/images/enum_1.png b/bin/app/data/gui/graph_view/images/enum_1.png new file mode 100644 index 00000000..4e97a001 Binary files /dev/null and b/bin/app/data/gui/graph_view/images/enum_1.png differ diff --git a/bin/app/data/gui/graph_view/images/enum_2.png b/bin/app/data/gui/graph_view/images/enum_2.png new file mode 100644 index 00000000..0cbb3873 Binary files /dev/null and b/bin/app/data/gui/graph_view/images/enum_2.png differ diff --git a/bin/app/data/gui/graph_view/images/macro_1.png b/bin/app/data/gui/graph_view/images/macro_1.png new file mode 100644 index 00000000..82fdc25e Binary files /dev/null and b/bin/app/data/gui/graph_view/images/macro_1.png differ diff --git a/bin/app/data/gui/graph_view/images/macro_2.png b/bin/app/data/gui/graph_view/images/macro_2.png new file mode 100644 index 00000000..839adfc2 Binary files /dev/null and b/bin/app/data/gui/graph_view/images/macro_2.png differ diff --git a/bin/app/data/gui/graph_view/images/macro_3.png b/bin/app/data/gui/graph_view/images/macro_3.png new file mode 100644 index 00000000..7e20eec3 Binary files /dev/null and b/bin/app/data/gui/graph_view/images/macro_3.png differ diff --git a/bin/app/data/gui/graph_view/images/typedef_1.png b/bin/app/data/gui/graph_view/images/typedef_1.png new file mode 100644 index 00000000..88a6d4fe Binary files /dev/null and b/bin/app/data/gui/graph_view/images/typedef_1.png differ diff --git a/bin/app/data/gui/graph_view/images/typedef_2.png b/bin/app/data/gui/graph_view/images/typedef_2.png new file mode 100644 index 00000000..2289c971 Binary files /dev/null and b/bin/app/data/gui/graph_view/images/typedef_2.png differ diff --git a/bin/app/data/gui/graph_view/images/typedef_3.png b/bin/app/data/gui/graph_view/images/typedef_3.png new file mode 100644 index 00000000..eee76dac Binary files /dev/null and b/bin/app/data/gui/graph_view/images/typedef_3.png differ diff --git a/bin/app/data/src/sample/samples.cpp b/bin/app/data/src/sample/samples.cpp index 680e8abe..860b8a9f 100644 --- a/bin/app/data/src/sample/samples.cpp +++ b/bin/app/data/src/sample/samples.cpp @@ -22,6 +22,18 @@ int calculate(int i) } +#define CALL_CALCULATE() \ + do \ + { \ + calculate(); \ + } \ + while(0) \ + +int main() +{ + CALL_CALCULATE(); +} + int count = 0; void countUp() @@ -173,3 +185,13 @@ class Tower : public Building {}; class SkyScrapper : public Building {}; class Mansion : public Building {}; class Shard : public House, public Tower, public SkyScrapper, public Mansion {}; + +typedef unsigned int uint; +uint a = 1 + 2; + +enum Size +{ + SMALL, + MEDIUM, + LARGE +}; diff --git a/src/app/qt/view/QtGraphView.cpp b/src/app/qt/view/QtGraphView.cpp index c0336183..591c3a89 100644 --- a/src/app/qt/view/QtGraphView.cpp +++ b/src/app/qt/view/QtGraphView.cpp @@ -108,11 +108,6 @@ void QtGraphView::centerScrollBars() void QtGraphView::finishedTransition() { - for (const std::shared_ptr& node : m_nodes) - { - node->setShadowEnabledRecursive(true); - } - QGraphicsView* view = getView(); view->setInteractive(true); @@ -434,16 +429,6 @@ void QtGraphView::createTransition() } } - for (const std::shared_ptr& node : m_nodes) - { - node->setShadowEnabledRecursive(false); - } - - for (const std::shared_ptr& node : m_oldNodes) - { - node->setShadowEnabledRecursive(false); - } - QGraphicsView* view = getView(); view->setInteractive(false); diff --git a/src/app/qt/view/graphElements/QtGraphNode.cpp b/src/app/qt/view/graphElements/QtGraphNode.cpp index 94229477..e8af64cf 100644 --- a/src/app/qt/view/graphElements/QtGraphNode.cpp +++ b/src/app/qt/view/graphElements/QtGraphNode.cpp @@ -199,16 +199,6 @@ void QtGraphNode::addComponent(const std::shared_ptr& comp m_components.push_back(component); } -void QtGraphNode::setShadowEnabledRecursive(bool enabled) -{ - m_rect->setShadowEnabled(enabled); - - for (const std::shared_ptr& node : m_subNodes) - { - node->setShadowEnabledRecursive(enabled); - } -} - void QtGraphNode::hoverEnter() { hoverEnterEvent(nullptr); @@ -352,30 +342,21 @@ void QtGraphNode::notifyEdgesAfterMove() void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style) { - QColor color = style.color.c_str(); + QPen pen(Qt::transparent); + if (style.borderWidth > 0) + { + pen.setColor(style.borderColor.c_str()); + pen.setWidthF(style.borderWidth); + if (style.borderDashed) + { + pen.setStyle(Qt::DashLine); + } + } + + m_rect->setPen(pen); + m_rect->setBrush(QBrush(style.color.c_str())); + qreal radius = style.cornerRadius; - - QPen p(style.borderColor.c_str()); - p.setWidthF(style.borderWidth); - if (style.borderDashed) - { - p.setStyle(Qt::DashLine); - } - - QFont font(style.fontName.c_str()); - font.setPixelSize(style.fontSize); - if (style.fontBold) - { - font.setWeight(QFont::Bold); - } - - if (style.shadowColor.size()) - { - m_rect->setShadow(style.shadowColor.c_str(), style.shadowBlurRadius); - } - - m_rect->setPen(p); - m_rect->setBrush(QBrush(color)); m_rect->setRadius(radius); if (style.hatchingColor.size()) @@ -390,10 +371,10 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style) setSize(getSize()); } - p.setWidth(0); - p.setColor(Qt::transparent); + pen.setWidth(0); + pen.setColor(Qt::transparent); - m_undefinedRect->setPen(p); + m_undefinedRect->setPen(pen); m_undefinedRect->setBrush(pixmap); m_undefinedRect->setRadius(radius); } @@ -407,6 +388,13 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style) m_icon->setPos(style.iconOffset.x, style.iconOffset.y); } + QFont font(style.fontName.c_str()); + font.setPixelSize(style.fontSize); + if (style.fontBold) + { + font.setWeight(QFont::Bold); + } + m_text->setFont(font); m_text->setBrush(QBrush(style.textColor.c_str())); m_text->setPos(style.iconOffset.x + style.iconSize + style.textOffset.x, style.textOffset.y); diff --git a/src/app/qt/view/graphElements/QtGraphNode.h b/src/app/qt/view/graphElements/QtGraphNode.h index b6e14a9e..ec330ae5 100644 --- a/src/app/qt/view/graphElements/QtGraphNode.h +++ b/src/app/qt/view/graphElements/QtGraphNode.h @@ -66,8 +66,6 @@ public: void addComponent(const std::shared_ptr& component); - void setShadowEnabledRecursive(bool enabled); - void hoverEnter(); void focusIn(); diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 39c1d554..9b348e1e 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -282,7 +282,7 @@ void GraphController::autoExpandActiveNode(const std::vector& activeTokenIds node = findDummyNodeRecursive(m_dummyNodes, activeTokenIds[0]); } - if (node && node->data->isType(Node::NODE_CLASS | Node::NODE_STRUCT)) + if (node && node->data->isType(Node::NODE_CLASS | Node::NODE_STRUCT | Node::NODE_ENUM)) { node->expanded = true; } @@ -378,7 +378,7 @@ void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode& node, bool pa if ((node.isGraphNode() && node.isExpanded()) || (node.isAccessNode() && parentExpanded) || - (node.isGraphNode() && node.data->isType(Node::NODE_ENUM))) + (node.isGraphNode() && parentExpanded && node.data->isType(Node::NODE_ENUM_CONSTANT))) { for (DummyNode& subNode : node.subNodes) { @@ -441,7 +441,7 @@ void GraphController::bundleNodes() return false; }, 3, - "Undefined Nodes" + "Undefined Symbols" ); } @@ -652,9 +652,7 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const width = margins.charWidth * node.data->getName().size(); } - width += margins.iconWidth; - - if (node.data->isType(Node::NODE_CLASS | Node::NODE_STRUCT) && node.subNodes.size()) + if (node.data->isType(Node::NODE_CLASS | Node::NODE_STRUCT | Node::NODE_ENUM) && node.subNodes.size()) { addExpandToggleNode(node); } @@ -664,6 +662,8 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const width = margins.charWidth * node.name.size(); } + width += margins.iconWidth; + // Horizontal layouting is currently not used, but left in place for experimentation. bool layoutHorizontal = false; @@ -762,6 +762,11 @@ void GraphController::addExpandToggleNode(DummyNode& node) const i--; continue; } + else if (subNode.isGraphNode() && subNode.data->isType(Node::NODE_ENUM_CONSTANT) && !subNode.visible) + { + expandNode.invisibleSubNodeCount++; + continue; + } for (DummyNode& subSubNode : subNode.subNodes) { diff --git a/src/lib/component/view/GraphViewStyle.cpp b/src/lib/component/view/GraphViewStyle.cpp index 9cef5ffb..a538e83f 100644 --- a/src/lib/component/view/GraphViewStyle.cpp +++ b/src/lib/component/view/GraphViewStyle.cpp @@ -21,8 +21,7 @@ GraphViewStyle::NodeMargins::NodeMargins() } GraphViewStyle::NodeStyle::NodeStyle() - : shadowBlurRadius(0) - , cornerRadius(0) + : cornerRadius(0) , borderWidth(0) , borderDashed(false) , fontSize(0) @@ -172,12 +171,14 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType break; case Node::NODE_FILE: + case Node::NODE_ENUM: + case Node::NODE_TYPEDEF: + case Node::NODE_UNDEFINED_MACRO: + case Node::NODE_MACRO: margins.iconWidth = s_fontSize + 11; case Node::NODE_UNDEFINED_TYPE: case Node::NODE_STRUCT: case Node::NODE_CLASS: - case Node::NODE_ENUM: - case Node::NODE_TYPEDEF: case Node::NODE_TEMPLATE_PARAMETER_TYPE: if (hasChildren) { @@ -199,8 +200,6 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType case Node::NODE_GLOBAL_VARIABLE: case Node::NODE_FIELD: case Node::NODE_ENUM_CONSTANT: - case Node::NODE_UNDEFINED_MACRO: - case Node::NODE_MACRO: margins.left = margins.right = 5; margins.top = margins.bottom = 3; break; @@ -252,7 +251,7 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfExpandToggleNode() GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfBundleNode() { - return getMarginsForNodeType(Node::NODE_CLASS, false); + return getMarginsForNodeType(Node::NODE_ENUM, false); } GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( @@ -272,7 +271,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( } style.textColor = scheme->getColor("graph/text"); - style.borderColor = isActive ? scheme->getColor("graph/border") : "#00000000"; + style.borderColor = scheme->getColor("graph/border"); style.fontName = getFontNameForNodeType(type); style.fontSize = getFontSizeForNodeType(type); @@ -294,6 +293,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( break; case Node::NODE_UNDEFINED_TYPE: + case Node::NODE_UNDEFINED_MACRO: style.hatchingColor = scheme->getColor("graph/hatching"); case Node::NODE_STRUCT: @@ -301,22 +301,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( case Node::NODE_ENUM: case Node::NODE_TYPEDEF: case Node::NODE_TEMPLATE_PARAMETER_TYPE: - if (isActive) - { - style.fontBold = true; - } - - style.shadowColor = scheme->getColor("graph/border"); - if (isFocused) - { - style.shadowColor.insert(1, "FF"); - } - else - { - style.shadowColor.insert(1, "80"); - } - style.shadowBlurRadius = 5; - + case Node::NODE_MACRO: if (hasChildren) { style.cornerRadius = 20; @@ -329,27 +314,30 @@ 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: - if (isActive) - { - style.fontBold = true; - } - style.cornerRadius = 10; style.textOffset.x = 6; style.textOffset.y = 9; - style.iconPath = "data/gui/graph_view/images/file.png"; - style.iconSize = s_fontSize + 2; - style.iconOffset.x = 9; - style.iconOffset.y = 9; - style.iconColor = scheme->getColor("graph/icon"); break; case Node::NODE_UNDEFINED_FUNCTION: case Node::NODE_UNDEFINED_VARIABLE: - case Node::NODE_UNDEFINED_MACRO: style.hatchingColor = scheme->getColor("graph/hatching"); case Node::NODE_FUNCTION: @@ -357,23 +345,24 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( case Node::NODE_GLOBAL_VARIABLE: case Node::NODE_FIELD: case Node::NODE_ENUM_CONSTANT: - case Node::NODE_MACRO: - if (isActive || isFocused) - { - style.fontBold = true; - } - style.cornerRadius = 8; style.textOffset.x = 5; style.textOffset.y = 3; + + if (isActive) + { + style.borderWidth = 2; + } break; } - if (isActive) + if (isActive || isFocused) { - style.borderWidth = 1.5f; + style.fontBold = true; } + addIcon(type, hasChildren, &style); + return style; } @@ -423,11 +412,8 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfBundleNode(bool isFocused) { NodeStyle style = getStyleForNodeType(Node::NODE_CLASS, false, isFocused, false); - ColorScheme* scheme = ColorScheme::getInstance().get(); - - style.shadowColor = ""; - style.borderColor = scheme->getColor("graph/border"); - style.borderWidth = isFocused ? 2 : 1; + addIcon(Node::NODE_ENUM, false, &style); + style.iconPath = "data/gui/graph_view/images/bundle.png"; return style; } @@ -527,6 +513,43 @@ int GraphViewStyle::toGridGap(int x) return s_gridCellPadding + toGridOffset(x - s_gridCellPadding); } +void GraphViewStyle::addIcon(Node::NodeType type, bool hasChildren, NodeStyle* style) +{ + switch (type) + { + case Node::NODE_ENUM: + style->iconPath = "data/gui/graph_view/images/enum_1.png"; + break; + case Node::NODE_TYPEDEF: + style->iconPath = "data/gui/graph_view/images/typedef_2.png"; + break; + case Node::NODE_UNDEFINED_MACRO: + case Node::NODE_MACRO: + style->iconPath = "data/gui/graph_view/images/macro_3.png"; + break; + case Node::NODE_FILE: + style->iconPath = "data/gui/graph_view/images/file.png"; + break; + default: + return; + } + + style->iconSize = s_fontSize + 2; + + if (hasChildren) + { + style->iconOffset.x = 11; + style->textOffset.x = 6; + } + else + { + style->iconOffset.x = 9; + } + + style->iconOffset.y = 9; + style->iconColor = ColorScheme::getInstance()->getColor("graph/icon"); +} + int GraphViewStyle::s_gridCellSize = 5; int GraphViewStyle::s_gridCellPadding = 10; diff --git a/src/lib/component/view/GraphViewStyle.h b/src/lib/component/view/GraphViewStyle.h index 02e0f0d7..5be35936 100644 --- a/src/lib/component/view/GraphViewStyle.h +++ b/src/lib/component/view/GraphViewStyle.h @@ -44,12 +44,9 @@ public: std::string iconColor; std::string hatchingColor; - std::string shadowColor; - int shadowBlurRadius; - int cornerRadius; - float borderWidth; + int borderWidth; std::string borderColor; bool borderDashed; @@ -123,6 +120,8 @@ public: static int s_gridCellPadding; private: + static void addIcon(Node::NodeType type, bool hasChildren, NodeStyle* style); + static std::map s_charWidths; static std::map s_charHeights;