Files
OmaPhoto/src/UI/ByteCounts.cpp
T
雷电芽衣andClaude c864304695
Release / deb (push) Canceled after 0s
Release / rpm (push) Canceled after 0s
Release / arch (push) Canceled after 0s
Release / publish (push) Canceled after 0s
OmaPhoto 1.0.0: the Linux port of Compositor
A layered image editor for Linux and Omarchy, ported from Compositor
(github.com/robbietilton/Compositor), whose Swift source is its
specification. It reads and writes Compositor's .comp projects.

Packages for Ubuntu, Fedora and Arch come from the release workflow;
scripts/install/ holds one install script per distribution family,
and flake.nix serves NixOS.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-26 00:44:52 -04:00

38 lines
1.0 KiB
C++

#include "UI/ByteCounts.h"
#include <QLocale>
#include <array>
namespace {
// Adaptive: places by unit, trailing zeros dropped, digits grouped.
QString counted(qint64 bytes, int base)
{
const QLocale english(QLocale::English, QLocale::UnitedStates);
// Nothing counted here holds one byte or a terabyte.
if (bytes < base)
return english.toString(bytes) + QStringLiteral(" bytes");
const std::array<QString, 3> units = {QStringLiteral("KB"), QStringLiteral("MB"), QStringLiteral("GB")};
double value = double(bytes) / base;
size_t unit = 0;
while (value >= base) {
value /= base;
++unit;
}
QString number = english.toString(value, 'f', int(unit));
while (unit > 0 && number.endsWith(QLatin1Char('0')))
number.chop(1);
if (number.endsWith(QLatin1Char('.')))
number.chop(1);
return number + QLatin1Char(' ') + units.at(unit);
}
}
QString ByteCounts::memory(qint64 bytes)
{
return counted(bytes, 1024);
}
QString ByteCounts::file(qint64 bytes)
{
return counted(bytes, 1000);
}