]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistview.h
Interface cleanups to prepare the return of "grouped sorting"
[dolphin.git] / src / kitemviews / kitemlistview.h
index a2fa23f3e83f8cfbdd5fcfd7afa5f514a0581548..c18f8cb8466a1d7b239c032c65330f1b574b1c5f 100644 (file)
@@ -65,7 +65,8 @@ class LIBDOLPHINPRIVATE_EXPORT KItemListView : public QGraphicsWidget
 {
     Q_OBJECT
 
-    Q_PROPERTY(qreal offset READ offset WRITE setOffset)
+    Q_PROPERTY(qreal scrollOffset READ scrollOffset WRITE setScrollOffset)
+    Q_PROPERTY(qreal itemOffset READ itemOffset WRITE setItemOffset)
 
 public:
     KItemListView(QGraphicsWidget* parent = 0);
@@ -78,17 +79,18 @@ public:
     QSizeF itemSize() const;
 
     // TODO: add note that offset is not checked against maximumOffset, only against 0.
-    void setOffset(qreal offset);
-    qreal offset() const;
+    void setScrollOffset(qreal offset);
+    qreal scrollOffset() const;
 
-    qreal maximumOffset() const;
+    qreal maximumScrollOffset() const;
 
-    /**
-     * Sets the visible roles to \p roles. The integer-value defines
-     * the order of the visible role: Smaller values are ordered first.
-     */
-    void setVisibleRoles(const QHash<QByteArray, int>& roles);
-    QHash<QByteArray, int> visibleRoles() const;
+    void setItemOffset(qreal scrollOffset);
+    qreal itemOffset() const;
+
+    qreal maximumItemOffset() const;
+
+    void setVisibleRoles(const QList<QByteArray>& roles);
+    QList<QByteArray> visibleRoles() const;
 
     /**
      * If set to true an automatic scrolling is done as soon as the
@@ -98,13 +100,6 @@ public:
     void setAutoScroll(bool enabled);
     bool autoScroll() const;
 
-    /**
-     * Turns on the header if \p show is true. Per default the
-     * header is not shown.
-     */
-    void setHeaderShown(bool show);
-    bool isHeaderShown() const;
-
     /**
      * @return Controller of the item-list. The controller gets
      *         initialized by KItemListController::setView() and will
@@ -150,8 +145,21 @@ public:
     int firstVisibleIndex() const;
     int lastVisibleIndex() const;
 
+    /**
+     * @return Required size for the item with the index \p index.
+     *         Per default KItemListView::itemSize() is returned.
+     *         When reimplementing this method it is recommended to
+     *         also reimplement KItemListView::itemSizeHintUpdateRequired().
+     */
     virtual QSizeF itemSizeHint(int index) const;
-    virtual QHash<QByteArray, QSizeF> visibleRoleSizes() const;
+
+    /**
+     * @param itemRanges Items that must be checked for getting the visible roles sizes.
+     * @return The size of each visible role in case if KItemListView::itemSize()
+     *         is empty. This allows to have dynamic but equal role sizes between
+     *         all items. Per default an empty hash is returned.
+     */
+    virtual QHash<QByteArray, QSizeF> visibleRolesSizes(const KItemRangeList& itemRanges) const;
 
     /**
      * @return The bounding rectangle of the item relative to the top/left of
@@ -172,6 +180,13 @@ public:
     void endTransaction();
     bool isTransactionActive() const;
 
+    /**
+     * Turns on the header if \p show is true. Per default the
+     * header is not shown.
+     */
+    void setHeaderShown(bool show);
+    bool isHeaderShown() const;
+
     /**
      * @return Pixmap that is used for a drag operation based on the
      *         items given by \a indexes. The default implementation returns
@@ -185,20 +200,33 @@ public:
     virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
 
 signals:
-    void offsetChanged(qreal current, qreal previous);
-    void maximumOffsetChanged(qreal current, qreal previous);
+    void scrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous);
+    void scrollOffsetChanged(qreal current, qreal previous);
+    void maximumScrollOffsetChanged(qreal current, qreal previous);
+    void itemOffsetChanged(qreal current, qreal previous);
+    void maximumItemOffsetChanged(qreal current, qreal previous);
     void scrollTo(qreal newOffset);
 
 protected:
     virtual void initializeItemListWidget(KItemListWidget* item);
 
+    /**
+     * @return True if at least one of the changed roles \p changedRoles might result
+     *         in the need to update the item-size hint (see KItemListView::itemSizeHint()).
+     *         Per default true is returned which means on each role-change of existing items
+     *         the item-size hints are recalculated. For performance reasons it is recommended
+     *         to return false in case if a role-change will not result in a changed
+     *         item-size hint.
+     */
+    virtual bool itemSizeHintUpdateRequired(const QSet<QByteArray>& changedRoles) const;
+
     virtual void onControllerChanged(KItemListController* current, KItemListController* previous);
     virtual void onModelChanged(KItemModelBase* current, KItemModelBase* previous);
 
     virtual void onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous);
     virtual void onItemSizeChanged(const QSizeF& current, const QSizeF& previous);
-    virtual void onOffsetChanged(qreal current, qreal previous);
-    virtual void onVisibleRolesChanged(const QHash<QByteArray, int>& current, const QHash<QByteArray, int>& previous);
+    virtual void onScrollOffsetChanged(qreal current, qreal previous);
+    virtual void onVisibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous);
     virtual void onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous);
 
     virtual void onTransactionBegin();
@@ -214,15 +242,18 @@ protected:
 
     QList<KItemListWidget*> visibleItemListWidgets() const;
 
+    /** @reimp */
     virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
 
 protected slots:
     virtual void slotItemsInserted(const KItemRangeList& itemRanges);
     virtual void slotItemsRemoved(const KItemRangeList& itemRanges);
+    virtual void slotItemsMoved(const KItemRange& itemRange, const QList<int>& movedToIndexes);
     virtual void slotItemsChanged(const KItemRangeList& itemRanges,
                                   const QSet<QByteArray>& roles);
 
 private slots:
+    void slotGroupedSortingChanged(bool current);
     void slotCurrentChanged(int current, int previous);
     void slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous);
     void slotAnimationFinished(QGraphicsWidget* widget,
@@ -232,6 +263,16 @@ private slots:
     void slotRubberBandPosChanged();
     void slotRubberBandActivationChanged(bool active);
 
+    /**
+     * Is invoked if the visible role-width of one role in the header has
+     * been changed by the user. It is remembered that the user has modified
+     * the role-width, so that it won't be changed anymore automatically to
+     * calculate an optimized width.
+     */
+    void slotVisibleRoleWidthChanged(const QByteArray& role,
+                                     qreal currentWidth,
+                                     qreal previousWidth);
+
     /**
      * Triggers the autoscrolling if autoScroll() is enabled by checking the
      * current mouse position. If the mouse position is within the autoscroll
@@ -283,30 +324,51 @@ private:
     void setLayouterSize(const QSizeF& size, SizeType sizeType);
 
     /**
-     * Marks the visible roles as dirty so that they will get updated when doing the next
-     * layout. The visible roles will only get marked as dirty if an empty item-size is
-     * given.
-     * @return True if the visible roles have been marked as dirty.
+     * Helper method for createWidget() and setWidgetIndex() to update the properties
+     * of the itemlist widget.
      */
-    bool markVisibleRolesSizesAsDirty();
+    void updateWidgetProperties(KItemListWidget* widget, int index);
 
     /**
-     * Updates the m_visibleRoleSizes property and applies the dynamic
-     * size to the layouter.
+     * @return The widths of each visible role that is shown in the KItemListHeader.
      */
-    void applyDynamicItemSize();
+    QHash<QByteArray, qreal> headerRolesWidths() const;
 
     /**
-     * Helper method for createWidget() and setWidgetIndex() to update the properties
-     * of the itemlist widget.
+     * Updates m_visibleRolesSizes by calling KItemListView::visibleRolesSizes().
+     * Nothing will be done if m_itemRect is not empty or custom header-widths
+     * are used (see m_useHeaderWidths). Also m_strechedVisibleRolesSizes will be adjusted
+     * to respect the available view-size.
      */
-    void updateWidgetProperties(KItemListWidget* widget, int index);
+    void updateVisibleRolesSizes(const KItemRangeList& itemRanges);
+
+    /**
+     * Convenience method for updateVisibleRoleSizes(KItemRangeList() << KItemRange(0, m_model->count()).
+     */
+    void updateVisibleRolesSizes();
+
+    /**
+     * Updates m_stretchedVisibleRolesSizes based on m_visibleRolesSizes and the available
+     * view-size. Nothing will be done if m_itemRect is not empty or custom header-widths
+     * are used (see m_useHeaderWidths).
+     */
+    void updateStretchedVisibleRolesSizes();
+
+    /**
+     * @return Sum of the widths of all visible roles.
+     */
+    qreal visibleRolesSizesWidthSum() const;
+
+    /**
+     * @return Sum of the heights of all visible roles.
+     */
+    qreal visibleRolesSizesHeightSum() const;
 
     /**
-     * Updates the width of the KItemListHeader corresponding to the required width of
-     * the roles.
+     * @return Boundaries of the header. An empty rectangle is returned
+     *         if no header is shown.
      */
-    void updateHeaderWidth();
+    QRectF headerBoundaries() const;
 
     /**
      * Helper function for triggerAutoScrolling().
@@ -327,8 +389,9 @@ private:
     QSizeF m_itemSize;
     KItemListController* m_controller;
     KItemModelBase* m_model;
-    QHash<QByteArray, int> m_visibleRoles;
+    QList<QByteArray> m_visibleRoles;
     QHash<QByteArray, QSizeF> m_visibleRolesSizes;
+    QHash<QByteArray, QSizeF> m_stretchedVisibleRolesSizes;
     KItemListWidgetCreatorBase* m_widgetCreator;
     KItemListGroupHeaderCreatorBase* m_groupHeaderCreator;
     KItemListStyleOption m_styleOption;
@@ -342,8 +405,10 @@ private:
     KItemListViewAnimation* m_animation;
 
     QTimer* m_layoutTimer; // Triggers an asynchronous doLayout() call.
-    qreal m_oldOffset;
-    qreal m_oldMaximumOffset;
+    qreal m_oldScrollOffset;
+    qreal m_oldMaximumScrollOffset;
+    qreal m_oldItemOffset;
+    qreal m_oldMaximumItemOffset;
 
     bool m_skipAutoScrollForRubberBand;
     KItemListRubberBand* m_rubberBand;
@@ -353,6 +418,7 @@ private:
     QTimer* m_autoScrollTimer;
 
     KItemListHeader* m_header;
+    bool m_useHeaderWidths;
 
     friend class KItemListController;
 };