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

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

Add a new utility: pc-mixer
This utility is a tray application that is a front-end to the "mixer" CLI tool, granting control over volumes and other audio settings.
The tray portion of it is complete, still need to finish filling out the full mixer GUI tomorrow.

  • Property mode set to 100644
File size: 2.0 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        bool starting, isMuted;
37
38        void changeVol(int); //Set volume to value (0-100), -1 = mute but save volume
39
40private slots:
41        void loadVol(); //Sync with backend mixer (or if default device changed)
42
43        //Click slots
44        void trayActivated(){
45          actionMenu->popup( QCursor::pos() );
46        }
47
48        //Menu Options
49        void openMixerGUI(){
50          GUI->updateGUI();
51          GUI->show();
52          GUI->raise();
53        }
54       
55        void closeTray(){
56          QCoreApplication::exit(0);
57        }
58
59        void muteClicked(){
60          if(isMuted && CVOL ==0){
61            changeVol(50); //Go to half value
62          }else{
63            changeVol(-1); //Mute or return to original value
64          }
65        }
66       
67        void sliderChanged(int value){
68          changeVol(value);
69        }
70
71        //Simple fix for single-instance issues where the DE also tries to start it up
72        //  (double-tap on login)
73        void doneStarting(){
74          starting = false;
75        }
76
77        void slotSingleInstance(){
78          this->show();
79          if(!starting){ openMixerGUI(); }
80        }
81protected:
82        //look for wheel events here
83        bool event(QEvent *event){
84          if(event->type() == QEvent::Wheel){
85            QWheelEvent *whEvent = static_cast<QWheelEvent*>(event);
86            int change = whEvent->delta()/40; // 3% volume change per 1/15th of a rotation (delta*3/120)
87            change = CVOL+change;
88            if(change > 100){ change = 100; }
89            if(change < 0){ change = 0; }
90            if(change != CVOL){
91              changeVol(change);
92            }
93            return true;
94          }else{
95            return false;
96          }
97        }
98
99};
100
101#endif
Note: See TracBrowser for help on using the repository browser.