Skip to content
Permalink
Browse files

Profile switching

  • Loading branch information...
martonborzak committed Oct 13, 2019
1 parent b2bf8bf commit f7581a4ef1c1d672f9adce0aed464f7fe387ae8c
@@ -49,15 +49,13 @@ Item {
break;
case "dpad up":
var newpos = mainNavigationSwipeview.currentItem.mainNavigationLoader.item.contentY - 200;
// mainNavigationSwipeview.currentItem.mainNavigationLoader.item.contentY -= 200;
if (newpos <= 0) {
newpos = 0;
haptic.playEffect("buzz");
}
mainNavigationSwipeview.currentItem.mainNavigationLoader.item.contentY = newpos;
break;
case "dpad down":
// mainNavigationSwipeview.currentItem.mainNavigationLoader.item.contentY += 200;
newpos = mainNavigationSwipeview.currentItem.mainNavigationLoader.item.contentY + 200;
if (newpos >= (mainNavigationSwipeview.currentItem.mainNavigationLoader.item.contentHeight - mainNavigationSwipeview.currentItem.mainNavigationLoader.item.height)) {
newpos = mainNavigationSwipeview.currentItem.mainNavigationLoader.item.contentHeight - mainNavigationSwipeview.currentItem.mainNavigationLoader.item.height;
@@ -150,23 +148,23 @@ Item {
}

if (itemsLoaded >= 3) {
if (!mainNavigation.mainNavigationListView.currentItem && !mainNavigation.mainNavigationListView.currentItem.held) {
if (mainNavigation.mainNavigationListView.count !== 0 && !mainNavigation.mainNavigationListView.currentItem && !mainNavigation.mainNavigationListView.currentItem.held) {
mainNavigation.mainNavigationListView.currentIndex = currentIndex
mainNavigation.mainNavigationListView.positionViewAtIndex(currentIndex, ListView.Center)
}
}

// change the statusbar title
if (mainNavigationSwipeview.currentItem.mainNavigationLoader.item && mainNavigationSwipeview.currentItem.mainNavigationLoader.item.contentY < 130) {
if (mainNavigation.mainNavigationListView.count !== 0 && mainNavigationSwipeview.currentItem.mainNavigationLoader.item && mainNavigationSwipeview.currentItem.mainNavigationLoader.item.contentY < 130) {
statusBar.title = "";
} else if (mainNavigationSwipeview.currentItem.mainNavigationLoader.item) {
} else if (mainNavigation.mainNavigationListView.count !== 0 && mainNavigationSwipeview.currentItem.mainNavigationLoader.item) {
statusBar.title = mainNavigationSwipeview.currentItem.mainNavigationLoader.item.title;
}

// change statusbar opacity
if (mainNavigationSwipeview.currentItem.mainNavigationLoader.item && mainNavigationSwipeview.currentItem.mainNavigationLoader.item.contentY < 10) {
if (mainNavigation.mainNavigationListView.count !== 0 && mainNavigationSwipeview.currentItem.mainNavigationLoader.item && mainNavigationSwipeview.currentItem.mainNavigationLoader.item.contentY < 10) {
statusBar.bg.opacity = 0;
} else if (mainNavigationSwipeview.currentItem.mainNavigationLoader.item) {
} else if (mainNavigation.mainNavigationListView.count !== 0 && mainNavigationSwipeview.currentItem.mainNavigationLoader.item) {
statusBar.bg.opacity = 1;
}
}
@@ -31,7 +31,7 @@ Item {
Connections {
target: config

onConfigChanged: {
onProfileChanged: {
loadmenuConfig();
}
}
@@ -16,9 +16,15 @@ Rectangle {

for (var value in config.read.ui_config.profiles) {
var v = config.read.ui_config.profiles[value];
v["id"] = value;
v["id"] = parseInt(value, 10);
profileModel.append(v);
}

for (var i=0; i<profileModel.count; i++) {
if (profileModel.get(i).id === config.profile) {
profileModel.move(i, 0, 1);
}
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -34,7 +40,7 @@ Rectangle {
PropertyChanges {target: loader_main; state: "visible" }
},
State { name: "open";
when: parent.status == Loader.Ready
when: parent.status === Loader.Ready
PropertyChanges {target: profiles; height: 670 }
PropertyChanges {target: parent; height: 670 }
PropertyChanges {target: loader_main; state: "hidden" }
@@ -143,22 +149,8 @@ Rectangle {
onClicked: {
config.profile = id;
profileModel.move(index, 0, 1);
// reloadTimer.start();
// closeTimer.start();
}
}

// Timer {
// id: closeTimer
// interval: 300
// repeat: false
// running: false

// onTriggered: {
// profiles.state = "closed";
// }
// }

}
}

@@ -7,6 +7,8 @@ Flickable {
//: Name of the settings page
property string title: qsTr("Favorites") + translateHandler.emptyString

property var favoritesModel: config.read.ui_config.profiles[config.profile].favorites

signal scrolledUp()
signal scrolledDown()
signal scrollupBegin()
@@ -71,27 +73,26 @@ Flickable {
interactive: false
spacing: 10

model: config.read.ui_config.profiles[config.profile].favorites
model: favoritesModel
delegate: entityDelegate
}


// LISTVIEW DELEGATE
Component {
id: entityDelegate

// Loader {
// id: entityLoader
// width: 460
// height: 125
// anchors.horizontalCenter: parent.horizontalCenter

// Component.onCompleted: {
// var e = entities.get(config.read.ui_config.profiles[config.profile].favorites[index]);
// if (e.type != "undefined") {
// this.setSource("qrc:/components/"+ e.type +"/ui/Button.qml", { "obj": e });
// }
// }
// }
Loader {
id: entityLoader
width: 460
height: 125
anchors.horizontalCenter: parent.horizontalCenter

Component.onCompleted: {
var e = entities.get(favoritesModel[index]);
this.setSource("qrc:/components/"+ e.type +"/ui/Button.qml", { "obj": e });
}
}
}

}
@@ -133,9 +133,7 @@ Item {

Component.onCompleted: {
var e = entities.get(config.read.ui_config.groups[groupID].entities[index]);
if (e) {
this.setSource("qrc:/components/"+ e.type +"/ui/Button.qml", { "obj": e });
}
this.setSource("qrc:/components/"+ e.type +"/ui/Button.qml", { "obj": e });
}
}
}
@@ -156,13 +156,13 @@ Flickable {
anchors.top: titleContainer.bottom
spacing: 60

// Repeater {
// id: groupRepeater
// model: config.read.ui_config.pages[page].groups

// Group {
// groupID: config.read.ui_config.pages[page].groups[index]
// }
// }
Repeater {
id: groupRepeater
model: config.read.ui_config.pages[page].groups

Group {
groupID: config.read.ui_config.pages[page].groups[index]
}
}
}
}
@@ -212,7 +212,6 @@ ApplicationWindow {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CONFIGURATION
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Component.onCompleted: {
if (config.read == undefined) {
console.debug("Cannot load configuration file");
@@ -334,29 +333,6 @@ ApplicationWindow {
}
}

// Connections {
// target: config

// onConfigChanged: {
// loader_main.source = "";
// loader_main.active = false;
// reloadTimer.start()
// }
// }

// property alias reloadTimer: reloadTimer

// Timer {
// id: reloadTimer
// interval: 1000
// running: false
// repeat: false

// onTriggered: {
// loader_main.setSource("qrc:/MainContainer.qml");
// loader_main.active = true;
// }
// }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SECONDARY CONTAINER
@@ -10,7 +10,6 @@ Config::Config(QQmlApplicationEngine *engine, QString path) :

//load the config file
readConfig(path);

}

Config::~Config()
@@ -31,7 +31,6 @@ class Config : public QObject, ConfigInterface
{
m_config = config;
emit configChanged();
qDebug() << "CONFIG READWRITE";
}

// profile
@@ -49,9 +48,6 @@ class Config : public QObject, ConfigInterface
writeConfig();

emit profileChanged();
emit configChanged();

qDebug() << "PROFILE CHANGE";
}

public:
@@ -39,12 +39,12 @@ void Blind::setPosition(int value)
command("POSITION", value);
}

Blind::Blind() :
Entity (Type, QVariantMap(), NULL)
Blind::Blind(QObject *parent) :
Entity (Type, QVariantMap(), NULL, parent)
{
}

Blind::Blind(const QVariantMap& config, QObject* integrationObj):
Entity (Type, config, integrationObj)
Blind::Blind(const QVariantMap& config, QObject* integrationObj, QObject *parent):
Entity (Type, config, integrationObj, parent)
{
}
@@ -23,8 +23,8 @@ class Blind : public Entity
Q_INVOKABLE void stop();
Q_INVOKABLE void setPosition(int value);

explicit Blind();
Blind(const QVariantMap& config, QObject* integrationObj);
explicit Blind(QObject *parent = nullptr);
Blind(const QVariantMap& config, QObject* integrationObj, QObject *parent = nullptr);

bool state() const { return m_state; }
int position() const { return m_position; }
@@ -110,19 +110,19 @@ void Entities::add(const QString& type, const QVariantMap& config, QObject *inte
Entity *entity;
// Light entity
if (type == "light") {
entity = new Light(config, integrationObj);
entity = new Light(config, integrationObj, this);
}
// Blind entity
if (type == "blind") {
entity = new Blind(config, integrationObj);
entity = new Blind(config, integrationObj, this);
}
// Media player entity
if (type == "media_player") {
entity = new MediaPlayer(config, integrationObj);
}
entity = new MediaPlayer(config, integrationObj, this);
}
// Remote entity
if (type == "remote") {
entity = new Remote(config, integrationObj);
entity = new Remote(config, integrationObj, this);
}
m_entities.insert(entity->entity_id(), entity);
}
@@ -4,7 +4,8 @@
#include <QtDebug>
#include <QTimer>

Entity::Entity(const QString& type, const QVariantMap& config, QObject *integrationObj) :
Entity::Entity(const QString& type, const QVariantMap& config, QObject *integrationObj, QObject *parent) :
QObject(parent),
m_integrationObj(integrationObj),
m_type(type),
m_area(config.value("area").toString()),
@@ -33,7 +33,7 @@ class Entity : public QObject
virtual bool update (const QVariantMap& attributes);

// Creation from config.json content and integration hub
explicit Entity (const QString& type, const QVariantMap& config, QObject *integrationObj);
explicit Entity (const QString& type, const QVariantMap& config, QObject *integrationObj, QObject *parent = nullptr);
virtual ~Entity ();

QString type() { return m_type; }
@@ -61,13 +61,13 @@ void Light::setColorTemp(int value)
command("COLORTEMP", value);
}

Light::Light() :
Entity (Type, QVariantMap(), NULL)
Light::Light(QObject *parent) :
Entity (Type, QVariantMap(), NULL, parent)
{

}

Light::Light(const QVariantMap& config, QObject* integrationObj):
Entity (Type, config, integrationObj)
Light::Light(const QVariantMap& config, QObject* integrationObj, QObject *parent):
Entity (Type, config, integrationObj, parent)
{
}
@@ -29,8 +29,8 @@ class Light : public Entity
Q_INVOKABLE void setColor(QColor value);
Q_INVOKABLE void setColorTemp(int value);

explicit Light();
Light(const QVariantMap& config, QObject* integrationObj);
explicit Light(QObject *parent = nullptr);
Light(const QVariantMap& config, QObject* integrationObj, QObject *parent = nullptr);

bool state() const { return m_state; }
int brightness() const { return m_brightness; }
@@ -93,12 +93,12 @@ void MediaPlayer::setVolume(double value)
command("VOLUME_SET", value);
}

MediaPlayer::MediaPlayer() :
Entity(Type, QVariantMap(), NULL)
MediaPlayer::MediaPlayer(QObject *parent) :
Entity(Type, QVariantMap(), NULL, parent)
{
}

MediaPlayer::MediaPlayer(const QVariantMap& config, QObject* integrationObj):
Entity(Type, config, integrationObj)
MediaPlayer::MediaPlayer(const QVariantMap& config, QObject* integrationObj, QObject *parent):
Entity(Type, config, integrationObj, parent)
{
}
@@ -51,8 +51,8 @@ class MediaPlayer : public Entity
Q_INVOKABLE void setVolume(double value);

// constructor
explicit MediaPlayer();
MediaPlayer(const QVariantMap& config, QObject* integrationObj);
explicit MediaPlayer(QObject *parent = nullptr);
MediaPlayer(const QVariantMap& config, QObject* integrationObj, QObject *parent = nullptr);

enum states state() { return m_state; }

@@ -9,14 +9,14 @@ bool Remote::update(const QVariantMap &attributes)
{
}

Remote::Remote() :
Entity (Type, QVariantMap(), NULL)
Remote::Remote(QObject *parent) :
Entity (Type, QVariantMap(), NULL, parent)
{

}

Remote::Remote(const QVariantMap& config, QObject* integrationObj):
Entity (Type, config, integrationObj)
Remote::Remote(const QVariantMap& config, QObject* integrationObj, QObject *parent):
Entity (Type, config, integrationObj, parent)
{
m_commands = config.value("commands").toJsonArray().toVariantList();
emit commandsChanged();

0 comments on commit f7581a4

Please sign in to comment.
You can’t perform that action at this time.