]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistwidget.h
New selection effects
[dolphin.git] / src / kitemviews / kitemlistwidget.h
index 9f99b9d951c0d860490741ae0b110e66a2250b97..b87a3b34e65f98e78c0bbcf6609a55953981c5ee 100644 (file)
@@ -22,7 +22,8 @@ class KItemListView;
 class QPropertyAnimation;
 
 /**
- * @brief Provides information for creating an instance of KItemListWidget.
+ * @brief Provides generic information for all KItemListWidgets
+ * for which the construction of any specific KItemListWidget isn't required.
  *
  * KItemListView only creates KItemListWidget instances for the visible
  * area. For calculating the required size of all items the expected
@@ -51,8 +52,6 @@ class DOLPHIN_EXPORT KItemListWidget : public QGraphicsWidget
 {
     Q_OBJECT
 
-    Q_PROPERTY(int iconSize READ iconSize WRITE setIconSize)
-
 public:
     KItemListWidget(KItemListWidgetInformant *informant, QGraphicsItem *parent);
     ~KItemListWidget() override;
@@ -62,6 +61,7 @@ public:
 
     void setData(const QHash<QByteArray, QVariant> &data, const QSet<QByteArray> &roles = QSet<QByteArray>());
     QHash<QByteArray, QVariant> data() const;
+    QVariant value(const QByteArray &key) const;
 
     /**
      * Draws the hover-rectangle if the item is hovered. Overwrite this method
@@ -80,8 +80,9 @@ public:
     void setColumnWidth(const QByteArray &role, qreal width);
     qreal columnWidth(const QByteArray &role) const;
 
-    void setSidePadding(qreal width);
-    qreal sidePadding() const;
+    void setSidePadding(qreal leftPaddingWidth, qreal rightPaddingWidth);
+    qreal leftPadding() const;
+    qreal rightPadding() const;
 
     void setStyleOption(const KItemListStyleOption &option);
     const KItemListStyleOption &styleOption() const;
@@ -97,6 +98,10 @@ public:
     void setHovered(bool hovered);
     bool isHovered() const;
 
+    /** Sets a purely visual pressed highlight effect. */
+    void setPressed(bool enabled);
+    bool isPressed() const;
+
     void setExpansionAreaHovered(bool hover);
     bool expansionAreaHovered() const;
 
@@ -136,18 +141,13 @@ public:
     int iconSize() const;
 
     /**
-     * @return True if \a point is inside KItemListWidget::hoverRect(),
-     *         KItemListWidget::textRect(), KItemListWidget::selectionToggleRect()
+     * @return True if \a point is inside KItemListWidget::selectionRectFull(),
+     *         KItemListWidget::selectionToggleRect()
      *         or KItemListWidget::expansionToggleRect().
      * @reimp
      */
     bool contains(const QPointF &point) const override;
 
-    /**
-     * @return Rectangle for the area that shows the icon.
-     */
-    virtual QRectF iconRect() const = 0;
-
     /**
      * @return Rectangle for the area that contains the text-properties.
      */
@@ -163,9 +163,17 @@ public:
     virtual QRectF textFocusRect() const;
 
     /**
-     * @return Rectangle around which a selection box should be drawn if the item is selected.
+     * Used for drawing the visuals, and situations where we want the behavior of the
+     * selection to match the visuals.
+     *
+     * @return The rectangle around selection.
      */
-    virtual QRectF selectionRect() const = 0;
+    virtual QRectF selectionRectFull() const = 0;
+
+    /**
+     * @return The core area of the item. All of it reacts exactly the same way to mouse clicks.
+     */
+    virtual QRectF selectionRectCore() const = 0;
 
     /**
      * @return Rectangle for the selection-toggle that is used to select or deselect an item.
@@ -187,6 +195,12 @@ public:
      */
     virtual QPixmap createDragPixmap(const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr);
 
+    /**
+     * Starts an animation that makes clear that the item will be activated soon.
+     * @param timeUntilActivation time in milliseconds until the item will activate
+     */
+    virtual void startActivateSoonAnimation(int timeUntilActivation);
+
 Q_SIGNALS:
     void roleEditingCanceled(int index, const QByteArray &role, const QVariant &value);
     void roleEditingFinished(int index, const QByteArray &role, const QVariant &value);
@@ -195,7 +209,7 @@ protected:
     virtual void dataChanged(const QHash<QByteArray, QVariant> &current, const QSet<QByteArray> &roles = QSet<QByteArray>());
     virtual void visibleRolesChanged(const QList<QByteArray> &current, const QList<QByteArray> &previous);
     virtual void columnWidthChanged(const QByteArray &role, qreal current, qreal previous);
-    virtual void sidePaddingChanged(qreal width);
+    virtual void sidePaddingChanged(qreal leftPaddingWidth, qreal rightPaddingWidth);
     virtual void styleOptionChanged(const KItemListStyleOption &current, const KItemListStyleOption &previous);
     virtual void currentChanged(bool current);
     virtual void selectedChanged(bool selected);
@@ -243,8 +257,6 @@ private:
     void drawItemStyleOption(QPainter *painter, QWidget *widget, QStyle::State styleState);
 
 private:
-    Q_PROPERTY(qreal hoverOpacity READ hoverOpacity WRITE setHoverOpacity)
-
     KItemListWidgetInformant *m_informant;
     int m_index;
     bool m_selected;
@@ -253,10 +265,12 @@ private:
     bool m_expansionAreaHovered;
     bool m_alternateBackground;
     bool m_enabledSelectionToggle;
+    bool m_clickHighlighted;
     QHash<QByteArray, QVariant> m_data;
     QList<QByteArray> m_visibleRoles;
     QHash<QByteArray, qreal> m_columnWidths;
-    qreal m_sidePadding;
+    qreal m_leftPadding;
+    qreal m_rightPadding;
     KItemListStyleOption m_styleOption;
     QBitArray m_siblingsInfo;