-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrectangle.cpp
More file actions
38 lines (34 loc) · 1.01 KB
/
rectangle.cpp
File metadata and controls
38 lines (34 loc) · 1.01 KB
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
#include "rectangle.h"
#include "canvas.h"
void Rectangle::draw(QPainter &painter) const
{
int x1 = m_start.x();
int y1 = m_start.y();
int x2 = m_end.x();
int y2 = m_end.y();
int left = std::min(x1, x2);
int top = std::min(y1, y2);
int right = std::max(x1, x2);
int bottom = std::max(y1, y2);
painter.drawRect(left, top, right - left, bottom - top);
}
void Rectangle::erase(QPainter &painter) const {
int x1 = m_start.x();
int y1 = m_start.y();
int x2 = m_end.x();
int y2 = m_end.y();
int left = std::min(x1, x2);
int top = std::min(y1, y2);
int right = std::max(x1, x2);
int bottom = std::max(y1, y2);
painter.setCompositionMode(QPainter::CompositionMode_Clear);
painter.setPen(QPen(QColor(Qt::transparent), m_pen_width + 2));
painter.drawRect(left, top, right - left, bottom - top);
}
QRect Rectangle::boundingRect() const {
return QRect(m_start, m_end);
}
void Rectangle::drag(const QPoint &offset) {
m_start += offset;
m_end += offset;
}