From 6ce791c0cee4485d55a9fe9a3c6c7df845e827dd Mon Sep 17 00:00:00 2001 From: rogo Date: Sat, 13 Oct 2018 00:21:18 +0200 Subject: [PATCH] added timer for volume changes --- mainwindow.cpp | 26 +++++++++++++++++++++++--- mainwindow.h | 9 +++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 722b20d..3a35b93 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,6 +1,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include #include #include @@ -16,6 +17,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->txt_address->setText(DEFAULT_ADDRESS); mAddress = ui->txt_address->text(); + connect(&mTimer, &QTimer::timeout, this, &MainWindow::sendVolume); + mTimer.setSingleShot(true); + // load initial data sendCommand("GetParam"); sendCommand("GetParam"); @@ -36,6 +40,7 @@ void MainWindow::sendCommand(QString cmd) QNetworkAccessManager *networkManager = new QNetworkAccessManager(this); networkManager->post(request, cmd.toUtf8()); connect(networkManager, &QNetworkAccessManager::finished, this, &MainWindow::replyFinished); + networkManager->deleteLater(); } void MainWindow::replyFinished(QNetworkReply* reply) @@ -108,10 +113,25 @@ void MainWindow::on_btn_onoff_clicked() updateUi(); } +void MainWindow::on_dial_valueChanged(int value) +{ + int d = value % 10; + qDebug() << d; + if (!( d == -5 || d == 0 )) + value -= d; + + ui->lbl_volume->setText(QString::number(value)); + mVolume = value; + mTimer.start(WAITTIME); } -void yremote::MainWindow::on_dial_valueChanged(int value) +void MainWindow::sendVolume() { - ui->lbl_volume->setText(QString::number(value)); - sendCommand("" + QString::number(value) + "1dB"); +// sendCommand("" +// + QString::number(mVolume) +// + "1dB"); } + +} + + diff --git a/mainwindow.h b/mainwindow.h index f3ce4d6..4a5d137 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include +#include #include "QtNetwork/QNetworkAccessManager" namespace Ui { @@ -18,9 +19,6 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); -protected: - void func(); - private slots: void on_btn_onoff_clicked(); void replyFinished(QNetworkReply *reply); @@ -32,12 +30,15 @@ private: Ui::MainWindow *ui; QString mAddress; - + QTimer mTimer; bool mPowered = false; int mVolume = 0; + const int WAITTIME = 300; + void sendCommand(QString cmd); void updateUi(); + void sendVolume(); }; }