diff --git a/mirage.pro b/mirage.pro index 015af3b0..37c26fb1 100644 --- a/mirage.pro +++ b/mirage.pro @@ -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 diff --git a/src/utils.cpp b/src/utils.cpp deleted file mode 100644 index db74827b..00000000 --- a/src/utils.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later - -// Function implementations of the Utils class, see the utils.h file. - -#include -#include -#include - -#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)) - ); -} diff --git a/src/utils.h b/src/utils.h index 95750957..cb3d0add 100644 --- a/src/utils.h +++ b/src/utils.h @@ -9,6 +9,9 @@ #include #include #include +#include + +#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; };