From 934c70272debf7883c3f0672fb91262d0b79b429 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 8 Sep 2015 17:08:33 +0200 Subject: [PATCH] ui: new file node style with icon --- bin/app/data/color_schemes/bright.xml | 9 +++++---- bin/app/data/color_schemes/dark.xml | 1 + bin/app/data/gui/graph_view/images/file.png | Bin 0 -> 436 bytes src/app/qt/element/QtCodeFile.cpp | 10 +++++++++- src/app/qt/view/graphElements/QtGraphNode.cpp | 12 +++++++++++- src/app/qt/view/graphElements/QtGraphNode.h | 1 + .../component/controller/GraphController.cpp | 2 ++ src/lib/component/view/GraphViewStyle.cpp | 16 ++++++++++++---- src/lib/component/view/GraphViewStyle.h | 6 ++++++ src/lib/data/Storage.cpp | 4 ++++ 10 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 bin/app/data/gui/graph_view/images/file.png diff --git a/bin/app/data/color_schemes/bright.xml b/bin/app/data/color_schemes/bright.xml index 50e4d83d..a02e356d 100644 --- a/bin/app/data/color_schemes/bright.xml +++ b/bin/app/data/color_schemes/bright.xml @@ -52,6 +52,7 @@ #E0E0E0 #B2B2B2 #626262 + black @@ -170,8 +171,8 @@ - #88BAB3 - #6AA39B + #DDD + #CCC @@ -233,8 +234,8 @@ - #5DA399 - #5DA399 + #878787 + #878787 diff --git a/bin/app/data/color_schemes/dark.xml b/bin/app/data/color_schemes/dark.xml index 0ed9b8be..d3a750cd 100644 --- a/bin/app/data/color_schemes/dark.xml +++ b/bin/app/data/color_schemes/dark.xml @@ -52,6 +52,7 @@ #777777 #555555 #444444 + white diff --git a/bin/app/data/gui/graph_view/images/file.png b/bin/app/data/gui/graph_view/images/file.png new file mode 100644 index 0000000000000000000000000000000000000000..f19d49e3224735b607e24feda9267144f57d389f GIT binary patch literal 436 zcmeAS@N?(olHy`uVBq!ia0vp^0U*r51|<6gKdl8)k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+7{feW978H@y}5Inx5+@H;o&t424xE-=@rr&8rMBi>3hJj zp;3DWr`S=Kc&{bj=l%EhtI1^gc}TZq#qq+BZCkGO{>%)$)fOTh_o-5ML+?uiU2hw6 zV_z+Y+c_bUrD?xHI<|Q+hI~#{u|6`1VY7=4uYvUuA;!&4I-&;BF7gf2Ulv~cEYckD zNpJ>h5^sa2U^b&qTZC|e(2-jV_8s3N^c}KT=G;2#p2Yp&*DQ$+Q)V~EHL?a4i&zdU z=m=tHR`g=xY0}`mV7B@+^>kRLZN=u>Wr_#{y-ghQ1Dl zTY}aMce5CIWE%Q%jqk2cK9c*@l!minimumSizeHint(); // force font loading m_title->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac m_title->setToolTip(QString::fromStdString(filePath.str())); - m_title->setFixedWidth(m_title->fontMetrics().width(filePath.fileName().c_str()) + 32); + m_title->setFixedWidth(m_title->fontMetrics().width(filePath.fileName().c_str()) + 52); m_title->setFixedHeight(std::max(m_title->fontMetrics().height() * 1.2, 28.0)); m_title->setSizePolicy(sizePolicy().horizontalPolicy(), QSizePolicy::Fixed); + + m_title->setIcon(utility::colorizePixmap( + QPixmap("data/gui/graph_view/images/file.png"), + ColorScheme::getInstance()->getColor("code/file/title/icon").c_str() + )); + titleLayout->addWidget(m_title); titleWidget->setMinimumHeight(m_title->height() + 4); diff --git a/src/app/qt/view/graphElements/QtGraphNode.cpp b/src/app/qt/view/graphElements/QtGraphNode.cpp index 861a4cc9..50bfce87 100644 --- a/src/app/qt/view/graphElements/QtGraphNode.cpp +++ b/src/app/qt/view/graphElements/QtGraphNode.cpp @@ -42,6 +42,7 @@ QFont QtGraphNode::getFontForNodeType(Node::NodeType type) QtGraphNode::QtGraphNode() : m_undefinedRect(nullptr) + , m_icon(nullptr) , m_isActive(false) , m_isHovering(false) { @@ -393,7 +394,16 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style) m_undefinedRect->setRadius(radius); } + if (style.iconPath.size()) + { + 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->setPos(style.iconOffset.x, style.iconOffset.y); + } + m_text->setFont(font); m_text->setBrush(QBrush(style.textColor.c_str())); - m_text->setPos(style.textOffset.x, style.textOffset.y); + 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 aa886749..46feac21 100644 --- a/src/app/qt/view/graphElements/QtGraphNode.h +++ b/src/app/qt/view/graphElements/QtGraphNode.h @@ -102,6 +102,7 @@ protected: QGraphicsSimpleTextItem* m_text; QtRoundedRectItem* m_rect; QtRoundedRectItem* m_undefinedRect; + QGraphicsPixmapItem* m_icon; Vec2i m_size; diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index a27d4bf9..bd2235d0 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -695,6 +695,8 @@ 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()) { addExpandToggleNode(node); diff --git a/src/lib/component/view/GraphViewStyle.cpp b/src/lib/component/view/GraphViewStyle.cpp index b8f52978..cb330060 100644 --- a/src/lib/component/view/GraphViewStyle.cpp +++ b/src/lib/component/view/GraphViewStyle.cpp @@ -16,6 +16,7 @@ GraphViewStyle::NodeMargins::NodeMargins() , minWidth(0) , charWidth(0.0f) , charHeight(0.0f) + , iconWidth(0) { } @@ -26,6 +27,7 @@ GraphViewStyle::NodeStyle::NodeStyle() , borderDashed(false) , fontSize(0) , fontBold(false) + , iconSize(0) { } @@ -162,13 +164,14 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType margins.bottom = 15; break; + case Node::NODE_FILE: + 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: - case Node::NODE_FILE: if (hasChildren) { margins.left = margins.right = 10; @@ -325,9 +328,14 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( style.fontBold = true; } - style.cornerRadius = 6; - style.textOffset.x = 8; - style.textOffset.y = 8; + 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: diff --git a/src/lib/component/view/GraphViewStyle.h b/src/lib/component/view/GraphViewStyle.h index f2586bb8..a6f0bf27 100644 --- a/src/lib/component/view/GraphViewStyle.h +++ b/src/lib/component/view/GraphViewStyle.h @@ -32,6 +32,8 @@ public: float charWidth; float charHeight; + + int iconWidth; }; struct NodeStyle @@ -57,6 +59,10 @@ public: bool fontBold; Vec2i textOffset; + + std::string iconPath; + Vec2i iconOffset; + size_t iconSize; }; struct EdgeStyle diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index d8284b81..b227ddff 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -487,6 +487,10 @@ Id Storage::onFileParsed(const std::string& filePath) fileNodeId = m_sqliteStorage.addFile(nameHierarchyElementId, filePath); } + NameHierarchy nameHierarchy; + nameHierarchy.push(std::make_shared(fileName)); + m_tokenIndex.addNode(nameHierarchy)->addTokenId(fileNodeId); + return fileNodeId; }