]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kstandarditemlistwidget.h
New selection effects
[dolphin.git] / src / kitemviews / kstandarditemlistwidget.h
index 1313179c96703b52fdb13e63ebcacd5153781155..cabe3a8c963a0aa24c1a28803deb92610f054bf6 100644 (file)
 #include "kitemviews/kitemlistwidget.h"
 
 #include <QPixmap>
+#include <QPointer>
 #include <QPointF>
 #include <QStaticText>
 
 class KItemListRoleEditor;
 class KItemListStyleOption;
 class KItemListView;
+class QVariantAnimation;
 
+/**
+ * @brief standard implementation of the ItemList widget informant for use with KStandardItemListView and KStandardItemModel.
+ *
+ * @see KItemListWidgetInformant
+ */
 class DOLPHIN_EXPORT KStandardItemListWidgetInformant : public KItemListWidgetInformant
 {
 public:
@@ -47,12 +54,19 @@ protected:
      */
     virtual bool itemIsLink(int index, const KItemListView *view) const;
 
+    /** Configure whether the requested text should be optimized for viewing on a screen or for being read out aloud by a text-to-speech engine. */
+    enum class ForUsageAs { DisplayedText, SpokenText };
+
     /**
+     * @param role          The role the text is being requested for.
+     * @param values        The data of the item. All the data is passed because the text might depend on multiple data points.
+     * @param forUsageAs    Whether the roleText should be optimized for displaying (i.e. kept somewhat short) or optimized for speaking e.g. by screen readers
+     *                      or text-to-speech in general (i.e. by prefering announcing a month as July instead of as the number 7).
      * @return String representation of the role \a role. The representation of
      *         a role might depend on other roles, so the values of all roles
      *         are passed as parameter.
      */
-    virtual QString roleText(const QByteArray &role, const QHash<QByteArray, QVariant> &values) const;
+    virtual QString roleText(const QByteArray &role, const QHash<QByteArray, QVariant> &values, ForUsageAs forUsageAs = ForUsageAs::DisplayedText) const;
 
     /**
     * @return A font based on baseFont which is customized for symlinks.
@@ -67,7 +81,9 @@ protected:
 };
 
 /**
- * @brief ItemList widget implementation for KStandardItemListView and KStandardItemModel.
+ * @brief standard implementation of an ItemList widget for KStandardItemListView and KStandardItemModel.
+ *
+ * @see KItemListWidget
  */
 class DOLPHIN_EXPORT KStandardItemListWidget : public KItemListWidget
 {
@@ -80,7 +96,6 @@ public:
     ~KStandardItemListWidget() override;
 
     void setLayout(Layout layout);
-    Layout layout() const;
 
     void setHighlightEntireRow(bool highlightEntireRow);
     bool highlightEntireRow() const;
@@ -90,13 +105,15 @@ public:
 
     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
 
-    QRectF iconRect() const override;
     QRectF textRect() const override;
     QRectF textFocusRect() const override;
-    QRectF selectionRect() const override;
+    QRectF selectionRectFull() const override;
+    QRectF selectionRectCore() const override;
     QRectF expansionToggleRect() const override;
     QRectF selectionToggleRect() const override;
     QPixmap createDragPixmap(const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
+    /** @see KItemListWidget::startActivateSoonAnimation() */
+    void startActivateSoonAnimation(int timeUntilActivation) override;
 
     static KItemListWidgetInformant *createInformant();
 
@@ -141,31 +158,25 @@ protected:
     void setTextColor(const QColor &color);
     QColor textColor(const QWidget &widget) const;
 
-    void setOverlay(const QPixmap &overlay);
-    QPixmap overlay() const;
+    void setOverlays(QHash<Qt::Corner, QString> &overlay);
+    QHash<Qt::Corner, QString> overlays() const;
 
     /**
      * @see KStandardItemListWidgetInformant::roleText().
      */
     QString roleText(const QByteArray &role, const QHash<QByteArray, QVariant> &values) const;
 
+    static int numberOfUnicodeCharactersIn(const QString &text);
+
     /**
-     * Fixes:
-     * Select the text without MIME-type extension
-     * This is file-item-specific and should be moved
-     * into KFileItemListWidget.
-     *
-     * Inherited classes can define, if the MIME-type extension
-     * should be selected or not.
-     *
-     * @return Selection length (with or without MIME-type extension)
+     * @return Selection length (with or without MIME-type extension) in number of unicode characters, which might be different from number of QChars.
      */
     virtual int selectionLength(const QString &text) const;
 
     void dataChanged(const QHash<QByteArray, QVariant> &current, const QSet<QByteArray> &roles = QSet<QByteArray>()) override;
     void visibleRolesChanged(const QList<QByteArray> &current, const QList<QByteArray> &previous) override;
     void columnWidthChanged(const QByteArray &role, qreal current, qreal previous) override;
-    void sidePaddingChanged(qreal width) override;
+    void sidePaddingChanged(qreal leftPaddingWidth, qreal rightPaddingWidth) override;
     void styleOptionChanged(const KItemListStyleOption &current, const KItemListStyleOption &previous) override;
     void hoveredChanged(bool hovered) override;
     void selectedChanged(bool selected) override;
@@ -201,12 +212,26 @@ private:
     void updateCompactLayoutTextCache();
     void updateDetailsLayoutTextCache();
 
+    QPixmap addOverlays(const QPixmap &pixmap,
+                        const QHash<Qt::Corner, QString> &overlays,
+                        const QSize &size,
+                        qreal devicePixelRatioF,
+                        QIcon::Mode mode = QIcon::Normal) const;
+
     void drawPixmap(QPainter *painter, const QPixmap &pixmap);
+    /** Draw the lines and arrows that visualize the expanded state and level of this row. */
     void drawSiblingsInformation(QPainter *painter);
 
     QRectF roleEditingRect(const QByteArray &role) const;
 
-    QString elideRightKeepExtension(const QString &text, int elidingWidth) const;
+    QString elideText(QString text, qreal elidingWidth) const;
+
+    /**
+     * Escapes text for display purposes.
+     *
+     * Replaces '\n' with Unicode line break (U+21B5).
+     */
+    QString escapeString(const QString &text) const;
 
     /**
      * Closes the role editor and returns the focus back
@@ -214,7 +239,7 @@ private:
      */
     void closeRoleEditor();
 
-    QPixmap pixmapForIcon(const QString &name, const QStringList &overlays, int size, QIcon::Mode mode) const;
+    QPixmap pixmapForIcon(const QString &name, const QSize &size, QIcon::Mode mode) const;
 
     /**
      * @return Preferred size of the rating-image based on the given
@@ -229,6 +254,9 @@ private:
      */
     static qreal columnPadding(const KItemListStyleOption &option);
 
+    /** @returns whether the usual icon should be shown or not. */
+    bool isIconControlledByActivateSoonAnimation() const;
+
 protected:
     QHash<QByteArray, TextInfo *> m_textInfo; // PlacesItemListWidget needs to access this
 
@@ -252,7 +280,6 @@ private:
 
     qreal m_columnWidthSum;
     QRectF m_iconRect; // Cache for KItemListWidget::iconRect()
-    QPixmap m_hoverPixmap; // Cache for modified m_pixmap when hovering the item
 
     QRectF m_textRect;
 
@@ -263,12 +290,15 @@ private:
     QColor m_customTextColor;
     QColor m_additionalInfoTextColor;
 
-    QPixmap m_overlay;
+    QHash<Qt::Corner, QString> m_overlays;
     QPixmap m_rating;
 
     KItemListRoleEditor *m_roleEditor;
     KItemListRoleEditor *m_oldRoleEditor;
 
+    /** @see startActivateSoonAnimation() */
+    QPointer<QVariantAnimation> m_activateSoonAnimation;
+
     friend class KStandardItemListWidgetInformant; // Accesses private static methods to be able to
                                                    // share a common layout calculation
 };