ui: new features for the Graph UI

* removed node shadows
* made enums collapsible
* added icons to nodes: enum, typedef, macro, bundle
This commit is contained in:
Eberhard Graether
2015-09-29 15:10:44 +02:00
parent 8777c9874b
commit 201e6d24a9
16 changed files with 131 additions and 111 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 748 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 546 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 805 B

+22
View File
@@ -22,6 +22,18 @@ int calculate(int i)
} }
#define CALL_CALCULATE() \
do \
{ \
calculate(); \
} \
while(0) \
int main()
{
CALL_CALCULATE();
}
int count = 0; int count = 0;
void countUp() void countUp()
@@ -173,3 +185,13 @@ class Tower : public Building {};
class SkyScrapper : public Building {}; class SkyScrapper : public Building {};
class Mansion : public Building {}; class Mansion : public Building {};
class Shard : public House, public Tower, public SkyScrapper, public Mansion {}; class Shard : public House, public Tower, public SkyScrapper, public Mansion {};
typedef unsigned int uint;
uint a = 1 + 2;
enum Size
{
SMALL,
MEDIUM,
LARGE
};
-15
View File
@@ -108,11 +108,6 @@ void QtGraphView::centerScrollBars()
void QtGraphView::finishedTransition() void QtGraphView::finishedTransition()
{ {
for (const std::shared_ptr<QtGraphNode>& node : m_nodes)
{
node->setShadowEnabledRecursive(true);
}
QGraphicsView* view = getView(); QGraphicsView* view = getView();
view->setInteractive(true); view->setInteractive(true);
@@ -434,16 +429,6 @@ void QtGraphView::createTransition()
} }
} }
for (const std::shared_ptr<QtGraphNode>& node : m_nodes)
{
node->setShadowEnabledRecursive(false);
}
for (const std::shared_ptr<QtGraphNode>& node : m_oldNodes)
{
node->setShadowEnabledRecursive(false);
}
QGraphicsView* view = getView(); QGraphicsView* view = getView();
view->setInteractive(false); view->setInteractive(false);
+24 -36
View File
@@ -199,16 +199,6 @@ void QtGraphNode::addComponent(const std::shared_ptr<QtGraphNodeComponent>& comp
m_components.push_back(component); m_components.push_back(component);
} }
void QtGraphNode::setShadowEnabledRecursive(bool enabled)
{
m_rect->setShadowEnabled(enabled);
for (const std::shared_ptr<QtGraphNode>& node : m_subNodes)
{
node->setShadowEnabledRecursive(enabled);
}
}
void QtGraphNode::hoverEnter() void QtGraphNode::hoverEnter()
{ {
hoverEnterEvent(nullptr); hoverEnterEvent(nullptr);
@@ -352,30 +342,21 @@ void QtGraphNode::notifyEdgesAfterMove()
void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style) 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; 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); m_rect->setRadius(radius);
if (style.hatchingColor.size()) if (style.hatchingColor.size())
@@ -390,10 +371,10 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style)
setSize(getSize()); setSize(getSize());
} }
p.setWidth(0); pen.setWidth(0);
p.setColor(Qt::transparent); pen.setColor(Qt::transparent);
m_undefinedRect->setPen(p); m_undefinedRect->setPen(pen);
m_undefinedRect->setBrush(pixmap); m_undefinedRect->setBrush(pixmap);
m_undefinedRect->setRadius(radius); m_undefinedRect->setRadius(radius);
} }
@@ -407,6 +388,13 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style)
m_icon->setPos(style.iconOffset.x, style.iconOffset.y); 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->setFont(font);
m_text->setBrush(QBrush(style.textColor.c_str())); m_text->setBrush(QBrush(style.textColor.c_str()));
m_text->setPos(style.iconOffset.x + style.iconSize + style.textOffset.x, style.textOffset.y); m_text->setPos(style.iconOffset.x + style.iconSize + style.textOffset.x, style.textOffset.y);
@@ -66,8 +66,6 @@ public:
void addComponent(const std::shared_ptr<QtGraphNodeComponent>& component); void addComponent(const std::shared_ptr<QtGraphNodeComponent>& component);
void setShadowEnabledRecursive(bool enabled);
void hoverEnter(); void hoverEnter();
void focusIn(); void focusIn();
@@ -282,7 +282,7 @@ void GraphController::autoExpandActiveNode(const std::vector<Id>& activeTokenIds
node = findDummyNodeRecursive(m_dummyNodes, activeTokenIds[0]); 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; node->expanded = true;
} }
@@ -378,7 +378,7 @@ void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode& node, bool pa
if ((node.isGraphNode() && node.isExpanded()) || if ((node.isGraphNode() && node.isExpanded()) ||
(node.isAccessNode() && parentExpanded) || (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) for (DummyNode& subNode : node.subNodes)
{ {
@@ -441,7 +441,7 @@ void GraphController::bundleNodes()
return false; return false;
}, },
3, 3,
"Undefined Nodes" "Undefined Symbols"
); );
} }
@@ -652,9 +652,7 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const
width = margins.charWidth * node.data->getName().size(); width = margins.charWidth * node.data->getName().size();
} }
width += margins.iconWidth; if (node.data->isType(Node::NODE_CLASS | Node::NODE_STRUCT | Node::NODE_ENUM) && node.subNodes.size())
if (node.data->isType(Node::NODE_CLASS | Node::NODE_STRUCT) && node.subNodes.size())
{ {
addExpandToggleNode(node); addExpandToggleNode(node);
} }
@@ -664,6 +662,8 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const
width = margins.charWidth * node.name.size(); width = margins.charWidth * node.name.size();
} }
width += margins.iconWidth;
// Horizontal layouting is currently not used, but left in place for experimentation. // Horizontal layouting is currently not used, but left in place for experimentation.
bool layoutHorizontal = false; bool layoutHorizontal = false;
@@ -762,6 +762,11 @@ void GraphController::addExpandToggleNode(DummyNode& node) const
i--; i--;
continue; continue;
} }
else if (subNode.isGraphNode() && subNode.data->isType(Node::NODE_ENUM_CONSTANT) && !subNode.visible)
{
expandNode.invisibleSubNodeCount++;
continue;
}
for (DummyNode& subSubNode : subNode.subNodes) for (DummyNode& subSubNode : subNode.subNodes)
{ {
+71 -48
View File
@@ -21,8 +21,7 @@ GraphViewStyle::NodeMargins::NodeMargins()
} }
GraphViewStyle::NodeStyle::NodeStyle() GraphViewStyle::NodeStyle::NodeStyle()
: shadowBlurRadius(0) : cornerRadius(0)
, cornerRadius(0)
, borderWidth(0) , borderWidth(0)
, borderDashed(false) , borderDashed(false)
, fontSize(0) , fontSize(0)
@@ -172,12 +171,14 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType
break; break;
case Node::NODE_FILE: 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; margins.iconWidth = s_fontSize + 11;
case Node::NODE_UNDEFINED_TYPE: case Node::NODE_UNDEFINED_TYPE:
case Node::NODE_STRUCT: case Node::NODE_STRUCT:
case Node::NODE_CLASS: case Node::NODE_CLASS:
case Node::NODE_ENUM:
case Node::NODE_TYPEDEF:
case Node::NODE_TEMPLATE_PARAMETER_TYPE: case Node::NODE_TEMPLATE_PARAMETER_TYPE:
if (hasChildren) if (hasChildren)
{ {
@@ -199,8 +200,6 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType
case Node::NODE_GLOBAL_VARIABLE: case Node::NODE_GLOBAL_VARIABLE:
case Node::NODE_FIELD: case Node::NODE_FIELD:
case Node::NODE_ENUM_CONSTANT: case Node::NODE_ENUM_CONSTANT:
case Node::NODE_UNDEFINED_MACRO:
case Node::NODE_MACRO:
margins.left = margins.right = 5; margins.left = margins.right = 5;
margins.top = margins.bottom = 3; margins.top = margins.bottom = 3;
break; break;
@@ -252,7 +251,7 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfExpandToggleNode()
GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfBundleNode() GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfBundleNode()
{ {
return getMarginsForNodeType(Node::NODE_CLASS, false); return getMarginsForNodeType(Node::NODE_ENUM, false);
} }
GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
@@ -272,7 +271,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
} }
style.textColor = scheme->getColor("graph/text"); 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.fontName = getFontNameForNodeType(type);
style.fontSize = getFontSizeForNodeType(type); style.fontSize = getFontSizeForNodeType(type);
@@ -294,6 +293,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
break; break;
case Node::NODE_UNDEFINED_TYPE: case Node::NODE_UNDEFINED_TYPE:
case Node::NODE_UNDEFINED_MACRO:
style.hatchingColor = scheme->getColor("graph/hatching"); style.hatchingColor = scheme->getColor("graph/hatching");
case Node::NODE_STRUCT: case Node::NODE_STRUCT:
@@ -301,22 +301,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
case Node::NODE_ENUM: case Node::NODE_ENUM:
case Node::NODE_TYPEDEF: case Node::NODE_TYPEDEF:
case Node::NODE_TEMPLATE_PARAMETER_TYPE: case Node::NODE_TEMPLATE_PARAMETER_TYPE:
if (isActive) case Node::NODE_MACRO:
{
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;
if (hasChildren) if (hasChildren)
{ {
style.cornerRadius = 20; style.cornerRadius = 20;
@@ -329,27 +314,30 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
style.textOffset.x = 8; style.textOffset.x = 8;
style.textOffset.y = 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; break;
case Node::NODE_FILE: case Node::NODE_FILE:
if (isActive)
{
style.fontBold = true;
}
style.cornerRadius = 10; style.cornerRadius = 10;
style.textOffset.x = 6; style.textOffset.x = 6;
style.textOffset.y = 9; 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; break;
case Node::NODE_UNDEFINED_FUNCTION: case Node::NODE_UNDEFINED_FUNCTION:
case Node::NODE_UNDEFINED_VARIABLE: case Node::NODE_UNDEFINED_VARIABLE:
case Node::NODE_UNDEFINED_MACRO:
style.hatchingColor = scheme->getColor("graph/hatching"); style.hatchingColor = scheme->getColor("graph/hatching");
case Node::NODE_FUNCTION: case Node::NODE_FUNCTION:
@@ -357,23 +345,24 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType(
case Node::NODE_GLOBAL_VARIABLE: case Node::NODE_GLOBAL_VARIABLE:
case Node::NODE_FIELD: case Node::NODE_FIELD:
case Node::NODE_ENUM_CONSTANT: case Node::NODE_ENUM_CONSTANT:
case Node::NODE_MACRO:
if (isActive || isFocused)
{
style.fontBold = true;
}
style.cornerRadius = 8; style.cornerRadius = 8;
style.textOffset.x = 5; style.textOffset.x = 5;
style.textOffset.y = 3; style.textOffset.y = 3;
if (isActive)
{
style.borderWidth = 2;
}
break; break;
} }
if (isActive) if (isActive || isFocused)
{ {
style.borderWidth = 1.5f; style.fontBold = true;
} }
addIcon(type, hasChildren, &style);
return style; return style;
} }
@@ -423,11 +412,8 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfBundleNode(bool isFocused)
{ {
NodeStyle style = getStyleForNodeType(Node::NODE_CLASS, false, isFocused, false); NodeStyle style = getStyleForNodeType(Node::NODE_CLASS, false, isFocused, false);
ColorScheme* scheme = ColorScheme::getInstance().get(); addIcon(Node::NODE_ENUM, false, &style);
style.iconPath = "data/gui/graph_view/images/bundle.png";
style.shadowColor = "";
style.borderColor = scheme->getColor("graph/border");
style.borderWidth = isFocused ? 2 : 1;
return style; return style;
} }
@@ -527,6 +513,43 @@ int GraphViewStyle::toGridGap(int x)
return s_gridCellPadding + toGridOffset(x - s_gridCellPadding); 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_gridCellSize = 5;
int GraphViewStyle::s_gridCellPadding = 10; int GraphViewStyle::s_gridCellPadding = 10;
+3 -4
View File
@@ -44,12 +44,9 @@ public:
std::string iconColor; std::string iconColor;
std::string hatchingColor; std::string hatchingColor;
std::string shadowColor;
int shadowBlurRadius;
int cornerRadius; int cornerRadius;
float borderWidth; int borderWidth;
std::string borderColor; std::string borderColor;
bool borderDashed; bool borderDashed;
@@ -123,6 +120,8 @@ public:
static int s_gridCellPadding; static int s_gridCellPadding;
private: private:
static void addIcon(Node::NodeType type, bool hasChildren, NodeStyle* style);
static std::map<Node::NodeType, float> s_charWidths; static std::map<Node::NodeType, float> s_charWidths;
static std::map<Node::NodeType, float> s_charHeights; static std::map<Node::NodeType, float> s_charHeights;