Skip to content

Commit 6c730a2

Browse files
committed
Implement hash-based connection color
1 parent b3a1028 commit 6c730a2

27 files changed

Lines changed: 413 additions & 105 deletions

‎CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.2)
22

33
project(NodeEditor)
44

5-
option(BUILD_EXAMPLES ON)
5+
option(BUILD_EXAMPLES "Build Examples" ON)
66

77
# Find includes in corresponding build directories
88
set(CMAKE_INCLUDE_CURRENT_DIR ON)

‎examples/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_subdirectory(example1)
1+
add_subdirectory(connection_colors)
22

33
add_subdirectory(example2)
44

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file(GLOB_RECURSE CPPS ./*.cpp )
2+
3+
add_executable(connection_colors ${CPPS})
4+
5+
target_link_libraries(connection_colors nodes)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <nodes/FlowScene>
55
#include <nodes/FlowView>
66
#include <nodes/DataModelRegistry>
7+
#include <nodes/ConnectionStyle>
78

89
#include "models.hpp"
910

@@ -27,13 +28,31 @@ registerDataModels()
2728
}
2829

2930

31+
32+
static
33+
void
34+
setStyle()
35+
{
36+
ConnectionStyle::setConnectionStyle(
37+
R"(
38+
{
39+
"ConnectionStyle": {
40+
"UseDataDefinedColors": true
41+
}
42+
}
43+
)");
44+
}
45+
46+
3047
//------------------------------------------------------------------------------
3148

3249
int
3350
main(int argc, char* argv[])
3451
{
3552
QApplication app(argc, argv);
3653

54+
setStyle();
55+
3756
FlowScene scene(registerDataModels());
3857

3958
FlowView view(&scene);
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class NaiveDataModel : public NodeDataModel
7878
break;
7979

8080
case PortType::Out:
81-
result = 1;
81+
result = 2;
8282

8383
default:
8484
break;
@@ -106,7 +106,16 @@ class NaiveDataModel : public NodeDataModel
106106
break;
107107

108108
case PortType::Out:
109-
return MyNodeData().type();
109+
switch (portIndex)
110+
{
111+
case 0:
112+
return MyNodeData().type();
113+
break;
114+
115+
case 1:
116+
return SimpleNodeData().type();
117+
break;
118+
}
110119
break;
111120

112121
default:

‎examples/example1/CMakeLists.txt‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎examples/styles/main.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ setStyle()
7070
7171
"LineWidth": 3.0,
7272
"ConstructionLineWidth": 2.0,
73-
"PointDiameter": 10.0
73+
"PointDiameter": 10.0,
74+
75+
"UseDataDefinedColors": false
7476
}
7577
}
7678
)");

‎resources/DefaultStyle.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
"LineWidth": 3.0,
3535
"ConstructionLineWidth": 2.0,
36-
"PointDiameter": 10.0
36+
"PointDiameter": 10.0,
37+
38+
"UseDataDefinedColors": false
3739
}
3840
}

‎src/ConnectionGeometry.cpp‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
#include <cmath>
44

5-
ConnectionStyle ConnectionGeometry::connectionStyle;
5+
#include "StyleCollection.hpp"
66

77
ConnectionGeometry::
88
ConnectionGeometry()
99
: _in(0, 0)
1010
, _out(0, 0)
11-
, _pointDiameter(10)
1211
//, _animationPhase(0)
1312
, _lineWidth(3.0)
1413
, _hovered(false)
@@ -76,10 +75,15 @@ boundingRect() const
7675

7776
QRectF c1c2Rect(points.first, points.second);
7877

79-
QMargins margins(_pointDiameter,
80-
_pointDiameter,
81-
_pointDiameter,
82-
_pointDiameter);
78+
auto const &connectionStyle =
79+
StyleCollection::connectionStyle();
80+
81+
float const pointDiameter = connectionStyle.pointDiameter();
82+
83+
QMargins margins(pointDiameter,
84+
pointDiameter,
85+
pointDiameter,
86+
pointDiameter);
8387

8488
return basicRect.united(c1c2Rect).marginsAdded(margins);
8589
}

0 commit comments

Comments
 (0)