tools/templates/pixlabel.cpp
author unc0rr
Sat, 18 Dec 2010 21:17:37 +0300
changeset 4558 8fb24f377974
parent 361 c3eebac100c0
child 8442 535a00ca0d35
permissions -rw-r--r--
merge
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()
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
     6
		: QLabel(0)
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
{
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    13
	QLabel::paintEvent(event);
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    14
	QPainter p(this);
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    15
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    16
	p.fillRect(QRect(0, 0, 1024, 512), QBrush(Qt::black));
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    17
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    18
	if (rects.size())
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    19
	{
361
c3eebac100c0 - Show sample line
unc0rr
parents: 359
diff changeset
    20
		p.setPen(QPen(Qt::lightGray));
c3eebac100c0 - Show sample line
unc0rr
parents: 359
diff changeset
    21
		QVector<QPoint> centers;
c3eebac100c0 - Show sample line
unc0rr
parents: 359
diff changeset
    22
		for(QList<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it)
c3eebac100c0 - Show sample line
unc0rr
parents: 359
diff changeset
    23
			centers.push_back((*it).center());
c3eebac100c0 - Show sample line
unc0rr
parents: 359
diff changeset
    24
		p.drawPolyline(QPolygon(centers));
c3eebac100c0 - Show sample line
unc0rr
parents: 359
diff changeset
    25
c3eebac100c0 - Show sample line
unc0rr
parents: 359
diff changeset
    26
		p.setPen(QPen(Qt::white));
c3eebac100c0 - Show sample line
unc0rr
parents: 359
diff changeset
    27
		p.drawRects(rects.toVector());
c3eebac100c0 - Show sample line
unc0rr
parents: 359
diff changeset
    28
359
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    29
		p.setPen(QPen(Qt::yellow));
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    30
		p.drawRect(rects.last());
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    31
	}
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
{
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    36
	if (!rects.empty())
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    37
	{
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    38
		if (e->button() == Qt::LeftButton)
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    39
			rects[rects.size() - 1].moveTopLeft(QPoint(e->x(), e->y()));
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    40
		else
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    41
		if (e->button() == Qt::RightButton)
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    42
			rects[rects.size() - 1].setBottomRight(QPoint(e->x(), e->y()));
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    43
		repaint();
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    44
	}
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
{
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    49
	rects.push_back(QRect(0, 0, 1, 1));
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    50
	repaint();
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    51
}