tools/templates/pixlabel.cpp
author nemo
Mon, 06 Feb 2012 20:04:32 -0500
changeset 6645 9ff40cf44827
parent 361 c3eebac100c0
child 8442 535a00ca0d35
permissions -rw-r--r--
Fixes slot sprite and ammo sprites overlapping left side border. There is still the issue that boxes should be 32px between borders, but right now they are 33px on all but the first row (since the outside border overlaps it by 1px) causing the slot sprite to have 2px of border on the left and 1px of border on the right.
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
}