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 void setVisibleRoles(const QList
<QByteArray
>& roles
);
96 QList
<QByteArray
> visibleRoles() const;
99 * If set to true an automatic scrolling is done as soon as the
100 * mouse is moved near the borders of the view. Per default
101 * the automatic scrolling is turned off.
103 void setAutoScroll(bool enabled
);
104 bool autoScroll() const;
107 * If set to true selection-toggles will be shown when hovering
108 * an item. Per default the selection-toggles are disabled.
110 void setEnabledSelectionToggles(bool enabled
);
111 bool enabledSelectionToggles() const;
114 * @return Controller of the item-list. The controller gets
115 * initialized by KItemListController::setView() and will
116 * result in calling KItemListController::onControllerChanged().
118 KItemListController
* controller() const;
121 * @return Model of the item-list. The model gets
122 * initialized by KItemListController::setModel() and will
123 * result in calling KItemListController::onModelChanged().
125 KItemModelBase
* model() const;
128 * Sets the creator that creates a widget showing the
129 * content of one model-item. Usually it is sufficient
130 * to implement a custom widget X derived from KItemListWidget and
131 * set the creator by:
133 * itemListView->setWidgetCreator(new KItemListWidgetCreator<X>());
135 * The ownership of the widget creator is transferred to
136 * the item-list view.
138 void setWidgetCreator(KItemListWidgetCreatorBase
* widgetCreator
);
139 KItemListWidgetCreatorBase
* widgetCreator() const;
142 * Sets the creator that creates a group header. Usually it is sufficient
143 * to implement a custom header widget X derived from KItemListGroupHeader and
144 * set the creator by:
146 * itemListView->setGroupHeaderCreator(new KItemListGroupHeaderCreator<X>());
148 * The ownership of the gropup header creator is transferred to
149 * the item-list view.
151 void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
* groupHeaderCreator
);
152 KItemListGroupHeaderCreatorBase
* groupHeaderCreator() const;
155 * @return The basic size of all items. The size of an item may be larger than
156 * the basic size (see KItemListView::itemSizeHint() and KItemListView::itemRect()).
158 QSizeF
itemSize() const;
160 const KItemListStyleOption
& styleOption() const;
163 virtual void setGeometry(const QRectF
& rect
);
166 * @return Index of the item that is below the point \a pos.
167 * The position is relative to the upper right of
168 * the visible area. Only (at least partly) visible
169 * items are considered. -1 is returned if no item is
170 * below the position.
172 int itemAt(const QPointF
& pos
) const;
173 bool isAboveSelectionToggle(int index
, const QPointF
& pos
) const;
174 bool isAboveExpansionToggle(int index
, const QPointF
& pos
) const;
177 * @return Index of the first item that is at least partly visible.
178 * -1 is returned if the model contains no items.
180 int firstVisibleIndex() const;
183 * @return Index of the last item that is at least partly visible.
184 * -1 is returned if the model contains no items.
186 int lastVisibleIndex() const;
189 * @return Required size for the item with the index \p index.
190 * The returned value might be larger than KItemListView::itemSize().
191 * In this case the layout grid will be stretched to assure an
194 QSizeF
itemSizeHint(int index
) const;
197 * If set to true, items having child-items can be expanded to show the child-items as
198 * part of the view. Per default the expanding of items is is disabled. If expanding of
199 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
200 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
201 * must be reimplemented. The view-implementation
202 * has to take care itself how to visually represent the expanded items provided
205 void setSupportsItemExpanding(bool supportsExpanding
);
206 bool supportsItemExpanding() const;
209 * @return The rectangle of the item relative to the top/left of
210 * the currently visible area (see KItemListView::offset()).
212 QRectF
itemRect(int index
) const;
215 * @return The context rectangle of the item relative to the top/left of
216 * the currently visible area (see KItemListView::offset()). The
217 * context rectangle is defined by by the united rectangle of
218 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
219 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
220 * a tooltip or a context-menu for an item. Note that a context rectangle will
221 * only be returned for (at least partly) visible items. An empty rectangle will
222 * be returned for fully invisible items.
224 QRectF
itemContextRect(int index
) const;
227 * Scrolls to the item with the index \a index so that the item
228 * will be fully visible.
230 void scrollToItem(int index
);
233 * If several properties of KItemListView are changed synchronously, it is
234 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
235 * This prevents unnecessary and expensive layout-calculations.
237 void beginTransaction();
240 * Counterpart to beginTransaction(). The layout changes will only be animated if
241 * all property changes between beginTransaction() and endTransaction() support
244 void endTransaction();
246 bool isTransactionActive() const;
249 * Turns on the header if \p visible is true. Per default the
250 * header is not visible. Usually the header is turned on when
251 * showing a classic "table-view" to describe the shown columns.
253 void setHeaderVisible(bool visible
);
254 bool isHeaderVisible() const;
257 * @return Header of the list. The header is also available if it is not shown
258 * (see KItemListView::setHeaderShown()).
260 KItemListHeader
* header() const;
263 * @return Pixmap that is used for a drag operation based on the
264 * items given by \a indexes.
266 virtual QPixmap
createDragPixmap(const QSet
<int>& indexes
) const;
269 * Lets the user edit the role \a role for item with the index \a index.
271 void editRole(int index
, const QByteArray
& role
);
276 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
279 * @return The Layouter for the view
281 KItemListViewLayouter
* layouter() const;
284 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
285 void scrollOffsetChanged(qreal current
, qreal previous
);
286 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
287 void itemOffsetChanged(qreal current
, qreal previous
);
288 void maximumItemOffsetChanged(qreal current
, qreal previous
);
289 void scrollTo(qreal newOffset
);
292 * Is emitted if the user has changed the sort order by clicking on a
293 * header item (see KItemListView::setHeaderShown()). The sort order
294 * of the model has already been adjusted to
295 * the current sort order. Note that no signal will be emitted if the
296 * sort order of the model has been changed without user interaction.
298 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
301 * Is emitted if the user has changed the sort role by clicking on a
302 * header item (see KItemListView::setHeaderShown()). The sort role
303 * of the model has already been adjusted to
304 * the current sort role. Note that no signal will be emitted if the
305 * sort role of the model has been changed without user interaction.
307 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
310 * Is emitted if the user has changed the visible roles by moving a header
311 * item (see KItemListView::setHeaderShown()). Note that no signal will be
312 * emitted if the roles have been changed without user interaction by
313 * KItemListView::setVisibleRoles().
315 void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
317 void roleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
318 void roleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
321 void setItemSize(const QSizeF
& size
);
322 void setStyleOption(const KItemListStyleOption
& option
);
325 * If the scroll-orientation is vertical, the items are ordered
326 * from top to bottom (= default setting). If the scroll-orientation
327 * is horizontal, the items are ordered from left to right.
329 void setScrollOrientation(Qt::Orientation orientation
);
330 Qt::Orientation
scrollOrientation() const;
333 * Factory method for creating a default widget-creator. The method will be used
334 * in case if setWidgetCreator() has not been set by the application.
335 * @return New instance of the widget-creator that should be used per
338 virtual KItemListWidgetCreatorBase
* defaultWidgetCreator() const;
341 * Factory method for creating a default group-header-creator. The method will be used
342 * in case if setGroupHeaderCreator() has not been set by the application.
343 * @return New instance of the group-header-creator that should be used per
346 virtual KItemListGroupHeaderCreatorBase
* defaultGroupHeaderCreator() const;
349 * Is called when creating a new KItemListWidget instance and allows derived
350 * classes to do a custom initialization.
352 virtual void initializeItemListWidget(KItemListWidget
* item
);
355 * @return True if at least one of the changed roles \p changedRoles might result
356 * in the need to update the item-size hint (see KItemListView::itemSizeHint()).
357 * Per default true is returned which means on each role-change of existing items
358 * the item-size hints are recalculated. For performance reasons it is recommended
359 * to return false in case if a role-change will not result in a changed
362 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
>& changedRoles
) const;
364 virtual void onControllerChanged(KItemListController
* current
, KItemListController
* previous
);
365 virtual void onModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
367 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
368 virtual void onItemSizeChanged(const QSizeF
& current
, const QSizeF
& previous
);
369 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
370 virtual void onVisibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
371 virtual void onStyleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
372 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
374 virtual void onTransactionBegin();
375 virtual void onTransactionEnd();
377 virtual bool event(QEvent
* event
);
378 virtual void mousePressEvent(QGraphicsSceneMouseEvent
* event
);
379 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
);
380 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent
* event
);
381 virtual void dragMoveEvent(QGraphicsSceneDragDropEvent
* event
);
382 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent
* event
);
383 virtual void dropEvent(QGraphicsSceneDragDropEvent
* event
);
385 QList
<KItemListWidget
*> visibleItemListWidgets() const;
388 virtual void slotItemsInserted(const KItemRangeList
& itemRanges
);
389 virtual void slotItemsRemoved(const KItemRangeList
& itemRanges
);
390 virtual void slotItemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
391 virtual void slotItemsChanged(const KItemRangeList
& itemRanges
,
392 const QSet
<QByteArray
>& roles
);
394 virtual void slotGroupedSortingChanged(bool current
);
395 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
396 virtual void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
397 virtual void slotCurrentChanged(int current
, int previous
);
398 virtual void slotSelectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
);
401 void slotAnimationFinished(QGraphicsWidget
* widget
,
402 KItemListViewAnimation::AnimationType type
);
403 void slotLayoutTimerFinished();
405 void slotRubberBandPosChanged();
406 void slotRubberBandActivationChanged(bool active
);
409 * Is invoked if the column-width of one role in the header has
410 * been changed by the user. The automatic resizing of columns
411 * will be turned off as soon as this method has been called at
414 void slotHeaderColumnWidthChanged(const QByteArray
& role
,
416 qreal previousWidth
);
419 * Is invoked if a column has been moved by the user. Applies
420 * the moved role to the view.
422 void slotHeaderColumnMoved(const QByteArray
& role
,
427 * Triggers the autoscrolling if autoScroll() is enabled by checking the
428 * current mouse position. If the mouse position is within the autoscroll
429 * margins a timer will be started that periodically triggers the autoscrolling.
431 void triggerAutoScrolling();
434 * Is invoked if the geometry of the parent-widget from a group-header has been
435 * changed. The x-position and width of the group-header gets adjusted to assure
436 * that it always spans the whole width even during temporary transitions of the
439 void slotGeometryOfGroupHeaderParentChanged();
441 void slotRoleEditingCanceled(int index
, const QByteArray
& role
, const QVariant
& value
);
442 void slotRoleEditingFinished(int index
, const QByteArray
& role
, const QVariant
& value
);
445 enum LayoutAnimationHint
457 void setController(KItemListController
* controller
);
458 void setModel(KItemModelBase
* model
);
460 KItemListRubberBand
* rubberBand() const;
462 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
465 * Helper method for doLayout: Returns a list of items that can be reused for the visible
466 * area. Invisible group headers get recycled. The reusable items are items that are
467 * invisible. If the animation hint is 'Animation' then items that are currently animated
468 * won't be reused. Reusing items is faster in comparison to deleting invisible
469 * items and creating a new instance for visible items.
471 QList
<int> recycleInvisibleItems(int firstVisibleIndex
,
472 int lastVisibleIndex
,
473 LayoutAnimationHint hint
);
476 * Helper method for doLayout: Starts a moving-animation for the widget to the given
477 * new position. The moving-animation is only started if the new position is within
478 * the same row or column, otherwise the create-animation is used instead.
479 * @return True if the moving-animation has been applied.
481 bool moveWidget(KItemListWidget
* widget
, const QPointF
& newPos
);
483 void emitOffsetChanges();
485 KItemListWidget
* createWidget(int index
);
486 void recycleWidget(KItemListWidget
* widget
);
489 * Changes the index of the widget to \a index and assures a consistent
490 * update for m_visibleItems and m_visibleCells. The cell-information
491 * for the new index will not be updated and be initialized as empty cell.
493 void setWidgetIndex(KItemListWidget
* widget
, int index
);
496 * Changes the index of the widget to \a index. In opposite to
497 * setWidgetIndex() the cell-information for the widget gets updated.
498 * This update gives doLayout() the chance to animate the moving
499 * of the item visually (see moveWidget()).
501 void moveWidgetToIndex(KItemListWidget
* widget
, int index
);
504 * Helper method for prepareLayoutForIncreasedItemCount().
506 void setLayouterSize(const QSizeF
& size
, SizeType sizeType
);
509 * Helper method for createWidget() and setWidgetIndex() to update the properties
510 * of the itemlist widget.
512 void updateWidgetProperties(KItemListWidget
* widget
, int index
);
515 * Helper method for updateWidgetPropertes() to create or update
516 * the itemlist group-header.
518 void updateGroupHeaderForWidget(KItemListWidget
* widget
);
521 * Updates the position and size of the group-header that belongs
522 * to the itemlist widget \a widget. The given widget must represent
523 * the first item of a group.
525 void updateGroupHeaderLayout(KItemListWidget
* widget
);
528 * Recycles the group-header for the widget.
530 void recycleGroupHeaderForWidget(KItemListWidget
* widget
);
533 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
534 * and slotSortRoleChanged(): Iterates through all visible items and updates
535 * the group-header widgets.
537 void updateVisibleGroupHeaders();
540 * @return Index for the item in the list returned by KItemModelBase::groups()
541 * that represents the group where the item with the index \a index
542 * belongs to. -1 is returned if no groups are available.
544 int groupIndexForItem(int index
) const;
547 * Updates the alternate background for all visible items.
548 * @see updateAlternateBackgroundForWidget()
550 void updateAlternateBackgrounds();
553 * Updates the alternateBackground-property of the widget dependent
554 * on the state of useAlternateBackgrounds() and the grouping state.
556 void updateAlternateBackgroundForWidget(KItemListWidget
* widget
);
559 * @return True if alternate backgrounds should be used for the items.
560 * This is the case if an empty item-size is given and if there
561 * is more than one visible role.
563 bool useAlternateBackgrounds() const;
566 * @param itemRanges Items that must be checked for getting the widths of columns.
567 * @return The preferred width of the column of each visible role. The width will
568 * be respected if the width of the item size is <= 0 (see
569 * KItemListView::setItemSize()). Per default an empty hash
572 QHash
<QByteArray
, qreal
> preferredColumnWidths(const KItemRangeList
& itemRanges
) const;
575 * Applies the column-widths from m_headerWidget to the layout
578 void applyColumnWidthsFromHeader();
581 * Applies the column-widths from m_headerWidget to \a widget.
583 void updateWidgetColumnWidths(KItemListWidget
* widget
);
586 * Updates the preferred column-widths of m_groupHeaderWidget by
587 * invoking KItemListView::columnWidths().
589 void updatePreferredColumnWidths(const KItemRangeList
& itemRanges
);
592 * Convenience method for
593 * updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model->count()).
595 void updatePreferredColumnWidths();
598 * Resizes the column-widths of m_headerWidget based on the preferred widths
599 * and the vailable view-size.
601 void applyAutomaticColumnWidths();
604 * @return Sum of the widths of all columns.
606 qreal
columnWidthsSum() const;
609 * @return Boundaries of the header. An empty rectangle is returned
610 * if no header is shown.
612 QRectF
headerBoundaries() const;
615 * @return True if the number of columns or rows will be changed when applying
616 * the new grid- and item-size. Used to determine whether an animation
617 * should be done when applying the new layout.
619 bool changesItemGridLayout(const QSizeF
& newGridSize
,
620 const QSizeF
& newItemSize
,
621 const QSizeF
& newItemMargin
) const;
624 * @param changedItemCount Number of inserted or removed items.
625 * @return True if the inserting or removing of items should be animated.
626 * No animation should be done if the number of items is too large
627 * to provide a pleasant animation.
629 bool animateChangedItemCount(int changedItemCount
) const;
632 * @return True if a scrollbar for the given scroll-orientation is required
633 * when using a size of \p size for the view. Calling the method is rather
634 * expansive as a temporary relayout needs to be done.
636 bool scrollBarRequired(const QSizeF
& size
) const;
639 * Shows a drop-indicator between items dependent on the given
640 * cursor position. The cursor position is relative the the upper left
642 * @return Index of the item where the dropping is done. An index of -1
643 * indicates that the item has been dropped after the last item.
645 int showDropIndicator(const QPointF
& pos
);
646 void hideDropIndicator();
649 * Applies the height of the group header to the layouter. The height
650 * depends on the used scroll orientation.
652 void updateGroupHeaderHeight();
655 * Updates the siblings-information for all visible items that are inside
656 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
657 * is smaller than 0, the siblings-information for all visible items gets
659 * @see KItemListWidget::setSiblingsInformation()
661 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
664 * Helper method for updateExpansionIndicators().
665 * @return True if the item with the index \a index has a sibling successor
666 * (= the item is not the last item of the current hierarchy).
668 bool hasSiblingSuccessor(int index
) const;
671 * Helper function for triggerAutoScrolling().
672 * @param pos Logical position of the mouse relative to the range.
673 * @param range Range of the visible area.
674 * @param oldInc Previous increment. Is used to assure that the increment
675 * increases only gradually.
676 * @return Scroll increment that should be added to the offset().
677 * As soon as \a pos is inside the autoscroll-margin a
678 * value != 0 will be returned.
680 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
683 * Helper functions for changesItemCount().
684 * @return The number of items that fit into the available size by
685 * respecting the size of the item and the margin between the items.
687 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
690 bool m_enabledSelectionToggles
;
692 bool m_supportsItemExpanding
;
694 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
695 LayoutAnimationHint m_endTransactionAnimationHint
;
698 KItemListController
* m_controller
;
699 KItemModelBase
* m_model
;
700 QList
<QByteArray
> m_visibleRoles
;
701 mutable KItemListWidgetCreatorBase
* m_widgetCreator
;
702 mutable KItemListGroupHeaderCreatorBase
* m_groupHeaderCreator
;
703 KItemListStyleOption m_styleOption
;
705 QHash
<int, KItemListWidget
*> m_visibleItems
;
706 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
710 Cell() : column(-1), row(-1) {}
711 Cell(int c
, int r
) : column(c
), row(r
) {}
715 QHash
<int, Cell
> m_visibleCells
;
717 int m_scrollBarExtent
;
718 KItemListSizeHintResolver
* m_sizeHintResolver
;
719 KItemListViewLayouter
* m_layouter
;
720 KItemListViewAnimation
* m_animation
;
722 QTimer
* m_layoutTimer
; // Triggers an asynchronous doLayout() call.
723 qreal m_oldScrollOffset
;
724 qreal m_oldMaximumScrollOffset
;
725 qreal m_oldItemOffset
;
726 qreal m_oldMaximumItemOffset
;
728 bool m_skipAutoScrollForRubberBand
;
729 KItemListRubberBand
* m_rubberBand
;
732 int m_autoScrollIncrement
;
733 QTimer
* m_autoScrollTimer
;
735 KItemListHeader
* m_header
;
736 KItemListHeaderWidget
* m_headerWidget
;
738 // When dragging items into the view where the sort-role of the model
739 // is empty, a visual indicator should be shown during dragging where
740 // the dropping will happen. This indicator is specified by an index
741 // of the item. -1 means that no indicator will be shown at all.
742 // The m_dropIndicator is set by the KItemListController
743 // by KItemListView::showDropIndicator() and KItemListView::hideDropIndicator().
744 QRectF m_dropIndicator
;
746 friend class KItemListContainer
; // Accesses scrollBarRequired()
747 friend class KItemListHeader
; // Accesses m_headerWidget
748 friend class KItemListController
;
749 friend class KItemListControllerTest
;
753 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
754 * by recycling existing QGraphicsWidgets instances. Is used by
755 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
758 class LIBDOLPHINPRIVATE_EXPORT KItemListCreatorBase
761 virtual ~KItemListCreatorBase();
764 void addCreatedWidget(QGraphicsWidget
* widget
);
765 void pushRecycleableWidget(QGraphicsWidget
* widget
);
766 QGraphicsWidget
* popRecycleableWidget();
769 QSet
<QGraphicsWidget
*> m_createdWidgets
;
770 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
774 * @brief Base class for creating KItemListWidgets.
776 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
777 * For a custom implementation the methods create(), itemSizeHint() and preferredColumnWith()
778 * must be reimplemented. The intention of the widget creator is to prevent repetitive and
779 * expensive instantiations and deletions of KItemListWidgets by recycling existing widget
782 class LIBDOLPHINPRIVATE_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
785 virtual ~KItemListWidgetCreatorBase();
787 virtual KItemListWidget
* create(KItemListView
* view
) = 0;
789 virtual void recycle(KItemListWidget
* widget
);
791 virtual QSizeF
itemSizeHint(int index
, const KItemListView
* view
) const = 0;
793 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
795 const KItemListView
* view
) const = 0;
799 * @brief Template class for creating KItemListWidgets.
802 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
805 KItemListWidgetCreator();
806 virtual ~KItemListWidgetCreator();
808 virtual KItemListWidget
* create(KItemListView
* view
);
810 virtual QSizeF
itemSizeHint(int index
, const KItemListView
* view
) const;
812 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
814 const KItemListView
* view
) const;
816 KItemListWidgetInformant
* m_informant
;
820 KItemListWidgetCreator
<T
>::KItemListWidgetCreator() :
821 m_informant(T::createInformant())
826 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
832 KItemListWidget
* KItemListWidgetCreator
<T
>::create(KItemListView
* view
)
834 KItemListWidget
* widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
836 widget
= new T(m_informant
, view
);
837 addCreatedWidget(widget
);
843 QSizeF KItemListWidgetCreator
<T
>::itemSizeHint(int index
, const KItemListView
* view
) const
845 return m_informant
->itemSizeHint(index
, view
);
849 qreal KItemListWidgetCreator
<T
>::preferredRoleColumnWidth(const QByteArray
& role
,
851 const KItemListView
* view
) const
853 return m_informant
->preferredRoleColumnWidth(role
, index
, view
);
857 * @brief Base class for creating KItemListGroupHeaders.
859 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
860 * For a custom implementation the methods create() and recyle() must be reimplemented.
861 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
862 * deletions of KItemListGroupHeaders by recycling existing header instances.
864 class LIBDOLPHINPRIVATE_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
867 virtual ~KItemListGroupHeaderCreatorBase();
868 virtual KItemListGroupHeader
* create(KItemListView
* view
) = 0;
869 virtual void recycle(KItemListGroupHeader
* header
);
873 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
876 virtual ~KItemListGroupHeaderCreator();
877 virtual KItemListGroupHeader
* create(KItemListView
* view
);
881 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
886 KItemListGroupHeader
* KItemListGroupHeaderCreator
<T
>::create(KItemListView
* view
)
888 KItemListGroupHeader
* widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
890 widget
= new T(view
);
891 addCreatedWidget(widget
);