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
;
36 * @brief Represents the view of an item-list.
38 * The view is responsible for showing the items of the model within
39 * a GraphicsItem. Each visible item is represented by a KItemListWidget.
41 * The created view must be applied to the KItemListController with
42 * KItemListController::setView() or with the constructor of
43 * KItemListController.
45 * @see KItemListWidget
48 class DOLPHIN_EXPORT KItemListView
: public QGraphicsWidget
52 Q_PROPERTY(qreal scrollOffset READ scrollOffset WRITE setScrollOffset
)
53 Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset
)
56 explicit KItemListView(QGraphicsWidget
* parent
= nullptr);
57 ~KItemListView() override
;
60 * Offset of the scrollbar that represents the scroll-orientation
61 * (see setScrollOrientation()).
63 void setScrollOffset(qreal offset
);
64 qreal
scrollOffset() const;
66 qreal
maximumScrollOffset() const;
69 * Offset related to an item, that does not fit into the available
70 * size of the listview. If the scroll-orientation is vertical
71 * the item-offset describes the offset of the horizontal axe, if
72 * the scroll-orientation is horizontal the item-offset describes
73 * the offset of the vertical axe.
75 void setItemOffset(qreal scrollOffset
);
76 qreal
itemOffset() const;
78 qreal
maximumItemOffset() const;
80 int maximumVisibleItems() const;
82 void setVisibleRoles(const QList
<QByteArray
>& roles
);
83 QList
<QByteArray
> visibleRoles() const;
86 * If set to true an automatic scrolling is done as soon as the
87 * mouse is moved near the borders of the view. Per default
88 * the automatic scrolling is turned off.
90 void setAutoScroll(bool enabled
);
91 bool autoScroll() const;
94 * If set to true selection-toggles will be shown when hovering
95 * an item. Per default the selection-toggles are disabled.
97 void setEnabledSelectionToggles(bool enabled
);
98 bool enabledSelectionToggles() const;
101 * @return Controller of the item-list. The controller gets
102 * initialized by KItemListController::setView() and will
103 * result in calling KItemListController::onControllerChanged().
105 KItemListController
* controller() const;
108 * @return Model of the item-list. The model gets
109 * initialized by KItemListController::setModel() and will
110 * result in calling KItemListController::onModelChanged().
112 KItemModelBase
* model() const;
115 * Sets the creator that creates a widget showing the
116 * content of one model-item. Usually it is sufficient
117 * to implement a custom widget X derived from KItemListWidget and
118 * set the creator by:
120 * itemListView->setWidgetCreator(new KItemListWidgetCreator<X>());
122 * The ownership of the widget creator is transferred to
123 * the item-list view.
125 void setWidgetCreator(KItemListWidgetCreatorBase
* widgetCreator
);
126 KItemListWidgetCreatorBase
* widgetCreator() const;
129 * Sets the creator that creates a group header. Usually it is sufficient
130 * to implement a custom header widget X derived from KItemListGroupHeader and
131 * set the creator by:
133 * itemListView->setGroupHeaderCreator(new KItemListGroupHeaderCreator<X>());
135 * The ownership of the gropup header creator is transferred to
136 * the item-list view.
138 void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
* groupHeaderCreator
);
139 KItemListGroupHeaderCreatorBase
* groupHeaderCreator() const;
142 * @return The basic size of all items. The size of an item may be larger than
143 * the basic size (see KItemListView::itemRect()).
145 QSizeF
itemSize() const;
147 const KItemListStyleOption
& styleOption() const;
149 void setGeometry(const QRectF
& rect
) override
;
152 * @return The page step which should be used by the vertical scroll bar.
153 * This is the height of the view except for the header widget.
155 qreal
verticalPageStep() const;
158 * @return Index of the item that is below the point \a pos.
159 * The position is relative to the upper right of
160 * the visible area. Only (at least partly) visible
161 * items are considered. -1 is returned if no item is
162 * below the position.
164 int itemAt(const QPointF
& pos
) const;
165 bool isAboveSelectionToggle(int index
, const QPointF
& pos
) const;
166 bool isAboveExpansionToggle(int index
, const QPointF
& pos
) const;
167 bool isAboveText(int index
, const QPointF
& pos
) const;
170 * @return Index of the first item that is at least partly visible.
171 * -1 is returned if the model contains no items.
173 int firstVisibleIndex() const;
176 * @return Index of the last item that is at least partly visible.
177 * -1 is returned if the model contains no items.
179 int lastVisibleIndex() const;
182 * Calculates the required size for all items in the model.
183 * It might be larger than KItemListView::itemSize().
184 * In this case the layout grid will be stretched to assure an
187 * @note the logical height (width) is actually the
188 * width (height) if the scroll orientation is Qt::Vertical!
190 void calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
) const;
193 * If set to true, items having child-items can be expanded to show the child-items as
194 * part of the view. Per default the expanding of items is disabled. If expanding of
195 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
196 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
197 * must be reimplemented. The view-implementation
198 * has to take care itself how to visually represent the expanded items provided
201 void setSupportsItemExpanding(bool supportsExpanding
);
202 bool supportsItemExpanding() const;
205 * @return The rectangle of the item relative to the top/left of
206 * the currently visible area (see KItemListView::offset()).
208 QRectF
itemRect(int index
) const;
211 * @return The context rectangle of the item relative to the top/left of
212 * the currently visible area (see KItemListView::offset()). The
213 * context rectangle is defined by the united rectangle of
214 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
215 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
216 * a tooltip or a context-menu for an item. Note that a context rectangle will
217 * only be returned for (at least partly) visible items. An empty rectangle will
218 * be returned for fully invisible items.
220 QRectF
itemContextRect(int index
) const;
223 * Scrolls to the item with the index \a index so that the item
224 * will be fully visible.
226 void scrollToItem(int index
);
229 * If several properties of KItemListView are changed synchronously, it is
230 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
231 * This prevents unnecessary and expensive layout-calculations.
233 void beginTransaction();
236 * Counterpart to beginTransaction(). The layout changes will only be animated if
237 * all property changes between beginTransaction() and endTransaction() support
240 void endTransaction();
242 bool isTransactionActive() const;
245 * Turns on the header if \p visible is true. Per default the
246 * header is not visible. Usually the header is turned on when
247 * showing a classic "table-view" to describe the shown columns.
249 void setHeaderVisible(bool visible
);
250 bool isHeaderVisible() const;
253 * @return Header of the list. The header is also available if it is not shown
254 * (see KItemListView::setHeaderShown()).
256 KItemListHeader
* header() const;
259 * @return Pixmap that is used for a drag operation based on the
260 * items given by \a indexes.
262 virtual QPixmap
createDragPixmap(const KItemSet
& indexes
) const;
265 * Lets the user edit the role \a role for item with the index \a index.
267 void editRole(int index
, const QByteArray
& role
);
269 void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= nullptr) override
;
272 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
273 void scrollOffsetChanged(qreal current
, qreal previous
);
274 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
275 void itemOffsetChanged(qreal current
, qreal previous
);
276 void maximumItemOffsetChanged(qreal current
, qreal previous
);
277 void scrollTo(qreal newOffset
);
280 * Is emitted if the user has changed the sort order by clicking on a
281 * header item (see KItemListView::setHeaderShown()). The sort order
282 * of the model has already been adjusted to
283 * the current sort order. Note that no signal will be emitted if the
284 * sort order of the model has been changed without user interaction.
286 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
289 * Is emitted if the user has changed the sort role by clicking on a
290 * header item (see KItemListView::setHeaderShown()). The sort role
291 * of the model has already been adjusted to
292 * the current sort role. Note that no signal will be emitted if the
293 * sort role of the model has been changed without user interaction.
295 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
298 * Is emitted if the user has changed the visible roles by moving a header
299 * item (see KItemListView::setHeaderShown()). Note that no signal will be
300 * emitted if the roles have been changed without user interaction by
301 * KItemListView::setVisibleRoles().
303 void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
305 void roleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
306 void roleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
309 QVariant
itemChange(GraphicsItemChange change
, const QVariant
&value
) override
;
310 void setItemSize(const QSizeF
& size
);
311 void setStyleOption(const KItemListStyleOption
& option
);
314 * If the scroll-orientation is vertical, the items are ordered
315 * from top to bottom (= default setting). If the scroll-orientation
316 * is horizontal, the items are ordered from left to right.
318 void setScrollOrientation(Qt::Orientation orientation
);
319 Qt::Orientation
scrollOrientation() const;
322 * Factory method for creating a default widget-creator. The method will be used
323 * in case if setWidgetCreator() has not been set by the application.
324 * @return New instance of the widget-creator that should be used per
327 virtual KItemListWidgetCreatorBase
* defaultWidgetCreator() const;
330 * Factory method for creating a default group-header-creator. The method will be used
331 * in case if setGroupHeaderCreator() has not been set by the application.
332 * @return New instance of the group-header-creator that should be used per
335 virtual KItemListGroupHeaderCreatorBase
* defaultGroupHeaderCreator() const;
338 * Is called when creating a new KItemListWidget instance and allows derived
339 * classes to do a custom initialization.
341 virtual void initializeItemListWidget(KItemListWidget
* item
);
344 * @return True if at least one of the changed roles \p changedRoles might result
345 * in the need to update the item-size hint (see KItemListView::itemSizeHint()).
346 * Per default true is returned which means on each role-change of existing items
347 * the item-size hints are recalculated. For performance reasons it is recommended
348 * to return false in case if a role-change will not result in a changed
351 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
>& changedRoles
) const;
353 virtual void onControllerChanged(KItemListController
* current
, KItemListController
* previous
);
354 virtual void onModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
356 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
357 virtual void onItemSizeChanged(const QSizeF
& current
, const QSizeF
& previous
);
358 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
359 virtual void onVisibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
360 virtual void onStyleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
361 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
363 virtual void onTransactionBegin();
364 virtual void onTransactionEnd();
366 bool event(QEvent
* event
) override
;
367 void mousePressEvent(QGraphicsSceneMouseEvent
* event
) override
;
368 void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
) override
;
369 void dragEnterEvent(QGraphicsSceneDragDropEvent
* event
) override
;
370 void dragMoveEvent(QGraphicsSceneDragDropEvent
* event
) override
;
371 void dragLeaveEvent(QGraphicsSceneDragDropEvent
* event
) override
;
372 void dropEvent(QGraphicsSceneDragDropEvent
* event
) override
;
374 QList
<KItemListWidget
*> visibleItemListWidgets() const;
376 virtual void updateFont();
377 virtual void updatePalette();
380 virtual void slotItemsInserted(const KItemRangeList
& itemRanges
);
381 virtual void slotItemsRemoved(const KItemRangeList
& itemRanges
);
382 virtual void slotItemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
383 virtual void slotItemsChanged(const KItemRangeList
& itemRanges
,
384 const QSet
<QByteArray
>& roles
);
385 virtual void slotGroupsChanged();
387 virtual void slotGroupedSortingChanged(bool current
);
388 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
389 virtual void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
390 virtual void slotCurrentChanged(int current
, int previous
);
391 virtual void slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
);
394 void slotAnimationFinished(QGraphicsWidget
* widget
,
395 KItemListViewAnimation::AnimationType type
);
396 void slotLayoutTimerFinished();
398 void slotRubberBandPosChanged();
399 void slotRubberBandActivationChanged(bool active
);
402 * Is invoked if the column-width of one role in the header has
403 * been changed by the user. The automatic resizing of columns
404 * will be turned off as soon as this method has been called at
407 void slotHeaderColumnWidthChanged(const QByteArray
& role
,
409 qreal previousWidth
);
412 * Is invoked if a column has been moved by the user. Applies
413 * the moved role to the view.
415 void slotHeaderColumnMoved(const QByteArray
& role
,
420 * Triggers the autoscrolling if autoScroll() is enabled by checking the
421 * current mouse position. If the mouse position is within the autoscroll
422 * margins a timer will be started that periodically triggers the autoscrolling.
424 void triggerAutoScrolling();
427 * Is invoked if the geometry of the parent-widget from a group-header has been
428 * changed. The x-position and width of the group-header gets adjusted to assure
429 * that it always spans the whole width even during temporary transitions of the
432 void slotGeometryOfGroupHeaderParentChanged();
434 void slotRoleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
435 void slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
438 enum LayoutAnimationHint
450 void setController(KItemListController
* controller
);
451 void setModel(KItemModelBase
* model
);
453 KItemListRubberBand
* rubberBand() const;
455 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
458 * Helper method for doLayout: Returns a list of items that can be reused for the visible
459 * area. Invisible group headers get recycled. The reusable items are items that are
460 * invisible. If the animation hint is 'Animation' then items that are currently animated
461 * won't be reused. Reusing items is faster in comparison to deleting invisible
462 * items and creating a new instance for visible items.
464 QList
<int> recycleInvisibleItems(int firstVisibleIndex
,
465 int lastVisibleIndex
,
466 LayoutAnimationHint hint
);
469 * Helper method for doLayout: Starts a moving-animation for the widget to the given
470 * new position. The moving-animation is only started if the new position is within
471 * the same row or column, otherwise the create-animation is used instead.
472 * @return True if the moving-animation has been applied.
474 bool moveWidget(KItemListWidget
* widget
, const QPointF
& newPos
);
476 void emitOffsetChanges();
478 KItemListWidget
* createWidget(int index
);
479 void recycleWidget(KItemListWidget
* widget
);
482 * Changes the index of the widget to \a index and assures a consistent
483 * update for m_visibleItems and m_visibleCells. The cell-information
484 * for the new index will not be updated and be initialized as empty cell.
486 void setWidgetIndex(KItemListWidget
* widget
, int index
);
489 * Changes the index of the widget to \a index. In opposite to
490 * setWidgetIndex() the cell-information for the widget gets updated.
491 * This update gives doLayout() the chance to animate the moving
492 * of the item visually (see moveWidget()).
494 void moveWidgetToIndex(KItemListWidget
* widget
, int index
);
497 * Helper method for prepareLayoutForIncreasedItemCount().
499 void setLayouterSize(const QSizeF
& size
, SizeType sizeType
);
502 * Helper method for createWidget() and setWidgetIndex() to update the properties
503 * of the itemlist widget.
505 void updateWidgetProperties(KItemListWidget
* widget
, int index
);
508 * Helper method for updateWidgetPropertes() to create or update
509 * the itemlist group-header.
511 void updateGroupHeaderForWidget(KItemListWidget
* widget
);
514 * Updates the position and size of the group-header that belongs
515 * to the itemlist widget \a widget. The given widget must represent
516 * the first item of a group.
518 void updateGroupHeaderLayout(KItemListWidget
* widget
);
521 * Recycles the group-header for the widget.
523 void recycleGroupHeaderForWidget(KItemListWidget
* widget
);
526 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
527 * and slotSortRoleChanged(): Iterates through all visible items and updates
528 * the group-header widgets.
530 void updateVisibleGroupHeaders();
533 * @return Index for the item in the list returned by KItemModelBase::groups()
534 * that represents the group where the item with the index \a index
535 * belongs to. -1 is returned if no groups are available.
537 int groupIndexForItem(int index
) const;
540 * Updates the alternate background for all visible items.
541 * @see updateAlternateBackgroundForWidget()
543 void updateAlternateBackgrounds();
546 * Updates the alternateBackground-property of the widget dependent
547 * on the state of useAlternateBackgrounds() and the grouping state.
549 void updateAlternateBackgroundForWidget(KItemListWidget
* widget
);
552 * @return True if alternate backgrounds should be used for the items.
553 * This is the case if an empty item-size is given and if there
554 * is more than one visible role.
556 bool useAlternateBackgrounds() const;
559 * @param itemRanges Items that must be checked for getting the widths of columns.
560 * @return The preferred width of the column of each visible role. The width will
561 * be respected if the width of the item size is <= 0 (see
562 * KItemListView::setItemSize()). Per default an empty hash
565 QHash
<QByteArray
, qreal
> preferredColumnWidths(const KItemRangeList
& itemRanges
) const;
568 * Applies the column-widths from m_headerWidget to the layout
571 void applyColumnWidthsFromHeader();
574 * Applies the column-widths from m_headerWidget to \a widget.
576 void updateWidgetColumnWidths(KItemListWidget
* widget
);
579 * Updates the preferred column-widths of m_groupHeaderWidget by
580 * invoking KItemListView::columnWidths().
582 void updatePreferredColumnWidths(const KItemRangeList
& itemRanges
);
585 * Convenience method for
586 * updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model->count()).
588 void updatePreferredColumnWidths();
591 * Resizes the column-widths of m_headerWidget based on the preferred widths
592 * and the vailable view-size.
594 void applyAutomaticColumnWidths();
597 * @return Sum of the widths of all columns.
599 qreal
columnWidthsSum() const;
602 * @return Boundaries of the header. An empty rectangle is returned
603 * if no header is shown.
605 QRectF
headerBoundaries() const;
608 * @return True if the number of columns or rows will be changed when applying
609 * the new grid- and item-size. Used to determine whether an animation
610 * should be done when applying the new layout.
612 bool changesItemGridLayout(const QSizeF
& newGridSize
,
613 const QSizeF
& newItemSize
,
614 const QSizeF
& newItemMargin
) const;
617 * @param changedItemCount Number of inserted or removed items.
618 * @return True if the inserting or removing of items should be animated.
619 * No animation should be done if the number of items is too large
620 * to provide a pleasant animation.
622 bool animateChangedItemCount(int changedItemCount
) const;
625 * @return True if a scrollbar for the given scroll-orientation is required
626 * when using a size of \p size for the view. Calling the method is rather
627 * expansive as a temporary relayout needs to be done.
629 bool scrollBarRequired(const QSizeF
& size
) const;
632 * Shows a drop-indicator between items dependent on the given
633 * cursor position. The cursor position is relative to the upper left
635 * @return Index of the item where the dropping is done. An index of -1
636 * indicates that the item has been dropped after the last item.
638 int showDropIndicator(const QPointF
& pos
);
639 void hideDropIndicator();
642 * Applies the height of the group header to the layouter. The height
643 * depends on the used scroll orientation.
645 void updateGroupHeaderHeight();
648 * Updates the siblings-information for all visible items that are inside
649 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
650 * is smaller than 0, the siblings-information for all visible items gets
652 * @see KItemListWidget::setSiblingsInformation()
654 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
657 * Helper method for updateExpansionIndicators().
658 * @return True if the item with the index \a index has a sibling successor
659 * (= the item is not the last item of the current hierarchy).
661 bool hasSiblingSuccessor(int index
) const;
664 * Helper method for slotRoleEditingCanceled() and slotRoleEditingFinished().
665 * Disconnects the two Signals "roleEditingCanceled" and
666 * "roleEditingFinished"
668 void disconnectRoleEditingSignals(int index
);
671 * Helper function for triggerAutoScrolling().
672 * @param pos Logical position of the mouse relative to the range.
673 * @param range Range of the visible area.
674 * @param oldInc Previous increment. Is used to assure that the increment
675 * increases only gradually.
676 * @return Scroll increment that should be added to the offset().
677 * As soon as \a pos is inside the autoscroll-margin a
678 * value != 0 will be returned.
680 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
683 * Helper functions for changesItemCount().
684 * @return The number of items that fit into the available size by
685 * respecting the size of the item and the margin between the items.
687 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
690 bool m_enabledSelectionToggles
;
692 bool m_supportsItemExpanding
;
694 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
695 LayoutAnimationHint m_endTransactionAnimationHint
;
698 KItemListController
* m_controller
;
699 KItemModelBase
* m_model
;
700 QList
<QByteArray
> m_visibleRoles
;
701 mutable KItemListWidgetCreatorBase
* m_widgetCreator
;
702 mutable KItemListGroupHeaderCreatorBase
* m_groupHeaderCreator
;
703 KItemListStyleOption m_styleOption
;
705 QHash
<int, KItemListWidget
*> m_visibleItems
;
706 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
710 Cell() : column(-1), row(-1) {}
711 Cell(int c
, int r
) : column(c
), row(r
) {}
715 QHash
<int, Cell
> m_visibleCells
;
717 int m_scrollBarExtent
;
718 KItemListSizeHintResolver
* m_sizeHintResolver
;
719 KItemListViewLayouter
* m_layouter
;
720 KItemListViewAnimation
* m_animation
;
722 QTimer
* m_layoutTimer
; // Triggers an asynchronous doLayout() call.
723 qreal m_oldScrollOffset
;
724 qreal m_oldMaximumScrollOffset
;
725 qreal m_oldItemOffset
;
726 qreal m_oldMaximumItemOffset
;
728 bool m_skipAutoScrollForRubberBand
;
729 KItemListRubberBand
* m_rubberBand
;
732 int m_autoScrollIncrement
;
733 QTimer
* m_autoScrollTimer
;
735 KItemListHeader
* m_header
;
736 KItemListHeaderWidget
* m_headerWidget
;
738 // When dragging items into the view where the sort-role of the model
739 // is empty, a visual indicator should be shown during dragging where
740 // the dropping will happen. This indicator is specified by an index
741 // of the item. -1 means that no indicator will be shown at all.
742 // The m_dropIndicator is set by the KItemListController
743 // by KItemListView::showDropIndicator() and KItemListView::hideDropIndicator().
744 QRectF m_dropIndicator
;
746 friend class KItemListContainer
; // Accesses scrollBarRequired()
747 friend class KItemListHeader
; // Accesses m_headerWidget
748 friend class KItemListController
;
749 friend class KItemListControllerTest
;
750 friend class KItemListViewAccessible
;
751 friend class KItemListAccessibleCell
;
755 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
756 * by recycling existing QGraphicsWidgets instances. Is used by
757 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
760 class DOLPHIN_EXPORT KItemListCreatorBase
763 virtual ~KItemListCreatorBase();
766 void addCreatedWidget(QGraphicsWidget
* widget
);
767 void pushRecycleableWidget(QGraphicsWidget
* widget
);
768 QGraphicsWidget
* popRecycleableWidget();
771 QSet
<QGraphicsWidget
*> m_createdWidgets
;
772 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
776 * @brief Base class for creating KItemListWidgets.
778 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
779 * For a custom implementation the methods create(), itemSizeHint() and preferredColumnWith()
780 * must be reimplemented. The intention of the widget creator is to prevent repetitive and
781 * expensive instantiations and deletions of KItemListWidgets by recycling existing widget
784 class DOLPHIN_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
787 ~KItemListWidgetCreatorBase() override
;
789 virtual KItemListWidget
* create(KItemListView
* view
) = 0;
791 virtual void recycle(KItemListWidget
* widget
);
793 virtual void calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const = 0;
795 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
797 const KItemListView
* view
) const = 0;
801 * @brief Template class for creating KItemListWidgets.
804 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
807 KItemListWidgetCreator();
808 ~KItemListWidgetCreator() override
;
810 KItemListWidget
* create(KItemListView
* view
) override
;
812 void calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const override
;
814 qreal
preferredRoleColumnWidth(const QByteArray
& role
,
816 const KItemListView
* view
) const override
;
818 KItemListWidgetInformant
* m_informant
;
822 KItemListWidgetCreator
<T
>::KItemListWidgetCreator() :
823 m_informant(T::createInformant())
828 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
834 KItemListWidget
* KItemListWidgetCreator
<T
>::create(KItemListView
* view
)
836 KItemListWidget
* widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
838 widget
= new T(m_informant
, view
);
839 addCreatedWidget(widget
);
845 void KItemListWidgetCreator
<T
>::calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const
847 return m_informant
->calculateItemSizeHints(logicalHeightHints
, logicalWidthHint
, view
);
851 qreal KItemListWidgetCreator
<T
>::preferredRoleColumnWidth(const QByteArray
& role
,
853 const KItemListView
* view
) const
855 return m_informant
->preferredRoleColumnWidth(role
, index
, view
);
859 * @brief Base class for creating KItemListGroupHeaders.
861 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
862 * For a custom implementation the methods create() and recyle() must be reimplemented.
863 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
864 * deletions of KItemListGroupHeaders by recycling existing header instances.
866 class DOLPHIN_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
869 ~KItemListGroupHeaderCreatorBase() override
;
870 virtual KItemListGroupHeader
* create(KItemListView
* view
) = 0;
871 virtual void recycle(KItemListGroupHeader
* header
);
875 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
878 ~KItemListGroupHeaderCreator() override
;
879 KItemListGroupHeader
* create(KItemListView
* view
) override
;
883 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
888 KItemListGroupHeader
* KItemListGroupHeaderCreator
<T
>::create(KItemListView
* view
)
890 KItemListGroupHeader
* widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
892 widget
= new T(view
);
893 addCreatedWidget(widget
);