30 #include "QY2DiskUsageList.h"
33 #include <QItemDelegate>
40 #define TEXTDOMAIN "qt"
48 contrastingColor(
const QColor & desiredColor,
49 const QColor & contrastColor )
51 if ( desiredColor != contrastColor )
56 if ( contrastColor != contrastColor.light() )
59 return contrastColor.light();
64 return contrastColor.dark();
73 interpolate(
int from,
74 int minFrom,
int maxFrom,
75 int minTo,
int maxTo )
77 if ( minFrom > maxFrom )
86 long x = from - minFrom;
88 x /= maxFrom - minFrom;
93 if ( x < minTo ) x = minTo;
94 if ( x > maxTo ) x = maxTo;
98 if ( x < maxTo ) x = maxTo;
99 if ( x > minTo ) x = minTo;
113 interpolateColor(
int val,
116 const QColor & minColor,
117 const QColor & maxColor )
123 minColor.getHsv( &minH, &minS, &minV );
124 maxColor.getHsv( &maxH, &maxS, &maxV );
126 return QColor::fromHsv( interpolate( val, minVal, maxVal, minH, maxH ),
127 interpolate( val, minVal, maxVal, minS, maxS ),
128 interpolate( val, minVal, maxVal, minV, maxV ) );
140 virtual void paint ( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index )
const
143 QColor background = option.palette.color(QPalette::Window);
144 painter->setBackground( background );
153 QColor( 0, 0xa0, 0 ),
154 QColor( 0xFF, 0, 0 ) ) );
164 _percentageBarCol = -42;
168 _deviceNameCol = -42;
173 QString savedtextdomain = textdomain(NULL);
174 textdomain(TEXTDOMAIN);
176 QStringList columnLabels;
180 columnLabels << _(
"Name" ); _nameCol = numCol++;
182 columnLabels << _(
"Disk Usage"); _percentageBarCol = numCol++;
185 columnLabels << _(
"Free"); _freeSizeCol = numCol++;
186 columnLabels << _(
"Total"); _totalSizeCol = numCol++;
188 addColumn( _(
"Device" ) ); _deviceNameCol = numCol++;
191 setColumnCount(numCol);
192 setHeaderLabels(columnLabels);
194 sortItems( percentageBarCol(), Qt::AscendingOrder );
195 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
198 textdomain(savedtextdomain.toLatin1());
201 setSelectionMode(QAbstractItemView::NoSelection);
210 void QY2DiskUsageList::drawRow( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index )
const
215 QTreeWidget::drawRow( painter, option, index );
221 , _diskUsageList( parent )
239 setSizeHint( percentageBarCol(), QSize( 20, 10 ) );
241 setTextAlignment( usedSizeCol(), Qt::AlignRight );
242 setTextAlignment( freeSizeCol(), Qt::AlignRight );
243 setTextAlignment( totalSizeCol(), Qt::AlignRight );
251 if ( nameCol() >= 0 )
setText( nameCol(),
name() );
255 if ( usedSizeCol() < 0 )
256 setToolTip( freeSizeCol(), _(
"Used %1" ).arg(
usedSize().form( 0, 1,
true ).c_str() ) );
263 QString sizeText = size.form( 0, 1,
true ).c_str();
312 int col = treeWidget()->sortColumn();
316 if ( col == percentageBarCol() )
321 else if ( col == usedSizeCol() )
325 else if ( col == freeSizeCol() )
329 else if ( col == totalSizeCol() )
343 QStyleOptionViewItem option,
344 const QColor & fillColor )
347 if ( percent > 100.0 ) percent = 100.0;
348 if ( percent < 0.0 ) percent = 0.0;
349 int x = option.rect.left() + 1;
350 int y = option.rect.top() + 1;
351 int w = option.rect.width() - 2;
352 int h = option.rect.height() - 2;
357 fillWidth = (int) ( w * percent / 100.0 );
361 painter->fillRect( x, y, fillWidth, h,
364 QString percentageText;
368 painter->setPen( treeWidget()->palette().color( QPalette::Base ) );
369 painter->drawText( QRect( x, y,
371 Qt::AlignRight, percentageText );
373 painter->setPen( treeWidget()->palette().color( QPalette::Text ) );
374 painter->drawText( QRect( x + fillWidth + 3, y,
375 w - fillWidth - 3, h ),
376 Qt::AlignLeft, percentageText );
382 #include "QY2DiskUsageList.moc"
virtual FSize totalSize() const =0
The total size of this partition.
QY2DiskUsageList(QWidget *parent, bool addStdColumns=true)
Constructor.
virtual bool operator<(const QTreeWidgetItem &other) const
Comparison function used for sorting the list.
virtual int usedPercent() const
The currently used percentage ( 0..100 ) of this partition.
virtual QString deviceName() const
The device name of this partition.
virtual FSize usedSize() const =0
The currently used size of this partition.
virtual void updateStatus()
Update this item's status ( here: the numeric fields ).
QY2DiskUsageListItem(QY2DiskUsageList *parent)
Constructor.
virtual void updateData()
Update this item's data completely.
void saveColumnWidths()
Save the current column widths.
virtual FSize freeSize() const
The current free size of this partition.
virtual QString name() const =0
The name to display for this partition.
Abstract base class for one partition ( mount point ) to display in a QY2DiskUsageList.
virtual bool operator<(const QTreeWidgetItem &other) const
Comparison function used for sorting the list.
void init(bool allFields)
( Re- ) initialize fields - all displayed fields ( if 'allFields' is 'true' ) or only the varying fie...
Generic scrollable list of disk usage for any number of partitions.
void setText(int column, const QString &text)
Re-declare ordinary setText() method so the compiler doesn't get confused which one to use...
virtual ~QY2DiskUsageListItem()
Destructor.
void paintPercentageBar(QPainter *painter, QStyleOptionViewItem option, const QColor &fillColor)
Paint a percentage bar into a QListViewItem cell.
Enhanced QTreeWidgetItem.
virtual ~QY2DiskUsageList()
Destructor.