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

enter/10releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1releng/10.1.1releng/10.1.2releng/10.2
Last change on this file since 0c784d0 was 0c784d0, checked in by Ken Moore <ken@…>, 18 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.8 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 
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  //Just use the largest value for the moment
65  if(L > R){ R = L; }
66  else if(L < R){ L = R; }
67  //Now just run the changeVol function to update everything (better than duplication)
68  changeVol(R);
69}
70
71void MixerTray::changeVol(int percent){
72  //Determine the percentage to actually use and adjust internal value
73  if(percent < 0 && isMuted){ percent = CVOL; }   //Return to CVOL value
74  else if(percent < 0){ percent = 0; } //Don't overwrite CVOL if mute clicked
75  else if(percent > 100){ percent = 100; CVOL = 100;}
76  else{ CVOL = percent; }
77  //Now update the backend mixer to the proper value
78  Mixer::setValues(settings->value("tray-device","vol").toString(), percent);
79  //Now update the display appropriately
80  if(percent == 0){
81    isMuted = true;
82    mute->setIcon( QIcon::fromTheme("audio-volume-high", QIcon(":icons/audio-volume-high.png")) );
83  }else{
84    isMuted = false;
85    if(percent < 33){
86      this->setIcon( QIcon::fromTheme("audio-volume-low", QIcon("icons/audio-volume-low.png")) );
87    }else if(percent < 66){
88      this->setIcon( QIcon::fromTheme("audio-volume-medium", QIcon("icons/audio-volume-medium.png")) );
89    }else{
90      this->setIcon( QIcon::fromTheme("audio-volume-high", QIcon("icons/audio-volume-high.png")) );
91    }
92    mute->setIcon( QIcon::fromTheme("audio-volume-muted", QIcon(":icons/audio-volume-muted.png")) );
93  }
94 
95  slider->disconnect(); //Make sure this slider change does not trigger the signal/slot
96  slider->setValue(percent);
97  connect(slider, SIGNAL(valueChanged(int)), this, SLOT(sliderChanged(int)) ); //reconnect it
98 
99  this->setToolTip(QString::number(percent)+"%");
100}
101
Note: See TracBrowser for help on using the repository browser.