|
|
@ -30,9 +30,41 @@
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <math.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
#include <QVariantAnimation>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace LXQt;
|
|
|
|
using namespace LXQt;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
class ItemMoveAnimation : public QVariantAnimation
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
static void animate(QLayoutItem * item, QRect const & geometry)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ItemMoveAnimation* animation = new ItemMoveAnimation(item);
|
|
|
|
|
|
|
|
animation->setStartValue(item->geometry());
|
|
|
|
|
|
|
|
animation->setEndValue(geometry);
|
|
|
|
|
|
|
|
animation->start(DeleteWhenStopped);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ItemMoveAnimation(QLayoutItem *item)
|
|
|
|
|
|
|
|
: mItem(item)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
setEasingCurve(QEasingCurve::OutBack);
|
|
|
|
|
|
|
|
setDuration(250);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void updateCurrentValue(const QVariant ¤t)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mItem->setGeometry(current.toRect());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
QLayoutItem* mItem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class LXQt::GridLayoutPrivate
|
|
|
|
class LXQt::GridLayoutPrivate
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
@ -48,13 +80,16 @@ public:
|
|
|
|
QSize mCellMaxSize;
|
|
|
|
QSize mCellMaxSize;
|
|
|
|
int mVisibleCount;
|
|
|
|
int mVisibleCount;
|
|
|
|
GridLayout::Stretch mStretch;
|
|
|
|
GridLayout::Stretch mStretch;
|
|
|
|
|
|
|
|
bool mAnimate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void updateCache();
|
|
|
|
void updateCache();
|
|
|
|
int rows() const;
|
|
|
|
int rows() const;
|
|
|
|
int cols() const;
|
|
|
|
int cols() const;
|
|
|
|
|
|
|
|
void setItemGeometry(QLayoutItem * item, QRect const & geometry);
|
|
|
|
QSize mPrefCellMinSize;
|
|
|
|
QSize mPrefCellMinSize;
|
|
|
|
QSize mPrefCellMaxSize;
|
|
|
|
QSize mPrefCellMaxSize;
|
|
|
|
|
|
|
|
QRect mOccupiedGeometry;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -69,6 +104,7 @@ GridLayoutPrivate::GridLayoutPrivate()
|
|
|
|
mIsValid = false;
|
|
|
|
mIsValid = false;
|
|
|
|
mVisibleCount = 0;
|
|
|
|
mVisibleCount = 0;
|
|
|
|
mStretch = GridLayout::StretchHorizontal | GridLayout::StretchVertical;
|
|
|
|
mStretch = GridLayout::StretchHorizontal | GridLayout::StretchVertical;
|
|
|
|
|
|
|
|
mAnimate = false;
|
|
|
|
mPrefCellMinSize = QSize(0,0);
|
|
|
|
mPrefCellMinSize = QSize(0,0);
|
|
|
|
mPrefCellMaxSize = QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
|
|
|
mPrefCellMaxSize = QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -153,6 +189,17 @@ int GridLayoutPrivate::cols() const
|
|
|
|
return ceil(mVisibleCount * 1.0 / rows);
|
|
|
|
return ceil(mVisibleCount * 1.0 / rows);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GridLayoutPrivate::setItemGeometry(QLayoutItem * item, QRect const & geometry)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mOccupiedGeometry |= geometry;
|
|
|
|
|
|
|
|
if (mAnimate)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ItemMoveAnimation::animate(item, geometry);
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item->setGeometry(geometry);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
/************************************************
|
|
|
@ -328,9 +375,10 @@ void GridLayout::setStretch(Stretch value)
|
|
|
|
/************************************************
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
************************************************/
|
|
|
|
void GridLayout::moveItem(int from, int to)
|
|
|
|
void GridLayout::moveItem(int from, int to, bool withAnimation /*= false*/)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Q_D(GridLayout);
|
|
|
|
Q_D(GridLayout);
|
|
|
|
|
|
|
|
d->mAnimate = withAnimation;
|
|
|
|
d->mItems.move(from, to);
|
|
|
|
d->mItems.move(from, to);
|
|
|
|
invalidate();
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -510,6 +558,10 @@ void GridLayout::setGeometry(const QRect &geometry)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Q_D(GridLayout);
|
|
|
|
Q_D(GridLayout);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QLayout::setGeometry(geometry);
|
|
|
|
|
|
|
|
d->mOccupiedGeometry.setTopLeft(geometry.topLeft());
|
|
|
|
|
|
|
|
d->mOccupiedGeometry.setBottomRight(geometry.topLeft());
|
|
|
|
|
|
|
|
|
|
|
|
if (!d->mIsValid)
|
|
|
|
if (!d->mIsValid)
|
|
|
|
d->updateCache();
|
|
|
|
d->updateCache();
|
|
|
|
|
|
|
|
|
|
|
@ -578,7 +630,7 @@ void GridLayout::setGeometry(const QRect &geometry)
|
|
|
|
remain_width = widthRemain;
|
|
|
|
remain_width = widthRemain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
item->setGeometry(QRect(x, y, width, height));
|
|
|
|
d->setItemGeometry(item, QRect(x, y, width, height));
|
|
|
|
x += width;
|
|
|
|
x += width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -599,9 +651,17 @@ void GridLayout::setGeometry(const QRect &geometry)
|
|
|
|
width = itemWidth + (0 < remain_width-- ? 1 : 0);
|
|
|
|
width = itemWidth + (0 < remain_width-- ? 1 : 0);
|
|
|
|
remain_height = heightRemain;
|
|
|
|
remain_height = heightRemain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
item->setGeometry(QRect(x, y, width, height));
|
|
|
|
d->setItemGeometry(item, QRect(x, y, width, height));
|
|
|
|
y += height;
|
|
|
|
y += height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d->mAnimate = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
|
|
QRect GridLayout::occupiedGeometry() const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return d_func()->mOccupiedGeometry;
|
|
|
|
|
|
|
|
}
|
|
|
|