Merge utils.h and utils.cpp

This commit is contained in:
miruka 2020-06-12 14:03:15 -04:00
parent 451abfdf25
commit 715a6ca530
3 changed files with 27 additions and 48 deletions

View File

@ -14,7 +14,7 @@ QRC_FILE = $$BUILD_DIR/resources.qrc
RESOURCES += $$QRC_FILE RESOURCES += $$QRC_FILE
HEADERS += src/utils.h src/clipboard.h \ HEADERS += src/utils.h src/clipboard.h \
submodules/hsluv-c/src/hsluv.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 submodules/hsluv-c/src/hsluv.c
TARGET = mirage TARGET = mirage

View File

@ -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))
);
}

View File

@ -9,6 +9,9 @@
#include <QColor> #include <QColor>
#include <QLocale> #include <QLocale>
#include <QObject> #include <QObject>
#include <QUuid>
#include "../submodules/hsluv-c/src/hsluv.h"
class Utils : public QObject { class Utils : public QObject {
@ -16,15 +19,33 @@ class Utils : public QObject {
Q_OBJECT Q_OBJECT
public: public:
Utils(); Utils() {};
public slots: public slots:
QString formattedBytes(qint64 bytes, int precision = 2); QString formattedBytes(qint64 bytes, int precision = 2) const {
QString uuid(); return this->appLocale.formattedDataSize(
QColor hsluv(qreal hue, qreal saturation, qreal luv, qreal alpha = 1.0); 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: private:
QLocale m_locale; QLocale appLocale;
}; };