QTfrontend/drawmapscene.cpp
author unc0rr
Sun, 27 Feb 2011 21:06:28 +0300
changeset 4968 8e1673f0dc05
parent 4938 0985edac2ad7
child 4976 088d40d8aba2
permissions -rw-r--r--
Read server config from file
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
     1
#include <QGraphicsSceneMouseEvent>
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
     2
#include <QGraphicsPathItem>
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
     3
#include <QtEndian>
4937
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
     4
#include <QDebug>
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
     5
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
     6
#include "drawmapscene.h"
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
     7
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
     8
template <class T> T sqr(const T & x)
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
     9
{
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    10
    return x*x;
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    11
}
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    12
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    13
DrawMapScene::DrawMapScene(QObject *parent) :
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    14
    QGraphicsScene(parent),
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    15
    m_pen(Qt::yellow),
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    16
    m_brush(Qt::yellow)
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    17
{
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    18
    setSceneRect(0, 0, 4096, 2048);
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    19
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    20
    QLinearGradient gradient(0, 0, 0, 2048);
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    21
    gradient.setColorAt(0, QColor(60, 60, 155));
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    22
    gradient.setColorAt(1, QColor(155, 155, 60));
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    23
    setBackgroundBrush(QBrush(gradient));
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    24
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    25
    m_pen.setWidth(67);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    26
    m_pen.setJoinStyle(Qt::RoundJoin);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    27
    m_pen.setCapStyle(Qt::RoundCap);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    28
    m_currPath = 0;
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    29
}
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    30
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    31
void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    32
{
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    33
    if(m_currPath && (mouseEvent->buttons() & Qt::LeftButton))
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    34
    {
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    35
        QPainterPath path = m_currPath->path();
4937
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    36
4938
0985edac2ad7 use ctrl instead of alt to avoid colliding with linux window positioning
nemo
parents: 4937
diff changeset
    37
        if(mouseEvent->modifiers() & Qt::ControlModifier)
4937
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    38
        {
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    39
            int c = path.elementCount();
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    40
            QPointF pos = mouseEvent->scenePos();
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    41
            path.setElementPositionAt(c - 1, pos.x(), pos.y());
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    42
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    43
        } else
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    44
        {
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    45
            path.lineTo(mouseEvent->scenePos());
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    46
            paths.first().append(mouseEvent->scenePos().toPoint());
55b9145fea94 Draw straight lines while holding Alt key
unc0rr
parents: 4666
diff changeset
    47
        }
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    48
        m_currPath->setPath(path);
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    49
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    50
        emit pathChanged();
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    51
    }
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    52
}
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    53
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    54
void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    55
{
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    56
    m_currPath = addPath(QPainterPath(), m_pen);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    57
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    58
    QPainterPath path = m_currPath->path();
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    59
    QPointF p = mouseEvent->scenePos();
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    60
    p += QPointF(0.01, 0.01);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    61
    path.moveTo(p);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    62
    path.lineTo(mouseEvent->scenePos());
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
    63
    paths.prepend(QList<QPoint>() << mouseEvent->scenePos().toPoint());
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    64
    m_currPath->setPath(path);
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    65
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    66
    emit pathChanged();
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    67
}
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    68
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    69
void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent)
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    70
{
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
    71
    Q_UNUSED(mouseEvent);
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
    72
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
    73
    simplifyLast();
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
    74
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    75
    m_currPath = 0;
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    76
}
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    77
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    78
void DrawMapScene::undo()
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    79
{
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    80
    if(items().size())
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    81
    {
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4424
diff changeset
    82
        removeItem(items().first());
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
    83
        paths.removeFirst();
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    84
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    85
        emit pathChanged();
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    86
    }
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    87
}
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    88
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
    89
