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 #ifndef KITEMLISTVIEW_H
10 #define KITEMLISTVIEW_H
14 #include "dolphin_export.h"
15 #include "kitemviews/kitemliststyleoption.h"
16 #include "kitemviews/kitemlistwidget.h"
17 #include "kitemviews/kitemmodelbase.h"
18 #include "kitemviews/kstandarditemlistgroupheader.h"
19 #include "kitemviews/private/kitemlistviewanimation.h"
21 #include <QGraphicsWidget>
24 class KItemListContainer
;
25 class KItemListContainerAccessible
;
26 class KItemListController
;
27 class KItemListGroupHeaderCreatorBase
;
28 class KItemListHeader
;
29 class KItemListHeaderWidget
;
30 class KItemListSizeHintResolver
;
31 class KItemListRubberBand
;
32 class KItemListViewAnimation
;
33 class KItemListViewLayouter
;
34 class KItemListWidget
;
35 class KItemListWidgetInformant
;
36 class KItemListWidgetCreatorBase
;
38 class QPropertyAnimation
;
39 class QVariantAnimation
;
42 * @brief Represents the view of an item-list.
44 * The view is responsible for showing the items of the model within
45 * a GraphicsItem. Each visible item is represented by a KItemListWidget.
47 * The created view must be applied to the KItemListController with
48 * KItemListController::setView() or with the constructor of
49 * KItemListController.
51 * @see KItemListWidget
54 class DOLPHIN_EXPORT KItemListView
: public QGraphicsWidget
58 Q_PROPERTY(qreal scrollOffset READ scrollOffset WRITE setScrollOffset NOTIFY scrollOffsetChanged
)
59 Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset NOTIFY itemOffsetChanged
)
62 /** The position in the view to which an item should be scrolled to. */
63 enum ViewItemPosition
{ Beginning
, Middle
, End
, Nearest
};
65 explicit KItemListView(QGraphicsWidget
*parent
= nullptr);
66 ~KItemListView() override
;
69 * Offset of the scrollbar that represents the scroll-orientation
70 * (see setScrollOrientation()).
72 void setScrollOffset(qreal offset
);
73 qreal
scrollOffset() const;
75 qreal
maximumScrollOffset() const;
78 * Offset related to an item, that does not fit into the available
79 * size of the listview. If the scroll-orientation is vertical
80 * the item-offset describes the offset of the horizontal axe, if
81 * the scroll-orientation is horizontal the item-offset describes
82 * the offset of the vertical axe.
84 void setItemOffset(qreal scrollOffset
);
85 qreal
itemOffset() const;
87 qreal
maximumItemOffset() const;
89 int maximumVisibleItems() const;
91 void setVisibleRoles(const QList
<QByteArray
> &roles
);
92 QList
<QByteArray
> visibleRoles() const;
95 * If set to true an automatic scrolling is done as soon as the
96 * mouse is moved near the borders of the view. Per default
97 * the automatic scrolling is turned off.
99 void setAutoScroll(bool enabled
);
100 bool autoScroll() const;
103 * If set to true selection-toggles will be shown when hovering
104 * an item. Per default the selection-toggles are disabled.
106 void setEnabledSelectionToggles(bool enabled
);
107 bool enabledSelectionToggles() const;
110 * @return Controller of the item-list. The controller gets
111 * initialized by KItemListController::setView() and will
112 * result in calling KItemListController::onControllerChanged().
114 KItemListController
*controller() const;
117 * @return Model of the item-list. The model gets
118 * initialized by KItemListController::setModel() and will
119 * result in calling KItemListController::onModelChanged().
121 KItemModelBase
*model() const;
124 * Sets the creator that creates a widget showing the
125 * content of one model-item. Usually it is sufficient
126 * to implement a custom widget X derived from KItemListWidget and
127 * set the creator by:
129 * itemListView->setWidgetCreator(new KItemListWidgetCreator<X>());
131 * The ownership of the widget creator is transferred to
132 * the item-list view.
134 void setWidgetCreator(KItemListWidgetCreatorBase
*widgetCreator
);
135 KItemListWidgetCreatorBase
*widgetCreator() const;
138 * Sets the creator that creates a group header. Usually it is sufficient
139 * to implement a custom header widget X derived from KItemListGroupHeader and
140 * set the creator by:
142 * itemListView->setGroupHeaderCreator(new KItemListGroupHeaderCreator<X>());
144 * The ownership of the gropup header creator is transferred to
145 * the item-list view.
147 void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
*groupHeaderCreator
);
148 KItemListGroupHeaderCreatorBase
*groupHeaderCreator() const;
150 #ifndef QT_NO_ACCESSIBILITY
152 * Uses \a parent to create an accessible object for \a parent. That accessible object will
153 * then be used as the accessible parent of the accessible object for this KItemListView.
154 * Make sure \a parent is the container which contains this specific KItemListView.
155 * This method must be called once before the accessible interface is queried for this class.
157 void setAccessibleParentsObject(KItemListContainer
*accessibleParentsObject
);
158 /** The parent of the QAccessibilityInterface of this class. */
159 KItemListContainerAccessible
*accessibleParent();
163 * @return The basic size of all items. The size of an item may be larger than
164 * the basic size (see KItemListView::itemRect()).
166 QSizeF
itemSize() const;
168 const KItemListStyleOption
&styleOption() const;
170 void setGeometry(const QRectF
&rect
) override
;
173 * @return The page step which should be used by the vertical scroll bar.
174 * This is the height of the view except for the header widget.
176 qreal
verticalPageStep() const;
179 * @return Index of the item that is below the point \a pos.
180 * The position is relative to the upper right of
181 * the visible area. Only (at least partly) visible
182 * items are considered. std::nullopt is returned if
183 * no item is below the position.
185 std::optional
<int> itemAt(const QPointF
&pos
) const;
186 bool isAboveSelectionToggle(int index
, const QPointF
&pos
) const;
187 bool isAboveExpansionToggle(int index
, const QPointF
&pos
) const;
188 bool isAboveText(int index
, const QPointF
&pos
) const;
191 * @return Index of the first item that is at least partly visible.
192 * -1 is returned if the model contains no items.
194 int firstVisibleIndex() const;
197 * @return Index of the last item that is at least partly visible.
198 * -1 is returned if the model contains no items.
200 int lastVisibleIndex() const;
203 * Calculates the required size for all items in the model.
204 * It might be larger than KItemListView::itemSize().
205 * In this case the layout grid will be stretched to assure an
208 * @note the logical height (width) is actually the
209 * width (height) if the scroll orientation is Qt::Vertical!
211 void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>> &logicalHeightHints
, qreal
&logicalWidthHint
) const;
214 * If set to true, items having child-items can be expanded to show the child-items as
215 * part of the view. Per default the expanding of items is disabled. If expanding of
216 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
217 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
218 * must be reimplemented. The view-implementation
219 * has to take care itself how to visually represent the expanded items provided
222 void setSupportsItemExpanding(bool supportsExpanding
);
223 bool supportsItemExpanding() const;
225 void setHighlightEntireRow(bool highlightEntireRow
);
226 bool highlightEntireRow() const;
228 void setAlternateBackgrounds(bool alternate
);
229 bool alternateBackgrounds() const;
232 * @return The rectangle of the item relative to the top/left of
233 * the currently visible area (see KItemListView::offset()).
235 QRectF
itemRect(int index
) const;
238 * @return The context rectangle of the item relative to the top/left of
239 * the currently visible area (see KItemListView::offset()). The
240 * context rectangle is defined by the united rectangle of
241 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
242 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
243 * a tooltip or a context-menu for an item. Note that a context rectangle will
244 * only be returned for (at least partly) visible items. An empty rectangle will
245 * be returned for fully invisible items.
247 QRectF
itemContextRect(int index
) const;
250 * @return Whether or not the name of the file has been elided. At present this will
251 * only ever be true when in icons view.
253 bool isElided(int index
) const;
256 * Scrolls to the item with the index \a index so that the item
257 * will be fully visible. The item is positioned within the view
258 * as specified by \a viewItemPosition.
260 void scrollToItem(int index
, ViewItemPosition viewItemPosition
= ViewItemPosition::Nearest
);
263 * If several properties of KItemListView are changed synchronously, it is
264 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
265 * This prevents unnecessary and expensive layout-calculations.
267 void beginTransaction();
270 * Counterpart to beginTransaction(). The layout changes will only be animated if
271 * all property changes between beginTransaction() and endTransaction() support
274 void endTransaction();
276 bool isTransactionActive() const;
279 * Turns on the header if \p visible is true. Per default the
280 * header is not visible. Usually the header is turned on when
281 * showing a classic "table-view" to describe the shown columns.
283 void setHeaderVisible(bool visible
);
284 bool isHeaderVisible() const;
287 * @return Header of the list. The header is also available if it is not shown
288 * (see KItemListView::setHeaderShown()).
290 KItemListHeader
*header() const;
293 * @return Pixmap that is used for a drag operation based on the
294 * items given by \a indexes.
296 virtual QPixmap
createDragPixmap(const KItemSet
&indexes
) const;
299 * Lets the user edit the role \a role for item with the index \a index.
301 void editRole(int index
, const QByteArray
&role
);
303 void paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
, QWidget
*widget
= nullptr) override
;
306 * Set the bottom offset for moving the view so that the small overlayed statusbar
307 * won't cover any items by accident.
309 void setStatusBarOffset(int offset
);
312 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
313 void scrollOffsetChanged(qreal current
, qreal previous
);
314 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
315 void itemOffsetChanged(qreal current
, qreal previous
);
316 void maximumItemOffsetChanged(qreal current
, qreal previous
);
317 void scrollTo(qreal newOffset
);
320 * Is emitted if the user has changed the sort order by clicking on a
321 * header item (see KItemListView::setHeaderShown()). The sort order
322 * of the model has already been adjusted to
323 * the current sort order. Note that no signal will be emitted if the
324 * sort order of the model has been changed without user interaction.
326 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
329 * Is emitted if the user has changed the sort role by clicking on a
330 * header item (see KItemListView::setHeaderShown()). The sort role
331 * of the model has already been adjusted to
332 * the current sort role. Note that no signal will be emitted if the
333 * sort role of the model has been changed without user interaction.
335 void sortRoleChanged(const QByteArray
¤t
, const QByteArray
&previous
);
338 * Is emitted if the user has changed the visible roles by moving a header
339 * item (see KItemListView::setHeaderShown()). Note that no signal will be
340 * emitted if the roles have been changed without user interaction by
341 * KItemListView::setVisibleRoles().
343 void visibleRolesChanged(const QList
<QByteArray
> ¤t
, const QList
<QByteArray
> &previous
);
345 void roleEditingCanceled(int index
, const QByteArray
&role
, const QVariant
&value
);
346 void roleEditingFinished(int index
, const QByteArray
&role
, const QVariant
&value
);
349 * Emitted once scrolling has finished, or immediately if no scrolling was necessary
350 * to get item in view in scrollToItem.
352 void scrollingStopped();
354 void columnHovered(int roleIndex
);
355 void columnUnHovered(int roleIndex
);
358 QVariant
itemChange(GraphicsItemChange change
, const QVariant
&value
) override
;
359 void setItemSize(const QSizeF
&size
);
360 void setStyleOption(const KItemListStyleOption
&option
);
363 * If the scroll-orientation is vertical, the items are ordered
364 * from top to bottom (= default setting). If the scroll-orientation
365 * is horizontal, the items are ordered from left to right.
367 void setScrollOrientation(Qt::Orientation orientation
);
368 Qt::Orientation
scrollOrientation() const;
371 * Factory method for creating a default widget-creator. The method will be used
372 * in case if setWidgetCreator() has not been set by the application.
373 * @return New instance of the widget-creator that should be used per
376 virtual KItemListWidgetCreatorBase
*defaultWidgetCreator() const;
379 * Factory method for creating a default group-header-creator. The method will be used
380 * in case if setGroupHeaderCreator() has not been set by the application.
381 * @return New instance of the group-header-creator that should be used per
384 virtual KItemListGroupHeaderCreatorBase
*defaultGroupHeaderCreator() const;
387 * Is called when creating a new KItemListWidget instance and allows derived
388 * classes to do a custom initialization.
390 virtual void initializeItemListWidget(KItemListWidget
*item
);
393 * @return True if at least one of the changed roles \p changedRoles might result
394 * in the need to update the item-size hint (see KItemListView::itemSizeHint()).
395 * Per default true is returned which means on each role-change of existing items
396 * the item-size hints are recalculated. For performance reasons it is recommended
397 * to return false in case if a role-change will not result in a changed
400 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
> &changedRoles
) const;
402 virtual void onControllerChanged(KItemListController
*current
, KItemListController
*previous
);
403 virtual void onModelChanged(KItemModelBase
*current
, KItemModelBase
*previous
);
405 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
406 virtual void onItemSizeChanged(const QSizeF
¤t
, const QSizeF
&previous
);
407 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
408 virtual void onVisibleRolesChanged(const QList
<QByteArray
> ¤t
, const QList
<QByteArray
> &previous
);
409 virtual void onStyleOptionChanged(const KItemListStyleOption
¤t
, const KItemListStyleOption
&previous
);
410 virtual void onHighlightEntireRowChanged(bool highlightEntireRow
);
411 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
413 virtual void onTransactionBegin();
414 virtual void onTransactionEnd();
416 bool event(QEvent
*event
) override
;
417 void mousePressEvent(QGraphicsSceneMouseEvent
*event
) override
;
418 void mouseMoveEvent(QGraphicsSceneMouseEvent
*event
) override
;
419 void dragEnterEvent(QGraphicsSceneDragDropEvent
*event
) override
;
420 void dragMoveEvent(QGraphicsSceneDragDropEvent
*event
) override
;
421 void dragLeaveEvent(QGraphicsSceneDragDropEvent
*event
) override
;
422 void dropEvent(QGraphicsSceneDragDropEvent
*event
) override
;
424 QList
<KItemListWidget
*> visibleItemListWidgets() const;
426 virtual void updateFont();
427 virtual void updatePalette();
430 virtual void slotItemsInserted(const KItemRangeList
&itemRanges
);
431 virtual void slotItemsRemoved(const KItemRangeList
&itemRanges
);
432 virtual void slotItemsMoved(const KItemRange
&itemRange
, const QList
<int> &movedToIndexes
);
433 virtual void slotItemsChanged(const KItemRangeList
&itemRanges
, const QSet
<QByteArray
> &roles
);
434 virtual void slotGroupsChanged();
436 virtual void slotGroupedSortingChanged(bool current
);
437 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
438 virtual void slotSortRoleChanged(const QByteArray
¤t
, const QByteArray
&previous
);
439 virtual void slotCurrentChanged(int current
, int previous
);
440 virtual void slotSelectionChanged(const KItemSet
¤t
, const KItemSet
&previous
);
443 void slotAnimationFinished(QGraphicsWidget
*widget
, KItemListViewAnimation::AnimationType type
);
445 void slotRubberBandPosChanged();
446 void slotRubberBandActivationChanged(bool active
);
449 * Is invoked if the column-width of one role in the header has
450 * been changed by the user. The automatic resizing of columns
451 * will be turned off as soon as this method has been called at
454 void slotHeaderColumnWidthChanged(const QByteArray
&role
, qreal currentWidth
, qreal previousWidth
);
456 void slotSidePaddingChanged(qreal width
);
459 * Is invoked if a column has been moved by the user. Applies
460 * the moved role to the view.
462 void slotHeaderColumnMoved(const QByteArray
&role
, int currentIndex
, int previousIndex
);
465 * Triggers the autoscrolling if autoScroll() is enabled by checking the
466 * current mouse position. If the mouse position is within the autoscroll
467 * margins a timer will be started that periodically triggers the autoscrolling.
469 void triggerAutoScrolling();
472 * Is invoked if the geometry of the parent-widget from a group-header has been
473 * changed. The x-position and width of the group-header gets adjusted to assure
474 * that it always spans the whole width even during temporary transitions of the
477 void slotGeometryOfGroupHeaderParentChanged();
479 void slotRoleEditingCanceled(int index
, const QByteArray
&role
, const QVariant
&value
);
480 void slotRoleEditingFinished(int index
, const QByteArray
&role
, const QVariant
&value
);
483 enum LayoutAnimationHint
{ NoAnimation
, Animation
};
485 enum SizeType
{ LayouterSize
, ItemSize
};
487 void setController(KItemListController
*controller
);
488 void setModel(KItemModelBase
*model
);
490 KItemListRubberBand
*rubberBand() const;
492 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
495 * Helper method for doLayout: Returns a list of items that can be reused for the visible
496 * area. Invisible group headers get recycled. The reusable items are items that are
497 * invisible. If the animation hint is 'Animation' then items that are currently animated
498 * won't be reused. Reusing items is faster in comparison to deleting invisible
499 * items and creating a new instance for visible items.
501 QList
<int> recycleInvisibleItems(int firstVisibleIndex
, int lastVisibleIndex
, LayoutAnimationHint hint
);
504 * Helper method for doLayout: Starts a moving-animation for the widget to the given
505 * new position. The moving-animation is only started if the new position is within
506 * the same row or column, otherwise the create-animation is used instead.
507 * @return True if the moving-animation has been applied.
509 bool moveWidget(KItemListWidget
*widget
, const QPointF
&newPos
);
511 void emitOffsetChanges();
513 KItemListWidget
*createWidget(int index
);
514 void recycleWidget(KItemListWidget
*widget
);
517 * Changes the index of the widget to \a index and assures a consistent
518 * update for m_visibleItems and m_visibleCells. The cell-information
519 * for the new index will not be updated and be initialized as empty cell.
521 void setWidgetIndex(KItemListWidget
*widget
, int index
);
524 * Changes the index of the widget to \a index. In opposite to
525 * setWidgetIndex() the cell-information for the widget gets updated.
526 * This update gives doLayout() the chance to animate the moving
527 * of the item visually (see moveWidget()).
529 void moveWidgetToIndex(KItemListWidget
*widget
, int index
);
532 * Helper method for prepareLayoutForIncreasedItemCount().
534 void setLayouterSize(const QSizeF
&size
, SizeType sizeType
);
537 * Helper method for createWidget() and setWidgetIndex() to update the properties
538 * of the itemlist widget.
540 void updateWidgetProperties(KItemListWidget
*widget
, int index
);
543 * Helper method for updateWidgetPropertes() to create or update
544 * the itemlist group-header.
546 void updateGroupHeaderForWidget(KItemListWidget
*widget
);
549 * Updates the position and size of the group-header that belongs
550 * to the itemlist widget \a widget. The given widget must represent
551 * the first item of a group.
553 void updateGroupHeaderLayout(KItemListWidget
*widget
);
556 * Recycles the group-header for the widget.
558 void recycleGroupHeaderForWidget(KItemListWidget
*widget
);
561 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
562 * and slotSortRoleChanged(): Iterates through all visible items and updates
563 * the group-header widgets.
565 void updateVisibleGroupHeaders();
568 * @return Index for the item in the list returned by KItemModelBase::groups()
569 * that represents the group where the item with the index \a index
570 * belongs to. -1 is returned if no groups are available.
572 int groupIndexForItem(int index
) const;
575 * Updates the alternate background for all visible items.
576 * @see updateAlternateBackgroundForWidget()
578 void updateAlternateBackgrounds();
581 * Updates the alternateBackground-property of the widget dependent
582 * on the state of useAlternateBackgrounds() and the grouping state.
584 void updateAlternateBackgroundForWidget(KItemListWidget
*widget
);
587 * @return True if alternate backgrounds should be used for the items.
588 * This is the case if an empty item-size is given and if there
589 * is more than one visible role.
591 bool useAlternateBackgrounds() const;
594 * @param itemRanges Items that must be checked for getting the widths of columns.
595 * @return The preferred width of the column of each visible role. The width will
596 * be respected if the width of the item size is <= 0 (see
597 * KItemListView::setItemSize()). Per default an empty hash
600 QHash
<QByteArray
, qreal
> preferredColumnWidths(const KItemRangeList
&itemRanges
) const;
603 * Applies the column-widths from m_headerWidget to the layout
606 void applyColumnWidthsFromHeader();
609 * Applies the column-widths from m_headerWidget to \a widget.
611 void updateWidgetColumnWidths(KItemListWidget
*widget
);
614 * Updates the preferred column-widths of m_groupHeaderWidget by
615 * invoking KItemListView::columnWidths().
617 void updatePreferredColumnWidths(const KItemRangeList
&itemRanges
);
620 * Convenience method for
621 * updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model->count()).
623 void updatePreferredColumnWidths();
626 * Resizes the column-widths of m_headerWidget based on the preferred widths
627 * and the available view-size.
629 void applyAutomaticColumnWidths();
632 * @return Sum of the widths of all columns.
634 qreal
columnWidthsSum() const;
637 * @return Boundaries of the header. An empty rectangle is returned
638 * if no header is shown.
640 QRectF
headerBoundaries() const;
643 * @return True if the number of columns or rows will be changed when applying
644 * the new grid- and item-size. Used to determine whether an animation
645 * should be done when applying the new layout.
647 bool changesItemGridLayout(const QSizeF
&newGridSize
, const QSizeF
&newItemSize
, const QSizeF
&newItemMargin
) const;
650 * @param changedItemCount Number of inserted or removed items.
651 * @return True if the inserting or removing of items should be animated.
652 * No animation should be done if the number of items is too large
653 * to provide a pleasant animation.
655 bool animateChangedItemCount(int changedItemCount
) const;
658 * @return True if a scrollbar for the given scroll-orientation is required
659 * when using a size of \p size for the view. Calling the method is rather
660 * expansive as a temporary relayout needs to be done.
662 bool scrollBarRequired(const QSizeF
&size
) const;
665 * Shows a drop-indicator between items dependent on the given
666 * cursor position. The cursor position is relative to the upper left
668 * @return Index of the item where the dropping is done. An index of -1
669 * indicates that the item has been dropped after the last item.
671 int showDropIndicator(const QPointF
&pos
);
672 void hideDropIndicator();
675 * Applies the height of the group header to the layouter. The height
676 * depends on the used scroll orientation.
678 void updateGroupHeaderHeight();
681 * Updates the siblings-information for all visible items that are inside
682 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
683 * is smaller than 0, the siblings-information for all visible items gets
685 * @see KItemListWidget::setSiblingsInformation()
687 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
690 * Helper method for updateExpansionIndicators().
691 * @return True if the item with the index \a index has a sibling successor
692 * (= the item is not the last item of the current hierarchy).
694 bool hasSiblingSuccessor(int index
) const;
697 * Helper method for slotRoleEditingCanceled() and slotRoleEditingFinished().
698 * Disconnects the two Signals "roleEditingCanceled" and
699 * "roleEditingFinished"
701 void disconnectRoleEditingSignals(int index
);
704 * Helper function for triggerAutoScrolling().
705 * @param pos Logical position of the mouse relative to the range.
706 * @param range Range of the visible area.
707 * @param oldInc Previous increment. Is used to assure that the increment
708 * increases only gradually.
709 * @return Scroll increment that should be added to the offset().
710 * As soon as \a pos is inside the autoscroll-margin a
711 * value != 0 will be returned.
713 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
716 * Helper functions for changesItemCount().
717 * @return The number of items that fit into the available size by
718 * respecting the size of the item and the margin between the items.
720 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
723 bool m_enabledSelectionToggles
;
725 bool m_highlightEntireRow
;
726 bool m_alternateBackgrounds
;
727 bool m_supportsItemExpanding
;
729 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
730 LayoutAnimationHint m_endTransactionAnimationHint
;
733 KItemListController
*m_controller
;
734 KItemModelBase
*m_model
;
735 QList
<QByteArray
> m_visibleRoles
;
736 mutable KItemListWidgetCreatorBase
*m_widgetCreator
;
737 mutable KItemListGroupHeaderCreatorBase
*m_groupHeaderCreator
;
738 #ifndef QT_NO_ACCESSIBILITY
739 /** The object that will be the parent of this classes QAccessibleInterface. */
740 KItemListContainerAccessible
*m_accessibleParent
= nullptr;
742 KItemListStyleOption m_styleOption
;
744 QHash
<int, KItemListWidget
*> m_visibleItems
;
745 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
761 QHash
<int, Cell
> m_visibleCells
;
763 int m_scrollBarExtent
;
764 KItemListViewLayouter
*m_layouter
;
765 KItemListViewAnimation
*m_animation
;
767 qreal m_oldScrollOffset
;
768 qreal m_oldMaximumScrollOffset
;
769 qreal m_oldItemOffset
;
770 qreal m_oldMaximumItemOffset
;
772 bool m_skipAutoScrollForRubberBand
;
773 KItemListRubberBand
*m_rubberBand
;
774 KItemListRubberBand
*m_tapAndHoldIndicator
;
777 int m_autoScrollIncrement
;
778 QTimer
*m_autoScrollTimer
;
780 KItemListHeader
*m_header
;
781 KItemListHeaderWidget
*m_headerWidget
;
783 QPropertyAnimation
*m_indicatorAnimation
;
785 int m_statusBarOffset
;
787 // When dragging items into the view where the sort-role of the model
788 // is empty, a visual indicator should be shown during dragging where
789 // the dropping will happen. This indicator is specified by an index
790 // of the item. -1 means that no indicator will be shown at all.
791 // The m_dropIndicator is set by the KItemListController
792 // by KItemListView::showDropIndicator() and KItemListView::hideDropIndicator().
793 QRectF m_dropIndicator
;
795 QList
<QVariantAnimation
*> m_rubberBandAnimations
;
797 KItemListSizeHintResolver
*m_sizeHintResolver
;
799 friend class KItemListContainer
; // Accesses scrollBarRequired()
800 friend class KItemListHeader
; // Accesses m_headerWidget
801 friend class KItemListController
;
802 friend class KItemListControllerTest
;
803 friend class KItemListViewAccessible
;
804 friend class KItemListDelegateAccessible
;
806 friend class DolphinMainWindowTest
;
810 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
811 * by recycling existing QGraphicsWidgets instances. Is used by
812 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
815 class DOLPHIN_EXPORT KItemListCreatorBase
818 virtual ~KItemListCreatorBase();
821 void addCreatedWidget(QGraphicsWidget
*widget
);
822 void pushRecycleableWidget(QGraphicsWidget
*widget
);
823 QGraphicsWidget
*popRecycleableWidget();
826 QSet
<QGraphicsWidget
*> m_createdWidgets
;
827 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
831 * @brief Base class for creating KItemListWidgets.
833 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
834 * For a custom implementation the methods create(), itemSizeHint() and preferredColumnWith()
835 * must be reimplemented. The intention of the widget creator is to prevent repetitive and
836 * expensive instantiations and deletions of KItemListWidgets by recycling existing widget
839 class DOLPHIN_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
842 ~KItemListWidgetCreatorBase() override
;
844 virtual KItemListWidget
*create(KItemListView
*view
) = 0;
846 virtual void recycle(KItemListWidget
*widget
);
848 virtual void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>> &logicalHeightHints
, qreal
&logicalWidthHint
, const KItemListView
*view
) const = 0;
850 virtual qreal
preferredRoleColumnWidth(const QByteArray
&role
, int index
, const KItemListView
*view
) const = 0;
854 * @brief Template class for creating KItemListWidgets.
857 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
860 KItemListWidgetCreator();
861 ~KItemListWidgetCreator() override
;
863 KItemListWidget
*create(KItemListView
*view
) override
;
865 void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>> &logicalHeightHints
, qreal
&logicalWidthHint
, const KItemListView
*view
) const override
;
867 qreal
preferredRoleColumnWidth(const QByteArray
&role
, int index
, const KItemListView
*view
) const override
;
870 KItemListWidgetInformant
*m_informant
;
874 KItemListWidgetCreator
<T
>::KItemListWidgetCreator()
875 : m_informant(T::createInformant())
880 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
886 KItemListWidget
*KItemListWidgetCreator
<T
>::create(KItemListView
*view
)
888 KItemListWidget
*widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
890 widget
= new T(m_informant
, view
);
891 addCreatedWidget(widget
);
893 widget
->setParentItem(view
);
898 void KItemListWidgetCreator
<T
>::calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>> &logicalHeightHints
,
899 qreal
&logicalWidthHint
,
900 const KItemListView
*view
) const
902 return m_informant
->calculateItemSizeHints(logicalHeightHints
, logicalWidthHint
, view
);
906 qreal KItemListWidgetCreator
<T
>::preferredRoleColumnWidth(const QByteArray
&role
, int index
, const KItemListView
*view
) const
908 return m_informant
->preferredRoleColumnWidth(role
, index
, view
);
912 * @brief Base class for creating KItemListGroupHeaders.
914 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
915 * For a custom implementation the methods create() and recycle() must be reimplemented.
916 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
917 * deletions of KItemListGroupHeaders by recycling existing header instances.
919 class DOLPHIN_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
922 ~KItemListGroupHeaderCreatorBase() override
;
923 virtual KItemListGroupHeader
*create(KItemListView
*view
) = 0;
924 virtual void recycle(KItemListGroupHeader
*header
);
928 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
931 ~KItemListGroupHeaderCreator() override
;
932 KItemListGroupHeader
*create(KItemListView
*view
) override
;
936 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
941 KItemListGroupHeader
*KItemListGroupHeaderCreator
<T
>::create(KItemListView
*view
)
943 KItemListGroupHeader
*widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
945 widget
= new T(view
);
946 addCreatedWidget(widget
);