Adding upstream version 0.9.0+20151024.

upstream/0.9.0+20151024
Alf Gaida 9 years ago
parent c3383caa2d
commit 08cd13d7e0

@ -4,7 +4,9 @@ Upstream Authors:
Copyright:
Copyright (c) 2010-2012 Razor team
Copyright (c) 2012-2014 LXQt team
Copyright (c) 2012-2015 LXQt team
License: GPL-2 and LGPL-2.1+
The full text of the licenses can be found in the 'COPYING' file.
License: LGPL-2.1+ and BSD-3-clause
The full text of the LGPL-2.1+ licenses can be found in the 'COPYING' file.
The full text of the BSD-3-clause license can be found in the headers of
the files under this license.

@ -30,9 +30,41 @@
#include <QDebug>
#include <math.h>
#include <QWidget>
#include <QVariantAnimation>
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 &current)
{
mItem->setGeometry(current.toRect());
}
private:
QLayoutItem* mItem;
};
}
class LXQt::GridLayoutPrivate
{
public:
@ -48,13 +80,16 @@ public:
QSize mCellMaxSize;
int mVisibleCount;
GridLayout::Stretch mStretch;
bool mAnimate;
void updateCache();
int rows() const;
int cols() const;
void setItemGeometry(QLayoutItem * item, QRect const & geometry);
QSize mPrefCellMinSize;
QSize mPrefCellMaxSize;
QRect mOccupiedGeometry;
};
@ -69,6 +104,7 @@ GridLayoutPrivate::GridLayoutPrivate()
mIsValid = false;
mVisibleCount = 0;
mStretch = GridLayout::StretchHorizontal | GridLayout::StretchVertical;
mAnimate = false;
mPrefCellMinSize = QSize(0,0);
mPrefCellMaxSize = QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
}
@ -153,6 +189,17 @@ int GridLayoutPrivate::cols() const
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);
d->mAnimate = withAnimation;
d->mItems.move(from, to);
invalidate();
}
@ -510,6 +558,10 @@ void GridLayout::setGeometry(const QRect &geometry)
{
Q_D(GridLayout);
QLayout::setGeometry(geometry);
d->mOccupiedGeometry.setTopLeft(geometry.topLeft());
d->mOccupiedGeometry.setBottomRight(geometry.topLeft());
if (!d->mIsValid)
d->updateCache();
@ -578,7 +630,7 @@ void GridLayout::setGeometry(const QRect &geometry)
remain_width = widthRemain;
}
item->setGeometry(QRect(x, y, width, height));
d->setItemGeometry(item, QRect(x, y, width, height));
x += width;
}
}
@ -599,9 +651,17 @@ void GridLayout::setGeometry(const QRect &geometry)
width = itemWidth + (0 < remain_width-- ? 1 : 0);
remain_height = heightRemain;
}
item->setGeometry(QRect(x, y, width, height));
d->setItemGeometry(item, QRect(x, y, width, height));
y += height;
}
}
d->mAnimate = false;
}
/************************************************
************************************************/
QRect GridLayout::occupiedGeometry() const
{
return d_func()->mOccupiedGeometry;
}

@ -89,6 +89,7 @@ public:
QSize sizeHint() const;
void setGeometry(const QRect &geometry);
QRect occupiedGeometry() const;
/**
@ -154,9 +155,10 @@ public:
void setStretch(Stretch value);
/**
Moves the item at index position from to index position to.
Moves the item at index position \param from to index position \param to.
If \param withAnimation set the reordering will be animated
**/
void moveItem(int from, int to);
void moveItem(int from, int to, bool withAnimation = false);
/**
Returns the cells' minimum size.

Loading…
Cancel
Save