]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kstandarditemlistwidget.h
Merge branch 'release/21.12'
[dolphin.git] / src / kitemviews / kstandarditemlistwidget.h
index c8102e42114d74d828dabee9c305311067ebd16a..060396a55fcb8ca4d50e288393ece2dc1586be3e 100644 (file)
@@ -1,21 +1,8 @@
-/***************************************************************************
- *   Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com>             *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #ifndef KSTANDARDITEMLISTWIDGET_H
 #define KSTANDARDITEMLISTWIDGET_H
@@ -36,12 +23,13 @@ class DOLPHIN_EXPORT KStandardItemListWidgetInformant : public KItemListWidgetIn
 public:
     KStandardItemListWidgetInformant();
     ~KStandardItemListWidgetInformant() override;
-
-    void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const override;
+    
+    void calculateItemSizeHints(QVector<std::pair<qreal /* height */, bool /* isElided */>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const override;
 
     qreal preferredRoleColumnWidth(const QByteArray& role,
                                            int index,
                                            const KItemListView* view) const override;
+
 protected:
     /**
      * @return The value of the "text" role. The default implementation returns
@@ -72,15 +60,15 @@ protected:
     */
     virtual QFont customizedFontForLinks(const QFont& baseFont) const;
 
-    void calculateIconsLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
-    void calculateCompactLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
-    void calculateDetailsLayoutItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
+    void calculateIconsLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
+    void calculateCompactLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
+    void calculateDetailsLayoutItemSizeHints(QVector<std::pair<qreal, bool>>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const;
 
     friend class KStandardItemListWidget; // Accesses roleText()
 };
 
 /**
- * @brief Itemlist widget implementation for KStandardItemListView and KStandardItemModel.
+ * @brief ItemList widget implementation for KStandardItemListView and KStandardItemModel.
  */
 class DOLPHIN_EXPORT KStandardItemListWidget : public KItemListWidget
 {
@@ -100,6 +88,9 @@ public:
     void setLayout(Layout layout);
     Layout layout() const;
 
+    void setHighlightEntireRow(bool highlightEntireRow);
+    bool highlightEntireRow() const;
+
     void setSupportsItemExpanding(bool supportsItemExpanding);
     bool supportsItemExpanding() const;
 
@@ -122,6 +113,12 @@ protected:
      */
     void invalidateCache();
 
+    /**
+     * Invalidates the icon cache which results in calling KStandardItemListWidget::refreshCache() as
+     * soon as the item needs to get repainted.
+     */
+    void invalidateIconCache();
+
     /**
      * Is called if the cache got invalidated by KStandardItemListWidget::invalidateCache().
      * The default implementation is empty.
@@ -174,20 +171,28 @@ protected:
     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 leadingPaddingChanged(qreal width) override;
     void styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) override;
     void hoveredChanged(bool hovered) override;
     void selectedChanged(bool selected) override;
     void siblingsInformationChanged(const QBitArray& current, const QBitArray& previous) override;
     void editedRoleChanged(const QByteArray& current, const QByteArray& previous) override;
+    void iconSizeChanged(int current, int previous) override;
     void resizeEvent(QGraphicsSceneResizeEvent* event) override;
     void showEvent(QShowEvent* event) override;
     void hideEvent(QHideEvent* event) override;
     bool event(QEvent *event) override;
 
-public slots:
+    struct TextInfo
+    {
+        QPointF pos;
+        QStaticText staticText;
+    };
+
+public Q_SLOTS:
     void finishRoleEditing();
 
-private slots:
+private Q_SLOTS:
     void slotCutItemsChanged();
     void slotRoleEditingCanceled(const QByteArray& role, const QVariant& value);
     void slotRoleEditingFinished(const QByteArray& role, const QVariant& value);
@@ -209,6 +214,8 @@ private:
 
     QRectF roleEditingRect(const QByteArray &role) const;
 
+    QString elideRightKeepExtension(const QString &text, int elidingWidth) const;
+
     /**
      * Closes the role editor and returns the focus back
      * to the KItemListContainer.
@@ -230,12 +237,16 @@ private:
      */
     static qreal columnPadding(const KItemListStyleOption& option);
 
+protected:
+    QHash<QByteArray, TextInfo*> m_textInfo; // PlacesItemListWidget needs to access this
+
 private:
     bool m_isCut;
     bool m_isHidden;
     QFont m_customizedFont;
     QFontMetrics m_customizedFontMetrics;
     bool m_isExpandable;
+    bool m_highlightEntireRow;
     bool m_supportsItemExpanding;
 
     bool m_dirtyLayout;
@@ -247,16 +258,10 @@ private:
     QPixmap m_pixmap;
     QSize m_scaledPixmapSize; //Size of the pixmap in device independent pixels
 
+    qreal m_columnWidthSum;
     QRectF m_iconRect;          // Cache for KItemListWidget::iconRect()
     QPixmap m_hoverPixmap;      // Cache for modified m_pixmap when hovering the item
 
-    struct TextInfo
-    {
-        QPointF pos;
-        QStaticText staticText;
-    };
-    QHash<QByteArray, TextInfo*> m_textInfo;
-
     QRectF m_textRect;
 
     QList<QByteArray> m_sortedVisibleRoles;