aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Collignon <loic.collignon@iot.bzh>2018-07-05 14:30:25 +0200
committerLoïc Collignon <loic.collignon@iot.bzh>2018-07-10 19:21:41 +0200
commitd009b2e3665ab49ce8885a7d1f59d67bdaf4cd7e (patch)
tree38337c044e2c50989ffc98cc7c5d2b9598f36eca
parent9b2c0778e6b83591cbad1d9c76cbcad2186512d9 (diff)
WIP better handling for slider creation
The creation of sliders is now using a template instead of a string computation. Also fixed some indentation and trailing spaces issues. Change-Id: Ieb1d9f953d61fa1bac46bf1ab6904e67d09a3fa9 Signed-off-by: Loïc Collignon <loic.collignon@iot.bzh>
-rw-r--r--app/CMakeLists.txt6
-rw-r--r--app/Mixer.qml63
-rw-r--r--app/Mixer.qrc1
-rw-r--r--app/VolumeSlider.qml44
-rw-r--r--app/main.cpp4
-rw-r--r--app/mixer.cpp9
-rw-r--r--app/mixer.h2
7 files changed, 85 insertions, 44 deletions
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index 9aacf16..abbc03b 100644
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -48,8 +48,8 @@ set_target_properties(mixer PROPERTIES
)
target_link_libraries(mixer
- Qt5::Core
- Qt5::Quick
+ Qt5::Core
+ Qt5::Quick
Qt5::QuickControls2
Qt5::WebSockets
json-c
@@ -59,6 +59,6 @@ target_link_libraries(mixer
if(NOT NATIVE_BUILD)
target_link_libraries(mixer
homescreen
- qtWindowmanager
+ qtWindowmanager
)
endif()
diff --git a/app/Mixer.qml b/app/Mixer.qml
index 631eda5..725c2bb 100644
--- a/app/Mixer.qml
+++ b/app/Mixer.qml
@@ -25,67 +25,52 @@ import AGL.Demo.Controls 1.0
import Mixer 1.0
ApplicationWindow {
+ property Component volumeSlider
+
id: root
Mixer {
id: mixer
Component.onCompleted: {
- mixer.open(bindingAddress)
+ root.volumeSlider = Qt.createComponent("VolumeSlider.qml");
+ if (root.VolumeSlider.status !== Component.Ready) {
+ console.log("Failed to load the VolumeSlider.qml component: " + root.volumeSlider.errorString());
+ }
+ mixer.open(bindingAddress);
}
onRolesChanged: {
// Remove existing sliders
for(var i = sliders.children.length; i > 0 ; --i) {
- console.log("destroying: " + i)
- sliders.children[i-1].destroy()
+ console.log("destroying: " + i);
+ sliders.children[i-1].destroy();
}
// Add slider for each role
for(var j = 0; j < mixer.roles.length; ++j) {
- addSlider(mixer.roles[j])
+ addSlider(mixer.roles[j]);
}
}
- function addSlider(name) {
- Qt.createQmlObject("
-import QtQuick.Layouts 1.1
-import QtQuick.Controls 2.0
-RowLayout {
- property int value
- id: slider_" + name + "
- Layout.minimumHeight: 75
- Label {
- font.pixelSize: 24
- text: \"" + name+ "\"
- Layout.minimumWidth: 150
+ onVolumeChanged: {
+ for(var i = 0; i < sliders.children.length ; i++) {
+ console.log("Slider found: " + i);
+ //if (sliders[i].role === name) {
+ // sliders[i].value = value;
+ //}
}
- Label {
- id: slider_" + name + "_textvalue
- font.pixelSize: 24
- text: \"0 %\"
- }
- Slider {
- id: slider_" + name + "_slider
- Layout.fillWidth: true
- from: 0
- to: 100
- stepSize: 1
- snapMode: Slider.SnapOnRelease
- onValueChanged: {
- slider_" + name + "_textvalue.text = value + \" %\"
- mixer.setVolume(\"" + name + "\", value)
- }
- Component.objectName: {
- mixer.getVolume(\"" + name + "\")
- }
- }
- }", sliders, "volumeslider")
+ }
+
+ function addSlider(name) {
+ var sld = root.volumeSlider.createObject(sliders);
+ sld.role = name;
+ mixer.getVolume(name); // Update volume
}
function deleteChilds(item) {
for(var i = item.children.length; i > 0 ; i--) {
- deleteChilds(item.children[i-1])
+ deleteChilds(item.children[i-1]);
}
- item.destroy()
+ item.destroy();
}
}
diff --git a/app/Mixer.qrc b/app/Mixer.qrc
index 27f216c..9512156 100644
--- a/app/Mixer.qrc
+++ b/app/Mixer.qrc
@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>Mixer.qml</file>
+ <file>VolumeSlider.qml</file>
</qresource>
</RCC>
diff --git a/app/VolumeSlider.qml b/app/VolumeSlider.qml
new file mode 100644
index 0000000..56881b7
--- /dev/null
+++ b/app/VolumeSlider.qml
@@ -0,0 +1,44 @@
+import QtQuick.Layouts 1.1
+import QtQuick.Controls 2.0
+
+RowLayout {
+ property int value
+ property string role
+
+ onRoleChanged: sliderName.text = role
+ onValueChanged: {
+ sliderValue.text = value + " %"
+ sliderControl.value = value;
+ }
+
+ //id: slider_" + name + "
+ Layout.minimumHeight: 75
+ Label {
+ id: sliderName
+ font.pixelSize: 24
+ text: role
+ Layout.minimumWidth: 150
+ }
+ Label {
+ id: sliderValue
+ //id: slider_" + name + "_textvalue
+ font.pixelSize: 24
+ text: "0 %"
+ }
+ Slider {
+ id: sliderControl
+ //id: slider_" + name + "_slider
+ Layout.fillWidth: true
+ from: 0
+ to: 100
+ stepSize: 1
+ snapMode: Slider.SnapOnRelease
+ onValueChanged: {
+ //slider_" + name + "_textvalue.text = value + \" %\"
+ //mixer.setVolume(\"" + name + "\", value)
+ }
+ //Component.onCompleted: {
+ //mixer.getVolume(\"" + name + "\")
+ //}
+ }
+}
diff --git a/app/main.cpp b/app/main.cpp
index 60b2951..52a0ff9 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -70,8 +70,9 @@ int main(int argc, char *argv[])
bindingAddress.setQuery(query);
QQmlContext *context = engine.rootContext();
context->setContextProperty(QStringLiteral("bindingAddress"), bindingAddress);
+ qDebug() << "Connect to: " << bindingAddress;
+
- std::string token = secret.toStdString();
#ifndef NATIVE_BUILD
LibHomeScreen* hs = new LibHomeScreen();
QLibWindowmanager* qwm = new QLibWindowmanager();
@@ -91,6 +92,7 @@ int main(int argc, char *argv[])
});
// HomeScreen
+ std::string token = secret.toStdString();
hs->init(port, token.c_str());
// Set the event handler for Event_TapShortcut which will activate the surface for windowmanager
hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [qwm, myname](json_object *object){
diff --git a/app/mixer.cpp b/app/mixer.cpp
index 6614569..6a1245c 100644
--- a/app/mixer.cpp
+++ b/app/mixer.cpp
@@ -61,7 +61,7 @@ void Mixer::setVolume(const QString& name, int value)
QJsonObject arg;
arg.insert("action", "volume");
arg.insert("value", QJsonValue(value));
- m_client.call("ahl-4a", name, arg, [this, name](bool r, const QJsonValue& v) {
+ m_client.call("ahl-4a", name, arg, [name](bool r, const QJsonValue& v) {
if (r && v.isObject())
{
// TODO: Success, update the slider
@@ -82,6 +82,13 @@ void Mixer::getVolume(const QString& name)
if (r && v.isObject())
{
// TODO: Success, update the slider
+ int newVolume = v.toObject()["response"].toObject()["volnew"].toInt();
+ auto currentVolume = volumes_.find(name);
+ if (currentVolume != volumes_.end() && *currentVolume == newVolume)
+ return;
+
+ volumes_[name] = newVolume;
+ emit volumeChanged(name, newVolume);
}
else
{
diff --git a/app/mixer.h b/app/mixer.h
index a46c8a1..1eb6b76 100644
--- a/app/mixer.h
+++ b/app/mixer.h
@@ -21,6 +21,7 @@
#include <QString>
#include <QSharedPointer>
#include <QStringList>
+#include <QMap>
#include "qafbwebsocketclient.h"
//#include "volumeslider.h"
@@ -31,6 +32,7 @@ class Mixer
Q_PROPERTY(QStringList roles READ roles NOTIFY rolesChanged)
private:
+ QMap<QString, int> volumes_;
public:
explicit Mixer(QObject* parent = nullptr);