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 KItemListController
;
25 class KItemListGroupHeaderCreatorBase
;
26 class KItemListHeader
;
27 class KItemListHeaderWidget
;
28 class KItemListSizeHintResolver
;
29 class KItemListRubberBand
;
30 class KItemListViewAnimation
;
31 class KItemListViewLayouter
;
32 class KItemListWidget
;
33 class KItemListWidgetInformant
;
34 class KItemListWidgetCreatorBase
;
36 class QPropertyAnimation
;
37 class QVariantAnimation
;
40 * @brief Represents the view of an item-list.
42 * The view is responsible for showing the items of the model within
43 * a GraphicsItem. Each visible item is represented by a KItemListWidget.
45 * The created view must be applied to the KItemListController with
46 * KItemListController::setView() or with the constructor of
47 * KItemListController.
49 * @see KItemListWidget
52 class DOLPHIN_EXPORT KItemListView
: public QGraphicsWidget
56 Q_PROPERTY(qreal scrollOffset READ scrollOffset WRITE setScrollOffset
)
57 Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset
)
60 explicit KItemListView(QGraphicsWidget
* parent
= nullptr);
61 ~KItemListView() override
;
64 * Offset of the scrollbar that represents the scroll-orientation
65 * (see setScrollOrientation()).
67 void setScrollOffset(qreal offset
);
68 qreal
scrollOffset() const;
70 qreal
maximumScrollOffset() const;
73 * Offset related to an item, that does not fit into the available
74 * size of the listview. If the scroll-orientation is vertical
75 * the item-offset describes the offset of the horizontal axe, if
76 * the scroll-orientation is horizontal the item-offset describes
77 * the offset of the vertical axe.
79 void setItemOffset(qreal scrollOffset
);
80 qreal
itemOffset() const;
82 qreal
maximumItemOffset() const;
84 int maximumVisibleItems() const;
86 void setVisibleRoles(const QList
<QByteArray
>& roles
);
87 QList
<QByteArray
> visibleRoles() const;
90 * If set to true an automatic scrolling is done as soon as the
91 * mouse is moved near the borders of the view. Per default
92 * the automatic scrolling is turned off.
94 void setAutoScroll(bool enabled
);
95 bool autoScroll() const;
98 * If set to true selection-toggles will be shown when hovering
99 * an item. Per default the selection-toggles are disabled.
101 void setEnabledSelectionToggles(bool enabled
);
102 bool enabledSelectionToggles() const;
105 * @return Controller of the item-list. The controller gets
106 * initialized by KItemListController::setView() and will
107 * result in calling KItemListController::onControllerChanged().
109 KItemListController
* controller() const;
112 * @return Model of the item-list. The model gets
113 * initialized by KItemListController::setModel() and will
114 * result in calling KItemListController::onModelChanged().
116 KItemModelBase
* model() const;
119 * Sets the creator that creates a widget showing the
120 * content of one model-item. Usually it is sufficient
121 * to implement a custom widget X derived from KItemListWidget and
122 * set the creator by:
124 * itemListView->setWidgetCreator(new KItemListWidgetCreator<X>());
126 * The ownership of the widget creator is transferred to
127 * the item-list view.
129 void setWidgetCreator(KItemListWidgetCreatorBase
* widgetCreator
);
130 KItemListWidgetCreatorBase
* widgetCreator() const;
133 * Sets the creator that creates a group header. Usually it is sufficient
134 * to implement a custom header widget X derived from KItemListGroupHeader and
135 * set the creator by:
137 * itemListView->setGroupHeaderCreator(new KItemListGroupHeaderCreator<X>());
139 * The ownership of the gropup header creator is transferred to
140 * the item-list view.
142 void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
* groupHeaderCreator
);
143 KItemListGroupHeaderCreatorBase
* groupHeaderCreator() const;
146 * @return The basic size of all items. The size of an item may be larger than
147 * the basic size (see KItemListView::itemRect()).
149 QSizeF
itemSize() const;
151 const KItemListStyleOption
& styleOption() const;
153 void setGeometry(const QRectF
& rect
) override
;
156 * @return The page step which should be used by the vertical scroll bar.
157 * This is the height of the view except for the header widget.
159 qreal
verticalPageStep() const;
162 * @return Index of the item that is below the point \a pos.
163 * The position is relative to the upper right of
164 * the visible area. Only (at least partly) visible
165 * items are considered. std::nullopt is returned if
166 * no item is below the position.
168 std::optional
<int> itemAt(const QPointF
& pos
) const;
169 bool isAboveSelectionToggle(int index
, const QPointF
& pos
) const;
170 bool isAboveExpansionToggle(int index
, const QPointF
& pos
) const;
171 bool isAboveText(int index
, const QPointF
& pos
) const;
174 * @return Index of the first item that is at least partly visible.
175 * -1 is returned if the model contains no items.
177 int firstVisibleIndex() const;
180 * @return Index of the last item that is at least partly visible.
181 * -1 is returned if the model contains no items.
183 int lastVisibleIndex() const;
186 * Calculates the required size for all items in the model.
187 * It might be larger than KItemListView::itemSize().
188 * In this case the layout grid will be stretched to assure an
191 * @note the logical height (width) is actually the
192 * width (height) if the scroll orientation is Qt::Vertical!
194 void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>>& logicalHeightHints
, qreal
& logicalWidthHint
) const;
197 * If set to true, items having child-items can be expanded to show the child-items as
198 * part of the view. Per default the expanding of items is disabled. If expanding of
199 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
200 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
201 * must be reimplemented. The view-implementation
202 * has to take care itself how to visually represent the expanded items provided
205 void setSupportsItemExpanding(bool supportsExpanding
);
206 bool supportsItemExpanding() const;
209 * @return The rectangle of the item relative to the top/left of
210 * the currently visible area (see KItemListView::offset()).
212 QRectF
itemRect(int index
) const;
215 * @return The context rectangle of the item relative to the top/left of
216 * the currently visible area (see KItemListView::offset()). The
217 * context rectangle is defined by the united rectangle of
218 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
219 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
220 * a tooltip or a context-menu for an item. Note that a context rectangle will
221 * only be returned for (at least partly) visible items. An empty rectangle will
222 * be returned for fully invisible items.
224 QRectF
itemContextRect(int index
) const;
227 * @return Whether or not the name of the file has been elided. At present this will
228 * only ever be true when in icons view.
230 bool isElided(int index
) const;
233 * Scrolls to the item with the index \a index so that the item
234 * will be fully visible.
236 void scrollToItem(int index
);
239 * If several properties of KItemListView are changed synchronously, it is
240 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
241 * This prevents unnecessary and expensive layout-calculations.
243 void beginTransaction();
246 * Counterpart to beginTransaction(). The layout changes will only be animated if
247 * all property changes between beginTransaction() and endTransaction() support
250 void endTransaction();
252 bool isTransactionActive() const;
255 * Turns on the header if \p visible is true. Per default the
256 * header is not visible. Usually the header is turned on when
257 * showing a classic "table-view" to describe the shown columns.
259 void setHeaderVisible(bool visible
);
260 bool isHeaderVisible() const;
263 * @return Header of the list. The header is also available if it is not shown
264 * (see KItemListView::setHeaderShown()).
266 KItemListHeader
* header() const;
269 * @return Pixmap that is used for a drag operation based on the
270 * items given by \a indexes.
272 virtual QPixmap
createDragPixmap(const KItemSet
& indexes
) const;
275 * Lets the user edit the role \a role for item with the index \a index.
277 void editRole(int index
, const QByteArray
& role
);
279 void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= nullptr) override
;
282 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
283 void scrollOffsetChanged(qreal current
, qreal previous
);
284 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
285 void itemOffsetChanged(qreal current
, qreal previous
);
286 void maximumItemOffsetChanged(qreal current
, qreal previous
);
287 void scrollTo(qreal newOffset
);
290 * Is emitted if the user has changed the sort order by clicking on a
291 * header item (see KItemListView::setHeaderShown()). The sort order
292 * of the model has already been adjusted to
293 * the current sort order. Note that no signal will be emitted if the
294 * sort order of the model has been changed without user interaction.
296 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
299 * Is emitted if the user has changed the sort role by clicking on a
300 * header item (see KItemListView::setHeaderShown()). The sort role
301 * of the model has already been adjusted to
302 * the current sort role. Note that no signal will be emitted if the
303 * sort role of the model has been changed without user interaction.
305 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
308 * Is emitted if the user has changed the visible roles by moving a header
309 * item (see KItemListView::setHeaderShown()). Note that no signal will be
310 * emitted if the roles have been changed without user interaction by
311 * KItemListView::setVisibleRoles().
313 void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
315 void roleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
316 void roleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
319 * Emitted once scrolling has finished, or immediately if no scrolling was necessary
320 * to get item in view in scrollToItem.
322 void scrollingStopped();
325 QVariant
itemChange(GraphicsItemChange change
, const QVariant
&value
) override
;
326 void setItemSize(const QSizeF
& size
);
327 void setStyleOption(const KItemListStyleOption
& option
);
330 * If the scroll-orientation is vertical, the items are ordered
331 * from top to bottom (= default setting). If the scroll-orientation
332 * is horizontal, the items are ordered from left to right.
334 void setScrollOrientation(Qt::Orientation orientation
);
335 Qt::Orientation
scrollOrientation() const;
338 * Factory method for creating a default widget-creator. The method will be used
339 * in case if setWidgetCreator() has not been set by the application.
340 * @return New instance of the widget-creator that should be used per
343 virtual KItemListWidgetCreatorBase
* defaultWidgetCreator() const;
346 * Factory method for creating a default group-header-creator. The method will be used
347 * in case if setGroupHeaderCreator() has not been set by the application.
348 * @return New instance of the group-header-creator that should be used per
351 virtual KItemListGroupHeaderCreatorBase
* defaultGroupHeaderCreator() const;
354 * Is called when creating a new KItemListWidget instance and allows derived
355 * classes to do a custom initialization.
357 virtual void initializeItemListWidget(KItemListWidget
* item
);
360 * @return True if at least one of the changed roles \p changedRoles might result
361 * in the need to update the item-size hint (see KItemListView::itemSizeHint()).
362 * Per default true is returned which means on each role-change of existing items
363 * the item-size hints are recalculated. For performance reasons it is recommended
364 * to return false in case if a role-change will not result in a changed
367 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
>& changedRoles
) const;
369 virtual void onControllerChanged(KItemListController
* current
, KItemListController
* previous
);
370 virtual void onModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
372 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
373 virtual void onItemSizeChanged(const QSizeF
& current
, const QSizeF
& previous
);
374 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
375 virtual void onVisibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
376 virtual void onStyleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
377 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
379 virtual void onTransactionBegin();
380 virtual void onTransactionEnd();
382 bool event(QEvent
* event
) override
;
383 void mousePressEvent(QGraphicsSceneMouseEvent
* event
) override
;
384 void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
) override
;
385 void dragEnterEvent(QGraphicsSceneDragDropEvent
* event
) override
;
386 void dragMoveEvent(QGraphicsSceneDragDropEvent
* event
) override
;
387 void dragLeaveEvent(QGraphicsSceneDragDropEvent
* event
) override
;
388 void dropEvent(QGraphicsSceneDragDropEvent
* event
) override
;
390 QList
<KItemListWidget
*> visibleItemListWidgets() const;
392 virtual void updateFont();
393 virtual void updatePalette();
395 KItemListSizeHintResolver
* m_sizeHintResolver
;
398 virtual void slotItemsInserted(const KItemRangeList
& itemRanges
);
399 virtual void slotItemsRemoved(const KItemRangeList
& itemRanges
);
400 virtual void slotItemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
401 virtual void slotItemsChanged(const KItemRangeList
& itemRanges
,
402 const QSet
<QByteArray
>& roles
);
403 virtual void slotGroupsChanged();
405 virtual void slotGroupedSortingChanged(bool current
);
406 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
407 virtual void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
408 virtual void slotCurrentChanged(int current
, int previous
);
409 virtual void slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
);
412 void slotAnimationFinished(QGraphicsWidget
* widget
,
413 KItemListViewAnimation::AnimationType type
);
414 void slotLayoutTimerFinished();
416 void slotRubberBandPosChanged();
417 void slotRubberBandActivationChanged(bool active
);
420 * Is invoked if the column-width of one role in the header has
421 * been changed by the user. The automatic resizing of columns
422 * will be turned off as soon as this method has been called at
425 void slotHeaderColumnWidthChanged(const QByteArray
& role
,
427 qreal previousWidth
);
430 * Is invoked if a column has been moved by the user. Applies
431 * the moved role to the view.
433 void slotHeaderColumnMoved(const QByteArray
& role
,
438 * Triggers the autoscrolling if autoScroll() is enabled by checking the
439 * current mouse position. If the mouse position is within the autoscroll
440 * margins a timer will be started that periodically triggers the autoscrolling.
442 void triggerAutoScrolling();
445 * Is invoked if the geometry of the parent-widget from a group-header has been
446 * changed. The x-position and width of the group-header gets adjusted to assure
447 * that it always spans the whole width even during temporary transitions of the
450 void slotGeometryOfGroupHeaderParentChanged();
452 void slotRoleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
453 void slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
456 enum LayoutAnimationHint
468 void setController(KItemListController
* controller
);
469 void setModel(KItemModelBase
* model
);
471 KItemListRubberBand
* rubberBand() const;
473 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
476 * Helper method for doLayout: Returns a list of items that can be reused for the visible
477 * area. Invisible group headers get recycled. The reusable items are items that are
478 * invisible. If the animation hint is 'Animation' then items that are currently animated
479 * won't be reused. Reusing items is faster in comparison to deleting invisible
480 * items and creating a new instance for visible items.
482 QList
<int> recycleInvisibleItems(int firstVisibleIndex
,
483 int lastVisibleIndex
,
484 LayoutAnimationHint hint
);
487 * Helper method for doLayout: Starts a moving-animation for the widget to the given
488 * new position. The moving-animation is only started if the new position is within
489 * the same row or column, otherwise the create-animation is used instead.
490 * @return True if the moving-animation has been applied.
492 bool moveWidget(KItemListWidget
* widget
, const QPointF
& newPos
);
494 void emitOffsetChanges();
496 KItemListWidget
* createWidget(int index
);
497 void recycleWidget(KItemListWidget
* widget
);
500 * Changes the index of the widget to \a index and assures a consistent
501 * update for m_visibleItems and m_visibleCells. The cell-information
502 * for the new index will not be updated and be initialized as empty cell.
504 void setWidgetIndex(KItemListWidget
* widget
, int index
);
507 * Changes the index of the widget to \a index. In opposite to
508 * setWidgetIndex() the cell-information for the widget gets updated.
509 * This update gives doLayout() the chance to animate the moving
510 * of the item visually (see moveWidget()).
512 void moveWidgetToIndex(KItemListWidget
* widget
, int index
);
515 * Helper method for prepareLayoutForIncreasedItemCount().
517 void setLayouterSize(const QSizeF
& size
, SizeType sizeType
);
520 * Helper method for createWidget() and setWidgetIndex() to update the properties
521 * of the itemlist widget.
523 void updateWidgetProperties(KItemListWidget
* widget
, int index
);
526 * Helper method for updateWidgetPropertes() to create or update
527 * the itemlist group-header.
529 void updateGroupHeaderForWidget(KItemListWidget
* widget
);
532 * Updates the position and size of the group-header that belongs
533 * to the itemlist widget \a widget. The given widget must represent
534 * the first item of a group.
536 void updateGroupHeaderLayout(KItemListWidget
* widget
);
539 * Recycles the group-header for the widget.
541 void recycleGroupHeaderForWidget(KItemListWidget
* widget
);
544 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
545 * and slotSortRoleChanged(): Iterates through all visible items and updates
546 * the group-header widgets.
548 void updateVisibleGroupHeaders();
551 * @return Index for the item in the list returned by KItemModelBase::groups()
552 * that represents the group where the item with the index \a index
553 * belongs to. -1 is returned if no groups are available.
555 int groupIndexForItem(int index
) const;
558 * Updates the alternate background for all visible items.
559 * @see updateAlternateBackgroundForWidget()
561 void updateAlternateBackgrounds();
564 * Updates the alternateBackground-property of the widget dependent
565 * on the state of useAlternateBackgrounds() and the grouping state.
567 void updateAlternateBackgroundForWidget(KItemListWidget
* widget
);
570 * @return True if alternate backgrounds should be used for the items.
571 * This is the case if an empty item-size is given and if there
572 * is more than one visible role.
574 bool useAlternateBackgrounds() const;
577 * @param itemRanges Items that must be checked for getting the widths of columns.
578 * @return The preferred width of the column of each visible role. The width will
579 * be respected if the width of the item size is <= 0 (see
580 * KItemListView::setItemSize()). Per default an empty hash
583 QHash
<QByteArray
, qreal
> preferredColumnWidths(const KItemRangeList
& itemRanges
) const;
586 * Applies the column-widths from m_headerWidget to the layout
589 void applyColumnWidthsFromHeader();
592 * Applies the column-widths from m_headerWidget to \a widget.
594 void updateWidgetColumnWidths(KItemListWidget
* widget
);
597 * Updates the preferred column-widths of m_groupHeaderWidget by
598 * invoking KItemListView::columnWidths().
600 void updatePreferredColumnWidths(const KItemRangeList
& itemRanges
);
603 * Convenience method for
604 * updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model->count()).
606 void updatePreferredColumnWidths();
609 * Resizes the column-widths of m_headerWidget based on the preferred widths
610 * and the available view-size.
612 void applyAutomaticColumnWidths();
615 * @return Sum of the widths of all columns.
617 qreal
columnWidthsSum() const;
620 * @return Boundaries of the header. An empty rectangle is returned
621 * if no header is shown.
623 QRectF
headerBoundaries() const;
626 * @return True if the number of columns or rows will be changed when applying
627 * the new grid- and item-size. Used to determine whether an animation
628 * should be done when applying the new layout.
630 bool changesItemGridLayout(const QSizeF
& newGridSize
,
631 const QSizeF
& newItemSize
,
632 const QSizeF
& newItemMargin
) const;
635 * @param changedItemCount Number of inserted or removed items.
636 * @return True if the inserting or removing of items should be animated.
637 * No animation should be done if the number of items is too large
638 * to provide a pleasant animation.
640 bool animateChangedItemCount(int changedItemCount
) const;
643 * @return True if a scrollbar for the given scroll-orientation is required
644 * when using a size of \p size for the view. Calling the method is rather
645 * expansive as a temporary relayout needs to be done.
647 bool scrollBarRequired(const QSizeF
& size
) const;
650 * Shows a drop-indicator between items dependent on the given
651 * cursor position. The cursor position is relative to the upper left
653 * @return Index of the item where the dropping is done. An index of -1
654 * indicates that the item has been dropped after the last item.
656 int showDropIndicator(const QPointF
& pos
);
657 void hideDropIndicator();
660 * Applies the height of the group header to the layouter. The height
661 * depends on the used scroll orientation.
663 void updateGroupHeaderHeight();
666 * Updates the siblings-information for all visible items that are inside
667 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
668 * is smaller than 0, the siblings-information for all visible items gets
670 * @see KItemListWidget::setSiblingsInformation()
672 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
675 * Helper method for updateExpansionIndicators().
676 * @return True if the item with the index \a index has a sibling successor
677 * (= the item is not the last item of the current hierarchy).
679 bool hasSiblingSuccessor(int index
) const;
682 * Helper method for slotRoleEditingCanceled() and slotRoleEditingFinished().
683 * Disconnects the two Signals "roleEditingCanceled" and
684 * "roleEditingFinished"
686 void disconnectRoleEditingSignals(int index
);
689 * Helper function for triggerAutoScrolling().
690 * @param pos Logical position of the mouse relative to the range.
691 * @param range Range of the visible area.
692 * @param oldInc Previous increment. Is used to assure that the increment
693 * increases only gradually.
694 * @return Scroll increment that should be added to the offset().
695 * As soon as \a pos is inside the autoscroll-margin a
696 * value != 0 will be returned.
698 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
701 * Helper functions for changesItemCount().
702 * @return The number of items that fit into the available size by
703 * respecting the size of the item and the margin between the items.
705 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
708 bool m_enabledSelectionToggles
;
710 bool m_supportsItemExpanding
;
712 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
713 LayoutAnimationHint m_endTransactionAnimationHint
;
716 KItemListController
* m_controller
;
717 KItemModelBase
* m_model
;
718 QList
<QByteArray
> m_visibleRoles
;
719 mutable KItemListWidgetCreatorBase
* m_widgetCreator
;
720 mutable KItemListGroupHeaderCreatorBase
* m_groupHeaderCreator
;
721 KItemListStyleOption m_styleOption
;
723 QHash
<int, KItemListWidget
*> m_visibleItems
;
724 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
728 Cell() : column(-1), row(-1) {}
729 Cell(int c
, int r
) : column(c
), row(r
) {}
733 QHash
<int, Cell
> m_visibleCells
;
735 int m_scrollBarExtent
;
736 KItemListViewLayouter
* m_layouter
;
737 KItemListViewAnimation
* m_animation
;
739 QTimer
* m_layoutTimer
; // Triggers an asynchronous doLayout() call.
740 qreal m_oldScrollOffset
;
741 qreal m_oldMaximumScrollOffset
;
742 qreal m_oldItemOffset
;
743 qreal m_oldMaximumItemOffset
;
745 bool m_skipAutoScrollForRubberBand
;
746 KItemListRubberBand
* m_rubberBand
;
747 KItemListRubberBand
* m_tapAndHoldIndicator
;
750 int m_autoScrollIncrement
;
751 QTimer
* m_autoScrollTimer
;
753 KItemListHeader
* m_header
;
754 KItemListHeaderWidget
* m_headerWidget
;
756 QPropertyAnimation
* m_indicatorAnimation
;
758 // When dragging items into the view where the sort-role of the model
759 // is empty, a visual indicator should be shown during dragging where
760 // the dropping will happen. This indicator is specified by an index
761 // of the item. -1 means that no indicator will be shown at all.
762 // The m_dropIndicator is set by the KItemListController
763 // by KItemListView::showDropIndicator() and KItemListView::hideDropIndicator().
764 QRectF m_dropIndicator
;
766 QList
<QVariantAnimation
*> m_rubberBandAnimations
;
768 friend class KItemListContainer
; // Accesses scrollBarRequired()
769 friend class KItemListHeader
; // Accesses m_headerWidget
770 friend class KItemListController
;
771 friend class KItemListControllerTest
;
772 friend class KItemListViewAccessible
;
773 friend class KItemListAccessibleCell
;
777 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
778 * by recycling existing QGraphicsWidgets instances. Is used by
779 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
782 class DOLPHIN_EXPORT KItemListCreatorBase
785 virtual ~KItemListCreatorBase();
788 void addCreatedWidget(QGraphicsWidget
* widget
);
789 void pushRecycleableWidget(QGraphicsWidget
* widget
);
790 QGraphicsWidget
* popRecycleableWidget();
793 QSet
<QGraphicsWidget
*> m_createdWidgets
;
794 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
798 * @brief Base class for creating KItemListWidgets.
800 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
801 * For a custom implementation the methods create(), itemSizeHint() and preferredColumnWith()
802 * must be reimplemented. The intention of the widget creator is to prevent repetitive and
803 * expensive instantiations and deletions of KItemListWidgets by recycling existing widget
806 class DOLPHIN_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
809 ~KItemListWidgetCreatorBase() override
;
811 virtual KItemListWidget
* create(KItemListView
* view
) = 0;
813 virtual void recycle(KItemListWidget
* widget
);
815 virtual void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const = 0;
817 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
819 const KItemListView
* view
) const = 0;
823 * @brief Template class for creating KItemListWidgets.
826 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
829 KItemListWidgetCreator();
830 ~KItemListWidgetCreator() override
;
832 KItemListWidget
* create(KItemListView
* view
) override
;
834 void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const override
;
836 qreal
preferredRoleColumnWidth(const QByteArray
& role
,
838 const KItemListView
* view
) const override
;
840 KItemListWidgetInformant
* m_informant
;
844 KItemListWidgetCreator
<T
>::KItemListWidgetCreator() :
845 m_informant(T::createInformant())
850 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
856 KItemListWidget
* KItemListWidgetCreator
<T
>::create(KItemListView
* view
)
858 KItemListWidget
* widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
860 widget
= new T(m_informant
, view
);
861 addCreatedWidget(widget
);
863 widget
->setParentItem(view
);
868 void KItemListWidgetCreator
<T
>::calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const
870 return m_informant
->calculateItemSizeHints(logicalHeightHints
, logicalWidthHint
, view
);
874 qreal KItemListWidgetCreator
<T
>::preferredRoleColumnWidth(const QByteArray
& role
,
876 const KItemListView
* view
) const
878 return m_informant
->preferredRoleColumnWidth(role
, index
, view
);
882 * @brief Base class for creating KItemListGroupHeaders.
884 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
885 * For a custom implementation the methods create() and recycle() must be reimplemented.
886 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
887 * deletions of KItemListGroupHeaders by recycling existing header instances.
889 class DOLPHIN_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
892 ~KItemListGroupHeaderCreatorBase() override
;
893 virtual KItemListGroupHeader
* create(KItemListView
* view
) = 0;
894 virtual void recycle(KItemListGroupHeader
* header
);
898 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
901 ~KItemListGroupHeaderCreator() override
;
902 KItemListGroupHeader
* create(KItemListView
* view
) override
;
906 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
911 KItemListGroupHeader
* KItemListGroupHeaderCreator
<T
>::create(KItemListView
* view
)
913 KItemListGroupHeader
* widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
915 widget
= new T(view
);
916 addCreatedWidget(widget
);