ui: new file node style with icon
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "qt/element/QtCodeFileList.h"
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "settings/ColorScheme.h"
|
||||
|
||||
QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
|
||||
: QFrame(parent)
|
||||
@@ -38,9 +40,15 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
|
||||
m_title->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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ protected:
|
||||
QGraphicsSimpleTextItem* m_text;
|
||||
QtRoundedRectItem* m_rect;
|
||||
QtRoundedRectItem* m_undefinedRect;
|
||||
QGraphicsPixmapItem* m_icon;
|
||||
|
||||
Vec2i m_size;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -487,6 +487,10 @@ Id Storage::onFileParsed(const std::string& filePath)
|
||||
fileNodeId = m_sqliteStorage.addFile(nameHierarchyElementId, filePath);
|
||||
}
|
||||
|
||||
NameHierarchy nameHierarchy;
|
||||
nameHierarchy.push(std::make_shared<NameElement>(fileName));
|
||||
m_tokenIndex.addNode(nameHierarchy)->addTokenId(fileNodeId);
|
||||
|
||||
return fileNodeId;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user