-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvideowallcontroller.cpp
More file actions
103 lines (78 loc) · 2.87 KB
/
videowallcontroller.cpp
File metadata and controls
103 lines (78 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "videowallcontroller.h"
#include <QDebug>
#include <QtWebSockets>
#include <QSettings>
#include "animation.h"
#include "websocket.h"
VideoWallController::VideoWallController(QObject *parent) : QObject(parent) {
// Setup animation model
_animationModel = new AnimationModel(this);
// Setup socket
_socket = new WebSocket(this);
connect(_socket, SIGNAL(connectionStateChanged(ConnectionState::Enum)), this, SIGNAL(connectionStateChanged(ConnectionState::Enum)));
connect(_socket, SIGNAL(errorString(QString)), this, SIGNAL(socketError(QString)));
connect(_socket, SIGNAL(animationsChanged(QList<Animation*>)), _animationModel, SLOT(setAnimations(QList<Animation*>)));
connect(_socket, SIGNAL(activeAnimationIdChanged(int)), this, SIGNAL(activeAnimationIdChanged(int)));
connect(_socket, SIGNAL(activeAnimationIdChanged(int)), this, SLOT(onActiveAnimationIdChanged(int)));
connect(_socket, SIGNAL(brightnessChanged(int)), this, SLOT(onBrightnessChanged(int)));
connect(_socket, SIGNAL(playModeChange(int)), this, SLOT(onPlayModeChanged(int)));
_activeAnimation = nullptr;
_playMode = 1;
setHostUrl(QSettings().value("hostUrl", "ws://localhost:9004").toString());
}
void VideoWallController::openSocket() {
_socket->open(_hostUrl);
}
void VideoWallController::closeSocket() {
_socket->close();
}
void VideoWallController::setHostUrl(const QString& hostUrl) {
if (hostUrl == _hostUrl) {
return;
}
QSettings().setValue("hostUrl", hostUrl);
_hostUrl = hostUrl;
emit hostUrlChanged(_hostUrl);
}
QString VideoWallController::hostUrl() const {
return _hostUrl;
}
void VideoWallController::onActiveAnimationIdChanged(int id) {
_activeAnimation = _animationModel->getAnimation(id);
emit activeAnimationChanged(id, _activeAnimation->name(), _activeAnimation->description());
}
void VideoWallController::setActiveAnimation(int animationId) {
_socket->sendActivateAnimationId(animationId);
}
int VideoWallController::activeAnimationId() const {
return (_activeAnimation != 0) ? _activeAnimation->id() : -1;
}
int VideoWallController::brightness() const {
return _brightness;
}
void VideoWallController::onBrightnessChanged(int brightness) {
_brightness = brightness;
emit brightnessChanged(_brightness);
}
void VideoWallController::setBrightness(int brightness) {
_socket->sendBrightness(brightness);
}
int VideoWallController::playMode() const {
return _playMode;
}
void VideoWallController::onPlayModeChanged(int playMode) {
_playMode = playMode;
emit playModeChanged(_playMode);
}
void VideoWallController::setPlayMode(int playMode) {
_socket->sendPlayMode(playMode);
}
AnimationModel* VideoWallController::getAnimationModel() {
return _animationModel;
}
ConnectionState::Enum VideoWallController::connectionState() const {
return _socket->connectionState();
}
QString VideoWallController::socketError() const {
return _socket->errorString();
}