tools/templates/pixlabel.cpp
author dag10 <gottlieb.drew@gmail.com>
Wed, 16 Jan 2013 18:34:43 -0500
changeset 8393 85bd6c7b2641
parent 361 c3eebac100c0
child 8442 535a00ca0d35
permissions -rw-r--r--
Can now change theme for static and mission maps. Fixed mission map descriptions that had commas which broke them. Now, you must escape commas in map descriptions. Made bgwidget repaint on animation tick to avoid buffer-not-clearing issue with widgets that change overtop the background leaving a ghost image of the widget's previous state. Generated map is now the default map in the mapconfig widget.
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
}