Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fontFamily options #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions include/QtNodes/internal/NodeStyle.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include <QtGui/QColor>

Expand Down Expand Up @@ -27,27 +27,27 @@ class NODE_EDITOR_PUBLIC NodeStyle : public Style
QJsonObject toJson() const override;

public:
QColor NormalBoundaryColor;
QColor SelectedBoundaryColor;
QColor GradientColor0;
QColor GradientColor1;
QColor GradientColor2;
QColor GradientColor3;
QColor ShadowColor;
QColor FontColor;
QColor FontColorFaded;

QColor ConnectionPointColor;
QColor FilledConnectionPointColor;

QColor WarningColor;
QColor ErrorColor;

float PenWidth;
float HoveredPenWidth;

float ConnectionPointDiameter;

float Opacity;
QColor NormalBoundaryColor;
QColor SelectedBoundaryColor;
QColor GradientColor0;
QColor GradientColor1;
QColor GradientColor2;
QColor GradientColor3;
QColor ShadowColor;
QColor FontColor;
QColor FontColorFaded;
Comment on lines +30 to +38
Copy link
Contributor

@nolankramer nolankramer Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert changes like these. There is no need to change these lines of code.

As a word of advice - it is usually desirable to only change code that needs to be changed to address the PR. This avoids causing confusion/overload when others review the change.

Additionally, stylistic coding is really up to repo owner as of now. And it seems like a single space between type and variable name is the overall style (and it typically is).

QString FontFamily;
QColor ConnectionPointColor;
QColor FilledConnectionPointColor;

QColor WarningColor;
QColor ErrorColor;

float PenWidth;
float HoveredPenWidth;

float ConnectionPointDiameter;

float Opacity;
Comment on lines +40 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert adding these additional spaces.

};
} // namespace QtNodes
3 changes: 2 additions & 1 deletion resources/DefaultStyle.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"GraphicsViewStyle": {
"BackgroundColor": [53, 53, 53],
"FineGridColor": [60, 60, 60],
Expand All @@ -14,6 +14,7 @@
"ShadowColor": [20, 20, 20],
"FontColor" : "white",
"FontColorFaded" : "gray",
"FontFamily": "Microsoft YaHei",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default font should be the default font of Qt: "Segoe UI"

(This font ships with Qt, so we know it's safe to use)

"ConnectionPointColor": [169, 169, 169],
"FilledConnectionPointColor": "cyan",
"ErrorColor": "red",
Expand Down
6 changes: 5 additions & 1 deletion src/DefaultNodePainter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "DefaultNodePainter.hpp"
#include "DefaultNodePainter.hpp"

#include <cmath>

Expand Down Expand Up @@ -209,6 +209,7 @@ void DefaultNodePainter::drawNodeCaption(QPainter *painter, NodeGraphicsObject &
QJsonDocument json = QJsonDocument::fromVariant(model.nodeData(nodeId, NodeRole::Style));
NodeStyle nodeStyle(json.object());

f.setFamily(nodeStyle.FontFamily);
painter->setFont(f);
painter->setPen(nodeStyle.FontColor);
painter->drawText(position, name);
Expand Down Expand Up @@ -252,6 +253,9 @@ void DefaultNodePainter::drawEntryLabels(QPainter *painter, NodeGraphicsObject &
s = portData.value<NodeDataType>().name;
}

auto f = painter->font();
f.setFamily(nodeStyle.FontFamily);
painter->setFont(f);
painter->drawText(p, s);
}
}
Expand Down
19 changes: 18 additions & 1 deletion src/NodeStyle.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "NodeStyle.hpp"
#include "NodeStyle.hpp"

#include <iostream>

Expand Down Expand Up @@ -88,6 +88,19 @@ void NodeStyle::setNodeStyle(QString jsonText)
values[#variable] = variable; \
}

#define NODE_STYLE_READ_STRING(values, variable)\
{ \
auto valueRef = values[#variable]; \
NODE_STYLE_CHECK_UNDEFINED_VALUE(valueRef, variable) \
variable = valueRef.toString(); \
}

#define NODE_STYLE_WRITE_STRING(values, variable) \
{ \
values[#variable] = variable; \
}


void NodeStyle::loadJson(QJsonObject const &json)
{
QJsonValue nodeStyleValues = json["NodeStyle"];
Expand All @@ -113,6 +126,8 @@ void NodeStyle::loadJson(QJsonObject const &json)
NODE_STYLE_READ_FLOAT(obj, ConnectionPointDiameter);

NODE_STYLE_READ_FLOAT(obj, Opacity);

NODE_STYLE_READ_STRING(obj, FontFamily);
}

QJsonObject NodeStyle::toJson() const
Expand All @@ -139,6 +154,8 @@ QJsonObject NodeStyle::toJson() const

NODE_STYLE_WRITE_FLOAT(obj, Opacity);

NODE_STYLE_WRITE_STRING(obj, FontFamily);

QJsonObject root;
root["NodeStyle"] = obj;

Expand Down