Commit 0ff13cde authored by Simon Persson's avatar Simon Persson

Add display of file sizes to the version list delegate.

parent 0b99ea7b
......@@ -21,6 +21,7 @@
#include "versionlistdelegate.h"
#include "versionlistmodel.h"
#include <KGlobal>
#include <KLocale>
#include <QAbstractItemView>
#include <QAbstractItemModel>
......@@ -198,8 +199,16 @@ void VersionListDelegate::paint(QPainter *pPainter, const QStyleOptionViewItem &
pPainter->save();
pPainter->setPen(pOption.palette.color(pOption.state & QStyle::State_Selected
? QPalette::HighlightedText: QPalette::Text));
QString lDateText = pOption.fontMetrics.elidedText(pIndex.data().toString(), Qt::ElideRight, pOption.rect.width() /*- sizeKBRect.width */);
pPainter->drawText(pOption.rect.topLeft() + QPoint(cMargin, cMargin+pOption.fontMetrics.ascent()), lDateText);
QRect lMarginRect = pOption.rect.adjusted(cMargin, cMargin, -cMargin, -cMargin);
QRect lSizeDisplayBounds;
if(!pIndex.data(VersionIsDirectoryRole).toBool()) {
QString lSizeText = KGlobal::locale()->formatByteSize((double)pIndex.data(VersionSizeRole).toULongLong(), 1);
pPainter->drawText(lMarginRect, Qt::AlignRight | Qt::AlignTop, lSizeText, &lSizeDisplayBounds);
}
QString lDateText = pOption.fontMetrics.elidedText(pIndex.data().toString(), Qt::ElideRight,
lMarginRect.width() - lSizeDisplayBounds.width());
pPainter->drawText(lMarginRect, Qt::AlignLeft | Qt::AlignTop, lDateText);
pPainter->restore();
VersionItemAnimation *lAnimation = mActiveAnimations.value(pIndex);
......
......@@ -72,6 +72,8 @@ QVariant VersionListModel::data(const QModelIndex &pIndex, int pRole) const {
lSourceInfo.mSize = lData->size();
return QVariant::fromValue<BupSourceInfo>(lSourceInfo);
}
case VersionIsDirectoryRole:
return mNode->isDirectory();
default:
return QVariant();
}
......
......@@ -51,10 +51,11 @@ protected:
};
enum VersionDataRole {
VersionBupUrlRole = Qt::UserRole + 1, //KUrl
VersionMimeTypeRole, //QString
VersionBupUrlRole = Qt::UserRole + 1, // KUrl
VersionMimeTypeRole, // QString
VersionSizeRole, // quint64
VersionSourceInfoRole //PathInfo
VersionSourceInfoRole, // PathInfo
VersionIsDirectoryRole // bool
};
#endif // VERSIONLISTMODEL_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment