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:
Copyright (c) 2010-2012 Razor team 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+ License: LGPL-2.1+ and BSD-3-clause
The full text of the licenses can be found in the 'COPYING' file. 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 <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 &current)
{
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;
}

@ -89,6 +89,7 @@ public:
QSize sizeHint() const; QSize sizeHint() const;
void setGeometry(const QRect &geometry); void setGeometry(const QRect &geometry);
QRect occupiedGeometry() const;
/** /**
@ -154,9 +155,10 @@ public:
void setStretch(Stretch value); 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. Returns the cells' minimum size.

Loading…
Cancel
Save