Skip to content

Commit

Permalink
Support reversing the order of items in LXQt's grid layout (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsujan authored Oct 1, 2024
1 parent 1a4055a commit 3c8db8e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
36 changes: 35 additions & 1 deletion lxqtgridlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class LXQt::GridLayoutPrivate
int mRowCount;
int mColumnCount;
GridLayout::Direction mDirection;
GridLayout::ItemsOrder mItemsOrder;

bool mIsValid;
QSize mCellSizeHint;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}


Expand Down Expand Up @@ -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();
}
}


/************************************************
************************************************/
Expand Down
25 changes: 25 additions & 0 deletions lxqtgridlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};



/**
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3c8db8e

Please sign in to comment.