mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #317 from apprb/filetrans
Progress bar in file transfers (fix #309)
This commit is contained in:
commit
9830b5122c
|
@ -21,6 +21,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
uint FileTransferInstance::Idconter = 0;
|
uint FileTransferInstance::Idconter = 0;
|
||||||
|
|
||||||
|
@ -76,6 +77,7 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t
|
||||||
long rawspeed = diff / timediff;
|
long rawspeed = diff / timediff;
|
||||||
speed = getHumanReadableSize(rawspeed)+"/s";
|
speed = getHumanReadableSize(rawspeed)+"/s";
|
||||||
size = getHumanReadableSize(Filesize);
|
size = getHumanReadableSize(Filesize);
|
||||||
|
totalBytes = Filesize;
|
||||||
if (!rawspeed)
|
if (!rawspeed)
|
||||||
return;
|
return;
|
||||||
int etaSecs = (Filesize - BytesSent) / rawspeed;
|
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 imgBstr = "<img src=\"data:ftrans." + widgetId + ".btnB/png;base64," + QImage2base64(imgB) + "\">";
|
||||||
|
|
||||||
QString content;
|
QString content;
|
||||||
content += "<p>" + filename + "</p>";
|
QString progrBar = "<img src=\"data:progressbar." + widgetId + "/png;base64," + QImage2base64(drawProgressBarImg(double(lastBytesSent)/totalBytes, 250, 9)) + "\">";
|
||||||
content += "<p>" + getHumanReadableSize(lastBytesSent) + " / " + size + " (" + speed + " ETA: " + eta + ")</p>\n";
|
|
||||||
|
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);
|
return wrapIntoForm(content, type, imgAstr, imgBstr);
|
||||||
}
|
}
|
||||||
|
@ -362,10 +372,10 @@ QString FileTransferInstance::wrapIntoForm(const QString& content, const QString
|
||||||
{
|
{
|
||||||
QString res;
|
QString res;
|
||||||
|
|
||||||
res = "<table widht=100% cellspacing=\"0\">\n";
|
res = "<table cellspacing=\"0\">\n";
|
||||||
res += "<tr valign=middle>\n";
|
res += "<tr valign=middle>\n";
|
||||||
res += insertMiniature(type);
|
res += insertMiniature(type);
|
||||||
res += "<td width=100%>\n";
|
res += "<td width=280>\n";
|
||||||
res += "<div class=" + type + ">";
|
res += "<div class=" + type + ">";
|
||||||
res += content;
|
res += content;
|
||||||
res += "</div>\n";
|
res += "</div>\n";
|
||||||
|
@ -378,3 +388,19 @@ QString FileTransferInstance::wrapIntoForm(const QString& content, const QString
|
||||||
|
|
||||||
return res;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ private:
|
||||||
QString draw2ButtonsForm(const QString &type, const QImage &imgA, const QImage &imgB);
|
QString draw2ButtonsForm(const QString &type, const QImage &imgA, const QImage &imgB);
|
||||||
QString insertMiniature(const QString &type);
|
QString insertMiniature(const QString &type);
|
||||||
QString wrapIntoForm(const QString &content, const QString &type, const QString &imgAstr, const QString &imgBstr);
|
QString wrapIntoForm(const QString &content, const QString &type, const QString &imgAstr, const QString &imgBstr);
|
||||||
|
QImage drawProgressBarImg(const double &part, int w, int h);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static uint Idconter;
|
static uint Idconter;
|
||||||
|
@ -72,7 +73,7 @@ private:
|
||||||
QImage pic;
|
QImage pic;
|
||||||
QString filename, size, speed, eta;
|
QString filename, size, speed, eta;
|
||||||
QDateTime lastUpdate;
|
QDateTime lastUpdate;
|
||||||
long long lastBytesSent;
|
long long lastBytesSent, totalBytes;
|
||||||
int fileNum;
|
int fileNum;
|
||||||
int friendId;
|
int friendId;
|
||||||
QString savePath;
|
QString savePath;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user