Put last DL column in order

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6666 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-09-01 13:56:05 +00:00
parent 5dee253030
commit a6905df48c
3 changed files with 20 additions and 12 deletions

View File

@ -25,6 +25,8 @@
#include <QStyleOptionProgressBarV2> #include <QStyleOptionProgressBarV2>
#include <QProgressBar> #include <QProgressBar>
#include <QApplication> #include <QApplication>
#include <QDateTime>
#include <limits>
#include "DLListDelegate.h" #include "DLListDelegate.h"
@ -51,9 +53,10 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
double dlspeed, multi; double dlspeed, multi;
int seconds,minutes, hours, days; int seconds,minutes, hours, days;
qlonglong remaining; qlonglong remaining;
QString temp , status; QString temp ;
qlonglong completed; qlonglong completed;
qlonglong downloadtime; qlonglong downloadtime;
qint64 qi64Value;
// prepare // prepare
painter->save(); painter->save();
@ -216,6 +219,15 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
} }
painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignLeft, temp); painter->drawText(option.rect.translated(pixmap.size().width(), 0), Qt::AlignLeft, temp);
break; break;
case COLUMN_LASTDL:
qi64Value = index.data().value<qint64>();
if (qi64Value < std::numeric_limits<qint64>::max()){
QDateTime qdtLastDL = QDateTime::fromMSecsSinceEpoch(qi64Value);
painter->drawText(option.rect, Qt::AlignCenter, qdtLastDL.toString("yyyy-MM-dd_hh:mm:ss"));
} else {
painter->drawText(option.rect, Qt::AlignCenter, tr("File Never Seen"));
}
break;
default: default:
painter->drawText(option.rect, Qt::AlignCenter, index.data().toString()); painter->drawText(option.rect, Qt::AlignCenter, index.data().toString());
} }
@ -224,14 +236,8 @@ void DLListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
painter->restore(); painter->restore();
} }
QSize DLListDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const QSize DLListDelegate::sizeHint(const QStyleOptionViewItem & /*option*/, const QModelIndex & /*index*/) const
{ {
return QSize(50,17); return QSize(50,17);
QVariant value = index.data(Qt::FontRole);
QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font;
QFontMetrics fontMetrics(fnt);
const QString text = index.data(Qt::DisplayRole).toString();
QRect textRect = QRect(0, 0, 0, fontMetrics.lineSpacing() * (text.count(QLatin1Char('\n')) + 1));
return textRect.size();
} }

View File

@ -60,7 +60,7 @@ class DLListDelegate: public QAbstractItemDelegate {
DLListDelegate(QObject *parent=0); DLListDelegate(QObject *parent=0);
~DLListDelegate(); ~DLListDelegate();
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const; void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
private: private:

View File

@ -38,6 +38,7 @@
#include <gui/common/FilesDefs.h> #include <gui/common/FilesDefs.h>
#include <algorithm> #include <algorithm>
#include <limits>
#include "TransfersDialog.h" #include "TransfersDialog.h"
#include <gui/RetroShareLink.h> #include <gui/RetroShareLink.h>
@ -932,7 +933,8 @@ int TransfersDialog::addItem(int row, const FileInfo &fileInfo, const std::map<s
qlonglong completed = fileInfo.transfered; qlonglong completed = fileInfo.transfered;
qlonglong remaining = fileInfo.size - fileInfo.transfered; qlonglong remaining = fileInfo.size - fileInfo.transfered;
qlonglong downloadtime = (fileInfo.size - fileInfo.transfered) / (fileInfo.tfRate * 1024.0); qlonglong downloadtime = (fileInfo.size - fileInfo.transfered) / (fileInfo.tfRate * 1024.0);
QString strLastDL = tr("File Never Seen"); qint64 qi64LastDL = std::numeric_limits<qint64>::max();
{ {
QFileInfo file; QFileInfo file;
@ -943,7 +945,7 @@ int TransfersDialog::addItem(int row, const FileInfo &fileInfo, const std::map<s
} }
/*Get Last Access on File */ /*Get Last Access on File */
if (file.exists()) { if (file.exists()) {
strLastDL= file.lastModified().toString("yyyy-MM-dd_hh:mm:ss"); qi64LastDL = file.lastModified().toMSecsSinceEpoch();
} }
} }
QString strPath = QString::fromUtf8(fileInfo.path.c_str()); QString strPath = QString::fromUtf8(fileInfo.path.c_str());
@ -1003,7 +1005,7 @@ int TransfersDialog::addItem(int row, const FileInfo &fileInfo, const std::map<s
DLListModel->setData(DLListModel->index(row, COLUMN_PRIORITY), QVariant(priority)); DLListModel->setData(DLListModel->index(row, COLUMN_PRIORITY), QVariant(priority));
DLListModel->setData(DLListModel->index(row, COLUMN_REMAINING), QVariant((qlonglong)remaining)); DLListModel->setData(DLListModel->index(row, COLUMN_REMAINING), QVariant((qlonglong)remaining));
DLListModel->setData(DLListModel->index(row, COLUMN_DOWNLOADTIME), QVariant((qlonglong)downloadtime)); DLListModel->setData(DLListModel->index(row, COLUMN_DOWNLOADTIME), QVariant((qlonglong)downloadtime));
DLListModel->setData(DLListModel->index(row, COLUMN_LASTDL), QVariant(strLastDL)); DLListModel->setData(DLListModel->index(row, COLUMN_LASTDL), QVariant(qi64LastDL));
DLListModel->setData(DLListModel->index(row, COLUMN_PATH), QVariant(strPathAfterDL)); DLListModel->setData(DLListModel->index(row, COLUMN_PATH), QVariant(strPathAfterDL));
DLListModel->item(row,COLUMN_PATH)->setToolTip(strPath); DLListModel->item(row,COLUMN_PATH)->setToolTip(strPath);
DLListModel->item(row,COLUMN_STATUS)->setToolTip(tooltip); DLListModel->item(row,COLUMN_STATUS)->setToolTip(tooltip);