mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-12 08:16:16 -07:00
Merge pull request #5774 from thalieht/unit_precision
Increase number of digits after the decimal point. Closes #5053
This commit is contained in:
commit
5b35981c85
3 changed files with 12 additions and 2 deletions
|
@ -35,6 +35,7 @@
|
||||||
// we put all problematic UTF-8 chars/strings in this file.
|
// we put all problematic UTF-8 chars/strings in this file.
|
||||||
// See issue #3059 for more details (https://github.com/qbittorrent/qBittorrent/issues/3059).
|
// See issue #3059 for more details (https://github.com/qbittorrent/qBittorrent/issues/3059).
|
||||||
const char C_INFINITY[] = "∞";
|
const char C_INFINITY[] = "∞";
|
||||||
|
const char C_NON_BREAKING_SPACE[] = " ";
|
||||||
const char C_UP[] = "▲";
|
const char C_UP[] = "▲";
|
||||||
const char C_DOWN[] = "▼";
|
const char C_DOWN[] = "▼";
|
||||||
const char C_COPYRIGHT[] = "©";
|
const char C_COPYRIGHT[] = "©";
|
||||||
|
|
|
@ -358,14 +358,22 @@ QString Utils::Misc::friendlyUnit(qint64 bytesValue, bool isSpeed)
|
||||||
return QCoreApplication::translate("misc", "Unknown", "Unknown (size)");
|
return QCoreApplication::translate("misc", "Unknown", "Unknown (size)");
|
||||||
QString ret;
|
QString ret;
|
||||||
if (unit == SizeUnit::Byte)
|
if (unit == SizeUnit::Byte)
|
||||||
ret = QString::number(bytesValue) + " " + unitString(unit);
|
ret = QString::number(bytesValue) + QString::fromUtf8(C_NON_BREAKING_SPACE) + unitString(unit);
|
||||||
else
|
else
|
||||||
ret = Utils::String::fromDouble(friendlyVal, 1) + " " + unitString(unit);
|
ret = Utils::String::fromDouble(friendlyVal, friendlyUnitPrecision(unit)) + QString::fromUtf8(C_NON_BREAKING_SPACE) + unitString(unit);
|
||||||
if (isSpeed)
|
if (isSpeed)
|
||||||
ret += QCoreApplication::translate("misc", "/s", "per second");
|
ret += QCoreApplication::translate("misc", "/s", "per second");
|
||||||
return ret;
|
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)
|
qlonglong Utils::Misc::sizeInBytes(qreal size, Utils::Misc::SizeUnit unit)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < static_cast<int>(unit); ++i)
|
for (int i = 0; i < static_cast<int>(unit); ++i)
|
||||||
|
|
|
@ -83,6 +83,7 @@ namespace Utils
|
||||||
// value must be given in bytes
|
// value must be given in bytes
|
||||||
bool friendlyUnit(qint64 sizeInBytes, qreal& val, SizeUnit& unit);
|
bool friendlyUnit(qint64 sizeInBytes, qreal& val, SizeUnit& unit);
|
||||||
QString friendlyUnit(qint64 bytesValue, bool isSpeed = false);
|
QString friendlyUnit(qint64 bytesValue, bool isSpeed = false);
|
||||||
|
int friendlyUnitPrecision(SizeUnit unit);
|
||||||
qint64 sizeInBytes(qreal size, SizeUnit unit);
|
qint64 sizeInBytes(qreal size, SizeUnit unit);
|
||||||
|
|
||||||
bool isPreviewable(const QString& extension);
|
bool isPreviewable(const QString& extension);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue