From 70215bd3ff8b13d2ec333e2e96ead5d9c73b8d33 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sat, 14 Sep 2013 15:15:30 +0300 Subject: [PATCH] Fixed rounding bugs with floating numbers v2. --- src/mainwindow.cpp | 6 ++++-- src/properties/proplistdelegate.h | 32 +++++++++++++++---------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 869a32b1f..241ab69b0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1128,10 +1128,12 @@ void MainWindow::updateGUI() { html += "qBittorrent"; html += ""; html += "
"; - html += " "+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 += " "+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 += "
"; html += "
"; - html += " "+tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString::number(QBtSession::instance()->getPayloadUploadRate()/1024., 'f', 1)); + html += " "+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 += "
"; #else // OSes such as Windows do not support html here diff --git a/src/properties/proplistdelegate.h b/src/properties/proplistdelegate.h index c24272a35..30855f16b 100644 --- a/src/properties/proplistdelegate.h +++ b/src/properties/proplistdelegate.h @@ -75,25 +75,23 @@ public: break; case PROGRESS:{ if (index.data().toDouble() >= 0) { - QStyleOptionProgressBarV2 newopt; - qreal progress = index.data().toDouble()*100.; - newopt.rect = opt.rect; - // We don't want to display 100% unless - // the torrent is really complete - if (progress > 99.94 && progress < 100.) - progress = 99.9; - newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%"); - newopt.progress = (int)progress; - newopt.maximum = 100; - newopt.minimum = 0; - newopt.state |= QStyle::State_Enabled; - newopt.textVisible = true; + QStyleOptionProgressBarV2 newopt; + qreal progress = index.data().toDouble()*100.; + newopt.rect = opt.rect; + /* 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 */ + newopt.text = QString::number((int)(progress*10)/10.0, 'f', 1)+"%"; + newopt.progress = (int)progress; + newopt.maximum = 100; + newopt.minimum = 0; + newopt.state |= QStyle::State_Enabled; + newopt.textVisible = true; #ifndef Q_WS_WIN - QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); + QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); #else - // XXX: To avoid having the progress text on the right of the bar - QPlastiqueStyle st; - st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); + // XXX: To avoid having the progress text on the right of the bar + QPlastiqueStyle st; + st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); #endif } else { // Do not display anything if the file is disabled (progress == -1)