forked from kenygia/MooseEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RelativePositionLayout.cpp
86 lines (78 loc) · 1.85 KB
/
RelativePositionLayout.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
75
76
77
78
79
80
81
82
83
84
85
86
#include "RelativePositionLayout.h"
#include <iostream>
RelativePositionLayout::~RelativePositionLayout()
{
QLayoutItem *item;
while ((item = takeAt(0)))
delete item;
}
void RelativePositionLayout::addItem(QLayoutItem *item)
{
t_itemData itemData;
itemData.x = item->geometry().x();
itemData.y = item->geometry().y();
itemData.w = item->geometry().width();
itemData.h = item->geometry().height();
itemData.item = item;
list.push_back(itemData);
}
QSize RelativePositionLayout::sizeHint() const
{
QSize s(0,0);
int n = list.count();
if (n > 0)
s = QSize(100,70);
int i = 0;
while (i < n) {
QLayoutItem *o = list.at(i).item;
s = s.expandedTo(o->sizeHint());
++i;
}
return s + n*QSize(spacing(), spacing());
}
QSize RelativePositionLayout::minimumSize() const
{
QSize s(0,0);
int n = list.count();
int i = 0;
while (i < n) {
QLayoutItem *o = list.at(i).item;
s = s.expandedTo(o->minimumSize());
++i;
}
return s + n*QSize(spacing(), spacing());
}
int RelativePositionLayout::count() const
{
return list.size();
}
QLayoutItem *RelativePositionLayout::itemAt(int index) const
{
if (index < list.size()) {
return list[index].item;
}
return 0;
}
QLayoutItem *RelativePositionLayout::takeAt(int index)
{
if (index < list.size()) {
QLayoutItem *item = list[index].item;
list.erase(list.begin() + index);
return item;
}
return 0;
}
void RelativePositionLayout::setGeometry(const QRect &rect)
{
float wIncrease = (float)rect.width() / originalW;
float hIncrease = (float)rect.height() / originalH;
for (int i=0; i<list.size(); ++i) {
QLayoutItem *item = list[i].item;
int x = list[i].x * wIncrease;
int y = list[i].y * hIncrease;
int w = list[i].w * wIncrease;
int h = list[i].h * hIncrease;
QRect newGeom(x, y, w, h);
item->setGeometry(newGeom);
}
}