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 The line step which should be used for the scroll by mouse wheel.
181 virtual qreal
scrollSingleStep() const;
184 * @return Index of the item that is below the point \a pos.
185 * The position is relative to the upper right of
186 * the visible area. Only (at least partly) visible
187 * items are considered. std::nullopt is returned if
188 * no item is below the position.
190 std::optional
<int> itemAt(const QPointF
&pos
) const;
191 bool isAboveSelectionToggle(int index
, const QPointF
&pos
) const;
192 bool isAboveExpansionToggle(int index
, const QPointF
&pos
) const;
193 bool isAboveText(int index
, const QPointF
&pos
) const;
196 * @return Index of the first item that is at least partly visible.
197 * -1 is returned if the model contains no items.
199 int firstVisibleIndex() const;
202 * @return Index of the last item that is at least partly visible.
203 * -1 is returned if the model contains no items.
205 int lastVisibleIndex() const;
208 * Calculates the required size for all items in the model.
209 * It might be larger than KItemListView::itemSize().
210 * In this case the layout grid will be stretched to assure an
213 * @note the logical height (width) is actually the
214 * width (height) if the scroll orientation is Qt::Vertical!
216 void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>> &logicalHeightHints
, qreal
&logicalWidthHint
) const;
219 * If set to true, items having child-items can be expanded to show the child-items as
220 * part of the view. Per default the expanding of items is disabled. If expanding of
221 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
222 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
223 * must be reimplemented. The view-implementation
224 * has to take care itself how to visually represent the expanded items provided
227 void setSupportsItemExpanding(bool supportsExpanding
);
228 bool supportsItemExpanding() const;
230 void setHighlightEntireRow(bool highlightEntireRow
);
231 bool highlightEntireRow() const;
233 void setAlternateBackgrounds(bool alternate
);
234 bool alternateBackgrounds() const;
237 * @return The rectangle of the item relative to the top/left of
238 * the currently visible area (see KItemListView::offset()).
240 QRectF
itemRect(int index
) const;
243 * @return The context rectangle of the item relative to the top/left of
244 * the currently visible area (see KItemListView::offset()). The
245 * context rectangle is defined by the united rectangle of
246 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
247 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
248 * a tooltip or a context-menu for an item. Note that a context rectangle will
249 * only be returned for (at least partly) visible items. An empty rectangle will
250 * be returned for fully invisible items.
252 QRectF
itemContextRect(int index
) const;
255 * @return Whether or not the name of the file has been elided. At present this will
256 * only ever be true when in icons view.
258 bool isElided(int index
) const;
261 * Scrolls to the item with the index \a index so that the item
262 * will be fully visible. The item is positioned within the view
263 * as specified by \a viewItemPosition.
265 void scrollToItem(int index
, ViewItemPosition viewItemPosition
= ViewItemPosition::Nearest
);
268 * If several properties of KItemListView are changed synchronously, it is
269 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
270 * This prevents unnecessary and expensive layout-calculations.
272 void beginTransaction();
275 * Counterpart to beginTransaction(). The layout changes will only be animated if
276 * all property changes between beginTransaction() and endTransaction() support
279 void endTransaction();
281 bool isTransactionActive() const;
284 * Turns on the header if \p visible is true. Per default the
285 * header is not visible. Usually the header is turned on when
286 * showing a classic "table-view" to describe the shown columns.
288 void setHeaderVisible(bool visible
);
289 bool isHeaderVisible() const;
292 * @return Header of the list. The header is also available if it is not shown
293 * (see KItemListView::setHeaderShown()).
295 KItemListHeader
*header() const;
298 * @return Pixmap that is used for a drag operation based on the
299 * items given by \a indexes.
301 virtual QPixmap
createDragPixmap(const KItemSet
&indexes
) const;
304 * Lets the user edit the role \a role for item with the index \a index.
306 void editRole(int index
, const QByteArray
&role
);
308 void paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
, QWidget
*widget
= nullptr) override
;
311 * Set the bottom offset for moving the view so that the small overlayed statusbar
312 * won't cover any items by accident.
314 void setStatusBarOffset(int offset
);
317 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
318 void scrollOffsetChanged(qreal current
, qreal previous
);
319 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
320 void itemOffsetChanged(qreal current
, qreal previous
);
321 void maximumItemOffsetChanged(qreal current
, qreal previous
);
322 void scrollTo(qreal newOffset
);
325 * Is emitted if the user has changed the sort order by clicking on a
326 * header item (see KItemListView::setHeaderShown()). The sort order
327 * of the model has already been adjusted to
328 * the current sort order. Note that no signal will be emitted if the
329 * sort order of the model has been changed without user interaction.
331 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
334 * Is emitted if the user has changed the sort role by clicking on a
335 * header item (see KItemListView::setHeaderShown()). The sort role
336 * of the model has already been adjusted to
337 * the current sort role. Note that no signal will be emitted if the
338 * sort role of the model has been changed without user interaction.
340 void sortRoleChanged(const QByteArray
¤t
, const QByteArray
&previous
);
343 * Is emitted if the user has changed the visible roles by moving a header
344 * item (see KItemListView::setHeaderShown()). Note that no signal will be
345 * emitted if the roles have been changed without user interaction by
346 * KItemListView::setVisibleRoles().
348 void visibleRolesChanged(const QList
<QByteArray
> ¤t
, const QList
<QByteArray
> &previous
);
350 void roleEditingCanceled(int index
, const QByteArray
&role
, const QVariant
&value
);
351 void roleEditingFinished(int index
, const QByteArray
&role
, const QVariant
&value
);
354 * Emitted once scrolling has finished, or immediately if no scrolling was necessary
355 * to get item in view in scrollToItem.
357 void scrollingStopped();
359 void columnHovered(int roleIndex
);
360 void columnUnHovered(int roleIndex
);
363 QVariant
itemChange(GraphicsItemChange change
, const QVariant
&value
) override
;
364 void setItemSize(const QSizeF
&size
);
365 void setStyleOption(const KItemListStyleOption
&option
);
368 * If the scroll-orientation is vertical, the items are ordered
369 * from top to bottom (= default setting). If the scroll-orientation
370 * is horizontal, the items are ordered from left to right.
372 void setScrollOrientation(Qt::Orientation orientation
);
373 Qt::Orientation
scrollOrientation() const;
376 * Factory method for creating a default widget-creator. The method will be used
377 * in case if setWidgetCreator() has not been set by the application.
378 * @return New instance of the widget-creator that should be used per
381 virtual KItemListWidgetCreatorBase
*defaultWidgetCreator() const;
384 * Factory method for creating a default group-header-creator. The method will be used
385 * in case if setGroupHeaderCreator() has not been set by the application.
386 * @return New instance of the group-header-creator that should be used per
389 virtual KItemListGroupHeaderCreatorBase
*defaultGroupHeaderCreator() const;
392 * Is called when creating a new KItemListWidget instance and allows derived
393 * classes to do a custom initialization.
395 virtual void initializeItemListWidget(KItemListWidget
*item
);
398 * @return True if at least one of the changed roles \p changedRoles might result
399 * in the need to update the item-size hint (see KItemListView::itemSizeHint()).
400 * Per default true is returned which means on each role-change of existing items
401 * the item-size hints are recalculated. For performance reasons it is recommended
402 * to return false in case if a role-change will not result in a changed
405 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
> &changedRoles
) const;
407 virtual void onControllerChanged(KItemListController
*current
, KItemListController
*previous
);
408 virtual void onModelChanged(KItemModelBase
*current
, KItemModelBase
*previous
);
410 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
411 virtual void onItemSizeChanged(const QSizeF
¤t
, const QSizeF
&previous
);
412 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
413 virtual void onVisibleRolesChanged(const QList
<QByteArray
> ¤t
, const QList
<QByteArray
> &previous
);
414 virtual void onStyleOptionChanged(const KItemListStyleOption
¤t
, const KItemListStyleOption
&previous
);
415 virtual void onHighlightEntireRowChanged(bool highlightEntireRow
);
416 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
418 virtual void onTransactionBegin();
419 virtual void onTransactionEnd();
421 bool event(QEvent
*event
) override
;
422 void mousePressEvent(QGraphicsSceneMouseEvent
*event
) override
;
423 void mouseMoveEvent(QGraphicsSceneMouseEvent
*event
) override
;
424 void dragEnterEvent(QGraphicsSceneDragDropEvent
*event
) override
;
425 void dragMoveEvent(QGraphicsSceneDragDropEvent
*event
) override
;
426 void dragLeaveEvent(QGraphicsSceneDragDropEvent
*event
) override
;
427 void dropEvent(QGraphicsSceneDragDropEvent
*event
) override
;
429 QList
<KItemListWidget
*> visibleItemListWidgets() const;
431 virtual void updateFont();
432 virtual void updatePalette();
435 virtual void slotItemsInserted(const KItemRangeList
&itemRanges
);
436 virtual void slotItemsRemoved(const KItemRangeList
&itemRanges
);
437 virtual void slotItemsMoved(const KItemRange
&itemRange
, const QList
<int> &movedToIndexes
);
438 virtual void slotItemsChanged(const KItemRangeList
&itemRanges
, const QSet
<QByteArray
> &roles
);
439 virtual void slotGroupsChanged();
441 virtual void slotGroupedSortingChanged(bool current
);
442 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
443 virtual void slotSortRoleChanged(const QByteArray
¤t
, const QByteArray
&previous
);
444 virtual void slotCurrentChanged(int current
, int previous
);
445 virtual void slotSelectionChanged(const KItemSet
¤t
, const KItemSet
&previous
);
448 void slotAnimationFinished(QGraphicsWidget
*widget
, KItemListViewAnimation::AnimationType type
);
450 void slotRubberBandPosChanged();
451 void slotRubberBandActivationChanged(bool active
);
454 * Is invoked if the column-width of one role in the header has
455 * been changed by the user. The automatic resizing of columns
456 * will be turned off as soon as this method has been called at
459 void slotHeaderColumnWidthChanged(const QByteArray
&role
, qreal currentWidth
, qreal previousWidth
);
461 void slotSidePaddingChanged(qreal width
);
464 * Is invoked if a column has been moved by the user. Applies
465 * the moved role to the view.
467 void slotHeaderColumnMoved(const QByteArray
&role
, int currentIndex
, int previousIndex
);
470 * Triggers the autoscrolling if autoScroll() is enabled by checking the
471 * current mouse position. If the mouse position is within the autoscroll
472 * margins a timer will be started that periodically triggers the autoscrolling.
474 void triggerAutoScrolling();
477 * Is invoked if the geometry of the parent-widget from a group-header has been
478 * changed. The x-position and width of the group-header gets adjusted to assure
479 * that it always spans the whole width even during temporary transitions of the
482 void slotGeometryOfGroupHeaderParentChanged();
484 void slotRoleEditingCanceled(int index
, const QByteArray
&role
, const QVariant
&value
);
485 void slotRoleEditingFinished(int index
, const QByteArray
&role
, const QVariant
&value
);
488 enum LayoutAnimationHint
{ NoAnimation
, Animation
};
490 enum SizeType
{ LayouterSize
, ItemSize
};
492 void setController(KItemListController
*controller
);
493 void setModel(KItemModelBase
*model
);
495 KItemListRubberBand
*rubberBand() const;
497 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
500 * Helper method for doLayout: Returns a list of items that can be reused for the visible
501 * area. Invisible group headers get recycled. The reusable items are items that are
502 * invisible. If the animation hint is 'Animation' then items that are currently animated
503 * won't be reused. Reusing items is faster in comparison to deleting invisible
504 * items and creating a new instance for visible items.
506 QList
<int> recycleInvisibleItems(int firstVisibleIndex
, int lastVisibleIndex
, LayoutAnimationHint hint
);
509 * Helper method for doLayout: Starts a moving-animation for the widget to the given
510 * new position. The moving-animation is only started if the new position is within
511 * the same row or column, otherwise the create-animation is used instead.
512 * @return True if the moving-animation has been applied.
514 bool moveWidget(KItemListWidget
*widget
, const QPointF
&newPos
);
516 void emitOffsetChanges();
518 KItemListWidget
*createWidget(int index
);
519 void recycleWidget(KItemListWidget
*widget
);
522 * Changes the index of the widget to \a index and assures a consistent
523 * update for m_visibleItems and m_visibleCells. The cell-information
524 * for the new index will not be updated and be initialized as empty cell.
526 void setWidgetIndex(KItemListWidget
*widget
, int index
);
529 * Changes the index of the widget to \a index. In opposite to
530 * setWidgetIndex() the cell-information for the widget gets updated.
531 * This update gives doLayout() the chance to animate the moving
532 * of the item visually (see moveWidget()).
534 void moveWidgetToIndex(KItemListWidget
*widget
, int index
);
537 * Helper method for prepareLayoutForIncreasedItemCount().
539 void setLayouterSize(const QSizeF
&size
, SizeType sizeType
);
542 * Helper method for createWidget() and setWidgetIndex() to update the properties
543 * of the itemlist widget.
545 void updateWidgetProperties(KItemListWidget
*widget
, int index
);
548 * Helper method for updateWidgetPropertes() to create or update
549 * the itemlist group-header.
551 void updateGroupHeaderForWidget(KItemListWidget
*widget
);
554 * Updates the position and size of the group-header that belongs
555 * to the itemlist widget \a widget. The given widget must represent
556 * the first item of a group.
558 void updateGroupHeaderLayout(KItemListWidget
*widget
);
561 * Recycles the group-header for the widget.
563 void recycleGroupHeaderForWidget(KItemListWidget
*widget
);
566 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
567 * and slotSortRoleChanged(): Iterates through all visible items and updates
568 * the group-header widgets.
570 void updateVisibleGroupHeaders();
573 * @return Index for the item in the list returned by KItemModelBase::groups()
574 * that represents the group where the item with the index \a index
575 * belongs to. -1 is returned if no groups are available.
577 int groupIndexForItem(int index
) const;
580 * Updates the alternate background for all visible items.
581 * @see updateAlternateBackgroundForWidget()
583 void updateAlternateBackgrounds();
586 * Updates the alternateBackground-property of the widget dependent
587 * on the state of useAlternateBackgrounds() and the grouping state.
589 void updateAlternateBackgroundForWidget(KItemListWidget
*widget
);
592 * @return True if alternate backgrounds should be used for the items.
593 * This is the case if an empty item-size is given and if there
594 * is more than one visible role.
596 bool useAlternateBackgrounds() const;
599 * @param itemRanges Items that must be checked for getting the widths of columns.
600 * @return The preferred width of the column of each visible role. The width will
601 * be respected if the width of the item size is <= 0 (see
602 * KItemListView::setItemSize()). Per default an empty hash
605 QHash
<QByteArray
, qreal
> preferredColumnWidths(const KItemRangeList
&itemRanges
) const;
608 * Applies the column-widths from m_headerWidget to the layout
611 void applyColumnWidthsFromHeader();
614 * Applies the column-widths from m_headerWidget to \a widget.
616 void updateWidgetColumnWidths(KItemListWidget
*widget
);
619 * Updates the preferred column-widths of m_groupHeaderWidget by
620 * invoking KItemListView::columnWidths().
622 void updatePreferredColumnWidths(const KItemRangeList
&itemRanges
);
625 * Convenience method for
626 * updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model->count()).
628 void updatePreferredColumnWidths();
631 * Resizes the column-widths of m_headerWidget based on the preferred widths
632 * and the available view-size.
634 void applyAutomaticColumnWidths();
637 * @return Sum of the widths of all columns.
639 qreal
columnWidthsSum() const;
642 * @return Boundaries of the header. An empty rectangle is returned
643 * if no header is shown.
645 QRectF
headerBoundaries() const;
648 * @return True if the number of columns or rows will be changed when applying
649 * the new grid- and item-size. Used to determine whether an animation
650 * should be done when applying the new layout.
652 bool changesItemGridLayout(const QSizeF
&newGridSize
, const QSizeF
&newItemSize
, const QSizeF
&newItemMargin
) const;
655 * @param changedItemCount Number of inserted or removed items.
656 * @return True if the inserting or removing of items should be animated.
657 * No animation should be done if the number of items is too large
658 * to provide a pleasant animation.
660 bool animateChangedItemCount(int changedItemCount
) const;
663 * @return True if a scrollbar for the given scroll-orientation is required
664 * when using a size of \p size for the view. Calling the method is rather
665 * expansive as a temporary relayout needs to be done.
667 bool scrollBarRequired(const QSizeF
&size
) const;
670 * Shows a drop-indicator between items dependent on the given
671 * cursor position. The cursor position is relative to the upper left
673 * @return Index of the item where the dropping is done. An index of -1
674 * indicates that the item has been dropped after the last item.
676 int showDropIndicator(const QPointF
&pos
);
677 void hideDropIndicator();
680 * Applies the height of the group header to the layouter. The height
681 * depends on the used scroll orientation.
683 void updateGroupHeaderHeight();
686 * Updates the siblings-information for all visible items that are inside
687 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
688 * is smaller than 0, the siblings-information for all visible items gets
690 * @see KItemListWidget::setSiblingsInformation()
692 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
695 * Helper method for updateExpansionIndicators().
696 * @return True if the item with the index \a index has a sibling successor
697 * (= the item is not the last item of the current hierarchy).
699 bool hasSiblingSuccessor(int index
) const;
702 * Helper method for slotRoleEditingCanceled() and slotRoleEditingFinished().
703 * Disconnects the two Signals "roleEditingCanceled" and
704 * "roleEditingFinished"
706 void disconnectRoleEditingSignals(int index
);
709 * Helper function for triggerAutoScrolling().
710 * @param pos Logical position of the mouse relative to the range.
711 * @param range Range of the visible area.
712 * @param oldInc Previous increment. Is used to assure that the increment
713 * increases only gradually.
714 * @return Scroll increment that should be added to the offset().
715 * As soon as \a pos is inside the autoscroll-margin a
716 * value != 0 will be returned.
718 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
721 * Helper functions for changesItemCount().
722 * @return The number of items that fit into the available size by
723 * respecting the size of the item and the margin between the items.
725 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
728 bool m_enabledSelectionToggles
;
730 bool m_highlightEntireRow
;
731 bool m_alternateBackgrounds
;
732 bool m_supportsItemExpanding
;
734 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
735 LayoutAnimationHint m_endTransactionAnimationHint
;
738 KItemListController
*m_controller
;
739 KItemModelBase
*m_model
;
740 QList
<QByteArray
> m_visibleRoles
;
741 mutable KItemListWidgetCreatorBase
*m_widgetCreator
;
742 mutable KItemListGroupHeaderCreatorBase
*m_groupHeaderCreator
;
743 #ifndef QT_NO_ACCESSIBILITY
744 /** The object that will be the parent of this classes QAccessibleInterface. */
745 KItemListContainerAccessible
*m_accessibleParent
= nullptr;
747 KItemListStyleOption m_styleOption
;
749 QHash
<int, KItemListWidget
*> m_visibleItems
;
750 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
766 QHash
<int, Cell
> m_visibleCells
;
768 int m_scrollBarExtent
;
769 KItemListViewLayouter
*m_layouter
;
770 KItemListViewAnimation
*m_animation
;
772 qreal m_oldScrollOffset
;
773 qreal m_oldMaximumScrollOffset
;
774 qreal m_oldItemOffset
;
775 qreal m_oldMaximumItemOffset
;
777 bool m_skipAutoScrollForRubberBand
;
778 KItemListRubberBand
*m_rubberBand
;
779 KItemListRubberBand
*m_tapAndHoldIndicator
;
782 int m_autoScrollIncrement
;
783 QTimer
*m_autoScrollTimer
;
785 KItemListHeader
*m_header
;
786 KItemListHeaderWidget
*m_headerWidget
;
788 QPropertyAnimation
*m_indicatorAnimation
;
790 int m_statusBarOffset
;
792 // When dragging items into the view where the sort-role of the model
793 // is empty, a visual indicator should be shown during dragging where
794 // the dropping will happen. This indicator is specified by an index
795 // of the item. -1 means that no indicator will be shown at all.
796 // The m_dropIndicator is set by the KItemListController
797 // by KItemListView::showDropIndicator() and KItemListView::hideDropIndicator().
798 QRectF m_dropIndicator
;
800 QList
<QVariantAnimation
*> m_rubberBandAnimations
;
802 KItemListSizeHintResolver
*m_sizeHintResolver
;
804 friend class KItemListContainer
; // Accesses scrollBarRequired()
805 friend class KItemListHeader
; // Accesses m_headerWidget
806 friend class KItemListController
;
807 friend class KItemListControllerTest
;
808 friend class KItemListViewAccessible
;
809 friend class KItemListDelegateAccessible
;
811 friend class DolphinMainWindowTest
;
815 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
816 * by recycling existing QGraphicsWidgets instances. Is used by
817 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
820 class DOLPHIN_EXPORT KItemListCreatorBase
823 virtual ~KItemListCreatorBase();
826 void addCreatedWidget(QGraphicsWidget
*widget
);
827 void pushRecycleableWidget(QGraphicsWidget
*widget
);
828 QGraphicsWidget
*popRecycleableWidget();
831 QSet
<QGraphicsWidget
*> m_createdWidgets
;
832 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
836 * @brief Base class for creating KItemListWidgets.
838 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
839 * For a custom implementation the methods create(), itemSizeHint() and preferredColumnWith()
840 * must be reimplemented. The intention of the widget creator is to prevent repetitive and
841 * expensive instantiations and deletions of KItemListWidgets by recycling existing widget
844 class DOLPHIN_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
847 ~KItemListWidgetCreatorBase() override
;
849 virtual KItemListWidget
*create(KItemListView
*view
) = 0;
851 virtual void recycle(KItemListWidget
*widget
);
853 virtual void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>> &logicalHeightHints
, qreal
&logicalWidthHint
, const KItemListView
*view
) const = 0;
855 virtual qreal
preferredRoleColumnWidth(const QByteArray
&role
, int index
, const KItemListView
*view
) const = 0;
859 * @brief Template class for creating KItemListWidgets.
862 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
865 KItemListWidgetCreator();
866 ~KItemListWidgetCreator() override
;
868 KItemListWidget
*create(KItemListView
*view
) override
;
870 void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>> &logicalHeightHints
, qreal
&logicalWidthHint
, const KItemListView
*view
) const override
;
872 qreal
preferredRoleColumnWidth(const QByteArray
&role
, int index
, const KItemListView
*view
) const override
;
875 KItemListWidgetInformant
*m_informant
;
879 KItemListWidgetCreator
<T
>::KItemListWidgetCreator()
880 : m_informant(T::createInformant())
885 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
891 KItemListWidget
*KItemListWidgetCreator
<T
>::create(KItemListView
*view
)
893 KItemListWidget
*widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
895 widget
= new T(m_informant
, view
);
896 addCreatedWidget(widget
);
898 widget
->setParentItem(view
);
903 void KItemListWidgetCreator
<T
>::calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>> &logicalHeightHints
,
904 qreal
&logicalWidthHint
,
905 const KItemListView
*view
) const
907 return m_informant
->calculateItemSizeHints(logicalHeightHints
, logicalWidthHint
, view
);
911 qreal KItemListWidgetCreator
<T
>::preferredRoleColumnWidth(const QByteArray
&role
, int index
, const KItemListView
*view
) const
913 return m_informant
->preferredRoleColumnWidth(role
, index
, view
);
917 * @brief Base class for creating KItemListGroupHeaders.
919 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
920 * For a custom implementation the methods create() and recycle() must be reimplemented.
921 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
922 * deletions of KItemListGroupHeaders by recycling existing header instances.
924 class DOLPHIN_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
927 ~KItemListGroupHeaderCreatorBase() override
;
928 virtual KItemListGroupHeader
*create(KItemListView
*view
) = 0;
929 virtual void recycle(KItemListGroupHeader
*header
);
933 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
936 ~KItemListGroupHeaderCreator() override
;
937 KItemListGroupHeader
*create(KItemListView
*view
) override
;
941 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
946 KItemListGroupHeader
*KItemListGroupHeaderCreator
<T
>::create(KItemListView
*view
)
948 KItemListGroupHeader
*widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
950 widget
= new T(view
);
951 addCreatedWidget(widget
);