22 #include <QGraphicsScene>
23 #include <QGraphicsWidget>
24 #include <QPropertyAnimation>
31 #include <KConfigGroup>
33 #define GOLDEN_SIZE 0.381966011250105 // 1 / (1 + phi); phi = (sqrt(5) + 1) / 2
38 class GoldenColumnSizer:
public ColumnLayout::ColumnSizer {
40 void init(
int count) {
46 m_sizes.prepend(size);
47 }
else if (count == 2) {
59 if (m_position < 0 || m_position > m_sizes.size())
return 0;
60 return m_sizes.at(m_position++);
63 QList < qreal > m_sizes;
67 class EqualColumnSizer:
public ColumnLayout::ColumnSizer {
69 void init(
int count) {
88 return new EqualColumnSizer();
90 return new GoldenColumnSizer();
95 class ColumnLayout::Private {
98 QList < QGraphicsWidget * > items;
99 QHash < QGraphicsWidget *, QPointer < QPropertyAnimation > > animators;
101 QGraphicsItem * parentItem;
107 enum RelayoutType { Clean, Push, Pop, Resize };
110 : q(parent), parentItem(NULL),
121 QPropertyAnimation * animator(
QGraphicsWidget * item,
const QByteArray & property)
123 QPropertyAnimation * result;
125 if (animators.contains(item) && animators[item]) {
126 result = animators[item];
128 result->setPropertyName(property);
131 animators[item] =
new QPropertyAnimation(item, property);
132 result = animators[item];
141 item->setGeometry(newGeometry);
147 if (newGeometry.width() < 1) {
151 if (item->isVisible()) {
154 if (item->geometry().height() == newGeometry.height()) {
155 QPropertyAnimation * animation = animator(item,
"geometry");
156 animation->setDuration(300);
157 animation->setStartValue(item->geometry());
158 animation->setEndValue(newGeometry);
162 item->setGeometry(newGeometry);
169 item->setGeometry(newGeometry);
173 QPropertyAnimation * animation = animator(item,
"opacity");
174 animation->setDuration(300);
175 animation->setStartValue(0);
176 animation->setEndValue(1);
189 if (!item->isVisible()) {
195 QPropertyAnimation * animation = animator(item,
"opacity");
196 animation->setDuration(300);
197 animation->setStartValue(1);
198 animation->setEndValue(0);
204 void relayout(RelayoutType type = Clean)
207 if (items.size() == 0)
return;
209 int showItems = qMin(items.size(),
count + 1);
212 qreal left, top, right, bottom;
213 q->getContentsMargins(&left, &top, &right, &bottom);
215 QRectF newGeometry = q->geometry().adjusted(left, top, right, bottom);
216 qreal width = newGeometry.width();
222 if (items.size() - showItems > i++) {
228 newGeometry.setWidth(itemWidth);
230 moveItemTo(item, newGeometry);
232 newGeometry.moveLeft(newGeometry.left() + itemWidth);
239 if (!widget || items.contains(widget)) {
244 items.append(widget);
253 animators.remove(widget);
264 d->relayout(Private::Resize);
273 const QSizeF & constraint)
const
276 Q_UNUSED(constraint);
292 if (count < 1)
return;
294 d->relayout(Private::Clean);
320 return d->items.at(i);
325 return d->items.size();
330 QGraphicsLayout::setGeometry(rect);
L_Override QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
~ColumnLayout()
Destroys Lancelot::ColumnLayout.
This layout is not a general purpose layout, and should not be used as such.
virtual void init(int count)=0
Initializes the ColumnSizer.
L_Override void setGeometry(const QRectF &rect)
void push(QGraphicsWidget *widget)
Pushes the specified widget to the end of stack.
void setSizer(ColumnSizer *sizer)
Sets the ColumnSizer object.
Abstract interface for implementing column size calculation depending on the column count...
L_Override void removeAt(int index)
Not implemented.
L_Override QGraphicsLayoutItem * itemAt(int i) const
L_Override int count() const
static ColumnSizer * create(SizerType type)
ColumnSizer * sizer() const
QGraphicsWidget * pop()
Removes the last widget from the stack and returns it.
virtual ~ColumnSizer()
Destroys the ColumnLayout::ColumnSizer.
ColumnLayout(QGraphicsLayoutItem *parent=0)
Creates a new Lancelot::ColumnLayout.
void setColumnCount(int count)
Sets the maximum number of visible columns.