Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit df452c2

Browse files
committed
Connection colors
1 parent 4dc58a5 commit df452c2

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

src/duqf-nodeview/duqfconnection.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ void DuQFConnection::init(DuQFSlot *output, DuQFSlot *input, DuQFConnector *conn
114114
setInput(m_input);
115115
setOutput(m_output);
116116

117+
connector->setFromColor(output->color());
118+
connector->setToColor(input->color());
119+
117120
connect(connector, &DuQFConnector::removed, this, &DuQFConnection::remove);
118121
}
119122

src/duqf-nodeview/duqfconnector.cpp

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ DuQFConnector::DuQFConnector(QString title, QGraphicsItem *parent):
1515
setFlags(ItemIsSelectable);
1616

1717
m_titleItem->setPlainText(title);
18+
19+
m_toColor = DuUI::getColor("light-grey");
20+
m_fromColor = DuUI::getColor("light-grey");
1821
}
1922

2023
DuQFConnector::DuQFConnector(QPointF from, QString title)
@@ -113,19 +116,40 @@ void DuQFConnector::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
113116

114117
painter->save();
115118

116-
CurveHandles handles = curveHandles();
119+
QPainterPath path;
117120

118121
// Create path
119-
QPainterPath path( QPointF( m_from.x(), m_from.y() ) );
120-
path.cubicTo( handles.from, handles.to, m_to);
122+
if (DuSettingsManager::instance()->nodesViewCurvature() < 1) {
123+
CurveHandles handles = curveHandles();
124+
path = QPainterPath(( QPointF( m_from.x(), m_from.y() ) ));
125+
path.cubicTo( handles.from, handles.to, m_to);
126+
}
127+
else {
128+
QPolygonF poly;
129+
poly.append(m_from);
130+
poly.append(QPointF((m_from.x() + m_to.x()) / 2, m_from.y()));
131+
poly.append(QPointF((m_from.x() + m_to.x()) / 2, m_to.y()));
132+
poly.append(m_to);
133+
path.addPolygon(poly);
134+
}
135+
121136

122137
// And draw
123138
painter->setBrush(QBrush(Qt::transparent));
124-
QPen pen;
125-
if (isSelected()) pen.setColor( DuUI::getColor("light-grey") );
126-
else pen.setColor( DuUI::getColor("less-light-grey") );
127-
pen.setWidth( m_width );
128-
pen.setCapStyle(Qt::RoundCap);
139+
140+
QLinearGradient gradient(m_from, m_to);
141+
142+
if (isSelected()) {
143+
gradient.setColorAt(0.0, m_fromColor);
144+
gradient.setColorAt(0.5, DuUI::getColor("light-grey"));
145+
gradient.setColorAt(1.0, m_toColor);
146+
}
147+
else {
148+
gradient.setColorAt(0.0, m_fromColor.darker());
149+
gradient.setColorAt(0.5, DuUI::getColor("less-light-grey"));
150+
gradient.setColorAt(1.0, m_toColor.darker());
151+
}
152+
QPen pen(gradient, m_width, Qt::SolidLine, Qt::RoundCap);
129153
painter->setPen(pen);
130154

131155
painter->drawPath(path);
@@ -235,6 +259,16 @@ void DuQFConnector::updateTitlePos()
235259
// boundingRect().height() / 2 - m_titleItem->boundingRect().height() / 2 + pos().y());
236260
}
237261

262+
void DuQFConnector::setToColor(const QColor &newToColor)
263+
{
264+
m_toColor = newToColor;
265+
}
266+
267+
void DuQFConnector::setFromColor(const QColor &newFromColor)
268+
{
269+
m_fromColor = newFromColor;
270+
}
271+
238272
CurveHandles DuQFConnector::curveHandles(float q) const
239273
{
240274
// Get handle coordinates

src/duqf-nodeview/duqfconnector.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class DuQFConnector : public QGraphicsObject
2626
QString title() const;
2727
void setTitle(const QString &title);
2828

29+
void setFromColor(const QColor &newFromColor);
30+
31+
void setToColor(const QColor &newToColor);
32+
2933
public slots:
3034
void setTo(const QPointF &to);
3135
void setFrom(const QPointF &from);
@@ -50,6 +54,9 @@ public slots:
5054
QPointF m_to;
5155
qreal m_width;
5256

57+
QColor m_fromColor;
58+
QColor m_toColor;
59+
5360
// Appearance
5461
int m_cornerRadius = 5;
5562
int m_padding = 5;

src/duqf-nodeview/duqfslot.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ void DuQFSlot::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
9595
update();
9696
}
9797

98+
QColor DuQFSlot::color() const
99+
{
100+
return m_color;
101+
}
102+
98103
DuQFSlot::SlotType DuQFSlot::slotType() const
99104
{
100105
return m_slotType;

src/duqf-nodeview/duqfslot.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class DuQFSlot : public QGraphicsObject
3333
SlotType slotType() const;
3434
void setSlotType(const SlotType &slotType);
3535

36+
QColor color() const;
37+
3638
public slots:
3739
void remove();
3840

0 commit comments

Comments
 (0)