From 85aa2f9bc3d5336c1c39beb5d06b0d9674b03268 Mon Sep 17 00:00:00 2001 From: flykhan Date: Thu, 31 Aug 2023 18:57:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9F=B3=E9=87=8F=E6=8E=A7=E5=88=B6=E6=BB=91?= =?UTF-8?q?=E5=9D=97=E4=BC=98=E5=8C=96=EF=BC=8C=E9=9F=B3=E9=87=8F=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=8C=BA=E6=98=BE=E7=A4=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mainwindow.cpp | 20 ++++++++++++++++++++ mainwindow.h | 2 ++ mainwindow.ui | 24 ++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 8934b96..cde22da 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -338,6 +338,7 @@ void MainWindow::volume_control(int value, int abs) // 音量调整到 value 大小(-数减+数加), abs 为 0 时在当前音量上加减一个值,abs 不为 0 时将当前音量设置为 value 大小 int len = sprintf(changeSongBuf, "volume %d %d\n", value, abs); write(this->fifo_fd, changeSongBuf, len); // 将音量控制指令写入到有名管道中 + ui->volume_label->setText(QString::number(currentVolume) + " %"); } void MainWindow::volume_mute_switch(int mute_arg) @@ -365,11 +366,24 @@ void MainWindow::on_mute_btn_clicked() // volume_mute_switch(1); // mute_flag = 1; volume_mute_switch(++mute_flag); + ui->volume_down_btn->setDisabled(true); + ui->volume_up_btn->setDisabled(true); + ui->volume_slider->setDisabled(true); + ui->volume_slider->setStyleSheet("QSlider::groove:horizontal { background-color: white; }" + "QSlider::handle:horizontal { background-color: gray; width: 20px;}"); + ui->volume_label->setText("Muted"); } else if (mute_flag == 1) // 已静音则按下后取消静音 { ui->mute_btn->setIcon(QIcon(":/icon2/sound-off")); volume_mute_switch(--mute_flag); + ui->volume_down_btn->setDisabled(false); + ui->volume_up_btn->setDisabled(false); + ui->volume_slider->setDisabled(false); + ui->volume_slider->setStyleSheet("QSlider::groove:horizontal { background-color: gray; }" + "QSlider::handle:horizontal { background-color: yellow; width: 20px;}"); + ui->volume_label->setText(QString::number(currentVolume) + " %"); + } } @@ -393,3 +407,9 @@ void MainWindow::on_volume_up_btn_clicked() setVolumeSlider(currentVolume); // 设置音量滑块位置 } } + +void MainWindow::on_volume_slider_sliderMoved(int position) +{ + currentVolume = position; + volume_control(position, 1); +} diff --git a/mainwindow.h b/mainwindow.h index 554c811..29d4203 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -77,6 +77,8 @@ private slots: void on_volume_up_btn_clicked(); + void on_volume_slider_sliderMoved(int position); + private: Ui::MainWindow *ui; }; diff --git a/mainwindow.ui b/mainwindow.ui index 7604c66..a62e844 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -244,10 +244,26 @@ color: rgb(255, 255, 0); - - - Qt::Horizontal - + + + + + + Qt::Horizontal + + + + + + + color: rgb(255, 255, 0); + + + ------ + + + +