1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Progress bar in file transfers (fix #309)

This commit is contained in:
apprb 2014-09-26 00:30:23 +07:00
parent 52d18f9f18
commit 46ffc883df
2 changed files with 32 additions and 5 deletions

View File

@ -21,6 +21,7 @@
#include <QMessageBox>
#include <QBuffer>
#include <QDebug>
#include <QPainter>
uint FileTransferInstance::Idconter = 0;
@ -76,6 +77,7 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t
long rawspeed = diff / timediff;
speed = getHumanReadableSize(rawspeed)+"/s";
size = getHumanReadableSize(Filesize);
totalBytes = Filesize;
if (!rawspeed)
return;
int etaSecs = (Filesize - BytesSent) / rawspeed;
@ -352,8 +354,16 @@ QString FileTransferInstance::draw2ButtonsForm(const QString &type, const QImage
QString imgBstr = "<img src=\"data:ftrans." + widgetId + ".btnB/png;base64," + QImage2base64(imgB) + "\">";
QString content;
content += "<p>" + filename + "</p>";
content += "<p>" + getHumanReadableSize(lastBytesSent) + " / " + size + "&nbsp;(" + speed + " ETA: " + eta + ")</p>\n";
QString progrBar = "<img src=\"data:progressbar." + widgetId + "/png;base64," + QImage2base64(drawProgressBarImg(double(lastBytesSent)/totalBytes, 250, 9)) + "\">";
content = "<p>" + filename + "</p>";
content += "<table cellspacing=\"0\"><tr>";
content += "<td>" + size + "</td>";
content += "<td align=center>" + speed + "</td>";
content += "<td align=right>ETA: " + eta + "</td>";
content += "</tr><tr><td colspan=3>";
content += progrBar;
content += "</td></tr></table>";
return wrapIntoForm(content, type, imgAstr, imgBstr);
}
@ -362,10 +372,10 @@ QString FileTransferInstance::wrapIntoForm(const QString& content, const QString
{
QString res;
res = "<table widht=100% cellspacing=\"0\">\n";
res = "<table cellspacing=\"0\">\n";
res += "<tr valign=middle>\n";
res += insertMiniature(type);
res += "<td width=100%>\n";
res += "<td width=280>\n";
res += "<div class=" + type + ">";
res += content;
res += "</div>\n";
@ -378,3 +388,19 @@ QString FileTransferInstance::wrapIntoForm(const QString& content, const QString
return res;
}
QImage FileTransferInstance::drawProgressBarImg(const double &part, int w, int h)
{
QImage progressBar(w, h, QImage::Format_Mono);
QPainter qPainter(&progressBar);
qPainter.setBrush(Qt::NoBrush);
qPainter.setPen(Qt::black);
qPainter.drawRect(0, 0, w - 1, h - 1);
qPainter.setBrush(Qt::SolidPattern);
qPainter.setPen(Qt::black);
qPainter.drawRect(1, 0, (w - 2) * (part), h - 1);
return progressBar;
}

View File

@ -62,6 +62,7 @@ private:
QString draw2ButtonsForm(const QString &type, const QImage &imgA, const QImage &imgB);
QString insertMiniature(const QString &type);
QString wrapIntoForm(const QString &content, const QString &type, const QString &imgAstr, const QString &imgBstr);
QImage drawProgressBarImg(const double &part, int w, int h);
private:
static uint Idconter;
@ -72,7 +73,7 @@ private:
QImage pic;
QString filename, size, speed, eta;
QDateTime lastUpdate;
long long lastBytesSent;
long long lastBytesSent, totalBytes;
int fileNum;
int friendId;
QString savePath;