2 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef KSTANDARDITEMLISTWIDGET_H
8 #define KSTANDARDITEMLISTWIDGET_H
10 #include "dolphin_export.h"
11 #include "kitemviews/kitemlistwidget.h"
15 #include <QStaticText>
17 class KItemListRoleEditor
;
18 class KItemListStyleOption
;
21 class DOLPHIN_EXPORT KStandardItemListWidgetInformant
: public KItemListWidgetInformant
24 KStandardItemListWidgetInformant();
25 ~KStandardItemListWidgetInformant() override
;
27 void calculateItemSizeHints(QVector
<std::pair
<qreal
/* height */, bool /* isElided */>>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const override
;
29 qreal
preferredRoleColumnWidth(const QByteArray
& role
,
31 const KItemListView
* view
) const override
;
35 * @return The value of the "text" role. The default implementation returns
36 * view->model()->data(index)["text"]. If a derived class can
37 * prevent the (possibly expensive) construction of the
38 * QHash<QByteArray, QVariant> returned by KItemModelBase::data(int),
39 * it can reimplement this function.
41 virtual QString
itemText(int index
, const KItemListView
* view
) const;
44 * @return The value of the "isLink" role. The default implementation returns false.
45 * The derived class should reimplement this function, when information about
46 * links is available and in usage.
48 virtual bool itemIsLink(int index
, const KItemListView
* view
) const;
51 * @return String representation of the role \a role. The representation of
52 * a role might depend on other roles, so the values of all roles
53 * are passed as parameter.
55 virtual QString
roleText(const QByteArray
& role
,
56 const QHash
<QByteArray
, QVariant
>& values
) const;
59 * @return A font based on baseFont which is customized for symlinks.
61 virtual QFont
customizedFontForLinks(const QFont
& baseFont
) const;
63 void calculateIconsLayoutItemSizeHints(QVector
<std::pair
<qreal
, bool>>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const;
64 void calculateCompactLayoutItemSizeHints(QVector
<std::pair
<qreal
, bool>>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const;
65 void calculateDetailsLayoutItemSizeHints(QVector
<std::pair
<qreal
, bool>>& logicalHeightHints
, qreal
& logicalWidthHint
, const KItemListView
* view
) const;
67 friend class KStandardItemListWidget
; // Accesses roleText()
71 * @brief ItemList widget implementation for KStandardItemListView and KStandardItemModel.
73 class DOLPHIN_EXPORT KStandardItemListWidget
: public KItemListWidget
85 KStandardItemListWidget(KItemListWidgetInformant
* informant
, QGraphicsItem
* parent
);
86 ~KStandardItemListWidget() override
;
88 void setLayout(Layout layout
);
89 Layout
layout() const;
91 void setHighlightEntireRow(bool highlightEntireRow
);
92 bool highlightEntireRow() const;
94 void setSupportsItemExpanding(bool supportsItemExpanding
);
95 bool supportsItemExpanding() const;
97 void paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= nullptr) override
;
99 QRectF
iconRect() const override
;
100 QRectF
textRect() const override
;
101 QRectF
textFocusRect() const override
;
102 QRectF
selectionRect() const override
;
103 QRectF
expansionToggleRect() const override
;
104 QRectF
selectionToggleRect() const override
;
105 QPixmap
createDragPixmap(const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= nullptr) override
;
107 static KItemListWidgetInformant
* createInformant();
111 * Invalidates the cache which results in calling KStandardItemListWidget::refreshCache() as
112 * soon as the item need to gets repainted.
114 void invalidateCache();
117 * Invalidates the icon cache which results in calling KStandardItemListWidget::refreshCache() as
118 * soon as the item needs to get repainted.
120 void invalidateIconCache();
123 * Is called if the cache got invalidated by KStandardItemListWidget::invalidateCache().
124 * The default implementation is empty.
126 virtual void refreshCache();
129 * @return True if the give role should be right aligned when showing it inside a column.
130 * Per default false is returned.
132 virtual bool isRoleRightAligned(const QByteArray
& role
) const;
135 * @return True if the item should be visually marked as hidden item. Per default
138 virtual bool isHidden() const;
141 * @return A font based on baseFont which is customized according to the data shown in the widget.
143 virtual QFont
customizedFont(const QFont
& baseFont
) const;
145 virtual QPalette::ColorRole
normalTextColorRole() const;
147 void setTextColor(const QColor
& color
);
148 QColor
textColor() const;
150 void setOverlay(const QPixmap
& overlay
);
151 QPixmap
overlay() const;
154 * @see KStandardItemListWidgetInformant::roleText().
156 QString
roleText(const QByteArray
& role
, const QHash
<QByteArray
, QVariant
>& values
) const;
160 * Select the text without MIME-type extension
161 * This is file-item-specific and should be moved
162 * into KFileItemListWidget.
164 * Inherited classes can define, if the MIME-type extension
165 * should be selected or not.
167 * @return Selection length (with or without MIME-type extension)
169 virtual int selectionLength(const QString
& text
) const;
171 void dataChanged(const QHash
<QByteArray
, QVariant
>& current
, const QSet
<QByteArray
>& roles
= QSet
<QByteArray
>()) override
;
172 void visibleRolesChanged(const QList
<QByteArray
>& current
, const QList
<QByteArray
>& previous
) override
;
173 void columnWidthChanged(const QByteArray
& role
, qreal current
, qreal previous
) override
;
174 void leadingPaddingChanged(qreal width
) override
;
175 void styleOptionChanged(const KItemListStyleOption
& current
, const KItemListStyleOption
& previous
) override
;
176 void hoveredChanged(bool hovered
) override
;
177 void selectedChanged(bool selected
) override
;
178 void siblingsInformationChanged(const QBitArray
& current
, const QBitArray
& previous
) override
;
179 void editedRoleChanged(const QByteArray
& current
, const QByteArray
& previous
) override
;
180 void resizeEvent(QGraphicsSceneResizeEvent
* event
) override
;
181 void showEvent(QShowEvent
* event
) override
;
182 void hideEvent(QHideEvent
* event
) override
;
183 bool event(QEvent
*event
) override
;
188 QStaticText staticText
;
192 void finishRoleEditing();
195 void slotCutItemsChanged();
196 void slotRoleEditingCanceled(const QByteArray
& role
, const QVariant
& value
);
197 void slotRoleEditingFinished(const QByteArray
& role
, const QVariant
& value
);
200 void triggerCacheRefreshing();
201 void updateExpansionArea();
202 void updatePixmapCache();
204 void updateTextsCache();
205 void updateIconsLayoutTextCache();
206 void updateCompactLayoutTextCache();
207 void updateDetailsLayoutTextCache();
209 void updateAdditionalInfoTextColor();
211 void drawPixmap(QPainter
* painter
, const QPixmap
& pixmap
);
212 void drawSiblingsInformation(QPainter
* painter
);
214 QRectF
roleEditingRect(const QByteArray
&role
) const;
216 QString
elideRightKeepExtension(const QString
&text
, int elidingWidth
) const;
219 * Closes the role editor and returns the focus back
220 * to the KItemListContainer.
222 void closeRoleEditor();
224 static QPixmap
pixmapForIcon(const QString
& name
, const QStringList
& overlays
, int size
, QIcon::Mode mode
);
227 * @return Preferred size of the rating-image based on the given
228 * style-option. The height of the font is taken as
231 static QSizeF
preferredRatingSize(const KItemListStyleOption
& option
);
234 * @return Horizontal padding in pixels that is added to the required width of
235 * a column to display the content.
237 static qreal
columnPadding(const KItemListStyleOption
& option
);
240 QHash
<QByteArray
, TextInfo
*> m_textInfo
; // PlacesItemListWidget needs to access this
245 QFont m_customizedFont
;
246 QFontMetrics m_customizedFontMetrics
;
248 bool m_highlightEntireRow
;
249 bool m_supportsItemExpanding
;
253 QSet
<QByteArray
> m_dirtyContentRoles
;
258 QSize m_scaledPixmapSize
; //Size of the pixmap in device independent pixels
260 qreal m_columnWidthSum
;
261 QRectF m_iconRect
; // Cache for KItemListWidget::iconRect()
262 QPixmap m_hoverPixmap
; // Cache for modified m_pixmap when hovering the item
266 QList
<QByteArray
> m_sortedVisibleRoles
;
268 QRectF m_expansionArea
;
270 QColor m_customTextColor
;
271 QColor m_additionalInfoTextColor
;
276 KItemListRoleEditor
* m_roleEditor
;
277 KItemListRoleEditor
* m_oldRoleEditor
;
279 friend class KStandardItemListWidgetInformant
; // Accesses private static methods to be able to
280 // share a common layout calculation