-
Notifications
You must be signed in to change notification settings - Fork 2
/
drawableelem.cpp
37 lines (31 loc) · 940 Bytes
/
drawableelem.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
#include "drawableelem.h"
#include <QDebug>
DrawableElem::DrawableElem(int x, int y, Background* parent) : Drawable(parent), pos_x(x), pos_y(y)
{
parent->subscribe(this);
}
void DrawableElem::resized(double fx, double fy)
{
QRect geom;
// redimensionnement sans marge
geom.setTop(pos_y*sizeHint().height()*fy);
geom.setLeft(pos_x*sizeHint().width()*fx);
geom.setWidth(sizeHint().width()*fx);
geom.setHeight(sizeHint().height()*fy);
correct_margins(geom);
this->setGeometry(geom);
}
void DrawableElem::correct_margins(QRect& geom)
{
// ajout de marges pour respecter l'aspect ratio
if (geom.width() > geom.height())
{
geom.setLeft(geom.left()+(geom.width()-geom.height())/2);
geom.setWidth(geom.height());
}
else if (geom.height() > geom.width())
{
geom.setTop(geom.top()+(geom.height()-geom.width())/2);
geom.setHeight(geom.width());
}
}