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 <libdolphin_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
;
47 class KItemListViewCreatorBase
;
51 * @brief Represents the view of an item-list.
53 * The view is responsible for showing the items of the model within
54 * a GraphicsItem. Each visible item is represented by a KItemListWidget.
56 * The created view must be applied to the KItemListController with
57 * KItemListController::setView() or with the constructor of
58 * KItemListController.
60 * @see KItemListWidget
63 class LIBDOLPHINPRIVATE_EXPORT KItemListView
: public QGraphicsWidget
67 Q_PROPERTY(qreal scrollOffset READ scrollOffset WRITE setScrollOffset
)
68 Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset
)
71 KItemListView(QGraphicsWidget
* parent
= 0);
72 virtual ~KItemListView();
75 * Offset of the scrollbar that represents the scroll-orientation
76 * (see setScrollOrientation()).
78 void setScrollOffset(qreal offset
);
79 qreal
scrollOffset() const;
81 qreal
maximumScrollOffset() const;
84 * Offset related to an item, that does not fit into the available
85 * size of the listview. If the scroll-orientation is vertical
86 * the item-offset describes the offset of the horizontal axe, if
87 * the scroll-orientation is horizontal the item-offset describes
88 * the offset of the vertical axe.
90 void setItemOffset(qreal scrollOffset
);
91 qreal
itemOffset() const;
93 qreal
maximumItemOffset() const;
95 int maximumVisibleItems() const;
97 void setVisibleRoles(const QList
<QByteArray
>& roles
);
98 QList
<QByteArray
> visibleRoles() const;
101 * If set to true an automatic scrolling is done as soon as the
102 * mouse is moved near the borders of the view. Per default
103 * the automatic scrolling is turned off.
105 void setAutoScroll(bool enabled
);
106 bool autoScroll() const;
109 * If set to true selection-toggles will be shown when hovering
110 * an item. Per default the selection-toggles are disabled.
112 void setEnabledSelectionToggles(bool enabled
);
113 bool enabledSelectionToggles() const;
116 * @return Controller of the item-list. The controller gets
117 * initialized by KItemListController::setView() and will
118 * result in calling KItemListController::onControllerChanged().
120 KItemListController
* controller() const;
123 * @return Model of the item-list. The model gets
124 * initialized by KItemListController::setModel() and will
125 * result in calling KItemListController::onModelChanged().
127 KItemModelBase
* model() const;
130 * Sets the creator that creates a widget showing the
131 * content of one model-item. Usually it is sufficient
132 * to implement a custom widget X derived from KItemListWidget and
133 * set the creator by:
135 * itemListView->setWidgetCreator(new KItemListWidgetCreator<X>());
137 * The ownership of the widget creator is transferred to
138 * the item-list view.
140 void setWidgetCreator(KItemListWidgetCreatorBase
* widgetCreator
);
141 KItemListWidgetCreatorBase
* widgetCreator() const;
144 * Sets the creator that creates a group header. Usually it is sufficient
145 * to implement a custom header widget X derived from KItemListGroupHeader and
146 * set the creator by:
148 * itemListView->setGroupHeaderCreator(new KItemListGroupHeaderCreator<X>());
150 * The ownership of the gropup header creator is transferred to
151 * the item-list view.
153 void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
* groupHeaderCreator
);
154 KItemListGroupHeaderCreatorBase
* groupHeaderCreator() const;
157 * @return The basic size of all items. The size of an item may be larger than
158 * the basic size (see KItemListView::itemSizeHint() and KItemListView::itemRect()).
160 QSizeF
itemSize() const;
162 const KItemListStyleOption
& styleOption() const;
165 virtual void setGeometry(const QRectF
& rect
);
168 * @return The page step which should be used by the vertical scroll bar.
169 * This is the height of the view except for the header widget.
171 qreal
verticalPageStep() const;
174 * @return Index of the item that is below the point \a pos.
175 * The position is relative to the upper right of
176 * the visible area. Only (at least partly) visible
177 * items are considered. -1 is returned if no item is
178 * below the position.
180 int itemAt(const QPointF
& pos
) const;
181 bool isAboveSelectionToggle(int index
, const QPointF
& pos
) const;
182 bool isAboveExpansionToggle(int index
, const QPointF
& pos
) const;
185 * @return Index of the first item that is at least partly visible.
186 * -1 is returned if the model contains no items.
188 int firstVisibleIndex() const;
191 * @return Index of the last item that is at least partly visible.
192 * -1 is returned if the model contains no items.
194 int lastVisibleIndex() const;
197 * @return Required size for the item with the index \p index.
198 * The returned value might be larger than KItemListView::itemSize().
199 * In this case the layout grid will be stretched to assure an
202 QSizeF
itemSizeHint(int index
) const;
205 * If set to true, items having child-items can be expanded to show the child-items as
206 * part of the view. Per default the expanding of items is is disabled. If expanding of
207 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
208 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
209 * must be reimplemented. The view-implementation
210 * has to take care itself how to visually represent the expanded items provided
213 void setSupportsItemExpanding(bool supportsExpanding
);
214 bool supportsItemExpanding() const;
217 * @return The rectangle of the item relative to the top/left of
218 * the currently visible area (see KItemListView::offset()).
220 QRectF
itemRect(int index
) const;
223 * @return The context rectangle of the item relative to the top/left of
224 * the currently visible area (see KItemListView::offset()). The
225 * context rectangle is defined by by the united rectangle of
226 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
227 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
228 * a tooltip or a context-menu for an item. Note that a context rectangle will
229 * only be returned for (at least partly) visible items. An empty rectangle will
230 * be returned for fully invisible items.
232 QRectF
itemContextRect(int index
) const;
235 * Scrolls to the item with the index \a index so that the item
236 * will be fully visible.
238 void scrollToItem(int index
);
241 * If several properties of KItemListView are changed synchronously, it is
242 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
243 * This prevents unnecessary and expensive layout-calculations.
245 void beginTransaction();
248 * Counterpart to beginTransaction(). The layout changes will only be animated if
249 * all property changes between beginTransaction() and endTransaction() support
252 void endTransaction();
254 bool isTransactionActive() const;
257 * Turns on the header if \p visible is true. Per default the
258 * header is not visible. Usually the header is turned on when
259 * showing a classic "table-view" to describe the shown columns.
261 void setHeaderVisible(bool visible
);
262 bool isHeaderVisible() const;
265 * @return Header of the list. The header is also available if it is not shown
266 * (see KItemListView::setHeaderShown()).
268 KItemListHeader
* header() const;
271 * @return Pixmap that is used for a drag operation based on the
272 * items given by \a indexes.
274 virtual QPixmap
createDragPixmap(const QSet
<int>& indexes
) const;
277 * Lets the user edit the role \a role for item with the index \a index.
279 void editRole(int index
, const QByteArray
& role
);
284 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
287 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
288 void scrollOffsetChanged(qreal current
, qreal previous
);
289 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
290 void itemOffsetChanged(qreal current
, qreal previous
);
291 void maximumItemOffsetChanged(qreal current
, qreal previous
);
292 void scrollTo(qreal newOffset
);
295 * Is emitted if the user has changed the sort order by clicking on a
296 * header item (see KItemListView::setHeaderShown()). The sort order
297 * of the model has already been adjusted to
298 * the current sort order. Note that no signal will be emitted if the
299 * sort order of the model has been changed without user interaction.
301 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
304 * Is emitted if the user has changed the sort role by clicking on a
305 * header item (see KItemListView::setHeaderShown()). The sort role
306 * of the model has already been adjusted to
307 * the current sort role. Note that no signal will be emitted if the
308 * sort role of the model has been changed without user interaction.
310 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
313 * Is emitted if the user has changed the visible roles by moving a header
314 * item (see KItemListView::setHeaderShown()). Note that no signal will be
315 * emitted if the roles have been changed without user interaction by
316 * KItemListView::setVisibleRoles().
318 void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
320 void roleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
321 void roleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
324 virtual QVariant
itemChange(GraphicsItemChange change
, const QVariant
&value
);
325 void setItemSize(const QSizeF
& size
);
326 void setStyleOption(const KItemListStyleOption
& option
);
329 * If the scroll-orientation is vertical, the items are ordered
330 * from top to bottom (= default setting). If the scroll-orientation
331 * is horizontal, the items are ordered from left to right.
333 void setScrollOrientation(Qt::Orientation orientation
);
334 Qt::Orientation
scrollOrientation() const;
337 * Factory method for creating a default widget-creator. The method will be used
338 * in case if setWidgetCreator() has not been set by the application.
339 * @return New instance of the widget-creator that should be used per
342 virtual KItemListWidgetCreatorBase
* defaultWidgetCreator() const;
345 * Factory method for creating a default group-header-creator. The method will be used
346 * in case if setGroupHeaderCreator() has not been set by the application.
347 * @return New instance of the group-header-creator that should be used per
350 virtual KItemListGroupHeaderCreatorBase
* defaultGroupHeaderCreator() const;
353 * Is called when creating a new KItemListWidget instance and allows derived
354 * classes to do a custom initialization.
356 virtual void initializeItemListWidget(KItemListWidget
* item
);
359 * @return True if at least one of the changed roles \p changedRoles might result
360 * in the need to update the item-size hint (see KItemListView::itemSizeHint()).
361 * Per default true is returned which means on each role-change of existing items
362 * the item-size hints are recalculated. For performance reasons it is recommended
363 * to return false in case if a role-change will not result in a changed
366 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
>& changedRoles
) const;
368 virtual void onControllerChanged(KItemListController
* current
, KItemListController
* previous
);
369 virtual void onModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
371 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
372 virtual void onItemSizeChanged(const QSizeF
& current
, const QSizeF
& previous
);
373 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
374 virtual void onVisibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
375 virtual void onStyleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
376 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
378 virtual void onTransactionBegin();
379 virtual void onTransactionEnd();
381 virtual bool event(QEvent
* event
);
382 virtual void mousePressEvent(QGraphicsSceneMouseEvent
* event
);
383 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
);
384 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent
* event
);
385 virtual void dragMoveEvent(QGraphicsSceneDragDropEvent
* event
);
386 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent
* event
);
387 virtual void dropEvent(QGraphicsSceneDragDropEvent
* event
);
389 QList
<KItemListWidget
*> visibleItemListWidgets() const;
392 virtual void slotItemsInserted(const KItemRangeList
& itemRanges
);
393 virtual void slotItemsRemoved(const KItemRangeList
& itemRanges
);
394 virtual void slotItemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
395 virtual void slotItemsChanged(const KItemRangeList
& itemRanges
,
396 const QSet
<QByteArray
>& roles
);
398 virtual void slotGroupedSortingChanged(bool current
);
399 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
400 virtual void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
401 virtual void slotCurrentChanged(int current
, int previous
);
402 virtual void slotSelectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
);
405 void slotAnimationFinished(QGraphicsWidget
* widget
,
406 KItemListViewAnimation::AnimationType type
);
407 void slotLayoutTimerFinished();
409 void slotRubberBandPosChanged();
410 void slotRubberBandActivationChanged(bool active
);
413 * Is invoked if the column-width of one role in the header has
414 * been changed by the user. The automatic resizing of columns
415 * will be turned off as soon as this method has been called at
418 void slotHeaderColumnWidthChanged(const QByteArray
& role
,
420 qreal previousWidth
);
423 * Is invoked if a column has been moved by the user. Applies
424 * the moved role to the view.
426 void slotHeaderColumnMoved(const QByteArray
& role
,
431 * Triggers the autoscrolling if autoScroll() is enabled by checking the
432 * current mouse position. If the mouse position is within the autoscroll
433 * margins a timer will be started that periodically triggers the autoscrolling.
435 void triggerAutoScrolling();
438 * Is invoked if the geometry of the parent-widget from a group-header has been
439 * changed. The x-position and width of the group-header gets adjusted to assure
440 * that it always spans the whole width even during temporary transitions of the
443 void slotGeometryOfGroupHeaderParentChanged();
445 void slotRoleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
446 void slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
449 enum LayoutAnimationHint
461 void setController(KItemListController
* controller
);
462 void setModel(KItemModelBase
* model
);
464 KItemListRubberBand
* rubberBand() const;
466 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
469 * Helper method for doLayout: Returns a list of items that can be reused for the visible
470 * area. Invisible group headers get recycled. The reusable items are items that are
471 * invisible. If the animation hint is 'Animation' then items that are currently animated
472 * won't be reused. Reusing items is faster in comparison to deleting invisible
473 * items and creating a new instance for visible items.
475 QList
<int> recycleInvisibleItems(int firstVisibleIndex
,
476 int lastVisibleIndex
,
477 LayoutAnimationHint hint
);
480 * Helper method for doLayout: Starts a moving-animation for the widget to the given
481 * new position. The moving-animation is only started if the new position is within
482 * the same row or column, otherwise the create-animation is used instead.
483 * @return True if the moving-animation has been applied.
485 bool moveWidget(KItemListWidget
* widget
, const QPointF
& newPos
);
487 void emitOffsetChanges();
489 KItemListWidget
* createWidget(int index
);
490 void recycleWidget(KItemListWidget
* widget
);
493 * Changes the index of the widget to \a index and assures a consistent
494 * update for m_visibleItems and m_visibleCells. The cell-information
495 * for the new index will not be updated and be initialized as empty cell.
497 void setWidgetIndex(KItemListWidget
* widget
, int index
);
500 * Changes the index of the widget to \a index. In opposite to
501 * setWidgetIndex() the cell-information for the widget gets updated.
502 * This update gives doLayout() the chance to animate the moving
503 * of the item visually (see moveWidget()).
505 void moveWidgetToIndex(KItemListWidget
* widget
, int index
);
508 * Helper method for prepareLayoutForIncreasedItemCount().
510 void setLayouterSize(const QSizeF
& size
, SizeType sizeType
);
513 * Helper method for createWidget() and setWidgetIndex() to update the properties
514 * of the itemlist widget.
516 void updateWidgetProperties(KItemListWidget
* widget
, int index
);
519 * Helper method for updateWidgetPropertes() to create or update
520 * the itemlist group-header.
522 void updateGroupHeaderForWidget(KItemListWidget
* widget
);
525 * Updates the position and size of the group-header that belongs
526 * to the itemlist widget \a widget. The given widget must represent
527 * the first item of a group.
529 void updateGroupHeaderLayout(KItemListWidget
* widget
);
532 * Recycles the group-header for the widget.
534 void recycleGroupHeaderForWidget(KItemListWidget
* widget
);
537 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
538 * and slotSortRoleChanged(): Iterates through all visible items and updates
539 * the group-header widgets.
541 void updateVisibleGroupHeaders();
544 * @return Index for the item in the list returned by KItemModelBase::groups()
545 * that represents the group where the item with the index \a index
546 * belongs to. -1 is returned if no groups are available.
548 int groupIndexForItem(int index
) const;
551 * Updates the alternate background for all visible items.
552 * @see updateAlternateBackgroundForWidget()
554 void updateAlternateBackgrounds();
557 * Updates the alternateBackground-property of the widget dependent
558 * on the state of useAlternateBackgrounds() and the grouping state.
560 void updateAlternateBackgroundForWidget(KItemListWidget
* widget
);
563 * @return True if alternate backgrounds should be used for the items.
564 * This is the case if an empty item-size is given and if there
565 * is more than one visible role.
567 bool useAlternateBackgrounds() const;
570 * @param itemRanges Items that must be checked for getting the widths of columns.
571 * @return The preferred width of the column of each visible role. The width will
572 * be respected if the width of the item size is <= 0 (see
573 * KItemListView::setItemSize()). Per default an empty hash
576 QHash
<QByteArray
, qreal
> preferredColumnWidths(const KItemRangeList
& itemRanges
) const;
579 * Applies the column-widths from m_headerWidget to the layout
582 void applyColumnWidthsFromHeader();
585 * Applies the column-widths from m_headerWidget to \a widget.
587 void updateWidgetColumnWidths(KItemListWidget
* widget
);
590 * Updates the preferred column-widths of m_groupHeaderWidget by
591 * invoking KItemListView::columnWidths().
593 void updatePreferredColumnWidths(const KItemRangeList
& itemRanges
);
596 * Convenience method for
597 * updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model->count()).
599 void updatePreferredColumnWidths();
602 * Resizes the column-widths of m_headerWidget based on the preferred widths
603 * and the vailable view-size.
605 void applyAutomaticColumnWidths();
608 * @return Sum of the widths of all columns.
610 qreal
columnWidthsSum() const;
613 * @return Boundaries of the header. An empty rectangle is returned
614 * if no header is shown.
616 QRectF
headerBoundaries() const;
619 * @return True if the number of columns or rows will be changed when applying
620 * the new grid- and item-size. Used to determine whether an animation
621 * should be done when applying the new layout.
623 bool changesItemGridLayout(const QSizeF
& newGridSize
,
624 const QSizeF
& newItemSize
,
625 const QSizeF
& newItemMargin
) const;
628 * @param changedItemCount Number of inserted or removed items.
629 * @return True if the inserting or removing of items should be animated.
630 * No animation should be done if the number of items is too large
631 * to provide a pleasant animation.
633 bool animateChangedItemCount(int changedItemCount
) const;
636 * @return True if a scrollbar for the given scroll-orientation is required
637 * when using a size of \p size for the view. Calling the method is rather
638 * expansive as a temporary relayout needs to be done.
640 bool scrollBarRequired(const QSizeF
& size
) const;
643 * Shows a drop-indicator between items dependent on the given
644 * cursor position. The cursor position is relative the the upper left
646 * @return Index of the item where the dropping is done. An index of -1
647 * indicates that the item has been dropped after the last item.
649 int showDropIndicator(const QPointF
& pos
);
650 void hideDropIndicator();
653 * Applies the height of the group header to the layouter. The height
654 * depends on the used scroll orientation.
656 void updateGroupHeaderHeight();
659 * Updates the siblings-information for all visible items that are inside
660 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
661 * is smaller than 0, the siblings-information for all visible items gets
663 * @see KItemListWidget::setSiblingsInformation()
665 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
668 * Helper method for updateExpansionIndicators().
669 * @return True if the item with the index \a index has a sibling successor
670 * (= the item is not the last item of the current hierarchy).
672 bool hasSiblingSuccessor(int index
) const;
675 * Helper method for slotRoleEditingCanceled() and slotRoleEditingFinished().
676 * Disconnects the two Signals "roleEditingCanceled" and
677 * "roleEditingFinished"
679 void disconnectRoleEditingSignals(int index
);
682 * Helper function for triggerAutoScrolling().
683 * @param pos Logical position of the mouse relative to the range.
684 * @param range Range of the visible area.
685 * @param oldInc Previous increment. Is used to assure that the increment
686 * increases only gradually.
687 * @return Scroll increment that should be added to the offset().
688 * As soon as \a pos is inside the autoscroll-margin a
689 * value != 0 will be returned.
691 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
694 * Helper functions for changesItemCount().
695 * @return The number of items that fit into the available size by
696 * respecting the size of the item and the margin between the items.
698 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
701 bool m_enabledSelectionToggles
;
703 bool m_supportsItemExpanding
;
705 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
706 LayoutAnimationHint m_endTransactionAnimationHint
;
709 KItemListController
* m_controller
;
710 KItemModelBase
* m_model
;
711 QList
<QByteArray
> m_visibleRoles
;
712 mutable KItemListWidgetCreatorBase
* m_widgetCreator
;
713 mutable KItemListGroupHeaderCreatorBase
* m_groupHeaderCreator
;
714 KItemListStyleOption m_styleOption
;
716 QHash
<int, KItemListWidget
*> m_visibleItems
;
717 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
721 Cell() : column(-1), row(-1) {}
722 Cell(int c
, int r
) : column(c
), row(r
) {}
726 QHash
<int, Cell
> m_visibleCells
;
728 int m_scrollBarExtent
;
729 KItemListSizeHintResolver
* m_sizeHintResolver
;
730 KItemListViewLayouter
* m_layouter
;
731 KItemListViewAnimation
* m_animation
;
733 QTimer
* m_layoutTimer
; // Triggers an asynchronous doLayout() call.
734 qreal m_oldScrollOffset
;
735 qreal m_oldMaximumScrollOffset
;
736 qreal m_oldItemOffset
;
737 qreal m_oldMaximumItemOffset
;
739 bool m_skipAutoScrollForRubberBand
;
740 KItemListRubberBand
* m_rubberBand
;
743 int m_autoScrollIncrement
;
744 QTimer
* m_autoScrollTimer
;
746 KItemListHeader
* m_header
;
747 KItemListHeaderWidget
* m_headerWidget
;
749 // When dragging items into the view where the sort-role of the model
750 // is empty, a visual indicator should be shown during dragging where
751 // the dropping will happen. This indicator is specified by an index
752 // of the item. -1 means that no indicator will be shown at all.
753 // The m_dropIndicator is set by the KItemListController
754 // by KItemListView::showDropIndicator() and KItemListView::hideDropIndicator().
755 QRectF m_dropIndicator
;
757 friend class KItemListContainer
; // Accesses scrollBarRequired()
758 friend class KItemListHeader
; // Accesses m_headerWidget
759 friend class KItemListController
;
760 friend class KItemListControllerTest
;
761 friend class KItemListViewAccessible
;
762 friend class KItemListAccessibleCell
;
766 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
767 * by recycling existing QGraphicsWidgets instances. Is used by
768 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
771 class LIBDOLPHINPRIVATE_EXPORT KItemListCreatorBase
774 virtual ~KItemListCreatorBase();
777 void addCreatedWidget(QGraphicsWidget
* widget
);
778 void pushRecycleableWidget(QGraphicsWidget
* widget
);
779 QGraphicsWidget
* popRecycleableWidget();
782 QSet
<QGraphicsWidget
*> m_createdWidgets
;
783 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
787 * @brief Base class for creating KItemListWidgets.
789 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
790 * For a custom implementation the methods create(), itemSizeHint() and preferredColumnWith()
791 * must be reimplemented. The intention of the widget creator is to prevent repetitive and
792 * expensive instantiations and deletions of KItemListWidgets by recycling existing widget
795 class LIBDOLPHINPRIVATE_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
798 virtual ~KItemListWidgetCreatorBase();
800 virtual KItemListWidget
* create(KItemListView
* view
) = 0;
802 virtual void recycle(KItemListWidget
* widget
);
804 virtual QSizeF
itemSizeHint(int index
, const KItemListView
* view
) const = 0;
806 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
808 const KItemListView
* view
) const = 0;
812 * @brief Template class for creating KItemListWidgets.
815 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
818 KItemListWidgetCreator();
819 virtual ~KItemListWidgetCreator();
821 virtual KItemListWidget
* create(KItemListView
* view
);
823 virtual QSizeF
itemSizeHint(int index
, const KItemListView
* view
) const;
825 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
827 const KItemListView
* view
) const;
829 KItemListWidgetInformant
* m_informant
;
833 KItemListWidgetCreator
<T
>::KItemListWidgetCreator() :
834 m_informant(T::createInformant())
839 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
845 KItemListWidget
* KItemListWidgetCreator
<T
>::create(KItemListView
* view
)
847 KItemListWidget
* widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
849 widget
= new T(m_informant
, view
);
850 addCreatedWidget(widget
);
856 QSizeF KItemListWidgetCreator
<T
>::itemSizeHint(int index
, const KItemListView
* view
) const
858 return m_informant
->itemSizeHint(index
, view
);
862 qreal KItemListWidgetCreator
<T
>::preferredRoleColumnWidth(const QByteArray
& role
,
864 const KItemListView
* view
) const
866 return m_informant
->preferredRoleColumnWidth(role
, index
, view
);
870 * @brief Base class for creating KItemListGroupHeaders.
872 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
873 * For a custom implementation the methods create() and recyle() must be reimplemented.
874 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
875 * deletions of KItemListGroupHeaders by recycling existing header instances.
877 class LIBDOLPHINPRIVATE_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
880 virtual ~KItemListGroupHeaderCreatorBase();
881 virtual KItemListGroupHeader
* create(KItemListView
* view
) = 0;
882 virtual void recycle(KItemListGroupHeader
* header
);
886 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
889 virtual ~KItemListGroupHeaderCreator();
890 virtual KItemListGroupHeader
* create(KItemListView
* view
);
894 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
899 KItemListGroupHeader
* KItemListGroupHeaderCreator
<T
>::create(KItemListView
* view
)
901 KItemListGroupHeader
* widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
903 widget
= new T(view
);
904 addCreatedWidget(widget
);