tools/templates/pixlabel.cpp
author belphegorr <szabibibi@gmail.com>
Mon, 23 Jul 2012 19:15:59 +0300
changeset 7263 644eabbc9218
parent 361 c3eebac100c0
child 8442 535a00ca0d35
permissions -rw-r--r--
Added a new function: AddNewEvent, which only adds an event to the list if it doesn't already exist. Kept the old one as it might me useful to be able to add an event more than once.
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
}