2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-18 09:50:21 +11:00
|
|
|
// The Utils class exposes various useful functions for QML that aren't
|
2019-12-27 23:19:56 +11:00
|
|
|
// provided by the `Qt` object.
|
2019-12-18 09:50:21 +11:00
|
|
|
|
2019-09-15 05:42:24 +10:00
|
|
|
#ifndef UTILS_H
|
|
|
|
#define UTILS_H
|
|
|
|
|
2019-12-27 23:19:56 +11:00
|
|
|
#include <QColor>
|
2019-09-15 05:42:24 +10:00
|
|
|
#include <QLocale>
|
2019-12-27 23:19:56 +11:00
|
|
|
#include <QObject>
|
2020-06-13 04:03:15 +10:00
|
|
|
#include <QUuid>
|
|
|
|
|
|
|
|
#include "../submodules/hsluv-c/src/hsluv.h"
|
2019-09-15 05:42:24 +10:00
|
|
|
|
|
|
|
|
|
|
|
class Utils : public QObject {
|
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-06-13 04:03:15 +10:00
|
|
|
Utils() {};
|
2019-09-15 05:42:24 +10:00
|
|
|
|
|
|
|
public slots:
|
2020-06-13 04:03:15 +10:00
|
|
|
QString formattedBytes(qint64 bytes, int precision = 2) const {
|
|
|
|
return this->appLocale.formattedDataSize(
|
|
|
|
bytes, precision, QLocale::DataSizeTraditionalFormat
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString uuid() const {
|
|
|
|
return QUuid::createUuid().toString(QUuid::WithoutBraces);
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor hsluv(qreal hue, qreal sat, qreal luv, qreal alpha = 1.0) const {
|
|
|
|
double red, green, blue;
|
|
|
|
hsluv2rgb(hue, sat, luv, &red, &green, &blue);
|
|
|
|
|
|
|
|
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-09-15 05:42:24 +10:00
|
|
|
|
|
|
|
private:
|
2020-06-13 04:03:15 +10:00
|
|
|
QLocale appLocale;
|
2019-09-15 05:42:24 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|