]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/QY2DiskUsageList.h
6dc51f7f8cbc2368a7624f66e6e0640f2d6832d1
[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 protected:
70
71     int _nameCol;
72     int _percentageBarCol;
73     int _percentageCol;
74     int _usedSizeCol;
75     int _freeSizeCol;
76     int _totalSizeCol;
77     int _deviceNameCol;
78 };
79
80
81
82 /**
83  * Abstract base class for one partition ( mount point ) to display in a
84  * QY2DiskUsageList.
85  *
86  * This class contains pure virtuals, so it cannot be used directly.
87  **/
88 class QY2DiskUsageListItem: public QY2ListViewItem
89 {
90 protected:
91     /**
92      * Constructor.
93      *
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
97      * this point.
98      **/
99     QY2DiskUsageListItem( QY2DiskUsageList * parent );
100
101
102     /**
103      * Destructor.
104      **/
105     virtual ~QY2DiskUsageListItem();
106
107
108 public:
109
110     /**
111      * The currently used size of this partition.
112      *
113      * Derived classes need to implement this method.
114      **/
115
116     virtual FSize usedSize() const = 0;
117
118     /**
119      * The total size of this partition.
120      *
121      * Derived classes need to implement this method.
122      **/
123     virtual FSize totalSize() const = 0;
124
125     /**
126      * The current free size of this partition.
127      *
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.
131      **/
132     virtual FSize freeSize() const;
133
134     /**
135      * The currently used percentage ( 0..100 ) of this partition.
136      *
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.
140      **/
141     virtual int usedPercent() const;
142
143     /**
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.
147      *
148      * Derived classes need to implement this method.
149      **/
150     virtual QString name() const = 0;
151
152     /**
153      * The device name of this partition.
154      *
155      * Derived classes may choose to reimplement this method.
156      * This default implementation returns an empty string.
157      **/
158     virtual QString deviceName() const { return ""; }
159
160
161     /**
162      * Update this item's status ( here: the numeric fields ).
163      * Triggered by QY2ListView::updateAllItemStates().
164      *
165      * Reimplemented from QY2ListViewItem.
166      **/
167     virtual void updateStatus();
168
169     /**
170      * Update this item's data completely.
171      * Triggered by QY2ListView::updateAllItemData().
172      *
173      * Reimplemented from QY2ListViewItem.
174      **/
175     virtual void updateData();
176
177     /**
178      * Re-declare ordinary setText() method so the compiler doesn't get
179      * confused which one to use.
180      **/
181     void setText( int column, const QString & text )
182         { QTreeWidgetItem::setText( column, text ); }
183
184     /**
185      * Set a column text via FSize.
186      **/
187     void setText( int column, const FSize & size );
188
189     /**
190      * Comparison function used for sorting the list.
191      * Returns:
192      * -1 if this <  other
193      *  0 if this == other
194      * +1 if this >  other
195      *
196      * Reimplemented from QY2ListViewItem.
197      **/
198     virtual int compare( QTreeWidgetItem *      other,
199                          int                    col,
200                          bool                   ascending ) const;
201
202     // Columns
203
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();       }
211
212
213 protected:
214
215     /**
216      * ( Re- ) initialize fields - all displayed fields ( if 'allFields' is
217      * 'true' ) or only the varying fields ( used, free, percentage ).
218      **/
219     void init( bool allFields );
220
221     /**
222      * Paint method.
223      *
224      * Reimplemented from QY2ListViewItem.
225      **/
226     /*virtual void paintCell( QPainter *                painter,
227                             const QColorGroup & colorGroup,
228                             int                 column,
229                             int                 width,
230                             int                 alignment );
231     */
232     public:
233     /**
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.
237      *
238      * Stolen from KDirStat::KDirTreeView with the author's permission.
239      **/
240     void paintPercentageBar( float              percent,
241                              QPainter *         painter,
242                              QStyleOptionViewItem option,
243                              const QColor &     fillColor,
244                              const QColor &     barBackground   );
245
246     protected:
247
248
249     //
250     // Data members
251     //
252
253     QY2DiskUsageList * _diskUsageList;
254 };
255
256
257
258
259 #endif // ifndef QY2DiskUsageList_h