diff --git a/lxqtgridlayout.cpp b/lxqtgridlayout.cpp index ebe1ff2..c741bb6 100644 --- a/lxqtgridlayout.cpp +++ b/lxqtgridlayout.cpp @@ -44,6 +44,7 @@ class LXQt::GridLayoutPrivate int mRowCount; int mColumnCount; GridLayout::Direction mDirection; + GridLayout::ItemsOrder mItemsOrder; bool mIsValid; QSize mCellSizeHint; @@ -104,6 +105,7 @@ GridLayoutPrivate::GridLayoutPrivate() mColumnCount = 0; mRowCount = 0; mDirection = GridLayout::LeftToRight; + mItemsOrder = GridLayout::FirstToLast; mIsValid = false; mVisibleCount = 0; mStretch = GridLayout::StretchHorizontal | GridLayout::StretchVertical; @@ -241,7 +243,14 @@ GridLayout::~GridLayout() ************************************************/ void GridLayout::addItem(QLayoutItem *item) { - d_ptr->mItems.append(item); + if (d_ptr->mItemsOrder == GridLayout::ItemsOrder::FirstToLast) + { + d_ptr->mItems.append(item); + } + else + { + d_ptr->mItems.prepend(item); + } } @@ -387,6 +396,31 @@ void GridLayout::setStretch(Stretch value) } +/************************************************ + + ************************************************/ +GridLayout::ItemsOrder GridLayout::itemsOrder() const +{ + Q_D(const GridLayout); + return d->mItemsOrder; +} + + +/************************************************ + + ************************************************/ +void GridLayout::setItemsOrder(GridLayout::ItemsOrder value) +{ + Q_D(GridLayout); + if (d->mItemsOrder != value) + { + d->mItemsOrder = value; + std::reverse(d->mItems.begin(), d->mItems.end()); + invalidate(); + } +} + + /************************************************ ************************************************/ diff --git a/lxqtgridlayout.h b/lxqtgridlayout.h index 9d82282..8540ecb 100644 --- a/lxqtgridlayout.h +++ b/lxqtgridlayout.h @@ -67,6 +67,15 @@ class LXQT_API GridLayout: public QLayout }; Q_DECLARE_FLAGS(Stretch, StretchFlag) + /** + This enum type is used to describe the order of items. + **/ + enum ItemsOrder + { + FirstToLast, ///< The newest item comes last + LastToFirst ///< The newest item comes first + }; + /** @@ -140,6 +149,22 @@ class LXQT_API GridLayout: public QLayout **/ void setDirection(Direction value); + + /** + Returns the order of items. + + \sa GridLayout::ItemsOrder + **/ + ItemsOrder itemsOrder() const; + + /** + Sets the the order of items. + + \sa GridLayout::ItemsOrder + **/ + void setItemsOrder(ItemsOrder value); + + /** Returns the stretch flags of this grid.