]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kstandarditemlistwidget.h
Add name-only tooltip and make logicalHeightHints a pair of qreal and bool
[dolphin.git] / src / kitemviews / kstandarditemlistwidget.h
index b13c303bc173f43b151e1757c080eb6102f960ab..f39f51fe486ba53ad5a50453a705040c2b022f94 100644 (file)
@@ -1,28 +1,14 @@
-/***************************************************************************
- *   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
 
 #include "dolphin_export.h"
-
-#include <kitemviews/kitemlistwidget.h>
+#include "kitemviews/kitemlistwidget.h"
 
 #include <QPixmap>
 #include <QPointF>
@@ -37,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
@@ -73,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 KStandardItemView and KStandardItemModel.
+ * @brief ItemList widget implementation for KStandardItemListView and KStandardItemModel.
  */
 class DOLPHIN_EXPORT KStandardItemListWidget : public KItemListWidget
 {
@@ -123,6 +110,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.
@@ -185,10 +178,16 @@ protected:
     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);
@@ -210,6 +209,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.
@@ -231,6 +232,9 @@ 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;
@@ -251,13 +255,6 @@ private:
     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;