prettify code spacing
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=765102
This commit is contained in:
parent
11f9ad3064
commit
593a6c8103
@ -44,7 +44,7 @@ public:
|
||||
bool multiRow;
|
||||
int rowCount;
|
||||
int colCount() const {
|
||||
return ((children.count()-1)/rowCount)+1;
|
||||
return ((children.count() - 1) / rowCount) + 1;
|
||||
}
|
||||
|
||||
Private(BoxLayout *parent)
|
||||
@ -91,7 +91,7 @@ public:
|
||||
// or shrinks
|
||||
Qt::Orientation expandingDirection() const
|
||||
{
|
||||
switch ( direction ) {
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
case RightToLeft:
|
||||
return Qt::Horizontal;
|
||||
@ -108,7 +108,7 @@ public:
|
||||
// begin depending on the direction of this layout
|
||||
qreal startPos(const QRectF& geometry) const
|
||||
{
|
||||
switch ( direction ) {
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
return geometry.left() + q->margin(LeftMargin);
|
||||
case TopToBottom:
|
||||
@ -144,39 +144,37 @@ public:
|
||||
|
||||
QSizeF minSize = item->minimumSize();
|
||||
QSizeF maxSize = item->maximumSize();
|
||||
switch ( direction ) {
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
case RightToLeft:
|
||||
height = (geometry.height()-q->spacing()*(rowCount-1))/rowCount;
|
||||
top = geometry.top()+row*(height+q->spacing());
|
||||
height = (geometry.height() - q->spacing() * (rowCount - 1)) / rowCount;
|
||||
top = geometry.top() + row * (height + q->spacing());
|
||||
height = qBound(minSize.height(), height, maxSize.height());
|
||||
break;
|
||||
case TopToBottom:
|
||||
case BottomToTop:
|
||||
height = (geometry.width()-q->spacing()*(rowCount-1))/rowCount;
|
||||
top = geometry.left()+row*(height+q->spacing());
|
||||
height = (geometry.width() - q->spacing() * (rowCount - 1)) / rowCount;
|
||||
top = geometry.left() + row * (height + q->spacing());
|
||||
height = qBound(minSize.width(), height, maxSize.width());
|
||||
break;
|
||||
}
|
||||
|
||||
switch ( direction ) {
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
newGeometry = QRectF(pos,top,size,height);
|
||||
newPos = pos+size+q->spacing();
|
||||
newGeometry = QRectF(pos, top, size, height);
|
||||
newPos = pos + size + q->spacing();
|
||||
break;
|
||||
case RightToLeft:
|
||||
newGeometry = QRectF(geometry.width()-pos-size,top,
|
||||
size,height);
|
||||
newPos = pos-size-q->spacing();
|
||||
newGeometry = QRectF(geometry.width() - pos - size, top, size, height);
|
||||
newPos = pos - size - q->spacing();
|
||||
break;
|
||||
case TopToBottom:
|
||||
newGeometry = QRectF(top,pos,height,size);
|
||||
newPos = pos+size+q->spacing();
|
||||
newGeometry = QRectF(top, pos, height, size);
|
||||
newPos = pos + size + q->spacing();
|
||||
break;
|
||||
case BottomToTop:
|
||||
newGeometry = QRectF(top,geometry.height()-pos-size,
|
||||
height,size);
|
||||
newPos = pos-size-q->spacing();
|
||||
newGeometry = QRectF(top, geometry.height() - pos - size, height, size);
|
||||
newPos = pos - size - q->spacing();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -200,9 +198,9 @@ public:
|
||||
|
||||
// this provides a + function which can be passed as the 'op'
|
||||
// argument to calculateSize
|
||||
static qreal sum(const qreal a , const qreal b)
|
||||
static qreal sum(const qreal a, const qreal b)
|
||||
{
|
||||
return a+b;
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// calcualtes a size hint or value for this layout
|
||||
@ -211,13 +209,13 @@ public:
|
||||
// 'op' - A function to apply to the size of each item in the layout
|
||||
// , usually qMax,qMin or sum
|
||||
template <class T>
|
||||
qreal calculateSize(SizeType sizeType , Qt::Orientation dir , T (*op)(const T,const T)) const
|
||||
qreal calculateSize(SizeType sizeType, Qt::Orientation dir, T (*op)(const T, const T)) const
|
||||
{
|
||||
qreal value = 0;
|
||||
for ( int i = 0 ; i < children.count() ; i++ ) {
|
||||
for (int i = 0; i < children.count(); i++) {
|
||||
|
||||
QSizeF itemSize;
|
||||
switch ( sizeType ) {
|
||||
switch (sizeType) {
|
||||
case MinSize:
|
||||
itemSize = children[i]->minimumSize();
|
||||
break;
|
||||
@ -229,10 +227,10 @@ public:
|
||||
break;
|
||||
}
|
||||
|
||||
if ( dir == Qt::Horizontal ) {
|
||||
value = op(value,itemSize.width());
|
||||
if (dir == Qt::Horizontal) {
|
||||
value = op(value, itemSize.width());
|
||||
} else {
|
||||
value = op(value,itemSize.height());
|
||||
value = op(value, itemSize.height());
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,14 +243,14 @@ public:
|
||||
{
|
||||
QSizeF result;
|
||||
|
||||
const qreal totalSpacingC = q->spacing() * colCount()-1;
|
||||
const qreal totalSpacingR = q->spacing() * rowCount-1;
|
||||
const qreal totalSpacingC = q->spacing() * colCount() - 1;
|
||||
const qreal totalSpacingR = q->spacing() * rowCount - 1;
|
||||
|
||||
switch ( direction ) {
|
||||
switch (direction) {
|
||||
case LeftToRight:
|
||||
case RightToLeft:
|
||||
result = QSizeF(calculateSize(calculateSizeType,Qt::Horizontal,sum)/rowCount,
|
||||
calculateSize(calculateSizeType,Qt::Vertical,qMax<qreal>)*rowCount);
|
||||
result = QSizeF(calculateSize(calculateSizeType, Qt::Horizontal, sum) / rowCount,
|
||||
calculateSize(calculateSizeType, Qt::Vertical, qMax<qreal>) * rowCount);
|
||||
|
||||
result.rwidth() += q->margin(LeftMargin) + q->margin(RightMargin) + totalSpacingC;
|
||||
result.rheight() += q->margin(TopMargin) + q->margin(BottomMargin) + totalSpacingR;
|
||||
@ -260,8 +258,8 @@ public:
|
||||
break;
|
||||
case TopToBottom:
|
||||
case BottomToTop:
|
||||
result = QSizeF(calculateSize(calculateSizeType,Qt::Horizontal,qMax<qreal>)/rowCount,
|
||||
calculateSize(calculateSizeType,Qt::Vertical,sum)*rowCount);
|
||||
result = QSizeF(calculateSize(calculateSizeType, Qt::Horizontal, qMax<qreal>) / rowCount,
|
||||
calculateSize(calculateSizeType, Qt::Vertical, sum) * rowCount);
|
||||
|
||||
result.rheight() += q->margin(TopMargin) + q->margin(BottomMargin) + totalSpacingC;
|
||||
result.rwidth() += q->margin(LeftMargin) + q->margin(RightMargin) + totalSpacingR;
|
||||
@ -274,7 +272,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
BoxLayout::BoxLayout(Direction direction , LayoutItem *parent)
|
||||
BoxLayout::BoxLayout(Direction direction, LayoutItem *parent)
|
||||
: Layout(parent),
|
||||
d(new Private(this))
|
||||
{
|
||||
@ -286,6 +284,7 @@ void BoxLayout::setDirection(Direction direction)
|
||||
d->direction = direction;
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
BoxLayout::Direction BoxLayout::direction() const
|
||||
{
|
||||
return d->direction;
|
||||
@ -301,7 +300,7 @@ BoxLayout::~BoxLayout()
|
||||
|
||||
Qt::Orientations BoxLayout::expandingDirections() const
|
||||
{
|
||||
switch ( d->direction ) {
|
||||
switch (d->direction) {
|
||||
case LeftToRight:
|
||||
case RightToLeft:
|
||||
return Qt::Horizontal;
|
||||
@ -411,9 +410,9 @@ void BoxLayout::relayout()
|
||||
//qDebug() << "Box layout beginning with geo" << geometry;
|
||||
//qDebug() << "This box max size" << maximumSize();
|
||||
d->rowCount = 1;
|
||||
if(d->multiRow) {
|
||||
qreal minRowSize=1;
|
||||
qreal minWidth=0;
|
||||
if (d->multiRow) {
|
||||
qreal minRowSize = 1;
|
||||
qreal minWidth = 0;
|
||||
for(int i = 0; i < d->children.count(); i++) {
|
||||
minRowSize = qMax(minRowSize, d->size_o(d->children[i]->minimumSize()));
|
||||
minWidth += d->size(d->children[i]->minimumSize());
|
||||
@ -429,42 +428,43 @@ void BoxLayout::relayout()
|
||||
//FIXME: this formula doesn't take the cellspacing in account
|
||||
// it should also try to "fill" before adding a row
|
||||
d->rowCount = 1 + sqrt(ratio * count() * d->size_o(margined.size()) /
|
||||
(d->size(margined.size())+1));
|
||||
(d->size(margined.size()) + 1));
|
||||
|
||||
d->rowCount = qMax(minRow,d->rowCount);
|
||||
d->rowCount = qMin(maxRow,d->rowCount);
|
||||
d->rowCount = qMax(1,d->rowCount);
|
||||
d->rowCount = qMax(minRow, d->rowCount);
|
||||
d->rowCount = qMin(maxRow, d->rowCount);
|
||||
d->rowCount = qMax(1, d->rowCount);
|
||||
}
|
||||
|
||||
int colCount = d->colCount();
|
||||
|
||||
QVector<qreal> sizes(colCount,0);
|
||||
QVector<qreal> expansionSpace(colCount,0);
|
||||
QVector<qreal> sizes(colCount, 0);
|
||||
QVector<qreal> expansionSpace(colCount, 0);
|
||||
|
||||
qreal available = d->size(margined.size()) - spacing() * colCount;
|
||||
qreal perItemSize = available / colCount;
|
||||
|
||||
// initial distribution of space to items
|
||||
for ( int i = 0 ; i < colCount ; i++ ) {
|
||||
qreal minItemSize=0;
|
||||
qreal maxItemSize=65536;
|
||||
bool isExpanding=true;
|
||||
for (int i = 0; i < colCount; i++) {
|
||||
qreal minItemSize = 0;
|
||||
qreal maxItemSize = 65536;
|
||||
bool isExpanding = true;
|
||||
qreal hint = 0;
|
||||
|
||||
for(int f = i*d->rowCount; f < (i+1)*d->rowCount; f++) {
|
||||
if(f>=count()) {
|
||||
for (int f = i * d->rowCount; f < (i + 1) * d->rowCount; f++) {
|
||||
if (f >= count()) {
|
||||
break;
|
||||
}
|
||||
const LayoutItem *item = d->children[f];
|
||||
const bool itemExp = (item->expandingDirections() & d->expandingDirection());
|
||||
isExpanding = isExpanding && itemExp;
|
||||
minItemSize = qMax(minItemSize,d->size(item->minimumSize()));
|
||||
maxItemSize = qMin(maxItemSize,d->size(item->maximumSize()));
|
||||
if(!itemExp)
|
||||
hint = qMax(hint,d->size(item->sizeHint()));
|
||||
minItemSize = qMax(minItemSize, d->size(item->minimumSize()));
|
||||
maxItemSize = qMin(maxItemSize, d->size(item->maximumSize()));
|
||||
if (!itemExp) {
|
||||
hint = qMax(hint, d->size(item->sizeHint()));
|
||||
}
|
||||
}
|
||||
|
||||
if ( isExpanding ) {
|
||||
if (isExpanding) {
|
||||
sizes[i] = perItemSize;
|
||||
} else {
|
||||
sizes[i] = hint;
|
||||
@ -472,22 +472,22 @@ void BoxLayout::relayout()
|
||||
|
||||
// qDebug() << "Layout max item " << i << "size: " << maxItemSize;
|
||||
|
||||
sizes[i] = qMin( sizes[i] , maxItemSize );
|
||||
sizes[i] = qMax( sizes[i] , minItemSize );
|
||||
sizes[i] = qMin(sizes[i], maxItemSize);
|
||||
sizes[i] = qMax(sizes[i], minItemSize);
|
||||
|
||||
// qDebug() << "Available: " << available << "per item:" << perItemSize <<
|
||||
// "Initial size: " << sizes[i];
|
||||
|
||||
if ( isExpanding ) {
|
||||
expansionSpace[i] = maxItemSize-sizes[i];
|
||||
if (isExpanding) {
|
||||
expansionSpace[i] = maxItemSize - sizes[i];
|
||||
} else {
|
||||
expansionSpace[i] = 0;
|
||||
}
|
||||
|
||||
available -= sizes[i];
|
||||
// adjust the per-item size if the space was over or under used
|
||||
if ( sizes[i] != perItemSize && i != sizes.count()-1 ) {
|
||||
perItemSize = available / (sizes.count()-i-1);
|
||||
if (sizes[i] != perItemSize && i != sizes.count() - 1) {
|
||||
perItemSize = available / (sizes.count() - i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -497,17 +497,17 @@ void BoxLayout::relayout()
|
||||
// out of space or items to expand
|
||||
int expandable = sizes.count();
|
||||
const qreal threshold = 1.0;
|
||||
while ( available > threshold && expandable > 0 ) {
|
||||
while (available > threshold && expandable > 0) {
|
||||
|
||||
qreal extraSpace = available / expandable;
|
||||
for ( int i = 0 ; i < colCount ; i++ ) {
|
||||
if ( expansionSpace[i] > threshold ) {
|
||||
for (int i = 0; i < colCount; i++) {
|
||||
if (expansionSpace[i] > threshold) {
|
||||
qreal oldSize = sizes[i];
|
||||
|
||||
sizes[i] += qMin(extraSpace,expansionSpace[i]);
|
||||
sizes[i] += qMin(extraSpace, expansionSpace[i]);
|
||||
|
||||
expansionSpace[i] -= sizes[i]-oldSize;
|
||||
available -= sizes[i]-oldSize;
|
||||
expansionSpace[i] -= sizes[i] - oldSize;
|
||||
available -= sizes[i] - oldSize;
|
||||
} else {
|
||||
expandable--;
|
||||
}
|
||||
@ -516,21 +516,22 @@ void BoxLayout::relayout()
|
||||
|
||||
// set items' geometry according to new sizes
|
||||
qreal pos = d->startPos(geometry());
|
||||
for ( int col = 0 ; col < colCount ; col++ ) {
|
||||
for (int col = 0; col < colCount; col++) {
|
||||
int newPos = pos;
|
||||
for ( int row = 0 ; row < d->rowCount ; row++ ) {
|
||||
int i = col*d->rowCount+row;
|
||||
if(i>=count())
|
||||
for (int row = 0; row < d->rowCount; row++) {
|
||||
int i = col * d->rowCount + row;
|
||||
if (i >= count()) {
|
||||
break;
|
||||
}
|
||||
|
||||
//QObject *obj = dynamic_cast<QObject*>(d->children[i]);
|
||||
//if ( obj )
|
||||
//qDebug() << "Item " << i << obj->metaObject()->className() << "size:" << sizes[i];
|
||||
|
||||
int p = d->layoutItem(margined, d->children[i], pos , sizes[col], row);
|
||||
newPos = (row != 0 && p < pos) ? qMin(p,newPos) : qMax(p,newPos);
|
||||
int p = d->layoutItem(margined, d->children[i], pos, sizes[col], row);
|
||||
newPos = (row != 0 && p < pos) ? qMin(p, newPos) : qMax(p, newPos);
|
||||
}
|
||||
pos=newPos;
|
||||
pos = newPos;
|
||||
}
|
||||
|
||||
startAnimation();
|
||||
@ -556,12 +557,12 @@ void BoxLayout::setMultiRow(bool b)
|
||||
}
|
||||
|
||||
HBoxLayout::HBoxLayout(LayoutItem *parent)
|
||||
: BoxLayout(LeftToRight,parent)
|
||||
: BoxLayout(LeftToRight, parent)
|
||||
{
|
||||
}
|
||||
|
||||
VBoxLayout::VBoxLayout(LayoutItem *parent)
|
||||
: BoxLayout(TopToBottom,parent)
|
||||
: BoxLayout(TopToBottom, parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ class PLASMA_EXPORT BoxLayout : public Layout
|
||||
* Creates a new box layout which lays items out in the specified
|
||||
* @p direction
|
||||
*/
|
||||
explicit BoxLayout(Direction direction , LayoutItem *parent = 0);
|
||||
explicit BoxLayout(Direction direction, LayoutItem *parent = 0);
|
||||
~BoxLayout();
|
||||
|
||||
/** Sets the direction in which items are laid out. */
|
||||
|
Loading…
Reference in New Issue
Block a user