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"
28 #include <kitemviews/kstandarditemlistgroupheader.h>
29 #include <kitemviews/kitemliststyleoption.h>
30 #include <kitemviews/kitemlistwidget.h>
31 #include <kitemviews/kitemmodelbase.h>
32 #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 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;
162 * @return The size hint of all items. It is provided by the KItemListSizeHintResolver.
164 QSizeF
itemSizeHint() const;
166 const KItemListStyleOption
& styleOption() const;
168 void setGeometry(const QRectF
& rect
) override
;
171 * @return The page step which should be used by the vertical scroll bar.
172 * This is the height of the view except for the header widget.
174 qreal
verticalPageStep() const;
177 * @return Index of the item that is below the point \a pos.
178 * The position is relative to the upper right of
179 * the visible area. Only (at least partly) visible
180 * items are considered. -1 is returned if no item is
181 * below the position.
183 int itemAt(const QPointF
& pos
) const;
184 bool isAboveSelectionToggle(int index
, const QPointF
& pos
) const;
185 bool isAboveExpansionToggle(int index
, const QPointF
& pos
) const;
186 bool isAboveText(int index
, const QPointF
& pos
) const;
189 * @return Index of the first item that is at least partly visible.
190 * -1 is returned if the model contains no items.
192 int firstVisibleIndex() const;
195 * @return Index of the last item that is at least partly visible.
196 * -1 is returned if the model contains no items.
198 int lastVisibleIndex() const;
201 * Calculates the required size for all items in the model.
202 * It might be larger than KItemListView::itemSize().
203 * In this case the layout grid will be stretched to assure an
206 * @note the logical height (width) is actually the
207 * width (height) if the scroll orientation is Qt::Vertical!
209 void calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
) const;
212 * If set to true, items having child-items can be expanded to show the child-items as
213 * part of the view. Per default the expanding of items is is disabled. If expanding of
214 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
215 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
216 * must be reimplemented. The view-implementation
217 * has to take care itself how to visually represent the expanded items provided
220 void setSupportsItemExpanding(bool supportsExpanding
);
221 bool supportsItemExpanding() const;
224 * @return The rectangle of the item relative to the top/left of
225 * the currently visible area (see KItemListView::offset()).
227 QRectF
itemRect(int index
) const;
230 * @return The context rectangle of the item relative to the top/left of
231 * the currently visible area (see KItemListView::offset()). The
232 * context rectangle is defined by by the united rectangle of
233 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
234 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
235 * a tooltip or a context-menu for an item. Note that a context rectangle will
236 * only be returned for (at least partly) visible items. An empty rectangle will
237 * be returned for fully invisible items.
239 QRectF
itemContextRect(int index
) const;
242 * Scrolls to the item with the index \a index so that the item
243 * will be fully visible.
245 void scrollToItem(int index
);
248 * If several properties of KItemListView are changed synchronously, it is
249 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
250 * This prevents unnecessary and expensive layout-calculations.
252 void beginTransaction();
255 * Counterpart to beginTransaction(). The layout changes will only be animated if
256 * all property changes between beginTransaction() and endTransaction() support
259 void endTransaction();
261 bool isTransactionActive() const;
264 * Turns on the header if \p visible is true. Per default the
265 * header is not visible. Usually the header is turned on when
266 * showing a classic "table-view" to describe the shown columns.
268 void setHeaderVisible(bool visible
);
269 bool isHeaderVisible() const;
272 * @return Header of the list. The header is also available if it is not shown
273 * (see KItemListView::setHeaderShown()).
275 KItemListHeader
* header() const;
278 * @return Pixmap that is used for a drag operation based on the
279 * items given by \a indexes.
281 virtual QPixmap
createDragPixmap(const KItemSet
& indexes
) const;
284 * Lets the user edit the role \a role for item with the index \a index.
286 void editRole(int index
, const QByteArray
& role
);
288 void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= nullptr) override
;
291 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
292 void scrollOffsetChanged(qreal current
, qreal previous
);
293 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
294 void itemOffsetChanged(qreal current
, qreal previous
);
295 void maximumItemOffsetChanged(qreal current
, qreal previous
);
296 void scrollTo(qreal newOffset
);
299 * Is emitted if the user has changed the sort order by clicking on a
300 * header item (see KItemListView::setHeaderShown()). The sort order
301 * of the model has already been adjusted to
302 * the current sort order. Note that no signal will be emitted if the
303 * sort order of the model has been changed without user interaction.
305 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
308 * Is emitted if the user has changed the sort role by clicking on a
309 * header item (see KItemListView::setHeaderShown()). The sort role
310 * of the model has already been adjusted to
311 * the current sort role. Note that no signal will be emitted if the
312 * sort role of the model has been changed without user interaction.
314 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
317 * Is emitted if the user has changed the visible roles by moving a header
318 * item (see KItemListView::setHeaderShown()). Note that no signal will be
319 * emitted if the roles have been changed without user interaction by
320 * KItemListView::setVisibleRoles().
322 void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
324 void roleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
325 void roleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
328 QVariant
itemChange(GraphicsItemChange change
, const QVariant
&value
) override
;
329 void setItemSize(const QSizeF
& size
);
330 void setStyleOption(const KItemListStyleOption
& option
);
333 * If the scroll-orientation is vertical, the items are ordered
334 * from top to bottom (= default setting). If the scroll-orientation
335 * is horizontal, the items are ordered from left to right.
337 void setScrollOrientation(Qt::Orientation orientation
);
338 Qt::Orientation
scrollOrientation() const;
341 * Factory method for creating a default widget-creator. The method will be used
342 * in case if setWidgetCreator() has not been set by the application.
343 * @return New instance of the widget-creator that should be used per
346 virtual KItemListWidgetCreatorBase
* defaultWidgetCreator() const;
349 * Factory method for creating a default group-header-creator. The method will be used
350 * in case if setGroupHeaderCreator() has not been set by the application.
351 * @return New instance of the group-header-creator that should be used per
354 virtual KItemListGroupHeaderCreatorBase
* defaultGroupHeaderCreator() const;
357 * Is called when creating a new KItemListWidget instance and allows derived
358 * classes to do a custom initialization.
360 virtual void initializeItemListWidget(KItemListWidget
* item
);
363 * @return True if at least one of the changed roles \p changedRoles might result
364 * in the need to update the item-size hint (see KItemListView::itemSizeHint()).
365 * Per default true is returned which means on each role-change of existing items
366 * the item-size hints are recalculated. For performance reasons it is recommended
367 * to return false in case if a role-change will not result in a changed
370 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
>& changedRoles
) const;
372 virtual void onControllerChanged(KItemListController
* current
, KItemListController
* previous
);
373 virtual void onModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
375 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
376 virtual void onItemSizeChanged(const QSizeF
& current
, const QSizeF
& previous
);
377 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
378 virtual void onVisibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
379 virtual void onStyleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
380 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
382 virtual void onTransactionBegin();
383 virtual void onTransactionEnd();
385 bool event(QEvent
* event
) override
;
386 void mousePressEvent(QGraphicsSceneMouseEvent
* event
) override
;
387 void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
) override
;
388 void dragEnterEvent(QGraphicsSceneDragDropEvent
* event
) override
;
389 void dragMoveEvent(QGraphicsSceneDragDropEvent
* event
) override
;
390 void dragLeaveEvent(QGraphicsSceneDragDropEvent
* event
) override
;
391 void dropEvent(QGraphicsSceneDragDropEvent
* event
) override
;
393 QList
<KItemListWidget
*> visibleItemListWidgets() const;
395 virtual void updateFont();
396 virtual void updatePalette();
399 virtual void slotItemsInserted(const KItemRangeList
& itemRanges
);
400 virtual void slotItemsRemoved(const KItemRangeList
& itemRanges
);
401 virtual void slotItemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
402 virtual void slotItemsChanged(const KItemRangeList
& itemRanges
,
403 const QSet
<QByteArray
>& roles
);
404 virtual void slotGroupsChanged();
406 virtual void slotGroupedSortingChanged(bool current
);
407 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
408 virtual void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
409 virtual void slotCurrentChanged(int current
, int previous
);
410 virtual void slotSelectionChanged(const KItemSet
& current
, const KItemSet
& previous
);
413 void slotAnimationFinished(QGraphicsWidget
* widget
,
414 KItemListViewAnimation::AnimationType type
);
415 void slotLayoutTimerFinished();
417 void slotRubberBandPosChanged();
418 void slotRubberBandActivationChanged(bool active
);
421 * Is invoked if the column-width of one role in the header has
422 * been changed by the user. The automatic resizing of columns
423 * will be turned off as soon as this method has been called at
426 void slotHeaderColumnWidthChanged(const QByteArray
& role
,
428 qreal previousWidth
);
431 * Is invoked if a column has been moved by the user. Applies
432 * the moved role to the view.
434 void slotHeaderColumnMoved(const QByteArray
& role
,
439 * Triggers the autoscrolling if autoScroll() is enabled by checking the
440 * current mouse position. If the mouse position is within the autoscroll
441 * margins a timer will be started that periodically triggers the autoscrolling.
443 void triggerAutoScrolling();
446 * Is invoked if the geometry of the parent-widget from a group-header has been
447 * changed. The x-position and width of the group-header gets adjusted to assure
448 * that it always spans the whole width even during temporary transitions of the
451 void slotGeometryOfGroupHeaderParentChanged();
453 void slotRoleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
454 void slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
457 enum LayoutAnimationHint
469 void setController(KItemListController
* controller
);
470 void setModel(KItemModelBase
* model
);
472 KItemListRubberBand
* rubberBand() const;
474 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
477 * Helper method for doLayout: Returns a list of items that can be reused for the visible
478 * area. Invisible group headers get recycled. The reusable items are items that are
479 * invisible. If the animation hint is 'Animation' then items that are currently animated
480 * won't be reused. Reusing items is faster in comparison to deleting invisible
481 * items and creating a new instance for visible items.
483 QList
<int> recycleInvisibleItems(int firstVisibleIndex
,
484 int lastVisibleIndex
,
485 LayoutAnimationHint hint
);
488 * Helper method for doLayout: Starts a moving-animation for the widget to the given
489 * new position. The moving-animation is only started if the new position is within
490 * the same row or column, otherwise the create-animation is used instead.
491 * @return True if the moving-animation has been applied.
493 bool moveWidget(KItemListWidget
* widget
, const QPointF
& newPos
);
495 void emitOffsetChanges();
497 KItemListWidget
* createWidget(int index
);
498 void recycleWidget(KItemListWidget
* widget
);
501 * Changes the index of the widget to \a index and assures a consistent
502 * update for m_visibleItems and m_visibleCells. The cell-information
503 * for the new index will not be updated and be initialized as empty cell.
505 void setWidgetIndex(KItemListWidget
* widget
, int index
);
508 * Changes the index of the widget to \a index. In opposite to
509 * setWidgetIndex() the cell-information for the widget gets updated.
510 * This update gives doLayout() the chance to animate the moving
511 * of the item visually (see moveWidget()).
513 void moveWidgetToIndex(KItemListWidget
* widget
, int index
);
516 * Helper method for prepareLayoutForIncreasedItemCount().
518 void setLayouterSize(const QSizeF
& size
, SizeType sizeType
);
521 * Helper method for createWidget() and setWidgetIndex() to update the properties
522 * of the itemlist widget.
524 void updateWidgetProperties(KItemListWidget
* widget
, int index
);
527 * Helper method for updateWidgetPropertes() to create or update
528 * the itemlist group-header.
530 void updateGroupHeaderForWidget(KItemListWidget
* widget
);
533 * Updates the position and size of the group-header that belongs
534 * to the itemlist widget \a widget. The given widget must represent
535 * the first item of a group.
537 void updateGroupHeaderLayout(KItemListWidget
* widget
);
540 * Recycles the group-header for the widget.
542 void recycleGroupHeaderForWidget(KItemListWidget
* widget
);
545 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
546 * and slotSortRoleChanged(): Iterates through all visible items and updates
547 * the group-header widgets.
549 void updateVisibleGroupHeaders();
552 * @return Index for the item in the list returned by KItemModelBase::groups()
553 * that represents the group where the item with the index \a index
554 * belongs to. -1 is returned if no groups are available.
556 int groupIndexForItem(int index
) const;
559 * Updates the alternate background for all visible items.
560 * @see updateAlternateBackgroundForWidget()
562 void updateAlternateBackgrounds();
565 * Updates the alternateBackground-property of the widget dependent
566 * on the state of useAlternateBackgrounds() and the grouping state.
568 void updateAlternateBackgroundForWidget(KItemListWidget
* widget
);
571 * @return True if alternate backgrounds should be used for the items.
572 * This is the case if an empty item-size is given and if there
573 * is more than one visible role.
575 bool useAlternateBackgrounds() const;
578 * @param itemRanges Items that must be checked for getting the widths of columns.
579 * @return The preferred width of the column of each visible role. The width will
580 * be respected if the width of the item size is <= 0 (see
581 * KItemListView::setItemSize()). Per default an empty hash
584 QHash
<QByteArray
, qreal
> preferredColumnWidths(const KItemRangeList
& itemRanges
) const;
587 * Applies the column-widths from m_headerWidget to the layout
590 void applyColumnWidthsFromHeader();
593 * Applies the column-widths from m_headerWidget to \a widget.
595 void updateWidgetColumnWidths(KItemListWidget
* widget
);
598 * Updates the preferred column-widths of m_groupHeaderWidget by
599 * invoking KItemListView::columnWidths().
601 void updatePreferredColumnWidths(const KItemRangeList
& itemRanges
);
604 * Convenience method for
605 * updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model->count()).
607 void updatePreferredColumnWidths();
610 * Resizes the column-widths of m_headerWidget based on the preferred widths
611 * and the vailable view-size.
613 void applyAutomaticColumnWidths();
616 * @return Sum of the widths of all columns.
618 qreal
columnWidthsSum() const;
621 * @return Boundaries of the header. An empty rectangle is returned
622 * if no header is shown.
624 QRectF
headerBoundaries() const;
627 * @return True if the number of columns or rows will be changed when applying
628 * the new grid- and item-size. Used to determine whether an animation
629 * should be done when applying the new layout.
631 bool changesItemGridLayout(const QSizeF
& newGridSize
,
632 const QSizeF
& newItemSize
,
633 const QSizeF
& newItemMargin
) const;
636 * @param changedItemCount Number of inserted or removed items.
637 * @return True if the inserting or removing of items should be animated.
638 * No animation should be done if the number of items is too large
639 * to provide a pleasant animation.
641 bool animateChangedItemCount(int changedItemCount
) const;
644 * @return True if a scrollbar for the given scroll-orientation is required
645 * when using a size of \p size for the view. Calling the method is rather
646 * expansive as a temporary relayout needs to be done.
648 bool scrollBarRequired(const QSizeF
& size
) const;
651 * Shows a drop-indicator between items dependent on the given
652 * cursor position. The cursor position is relative to the upper left
654 * @return Index of the item where the dropping is done. An index of -1
655 * indicates that the item has been dropped after the last item.
657 int showDropIndicator(const QPointF
& pos
);
658 void hideDropIndicator();
661 * Applies the height of the group header to the layouter. The height
662 * depends on the used scroll orientation.
664 void updateGroupHeaderHeight();
667 * Updates the siblings-information for all visible items that are inside
668 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
669 * is smaller than 0, the siblings-information for all visible items gets
671 * @see KItemListWidget::setSiblingsInformation()
673 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
676 * Helper method for updateExpansionIndicators().
677 * @return True if the item with the index \a index has a sibling successor
678 * (= the item is not the last item of the current hierarchy).
680 bool hasSiblingSuccessor(int index
) const;
683 * Helper method for slotRoleEditingCanceled() and slotRoleEditingFinished().
684 * Disconnects the two Signals "roleEditingCanceled" and
685 * "roleEditingFinished"
687 void disconnectRoleEditingSignals(int index
);
690 * Helper function for triggerAutoScrolling().
691 * @param pos Logical position of the mouse relative to the range.
692 * @param range Range of the visible area.
693 * @param oldInc Previous increment. Is used to assure that the increment
694 * increases only gradually.
695 * @return Scroll increment that should be added to the offset().
696 * As soon as \a pos is inside the autoscroll-margin a
697 * value != 0 will be returned.
699 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
702 * Helper functions for changesItemCount().
703 * @return The number of items that fit into the available size by
704 * respecting the size of the item and the margin between the items.
706 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
709 bool m_enabledSelectionToggles
;
711 bool m_supportsItemExpanding
;
713 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
714 LayoutAnimationHint m_endTransactionAnimationHint
;
717 KItemListController
* m_controller
;
718 KItemModelBase
* m_model
;
719 QList
<QByteArray
> m_visibleRoles
;
720 mutable KItemListWidgetCreatorBase
* m_widgetCreator
;
721 mutable KItemListGroupHeaderCreatorBase
* m_groupHeaderCreator
;
722 KItemListStyleOption m_styleOption
;
724 QHash
<int, KItemListWidget
*> m_visibleItems
;
725 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
729 Cell() : column(-1), row(-1) {}
730 Cell(int c
, int r
) : column(c
), row(r
) {}
734 QHash
<int, Cell
> m_visibleCells
;
736 int m_scrollBarExtent
;
737 KItemListSizeHintResolver
* m_sizeHintResolver
;
738 KItemListViewLayouter
* m_layouter
;
739 KItemListViewAnimation
* m_animation
;
741 QTimer
* m_layoutTimer
; // Triggers an asynchronous doLayout() call.
742 qreal m_oldScrollOffset
;
743 qreal m_oldMaximumScrollOffset
;
744 qreal m_oldItemOffset
;
745 qreal m_oldMaximumItemOffset
;
747 bool m_skipAutoScrollForRubberBand
;
748 KItemListRubberBand
* m_rubberBand
;
751 int m_autoScrollIncrement
;
752 QTimer
* m_autoScrollTimer
;
754 KItemListHeader
* m_header
;
755 KItemListHeaderWidget
* m_headerWidget
;
757 // When dragging items into the view where the sort-role of the model
758 // is empty, a visual indicator should be shown during dragging where
759 // the dropping will happen. This indicator is specified by an index
760 // of the item. -1 means that no indicator will be shown at all.
761 // The m_dropIndicator is set by the KItemListController
762 // by KItemListView::showDropIndicator() and KItemListView::hideDropIndicator().
763 QRectF m_dropIndicator
;
765 friend class KItemListContainer
; // Accesses scrollBarRequired()
766 friend class KItemListHeader
; // Accesses m_headerWidget
767 friend class KItemListController
;
768 friend class KItemListControllerTest
;
769 friend class KItemListViewAccessible
;
770 friend class KItemListAccessibleCell
;
774 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
775 * by recycling existing QGraphicsWidgets instances. Is used by
776 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
779 class DOLPHIN_EXPORT KItemListCreatorBase
782 virtual ~KItemListCreatorBase();
785 void addCreatedWidget(QGraphicsWidget
* widget
);
786 void pushRecycleableWidget(QGraphicsWidget
* widget
);
787 QGraphicsWidget
* popRecycleableWidget();
790 QSet
<QGraphicsWidget
*> m_createdWidgets
;
791 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
795 * @brief Base class for creating KItemListWidgets.
797 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
798 * For a custom implementation the methods create(), itemSizeHint() and preferredColumnWith()
799 * must be reimplemented. The intention of the widget creator is to prevent repetitive and
800 * expensive instantiations and deletions of KItemListWidgets by recycling existing widget
803 class DOLPHIN_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
806 ~KItemListWidgetCreatorBase() override
;
808 virtual KItemListWidget
* create(KItemListView
* view
) = 0;
810 virtual void recycle(KItemListWidget
* widget
);
812 virtual void calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const = 0;
814 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
816 const KItemListView
* view
) const = 0;
820 * @brief Template class for creating KItemListWidgets.
823 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
826 KItemListWidgetCreator();
827 ~KItemListWidgetCreator() override
;
829 KItemListWidget
* create(KItemListView
* view
) override
;
831 void calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const override
;
833 qreal
preferredRoleColumnWidth(const QByteArray
& role
,
835 const KItemListView
* view
) const override
;
837 KItemListWidgetInformant
* m_informant
;
841 KItemListWidgetCreator
<T
>::KItemListWidgetCreator() :
842 m_informant(T::createInformant())
847 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
853 KItemListWidget
* KItemListWidgetCreator
<T
>::create(KItemListView
* view
)
855 KItemListWidget
* widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
857 widget
= new T(m_informant
, view
);
858 addCreatedWidget(widget
);
864 void KItemListWidgetCreator
<T
>::calculateItemSizeHints(QVector
<qreal
>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const
866 return m_informant
->calculateItemSizeHints(logicalHeightHints
, logicalWidthHint
, view
);
870 qreal KItemListWidgetCreator
<T
>::preferredRoleColumnWidth(const QByteArray
& role
,
872 const KItemListView
* view
) const
874 return m_informant
->preferredRoleColumnWidth(role
, index
, view
);
878 * @brief Base class for creating KItemListGroupHeaders.
880 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
881 * For a custom implementation the methods create() and recyle() must be reimplemented.
882 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
883 * deletions of KItemListGroupHeaders by recycling existing header instances.
885 class DOLPHIN_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
888 ~KItemListGroupHeaderCreatorBase() override
;
889 virtual KItemListGroupHeader
* create(KItemListView
* view
) = 0;
890 virtual void recycle(KItemListGroupHeader
* header
);
894 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
897 ~KItemListGroupHeaderCreator() override
;
898 KItemListGroupHeader
* create(KItemListView
* view
) override
;
902 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
907 KItemListGroupHeader
* KItemListGroupHeaderCreator
<T
>::create(KItemListView
* view
)
909 KItemListGroupHeader
* widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
911 widget
= new T(view
);
912 addCreatedWidget(widget
);