-
Notifications
You must be signed in to change notification settings - Fork 4
/
selection.cpp
75 lines (55 loc) · 1.1 KB
/
selection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <QPainter>
#include "selection.h"
Selection::Selection()
{
rect_ = QRect();
}
Selection::~Selection()
{
}
void Selection::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QPen pen;
pen.setStyle(Qt::DashLine);
pen.setColor(Qt::blue);
pen.setWidth(2);
painter->setPen(pen);
painter->setBrush(Qt::NoBrush);
painter->drawRect(boundingRect());
}
QRectF Selection::boundingRect() const
{
return QRectF(rect_.x() * 10.0f, rect_.y() * 10.0f,
rect_.width() * 10.0f, rect_.height() * 10.0f);
}
void Selection::set(const QRect &rect)
{
show();
rect_ = rect;
if (!rect_.isValid())
rect_ = rect_.normalized();
resetGeometry();
}
void Selection::move(const QPoint &point)
{
rect_.moveTopLeft(point);
resetGeometry();
}
void Selection::clear()
{
hide();
rect_ = QRect();
resetGeometry();
}
bool Selection::within(const QPoint &point) const
{
return rect_.contains(point);
}
void Selection::resetGeometry()
{
prepareGeometryChange();
}