Merge branch 'style' into 0.3

This commit is contained in:
miruka 2019-12-27 16:35:56 -04:00
commit 5f3ecef408
19 changed files with 59 additions and 22 deletions

3
.gitmodules vendored
View File

@ -4,3 +4,6 @@
[submodule "submodules/RadialBarDemo"] [submodule "submodules/RadialBarDemo"]
path = submodules/RadialBarDemo path = submodules/RadialBarDemo
url = https://github.com/mirukan/RadialBarDemo/ url = https://github.com/mirukan/RadialBarDemo/
[submodule "submodules/hsluv-c"]
path = submodules/hsluv-c
url = https://github.com/hsluv/hsluv-c

View File

@ -13,9 +13,11 @@ 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/RadialBarDemo/radialbar.h submodules/RadialBarDemo/radialbar.h \
submodules/hsluv-c/src/hsluv.h
SOURCES += src/main.cpp src/utils.cpp src/clipboard.cpp \ SOURCES += src/main.cpp src/utils.cpp src/clipboard.cpp \
submodules/RadialBarDemo/radialbar.cpp submodules/RadialBarDemo/radialbar.cpp \
submodules/hsluv-c/src/hsluv.c
TARGET = harmonyqml TARGET = harmonyqml

View File

@ -1,4 +1,3 @@
hsluv == 0.0.2
Pillow >= 5.4.1, < 6 Pillow >= 5.4.1, < 6
pymediainfo >= 4.1, < 5 pymediainfo >= 4.1, < 5
cairosvg >= 2.4.2, < 3 cairosvg >= 2.4.2, < 3

View File

@ -7,7 +7,6 @@ import traceback
from pathlib import Path from pathlib import Path
from typing import Any, DefaultDict, Dict, List, Optional, Tuple from typing import Any, DefaultDict, Dict, List, Optional, Tuple
import hsluv
from appdirs import AppDirs from appdirs import AppDirs
import nio import nio
@ -245,13 +244,6 @@ class Backend:
# General functions # General functions
@staticmethod
def hsluv(hue: int, saturation: int, lightness: int) -> List[float]:
"""Convert HSLuv (0-360, 0-100, 0-100) to RGB (0-1, 0-1, 0-1) color."""
return hsluv.hsluv_to_rgb([hue, saturation, lightness])
async def load_settings(self) -> tuple: async def load_settings(self) -> tuple:
"""Return parsed user config files.""" """Return parsed user config files."""

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-or-later // SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12 import QtQuick 2.12
import Clipboard 0.1
FocusScope { FocusScope {
signal deselectAll() signal deselectAll()

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.12 import QtQuick.Controls 2.12
import Clipboard 0.1
import "Base" import "Base"
Item { Item {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import Clipboard 0.1
import "../Base" import "../Base"
HTileDelegate { HTileDelegate {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import Clipboard 0.1
import "../Base" import "../Base"
HTileDelegate { HTileDelegate {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import Clipboard 0.1
import "../../Base" import "../../Base"
import "../../Dialogs" import "../../Dialogs"

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import CppUtils 0.1
import "../../../Base" import "../../../Base"
HColumnLayout { HColumnLayout {

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-or-later // SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12 import QtQuick 2.12
import Clipboard 0.1
import "../../../Base" import "../../../Base"
HTileDelegate { HTileDelegate {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import Clipboard 0.1
import "../../../Base" import "../../../Base"
HColumnLayout { HColumnLayout {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import CppUtils 0.1
import "../../../Base" import "../../../Base"
HTile { HTile {

View File

@ -2,6 +2,7 @@
import QtQuick 2.12 import QtQuick 2.12
import io.thp.pyotherside 1.5 import io.thp.pyotherside 1.5
import CppUtils 0.1
Python { Python {
id: py id: py

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-or-later // SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12 import QtQuick 2.12
import CppUtils 0.1
QtObject { QtObject {
function makeObject(urlComponent, parent=null, properties={}, function makeObject(urlComponent, parent=null, properties={},
@ -91,9 +92,7 @@ QtObject {
function hsluv(hue, saturation, lightness, alpha=1.0) { function hsluv(hue, saturation, lightness, alpha=1.0) {
hue = numberWrapAt(hue, 360) return CppUtils.hsluv(hue, saturation, lightness, alpha)
let rgb = py.callSync("hsluv", [hue, saturation, lightness])
return Qt.rgba(rgb[0], rgb[1], rgb[2], alpha)
} }

View File

@ -37,13 +37,33 @@ int main(int argc, char *argv[]) {
objectContext->setContextProperty("debugMode", false); objectContext->setContextProperty("debugMode", false);
#endif #endif
// Add our custom non-visual `QObject `s as properties. // Register our custom non-visual QObject singletons,
// Their attributes and methods will be accessing like normal QML objects. // that will be importable anywhere in QML. Example:
objectContext->setContextProperty("CppUtils", new Utils()); // import Clipboard 0.1
objectContext->setContextProperty("Clipboard", new Clipboard()); // ...
// Component.onCompleted: print(Clipboard.text)
qmlRegisterSingletonType<Clipboard>(
"Clipboard", 0, 1, "Clipboard",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new Clipboard();
}
);
// Register our custom visual items that will be importable from QML, qmlRegisterSingletonType<Utils>(
// e.g. `import RadialBar 1.0` "CppUtils", 0, 1, "CppUtils",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new Utils();
}
);
// Register our custom visual items that will be importable from QML, e.g.
// import RadialBar 1.0
// ...
// RadialBar { ... }
qmlRegisterType<RadialBar>("RadialBar", 1, 0, "RadialBar"); qmlRegisterType<RadialBar>("RadialBar", 1, 0, "RadialBar");
// Create the QML root component by loading its file from the Qt Resource // Create the QML root component by loading its file from the Qt Resource

View File

@ -2,10 +2,12 @@
// Function implementations of the Utils class, see the utils.h file. // Function implementations of the Utils class, see the utils.h file.
#include <QColor>
#include <QLocale> #include <QLocale>
#include <QUuid> #include <QUuid>
#include "utils.h" #include "utils.h"
#include "../submodules/hsluv-c/src/hsluv.h"
Utils::Utils() { Utils::Utils() {
@ -23,3 +25,10 @@ QString Utils::formattedBytes(qint64 bytes, int precision) {
QString Utils::uuid() { QString Utils::uuid() {
return QUuid::createUuid().toString(QUuid::WithoutBraces); 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(red, green, blue, alpha);
}

View File

@ -1,13 +1,14 @@
// SPDX-License-Identifier: LGPL-3.0-or-later // SPDX-License-Identifier: LGPL-3.0-or-later
// The Utils class exposes various useful functions for QML that aren't // The Utils class exposes various useful functions for QML that aren't
// normally provided by Qt. // provided by the `Qt` object.
#ifndef UTILS_H #ifndef UTILS_H
#define UTILS_H #define UTILS_H
#include <QObject> #include <QColor>
#include <QLocale> #include <QLocale>
#include <QObject>
class Utils : public QObject { class Utils : public QObject {
@ -20,6 +21,7 @@ public:
public slots: public slots:
QString formattedBytes(qint64 bytes, int precision = 2); QString formattedBytes(qint64 bytes, int precision = 2);
QString uuid(); QString uuid();
QColor hsluv(qreal hue, qreal saturation, qreal luv, qreal alpha = 1.0);
private: private:
QLocale m_locale; QLocale m_locale;

1
submodules/hsluv-c Submodule

@ -0,0 +1 @@
Subproject commit 9e9be32d6010cad484a7b12b1a3d19c6cf4c1353