1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on the Itemviews NG project from Trolltech Labs: *
5 * http://qt.gitorious.org/qt-labs/itemviews-ng *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
21 ***************************************************************************/
23 #ifndef KITEMLISTVIEW_H
24 #define KITEMLISTVIEW_H
26 #include "dolphin_export.h"
27 #include "kitemviews/kitemliststyleoption.h"
28 #include "kitemviews/kitemlistwidget.h"
29 #include "kitemviews/kitemmodelbase.h"
30 #include "kitemviews/kstandarditemlistgroupheader.h"
31 #include "kitemviews/private/kitemlistviewanimation.h"
33 #include <QGraphicsWidget>
36 class KItemListController
;
37 class KItemListGroupHeaderCreatorBase
;
38 class KItemListHeader
;
39 class KItemListHeaderWidget
;
40 class KItemListSizeHintResolver
;
41 class KItemListRubberBand
;
42 class KItemListViewAnimation
;
43 class KItemListViewLayouter
;
44 class KItemListWidget
;
45 class KItemListWidgetInformant
;
46 class KItemListWidgetCreatorBase
;
50 * @brief Represents the view of an item-list.
52 * The view is responsible for showing the items of the model within
53 * a GraphicsItem. Each visible item is represented by a KItemListWidget.
55 * The created view must be applied to the KItemListController with
56 * KItemListController::setView() or with the constructor of
57 * KItemListController.
59 * @see KItemListWidget
62 class DOLPHIN_EXPORT KItemListView
: public QGraphicsWidget
66 Q_PROPERTY(qreal scrollOffset READ scrollOffset WRITE setScrollOffset
)
67 Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset
)
70 explicit KItemListView(QGraphicsWidget
* parent
= nullptr);
71 ~KItemListView() override
;
74 * Offset of the scrollbar that represents the scroll-orientation
75 * (see setScrollOrientation()).
77 void setScrollOffset(qreal offset
);
78 qreal
scrollOffset() const;
80 qreal
maximumScrollOffset() const;
83 * Offset related to an item, that does not fit into the available
84 * size of the listview. If the scroll-orientation is vertical
85 * the item-offset describes the offset of the horizontal axe, if
86 * the scroll-orientation is horizontal the item-offset describes
87 * the offset of the vertical axe.
89 void setItemOffset(qreal scrollOffset
);
90 qreal
itemOffset() const;
92 qreal
maximumItemOffset() const;
94 int maximumVisibleItems() const;
96 void setVisibleRoles(const QList
<QByteArray
>& roles
);
97 QList
<QByteArray
> visibleRoles() const;
100 * If set to true an automatic scrolling is done as soon as the
101 * mouse is moved near the borders of the view. Per default
102 * the automatic scrolling is turned off.
104 void setAutoScroll(bool enabled
);
105 bool autoScroll() const;
108 * If set to true selection-toggles will be shown when hovering
109 * an item. Per default the selection-toggles are disabled.
111 void setEnabledSelectionToggles(bool enabled
);
112 bool enabledSelectionToggles() const;
115 * @return Controller of the item-list. The controller gets
116 * initialized by KItemListController::setView() and will
117 * result in calling KItemListController::onControllerChanged().
119 KItemListController
* controller() const;
122 * @return Model of the item-list. The model gets
123 * initialized by KItemListController::setModel() and will
124 * result in calling KItemListController::onModelChanged().
126 KItemModelBase
* model() const;
129 * Sets the creator that creates a widget showing the
130 * content of one model-item. Usually it is sufficient
131 * to implement a custom widget X derived from KItemListWidget and
132 * set the creator by:
134 * itemListView->setWidgetCreator(new KItemListWidgetCreator<X>());
136 * The ownership of the widget creator is transferred to
137 * the item-list view.
139 void setWidgetCreator(KItemListWidgetCreatorBase
* widgetCreator
);
140 KItemListWidgetCreatorBase
* widgetCreator() const;
143 * Sets the creator that creates a group header. Usually it is sufficient
144 * to implement a custom header widget X derived from KItemListGroupHeader and
145 * set the creator by:
147 * itemListView->setGroupHeaderCreator(new KItemListGroupHeaderCreator<X>());
149 * The ownership of the gropup header creator is transferred to
150 * the item-list view.
152 void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
* groupHeaderCreator
);
153 KItemListGroupHeaderCreatorBase
* groupHeaderCreator() const;
156 * @return The basic size of all items. The size of an item may be larger than
157 * the basic size (see KItemListView::itemRect()).
159 QSizeF
itemSize() const;
161 const KItemListStyleOption
& styleOption() const;
163 void setGeometry(const QRectF
& rect
) override
;
166 * @return The page step which should be used by the vertical scroll bar.
167 * This is the height of the view except for the header widget.
169 qreal
verticalPageStep() const;
172 * @return Index of the item that is below the point \a pos.
173 * The position is relative to the upper right of
174 * the visible area. Only (at least partly) visible
175 * items are considered. -1 is returned if no item is
176 * below the position.
178 int itemAt(const QPointF
& pos
) const;
179 bool isAboveSelectionToggle(int index
, const QPointF
& pos
) const;
180 bool isAboveExpansionToggle(int index
, const QPointF
& pos
) const;
181 bool isAboveText(int index
, const QPointF
& pos
) const;
184 * @return Index of the first item that is at least partly visible.
185 * -1 is returned if the model contains no items.
187 int firstVisibleIndex() const;
190 * @return Index of the last item that is at least partly visible.
191 * -1 is returned if the model contains no items.
193 int lastVisibleIndex() const;
196 * Calculates the required size for all items in the model.
197 * It might be larger than KItemListView::itemSize().
198 * In this case the layout grid will be stretched to assure an
201 * @note the logical height (width) is actually the
202 * width (height) if the scroll orientation is Qt::Vertical!
204 void calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
) const;
207 * If set to true, items having child-items can be expanded to show the child-items as
208 * part of the view. Per default the expanding of items is disabled. If expanding of
209 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
210 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
211 * must be reimplemented. The view-implementation
212 * has to take care itself how to visually represent the expanded items provided
215 void setSupportsItemExpanding(bool supportsExpanding
);
216 bool supportsItemExpanding() const;
219 * @return The rectangle of the item relative to the top/left of
220 * the currently visible area (see KItemListView::offset()).
222 QRectF
itemRect(int index
) const;
225 * @return The context rectangle of the item relative to the top/left of
226 * the currently visible area (see KItemListView::offset()). The
227 * context rectangle is defined by the united rectangle of
228 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
229 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
230 * a tooltip or a context-menu for an item. Note that a context rectangle will
231 * only be returned for (at least partly) visible items. An empty rectangle will
232 * be returned for fully invisible items.
234 QRectF
itemContextRect(int index
) const;
237 * Scrolls to the item with the index \a index so that the item
238 * will be fully visible.
240 void scrollToItem(int index
);
243 * If several properties of KItemListView are changed synchronously, it is
244 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
245 * This prevents unnecessary and expensive layout-calculations.
247 void beginTransaction();
250 * Counterpart to beginTransaction(). The layout changes will only be animated if
251 * all property changes between beginTransaction() and endTransaction() support
254 void endTransaction();
256 bool isTransactionActive() const;
259 * Turns on the header if \p visible is true. Per default the
260 * header is not visible. Usually the header is turned on when
261 * showing a classic "table-view" to describe the shown columns.
263 void setHeaderVisible(bool visible
);
264 bool isHeaderVisible() const;
267 * @return Header of the list. The header is also available if it is not shown
268 * (see KItemListView::setHeaderShown()).
270 KItemListHeader
* header() const;
273 * @return Pixmap that is used for a drag operation based on the
274 * items given by \a indexes.
276 virtual QPixmap
createDragPixmap(const KItemSet
& indexes
) const;
279 * Lets the user edit the role \a role for item with the index \a index.
281 void editRole(int index
, const QByteArray
& role
);
283 void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= nullptr) override
;
286 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
287 void scrollOffsetChanged(qreal current
, qreal previous
);
288 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
289 void itemOffsetChanged(qreal current
, qreal previous
);
290 void maximumItemOffsetChanged(qreal current
, qreal previous
);
291 void scrollTo(qreal newOffset
);
294 * Is emitted if the user has changed the sort order by clicking on a
295 * header item (see KItemListView::setHeaderShown()). The sort order
296 * of the model has already been adjusted to
297 * the current sort order. Note that no signal will be emitted if the
298 * sort order of the model has been changed without user interaction.
300 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
303 * Is emitted if the user has changed the sort role by clicking on a
304 * header item (see KItemListView::setHeaderShown()). The sort role
305 * of the model has already been adjusted to
306 * the current sort role. Note that no signal will be emitted if the
307 * sort role of the model has been changed without user interaction.
309 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
312 * Is emitted if the user has changed the visible roles by moving a header
313 * item (see KItemListView::setHeaderShown()). Note that no signal will be
314 * emitted if the roles have been changed without user interaction by
315 * KItemListView::setVisibleRoles().
317 void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
319 void roleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
320 void roleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
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();
394 virtual void slotItemsInserted(const KItemRangeList
& itemRanges
);
395 virtual void slotItemsRemoved(const KItemRangeList
& itemRanges
);
396 virtual void slotItemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
397 virtual void slotItemsChanged(const KItemRangeList
& itemRanges
,
398 const QSet
<QByteArray
>& roles
);
399 virtual void slotGroupsChanged();
401 virtual void slotGroupedSortingChanged(bool current
);
402 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
403 virtual void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
404 virtual void slotCurrentChanged(int current
, int previous
);
405 virtual void slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
);
408 void slotAnimationFinished(QGraphicsWidget
* widget
,
409 KItemListViewAnimation::AnimationType type
);
410 void slotLayoutTimerFinished();
412 void slotRubberBandPosChanged();
413 void slotRubberBandActivationChanged(bool active
);
416 * Is invoked if the column-width of one role in the header has
417 * been changed by the user. The automatic resizing of columns
418 * will be turned off as soon as this method has been called at
421 void slotHeaderColumnWidthChanged(const QByteArray
& role
,
423 qreal previousWidth
);
426 * Is invoked if a column has been moved by the user. Applies
427 * the moved role to the view.
429 void slotHeaderColumnMoved(const QByteArray
& role
,
434 * Triggers the autoscrolling if autoScroll() is enabled by checking the
435 * current mouse position. If the mouse position is within the autoscroll
436 * margins a timer will be started that periodically triggers the autoscrolling.
438 void triggerAutoScrolling();
441 * Is invoked if the geometry of the parent-widget from a group-header has been
442 * changed. The x-position and width of the group-header gets adjusted to assure
443 * that it always spans the whole width even during temporary transitions of the
446 void slotGeometryOfGroupHeaderParentChanged();
448 void slotRoleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
449 void slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
452 enum LayoutAnimationHint
464 void setController(KItemListController
* controller
);
465 void setModel(KItemModelBase
* model
);
467 KItemListRubberBand
* rubberBand() const;
469 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
472 * Helper method for doLayout: Returns a list of items that can be reused for the visible
473 * area. Invisible group headers get recycled. The reusable items are items that are
474 * invisible. If the animation hint is 'Animation' then items that are currently animated
475 * won't be reused. Reusing items is faster in comparison to deleting invisible
476 * items and creating a new instance for visible items.
478 QList
<int> recycleInvisibleItems(int firstVisibleIndex
,
479 int lastVisibleIndex
,
480 LayoutAnimationHint hint
);
483 * Helper method for doLayout: Starts a moving-animation for the widget to the given
484 * new position. The moving-animation is only started if the new position is within
485 * the same row or column, otherwise the create-animation is used instead.
486 * @return True if the moving-animation has been applied.
488 bool moveWidget(KItemListWidget
* widget
, const QPointF
& newPos
);
490 void emitOffsetChanges();
492 KItemListWidget
* createWidget(int index
);
493 void recycleWidget(KItemListWidget
* widget
);
496 * Changes the index of the widget to \a index and assures a consistent
497 * update for m_visibleItems and m_visibleCells. The cell-information
498 * for the new index will not be updated and be initialized as empty cell.
500 void setWidgetIndex(KItemListWidget
* widget
, int index
);
503 * Changes the index of the widget to \a index. In opposite to
504 * setWidgetIndex() the cell-information for the widget gets updated.
505 * This update gives doLayout() the chance to animate the moving
506 * of the item visually (see moveWidget()).
508 void moveWidgetToIndex(KItemListWidget
* widget
, int index
);
511 * Helper method for prepareLayoutForIncreasedItemCount().
513 void setLayouterSize(const QSizeF
& size
, SizeType sizeType
);
516 * Helper method for createWidget() and setWidgetIndex() to update the properties
517 * of the itemlist widget.
519 void updateWidgetProperties(KItemListWidget
* widget
, int index
);
522 * Helper method for updateWidgetPropertes() to create or update
523 * the itemlist group-header.
525 void updateGroupHeaderForWidget(KItemListWidget
* widget
);
528 * Updates the position and size of the group-header that belongs
529 * to the itemlist widget \a widget. The given widget must represent
530 * the first item of a group.
532 void updateGroupHeaderLayout(KItemListWidget
* widget
);
535 * Recycles the group-header for the widget.
537 void recycleGroupHeaderForWidget(KItemListWidget
* widget
);
540 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
541 * and slotSortRoleChanged(): Iterates through all visible items and updates
542 * the group-header widgets.
544 void updateVisibleGroupHeaders();
547 * @return Index for the item in the list returned by KItemModelBase::groups()
548 * that represents the group where the item with the index \a index
549 * belongs to. -1 is returned if no groups are available.
551 int groupIndexForItem(int index
) const;
554 * Updates the alternate background for all visible items.
555 * @see updateAlternateBackgroundForWidget()
557 void updateAlternateBackgrounds();
560 * Updates the alternateBackground-property of the widget dependent
561 * on the state of useAlternateBackgrounds() and the grouping state.
563 void updateAlternateBackgroundForWidget(KItemListWidget
* widget
);
566 * @return True if alternate backgrounds should be used for the items.
567 * This is the case if an empty item-size is given and if there
568 * is more than one visible role.
570 bool useAlternateBackgrounds() const;
573 * @param itemRanges Items that must be checked for getting the widths of columns.
574 * @return The preferred width of the column of each visible role. The width will
575 * be respected if the width of the item size is <= 0 (see
576 * KItemListView::setItemSize()). Per default an empty hash
579 QHash
<QByteArray
, qreal
> preferredColumnWidths(const KItemRangeList
& itemRanges
) const;
582 * Applies the column-widths from m_headerWidget to the layout
585 void applyColumnWidthsFromHeader();
588 * Applies the column-widths from m_headerWidget to \a widget.
590 void updateWidgetColumnWidths(KItemListWidget
* widget
);
593 * Updates the preferred column-widths of m_groupHeaderWidget by
594 * invoking KItemListView::columnWidths().
596 void updatePreferredColumnWidths(const KItemRangeList
& itemRanges
);
599 * Convenience method for
600 * updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model->count()).
602 void updatePreferredColumnWidths();
605 * Resizes the column-widths of m_headerWidget based on the preferred widths
606 * and the vailable view-size.
608 void applyAutomaticColumnWidths();
611 * @return Sum of the widths of all columns.
613 qreal
columnWidthsSum() const;
616 * @return Boundaries of the header. An empty rectangle is returned
617 * if no header is shown.
619 QRectF
headerBoundaries() const;
622 * @return True if the number of columns or rows will be changed when applying
623 * the new grid- and item-size. Used to determine whether an animation
624 * should be done when applying the new layout.
626 bool changesItemGridLayout(const QSizeF
& newGridSize
,
627 const QSizeF
& newItemSize
,
628 const QSizeF
& newItemMargin
) const;
631 * @param changedItemCount Number of inserted or removed items.
632 * @return True if the inserting or removing of items should be animated.
633 * No animation should be done if the number of items is too large
634 * to provide a pleasant animation.
636 bool animateChangedItemCount(int changedItemCount
) const;
639 * @return True if a scrollbar for the given scroll-orientation is required
640 * when using a size of \p size for the view. Calling the method is rather
641 * expansive as a temporary relayout needs to be done.
643 bool scrollBarRequired(const QSizeF
& size
) const;
646 * Shows a drop-indicator between items dependent on the given
647 * cursor position. The cursor position is relative to the upper left
649 * @return Index of the item where the dropping is done. An index of -1
650 * indicates that the item has been dropped after the last item.
652 int showDropIndicator(const QPointF
& pos
);
653 void hideDropIndicator();
656 * Applies the height of the group header to the layouter. The height
657 * depends on the used scroll orientation.
659 void updateGroupHeaderHeight();
662 * Updates the siblings-information for all visible items that are inside
663 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
664 * is smaller than 0, the siblings-information for all visible items gets
666 * @see KItemListWidget::setSiblingsInformation()
668 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
671 * Helper method for updateExpansionIndicators().
672 * @return True if the item with the index \a index has a sibling successor
673 * (= the item is not the last item of the current hierarchy).
675 bool hasSiblingSuccessor(int index
) const;
678 * Helper method for slotRoleEditingCanceled() and slotRoleEditingFinished().
679 * Disconnects the two Signals "roleEditingCanceled" and
680 * "roleEditingFinished"
682 void disconnectRoleEditingSignals(int index
);
685 * Helper function for triggerAutoScrolling().
686 * @param pos Logical position of the mouse relative to the range.
687 * @param range Range of the visible area.
688 * @param oldInc Previous increment. Is used to assure that the increment
689 * increases only gradually.
690 * @return Scroll increment that should be added to the offset().
691 * As soon as \a pos is inside the autoscroll-margin a
692 * value != 0 will be returned.
694 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
697 * Helper functions for changesItemCount().
698 * @return The number of items that fit into the available size by
699 * respecting the size of the item and the margin between the items.
701 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
704 bool m_enabledSelectionToggles
;
706 bool m_supportsItemExpanding
;
708 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
709 LayoutAnimationHint m_endTransactionAnimationHint
;
712 KItemListController
* m_controller
;
713 KItemModelBase
* m_model
;
714 QList
<QByteArray
> m_visibleRoles
;
715 mutable KItemListWidgetCreatorBase
* m_widgetCreator
;
716 mutable KItemListGroupHeaderCreatorBase
* m_groupHeaderCreator
;
717 KItemListStyleOption m_styleOption
;
719 QHash
<int, KItemListWidget
*> m_visibleItems
;
720 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
724 Cell() : column(-1), row(-1) {}
725 Cell(int c
, int r
) : column(c
), row(r
) {}
729 QHash
<int, Cell
> m_visibleCells
;
731 int m_scrollBarExtent
;
732 KItemListSizeHintResolver
* m_sizeHintResolver
;
733 KItemListViewLayouter
* m_layouter
;
734 KItemListViewAnimation
* m_animation
;
736 QTimer
* m_layoutTimer
; // Triggers an asynchronous doLayout() call.
737 qreal m_oldScrollOffset
;
738 qreal m_oldMaximumScrollOffset
;
739 qreal m_oldItemOffset
;
740 qreal m_oldMaximumItemOffset
;
742 bool m_skipAutoScrollForRubberBand
;
743 KItemListRubberBand
* m_rubberBand
;
746 int m_autoScrollIncrement
;
747 QTimer
* m_autoScrollTimer
;
749 KItemListHeader
* m_header
;
750 KItemListHeaderWidget
* m_headerWidget
;
752 // When dragging items into the view where the sort-role of the model
753 // is empty, a visual indicator should be shown during dragging where
754 // the dropping will happen. This indicator is specified by an index
755 // of the item. -1 means that no indicator will be shown at all.
756 // The m_dropIndicator is set by the KItemListController
757 // by KItemListView::showDropIndicator() and KItemListView::hideDropIndicator().
758 QRectF m_dropIndicator
;
760 friend class KItemListContainer
; // Accesses scrollBarRequired()
761 friend class KItemListHeader
; // Accesses m_headerWidget
762 friend class KItemListController
;
763 friend class KItemListControllerTest
;
764 friend class KItemListViewAccessible
;
765 friend class KItemListAccessibleCell
;
769 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
770 * by recycling existing QGraphicsWidgets instances. Is used by
771 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
774 class DOLPHIN_EXPORT KItemListCreatorBase
777 virtual ~KItemListCreatorBase();
780 void addCreatedWidget(QGraphicsWidget
* widget
);
781 void pushRecycleableWidget(QGraphicsWidget
* widget
);
782 QGraphicsWidget
* popRecycleableWidget();
785 QSet
<QGraphicsWidget
*> m_createdWidgets
;
786 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
790 * @brief Base class for creating KItemListWidgets.
792 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
793 * For a custom implementation the methods create(), itemSizeHint() and preferredColumnWith()
794 * must be reimplemented. The intention of the widget creator is to prevent repetitive and
795 * expensive instantiations and deletions of KItemListWidgets by recycling existing widget
798 class DOLPHIN_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
801 ~KItemListWidgetCreatorBase() override
;
803 virtual KItemListWidget
* create(KItemListView
* view
) = 0;
805 virtual void recycle(KItemListWidget
* widget
);
807 virtual void calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const = 0;
809 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
811 const KItemListView
* view
) const = 0;
815 * @brief Template class for creating KItemListWidgets.
818 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
821 KItemListWidgetCreator();
822 ~KItemListWidgetCreator() override
;
824 KItemListWidget
* create(KItemListView
* view
) override
;
826 void calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const override
;
828 qreal
preferredRoleColumnWidth(const QByteArray
& role
,
830 const KItemListView
* view
) const override
;
832 KItemListWidgetInformant
* m_informant
;
836 KItemListWidgetCreator
<T
>::KItemListWidgetCreator() :
837 m_informant(T::createInformant())
842 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
848 KItemListWidget
* KItemListWidgetCreator
<T
>::create(KItemListView
* view
)
850 KItemListWidget
* widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
852 widget
= new T(m_informant
, view
);
853 addCreatedWidget(widget
);
859 void KItemListWidgetCreator
<T
>::calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const
861 return m_informant
->calculateItemSizeHints(logicalHeightHints
, logicalWidthHint
, view
);
865 qreal KItemListWidgetCreator
<T
>::preferredRoleColumnWidth(const QByteArray
& role
,
867 const KItemListView
* view
) const
869 return m_informant
->preferredRoleColumnWidth(role
, index
, view
);
873 * @brief Base class for creating KItemListGroupHeaders.
875 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
876 * For a custom implementation the methods create() and recyle() must be reimplemented.
877 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
878 * deletions of KItemListGroupHeaders by recycling existing header instances.
880 class DOLPHIN_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
883 ~KItemListGroupHeaderCreatorBase() override
;
884 virtual KItemListGroupHeader
* create(KItemListView
* view
) = 0;
885 virtual void recycle(KItemListGroupHeader
* header
);
889 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
892 ~KItemListGroupHeaderCreator() override
;
893 KItemListGroupHeader
* create(KItemListView
* view
) override
;
897 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
902 KItemListGroupHeader
* KItemListGroupHeaderCreator
<T
>::create(KItemListView
* view
)
904 KItemListGroupHeader
* widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
906 widget
= new T(view
);
907 addCreatedWidget(widget
);