|
@@ -32,13 +32,16 @@ public:
|
|
|
delete socket;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private slots:
|
|
|
void onConnected() {
|
|
|
statusLabel->setText("Connected to status server");
|
|
|
+ updateBackgroundColor(Qt::gray); // assume no recording yet
|
|
|
}
|
|
|
|
|
|
void onDisconnected() {
|
|
|
statusLabel->setText("Disconnected from server");
|
|
|
+ updateBackgroundColor(Qt::red);
|
|
|
}
|
|
|
|
|
|
void onMessageReceived(const QString &message) {
|
|
@@ -46,20 +49,45 @@ private slots:
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &parseError);
|
|
|
if (parseError.error != QJsonParseError::NoError || !doc.isObject()) {
|
|
|
statusLabel->setText("Invalid status message");
|
|
|
+ updateBackgroundColor(Qt::red);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
QJsonObject obj = doc.object();
|
|
|
- QString statusText = QString("Recording: %1\nCD: %2\nTrack: %3\nElapsed CD Time: %4\nElapsed Track Time: %5")
|
|
|
- .arg(obj["recording"].toBool() ? "Yes" : "No")
|
|
|
- .arg(obj["cd"].toInt())
|
|
|
- .arg(obj["track"].toInt())
|
|
|
- .arg(obj["cd_time"].toString())
|
|
|
- .arg(obj["track_time"].toString());
|
|
|
-
|
|
|
- statusLabel->setText(statusText);
|
|
|
+ bool isRecording = obj["recording"].toBool();
|
|
|
+
|
|
|
+ QString statusText;
|
|
|
+ if (isRecording) {
|
|
|
+ statusText =
|
|
|
+ QString("Recording: active\nCD: %2\nTrack: %3\nElapsed CD Time: %4\nElapsed Track Time: %5")
|
|
|
+ .arg(obj["cd"].toInt())
|
|
|
+ .arg(obj["track"].toInt())
|
|
|
+ .arg(obj["cd_time"].toString())
|
|
|
+ .arg(obj["track_time"].toString());
|
|
|
+ } else {
|
|
|
+ statusText = QString("Recording is currently not active.");
|
|
|
+ }
|
|
|
+
|
|
|
+ statusLabel->setText(statusText);
|
|
|
+ updateBackgroundColor(isRecording ? QColor("#228B22") : Qt::gray);
|
|
|
}
|
|
|
|
|
|
+private:
|
|
|
+ void updateBackgroundColor(const QColor &bgColor) {
|
|
|
+ this->setStyleSheet(QString(
|
|
|
+ "background-color: %1;"
|
|
|
+ "color: %2;"
|
|
|
+ ).arg(bgColor.name())
|
|
|
+ .arg(isColorDark(bgColor) ? "white" : "black"));
|
|
|
+}
|
|
|
+
|
|
|
+bool isColorDark(const QColor &color) {
|
|
|
+ // Perceived brightness formula
|
|
|
+ int brightness = (color.red() * 299 + color.green() * 587 + color.blue() * 114) / 1000;
|
|
|
+ return brightness < 128;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
private:
|
|
|
QLabel *statusLabel;
|
|
|
QWebSocket *socket;
|