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/kitemlistgroupheader.h>
29 #include <kitemviews/kitemliststyleoption.h>
30 #include <kitemviews/kitemlistviewanimation_p.h>
31 #include <kitemviews/kitemlistwidget.h>
32 #include <kitemviews/kitemmodelbase.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 KItemListWidgetCreatorBase
;
46 class KItemListViewCreatorBase
;
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(). For showing a custom model it is not
57 * mandatory to derive from KItemListView, all that is necessary is
58 * to set a widget-creator that is capable to create KItemListWidgets
59 * showing the model items. A widget-creator can be set with
60 * KItemListView::setWidgetCreator().
62 * @see KItemListWidget
65 class LIBDOLPHINPRIVATE_EXPORT KItemListView
: public QGraphicsWidget
69 Q_PROPERTY(qreal scrollOffset READ scrollOffset WRITE setScrollOffset
)
70 Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset
)
73 KItemListView(QGraphicsWidget
* parent
= 0);
74 virtual ~KItemListView();
77 * If the scroll-orientation is vertical, the items are ordered
78 * from top to bottom (= default setting). If the scroll-orientation
79 * is horizontal, the items are ordered from left to right.
81 void setScrollOrientation(Qt::Orientation orientation
);
82 Qt::Orientation
scrollOrientation() const;
84 void setItemSize(const QSizeF
& size
);
85 QSizeF
itemSize() const;
88 * Offset of the scrollbar that represents the scroll-orientation
89 * (see setScrollOrientation()).
91 void setScrollOffset(qreal offset
);
92 qreal
scrollOffset() const;
94 qreal
maximumScrollOffset() const;
97 * Offset related to an item, that does not fit into the available
98 * size of the listview. If the scroll-orientation is vertical
99 * the item-offset describes the offset of the horizontal axe, if
100 * the scroll-orientation is horizontal the item-offset describes
101 * the offset of the vertical axe.
103 void setItemOffset(qreal scrollOffset
);
104 qreal
itemOffset() const;
106 qreal
maximumItemOffset() const;
108 void setVisibleRoles(const QList
<QByteArray
>& roles
);
109 QList
<QByteArray
> visibleRoles() const;
112 * If set to true an automatic scrolling is done as soon as the
113 * mouse is moved near the borders of the view. Per default
114 * the automatic scrolling is turned off.
116 void setAutoScroll(bool enabled
);
117 bool autoScroll() const;
120 * If set to true selection-toggles will be shown when hovering
121 * an item. Per default the selection-toggles are disabled.
123 void setEnabledSelectionToggles(bool enabled
);
124 bool enabledSelectionToggles() const;
127 * @return Controller of the item-list. The controller gets
128 * initialized by KItemListController::setView() and will
129 * result in calling KItemListController::onControllerChanged().
131 KItemListController
* controller() const;
134 * @return Model of the item-list. The model gets
135 * initialized by KItemListController::setModel() and will
136 * result in calling KItemListController::onModelChanged().
138 KItemModelBase
* model() const;
141 * Sets the creator that creates a widget showing the
142 * content of one model-item. Usually it is sufficient
143 * to implement a custom widget X derived from KItemListWidget and
144 * set the creator by:
146 * itemListView->setWidgetCreator(new KItemListWidgetCreator<X>());
148 * Note that the ownership of the widget creator is not transferred to
149 * the item-list view: One instance of a widget creator might get shared
150 * by several item-list view instances.
152 void setWidgetCreator(KItemListWidgetCreatorBase
* widgetCreator
);
153 KItemListWidgetCreatorBase
* widgetCreator() const;
155 void setGroupHeaderCreator(KItemListGroupHeaderCreatorBase
* groupHeaderCreator
);
156 KItemListGroupHeaderCreatorBase
* groupHeaderCreator() const;
158 void setStyleOption(const KItemListStyleOption
& option
);
159 const KItemListStyleOption
& styleOption() const;
162 virtual void setGeometry(const QRectF
& rect
);
165 * @return Index of the item that is below the point \a pos.
166 * The position is relative to the upper right of
167 * the visible area. Only (at least partly) visible
168 * items are considered. -1 is returned if no item is
169 * below the position.
171 int itemAt(const QPointF
& pos
) const;
172 bool isAboveSelectionToggle(int index
, const QPointF
& pos
) const;
173 bool isAboveExpansionToggle(int index
, const QPointF
& pos
) const;
176 * @return Index of the first item that is at least partly visible.
177 * -1 is returned if the model contains no items.
179 int firstVisibleIndex() const;
182 * @return Index of the last item that is at least partly visible.
183 * -1 is returned if the model contains no items.
185 int lastVisibleIndex() const;
188 * @return Required size for the item with the index \p index.
189 * The returned value might be larger than KItemListView::itemSize().
190 * In this case the layout grid will be stretched to assure an
193 QSizeF
itemSizeHint(int index
) const;
196 * If set to true, items having child-items can be expanded to show the child-items as
197 * part of the view. Per default the expanding of items is is disabled. If expanding of
198 * items is enabled, the methods KItemModelBase::setExpanded(), KItemModelBase::isExpanded(),
199 * KItemModelBase::isExpandable() and KItemModelBase::expandedParentsCount()
200 * must be reimplemented. The view-implementation
201 * has to take care itself how to visually represent the expanded items provided
204 void setSupportsItemExpanding(bool supportsExpanding
);
205 bool supportsItemExpanding() const;
208 * @return The rectangle of the item relative to the top/left of
209 * the currently visible area (see KItemListView::offset()).
211 QRectF
itemRect(int index
) const;
214 * @return The context rectangle of the item relative to the top/left of
215 * the currently visible area (see KItemListView::offset()). The
216 * context rectangle is defined by by the united rectangle of
217 * the icon rectangle and the text rectangle (see KItemListWidget::iconRect()
218 * and KItemListWidget::textRect()) and is useful as reference for e.g. aligning
219 * a tooltip or a context-menu for an item. Note that a context rectangle will
220 * only be returned for (at least partly) visible items. An empty rectangle will
221 * be returned for fully invisible items.
223 QRectF
itemContextRect(int index
) const;
226 * Scrolls to the item with the index \a index so that the item
227 * will be fully visible.
229 void scrollToItem(int index
);
232 * If several properties of KItemListView are changed synchronously, it is
233 * recommended to encapsulate the calls between beginTransaction() and endTransaction().
234 * This prevents unnecessary and expensive layout-calculations.
236 void beginTransaction();
239 * Counterpart to beginTransaction(). The layout changes will only be animated if
240 * all property changes between beginTransaction() and endTransaction() support
243 void endTransaction();
245 bool isTransactionActive() const;
248 * Turns on the header if \p visible is true. Per default the
249 * header is not visible. Usually the header is turned on when
250 * showing a classic "table-view" to describe the shown columns.
252 void setHeaderVisible(bool visible
);
253 bool isHeaderVisible() const;
256 * @return Header of the list. The header is also available if it is not shown
257 * (see KItemListView::setHeaderShown()).
259 KItemListHeader
* header() const;
262 * @return Pixmap that is used for a drag operation based on the
263 * items given by \a indexes. The default implementation returns
266 virtual QPixmap
createDragPixmap(const QSet
<int>& indexes
) const;
271 virtual void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0);
274 void scrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
275 void scrollOffsetChanged(qreal current
, qreal previous
);
276 void maximumScrollOffsetChanged(qreal current
, qreal previous
);
277 void itemOffsetChanged(qreal current
, qreal previous
);
278 void maximumItemOffsetChanged(qreal current
, qreal previous
);
279 void scrollTo(qreal newOffset
);
282 * Is emitted if the user has changed the sort order by clicking on a
283 * header item (see KItemListView::setHeaderShown()). The sort order
284 * of the model has already been adjusted to
285 * the current sort order. Note that no signal will be emitted if the
286 * sort order of the model has been changed without user interaction.
288 void sortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
291 * Is emitted if the user has changed the sort role by clicking on a
292 * header item (see KItemListView::setHeaderShown()). The sort role
293 * of the model has already been adjusted to
294 * the current sort role. Note that no signal will be emitted if the
295 * sort role of the model has been changed without user interaction.
297 void sortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
300 * Is emitted if the user has changed the visible roles by moving a header
301 * item (see KItemListView::setHeaderShown()). Note that no signal will be
302 * emitted if the roles have been changed without user interaction by
303 * KItemListView::setVisibleRoles().
305 void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
308 virtual void initializeItemListWidget(KItemListWidget
* item
);
311 * @return True if at least one of the changed roles \p changedRoles might result
312 * in the need to update the item-size hint (see KItemListView::itemSizeHint()).
313 * Per default true is returned which means on each role-change of existing items
314 * the item-size hints are recalculated. For performance reasons it is recommended
315 * to return false in case if a role-change will not result in a changed
318 virtual bool itemSizeHintUpdateRequired(const QSet
<QByteArray
>& changedRoles
) const;
320 virtual void onControllerChanged(KItemListController
* current
, KItemListController
* previous
);
321 virtual void onModelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
323 virtual void onScrollOrientationChanged(Qt::Orientation current
, Qt::Orientation previous
);
324 virtual void onItemSizeChanged(const QSizeF
& current
, const QSizeF
& previous
);
325 virtual void onScrollOffsetChanged(qreal current
, qreal previous
);
326 virtual void onVisibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
);
327 virtual void onStyleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
);
328 virtual void onSupportsItemExpandingChanged(bool supportsExpanding
);
330 virtual void onTransactionBegin();
331 virtual void onTransactionEnd();
333 virtual bool event(QEvent
* event
);
334 virtual void mousePressEvent(QGraphicsSceneMouseEvent
* event
);
335 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent
* event
);
336 virtual void dragEnterEvent(QGraphicsSceneDragDropEvent
* event
);
337 virtual void dragMoveEvent(QGraphicsSceneDragDropEvent
* event
);
338 virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent
* event
);
339 virtual void dropEvent(QGraphicsSceneDragDropEvent
* event
);
341 QList
<KItemListWidget
*> visibleItemListWidgets() const;
344 virtual void slotItemsInserted(const KItemRangeList
& itemRanges
);
345 virtual void slotItemsRemoved(const KItemRangeList
& itemRanges
);
346 virtual void slotItemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
347 virtual void slotItemsChanged(const KItemRangeList
& itemRanges
,
348 const QSet
<QByteArray
>& roles
);
350 virtual void slotGroupedSortingChanged(bool current
);
351 virtual void slotSortOrderChanged(Qt::SortOrder current
, Qt::SortOrder previous
);
352 virtual void slotSortRoleChanged(const QByteArray
& current
, const QByteArray
& previous
);
353 virtual void slotCurrentChanged(int current
, int previous
);
354 virtual void slotSelectionChanged(const QSet
<int>& current
, const QSet
<int>& previous
);
357 void slotAnimationFinished(QGraphicsWidget
* widget
,
358 KItemListViewAnimation::AnimationType type
);
359 void slotLayoutTimerFinished();
361 void slotRubberBandPosChanged();
362 void slotRubberBandActivationChanged(bool active
);
365 * Is invoked if the column-width of one role in the header has
366 * been changed by the user. The automatic resizing of columns
367 * will be turned off as soon as this method has been called at
370 void slotHeaderColumnWidthChanged(const QByteArray
& role
,
372 qreal previousWidth
);
375 * Is invoked if a column has been moved by the user. Applies
376 * the moved role to the view.
378 void slotHeaderColumnMoved(const QByteArray
& role
,
383 * Triggers the autoscrolling if autoScroll() is enabled by checking the
384 * current mouse position. If the mouse position is within the autoscroll
385 * margins a timer will be started that periodically triggers the autoscrolling.
387 void triggerAutoScrolling();
390 * Is invoked if the geometry of the parent-widget from a group-header has been
391 * changed. The x-position and width of the group-header gets adjusted to assure
392 * that it always spans the whole width even during temporary transitions of the
395 void slotGeometryOfGroupHeaderParentChanged();
398 enum LayoutAnimationHint
410 void setController(KItemListController
* controller
);
411 void setModel(KItemModelBase
* model
);
413 KItemListRubberBand
* rubberBand() const;
415 void doLayout(LayoutAnimationHint hint
, int changedIndex
= 0, int changedCount
= 0);
418 * Helper method for doLayout: Returns a list of items that can be reused for the visible
419 * area. Invisible group headers get recycled. The reusable items are items that are
420 * invisible. If the animation hint is 'Animation' then items that are currently animated
421 * won't be reused. Reusing items is faster in comparison to deleting invisible
422 * items and creating a new instance for visible items.
424 QList
<int> recycleInvisibleItems(int firstVisibleIndex
,
425 int lastVisibleIndex
,
426 LayoutAnimationHint hint
);
429 * Helper method for doLayout: Starts a moving-animation for the widget to the given
430 * new position. The moving-animation is only started if the new position is within
431 * the same row or column, otherwise the create-animation is used instead.
432 * @return True if the moving-animation has been applied.
434 bool moveWidget(KItemListWidget
* widget
, const QPointF
& newPos
);
436 void emitOffsetChanges();
438 KItemListWidget
* createWidget(int index
);
439 void recycleWidget(KItemListWidget
* widget
);
442 * Changes the index of the widget to \a index and assures a consistent
443 * update for m_visibleItems and m_visibleCells. The cell-information
444 * for the new index will not be updated and be initialized as empty cell.
446 void setWidgetIndex(KItemListWidget
* widget
, int index
);
449 * Changes the index of the widget to \a index. In opposite to
450 * setWidgetIndex() the cell-information for the widget gets updated.
451 * This update gives doLayout() the chance to animate the moving
452 * of the item visually (see moveWidget()).
454 void moveWidgetToIndex(KItemListWidget
* widget
, int index
);
457 * Helper method for prepareLayoutForIncreasedItemCount().
459 void setLayouterSize(const QSizeF
& size
, SizeType sizeType
);
462 * Helper method for createWidget() and setWidgetIndex() to update the properties
463 * of the itemlist widget.
465 void updateWidgetProperties(KItemListWidget
* widget
, int index
);
468 * Helper method for updateWidgetPropertes() to create or update
469 * the itemlist group-header.
471 void updateGroupHeaderForWidget(KItemListWidget
* widget
);
474 * Updates the position and size of the group-header that belongs
475 * to the itemlist widget \a widget. The given widget must represent
476 * the first item of a group.
478 void updateGroupHeaderLayout(KItemListWidget
* widget
);
481 * Recycles the group-header for the widget.
483 void recycleGroupHeaderForWidget(KItemListWidget
* widget
);
486 * Helper method for slotGroupedSortingChanged(), slotSortOrderChanged()
487 * and slotSortRoleChanged(): Iterates through all visible items and updates
488 * the group-header widgets.
490 void updateVisibleGroupHeaders();
493 * @return Index for the item in the list returned by KItemModelBase::groups()
494 * that represents the group where the item with the index \a index
495 * belongs to. -1 is returned if no groups are available.
497 int groupIndexForItem(int index
) const;
500 * Updates the alternate background for all visible items.
501 * @see updateAlternateBackgroundForWidget()
503 void updateAlternateBackgrounds();
506 * Updates the alternateBackground-property of the widget dependent
507 * on the state of useAlternateBackgrounds() and the grouping state.
509 void updateAlternateBackgroundForWidget(KItemListWidget
* widget
);
512 * @return True if alternate backgrounds should be used for the items.
513 * This is the case if an empty item-size is given and if there
514 * is more than one visible role.
516 bool useAlternateBackgrounds() const;
519 * @param itemRanges Items that must be checked for getting the widths of columns.
520 * @return The preferred width of the column of each visible role. The width will
521 * be respected if the width of the item size is <= 0 (see
522 * KItemListView::setItemSize()). Per default an empty hash
525 QHash
<QByteArray
, qreal
> preferredColumnWidths(const KItemRangeList
& itemRanges
) const;
528 * Applies the column-widths from m_headerWidget to the layout
531 void applyColumnWidthsFromHeader();
534 * Applies the column-widths from m_headerWidget to \a widget.
536 void updateWidgetColumnWidths(KItemListWidget
* widget
);
539 * Updates the preferred column-widths of m_groupHeaderWidget by
540 * invoking KItemListView::columnWidths().
542 void updatePreferredColumnWidths(const KItemRangeList
& itemRanges
);
545 * Convenience method for
546 * updatePreferredColumnWidths(KItemRangeList() << KItemRange(0, m_model->count()).
548 void updatePreferredColumnWidths();
551 * Resizes the column-widths of m_headerWidget based on the preferred widths
552 * and the vailable view-size.
554 void applyAutomaticColumnWidths();
557 * @return Sum of the widths of all columns.
559 qreal
columnWidthsSum() const;
562 * @return Boundaries of the header. An empty rectangle is returned
563 * if no header is shown.
565 QRectF
headerBoundaries() const;
568 * @return True if the number of columns or rows will be changed when applying
569 * the new grid- and item-size. Used to determine whether an animation
570 * should be done when applying the new layout.
572 bool changesItemGridLayout(const QSizeF
& newGridSize
,
573 const QSizeF
& newItemSize
,
574 const QSizeF
& newItemMargin
) const;
577 * @param changedItemCount Number of inserted or removed items.
578 * @return True if the inserting or removing of items should be animated.
579 * No animation should be done if the number of items is too large
580 * to provide a pleasant animation.
582 bool animateChangedItemCount(int changedItemCount
) const;
585 * @return True if a scrollbar for the given scroll-orientation is required
586 * when using a size of \p size for the view. Calling the method is rather
587 * expansive as a temporary relayout needs to be done.
589 bool scrollBarRequired(const QSizeF
& size
) const;
592 * Applies the height of the group header to the layouter. The height
593 * depends on the used scroll orientation.
595 void updateGroupHeaderHeight();
598 * Updates the siblings-information for all visible items that are inside
599 * the range of \p firstIndex and \p lastIndex. If firstIndex or lastIndex
600 * is smaller than 0, the siblings-information for all visible items gets
602 * @see KItemListWidget::setSiblingsInformation()
604 void updateSiblingsInformation(int firstIndex
= -1, int lastIndex
= -1);
607 * Helper method for updateExpansionIndicators().
608 * @return True if the item with the index \a index has a sibling successor
609 * (= the item is not the last item of the current hierarchy).
611 bool hasSiblingSuccessor(int index
) const;
614 * Helper function for triggerAutoScrolling().
615 * @param pos Logical position of the mouse relative to the range.
616 * @param range Range of the visible area.
617 * @param oldInc Previous increment. Is used to assure that the increment
618 * increases only gradually.
619 * @return Scroll increment that should be added to the offset().
620 * As soon as \a pos is inside the autoscroll-margin a
621 * value != 0 will be returned.
623 static int calculateAutoScrollingIncrement(int pos
, int range
, int oldInc
);
626 * Helper functions for changesItemCount().
627 * @return The number of items that fit into the available size by
628 * respecting the size of the item and the margin between the items.
630 static int itemsPerSize(qreal size
, qreal itemSize
, qreal itemMargin
);
633 bool m_enabledSelectionToggles
;
635 bool m_supportsItemExpanding
;
636 int m_activeTransactions
; // Counter for beginTransaction()/endTransaction()
637 LayoutAnimationHint m_endTransactionAnimationHint
;
640 KItemListController
* m_controller
;
641 KItemModelBase
* m_model
;
642 QList
<QByteArray
> m_visibleRoles
;
643 KItemListWidgetCreatorBase
* m_widgetCreator
;
644 KItemListGroupHeaderCreatorBase
* m_groupHeaderCreator
;
645 KItemListStyleOption m_styleOption
;
647 QHash
<int, KItemListWidget
*> m_visibleItems
;
648 QHash
<KItemListWidget
*, KItemListGroupHeader
*> m_visibleGroups
;
652 Cell() : column(-1), row(-1) {}
653 Cell(int c
, int r
) : column(c
), row(r
) {}
657 QHash
<int, Cell
> m_visibleCells
;
659 int m_scrollBarExtent
;
660 KItemListSizeHintResolver
* m_sizeHintResolver
;
661 KItemListViewLayouter
* m_layouter
;
662 KItemListViewAnimation
* m_animation
;
664 QTimer
* m_layoutTimer
; // Triggers an asynchronous doLayout() call.
665 qreal m_oldScrollOffset
;
666 qreal m_oldMaximumScrollOffset
;
667 qreal m_oldItemOffset
;
668 qreal m_oldMaximumItemOffset
;
670 bool m_skipAutoScrollForRubberBand
;
671 KItemListRubberBand
* m_rubberBand
;
674 int m_autoScrollIncrement
;
675 QTimer
* m_autoScrollTimer
;
677 KItemListHeader
* m_header
;
678 KItemListHeaderWidget
* m_headerWidget
;
680 friend class KItemListContainer
; // Accesses scrollBarRequired()
681 friend class KItemListHeader
; // Accesses m_headerWidget
682 friend class KItemListController
;
683 friend class KItemListControllerTest
;
687 * Allows to do a fast logical creation and deletion of QGraphicsWidgets
688 * by recycling existing QGraphicsWidgets instances. Is used by
689 * KItemListWidgetCreatorBase and KItemListGroupHeaderCreatorBase.
692 class LIBDOLPHINPRIVATE_EXPORT KItemListCreatorBase
695 virtual ~KItemListCreatorBase();
698 void addCreatedWidget(QGraphicsWidget
* widget
);
699 void pushRecycleableWidget(QGraphicsWidget
* widget
);
700 QGraphicsWidget
* popRecycleableWidget();
703 QSet
<QGraphicsWidget
*> m_createdWidgets
;
704 QList
<QGraphicsWidget
*> m_recycleableWidgets
;
708 * @brief Base class for creating KItemListWidgets.
710 * It is recommended that applications simply use the KItemListWidgetCreator-template class.
711 * For a custom implementation the methods create(), itemSizeHint() and preferredColumnWith()
712 * must be reimplemented. The intention of the widget creator is to prevent repetitive and
713 * expensive instantiations and deletions of KItemListWidgets by recycling existing widget
716 class LIBDOLPHINPRIVATE_EXPORT KItemListWidgetCreatorBase
: public KItemListCreatorBase
719 virtual ~KItemListWidgetCreatorBase();
721 virtual KItemListWidget
* create(KItemListView
* view
) = 0;
723 virtual void recycle(KItemListWidget
* widget
);
725 virtual QSizeF
itemSizeHint(int index
, const KItemListView
* view
) const = 0;
727 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
729 const KItemListView
* view
) const = 0;
733 * @brief Template class for creating KItemListWidgets.
735 * The template class must provide the following two static methods:
736 * - QSizeF itemSizeHint(int index, const KItemListView* view)
737 * - preferredRoleColumnWidth(const QByteArray& role, int index, const KItemListView* view)
738 * Those static methods are used as implementation for
739 * KItemListWidgetCreatorBase::itemSizeHint() and
740 * KItemListWidgetCreatorBase::preferedRoleColumnWidth().
743 class KItemListWidgetCreator
: public KItemListWidgetCreatorBase
746 virtual ~KItemListWidgetCreator();
748 virtual KItemListWidget
* create(KItemListView
* view
);
750 virtual QSizeF
itemSizeHint(int index
, const KItemListView
* view
) const;
752 virtual qreal
preferredRoleColumnWidth(const QByteArray
& role
,
754 const KItemListView
* view
) const;
758 KItemListWidgetCreator
<T
>::~KItemListWidgetCreator()
763 KItemListWidget
* KItemListWidgetCreator
<T
>::create(KItemListView
* view
)
765 KItemListWidget
* widget
= static_cast<KItemListWidget
*>(popRecycleableWidget());
767 widget
= new T(view
);
768 addCreatedWidget(widget
);
774 QSizeF KItemListWidgetCreator
<T
>::itemSizeHint(int index
, const KItemListView
* view
) const
776 return T::itemSizeHint(index
, view
);
780 qreal KItemListWidgetCreator
<T
>::preferredRoleColumnWidth(const QByteArray
& role
,
782 const KItemListView
* view
) const
784 return T::preferredRoleColumnWidth(role
, index
, view
);
788 * @brief Base class for creating KItemListGroupHeaders.
790 * It is recommended that applications simply use the KItemListGroupHeaderCreator-template class.
791 * For a custom implementation the methods create() and recyle() must be reimplemented.
792 * The intention of the group-header creator is to prevent repetitive and expensive instantiations and
793 * deletions of KItemListGroupHeaders by recycling existing header instances.
795 class LIBDOLPHINPRIVATE_EXPORT KItemListGroupHeaderCreatorBase
: public KItemListCreatorBase
798 virtual ~KItemListGroupHeaderCreatorBase();
799 virtual KItemListGroupHeader
* create(KItemListView
* view
) = 0;
800 virtual void recycle(KItemListGroupHeader
* header
);
804 class KItemListGroupHeaderCreator
: public KItemListGroupHeaderCreatorBase
807 virtual ~KItemListGroupHeaderCreator();
808 virtual KItemListGroupHeader
* create(KItemListView
* view
);
812 KItemListGroupHeaderCreator
<T
>::~KItemListGroupHeaderCreator()
817 KItemListGroupHeader
* KItemListGroupHeaderCreator
<T
>::create(KItemListView
* view
)
819 KItemListGroupHeader
* widget
= static_cast<KItemListGroupHeader
*>(popRecycleableWidget());
821 widget
= new T(view
);
822 addCreatedWidget(widget
);