summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-04-15 03:34:07 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-04-15 03:34:07 (GMT)
commit451f1f33fa65ba213b1585592225c358f124146a (patch)
tree6f24ff4af2bcd42bbc6f4f10254e7a4182484127 /src
parentc0eb81664f2bae225dcaca897c23564d6f97a3d1 (diff)
downloadQt-451f1f33fa65ba213b1585592225c358f124146a.zip
Qt-451f1f33fa65ba213b1585592225c358f124146a.tar.gz
Qt-451f1f33fa65ba213b1585592225c358f124146a.tar.bz2
Add flow property to Grid, adding TopToBottom mode.
Task-number: QTBUG-9183
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners.cpp138
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners_p.h17
2 files changed, 112 insertions, 43 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
index f436471..21c33e2 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
@@ -656,10 +656,8 @@ Grid {
*/
QDeclarativeGrid::QDeclarativeGrid(QDeclarativeItem *parent) :
- QDeclarativeBasePositioner(Both, parent)
+ QDeclarativeBasePositioner(Both, parent), m_rows(-1), m_columns(-1), m_flow(LeftToRight)
{
- _columns=-1;
- _rows=-1;
}
/*!
@@ -682,55 +680,101 @@ QDeclarativeGrid::QDeclarativeGrid(QDeclarativeItem *parent) :
void QDeclarativeGrid::setColumns(const int columns)
{
- if (columns == _columns)
+ if (columns == m_columns)
return;
- _columns = columns;
+ m_columns = columns;
prePositioning();
emit columnsChanged();
}
void QDeclarativeGrid::setRows(const int rows)
{
- if (rows == _rows)
+ if (rows == m_rows)
return;
- _rows = rows;
+ m_rows = rows;
prePositioning();
emit rowsChanged();
}
+/*!
+ \qmlproperty enumeration Flow::flow
+ This property holds the flow of the layout.
+
+ Possible values are \c LeftToRight (default) and \c TopToBottom.
+
+ If \a flow is \c LeftToRight, the items are positioned next to
+ to each other from left to right, then wrapped to the next line.
+ If \a flow is \c TopToBottom, the items are positioned next to each
+ other from top to bottom, then wrapped to the next column.
+*/
+QDeclarativeGrid::Flow QDeclarativeGrid::flow() const
+{
+ return m_flow;
+}
+
+void QDeclarativeGrid::setFlow(Flow flow)
+{
+ if (m_flow != flow) {
+ m_flow = flow;
+ prePositioning();
+ emit flowChanged();
+ }
+}
+
void QDeclarativeGrid::doPositioning(QSizeF *contentSize)
{
- int c = _columns;
- int r = _rows;
+ int c = m_columns;
+ int r = m_rows;
int numVisible = positionedItems.count();
- if (_columns <= 0 && _rows <= 0){
+ if (m_columns <= 0 && m_rows <= 0){
c = 4;
r = (numVisible+3)/4;
- } else if (_rows <= 0){
- r = (numVisible+(_columns-1))/_columns;
- } else if (_columns <= 0){
- c = (numVisible+(_rows-1))/_rows;
+ } else if (m_rows <= 0){
+ r = (numVisible+(m_columns-1))/m_columns;
+ } else if (m_columns <= 0){
+ c = (numVisible+(m_rows-1))/m_rows;
}
QList<int> maxColWidth;
QList<int> maxRowHeight;
int childIndex =0;
- for (int i=0; i<r; i++){
- for (int j=0; j<c; j++){
- if (j==0)
- maxRowHeight << 0;
- if (i==0)
- maxColWidth << 0;
-
- if (childIndex == positionedItems.count())
- continue;
- const PositionedItem &child = positionedItems.at(childIndex++);
- if (!child.item || isInvisible(child.item))
- continue;
- if (child.item->width() > maxColWidth[j])
- maxColWidth[j] = child.item->width();
- if (child.item->height() > maxRowHeight[i])
- maxRowHeight[i] = child.item->height();
+ if (m_flow == LeftToRight) {
+ for (int i=0; i < r; i++){
+ for (int j=0; j < c; j++){
+ if (j==0)
+ maxRowHeight << 0;
+ if (i==0)
+ maxColWidth << 0;
+
+ if (childIndex == positionedItems.count())
+ continue;
+ const PositionedItem &child = positionedItems.at(childIndex++);
+ if (!child.item || isInvisible(child.item))
+ continue;
+ if (child.item->width() > maxColWidth[j])
+ maxColWidth[j] = child.item->width();
+ if (child.item->height() > maxRowHeight[i])
+ maxRowHeight[i] = child.item->height();
+ }
+ }
+ } else {
+ for (int j=0; j < c; j++){
+ for (int i=0; i < r; i++){
+ if (j==0)
+ maxRowHeight << 0;
+ if (i==0)
+ maxColWidth << 0;
+
+ if (childIndex == positionedItems.count())
+ continue;
+ const PositionedItem &child = positionedItems.at(childIndex++);
+ if (!child.item || isInvisible(child.item))
+ continue;
+ if (child.item->width() > maxColWidth[j])
+ maxColWidth[j] = child.item->width();
+ if (child.item->height() > maxRowHeight[i])
+ maxRowHeight[i] = child.item->height();
+ }
}
}
@@ -747,18 +791,34 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize)
positionY(yoffset, child);
}
- contentSize->setWidth(qMax(contentSize->width(), xoffset + child.item->width()));
- contentSize->setHeight(yoffset + maxRowHeight[curRow]);
+ if (m_flow == LeftToRight) {
+ contentSize->setWidth(qMax(contentSize->width(), xoffset + child.item->width()));
+ contentSize->setHeight(yoffset + maxRowHeight[curRow]);
+
+ xoffset+=maxColWidth[curCol]+spacing();
+ curCol++;
+ curCol%=c;
+ if (!curCol){
+ yoffset+=maxRowHeight[curRow]+spacing();
+ xoffset=0;
+ curRow++;
+ if (curRow>=r)
+ break;
+ }
+ } else {
+ contentSize->setHeight(qMax(contentSize->height(), yoffset + child.item->height()));
+ contentSize->setWidth(xoffset + maxColWidth[curCol]);
- xoffset+=maxColWidth[curCol]+spacing();
- curCol++;
- curCol%=c;
- if (!curCol){
yoffset+=maxRowHeight[curRow]+spacing();
- xoffset=0;
curRow++;
- if (curRow>=r)
- break;
+ curRow%=r;
+ if (!curRow){
+ xoffset+=maxColWidth[curCol]+spacing();
+ yoffset=0;
+ curCol++;
+ if (curCol>=c)
+ break;
+ }
}
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners_p.h b/src/declarative/graphicsitems/qdeclarativepositioners_p.h
index c4414d1..24b65fa 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepositioners_p.h
@@ -138,25 +138,34 @@ class Q_DECLARATIVE_EXPORT QDeclarativeGrid : public QDeclarativeBasePositioner
Q_OBJECT
Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowChanged)
Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
+ Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
+
public:
QDeclarativeGrid(QDeclarativeItem *parent=0);
- int rows() const {return _rows;}
+ int rows() const {return m_rows;}
void setRows(const int rows);
- int columns() const {return _columns;}
+ int columns() const {return m_columns;}
void setColumns(const int columns);
+ Q_ENUMS(Flow)
+ enum Flow { LeftToRight, TopToBottom };
+ Flow flow() const;
+ void setFlow(Flow);
+
Q_SIGNALS:
void rowsChanged();
void columnsChanged();
+ void flowChanged();
protected:
virtual void doPositioning(QSizeF *contentSize);
private:
- int _rows;
- int _columns;
+ int m_rows;
+ int m_columns;
+ Flow m_flow;
Q_DISABLE_COPY(QDeclarativeGrid)
};