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