-
Notifications
You must be signed in to change notification settings - Fork 0
/
centerfloatlayout.cpp
67 lines (57 loc) · 1.48 KB
/
centerfloatlayout.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
#include "centerfloatlayout.h"
CenterFloatLayout::CenterFloatLayout(QWidget *parent)
: QLayout(parent)
{
}
CenterFloatLayout::~CenterFloatLayout()
{
QLayoutItem* item;
while( (item = takeAt(0)) )
delete item;
}
void CenterFloatLayout::addItem(QLayoutItem* item)
{
items.append(item);
}
int CenterFloatLayout::count() const
{
return items.count();
}
QSize CenterFloatLayout::sizeHint() const
{
QSize size;
for( auto i=items.begin(); i!=items.end(); ++i ){
QLayoutItem* item = *i;
size = size.expandedTo(item->sizeHint());
}
return size;
}
QSize CenterFloatLayout::minimumSize() const
{
QSize size;
for( auto i=items.begin(); i!=items.end(); ++i ){
QLayoutItem* item = *i;
size = size.expandedTo(item->minimumSize());
}
return size;
}
QLayoutItem* CenterFloatLayout::itemAt(int index) const
{
return (index > 0 && index < items.size()) ? items.at(index) : nullptr;
}
QLayoutItem* CenterFloatLayout::takeAt(int index)
{
return (index > 0 && index < items.size()) ? items.takeAt(index) : nullptr;
}
void CenterFloatLayout::setGeometry(const QRect& rect)
{
QLayout::setGeometry(rect);
int size = qMin(rect.width() - contentsMargins().left() - contentsMargins().right(),
rect.height() - contentsMargins().top() - contentsMargins().bottom());
QSize corner((rect.width()-size)/2, (rect.height()-size)/2);
for( auto i=items.begin(); i!=items.end(); ++i )
{
QLayoutItem* item = *i;
item->setGeometry( QRect(rect.x()+corner.width(), rect.y()+corner.height(), size, size) );
}
}