source: src-qt4/pc-mixer/MixerTray.h @ 89ae974

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

Make the tray portion of pc-mixer also "L/R channel" aware. It reports whichever value is higher on the tray slider, but keeps the difference between the two channels the same when modified.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#ifndef _PC_MIXER_TRAY_H
2#define _PC_MIXER_TRAY_H
3
4#include <QSystemTrayIcon>
5#include <QMenu>
6#include <QSlider>
7#include <QToolButton>
8#include <QWidgetAction>
9#include <QSettings>
10#include <QString>
11#include <QCoreApplication>
12#include <QCursor>
13#include <QEvent>
14#include <QWheelEvent>
15#include <QTimer>
16#include <QDebug>
17
18#include "MixerBackend.h" //for CLI mixer integration
19#include "MixerGUI.h"
20
21class MixerTray : public QSystemTrayIcon{
22        Q_OBJECT
23public:
24        MixerTray();
25        ~MixerTray();
26
27private:
28        QMenu *actionMenu;
29        QSlider *slider;
30        QToolButton *mute, *mixer;
31        QWidgetAction *slideA, *muteA, *mixerA;
32        QSettings *settings;
33        QTimer *timer;
34        MixerGUI *GUI;
35        int CVOL; //current volume
36        int CDIFF; //difference between L/R channels
37        bool starting, isMuted;
38
39        void changeVol(int percent, bool modify = true); //Set volume to value (0-100), -1 = mute but save volume
40
41private slots:
42        void loadVol(); //Sync with backend mixer (or if default device changed)
43
44        //Click slots
45        void trayActivated(){
46          actionMenu->popup( QCursor::pos() );
47        }
48
49        //Menu Options
50        void openMixerGUI(){
51          GUI->updateGUI();
52          GUI->show();
53          GUI->raise();
54        }
55       
56        void closeTray(){
57          QCoreApplication::exit(0);
58        }
59
60        void muteClicked(){
61          if(isMuted && CVOL ==0){
62            changeVol(50); //Go to half value
63          }else{
64            changeVol(-1); //Mute or return to original value
65          }
66        }
67       
68        void sliderChanged(int value){
69          changeVol(value);
70        }
71
72        //Simple fix for single-instance issues where the DE also tries to start it up
73        //  (double-tap on login)
74        void doneStarting(){
75          starting = false;
76        }
77
78        void slotSingleInstance(){
79          this->show();
80          if(!starting){ openMixerGUI(); }
81        }
82protected:
83        //look for wheel events here
84        bool event(QEvent *event){
85          if(event->type() == QEvent::Wheel){
86            QWheelEvent *whEvent = static_cast<QWheelEvent*>(event);
87            int change = whEvent->delta()/40; // 3% volume change per 1/15th of a rotation (delta*3/120)
88            change = CVOL+change;
89            if(change > 100){ change = 100; }
90            if(change < 0){ change = 0; }
91            if(change != CVOL){
92              changeVol(change);
93            }
94            return true;
95          }else{
96            return false;
97          }
98        }
99
100};
101
102#endif
Note: See TracBrowser for help on using the repository browser.