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; }
67 virtual void drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
72 int _percentageBarCol;
83 * Abstract base class for one partition ( mount point ) to display in a
86 * This class contains pure virtuals, so it cannot be used directly.
88 class QY2DiskUsageListItem: public QY2ListViewItem
94 * Call updateData() after the constructor for the initial display
95 * update. Unfortunately, this cannot be done automatically in the
96 * constructor since it uses virtual methods that are not available yet at
99 QY2DiskUsageListItem( QY2DiskUsageList * parent );
105 virtual ~QY2DiskUsageListItem();
111 * The currently used size of this partition.
113 * Derived classes need to implement this method.
116 virtual FSize usedSize() const = 0;
119 * The total size of this partition.
121 * Derived classes need to implement this method.
123 virtual FSize totalSize() const = 0;
126 * The current free size of this partition.
128 * Derived classes can choose reimpmenent this if it is less expensive than
129 * calculating this value each time from usedSize() and totalSize() which
130 * is the default implementation.
132 virtual FSize freeSize() const;
135 * The currently used percentage ( 0..100 ) of this partition.
137 * Derived classes can choose reimpmenent this if it is less expensive than
138 * calculating this value each time from usedSize() and totalSize() which
139 * is the default implementation.
141 virtual int usedPercent() const;
144 * The name to display for this partition.
145 * It makes most sense to use the mount point here ( but this is not a
146 * requirement ). This is what will be displayed in the "Name" column.
148 * Derived classes need to implement this method.
150 virtual QString name() const = 0;
153 * The device name of this partition.
155 * Derived classes may choose to reimplement this method.
156 * This default implementation returns an empty string.
158 virtual QString deviceName() const { return ""; }
162 * Update this item's status ( here: the numeric fields ).
163 * Triggered by QY2ListView::updateAllItemStates().
165 * Reimplemented from QY2ListViewItem.
167 virtual void updateStatus();
170 * Update this item's data completely.
171 * Triggered by QY2ListView::updateAllItemData().
173 * Reimplemented from QY2ListViewItem.
175 virtual void updateData();
178 * Re-declare ordinary setText() method so the compiler doesn't get
179 * confused which one to use.
181 void setText( int column, const QString & text )
182 { QTreeWidgetItem::setText( column, text ); }
185 * Set a column text via FSize.
187 void setText( int column, const FSize & size );
190 * Comparison function used for sorting the list.
196 * Reimplemented from QY2ListViewItem.
198 virtual int compare( QTreeWidgetItem * other,
200 bool ascending ) const;
204 int nameCol() const { return _diskUsageList->nameCol(); }
205 int percentageBarCol() const { return _diskUsageList->percentageBarCol(); }
206 int percentageCol() const { return _diskUsageList->percentageCol(); }
207 int usedSizeCol() const { return _diskUsageList->usedSizeCol(); }
208 int freeSizeCol() const { return _diskUsageList->freeSizeCol(); }
209 int totalSizeCol() const { return _diskUsageList->totalSizeCol(); }
210 int deviceNameCol() const { return _diskUsageList->deviceNameCol(); }
216 * ( Re- ) initialize fields - all displayed fields ( if 'allFields' is
217 * 'true' ) or only the varying fields ( used, free, percentage ).
219 void init( bool allFields );
224 * Reimplemented from QY2ListViewItem.
226 /*virtual void paintCell( QPainter * painter,
227 const QColorGroup & colorGroup,
234 * Paint a percentage bar into a @ref QListViewItem cell.
235 * 'width' is the width of the entire cell.
236 * 'indent' is the number of pixels to indent the bar.
238 * Stolen from KDirStat::KDirTreeView with the author's permission.
240 void paintPercentageBar( float percent,
242 QStyleOptionViewItem option,
243 const QColor & fillColor,
244 const QColor & barBackground );
253 QY2DiskUsageList * _diskUsageList;
259 #endif // ifndef QY2DiskUsageList_h