source: src-qt4/pc-mixer/DeviceWidget.cpp @ 0c784d0

releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 0c784d0 was 0c784d0, checked in by Ken Moore <ken@…>, 6 months ago

Finish up the new pc-mixer utility. The main Mixer GUI is done now, and it all works great!

  • Property mode set to 100644
File size: 3.3 KB
Line 
1#include "DeviceWidget.h"
2#include "ui_DeviceWidget.h"
3
4DeviceWidget::DeviceWidget(QWidget *parent) : QWidget(parent), ui(new Ui::DeviceWidget){
5  ui->setupUi(this); //Load the designer file
6  //Initialize the rest of the items
7  islinked = true;
8  ismuted = false;
9  changing = false; //if true, slots will be de-activated
10  CRV = 0; CLV = 0;
11  //connect the signals/slots
12  connect(ui->slider_L, SIGNAL(valueChanged(int)), this, SLOT(LSliderChanged(int)) );
13  connect(ui->slider_R, SIGNAL(valueChanged(int)), this, SLOT(RSliderChanged(int)) );
14  connect(ui->push_mute, SIGNAL(clicked()), this, SLOT(muteClicked()) );
15  connect(ui->tool_chain, SIGNAL(clicked()), this, SLOT(linkClicked()) );
16}
17
18DeviceWidget::~DeviceWidget(){
19       
20}
21
22//===============
23//            PUBLIC
24//===============
25void DeviceWidget::setupDevice(QString device, int Lvol, int Rvol){
26  changing = true; //going to change the sliders
27  ui->label_device->setText(device);
28  ui->slider_L->setValue(Lvol);
29  ui->slider_R->setValue(Rvol);
30  islinked = (Lvol == Rvol);
31  ismuted = (islinked && (Lvol == 0) );
32  changing = false; //done making changes
33  updateButtons();
34}
35       
36QString DeviceWidget::device(){
37  return ui->label_device->text();     
38}
39
40int DeviceWidget::LVolume(){
41  return ui->slider_L->value();
42}
43
44int DeviceWidget::RVolume(){
45  return ui->slider_R->value();
46}
47
48//===============
49//            PRIVATE
50//===============
51void DeviceWidget::updateButtons(){
52  //Update the button icons/text as necessary
53  if(islinked){
54    ui->tool_chain->setIcon(QIcon(":icons/link.png"));
55  }else{
56    ui->tool_chain->setIcon(QIcon(":icons/link_break.png"));
57  }
58  if(ismuted){
59    ui->push_mute->setIcon( QIcon(":icons/audio-volume-high.png") );
60    ui->push_mute->setText( tr("Unmute") );
61  }else{
62    ui->push_mute->setIcon( QIcon(":icons/audio-volume-muted.png") );
63    ui->push_mute->setText( tr("Mute") );         
64  }
65}
66
67void DeviceWidget::updateVolumes(int Lvol, int Rvol){
68  changing=true; //going to change the sliders
69  //Update the sliders
70  if(ui->slider_L->value() != Lvol){ ui->slider_L->setValue(Lvol); }
71  if(ui->slider_R->value() != Rvol){ ui->slider_R->setValue(Rvol); }
72  changing = false; //done making changes to sliders
73  ismuted = (Lvol==Rvol) && (Lvol ==0);
74  updateButtons(); //make sure to update the buttons now
75  //Now adjust the backend mixer to reflect the changes
76  Mixer::setValues(ui->label_device->text(), Lvol, Rvol);
77  emit deviceChanged( ui->label_device->text() );
78}
79
80//===============
81//      PRIVATE SLOTS
82//===============
83void DeviceWidget::muteClicked(){
84  if(ismuted){
85    if(CLV==0  && CRV==0){
86      updateVolumes(50,50);
87    }else{
88      updateVolumes(CLV, CRV);
89    }
90  }else{
91    CLV = ui->slider_L->value(); CRV = ui->slider_R->value(); //save for later
92    updateVolumes(0,0);
93  }
94}
95
96void DeviceWidget::linkClicked(){
97  islinked = !islinked; //flip to the other
98  updateButtons();
99}
100
101void DeviceWidget::LSliderChanged(int Lvol){
102  if(changing){ return; } //no double-taps while class is making adjustments
103  if(islinked){
104    updateVolumes(Lvol, Lvol);
105  }else{
106    updateVolumes(Lvol, ui->slider_R->value() );
107  }
108 
109}
110
111void DeviceWidget::RSliderChanged(int Rvol){
112  if(changing){ return; } //no double-taps while class is making adjustments
113  if(islinked){
114    updateVolumes(Rvol, Rvol);
115  }else{
116    updateVolumes(ui->slider_L->value(), Rvol);
117  } 
118}
119
Note: See TracBrowser for help on using the repository browser.