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