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

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

Add new options to the pc-mixer GUI:
Links to run pc-soundconfig, pavucontrol, paprefs.
Also add some icons.

  • Property mode set to 100644
File size: 3.4 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    ui->tool_chain->setAutoRaise(false);
56  }else{
57    ui->tool_chain->setIcon(QIcon(":icons/link_break.png"));
58    ui->tool_chain->setAutoRaise(true);
59  }
60  if(ismuted){
61    ui->push_mute->setIcon( QIcon(":icons/audio-volume-high.png") );
62    ui->push_mute->setText( tr("Unmute") );
63  }else{
64    ui->push_mute->setIcon( QIcon(":icons/audio-volume-muted.png") );
65    ui->push_mute->setText( tr("Mute") );         
66  }
67}
68
69void DeviceWidget::updateVolumes(int Lvol, int Rvol){
70  changing=true; //going to change the sliders
71  //Update the sliders
72  if(ui->slider_L->value() != Lvol){ ui->slider_L->setValue(Lvol); }
73  if(ui->slider_R->value() != Rvol){ ui->slider_R->setValue(Rvol); }
74  changing = false; //done making changes to sliders
75  ismuted = (Lvol==Rvol) && (Lvol ==0);
76  updateButtons(); //make sure to update the buttons now
77  //Now adjust the backend mixer to reflect the changes
78  Mixer::setValues(ui->label_device->text(), Lvol, Rvol);
79  emit deviceChanged( ui->label_device->text() );
80}
81
82//===============
83//      PRIVATE SLOTS
84//===============
85void DeviceWidget::muteClicked(){
86  if(ismuted){
87    if(CLV==0  && CRV==0){
88      updateVolumes(50,50);
89    }else{
90      updateVolumes(CLV, CRV);
91    }
92  }else{
93    CLV = ui->slider_L->value(); CRV = ui->slider_R->value(); //save for later
94    updateVolumes(0,0);
95  }
96}
97
98void DeviceWidget::linkClicked(){
99  islinked = !islinked; //flip to the other
100  updateButtons();
101}
102
103void DeviceWidget::LSliderChanged(int Lvol){
104  if(changing){ return; } //no double-taps while class is making adjustments
105  if(islinked){
106    updateVolumes(Lvol, Lvol);
107  }else{
108    updateVolumes(Lvol, ui->slider_R->value() );
109  }
110 
111}
112
113void DeviceWidget::RSliderChanged(int Rvol){
114  if(changing){ return; } //no double-taps while class is making adjustments
115  if(islinked){
116    updateVolumes(Rvol, Rvol);
117  }else{
118    updateVolumes(ui->slider_L->value(), Rvol);
119  } 
120}
121
Note: See TracBrowser for help on using the repository browser.