]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/QY2DiskUsageList.h
clicking packages work! so the package selector is now
[duncan/yast2-qt4.git] / src / QY2DiskUsageList.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                          contributed Qt widgets                      |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       QY2DiskUsageList.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   This is a pure Qt widget - it can be used independently of YaST2.
18
19 /-*/
20
21
22 #ifndef QY2DiskUsageList_h
23 #define QY2DiskUsageList_h
24
25 #include <QY2ListView.h>
26 #include <FSize.h>
27 #include <qcolor.h>
28
29
30 class QY2DiskUsageListItem;
31
32
33 /**
34  * Generic scrollable list of disk usage for any number of partitions.
35  **/
36 class QY2DiskUsageList : public QY2ListView
37 {
38     Q_OBJECT
39
40 public:
41
42     /**
43      * Constructor.
44      *
45      * Adds a standard set of list columns if 'addStdColumns' is
46      *'true'. Otherwise the caller is responsible for adding any columns.
47      **/
48     QY2DiskUsageList( QWidget * parent, bool addStdColumns = true );
49
50     /**
51      * Destructor
52      **/
53     virtual ~QY2DiskUsageList();
54
55
56     // Column numbers
57
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;        }
65
66
67     virtual void drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
68
69     // make it public
70     QTreeWidgetItem * itemFromIndex ( const QModelIndex & index ) const
71     { return QY2ListView::itemFromIndex(index); }
72
73 protected:
74
75     int _nameCol;
76     int _percentageBarCol;
77     int _percentageCol;
78     int _usedSizeCol;
79     int _freeSizeCol;
80     int _totalSizeCol;
81     int _deviceNameCol;
82 };
83
84
85
86 /**
87  * Abstract base class for one partition ( mount point ) to display in a
88  * QY2DiskUsageList.
89  *
90  * This class contains pure virtuals, so it cannot be used directly.
91  **/
92 class QY2DiskUsageListItem: public QY2ListViewItem
93 {
94 protected:
95     /**
96      * Constructor.
97      *
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
101      * this point.
102      **/
103     QY2DiskUsageListItem( QY2DiskUsageList * parent );
104
105
106     /**
107      * Destructor.
108      **/
109     virtual ~QY2DiskUsageListItem();
110
111
112 public:
113
114     /**
115      * The currently used size of this partition.
116      *
117      * Derived classes need to implement this method.
118      **/
119
120     virtual FSize usedSize() const = 0;
121
122     /**
123      * The total size of this partition.
124      *
125      * Derived classes need to implement this method.
126      **/
127     virtual FSize totalSize() const = 0;
128
129     /**
130      * The current free size of this partition.
131      *
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.
135      **/
136     virtual FSize freeSize() const;
137
138     /**
139      * The currently used percentage ( 0..100 ) of this partition.
140      *
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.
144      **/
145     virtual int usedPercent() const;
146
147     /**
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.
151      *
152      * Derived classes need to implement this method.
153      **/
154     virtual QString name() const = 0;
155
156     /**
157      * The device name of this partition.
158      *
159      * Derived classes may choose to reimplement this method.
160      * This default implementation returns an empty string.
161      **/
162     virtual QString deviceName() const { return ""; }
163
164
165     /**
166      * Update this item's status ( here: the numeric fields ).
167      * Triggered by QY2ListView::updateAllItemStates().
168      *
169      * Reimplemented from QY2ListViewItem.
170      **/
171     virtual void updateStatus();
172
173     /**
174      * Update this item's data completely.
175      * Triggered by QY2ListView::updateAllItemData().
176      *
177      * Reimplemented from QY2ListViewItem.
178      **/
179     virtual void updateData();
180
181     /**
182      * Re-declare ordinary setText() method so the compiler doesn't get
183      * confused which one to use.
184      **/
185     void setText( int column, const QString & text )
186         { QTreeWidgetItem::setText( column, text ); }
187
188     /**
189      * Set a column text via FSize.
190      **/
191     void setText( int column, const FSize & size );
192
193     /**
194      * Comparison function used for sorting the list.
195      * Reimplemented from QTreeWidgetItem
196      **/
197     virtual bool operator< ( const QTreeWidgetItem & other ) const;
198
199     // Columns
200
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();       }
208
209
210 protected:
211
212     /**
213      * ( Re- ) initialize fields - all displayed fields ( if 'allFields' is
214      * 'true' ) or only the varying fields ( used, free, percentage ).
215      **/
216     void init( bool allFields );
217
218     /**
219      * Paint method.
220      *
221      * Reimplemented from QY2ListViewItem.
222      **/
223     /*virtual void paintCell( QPainter *                painter,
224                             const QColorGroup & colorGroup,
225                             int                 column,
226                             int                 width,
227                             int                 alignment );
228     */
229     public:
230     /**
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.
234      *
235      * Stolen from KDirStat::KDirTreeView with the author's permission.
236      **/
237     void paintPercentageBar( float              percent,
238                              QPainter *         painter,
239                              QStyleOptionViewItem option,
240                              const QColor &     fillColor,
241                              const QColor &     barBackground   );
242
243     protected:
244
245
246     //
247     // Data members
248     //
249
250     QY2DiskUsageList * _diskUsageList;
251 };
252
253
254
255
256 #endif // ifndef QY2DiskUsageList_h