tools/drawMapTest/drawmapscene.cpp
author unc0rr
Sat, 27 Nov 2010 23:57:31 +0300
changeset 4425 2314bb0c433d
parent 4424 3225ea34e415
child 4426 969e411c72aa
permissions -rw-r--r--
Small testing app for DrawMap scene
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 <QDebug>
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
     2
#include <QGraphicsSceneMouseEvent>
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
     3
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
     4
#include "drawmapscene.h"
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
DrawMapScene::DrawMapScene(QObject *parent) :
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
     7
    QGraphicsScene(parent),
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
     8
    m_pen(Qt::black),
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
     9
    m_brush(Qt::black)
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    10
{
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    11
    setSceneRect(0, 0, 4096, 2048);
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    12
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    13
    QLinearGradient gradient(0, 0, 0, 2048);
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    14
    gradient.setColorAt(0, QColor(160, 160, 255));
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    15
    gradient.setColorAt(1, QColor(255, 255, 160));
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    16
    setBackgroundBrush(QBrush(gradient));
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    17
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    18
    m_halfWidth = 67;
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    19
}
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    20
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    21
void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    22
{
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    23
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    24
    qDebug() << "move" << mouseEvent->scenePos();
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    25
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    26
    if(mouseEvent->buttons() && Qt::LeftButton)
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    27
        drawFigure(mouseEvent->scenePos());
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    28
}
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
void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    31
{
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    32
    qDebug() << "press" << mouseEvent->scenePos();
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    33
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    34
    drawFigure(mouseEvent->scenePos());
4423
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    35
}
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    36
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    37
void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent)
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    38
{
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    39
    qDebug() << "release" << mouseEvent->scenePos();
4391526e436e Initial commit of the Draw Map Scene
unc0rr
parents:
diff changeset
    40
}
4424
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    41
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    42
void DrawMapScene::drawFigure(const QPointF & point)
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    43
{
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    44
    addEllipse(
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    45
            point.x() - m_halfWidth,
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    46
            point.y() - m_halfWidth,
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    47
            m_halfWidth * 2,
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    48
            m_halfWidth * 2,
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    49
            m_pen,
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    50
            m_brush
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    51
        );
3225ea34e415 Some basic functionality
unc0rr
parents: 4423
diff changeset
    52
}