source: src-qt4/pc-mixer/MixerTray.cpp @ 187a4cf

releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 187a4cf was 187a4cf, checked in by Ken Moore <ken@…>, 10 months ago

Now make sure that if the main Mixer is open, that any changes through the tray also reflect in the main Mixer. Now both the tray and main mixer UI should be in sync at all times (even though if the mixer is open the user will probably not be using the tray to change things).

  • Property mode set to 100644
File size: 4.3 KB
Line 
1#include "MixerTray.h"
2
3MixerTray::MixerTray() : QSystemTrayIcon(){
4  starting = true;
5  //Initialize the settings backend
6  settings = new QSettings("PCBSD", "pc-mixer");
7  //Initialize all the widgets
8  isMuted = false;
9  slider = new QSlider(Qt::Vertical, 0);
10    slider->setRange(0,100);
11    slider->setTickPosition(QSlider::NoTicks);
12  slideA  = new QWidgetAction(0);
13        slideA->setDefaultWidget(slider);
14  mute = new QToolButton(0);
15  muteA = new QWidgetAction(0);
16        muteA->setDefaultWidget(mute);
17  mixer = new QToolButton(0);
18        mixer->setText(tr("Mixer"));
19        mixer->setIcon(QIcon(":icons/configure.png"));
20        mixer->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
21  mixerA = new QWidgetAction(0);
22        mixerA->setDefaultWidget(mixer);
23  actionMenu = new QMenu(0);
24        actionMenu->addAction(slideA);
25        actionMenu->addAction(muteA);
26        actionMenu->addSeparator();
27        actionMenu->addAction(mixerA);
28  //Now initialize the GUI
29  GUI = new MixerGUI(settings);
30 
31  //Connect the signals/slots
32  connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayActivated()) );
33  connect(mixer, SIGNAL(clicked()), this, SLOT(openMixerGUI()) );
34  connect(mute, SIGNAL(clicked()), this, SLOT(muteClicked()) );
35  connect(slider, SIGNAL(valueChanged(int)), this, SLOT(sliderChanged(int)) );
36  connect(GUI, SIGNAL(updateTray()), this, SLOT(loadVol()) );
37 
38  //Show a quick icon to prevent a warning message
39  this->setIcon(QIcon(":icons/audio-volume-high.png"));
40  CVOL = 101; //quick default to maximize it
41  CDIFF = 0;
42  //Make sure no single-instance events for 30 seconds
43  QTimer::singleShot(30000, this, SLOT(doneStarting()) );
44  QTimer::singleShot(10, this, SLOT(loadVol()) ); //Update the UI
45}
46
47MixerTray::~MixerTray(){
48       
49}
50
51//==============
52//        PRIVATE
53//==============
54void MixerTray::loadVol(){
55  //Generally only used to update the tray to match the backend setting (or if tray device changed)
56  QString val = Mixer::getValues(settings->value("tray-device","vol").toString());
57  if(val.isEmpty()){
58    //invalid device - return to default "vol"
59    settings->setValue("tray-device","vol");
60    val = Mixer::getValues("vol");
61  }
62  int L = val.section(":",0,0).toInt();
63  int R = val.section(":",1,1).toInt();
64  //Record the different between L/R channels (if any)
65  CDIFF = L - R; // - for L lower, + for R lower
66  //Just use the largest value for the moment
67  if(L > R){ R = L; }
68  else if(L < R){ L = R; }
69  //Now just run the changeVol function to update everything (better than duplication)
70  changeVol(R, false);
71}
72
73void MixerTray::changeVol(int percent, bool modify){
74  //Determine the percentage to actually use and adjust internal value
75  if(percent < 0 && isMuted){ percent = CVOL; }   //Return to CVOL value
76  else if(percent < 0){ percent = 0; } //Don't overwrite CVOL if mute clicked
77  else if(percent > 100){ percent = 100; CVOL = 100;}
78  else{ CVOL = percent; }
79  //Now update the backend mixer to the proper value
80  if(modify){
81    if(CDIFF==0){
82      Mixer::setValues(settings->value("tray-device","vol").toString(), percent);
83    }else if(CDIFF < 0){
84      //L channel lower
85      Mixer::setValues(settings->value("tray-device","vol").toString(), percent + CDIFF, percent);
86    }else{
87      //R channel lower
88      Mixer::setValues(settings->value("tray-device","vol").toString(), percent, percent - CDIFF);
89    }
90    if(GUI->isVisible()){
91      //also update the main mixer GUI if it is visible
92      GUI->updateGUI();
93    }
94  }
95  //Now update the display appropriately
96  if(percent == 0){
97    isMuted = true;
98    mute->setIcon( QIcon::fromTheme("audio-volume-high", QIcon(":icons/audio-volume-high.png")) );
99  }else{
100    isMuted = false;
101    if(percent < 33){
102      this->setIcon( QIcon::fromTheme("audio-volume-low", QIcon("icons/audio-volume-low.png")) );
103    }else if(percent < 66){
104      this->setIcon( QIcon::fromTheme("audio-volume-medium", QIcon("icons/audio-volume-medium.png")) );
105    }else{
106      this->setIcon( QIcon::fromTheme("audio-volume-high", QIcon("icons/audio-volume-high.png")) );
107    }
108    mute->setIcon( QIcon::fromTheme("audio-volume-muted", QIcon(":icons/audio-volume-muted.png")) );
109  }
110 
111  slider->disconnect(); //Make sure this slider change does not trigger the signal/slot
112  slider->setValue(percent);
113  connect(slider, SIGNAL(valueChanged(int)), this, SLOT(sliderChanged(int)) ); //reconnect it
114 
115  this->setToolTip(QString::number(percent)+"%");
116}
117
Note: See TracBrowser for help on using the repository browser.