]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistview.cpp
Fix Bug 310465 - Can't switch view mode for non-writable paths
[dolphin.git] / src / kitemviews / kitemlistview.cpp
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * Based on the Itemviews NG project from Trolltech Labs: *
5 * http://qt.gitorious.org/qt-labs/itemviews-ng *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
21 ***************************************************************************/
22
23 #include "kitemlistview.h"
24
25 #include <KDebug>
26 #include "kitemlistcontroller.h"
27 #include "kitemlistheader.h"
28 #include "kitemlistselectionmanager.h"
29 #include "kitemlistwidget.h"
30
31 #include "private/kitemlistheaderwidget.h"
32 #include "private/kitemlistrubberband.h"
33 #include "private/kitemlistsizehintresolver.h"
34 #include "private/kitemlistviewlayouter.h"
35 #include "private/kitemlistviewanimation.h"
36
37 #include <QCursor>
38 #include <QGraphicsSceneMouseEvent>
39 #include <QGraphicsView>
40 #include <QPainter>
41 #include <QPropertyAnimation>
42 #include <QStyle>
43 #include <QStyleOptionRubberBand>
44 #include <QTimer>
45
46 namespace {
47 // Time in ms until reaching the autoscroll margin triggers
48 // an initial autoscrolling
49 const int InitialAutoScrollDelay = 700;
50
51 // Delay in ms for triggering the next autoscroll
52 const int RepeatingAutoScrollDelay = 1000 / 60;
53 }
54
55 KItemListView::KItemListView(QGraphicsWidget* parent) :
56 QGraphicsWidget(parent),
57 m_enabledSelectionToggles(false),
58 m_grouped(false),
59 m_supportsItemExpanding(false),
60 m_editingRole(false),
61 m_activeTransactions(0),
62 m_endTransactionAnimationHint(Animation),
63 m_itemSize(),
64 m_controller(0),
65 m_model(0),
66 m_visibleRoles(),
67 m_widgetCreator(0),
68 m_groupHeaderCreator(0),
69 m_styleOption(),
70 m_visibleItems(),
71 m_visibleGroups(),
72 m_visibleCells(),
73 m_sizeHintResolver(0),
74 m_layouter(0),
75 m_animation(0),
76 m_layoutTimer(0),
77 m_oldScrollOffset(0),
78 m_oldMaximumScrollOffset(0),
79 m_oldItemOffset(0),
80 m_oldMaximumItemOffset(0),
81 m_skipAutoScrollForRubberBand(false),
82 m_rubberBand(0),
83 m_mousePos(),
84 m_autoScrollIncrement(0),
85 m_autoScrollTimer(0),
86 m_header(0),
87 m_headerWidget(0),
88 m_dropIndicator()
89 {
90 setAcceptHoverEvents(true);
91
92 m_sizeHintResolver = new KItemListSizeHintResolver(this);
93
94 m_layouter = new KItemListViewLayouter(this);
95 m_layouter->setSizeHintResolver(m_sizeHintResolver);
96
97 m_animation = new KItemListViewAnimation(this);
98 connect(m_animation, SIGNAL(finished(QGraphicsWidget*,KItemListViewAnimation::AnimationType)),
99 this, SLOT(slotAnimationFinished(QGraphicsWidget*,KItemListViewAnimation::AnimationType)));
100
101 m_layoutTimer = new QTimer(this);
102 m_layoutTimer->setInterval(300);
103 m_layoutTimer->setSingleShot(true);
104 connect(m_layoutTimer, SIGNAL(timeout()), this, SLOT(slotLayoutTimerFinished()));
105
106 m_rubberBand = new KItemListRubberBand(this);
107 connect(m_rubberBand, SIGNAL(activationChanged(bool)), this, SLOT(slotRubberBandActivationChanged(bool)));
108
109 m_headerWidget = new KItemListHeaderWidget(this);
110 m_headerWidget->setVisible(false);
111
112 m_header = new KItemListHeader(this);
113 }
114
115 KItemListView::~KItemListView()
116 {
117 // The group headers are children of the widgets created by
118 // widgetCreator(). So it is mandatory to delete the group headers
119 // first.
120 delete m_groupHeaderCreator;
121 m_groupHeaderCreator = 0;
122
123 delete m_widgetCreator;
124 m_widgetCreator = 0;
125
126 delete m_sizeHintResolver;
127 m_sizeHintResolver = 0;
128 }
129
130 void KItemListView::setScrollOffset(qreal offset)
131 {
132 if (offset < 0) {
133 offset = 0;
134 }
135
136 const qreal previousOffset = m_layouter->scrollOffset();
137 if (offset == previousOffset) {
138 return;
139 }
140
141 m_layouter->setScrollOffset(offset);
142 m_animation->setScrollOffset(offset);
143
144 // Don't check whether the m_layoutTimer is active: Changing the
145 // scroll offset must always trigger a synchronous layout, otherwise
146 // the smooth-scrolling might get jerky.
147 doLayout(NoAnimation);
148 onScrollOffsetChanged(offset, previousOffset);
149 }
150
151 qreal KItemListView::scrollOffset() const
152 {
153 return m_layouter->scrollOffset();
154 }
155
156 qreal KItemListView::maximumScrollOffset() const
157 {
158 return m_layouter->maximumScrollOffset();
159 }
160
161 void KItemListView::setItemOffset(qreal offset)
162 {
163 if (m_layouter->itemOffset() == offset) {
164 return;
165 }
166
167 m_layouter->setItemOffset(offset);
168 if (m_headerWidget->isVisible()) {
169 m_headerWidget->setOffset(offset);
170 }
171
172 // Don't check whether the m_layoutTimer is active: Changing the
173 // item offset must always trigger a synchronous layout, otherwise
174 // the smooth-scrolling might get jerky.
175 doLayout(NoAnimation);
176 }
177
178 qreal KItemListView::itemOffset() const
179 {
180 return m_layouter->itemOffset();
181 }
182
183 qreal KItemListView::maximumItemOffset() const
184 {
185 return m_layouter->maximumItemOffset();
186 }
187
188 void KItemListView::setVisibleRoles(const QList<QByteArray>& roles)
189 {
190 const QList<QByteArray> previousRoles = m_visibleRoles;
191 m_visibleRoles = roles;
192 onVisibleRolesChanged(roles, previousRoles);
193
194 m_sizeHintResolver->clearCache();
195 m_layouter->markAsDirty();
196
197 if (m_itemSize.isEmpty()) {
198 m_headerWidget->setColumns(roles);
199 updatePreferredColumnWidths();
200 if (!m_headerWidget->automaticColumnResizing()) {
201 // The column-width of new roles are still 0. Apply the preferred
202 // column-width as default with.
203 foreach (const QByteArray& role, m_visibleRoles) {
204 if (m_headerWidget->columnWidth(role) == 0) {
205 const qreal width = m_headerWidget->preferredColumnWidth(role);
206 m_headerWidget->setColumnWidth(role, width);
207 }
208 }
209
210 applyColumnWidthsFromHeader();
211 }
212 }
213
214 const bool alternateBackgroundsChanged = m_itemSize.isEmpty() &&
215 ((roles.count() > 1 && previousRoles.count() <= 1) ||
216 (roles.count() <= 1 && previousRoles.count() > 1));
217
218 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
219 while (it.hasNext()) {
220 it.next();
221 KItemListWidget* widget = it.value();
222 widget->setVisibleRoles(roles);
223 if (alternateBackgroundsChanged) {
224 updateAlternateBackgroundForWidget(widget);
225 }
226 }
227
228 doLayout(NoAnimation);
229 }
230
231 QList<QByteArray> KItemListView::visibleRoles() const
232 {
233 return m_visibleRoles;
234 }
235
236 void KItemListView::setAutoScroll(bool enabled)
237 {
238 if (enabled && !m_autoScrollTimer) {
239 m_autoScrollTimer = new QTimer(this);
240 m_autoScrollTimer->setSingleShot(true);
241 connect(m_autoScrollTimer, SIGNAL(timeout()), this, SLOT(triggerAutoScrolling()));
242 m_autoScrollTimer->start(InitialAutoScrollDelay);
243 } else if (!enabled && m_autoScrollTimer) {
244 delete m_autoScrollTimer;
245 m_autoScrollTimer = 0;
246 }
247 }
248
249 bool KItemListView::autoScroll() const
250 {
251 return m_autoScrollTimer != 0;
252 }
253
254 void KItemListView::setEnabledSelectionToggles(bool enabled)
255 {
256 if (m_enabledSelectionToggles != enabled) {
257 m_enabledSelectionToggles = enabled;
258
259 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
260 while (it.hasNext()) {
261 it.next();
262 it.value()->setEnabledSelectionToggle(enabled);
263 }
264 }
265 }
266
267 bool KItemListView::enabledSelectionToggles() const
268 {
269 return m_enabledSelectionToggles;
270 }
271
272 KItemListController* KItemListView::controller() const
273 {
274 return m_controller;
275 }
276
277 KItemModelBase* KItemListView::model() const
278 {
279 return m_model;
280 }
281
282 void KItemListView::setWidgetCreator(KItemListWidgetCreatorBase* widgetCreator)
283 {
284 if (m_widgetCreator) {
285 delete m_widgetCreator;
286 }
287 m_widgetCreator = widgetCreator;
288 }
289
290 KItemListWidgetCreatorBase* KItemListView::widgetCreator() const
291 {
292 if (!m_widgetCreator) {
293 m_widgetCreator = defaultWidgetCreator();
294 }
295 return m_widgetCreator;
296 }
297
298 void KItemListView::setGroupHeaderCreator(KItemListGroupHeaderCreatorBase* groupHeaderCreator)
299 {
300 if (m_groupHeaderCreator) {
301 delete m_groupHeaderCreator;
302 }
303 m_groupHeaderCreator = groupHeaderCreator;
304 }
305
306 KItemListGroupHeaderCreatorBase* KItemListView::groupHeaderCreator() const
307 {
308 if (!m_groupHeaderCreator) {
309 m_groupHeaderCreator = defaultGroupHeaderCreator();
310 }
311 return m_groupHeaderCreator;
312 }
313
314 QSizeF KItemListView::itemSize() const
315 {
316 return m_itemSize;
317 }
318
319 const KItemListStyleOption& KItemListView::styleOption() const
320 {
321 return m_styleOption;
322 }
323
324 void KItemListView::setGeometry(const QRectF& rect)
325 {
326 QGraphicsWidget::setGeometry(rect);
327
328 if (!m_model) {
329 return;
330 }
331
332 const QSizeF newSize = rect.size();
333 if (m_itemSize.isEmpty()) {
334 m_headerWidget->resize(rect.width(), m_headerWidget->size().height());
335 if (m_headerWidget->automaticColumnResizing()) {
336 applyAutomaticColumnWidths();
337 } else {
338 const qreal requiredWidth = columnWidthsSum();
339 const QSizeF dynamicItemSize(qMax(newSize.width(), requiredWidth),
340 m_itemSize.height());
341 m_layouter->setItemSize(dynamicItemSize);
342 }
343
344 // Triggering a synchronous layout is fine from a performance point of view,
345 // as with dynamic item sizes no moving animation must be done.
346 m_layouter->setSize(newSize);
347 doLayout(NoAnimation);
348 } else {
349 const bool animate = !changesItemGridLayout(newSize,
350 m_layouter->itemSize(),
351 m_layouter->itemMargin());
352 m_layouter->setSize(newSize);
353
354 if (animate) {
355 // Trigger an asynchronous relayout with m_layoutTimer to prevent
356 // performance bottlenecks. If the timer is exceeded, an animated layout
357 // will be triggered.
358 if (!m_layoutTimer->isActive()) {
359 m_layoutTimer->start();
360 }
361 } else {
362 m_layoutTimer->stop();
363 doLayout(NoAnimation);
364 }
365 }
366 }
367
368 int KItemListView::itemAt(const QPointF& pos) const
369 {
370 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
371 while (it.hasNext()) {
372 it.next();
373
374 const KItemListWidget* widget = it.value();
375 const QPointF mappedPos = widget->mapFromItem(this, pos);
376 if (widget->contains(mappedPos)) {
377 return it.key();
378 }
379 }
380
381 return -1;
382 }
383
384 bool KItemListView::isAboveSelectionToggle(int index, const QPointF& pos) const
385 {
386 if (!m_enabledSelectionToggles) {
387 return false;
388 }
389
390 const KItemListWidget* widget = m_visibleItems.value(index);
391 if (widget) {
392 const QRectF selectionToggleRect = widget->selectionToggleRect();
393 if (!selectionToggleRect.isEmpty()) {
394 const QPointF mappedPos = widget->mapFromItem(this, pos);
395 return selectionToggleRect.contains(mappedPos);
396 }
397 }
398 return false;
399 }
400
401 bool KItemListView::isAboveExpansionToggle(int index, const QPointF& pos) const
402 {
403 const KItemListWidget* widget = m_visibleItems.value(index);
404 if (widget) {
405 const QRectF expansionToggleRect = widget->expansionToggleRect();
406 if (!expansionToggleRect.isEmpty()) {
407 const QPointF mappedPos = widget->mapFromItem(this, pos);
408 return expansionToggleRect.contains(mappedPos);
409 }
410 }
411 return false;
412 }
413
414 int KItemListView::firstVisibleIndex() const
415 {
416 return m_layouter->firstVisibleIndex();
417 }
418
419 int KItemListView::lastVisibleIndex() const
420 {
421 return m_layouter->lastVisibleIndex();
422 }
423
424 QSizeF KItemListView::itemSizeHint(int index) const
425 {
426 return widgetCreator()->itemSizeHint(index, this);
427 }
428
429 void KItemListView::setSupportsItemExpanding(bool supportsExpanding)
430 {
431 if (m_supportsItemExpanding != supportsExpanding) {
432 m_supportsItemExpanding = supportsExpanding;
433 updateSiblingsInformation();
434 onSupportsItemExpandingChanged(supportsExpanding);
435 }
436 }
437
438 bool KItemListView::supportsItemExpanding() const
439 {
440 return m_supportsItemExpanding;
441 }
442
443 QRectF KItemListView::itemRect(int index) const
444 {
445 return m_layouter->itemRect(index);
446 }
447
448 QRectF KItemListView::itemContextRect(int index) const
449 {
450 QRectF contextRect;
451
452 const KItemListWidget* widget = m_visibleItems.value(index);
453 if (widget) {
454 contextRect = widget->iconRect() | widget->textRect();
455 contextRect.translate(itemRect(index).topLeft());
456 }
457
458 return contextRect;
459 }
460
461 void KItemListView::scrollToItem(int index)
462 {
463 QRectF viewGeometry = geometry();
464 if (m_headerWidget->isVisible()) {
465 const qreal headerHeight = m_headerWidget->size().height();
466 viewGeometry.adjust(0, headerHeight, 0, 0);
467 }
468 const QRectF currentRect = itemRect(index);
469
470 if (!viewGeometry.contains(currentRect)) {
471 qreal newOffset = scrollOffset();
472 if (scrollOrientation() == Qt::Vertical) {
473 if (currentRect.top() < viewGeometry.top()) {
474 newOffset += currentRect.top() - viewGeometry.top();
475 } else if (currentRect.bottom() > viewGeometry.bottom()) {
476 newOffset += currentRect.bottom() - viewGeometry.bottom();
477 }
478 } else {
479 if (currentRect.left() < viewGeometry.left()) {
480 newOffset += currentRect.left() - viewGeometry.left();
481 } else if (currentRect.right() > viewGeometry.right()) {
482 newOffset += currentRect.right() - viewGeometry.right();
483 }
484 }
485
486 if (newOffset != scrollOffset()) {
487 emit scrollTo(newOffset);
488 }
489 }
490 }
491
492 void KItemListView::beginTransaction()
493 {
494 ++m_activeTransactions;
495 if (m_activeTransactions == 1) {
496 onTransactionBegin();
497 }
498 }
499
500 void KItemListView::endTransaction()
501 {
502 --m_activeTransactions;
503 if (m_activeTransactions < 0) {
504 m_activeTransactions = 0;
505 kWarning() << "Mismatch between beginTransaction()/endTransaction()";
506 }
507
508 if (m_activeTransactions == 0) {
509 onTransactionEnd();
510 doLayout(m_endTransactionAnimationHint);
511 m_endTransactionAnimationHint = Animation;
512 }
513 }
514
515 bool KItemListView::isTransactionActive() const
516 {
517 return m_activeTransactions > 0;
518 }
519
520 void KItemListView::setHeaderVisible(bool visible)
521 {
522 if (visible && !m_headerWidget->isVisible()) {
523 QStyleOptionHeader option;
524 const QSize headerSize = style()->sizeFromContents(QStyle::CT_HeaderSection,
525 &option, QSize());
526
527 m_headerWidget->setPos(0, 0);
528 m_headerWidget->resize(size().width(), headerSize.height());
529 m_headerWidget->setModel(m_model);
530 m_headerWidget->setColumns(m_visibleRoles);
531 m_headerWidget->setZValue(1);
532
533 connect(m_headerWidget, SIGNAL(columnWidthChanged(QByteArray,qreal,qreal)),
534 this, SLOT(slotHeaderColumnWidthChanged(QByteArray,qreal,qreal)));
535 connect(m_headerWidget, SIGNAL(columnMoved(QByteArray,int,int)),
536 this, SLOT(slotHeaderColumnMoved(QByteArray,int,int)));
537 connect(m_headerWidget, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
538 this, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)));
539 connect(m_headerWidget, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
540 this, SIGNAL(sortRoleChanged(QByteArray,QByteArray)));
541
542 m_layouter->setHeaderHeight(headerSize.height());
543 m_headerWidget->setVisible(true);
544 } else if (!visible && m_headerWidget->isVisible()) {
545 disconnect(m_headerWidget, SIGNAL(columnWidthChanged(QByteArray,qreal,qreal)),
546 this, SLOT(slotHeaderColumnWidthChanged(QByteArray,qreal,qreal)));
547 disconnect(m_headerWidget, SIGNAL(columnMoved(QByteArray,int,int)),
548 this, SLOT(slotHeaderColumnMoved(QByteArray,int,int)));
549 disconnect(m_headerWidget, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
550 this, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)));
551 disconnect(m_headerWidget, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
552 this, SIGNAL(sortRoleChanged(QByteArray,QByteArray)));
553
554 m_layouter->setHeaderHeight(0);
555 m_headerWidget->setVisible(false);
556 }
557 }
558
559 bool KItemListView::isHeaderVisible() const
560 {
561 return m_headerWidget->isVisible();
562 }
563
564 KItemListHeader* KItemListView::header() const
565 {
566 return m_header;
567 }
568
569 QPixmap KItemListView::createDragPixmap(const QSet<int>& indexes) const
570 {
571 QPixmap pixmap;
572
573 if (indexes.count() == 1) {
574 KItemListWidget* item = m_visibleItems.value(indexes.toList().first());
575 QGraphicsView* graphicsView = scene()->views()[0];
576 if (item && graphicsView) {
577 pixmap = item->createDragPixmap(0, graphicsView);
578 }
579 } else {
580 // TODO: Not implemented yet. Probably extend the interface
581 // from KItemListWidget::createDragPixmap() to return a pixmap
582 // that can be used for multiple indexes.
583 }
584
585 return pixmap;
586 }
587
588 void KItemListView::editRole(int index, const QByteArray& role)
589 {
590 KItemListWidget* widget = m_visibleItems.value(index);
591 if (!widget || m_editingRole) {
592 return;
593 }
594
595 m_editingRole = true;
596 widget->setEditedRole(role);
597
598 connect(widget, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
599 this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
600 connect(widget, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
601 this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
602 }
603
604 void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
605 {
606 QGraphicsWidget::paint(painter, option, widget);
607
608 if (m_rubberBand->isActive()) {
609 QRectF rubberBandRect = QRectF(m_rubberBand->startPosition(),
610 m_rubberBand->endPosition()).normalized();
611
612 const QPointF topLeft = rubberBandRect.topLeft();
613 if (scrollOrientation() == Qt::Vertical) {
614 rubberBandRect.moveTo(topLeft.x(), topLeft.y() - scrollOffset());
615 } else {
616 rubberBandRect.moveTo(topLeft.x() - scrollOffset(), topLeft.y());
617 }
618
619 QStyleOptionRubberBand opt;
620 opt.initFrom(widget);
621 opt.shape = QRubberBand::Rectangle;
622 opt.opaque = false;
623 opt.rect = rubberBandRect.toRect();
624 style()->drawControl(QStyle::CE_RubberBand, &opt, painter);
625 }
626
627 if (!m_dropIndicator.isEmpty()) {
628 const QRectF r = m_dropIndicator.toRect();
629
630 QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color();
631 painter->setPen(color);
632
633 // TODO: The following implementation works only for a vertical scroll-orientation
634 // and assumes a height of the m_draggingInsertIndicator of 1.
635 Q_ASSERT(r.height() == 1);
636 painter->drawLine(r.left() + 1, r.top(), r.right() - 1, r.top());
637
638 color.setAlpha(128);
639 painter->setPen(color);
640 painter->drawRect(r.left(), r.top() - 1, r.width() - 1, 2);
641 }
642 }
643
644 void KItemListView::setItemSize(const QSizeF& size)
645 {
646 const QSizeF previousSize = m_itemSize;
647 if (size == previousSize) {
648 return;
649 }
650
651 // Skip animations when the number of rows or columns
652 // are changed in the grid layout. Although the animation
653 // engine can handle this usecase, it looks obtrusive.
654 const bool animate = !changesItemGridLayout(m_layouter->size(),
655 size,
656 m_layouter->itemMargin());
657
658 const bool alternateBackgroundsChanged = (m_visibleRoles.count() > 1) &&
659 (( m_itemSize.isEmpty() && !size.isEmpty()) ||
660 (!m_itemSize.isEmpty() && size.isEmpty()));
661
662 m_itemSize = size;
663
664 if (alternateBackgroundsChanged) {
665 // For an empty item size alternate backgrounds are drawn if more than
666 // one role is shown. Assure that the backgrounds for visible items are
667 // updated when changing the size in this context.
668 updateAlternateBackgrounds();
669 }
670
671 if (size.isEmpty()) {
672 if (m_headerWidget->automaticColumnResizing()) {
673 updatePreferredColumnWidths();
674 } else {
675 // Only apply the changed height and respect the header widths
676 // set by the user
677 const qreal currentWidth = m_layouter->itemSize().width();
678 const QSizeF newSize(currentWidth, size.height());
679 m_layouter->setItemSize(newSize);
680 }
681 } else {
682 m_layouter->setItemSize(size);
683 }
684
685 m_sizeHintResolver->clearCache();
686 doLayout(animate ? Animation : NoAnimation);
687 onItemSizeChanged(size, previousSize);
688 }
689
690 void KItemListView::setStyleOption(const KItemListStyleOption& option)
691 {
692 const KItemListStyleOption previousOption = m_styleOption;
693 m_styleOption = option;
694
695 bool animate = true;
696 const QSizeF margin(option.horizontalMargin, option.verticalMargin);
697 if (margin != m_layouter->itemMargin()) {
698 // Skip animations when the number of rows or columns
699 // are changed in the grid layout. Although the animation
700 // engine can handle this usecase, it looks obtrusive.
701 animate = !changesItemGridLayout(m_layouter->size(),
702 m_layouter->itemSize(),
703 margin);
704 m_layouter->setItemMargin(margin);
705 }
706
707 if (m_grouped) {
708 updateGroupHeaderHeight();
709 }
710
711 if (animate && previousOption.maxTextSize != option.maxTextSize) {
712 // Animating a change of the maximum text size just results in expensive
713 // temporary eliding and clipping operations and does not look good visually.
714 animate = false;
715 }
716
717 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
718 while (it.hasNext()) {
719 it.next();
720 it.value()->setStyleOption(option);
721 }
722
723 m_sizeHintResolver->clearCache();
724 m_layouter->markAsDirty();
725 doLayout(animate ? Animation : NoAnimation);
726
727 if (m_itemSize.isEmpty()) {
728 updatePreferredColumnWidths();
729 }
730
731 onStyleOptionChanged(option, previousOption);
732 }
733
734 void KItemListView::setScrollOrientation(Qt::Orientation orientation)
735 {
736 const Qt::Orientation previousOrientation = m_layouter->scrollOrientation();
737 if (orientation == previousOrientation) {
738 return;
739 }
740
741 m_layouter->setScrollOrientation(orientation);
742 m_animation->setScrollOrientation(orientation);
743 m_sizeHintResolver->clearCache();
744
745 if (m_grouped) {
746 QMutableHashIterator<KItemListWidget*, KItemListGroupHeader*> it (m_visibleGroups);
747 while (it.hasNext()) {
748 it.next();
749 it.value()->setScrollOrientation(orientation);
750 }
751 updateGroupHeaderHeight();
752
753 }
754
755 doLayout(NoAnimation);
756
757 onScrollOrientationChanged(orientation, previousOrientation);
758 emit scrollOrientationChanged(orientation, previousOrientation);
759 }
760
761 Qt::Orientation KItemListView::scrollOrientation() const
762 {
763 return m_layouter->scrollOrientation();
764 }
765
766 KItemListWidgetCreatorBase* KItemListView::defaultWidgetCreator() const
767 {
768 return 0;
769 }
770
771 KItemListGroupHeaderCreatorBase* KItemListView::defaultGroupHeaderCreator() const
772 {
773 return 0;
774 }
775
776 void KItemListView::initializeItemListWidget(KItemListWidget* item)
777 {
778 Q_UNUSED(item);
779 }
780
781 bool KItemListView::itemSizeHintUpdateRequired(const QSet<QByteArray>& changedRoles) const
782 {
783 Q_UNUSED(changedRoles);
784 return true;
785 }
786
787 void KItemListView::onControllerChanged(KItemListController* current, KItemListController* previous)
788 {
789 Q_UNUSED(current);
790 Q_UNUSED(previous);
791 }
792
793 void KItemListView::onModelChanged(KItemModelBase* current, KItemModelBase* previous)
794 {
795 Q_UNUSED(current);
796 Q_UNUSED(previous);
797 }
798
799 void KItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous)
800 {
801 Q_UNUSED(current);
802 Q_UNUSED(previous);
803 }
804
805 void KItemListView::onItemSizeChanged(const QSizeF& current, const QSizeF& previous)
806 {
807 Q_UNUSED(current);
808 Q_UNUSED(previous);
809 }
810
811 void KItemListView::onScrollOffsetChanged(qreal current, qreal previous)
812 {
813 Q_UNUSED(current);
814 Q_UNUSED(previous);
815 }
816
817 void KItemListView::onVisibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous)
818 {
819 Q_UNUSED(current);
820 Q_UNUSED(previous);
821 }
822
823 void KItemListView::onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous)
824 {
825 Q_UNUSED(current);
826 Q_UNUSED(previous);
827 }
828
829 void KItemListView::onSupportsItemExpandingChanged(bool supportsExpanding)
830 {
831 Q_UNUSED(supportsExpanding);
832 }
833
834 void KItemListView::onTransactionBegin()
835 {
836 }
837
838 void KItemListView::onTransactionEnd()
839 {
840 }
841
842 bool KItemListView::event(QEvent* event)
843 {
844 // Forward all events to the controller and handle them there
845 if (!m_editingRole && m_controller && m_controller->processEvent(event, transform())) {
846 event->accept();
847 return true;
848 }
849 return QGraphicsWidget::event(event);
850 }
851
852 void KItemListView::mousePressEvent(QGraphicsSceneMouseEvent* event)
853 {
854 m_mousePos = transform().map(event->pos());
855 event->accept();
856 }
857
858 void KItemListView::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
859 {
860 QGraphicsWidget::mouseMoveEvent(event);
861
862 m_mousePos = transform().map(event->pos());
863 if (m_autoScrollTimer && !m_autoScrollTimer->isActive()) {
864 m_autoScrollTimer->start(InitialAutoScrollDelay);
865 }
866 }
867
868 void KItemListView::dragEnterEvent(QGraphicsSceneDragDropEvent* event)
869 {
870 event->setAccepted(true);
871 setAutoScroll(true);
872 }
873
874 void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
875 {
876 QGraphicsWidget::dragMoveEvent(event);
877
878 m_mousePos = transform().map(event->pos());
879 if (m_autoScrollTimer && !m_autoScrollTimer->isActive()) {
880 m_autoScrollTimer->start(InitialAutoScrollDelay);
881 }
882 }
883
884 void KItemListView::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
885 {
886 QGraphicsWidget::dragLeaveEvent(event);
887 setAutoScroll(false);
888 }
889
890 void KItemListView::dropEvent(QGraphicsSceneDragDropEvent* event)
891 {
892 QGraphicsWidget::dropEvent(event);
893 setAutoScroll(false);
894 }
895
896 QList<KItemListWidget*> KItemListView::visibleItemListWidgets() const
897 {
898 return m_visibleItems.values();
899 }
900
901 void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
902 {
903 if (m_itemSize.isEmpty()) {
904 updatePreferredColumnWidths(itemRanges);
905 }
906
907 const bool hasMultipleRanges = (itemRanges.count() > 1);
908 if (hasMultipleRanges) {
909 beginTransaction();
910 }
911
912 m_layouter->markAsDirty();
913
914 int previouslyInsertedCount = 0;
915 foreach (const KItemRange& range, itemRanges) {
916 // range.index is related to the model before anything has been inserted.
917 // As in each loop the current item-range gets inserted the index must
918 // be increased by the already previously inserted items.
919 const int index = range.index + previouslyInsertedCount;
920 const int count = range.count;
921 if (index < 0 || count <= 0) {
922 kWarning() << "Invalid item range (index:" << index << ", count:" << count << ")";
923 continue;
924 }
925 previouslyInsertedCount += count;
926
927 m_sizeHintResolver->itemsInserted(index, count);
928
929 // Determine which visible items must be moved
930 QList<int> itemsToMove;
931 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
932 while (it.hasNext()) {
933 it.next();
934 const int visibleItemIndex = it.key();
935 if (visibleItemIndex >= index) {
936 itemsToMove.append(visibleItemIndex);
937 }
938 }
939
940 // Update the indexes of all KItemListWidget instances that are located
941 // after the inserted items. It is important to adjust the indexes in the order
942 // from the highest index to the lowest index to prevent overlaps when setting the new index.
943 qSort(itemsToMove);
944 for (int i = itemsToMove.count() - 1; i >= 0; --i) {
945 KItemListWidget* widget = m_visibleItems.value(itemsToMove[i]);
946 Q_ASSERT(widget);
947 const int newIndex = widget->index() + count;
948 if (hasMultipleRanges) {
949 setWidgetIndex(widget, newIndex);
950 } else {
951 // Try to animate the moving of the item
952 moveWidgetToIndex(widget, newIndex);
953 }
954 }
955
956 if (m_model->count() == count && m_activeTransactions == 0) {
957 // Check whether a scrollbar is required to show the inserted items. In this case
958 // the size of the layouter will be decreased before calling doLayout(): This prevents
959 // an unnecessary temporary animation due to the geometry change of the inserted scrollbar.
960 const bool verticalScrollOrientation = (scrollOrientation() == Qt::Vertical);
961 const bool decreaseLayouterSize = ( verticalScrollOrientation && maximumScrollOffset() > size().height()) ||
962 (!verticalScrollOrientation && maximumScrollOffset() > size().width());
963 if (decreaseLayouterSize) {
964 const int scrollBarExtent = style()->pixelMetric(QStyle::PM_ScrollBarExtent);
965 QSizeF layouterSize = m_layouter->size();
966 if (verticalScrollOrientation) {
967 layouterSize.rwidth() -= scrollBarExtent;
968 } else {
969 layouterSize.rheight() -= scrollBarExtent;
970 }
971 m_layouter->setSize(layouterSize);
972 }
973 }
974
975 if (!hasMultipleRanges) {
976 doLayout(animateChangedItemCount(count) ? Animation : NoAnimation, index, count);
977 updateSiblingsInformation();
978 }
979 }
980
981 if (m_controller) {
982 m_controller->selectionManager()->itemsInserted(itemRanges);
983 }
984
985 if (hasMultipleRanges) {
986 #ifndef QT_NO_DEBUG
987 // Important: Don't read any m_layouter-property inside the for-loop in case if
988 // multiple ranges are given! m_layouter accesses m_sizeHintResolver which is
989 // updated in each loop-cycle and has only a consistent state after the loop.
990 Q_ASSERT(m_layouter->isDirty());
991 #endif
992 m_endTransactionAnimationHint = NoAnimation;
993 endTransaction();
994
995 updateSiblingsInformation();
996 }
997
998 if (m_grouped && (hasMultipleRanges || itemRanges.first().count < m_model->count())) {
999 // In case if items of the same group have been inserted before an item that
1000 // currently represents the first item of the group, the group header of
1001 // this item must be removed.
1002 updateVisibleGroupHeaders();
1003 }
1004
1005 if (useAlternateBackgrounds()) {
1006 updateAlternateBackgrounds();
1007 }
1008 }
1009
1010 void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
1011 {
1012 if (m_itemSize.isEmpty()) {
1013 // Don't pass the item-range: The preferred column-widths of
1014 // all items must be adjusted when removing items.
1015 updatePreferredColumnWidths();
1016 }
1017
1018 const bool hasMultipleRanges = (itemRanges.count() > 1);
1019 if (hasMultipleRanges) {
1020 beginTransaction();
1021 }
1022
1023 m_layouter->markAsDirty();
1024
1025 int removedItemsCount = 0;
1026 for (int i = 0; i < itemRanges.count(); ++i) {
1027 removedItemsCount += itemRanges[i].count;
1028 }
1029
1030 for (int i = itemRanges.count() - 1; i >= 0; --i) {
1031 const KItemRange& range = itemRanges[i];
1032 const int index = range.index;
1033 const int count = range.count;
1034 if (index < 0 || count <= 0) {
1035 kWarning() << "Invalid item range (index:" << index << ", count:" << count << ")";
1036 continue;
1037 }
1038
1039 m_sizeHintResolver->itemsRemoved(index, count);
1040
1041 const int firstRemovedIndex = index;
1042 const int lastRemovedIndex = index + count - 1;
1043 const int lastIndex = m_model->count() - 1 + removedItemsCount;
1044 removedItemsCount -= count;
1045
1046 // Remove all KItemListWidget instances that got deleted
1047 for (int i = firstRemovedIndex; i <= lastRemovedIndex; ++i) {
1048 KItemListWidget* widget = m_visibleItems.value(i);
1049 if (!widget) {
1050 continue;
1051 }
1052
1053 m_animation->stop(widget);
1054 // Stopping the animation might lead to recycling the widget if
1055 // it is invisible (see slotAnimationFinished()).
1056 // Check again whether it is still visible:
1057 if (!m_visibleItems.contains(i)) {
1058 continue;
1059 }
1060
1061 if (m_model->count() == 0 || hasMultipleRanges || !animateChangedItemCount(count)) {
1062 // Remove the widget without animation
1063 recycleWidget(widget);
1064 } else {
1065 // Animate the removing of the items. Special case: When removing an item there
1066 // is no valid model index available anymore. For the
1067 // remove-animation the item gets removed from m_visibleItems but the widget
1068 // will stay alive until the animation has been finished and will
1069 // be recycled (deleted) in KItemListView::slotAnimationFinished().
1070 m_visibleItems.remove(i);
1071 widget->setIndex(-1);
1072 m_animation->start(widget, KItemListViewAnimation::DeleteAnimation);
1073 }
1074 }
1075
1076 // Update the indexes of all KItemListWidget instances that are located
1077 // after the deleted items
1078 for (int i = lastRemovedIndex + 1; i <= lastIndex; ++i) {
1079 KItemListWidget* widget = m_visibleItems.value(i);
1080 if (widget) {
1081 const int newIndex = i - count;
1082 if (hasMultipleRanges) {
1083 setWidgetIndex(widget, newIndex);
1084 } else {
1085 // Try to animate the moving of the item
1086 moveWidgetToIndex(widget, newIndex);
1087 }
1088 }
1089 }
1090
1091 if (!hasMultipleRanges) {
1092 // The decrease-layout-size optimization in KItemListView::slotItemsInserted()
1093 // assumes an updated geometry. If items are removed during an active transaction,
1094 // the transaction will be temporary deactivated so that doLayout() triggers a
1095 // geometry update if necessary.
1096 const int activeTransactions = m_activeTransactions;
1097 m_activeTransactions = 0;
1098 doLayout(animateChangedItemCount(count) ? Animation : NoAnimation, index, -count);
1099 m_activeTransactions = activeTransactions;
1100 updateSiblingsInformation();
1101 }
1102 }
1103
1104 if (m_controller) {
1105 m_controller->selectionManager()->itemsRemoved(itemRanges);
1106 }
1107
1108 if (hasMultipleRanges) {
1109 #ifndef QT_NO_DEBUG
1110 // Important: Don't read any m_layouter-property inside the for-loop in case if
1111 // multiple ranges are given! m_layouter accesses m_sizeHintResolver which is
1112 // updated in each loop-cycle and has only a consistent state after the loop.
1113 Q_ASSERT(m_layouter->isDirty());
1114 #endif
1115 m_endTransactionAnimationHint = NoAnimation;
1116 endTransaction();
1117 updateSiblingsInformation();
1118 }
1119
1120 if (m_grouped && (hasMultipleRanges || m_model->count() > 0)) {
1121 // In case if the first item of a group has been removed, the group header
1122 // must be applied to the next visible item.
1123 updateVisibleGroupHeaders();
1124 }
1125
1126 if (useAlternateBackgrounds()) {
1127 updateAlternateBackgrounds();
1128 }
1129 }
1130
1131 void KItemListView::slotItemsMoved(const KItemRange& itemRange, const QList<int>& movedToIndexes)
1132 {
1133 m_sizeHintResolver->itemsMoved(itemRange.index, itemRange.count);
1134 m_layouter->markAsDirty();
1135
1136 if (m_controller) {
1137 m_controller->selectionManager()->itemsMoved(itemRange, movedToIndexes);
1138 }
1139
1140 const int firstVisibleMovedIndex = qMax(firstVisibleIndex(), itemRange.index);
1141 const int lastVisibleMovedIndex = qMin(lastVisibleIndex(), itemRange.index + itemRange.count - 1);
1142
1143 for (int index = firstVisibleMovedIndex; index <= lastVisibleMovedIndex; ++index) {
1144 KItemListWidget* widget = m_visibleItems.value(index);
1145 if (widget) {
1146 updateWidgetProperties(widget, index);
1147 initializeItemListWidget(widget);
1148 }
1149 }
1150
1151 doLayout(NoAnimation);
1152 updateSiblingsInformation();
1153 }
1154
1155 void KItemListView::slotItemsChanged(const KItemRangeList& itemRanges,
1156 const QSet<QByteArray>& roles)
1157 {
1158 const bool updateSizeHints = itemSizeHintUpdateRequired(roles);
1159 if (updateSizeHints && m_itemSize.isEmpty()) {
1160 updatePreferredColumnWidths(itemRanges);
1161 }
1162
1163 foreach (const KItemRange& itemRange, itemRanges) {
1164 const int index = itemRange.index;
1165 const int count = itemRange.count;
1166
1167 if (updateSizeHints) {
1168 m_sizeHintResolver->itemsChanged(index, count, roles);
1169 m_layouter->markAsDirty();
1170
1171 if (!m_layoutTimer->isActive()) {
1172 m_layoutTimer->start();
1173 }
1174 }
1175
1176 // Apply the changed roles to the visible item-widgets
1177 const int lastIndex = index + count - 1;
1178 for (int i = index; i <= lastIndex; ++i) {
1179 KItemListWidget* widget = m_visibleItems.value(i);
1180 if (widget) {
1181 widget->setData(m_model->data(i), roles);
1182 }
1183 }
1184
1185 if (m_grouped && roles.contains(m_model->sortRole())) {
1186 // The sort-role has been changed which might result
1187 // in modified group headers
1188 updateVisibleGroupHeaders();
1189 doLayout(NoAnimation);
1190 }
1191 }
1192 }
1193
1194 void KItemListView::slotGroupedSortingChanged(bool current)
1195 {
1196 m_grouped = current;
1197 m_layouter->markAsDirty();
1198
1199 if (m_grouped) {
1200 updateGroupHeaderHeight();
1201 } else {
1202 // Clear all visible headers
1203 QMutableHashIterator<KItemListWidget*, KItemListGroupHeader*> it (m_visibleGroups);
1204 while (it.hasNext()) {
1205 it.next();
1206 recycleGroupHeaderForWidget(it.key());
1207 }
1208 Q_ASSERT(m_visibleGroups.isEmpty());
1209 }
1210
1211 if (useAlternateBackgrounds()) {
1212 // Changing the group mode requires to update the alternate backgrounds
1213 // as with the enabled group mode the altering is done on base of the first
1214 // group item.
1215 updateAlternateBackgrounds();
1216 }
1217 updateSiblingsInformation();
1218 doLayout(NoAnimation);
1219 }
1220
1221 void KItemListView::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
1222 {
1223 Q_UNUSED(current);
1224 Q_UNUSED(previous);
1225 if (m_grouped) {
1226 updateVisibleGroupHeaders();
1227 doLayout(NoAnimation);
1228 }
1229 }
1230
1231 void KItemListView::slotSortRoleChanged(const QByteArray& current, const QByteArray& previous)
1232 {
1233 Q_UNUSED(current);
1234 Q_UNUSED(previous);
1235 if (m_grouped) {
1236 updateVisibleGroupHeaders();
1237 doLayout(NoAnimation);
1238 }
1239 }
1240
1241 void KItemListView::slotCurrentChanged(int current, int previous)
1242 {
1243 Q_UNUSED(previous);
1244
1245 KItemListWidget* previousWidget = m_visibleItems.value(previous, 0);
1246 if (previousWidget) {
1247 previousWidget->setCurrent(false);
1248 }
1249
1250 KItemListWidget* currentWidget = m_visibleItems.value(current, 0);
1251 if (currentWidget) {
1252 currentWidget->setCurrent(true);
1253 }
1254 }
1255
1256 void KItemListView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)
1257 {
1258 Q_UNUSED(previous);
1259
1260 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
1261 while (it.hasNext()) {
1262 it.next();
1263 const int index = it.key();
1264 KItemListWidget* widget = it.value();
1265 widget->setSelected(current.contains(index));
1266 }
1267 }
1268
1269 void KItemListView::slotAnimationFinished(QGraphicsWidget* widget,
1270 KItemListViewAnimation::AnimationType type)
1271 {
1272 KItemListWidget* itemListWidget = qobject_cast<KItemListWidget*>(widget);
1273 Q_ASSERT(itemListWidget);
1274
1275 switch (type) {
1276 case KItemListViewAnimation::DeleteAnimation: {
1277 // As we recycle the widget in this case it is important to assure that no
1278 // other animation has been started. This is a convention in KItemListView and
1279 // not a requirement defined by KItemListViewAnimation.
1280 Q_ASSERT(!m_animation->isStarted(itemListWidget));
1281
1282 // All KItemListWidgets that are animated by the DeleteAnimation are not maintained
1283 // by m_visibleWidgets and must be deleted manually after the animation has
1284 // been finished.
1285 recycleGroupHeaderForWidget(itemListWidget);
1286 widgetCreator()->recycle(itemListWidget);
1287 break;
1288 }
1289
1290 case KItemListViewAnimation::CreateAnimation:
1291 case KItemListViewAnimation::MovingAnimation:
1292 case KItemListViewAnimation::ResizeAnimation: {
1293 const int index = itemListWidget->index();
1294 const bool invisible = (index < m_layouter->firstVisibleIndex()) ||
1295 (index > m_layouter->lastVisibleIndex());
1296 if (invisible && !m_animation->isStarted(itemListWidget)) {
1297 recycleWidget(itemListWidget);
1298 }
1299 break;
1300 }
1301
1302 default: break;
1303 }
1304 }
1305
1306 void KItemListView::slotLayoutTimerFinished()
1307 {
1308 m_layouter->setSize(geometry().size());
1309 doLayout(Animation);
1310 }
1311
1312 void KItemListView::slotRubberBandPosChanged()
1313 {
1314 update();
1315 }
1316
1317 void KItemListView::slotRubberBandActivationChanged(bool active)
1318 {
1319 if (active) {
1320 connect(m_rubberBand, SIGNAL(startPositionChanged(QPointF,QPointF)), this, SLOT(slotRubberBandPosChanged()));
1321 connect(m_rubberBand, SIGNAL(endPositionChanged(QPointF,QPointF)), this, SLOT(slotRubberBandPosChanged()));
1322 m_skipAutoScrollForRubberBand = true;
1323 } else {
1324 disconnect(m_rubberBand, SIGNAL(startPositionChanged(QPointF,QPointF)), this, SLOT(slotRubberBandPosChanged()));
1325 disconnect(m_rubberBand, SIGNAL(endPositionChanged(QPointF,QPointF)), this, SLOT(slotRubberBandPosChanged()));
1326 m_skipAutoScrollForRubberBand = false;
1327 }
1328
1329 update();
1330 }
1331
1332 void KItemListView::slotHeaderColumnWidthChanged(const QByteArray& role,
1333 qreal currentWidth,
1334 qreal previousWidth)
1335 {
1336 Q_UNUSED(role);
1337 Q_UNUSED(currentWidth);
1338 Q_UNUSED(previousWidth);
1339
1340 m_headerWidget->setAutomaticColumnResizing(false);
1341 applyColumnWidthsFromHeader();
1342 doLayout(NoAnimation);
1343 }
1344
1345 void KItemListView::slotHeaderColumnMoved(const QByteArray& role,
1346 int currentIndex,
1347 int previousIndex)
1348 {
1349 Q_ASSERT(m_visibleRoles[previousIndex] == role);
1350
1351 const QList<QByteArray> previous = m_visibleRoles;
1352
1353 QList<QByteArray> current = m_visibleRoles;
1354 current.removeAt(previousIndex);
1355 current.insert(currentIndex, role);
1356
1357 setVisibleRoles(current);
1358
1359 emit visibleRolesChanged(current, previous);
1360 }
1361
1362 void KItemListView::triggerAutoScrolling()
1363 {
1364 if (!m_autoScrollTimer) {
1365 return;
1366 }
1367
1368 int pos = 0;
1369 int visibleSize = 0;
1370 if (scrollOrientation() == Qt::Vertical) {
1371 pos = m_mousePos.y();
1372 visibleSize = size().height();
1373 } else {
1374 pos = m_mousePos.x();
1375 visibleSize = size().width();
1376 }
1377
1378 if (m_autoScrollTimer->interval() == InitialAutoScrollDelay) {
1379 m_autoScrollIncrement = 0;
1380 }
1381
1382 m_autoScrollIncrement = calculateAutoScrollingIncrement(pos, visibleSize, m_autoScrollIncrement);
1383 if (m_autoScrollIncrement == 0) {
1384 // The mouse position is not above an autoscroll margin (the autoscroll timer
1385 // will be restarted in mouseMoveEvent())
1386 m_autoScrollTimer->stop();
1387 return;
1388 }
1389
1390 if (m_rubberBand->isActive() && m_skipAutoScrollForRubberBand) {
1391 // If a rubberband selection is ongoing the autoscrolling may only get triggered
1392 // if the direction of the rubberband is similar to the autoscroll direction. This
1393 // prevents that starting to create a rubberband within the autoscroll margins starts
1394 // an autoscrolling.
1395
1396 const qreal minDiff = 4; // Ignore any autoscrolling if the rubberband is very small
1397 const qreal diff = (scrollOrientation() == Qt::Vertical)
1398 ? m_rubberBand->endPosition().y() - m_rubberBand->startPosition().y()
1399 : m_rubberBand->endPosition().x() - m_rubberBand->startPosition().x();
1400 if (qAbs(diff) < minDiff || (m_autoScrollIncrement < 0 && diff > 0) || (m_autoScrollIncrement > 0 && diff < 0)) {
1401 // The rubberband direction is different from the scroll direction (e.g. the rubberband has
1402 // been moved up although the autoscroll direction might be down)
1403 m_autoScrollTimer->stop();
1404 return;
1405 }
1406 }
1407
1408 // As soon as the autoscrolling has been triggered at least once despite having an active rubberband,
1409 // the autoscrolling may not get skipped anymore until a new rubberband is created
1410 m_skipAutoScrollForRubberBand = false;
1411
1412 const qreal maxVisibleOffset = qMax(qreal(0), maximumScrollOffset() - visibleSize);
1413 const qreal newScrollOffset = qMin(scrollOffset() + m_autoScrollIncrement, maxVisibleOffset);
1414 setScrollOffset(newScrollOffset);
1415
1416 // Trigger the autoscroll timer which will periodically call
1417 // triggerAutoScrolling()
1418 m_autoScrollTimer->start(RepeatingAutoScrollDelay);
1419 }
1420
1421 void KItemListView::slotGeometryOfGroupHeaderParentChanged()
1422 {
1423 KItemListWidget* widget = qobject_cast<KItemListWidget*>(sender());
1424 Q_ASSERT(widget);
1425 KItemListGroupHeader* groupHeader = m_visibleGroups.value(widget);
1426 Q_ASSERT(groupHeader);
1427 updateGroupHeaderLayout(widget);
1428 }
1429
1430 void KItemListView::slotRoleEditingCanceled(int index, const QByteArray& role, const QVariant& value)
1431 {
1432 disconnectRoleEditingSignals(index);
1433
1434 emit roleEditingCanceled(index, role, value);
1435 m_editingRole = false;
1436 }
1437
1438 void KItemListView::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
1439 {
1440 disconnectRoleEditingSignals(index);
1441
1442 emit roleEditingFinished(index, role, value);
1443 m_editingRole = false;
1444 }
1445
1446 void KItemListView::setController(KItemListController* controller)
1447 {
1448 if (m_controller != controller) {
1449 KItemListController* previous = m_controller;
1450 if (previous) {
1451 KItemListSelectionManager* selectionManager = previous->selectionManager();
1452 disconnect(selectionManager, SIGNAL(currentChanged(int,int)), this, SLOT(slotCurrentChanged(int,int)));
1453 disconnect(selectionManager, SIGNAL(selectionChanged(QSet<int>,QSet<int>)), this, SLOT(slotSelectionChanged(QSet<int>,QSet<int>)));
1454 }
1455
1456 m_controller = controller;
1457
1458 if (controller) {
1459 KItemListSelectionManager* selectionManager = controller->selectionManager();
1460 connect(selectionManager, SIGNAL(currentChanged(int,int)), this, SLOT(slotCurrentChanged(int,int)));
1461 connect(selectionManager, SIGNAL(selectionChanged(QSet<int>,QSet<int>)), this, SLOT(slotSelectionChanged(QSet<int>,QSet<int>)));
1462 }
1463
1464 onControllerChanged(controller, previous);
1465 }
1466 }
1467
1468 void KItemListView::setModel(KItemModelBase* model)
1469 {
1470 if (m_model == model) {
1471 return;
1472 }
1473
1474 KItemModelBase* previous = m_model;
1475
1476 if (m_model) {
1477 disconnect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
1478 this, SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
1479 disconnect(m_model, SIGNAL(itemsInserted(KItemRangeList)),
1480 this, SLOT(slotItemsInserted(KItemRangeList)));
1481 disconnect(m_model, SIGNAL(itemsRemoved(KItemRangeList)),
1482 this, SLOT(slotItemsRemoved(KItemRangeList)));
1483 disconnect(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)),
1484 this, SLOT(slotItemsMoved(KItemRange,QList<int>)));
1485 disconnect(m_model, SIGNAL(groupedSortingChanged(bool)),
1486 this, SLOT(slotGroupedSortingChanged(bool)));
1487 disconnect(m_model, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
1488 this, SLOT(slotSortOrderChanged(Qt::SortOrder,Qt::SortOrder)));
1489 disconnect(m_model, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
1490 this, SLOT(slotSortRoleChanged(QByteArray,QByteArray)));
1491 }
1492
1493 m_sizeHintResolver->clearCache();
1494
1495 m_model = model;
1496 m_layouter->setModel(model);
1497 m_grouped = model->groupedSorting();
1498
1499 if (m_model) {
1500 connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
1501 this, SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
1502 connect(m_model, SIGNAL(itemsInserted(KItemRangeList)),
1503 this, SLOT(slotItemsInserted(KItemRangeList)));
1504 connect(m_model, SIGNAL(itemsRemoved(KItemRangeList)),
1505 this, SLOT(slotItemsRemoved(KItemRangeList)));
1506 connect(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)),
1507 this, SLOT(slotItemsMoved(KItemRange,QList<int>)));
1508 connect(m_model, SIGNAL(groupedSortingChanged(bool)),
1509 this, SLOT(slotGroupedSortingChanged(bool)));
1510 connect(m_model, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
1511 this, SLOT(slotSortOrderChanged(Qt::SortOrder,Qt::SortOrder)));
1512 connect(m_model, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
1513 this, SLOT(slotSortRoleChanged(QByteArray,QByteArray)));
1514
1515 const int itemCount = m_model->count();
1516 if (itemCount > 0) {
1517 m_sizeHintResolver->itemsInserted(0, itemCount);
1518 slotItemsInserted(KItemRangeList() << KItemRange(0, itemCount));
1519 }
1520 }
1521
1522 onModelChanged(model, previous);
1523 }
1524
1525 KItemListRubberBand* KItemListView::rubberBand() const
1526 {
1527 return m_rubberBand;
1528 }
1529
1530 void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int changedCount)
1531 {
1532 if (m_layoutTimer->isActive()) {
1533 m_layoutTimer->stop();
1534 }
1535
1536 if (m_activeTransactions > 0) {
1537 if (hint == NoAnimation) {
1538 // As soon as at least one property change should be done without animation,
1539 // the whole transaction will be marked as not animated.
1540 m_endTransactionAnimationHint = NoAnimation;
1541 }
1542 return;
1543 }
1544
1545 if (!m_model || m_model->count() < 0) {
1546 return;
1547 }
1548
1549 int firstVisibleIndex = m_layouter->firstVisibleIndex();
1550 if (firstVisibleIndex < 0) {
1551 emitOffsetChanges();
1552 return;
1553 }
1554
1555 // Do a sanity check of the scroll-offset property: When properties of the itemlist-view have been changed
1556 // it might be possible that the maximum offset got changed too. Assure that the full visible range
1557 // is still shown if the maximum offset got decreased.
1558 const qreal visibleOffsetRange = (scrollOrientation() == Qt::Horizontal) ? size().width() : size().height();
1559 const qreal maxOffsetToShowFullRange = maximumScrollOffset() - visibleOffsetRange;
1560 if (scrollOffset() > maxOffsetToShowFullRange) {
1561 m_layouter->setScrollOffset(qMax(qreal(0), maxOffsetToShowFullRange));
1562 firstVisibleIndex = m_layouter->firstVisibleIndex();
1563 }
1564
1565 const int lastVisibleIndex = m_layouter->lastVisibleIndex();
1566
1567 int firstSibblingIndex = -1;
1568 int lastSibblingIndex = -1;
1569 const bool supportsExpanding = supportsItemExpanding();
1570
1571 QList<int> reusableItems = recycleInvisibleItems(firstVisibleIndex, lastVisibleIndex, hint);
1572
1573 // Assure that for each visible item a KItemListWidget is available. KItemListWidget
1574 // instances from invisible items are reused. If no reusable items are
1575 // found then new KItemListWidget instances get created.
1576 const bool animate = (hint == Animation);
1577 for (int i = firstVisibleIndex; i <= lastVisibleIndex; ++i) {
1578 bool applyNewPos = true;
1579 bool wasHidden = false;
1580
1581 const QRectF itemBounds = m_layouter->itemRect(i);
1582 const QPointF newPos = itemBounds.topLeft();
1583 KItemListWidget* widget = m_visibleItems.value(i);
1584 if (!widget) {
1585 wasHidden = true;
1586 if (!reusableItems.isEmpty()) {
1587 // Reuse a KItemListWidget instance from an invisible item
1588 const int oldIndex = reusableItems.takeLast();
1589 widget = m_visibleItems.value(oldIndex);
1590 setWidgetIndex(widget, i);
1591 updateWidgetProperties(widget, i);
1592 initializeItemListWidget(widget);
1593 } else {
1594 // No reusable KItemListWidget instance is available, create a new one
1595 widget = createWidget(i);
1596 }
1597 widget->resize(itemBounds.size());
1598
1599 if (animate && changedCount < 0) {
1600 // Items have been deleted, move the created item to the
1601 // imaginary old position. They will get animated to the new position
1602 // later.
1603 const QRectF itemRect = m_layouter->itemRect(i - changedCount);
1604 if (itemRect.isEmpty()) {
1605 const QPointF invisibleOldPos = (scrollOrientation() == Qt::Vertical)
1606 ? QPointF(0, size().height()) : QPointF(size().width(), 0);
1607 widget->setPos(invisibleOldPos);
1608 } else {
1609 widget->setPos(itemRect.topLeft());
1610 }
1611 applyNewPos = false;
1612 }
1613
1614 if (supportsExpanding && changedCount == 0) {
1615 if (firstSibblingIndex < 0) {
1616 firstSibblingIndex = i;
1617 }
1618 lastSibblingIndex = i;
1619 }
1620 }
1621
1622 if (animate) {
1623 if (m_animation->isStarted(widget, KItemListViewAnimation::MovingAnimation)) {
1624 m_animation->start(widget, KItemListViewAnimation::MovingAnimation, newPos);
1625 applyNewPos = false;
1626 }
1627
1628 const bool itemsRemoved = (changedCount < 0);
1629 const bool itemsInserted = (changedCount > 0);
1630 if (itemsRemoved && (i >= changedIndex + changedCount + 1)) {
1631 // The item is located after the removed items. Animate the moving of the position.
1632 applyNewPos = !moveWidget(widget, newPos);
1633 } else if (itemsInserted && i >= changedIndex) {
1634 // The item is located after the first inserted item
1635 if (i <= changedIndex + changedCount - 1) {
1636 // The item is an inserted item. Animate the appearing of the item.
1637 // For performance reasons no animation is done when changedCount is equal
1638 // to all available items.
1639 if (changedCount < m_model->count()) {
1640 m_animation->start(widget, KItemListViewAnimation::CreateAnimation);
1641 }
1642 } else if (!m_animation->isStarted(widget, KItemListViewAnimation::CreateAnimation)) {
1643 // The item was already there before, so animate the moving of the position.
1644 // No moving animation is done if the item is animated by a create animation: This
1645 // prevents a "move animation mess" when inserting several ranges in parallel.
1646 applyNewPos = !moveWidget(widget, newPos);
1647 }
1648 } else if (!itemsRemoved && !itemsInserted && !wasHidden) {
1649 // The size of the view might have been changed. Animate the moving of the position.
1650 applyNewPos = !moveWidget(widget, newPos);
1651 }
1652 } else {
1653 m_animation->stop(widget);
1654 }
1655
1656 if (applyNewPos) {
1657 widget->setPos(newPos);
1658 }
1659
1660 Q_ASSERT(widget->index() == i);
1661 widget->setVisible(true);
1662
1663 if (widget->size() != itemBounds.size()) {
1664 // Resize the widget for the item to the changed size.
1665 if (animate) {
1666 // If a dynamic item size is used then no animation is done in the direction
1667 // of the dynamic size.
1668 if (m_itemSize.width() <= 0) {
1669 // The width is dynamic, apply the new width without animation.
1670 widget->resize(itemBounds.width(), widget->size().height());
1671 } else if (m_itemSize.height() <= 0) {
1672 // The height is dynamic, apply the new height without animation.
1673 widget->resize(widget->size().width(), itemBounds.height());
1674 }
1675 m_animation->start(widget, KItemListViewAnimation::ResizeAnimation, itemBounds.size());
1676 } else {
1677 widget->resize(itemBounds.size());
1678 }
1679 }
1680
1681 // Updating the cell-information must be done as last step: The decision whether the
1682 // moving-animation should be started at all is based on the previous cell-information.
1683 const Cell cell(m_layouter->itemColumn(i), m_layouter->itemRow(i));
1684 m_visibleCells.insert(i, cell);
1685 }
1686
1687 // Delete invisible KItemListWidget instances that have not been reused
1688 foreach (int index, reusableItems) {
1689 recycleWidget(m_visibleItems.value(index));
1690 }
1691
1692 if (supportsExpanding && firstSibblingIndex >= 0) {
1693 Q_ASSERT(lastSibblingIndex >= 0);
1694 updateSiblingsInformation(firstSibblingIndex, lastSibblingIndex);
1695 }
1696
1697 if (m_grouped) {
1698 // Update the layout of all visible group headers
1699 QHashIterator<KItemListWidget*, KItemListGroupHeader*> it(m_visibleGroups);
1700 while (it.hasNext()) {
1701 it.next();
1702 updateGroupHeaderLayout(it.key());
1703 }
1704 }
1705
1706 emitOffsetChanges();
1707 }
1708
1709 QList<int> KItemListView::recycleInvisibleItems(int firstVisibleIndex,
1710 int lastVisibleIndex,
1711 LayoutAnimationHint hint)
1712 {
1713 // Determine all items that are completely invisible and might be
1714 // reused for items that just got (at least partly) visible. If the
1715 // animation hint is set to 'Animation' items that do e.g. an animated
1716 // moving of their position are not marked as invisible: This assures
1717 // that a scrolling inside the view can be done without breaking an animation.
1718
1719 QList<int> items;
1720
1721 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
1722 while (it.hasNext()) {
1723 it.next();
1724
1725 KItemListWidget* widget = it.value();
1726 const int index = widget->index();
1727 const bool invisible = (index < firstVisibleIndex) || (index > lastVisibleIndex);
1728
1729 if (invisible) {
1730 if (m_animation->isStarted(widget)) {
1731 if (hint == NoAnimation) {
1732 // Stopping the animation will call KItemListView::slotAnimationFinished()
1733 // and the widget will be recycled if necessary there.
1734 m_animation->stop(widget);
1735 }
1736 } else {
1737 widget->setVisible(false);
1738 items.append(index);
1739
1740 if (m_grouped) {
1741 recycleGroupHeaderForWidget(widget);
1742 }
1743 }
1744 }
1745 }
1746
1747 return items;
1748 }
1749
1750 bool KItemListView::moveWidget(KItemListWidget* widget,const QPointF& newPos)
1751 {
1752 if (widget->pos() == newPos) {
1753 return false;
1754 }
1755
1756 bool startMovingAnim = false;
1757
1758 if (m_itemSize.isEmpty()) {
1759 // The items are not aligned in a grid but either as columns or rows.
1760 startMovingAnim = true;
1761 } else {
1762 // When having a grid the moving-animation should only be started, if it is done within
1763 // one row in the vertical scroll-orientation or one column in the horizontal scroll-orientation.
1764 // Otherwise instead of a moving-animation a create-animation on the new position will be used
1765 // instead. This is done to prevent overlapping (and confusing) moving-animations.
1766 const int index = widget->index();
1767 const Cell cell = m_visibleCells.value(index);
1768 if (cell.column >= 0 && cell.row >= 0) {
1769 if (scrollOrientation() == Qt::Vertical) {
1770 startMovingAnim = (cell.row == m_layouter->itemRow(index));
1771 } else {
1772 startMovingAnim = (cell.column == m_layouter->itemColumn(index));
1773 }
1774 }
1775 }
1776
1777 if (startMovingAnim) {
1778 m_animation->start(widget, KItemListViewAnimation::MovingAnimation, newPos);
1779 return true;
1780 }
1781
1782 m_animation->stop(widget);
1783 m_animation->start(widget, KItemListViewAnimation::CreateAnimation);
1784 return false;
1785 }
1786
1787 void KItemListView::emitOffsetChanges()
1788 {
1789 const qreal newScrollOffset = m_layouter->scrollOffset();
1790 if (m_oldScrollOffset != newScrollOffset) {
1791 emit scrollOffsetChanged(newScrollOffset, m_oldScrollOffset);
1792 m_oldScrollOffset = newScrollOffset;
1793 }
1794
1795 const qreal newMaximumScrollOffset = m_layouter->maximumScrollOffset();
1796 if (m_oldMaximumScrollOffset != newMaximumScrollOffset) {
1797 emit maximumScrollOffsetChanged(newMaximumScrollOffset, m_oldMaximumScrollOffset);
1798 m_oldMaximumScrollOffset = newMaximumScrollOffset;
1799 }
1800
1801 const qreal newItemOffset = m_layouter->itemOffset();
1802 if (m_oldItemOffset != newItemOffset) {
1803 emit itemOffsetChanged(newItemOffset, m_oldItemOffset);
1804 m_oldItemOffset = newItemOffset;
1805 }
1806
1807 const qreal newMaximumItemOffset = m_layouter->maximumItemOffset();
1808 if (m_oldMaximumItemOffset != newMaximumItemOffset) {
1809 emit maximumItemOffsetChanged(newMaximumItemOffset, m_oldMaximumItemOffset);
1810 m_oldMaximumItemOffset = newMaximumItemOffset;
1811 }
1812 }
1813
1814 KItemListWidget* KItemListView::createWidget(int index)
1815 {
1816 KItemListWidget* widget = widgetCreator()->create(this);
1817 widget->setFlag(QGraphicsItem::ItemStacksBehindParent);
1818
1819 m_visibleItems.insert(index, widget);
1820 m_visibleCells.insert(index, Cell());
1821 updateWidgetProperties(widget, index);
1822 initializeItemListWidget(widget);
1823 return widget;
1824 }
1825
1826 void KItemListView::recycleWidget(KItemListWidget* widget)
1827 {
1828 if (m_grouped) {
1829 recycleGroupHeaderForWidget(widget);
1830 }
1831
1832 const int index = widget->index();
1833 m_visibleItems.remove(index);
1834 m_visibleCells.remove(index);
1835
1836 widgetCreator()->recycle(widget);
1837 }
1838
1839 void KItemListView::setWidgetIndex(KItemListWidget* widget, int index)
1840 {
1841 const int oldIndex = widget->index();
1842 m_visibleItems.remove(oldIndex);
1843 m_visibleCells.remove(oldIndex);
1844
1845 m_visibleItems.insert(index, widget);
1846 m_visibleCells.insert(index, Cell());
1847
1848 widget->setIndex(index);
1849 }
1850
1851 void KItemListView::moveWidgetToIndex(KItemListWidget* widget, int index)
1852 {
1853 const int oldIndex = widget->index();
1854 const Cell oldCell = m_visibleCells.value(oldIndex);
1855
1856 setWidgetIndex(widget, index);
1857
1858 const Cell newCell(m_layouter->itemColumn(index), m_layouter->itemRow(index));
1859 const bool vertical = (scrollOrientation() == Qt::Vertical);
1860 const bool updateCell = (vertical && oldCell.row == newCell.row) ||
1861 (!vertical && oldCell.column == newCell.column);
1862 if (updateCell) {
1863 m_visibleCells.insert(index, newCell);
1864 }
1865 }
1866
1867 void KItemListView::setLayouterSize(const QSizeF& size, SizeType sizeType)
1868 {
1869 switch (sizeType) {
1870 case LayouterSize: m_layouter->setSize(size); break;
1871 case ItemSize: m_layouter->setItemSize(size); break;
1872 default: break;
1873 }
1874 }
1875
1876 void KItemListView::updateWidgetProperties(KItemListWidget* widget, int index)
1877 {
1878 widget->setVisibleRoles(m_visibleRoles);
1879 updateWidgetColumnWidths(widget);
1880 widget->setStyleOption(m_styleOption);
1881
1882 const KItemListSelectionManager* selectionManager = m_controller->selectionManager();
1883 widget->setCurrent(index == selectionManager->currentItem());
1884 widget->setSelected(selectionManager->isSelected(index));
1885 widget->setHovered(false);
1886 widget->setEnabledSelectionToggle(enabledSelectionToggles());
1887 widget->setIndex(index);
1888 widget->setData(m_model->data(index));
1889 widget->setSiblingsInformation(QBitArray());
1890 updateAlternateBackgroundForWidget(widget);
1891
1892 if (m_grouped) {
1893 updateGroupHeaderForWidget(widget);
1894 }
1895 }
1896
1897 void KItemListView::updateGroupHeaderForWidget(KItemListWidget* widget)
1898 {
1899 Q_ASSERT(m_grouped);
1900
1901 const int index = widget->index();
1902 if (!m_layouter->isFirstGroupItem(index)) {
1903 // The widget does not represent the first item of a group
1904 // and hence requires no header
1905 recycleGroupHeaderForWidget(widget);
1906 return;
1907 }
1908
1909 const QList<QPair<int, QVariant> > groups = model()->groups();
1910 if (groups.isEmpty() || !groupHeaderCreator()) {
1911 return;
1912 }
1913
1914 KItemListGroupHeader* groupHeader = m_visibleGroups.value(widget);
1915 if (!groupHeader) {
1916 groupHeader = groupHeaderCreator()->create(this);
1917 groupHeader->setParentItem(widget);
1918 m_visibleGroups.insert(widget, groupHeader);
1919 connect(widget, SIGNAL(geometryChanged()), this, SLOT(slotGeometryOfGroupHeaderParentChanged()));
1920 }
1921 Q_ASSERT(groupHeader->parentItem() == widget);
1922
1923 const int groupIndex = groupIndexForItem(index);
1924 Q_ASSERT(groupIndex >= 0);
1925 groupHeader->setData(groups.at(groupIndex).second);
1926 groupHeader->setRole(model()->sortRole());
1927 groupHeader->setStyleOption(m_styleOption);
1928 groupHeader->setScrollOrientation(scrollOrientation());
1929 groupHeader->setItemIndex(index);
1930
1931 groupHeader->show();
1932 }
1933
1934 void KItemListView::updateGroupHeaderLayout(KItemListWidget* widget)
1935 {
1936 KItemListGroupHeader* groupHeader = m_visibleGroups.value(widget);
1937 Q_ASSERT(groupHeader);
1938
1939 const int index = widget->index();
1940 const QRectF groupHeaderRect = m_layouter->groupHeaderRect(index);
1941 const QRectF itemRect = m_layouter->itemRect(index);
1942
1943 // The group-header is a child of the itemlist widget. Translate the
1944 // group header position to the relative position.
1945 if (scrollOrientation() == Qt::Vertical) {
1946 // In the vertical scroll orientation the group header should always span
1947 // the whole width no matter which temporary position the parent widget
1948 // has. In this case the x-position and width will be adjusted manually.
1949 const qreal x = -widget->x() - itemOffset();
1950 const qreal width = maximumItemOffset();
1951 groupHeader->setPos(x, -groupHeaderRect.height());
1952 groupHeader->resize(width, groupHeaderRect.size().height());
1953 } else {
1954 groupHeader->setPos(groupHeaderRect.x() - itemRect.x(), -widget->y());
1955 groupHeader->resize(groupHeaderRect.size());
1956 }
1957 }
1958
1959 void KItemListView::recycleGroupHeaderForWidget(KItemListWidget* widget)
1960 {
1961 KItemListGroupHeader* header = m_visibleGroups.value(widget);
1962 if (header) {
1963 header->setParentItem(0);
1964 groupHeaderCreator()->recycle(header);
1965 m_visibleGroups.remove(widget);
1966 disconnect(widget, SIGNAL(geometryChanged()), this, SLOT(slotGeometryOfGroupHeaderParentChanged()));
1967 }
1968 }
1969
1970 void KItemListView::updateVisibleGroupHeaders()
1971 {
1972 Q_ASSERT(m_grouped);
1973 m_layouter->markAsDirty();
1974
1975 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
1976 while (it.hasNext()) {
1977 it.next();
1978 updateGroupHeaderForWidget(it.value());
1979 }
1980 }
1981
1982 int KItemListView::groupIndexForItem(int index) const
1983 {
1984 Q_ASSERT(m_grouped);
1985
1986 const QList<QPair<int, QVariant> > groups = model()->groups();
1987 if (groups.isEmpty()) {
1988 return -1;
1989 }
1990
1991 int min = 0;
1992 int max = groups.count() - 1;
1993 int mid = 0;
1994 do {
1995 mid = (min + max) / 2;
1996 if (index > groups[mid].first) {
1997 min = mid + 1;
1998 } else {
1999 max = mid - 1;
2000 }
2001 } while (groups[mid].first != index && min <= max);
2002
2003 if (min > max) {
2004 while (groups[mid].first > index && mid > 0) {
2005 --mid;
2006 }
2007 }
2008
2009 return mid;
2010 }
2011
2012 void KItemListView::updateAlternateBackgrounds()
2013 {
2014 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
2015 while (it.hasNext()) {
2016 it.next();
2017 updateAlternateBackgroundForWidget(it.value());
2018 }
2019 }
2020
2021 void KItemListView::updateAlternateBackgroundForWidget(KItemListWidget* widget)
2022 {
2023 bool enabled = useAlternateBackgrounds();
2024 if (enabled) {
2025 const int index = widget->index();
2026 enabled = (index & 0x1) > 0;
2027 if (m_grouped) {
2028 const int groupIndex = groupIndexForItem(index);
2029 if (groupIndex >= 0) {
2030 const QList<QPair<int, QVariant> > groups = model()->groups();
2031 const int indexOfFirstGroupItem = groups[groupIndex].first;
2032 const int relativeIndex = index - indexOfFirstGroupItem;
2033 enabled = (relativeIndex & 0x1) > 0;
2034 }
2035 }
2036 }
2037 widget->setAlternateBackground(enabled);
2038 }
2039
2040 bool KItemListView::useAlternateBackgrounds() const
2041 {
2042 return m_itemSize.isEmpty() && m_visibleRoles.count() > 1;
2043 }
2044
2045 QHash<QByteArray, qreal> KItemListView::preferredColumnWidths(const KItemRangeList& itemRanges) const
2046 {
2047 QElapsedTimer timer;
2048 timer.start();
2049
2050 QHash<QByteArray, qreal> widths;
2051
2052 // Calculate the minimum width for each column that is required
2053 // to show the headline unclipped.
2054 const QFontMetricsF fontMetrics(m_headerWidget->font());
2055 const int gripMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderGripMargin);
2056 const int headerMargin = m_headerWidget->style()->pixelMetric(QStyle::PM_HeaderMargin);
2057 foreach (const QByteArray& visibleRole, visibleRoles()) {
2058 const QString headerText = m_model->roleDescription(visibleRole);
2059 const qreal headerWidth = fontMetrics.width(headerText) + gripMargin + headerMargin * 2;
2060 widths.insert(visibleRole, headerWidth);
2061 }
2062
2063 // Calculate the preferred column withs for each item and ignore values
2064 // smaller than the width for showing the headline unclipped.
2065 const KItemListWidgetCreatorBase* creator = widgetCreator();
2066 int calculatedItemCount = 0;
2067 bool maxTimeExceeded = false;
2068 foreach (const KItemRange& itemRange, itemRanges) {
2069 const int startIndex = itemRange.index;
2070 const int endIndex = startIndex + itemRange.count - 1;
2071
2072 for (int i = startIndex; i <= endIndex; ++i) {
2073 foreach (const QByteArray& visibleRole, visibleRoles()) {
2074 qreal maxWidth = widths.value(visibleRole, 0);
2075 const qreal width = creator->preferredRoleColumnWidth(visibleRole, i, this);
2076 maxWidth = qMax(width, maxWidth);
2077 widths.insert(visibleRole, maxWidth);
2078 }
2079
2080 if (calculatedItemCount > 100 && timer.elapsed() > 200) {
2081 // When having several thousands of items calculating the sizes can get
2082 // very expensive. We accept a possibly too small role-size in favour
2083 // of having no blocking user interface.
2084 maxTimeExceeded = true;
2085 break;
2086 }
2087 ++calculatedItemCount;
2088 }
2089 if (maxTimeExceeded) {
2090 break;
2091 }
2092 }
2093
2094 return widths;
2095 }
2096
2097 void KItemListView::applyColumnWidthsFromHeader()
2098 {
2099 // Apply the new size to the layouter
2100 const qreal requiredWidth = columnWidthsSum();
2101 const QSizeF dynamicItemSize(qMax(size().width(), requiredWidth),
2102 m_itemSize.height());
2103 m_layouter->setItemSize(dynamicItemSize);
2104
2105 // Update the role sizes for all visible widgets
2106 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
2107 while (it.hasNext()) {
2108 it.next();
2109 updateWidgetColumnWidths(it.value());
2110 }
2111 }
2112
2113 void KItemListView::updateWidgetColumnWidths(KItemListWidget* widget)
2114 {
2115 foreach (const QByteArray& role, m_visibleRoles) {
2116 widget->setColumnWidth(role, m_headerWidget->columnWidth(role));
2117 }
2118 }
2119
2120 void KItemListView::updatePreferredColumnWidths(const KItemRangeList& itemRanges)
2121 {
2122 Q_ASSERT(m_itemSize.isEmpty());
2123 const int itemCount = m_model->count();
2124 int rangesItemCount = 0;
2125 foreach (const KItemRange& range, itemRanges) {
2126 rangesItemCount += range.count;
2127 }
2128
2129 if (itemCount == rangesItemCount) {
2130 const QHash<QByteArray, qreal> preferredWidths = preferredColumnWidths(itemRanges);
2131 foreach (const QByteArray& role, m_visibleRoles) {
2132 m_headerWidget->setPreferredColumnWidth(role, preferredWidths.value(role));
2133 }
2134 } else {
2135 // Only a sub range of the roles need to be determined.
2136 // The chances are good that the widths of the sub ranges
2137 // already fit into the available widths and hence no
2138 // expensive update might be required.
2139 bool changed = false;
2140
2141 const QHash<QByteArray, qreal> updatedWidths = preferredColumnWidths(itemRanges);
2142 QHashIterator<QByteArray, qreal> it(updatedWidths);
2143 while (it.hasNext()) {
2144 it.next();
2145 const QByteArray& role = it.key();
2146 const qreal updatedWidth = it.value();
2147 const qreal currentWidth = m_headerWidget->preferredColumnWidth(role);
2148 if (updatedWidth > currentWidth) {
2149 m_headerWidget->setPreferredColumnWidth(role, updatedWidth);
2150 changed = true;
2151 }
2152 }
2153
2154 if (!changed) {
2155 // All the updated sizes are smaller than the current sizes and no change
2156 // of the stretched roles-widths is required
2157 return;
2158 }
2159 }
2160
2161 if (m_headerWidget->automaticColumnResizing()) {
2162 applyAutomaticColumnWidths();
2163 }
2164 }
2165
2166 void KItemListView::updatePreferredColumnWidths()
2167 {
2168 if (m_model) {
2169 updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model->count()));
2170 }
2171 }
2172
2173 void KItemListView::applyAutomaticColumnWidths()
2174 {
2175 Q_ASSERT(m_itemSize.isEmpty());
2176 Q_ASSERT(m_headerWidget->automaticColumnResizing());
2177 if (m_visibleRoles.isEmpty()) {
2178 return;
2179 }
2180
2181 // Calculate the maximum size of an item by considering the
2182 // visible role sizes and apply them to the layouter. If the
2183 // size does not use the available view-size the size of the
2184 // first role will get stretched.
2185
2186 foreach (const QByteArray& role, m_visibleRoles) {
2187 const qreal preferredWidth = m_headerWidget->preferredColumnWidth(role);
2188 m_headerWidget->setColumnWidth(role, preferredWidth);
2189 }
2190
2191 const QByteArray firstRole = m_visibleRoles.first();
2192 qreal firstColumnWidth = m_headerWidget->columnWidth(firstRole);
2193 QSizeF dynamicItemSize = m_itemSize;
2194
2195 qreal requiredWidth = columnWidthsSum();
2196 const qreal availableWidth = size().width();
2197 if (requiredWidth < availableWidth) {
2198 // Stretch the first column to use the whole remaining width
2199 firstColumnWidth += availableWidth - requiredWidth;
2200 m_headerWidget->setColumnWidth(firstRole, firstColumnWidth);
2201 } else if (requiredWidth > availableWidth && m_visibleRoles.count() > 1) {
2202 // Shrink the first column to be able to show as much other
2203 // columns as possible
2204 qreal shrinkedFirstColumnWidth = firstColumnWidth - requiredWidth + availableWidth;
2205
2206 // TODO: A proper calculation of the minimum width depends on the implementation
2207 // of KItemListWidget. Probably a kind of minimum size-hint should be introduced
2208 // later.
2209 const qreal minWidth = qMin(firstColumnWidth, qreal(m_styleOption.iconSize * 2 + 200));
2210 if (shrinkedFirstColumnWidth < minWidth) {
2211 shrinkedFirstColumnWidth = minWidth;
2212 }
2213
2214 m_headerWidget->setColumnWidth(firstRole, shrinkedFirstColumnWidth);
2215 requiredWidth -= firstColumnWidth - shrinkedFirstColumnWidth;
2216 }
2217
2218 dynamicItemSize.rwidth() = qMax(requiredWidth, availableWidth);
2219
2220 m_layouter->setItemSize(dynamicItemSize);
2221
2222 // Update the role sizes for all visible widgets
2223 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
2224 while (it.hasNext()) {
2225 it.next();
2226 updateWidgetColumnWidths(it.value());
2227 }
2228 }
2229
2230 qreal KItemListView::columnWidthsSum() const
2231 {
2232 qreal widthsSum = 0;
2233 foreach (const QByteArray& role, m_visibleRoles) {
2234 widthsSum += m_headerWidget->columnWidth(role);
2235 }
2236 return widthsSum;
2237 }
2238
2239 QRectF KItemListView::headerBoundaries() const
2240 {
2241 return m_headerWidget->isVisible() ? m_headerWidget->geometry() : QRectF();
2242 }
2243
2244 bool KItemListView::changesItemGridLayout(const QSizeF& newGridSize,
2245 const QSizeF& newItemSize,
2246 const QSizeF& newItemMargin) const
2247 {
2248 if (newItemSize.isEmpty() || newGridSize.isEmpty()) {
2249 return false;
2250 }
2251
2252 if (m_layouter->scrollOrientation() == Qt::Vertical) {
2253 const qreal itemWidth = m_layouter->itemSize().width();
2254 if (itemWidth > 0) {
2255 const int newColumnCount = itemsPerSize(newGridSize.width(),
2256 newItemSize.width(),
2257 newItemMargin.width());
2258 if (m_model->count() > newColumnCount) {
2259 const int oldColumnCount = itemsPerSize(m_layouter->size().width(),
2260 itemWidth,
2261 m_layouter->itemMargin().width());
2262 return oldColumnCount != newColumnCount;
2263 }
2264 }
2265 } else {
2266 const qreal itemHeight = m_layouter->itemSize().height();
2267 if (itemHeight > 0) {
2268 const int newRowCount = itemsPerSize(newGridSize.height(),
2269 newItemSize.height(),
2270 newItemMargin.height());
2271 if (m_model->count() > newRowCount) {
2272 const int oldRowCount = itemsPerSize(m_layouter->size().height(),
2273 itemHeight,
2274 m_layouter->itemMargin().height());
2275 return oldRowCount != newRowCount;
2276 }
2277 }
2278 }
2279
2280 return false;
2281 }
2282
2283 bool KItemListView::animateChangedItemCount(int changedItemCount) const
2284 {
2285 if (m_itemSize.isEmpty()) {
2286 // We have only columns or only rows, but no grid: An animation is usually
2287 // welcome when inserting or removing items.
2288 return !supportsItemExpanding();
2289 }
2290
2291 if (m_layouter->size().isEmpty() || m_layouter->itemSize().isEmpty()) {
2292 return false;
2293 }
2294
2295 const int maximum = (scrollOrientation() == Qt::Vertical)
2296 ? m_layouter->size().width() / m_layouter->itemSize().width()
2297 : m_layouter->size().height() / m_layouter->itemSize().height();
2298 // Only animate if up to 2/3 of a row or column are inserted or removed
2299 return changedItemCount <= maximum * 2 / 3;
2300 }
2301
2302
2303 bool KItemListView::scrollBarRequired(const QSizeF& size) const
2304 {
2305 const QSizeF oldSize = m_layouter->size();
2306
2307 m_layouter->setSize(size);
2308 const qreal maxOffset = m_layouter->maximumScrollOffset();
2309 m_layouter->setSize(oldSize);
2310
2311 return m_layouter->scrollOrientation() == Qt::Vertical ? maxOffset > size.height()
2312 : maxOffset > size.width();
2313 }
2314
2315 int KItemListView::showDropIndicator(const QPointF& pos)
2316 {
2317 QHashIterator<int, KItemListWidget*> it(m_visibleItems);
2318 while (it.hasNext()) {
2319 it.next();
2320 const KItemListWidget* widget = it.value();
2321
2322 const QPointF mappedPos = widget->mapFromItem(this, pos);
2323 const QRectF rect = itemRect(widget->index());
2324 if (mappedPos.y() >= 0 && mappedPos.y() <= rect.height()) {
2325 if (m_model->supportsDropping(widget->index())) {
2326 const int gap = qMax(4, m_styleOption.padding);
2327 if (mappedPos.y() >= gap && mappedPos.y() <= rect.height() - gap) {
2328 return -1;
2329 }
2330 }
2331
2332 const bool isAboveItem = (mappedPos.y () < rect.height() / 2);
2333 const qreal y = isAboveItem ? rect.top() : rect.bottom();
2334
2335 const QRectF draggingInsertIndicator(rect.left(), y, rect.width(), 1);
2336 if (m_dropIndicator != draggingInsertIndicator) {
2337 m_dropIndicator = draggingInsertIndicator;
2338 update();
2339 }
2340
2341 int index = widget->index();
2342 if (!isAboveItem) {
2343 ++index;
2344 }
2345 return index;
2346 }
2347 }
2348
2349 const QRectF firstItemRect = itemRect(firstVisibleIndex());
2350 return (pos.y() <= firstItemRect.top()) ? 0 : -1;
2351 }
2352
2353 void KItemListView::hideDropIndicator()
2354 {
2355 if (!m_dropIndicator.isNull()) {
2356 m_dropIndicator = QRectF();
2357 update();
2358 }
2359 }
2360
2361 void KItemListView::updateGroupHeaderHeight()
2362 {
2363 qreal groupHeaderHeight = m_styleOption.fontMetrics.height();
2364 qreal groupHeaderMargin = 0;
2365
2366 if (scrollOrientation() == Qt::Horizontal) {
2367 // The vertical margin above and below the header should be
2368 // equal to the horizontal margin, not the vertical margin
2369 // from m_styleOption.
2370 groupHeaderHeight += 2 * m_styleOption.horizontalMargin;
2371 groupHeaderMargin = m_styleOption.horizontalMargin;
2372 } else if (m_itemSize.isEmpty()){
2373 groupHeaderHeight += 4 * m_styleOption.padding;
2374 groupHeaderMargin = m_styleOption.iconSize / 2;
2375 } else {
2376 groupHeaderHeight += 2 * m_styleOption.padding + m_styleOption.verticalMargin;
2377 groupHeaderMargin = m_styleOption.iconSize / 4;
2378 }
2379 m_layouter->setGroupHeaderHeight(groupHeaderHeight);
2380 m_layouter->setGroupHeaderMargin(groupHeaderMargin);
2381
2382 updateVisibleGroupHeaders();
2383 }
2384
2385 void KItemListView::updateSiblingsInformation(int firstIndex, int lastIndex)
2386 {
2387 if (!supportsItemExpanding() || !m_model) {
2388 return;
2389 }
2390
2391 if (firstIndex < 0 || lastIndex < 0) {
2392 firstIndex = m_layouter->firstVisibleIndex();
2393 lastIndex = m_layouter->lastVisibleIndex();
2394 } else {
2395 const bool isRangeVisible = (firstIndex <= m_layouter->lastVisibleIndex() &&
2396 lastIndex >= m_layouter->firstVisibleIndex());
2397 if (!isRangeVisible) {
2398 return;
2399 }
2400 }
2401
2402 int previousParents = 0;
2403 QBitArray previousSiblings;
2404
2405 // The rootIndex describes the first index where the siblings get
2406 // calculated from. For the calculation the upper most parent item
2407 // is required. For performance reasons it is checked first whether
2408 // the visible items before or after the current range already
2409 // contain a siblings information which can be used as base.
2410 int rootIndex = firstIndex;
2411
2412 KItemListWidget* widget = m_visibleItems.value(firstIndex - 1);
2413 if (!widget) {
2414 // There is no visible widget before the range, check whether there
2415 // is one after the range:
2416 widget = m_visibleItems.value(lastIndex + 1);
2417 if (widget) {
2418 // The sibling information of the widget may only be used if
2419 // all items of the range have the same number of parents.
2420 const int parents = m_model->expandedParentsCount(lastIndex + 1);
2421 for (int i = lastIndex; i >= firstIndex; --i) {
2422 if (m_model->expandedParentsCount(i) != parents) {
2423 widget = 0;
2424 break;
2425 }
2426 }
2427 }
2428 }
2429
2430 if (widget) {
2431 // Performance optimization: Use the sibling information of the visible
2432 // widget beside the given range.
2433 previousSiblings = widget->siblingsInformation();
2434 if (previousSiblings.isEmpty()) {
2435 return;
2436 }
2437 previousParents = previousSiblings.count() - 1;
2438 previousSiblings.truncate(previousParents);
2439 } else {
2440 // Potentially slow path: Go back to the upper most parent of firstIndex
2441 // to be able to calculate the initial value for the siblings.
2442 while (rootIndex > 0 && m_model->expandedParentsCount(rootIndex) > 0) {
2443 --rootIndex;
2444 }
2445 }
2446
2447 Q_ASSERT(previousParents >= 0);
2448 for (int i = rootIndex; i <= lastIndex; ++i) {
2449 // Update the parent-siblings in case if the current item represents
2450 // a child or an upper parent.
2451 const int currentParents = m_model->expandedParentsCount(i);
2452 Q_ASSERT(currentParents >= 0);
2453 if (previousParents < currentParents) {
2454 previousParents = currentParents;
2455 previousSiblings.resize(currentParents);
2456 previousSiblings.setBit(currentParents - 1, hasSiblingSuccessor(i - 1));
2457 } else if (previousParents > currentParents) {
2458 previousParents = currentParents;
2459 previousSiblings.truncate(currentParents);
2460 }
2461
2462 if (i >= firstIndex) {
2463 // The index represents a visible item. Apply the parent-siblings
2464 // and update the sibling of the current item.
2465 KItemListWidget* widget = m_visibleItems.value(i);
2466 if (!widget) {
2467 continue;
2468 }
2469
2470 QBitArray siblings = previousSiblings;
2471 siblings.resize(siblings.count() + 1);
2472 siblings.setBit(siblings.count() - 1, hasSiblingSuccessor(i));
2473
2474 widget->setSiblingsInformation(siblings);
2475 }
2476 }
2477 }
2478
2479 bool KItemListView::hasSiblingSuccessor(int index) const
2480 {
2481 bool hasSuccessor = false;
2482 const int parentsCount = m_model->expandedParentsCount(index);
2483 int successorIndex = index + 1;
2484
2485 // Search the next sibling
2486 const int itemCount = m_model->count();
2487 while (successorIndex < itemCount) {
2488 const int currentParentsCount = m_model->expandedParentsCount(successorIndex);
2489 if (currentParentsCount == parentsCount) {
2490 hasSuccessor = true;
2491 break;
2492 } else if (currentParentsCount < parentsCount) {
2493 break;
2494 }
2495 ++successorIndex;
2496 }
2497
2498 if (m_grouped && hasSuccessor) {
2499 // If the sibling is part of another group, don't mark it as
2500 // successor as the group header is between the sibling connections.
2501 for (int i = index + 1; i <= successorIndex; ++i) {
2502 if (m_layouter->isFirstGroupItem(i)) {
2503 hasSuccessor = false;
2504 break;
2505 }
2506 }
2507 }
2508
2509 return hasSuccessor;
2510 }
2511
2512 void KItemListView::disconnectRoleEditingSignals(int index)
2513 {
2514 KItemListWidget* widget = m_visibleItems.value(index);
2515 if (!widget) {
2516 return;
2517 }
2518
2519 widget->disconnect(SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)), this);
2520 widget->disconnect(SIGNAL(roleEditingFinished(int,QByteArray,QVariant)), this);
2521 }
2522
2523 int KItemListView::calculateAutoScrollingIncrement(int pos, int range, int oldInc)
2524 {
2525 int inc = 0;
2526
2527 const int minSpeed = 4;
2528 const int maxSpeed = 128;
2529 const int speedLimiter = 96;
2530 const int autoScrollBorder = 64;
2531
2532 // Limit the increment that is allowed to be added in comparison to 'oldInc'.
2533 // This assures that the autoscrolling speed grows gradually.
2534 const int incLimiter = 1;
2535
2536 if (pos < autoScrollBorder) {
2537 inc = -minSpeed + qAbs(pos - autoScrollBorder) * (pos - autoScrollBorder) / speedLimiter;
2538 inc = qMax(inc, -maxSpeed);
2539 inc = qMax(inc, oldInc - incLimiter);
2540 } else if (pos > range - autoScrollBorder) {
2541 inc = minSpeed + qAbs(pos - range + autoScrollBorder) * (pos - range + autoScrollBorder) / speedLimiter;
2542 inc = qMin(inc, maxSpeed);
2543 inc = qMin(inc, oldInc + incLimiter);
2544 }
2545
2546 return inc;
2547 }
2548
2549 int KItemListView::itemsPerSize(qreal size, qreal itemSize, qreal itemMargin)
2550 {
2551 const qreal availableSize = size - itemMargin;
2552 const int count = availableSize / (itemSize + itemMargin);
2553 return count;
2554 }
2555
2556
2557
2558 KItemListCreatorBase::~KItemListCreatorBase()
2559 {
2560 qDeleteAll(m_recycleableWidgets);
2561 qDeleteAll(m_createdWidgets);
2562 }
2563
2564 void KItemListCreatorBase::addCreatedWidget(QGraphicsWidget* widget)
2565 {
2566 m_createdWidgets.insert(widget);
2567 }
2568
2569 void KItemListCreatorBase::pushRecycleableWidget(QGraphicsWidget* widget)
2570 {
2571 Q_ASSERT(m_createdWidgets.contains(widget));
2572 m_createdWidgets.remove(widget);
2573
2574 if (m_recycleableWidgets.count() < 100) {
2575 m_recycleableWidgets.append(widget);
2576 widget->setVisible(false);
2577 } else {
2578 delete widget;
2579 }
2580 }
2581
2582 QGraphicsWidget* KItemListCreatorBase::popRecycleableWidget()
2583 {
2584 if (m_recycleableWidgets.isEmpty()) {
2585 return 0;
2586 }
2587
2588 QGraphicsWidget* widget = m_recycleableWidgets.takeLast();
2589 m_createdWidgets.insert(widget);
2590 return widget;
2591 }
2592
2593 KItemListWidgetCreatorBase::~KItemListWidgetCreatorBase()
2594 {
2595 }
2596
2597 void KItemListWidgetCreatorBase::recycle(KItemListWidget* widget)
2598 {
2599 widget->setParentItem(0);
2600 widget->setOpacity(1.0);
2601 pushRecycleableWidget(widget);
2602 }
2603
2604 KItemListGroupHeaderCreatorBase::~KItemListGroupHeaderCreatorBase()
2605 {
2606 }
2607
2608 void KItemListGroupHeaderCreatorBase::recycle(KItemListGroupHeader* header)
2609 {
2610 header->setOpacity(1.0);
2611 pushRecycleableWidget(header);
2612 }
2613
2614 #include "kitemlistview.moc"