libyui-qt
2.43.5
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: QY2DiskUsageList.h 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 This is a pure Qt widget - it can be used independently of YaST2. 00024 00025 /-*/ 00026 00027 00028 #ifndef QY2DiskUsageList_h 00029 #define QY2DiskUsageList_h 00030 00031 #include <QY2ListView.h> 00032 #include <yui/FSize.h> 00033 #include <qcolor.h> 00034 00035 00036 class QY2DiskUsageListItem; 00037 00038 00039 /** 00040 * Generic scrollable list of disk usage for any number of partitions. 00041 **/ 00042 class QY2DiskUsageList : public QY2ListView 00043 { 00044 Q_OBJECT 00045 00046 public: 00047 00048 /** 00049 * Constructor. 00050 * 00051 * Adds a standard set of list columns if 'addStdColumns' is 00052 *'true'. Otherwise the caller is responsible for adding any columns. 00053 **/ 00054 QY2DiskUsageList( QWidget * parent, bool addStdColumns = true ); 00055 00056 /** 00057 * Destructor 00058 **/ 00059 virtual ~QY2DiskUsageList(); 00060 00061 00062 // Column numbers 00063 00064 int nameCol() const { return _nameCol; } 00065 int percentageBarCol() const { return _percentageBarCol; } 00066 int usedSizeCol() const { return _usedSizeCol; } 00067 int freeSizeCol() const { return _freeSizeCol; } 00068 int totalSizeCol() const { return _totalSizeCol; } 00069 int deviceNameCol() const { return _deviceNameCol; } 00070 00071 00072 virtual void drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; 00073 00074 // make it public 00075 QTreeWidgetItem * itemFromIndex ( const QModelIndex & index ) const 00076 { return QY2ListView::itemFromIndex(index); } 00077 00078 protected: 00079 00080 int _nameCol; 00081 int _percentageBarCol; 00082 int _usedSizeCol; 00083 int _freeSizeCol; 00084 int _totalSizeCol; 00085 int _deviceNameCol; 00086 }; 00087 00088 00089 00090 /** 00091 * Abstract base class for one partition ( mount point ) to display in a 00092 * QY2DiskUsageList. 00093 * 00094 * This class contains pure virtuals, so it cannot be used directly. 00095 **/ 00096 class QY2DiskUsageListItem: public QY2ListViewItem 00097 { 00098 protected: 00099 /** 00100 * Constructor. 00101 * 00102 * Call updateData() after the constructor for the initial display 00103 * update. Unfortunately, this cannot be done automatically in the 00104 * constructor since it uses virtual methods that are not available yet at 00105 * this point. 00106 **/ 00107 QY2DiskUsageListItem( QY2DiskUsageList * parent ); 00108 00109 00110 /** 00111 * Destructor. 00112 **/ 00113 virtual ~QY2DiskUsageListItem(); 00114 00115 00116 public: 00117 00118 /** 00119 * The currently used size of this partition. 00120 * 00121 * Derived classes need to implement this method. 00122 **/ 00123 00124 virtual FSize usedSize() const = 0; 00125 00126 /** 00127 * The total size of this partition. 00128 * 00129 * Derived classes need to implement this method. 00130 **/ 00131 virtual FSize totalSize() const = 0; 00132 00133 /** 00134 * The current free size of this partition. 00135 * 00136 * Derived classes can choose reimpmenent this if it is less expensive than 00137 * calculating this value each time from usedSize() and totalSize() which 00138 * is the default implementation. 00139 **/ 00140 virtual FSize freeSize() const; 00141 00142 /** 00143 * The currently used percentage ( 0..100 ) of this partition. 00144 * 00145 * Derived classes can choose reimpmenent this if it is less expensive than 00146 * calculating this value each time from usedSize() and totalSize() which 00147 * is the default implementation. 00148 **/ 00149 virtual int usedPercent() const; 00150 00151 /** 00152 * The name to display for this partition. 00153 * It makes most sense to use the mount point here ( but this is not a 00154 * requirement ). This is what will be displayed in the "Name" column. 00155 * 00156 * Derived classes need to implement this method. 00157 **/ 00158 virtual QString name() const = 0; 00159 00160 /** 00161 * The device name of this partition. 00162 * 00163 * Derived classes may choose to reimplement this method. 00164 * This default implementation returns an empty std::string. 00165 **/ 00166 virtual QString deviceName() const { return ""; } 00167 00168 00169 /** 00170 * Update this item's status ( here: the numeric fields ). 00171 * Triggered by QY2ListView::updateAllItemStates(). 00172 * 00173 * Reimplemented from QY2ListViewItem. 00174 **/ 00175 virtual void updateStatus(); 00176 00177 /** 00178 * Update this item's data completely. 00179 * Triggered by QY2ListView::updateAllItemData(). 00180 * 00181 * Reimplemented from QY2ListViewItem. 00182 **/ 00183 virtual void updateData(); 00184 00185 /** 00186 * Re-declare ordinary setText() method so the compiler doesn't get 00187 * confused which one to use. 00188 **/ 00189 void setText( int column, const QString & text ) 00190 { QTreeWidgetItem::setText( column, text ); } 00191 00192 /** 00193 * Set a column text via FSize. 00194 **/ 00195 void setText( int column, const FSize & size ); 00196 00197 /** 00198 * Comparison function used for sorting the list. 00199 * Reimplemented from QTreeWidgetItem 00200 **/ 00201 virtual bool operator< ( const QTreeWidgetItem & other ) const; 00202 00203 // Columns 00204 00205 int nameCol() const { return _diskUsageList->nameCol(); } 00206 int percentageBarCol() const { return _diskUsageList->percentageBarCol(); } 00207 int usedSizeCol() const { return _diskUsageList->usedSizeCol(); } 00208 int freeSizeCol() const { return _diskUsageList->freeSizeCol(); } 00209 int totalSizeCol() const { return _diskUsageList->totalSizeCol(); } 00210 int deviceNameCol() const { return _diskUsageList->deviceNameCol(); } 00211 00212 00213 protected: 00214 00215 /** 00216 * ( Re- ) initialize fields - all displayed fields ( if 'allFields' is 00217 * 'true' ) or only the varying fields ( used, free, percentage ). 00218 **/ 00219 void init( bool allFields ); 00220 00221 /** 00222 * Paint method. 00223 * 00224 * Reimplemented from QY2ListViewItem. 00225 **/ 00226 /*virtual void paintCell( QPainter * painter, 00227 const QColorGroup & colorGroup, 00228 int column, 00229 int width, 00230 int alignment ); 00231 */ 00232 public: 00233 /** 00234 * Paint a percentage bar into a @ref QListViewItem cell. 00235 * 'width' is the width of the entire cell. 00236 * 'indent' is the number of pixels to indent the bar. 00237 * 00238 * Stolen from KDirStat::KDirTreeView with the author's permission. 00239 **/ 00240 void paintPercentageBar( QPainter * painter, 00241 QStyleOptionViewItem option, 00242 const QColor & fillColor); 00243 00244 protected: 00245 00246 00247 // 00248 // Data members 00249 // 00250 00251 QY2DiskUsageList * _diskUsageList; 00252 }; 00253 00254 00255 00256 00257 #endif // ifndef QY2DiskUsageList_h