tools/templates/pixlabel.cpp
author nemo
Mon, 18 Feb 2013 14:06:16 -0500
changeset 8516 e422cbf9aa33
parent 8442 535a00ca0d35
permissions -rw-r--r--
pretty sure esc here is just a holdover from past, and has no use in rearranged implementation.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
359
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
     1
#include <QPainter>
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
     2
#include <QPen>
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
     3
#include "pixlabel.h"
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
     4
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
     5
PixLabel::PixLabel()
8442
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
     6
        : QLabel(0)
359
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
     7
{
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
     8
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
     9
}
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    10
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    11
void PixLabel::paintEvent(QPaintEvent * event)
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    12
{
8442
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    13
    QLabel::paintEvent(event);
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    14
    QPainter p(this);
359
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    15
8442
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    16
    p.fillRect(QRect(0, 0, 1024, 512), QBrush(Qt::black));
359
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    17
8442
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    18
    if (rects.size())
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    19
    {
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    20
        p.setPen(QPen(Qt::lightGray));
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    21
        QVector<QPoint> centers;
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    22
        for(QList<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it)
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    23
            centers.push_back((*it).center());
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    24
        p.drawPolyline(QPolygon(centers));
361
c3eebac100c0 - Show sample line
unc0rr
parents: 359
diff changeset
    25
8442
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    26
        p.setPen(QPen(Qt::white));
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    27
        p.drawRects(rects.toVector());
361
c3eebac100c0 - Show sample line
unc0rr
parents: 359
diff changeset
    28
8442
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    29
        p.setPen(QPen(Qt::yellow));
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    30
        p.drawRect(rects.last());
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    31
    }
359
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    32
}
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    33
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    34
void PixLabel::mousePressEvent(QMouseEvent * e)
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    35
{
8442
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    36
    if (!rects.empty())
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    37
    {
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    38
        if (e->button() == Qt::LeftButton)
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    39
            rects[rects.size() - 1].moveTopLeft(QPoint(e->x(), e->y()));
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    40
        else
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    41
        if (e->button() == Qt::RightButton)
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    42
            rects[rects.size() - 1].setBottomRight(QPoint(e->x(), e->y()));
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    43
        repaint();
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    44
    }
359
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    45
}
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    46
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    47
void PixLabel::AddRect()
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    48
{
8442
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    49
    rects.push_back(QRect(0, 0, 1, 1));
535a00ca0d35 whitespaces and tabs again
koda
parents: 361
diff changeset
    50
    repaint();
359
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    51
}