summaryrefslogtreecommitdiff
path: root/src/data/nodestyle.cpp
blob: 302ab84d792af1fa91f1a5d427b58fc08163bb7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "nodestyle.h"
#include <QPainter>

NodeStyle *noneStyle = new NodeStyle();

NodeStyle::NodeStyle() : _name("none"), _data(0)
{
}


NodeStyle::NodeStyle(QString name, GraphElementData *data): _name(name), _data(data)
{
}

bool NodeStyle::isNone() { return _data == 0; }

GraphElementData *NodeStyle::data() const
{
    return _data;
}

QString NodeStyle::name() const
{
    return _name;
}

NodeStyle::Shape NodeStyle::shape() const
{
    QString sh = _data->property("shape");
    if (sh.isNull()) return NodeStyle::Circle;
    else if (sh == "circle") return NodeStyle::Circle;
    else if (sh == "rectangle") return NodeStyle::Rectangle;
    else return NodeStyle::Circle;
}

QColor NodeStyle::fillColor() const
{
    QString col = _data->property("fill");

    if (col.isNull()) {
        return QColor(Qt::white);
    } else {
        QColor namedColor(col);
        if (namedColor.isValid()) {
            return namedColor;
        } else {
            // TODO: read RGB colors
            return QColor(Qt::white);
        }
    }
}

QColor NodeStyle::strokeColor() const
{
    QString col = _data->property("draw");

    if (col.isNull()) {
        return QColor(Qt::black);
    } else {
        QColor namedColor(col);
        if (namedColor.isValid()) {
            return namedColor;
        } else {
            // TODO: read RGB colors
            return QColor(Qt::white);
        }
    }
}

int NodeStyle::strokeThickness() const
{
    return 1;
}

QPen NodeStyle::pen() const
{
    QPen p(strokeColor());
    p.setWidthF((float)strokeThickness() * 3.0f);
    return p;
}

QBrush NodeStyle::brush() const
{
    return QBrush(fillColor());
}

QPainterPath NodeStyle::path() const
{
    QPainterPath pth;
    pth.addEllipse(QPointF(0.0f,0.0f), 30.0f, 30.0f);
    return pth;
}

QPainterPath NodeStyle::palettePath() const
{
    return path();
}

QIcon NodeStyle::icon() const
{
    // draw an icon matching the style
    QPixmap px(100,100);
    px.fill(Qt::transparent);
    QPainter painter(&px);
    QPainterPath pth = path();
    painter.setPen(pen());
    painter.setBrush(brush());

    pth.translate(50.0f, 50.0f);
    painter.drawPath(pth);
    return QIcon(px);
}