1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
9 | contributed Qt widgets |
11 \----------------------------------------------------------------------/
13 File: QY2DiskUsageList.h
15 Author: Stefan Hundhammer <sh@suse.de>
17 This is a pure Qt widget - it can be used independently of YaST2.
22 #ifndef QY2DiskUsageList_h
23 #define QY2DiskUsageList_h
25 #include <QY2ListView.h>
30 class QY2DiskUsageListItem;
34 * Generic scrollable list of disk usage for any number of partitions.
36 class QY2DiskUsageList : public QY2ListView
45 * Adds a standard set of list columns if 'addStdColumns' is
46 *'true'. Otherwise the caller is responsible for adding any columns.
48 QY2DiskUsageList( QWidget * parent, bool addStdColumns = true );
53 virtual ~QY2DiskUsageList();
58 int nameCol() const { return _nameCol; }
59 int percentageBarCol() const { return _percentageBarCol; }
60 int percentageCol() const { return _percentageCol; }
61 int usedSizeCol() const { return _usedSizeCol; }
62 int freeSizeCol() const { return _freeSizeCol; }
63 int totalSizeCol() const { return _totalSizeCol; }
64 int deviceNameCol() const { return _deviceNameCol; }
70 int _percentageBarCol;
81 * Abstract base class for one partition ( mount point ) to display in a
84 * This class contains pure virtuals, so it cannot be used directly.
86 class QY2DiskUsageListItem: public QY2ListViewItem
92 * Call updateData() after the constructor for the initial display
93 * update. Unfortunately, this cannot be done automatically in the
94 * constructor since it uses virtual methods that are not available yet at
97 QY2DiskUsageListItem( QY2DiskUsageList * parent );
103 virtual ~QY2DiskUsageListItem();
109 * The currently used size of this partition.
111 * Derived classes need to implement this method.
114 virtual FSize usedSize() const = 0;
117 * The total size of this partition.
119 * Derived classes need to implement this method.
121 virtual FSize totalSize() const = 0;
124 * The current free size of this partition.
126 * Derived classes can choose reimpmenent this if it is less expensive than
127 * calculating this value each time from usedSize() and totalSize() which
128 * is the default implementation.
130 virtual FSize freeSize() const;
133 * The currently used percentage ( 0..100 ) of this partition.
135 * Derived classes can choose reimpmenent this if it is less expensive than
136 * calculating this value each time from usedSize() and totalSize() which
137 * is the default implementation.
139 virtual int usedPercent() const;
142 * The name to display for this partition.
143 * It makes most sense to use the mount point here ( but this is not a
144 * requirement ). This is what will be displayed in the "Name" column.
146 * Derived classes need to implement this method.
148 virtual QString name() const = 0;
151 * The device name of this partition.
153 * Derived classes may choose to reimplement this method.
154 * This default implementation returns an empty string.
156 virtual QString deviceName() const { return ""; }
160 * Update this item's status ( here: the numeric fields ).
161 * Triggered by QY2ListView::updateAllItemStates().
163 * Reimplemented from QY2ListViewItem.
165 virtual void updateStatus();
168 * Update this item's data completely.
169 * Triggered by QY2ListView::updateAllItemData().
171 * Reimplemented from QY2ListViewItem.
173 virtual void updateData();
176 * Re-declare ordinary setText() method so the compiler doesn't get
177 * confused which one to use.
179 void setText( int column, const QString & text )
180 { QTreeWidgetItem::setText( column, text ); }
183 * Set a column text via FSize.
185 void setText( int column, const FSize & size );
188 * Comparison function used for sorting the list.
194 * Reimplemented from QY2ListViewItem.
196 virtual int compare( QTreeWidgetItem * other,
198 bool ascending ) const;
202 int nameCol() const { return _diskUsageList->nameCol(); }
203 int percentageBarCol() const { return _diskUsageList->percentageBarCol(); }
204 int percentageCol() const { return _diskUsageList->percentageCol(); }
205 int usedSizeCol() const { return _diskUsageList->usedSizeCol(); }
206 int freeSizeCol() const { return _diskUsageList->freeSizeCol(); }
207 int totalSizeCol() const { return _diskUsageList->totalSizeCol(); }
208 int deviceNameCol() const { return _diskUsageList->deviceNameCol(); }
214 * ( Re- ) initialize fields - all displayed fields ( if 'allFields' is
215 * 'true' ) or only the varying fields ( used, free, percentage ).
217 void init( bool allFields );
222 * Reimplemented from QY2ListViewItem.
224 /*virtual void paintCell( QPainter * painter,
225 const QColorGroup & colorGroup,
231 * Paint a percentage bar into a @ref QListViewItem cell.
232 * 'width' is the width of the entire cell.
233 * 'indent' is the number of pixels to indent the bar.
235 * Stolen from KDirStat::KDirTreeView with the author's permission.
237 void paintPercentageBar( float percent,
241 const QColor & fillColor,
242 const QColor & barBackground );
245 * Return a color that contrasts to 'contrastColor'.
247 * Stolen from KDirStat::KDirTreeView with the author's permission.
249 QColor contrastingColor ( const QColor & desiredColor,
250 const QColor & contrastColor );
253 * Interpolate ( in the HSV color space ) a color between 'minColor' and
254 * 'maxColor' for a current value 'val' so that 'minVal' corresponds to
255 * 'minColor' and 'maxVal' to 'maxColor'.
257 * Returns the interpolated color.
259 virtual QColor interpolateColor( int val,
262 const QColor & minColor,
263 const QColor & maxColor );
266 * Interpolate ( translate ) a value 'from' in the range between 'minFrom'
267 * and 'maxFrom' to a range between 'minTo' and 'maxTo'.
269 int interpolate( int from,
270 int minFrom, int maxFrom,
271 int minTo, int maxTo );
278 QY2DiskUsageList * _diskUsageList;
284 #endif // ifndef QY2DiskUsageList_h