359
|
1 |
#include <QPainter>
|
|
2 |
#include <QPen>
|
|
3 |
#include "pixlabel.h"
|
|
4 |
|
|
5 |
PixLabel::PixLabel()
|
8442
|
6 |
: QLabel(0)
|
359
|
7 |
{
|
|
8 |
|
|
9 |
}
|
|
10 |
|
|
11 |
void PixLabel::paintEvent(QPaintEvent * event)
|
|
12 |
{
|
8442
|
13 |
QLabel::paintEvent(event);
|
|
14 |
QPainter p(this);
|
359
|
15 |
|
8442
|
16 |
p.fillRect(QRect(0, 0, 1024, 512), QBrush(Qt::black));
|
359
|
17 |
|
8442
|
18 |
if (rects.size())
|
|
19 |
{
|
|
20 |
p.setPen(QPen(Qt::lightGray));
|
|
21 |
QVector<QPoint> centers;
|
|
22 |
for(QList<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it)
|
|
23 |
centers.push_back((*it).center());
|
|
24 |
p.drawPolyline(QPolygon(centers));
|
361
|
25 |
|
8442
|
26 |
p.setPen(QPen(Qt::white));
|
|
27 |
p.drawRects(rects.toVector());
|
361
|
28 |
|
8442
|
29 |
p.setPen(QPen(Qt::yellow));
|
|
30 |
p.drawRect(rects.last());
|
|
31 |
}
|
359
|
32 |
}
|
|
33 |
|
|
34 |
void PixLabel::mousePressEvent(QMouseEvent * e)
|
|
35 |
{
|
8442
|
36 |
if (!rects.empty())
|
|
37 |
{
|
|
38 |
if (e->button() == Qt::LeftButton)
|
|
39 |
rects[rects.size() - 1].moveTopLeft(QPoint(e->x(), e->y()));
|
|
40 |
else
|
|
41 |
if (e->button() == Qt::RightButton)
|
|
42 |
rects[rects.size() - 1].setBottomRight(QPoint(e->x(), e->y()));
|
|
43 |
repaint();
|
|
44 |
}
|
359
|
45 |
}
|
|
46 |
|
|
47 |
void PixLabel::AddRect()
|
|
48 |
{
|
8442
|
49 |
rects.push_back(QRect(0, 0, 1, 1));
|
|
50 |
repaint();
|
359
|
51 |
}
|