From f1d9a08a84092f72c6e344b6013219c796d7c04e Mon Sep 17 00:00:00 2001 From: rogo Date: Sat, 13 Oct 2018 13:04:08 +0200 Subject: [PATCH] added functioning input change and read --- mainwindow.cpp | 53 ++++++++++++++++++++--- mainwindow.h | 12 ++++-- mainwindow.ui | 115 ++++++++++++++++++++++++++++++------------------- 3 files changed, 126 insertions(+), 54 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 39a334f..545c39f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,7 +2,6 @@ #include "ui_mainwindow.h" #include -#include #include class QNetworkReply; @@ -23,6 +22,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi // load initial data sendCommand("GetParam"); sendCommand("GetParam"); + sendCommand("GetParam"); } MainWindow::~MainWindow() @@ -56,22 +56,26 @@ void MainWindow::replyFinished(QNetworkReply* reply) } // check power state - QRegularExpression regexPower("(.*)"); + QRegularExpression regexPower("(.+)"); QRegularExpressionMatch matchPower = regexPower.match(ans); - if (matchPower.hasMatch()) { if (matchPower.captured(1) == "On") mPowered = true; else if (matchPower.captured(1) == "Off") mPowered = false; } // check volume - QRegularExpression regexVolume("(.*)"); + QRegularExpression regexVolume("(.+)"); QRegularExpressionMatch matchVolume = regexVolume.match(ans); - if (matchVolume.hasMatch()) { mVolume = matchVolume.captured(1).toInt(); } + // check input + QRegularExpression regexInput("(.+)"); + QRegularExpressionMatch matchInput = regexInput.match(ans); + if (matchInput.hasMatch()) + mInput = matchInput.captured(1); + reply->deleteLater(); updateUi(); } @@ -87,6 +91,7 @@ void MainWindow::updateUi() { ui->btn_spotify->setEnabled(mPowered); ui->btn_airplay->setEnabled(mPowered); ui->btn_audioin->setEnabled(mPowered); + ui->lbl_input->setText(mInput); } void MainWindow::on_txt_address_textEdited(const QString &arg1) @@ -118,7 +123,6 @@ void MainWindow::on_dial_valueChanged(int value) value -= d; ui->lbl_volume->setText(QString::number(value)); - ui->dial->setValue(value); mVolume = value; mTimer.start(WAITTIME); } @@ -130,4 +134,41 @@ void MainWindow::sendVolume() + "1dB"); } +void MainWindow::on_btn_hdmi1_clicked() +{ + sendCommand("HDMI1"); + mInput = "HDMI1"; +} + +void MainWindow::on_btn_hdmi2_clicked() +{ + sendCommand("HDMI2"); + mInput = "HDMI2"; +} + +void MainWindow::on_btn_hdmi3_clicked() +{ + sendCommand("HDMI3"); + mInput = "HDMI3"; +} + +void MainWindow::on_btn_spotify_clicked() +{ + sendCommand("Spotify"); + mInput = "Spotify"; +} + +void MainWindow::on_btn_airplay_clicked() +{ + // TODO + sendCommand("IPOD"); + mInput = "IPOD"; +} + +void MainWindow::on_btn_audioin_clicked() +{ + sendCommand("AUDIO"); + mInput = "AUDIO"; +} + } diff --git a/mainwindow.h b/mainwindow.h index 4a5d137..9b64113 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -22,9 +22,15 @@ public: private slots: void on_btn_onoff_clicked(); void replyFinished(QNetworkReply *reply); - void on_txt_address_textEdited(const QString &arg1); + void on_txt_address_textEdited(const QString &arg1); void on_dial_valueChanged(int value); + void on_btn_hdmi1_clicked(); + void on_btn_hdmi2_clicked(); + void on_btn_hdmi3_clicked(); + void on_btn_spotify_clicked(); + void on_btn_airplay_clicked(); + void on_btn_audioin_clicked(); private: Ui::MainWindow *ui; @@ -33,8 +39,8 @@ private: QTimer mTimer; bool mPowered = false; int mVolume = 0; - const int WAITTIME = 300; - + QString mInput; + const int WAITTIME = 400; void sendCommand(QString cmd); void updateUi(); diff --git a/mainwindow.ui b/mainwindow.ui index a25e7ee..6e8b73c 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 500 - 168 + 528 + 199 @@ -18,51 +18,14 @@ - - - - On - - - - - - - Address: - - - - - - - 10.0.0.227 - - - Qt::AlignCenter - - - - - - - -805 - - - -165 - - - 5 - - - 5 - - - - + Input + + true + @@ -143,7 +106,7 @@ - + @@ -158,7 +121,69 @@ QFrame::Sunken - -666 + -400 + + + Qt::AlignCenter + + + + + + + On + + + + + + + -805 + + + -200 + + + 5 + + + 5 + + + -400 + + + Qt::Vertical + + + false + + + false + + + + + + + Address: + + + + + + + 10.0.0.227 + + + Qt::AlignCenter + + + + + + + Qt::AlignCenter