Merge utils.h and utils.cpp
This commit is contained in:
parent
451abfdf25
commit
715a6ca530
|
@ -14,7 +14,7 @@ QRC_FILE = $$BUILD_DIR/resources.qrc
|
|||
RESOURCES += $$QRC_FILE
|
||||
HEADERS += src/utils.h src/clipboard.h \
|
||||
submodules/hsluv-c/src/hsluv.h
|
||||
SOURCES += src/main.cpp src/utils.cpp src/clipboard.cpp \
|
||||
SOURCES += src/main.cpp src/clipboard.cpp \
|
||||
submodules/hsluv-c/src/hsluv.c
|
||||
TARGET = mirage
|
||||
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
// Function implementations of the Utils class, see the utils.h file.
|
||||
|
||||
#include <QColor>
|
||||
#include <QLocale>
|
||||
#include <QUuid>
|
||||
|
||||
#include "utils.h"
|
||||
#include "../submodules/hsluv-c/src/hsluv.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
Utils::Utils() {
|
||||
// Initialization
|
||||
}
|
||||
|
||||
|
||||
QString Utils::formattedBytes(qint64 bytes, int precision) {
|
||||
return m_locale.formattedDataSize(
|
||||
bytes, precision, QLocale::DataSizeTraditionalFormat
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
QString Utils::uuid() {
|
||||
return QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||
}
|
||||
|
||||
|
||||
QColor Utils::hsluv(qreal hue, qreal saturation, qreal luv, qreal alpha) {
|
||||
double red, green, blue;
|
||||
hsluv2rgb(hue, saturation, 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))
|
||||
);
|
||||
}
|
31
src/utils.h
31
src/utils.h
|
@ -9,6 +9,9 @@
|
|||
#include <QColor>
|
||||
#include <QLocale>
|
||||
#include <QObject>
|
||||
#include <QUuid>
|
||||
|
||||
#include "../submodules/hsluv-c/src/hsluv.h"
|
||||
|
||||
|
||||
class Utils : public QObject {
|
||||
|
@ -16,15 +19,33 @@ class Utils : public QObject {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Utils();
|
||||
Utils() {};
|
||||
|
||||
public slots:
|
||||
QString formattedBytes(qint64 bytes, int precision = 2);
|
||||
QString uuid();
|
||||
QColor hsluv(qreal hue, qreal saturation, qreal luv, qreal alpha = 1.0);
|
||||
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))
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
QLocale m_locale;
|
||||
QLocale appLocale;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user