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
12 #include "dolphin_export.h"
13 #include "kitemviews/kitemliststyleoption.h"
14 #include "kitemviews/kitemlistwidget.h"
15 #include "kitemviews/kitemmodelbase.h"
16 #include "kitemviews/kstandarditemlistgroupheader.h"
17 #include "kitemviews/private/kitemlistviewanimation.h"
19 #include <QGraphicsWidget>
22 class KItemListController
;
23 class KItemListGroupHeaderCreatorBase
;
24 class KItemListHeader
;
25 class KItemListHeaderWidget
;
26 class KItemListSizeHintResolver
;
27 class KItemListRubberBand
;
28 class KItemListViewAnimation
;
29 class KItemListViewLayouter
;
30 class KItemListWidget
;
31 class KItemListWidgetInformant
;
32 class KItemListWidgetCreatorBase
;
34 class QPropertyAnimation
;
35 class QVariantAnimation
;
38 * @brief Represents the view of an item-list.
40 * The view is responsible for showing the items of the model within
41 * a GraphicsItem. Each visible item is represented by a KItemListWidget.
43 * The created view must be applied to the KItemListController with
44 * KItemListController::setView() or with the constructor of
45 * KItemListController.
47 * @see KItemListWidget
50 class DOLPHIN_EXPORT KItemListView
: public QGraphicsWidget
54 Q_PROPERTY(qreal scrollOffset READ scrollOffset WRITE setScrollOffset
)
55 Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset
)
58 explicit KItemListView(QGraphicsWidget
* parent
= nullptr);
59 ~KItemListView() override
;
62 * Offset of the scrollbar that represents the scroll-orientation
63 * (see setScrollOrientation()).
65 void setScrollOffset(qreal offset
);
66 qreal
scrollOffset() const;
68 qreal
maximumScrollOffset() const;
71 * Offset related to an item, that does not fit into the available
72 * size of the listview. If the scroll-orientation is vertical
73 * the item-offset describes the offset of the horizontal axe, if
74 * the scroll-orientation is horizontal the item-offset describes
75 * the offset of the vertical axe.
77 void setItemOffset(qreal scrollOffset
);
78 qreal
itemOffset() const;
80 qreal
maximumItemOffset() const;
82 int maximumVisibleItems() const;
84 void setVisibleRoles(const QList
<QByteArray
>& roles
);
85 QList
<QByteArray
> visibleRoles() const;
88 * If set to true an automatic scrolling is done as soon as the
89 * mouse is moved near the borders of the view. Per default
90 * the automatic scrolling is turned off.
92 void setAutoScroll(bool enabled
);
93 bool autoScroll() const;
96 * If set to true selection-toggles will be shown when hovering
97 * an item. Per default the selection-toggles are disabled.
99 void setEnabledSelectionToggles(bool enabled
);
100 bool enabledSelectionToggles() const;
103 * @return Controller of the item-list. The controller gets
104 * initialized by KItemListController::setView() and will
105 * result in calling KItemListController::onControllerChanged().
107 KItemListController
* controller() const;
110 * @return Model of the item-list. The model gets
111 * initialized by KItemListController::setModel() and will
112 * result in calling KItemListController::onModelChanged().
114 KItemModelBase
* model() const;
117 * Sets the creator that creates a widget showing the
118 * content of one model-item. Usually it is sufficient
119 * to implement a custom widget X derived from KItemListWidget and
120 * set the creator by:
122 * itemListView->setWidgetCreator(new KItemListWidgetCreator<X>());
124 * The ownership of the widget creator is transferred to
125 * the item-list view.
127 void setWidgetCreator(KItemListWidgetCreatorBase
* widgetCreator
);
128 KItemListWidgetCreatorBase
* widgetCreator() const;
131 * Sets the creator that creates a group header. Usually it is sufficient
132 * to implement a custom header widget X derived from KItemListGroupHeader and
133 * set the creator by:
135 * itemListView->setGroupHeaderCreator(new KItemListGroupHeaderCreator<X>());
137 * The ownership of the gropup header creator is transferred to
138 * the item-list view.
140 void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
* groupHeaderCreator
);
141 KItemListGroupHeaderCreatorBase
* groupHeaderCreator() const;
144 * @return The basic size of all items. The size of an item may be larger than
145 * the basic size (see KItemListView::itemRect()).
147 QSizeF
itemSize() const;
149 const KItemListStyleOption
& styleOption() const;
151 void setGeometry(const QRectF
& rect
) override
;
154 * @return The page step which should be used by the vertical scroll bar.
155 * This is the height of the view except for the header widget.
157 qreal
verticalPageStep() const;
160 * @return Index of the item that is below the point \a pos.
161 * The position is relative to the upper right of
162 * the visible area. Only (at least partly) visible
163 * items are considered. -1 is returned if no item is
164 * below the position.
166 int itemAt(const QPointF
& pos
) const;
167 bool isAboveSelectionToggle(int index
, const QPointF
& pos
) const;
168 bool isAboveExpansionToggle(int index
, const QPointF
& pos
) const;
169 bool isAboveText(int index
, const QPointF
& pos
) const;
172 * @return Index of the first item that is at least partly visible.
173 * -1 is returned if the model contains no items.
175 int firstVisibleIndex() const;
178 * @return Index of the last item that is at least partly visible.
179 * -1 is returned if the model contains no items.
181 int lastVisibleIndex() const;
184 * Calculates the required size for all items in the model.
185 * It might be larger than KItemListView::itemSize().
186 * In this case the layout grid will be stretched to assure an
189 * @note the logical height (width) is actually the
190 * width (height) if the scroll orientation is Qt::Vertical!
192 void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>>& logicalHeightHints
, qreal
& logicalWidthHint
) const;
195 * If set to true, items having child-items can be expanded to show the child-items as
196 * part of the view. Per default the expanding of items is disabled. If expanding of
197 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
198 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
199 * must be reimplemented. The view-implementation
200 * has to take care itself how to visually represent the expanded items provided
203 void setSupportsItemExpanding(bool supportsExpanding
);
204 bool supportsItemExpanding() const;
207 * @return The rectangle of the item relative to the top/left of
208 * the currently visible area (see KItemListView::offset()).
210 QRectF
itemRect(int index
) const;
213 * @return The context rectangle of the item relative to the top/left of
214 * the currently visible area (see KItemListView::offset()). The
215 * context rectangle is defined by the united rectangle of
216 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
217 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
218 * a tooltip or a context-menu for an item. Note that a context rectangle will
219 * only be returned for (at least partly) visible items. An empty rectangle will
220 * be returned for fully invisible items.
222 QRectF
itemContextRect(int index
) const;
225 * @return Whether or not the name of the file has been elided. At present this will
226 * only ever be true when in icons view.
228 bool isElided(int index
) const;
231 * Scrolls to the item with the index \a index so that the item
232 * will be fully visible.
234 void scrollToItem(int index
);
237 * If several properties of KItemListView are changed synchronously, it is
238 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
239 * This prevents unnecessary and expensive layout-calculations.
241 void beginTransaction();
244 * Counterpart to beginTransaction(). The layout changes will only be animated if
245 * all property changes between beginTransaction() and endTransaction() support
248 void endTransaction();
250 bool isTransactionActive() const;
253 * Turns on the header if \p visible is true. Per default the
254 * header is not visible. Usually the header is turned on when
255 * showing a classic "table-view" to describe the shown columns.
257 void setHeaderVisible(bool visible
);
258 bool isHeaderVisible() const;
261 * @return Header of the list. The header is also available if it is not shown
262 * (see KItemListView::setHeaderShown()).
264 KItemListHeader
* header() const;
267 * @return Pixmap that is used for a drag operation based on the
268 * items given by \a indexes.
270 virtual QPixmap
createDragPixmap(const KItemSet
& indexes
) const;
273 * Lets the user edit the role \a role for item with the index \a index.
275 void editRole(int index
, const QByteArray
& role
);
277 void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= nullptr) override
;
280 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
281 void scrollOffsetChanged(qreal current
, qreal previous
);
282 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
283 void itemOffsetChanged(qreal current
, qreal previous
);
284 void maximumItemOffsetChanged(qreal current
, qreal previous
);
285 void scrollTo(qreal newOffset
);
288 * Is emitted if the user has changed the sort order by clicking on a
289 * header item (see KItemListView::setHeaderShown()). The sort order
290 * of the model has already been adjusted to
291 * the current sort order. Note that no signal will be emitted if the
292 * sort order of the model has been changed without user interaction.
294 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
297 * Is emitted if the user has changed the sort role by clicking on a
298 * header item (see KItemListView::setHeaderShown()). The sort role
299 * of the model has already been adjusted to
300 * the current sort role. Note that no signal will be emitted if the
301 * sort role of the model has been changed without user interaction.
303 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
306 * Is emitted if the user has changed the visible roles by moving a header
307 * item (see KItemListView::setHeaderShown()). Note that no signal will be
308 * emitted if the roles have been changed without user interaction by
309 * KItemListView::setVisibleRoles().
311 void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
313 void roleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
314 void roleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
317 * Emitted once scrolling has finished, or immediately if no scrolling was necessary
318 * to get item in view in scrollToItem.
320 void scrollingStopped();
323 QVariant
itemChange(GraphicsItemChange change
, const QVariant
&value
) override
;
324 void setItemSize(const QSizeF
& size
);
325 void setStyleOption(const KItemListStyleOption
& option
);
328 * If the scroll-orientation is vertical, the items are ordered
329 * from top to bottom (= default setting). If the scroll-orientation
330 * is horizontal, the items are ordered from left to right.
332 void setScrollOrientation(Qt::Orientation orientation
);
333 Qt::Orientation
scrollOrientation() const;
336 * Factory method for creating a default widget-creator. The method will be used
337 * in case if setWidgetCreator() has not been set by the application.
338 * @return New instance of the widget-creator that should be used per
341 virtual KItemListWidgetCreatorBase
* defaultWidgetCreator() const;
344 * Factory method for creating a default group-header-creator. The method will be used
345 * in case if setGroupHeaderCreator() has not been set by the application.
346 * @return New instance of the group-header-creator that should be used per
349 virtual KItemListGroupHeaderCreatorBase
* defaultGroupHeaderCreator() const;
352 * Is called when creating a new KItemListWidget instance and allows derived
353 * classes to do a custom initialization.
355 virtual void initializeItemListWidget(KItemListWidget
* item
);
358 * @return True if at least one of the changed roles \p changedRoles might result
359 * in the need to update the item-size hint (see KItemListView::itemSizeHint()).
360 * Per default true is returned which means on each role-change of existing items
361 * the item-size hints are recalculated. For performance reasons it is recommended
362 * to return false in case if a role-change will not result in a changed
365 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
>& changedRoles
) const;
367 virtual void onControllerChanged(KItemListController
* current
, KItemListController
* previous
);
368 virtual void onModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
370 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
371 virtual void onItemSizeChanged(const QSizeF
& current
, const QSizeF
& previous
);
372 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
373 virtual void onVisibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
374 virtual void onStyleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
375 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
377 virtual void onTransactionBegin();
378 virtual void onTransactionEnd();
380 bool event(QEvent
* event
) override
;
381 void mousePressEvent(QGraphicsSceneMouseEvent
* event
) override
;
382 void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
) override
;
383 void dragEnterEvent(QGraphicsSceneDragDropEvent
* event
) override
;
384 void dragMoveEvent(QGraphicsSceneDragDropEvent
* event
) override
;
385 void dragLeaveEvent(QGraphicsSceneDragDropEvent
* event
) override
;
386 void dropEvent(QGraphicsSceneDragDropEvent
* event
) override
;
388 QList
<KItemListWidget
*> visibleItemListWidgets() const;
390 virtual void updateFont();
391 virtual void updatePalette();
393 KItemListSizeHintResolver
* m_sizeHintResolver
;
396 virtual void slotItemsInserted(const KItemRangeList
& itemRanges
);
397 virtual void slotItemsRemoved(const KItemRangeList
& itemRanges
);
398 virtual void slotItemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
399 virtual void slotItemsChanged(const KItemRangeList
& itemRanges
,
400 const QSet
<QByteArray
>& roles
);
401 virtual void slotGroupsChanged();
403 virtual void slotGroupedSortingChanged(bool current
);
404 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
405 virtual void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
406 virtual void slotCurrentChanged(int current
, int previous
);
407 virtual void slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
);
410 void slotAnimationFinished(QGraphicsWidget
* widget
,
411 KItemListViewAnimation::AnimationType type
);
412 void slotLayoutTimerFinished();
414 void slotRubberBandPosChanged();
415 void slotRubberBandActivationChanged(bool active
);
418 * Is invoked if the column-width of one role in the header has
419 * been changed by the user. The automatic resizing of columns
420 * will be turned off as soon as this method has been called at
423 void slotHeaderColumnWidthChanged(const QByteArray
& role
,
425 qreal previousWidth
);
428 * Is invoked if a column has been moved by the user. Applies
429 * the moved role to the view.
431 void slotHeaderColumnMoved(const QByteArray
& role
,
436 * Triggers the autoscrolling if autoScroll() is enabled by checking the
437 * current mouse position. If the mouse position is within the autoscroll
438 * margins a timer will be started that periodically triggers the autoscrolling.
440 void triggerAutoScrolling();
443 * Is invoked if the geometry of the parent-widget from a group-header has been
444 * changed. The x-position and width of the group-header gets adjusted to assure
445 * that it always spans the whole width even during temporary transitions of the
448 void slotGeometryOfGroupHeaderParentChanged();
450 void slotRoleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
451 void slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
454 enum LayoutAnimationHint
466 void setController(KItemListController
* controller
);
467 void setModel(KItemModelBase
* model
);
469 KItemListRubberBand
* rubberBand() const;
471 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
474 * Helper method for doLayout: Returns a list of items that can be reused for the visible
475 * area. Invisible group headers get recycled. The reusable items are items that are
476 * invisible. If the animation hint is 'Animation' then items that are currently animated
477 * won't be reused. Reusing items is faster in comparison to deleting invisible
478 * items and creating a new instance for visible items.
480 QList
<int> recycleInvisibleItems(int firstVisibleIndex
,
481 int lastVisibleIndex
,
482 LayoutAnimationHint hint
);
485 * Helper method for doLayout: Starts a moving-animation for the widget to the given
486 * new position. The moving-animation is only started if the new position is within
487 * the same row or column, otherwise the create-animation is used instead.
488 * @return True if the moving-animation has been applied.
490 bool moveWidget(KItemListWidget
* widget
, const QPointF
& newPos
);
492 void emitOffsetChanges();
494 KItemListWidget
* createWidget(int index
);
495 void recycleWidget(KItemListWidget
* widget
);
498 * Changes the index of the widget to \a index and assures a consistent
499 * update for m_visibleItems and m_visibleCells. The cell-information
500 * for the new index will not be updated and be initialized as empty cell.
502 void setWidgetIndex(KItemListWidget
* widget
, int index
);
505 * Changes the index of the widget to \a index. In opposite to
506 * setWidgetIndex() the cell-information for the widget gets updated.
507 * This update gives doLayout() the chance to animate the moving
508 * of the item visually (see moveWidget()).
510 void moveWidgetToIndex(KItemListWidget
* widget
, int index
);
513 * Helper method for prepareLayoutForIncreasedItemCount().
515 void setLayouterSize(const QSizeF
& size
, SizeType sizeType
);
518 * Helper method for createWidget() and setWidgetIndex() to update the properties
519 * of the itemlist widget.
521 void updateWidgetProperties(KItemListWidget
* widget
, int index
);
524 * Helper method for updateWidgetPropertes() to create or update
525 * the itemlist group-header.
527 void updateGroupHeaderForWidget(KItemListWidget
* widget
);
530 * Updates the position and size of the group-header that belongs
531 * to the itemlist widget \a widget. The given widget must represent
532 * the first item of a group.
534 void updateGroupHeaderLayout(KItemListWidget
* widget
);
537 * Recycles the group-header for the widget.
539 void recycleGroupHeaderForWidget(KItemListWidget
* widget
);
542 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
543 * and slotSortRoleChanged(): Iterates through all visible items and updates
544 * the group-header widgets.
546 void updateVisibleGroupHeaders();
549 * @return Index for the item in the list returned by KItemModelBase::groups()
550 * that represents the group where the item with the index \a index
551 * belongs to. -1 is returned if no groups are available.
553 int groupIndexForItem(int index
) const;
556 * Updates the alternate background for all visible items.
557 * @see updateAlternateBackgroundForWidget()
559 void updateAlternateBackgrounds();
562 * Updates the alternateBackground-property of the widget dependent
563 * on the state of useAlternateBackgrounds() and the grouping state.
565 void updateAlternateBackgroundForWidget(KItemListWidget
* widget
);
568 * @return True if alternate backgrounds should be used for the items.
569 * This is the case if an empty item-size is given and if there
570 * is more than one visible role.
572 bool useAlternateBackgrounds() const;
575 * @param itemRanges Items that must be checked for getting the widths of columns.
576 * @return The preferred width of the column of each visible role. The width will
577 * be respected if the width of the item size is <= 0 (see
578 * KItemListView::setItemSize()). Per default an empty hash
581 QHash
<QByteArray
, qreal
> preferredColumnWidths(const KItemRangeList
& itemRanges
) const;
584 * Applies the column-widths from m_headerWidget to the layout
587 void applyColumnWidthsFromHeader();
590 * Applies the column-widths from m_headerWidget to \a widget.
592 void updateWidgetColumnWidths(KItemListWidget
* widget
);
595 * Updates the preferred column-widths of m_groupHeaderWidget by
596 * invoking KItemListView::columnWidths().
598 void updatePreferredColumnWidths(const KItemRangeList
& itemRanges
);
601 * Convenience method for
602 * updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model->count()).
604 void updatePreferredColumnWidths();
607 * Resizes the column-widths of m_headerWidget based on the preferred widths
608 * and the available view-size.
610 void applyAutomaticColumnWidths();
613 * @return Sum of the widths of all columns.
615 qreal
columnWidthsSum() const;
618 * @return Boundaries of the header. An empty rectangle is returned
619 * if no header is shown.
621 QRectF
headerBoundaries() const;
624 * @return True if the number of columns or rows will be changed when applying
625 * the new grid- and item-size. Used to determine whether an animation
626 * should be done when applying the new layout.
628 bool changesItemGridLayout(const QSizeF
& newGridSize
,
629 const QSizeF
& newItemSize
,
630 const QSizeF
& newItemMargin
) const;
633 * @param changedItemCount Number of inserted or removed items.
634 * @return True if the inserting or removing of items should be animated.
635 * No animation should be done if the number of items is too large
636 * to provide a pleasant animation.
638 bool animateChangedItemCount(int changedItemCount
) const;
641 * @return True if a scrollbar for the given scroll-orientation is required
642 * when using a size of \p size for the view. Calling the method is rather
643 * expansive as a temporary relayout needs to be done.
645 bool scrollBarRequired(const QSizeF
& size
) const;
648 * Shows a drop-indicator between items dependent on the given
649 * cursor position. The cursor position is relative to the upper left
651 * @return Index of the item where the dropping is done. An index of -1
652 * indicates that the item has been dropped after the last item.
654 int showDropIndicator(const QPointF
& pos
);
655 void hideDropIndicator();
658 * Applies the height of the group header to the layouter. The height
659 * depends on the used scroll orientation.
661 void updateGroupHeaderHeight();
664 * Updates the siblings-information for all visible items that are inside
665 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
666 * is smaller than 0, the siblings-information for all visible items gets
668 * @see KItemListWidget::setSiblingsInformation()
670 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
673 * Helper method for updateExpansionIndicators().
674 * @return True if the item with the index \a index has a sibling successor
675 * (= the item is not the last item of the current hierarchy).
677 bool hasSiblingSuccessor(int index
) const;
680 * Helper method for slotRoleEditingCanceled() and slotRoleEditingFinished().
681 * Disconnects the two Signals "roleEditingCanceled" and
682 * "roleEditingFinished"
684 void disconnectRoleEditingSignals(int index
);
687 * Helper function for triggerAutoScrolling().
688 * @param pos Logical position of the mouse relative to the range.
689 * @param range Range of the visible area.
690 * @param oldInc Previous increment. Is used to assure that the increment
691 * increases only gradually.
692 * @return Scroll increment that should be added to the offset().
693 * As soon as \a pos is inside the autoscroll-margin a
694 * value != 0 will be returned.
696 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
699 * Helper functions for changesItemCount().
700 * @return The number of items that fit into the available size by
701 * respecting the size of the item and the margin between the items.
703 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
706 bool m_enabledSelectionToggles
;
708 bool m_supportsItemExpanding
;
710 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
711 LayoutAnimationHint m_endTransactionAnimationHint
;
714 KItemListController
* m_controller
;
715 KItemModelBase
* m_model
;
716 QList
<QByteArray
> m_visibleRoles
;
717 mutable KItemListWidgetCreatorBase
* m_widgetCreator
;
718 mutable KItemListGroupHeaderCreatorBase
* m_groupHeaderCreator
;
719 KItemListStyleOption m_styleOption
;
721 QHash
<int, KItemListWidget
*> m_visibleItems
;
722 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
726 Cell() : column(-1), row(-1) {}
727 Cell(int c
, int r
) : column(c
), row(r
) {}
731 QHash
<int, Cell
> m_visibleCells
;
733 int m_scrollBarExtent
;
734 KItemListViewLayouter
* m_layouter
;
735 KItemListViewAnimation
* m_animation
;
737 QTimer
* m_layoutTimer
; // Triggers an asynchronous doLayout() call.
738 qreal m_oldScrollOffset
;
739 qreal m_oldMaximumScrollOffset
;
740 qreal m_oldItemOffset
;
741 qreal m_oldMaximumItemOffset
;
743 bool m_skipAutoScrollForRubberBand
;
744 KItemListRubberBand
* m_rubberBand
;
745 KItemListRubberBand
* m_tapAndHoldIndicator
;
748 int m_autoScrollIncrement
;
749 QTimer
* m_autoScrollTimer
;
751 KItemListHeader
* m_header
;
752 KItemListHeaderWidget
* m_headerWidget
;
754 QPropertyAnimation
* m_indicatorAnimation
;
756 // When dragging items into the view where the sort-role of the model
757 // is empty, a visual indicator should be shown during dragging where
758 // the dropping will happen. This indicator is specified by an index
759 // of the item. -1 means that no indicator will be shown at all.
760 // The m_dropIndicator is set by the KItemListController
761 // by KItemListView::showDropIndicator() and KItemListView::hideDropIndicator().
762 QRectF m_dropIndicator
;
764 QList
<QVariantAnimation
*> m_rubberBandAnimations
;
766 friend class KItemListContainer
; // Accesses scrollBarRequired()
767 friend class KItemListHeader
; // Accesses m_headerWidget
768 friend class KItemListController
;
769 friend class KItemListControllerTest
;
770 friend class KItemListViewAccessible
;
771 friend class KItemListAccessibleCell
;
775 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
776 * by recycling existing QGraphicsWidgets instances. Is used by
777 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
780 class DOLPHIN_EXPORT KItemListCreatorBase
783 virtual ~KItemListCreatorBase();
786 void addCreatedWidget(QGraphicsWidget
* widget
);
787 void pushRecycleableWidget(QGraphicsWidget
* widget
);
788 QGraphicsWidget
* popRecycleableWidget();
791 QSet
<QGraphicsWidget
*> m_createdWidgets
;
792 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
796 * @brief Base class for creating KItemListWidgets.
798 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
799 * For a custom implementation the methods create(), itemSizeHint() and preferredColumnWith()
800 * must be reimplemented. The intention of the widget creator is to prevent repetitive and
801 * expensive instantiations and deletions of KItemListWidgets by recycling existing widget
804 class DOLPHIN_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
807 ~KItemListWidgetCreatorBase() override
;
809 virtual KItemListWidget
* create(KItemListView
* view
) = 0;
811 virtual void recycle(KItemListWidget
* widget
);
813 virtual void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const = 0;
815 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
817 const KItemListView
* view
) const = 0;
821 * @brief Template class for creating KItemListWidgets.
824 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
827 KItemListWidgetCreator();
828 ~KItemListWidgetCreator() override
;
830 KItemListWidget
* create(KItemListView
* view
) override
;
832 void calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const override
;
834 qreal
preferredRoleColumnWidth(const QByteArray
& role
,
836 const KItemListView
* view
) const override
;
838 KItemListWidgetInformant
* m_informant
;
842 KItemListWidgetCreator
<T
>::KItemListWidgetCreator() :
843 m_informant(T::createInformant())
848 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
854 KItemListWidget
* KItemListWidgetCreator
<T
>::create(KItemListView
* view
)
856 KItemListWidget
* widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
858 widget
= new T(m_informant
, view
);
859 addCreatedWidget(widget
);
861 widget
->setParentItem(view
);
866 void KItemListWidgetCreator
<T
>::calculateItemSizeHints(QVector
<std::pair
<qreal
, bool>>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const
868 return m_informant
->calculateItemSizeHints(logicalHeightHints
, logicalWidthHint
, view
);
872 qreal KItemListWidgetCreator
<T
>::preferredRoleColumnWidth(const QByteArray
& role
,
874 const KItemListView
* view
) const
876 return m_informant
->preferredRoleColumnWidth(role
, index
, view
);
880 * @brief Base class for creating KItemListGroupHeaders.
882 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
883 * For a custom implementation the methods create() and recycle() must be reimplemented.
884 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
885 * deletions of KItemListGroupHeaders by recycling existing header instances.
887 class DOLPHIN_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
890 ~KItemListGroupHeaderCreatorBase() override
;
891 virtual KItemListGroupHeader
* create(KItemListView
* view
) = 0;
892 virtual void recycle(KItemListGroupHeader
* header
);
896 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
899 ~KItemListGroupHeaderCreator() override
;
900 KItemListGroupHeader
* create(KItemListView
* view
) override
;
904 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
909 KItemListGroupHeader
* KItemListGroupHeaderCreator
<T
>::create(KItemListView
* view
)
911 KItemListGroupHeader
* widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
913 widget
= new T(view
);
914 addCreatedWidget(widget
);