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 if (auto controller
= container
->controller(); controller
) {
54 if (KItemListView
*view
= controller
->view(); view
&& view
->accessibleParent()) {
55 return view
->accessibleParent();
58 return new KItemListContainerAccessible(container
);
59 } else if (KItemListView
*view
= qobject_cast
<KItemListView
*>(object
)) {
60 return new KItemListViewAccessible(view
, view
->accessibleParent());
67 KItemListView::KItemListView(QGraphicsWidget
*parent
)
68 : QGraphicsWidget(parent
)
69 , m_enabledSelectionToggles(false)
71 , m_highlightEntireRow(false)
72 , m_alternateBackgrounds(false)
73 , m_supportsItemExpanding(false)
74 , m_editingRole(false)
75 , m_activeTransactions(0)
76 , m_endTransactionAnimationHint(Animation
)
78 , m_controller(nullptr)
81 , m_widgetCreator(nullptr)
82 , m_groupHeaderCreator(nullptr)
87 , m_scrollBarExtent(0)
89 , m_animation(nullptr)
90 , m_oldScrollOffset(0)
91 , m_oldMaximumScrollOffset(0)
93 , m_oldMaximumItemOffset(0)
94 , m_skipAutoScrollForRubberBand(false)
95 , m_rubberBand(nullptr)
96 , m_tapAndHoldIndicator(nullptr)
98 , m_autoScrollIncrement(0)
99 , m_autoScrollTimer(nullptr)
101 , m_headerWidget(nullptr)
102 , m_indicatorAnimation(nullptr)
104 , m_sizeHintResolver(nullptr)
106 setAcceptHoverEvents(true);
107 setAcceptTouchEvents(true);
109 m_sizeHintResolver
= new KItemListSizeHintResolver(this);
111 m_layouter
= new KItemListViewLayouter(m_sizeHintResolver
, this);
113 m_animation
= new KItemListViewAnimation(this);
114 connect(m_animation
, &KItemListViewAnimation::finished
, this, &KItemListView::slotAnimationFinished
);
116 m_rubberBand
= new KItemListRubberBand(this);
117 connect(m_rubberBand
, &KItemListRubberBand::activationChanged
, this, &KItemListView::slotRubberBandActivationChanged
);
119 m_tapAndHoldIndicator
= new KItemListRubberBand(this);
120 m_indicatorAnimation
= new QPropertyAnimation(m_tapAndHoldIndicator
, "endPosition", this);
121 connect(m_tapAndHoldIndicator
, &KItemListRubberBand::activationChanged
, this, [this](bool active
) {
123 m_indicatorAnimation
->setDuration(150);
124 m_indicatorAnimation
->setStartValue(QPointF(1, 1));
125 m_indicatorAnimation
->setEndValue(QPointF(40, 40));
126 m_indicatorAnimation
->start();
130 connect(m_tapAndHoldIndicator
, &KItemListRubberBand::endPositionChanged
, this, [this]() {
131 if (m_tapAndHoldIndicator
->isActive()) {
136 m_headerWidget
= new KItemListHeaderWidget(this);
137 m_headerWidget
->setVisible(false);
139 m_header
= new KItemListHeader(this);
141 #ifndef QT_NO_ACCESSIBILITY
142 QAccessible::installFactory(accessibleInterfaceFactory
);
146 KItemListView::~KItemListView()
148 // The group headers are children of the widgets created by
149 // widgetCreator(). So it is mandatory to delete the group headers
151 delete m_groupHeaderCreator
;
152 m_groupHeaderCreator
= nullptr;
154 delete m_widgetCreator
;
155 m_widgetCreator
= nullptr;
157 delete m_sizeHintResolver
;
158 m_sizeHintResolver
= nullptr;
161 void KItemListView::setScrollOffset(qreal offset
)
167 const qreal previousOffset
= m_layouter
->scrollOffset();
168 if (offset
== previousOffset
) {
172 m_layouter
->setScrollOffset(offset
);
173 m_animation
->setScrollOffset(offset
);
175 // Don't check whether the m_layoutTimer is active: Changing the
176 // scroll offset must always trigger a synchronous layout, otherwise
177 // the smooth-scrolling might get jerky.
178 doLayout(NoAnimation
);
179 onScrollOffsetChanged(offset
, previousOffset
);
182 qreal
KItemListView::scrollOffset() const
184 return m_layouter
->scrollOffset();
187 qreal
KItemListView::maximumScrollOffset() const
189 return m_layouter
->maximumScrollOffset();
192 void KItemListView::setItemOffset(qreal offset
)
194 if (m_layouter
->itemOffset() == offset
) {
198 m_layouter
->setItemOffset(offset
);
199 if (m_headerWidget
->isVisible()) {
200 m_headerWidget
->setOffset(offset
);
203 // Don't check whether the m_layoutTimer is active: Changing the
204 // item offset must always trigger a synchronous layout, otherwise
205 // the smooth-scrolling might get jerky.
206 doLayout(NoAnimation
);
209 qreal
KItemListView::itemOffset() const
211 return m_layouter
->itemOffset();
214 qreal
KItemListView::maximumItemOffset() const
216 return m_layouter
->maximumItemOffset();
219 int KItemListView::maximumVisibleItems() const
221 return m_layouter
->maximumVisibleItems();
224 void KItemListView::setVisibleRoles(const QList
<QByteArray
> &roles
)
226 const QList
<QByteArray
> previousRoles
= m_visibleRoles
;
227 m_visibleRoles
= roles
;
228 onVisibleRolesChanged(roles
, previousRoles
);
230 m_sizeHintResolver
->clearCache();
231 m_layouter
->markAsDirty();
233 if (m_itemSize
.isEmpty()) {
234 m_headerWidget
->setColumns(roles
);
235 updatePreferredColumnWidths();
236 if (!m_headerWidget
->automaticColumnResizing()) {
237 // The column-width of new roles are still 0. Apply the preferred
238 // column-width as default with.
239 for (const QByteArray
&role
: std::as_const(m_visibleRoles
)) {
240 if (m_headerWidget
->columnWidth(role
) == 0) {
241 const qreal width
= m_headerWidget
->preferredColumnWidth(role
);
242 m_headerWidget
->setColumnWidth(role
, width
);
246 applyColumnWidthsFromHeader();
250 const bool alternateBackgroundsChanged
=
251 m_itemSize
.isEmpty() && ((roles
.count() > 1 && previousRoles
.count() <= 1) || (roles
.count() <= 1 && previousRoles
.count() > 1));
253 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
254 while (it
.hasNext()) {
256 KItemListWidget
*widget
= it
.value();
257 widget
->setVisibleRoles(roles
);
258 if (alternateBackgroundsChanged
) {
259 updateAlternateBackgroundForWidget(widget
);
263 doLayout(NoAnimation
);
266 QList
<QByteArray
> KItemListView::visibleRoles() const
268 return m_visibleRoles
;
271 void KItemListView::setAutoScroll(bool enabled
)
273 if (enabled
&& !m_autoScrollTimer
) {
274 m_autoScrollTimer
= new QTimer(this);
275 m_autoScrollTimer
->setSingleShot(true);
276 connect(m_autoScrollTimer
, &QTimer::timeout
, this, &KItemListView::triggerAutoScrolling
);
277 m_autoScrollTimer
->start(InitialAutoScrollDelay
);
278 } else if (!enabled
&& m_autoScrollTimer
) {
279 delete m_autoScrollTimer
;
280 m_autoScrollTimer
= nullptr;
284 bool KItemListView::autoScroll() const
286 return m_autoScrollTimer
!= nullptr;
289 void KItemListView::setEnabledSelectionToggles(bool enabled
)
291 if (m_enabledSelectionToggles
!= enabled
) {
292 m_enabledSelectionToggles
= enabled
;
294 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
295 while (it
.hasNext()) {
297 it
.value()->setEnabledSelectionToggle(enabled
);
302 bool KItemListView::enabledSelectionToggles() const
304 return m_enabledSelectionToggles
;
307 KItemListController
*KItemListView::controller() const
312 KItemModelBase
*KItemListView::model() const
317 void KItemListView::setWidgetCreator(KItemListWidgetCreatorBase
*widgetCreator
)
319 delete m_widgetCreator
;
320 m_widgetCreator
= widgetCreator
;
323 KItemListWidgetCreatorBase
*KItemListView::widgetCreator() const
325 if (!m_widgetCreator
) {
326 m_widgetCreator
= defaultWidgetCreator();
328 return m_widgetCreator
;
331 void KItemListView::setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
*groupHeaderCreator
)
333 delete m_groupHeaderCreator
;
334 m_groupHeaderCreator
= groupHeaderCreator
;
337 KItemListGroupHeaderCreatorBase
*KItemListView::groupHeaderCreator() const
339 if (!m_groupHeaderCreator
) {
340 m_groupHeaderCreator
= defaultGroupHeaderCreator();
342 return m_groupHeaderCreator
;
345 #ifndef QT_NO_ACCESSIBILITY
346 void KItemListView::setAccessibleParentsObject(KItemListContainer
*accessibleParentsObject
)
348 Q_ASSERT(!m_accessibleParent
);
349 m_accessibleParent
= new KItemListContainerAccessible(accessibleParentsObject
);
351 KItemListContainerAccessible
*KItemListView::accessibleParent()
353 Q_CHECK_PTR(m_accessibleParent
); // We always want the accessibility tree/hierarchy to be complete.
354 return m_accessibleParent
;
358 QSizeF
KItemListView::itemSize() const
363 const KItemListStyleOption
&KItemListView::styleOption() const
365 return m_styleOption
;
368 void KItemListView::setGeometry(const QRectF
&rect
)
370 QGraphicsWidget::setGeometry(rect
);
376 const QSizeF newSize
= rect
.size();
377 if (m_itemSize
.isEmpty()) {
378 m_headerWidget
->resize(rect
.width(), m_headerWidget
->size().height());
379 if (m_headerWidget
->automaticColumnResizing()) {
380 applyAutomaticColumnWidths();
382 const qreal requiredWidth
= columnWidthsSum() + 2 * m_headerWidget
->sidePadding();
383 const QSizeF
dynamicItemSize(qMax(newSize
.width(), requiredWidth
), m_itemSize
.height());
384 m_layouter
->setItemSize(dynamicItemSize
);
388 m_layouter
->setSize(newSize
);
389 // We don't animate the moving of the items here because
390 // it would look like the items are slow to find their position.
391 doLayout(NoAnimation
);
394 qreal
KItemListView::verticalPageStep() const
396 qreal headerHeight
= 0;
397 if (m_headerWidget
->isVisible()) {
398 headerHeight
= m_headerWidget
->size().height();
400 return size().height() - headerHeight
;
403 std::optional
<int> KItemListView::itemAt(const QPointF
&pos
) const
405 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
406 while (it
.hasNext()) {
409 const KItemListWidget
*widget
= it
.value();
410 const QPointF mappedPos
= widget
->mapFromItem(this, pos
);
411 if (widget
->contains(mappedPos
) || widget
->selectionRect().contains(mappedPos
)) {
419 bool KItemListView::isAboveSelectionToggle(int index
, const QPointF
&pos
) const
421 if (!m_enabledSelectionToggles
) {
425 const KItemListWidget
*widget
= m_visibleItems
.value(index
);
427 const QRectF selectionToggleRect
= widget
->selectionToggleRect();
428 if (!selectionToggleRect
.isEmpty()) {
429 const QPointF mappedPos
= widget
->mapFromItem(this, pos
);
430 return selectionToggleRect
.contains(mappedPos
);
436 bool KItemListView::isAboveExpansionToggle(int index
, const QPointF
&pos
) const
438 const KItemListWidget
*widget
= m_visibleItems
.value(index
);
440 const QRectF expansionToggleRect
= widget
->expansionToggleRect();
441 if (!expansionToggleRect
.isEmpty()) {
442 const QPointF mappedPos
= widget
->mapFromItem(this, pos
);
443 return expansionToggleRect
.contains(mappedPos
);
449 bool KItemListView::isAboveText(int index
, const QPointF
&pos
) const
451 const KItemListWidget
*widget
= m_visibleItems
.value(index
);
453 const QRectF
&textRect
= widget
->textRect();
454 if (!textRect
.isEmpty()) {
455 const QPointF mappedPos
= widget
->mapFromItem(this, pos
);
456 return textRect
.contains(mappedPos
);
462 int KItemListView::firstVisibleIndex() const
464 return m_layouter
->firstVisibleIndex();
467 int KItemListView::lastVisibleIndex() const
469 return m_layouter
->lastVisibleIndex();
472 void KItemListView::calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>> &logicalHeightHints
, qreal
&logicalWidthHint
) const
474 widgetCreator()->calculateItemSizeHints(logicalHeightHints
, logicalWidthHint
, this);
477 void KItemListView::setSupportsItemExpanding(bool supportsExpanding
)
479 if (m_supportsItemExpanding
!= supportsExpanding
) {
480 m_supportsItemExpanding
= supportsExpanding
;
481 updateSiblingsInformation();
482 onSupportsItemExpandingChanged(supportsExpanding
);
486 bool KItemListView::supportsItemExpanding() const
488 return m_supportsItemExpanding
;
491 void KItemListView::setHighlightEntireRow(bool highlightEntireRow
)
493 if (m_highlightEntireRow
!= highlightEntireRow
) {
494 m_highlightEntireRow
= highlightEntireRow
;
495 onHighlightEntireRowChanged(highlightEntireRow
);
499 bool KItemListView::highlightEntireRow() const
501 return m_highlightEntireRow
;
504 void KItemListView::setAlternateBackgrounds(bool alternate
)
506 if (m_alternateBackgrounds
!= alternate
) {
507 m_alternateBackgrounds
= alternate
;
508 updateAlternateBackgrounds();
512 bool KItemListView::alternateBackgrounds() const
514 return m_alternateBackgrounds
;
517 QRectF
KItemListView::itemRect(int index
) const
519 return m_layouter
->itemRect(index
);
522 QRectF
KItemListView::itemContextRect(int index
) const
526 const KItemListWidget
*widget
= m_visibleItems
.value(index
);
528 contextRect
= widget
->iconRect() | widget
->textRect();
529 contextRect
.translate(itemRect(index
).topLeft());
535 bool KItemListView::isElided(int index
) const
537 return m_sizeHintResolver
->isElided(index
);
540 void KItemListView::scrollToItem(int index
)
542 QRectF viewGeometry
= geometry();
543 if (m_headerWidget
->isVisible()) {
544 const qreal headerHeight
= m_headerWidget
->size().height();
545 viewGeometry
.adjust(0, headerHeight
, 0, 0);
547 QRectF currentRect
= itemRect(index
);
549 // Fix for Bug 311099 - View the underscore when using Ctrl + PagDown
550 currentRect
.adjust(-m_styleOption
.horizontalMargin
, -m_styleOption
.verticalMargin
, m_styleOption
.horizontalMargin
, m_styleOption
.verticalMargin
);
552 if (!viewGeometry
.contains(currentRect
)) {
553 qreal newOffset
= scrollOffset();
554 if (scrollOrientation() == Qt::Vertical
) {
555 if (currentRect
.top() < viewGeometry
.top()) {
556 newOffset
+= currentRect
.top() - viewGeometry
.top();
557 } else if (currentRect
.bottom() > viewGeometry
.bottom()) {
558 newOffset
+= currentRect
.bottom() - viewGeometry
.bottom();
561 if (currentRect
.left() < viewGeometry
.left()) {
562 newOffset
+= currentRect
.left() - viewGeometry
.left();
563 } else if (currentRect
.right() > viewGeometry
.right()) {
564 newOffset
+= currentRect
.right() - viewGeometry
.right();
568 if (newOffset
!= scrollOffset()) {
569 Q_EMIT
scrollTo(newOffset
);
574 Q_EMIT
scrollingStopped();
577 void KItemListView::beginTransaction()
579 ++m_activeTransactions
;
580 if (m_activeTransactions
== 1) {
581 onTransactionBegin();
585 void KItemListView::endTransaction()
587 --m_activeTransactions
;
588 if (m_activeTransactions
< 0) {
589 m_activeTransactions
= 0;
590 qCWarning(DolphinDebug
) << "Mismatch between beginTransaction()/endTransaction()";
593 if (m_activeTransactions
== 0) {
595 doLayout(m_endTransactionAnimationHint
);
596 m_endTransactionAnimationHint
= Animation
;
600 bool KItemListView::isTransactionActive() const
602 return m_activeTransactions
> 0;
605 void KItemListView::setHeaderVisible(bool visible
)
607 if (visible
&& !m_headerWidget
->isVisible()) {
608 QStyleOptionHeader option
;
609 const QSize headerSize
= style()->sizeFromContents(QStyle::CT_HeaderSection
, &option
, QSize());
611 m_headerWidget
->setPos(0, 0);
612 m_headerWidget
->resize(size().width(), headerSize
.height());
613 m_headerWidget
->setModel(m_model
);
614 m_headerWidget
->setColumns(m_visibleRoles
);
615 m_headerWidget
->setZValue(1);
617 connect(m_headerWidget
, &KItemListHeaderWidget::columnWidthChanged
, this, &KItemListView::slotHeaderColumnWidthChanged
);
618 connect(m_headerWidget
, &KItemListHeaderWidget::sidePaddingChanged
, this, &KItemListView::slotSidePaddingChanged
);
619 connect(m_headerWidget
, &KItemListHeaderWidget::columnMoved
, this, &KItemListView::slotHeaderColumnMoved
);
620 connect(m_headerWidget
, &KItemListHeaderWidget::sortOrderChanged
, this, &KItemListView::sortOrderChanged
);
621 connect(m_headerWidget
, &KItemListHeaderWidget::sortRoleChanged
, this, &KItemListView::sortRoleChanged
);
622 connect(m_headerWidget
, &KItemListHeaderWidget::columnHovered
, this, &KItemListView::columnHovered
);
623 connect(m_headerWidget
, &KItemListHeaderWidget::columnUnHovered
, this, &KItemListView::columnUnHovered
);
625 m_layouter
->setHeaderHeight(headerSize
.height());
626 m_headerWidget
->setVisible(true);
627 } else if (!visible
&& m_headerWidget
->isVisible()) {
628 disconnect(m_headerWidget
, &KItemListHeaderWidget::columnWidthChanged
, this, &KItemListView::slotHeaderColumnWidthChanged
);
629 disconnect(m_headerWidget
, &KItemListHeaderWidget::sidePaddingChanged
, this, &KItemListView::slotSidePaddingChanged
);
630 disconnect(m_headerWidget
, &KItemListHeaderWidget::columnMoved
, this, &KItemListView::slotHeaderColumnMoved
);
631 disconnect(m_headerWidget
, &KItemListHeaderWidget::sortOrderChanged
, this, &KItemListView::sortOrderChanged
);
632 disconnect(m_headerWidget
, &KItemListHeaderWidget::sortRoleChanged
, this, &KItemListView::sortRoleChanged
);
633 disconnect(m_headerWidget
, &KItemListHeaderWidget::columnHovered
, this, &KItemListView::columnHovered
);
634 disconnect(m_headerWidget
, &KItemListHeaderWidget::columnUnHovered
, this, &KItemListView::columnUnHovered
);
636 m_layouter
->setHeaderHeight(0);
637 m_headerWidget
->setVisible(false);
641 bool KItemListView::isHeaderVisible() const
643 return m_headerWidget
->isVisible();
646 KItemListHeader
*KItemListView::header() const
651 QPixmap
KItemListView::createDragPixmap(const KItemSet
&indexes
) const
655 if (indexes
.count() == 1) {
656 KItemListWidget
*item
= m_visibleItems
.value(indexes
.first());
657 QGraphicsView
*graphicsView
= scene()->views()[0];
658 if (item
&& graphicsView
) {
659 pixmap
= item
->createDragPixmap(nullptr, graphicsView
);
662 // TODO: Not implemented yet. Probably extend the interface
663 // from KItemListWidget::createDragPixmap() to return a pixmap
664 // that can be used for multiple indexes.
670 void KItemListView::editRole(int index
, const QByteArray
&role
)
672 KStandardItemListWidget
*widget
= qobject_cast
<KStandardItemListWidget
*>(m_visibleItems
.value(index
));
673 if (!widget
|| m_editingRole
) {
677 m_editingRole
= true;
678 widget
->setEditedRole(role
);
680 connect(widget
, &KItemListWidget::roleEditingCanceled
, this, &KItemListView::slotRoleEditingCanceled
);
681 connect(widget
, &KItemListWidget::roleEditingFinished
, this, &KItemListView::slotRoleEditingFinished
);
683 connect(this, &KItemListView::scrollOffsetChanged
, widget
, &KStandardItemListWidget::finishRoleEditing
);
686 void KItemListView::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
, QWidget
*widget
)
688 QGraphicsWidget::paint(painter
, option
, widget
);
690 for (auto animation
: std::as_const(m_rubberBandAnimations
)) {
691 QRectF rubberBandRect
= animation
->property(RubberPropertyName
).toRectF();
693 const QPointF topLeft
= rubberBandRect
.topLeft();
694 if (scrollOrientation() == Qt::Vertical
) {
695 rubberBandRect
.moveTo(topLeft
.x(), topLeft
.y() - scrollOffset());
697 rubberBandRect
.moveTo(topLeft
.x() - scrollOffset(), topLeft
.y());
700 QStyleOptionRubberBand opt
;
701 initStyleOption(&opt
);
702 opt
.shape
= QRubberBand::Rectangle
;
704 opt
.rect
= rubberBandRect
.toRect();
708 painter
->setOpacity(animation
->currentValue().toReal());
709 style()->drawControl(QStyle::CE_RubberBand
, &opt
, painter
);
714 if (m_rubberBand
->isActive()) {
715 QRectF rubberBandRect
= QRectF(m_rubberBand
->startPosition(), m_rubberBand
->endPosition()).normalized();
717 const QPointF topLeft
= rubberBandRect
.topLeft();
718 if (scrollOrientation() == Qt::Vertical
) {
719 rubberBandRect
.moveTo(topLeft
.x(), topLeft
.y() - scrollOffset());
721 rubberBandRect
.moveTo(topLeft
.x() - scrollOffset(), topLeft
.y());
724 QStyleOptionRubberBand opt
;
725 initStyleOption(&opt
);
726 opt
.shape
= QRubberBand::Rectangle
;
728 opt
.rect
= rubberBandRect
.toRect();
729 style()->drawControl(QStyle::CE_RubberBand
, &opt
, painter
);
732 if (m_tapAndHoldIndicator
->isActive()) {
733 const QPointF indicatorSize
= m_tapAndHoldIndicator
->endPosition();
734 const QRectF rubberBandRect
=
735 QRectF(m_tapAndHoldIndicator
->startPosition() - indicatorSize
, (m_tapAndHoldIndicator
->startPosition()) + indicatorSize
).normalized();
736 QStyleOptionRubberBand opt
;
737 initStyleOption(&opt
);
738 opt
.shape
= QRubberBand::Rectangle
;
740 opt
.rect
= rubberBandRect
.toRect();
741 style()->drawControl(QStyle::CE_RubberBand
, &opt
, painter
);
744 if (!m_dropIndicator
.isEmpty()) {
745 const QRectF r
= m_dropIndicator
.toRect();
747 QColor color
= palette().brush(QPalette::Normal
, QPalette::Text
).color();
748 painter
->setPen(color
);
750 // TODO: The following implementation works only for a vertical scroll-orientation
751 // and assumes a height of the m_draggingInsertIndicator of 1.
752 Q_ASSERT(r
.height() == 1);
753 painter
->drawLine(r
.left() + 1, r
.top(), r
.right() - 1, r
.top());
756 painter
->setPen(color
);
757 painter
->drawRect(r
.left(), r
.top() - 1, r
.width() - 1, 2);
761 QVariant
KItemListView::itemChange(GraphicsItemChange change
, const QVariant
&value
)
763 if (change
== QGraphicsItem::ItemSceneHasChanged
&& scene()) {
764 if (!scene()->views().isEmpty()) {
765 m_styleOption
.palette
= scene()->views().at(0)->palette();
768 return QGraphicsItem::itemChange(change
, value
);
771 void KItemListView::setItemSize(const QSizeF
&size
)
773 const QSizeF previousSize
= m_itemSize
;
774 if (size
== previousSize
) {
778 // Skip animations when the number of rows or columns
779 // are changed in the grid layout. Although the animation
780 // engine can handle this usecase, it looks obtrusive.
781 const bool animate
= !changesItemGridLayout(m_layouter
->size(), size
, m_layouter
->itemMargin());
783 const bool alternateBackgroundsChanged
= m_alternateBackgrounds
&& ((m_itemSize
.isEmpty() && !size
.isEmpty()) || (!m_itemSize
.isEmpty() && size
.isEmpty()));
787 if (alternateBackgroundsChanged
) {
788 // For an empty item size alternate backgrounds are drawn if more than
789 // one role is shown. Assure that the backgrounds for visible items are
790 // updated when changing the size in this context.
791 updateAlternateBackgrounds();
794 if (size
.isEmpty()) {
795 if (m_headerWidget
->automaticColumnResizing()) {
796 updatePreferredColumnWidths();
798 // Only apply the changed height and respect the header widths
800 const qreal currentWidth
= m_layouter
->itemSize().width();
801 const QSizeF
newSize(currentWidth
, size
.height());
802 m_layouter
->setItemSize(newSize
);
805 m_layouter
->setItemSize(size
);
808 m_sizeHintResolver
->clearCache();
809 doLayout(animate
? Animation
: NoAnimation
);
810 onItemSizeChanged(size
, previousSize
);
813 void KItemListView::setStyleOption(const KItemListStyleOption
&option
)
815 if (m_styleOption
== option
) {
819 const KItemListStyleOption previousOption
= m_styleOption
;
820 m_styleOption
= option
;
823 const QSizeF
margin(option
.horizontalMargin
, option
.verticalMargin
);
824 if (margin
!= m_layouter
->itemMargin()) {
825 // Skip animations when the number of rows or columns
826 // are changed in the grid layout. Although the animation
827 // engine can handle this usecase, it looks obtrusive.
828 animate
= !changesItemGridLayout(m_layouter
->size(), m_layouter
->itemSize(), margin
);
829 m_layouter
->setItemMargin(margin
);
833 updateGroupHeaderHeight();
836 if (animate
&& (previousOption
.maxTextLines
!= option
.maxTextLines
|| previousOption
.maxTextWidth
!= option
.maxTextWidth
)) {
837 // Animating a change of the maximum text size just results in expensive
838 // temporary eliding and clipping operations and does not look good visually.
842 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
843 while (it
.hasNext()) {
845 it
.value()->setStyleOption(option
);
848 m_sizeHintResolver
->clearCache();
849 m_layouter
->markAsDirty();
850 doLayout(animate
? Animation
: NoAnimation
);
852 if (m_itemSize
.isEmpty()) {
853 updatePreferredColumnWidths();
856 onStyleOptionChanged(option
, previousOption
);
859 void KItemListView::setScrollOrientation(Qt::Orientation orientation
)
861 const Qt::Orientation previousOrientation
= m_layouter
->scrollOrientation();
862 if (orientation
== previousOrientation
) {
866 m_layouter
->setScrollOrientation(orientation
);
867 m_animation
->setScrollOrientation(orientation
);
868 m_sizeHintResolver
->clearCache();
871 QMutableHashIterator
<KItemListWidget
*, KItemListGroupHeader
*> it(m_visibleGroups
);
872 while (it
.hasNext()) {
874 it
.value()->setScrollOrientation(orientation
);
876 updateGroupHeaderHeight();
879 doLayout(NoAnimation
);
881 onScrollOrientationChanged(orientation
, previousOrientation
);
882 Q_EMIT
scrollOrientationChanged(orientation
, previousOrientation
);
885 Qt::Orientation
KItemListView::scrollOrientation() const
887 return m_layouter
->scrollOrientation();
890 KItemListWidgetCreatorBase
*KItemListView::defaultWidgetCreator() const
895 KItemListGroupHeaderCreatorBase
*KItemListView::defaultGroupHeaderCreator() const
900 void KItemListView::initializeItemListWidget(KItemListWidget
*item
)
905 bool KItemListView::itemSizeHintUpdateRequired(const QSet
<QByteArray
> &changedRoles
) const
907 Q_UNUSED(changedRoles
)
911 void KItemListView::onControllerChanged(KItemListController
*current
, KItemListController
*previous
)
917 void KItemListView::onModelChanged(KItemModelBase
*current
, KItemModelBase
*previous
)
923 void KItemListView::onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
)
929 void KItemListView::onItemSizeChanged(const QSizeF
¤t
, const QSizeF
&previous
)
935 void KItemListView::onScrollOffsetChanged(qreal current
, qreal previous
)
941 void KItemListView::onVisibleRolesChanged(const QList
<QByteArray
> ¤t
, const QList
<QByteArray
> &previous
)
947 void KItemListView::onStyleOptionChanged(const KItemListStyleOption
¤t
, const KItemListStyleOption
&previous
)
953 void KItemListView::onHighlightEntireRowChanged(bool highlightEntireRow
)
955 Q_UNUSED(highlightEntireRow
)
958 void KItemListView::onSupportsItemExpandingChanged(bool supportsExpanding
)
960 Q_UNUSED(supportsExpanding
)
963 void KItemListView::onTransactionBegin()
967 void KItemListView::onTransactionEnd()
971 bool KItemListView::event(QEvent
*event
)
973 switch (event
->type()) {
974 case QEvent::PaletteChange
:
978 case QEvent::FontChange
:
982 case QEvent::FocusIn
:
983 focusInEvent(static_cast<QFocusEvent
*>(event
));
988 case QEvent::FocusOut
:
989 focusOutEvent(static_cast<QFocusEvent
*>(event
));
995 // Forward all other events to the controller and handle them there
996 if (!m_editingRole
&& m_controller
&& m_controller
->processEvent(event
, transform())) {
1002 return QGraphicsWidget::event(event
);
1005 void KItemListView::mousePressEvent(QGraphicsSceneMouseEvent
*event
)
1007 m_mousePos
= transform().map(event
->pos());
1011 void KItemListView::mouseMoveEvent(QGraphicsSceneMouseEvent
*event
)
1013 QGraphicsWidget::mouseMoveEvent(event
);
1015 m_mousePos
= transform().map(event
->pos());
1016 if (m_autoScrollTimer
&& !m_autoScrollTimer
->isActive()) {
1017 m_autoScrollTimer
->start(InitialAutoScrollDelay
);
1021 void KItemListView::dragEnterEvent(QGraphicsSceneDragDropEvent
*event
)
1023 event
->setAccepted(true);
1024 setAutoScroll(true);
1027 void KItemListView::dragMoveEvent(QGraphicsSceneDragDropEvent
*event
)
1029 QGraphicsWidget::dragMoveEvent(event
);
1031 m_mousePos
= transform().map(event
->pos());
1032 if (m_autoScrollTimer
&& !m_autoScrollTimer
->isActive()) {
1033 m_autoScrollTimer
->start(InitialAutoScrollDelay
);
1037 void KItemListView::dragLeaveEvent(QGraphicsSceneDragDropEvent
*event
)
1039 QGraphicsWidget::dragLeaveEvent(event
);
1040 setAutoScroll(false);
1043 void KItemListView::dropEvent(QGraphicsSceneDragDropEvent
*event
)
1045 QGraphicsWidget::dropEvent(event
);
1046 setAutoScroll(false);
1049 QList
<KItemListWidget
*> KItemListView::visibleItemListWidgets() const
1051 return m_visibleItems
.values();
1054 void KItemListView::updateFont()
1056 if (scene() && !scene()->views().isEmpty()) {
1057 KItemListStyleOption option
= styleOption();
1058 option
.font
= scene()->views().first()->font();
1059 option
.fontMetrics
= QFontMetrics(option
.font
);
1061 setStyleOption(option
);
1065 void KItemListView::updatePalette()
1067 KItemListStyleOption option
= styleOption();
1068 option
.palette
= palette();
1069 setStyleOption(option
);
1072 void KItemListView::slotItemsInserted(const KItemRangeList
&itemRanges
)
1074 if (m_itemSize
.isEmpty()) {
1075 updatePreferredColumnWidths(itemRanges
);
1078 const bool hasMultipleRanges
= (itemRanges
.count() > 1);
1079 if (hasMultipleRanges
) {
1083 m_layouter
->markAsDirty();
1085 m_sizeHintResolver
->itemsInserted(itemRanges
);
1087 int previouslyInsertedCount
= 0;
1088 for (const KItemRange
&range
: itemRanges
) {
1089 // range.index is related to the model before anything has been inserted.
1090 // As in each loop the current item-range gets inserted the index must
1091 // be increased by the already previously inserted items.
1092 const int index
= range
.index
+ previouslyInsertedCount
;
1093 const int count
= range
.count
;
1094 if (index
< 0 || count
<= 0) {
1095 qCWarning(DolphinDebug
) << "Invalid item range (index:" << index
<< ", count:" << count
<< ")";
1098 previouslyInsertedCount
+= count
;
1100 // Determine which visible items must be moved
1101 QList
<int> itemsToMove
;
1102 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
1103 while (it
.hasNext()) {
1105 const int visibleItemIndex
= it
.key();
1106 if (visibleItemIndex
>= index
) {
1107 itemsToMove
.append(visibleItemIndex
);
1111 // Update the indexes of all KItemListWidget instances that are located
1112 // after the inserted items. It is important to adjust the indexes in the order
1113 // from the highest index to the lowest index to prevent overlaps when setting the new index.
1114 std::sort(itemsToMove
.begin(), itemsToMove
.end());
1115 for (int i
= itemsToMove
.count() - 1; i
>= 0; --i
) {
1116 KItemListWidget
*widget
= m_visibleItems
.value(itemsToMove
[i
]);
1118 const int newIndex
= widget
->index() + count
;
1119 if (hasMultipleRanges
) {
1120 setWidgetIndex(widget
, newIndex
);
1122 // Try to animate the moving of the item
1123 moveWidgetToIndex(widget
, newIndex
);
1127 if (m_model
->count() == count
&& m_activeTransactions
== 0) {
1128 // Check whether a scrollbar is required to show the inserted items. In this case
1129 // the size of the layouter will be decreased before calling doLayout(): This prevents
1130 // an unnecessary temporary animation due to the geometry change of the inserted scrollbar.
1131 const bool verticalScrollOrientation
= (scrollOrientation() == Qt::Vertical
);
1132 const bool decreaseLayouterSize
= (verticalScrollOrientation
&& maximumScrollOffset() > size().height())
1133 || (!verticalScrollOrientation
&& maximumScrollOffset() > size().width());
1134 if (decreaseLayouterSize
) {
1135 const int scrollBarExtent
= style()->pixelMetric(QStyle::PM_ScrollBarExtent
);
1137 int scrollbarSpacing
= 0;
1138 if (style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents
)) {
1139 scrollbarSpacing
= style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing
);
1142 QSizeF layouterSize
= m_layouter
->size();
1143 if (verticalScrollOrientation
) {
1144 layouterSize
.rwidth() -= scrollBarExtent
+ scrollbarSpacing
;
1146 layouterSize
.rheight() -= scrollBarExtent
+ scrollbarSpacing
;
1148 m_layouter
->setSize(layouterSize
);
1152 if (!hasMultipleRanges
) {
1153 doLayout(animateChangedItemCount(count
) ? Animation
: NoAnimation
, index
, count
);
1154 updateSiblingsInformation();
1159 m_controller
->selectionManager()->itemsInserted(itemRanges
);
1162 if (hasMultipleRanges
) {
1163 m_endTransactionAnimationHint
= NoAnimation
;
1166 updateSiblingsInformation();
1169 if (m_grouped
&& (hasMultipleRanges
|| itemRanges
.first().count
< m_model
->count())) {
1170 // In case if items of the same group have been inserted before an item that
1171 // currently represents the first item of the group, the group header of
1172 // this item must be removed.
1173 updateVisibleGroupHeaders();
1176 if (useAlternateBackgrounds()) {
1177 updateAlternateBackgrounds();
1181 void KItemListView::slotItemsRemoved(const KItemRangeList
&itemRanges
)
1183 if (m_itemSize
.isEmpty()) {
1184 // Don't pass the item-range: The preferred column-widths of
1185 // all items must be adjusted when removing items.
1186 updatePreferredColumnWidths();
1189 const bool hasMultipleRanges
= (itemRanges
.count() > 1);
1190 if (hasMultipleRanges
) {
1194 m_layouter
->markAsDirty();
1196 m_sizeHintResolver
->itemsRemoved(itemRanges
);
1198 for (int i
= itemRanges
.count() - 1; i
>= 0; --i
) {
1199 const KItemRange
&range
= itemRanges
[i
];
1200 const int index
= range
.index
;
1201 const int count
= range
.count
;
1202 if (index
< 0 || count
<= 0) {
1203 qCWarning(DolphinDebug
) << "Invalid item range (index:" << index
<< ", count:" << count
<< ")";
1207 const int firstRemovedIndex
= index
;
1208 const int lastRemovedIndex
= index
+ count
- 1;
1210 // Remember which items have to be moved because they are behind the removed range.
1211 QVector
<int> itemsToMove
;
1213 // Remove all KItemListWidget instances that got deleted
1214 // Iterate over a const copy because the container is mutated within the loop
1215 // directly and in `recycleWidget()` (https://bugs.kde.org/show_bug.cgi?id=428374)
1216 const auto visibleItems
= m_visibleItems
;
1217 for (KItemListWidget
*widget
: visibleItems
) {
1218 const int i
= widget
->index();
1219 if (i
< firstRemovedIndex
) {
1221 } else if (i
> lastRemovedIndex
) {
1222 itemsToMove
.append(i
);
1226 m_animation
->stop(widget
);
1227 // Stopping the animation might lead to recycling the widget if
1228 // it is invisible (see slotAnimationFinished()).
1229 // Check again whether it is still visible:
1230 if (!m_visibleItems
.contains(i
)) {
1234 if (m_model
->count() == 0 || hasMultipleRanges
|| !animateChangedItemCount(count
)) {
1235 // Remove the widget without animation
1236 recycleWidget(widget
);
1238 // Animate the removing of the items. Special case: When removing an item there
1239 // is no valid model index available anymore. For the
1240 // remove-animation the item gets removed from m_visibleItems but the widget
1241 // will stay alive until the animation has been finished and will
1242 // be recycled (deleted) in KItemListView::slotAnimationFinished().
1243 m_visibleItems
.remove(i
);
1244 widget
->setIndex(-1);
1245 m_animation
->start(widget
, KItemListViewAnimation::DeleteAnimation
);
1249 // Update the indexes of all KItemListWidget instances that are located
1250 // after the deleted items. It is important to update them in ascending
1251 // order to prevent overlaps when setting the new index.
1252 std::sort(itemsToMove
.begin(), itemsToMove
.end());
1253 for (int i
: std::as_const(itemsToMove
)) {
1254 KItemListWidget
*widget
= m_visibleItems
.value(i
);
1256 const int newIndex
= i
- count
;
1257 if (hasMultipleRanges
) {
1258 setWidgetIndex(widget
, newIndex
);
1260 // Try to animate the moving of the item
1261 moveWidgetToIndex(widget
, newIndex
);
1265 if (!hasMultipleRanges
) {
1266 // The decrease-layout-size optimization in KItemListView::slotItemsInserted()
1267 // assumes an updated geometry. If items are removed during an active transaction,
1268 // the transaction will be temporary deactivated so that doLayout() triggers a
1269 // geometry update if necessary.
1270 const int activeTransactions
= m_activeTransactions
;
1271 m_activeTransactions
= 0;
1272 doLayout(animateChangedItemCount(count
) ? Animation
: NoAnimation
, index
, -count
);
1273 m_activeTransactions
= activeTransactions
;
1274 updateSiblingsInformation();
1279 m_controller
->selectionManager()->itemsRemoved(itemRanges
);
1282 if (hasMultipleRanges
) {
1283 m_endTransactionAnimationHint
= NoAnimation
;
1285 updateSiblingsInformation();
1288 if (m_grouped
&& (hasMultipleRanges
|| m_model
->count() > 0)) {
1289 // In case if the first item of a group has been removed, the group header
1290 // must be applied to the next visible item.
1291 updateVisibleGroupHeaders();
1294 if (useAlternateBackgrounds()) {
1295 updateAlternateBackgrounds();
1299 void KItemListView::slotItemsMoved(const KItemRange
&itemRange
, const QList
<int> &movedToIndexes
)
1301 m_sizeHintResolver
->itemsMoved(itemRange
, movedToIndexes
);
1302 m_layouter
->markAsDirty();
1305 m_controller
->selectionManager()->itemsMoved(itemRange
, movedToIndexes
);
1308 const int firstVisibleMovedIndex
= qMax(firstVisibleIndex(), itemRange
.index
);
1309 const int lastVisibleMovedIndex
= qMin(lastVisibleIndex(), itemRange
.index
+ itemRange
.count
- 1);
1311 for (int index
= firstVisibleMovedIndex
; index
<= lastVisibleMovedIndex
; ++index
) {
1312 KItemListWidget
*widget
= m_visibleItems
.value(index
);
1314 updateWidgetProperties(widget
, index
);
1315 initializeItemListWidget(widget
);
1319 doLayout(NoAnimation
);
1320 updateSiblingsInformation();
1323 void KItemListView::slotItemsChanged(const KItemRangeList
&itemRanges
, const QSet
<QByteArray
> &roles
)
1325 const bool updateSizeHints
= itemSizeHintUpdateRequired(roles
);
1326 if (updateSizeHints
&& m_itemSize
.isEmpty()) {
1327 updatePreferredColumnWidths(itemRanges
);
1330 for (const KItemRange
&itemRange
: itemRanges
) {
1331 const int index
= itemRange
.index
;
1332 const int count
= itemRange
.count
;
1334 if (updateSizeHints
) {
1335 m_sizeHintResolver
->itemsChanged(index
, count
, roles
);
1336 m_layouter
->markAsDirty();
1339 // Apply the changed roles to the visible item-widgets
1340 const int lastIndex
= index
+ count
- 1;
1341 for (int i
= index
; i
<= lastIndex
; ++i
) {
1342 KItemListWidget
*widget
= m_visibleItems
.value(i
);
1344 widget
->setData(m_model
->data(i
), roles
);
1348 if (m_grouped
&& roles
.contains(m_model
->sortRole())) {
1349 // The sort-role has been changed which might result
1350 // in modified group headers
1351 updateVisibleGroupHeaders();
1352 doLayout(NoAnimation
);
1355 QAccessibleTableModelChangeEvent
ev(this, QAccessibleTableModelChangeEvent::DataChanged
);
1356 ev
.setFirstRow(itemRange
.index
);
1357 ev
.setLastRow(itemRange
.index
+ itemRange
.count
);
1358 QAccessible::updateAccessibility(&ev
);
1361 doLayout(NoAnimation
);
1364 void KItemListView::slotGroupsChanged()
1366 updateVisibleGroupHeaders();
1367 doLayout(NoAnimation
);
1368 updateSiblingsInformation();
1371 void KItemListView::slotGroupedSortingChanged(bool current
)
1373 m_grouped
= current
;
1374 m_layouter
->markAsDirty();
1377 updateGroupHeaderHeight();
1379 // Clear all visible headers. Note that the QHashIterator takes a copy of
1380 // m_visibleGroups. Therefore, it remains valid even if items are removed
1381 // from m_visibleGroups in recycleGroupHeaderForWidget().
1382 QHashIterator
<KItemListWidget
*, KItemListGroupHeader
*> it(m_visibleGroups
);
1383 while (it
.hasNext()) {
1385 recycleGroupHeaderForWidget(it
.key());
1387 Q_ASSERT(m_visibleGroups
.isEmpty());
1390 if (useAlternateBackgrounds()) {
1391 // Changing the group mode requires to update the alternate backgrounds
1392 // as with the enabled group mode the altering is done on base of the first
1394 updateAlternateBackgrounds();
1396 updateSiblingsInformation();
1397 doLayout(NoAnimation
);
1400 void KItemListView::slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
)
1405 updateVisibleGroupHeaders();
1406 doLayout(NoAnimation
);
1410 void KItemListView::slotSortRoleChanged(const QByteArray
¤t
, const QByteArray
&previous
)
1415 updateVisibleGroupHeaders();
1416 doLayout(NoAnimation
);
1420 void KItemListView::slotCurrentChanged(int current
, int previous
)
1424 // In SingleSelection mode (e.g., in the Places Panel), the current item is
1425 // always the selected item. It is not necessary to highlight the current item then.
1426 if (m_controller
->selectionBehavior() != KItemListController::SingleSelection
) {
1427 KItemListWidget
*previousWidget
= m_visibleItems
.value(previous
, nullptr);
1428 if (previousWidget
) {
1429 previousWidget
->setCurrent(false);
1432 KItemListWidget
*currentWidget
= m_visibleItems
.value(current
, nullptr);
1433 if (currentWidget
) {
1434 currentWidget
->setCurrent(true);
1438 QAccessibleEvent
ev(this, QAccessible::Focus
);
1439 ev
.setChild(current
);
1440 QAccessible::updateAccessibility(&ev
);
1443 void KItemListView::slotSelectionChanged(const KItemSet
¤t
, const KItemSet
&previous
)
1447 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
1448 while (it
.hasNext()) {
1450 const int index
= it
.key();
1451 KItemListWidget
*widget
= it
.value();
1452 widget
->setSelected(current
.contains(index
));
1456 void KItemListView::slotAnimationFinished(QGraphicsWidget
*widget
, KItemListViewAnimation::AnimationType type
)
1458 KItemListWidget
*itemListWidget
= qobject_cast
<KItemListWidget
*>(widget
);
1459 Q_ASSERT(itemListWidget
);
1461 if (type
== KItemListViewAnimation::DeleteAnimation
) {
1462 // As we recycle the widget in this case it is important to assure that no
1463 // other animation has been started. This is a convention in KItemListView and
1464 // not a requirement defined by KItemListViewAnimation.
1465 Q_ASSERT(!m_animation
->isStarted(itemListWidget
));
1467 // All KItemListWidgets that are animated by the DeleteAnimation are not maintained
1468 // by m_visibleWidgets and must be deleted manually after the animation has
1470 recycleGroupHeaderForWidget(itemListWidget
);
1471 widgetCreator()->recycle(itemListWidget
);
1473 const int index
= itemListWidget
->index();
1474 const bool invisible
= (index
< m_layouter
->firstVisibleIndex()) || (index
> m_layouter
->lastVisibleIndex());
1475 if (invisible
&& !m_animation
->isStarted(itemListWidget
)) {
1476 recycleWidget(itemListWidget
);
1481 void KItemListView::slotRubberBandPosChanged()
1486 void KItemListView::slotRubberBandActivationChanged(bool active
)
1489 connect(m_rubberBand
, &KItemListRubberBand::startPositionChanged
, this, &KItemListView::slotRubberBandPosChanged
);
1490 connect(m_rubberBand
, &KItemListRubberBand::endPositionChanged
, this, &KItemListView::slotRubberBandPosChanged
);
1491 m_skipAutoScrollForRubberBand
= true;
1493 QRectF rubberBandRect
= QRectF(m_rubberBand
->startPosition(), m_rubberBand
->endPosition()).normalized();
1495 auto animation
= new QVariantAnimation(this);
1496 animation
->setStartValue(1.0);
1497 animation
->setEndValue(0.0);
1498 animation
->setDuration(RubberFadeSpeed
);
1499 animation
->setProperty(RubberPropertyName
, rubberBandRect
);
1502 curve
.setType(QEasingCurve::BezierSpline
);
1503 curve
.addCubicBezierSegment(QPointF(0.4, 0.0), QPointF(1.0, 1.0), QPointF(1.0, 1.0));
1504 animation
->setEasingCurve(curve
);
1506 connect(animation
, &QVariantAnimation::valueChanged
, this, [=](const QVariant
&) {
1509 connect(animation
, &QVariantAnimation::finished
, this, [=]() {
1510 m_rubberBandAnimations
.removeAll(animation
);
1514 m_rubberBandAnimations
<< animation
;
1516 disconnect(m_rubberBand
, &KItemListRubberBand::startPositionChanged
, this, &KItemListView::slotRubberBandPosChanged
);
1517 disconnect(m_rubberBand
, &KItemListRubberBand::endPositionChanged
, this, &KItemListView::slotRubberBandPosChanged
);
1518 m_skipAutoScrollForRubberBand
= false;
1524 void KItemListView::slotHeaderColumnWidthChanged(const QByteArray
&role
, qreal currentWidth
, qreal previousWidth
)
1527 Q_UNUSED(currentWidth
)
1528 Q_UNUSED(previousWidth
)
1530 m_headerWidget
->setAutomaticColumnResizing(false);
1531 applyColumnWidthsFromHeader();
1532 doLayout(NoAnimation
);
1535 void KItemListView::slotSidePaddingChanged(qreal width
)
1538 if (m_headerWidget
->automaticColumnResizing()) {
1539 applyAutomaticColumnWidths();
1541 applyColumnWidthsFromHeader();
1542 doLayout(NoAnimation
);
1545 void KItemListView::slotHeaderColumnMoved(const QByteArray
&role
, int currentIndex
, int previousIndex
)
1547 Q_ASSERT(m_visibleRoles
[previousIndex
] == role
);
1549 const QList
<QByteArray
> previous
= m_visibleRoles
;
1551 QList
<QByteArray
> current
= m_visibleRoles
;
1552 current
.removeAt(previousIndex
);
1553 current
.insert(currentIndex
, role
);
1555 setVisibleRoles(current
);
1557 Q_EMIT
visibleRolesChanged(current
, previous
);
1560 void KItemListView::triggerAutoScrolling()
1562 if (!m_autoScrollTimer
) {
1567 int visibleSize
= 0;
1568 if (scrollOrientation() == Qt::Vertical
) {
1569 pos
= m_mousePos
.y();
1570 visibleSize
= size().height();
1572 pos
= m_mousePos
.x();
1573 visibleSize
= size().width();
1576 if (m_autoScrollTimer
->interval() == InitialAutoScrollDelay
) {
1577 m_autoScrollIncrement
= 0;
1580 m_autoScrollIncrement
= calculateAutoScrollingIncrement(pos
, visibleSize
, m_autoScrollIncrement
);
1581 if (m_autoScrollIncrement
== 0) {
1582 // The mouse position is not above an autoscroll margin (the autoscroll timer
1583 // will be restarted in mouseMoveEvent())
1584 m_autoScrollTimer
->stop();
1588 if (m_rubberBand
->isActive() && m_skipAutoScrollForRubberBand
) {
1589 // If a rubberband selection is ongoing the autoscrolling may only get triggered
1590 // if the direction of the rubberband is similar to the autoscroll direction. This
1591 // prevents that starting to create a rubberband within the autoscroll margins starts
1592 // an autoscrolling.
1594 const qreal minDiff
= 4; // Ignore any autoscrolling if the rubberband is very small
1595 const qreal diff
= (scrollOrientation() == Qt::Vertical
) ? m_rubberBand
->endPosition().y() - m_rubberBand
->startPosition().y()
1596 : m_rubberBand
->endPosition().x() - m_rubberBand
->startPosition().x();
1597 if (qAbs(diff
) < minDiff
|| (m_autoScrollIncrement
< 0 && diff
> 0) || (m_autoScrollIncrement
> 0 && diff
< 0)) {
1598 // The rubberband direction is different from the scroll direction (e.g. the rubberband has
1599 // been moved up although the autoscroll direction might be down)
1600 m_autoScrollTimer
->stop();
1605 // As soon as the autoscrolling has been triggered at least once despite having an active rubberband,
1606 // the autoscrolling may not get skipped anymore until a new rubberband is created
1607 m_skipAutoScrollForRubberBand
= false;
1609 const qreal maxVisibleOffset
= qMax(qreal(0), maximumScrollOffset() - visibleSize
);
1610 const qreal newScrollOffset
= qMin(scrollOffset() + m_autoScrollIncrement
, maxVisibleOffset
);
1611 setScrollOffset(newScrollOffset
);
1613 // Trigger the autoscroll timer which will periodically call
1614 // triggerAutoScrolling()
1615 m_autoScrollTimer
->start(RepeatingAutoScrollDelay
);
1618 void KItemListView::slotGeometryOfGroupHeaderParentChanged()
1620 KItemListWidget
*widget
= qobject_cast
<KItemListWidget
*>(sender());
1622 KItemListGroupHeader
*groupHeader
= m_visibleGroups
.value(widget
);
1623 Q_ASSERT(groupHeader
);
1624 updateGroupHeaderLayout(widget
);
1627 void KItemListView::slotRoleEditingCanceled(int index
, const QByteArray
&role
, const QVariant
&value
)
1629 disconnectRoleEditingSignals(index
);
1631 m_editingRole
= false;
1632 Q_EMIT
roleEditingCanceled(index
, role
, value
);
1635 void KItemListView::slotRoleEditingFinished(int index
, const QByteArray
&role
, const QVariant
&value
)
1637 disconnectRoleEditingSignals(index
);
1639 m_editingRole
= false;
1640 Q_EMIT
roleEditingFinished(index
, role
, value
);
1643 void KItemListView::setController(KItemListController
*controller
)
1645 if (m_controller
!= controller
) {
1646 KItemListController
*previous
= m_controller
;
1648 KItemListSelectionManager
*selectionManager
= previous
->selectionManager();
1649 disconnect(selectionManager
, &KItemListSelectionManager::currentChanged
, this, &KItemListView::slotCurrentChanged
);
1650 disconnect(selectionManager
, &KItemListSelectionManager::selectionChanged
, this, &KItemListView::slotSelectionChanged
);
1653 m_controller
= controller
;
1656 KItemListSelectionManager
*selectionManager
= controller
->selectionManager();
1657 connect(selectionManager
, &KItemListSelectionManager::currentChanged
, this, &KItemListView::slotCurrentChanged
);
1658 connect(selectionManager
, &KItemListSelectionManager::selectionChanged
, this, &KItemListView::slotSelectionChanged
);
1661 onControllerChanged(controller
, previous
);
1665 void KItemListView::setModel(KItemModelBase
*model
)
1667 if (m_model
== model
) {
1671 KItemModelBase
*previous
= m_model
;
1674 disconnect(m_model
, &KItemModelBase::itemsChanged
, this, &KItemListView::slotItemsChanged
);
1675 disconnect(m_model
, &KItemModelBase::itemsInserted
, this, &KItemListView::slotItemsInserted
);
1676 disconnect(m_model
, &KItemModelBase::itemsRemoved
, this, &KItemListView::slotItemsRemoved
);
1677 disconnect(m_model
, &KItemModelBase::itemsMoved
, this, &KItemListView::slotItemsMoved
);
1678 disconnect(m_model
, &KItemModelBase::groupsChanged
, this, &KItemListView::slotGroupsChanged
);
1679 disconnect(m_model
, &KItemModelBase::groupedSortingChanged
, this, &KItemListView::slotGroupedSortingChanged
);
1680 disconnect(m_model
, &KItemModelBase::sortOrderChanged
, this, &KItemListView::slotSortOrderChanged
);
1681 disconnect(m_model
, &KItemModelBase::sortRoleChanged
, this, &KItemListView::slotSortRoleChanged
);
1683 m_sizeHintResolver
->itemsRemoved(KItemRangeList() << KItemRange(0, m_model
->count()));
1687 m_layouter
->setModel(model
);
1688 m_grouped
= model
->groupedSorting();
1691 connect(m_model
, &KItemModelBase::itemsChanged
, this, &KItemListView::slotItemsChanged
);
1692 connect(m_model
, &KItemModelBase::itemsInserted
, this, &KItemListView::slotItemsInserted
);
1693 connect(m_model
, &KItemModelBase::itemsRemoved
, this, &KItemListView::slotItemsRemoved
);
1694 connect(m_model
, &KItemModelBase::itemsMoved
, this, &KItemListView::slotItemsMoved
);
1695 connect(m_model
, &KItemModelBase::groupsChanged
, this, &KItemListView::slotGroupsChanged
);
1696 connect(m_model
, &KItemModelBase::groupedSortingChanged
, this, &KItemListView::slotGroupedSortingChanged
);
1697 connect(m_model
, &KItemModelBase::sortOrderChanged
, this, &KItemListView::slotSortOrderChanged
);
1698 connect(m_model
, &KItemModelBase::sortRoleChanged
, this, &KItemListView::slotSortRoleChanged
);
1700 const int itemCount
= m_model
->count();
1701 if (itemCount
> 0) {
1702 slotItemsInserted(KItemRangeList() << KItemRange(0, itemCount
));
1706 onModelChanged(model
, previous
);
1709 KItemListRubberBand
*KItemListView::rubberBand() const
1711 return m_rubberBand
;
1714 void KItemListView::doLayout(LayoutAnimationHint hint
, int changedIndex
, int changedCount
)
1716 if (m_activeTransactions
> 0) {
1717 if (hint
== NoAnimation
) {
1718 // As soon as at least one property change should be done without animation,
1719 // the whole transaction will be marked as not animated.
1720 m_endTransactionAnimationHint
= NoAnimation
;
1725 if (!m_model
|| m_model
->count() < 0) {
1729 int firstVisibleIndex
= m_layouter
->firstVisibleIndex();
1730 if (firstVisibleIndex
< 0) {
1731 emitOffsetChanges();
1735 // Do a sanity check of the scroll-offset property: When properties of the itemlist-view have been changed
1736 // it might be possible that the maximum offset got changed too. Assure that the full visible range
1737 // is still shown if the maximum offset got decreased.
1738 const qreal visibleOffsetRange
= (scrollOrientation() == Qt::Horizontal
) ? size().width() : size().height();
1739 const qreal maxOffsetToShowFullRange
= maximumScrollOffset() - visibleOffsetRange
;
1740 if (scrollOffset() > maxOffsetToShowFullRange
) {
1741 m_layouter
->setScrollOffset(qMax(qreal(0), maxOffsetToShowFullRange
));
1742 firstVisibleIndex
= m_layouter
->firstVisibleIndex();
1745 const int lastVisibleIndex
= m_layouter
->lastVisibleIndex();
1747 int firstSibblingIndex
= -1;
1748 int lastSibblingIndex
= -1;
1749 const bool supportsExpanding
= supportsItemExpanding();
1751 QList
<int> reusableItems
= recycleInvisibleItems(firstVisibleIndex
, lastVisibleIndex
, hint
);
1753 // Assure that for each visible item a KItemListWidget is available. KItemListWidget
1754 // instances from invisible items are reused. If no reusable items are
1755 // found then new KItemListWidget instances get created.
1756 const bool animate
= (hint
== Animation
);
1757 for (int i
= firstVisibleIndex
; i
<= lastVisibleIndex
; ++i
) {
1758 bool applyNewPos
= true;
1760 const QRectF itemBounds
= m_layouter
->itemRect(i
);
1761 const QPointF newPos
= itemBounds
.topLeft();
1762 KItemListWidget
*widget
= m_visibleItems
.value(i
);
1764 if (!reusableItems
.isEmpty()) {
1765 // Reuse a KItemListWidget instance from an invisible item
1766 const int oldIndex
= reusableItems
.takeLast();
1767 widget
= m_visibleItems
.value(oldIndex
);
1768 setWidgetIndex(widget
, i
);
1769 updateWidgetProperties(widget
, i
);
1770 initializeItemListWidget(widget
);
1772 // No reusable KItemListWidget instance is available, create a new one
1773 widget
= createWidget(i
);
1775 widget
->resize(itemBounds
.size());
1777 if (animate
&& changedCount
< 0) {
1778 // Items have been deleted.
1779 if (i
>= changedIndex
) {
1780 // The item is located behind the removed range. Move the
1781 // created item to the imaginary old position outside the
1782 // view. It will get animated to the new position later.
1783 const int previousIndex
= i
- changedCount
;
1784 const QRectF itemRect
= m_layouter
->itemRect(previousIndex
);
1785 if (itemRect
.isEmpty()) {
1786 const QPointF invisibleOldPos
= (scrollOrientation() == Qt::Vertical
) ? QPointF(0, size().height()) : QPointF(size().width(), 0);
1787 widget
->setPos(invisibleOldPos
);
1789 widget
->setPos(itemRect
.topLeft());
1791 applyNewPos
= false;
1795 if (supportsExpanding
&& changedCount
== 0) {
1796 if (firstSibblingIndex
< 0) {
1797 firstSibblingIndex
= i
;
1799 lastSibblingIndex
= i
;
1804 if (m_animation
->isStarted(widget
, KItemListViewAnimation::MovingAnimation
)) {
1805 m_animation
->start(widget
, KItemListViewAnimation::MovingAnimation
, newPos
);
1806 applyNewPos
= false;
1809 const bool itemsRemoved
= (changedCount
< 0);
1810 const bool itemsInserted
= (changedCount
> 0);
1811 if (itemsRemoved
&& (i
>= changedIndex
)) {
1812 // The item is located after the removed items. Animate the moving of the position.
1813 applyNewPos
= !moveWidget(widget
, newPos
);
1814 } else if (itemsInserted
&& i
>= changedIndex
) {
1815 // The item is located after the first inserted item
1816 if (i
<= changedIndex
+ changedCount
- 1) {
1817 // The item is an inserted item. Animate the appearing of the item.
1818 // For performance reasons no animation is done when changedCount is equal
1819 // to all available items.
1820 if (changedCount
< m_model
->count()) {
1821 m_animation
->start(widget
, KItemListViewAnimation::CreateAnimation
);
1823 } else if (!m_animation
->isStarted(widget
, KItemListViewAnimation::CreateAnimation
)) {
1824 // The item was already there before, so animate the moving of the position.
1825 // No moving animation is done if the item is animated by a create animation: This
1826 // prevents a "move animation mess" when inserting several ranges in parallel.
1827 applyNewPos
= !moveWidget(widget
, newPos
);
1831 m_animation
->stop(widget
);
1835 widget
->setPos(newPos
);
1838 Q_ASSERT(widget
->index() == i
);
1839 widget
->setVisible(true);
1841 bool animateIconResizing
= animate
;
1843 if (widget
->size() != itemBounds
.size()) {
1844 // Resize the widget for the item to the changed size.
1846 // If a dynamic item size is used then no animation is done in the direction
1847 // of the dynamic size.
1848 if (m_itemSize
.width() <= 0) {
1849 // The width is dynamic, apply the new width without animation.
1850 widget
->resize(itemBounds
.width(), widget
->size().height());
1851 } else if (m_itemSize
.height() <= 0) {
1852 // The height is dynamic, apply the new height without animation.
1853 widget
->resize(widget
->size().width(), itemBounds
.height());
1855 m_animation
->start(widget
, KItemListViewAnimation::ResizeAnimation
, itemBounds
.size());
1857 widget
->resize(itemBounds
.size());
1860 animateIconResizing
= false;
1863 const int newIconSize
= widget
->styleOption().iconSize
;
1864 if (widget
->iconSize() != newIconSize
) {
1865 if (animateIconResizing
) {
1866 m_animation
->start(widget
, KItemListViewAnimation::IconResizeAnimation
, newIconSize
);
1868 widget
->setIconSize(newIconSize
);
1872 // Updating the cell-information must be done as last step: The decision whether the
1873 // moving-animation should be started at all is based on the previous cell-information.
1874 const Cell
cell(m_layouter
->itemColumn(i
), m_layouter
->itemRow(i
));
1875 m_visibleCells
.insert(i
, cell
);
1878 // Delete invisible KItemListWidget instances that have not been reused
1879 for (int index
: std::as_const(reusableItems
)) {
1880 recycleWidget(m_visibleItems
.value(index
));
1883 if (supportsExpanding
&& firstSibblingIndex
>= 0) {
1884 Q_ASSERT(lastSibblingIndex
>= 0);
1885 updateSiblingsInformation(firstSibblingIndex
, lastSibblingIndex
);
1889 // Update the layout of all visible group headers
1890 QHashIterator
<KItemListWidget
*, KItemListGroupHeader
*> it(m_visibleGroups
);
1891 while (it
.hasNext()) {
1893 updateGroupHeaderLayout(it
.key());
1897 emitOffsetChanges();
1900 QList
<int> KItemListView::recycleInvisibleItems(int firstVisibleIndex
, int lastVisibleIndex
, LayoutAnimationHint hint
)
1902 // Determine all items that are completely invisible and might be
1903 // reused for items that just got (at least partly) visible. If the
1904 // animation hint is set to 'Animation' items that do e.g. an animated
1905 // moving of their position are not marked as invisible: This assures
1906 // that a scrolling inside the view can be done without breaking an animation.
1910 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
1911 while (it
.hasNext()) {
1914 KItemListWidget
*widget
= it
.value();
1915 const int index
= widget
->index();
1916 const bool invisible
= (index
< firstVisibleIndex
) || (index
> lastVisibleIndex
);
1919 if (m_animation
->isStarted(widget
)) {
1920 if (hint
== NoAnimation
) {
1921 // Stopping the animation will call KItemListView::slotAnimationFinished()
1922 // and the widget will be recycled if necessary there.
1923 m_animation
->stop(widget
);
1926 widget
->setVisible(false);
1927 items
.append(index
);
1930 recycleGroupHeaderForWidget(widget
);
1939 bool KItemListView::moveWidget(KItemListWidget
*widget
, const QPointF
&newPos
)
1941 if (widget
->pos() == newPos
) {
1945 bool startMovingAnim
= false;
1947 if (m_itemSize
.isEmpty()) {
1948 // The items are not aligned in a grid but either as columns or rows.
1949 startMovingAnim
= true;
1951 // When having a grid the moving-animation should only be started, if it is done within
1952 // one row in the vertical scroll-orientation or one column in the horizontal scroll-orientation.
1953 // Otherwise instead of a moving-animation a create-animation on the new position will be used
1954 // instead. This is done to prevent overlapping (and confusing) moving-animations.
1955 const int index
= widget
->index();
1956 const Cell cell
= m_visibleCells
.value(index
);
1957 if (cell
.column
>= 0 && cell
.row
>= 0) {
1958 if (scrollOrientation() == Qt::Vertical
) {
1959 startMovingAnim
= (cell
.row
== m_layouter
->itemRow(index
));
1961 startMovingAnim
= (cell
.column
== m_layouter
->itemColumn(index
));
1966 if (startMovingAnim
) {
1967 m_animation
->start(widget
, KItemListViewAnimation::MovingAnimation
, newPos
);
1971 m_animation
->stop(widget
);
1972 m_animation
->start(widget
, KItemListViewAnimation::CreateAnimation
);
1976 void KItemListView::emitOffsetChanges()
1978 const qreal newScrollOffset
= m_layouter
->scrollOffset();
1979 if (m_oldScrollOffset
!= newScrollOffset
) {
1980 Q_EMIT
scrollOffsetChanged(newScrollOffset
, m_oldScrollOffset
);
1981 m_oldScrollOffset
= newScrollOffset
;
1984 const qreal newMaximumScrollOffset
= m_layouter
->maximumScrollOffset();
1985 if (m_oldMaximumScrollOffset
!= newMaximumScrollOffset
) {
1986 Q_EMIT
maximumScrollOffsetChanged(newMaximumScrollOffset
, m_oldMaximumScrollOffset
);
1987 m_oldMaximumScrollOffset
= newMaximumScrollOffset
;
1990 const qreal newItemOffset
= m_layouter
->itemOffset();
1991 if (m_oldItemOffset
!= newItemOffset
) {
1992 Q_EMIT
itemOffsetChanged(newItemOffset
, m_oldItemOffset
);
1993 m_oldItemOffset
= newItemOffset
;
1996 const qreal newMaximumItemOffset
= m_layouter
->maximumItemOffset();
1997 if (m_oldMaximumItemOffset
!= newMaximumItemOffset
) {
1998 Q_EMIT
maximumItemOffsetChanged(newMaximumItemOffset
, m_oldMaximumItemOffset
);
1999 m_oldMaximumItemOffset
= newMaximumItemOffset
;
2003 KItemListWidget
*KItemListView::createWidget(int index
)
2005 KItemListWidget
*widget
= widgetCreator()->create(this);
2006 widget
->setFlag(QGraphicsItem::ItemStacksBehindParent
);
2008 m_visibleItems
.insert(index
, widget
);
2009 m_visibleCells
.insert(index
, Cell());
2010 updateWidgetProperties(widget
, index
);
2011 initializeItemListWidget(widget
);
2015 void KItemListView::recycleWidget(KItemListWidget
*widget
)
2018 recycleGroupHeaderForWidget(widget
);
2021 const int index
= widget
->index();
2022 m_visibleItems
.remove(index
);
2023 m_visibleCells
.remove(index
);
2025 widgetCreator()->recycle(widget
);
2028 void KItemListView::setWidgetIndex(KItemListWidget
*widget
, int index
)
2030 const int oldIndex
= widget
->index();
2031 m_visibleItems
.remove(oldIndex
);
2032 m_visibleCells
.remove(oldIndex
);
2034 m_visibleItems
.insert(index
, widget
);
2035 m_visibleCells
.insert(index
, Cell());
2037 widget
->setIndex(index
);
2040 void KItemListView::moveWidgetToIndex(KItemListWidget
*widget
, int index
)
2042 const int oldIndex
= widget
->index();
2043 const Cell oldCell
= m_visibleCells
.value(oldIndex
);
2045 setWidgetIndex(widget
, index
);
2047 const Cell
newCell(m_layouter
->itemColumn(index
), m_layouter
->itemRow(index
));
2048 const bool vertical
= (scrollOrientation() == Qt::Vertical
);
2049 const bool updateCell
= (vertical
&& oldCell
.row
== newCell
.row
) || (!vertical
&& oldCell
.column
== newCell
.column
);
2051 m_visibleCells
.insert(index
, newCell
);
2055 void KItemListView::setLayouterSize(const QSizeF
&size
, SizeType sizeType
)
2059 m_layouter
->setSize(size
);
2062 m_layouter
->setItemSize(size
);
2069 void KItemListView::updateWidgetProperties(KItemListWidget
*widget
, int index
)
2071 widget
->setVisibleRoles(m_visibleRoles
);
2072 updateWidgetColumnWidths(widget
);
2073 widget
->setStyleOption(m_styleOption
);
2075 const KItemListSelectionManager
*selectionManager
= m_controller
->selectionManager();
2077 // In SingleSelection mode (e.g., in the Places Panel), the current item is
2078 // always the selected item. It is not necessary to highlight the current item then.
2079 if (m_controller
->selectionBehavior() != KItemListController::SingleSelection
) {
2080 widget
->setCurrent(index
== selectionManager
->currentItem());
2082 widget
->setSelected(selectionManager
->isSelected(index
));
2083 widget
->setHovered(false);
2084 widget
->setEnabledSelectionToggle(enabledSelectionToggles());
2085 widget
->setIndex(index
);
2086 widget
->setData(m_model
->data(index
));
2087 widget
->setSiblingsInformation(QBitArray());
2088 updateAlternateBackgroundForWidget(widget
);
2091 updateGroupHeaderForWidget(widget
);
2095 void KItemListView::updateGroupHeaderForWidget(KItemListWidget
*widget
)
2097 Q_ASSERT(m_grouped
);
2099 const int index
= widget
->index();
2100 if (!m_layouter
->isFirstGroupItem(index
)) {
2101 // The widget does not represent the first item of a group
2102 // and hence requires no header
2103 recycleGroupHeaderForWidget(widget
);
2107 const QList
<QPair
<int, QVariant
>> groups
= model()->groups();
2108 if (groups
.isEmpty() || !groupHeaderCreator()) {
2112 KItemListGroupHeader
*groupHeader
= m_visibleGroups
.value(widget
);
2114 groupHeader
= groupHeaderCreator()->create(this);
2115 groupHeader
->setParentItem(widget
);
2116 m_visibleGroups
.insert(widget
, groupHeader
);
2117 connect(widget
, &KItemListWidget::geometryChanged
, this, &KItemListView::slotGeometryOfGroupHeaderParentChanged
);
2119 Q_ASSERT(groupHeader
->parentItem() == widget
);
2121 const int groupIndex
= groupIndexForItem(index
);
2122 Q_ASSERT(groupIndex
>= 0);
2123 groupHeader
->setData(groups
.at(groupIndex
).second
);
2124 groupHeader
->setRole(model()->sortRole());
2125 groupHeader
->setStyleOption(m_styleOption
);
2126 groupHeader
->setScrollOrientation(scrollOrientation());
2127 groupHeader
->setItemIndex(index
);
2129 groupHeader
->show();
2132 void KItemListView::updateGroupHeaderLayout(KItemListWidget
*widget
)
2134 KItemListGroupHeader
*groupHeader
= m_visibleGroups
.value(widget
);
2135 Q_ASSERT(groupHeader
);
2137 const int index
= widget
->index();
2138 const QRectF groupHeaderRect
= m_layouter
->groupHeaderRect(index
);
2139 const QRectF itemRect
= m_layouter
->itemRect(index
);
2141 // The group-header is a child of the itemlist widget. Translate the
2142 // group header position to the relative position.
2143 if (scrollOrientation() == Qt::Vertical
) {
2144 // In the vertical scroll orientation the group header should always span
2145 // the whole width no matter which temporary position the parent widget
2146 // has. In this case the x-position and width will be adjusted manually.
2147 const qreal x
= -widget
->x() - itemOffset();
2148 const qreal width
= maximumItemOffset();
2149 groupHeader
->setPos(x
, -groupHeaderRect
.height());
2150 groupHeader
->resize(width
, groupHeaderRect
.size().height());
2152 groupHeader
->setPos(groupHeaderRect
.x() - itemRect
.x(), -widget
->y());
2153 groupHeader
->resize(groupHeaderRect
.size());
2157 void KItemListView::recycleGroupHeaderForWidget(KItemListWidget
*widget
)
2159 KItemListGroupHeader
*header
= m_visibleGroups
.value(widget
);
2161 header
->setParentItem(nullptr);
2162 groupHeaderCreator()->recycle(header
);
2163 m_visibleGroups
.remove(widget
);
2164 disconnect(widget
, &KItemListWidget::geometryChanged
, this, &KItemListView::slotGeometryOfGroupHeaderParentChanged
);
2168 void KItemListView::updateVisibleGroupHeaders()
2170 Q_ASSERT(m_grouped
);
2171 m_layouter
->markAsDirty();
2173 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
2174 while (it
.hasNext()) {
2176 updateGroupHeaderForWidget(it
.value());
2180 int KItemListView::groupIndexForItem(int index
) const
2182 Q_ASSERT(m_grouped
);
2184 const QList
<QPair
<int, QVariant
>> groups
= model()->groups();
2185 if (groups
.isEmpty()) {
2190 int max
= groups
.count() - 1;
2193 mid
= (min
+ max
) / 2;
2194 if (index
> groups
[mid
].first
) {
2199 } while (groups
[mid
].first
!= index
&& min
<= max
);
2202 while (groups
[mid
].first
> index
&& mid
> 0) {
2210 void KItemListView::updateAlternateBackgrounds()
2212 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
2213 while (it
.hasNext()) {
2215 updateAlternateBackgroundForWidget(it
.value());
2219 void KItemListView::updateAlternateBackgroundForWidget(KItemListWidget
*widget
)
2221 bool enabled
= useAlternateBackgrounds();
2223 const int index
= widget
->index();
2224 enabled
= (index
& 0x1) > 0;
2226 const int groupIndex
= groupIndexForItem(index
);
2227 if (groupIndex
>= 0) {
2228 const QList
<QPair
<int, QVariant
>> groups
= model()->groups();
2229 const int indexOfFirstGroupItem
= groups
[groupIndex
].first
;
2230 const int relativeIndex
= index
- indexOfFirstGroupItem
;
2231 enabled
= (relativeIndex
& 0x1) > 0;
2235 widget
->setAlternateBackground(enabled
);
2238 bool KItemListView::useAlternateBackgrounds() const
2240 return m_alternateBackgrounds
&& m_itemSize
.isEmpty();
2243 QHash
<QByteArray
, qreal
> KItemListView::preferredColumnWidths(const KItemRangeList
&itemRanges
) const
2245 QElapsedTimer timer
;
2248 QHash
<QByteArray
, qreal
> widths
;
2250 // Calculate the minimum width for each column that is required
2251 // to show the headline unclipped.
2252 const QFontMetricsF
fontMetrics(m_headerWidget
->font());
2253 const int gripMargin
= m_headerWidget
->style()->pixelMetric(QStyle::PM_HeaderGripMargin
);
2254 const int headerMargin
= m_headerWidget
->style()->pixelMetric(QStyle::PM_HeaderMargin
);
2255 for (const QByteArray
&visibleRole
: std::as_const(m_visibleRoles
)) {
2256 const QString headerText
= m_model
->roleDescription(visibleRole
);
2257 const qreal headerWidth
= fontMetrics
.horizontalAdvance(headerText
) + gripMargin
+ headerMargin
* 2;
2258 widths
.insert(visibleRole
, headerWidth
);
2261 // Calculate the preferred column widths for each item and ignore values
2262 // smaller than the width for showing the headline unclipped.
2263 const KItemListWidgetCreatorBase
*creator
= widgetCreator();
2264 int calculatedItemCount
= 0;
2265 bool maxTimeExceeded
= false;
2266 for (const KItemRange
&itemRange
: itemRanges
) {
2267 const int startIndex
= itemRange
.index
;
2268 const int endIndex
= startIndex
+ itemRange
.count
- 1;
2270 for (int i
= startIndex
; i
<= endIndex
; ++i
) {
2271 for (const QByteArray
&visibleRole
: std::as_const(m_visibleRoles
)) {
2272 qreal maxWidth
= widths
.value(visibleRole
, 0);
2273 const qreal width
= creator
->preferredRoleColumnWidth(visibleRole
, i
, this);
2274 maxWidth
= qMax(width
, maxWidth
);
2275 widths
.insert(visibleRole
, maxWidth
);
2278 if (calculatedItemCount
> 100 && timer
.elapsed() > 200) {
2279 // When having several thousands of items calculating the sizes can get
2280 // very expensive. We accept a possibly too small role-size in favour
2281 // of having no blocking user interface.
2282 maxTimeExceeded
= true;
2285 ++calculatedItemCount
;
2287 if (maxTimeExceeded
) {
2295 void KItemListView::applyColumnWidthsFromHeader()
2297 // Apply the new size to the layouter
2298 const qreal requiredWidth
= columnWidthsSum() + 2 * m_headerWidget
->sidePadding();
2299 const QSizeF
dynamicItemSize(qMax(size().width(), requiredWidth
), m_itemSize
.height());
2300 m_layouter
->setItemSize(dynamicItemSize
);
2302 // Update the role sizes for all visible widgets
2303 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
2304 while (it
.hasNext()) {
2306 updateWidgetColumnWidths(it
.value());
2310 void KItemListView::updateWidgetColumnWidths(KItemListWidget
*widget
)
2312 for (const QByteArray
&role
: std::as_const(m_visibleRoles
)) {
2313 widget
->setColumnWidth(role
, m_headerWidget
->columnWidth(role
));
2315 widget
->setSidePadding(m_headerWidget
->sidePadding());
2318 void KItemListView::updatePreferredColumnWidths(const KItemRangeList
&itemRanges
)
2320 Q_ASSERT(m_itemSize
.isEmpty());
2321 const int itemCount
= m_model
->count();
2322 int rangesItemCount
= 0;
2323 for (const KItemRange
&range
: itemRanges
) {
2324 rangesItemCount
+= range
.count
;
2327 if (itemCount
== rangesItemCount
) {
2328 const QHash
<QByteArray
, qreal
> preferredWidths
= preferredColumnWidths(itemRanges
);
2329 for (const QByteArray
&role
: std::as_const(m_visibleRoles
)) {
2330 m_headerWidget
->setPreferredColumnWidth(role
, preferredWidths
.value(role
));
2333 // Only a sub range of the roles need to be determined.
2334 // The chances are good that the widths of the sub ranges
2335 // already fit into the available widths and hence no
2336 // expensive update might be required.
2337 bool changed
= false;
2339 const QHash
<QByteArray
, qreal
> updatedWidths
= preferredColumnWidths(itemRanges
);
2340 QHashIterator
<QByteArray
, qreal
> it(updatedWidths
);
2341 while (it
.hasNext()) {
2343 const QByteArray
&role
= it
.key();
2344 const qreal updatedWidth
= it
.value();
2345 const qreal currentWidth
= m_headerWidget
->preferredColumnWidth(role
);
2346 if (updatedWidth
> currentWidth
) {
2347 m_headerWidget
->setPreferredColumnWidth(role
, updatedWidth
);
2353 // All the updated sizes are smaller than the current sizes and no change
2354 // of the stretched roles-widths is required
2359 if (m_headerWidget
->automaticColumnResizing()) {
2360 applyAutomaticColumnWidths();
2364 void KItemListView::updatePreferredColumnWidths()
2367 updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model
->count()));
2371 void KItemListView::applyAutomaticColumnWidths()
2373 Q_ASSERT(m_itemSize
.isEmpty());
2374 Q_ASSERT(m_headerWidget
->automaticColumnResizing());
2375 if (m_visibleRoles
.isEmpty()) {
2379 // Calculate the maximum size of an item by considering the
2380 // visible role sizes and apply them to the layouter. If the
2381 // size does not use the available view-size the size of the
2382 // first role will get stretched.
2384 for (const QByteArray
&role
: std::as_const(m_visibleRoles
)) {
2385 const qreal preferredWidth
= m_headerWidget
->preferredColumnWidth(role
);
2386 m_headerWidget
->setColumnWidth(role
, preferredWidth
);
2389 const QByteArray firstRole
= m_visibleRoles
.first();
2390 qreal firstColumnWidth
= m_headerWidget
->columnWidth(firstRole
);
2391 QSizeF dynamicItemSize
= m_itemSize
;
2393 qreal requiredWidth
= columnWidthsSum() + 2 * m_headerWidget
->sidePadding(); // Adding the padding a second time so we have the same padding
2394 // symmetrically on both sides of the view. This improves UX, looks better and increases the chances of users figuring out that the padding
2395 // area can be used for deselecting and dropping files.
2396 const qreal availableWidth
= size().width();
2397 if (requiredWidth
< availableWidth
) {
2398 // Stretch the first column to use the whole remaining width
2399 firstColumnWidth
+= availableWidth
- requiredWidth
;
2400 m_headerWidget
->setColumnWidth(firstRole
, firstColumnWidth
);
2401 } else if (requiredWidth
> availableWidth
&& m_visibleRoles
.count() > 1) {
2402 // Shrink the first column to be able to show as much other
2403 // columns as possible
2404 qreal shrinkedFirstColumnWidth
= firstColumnWidth
- requiredWidth
+ availableWidth
;
2406 // TODO: A proper calculation of the minimum width depends on the implementation
2407 // of KItemListWidget. Probably a kind of minimum size-hint should be introduced
2409 const qreal minWidth
= qMin(firstColumnWidth
, qreal(m_styleOption
.iconSize
* 2 + 200));
2410 if (shrinkedFirstColumnWidth
< minWidth
) {
2411 shrinkedFirstColumnWidth
= minWidth
;
2414 m_headerWidget
->setColumnWidth(firstRole
, shrinkedFirstColumnWidth
);
2415 requiredWidth
-= firstColumnWidth
- shrinkedFirstColumnWidth
;
2418 dynamicItemSize
.rwidth() = qMax(requiredWidth
, availableWidth
);
2420 m_layouter
->setItemSize(dynamicItemSize
);
2422 // Update the role sizes for all visible widgets
2423 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
2424 while (it
.hasNext()) {
2426 updateWidgetColumnWidths(it
.value());
2430 qreal
KItemListView::columnWidthsSum() const
2432 qreal widthsSum
= 0;
2433 for (const QByteArray
&role
: std::as_const(m_visibleRoles
)) {
2434 widthsSum
+= m_headerWidget
->columnWidth(role
);
2439 QRectF
KItemListView::headerBoundaries() const
2441 return m_headerWidget
->isVisible() ? m_headerWidget
->geometry() : QRectF();
2444 bool KItemListView::changesItemGridLayout(const QSizeF
&newGridSize
, const QSizeF
&newItemSize
, const QSizeF
&newItemMargin
) const
2446 if (newItemSize
.isEmpty() || newGridSize
.isEmpty()) {
2450 if (m_layouter
->scrollOrientation() == Qt::Vertical
) {
2451 const qreal itemWidth
= m_layouter
->itemSize().width();
2452 if (itemWidth
> 0) {
2453 const int newColumnCount
= itemsPerSize(newGridSize
.width(), newItemSize
.width(), newItemMargin
.width());
2454 if (m_model
->count() > newColumnCount
) {
2455 const int oldColumnCount
= itemsPerSize(m_layouter
->size().width(), itemWidth
, m_layouter
->itemMargin().width());
2456 return oldColumnCount
!= newColumnCount
;
2460 const qreal itemHeight
= m_layouter
->itemSize().height();
2461 if (itemHeight
> 0) {
2462 const int newRowCount
= itemsPerSize(newGridSize
.height(), newItemSize
.height(), newItemMargin
.height());
2463 if (m_model
->count() > newRowCount
) {
2464 const int oldRowCount
= itemsPerSize(m_layouter
->size().height(), itemHeight
, m_layouter
->itemMargin().height());
2465 return oldRowCount
!= newRowCount
;
2473 bool KItemListView::animateChangedItemCount(int changedItemCount
) const
2475 if (m_itemSize
.isEmpty()) {
2476 // We have only columns or only rows, but no grid: An animation is usually
2477 // welcome when inserting or removing items.
2478 return !supportsItemExpanding();
2481 if (m_layouter
->size().isEmpty() || m_layouter
->itemSize().isEmpty()) {
2485 const int maximum
= (scrollOrientation() == Qt::Vertical
) ? m_layouter
->size().width() / m_layouter
->itemSize().width()
2486 : m_layouter
->size().height() / m_layouter
->itemSize().height();
2487 // Only animate if up to 2/3 of a row or column are inserted or removed
2488 return changedItemCount
<= maximum
* 2 / 3;
2491 bool KItemListView::scrollBarRequired(const QSizeF
&size
) const
2493 const QSizeF oldSize
= m_layouter
->size();
2495 m_layouter
->setSize(size
);
2496 const qreal maxOffset
= m_layouter
->maximumScrollOffset();
2497 m_layouter
->setSize(oldSize
);
2499 return m_layouter
->scrollOrientation() == Qt::Vertical
? maxOffset
> size
.height() : maxOffset
> size
.width();
2502 int KItemListView::showDropIndicator(const QPointF
&pos
)
2504 QHashIterator
<int, KItemListWidget
*> it(m_visibleItems
);
2505 while (it
.hasNext()) {
2507 const KItemListWidget
*widget
= it
.value();
2509 const QPointF mappedPos
= widget
->mapFromItem(this, pos
);
2510 const QRectF rect
= itemRect(widget
->index());
2511 if (mappedPos
.y() >= 0 && mappedPos
.y() <= rect
.height()) {
2512 if (m_model
->supportsDropping(widget
->index())) {
2513 // Keep 30% of the rectangle as the gap instead of always having a fixed gap
2514 const int gap
= qMax(qreal(4.0), qreal(0.3) * rect
.height());
2515 if (mappedPos
.y() >= gap
&& mappedPos
.y() <= rect
.height() - gap
) {
2520 const bool isAboveItem
= (mappedPos
.y() < rect
.height() / 2);
2521 const qreal y
= isAboveItem
? rect
.top() : rect
.bottom();
2523 const QRectF
draggingInsertIndicator(rect
.left(), y
, rect
.width(), 1);
2524 if (m_dropIndicator
!= draggingInsertIndicator
) {
2525 m_dropIndicator
= draggingInsertIndicator
;
2529 int index
= widget
->index();
2537 const QRectF firstItemRect
= itemRect(firstVisibleIndex());
2538 return (pos
.y() <= firstItemRect
.top()) ? 0 : -1;
2541 void KItemListView::hideDropIndicator()
2543 if (!m_dropIndicator
.isNull()) {
2544 m_dropIndicator
= QRectF();
2549 void KItemListView::updateGroupHeaderHeight()
2551 qreal groupHeaderHeight
= m_styleOption
.fontMetrics
.height();
2552 qreal groupHeaderMargin
= 0;
2554 if (scrollOrientation() == Qt::Horizontal
) {
2555 // The vertical margin above and below the header should be
2556 // equal to the horizontal margin, not the vertical margin
2557 // from m_styleOption.
2558 groupHeaderHeight
+= 2 * m_styleOption
.horizontalMargin
;
2559 groupHeaderMargin
= m_styleOption
.horizontalMargin
;
2560 } else if (m_itemSize
.isEmpty()) {
2561 groupHeaderHeight
+= 4 * m_styleOption
.padding
;
2562 groupHeaderMargin
= m_styleOption
.iconSize
/ 2;
2564 groupHeaderHeight
+= 2 * m_styleOption
.padding
+ m_styleOption
.verticalMargin
;
2565 groupHeaderMargin
= m_styleOption
.iconSize
/ 4;
2567 m_layouter
->setGroupHeaderHeight(groupHeaderHeight
);
2568 m_layouter
->setGroupHeaderMargin(groupHeaderMargin
);
2570 updateVisibleGroupHeaders();
2573 void KItemListView::updateSiblingsInformation(int firstIndex
, int lastIndex
)
2575 if (!supportsItemExpanding() || !m_model
) {
2579 if (firstIndex
< 0 || lastIndex
< 0) {
2580 firstIndex
= m_layouter
->firstVisibleIndex();
2581 lastIndex
= m_layouter
->lastVisibleIndex();
2583 const bool isRangeVisible
= (firstIndex
<= m_layouter
->lastVisibleIndex() && lastIndex
>= m_layouter
->firstVisibleIndex());
2584 if (!isRangeVisible
) {
2589 int previousParents
= 0;
2590 QBitArray previousSiblings
;
2592 // The rootIndex describes the first index where the siblings get
2593 // calculated from. For the calculation the upper most parent item
2594 // is required. For performance reasons it is checked first whether
2595 // the visible items before or after the current range already
2596 // contain a siblings information which can be used as base.
2597 int rootIndex
= firstIndex
;
2599 KItemListWidget
*widget
= m_visibleItems
.value(firstIndex
- 1);
2601 // There is no visible widget before the range, check whether there
2602 // is one after the range:
2603 widget
= m_visibleItems
.value(lastIndex
+ 1);
2605 // The sibling information of the widget may only be used if
2606 // all items of the range have the same number of parents.
2607 const int parents
= m_model
->expandedParentsCount(lastIndex
+ 1);
2608 for (int i
= lastIndex
; i
>= firstIndex
; --i
) {
2609 if (m_model
->expandedParentsCount(i
) != parents
) {
2618 // Performance optimization: Use the sibling information of the visible
2619 // widget beside the given range.
2620 previousSiblings
= widget
->siblingsInformation();
2621 if (previousSiblings
.isEmpty()) {
2624 previousParents
= previousSiblings
.count() - 1;
2625 previousSiblings
.truncate(previousParents
);
2627 // Potentially slow path: Go back to the upper most parent of firstIndex
2628 // to be able to calculate the initial value for the siblings.
2629 while (rootIndex
> 0 && m_model
->expandedParentsCount(rootIndex
) > 0) {
2634 Q_ASSERT(previousParents
>= 0);
2635 for (int i
= rootIndex
; i
<= lastIndex
; ++i
) {
2636 // Update the parent-siblings in case if the current item represents
2637 // a child or an upper parent.
2638 const int currentParents
= m_model
->expandedParentsCount(i
);
2639 Q_ASSERT(currentParents
>= 0);
2640 if (previousParents
< currentParents
) {
2641 previousParents
= currentParents
;
2642 previousSiblings
.resize(currentParents
);
2643 previousSiblings
.setBit(currentParents
- 1, hasSiblingSuccessor(i
- 1));
2644 } else if (previousParents
> currentParents
) {
2645 previousParents
= currentParents
;
2646 previousSiblings
.truncate(currentParents
);
2649 if (i
>= firstIndex
) {
2650 // The index represents a visible item. Apply the parent-siblings
2651 // and update the sibling of the current item.
2652 KItemListWidget
*widget
= m_visibleItems
.value(i
);
2657 QBitArray siblings
= previousSiblings
;
2658 siblings
.resize(siblings
.count() + 1);
2659 siblings
.setBit(siblings
.count() - 1, hasSiblingSuccessor(i
));
2661 widget
->setSiblingsInformation(siblings
);
2666 bool KItemListView::hasSiblingSuccessor(int index
) const
2668 bool hasSuccessor
= false;
2669 const int parentsCount
= m_model
->expandedParentsCount(index
);
2670 int successorIndex
= index
+ 1;
2672 // Search the next sibling
2673 const int itemCount
= m_model
->count();
2674 while (successorIndex
< itemCount
) {
2675 const int currentParentsCount
= m_model
->expandedParentsCount(successorIndex
);
2676 if (currentParentsCount
== parentsCount
) {
2677 hasSuccessor
= true;
2679 } else if (currentParentsCount
< parentsCount
) {
2685 if (m_grouped
&& hasSuccessor
) {
2686 // If the sibling is part of another group, don't mark it as
2687 // successor as the group header is between the sibling connections.
2688 for (int i
= index
+ 1; i
<= successorIndex
; ++i
) {
2689 if (m_layouter
->isFirstGroupItem(i
)) {
2690 hasSuccessor
= false;
2696 return hasSuccessor
;
2699 void KItemListView::disconnectRoleEditingSignals(int index
)
2701 KStandardItemListWidget
*widget
= qobject_cast
<KStandardItemListWidget
*>(m_visibleItems
.value(index
));
2706 disconnect(widget
, &KItemListWidget::roleEditingCanceled
, this, nullptr);
2707 disconnect(widget
, &KItemListWidget::roleEditingFinished
, this, nullptr);
2708 disconnect(this, &KItemListView::scrollOffsetChanged
, widget
, nullptr);
2711 int KItemListView::calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
)
2715 const int minSpeed
= 4;
2716 const int maxSpeed
= 128;
2717 const int speedLimiter
= 96;
2718 const int autoScrollBorder
= 64;
2720 // Limit the increment that is allowed to be added in comparison to 'oldInc'.
2721 // This assures that the autoscrolling speed grows gradually.
2722 const int incLimiter
= 1;
2724 if (pos
< autoScrollBorder
) {
2725 inc
= -minSpeed
+ qAbs(pos
- autoScrollBorder
) * (pos
- autoScrollBorder
) / speedLimiter
;
2726 inc
= qMax(inc
, -maxSpeed
);
2727 inc
= qMax(inc
, oldInc
- incLimiter
);
2728 } else if (pos
> range
- autoScrollBorder
) {
2729 inc
= minSpeed
+ qAbs(pos
- range
+ autoScrollBorder
) * (pos
- range
+ autoScrollBorder
) / speedLimiter
;
2730 inc
= qMin(inc
, maxSpeed
);
2731 inc
= qMin(inc
, oldInc
+ incLimiter
);
2737 int KItemListView::itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
)
2739 const qreal availableSize
= size
- itemMargin
;
2740 const int count
= availableSize
/ (itemSize
+ itemMargin
);
2744 KItemListCreatorBase::~KItemListCreatorBase()
2746 qDeleteAll(m_recycleableWidgets
);
2747 qDeleteAll(m_createdWidgets
);
2750 void KItemListCreatorBase::addCreatedWidget(QGraphicsWidget
*widget
)
2752 m_createdWidgets
.insert(widget
);
2755 void KItemListCreatorBase::pushRecycleableWidget(QGraphicsWidget
*widget
)
2757 Q_ASSERT(m_createdWidgets
.contains(widget
));
2758 m_createdWidgets
.remove(widget
);
2760 if (m_recycleableWidgets
.count() < 100) {
2761 m_recycleableWidgets
.append(widget
);
2762 widget
->setVisible(false);
2768 QGraphicsWidget
*KItemListCreatorBase::popRecycleableWidget()
2770 if (m_recycleableWidgets
.isEmpty()) {
2774 QGraphicsWidget
*widget
= m_recycleableWidgets
.takeLast();
2775 m_createdWidgets
.insert(widget
);
2779 KItemListWidgetCreatorBase::~KItemListWidgetCreatorBase()
2783 void KItemListWidgetCreatorBase::recycle(KItemListWidget
*widget
)
2785 widget
->setParentItem(nullptr);
2786 widget
->setOpacity(1.0);
2787 pushRecycleableWidget(widget
);
2790 KItemListGroupHeaderCreatorBase::~KItemListGroupHeaderCreatorBase()
2794 void KItemListGroupHeaderCreatorBase::recycle(KItemListGroupHeader
*header
)
2796 header
->setOpacity(1.0);
2797 pushRecycleableWidget(header
);
2800 #include "moc_kitemlistview.cpp"