2 * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
4 * Based on the Itemviews NG project from Trolltech Labs
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "kitemlistview.h"
11 #include "dolphindebug.h"
12 #include "kitemlistcontainer.h"
13 #include "kitemlistcontroller.h"
14 #include "kitemlistheader.h"
15 #include "kitemlistselectionmanager.h"
16 #include "kitemlistviewaccessible.h"
17 #include "kstandarditemlistwidget.h"
19 #include "private/kitemlistheaderwidget.h"
20 #include "private/kitemlistrubberband.h"
21 #include "private/kitemlistsizehintresolver.h"
22 #include "private/kitemlistviewlayouter.h"
24 #include <QElapsedTimer>
25 #include <QGraphicsSceneMouseEvent>
26 #include <QGraphicsView>
27 #include <QPropertyAnimation>
28 #include <QStyleOptionRubberBand>
30 #include <QVariantAnimation>
34 // Time in ms until reaching the autoscroll margin triggers
35 // an initial autoscrolling
36 const int InitialAutoScrollDelay
= 700;
38 // Delay in ms for triggering the next autoscroll
39 const int RepeatingAutoScrollDelay
= 1000 / 60;
41 // Copied from the Kirigami.Units.shortDuration
42 const int RubberFadeSpeed
= 150;
44 const char *RubberPropertyName
= "_kitemviews_rubberBandPosition";
47 #ifndef QT_NO_ACCESSIBILITY
48 QAccessibleInterface
*accessibleInterfaceFactory(const QString
&key
, QObject
*object
)
52 if (KItemListContainer
*container
= qobject_cast
<KItemListContainer
*>(object
)) {
53 return new KItemListContainerAccessible(container
);
54 } else if (KItemListView
*view
= qobject_cast
<KItemListView
*>(object
)) {
55 return new KItemListViewAccessible(view
);
62 KItemListView::KItemListView(QGraphicsWidget
*parent
)
63 : QGraphicsWidget(parent
)
64 , m_enabledSelectionToggles(false)
66 , m_highlightEntireRow(false)
67 , m_alternateBackgrounds(false)
68 , m_supportsItemExpanding(false)
69 , m_editingRole(false)
70 , m_activeTransactions(0)
71 , m_endTransactionAnimationHint(Animation
)
73 , m_controller(nullptr)
76 , m_widgetCreator(nullptr)
77 , m_groupHeaderCreator(nullptr)
82 , m_scrollBarExtent(0)
84 , m_animation(nullptr)
85 , m_oldScrollOffset(0)
86 , m_oldMaximumScrollOffset(0)
88 , m_oldMaximumItemOffset(0)
89 , m_skipAutoScrollForRubberBand(false)
90 , m_rubberBand(nullptr)
91 , m_tapAndHoldIndicator(nullptr)
93 , m_autoScrollIncrement(0)
94 , m_autoScrollTimer(nullptr)
96 , m_headerWidget(nullptr)
97 , m_indicatorAnimation(nullptr)
99 , m_sizeHintResolver(nullptr)
101 setAcceptHoverEvents(true);
102 setAcceptTouchEvents(true);
104 m_sizeHintResolver
= new KItemListSizeHintResolver(this);
106 m_layouter
= new KItemListViewLayouter(m_sizeHintResolver
, this);
108 m_animation
= new KItemListViewAnimation(this);
109 connect(m_animation
, &KItemListViewAnimation::finished
, this, &KItemListView::slotAnimationFinished
);
111 m_rubberBand
= new KItemListRubberBand(this);
112 connect(m_rubberBand
, &KItemListRubberBand::activationChanged
, this, &KItemListView::slotRubberBandActivationChanged
);
114 m_tapAndHoldIndicator
= new KItemListRubberBand(this);
115 m_indicatorAnimation
= new QPropertyAnimation(m_tapAndHoldIndicator
, "endPosition", this);
116 connect(m_tapAndHoldIndicator
, &KItemListRubberBand::activationChanged
, this, [this](bool active
) {
118 m_indicatorAnimation
->setDuration(150);
119 m_indicatorAnimation
->setStartValue(QPointF(1, 1));
120 m_indicatorAnimation
->setEndValue(QPointF(40, 40));
121 m_indicatorAnimation
->start();
125 connect(m_tapAndHoldIndicator
, &KItemListRubberBand::endPositionChanged
, this, [this]() {
126 if (m_tapAndHoldIndicator
->isActive()) {
131 m_headerWidget
= new KItemListHeaderWidget(this);
132 m_headerWidget
->setVisible(false);
134 m_header
= new KItemListHeader(this);
136 #ifndef QT_NO_ACCESSIBILITY
137 QAccessible::installFactory(accessibleInterfaceFactory
);
141 KItemListView::~KItemListView()
143 // The group headers are children of the widgets created by
144 // widgetCreator(). So it is mandatory to delete the group headers
146 delete m_groupHeaderCreator
;
147 m_groupHeaderCreator
= nullptr;
149 delete m_widgetCreator
;
150 m_widgetCreator
= nullptr;
152 delete m_sizeHintResolver
;
153 m_sizeHintResolver
= nullptr;
156 void KItemListView::setScrollOffset(qreal offset
)
162 const qreal previousOffset
= m_layouter
->scrollOffset();
163 if (offset
== previousOffset
) {
167 m_layouter
->setScrollOffset(offset
);
168 m_animation
->setScrollOffset(offset
);
170 // Don't check whether the m_layoutTimer is active: Changing the
171 // scroll offset must always trigger a synchronous layout, otherwise
172 // the smooth-scrolling might get jerky.
173 doLayout(NoAnimation
);
174 onScrollOffsetChanged(offset
, previousOffset
);
177 qreal
KItemListView::scrollOffset() const
179 return m_layouter
->scrollOffset();
182 qreal
KItemListView::maximumScrollOffset() const
184 return m_layouter
->maximumScrollOffset();
187 void KItemListView::setItemOffset(qreal offset
)
189 if (m_layouter
->itemOffset() == offset
) {
193 m_layouter
->setItemOffset(offset
);
194 if (m_headerWidget
->isVisible()) {
195 m_headerWidget
->setOffset(offset
);
198 // Don't check whether the m_layoutTimer is active: Changing the
199 // item offset must always trigger a synchronous layout, otherwise
200 // the smooth-scrolling might get jerky.
201 doLayout(NoAnimation
);
204 qreal
KItemListView::itemOffset() const
206 return m_layouter
->itemOffset();
209 qreal
KItemListView::maximumItemOffset() const
211 return m_layouter
->maximumItemOffset();
214 int KItemListView::maximumVisibleItems() const
216 return m_layouter
->maximumVisibleItems();
219 void KItemListView::setVisibleRoles(const QList
<QByteArray
> &roles
)
221 const QList
<QByteArray
> previousRoles
= m_visibleRoles
;
222 m_visibleRoles
= roles
;
223 onVisibleRolesChanged(roles
, previousRoles
);
225 m_sizeHintResolver
->clearCache();
226 m_layouter
->markAsDirty();
228 if (m_itemSize
.isEmpty()) {
229 m_headerWidget
->setColumns(roles
);
230 updatePreferredColumnWidths();
231 if (!m_headerWidget
->automaticColumnResizing()) {
232 // The column-width of new roles are still 0. Apply the preferred
233 // column-width as default with.
234 for (const QByteArray
&role
: std::as_const(m_visibleRoles
)) {
235 if (m_headerWidget
->columnWidth(role
) == 0) {
236 const qreal width
= m_headerWidget
->preferredColumnWidth(role
);
237 m_headerWidget
->setColumnWidth(role
, width
);
241 applyColumnWidthsFromHeader();
245 const bool alternateBackgroundsChanged
=
246 m_itemSize
.isEmpty() && ((roles
.count() > 1 && previousRoles
.count() <= 1) || (roles
.count() <= 1 && previousRoles
.count() > 1));
248 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
249 while (it
.hasNext()) {
251 KItemListWidget
*widget
= it
.value();
252 widget
->setVisibleRoles(roles
);
253 if (alternateBackgroundsChanged
) {
254 updateAlternateBackgroundForWidget(widget
);
258 doLayout(NoAnimation
);
261 QList
<QByteArray
> KItemListView::visibleRoles() const
263 return m_visibleRoles
;
266 void KItemListView::setAutoScroll(bool enabled
)
268 if (enabled
&& !m_autoScrollTimer
) {
269 m_autoScrollTimer
= new QTimer(this);
270 m_autoScrollTimer
->setSingleShot(true);
271 connect(m_autoScrollTimer
, &QTimer::timeout
, this, &KItemListView::triggerAutoScrolling
);
272 m_autoScrollTimer
->start(InitialAutoScrollDelay
);
273 } else if (!enabled
&& m_autoScrollTimer
) {
274 delete m_autoScrollTimer
;
275 m_autoScrollTimer
= nullptr;
279 bool KItemListView::autoScroll() const
281 return m_autoScrollTimer
!= nullptr;
284 void KItemListView::setEnabledSelectionToggles(bool enabled
)
286 if (m_enabledSelectionToggles
!= enabled
) {
287 m_enabledSelectionToggles
= enabled
;
289 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
290 while (it
.hasNext()) {
292 it
.value()->setEnabledSelectionToggle(enabled
);
297 bool KItemListView::enabledSelectionToggles() const
299 return m_enabledSelectionToggles
;
302 KItemListController
*KItemListView::controller() const
307 KItemModelBase
*KItemListView::model() const
312 void KItemListView::setWidgetCreator(KItemListWidgetCreatorBase
*widgetCreator
)
314 delete m_widgetCreator
;
315 m_widgetCreator
= widgetCreator
;
318 KItemListWidgetCreatorBase
*KItemListView::widgetCreator() const
320 if (!m_widgetCreator
) {
321 m_widgetCreator
= defaultWidgetCreator();
323 return m_widgetCreator
;
326 void KItemListView::setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
*groupHeaderCreator
)
328 delete m_groupHeaderCreator
;
329 m_groupHeaderCreator
= groupHeaderCreator
;
332 KItemListGroupHeaderCreatorBase
*KItemListView::groupHeaderCreator() const
334 if (!m_groupHeaderCreator
) {
335 m_groupHeaderCreator
= defaultGroupHeaderCreator();
337 return m_groupHeaderCreator
;
340 QSizeF
KItemListView::itemSize() const
345 const KItemListStyleOption
&KItemListView::styleOption() const
347 return m_styleOption
;
350 void KItemListView::setGeometry(const QRectF
&rect
)
352 QGraphicsWidget::setGeometry(rect
);
358 const QSizeF newSize
= rect
.size();
359 if (m_itemSize
.isEmpty()) {
360 m_headerWidget
->resize(rect
.width(), m_headerWidget
->size().height());
361 if (m_headerWidget
->automaticColumnResizing()) {
362 applyAutomaticColumnWidths();
364 const qreal requiredWidth
= columnWidthsSum() + 2 * m_headerWidget
->sidePadding();
365 const QSizeF
dynamicItemSize(qMax(newSize
.width(), requiredWidth
), m_itemSize
.height());
366 m_layouter
->setItemSize(dynamicItemSize
);
370 m_layouter
->setSize(newSize
);
371 // We don't animate the moving of the items here because
372 // it would look like the items are slow to find their position.
373 doLayout(NoAnimation
);
376 qreal
KItemListView::verticalPageStep() const
378 qreal headerHeight
= 0;
379 if (m_headerWidget
->isVisible()) {
380 headerHeight
= m_headerWidget
->size().height();
382 return size().height() - headerHeight
;
385 std::optional
<int> KItemListView::itemAt(const QPointF
&pos
) const
387 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
388 while (it
.hasNext()) {
391 const KItemListWidget
*widget
= it
.value();
392 const QPointF mappedPos
= widget
->mapFromItem(this, pos
);
393 if (widget
->contains(mappedPos
) || widget
->selectionRect().contains(mappedPos
)) {
401 bool KItemListView::isAboveSelectionToggle(int index
, const QPointF
&pos
) const
403 if (!m_enabledSelectionToggles
) {
407 const KItemListWidget
*widget
= m_visibleItems
.value(index
);
409 const QRectF selectionToggleRect
= widget
->selectionToggleRect();
410 if (!selectionToggleRect
.isEmpty()) {
411 const QPointF mappedPos
= widget
->mapFromItem(this, pos
);
412 return selectionToggleRect
.contains(mappedPos
);
418 bool KItemListView::isAboveExpansionToggle(int index
, const QPointF
&pos
) const
420 const KItemListWidget
*widget
= m_visibleItems
.value(index
);
422 const QRectF expansionToggleRect
= widget
->expansionToggleRect();
423 if (!expansionToggleRect
.isEmpty()) {
424 const QPointF mappedPos
= widget
->mapFromItem(this, pos
);
425 return expansionToggleRect
.contains(mappedPos
);
431 bool KItemListView::isAboveText(int index
, const QPointF
&pos
) const
433 const KItemListWidget
*widget
= m_visibleItems
.value(index
);
435 const QRectF
&textRect
= widget
->textRect();
436 if (!textRect
.isEmpty()) {
437 const QPointF mappedPos
= widget
->mapFromItem(this, pos
);
438 return textRect
.contains(mappedPos
);
444 int KItemListView::firstVisibleIndex() const
446 return m_layouter
->firstVisibleIndex();
449 int KItemListView::lastVisibleIndex() const
451 return m_layouter
->lastVisibleIndex();
454 void KItemListView::calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>> &logicalHeightHints
, qreal
&logicalWidthHint
) const
456 widgetCreator()->calculateItemSizeHints(logicalHeightHints
, logicalWidthHint
, this);
459 void KItemListView::setSupportsItemExpanding(bool supportsExpanding
)
461 if (m_supportsItemExpanding
!= supportsExpanding
) {
462 m_supportsItemExpanding
= supportsExpanding
;
463 updateSiblingsInformation();
464 onSupportsItemExpandingChanged(supportsExpanding
);
468 bool KItemListView::supportsItemExpanding() const
470 return m_supportsItemExpanding
;
473 void KItemListView::setHighlightEntireRow(bool highlightEntireRow
)
475 if (m_highlightEntireRow
!= highlightEntireRow
) {
476 m_highlightEntireRow
= highlightEntireRow
;
477 onHighlightEntireRowChanged(highlightEntireRow
);
481 bool KItemListView::highlightEntireRow() const
483 return m_highlightEntireRow
;
486 void KItemListView::setAlternateBackgrounds(bool alternate
)
488 if (m_alternateBackgrounds
!= alternate
) {
489 m_alternateBackgrounds
= alternate
;
490 updateAlternateBackgrounds();
494 bool KItemListView::alternateBackgrounds() const
496 return m_alternateBackgrounds
;
499 QRectF
KItemListView::itemRect(int index
) const
501 return m_layouter
->itemRect(index
);
504 QRectF
KItemListView::itemContextRect(int index
) const
508 const KItemListWidget
*widget
= m_visibleItems
.value(index
);
510 contextRect
= widget
->iconRect() | widget
->textRect();
511 contextRect
.translate(itemRect(index
).topLeft());
517 bool KItemListView::isElided(int index
) const
519 return m_sizeHintResolver
->isElided(index
);
522 void KItemListView::scrollToItem(int index
)
524 QRectF viewGeometry
= geometry();
525 if (m_headerWidget
->isVisible()) {
526 const qreal headerHeight
= m_headerWidget
->size().height();
527 viewGeometry
.adjust(0, headerHeight
, 0, 0);
529 QRectF currentRect
= itemRect(index
);
531 // Fix for Bug 311099 - View the underscore when using Ctrl + PagDown
532 currentRect
.adjust(-m_styleOption
.horizontalMargin
, -m_styleOption
.verticalMargin
, m_styleOption
.horizontalMargin
, m_styleOption
.verticalMargin
);
534 if (!viewGeometry
.contains(currentRect
)) {
535 qreal newOffset
= scrollOffset();
536 if (scrollOrientation() == Qt::Vertical
) {
537 if (currentRect
.top() < viewGeometry
.top()) {
538 newOffset
+= currentRect
.top() - viewGeometry
.top();
539 } else if (currentRect
.bottom() > viewGeometry
.bottom()) {
540 newOffset
+= currentRect
.bottom() - viewGeometry
.bottom();
543 if (currentRect
.left() < viewGeometry
.left()) {
544 newOffset
+= currentRect
.left() - viewGeometry
.left();
545 } else if (currentRect
.right() > viewGeometry
.right()) {
546 newOffset
+= currentRect
.right() - viewGeometry
.right();
550 if (newOffset
!= scrollOffset()) {
551 Q_EMIT
scrollTo(newOffset
);
556 Q_EMIT
scrollingStopped();
559 void KItemListView::beginTransaction()
561 ++m_activeTransactions
;
562 if (m_activeTransactions
== 1) {
563 onTransactionBegin();
567 void KItemListView::endTransaction()
569 --m_activeTransactions
;
570 if (m_activeTransactions
< 0) {
571 m_activeTransactions
= 0;
572 qCWarning(DolphinDebug
) << "Mismatch between beginTransaction()/endTransaction()";
575 if (m_activeTransactions
== 0) {
577 doLayout(m_endTransactionAnimationHint
);
578 m_endTransactionAnimationHint
= Animation
;
582 bool KItemListView::isTransactionActive() const
584 return m_activeTransactions
> 0;
587 void KItemListView::setHeaderVisible(bool visible
)
589 if (visible
&& !m_headerWidget
->isVisible()) {
590 QStyleOptionHeader option
;
591 const QSize headerSize
= style()->sizeFromContents(QStyle::CT_HeaderSection
, &option
, QSize());
593 m_headerWidget
->setPos(0, 0);
594 m_headerWidget
->resize(size().width(), headerSize
.height());
595 m_headerWidget
->setModel(m_model
);
596 m_headerWidget
->setColumns(m_visibleRoles
);
597 m_headerWidget
->setZValue(1);
599 connect(m_headerWidget
, &KItemListHeaderWidget::columnWidthChanged
, this, &KItemListView::slotHeaderColumnWidthChanged
);
600 connect(m_headerWidget
, &KItemListHeaderWidget::sidePaddingChanged
, this, &KItemListView::slotSidePaddingChanged
);
601 connect(m_headerWidget
, &KItemListHeaderWidget::columnMoved
, this, &KItemListView::slotHeaderColumnMoved
);
602 connect(m_headerWidget
, &KItemListHeaderWidget::sortOrderChanged
, this, &KItemListView::sortOrderChanged
);
603 connect(m_headerWidget
, &KItemListHeaderWidget::sortRoleChanged
, this, &KItemListView::sortRoleChanged
);
604 connect(m_headerWidget
, &KItemListHeaderWidget::columnHovered
, this, &KItemListView::columnHovered
);
605 connect(m_headerWidget
, &KItemListHeaderWidget::columnUnHovered
, this, &KItemListView::columnUnHovered
);
607 m_layouter
->setHeaderHeight(headerSize
.height());
608 m_headerWidget
->setVisible(true);
609 } else if (!visible
&& m_headerWidget
->isVisible()) {
610 disconnect(m_headerWidget
, &KItemListHeaderWidget::columnWidthChanged
, this, &KItemListView::slotHeaderColumnWidthChanged
);
611 disconnect(m_headerWidget
, &KItemListHeaderWidget::sidePaddingChanged
, this, &KItemListView::slotSidePaddingChanged
);
612 disconnect(m_headerWidget
, &KItemListHeaderWidget::columnMoved
, this, &KItemListView::slotHeaderColumnMoved
);
613 disconnect(m_headerWidget
, &KItemListHeaderWidget::sortOrderChanged
, this, &KItemListView::sortOrderChanged
);
614 disconnect(m_headerWidget
, &KItemListHeaderWidget::sortRoleChanged
, this, &KItemListView::sortRoleChanged
);
615 disconnect(m_headerWidget
, &KItemListHeaderWidget::columnHovered
, this, &KItemListView::columnHovered
);
616 disconnect(m_headerWidget
, &KItemListHeaderWidget::columnUnHovered
, this, &KItemListView::columnUnHovered
);
618 m_layouter
->setHeaderHeight(0);
619 m_headerWidget
->setVisible(false);
623 bool KItemListView::isHeaderVisible() const
625 return m_headerWidget
->isVisible();
628 KItemListHeader
*KItemListView::header() const
633 QPixmap
KItemListView::createDragPixmap(const KItemSet
&indexes
) const
637 if (indexes
.count() == 1) {
638 KItemListWidget
*item
= m_visibleItems
.value(indexes
.first());
639 QGraphicsView
*graphicsView
= scene()->views()[0];
640 if (item
&& graphicsView
) {
641 pixmap
= item
->createDragPixmap(nullptr, graphicsView
);
644 // TODO: Not implemented yet. Probably extend the interface
645 // from KItemListWidget::createDragPixmap() to return a pixmap
646 // that can be used for multiple indexes.
652 void KItemListView::editRole(int index
, const QByteArray
&role
)
654 KStandardItemListWidget
*widget
= qobject_cast
<KStandardItemListWidget
*>(m_visibleItems
.value(index
));
655 if (!widget
|| m_editingRole
) {
659 m_editingRole
= true;
660 widget
->setEditedRole(role
);
662 connect(widget
, &KItemListWidget::roleEditingCanceled
, this, &KItemListView::slotRoleEditingCanceled
);
663 connect(widget
, &KItemListWidget::roleEditingFinished
, this, &KItemListView::slotRoleEditingFinished
);
665 connect(this, &KItemListView::scrollOffsetChanged
, widget
, &KStandardItemListWidget::finishRoleEditing
);
668 void KItemListView::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
, QWidget
*widget
)
670 QGraphicsWidget::paint(painter
, option
, widget
);
672 for (auto animation
: std::as_const(m_rubberBandAnimations
)) {
673 QRectF rubberBandRect
= animation
->property(RubberPropertyName
).toRectF();
675 const QPointF topLeft
= rubberBandRect
.topLeft();
676 if (scrollOrientation() == Qt::Vertical
) {
677 rubberBandRect
.moveTo(topLeft
.x(), topLeft
.y() - scrollOffset());
679 rubberBandRect
.moveTo(topLeft
.x() - scrollOffset(), topLeft
.y());
682 QStyleOptionRubberBand opt
;
683 initStyleOption(&opt
);
684 opt
.shape
= QRubberBand::Rectangle
;
686 opt
.rect
= rubberBandRect
.toRect();
690 painter
->setOpacity(animation
->currentValue().toReal());
691 style()->drawControl(QStyle::CE_RubberBand
, &opt
, painter
);
696 if (m_rubberBand
->isActive()) {
697 QRectF rubberBandRect
= QRectF(m_rubberBand
->startPosition(), m_rubberBand
->endPosition()).normalized();
699 const QPointF topLeft
= rubberBandRect
.topLeft();
700 if (scrollOrientation() == Qt::Vertical
) {
701 rubberBandRect
.moveTo(topLeft
.x(), topLeft
.y() - scrollOffset());
703 rubberBandRect
.moveTo(topLeft
.x() - scrollOffset(), topLeft
.y());
706 QStyleOptionRubberBand opt
;
707 initStyleOption(&opt
);
708 opt
.shape
= QRubberBand::Rectangle
;
710 opt
.rect
= rubberBandRect
.toRect();
711 style()->drawControl(QStyle::CE_RubberBand
, &opt
, painter
);
714 if (m_tapAndHoldIndicator
->isActive()) {
715 const QPointF indicatorSize
= m_tapAndHoldIndicator
->endPosition();
716 const QRectF rubberBandRect
=
717 QRectF(m_tapAndHoldIndicator
->startPosition() - indicatorSize
, (m_tapAndHoldIndicator
->startPosition()) + indicatorSize
).normalized();
718 QStyleOptionRubberBand opt
;
719 initStyleOption(&opt
);
720 opt
.shape
= QRubberBand::Rectangle
;
722 opt
.rect
= rubberBandRect
.toRect();
723 style()->drawControl(QStyle::CE_RubberBand
, &opt
, painter
);
726 if (!m_dropIndicator
.isEmpty()) {
727 const QRectF r
= m_dropIndicator
.toRect();
729 QColor color
= palette().brush(QPalette::Normal
, QPalette::Text
).color();
730 painter
->setPen(color
);
732 // TODO: The following implementation works only for a vertical scroll-orientation
733 // and assumes a height of the m_draggingInsertIndicator of 1.
734 Q_ASSERT(r
.height() == 1);
735 painter
->drawLine(r
.left() + 1, r
.top(), r
.right() - 1, r
.top());
738 painter
->setPen(color
);
739 painter
->drawRect(r
.left(), r
.top() - 1, r
.width() - 1, 2);
743 QVariant
KItemListView::itemChange(GraphicsItemChange change
, const QVariant
&value
)
745 if (change
== QGraphicsItem::ItemSceneHasChanged
&& scene()) {
746 if (!scene()->views().isEmpty()) {
747 m_styleOption
.palette
= scene()->views().at(0)->palette();
750 return QGraphicsItem::itemChange(change
, value
);
753 void KItemListView::setItemSize(const QSizeF
&size
)
755 const QSizeF previousSize
= m_itemSize
;
756 if (size
== previousSize
) {
760 // Skip animations when the number of rows or columns
761 // are changed in the grid layout. Although the animation
762 // engine can handle this usecase, it looks obtrusive.
763 const bool animate
= !changesItemGridLayout(m_layouter
->size(), size
, m_layouter
->itemMargin());
765 const bool alternateBackgroundsChanged
= m_alternateBackgrounds
&& ((m_itemSize
.isEmpty() && !size
.isEmpty()) || (!m_itemSize
.isEmpty() && size
.isEmpty()));
769 if (alternateBackgroundsChanged
) {
770 // For an empty item size alternate backgrounds are drawn if more than
771 // one role is shown. Assure that the backgrounds for visible items are
772 // updated when changing the size in this context.
773 updateAlternateBackgrounds();
776 if (size
.isEmpty()) {
777 if (m_headerWidget
->automaticColumnResizing()) {
778 updatePreferredColumnWidths();
780 // Only apply the changed height and respect the header widths
782 const qreal currentWidth
= m_layouter
->itemSize().width();
783 const QSizeF
newSize(currentWidth
, size
.height());
784 m_layouter
->setItemSize(newSize
);
787 m_layouter
->setItemSize(size
);
790 m_sizeHintResolver
->clearCache();
791 doLayout(animate
? Animation
: NoAnimation
);
792 onItemSizeChanged(size
, previousSize
);
795 void KItemListView::setStyleOption(const KItemListStyleOption
&option
)
797 if (m_styleOption
== option
) {
801 const KItemListStyleOption previousOption
= m_styleOption
;
802 m_styleOption
= option
;
805 const QSizeF
margin(option
.horizontalMargin
, option
.verticalMargin
);
806 if (margin
!= m_layouter
->itemMargin()) {
807 // Skip animations when the number of rows or columns
808 // are changed in the grid layout. Although the animation
809 // engine can handle this usecase, it looks obtrusive.
810 animate
= !changesItemGridLayout(m_layouter
->size(), m_layouter
->itemSize(), margin
);
811 m_layouter
->setItemMargin(margin
);
815 updateGroupHeaderHeight();
818 if (animate
&& (previousOption
.maxTextLines
!= option
.maxTextLines
|| previousOption
.maxTextWidth
!= option
.maxTextWidth
)) {
819 // Animating a change of the maximum text size just results in expensive
820 // temporary eliding and clipping operations and does not look good visually.
824 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
825 while (it
.hasNext()) {
827 it
.value()->setStyleOption(option
);
830 m_sizeHintResolver
->clearCache();
831 m_layouter
->markAsDirty();
832 doLayout(animate
? Animation
: NoAnimation
);
834 if (m_itemSize
.isEmpty()) {
835 updatePreferredColumnWidths();
838 onStyleOptionChanged(option
, previousOption
);
841 void KItemListView::setScrollOrientation(Qt::Orientation orientation
)
843 const Qt::Orientation previousOrientation
= m_layouter
->scrollOrientation();
844 if (orientation
== previousOrientation
) {
848 m_layouter
->setScrollOrientation(orientation
);
849 m_animation
->setScrollOrientation(orientation
);
850 m_sizeHintResolver
->clearCache();
853 QMutableHashIterator
<KItemListWidget
*, KItemListGroupHeader
*> it(m_visibleGroups
);
854 while (it
.hasNext()) {
856 it
.value()->setScrollOrientation(orientation
);
858 updateGroupHeaderHeight();
861 doLayout(NoAnimation
);
863 onScrollOrientationChanged(orientation
, previousOrientation
);
864 Q_EMIT
scrollOrientationChanged(orientation
, previousOrientation
);
867 Qt::Orientation
KItemListView::scrollOrientation() const
869 return m_layouter
->scrollOrientation();
872 KItemListWidgetCreatorBase
*KItemListView::defaultWidgetCreator() const
877 KItemListGroupHeaderCreatorBase
*KItemListView::defaultGroupHeaderCreator() const
882 void KItemListView::initializeItemListWidget(KItemListWidget
*item
)
887 bool KItemListView::itemSizeHintUpdateRequired(const QSet
<QByteArray
> &changedRoles
) const
889 Q_UNUSED(changedRoles
)
893 void KItemListView::onControllerChanged(KItemListController
*current
, KItemListController
*previous
)
899 void KItemListView::onModelChanged(KItemModelBase
*current
, KItemModelBase
*previous
)
905 void KItemListView::onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
)
911 void KItemListView::onItemSizeChanged(const QSizeF
¤t
, const QSizeF
&previous
)
917 void KItemListView::onScrollOffsetChanged(qreal current
, qreal previous
)
923 void KItemListView::onVisibleRolesChanged(const QList
<QByteArray
> ¤t
, const QList
<QByteArray
> &previous
)
929 void KItemListView::onStyleOptionChanged(const KItemListStyleOption
¤t
, const KItemListStyleOption
&previous
)
935 void KItemListView::onHighlightEntireRowChanged(bool highlightEntireRow
)
937 Q_UNUSED(highlightEntireRow
)
940 void KItemListView::onSupportsItemExpandingChanged(bool supportsExpanding
)
942 Q_UNUSED(supportsExpanding
)
945 void KItemListView::onTransactionBegin()
949 void KItemListView::onTransactionEnd()
953 bool KItemListView::event(QEvent
*event
)
955 switch (event
->type()) {
956 case QEvent::PaletteChange
:
960 case QEvent::FontChange
:
964 case QEvent::FocusIn
:
965 focusInEvent(static_cast<QFocusEvent
*>(event
));
970 case QEvent::FocusOut
:
971 focusOutEvent(static_cast<QFocusEvent
*>(event
));
977 // Forward all other events to the controller and handle them there
978 if (!m_editingRole
&& m_controller
&& m_controller
->processEvent(event
, transform())) {
984 return QGraphicsWidget::event(event
);
987 void KItemListView::mousePressEvent(QGraphicsSceneMouseEvent
*event
)
989 m_mousePos
= transform().map(event
->pos());
993 void KItemListView::mouseMoveEvent(QGraphicsSceneMouseEvent
*event
)
995 QGraphicsWidget::mouseMoveEvent(event
);
997 m_mousePos
= transform().map(event
->pos());
998 if (m_autoScrollTimer
&& !m_autoScrollTimer
->isActive()) {
999 m_autoScrollTimer
->start(InitialAutoScrollDelay
);
1003 void KItemListView::dragEnterEvent(QGraphicsSceneDragDropEvent
*event
)
1005 event
->setAccepted(true);
1006 setAutoScroll(true);
1009 void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEvent
*event
)
1011 QGraphicsWidget::dragMoveEvent(event
);
1013 m_mousePos
= transform().map(event
->pos());
1014 if (m_autoScrollTimer
&& !m_autoScrollTimer
->isActive()) {
1015 m_autoScrollTimer
->start(InitialAutoScrollDelay
);
1019 void KItemListView::dragLeaveEvent(QGraphicsSceneDragDropEvent
*event
)
1021 QGraphicsWidget::dragLeaveEvent(event
);
1022 setAutoScroll(false);
1025 void KItemListView::dropEvent(QGraphicsSceneDragDropEvent
*event
)
1027 QGraphicsWidget::dropEvent(event
);
1028 setAutoScroll(false);
1031 QList
<KItemListWidget
*> KItemListView::visibleItemListWidgets() const
1033 return m_visibleItems
.values();
1036 void KItemListView::updateFont()
1038 if (scene() && !scene()->views().isEmpty()) {
1039 KItemListStyleOption option
= styleOption();
1040 option
.font
= scene()->views().first()->font();
1041 option
.fontMetrics
= QFontMetrics(option
.font
);
1043 setStyleOption(option
);
1047 void KItemListView::updatePalette()
1049 KItemListStyleOption option
= styleOption();
1050 option
.palette
= palette();
1051 setStyleOption(option
);
1054 void KItemListView::slotItemsInserted(const KItemRangeList
&itemRanges
)
1056 if (m_itemSize
.isEmpty()) {
1057 updatePreferredColumnWidths(itemRanges
);
1060 const bool hasMultipleRanges
= (itemRanges
.count() > 1);
1061 if (hasMultipleRanges
) {
1065 m_layouter
->markAsDirty();
1067 m_sizeHintResolver
->itemsInserted(itemRanges
);
1069 int previouslyInsertedCount
= 0;
1070 for (const KItemRange
&range
: itemRanges
) {
1071 // range.index is related to the model before anything has been inserted.
1072 // As in each loop the current item-range gets inserted the index must
1073 // be increased by the already previously inserted items.
1074 const int index
= range
.index
+ previouslyInsertedCount
;
1075 const int count
= range
.count
;
1076 if (index
< 0 || count
<= 0) {
1077 qCWarning(DolphinDebug
) << "Invalid item range (index:" << index
<< ", count:" << count
<< ")";
1080 previouslyInsertedCount
+= count
;
1082 // Determine which visible items must be moved
1083 QList
<int> itemsToMove
;
1084 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
1085 while (it
.hasNext()) {
1087 const int visibleItemIndex
= it
.key();
1088 if (visibleItemIndex
>= index
) {
1089 itemsToMove
.append(visibleItemIndex
);
1093 // Update the indexes of all KItemListWidget instances that are located
1094 // after the inserted items. It is important to adjust the indexes in the order
1095 // from the highest index to the lowest index to prevent overlaps when setting the new index.
1096 std::sort(itemsToMove
.begin(), itemsToMove
.end());
1097 for (int i
= itemsToMove
.count() - 1; i
>= 0; --i
) {
1098 KItemListWidget
*widget
= m_visibleItems
.value(itemsToMove
[i
]);
1100 const int newIndex
= widget
->index() + count
;
1101 if (hasMultipleRanges
) {
1102 setWidgetIndex(widget
, newIndex
);
1104 // Try to animate the moving of the item
1105 moveWidgetToIndex(widget
, newIndex
);
1109 if (m_model
->count() == count
&& m_activeTransactions
== 0) {
1110 // Check whether a scrollbar is required to show the inserted items. In this case
1111 // the size of the layouter will be decreased before calling doLayout(): This prevents
1112 // an unnecessary temporary animation due to the geometry change of the inserted scrollbar.
1113 const bool verticalScrollOrientation
= (scrollOrientation() == Qt::Vertical
);
1114 const bool decreaseLayouterSize
= (verticalScrollOrientation
&& maximumScrollOffset() > size().height())
1115 || (!verticalScrollOrientation
&& maximumScrollOffset() > size().width());
1116 if (decreaseLayouterSize
) {
1117 const int scrollBarExtent
= style()->pixelMetric(QStyle::PM_ScrollBarExtent
);
1119 int scrollbarSpacing
= 0;
1120 if (style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents
)) {
1121 scrollbarSpacing
= style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing
);
1124 QSizeF layouterSize
= m_layouter
->size();
1125 if (verticalScrollOrientation
) {
1126 layouterSize
.rwidth() -= scrollBarExtent
+ scrollbarSpacing
;
1128 layouterSize
.rheight() -= scrollBarExtent
+ scrollbarSpacing
;
1130 m_layouter
->setSize(layouterSize
);
1134 if (!hasMultipleRanges
) {
1135 doLayout(animateChangedItemCount(count
) ? Animation
: NoAnimation
, index
, count
);
1136 updateSiblingsInformation();
1141 m_controller
->selectionManager()->itemsInserted(itemRanges
);
1144 if (hasMultipleRanges
) {
1145 m_endTransactionAnimationHint
= NoAnimation
;
1148 updateSiblingsInformation();
1151 if (m_grouped
&& (hasMultipleRanges
|| itemRanges
.first().count
< m_model
->count())) {
1152 // In case if items of the same group have been inserted before an item that
1153 // currently represents the first item of the group, the group header of
1154 // this item must be removed.
1155 updateVisibleGroupHeaders();
1158 if (useAlternateBackgrounds()) {
1159 updateAlternateBackgrounds();
1163 void KItemListView::slotItemsRemoved(const KItemRangeList
&itemRanges
)
1165 if (m_itemSize
.isEmpty()) {
1166 // Don't pass the item-range: The preferred column-widths of
1167 // all items must be adjusted when removing items.
1168 updatePreferredColumnWidths();
1171 const bool hasMultipleRanges
= (itemRanges
.count() > 1);
1172 if (hasMultipleRanges
) {
1176 m_layouter
->markAsDirty();
1178 m_sizeHintResolver
->itemsRemoved(itemRanges
);
1180 for (int i
= itemRanges
.count() - 1; i
>= 0; --i
) {
1181 const KItemRange
&range
= itemRanges
[i
];
1182 const int index
= range
.index
;
1183 const int count
= range
.count
;
1184 if (index
< 0 || count
<= 0) {
1185 qCWarning(DolphinDebug
) << "Invalid item range (index:" << index
<< ", count:" << count
<< ")";
1189 const int firstRemovedIndex
= index
;
1190 const int lastRemovedIndex
= index
+ count
- 1;
1192 // Remember which items have to be moved because they are behind the removed range.
1193 QVector
<int> itemsToMove
;
1195 // Remove all KItemListWidget instances that got deleted
1196 // Iterate over a const copy because the container is mutated within the loop
1197 // directly and in `recycleWidget()` (https://bugs.kde.org/show_bug.cgi?id=428374)
1198 const auto visibleItems
= m_visibleItems
;
1199 for (KItemListWidget
*widget
: visibleItems
) {
1200 const int i
= widget
->index();
1201 if (i
< firstRemovedIndex
) {
1203 } else if (i
> lastRemovedIndex
) {
1204 itemsToMove
.append(i
);
1208 m_animation
->stop(widget
);
1209 // Stopping the animation might lead to recycling the widget if
1210 // it is invisible (see slotAnimationFinished()).
1211 // Check again whether it is still visible:
1212 if (!m_visibleItems
.contains(i
)) {
1216 if (m_model
->count() == 0 || hasMultipleRanges
|| !animateChangedItemCount(count
)) {
1217 // Remove the widget without animation
1218 recycleWidget(widget
);
1220 // Animate the removing of the items. Special case: When removing an item there
1221 // is no valid model index available anymore. For the
1222 // remove-animation the item gets removed from m_visibleItems but the widget
1223 // will stay alive until the animation has been finished and will
1224 // be recycled (deleted) in KItemListView::slotAnimationFinished().
1225 m_visibleItems
.remove(i
);
1226 widget
->setIndex(-1);
1227 m_animation
->start(widget
, KItemListViewAnimation::DeleteAnimation
);
1231 // Update the indexes of all KItemListWidget instances that are located
1232 // after the deleted items. It is important to update them in ascending
1233 // order to prevent overlaps when setting the new index.
1234 std::sort(itemsToMove
.begin(), itemsToMove
.end());
1235 for (int i
: std::as_const(itemsToMove
)) {
1236 KItemListWidget
*widget
= m_visibleItems
.value(i
);
1238 const int newIndex
= i
- count
;
1239 if (hasMultipleRanges
) {
1240 setWidgetIndex(widget
, newIndex
);
1242 // Try to animate the moving of the item
1243 moveWidgetToIndex(widget
, newIndex
);
1247 if (!hasMultipleRanges
) {
1248 // The decrease-layout-size optimization in KItemListView::slotItemsInserted()
1249 // assumes an updated geometry. If items are removed during an active transaction,
1250 // the transaction will be temporary deactivated so that doLayout() triggers a
1251 // geometry update if necessary.
1252 const int activeTransactions
= m_activeTransactions
;
1253 m_activeTransactions
= 0;
1254 doLayout(animateChangedItemCount(count
) ? Animation
: NoAnimation
, index
, -count
);
1255 m_activeTransactions
= activeTransactions
;
1256 updateSiblingsInformation();
1261 m_controller
->selectionManager()->itemsRemoved(itemRanges
);
1264 if (hasMultipleRanges
) {
1265 m_endTransactionAnimationHint
= NoAnimation
;
1267 updateSiblingsInformation();
1270 if (m_grouped
&& (hasMultipleRanges
|| m_model
->count() > 0)) {
1271 // In case if the first item of a group has been removed, the group header
1272 // must be applied to the next visible item.
1273 updateVisibleGroupHeaders();
1276 if (useAlternateBackgrounds()) {
1277 updateAlternateBackgrounds();
1281 void KItemListView::slotItemsMoved(const KItemRange
&itemRange
, const QList
<int> &movedToIndexes
)
1283 m_sizeHintResolver
->itemsMoved(itemRange
, movedToIndexes
);
1284 m_layouter
->markAsDirty();
1287 m_controller
->selectionManager()->itemsMoved(itemRange
, movedToIndexes
);
1290 const int firstVisibleMovedIndex
= qMax(firstVisibleIndex(), itemRange
.index
);
1291 const int lastVisibleMovedIndex
= qMin(lastVisibleIndex(), itemRange
.index
+ itemRange
.count
- 1);
1293 for (int index
= firstVisibleMovedIndex
; index
<= lastVisibleMovedIndex
; ++index
) {
1294 KItemListWidget
*widget
= m_visibleItems
.value(index
);
1296 updateWidgetProperties(widget
, index
);
1297 initializeItemListWidget(widget
);
1301 doLayout(NoAnimation
);
1302 updateSiblingsInformation();
1305 void KItemListView::slotItemsChanged(const KItemRangeList
&itemRanges
, const QSet
<QByteArray
> &roles
)
1307 const bool updateSizeHints
= itemSizeHintUpdateRequired(roles
);
1308 if (updateSizeHints
&& m_itemSize
.isEmpty()) {
1309 updatePreferredColumnWidths(itemRanges
);
1312 for (const KItemRange
&itemRange
: itemRanges
) {
1313 const int index
= itemRange
.index
;
1314 const int count
= itemRange
.count
;
1316 if (updateSizeHints
) {
1317 m_sizeHintResolver
->itemsChanged(index
, count
, roles
);
1318 m_layouter
->markAsDirty();
1321 // Apply the changed roles to the visible item-widgets
1322 const int lastIndex
= index
+ count
- 1;
1323 for (int i
= index
; i
<= lastIndex
; ++i
) {
1324 KItemListWidget
*widget
= m_visibleItems
.value(i
);
1326 widget
->setData(m_model
->data(i
), roles
);
1330 if (m_grouped
&& roles
.contains(m_model
->sortRole())) {
1331 // The sort-role has been changed which might result
1332 // in modified group headers
1333 updateVisibleGroupHeaders();
1334 doLayout(NoAnimation
);
1337 QAccessibleTableModelChangeEvent
ev(this, QAccessibleTableModelChangeEvent::DataChanged
);
1338 ev
.setFirstRow(itemRange
.index
);
1339 ev
.setLastRow(itemRange
.index
+ itemRange
.count
);
1340 QAccessible::updateAccessibility(&ev
);
1343 doLayout(NoAnimation
);
1346 void KItemListView::slotGroupsChanged()
1348 updateVisibleGroupHeaders();
1349 doLayout(NoAnimation
);
1350 updateSiblingsInformation();
1353 void KItemListView::slotGroupedSortingChanged(bool current
)
1355 m_grouped
= current
;
1356 m_layouter
->markAsDirty();
1359 updateGroupHeaderHeight();
1361 // Clear all visible headers. Note that the QHashIterator takes a copy of
1362 // m_visibleGroups. Therefore, it remains valid even if items are removed
1363 // from m_visibleGroups in recycleGroupHeaderForWidget().
1364 QHashIterator
<KItemListWidget
*, KItemListGroupHeader
*> it(m_visibleGroups
);
1365 while (it
.hasNext()) {
1367 recycleGroupHeaderForWidget(it
.key());
1369 Q_ASSERT(m_visibleGroups
.isEmpty());
1372 if (useAlternateBackgrounds()) {
1373 // Changing the group mode requires to update the alternate backgrounds
1374 // as with the enabled group mode the altering is done on base of the first
1376 updateAlternateBackgrounds();
1378 updateSiblingsInformation();
1379 doLayout(NoAnimation
);
1382 void KItemListView::slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
)
1387 updateVisibleGroupHeaders();
1388 doLayout(NoAnimation
);
1392 void KItemListView::slotSortRoleChanged(const QByteArray
¤t
, const QByteArray
&previous
)
1397 updateVisibleGroupHeaders();
1398 doLayout(NoAnimation
);
1402 void KItemListView::slotCurrentChanged(int current
, int previous
)
1406 // In SingleSelection mode (e.g., in the Places Panel), the current item is
1407 // always the selected item. It is not necessary to highlight the current item then.
1408 if (m_controller
->selectionBehavior() != KItemListController::SingleSelection
) {
1409 KItemListWidget
*previousWidget
= m_visibleItems
.value(previous
, nullptr);
1410 if (previousWidget
) {
1411 previousWidget
->setCurrent(false);
1414 KItemListWidget
*currentWidget
= m_visibleItems
.value(current
, nullptr);
1415 if (currentWidget
) {
1416 currentWidget
->setCurrent(true);
1420 QAccessibleEvent
ev(this, QAccessible::Focus
);
1421 ev
.setChild(current
);
1422 QAccessible::updateAccessibility(&ev
);
1425 void KItemListView::slotSelectionChanged(const KItemSet
¤t
, const KItemSet
&previous
)
1429 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
1430 while (it
.hasNext()) {
1432 const int index
= it
.key();
1433 KItemListWidget
*widget
= it
.value();
1434 widget
->setSelected(current
.contains(index
));
1438 void KItemListView::slotAnimationFinished(QGraphicsWidget
*widget
, KItemListViewAnimation::AnimationType type
)
1440 KItemListWidget
*itemListWidget
= qobject_cast
<KItemListWidget
*>(widget
);
1441 Q_ASSERT(itemListWidget
);
1443 if (type
== KItemListViewAnimation::DeleteAnimation
) {
1444 // As we recycle the widget in this case it is important to assure that no
1445 // other animation has been started. This is a convention in KItemListView and
1446 // not a requirement defined by KItemListViewAnimation.
1447 Q_ASSERT(!m_animation
->isStarted(itemListWidget
));
1449 // All KItemListWidgets that are animated by the DeleteAnimation are not maintained
1450 // by m_visibleWidgets and must be deleted manually after the animation has
1452 recycleGroupHeaderForWidget(itemListWidget
);
1453 widgetCreator()->recycle(itemListWidget
);
1455 const int index
= itemListWidget
->index();
1456 const bool invisible
= (index
< m_layouter
->firstVisibleIndex()) || (index
> m_layouter
->lastVisibleIndex());
1457 if (invisible
&& !m_animation
->isStarted(itemListWidget
)) {
1458 recycleWidget(itemListWidget
);
1463 void KItemListView::slotRubberBandPosChanged()
1468 void KItemListView::slotRubberBandActivationChanged(bool active
)
1471 connect(m_rubberBand
, &KItemListRubberBand::startPositionChanged
, this, &KItemListView::slotRubberBandPosChanged
);
1472 connect(m_rubberBand
, &KItemListRubberBand::endPositionChanged
, this, &KItemListView::slotRubberBandPosChanged
);
1473 m_skipAutoScrollForRubberBand
= true;
1475 QRectF rubberBandRect
= QRectF(m_rubberBand
->startPosition(), m_rubberBand
->endPosition()).normalized();
1477 auto animation
= new QVariantAnimation(this);
1478 animation
->setStartValue(1.0);
1479 animation
->setEndValue(0.0);
1480 animation
->setDuration(RubberFadeSpeed
);
1481 animation
->setProperty(RubberPropertyName
, rubberBandRect
);
1484 curve
.setType(QEasingCurve::BezierSpline
);
1485 curve
.addCubicBezierSegment(QPointF(0.4, 0.0), QPointF(1.0, 1.0), QPointF(1.0, 1.0));
1486 animation
->setEasingCurve(curve
);
1488 connect(animation
, &QVariantAnimation::valueChanged
, this, [=](const QVariant
&) {
1491 connect(animation
, &QVariantAnimation::finished
, this, [=]() {
1492 m_rubberBandAnimations
.removeAll(animation
);
1496 m_rubberBandAnimations
<< animation
;
1498 disconnect(m_rubberBand
, &KItemListRubberBand::startPositionChanged
, this, &KItemListView::slotRubberBandPosChanged
);
1499 disconnect(m_rubberBand
, &KItemListRubberBand::endPositionChanged
, this, &KItemListView::slotRubberBandPosChanged
);
1500 m_skipAutoScrollForRubberBand
= false;
1506 void KItemListView::slotHeaderColumnWidthChanged(const QByteArray
&role
, qreal currentWidth
, qreal previousWidth
)
1509 Q_UNUSED(currentWidth
)
1510 Q_UNUSED(previousWidth
)
1512 m_headerWidget
->setAutomaticColumnResizing(false);
1513 applyColumnWidthsFromHeader();
1514 doLayout(NoAnimation
);
1517 void KItemListView::slotSidePaddingChanged(qreal width
)
1520 if (m_headerWidget
->automaticColumnResizing()) {
1521 applyAutomaticColumnWidths();
1523 applyColumnWidthsFromHeader();
1524 doLayout(NoAnimation
);
1527 void KItemListView::slotHeaderColumnMoved(const QByteArray
&role
, int currentIndex
, int previousIndex
)
1529 Q_ASSERT(m_visibleRoles
[previousIndex
] == role
);
1531 const QList
<QByteArray
> previous
= m_visibleRoles
;
1533 QList
<QByteArray
> current
= m_visibleRoles
;
1534 current
.removeAt(previousIndex
);
1535 current
.insert(currentIndex
, role
);
1537 setVisibleRoles(current
);
1539 Q_EMIT
visibleRolesChanged(current
, previous
);
1542 void KItemListView::triggerAutoScrolling()
1544 if (!m_autoScrollTimer
) {
1549 int visibleSize
= 0;
1550 if (scrollOrientation() == Qt::Vertical
) {
1551 pos
= m_mousePos
.y();
1552 visibleSize
= size().height();
1554 pos
= m_mousePos
.x();
1555 visibleSize
= size().width();
1558 if (m_autoScrollTimer
->interval() == InitialAutoScrollDelay
) {
1559 m_autoScrollIncrement
= 0;
1562 m_autoScrollIncrement
= calculateAutoScrollingIncrement(pos
, visibleSize
, m_autoScrollIncrement
);
1563 if (m_autoScrollIncrement
== 0) {
1564 // The mouse position is not above an autoscroll margin (the autoscroll timer
1565 // will be restarted in mouseMoveEvent())
1566 m_autoScrollTimer
->stop();
1570 if (m_rubberBand
->isActive() && m_skipAutoScrollForRubberBand
) {
1571 // If a rubberband selection is ongoing the autoscrolling may only get triggered
1572 // if the direction of the rubberband is similar to the autoscroll direction. This
1573 // prevents that starting to create a rubberband within the autoscroll margins starts
1574 // an autoscrolling.
1576 const qreal minDiff
= 4; // Ignore any autoscrolling if the rubberband is very small
1577 const qreal diff
= (scrollOrientation() == Qt::Vertical
) ? m_rubberBand
->endPosition().y() - m_rubberBand
->startPosition().y()
1578 : m_rubberBand
->endPosition().x() - m_rubberBand
->startPosition().x();
1579 if (qAbs(diff
) < minDiff
|| (m_autoScrollIncrement
< 0 && diff
> 0) || (m_autoScrollIncrement
> 0 && diff
< 0)) {
1580 // The rubberband direction is different from the scroll direction (e.g. the rubberband has
1581 // been moved up although the autoscroll direction might be down)
1582 m_autoScrollTimer
->stop();
1587 // As soon as the autoscrolling has been triggered at least once despite having an active rubberband,
1588 // the autoscrolling may not get skipped anymore until a new rubberband is created
1589 m_skipAutoScrollForRubberBand
= false;
1591 const qreal maxVisibleOffset
= qMax(qreal(0), maximumScrollOffset() - visibleSize
);
1592 const qreal newScrollOffset
= qMin(scrollOffset() + m_autoScrollIncrement
, maxVisibleOffset
);
1593 setScrollOffset(newScrollOffset
);
1595 // Trigger the autoscroll timer which will periodically call
1596 // triggerAutoScrolling()
1597 m_autoScrollTimer
->start(RepeatingAutoScrollDelay
);
1600 void KItemListView::slotGeometryOfGroupHeaderParentChanged()
1602 KItemListWidget
*widget
= qobject_cast
<KItemListWidget
*>(sender());
1604 KItemListGroupHeader
*groupHeader
= m_visibleGroups
.value(widget
);
1605 Q_ASSERT(groupHeader
);
1606 updateGroupHeaderLayout(widget
);
1609 void KItemListView::slotRoleEditingCanceled(int index
, const QByteArray
&role
, const QVariant
&value
)
1611 disconnectRoleEditingSignals(index
);
1613 m_editingRole
= false;
1614 Q_EMIT
roleEditingCanceled(index
, role
, value
);
1617 void KItemListView::slotRoleEditingFinished(int index
, const QByteArray
&role
, const QVariant
&value
)
1619 disconnectRoleEditingSignals(index
);
1621 m_editingRole
= false;
1622 Q_EMIT
roleEditingFinished(index
, role
, value
);
1625 void KItemListView::setController(KItemListController
*controller
)
1627 if (m_controller
!= controller
) {
1628 KItemListController
*previous
= m_controller
;
1630 KItemListSelectionManager
*selectionManager
= previous
->selectionManager();
1631 disconnect(selectionManager
, &KItemListSelectionManager::currentChanged
, this, &KItemListView::slotCurrentChanged
);
1632 disconnect(selectionManager
, &KItemListSelectionManager::selectionChanged
, this, &KItemListView::slotSelectionChanged
);
1635 m_controller
= controller
;
1638 KItemListSelectionManager
*selectionManager
= controller
->selectionManager();
1639 connect(selectionManager
, &KItemListSelectionManager::currentChanged
, this, &KItemListView::slotCurrentChanged
);
1640 connect(selectionManager
, &KItemListSelectionManager::selectionChanged
, this, &KItemListView::slotSelectionChanged
);
1643 onControllerChanged(controller
, previous
);
1647 void KItemListView::setModel(KItemModelBase
*model
)
1649 if (m_model
== model
) {
1653 KItemModelBase
*previous
= m_model
;
1656 disconnect(m_model
, &KItemModelBase::itemsChanged
, this, &KItemListView::slotItemsChanged
);
1657 disconnect(m_model
, &KItemModelBase::itemsInserted
, this, &KItemListView::slotItemsInserted
);
1658 disconnect(m_model
, &KItemModelBase::itemsRemoved
, this, &KItemListView::slotItemsRemoved
);
1659 disconnect(m_model
, &KItemModelBase::itemsMoved
, this, &KItemListView::slotItemsMoved
);
1660 disconnect(m_model
, &KItemModelBase::groupsChanged
, this, &KItemListView::slotGroupsChanged
);
1661 disconnect(m_model
, &KItemModelBase::groupedSortingChanged
, this, &KItemListView::slotGroupedSortingChanged
);
1662 disconnect(m_model
, &KItemModelBase::sortOrderChanged
, this, &KItemListView::slotSortOrderChanged
);
1663 disconnect(m_model
, &KItemModelBase::sortRoleChanged
, this, &KItemListView::slotSortRoleChanged
);
1665 m_sizeHintResolver
->itemsRemoved(KItemRangeList() << KItemRange(0, m_model
->count()));
1669 m_layouter
->setModel(model
);
1670 m_grouped
= model
->groupedSorting();
1673 connect(m_model
, &KItemModelBase::itemsChanged
, this, &KItemListView::slotItemsChanged
);
1674 connect(m_model
, &KItemModelBase::itemsInserted
, this, &KItemListView::slotItemsInserted
);
1675 connect(m_model
, &KItemModelBase::itemsRemoved
, this, &KItemListView::slotItemsRemoved
);
1676 connect(m_model
, &KItemModelBase::itemsMoved
, this, &KItemListView::slotItemsMoved
);
1677 connect(m_model
, &KItemModelBase::groupsChanged
, this, &KItemListView::slotGroupsChanged
);
1678 connect(m_model
, &KItemModelBase::groupedSortingChanged
, this, &KItemListView::slotGroupedSortingChanged
);
1679 connect(m_model
, &KItemModelBase::sortOrderChanged
, this, &KItemListView::slotSortOrderChanged
);
1680 connect(m_model
, &KItemModelBase::sortRoleChanged
, this, &KItemListView::slotSortRoleChanged
);
1682 const int itemCount
= m_model
->count();
1683 if (itemCount
> 0) {
1684 slotItemsInserted(KItemRangeList() << KItemRange(0, itemCount
));
1688 onModelChanged(model
, previous
);
1691 KItemListRubberBand
*KItemListView::rubberBand() const
1693 return m_rubberBand
;
1696 void KItemListView::doLayout(LayoutAnimationHint hint
, int changedIndex
, int changedCount
)
1698 if (m_activeTransactions
> 0) {
1699 if (hint
== NoAnimation
) {
1700 // As soon as at least one property change should be done without animation,
1701 // the whole transaction will be marked as not animated.
1702 m_endTransactionAnimationHint
= NoAnimation
;
1707 if (!m_model
|| m_model
->count() < 0) {
1711 int firstVisibleIndex
= m_layouter
->firstVisibleIndex();
1712 if (firstVisibleIndex
< 0) {
1713 emitOffsetChanges();
1717 // Do a sanity check of the scroll-offset property: When properties of the itemlist-view have been changed
1718 // it might be possible that the maximum offset got changed too. Assure that the full visible range
1719 // is still shown if the maximum offset got decreased.
1720 const qreal visibleOffsetRange
= (scrollOrientation() == Qt::Horizontal
) ? size().width() : size().height();
1721 const qreal maxOffsetToShowFullRange
= maximumScrollOffset() - visibleOffsetRange
;
1722 if (scrollOffset() > maxOffsetToShowFullRange
) {
1723 m_layouter
->setScrollOffset(qMax(qreal(0), maxOffsetToShowFullRange
));
1724 firstVisibleIndex
= m_layouter
->firstVisibleIndex();
1727 const int lastVisibleIndex
= m_layouter
->lastVisibleIndex();
1729 int firstSibblingIndex
= -1;
1730 int lastSibblingIndex
= -1;
1731 const bool supportsExpanding
= supportsItemExpanding();
1733 QList
<int> reusableItems
= recycleInvisibleItems(firstVisibleIndex
, lastVisibleIndex
, hint
);
1735 // Assure that for each visible item a KItemListWidget is available. KItemListWidget
1736 // instances from invisible items are reused. If no reusable items are
1737 // found then new KItemListWidget instances get created.
1738 const bool animate
= (hint
== Animation
);
1739 for (int i
= firstVisibleIndex
; i
<= lastVisibleIndex
; ++i
) {
1740 bool applyNewPos
= true;
1742 const QRectF itemBounds
= m_layouter
->itemRect(i
);
1743 const QPointF newPos
= itemBounds
.topLeft();
1744 KItemListWidget
*widget
= m_visibleItems
.value(i
);
1746 if (!reusableItems
.isEmpty()) {
1747 // Reuse a KItemListWidget instance from an invisible item
1748 const int oldIndex
= reusableItems
.takeLast();
1749 widget
= m_visibleItems
.value(oldIndex
);
1750 setWidgetIndex(widget
, i
);
1751 updateWidgetProperties(widget
, i
);
1752 initializeItemListWidget(widget
);
1754 // No reusable KItemListWidget instance is available, create a new one
1755 widget
= createWidget(i
);
1757 widget
->resize(itemBounds
.size());
1759 if (animate
&& changedCount
< 0) {
1760 // Items have been deleted.
1761 if (i
>= changedIndex
) {
1762 // The item is located behind the removed range. Move the
1763 // created item to the imaginary old position outside the
1764 // view. It will get animated to the new position later.
1765 const int previousIndex
= i
- changedCount
;
1766 const QRectF itemRect
= m_layouter
->itemRect(previousIndex
);
1767 if (itemRect
.isEmpty()) {
1768 const QPointF invisibleOldPos
= (scrollOrientation() == Qt::Vertical
) ? QPointF(0, size().height()) : QPointF(size().width(), 0);
1769 widget
->setPos(invisibleOldPos
);
1771 widget
->setPos(itemRect
.topLeft());
1773 applyNewPos
= false;
1777 if (supportsExpanding
&& changedCount
== 0) {
1778 if (firstSibblingIndex
< 0) {
1779 firstSibblingIndex
= i
;
1781 lastSibblingIndex
= i
;
1786 if (m_animation
->isStarted(widget
, KItemListViewAnimation::MovingAnimation
)) {
1787 m_animation
->start(widget
, KItemListViewAnimation::MovingAnimation
, newPos
);
1788 applyNewPos
= false;
1791 const bool itemsRemoved
= (changedCount
< 0);
1792 const bool itemsInserted
= (changedCount
> 0);
1793 if (itemsRemoved
&& (i
>= changedIndex
)) {
1794 // The item is located after the removed items. Animate the moving of the position.
1795 applyNewPos
= !moveWidget(widget
, newPos
);
1796 } else if (itemsInserted
&& i
>= changedIndex
) {
1797 // The item is located after the first inserted item
1798 if (i
<= changedIndex
+ changedCount
- 1) {
1799 // The item is an inserted item. Animate the appearing of the item.
1800 // For performance reasons no animation is done when changedCount is equal
1801 // to all available items.
1802 if (changedCount
< m_model
->count()) {
1803 m_animation
->start(widget
, KItemListViewAnimation::CreateAnimation
);
1805 } else if (!m_animation
->isStarted(widget
, KItemListViewAnimation::CreateAnimation
)) {
1806 // The item was already there before, so animate the moving of the position.
1807 // No moving animation is done if the item is animated by a create animation: This
1808 // prevents a "move animation mess" when inserting several ranges in parallel.
1809 applyNewPos
= !moveWidget(widget
, newPos
);
1813 m_animation
->stop(widget
);
1817 widget
->setPos(newPos
);
1820 Q_ASSERT(widget
->index() == i
);
1821 widget
->setVisible(true);
1823 bool animateIconResizing
= animate
;
1825 if (widget
->size() != itemBounds
.size()) {
1826 // Resize the widget for the item to the changed size.
1828 // If a dynamic item size is used then no animation is done in the direction
1829 // of the dynamic size.
1830 if (m_itemSize
.width() <= 0) {
1831 // The width is dynamic, apply the new width without animation.
1832 widget
->resize(itemBounds
.width(), widget
->size().height());
1833 } else if (m_itemSize
.height() <= 0) {
1834 // The height is dynamic, apply the new height without animation.
1835 widget
->resize(widget
->size().width(), itemBounds
.height());
1837 m_animation
->start(widget
, KItemListViewAnimation::ResizeAnimation
, itemBounds
.size());
1839 widget
->resize(itemBounds
.size());
1842 animateIconResizing
= false;
1845 const int newIconSize
= widget
->styleOption().iconSize
;
1846 if (widget
->iconSize() != newIconSize
) {
1847 if (animateIconResizing
) {
1848 m_animation
->start(widget
, KItemListViewAnimation::IconResizeAnimation
, newIconSize
);
1850 widget
->setIconSize(newIconSize
);
1854 // Updating the cell-information must be done as last step: The decision whether the
1855 // moving-animation should be started at all is based on the previous cell-information.
1856 const Cell
cell(m_layouter
->itemColumn(i
), m_layouter
->itemRow(i
));
1857 m_visibleCells
.insert(i
, cell
);
1860 // Delete invisible KItemListWidget instances that have not been reused
1861 for (int index
: std::as_const(reusableItems
)) {
1862 recycleWidget(m_visibleItems
.value(index
));
1865 if (supportsExpanding
&& firstSibblingIndex
>= 0) {
1866 Q_ASSERT(lastSibblingIndex
>= 0);
1867 updateSiblingsInformation(firstSibblingIndex
, lastSibblingIndex
);
1871 // Update the layout of all visible group headers
1872 QHashIterator
<KItemListWidget
*, KItemListGroupHeader
*> it(m_visibleGroups
);
1873 while (it
.hasNext()) {
1875 updateGroupHeaderLayout(it
.key());
1879 emitOffsetChanges();
1882 QList
<int> KItemListView::recycleInvisibleItems(int firstVisibleIndex
, int lastVisibleIndex
, LayoutAnimationHint hint
)
1884 // Determine all items that are completely invisible and might be
1885 // reused for items that just got (at least partly) visible. If the
1886 // animation hint is set to 'Animation' items that do e.g. an animated
1887 // moving of their position are not marked as invisible: This assures
1888 // that a scrolling inside the view can be done without breaking an animation.
1892 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
1893 while (it
.hasNext()) {
1896 KItemListWidget
*widget
= it
.value();
1897 const int index
= widget
->index();
1898 const bool invisible
= (index
< firstVisibleIndex
) || (index
> lastVisibleIndex
);
1901 if (m_animation
->isStarted(widget
)) {
1902 if (hint
== NoAnimation
) {
1903 // Stopping the animation will call KItemListView::slotAnimationFinished()
1904 // and the widget will be recycled if necessary there.
1905 m_animation
->stop(widget
);
1908 widget
->setVisible(false);
1909 items
.append(index
);
1912 recycleGroupHeaderForWidget(widget
);
1921 bool KItemListView::moveWidget(KItemListWidget
*widget
, const QPointF
&newPos
)
1923 if (widget
->pos() == newPos
) {
1927 bool startMovingAnim
= false;
1929 if (m_itemSize
.isEmpty()) {
1930 // The items are not aligned in a grid but either as columns or rows.
1931 startMovingAnim
= true;
1933 // When having a grid the moving-animation should only be started, if it is done within
1934 // one row in the vertical scroll-orientation or one column in the horizontal scroll-orientation.
1935 // Otherwise instead of a moving-animation a create-animation on the new position will be used
1936 // instead. This is done to prevent overlapping (and confusing) moving-animations.
1937 const int index
= widget
->index();
1938 const Cell cell
= m_visibleCells
.value(index
);
1939 if (cell
.column
>= 0 && cell
.row
>= 0) {
1940 if (scrollOrientation() == Qt::Vertical
) {
1941 startMovingAnim
= (cell
.row
== m_layouter
->itemRow(index
));
1943 startMovingAnim
= (cell
.column
== m_layouter
->itemColumn(index
));
1948 if (startMovingAnim
) {
1949 m_animation
->start(widget
, KItemListViewAnimation::MovingAnimation
, newPos
);
1953 m_animation
->stop(widget
);
1954 m_animation
->start(widget
, KItemListViewAnimation::CreateAnimation
);
1958 void KItemListView::emitOffsetChanges()
1960 const qreal newScrollOffset
= m_layouter
->scrollOffset();
1961 if (m_oldScrollOffset
!= newScrollOffset
) {
1962 Q_EMIT
scrollOffsetChanged(newScrollOffset
, m_oldScrollOffset
);
1963 m_oldScrollOffset
= newScrollOffset
;
1966 const qreal newMaximumScrollOffset
= m_layouter
->maximumScrollOffset();
1967 if (m_oldMaximumScrollOffset
!= newMaximumScrollOffset
) {
1968 Q_EMIT
maximumScrollOffsetChanged(newMaximumScrollOffset
, m_oldMaximumScrollOffset
);
1969 m_oldMaximumScrollOffset
= newMaximumScrollOffset
;
1972 const qreal newItemOffset
= m_layouter
->itemOffset();
1973 if (m_oldItemOffset
!= newItemOffset
) {
1974 Q_EMIT
itemOffsetChanged(newItemOffset
, m_oldItemOffset
);
1975 m_oldItemOffset
= newItemOffset
;
1978 const qreal newMaximumItemOffset
= m_layouter
->maximumItemOffset();
1979 if (m_oldMaximumItemOffset
!= newMaximumItemOffset
) {
1980 Q_EMIT
maximumItemOffsetChanged(newMaximumItemOffset
, m_oldMaximumItemOffset
);
1981 m_oldMaximumItemOffset
= newMaximumItemOffset
;
1985 KItemListWidget
*KItemListView::createWidget(int index
)
1987 KItemListWidget
*widget
= widgetCreator()->create(this);
1988 widget
->setFlag(QGraphicsItem::ItemStacksBehindParent
);
1990 m_visibleItems
.insert(index
, widget
);
1991 m_visibleCells
.insert(index
, Cell());
1992 updateWidgetProperties(widget
, index
);
1993 initializeItemListWidget(widget
);
1997 void KItemListView::recycleWidget(KItemListWidget
*widget
)
2000 recycleGroupHeaderForWidget(widget
);
2003 const int index
= widget
->index();
2004 m_visibleItems
.remove(index
);
2005 m_visibleCells
.remove(index
);
2007 widgetCreator()->recycle(widget
);
2010 void KItemListView::setWidgetIndex(KItemListWidget
*widget
, int index
)
2012 const int oldIndex
= widget
->index();
2013 m_visibleItems
.remove(oldIndex
);
2014 m_visibleCells
.remove(oldIndex
);
2016 m_visibleItems
.insert(index
, widget
);
2017 m_visibleCells
.insert(index
, Cell());
2019 widget
->setIndex(index
);
2022 void KItemListView::moveWidgetToIndex(KItemListWidget
*widget
, int index
)
2024 const int oldIndex
= widget
->index();
2025 const Cell oldCell
= m_visibleCells
.value(oldIndex
);
2027 setWidgetIndex(widget
, index
);
2029 const Cell
newCell(m_layouter
->itemColumn(index
), m_layouter
->itemRow(index
));
2030 const bool vertical
= (scrollOrientation() == Qt::Vertical
);
2031 const bool updateCell
= (vertical
&& oldCell
.row
== newCell
.row
) || (!vertical
&& oldCell
.column
== newCell
.column
);
2033 m_visibleCells
.insert(index
, newCell
);
2037 void KItemListView::setLayouterSize(const QSizeF
&size
, SizeType sizeType
)
2041 m_layouter
->setSize(size
);
2044 m_layouter
->setItemSize(size
);
2051 void KItemListView::updateWidgetProperties(KItemListWidget
*widget
, int index
)
2053 widget
->setVisibleRoles(m_visibleRoles
);
2054 updateWidgetColumnWidths(widget
);
2055 widget
->setStyleOption(m_styleOption
);
2057 const KItemListSelectionManager
*selectionManager
= m_controller
->selectionManager();
2059 // In SingleSelection mode (e.g., in the Places Panel), the current item is
2060 // always the selected item. It is not necessary to highlight the current item then.
2061 if (m_controller
->selectionBehavior() != KItemListController::SingleSelection
) {
2062 widget
->setCurrent(index
== selectionManager
->currentItem());
2064 widget
->setSelected(selectionManager
->isSelected(index
));
2065 widget
->setHovered(false);
2066 widget
->setEnabledSelectionToggle(enabledSelectionToggles());
2067 widget
->setIndex(index
);
2068 widget
->setData(m_model
->data(index
));
2069 widget
->setSiblingsInformation(QBitArray());
2070 updateAlternateBackgroundForWidget(widget
);
2073 updateGroupHeaderForWidget(widget
);
2077 void KItemListView::updateGroupHeaderForWidget(KItemListWidget
*widget
)
2079 Q_ASSERT(m_grouped
);
2081 const int index
= widget
->index();
2082 if (!m_layouter
->isFirstGroupItem(index
)) {
2083 // The widget does not represent the first item of a group
2084 // and hence requires no header
2085 recycleGroupHeaderForWidget(widget
);
2089 const QList
<QPair
<int, QVariant
>> groups
= model()->groups();
2090 if (groups
.isEmpty() || !groupHeaderCreator()) {
2094 KItemListGroupHeader
*groupHeader
= m_visibleGroups
.value(widget
);
2096 groupHeader
= groupHeaderCreator()->create(this);
2097 groupHeader
->setParentItem(widget
);
2098 m_visibleGroups
.insert(widget
, groupHeader
);
2099 connect(widget
, &KItemListWidget::geometryChanged
, this, &KItemListView::slotGeometryOfGroupHeaderParentChanged
);
2101 Q_ASSERT(groupHeader
->parentItem() == widget
);
2103 const int groupIndex
= groupIndexForItem(index
);
2104 Q_ASSERT(groupIndex
>= 0);
2105 groupHeader
->setData(groups
.at(groupIndex
).second
);
2106 groupHeader
->setRole(model()->sortRole());
2107 groupHeader
->setStyleOption(m_styleOption
);
2108 groupHeader
->setScrollOrientation(scrollOrientation());
2109 groupHeader
->setItemIndex(index
);
2111 groupHeader
->show();
2114 void KItemListView::updateGroupHeaderLayout(KItemListWidget
*widget
)
2116 KItemListGroupHeader
*groupHeader
= m_visibleGroups
.value(widget
);
2117 Q_ASSERT(groupHeader
);
2119 const int index
= widget
->index();
2120 const QRectF groupHeaderRect
= m_layouter
->groupHeaderRect(index
);
2121 const QRectF itemRect
= m_layouter
->itemRect(index
);
2123 // The group-header is a child of the itemlist widget. Translate the
2124 // group header position to the relative position.
2125 if (scrollOrientation() == Qt::Vertical
) {
2126 // In the vertical scroll orientation the group header should always span
2127 // the whole width no matter which temporary position the parent widget
2128 // has. In this case the x-position and width will be adjusted manually.
2129 const qreal x
= -widget
->x() - itemOffset();
2130 const qreal width
= maximumItemOffset();
2131 groupHeader
->setPos(x
, -groupHeaderRect
.height());
2132 groupHeader
->resize(width
, groupHeaderRect
.size().height());
2134 groupHeader
->setPos(groupHeaderRect
.x() - itemRect
.x(), -widget
->y());
2135 groupHeader
->resize(groupHeaderRect
.size());
2139 void KItemListView::recycleGroupHeaderForWidget(KItemListWidget
*widget
)
2141 KItemListGroupHeader
*header
= m_visibleGroups
.value(widget
);
2143 header
->setParentItem(nullptr);
2144 groupHeaderCreator()->recycle(header
);
2145 m_visibleGroups
.remove(widget
);
2146 disconnect(widget
, &KItemListWidget::geometryChanged
, this, &KItemListView::slotGeometryOfGroupHeaderParentChanged
);
2150 void KItemListView::updateVisibleGroupHeaders()
2152 Q_ASSERT(m_grouped
);
2153 m_layouter
->markAsDirty();
2155 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
2156 while (it
.hasNext()) {
2158 updateGroupHeaderForWidget(it
.value());
2162 int KItemListView::groupIndexForItem(int index
) const
2164 Q_ASSERT(m_grouped
);
2166 const QList
<QPair
<int, QVariant
>> groups
= model()->groups();
2167 if (groups
.isEmpty()) {
2172 int max
= groups
.count() - 1;
2175 mid
= (min
+ max
) / 2;
2176 if (index
> groups
[mid
].first
) {
2181 } while (groups
[mid
].first
!= index
&& min
<= max
);
2184 while (groups
[mid
].first
> index
&& mid
> 0) {
2192 void KItemListView::updateAlternateBackgrounds()
2194 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
2195 while (it
.hasNext()) {
2197 updateAlternateBackgroundForWidget(it
.value());
2201 void KItemListView::updateAlternateBackgroundForWidget(KItemListWidget
*widget
)
2203 bool enabled
= useAlternateBackgrounds();
2205 const int index
= widget
->index();
2206 enabled
= (index
& 0x1) > 0;
2208 const int groupIndex
= groupIndexForItem(index
);
2209 if (groupIndex
>= 0) {
2210 const QList
<QPair
<int, QVariant
>> groups
= model()->groups();
2211 const int indexOfFirstGroupItem
= groups
[groupIndex
].first
;
2212 const int relativeIndex
= index
- indexOfFirstGroupItem
;
2213 enabled
= (relativeIndex
& 0x1) > 0;
2217 widget
->setAlternateBackground(enabled
);
2220 bool KItemListView::useAlternateBackgrounds() const
2222 return m_alternateBackgrounds
&& m_itemSize
.isEmpty();
2225 QHash
<QByteArray
, qreal
> KItemListView::preferredColumnWidths(const KItemRangeList
&itemRanges
) const
2227 QElapsedTimer timer
;
2230 QHash
<QByteArray
, qreal
> widths
;
2232 // Calculate the minimum width for each column that is required
2233 // to show the headline unclipped.
2234 const QFontMetricsF
fontMetrics(m_headerWidget
->font());
2235 const int gripMargin
= m_headerWidget
->style()->pixelMetric(QStyle::PM_HeaderGripMargin
);
2236 const int headerMargin
= m_headerWidget
->style()->pixelMetric(QStyle::PM_HeaderMargin
);
2237 for (const QByteArray
&visibleRole
: std::as_const(m_visibleRoles
)) {
2238 const QString headerText
= m_model
->roleDescription(visibleRole
);
2239 const qreal headerWidth
= fontMetrics
.horizontalAdvance(headerText
) + gripMargin
+ headerMargin
* 2;
2240 widths
.insert(visibleRole
, headerWidth
);
2243 // Calculate the preferred column widths for each item and ignore values
2244 // smaller than the width for showing the headline unclipped.
2245 const KItemListWidgetCreatorBase
*creator
= widgetCreator();
2246 int calculatedItemCount
= 0;
2247 bool maxTimeExceeded
= false;
2248 for (const KItemRange
&itemRange
: itemRanges
) {
2249 const int startIndex
= itemRange
.index
;
2250 const int endIndex
= startIndex
+ itemRange
.count
- 1;
2252 for (int i
= startIndex
; i
<= endIndex
; ++i
) {
2253 for (const QByteArray
&visibleRole
: std::as_const(m_visibleRoles
)) {
2254 qreal maxWidth
= widths
.value(visibleRole
, 0);
2255 const qreal width
= creator
->preferredRoleColumnWidth(visibleRole
, i
, this);
2256 maxWidth
= qMax(width
, maxWidth
);
2257 widths
.insert(visibleRole
, maxWidth
);
2260 if (calculatedItemCount
> 100 && timer
.elapsed() > 200) {
2261 // When having several thousands of items calculating the sizes can get
2262 // very expensive. We accept a possibly too small role-size in favour
2263 // of having no blocking user interface.
2264 maxTimeExceeded
= true;
2267 ++calculatedItemCount
;
2269 if (maxTimeExceeded
) {
2277 void KItemListView::applyColumnWidthsFromHeader()
2279 // Apply the new size to the layouter
2280 const qreal requiredWidth
= columnWidthsSum() + 2 * m_headerWidget
->sidePadding();
2281 const QSizeF
dynamicItemSize(qMax(size().width(), requiredWidth
), m_itemSize
.height());
2282 m_layouter
->setItemSize(dynamicItemSize
);
2284 // Update the role sizes for all visible widgets
2285 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
2286 while (it
.hasNext()) {
2288 updateWidgetColumnWidths(it
.value());
2292 void KItemListView::updateWidgetColumnWidths(KItemListWidget
*widget
)
2294 for (const QByteArray
&role
: std::as_const(m_visibleRoles
)) {
2295 widget
->setColumnWidth(role
, m_headerWidget
->columnWidth(role
));
2297 widget
->setSidePadding(m_headerWidget
->sidePadding());
2300 void KItemListView::updatePreferredColumnWidths(const KItemRangeList
&itemRanges
)
2302 Q_ASSERT(m_itemSize
.isEmpty());
2303 const int itemCount
= m_model
->count();
2304 int rangesItemCount
= 0;
2305 for (const KItemRange
&range
: itemRanges
) {
2306 rangesItemCount
+= range
.count
;
2309 if (itemCount
== rangesItemCount
) {
2310 const QHash
<QByteArray
, qreal
> preferredWidths
= preferredColumnWidths(itemRanges
);
2311 for (const QByteArray
&role
: std::as_const(m_visibleRoles
)) {
2312 m_headerWidget
->setPreferredColumnWidth(role
, preferredWidths
.value(role
));
2315 // Only a sub range of the roles need to be determined.
2316 // The chances are good that the widths of the sub ranges
2317 // already fit into the available widths and hence no
2318 // expensive update might be required.
2319 bool changed
= false;
2321 const QHash
<QByteArray
, qreal
> updatedWidths
= preferredColumnWidths(itemRanges
);
2322 QHashIterator
<QByteArray
, qreal
> it(updatedWidths
);
2323 while (it
.hasNext()) {
2325 const QByteArray
&role
= it
.key();
2326 const qreal updatedWidth
= it
.value();
2327 const qreal currentWidth
= m_headerWidget
->preferredColumnWidth(role
);
2328 if (updatedWidth
> currentWidth
) {
2329 m_headerWidget
->setPreferredColumnWidth(role
, updatedWidth
);
2335 // All the updated sizes are smaller than the current sizes and no change
2336 // of the stretched roles-widths is required
2341 if (m_headerWidget
->automaticColumnResizing()) {
2342 applyAutomaticColumnWidths();
2346 void KItemListView::updatePreferredColumnWidths()
2349 updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model
->count()));
2353 void KItemListView::applyAutomaticColumnWidths()
2355 Q_ASSERT(m_itemSize
.isEmpty());
2356 Q_ASSERT(m_headerWidget
->automaticColumnResizing());
2357 if (m_visibleRoles
.isEmpty()) {
2361 // Calculate the maximum size of an item by considering the
2362 // visible role sizes and apply them to the layouter. If the
2363 // size does not use the available view-size the size of the
2364 // first role will get stretched.
2366 for (const QByteArray
&role
: std::as_const(m_visibleRoles
)) {
2367 const qreal preferredWidth
= m_headerWidget
->preferredColumnWidth(role
);
2368 m_headerWidget
->setColumnWidth(role
, preferredWidth
);
2371 const QByteArray firstRole
= m_visibleRoles
.first();
2372 qreal firstColumnWidth
= m_headerWidget
->columnWidth(firstRole
);
2373 QSizeF dynamicItemSize
= m_itemSize
;
2375 qreal requiredWidth
= columnWidthsSum() + 2 * m_headerWidget
->sidePadding(); // Adding the padding a second time so we have the same padding
2376 // symmetrically on both sides of the view. This improves UX, looks better and increases the chances of users figuring out that the padding
2377 // area can be used for deselecting and dropping files.
2378 const qreal availableWidth
= size().width();
2379 if (requiredWidth
< availableWidth
) {
2380 // Stretch the first column to use the whole remaining width
2381 firstColumnWidth
+= availableWidth
- requiredWidth
;
2382 m_headerWidget
->setColumnWidth(firstRole
, firstColumnWidth
);
2383 } else if (requiredWidth
> availableWidth
&& m_visibleRoles
.count() > 1) {
2384 // Shrink the first column to be able to show as much other
2385 // columns as possible
2386 qreal shrinkedFirstColumnWidth
= firstColumnWidth
- requiredWidth
+ availableWidth
;
2388 // TODO: A proper calculation of the minimum width depends on the implementation
2389 // of KItemListWidget. Probably a kind of minimum size-hint should be introduced
2391 const qreal minWidth
= qMin(firstColumnWidth
, qreal(m_styleOption
.iconSize
* 2 + 200));
2392 if (shrinkedFirstColumnWidth
< minWidth
) {
2393 shrinkedFirstColumnWidth
= minWidth
;
2396 m_headerWidget
->setColumnWidth(firstRole
, shrinkedFirstColumnWidth
);
2397 requiredWidth
-= firstColumnWidth
- shrinkedFirstColumnWidth
;
2400 dynamicItemSize
.rwidth() = qMax(requiredWidth
, availableWidth
);
2402 m_layouter
->setItemSize(dynamicItemSize
);
2404 // Update the role sizes for all visible widgets
2405 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
2406 while (it
.hasNext()) {
2408 updateWidgetColumnWidths(it
.value());
2412 qreal
KItemListView::columnWidthsSum() const
2414 qreal widthsSum
= 0;
2415 for (const QByteArray
&role
: std::as_const(m_visibleRoles
)) {
2416 widthsSum
+= m_headerWidget
->columnWidth(role
);
2421 QRectF
KItemListView::headerBoundaries() const
2423 return m_headerWidget
->isVisible() ? m_headerWidget
->geometry() : QRectF();
2426 bool KItemListView::changesItemGridLayout(const QSizeF
&newGridSize
, const QSizeF
&newItemSize
, const QSizeF
&newItemMargin
) const
2428 if (newItemSize
.isEmpty() || newGridSize
.isEmpty()) {
2432 if (m_layouter
->scrollOrientation() == Qt::Vertical
) {
2433 const qreal itemWidth
= m_layouter
->itemSize().width();
2434 if (itemWidth
> 0) {
2435 const int newColumnCount
= itemsPerSize(newGridSize
.width(), newItemSize
.width(), newItemMargin
.width());
2436 if (m_model
->count() > newColumnCount
) {
2437 const int oldColumnCount
= itemsPerSize(m_layouter
->size().width(), itemWidth
, m_layouter
->itemMargin().width());
2438 return oldColumnCount
!= newColumnCount
;
2442 const qreal itemHeight
= m_layouter
->itemSize().height();
2443 if (itemHeight
> 0) {
2444 const int newRowCount
= itemsPerSize(newGridSize
.height(), newItemSize
.height(), newItemMargin
.height());
2445 if (m_model
->count() > newRowCount
) {
2446 const int oldRowCount
= itemsPerSize(m_layouter
->size().height(), itemHeight
, m_layouter
->itemMargin().height());
2447 return oldRowCount
!= newRowCount
;
2455 bool KItemListView::animateChangedItemCount(int changedItemCount
) const
2457 if (m_itemSize
.isEmpty()) {
2458 // We have only columns or only rows, but no grid: An animation is usually
2459 // welcome when inserting or removing items.
2460 return !supportsItemExpanding();
2463 if (m_layouter
->size().isEmpty() || m_layouter
->itemSize().isEmpty()) {
2467 const int maximum
= (scrollOrientation() == Qt::Vertical
) ? m_layouter
->size().width() / m_layouter
->itemSize().width()
2468 : m_layouter
->size().height() / m_layouter
->itemSize().height();
2469 // Only animate if up to 2/3 of a row or column are inserted or removed
2470 return changedItemCount
<= maximum
* 2 / 3;
2473 bool KItemListView::scrollBarRequired(const QSizeF
&size
) const
2475 const QSizeF oldSize
= m_layouter
->size();
2477 m_layouter
->setSize(size
);
2478 const qreal maxOffset
= m_layouter
->maximumScrollOffset();
2479 m_layouter
->setSize(oldSize
);
2481 return m_layouter
->scrollOrientation() == Qt::Vertical
? maxOffset
> size
.height() : maxOffset
> size
.width();
2484 int KItemListView::showDropIndicator(const QPointF
&pos
)
2486 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
2487 while (it
.hasNext()) {
2489 const KItemListWidget
*widget
= it
.value();
2491 const QPointF mappedPos
= widget
->mapFromItem(this, pos
);
2492 const QRectF rect
= itemRect(widget
->index());
2493 if (mappedPos
.y() >= 0 && mappedPos
.y() <= rect
.height()) {
2494 if (m_model
->supportsDropping(widget
->index())) {
2495 // Keep 30% of the rectangle as the gap instead of always having a fixed gap
2496 const int gap
= qMax(qreal(4.0), qreal(0.3) * rect
.height());
2497 if (mappedPos
.y() >= gap
&& mappedPos
.y() <= rect
.height() - gap
) {
2502 const bool isAboveItem
= (mappedPos
.y() < rect
.height() / 2);
2503 const qreal y
= isAboveItem
? rect
.top() : rect
.bottom();
2505 const QRectF
draggingInsertIndicator(rect
.left(), y
, rect
.width(), 1);
2506 if (m_dropIndicator
!= draggingInsertIndicator
) {
2507 m_dropIndicator
= draggingInsertIndicator
;
2511 int index
= widget
->index();
2519 const QRectF firstItemRect
= itemRect(firstVisibleIndex());
2520 return (pos
.y() <= firstItemRect
.top()) ? 0 : -1;
2523 void KItemListView::hideDropIndicator()
2525 if (!m_dropIndicator
.isNull()) {
2526 m_dropIndicator
= QRectF();
2531 void KItemListView::updateGroupHeaderHeight()
2533 qreal groupHeaderHeight
= m_styleOption
.fontMetrics
.height();
2534 qreal groupHeaderMargin
= 0;
2536 if (scrollOrientation() == Qt::Horizontal
) {
2537 // The vertical margin above and below the header should be
2538 // equal to the horizontal margin, not the vertical margin
2539 // from m_styleOption.
2540 groupHeaderHeight
+= 2 * m_styleOption
.horizontalMargin
;
2541 groupHeaderMargin
= m_styleOption
.horizontalMargin
;
2542 } else if (m_itemSize
.isEmpty()) {
2543 groupHeaderHeight
+= 4 * m_styleOption
.padding
;
2544 groupHeaderMargin
= m_styleOption
.iconSize
/ 2;
2546 groupHeaderHeight
+= 2 * m_styleOption
.padding
+ m_styleOption
.verticalMargin
;
2547 groupHeaderMargin
= m_styleOption
.iconSize
/ 4;
2549 m_layouter
->setGroupHeaderHeight(groupHeaderHeight
);
2550 m_layouter
->setGroupHeaderMargin(groupHeaderMargin
);
2552 updateVisibleGroupHeaders();
2555 void KItemListView::updateSiblingsInformation(int firstIndex
, int lastIndex
)
2557 if (!supportsItemExpanding() || !m_model
) {
2561 if (firstIndex
< 0 || lastIndex
< 0) {
2562 firstIndex
= m_layouter
->firstVisibleIndex();
2563 lastIndex
= m_layouter
->lastVisibleIndex();
2565 const bool isRangeVisible
= (firstIndex
<= m_layouter
->lastVisibleIndex() && lastIndex
>= m_layouter
->firstVisibleIndex());
2566 if (!isRangeVisible
) {
2571 int previousParents
= 0;
2572 QBitArray previousSiblings
;
2574 // The rootIndex describes the first index where the siblings get
2575 // calculated from. For the calculation the upper most parent item
2576 // is required. For performance reasons it is checked first whether
2577 // the visible items before or after the current range already
2578 // contain a siblings information which can be used as base.
2579 int rootIndex
= firstIndex
;
2581 KItemListWidget
*widget
= m_visibleItems
.value(firstIndex
- 1);
2583 // There is no visible widget before the range, check whether there
2584 // is one after the range:
2585 widget
= m_visibleItems
.value(lastIndex
+ 1);
2587 // The sibling information of the widget may only be used if
2588 // all items of the range have the same number of parents.
2589 const int parents
= m_model
->expandedParentsCount(lastIndex
+ 1);
2590 for (int i
= lastIndex
; i
>= firstIndex
; --i
) {
2591 if (m_model
->expandedParentsCount(i
) != parents
) {
2600 // Performance optimization: Use the sibling information of the visible
2601 // widget beside the given range.
2602 previousSiblings
= widget
->siblingsInformation();
2603 if (previousSiblings
.isEmpty()) {
2606 previousParents
= previousSiblings
.count() - 1;
2607 previousSiblings
.truncate(previousParents
);
2609 // Potentially slow path: Go back to the upper most parent of firstIndex
2610 // to be able to calculate the initial value for the siblings.
2611 while (rootIndex
> 0 && m_model
->expandedParentsCount(rootIndex
) > 0) {
2616 Q_ASSERT(previousParents
>= 0);
2617 for (int i
= rootIndex
; i
<= lastIndex
; ++i
) {
2618 // Update the parent-siblings in case if the current item represents
2619 // a child or an upper parent.
2620 const int currentParents
= m_model
->expandedParentsCount(i
);
2621 Q_ASSERT(currentParents
>= 0);
2622 if (previousParents
< currentParents
) {
2623 previousParents
= currentParents
;
2624 previousSiblings
.resize(currentParents
);
2625 previousSiblings
.setBit(currentParents
- 1, hasSiblingSuccessor(i
- 1));
2626 } else if (previousParents
> currentParents
) {
2627 previousParents
= currentParents
;
2628 previousSiblings
.truncate(currentParents
);
2631 if (i
>= firstIndex
) {
2632 // The index represents a visible item. Apply the parent-siblings
2633 // and update the sibling of the current item.
2634 KItemListWidget
*widget
= m_visibleItems
.value(i
);
2639 QBitArray siblings
= previousSiblings
;
2640 siblings
.resize(siblings
.count() + 1);
2641 siblings
.setBit(siblings
.count() - 1, hasSiblingSuccessor(i
));
2643 widget
->setSiblingsInformation(siblings
);
2648 bool KItemListView::hasSiblingSuccessor(int index
) const
2650 bool hasSuccessor
= false;
2651 const int parentsCount
= m_model
->expandedParentsCount(index
);
2652 int successorIndex
= index
+ 1;
2654 // Search the next sibling
2655 const int itemCount
= m_model
->count();
2656 while (successorIndex
< itemCount
) {
2657 const int currentParentsCount
= m_model
->expandedParentsCount(successorIndex
);
2658 if (currentParentsCount
== parentsCount
) {
2659 hasSuccessor
= true;
2661 } else if (currentParentsCount
< parentsCount
) {
2667 if (m_grouped
&& hasSuccessor
) {
2668 // If the sibling is part of another group, don't mark it as
2669 // successor as the group header is between the sibling connections.
2670 for (int i
= index
+ 1; i
<= successorIndex
; ++i
) {
2671 if (m_layouter
->isFirstGroupItem(i
)) {
2672 hasSuccessor
= false;
2678 return hasSuccessor
;
2681 void KItemListView::disconnectRoleEditingSignals(int index
)
2683 KStandardItemListWidget
*widget
= qobject_cast
<KStandardItemListWidget
*>(m_visibleItems
.value(index
));
2688 disconnect(widget
, &KItemListWidget::roleEditingCanceled
, this, nullptr);
2689 disconnect(widget
, &KItemListWidget::roleEditingFinished
, this, nullptr);
2690 disconnect(this, &KItemListView::scrollOffsetChanged
, widget
, nullptr);
2693 int KItemListView::calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
)
2697 const int minSpeed
= 4;
2698 const int maxSpeed
= 128;
2699 const int speedLimiter
= 96;
2700 const int autoScrollBorder
= 64;
2702 // Limit the increment that is allowed to be added in comparison to 'oldInc'.
2703 // This assures that the autoscrolling speed grows gradually.
2704 const int incLimiter
= 1;
2706 if (pos
< autoScrollBorder
) {
2707 inc
= -minSpeed
+ qAbs(pos
- autoScrollBorder
) * (pos
- autoScrollBorder
) / speedLimiter
;
2708 inc
= qMax(inc
, -maxSpeed
);
2709 inc
= qMax(inc
, oldInc
- incLimiter
);
2710 } else if (pos
> range
- autoScrollBorder
) {
2711 inc
= minSpeed
+ qAbs(pos
- range
+ autoScrollBorder
) * (pos
- range
+ autoScrollBorder
) / speedLimiter
;
2712 inc
= qMin(inc
, maxSpeed
);
2713 inc
= qMin(inc
, oldInc
+ incLimiter
);
2719 int KItemListView::itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
)
2721 const qreal availableSize
= size
- itemMargin
;
2722 const int count
= availableSize
/ (itemSize
+ itemMargin
);
2726 KItemListCreatorBase::~KItemListCreatorBase()
2728 qDeleteAll(m_recycleableWidgets
);
2729 qDeleteAll(m_createdWidgets
);
2732 void KItemListCreatorBase::addCreatedWidget(QGraphicsWidget
*widget
)
2734 m_createdWidgets
.insert(widget
);
2737 void KItemListCreatorBase::pushRecycleableWidget(QGraphicsWidget
*widget
)
2739 Q_ASSERT(m_createdWidgets
.contains(widget
));
2740 m_createdWidgets
.remove(widget
);
2742 if (m_recycleableWidgets
.count() < 100) {
2743 m_recycleableWidgets
.append(widget
);
2744 widget
->setVisible(false);
2750 QGraphicsWidget
*KItemListCreatorBase::popRecycleableWidget()
2752 if (m_recycleableWidgets
.isEmpty()) {
2756 QGraphicsWidget
*widget
= m_recycleableWidgets
.takeLast();
2757 m_createdWidgets
.insert(widget
);
2761 KItemListWidgetCreatorBase::~KItemListWidgetCreatorBase()
2765 void KItemListWidgetCreatorBase::recycle(KItemListWidget
*widget
)
2767 widget
->setParentItem(nullptr);
2768 widget
->setOpacity(1.0);
2769 pushRecycleableWidget(widget
);
2772 KItemListGroupHeaderCreatorBase::~KItemListGroupHeaderCreatorBase()
2776 void KItemListGroupHeaderCreatorBase::recycle(KItemListGroupHeader
*header
)
2778 header
->setOpacity(1.0);
2779 pushRecycleableWidget(header
);
2782 #include "moc_kitemlistview.cpp"