]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kstandarditemlistwidget.h
Build with QT_NO_KEYWORDS
[dolphin.git] / src / kitemviews / kstandarditemlistwidget.h
index 7dd93b2b819babd5e48271ba47a1d89339b166bb..1c3c61c3831ca18d1732ce9a0f2b7e48776ba754 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 <libdolphin_export.h>
-
-#include <kitemviews/kitemlistwidget.h>
+#include "dolphin_export.h"
+#include "kitemviews/kitemlistwidget.h"
 
 #include <QPixmap>
 #include <QPointF>
@@ -32,17 +18,17 @@ class KItemListRoleEditor;
 class KItemListStyleOption;
 class KItemListView;
 
-class LIBDOLPHINPRIVATE_EXPORT KStandardItemListWidgetInformant : public KItemListWidgetInformant
+class DOLPHIN_EXPORT KStandardItemListWidgetInformant : public KItemListWidgetInformant
 {
 public:
     KStandardItemListWidgetInformant();
-    virtual ~KStandardItemListWidgetInformant();
+    ~KStandardItemListWidgetInformant() override;
 
-    virtual QSizeF itemSizeHint(int index, const KItemListView* view) const;
+    void calculateItemSizeHints(QVector<qreal>& logicalHeightHints, qreal& logicalWidthHint, const KItemListView* view) const override;
 
-    virtual qreal preferredRoleColumnWidth(const QByteArray& role,
+    qreal preferredRoleColumnWidth(const QByteArray& role,
                                            int index,
-                                           const KItemListView* view) const;
+                                           const KItemListView* view) const override;
 protected:
     /**
      * @return The value of the "text" role. The default implementation returns
@@ -53,6 +39,13 @@ protected:
      */
     virtual QString itemText(int index, const KItemListView* view) const;
 
+    /**
+     * @return The value of the "isLink" role. The default implementation returns false.
+     *         The derived class should reimplement this function, when information about
+     *         links is available and in usage.
+     */
+    virtual bool itemIsLink(int index, const KItemListView* view) const;
+
     /**
      * @return String representation of the role \a role. The representation of
      *         a role might depend on other roles, so the values of all roles
@@ -61,13 +54,22 @@ protected:
     virtual QString roleText(const QByteArray& role,
                              const QHash<QByteArray, QVariant>& values) const;
 
+    /**
+    * @return A font based on baseFont which is customized for symlinks.
+    */
+    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;
+
     friend class KStandardItemListWidget; // Accesses roleText()
 };
 
 /**
- * @brief Itemlist widget implementation for KStandardItemView and KStandardItemModel.
+ * @brief Itemlist widget implementation for KStandardItemListView and KStandardItemModel.
  */
-class LIBDOLPHINPRIVATE_EXPORT KStandardItemListWidget : public KItemListWidget
+class DOLPHIN_EXPORT KStandardItemListWidget : public KItemListWidget
 {
     Q_OBJECT
 
@@ -80,7 +82,7 @@ public:
     };
 
     KStandardItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent);
-    virtual ~KStandardItemListWidget();
+    ~KStandardItemListWidget() override;
 
     void setLayout(Layout layout);
     Layout layout() const;
@@ -88,14 +90,15 @@ public:
     void setSupportsItemExpanding(bool supportsItemExpanding);
     bool supportsItemExpanding() const;
 
-    virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
+    void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
 
-    virtual QRectF iconRect() const;
-    virtual QRectF textRect() const;
-    virtual QRectF textFocusRect() const;
-    virtual QRectF expansionToggleRect() const;
-    virtual QRectF selectionToggleRect() const;
-    virtual QPixmap createDragPixmap(const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
+    QRectF iconRect() const override;
+    QRectF textRect() const override;
+    QRectF textFocusRect() const override;
+    QRectF selectionRect() const override;
+    QRectF expansionToggleRect() const override;
+    QRectF selectionToggleRect() const override;
+    QPixmap createDragPixmap(const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
 
     static KItemListWidgetInformant* createInformant();
 
@@ -155,19 +158,29 @@ protected:
      */
     virtual int selectionLength(const QString& text) const;
 
-    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 styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous);
-    virtual void hoveredChanged(bool hovered);
-    virtual void selectedChanged(bool selected);
-    virtual void siblingsInformationChanged(const QBitArray& current, const QBitArray& previous);
-    virtual void editedRoleChanged(const QByteArray& current, const QByteArray& previous);
-    virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
-    virtual void showEvent(QShowEvent* event);
-    virtual void hideEvent(QHideEvent* event);
-
-private slots:
+    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 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 resizeEvent(QGraphicsSceneResizeEvent* event) override;
+    void showEvent(QShowEvent* event) override;
+    void hideEvent(QHideEvent* event) override;
+    bool event(QEvent *event) override;
+
+    struct TextInfo
+    {
+        QPointF pos;
+        QStaticText staticText;
+    };
+
+public Q_SLOTS:
+    void finishRoleEditing();
+
+private Q_SLOTS:
     void slotCutItemsChanged();
     void slotRoleEditingCanceled(const QByteArray& role, const QVariant& value);
     void slotRoleEditingFinished(const QByteArray& role, const QVariant& value);
@@ -189,13 +202,15 @@ 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.
      */
     void closeRoleEditor();
 
-    static QPixmap pixmapForIcon(const QString& name, const QStringList& overlays, int size);
+    static QPixmap pixmapForIcon(const QString& name, const QStringList& overlays, int size, QIcon::Mode mode);
 
     /**
      * @return Preferred size of the rating-image based on the given
@@ -210,6 +225,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;
@@ -225,18 +243,11 @@ private:
     Layout m_layout;
     QPointF m_pixmapPos;
     QPixmap m_pixmap;
-    QSize m_scaledPixmapSize;
+    QSize m_scaledPixmapSize; //Size of the pixmap in device independent pixels
 
     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;
@@ -257,5 +268,3 @@ private:
 };
 
 #endif
-
-