91
98
QList < QGraphicsWidget * > items;
99
QHash < QGraphicsWidget *, QPointer < QPropertyAnimation > > animators;
92
101
QGraphicsItem * parentItem;
93
102
ColumnLayout::ColumnSizer * sizer;
96
107
enum RelayoutType { Clean, Push, Pop, Resize };
98
109
Private(ColumnLayout * parent)
99
110
: q(parent), parentItem(NULL),
100
sizer(new GoldenColumnSizer()), count(2) {}
111
sizer(new GoldenColumnSizer()), count(2)
113
animate = !Global::self()->config("Animation", "disableAnimations", false)
114
&& Global::self()->config("Animation", "columnLayoutAnimaiton", true);
117
QPropertyAnimation * animator(QGraphicsWidget * item, const QByteArray & property)
119
QPropertyAnimation * result;
121
if (animators.contains(item) && animators[item]) {
122
result = animators[item];
124
result->setPropertyName(property);
127
animators[item] = new QPropertyAnimation(item, property);
128
result = animators[item];
134
void moveItemTo(QGraphicsWidget * item, QRectF newGeometry)
137
item->setGeometry(newGeometry);
143
if (newGeometry.width() < 1) {
147
if (item->isVisible()) {
150
if (item->geometry().height() == newGeometry.height()) {
151
QPropertyAnimation * animation = animator(item, "geometry");
152
animation->setDuration(300);
153
animation->setStartValue(item->geometry());
154
animation->setEndValue(newGeometry);
158
item->setGeometry(newGeometry);
165
item->setGeometry(newGeometry);
169
QPropertyAnimation * animation = animator(item, "opacity");
170
animation->setDuration(300);
171
animation->setStartValue(0);
172
animation->setEndValue(1);
178
void hideItem(QGraphicsWidget * item)
185
if (!item->isVisible()) {
191
QPropertyAnimation * animation = animator(item, "opacity");
192
animation->setDuration(300);
193
animation->setStartValue(1);
194
animation->setEndValue(0);
197
//item->connect(animation, SIGNAL(finished()), SLOT(hide()));
102
200
void relayout(RelayoutType type = Clean)
105
203
if (items.size() == 0) return;
107
205
int showItems = qMin(items.size(), count);
108
qreal width = q->geometry().width();
109
206
sizer->init(showItems);
111
QRectF newGeometry = q->geometry();
208
qreal left, top, right, bottom;
209
q->getContentsMargins(&left, &top, &right, &bottom);
211
QRectF newGeometry = q->geometry().adjusted(left, top, right, bottom);
212
qreal width = newGeometry.width();
115
217
foreach (QGraphicsWidget * item, items) {
116
218
if (items.size() - showItems > i++) {
117
item->setVisible(false);
119
qreal itemWidth = sizer->size() * width;
120
if (itemWidth != 0) {
121
newGeometry.setWidth(itemWidth);
122
item->setGeometry(newGeometry);
125
newGeometry.moveLeft(newGeometry.left() + itemWidth);
127
item->setVisible(false);
222
int itemWidth = sizer->size() * width;
224
newGeometry.setWidth(itemWidth);
226
moveItemTo(item, newGeometry);
228
newGeometry.moveLeft(newGeometry.left() + itemWidth);