From c395cc03bbbbabeedda1573910f9d37a3615152b Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 28 Jan 2008 11:55:56 +0000 Subject: [PATCH] added the function setExpandingBoth(bool) that makes the layout to expand in both directions, useful for instance if you put an horizontal layout into a vertical layout oh, and fixed a typo in a comment svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=767568 --- layouts/boxlayout.cpp | 30 +++++++++++++++--------------- layouts/boxlayout.h | 5 ++++- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/layouts/boxlayout.cpp b/layouts/boxlayout.cpp index 6de09d60d..3840c1976 100644 --- a/layouts/boxlayout.cpp +++ b/layouts/boxlayout.cpp @@ -41,6 +41,7 @@ public: BoxLayout *const q; Direction direction; QList children; + bool expandingBoth; bool multiRow; int rowCount; int colCount() const { @@ -49,7 +50,7 @@ public: Private(BoxLayout *parent) : q(parent) - , direction(LeftToRight), multiRow(false) , rowCount(1) + , direction(LeftToRight), expandingBoth(false), multiRow(false) , rowCount(1) { } @@ -87,10 +88,14 @@ public: } - // returns the direction in which this layout expands + // returns the directions in which this layout expands // or shrinks - Qt::Orientation expandingDirection() const + Qt::Orientations expandingDirections() const { + if (expandingBoth) { + return Qt::Horizontal|Qt::Vertical; + } + switch (direction) { case LeftToRight: case RightToLeft: @@ -300,17 +305,7 @@ BoxLayout::~BoxLayout() Qt::Orientations BoxLayout::expandingDirections() const { - switch (d->direction) { - case LeftToRight: - case RightToLeft: - return Qt::Horizontal; - case TopToBottom: - case BottomToTop: - return Qt::Vertical; - default: - Q_ASSERT(false); - return 0; - } + return d->expandingDirections(); } int BoxLayout::count() const @@ -455,7 +450,7 @@ void BoxLayout::relayout() break; } const LayoutItem *item = d->children[f]; - const bool itemExp = (item->expandingDirections() & d->expandingDirection()); + const bool itemExp = (item->expandingDirections() & d->expandingDirections()); isExpanding = isExpanding && itemExp; minItemSize = qMax(minItemSize, d->size(item->minimumSize())); maxItemSize = qMin(maxItemSize, d->size(item->maximumSize())); @@ -556,6 +551,11 @@ void BoxLayout::setMultiRow(bool b) d->multiRow = b; } +void BoxLayout::setExpandingBoth(bool both) +{ + d->expandingBoth = both; +} + HBoxLayout::HBoxLayout(LayoutItem *parent) : BoxLayout(LeftToRight, parent) { diff --git a/layouts/boxlayout.h b/layouts/boxlayout.h index 13fd0ce08..9882d6383 100644 --- a/layouts/boxlayout.h +++ b/layouts/boxlayout.h @@ -67,9 +67,12 @@ class PLASMA_EXPORT BoxLayout : public Layout /** Inserts a new item into the layout at the specified index. */ void insertItem(int index, LayoutItem *l); - /** Set weither this layout will take severals row */ + /** Set whether this layout will take several rows */ void setMultiRow(bool b); + /** Set whether this layout will expand in both directions */ + void setExpandingBoth(bool both); + // reimplemented from Layout virtual void addItem(LayoutItem *l); virtual void removeItem(LayoutItem *l);