introduce per-side margins to layouts. you can still just call setMargin(qreal) if you wish, but now this is much more useful for, say, panels.
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=738526
This commit is contained in:
parent
fbf2505f8a
commit
0006ce0ec4
|
@ -84,8 +84,8 @@ void BorderLayout::setGeometry(const QRectF& geometry)
|
||||||
void BorderLayout::invalidate()
|
void BorderLayout::invalidate()
|
||||||
{
|
{
|
||||||
QRectF geometry = d->geometry;
|
QRectF geometry = d->geometry;
|
||||||
geometry.setTopLeft(geometry.topLeft() + QPointF(margin(), margin()));
|
geometry.setTopLeft(geometry.topLeft() + QPointF(margin(LeftMargin), margin(TopMargin)));
|
||||||
geometry.setBottomRight(geometry.bottomRight() - QPointF(margin(), margin()));
|
geometry.setBottomRight(geometry.bottomRight() - QPointF(margin(RightMargin), margin(BottomMargin)));
|
||||||
|
|
||||||
QPointF origin = geometry.topLeft();
|
QPointF origin = geometry.topLeft();
|
||||||
qreal top, bottom, left, right;
|
qreal top, bottom, left, right;
|
||||||
|
@ -157,7 +157,7 @@ QSizeF BorderLayout::sizeHint() const
|
||||||
hintWidth += d->itemPositions[CenterPositioned]->sizeHint().width();
|
hintWidth += d->itemPositions[CenterPositioned]->sizeHint().width();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QSizeF(hintWidth + 2 * margin(), hintHeight + 2 * margin());
|
return QSizeF(hintWidth + 2 + margin(LeftMargin) + margin(RightMargin), hintHeight + 2 + margin(TopMargin) + margin(BottomMargin));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BorderLayout::addItem(Plasma::LayoutItem * item)
|
void BorderLayout::addItem(Plasma::LayoutItem * item)
|
||||||
|
|
|
@ -85,12 +85,13 @@ public:
|
||||||
{
|
{
|
||||||
switch ( direction ) {
|
switch ( direction ) {
|
||||||
case LeftToRight:
|
case LeftToRight:
|
||||||
|
return q->margin(LeftMargin);
|
||||||
case TopToBottom:
|
case TopToBottom:
|
||||||
return q->margin();
|
return q->margin(TopMargin);
|
||||||
case RightToLeft:
|
case RightToLeft:
|
||||||
return geometry.width() - q->margin();
|
return geometry.width() - q->margin(RightMargin);
|
||||||
case BottomToTop:
|
case BottomToTop:
|
||||||
return geometry.height() - q->margin();
|
return geometry.height() - q->margin(BottomMargin);
|
||||||
default:
|
default:
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -155,7 +156,7 @@ public:
|
||||||
// qDebug() << "Item geometry: " << newGeometry;
|
// qDebug() << "Item geometry: " << newGeometry;
|
||||||
|
|
||||||
if ( q->animator() )
|
if ( q->animator() )
|
||||||
q->animator()->setGeometry(item,newGeometry);
|
q->animator()->setGeometry(item, newGeometry);
|
||||||
else
|
else
|
||||||
item->setGeometry(newGeometry);
|
item->setGeometry(newGeometry);
|
||||||
|
|
||||||
|
@ -216,7 +217,6 @@ public:
|
||||||
{
|
{
|
||||||
QSizeF result;
|
QSizeF result;
|
||||||
|
|
||||||
const qreal totalMargin = q->margin() * 2;
|
|
||||||
const qreal totalSpacing = q->spacing() * (children.count()-1);
|
const qreal totalSpacing = q->spacing() * (children.count()-1);
|
||||||
|
|
||||||
switch ( direction ) {
|
switch ( direction ) {
|
||||||
|
@ -225,8 +225,8 @@ public:
|
||||||
result = QSizeF(calculateSize(calculateSizeType,Qt::Horizontal,sum),
|
result = QSizeF(calculateSize(calculateSizeType,Qt::Horizontal,sum),
|
||||||
calculateSize(calculateSizeType,Qt::Vertical,qMax<qreal>));
|
calculateSize(calculateSizeType,Qt::Vertical,qMax<qreal>));
|
||||||
|
|
||||||
result.rwidth() += totalMargin + totalSpacing;
|
result.rwidth() += q->margin(LeftMargin) + q->margin(RightMargin) + totalSpacing;
|
||||||
result.rheight() += totalMargin;
|
result.rheight() += q->margin(TopMargin) + q->margin(BottomMargin);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case TopToBottom:
|
case TopToBottom:
|
||||||
|
@ -234,8 +234,8 @@ public:
|
||||||
result = QSizeF(calculateSize(calculateSizeType,Qt::Horizontal,qMax<qreal>),
|
result = QSizeF(calculateSize(calculateSizeType,Qt::Horizontal,qMax<qreal>),
|
||||||
calculateSize(calculateSizeType,Qt::Vertical,sum));
|
calculateSize(calculateSizeType,Qt::Vertical,sum));
|
||||||
|
|
||||||
result.rheight() += totalMargin + totalSpacing;
|
result.rheight() += q->margin(TopMargin) + q->margin(BottomMargin) + totalSpacing;
|
||||||
result.rwidth() += totalMargin;
|
result.rwidth() += q->margin(LeftMargin) + q->margin(RightMargin);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -353,16 +353,17 @@ LayoutItem *BoxLayout::takeAt(int i)
|
||||||
|
|
||||||
void BoxLayout::setGeometry(const QRectF& geo)
|
void BoxLayout::setGeometry(const QRectF& geo)
|
||||||
{
|
{
|
||||||
QRectF geometry = geo.adjusted(margin(),margin(),-margin(),-margin());
|
QRectF margined = geo.adjusted(margin(LeftMargin), margin(TopMargin), -margin(RightMargin), -margin(BottomMargin));
|
||||||
|
|
||||||
//qDebug() << "geo before " << geo << "after" << geometry << "margin" << margin();
|
//qDebug() << "geo before " << geo << "and with margins" << margined << "margins" << margin(LeftMargin)
|
||||||
|
// << margin(TopMargin) << -margin(RightMargin) << -margin(BottomMargin);
|
||||||
//qDebug() << "Box layout beginning with geo" << geometry;
|
//qDebug() << "Box layout beginning with geo" << geometry;
|
||||||
//qDebug() << "This box max size" << maximumSize();
|
//qDebug() << "This box max size" << maximumSize();
|
||||||
|
|
||||||
QVector<qreal> sizes(count());
|
QVector<qreal> sizes(count());
|
||||||
QVector<qreal> expansionSpace(count());
|
QVector<qreal> expansionSpace(count());
|
||||||
|
|
||||||
qreal available = d->size(geometry.size()) - spacing()*(d->children.count()-1);
|
qreal available = d->size(margined.size()) - spacing() * (d->children.count()-1);
|
||||||
qreal perItemSize = available / count();
|
qreal perItemSize = available / count();
|
||||||
|
|
||||||
// initial distribution of space to items
|
// initial distribution of space to items
|
||||||
|
@ -423,17 +424,17 @@ void BoxLayout::setGeometry(const QRectF& geo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set items' geometry according to new sizes
|
// set items' geometry according to new sizes
|
||||||
qreal pos = d->startPos(geometry);
|
qreal pos = d->startPos(geo);
|
||||||
for ( int i = 0 ; i < sizes.count() ; i++ ) {
|
for ( int i = 0 ; i < sizes.count() ; i++ ) {
|
||||||
|
|
||||||
//QObject *obj = dynamic_cast<QObject*>(d->children[i]);
|
//QObject *obj = dynamic_cast<QObject*>(d->children[i]);
|
||||||
//if ( obj )
|
//if ( obj )
|
||||||
//qDebug() << "Item " << i << obj->metaObject()->className() << "size:" << sizes[i];
|
//qDebug() << "Item " << i << obj->metaObject()->className() << "size:" << sizes[i];
|
||||||
|
|
||||||
pos = d->layoutItem( geometry , d->children[i] , pos , sizes[i] );
|
pos = d->layoutItem(margined, d->children[i], pos , sizes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
d->geometry = geometry;
|
d->geometry = geo;
|
||||||
|
|
||||||
startAnimation();
|
startAnimation();
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,9 +112,8 @@ T qSum(const QList<T>& container)
|
||||||
|
|
||||||
void FlowLayout::setGeometry(const QRectF& geo)
|
void FlowLayout::setGeometry(const QRectF& geo)
|
||||||
{
|
{
|
||||||
QRectF geometry(geo);
|
QRectF geometry = geo.adjusted(margin(LeftMargin), margin(TopMargin), -margin(RightMargin), -margin(BottomMargin));
|
||||||
geometry.adjust(margin(),margin(),-margin(),-margin());
|
|
||||||
|
|
||||||
qDebug() << "Flow layout geometry set to " << geo;
|
qDebug() << "Flow layout geometry set to " << geo;
|
||||||
|
|
||||||
// calculate average size of items
|
// calculate average size of items
|
||||||
|
|
|
@ -36,7 +36,10 @@ class Layout::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Private(LayoutItem* p)
|
Private(LayoutItem* p)
|
||||||
: margin(12.0),
|
: leftMargin(12.0),
|
||||||
|
rightMargin(12.0),
|
||||||
|
topMargin(12.0),
|
||||||
|
bottomMargin(12.0),
|
||||||
spacing(6.0),
|
spacing(6.0),
|
||||||
parent(p),
|
parent(p),
|
||||||
animator(0)
|
animator(0)
|
||||||
|
@ -45,7 +48,10 @@ class Layout::Private
|
||||||
|
|
||||||
~Private() {}
|
~Private() {}
|
||||||
|
|
||||||
qreal margin;
|
qreal leftMargin;
|
||||||
|
qreal rightMargin;
|
||||||
|
qreal topMargin;
|
||||||
|
qreal bottomMargin;
|
||||||
qreal spacing;
|
qreal spacing;
|
||||||
|
|
||||||
LayoutItem *parent;
|
LayoutItem *parent;
|
||||||
|
@ -111,14 +117,48 @@ void Layout::setAnimator(LayoutAnimator *animator)
|
||||||
d->animator = animator;
|
d->animator = animator;
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal Layout::margin() const
|
qreal Layout::margin(MarginEdge edge) const
|
||||||
{
|
{
|
||||||
return d->margin;
|
switch (edge) {
|
||||||
|
case LeftMargin:
|
||||||
|
return d->leftMargin;
|
||||||
|
break;
|
||||||
|
case RightMargin:
|
||||||
|
return d->rightMargin;
|
||||||
|
break;
|
||||||
|
case TopMargin:
|
||||||
|
return d->topMargin;
|
||||||
|
break;
|
||||||
|
case BottomMargin:
|
||||||
|
return d->bottomMargin;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layout::setMargin(MarginEdge edge, qreal m)
|
||||||
|
{
|
||||||
|
switch (edge) {
|
||||||
|
case LeftMargin:
|
||||||
|
d->leftMargin = m;
|
||||||
|
break;
|
||||||
|
case RightMargin:
|
||||||
|
d->rightMargin = m;
|
||||||
|
break;
|
||||||
|
case TopMargin:
|
||||||
|
d->topMargin = m;
|
||||||
|
break;
|
||||||
|
case BottomMargin:
|
||||||
|
d->bottomMargin = m;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::setMargin(qreal m)
|
void Layout::setMargin(qreal m)
|
||||||
{
|
{
|
||||||
d->margin = m;
|
d->leftMargin = m;
|
||||||
|
d->rightMargin = m;
|
||||||
|
d->topMargin = m;
|
||||||
|
d->bottomMargin = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal Layout::spacing() const
|
qreal Layout::spacing() const
|
||||||
|
|
|
@ -44,6 +44,7 @@ class LayoutAnimator;
|
||||||
class PLASMA_EXPORT Layout : public LayoutItem
|
class PLASMA_EXPORT Layout : public LayoutItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum MarginEdge { TopMargin, BottomMargin, LeftMargin, RightMargin };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -58,11 +59,16 @@ class PLASMA_EXPORT Layout : public LayoutItem
|
||||||
/**
|
/**
|
||||||
* Returns the margin of this Layout.
|
* Returns the margin of this Layout.
|
||||||
*/
|
*/
|
||||||
qreal margin() const;
|
qreal margin(MarginEdge edge) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the margin of this Layout.
|
* Sets the margin of this Layout.
|
||||||
*/
|
*/
|
||||||
|
void setMargin(MarginEdge edge, qreal m);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets all the margins of this Layout.
|
||||||
|
*/
|
||||||
void setMargin(qreal m);
|
void setMargin(qreal m);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user