22 #include <QGraphicsWidget>
28 class FullBorderLayout::Private {
45 QMap < FullBorderLayout::Place, QGraphicsLayoutItem * > itemPositions;
46 QMap < FullBorderLayout::Border, qreal > sizes;
48 void calculateBorderSizes(qreal & top, qreal & bottom, qreal & left, qreal & right)
55 top = qMax(top, itemPositions[FullBorderLayout::TopLeft]->preferredSize().height());
58 top = qMax(top, itemPositions[FullBorderLayout::Top]->preferredSize().height());
61 top = qMax(top, itemPositions[FullBorderLayout::TopRight]->preferredSize().height());
70 bottom = qMax(bottom, itemPositions[FullBorderLayout::BottomLeft]->preferredSize().height());
73 bottom = qMax(bottom, itemPositions[FullBorderLayout::Bottom]->preferredSize().height());
76 bottom = qMax(bottom, itemPositions[FullBorderLayout::BottomRight]->preferredSize().height());
84 if (itemPositions[FullBorderLayout::TopLeft]) {
85 left = qMax(left, itemPositions[FullBorderLayout::TopLeft]->preferredSize().width());
88 left = qMax(left, itemPositions[FullBorderLayout::Left]->preferredSize().width());
90 if (itemPositions[FullBorderLayout::BottomLeft]) {
91 left = qMax(left, itemPositions[FullBorderLayout::BottomLeft]->preferredSize().width());
99 if (itemPositions[FullBorderLayout::TopRight]) {
100 right = qMax(right, itemPositions[FullBorderLayout::TopRight]->preferredSize().width());
103 right = qMax(right, itemPositions[FullBorderLayout::Right]->preferredSize().width());
105 if (itemPositions[FullBorderLayout::BottomRight]) {
106 right = qMax(right, itemPositions[FullBorderLayout::BottomRight]->preferredSize().width());
124 QGraphicsLayout::setGeometry(rect);
126 QRectF effectiveRect = geometry();
127 qreal left = 0, top = 0, right = 0, bottom = 0;
128 getContentsMargins(&left, &top, &right, &bottom);
129 effectiveRect.adjust(+left, +top, -right, -bottom);
131 qreal topBorder, bottomBorder, leftBorder, rightBorder;
132 d->calculateBorderSizes(topBorder, bottomBorder, leftBorder, rightBorder);
136 itemRect = effectiveRect;
137 itemRect.setSize(QSizeF(leftBorder, topBorder));
139 if (d->itemPositions[
TopLeft]) {
140 d->itemPositions[
TopLeft]->setGeometry(itemRect);
143 itemRect.setLeft(effectiveRect.left() + leftBorder);
144 itemRect.setWidth(effectiveRect.width() - leftBorder - rightBorder);
146 if (d->itemPositions[
Top]) {
147 d->itemPositions[
Top]->setGeometry(itemRect);
150 itemRect.setWidth(rightBorder);
151 itemRect.moveRight(effectiveRect.right());
154 d->itemPositions[
TopRight]->setGeometry(itemRect);
157 itemRect.setTop(effectiveRect.top() + topBorder);
158 itemRect.setHeight(effectiveRect.height() - topBorder - bottomBorder);
160 if (d->itemPositions[
Right]) {
161 d->itemPositions[
Right]->setGeometry(itemRect);
164 itemRect.setHeight(bottomBorder);
165 itemRect.moveBottom(effectiveRect.bottom());
168 d->itemPositions[
BottomRight]->setGeometry(itemRect);
171 itemRect.setLeft(effectiveRect.left() + leftBorder);
172 itemRect.setWidth(effectiveRect.width() - leftBorder - rightBorder);
174 if (d->itemPositions[
Bottom]) {
175 d->itemPositions[
Bottom]->setGeometry(itemRect);
178 itemRect.setLeft(effectiveRect.left());
179 itemRect.setWidth(leftBorder);
182 d->itemPositions[
BottomLeft]->setGeometry(itemRect);
185 itemRect.setTop(effectiveRect.top() + topBorder);
186 itemRect.setHeight(effectiveRect.height() - topBorder - bottomBorder);
188 if (d->itemPositions[
Left]) {
189 d->itemPositions[
Left]->setGeometry(itemRect);
192 itemRect = effectiveRect;
194 leftBorder, topBorder,
195 - rightBorder, - bottomBorder
198 if (d->itemPositions[
Center]) {
199 d->itemPositions[
Center]->setGeometry(itemRect);
204 const QSizeF & constraint)
const
206 if (which == Qt::MaximumSize) {
210 qreal topMargin, bottomMargin, leftMargin, rightMargin;
211 d->calculateBorderSizes(topMargin, bottomMargin, leftMargin, rightMargin);
213 qreal hintHeight = topMargin + bottomMargin;
214 qreal hintWidth = leftMargin + rightMargin;
216 if (d->itemPositions[
Center]) {
217 hintHeight += d->itemPositions[
Center]
218 ->effectiveSizeHint(which, constraint).height();
219 hintWidth += d->itemPositions[
Center]
220 ->effectiveSizeHint(which, constraint).width();
223 QSizeF result = QSizeF(hintWidth, hintHeight);
224 if (constraint.isValid()) {
225 result = result.boundedTo(constraint);
237 d->itemPositions[position] = item;
244 foreach (QGraphicsLayoutItem * i, d->itemPositions) {
255 foreach (QGraphicsLayoutItem * i, d->itemPositions) {
257 if (index == count) {
268 d->sizes[border] =
size;
274 d->sizes[border] = -1;
280 return d->sizes[border];
285 QMutableMapIterator < Place, QGraphicsLayoutItem * > i(d->itemPositions);
287 while (i.hasNext()) {
290 if (index == count++) {
void addItem(QGraphicsLayoutItem *item)
Adds item in the center.
L_Override QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
L_Override void removeAt(int index)
L_Override void setGeometry(const QRectF &rect)
virtual ~FullBorderLayout()
Destroys this Lancelot::FullBorderLayout.
void setSize(qreal size, Border border)
Deactivates the automatic sizing of a border widget, and sets it to the specified size...
Place
Positions supported by FullBorderLayout.
L_Override int count() const
qreal size(Border border) const
Returns the size of the specified border widget.
L_Override QGraphicsLayoutItem * itemAt(int i) const
FullBorderLayout(QGraphicsLayoutItem *parent=0)
Creates a new Lancelot::FullBorderLayout.
void setAutoSize(Border border)
Activates the automatic sizing of a border widget, according to it's sizeHint()