void DrawMapScene::clearMap()
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
    90
{
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
    91
    clear();
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
    92
    paths.clear();
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
    93
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
    94
    emit pathChanged();
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
    95
}
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
    96
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    97
QByteArray DrawMapScene::encode()
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    98
{
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    99
    QByteArray b;
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   100
4666
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   101
    for(int i = paths.size() - 1; i >= 0; --i)
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   102
    {
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   103
        int cnt = 0;
4666
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   104
        QList<QPoint> points = paths.at(i);
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   105
        foreach(QPoint point, points)
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   106
        {
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   107
            qint16 px = qToBigEndian((qint16)point.x());
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   108
            qint16 py = qToBigEndian((qint16)point.y());
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   109
            quint8 flags = 2;
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   110
            if(!cnt) flags |= 0x80;
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   111
            b.append((const char *)&px, 2);
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   112
            b.append((const char *)&py, 2);
4457
ffb766e85150 - Change painted map file format
unc0rr
parents: 4442
diff changeset
   113
            b.append((const char *)&flags, 1);
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   114
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   115
            ++cnt;
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   116
        }
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   117
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   118
    }
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   119
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   120
    return b;
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
   121
}
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   122
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   123
void DrawMapScene::decode(QByteArray data)
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   124
{
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   125
    clear();
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   126
    paths.clear();
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   127
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   128
    QList<QPoint> points;
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   129
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   130
    while(data.size() >= 5)
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   131
    {
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   132
        qint16 px = qFromBigEndian(*(qint16 *)data.data());
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   133
        data.remove(0, 2);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   134
        qint16 py = qFromBigEndian(*(qint16 *)data.data());
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   135
        data.remove(0, 2);
4457
ffb766e85150 - Change painted map file format
unc0rr
parents: 4442
diff changeset
   136
        quint8 flags = *(quint8 *)data.data();
ffb766e85150 - Change painted map file format
unc0rr
parents: 4442
diff changeset
   137
        data.remove(0, 1);
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   138
4666
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   139
        if((flags & 0x80) && points.size())
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   140
        {
4666
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   141
            addPath(pointsToPath(points), m_pen);
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   142
            paths.prepend(points);
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   143
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   144
            points.clear();
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   145
        }
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   146
4666
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   147
        points.append(QPoint(px, py));
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   148
    }
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   149
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   150
    if(points.size())
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   151
    {
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   152
        addPath(pointsToPath(points), m_pen);
34551d8639cf - Fix encoding function to iterate reversed list
unc0rr
parents: 4658
diff changeset
   153
        paths.prepend(points);
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   154
    }
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   155
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   156
    emit pathChanged();
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   157
}
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   158
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   159
void DrawMapScene::simplifyLast()
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   160
{
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   161
    if(!paths.size()) return;
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   162
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4520
diff changeset
   163
    QList<QPoint> points = paths.at(0);
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   164
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   165
    QPoint prevPoint = points.first();
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   166
    int i = 1;
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   167
    while(i < points.size())
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   168
    {
4471
220d44cb8659 Always keep last point of drawn polyline
unc0rr
parents: 4457
diff changeset
   169
        if( (i != points.size() - 1)
220d44cb8659 Always keep last point of drawn polyline
unc0rr
parents: 4457
diff changeset
   170
            && (sqr(prevPoint.x() - points[i].x()) + sqr(prevPoint.y() - points[i].y()) < 1000)
220d44cb8659 Always keep last point of drawn polyline
unc0rr
parents: 4457
diff changeset
   171
          )
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   172
            points.removeAt(i);
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   173
        else
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   174
        {
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   175
            prevPoint = points[i];
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   176
            ++i;
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   177
        }
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   178
    }
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   179
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   180
    paths[0] = points;
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   181
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   182
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   183
    // redraw path
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   184
    {
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
   185
        QGraphicsPathItem * pathItem = static_cast<QGraphicsPathItem *>(items()[0]);
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   186
        pathItem->setPath(pointsToPath(paths[0]));
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   187
    }
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   188
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   189
    emit pathChanged();
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
   190
}
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   191
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   192
QPainterPath DrawMapScene::pointsToPath(const QList<QPoint> points)
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   193
{
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   194
    QPainterPath path;
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   195
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   196
    if(points.size())
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   197
    {
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   198
        QPointF p = points[0] + QPointF(0.01, 0.01);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   199
        path.moveTo(p);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   200
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   201
        foreach(QPoint p, points)
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   202
            path.lineTo(p);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   203
    }
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   204
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   205
    return path;
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
   206
}