Browse Source

Fixed rounding bugs with floating numbers v2.

adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
70215bd3ff
  1. 6
      src/mainwindow.cpp
  2. 32
      src/properties/proplistdelegate.h

6
src/mainwindow.cpp

@ -1128,10 +1128,12 @@ void MainWindow::updateGUI() {
html += "qBittorrent"; html += "qBittorrent";
html += "</div>"; html += "</div>";
html += "<div style='vertical-align: baseline; height: 18px;'>"; html += "<div style='vertical-align: baseline; height: 18px;'>";
html += "<img src=':/Icons/skin/download.png'/>&nbsp;"+tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString::number(QBtSession::instance()->getPayloadDownloadRate()/1024., 'f', 1)); /* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
html += "<img src=':/Icons/skin/download.png'/>&nbsp;"+tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString::number((int)((QBtSession::instance()->getPayloadDownloadRate()/1024.)*10)/10.0, 'f', 1));
html += "</div>"; html += "</div>";
html += "<div style='vertical-align: baseline; height: 18px;'>"; html += "<div style='vertical-align: baseline; height: 18px;'>";
html += "<img src=':/Icons/skin/seeding.png'/>&nbsp;"+tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString::number(QBtSession::instance()->getPayloadUploadRate()/1024., 'f', 1)); html += "<img src=':/Icons/skin/seeding.png'/>&nbsp;"+tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString::number((int)((QBtSession::instance()->getPayloadUploadRate()/1024.)*10)/10.0, 'f', 1));
html += "</div>"; html += "</div>";
#else #else
// OSes such as Windows do not support html here // OSes such as Windows do not support html here

32
src/properties/proplistdelegate.h

@ -75,25 +75,23 @@ public:
break; break;
case PROGRESS:{ case PROGRESS:{
if (index.data().toDouble() >= 0) { if (index.data().toDouble() >= 0) {
QStyleOptionProgressBarV2 newopt; QStyleOptionProgressBarV2 newopt;
qreal progress = index.data().toDouble()*100.; qreal progress = index.data().toDouble()*100.;
newopt.rect = opt.rect; newopt.rect = opt.rect;
// We don't want to display 100% unless /* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
// the torrent is really complete ** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 */
if (progress > 99.94 && progress < 100.) newopt.text = QString::number((int)(progress*10)/10.0, 'f', 1)+"%";
progress = 99.9; newopt.progress = (int)progress;
newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%"); newopt.maximum = 100;
newopt.progress = (int)progress; newopt.minimum = 0;
newopt.maximum = 100; newopt.state |= QStyle::State_Enabled;
newopt.minimum = 0; newopt.textVisible = true;
newopt.state |= QStyle::State_Enabled;
newopt.textVisible = true;
#ifndef Q_WS_WIN #ifndef Q_WS_WIN
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
#else #else
// XXX: To avoid having the progress text on the right of the bar // XXX: To avoid having the progress text on the right of the bar
QPlastiqueStyle st; QPlastiqueStyle st;
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
#endif #endif
} else { } else {
// Do not display anything if the file is disabled (progress == -1) // Do not display anything if the file is disabled (progress == -1)

Loading…
Cancel
Save