-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrectangle.cpp
51 lines (42 loc) · 1.25 KB
/
rectangle.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
#include "rectangle.h"
Rectangle::Rectangle(int x, int y, int width, int height, QPen& pen, QBrush& brush)
{
this->_x = x;
this->_y = y;
this->_width = width;
this->_height = height;
this->_pen = pen;
this->_brush = brush;
this->_rotation = 0;
}
Rectangle::Rectangle(int x, int y, int width, int height, Qt::PenStyle penColor, Qt::BrushStyle brushColor)
{
this->_x = x;
this->_y = y;
this->_width = width;
this->_height = height;
this->_pen = QPen(penColor);
this->_brush = QBrush(brushColor);
this->_rotation = 0;
}
Rectangle::~Rectangle()
{
}
void Rectangle::draw(QPainter *painter)
{
QPen oldPen = painter->pen();
QBrush oldBrush = painter->brush();
painter->setPen(this->_pen);
painter->setBrush(this->_brush);
painter->translate(this->_x + this->_width / 2, this->_y + this->_height / 2);
painter->rotate(this->_rotation);
painter->drawRect(-(this->_width / 2), -(this->_height / 2), this->_width, this->_height);
painter->rotate(-this->_rotation);
painter->translate(-(this->_x + this->_width / 2), -(this->_y + this->_height / 2));
painter->setBrush(oldBrush);
painter->setPen(oldPen);
}
void Rectangle::rotate(int degrees)
{
this->_rotation += degrees;
}