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;
70 QTreeWidgetItem * itemFromIndex ( const QModelIndex & index ) const
71 { return QY2ListView::itemFromIndex(index); }
76 int _percentageBarCol;
87 * Abstract base class for one partition ( mount point ) to display in a
90 * This class contains pure virtuals, so it cannot be used directly.
92 class QY2DiskUsageListItem: public QY2ListViewItem
98 * Call updateData() after the constructor for the initial display
99 * update. Unfortunately, this cannot be done automatically in the
100 * constructor since it uses virtual methods that are not available yet at
103 QY2DiskUsageListItem( QY2DiskUsageList * parent );
109 virtual ~QY2DiskUsageListItem();
115 * The currently used size of this partition.
117 * Derived classes need to implement this method.
120 virtual FSize usedSize() const = 0;
123 * The total size of this partition.
125 * Derived classes need to implement this method.
127 virtual FSize totalSize() const = 0;
130 * The current free size of this partition.
132 * Derived classes can choose reimpmenent this if it is less expensive than
133 * calculating this value each time from usedSize() and totalSize() which
134 * is the default implementation.
136 virtual FSize freeSize() const;
139 * The currently used percentage ( 0..100 ) of this partition.
141 * Derived classes can choose reimpmenent this if it is less expensive than
142 * calculating this value each time from usedSize() and totalSize() which
143 * is the default implementation.
145 virtual int usedPercent() const;
148 * The name to display for this partition.
149 * It makes most sense to use the mount point here ( but this is not a
150 * requirement ). This is what will be displayed in the "Name" column.
152 * Derived classes need to implement this method.
154 virtual QString name() const = 0;
157 * The device name of this partition.
159 * Derived classes may choose to reimplement this method.
160 * This default implementation returns an empty string.
162 virtual QString deviceName() const { return ""; }
166 * Update this item's status ( here: the numeric fields ).
167 * Triggered by QY2ListView::updateAllItemStates().
169 * Reimplemented from QY2ListViewItem.
171 virtual void updateStatus();
174 * Update this item's data completely.
175 * Triggered by QY2ListView::updateAllItemData().
177 * Reimplemented from QY2ListViewItem.
179 virtual void updateData();
182 * Re-declare ordinary setText() method so the compiler doesn't get
183 * confused which one to use.
185 void setText( int column, const QString & text )
186 { QTreeWidgetItem::setText( column, text ); }
189 * Set a column text via FSize.
191 void setText( int column, const FSize & size );
194 * Comparison function used for sorting the list.
195 * Reimplemented from QTreeWidgetItem
197 virtual bool operator< ( const QTreeWidgetItem & other ) const;
201 int nameCol() const { return _diskUsageList->nameCol(); }
202 int percentageBarCol() const { return _diskUsageList->percentageBarCol(); }
203 int percentageCol() const { return _diskUsageList->percentageCol(); }
204 int usedSizeCol() const { return _diskUsageList->usedSizeCol(); }
205 int freeSizeCol() const { return _diskUsageList->freeSizeCol(); }
206 int totalSizeCol() const { return _diskUsageList->totalSizeCol(); }
207 int deviceNameCol() const { return _diskUsageList->deviceNameCol(); }
213 * ( Re- ) initialize fields - all displayed fields ( if 'allFields' is
214 * 'true' ) or only the varying fields ( used, free, percentage ).
216 void init( bool allFields );
221 * Reimplemented from QY2ListViewItem.
223 /*virtual void paintCell( QPainter * painter,
224 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,
239 QStyleOptionViewItem option,
240 const QColor & fillColor,
241 const QColor & barBackground );
250 QY2DiskUsageList * _diskUsageList;
256 #endif // ifndef QY2DiskUsageList_h