tools/templates/pixlabel.cpp
author unc0rr
Tue, 23 Jan 2007 18:54:09 +0000
changeset 359 59fbfc65fbda
child 361 c3eebac100c0
permissions -rw-r--r--
- New land templates - Template editor
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
	p.setPen(QPen(Qt::white));
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    19
	p.drawRects(rects.toVector());
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    20
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    21
	if (rects.size())
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    22
	{
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    23
		p.setPen(QPen(Qt::yellow));
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    24
		p.drawRect(rects.last());
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    25
	}
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    26
}
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    27
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    28
void PixLabel::mousePressEvent(QMouseEvent * e)
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    29
{
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    30
	if (!rects.empty())
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    31
	{
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    32
		if (e->button() == Qt::LeftButton)
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    33
			rects[rects.size() - 1].moveTopLeft(QPoint(e->x(), e->y()));
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    34
		else
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    35
		if (e->button() == Qt::RightButton)
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    36
			rects[rects.size() - 1].setBottomRight(QPoint(e->x(), e->y()));
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    37
		repaint();
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    38
	}
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    39
}
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    40
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    41
void PixLabel::AddRect()
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    42
{
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    43
	rects.push_back(QRect(0, 0, 1, 1));
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    44
	repaint();
59fbfc65fbda - New land templates
unc0rr
parents:
diff changeset
    45
}