2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-18 09:50:21 +11:00
|
|
|
// Function implementations of the Utils class, see the utils.h file.
|
|
|
|
|
2019-12-27 23:19:56 +11:00
|
|
|
#include <QColor>
|
2019-09-15 05:42:24 +10:00
|
|
|
#include <QLocale>
|
2019-12-04 21:22:04 +11:00
|
|
|
#include <QUuid>
|
2019-09-15 05:42:24 +10:00
|
|
|
|
|
|
|
#include "utils.h"
|
2019-12-27 23:19:56 +11:00
|
|
|
#include "../submodules/hsluv-c/src/hsluv.h"
|
2019-09-15 05:42:24 +10:00
|
|
|
|
2020-02-15 03:32:45 +11:00
|
|
|
using namespace std;
|
|
|
|
|
2019-09-15 05:42:24 +10:00
|
|
|
|
|
|
|
Utils::Utils() {
|
|
|
|
// Initialization
|
2019-12-18 09:50:21 +11:00
|
|
|
}
|
2019-09-15 05:42:24 +10:00
|
|
|
|
|
|
|
|
|
|
|
QString Utils::formattedBytes(qint64 bytes, int precision) {
|
|
|
|
return m_locale.formattedDataSize(
|
|
|
|
bytes, precision, QLocale::DataSizeTraditionalFormat
|
|
|
|
);
|
2019-12-18 09:50:21 +11:00
|
|
|
}
|
2019-12-04 21:22:04 +11:00
|
|
|
|
|
|
|
|
|
|
|
QString Utils::uuid() {
|
|
|
|
return QUuid::createUuid().toString(QUuid::WithoutBraces);
|
|
|
|
}
|
2019-12-27 23:19:56 +11:00
|
|
|
|
|
|
|
|
|
|
|
QColor Utils::hsluv(qreal hue, qreal saturation, qreal luv, qreal alpha) {
|
|
|
|
double red, green, blue;
|
|
|
|
hsluv2rgb(hue, saturation, luv, &red, &green, &blue);
|
2020-02-15 03:32:45 +11:00
|
|
|
|
|
|
|
return QColor::fromRgbF(
|
|
|
|
qMax(0.0, qMin(1.0, red)),
|
|
|
|
qMax(0.0, qMin(1.0, green)),
|
|
|
|
qMax(0.0, qMin(1.0, blue)),
|
|
|
|
qMax(0.0, qMin(1.0, alpha))
|
|
|
|
);
|
2019-12-27 23:19:56 +11:00
|
|
|
}
|