File indexing completed on 2024-04-28 05:45:07
0001 /* 0002 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KITEMLISTHEADER_H 0008 #define KITEMLISTHEADER_H 0009 0010 #include "dolphin_export.h" 0011 0012 #include <QHash> 0013 #include <QObject> 0014 0015 class KItemListHeaderWidget; 0016 class KItemListView; 0017 0018 /** 0019 * @brief Provides access to the header of a KItemListView. 0020 * 0021 * Each column of the header represents a visible role 0022 * accessible by KItemListView::visibleRoles(). 0023 */ 0024 class DOLPHIN_EXPORT KItemListHeader : public QObject 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 ~KItemListHeader() override; 0030 0031 /** 0032 * If set to true, KItemListView will automatically adjust the 0033 * widths of the columns. If set to false, the size can be 0034 * manually adjusted by KItemListHeader::setColumnWidth(). 0035 */ 0036 void setAutomaticColumnResizing(bool automatic); 0037 bool automaticColumnResizing() const; 0038 0039 /** 0040 * Sets the width of the column for the given role. Note that 0041 * the width only gets applied if KItemListHeader::automaticColumnResizing() 0042 * has been turned off. 0043 */ 0044 void setColumnWidth(const QByteArray &role, qreal width); 0045 qreal columnWidth(const QByteArray &role) const; 0046 0047 /** 0048 * Sets the widths of the columns for all roles. From a performance point of 0049 * view calling this method should be preferred over several setColumnWidth() 0050 * calls in case if the width of more than one column should be changed. 0051 * Note that the widths only get applied if KItemListHeader::automaticColumnResizing() 0052 * has been turned off. 0053 */ 0054 void setColumnWidths(const QHash<QByteArray, qreal> &columnWidths); 0055 0056 /** 0057 * @return The column width that is required to show the role unclipped. 0058 */ 0059 qreal preferredColumnWidth(const QByteArray &role) const; 0060 0061 /** 0062 * Sets the width of the column *before* the first column. 0063 * This is intended to facilitate an empty region for deselection in the main viewport. 0064 */ 0065 void setSidePadding(qreal width); 0066 qreal sidePadding() const; 0067 0068 Q_SIGNALS: 0069 void sidePaddingChanged(qreal width); 0070 0071 /** 0072 * Is emitted if the width of a column has been adjusted by the user with the mouse 0073 * (no signal is emitted if KItemListHeader::setColumnWidth() is invoked). 0074 */ 0075 void columnWidthChanged(const QByteArray &role, qreal currentWidth, qreal previousWidth); 0076 0077 /** 0078 * Is emitted if the user has released the mouse button after adjusting the 0079 * width of a visible role. 0080 */ 0081 void columnWidthChangeFinished(const QByteArray &role, qreal currentWidth); 0082 0083 private: 0084 explicit KItemListHeader(KItemListView *listView); 0085 0086 private: 0087 KItemListView *m_view; 0088 KItemListHeaderWidget *m_headerWidget; 0089 0090 friend class KItemListView; // Constructs the KItemListHeader instance 0091 }; 0092 0093 #endif