Newer
Older
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "rectangle.h"
#include <iostream>
#include <ostream>
Rectangle::Rectangle(){
width = getStopPoint().x() - getStartPoint().x() ;
height = getStopPoint().y() - getStartPoint().y() ;
}
Rectangle::Rectangle(const Rectangle &graph)
{
}
Rectangle::~Rectangle(){
}
void Rectangle::draw(QPainter &painter){
// change later if i will work with new
width = getStopPoint().x() - getStartPoint().x() ;
height = getStopPoint().y() - getStartPoint().y() ;
// Set brush color using hexadecimal value
setBrushForTheObject(painter);
painter.drawRect(getStartPoint().x(),getStartPoint().y(), width, height);
}
void Rectangle::move(QPoint vector){
setStartPoint(getStartPoint() + vector);
setStopPoint(getStopPoint() + vector);
}
bool Rectangle::checkTheSelectedShape(QPoint p){
// swap start- and stop point if stop grather than start point
// swap start- and stop point if stop grather than start point
if(getStartPoint().y() < getStopPoint().y()){
QPoint y;
y = getStopPoint();
setStopPoint(getStartPoint());
setStartPoint(y);
}
float steigung = (float)(getStartPoint().y() - getStopPoint().y())/(getStartPoint().x() - getStopPoint().x());
// wenn Y nicht stimmt
if(!(p.y() <= getStartPoint().y() && p.y() >= getStopPoint().y())) return false;
// jenach Start- StopPunkt wird X anders geprüft mit Hilfe der Steigung der Diagonale
if (steigung<0)
return( p.x() >= getStartPoint().x() && p.x() <= getStopPoint().x() );
else
return(p.x() <= getStartPoint().x() &&p.x() >= getStopPoint().x() );
// wenn Y nicht stimmt
if(!(p.y() <= getStartPoint().y() && p.y() >= getStopPoint().y())) return false;
// jenach Start- StopPunkt wird X anders geprüft mit Hilfe der Steigung der Diagonale
if (steigung<0)
return( p.x() >= getStartPoint().x() && p.x() <= getStopPoint().x() );
else
return(p.x() <= getStartPoint().x() &&p.x() >= getStopPoint().x() );
}
int Rectangle::getWidth() const
{
return width;
}
void Rectangle::setWidth(int newWidth)
{
width = newWidth;
}
int Rectangle::getHeight() const
{
return height;
}
void Rectangle::setHeight(int newHeight)
{
height = newHeight;
}