From 311b060c705991df5c1a0990948f9bb33c6ee642 Mon Sep 17 00:00:00 2001 From: thalieht Date: Mon, 26 Sep 2016 13:26:25 +0300 Subject: [PATCH 1/2] Increased number of digits after the decimal point for Gibibytes and above --- src/base/utils/misc.cpp | 10 +++++++++- src/base/utils/misc.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index 18f06d2d7..7739cd39c 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -358,12 +358,20 @@ QString Utils::Misc::friendlyUnit(qint64 bytesValue, bool isSpeed) if (unit == SizeUnit::Byte) ret = QString::number(bytesValue) + " " + unitString(unit); else - ret = Utils::String::fromDouble(friendlyVal, 1) + " " + unitString(unit); + ret = Utils::String::fromDouble(friendlyVal, friendlyUnitPrecision(unit)) + " " + unitString(unit); if (isSpeed) ret += QCoreApplication::translate("misc", "/s", "per second"); return ret; } +int Utils::Misc::friendlyUnitPrecision(SizeUnit unit) +{ + // friendlyUnit's number of digits after the decimal point + if (unit <= SizeUnit::MebiByte) return 1; + else if (unit == SizeUnit::GibiByte) return 2; + else return 3; +} + qlonglong Utils::Misc::sizeInBytes(qreal size, Utils::Misc::SizeUnit unit) { for (int i = 0; i < static_cast(unit); ++i) diff --git a/src/base/utils/misc.h b/src/base/utils/misc.h index d0a1c39bb..9a456fd26 100644 --- a/src/base/utils/misc.h +++ b/src/base/utils/misc.h @@ -88,6 +88,7 @@ namespace Utils // value must be given in bytes bool friendlyUnit(qint64 sizeInBytes, qreal& val, SizeUnit& unit); QString friendlyUnit(qint64 bytesValue, bool isSpeed = false); + int friendlyUnitPrecision(SizeUnit unit); qint64 sizeInBytes(qreal size, SizeUnit unit); bool isPreviewable(const QString& extension); From f8213f5d56d2c9fbeb3fcb4f3272b85b1f75a610 Mon Sep 17 00:00:00 2001 From: thalieht Date: Wed, 19 Oct 2016 16:29:09 +0300 Subject: [PATCH 2/2] friendlyUnit: Properly replace spaces with non-breaking spaces --- src/base/unicodestrings.h | 1 + src/base/utils/misc.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/base/unicodestrings.h b/src/base/unicodestrings.h index 24268544b..4093cce8d 100644 --- a/src/base/unicodestrings.h +++ b/src/base/unicodestrings.h @@ -35,6 +35,7 @@ // we put all problematic UTF-8 chars/strings in this file. // See issue #3059 for more details (https://github.com/qbittorrent/qBittorrent/issues/3059). const char C_INFINITY[] = "∞"; +const char C_NON_BREAKING_SPACE[] = " "; const char C_UP[] = "▲"; const char C_DOWN[] = "▼"; const char C_COPYRIGHT[] = "©"; diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index 7739cd39c..bbd6918f1 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -356,9 +356,9 @@ QString Utils::Misc::friendlyUnit(qint64 bytesValue, bool isSpeed) return QCoreApplication::translate("misc", "Unknown", "Unknown (size)"); QString ret; if (unit == SizeUnit::Byte) - ret = QString::number(bytesValue) + " " + unitString(unit); + ret = QString::number(bytesValue) + QString::fromUtf8(C_NON_BREAKING_SPACE) + unitString(unit); else - ret = Utils::String::fromDouble(friendlyVal, friendlyUnitPrecision(unit)) + " " + unitString(unit); + ret = Utils::String::fromDouble(friendlyVal, friendlyUnitPrecision(unit)) + QString::fromUtf8(C_NON_BREAKING_SPACE) + unitString(unit); if (isSpeed) ret += QCoreApplication::translate("misc", "/s", "per second"); return ret;