~ubuntu-branches/ubuntu/natty/kdemultimedia/natty-proposed

« back to all changes in this revision

Viewing changes to kmix/mdwslider.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers
  • Date: 2011-05-26 02:41:36 UTC
  • mfrom: (0.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 108.
  • Revision ID: james.westby@ubuntu.com-20110526024136-jjwsigfy402jhupm
Tags: upstream-4.6.3
ImportĀ upstreamĀ versionĀ 4.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * KMix -- KDE's full featured mini mixer
3
 
 *
4
 
 *
5
 
 * Copyright (C) 1996-2007 Christian Esken <esken@kde.org>
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU Library General Public
9
 
 * License as published by the Free Software Foundation; either
10
 
 * version 2 of the License, or (at your option) any later version.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * Library General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU Library General Public
18
 
 * License along with this program; if not, write to the Free
19
 
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
 */
21
 
 
22
 
#include <klocale.h>
23
 
#include <kled.h>
24
 
#include <kiconloader.h>
25
 
#include <kconfig.h>
26
 
#include <kaction.h>
27
 
#include <kmenu.h>
28
 
#include <kglobalaccel.h>
29
 
#include <kdebug.h>
30
 
#include <kactioncollection.h>
31
 
#include <ktoggleaction.h>
32
 
 
33
 
#include <qicon.h>
34
 
#include <qtoolbutton.h>
35
 
#include <QObject>
36
 
#include <qcursor.h>
37
 
#include <QCheckBox>
38
 
#include <QMouseEvent>
39
 
#include <qslider.h>
40
 
#include <QLabel>
41
 
#include <qpixmap.h>
42
 
#include <qwmatrix.h>
43
 
#include <QBoxLayout>
44
 
 
45
 
#include "mdwslider.h"
46
 
#include "mixer.h"
47
 
#include "viewbase.h"
48
 
#include "kledbutton.h"
49
 
#include "ksmallslider.h"
50
 
#include "verticaltext.h"
51
 
 
52
 
static const int MIN_SLIDER_SIZE = 50;
53
 
 
54
 
/**
55
 
 * MixDeviceWidget that represents a single mix device, inlcuding PopUp, muteLED, ...
56
 
 *
57
 
 * Used in KMix main window and DockWidget and PanelApplet.
58
 
 * It can be configured to include or exclude the captureLED and the muteLED.
59
 
 * The direction (horizontal, vertical) can be configured and whether it should
60
 
 * be "small"  (uses KSmallSlider instead of QSlider then).
61
 
 *
62
 
 * Due to the many options, this is the most complicated MixDeviceWidget subclass.
63
 
 */
64
 
MDWSlider::MDWSlider(MixDevice* md,
65
 
                                 bool showMuteLED, bool showCaptureLED,
66
 
                                 bool small, Qt::Orientation orientation,
67
 
                                 QWidget* parent, ViewBase* mw) :
68
 
    MixDeviceWidget(md,small,orientation,parent,mw),
69
 
            m_linked(true), m_defaultLabelSpacer(0), m_iconLabelSimple(0), m_qcb(0), m_muteText(0),
70
 
            m_playbackSpacer(0), _layout(0), m_extraCaptureLabel( 0 ), m_label( 0 ),
71
 
            m_captureLED( 0 ), m_captureText(0), m_captureSpacer(0)
72
 
{
73
 
   // create actions (on _mdwActions, see MixDeviceWidget)
74
 
 
75
 
   KToggleAction *action = _mdwActions->add<KToggleAction>( "stereo" );
76
 
   action->setText( i18n("&Split Channels") );
77
 
   connect(action, SIGNAL(triggered(bool) ), SLOT(toggleStereoLinked()));
78
 
   action = _mdwActions->add<KToggleAction>( "hide" );
79
 
   action->setText( i18n("&Hide") );
80
 
   connect(action, SIGNAL(triggered(bool) ), SLOT(setDisabled()));
81
 
 
82
 
   if( m_mixdevice->playbackVolume().hasSwitch() ) {
83
 
      KToggleAction *a = _mdwActions->add<KToggleAction>( "mute" );
84
 
      a->setText( i18n("&Muted") );
85
 
      connect( a, SIGNAL(toggled(bool)), SLOT(toggleMuted()) );
86
 
   }
87
 
 
88
 
   if( m_mixdevice->captureVolume().hasSwitch() ) {
89
 
      KToggleAction *a = _mdwActions->add<KToggleAction>( "recsrc" );
90
 
      a->setText( i18n("Set &Record Source") );
91
 
      connect( a, SIGNAL(toggled(bool)), SLOT( toggleRecsrc()) );
92
 
   }
93
 
 
94
 
   KAction *c = _mdwActions->addAction( "keys" );
95
 
   c->setText( i18n("C&onfigure Shortcuts...") );
96
 
   connect(c, SIGNAL(triggered(bool) ), SLOT(defineKeys()));
97
 
 
98
 
   // create widgets
99
 
   createWidgets( showMuteLED, showCaptureLED );
100
 
   
101
 
   // The following actions are for the "Configure Shortcuts" dialog
102
 
   /* PLEASE NOTE THAT global shortcuts are saved with the name as set with setName(), instead of their action name.
103
 
      This is a bug according to the thread "Global shortcuts are saved with their text-name and not their action-name - Bug?" on kcd.
104
 
      I work around this by using a text with setText() that is unique, but still readable to the user.
105
 
    */
106
 
   //QString actionSuffix  = QString("%1@%2").arg(mixDevice()->id()).arg(mixDevice()->mixer()->id());
107
 
   QString actionSuffix  = QString(" - %1, %2").arg(mixDevice()->readableName()).arg(mixDevice()->mixer()->readableName());
108
 
   KAction *b;
109
 
 
110
 
   b = _mdwPopupActions->addAction( QString("Increase volume %1").arg( actionSuffix ) );
111
 
   QString increaseVolumeName = i18n( "Increase Volume" );
112
 
   increaseVolumeName += " - " + mixDevice()->readableName() + ", " + mixDevice()->mixer()->readableName();
113
 
   b->setText( increaseVolumeName  );
114
 
#ifdef __GNUC__
115
 
#warning GLOBAL SHORTCUTS ARE NOW ASSIGNED TO ALL CONTROLS, as enableGlobalShortcut(), has not been committed
116
 
#endif
117
 
   b->setGlobalShortcut(dummyShortcut);  // -<- enableGlobalShortcut() is not there => use workaround
118
 
//   b->enableGlobalShortcut();
119
 
   connect(b, SIGNAL(triggered(bool) ), SLOT(increaseVolume()));
120
 
 
121
 
   b = _mdwPopupActions->addAction( QString("Decrease volume %1").arg( actionSuffix ) );
122
 
   QString decreaseVolumeName = i18n( "Decrease Volume" );
123
 
   decreaseVolumeName += " - " + mixDevice()->readableName() + ", " + mixDevice()->mixer()->readableName();
124
 
   b->setText( decreaseVolumeName );
125
 
#ifdef __GNUC__
126
 
#warning GLOBAL SHORTCUTS ARE NOW ASSIGNED TO ALL CONTROLS, as enableGlobalShortcut(), has not been committed
127
 
#endif
128
 
   b->setGlobalShortcut(dummyShortcut);  // -<- enableGlobalShortcut() is not there => use workaround
129
 
//   b->enableGlobalShortcut();
130
 
   connect(b, SIGNAL(triggered(bool) ), SLOT( decreaseVolume() ));
131
 
 
132
 
   b = _mdwPopupActions->addAction( QString("Toggle mute %1").arg( actionSuffix ) );
133
 
   QString muteVolumeName = i18n( "Toggle Mute" );
134
 
   muteVolumeName += " - " + mixDevice()->readableName() + ", " + mixDevice()->mixer()->readableName();
135
 
   b->setText( muteVolumeName );
136
 
#ifdef __GNUC__
137
 
#warning GLOBAL SHORTCUTS ARE NOW ASSIGNED TO ALL CONTROLS, as enableGlobalShortcut(), has not been committed
138
 
#endif
139
 
   b->setGlobalShortcut(dummyShortcut);  // -<- enableGlobalShortcut() is not there => use workaround
140
 
//   b->enableGlobalShortcut();
141
 
 
142
 
   connect(b, SIGNAL(triggered(bool) ), SLOT( toggleMuted() ));
143
 
   if (mw) mw->actionCollection()->addAction( QString("Toggle mute %1").arg( actionSuffix ), b );
144
 
/*
145
 
   b = _mdwActions->addAction( "Set Record Source" );
146
 
   b->setText( i18n( "Set Record Source" ) );
147
 
   connect(b, SIGNAL(triggered(bool) ), SLOT( toggleRecsrc() ));
148
 
*/ 
149
 
   installEventFilter( this ); // filter for popup
150
 
 
151
 
        update();
152
 
}
153
 
 
154
 
 
155
 
QSizePolicy MDWSlider::sizePolicy() const
156
 
{
157
 
    if ( _orientation == Qt::Vertical ) {
158
 
        return QSizePolicy(  QSizePolicy::Fixed, QSizePolicy::MinimumExpanding );
159
 
    }
160
 
    else {
161
 
        return QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
162
 
    }
163
 
}
164
 
 
165
 
/* This method is a helper for users of this class who would like to show multiple MDWSlider, and align the sliders.
166
 
 * It returns the "height" (if Vertical) or width (of Horizontal) of the "playback portion" (e.g. Icon, Label, QCheckBox)
167
 
 */
168
 
int MDWSlider::playbackExtentHint() const
169
 
{
170
 
    int currentExtent = 0;
171
 
    if ( _orientation == Qt::Vertical ) {
172
 
        if ( m_qcb ) currentExtent += m_qcb->height();
173
 
        if ( m_muteText ) currentExtent += m_muteText->height();
174
 
    }
175
 
    else {
176
 
        if ( m_qcb ) currentExtent += m_qcb->width();
177
 
        if ( m_muteText ) currentExtent += m_muteText->width();
178
 
    }
179
 
    return currentExtent;
180
 
}
181
 
 
182
 
void MDWSlider::setPlaybackExtent(int extent) {
183
 
    if ( playbackExtentHint() < extent ) {
184
 
        if ( _orientation == Qt::Vertical )
185
 
             if ( playbackExtentHint() < extent )
186
 
               m_playbackSpacer->setFixedHeight(extent-playbackExtentHint());
187
 
             else
188
 
               m_playbackSpacer->setFixedHeight(0);
189
 
        else
190
 
            if ( playbackExtentHint() < extent )
191
 
               m_playbackSpacer->setFixedWidth(extent-playbackExtentHint());
192
 
             else
193
 
               m_playbackSpacer->setFixedWidth(0);
194
 
    }
195
 
}
196
 
 
197
 
/* This method is a helper for users of this class who would like to show multiple MDWSlider, and align the sliders.
198
 
 * It returns the "height" (if Vertical) or width (of Horizontal) of the "capture portion" (e.g. Label, QCheckBox)
199
 
 */
200
 
int MDWSlider::captureExtentHint() const
201
 
{
202
 
    int currentExtent = 0;
203
 
    if ( _orientation == Qt::Vertical ) {
204
 
        if ( m_captureLED ) currentExtent += m_captureLED->height();
205
 
        if ( m_captureText ) currentExtent += m_captureText->height();
206
 
    }
207
 
    else {
208
 
        if ( m_captureLED ) currentExtent += m_captureLED->width();
209
 
        if ( m_captureText ) currentExtent += m_captureText->width();
210
 
    }
211
 
    return currentExtent;
212
 
}
213
 
 
214
 
void MDWSlider::setCaptureExtent(int extent) {
215
 
 
216
 
    if ( _orientation == Qt::Vertical ) {
217
 
        m_defaultLabelSpacer->setFixedHeight(extent);
218
 
        if ( captureExtentHint() < extent )
219
 
            m_captureSpacer->setFixedHeight(extent-captureExtentHint());
220
 
        else
221
 
            m_captureSpacer->setFixedHeight(0);
222
 
    }
223
 
    else {
224
 
        m_defaultLabelSpacer->setFixedWidth(extent);
225
 
        if ( captureExtentHint() < extent )
226
 
            m_captureSpacer->setFixedWidth(extent-captureExtentHint());
227
 
        else
228
 
            m_captureSpacer->setFixedWidth(0);
229
 
    }
230
 
}
231
 
 
232
 
 
233
 
void MDWSlider::addDefaultLabel(QBoxLayout *layout, Qt::Orientation orientation)
234
 
{
235
 
    QBoxLayout *labelLayout;
236
 
    if ( orientation == Qt::Vertical ) {
237
 
        labelLayout = new QVBoxLayout( );
238
 
        labelLayout->setAlignment(Qt::AlignHCenter|Qt::AlignBottom);
239
 
        m_label = new VerticalText( this, m_mixdevice->readableName() ); // .toUtf8().data()
240
 
    }
241
 
    else {
242
 
        labelLayout = new QHBoxLayout();
243
 
        labelLayout->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);
244
 
        m_label = new QLabel(this);
245
 
        static_cast<QLabel*>(m_label) ->setText(m_mixdevice->readableName());
246
 
    }
247
 
    //m_label->setToolTip( m_mixdevice->readableName() );  // @todo: Whatsthis, explaining the device
248
 
    m_label->installEventFilter( this );
249
 
    labelLayout->addWidget( m_label );
250
 
    layout->addItem( labelLayout );
251
 
    
252
 
    m_defaultLabelSpacer = new QWidget(this);
253
 
    labelLayout->addWidget( m_defaultLabelSpacer );
254
 
    m_defaultLabelSpacer->installEventFilter(this);
255
 
}
256
 
 
257
 
 
258
 
/**
259
 
 * Creates all widgets - Icon/Mute-Button, Slider(s) and capture-Button.
260
 
 *
261
 
 * Those widgets are placed into
262
 
 */
263
 
void MDWSlider::createWidgets( bool showMuteLED, bool showCaptureLED )
264
 
{
265
 
    // Base layout with two items: Left the Label, and Right the Sliders
266
 
   if ( _orientation == Qt::Vertical ) {
267
 
       _layout = new QHBoxLayout( this );
268
 
   }
269
 
   else {
270
 
       _layout = new QVBoxLayout( this );
271
 
   }
272
 
   _layout->setAlignment(Qt::AlignLeft|Qt::AlignTop);
273
 
   _layout->setSpacing(0);
274
 
   _layout->setMargin(0);
275
 
 
276
 
   bool hasVolumeSliders =  ( m_mixdevice->playbackVolume().count() + m_mixdevice->captureVolume().count() > 0 );
277
 
   
278
 
   // --- LABEL -----------------------------------------------
279
 
    if ( hasVolumeSliders ) {
280
 
        // When we have volume sliders, we put the label left of them (in an own layout). Otherwise see below at "if ( ! hasVolumeSliders )"
281
 
        addDefaultLabel( _layout, _orientation);
282
 
    }
283
 
 
284
 
    // The controlLayout holds three items: TopPart (Icon + MuteCheckBox + Label) ; MiddlePart (Sliders); Lower Part (CaptureCheckBox + Label)
285
 
    QBoxLayout *controlLayout;
286
 
    if ( _orientation == Qt::Vertical ) {
287
 
        controlLayout = new QVBoxLayout();
288
 
        controlLayout->setAlignment(Qt::AlignHCenter|Qt::AlignTop);
289
 
    }
290
 
    else {
291
 
        controlLayout = new QHBoxLayout();
292
 
        controlLayout->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);
293
 
    }
294
 
    _layout->addItem( controlLayout );
295
 
 
296
 
   // --- ICON + Mute Switch  ----------------------------
297
 
    createWidgetsTopPart(controlLayout, showMuteLED);
298
 
 
299
 
    controlLayout->addSpacing( 3 );
300
 
 
301
 
    // --- SLIDERS ---------------------------
302
 
    QBoxLayout *volLayout;
303
 
    if ( _orientation == Qt::Vertical ) {
304
 
        volLayout = new QHBoxLayout( );
305
 
       // we use AlignBottom, so that Switches will be aligned with the bottom of the sliders
306
 
        volLayout->setAlignment(Qt::AlignHCenter|Qt::AlignBottom);
307
 
    }
308
 
    else {
309
 
        volLayout = new QVBoxLayout(  );
310
 
        volLayout->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
311
 
    }
312
 
    controlLayout->addItem( volLayout );
313
 
 
314
 
 
315
 
   // -- SLIDERS, LEDS AND ICON
316
 
   if ( ! hasVolumeSliders ) {
317
 
        // When we don't have volume sliders, we but the label left of them (in an own layout). Otherwise see below
318
 
       addDefaultLabel( volLayout, _orientation );
319
 
   }
320
 
    else {
321
 
        bool bothCaptureANDPlaybackExist = ( m_mixdevice->playbackVolume().count() > 0 && m_mixdevice->captureVolume().count() > 0 );
322
 
        // --- SLIDERS -----------------------------------------------
323
 
        if ( m_mixdevice->playbackVolume().count() > 0 )
324
 
            addSliders( volLayout, 'p', false );
325
 
        if ( m_mixdevice->captureVolume().count() > 0 )
326
 
            addSliders( volLayout, 'c', bothCaptureANDPlaybackExist );
327
 
    }
328
 
   
329
 
    createWidgetsBottomPart(controlLayout, showCaptureLED);
330
 
 
331
 
   layout()->activate(); // Activate it explicitly in KDE3 because of PanelApplet/kicker issues
332
 
}
333
 
 
334
 
 
335
 
/* Creates the top part: Icon, PlaybackSwitch (Switch + Text) */
336
 
void MDWSlider::createWidgetsTopPart(QBoxLayout *layout, bool showMuteLED)
337
 
{
338
 
   QBoxLayout *m_iconLayout;
339
 
   if ( _orientation == Qt::Vertical ) {
340
 
      m_iconLayout = new QVBoxLayout( );
341
 
      m_iconLayout->setAlignment(Qt::AlignHCenter|Qt::AlignTop);
342
 
   }
343
 
   else {
344
 
      m_iconLayout = new QHBoxLayout( );
345
 
      m_iconLayout->setAlignment(Qt::AlignVCenter|Qt::AlignLeft);
346
 
   }
347
 
   layout->addItem(m_iconLayout);
348
 
 
349
 
   m_iconLabelSimple = 0L;
350
 
   if ( showMuteLED ) {
351
 
        //kDebug(67100) << ">>> MixDevice " << m_mixdevice->readableName() << " icon calculation:";
352
 
       setIcon( m_mixdevice->type() );
353
 
       m_iconLayout->addWidget( m_iconLabelSimple );
354
 
       QString muteTip( m_mixdevice->readableName() );
355
 
       m_iconLabelSimple->setToolTip( muteTip );
356
 
       m_iconLayout->addSpacing( 3 );
357
 
       if ( m_mixdevice->playbackVolume().hasSwitch() ) {
358
 
            if ( m_mixdevice->playbackVolume().switchType() == Volume::OnSwitch ) {
359
 
               m_muteText = new QLabel(i18n("On"), this); 
360
 
            }
361
 
            else if ( m_mixdevice->playbackVolume().switchType() == Volume::OffSwitch ) {
362
 
               m_muteText = new QLabel( i18n("Off"), this); 
363
 
            }
364
 
           else {
365
 
               m_muteText = new QLabel(i18n( "Mute"), this);
366
 
            }
367
 
           m_iconLayout->addWidget( m_muteText );
368
 
           m_muteText->installEventFilter(this);
369
 
 
370
 
           m_qcb =  new QCheckBox(this);
371
 
           m_iconLayout->addWidget( m_qcb );
372
 
           m_qcb->installEventFilter(this);
373
 
           connect ( m_qcb, SIGNAL( toggled(bool) ), this, SLOT(toggleMuted() ) );
374
 
           QString muteTip( i18n( "Mute/Unmute %1", m_mixdevice->readableName() ) );
375
 
           m_qcb->setToolTip( muteTip );
376
 
       } // can be muted
377
 
   }
378
 
   m_playbackSpacer = new QWidget(this);
379
 
   m_iconLayout->addWidget( m_playbackSpacer );
380
 
   m_playbackSpacer->installEventFilter(this);
381
 
}
382
 
 
383
 
void MDWSlider::createWidgetsBottomPart(QBoxLayout *layout, bool showCaptureLED)
384
 
{
385
 
       // --- capture SOURCE LED --------------------------
386
 
   if ( showCaptureLED ) {
387
 
      layout->addSpacing( 3 );
388
 
   }
389
 
 
390
 
      QBoxLayout *reclayout;
391
 
      if ( _orientation == Qt::Vertical ) {
392
 
         reclayout = new QVBoxLayout( );
393
 
         reclayout->setAlignment(Qt::AlignHCenter|Qt::AlignBottom);
394
 
      }
395
 
      else {
396
 
         reclayout = new QHBoxLayout( );
397
 
         reclayout->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
398
 
      }
399
 
      layout->addItem( reclayout );
400
 
 
401
 
      m_captureSpacer = new QWidget(this);
402
 
      reclayout->addWidget( m_captureSpacer );
403
 
      m_captureSpacer->installEventFilter(this);
404
 
        
405
 
   if ( showCaptureLED  && m_mixdevice->captureVolume().hasSwitch() )
406
 
   {
407
 
      m_captureLED =  new QCheckBox(this);
408
 
      reclayout->addWidget( m_captureLED );
409
 
      m_captureLED->installEventFilter( this );
410
 
      connect(m_captureLED, SIGNAL(toggled(bool)), this, SLOT(setRecsrc(bool)));
411
 
      QString muteTip( i18n( "Capture/Uncapture %1", m_mixdevice->readableName() ) );
412
 
      m_captureLED->setToolTip( muteTip );  // @todo: Whatsthis, explaining the device
413
 
      
414
 
      m_captureText = new QLabel(i18n("Capture"), this);
415
 
      reclayout->addWidget( m_captureText );
416
 
      m_captureText->installEventFilter(this);
417
 
   } // has capture LED
418
 
}
419
 
   
420
 
void MDWSlider::addSliders( QBoxLayout *volLayout, char type, bool addLabel)
421
 
{
422
 
   Volume* volP;
423
 
   QList<Volume::ChannelID>* ref_slidersChidsP;
424
 
   QList<QWidget *>* ref_slidersP;
425
 
 
426
 
   if ( type == 'c' ) { // capture
427
 
      volP              = & m_mixdevice->captureVolume();
428
 
      ref_slidersChidsP = & _slidersChidsCapture;
429
 
      ref_slidersP      = & m_slidersCapture;
430
 
   }
431
 
   else { // playback
432
 
      volP              = & m_mixdevice->playbackVolume();
433
 
      ref_slidersChidsP = & _slidersChidsPlayback;
434
 
      ref_slidersP      = & m_slidersPlayback;
435
 
   }
436
 
 
437
 
   Volume& vol = *volP;
438
 
   QList<Volume::ChannelID>& ref_slidersChids = *ref_slidersChidsP;
439
 
   QList<QWidget *>& ref_sliders = *ref_slidersP;
440
 
 
441
 
 
442
 
   if (addLabel)
443
 
   {
444
 
        static QString capture = i18n("(capture)");
445
 
        QString sliderDescription = m_mixdevice->readableName();
446
 
        if ( type == 'c' ) { // capture
447
 
            sliderDescription += ' ' + capture;
448
 
        }
449
 
        
450
 
        QWidget *label;
451
 
        if ( _orientation == Qt::Vertical ) {
452
 
            label = new VerticalText( this, sliderDescription );
453
 
        }
454
 
        else {
455
 
            label = new QLabel(this);
456
 
            static_cast<QLabel*>(m_label)->setText(sliderDescription);
457
 
        }
458
 
        volLayout->addWidget( label );
459
 
        label->installEventFilter( this );
460
 
        if ( type == 'c' ) { // capture
461
 
            m_extraCaptureLabel = label;
462
 
        }
463
 
        label->installEventFilter( this );
464
 
   }
465
 
 
466
 
    for ( int i=0; i<= Volume::CHIDMAX; i++ ) {
467
 
     if ( vol._chmask & Volume::_channelMaskEnum[i] ) {
468
 
        Volume::ChannelID chid = Volume::ChannelID(i);
469
 
 
470
 
        long minvol = vol.minVolume();
471
 
        long maxvol = vol.maxVolume();
472
 
 
473
 
        QWidget* slider;
474
 
        if ( m_small ) {
475
 
            slider = new KSmallSlider( minvol, maxvol, (maxvol-minvol)/10, // @todo !! User definable steps
476
 
            vol.getVolume( chid ), _orientation, this );
477
 
        } // small
478
 
        else  {
479
 
            QSlider* sliderBig = new QSlider( _orientation, this );
480
 
            slider = sliderBig;
481
 
            sliderBig->setMinimum(0);
482
 
            sliderBig->setMaximum(maxvol);
483
 
            sliderBig->setPageStep(maxvol/10);
484
 
            sliderBig->setValue(maxvol - vol.getVolume( chid ));
485
 
 
486
 
            if ( _orientation == Qt::Vertical ) {
487
 
                sliderBig->setMinimumHeight( MIN_SLIDER_SIZE );
488
 
            }
489
 
            else {
490
 
                sliderBig->setMinimumWidth( MIN_SLIDER_SIZE );
491
 
            }
492
 
        } // not small
493
 
 
494
 
        slider->installEventFilter( this );
495
 
        if ( type == 'p' ) {
496
 
            slider->setToolTip( m_mixdevice->readableName() );
497
 
        }
498
 
        else {
499
 
            QString captureTip( i18n( "%1 (capture)", m_mixdevice->readableName() ) );
500
 
            slider->setToolTip( captureTip );
501
 
        }
502
 
        
503
 
        if( i>0 && isStereoLinked() ) {
504
 
            // show only one (the first) slider, when the user wants it so
505
 
            slider->hide();
506
 
        }
507
 
        volLayout->addWidget( slider );  // add to layout
508
 
        ref_sliders.append ( slider );   // add to list
509
 
        ref_slidersChids.append(chid);
510
 
        connect( slider, SIGNAL(valueChanged(int)), SLOT(volumeChange(int)) );
511
 
     } //if channel is present
512
 
    } // for all channels of this device
513
 
}
514
 
 
515
 
 
516
 
QPixmap MDWSlider::icon( int icontype )
517
 
{
518
 
   QPixmap miniDevPM;
519
 
 
520
 
   switch (icontype) {
521
 
      case MixDevice::AUDIO:
522
 
         miniDevPM = _iconName = "mixer-pcm"; break;
523
 
      case MixDevice::BASS:
524
 
      case MixDevice::SURROUND_LFE:  // "LFE" SHOULD have an own icon
525
 
          miniDevPM = _iconName ="mixer-lfe"; break;
526
 
      case MixDevice::CD:
527
 
          miniDevPM = _iconName ="mixer-cd"; break;
528
 
      case MixDevice::EXTERNAL:
529
 
         miniDevPM = _iconName = "mixer-line"; break;
530
 
      case MixDevice::MICROPHONE:
531
 
          miniDevPM = _iconName ="mixer-microphone";break;
532
 
      case MixDevice::MIDI:
533
 
          miniDevPM = _iconName ="mixer-midi"; break;
534
 
      case MixDevice::RECMONITOR:
535
 
          miniDevPM = _iconName ="mixer-capture"; break;
536
 
      case MixDevice::TREBLE:
537
 
          miniDevPM = _iconName ="mixer-pcm-default"; break;
538
 
      case MixDevice::UNKNOWN:
539
 
          miniDevPM = _iconName ="mixer-front"; break;
540
 
      case MixDevice::VOLUME:
541
 
          miniDevPM = _iconName ="mixer-master"; break;
542
 
      case MixDevice::VIDEO:
543
 
          miniDevPM = _iconName ="mixer-video"; break;
544
 
      case MixDevice::SURROUND:
545
 
      case MixDevice::SURROUND_BACK:
546
 
          miniDevPM = _iconName = "mixer-surround"; break;
547
 
      case MixDevice::SURROUND_CENTERFRONT:
548
 
      case MixDevice::SURROUND_CENTERBACK:
549
 
          miniDevPM = _iconName ="mixer-surround-center"; break;
550
 
      case MixDevice::HEADPHONE:
551
 
         miniDevPM = _iconName = "mixer-headset"; break;
552
 
      case MixDevice::DIGITAL:
553
 
          miniDevPM = _iconName = "mixer-digital"; break;
554
 
      case MixDevice::AC97:
555
 
          miniDevPM = _iconName = "mixer-ac97"; break;
556
 
      case MixDevice::SPEAKER:
557
 
          miniDevPM = _iconName = "mixer-pc-speaker"; break;
558
 
      case MixDevice::MICROPHONE_BOOST:
559
 
          miniDevPM = _iconName = "mixer-microphone-boost"; break;
560
 
      case MixDevice::MICROPHONE_FRONT_BOOST:
561
 
          miniDevPM = _iconName = "mixer-microphone-front-boost"; break;
562
 
      case MixDevice::MICROPHONE_FRONT:
563
 
          miniDevPM = _iconName = "mixer-microphone-front"; break;
564
 
      default:
565
 
          miniDevPM = _iconName ="mixer-front"; break;
566
 
   }
567
 
 
568
 
   miniDevPM = loadIcon(_iconName);
569
 
   return miniDevPM;
570
 
}
571
 
 
572
 
QPixmap MDWSlider::loadIcon( QString& filename )
573
 
{
574
 
    return  KIconLoader::global()->loadIcon( filename, KIconLoader::Small, KIconLoader::SizeSmallMedium );
575
 
}
576
 
 
577
 
void
578
 
MDWSlider::setIcon( int icontype )
579
 
{
580
 
   if( !m_iconLabelSimple )
581
 
   {
582
 
         m_iconLabelSimple = new QLabel(this);
583
 
         installEventFilter( m_iconLabelSimple );
584
 
   }
585
 
 
586
 
   QPixmap miniDevPM = icon( icontype );
587
 
   if ( !miniDevPM.isNull() )
588
 
   {
589
 
      if ( m_small )
590
 
      {
591
 
         // scale icon
592
 
         QMatrix t;
593
 
         t = t.scale( 10.0/miniDevPM.width(), 10.0/miniDevPM.height() );
594
 
         m_iconLabelSimple->setPixmap( miniDevPM.transformed( t ) );
595
 
         m_iconLabelSimple->resize( 10, 10 );
596
 
      } // small size
597
 
      else
598
 
      {
599
 
            m_iconLabelSimple->setPixmap( miniDevPM );
600
 
            //kDebug(67100) << " > simple > icontype=" <<icontype<< "size=" << miniDevPM.size();
601
 
      } // normal size
602
 
   }
603
 
   else
604
 
   {
605
 
      kError(67100) << "Pixmap missing." << endl;
606
 
   }
607
 
 
608
 
   layout()->activate();
609
 
}
610
 
 
611
 
 
612
 
void
613
 
MDWSlider::toggleStereoLinked()
614
 
{
615
 
   setStereoLinked( !isStereoLinked() );
616
 
}
617
 
 
618
 
void
619
 
MDWSlider::setStereoLinked(bool value)
620
 
{
621
 
   m_linked = value;
622
 
   if (m_slidersPlayback.count() != 0) setStereoLinkedInternal(m_slidersPlayback);
623
 
   if (m_slidersCapture.count() != 0) setStereoLinkedInternal(m_slidersCapture);
624
 
   update(); // Call update(), so that the sliders can adjust EITHER to the individual values OR the average value.
625
 
}
626
 
 
627
 
void
628
 
MDWSlider::setStereoLinkedInternal(QList<QWidget *>& ref_sliders)
629
 
{
630
 
   QWidget *slider = ref_sliders[0];
631
 
 
632
 
   /***********************************************************
633
 
      Remember value of first slider, so that it can be copied
634
 
      to the other sliders.
635
 
    ***********************************************************/
636
 
   int firstSliderValue = 0;
637
 
   bool firstSliderValueValid = false;
638
 
   if (::qobject_cast<QSlider*>(slider)) {
639
 
      QSlider *sld = static_cast<QSlider*>(slider);
640
 
      firstSliderValue = sld->value();
641
 
      firstSliderValueValid = true;
642
 
   }
643
 
   else if ( ::qobject_cast<KSmallSlider*>(slider))  {
644
 
      KSmallSlider *sld = static_cast<KSmallSlider*>(slider);
645
 
      firstSliderValue = sld->value();
646
 
      firstSliderValueValid = true;
647
 
   }
648
 
 
649
 
   for( int i=1; i<ref_sliders.count(); ++i ) {
650
 
      slider = ref_sliders[i];
651
 
      if ( slider == 0 ) {
652
 
         continue;
653
 
      }
654
 
      if ( m_linked ) {
655
 
         slider->hide();
656
 
      }
657
 
      else {
658
 
         slider->show();
659
 
      }
660
 
   }
661
 
 
662
 
   // Redo the tickmarks to last slider in the slider list.
663
 
   // The implementation is not obvious, so lets explain:
664
 
   // We ALWAYS have tickmarks on the LAST slider. Sometimes the slider is not shown, and then we just don't bother.
665
 
   // a) So, if the last slider has tickmarks, we can always call setTicks( true ).
666
 
   // b) if the last slider has NO tickmarks, there ae no tickmarks at all, and we don't need to redo the tickmarks.
667
 
   slider = ref_sliders.last();
668
 
   if( slider && ( static_cast<QSlider *>(slider)->tickPosition() != QSlider::NoTicks) )
669
 
      setTicks( true );
670
 
 
671
 
}
672
 
 
673
 
 
674
 
void
675
 
MDWSlider::setLabeled(bool value)
676
 
{
677
 
    if ( m_label == 0  && m_extraCaptureLabel == 0 )
678
 
      return;
679
 
 
680
 
   if (value ) {
681
 
       if ( m_label != 0) m_label->show();
682
 
       if ( m_extraCaptureLabel != 0) m_extraCaptureLabel->show();
683
 
       if ( m_muteText != 0) m_muteText->show();
684
 
       if ( m_captureText != 0) m_captureText->show();
685
 
   }
686
 
   else {
687
 
       if ( m_label != 0) m_label->hide();
688
 
       if ( m_extraCaptureLabel != 0) m_extraCaptureLabel->hide();
689
 
       if ( m_muteText != 0) m_muteText->hide();
690
 
       if ( m_captureText != 0) m_captureText->hide();
691
 
   }
692
 
   layout()->activate();
693
 
}
694
 
 
695
 
void
696
 
MDWSlider::setTicks( bool value )
697
 
{
698
 
   if (m_slidersPlayback.count() != 0) setTicksInternal(m_slidersPlayback, value);
699
 
   if (m_slidersCapture.count() != 0) setTicksInternal(m_slidersCapture, value);
700
 
}
701
 
 
702
 
void
703
 
MDWSlider::setTicksInternal(QList<QWidget *>& ref_sliders, bool ticks)
704
 
{
705
 
  QWidget* slider = ref_sliders[0];
706
 
 
707
 
   if ( slider->inherits( "QSlider" ) )
708
 
   {
709
 
      if( ticks )
710
 
         if( isStereoLinked() )
711
 
            static_cast<QSlider *>(slider)->setTickPosition( QSlider::TicksRight );
712
 
         else
713
 
         {
714
 
            static_cast<QSlider *>(slider)->setTickPosition( QSlider::NoTicks );
715
 
            slider = ref_sliders.last();
716
 
            static_cast<QSlider *>(slider)->setTickPosition( QSlider::TicksLeft );
717
 
         }
718
 
      else
719
 
      {
720
 
         static_cast<QSlider *>(slider)->setTickPosition( QSlider::NoTicks );
721
 
         slider = ref_sliders.last();
722
 
         static_cast<QSlider *>(slider)->setTickPosition( QSlider::NoTicks );
723
 
      }
724
 
   }
725
 
}
726
 
 
727
 
void
728
 
MDWSlider::setIcons(bool value)
729
 
{
730
 
   if ( m_iconLabelSimple != 0 ) {
731
 
      if ( ( ! m_iconLabelSimple->isHidden()) !=value ) {
732
 
         if (value)
733
 
            m_iconLabelSimple->show();
734
 
         else
735
 
            m_iconLabelSimple->hide();
736
 
 
737
 
         layout()->activate();
738
 
      }
739
 
    } // if it has an icon
740
 
}
741
 
 
742
 
void
743
 
MDWSlider::setColors( QColor high, QColor low, QColor back )
744
 
{
745
 
    for( int i=0; i<m_slidersPlayback.count(); ++i ) {
746
 
        QWidget *slider = m_slidersPlayback[i];
747
 
        KSmallSlider *smallSlider = dynamic_cast<KSmallSlider*>(slider);
748
 
        if ( smallSlider ) smallSlider->setColors( high, low, back );
749
 
    }
750
 
    for( int i=0; i<m_slidersCapture.count(); ++i ) {
751
 
        QWidget *slider = m_slidersCapture[i];
752
 
        KSmallSlider *smallSlider = dynamic_cast<KSmallSlider*>(slider);
753
 
        if ( smallSlider ) smallSlider->setColors( high, low, back );
754
 
    }
755
 
}
756
 
 
757
 
void
758
 
MDWSlider::setMutedColors( QColor high, QColor low, QColor back )
759
 
{
760
 
    for( int i=0; i<m_slidersPlayback.count(); ++i ) {
761
 
        QWidget *slider = m_slidersPlayback[i];
762
 
        KSmallSlider *smallSlider = dynamic_cast<KSmallSlider*>(slider);
763
 
        if ( smallSlider ) smallSlider->setGrayColors( high, low, back );
764
 
    }
765
 
    for( int i=0; i<m_slidersCapture.count(); ++i ) {
766
 
        QWidget *slider = m_slidersCapture[i];
767
 
        KSmallSlider *smallSlider = dynamic_cast<KSmallSlider*>(slider);
768
 
        if ( smallSlider ) smallSlider->setGrayColors( high, low, back );
769
 
    }
770
 
}
771
 
 
772
 
 
773
 
/** This slot is called, when a user has changed the volume via the KMix Slider. */
774
 
void MDWSlider::volumeChange( int )
775
 
{
776
 
   if (m_slidersPlayback.count() > 0) volumeChangeInternal(m_mixdevice->playbackVolume(), _slidersChidsPlayback, m_slidersPlayback);
777
 
   if (m_slidersCapture.count()  > 0) volumeChangeInternal(m_mixdevice->captureVolume() , _slidersChidsCapture, m_slidersCapture);
778
 
   m_mixdevice->mixer()->commitVolumeChange(m_mixdevice);
779
 
}
780
 
 
781
 
void MDWSlider::volumeChangeInternal( Volume& vol, QList<Volume::ChannelID>& ref_slidersChids, QList<QWidget *>& ref_sliders  )
782
 
{
783
 
 
784
 
   // --- Step 2: Change the volumes directly in the Volume object to reflect the Sliders ---
785
 
   if ( isStereoLinked() )
786
 
   {
787
 
      long firstVolume = 0;
788
 
      if ( ref_sliders.first()->inherits( "KSmallSlider" ) )
789
 
      {
790
 
         KSmallSlider *slider = dynamic_cast<KSmallSlider *>(ref_sliders.first());
791
 
         if (slider != 0 ) firstVolume = slider->value();
792
 
      }
793
 
      else
794
 
      {
795
 
         QSlider *slider = dynamic_cast<QSlider *>(ref_sliders.first());
796
 
         if (slider != 0 ) firstVolume = slider->value();
797
 
      }
798
 
      vol.setAllVolumes(firstVolume);
799
 
    } // stereoLinked()
800
 
 
801
 
    else {
802
 
        QList<Volume::ChannelID>::Iterator it = ref_slidersChids.begin();
803
 
        for( int i=0; i<ref_sliders.count(); i++, ++it ) {
804
 
            Volume::ChannelID chid = *it;
805
 
            QWidget *sliderWidget = ref_sliders[i];
806
 
 
807
 
            if ( sliderWidget->inherits( "KSmallSlider" ) )
808
 
            {
809
 
                KSmallSlider *slider = dynamic_cast<KSmallSlider *>(sliderWidget);
810
 
                if (slider) vol.setVolume( chid, slider->value() );
811
 
            }
812
 
            else
813
 
            {
814
 
                QSlider *slider = dynamic_cast<QSlider *>(sliderWidget);
815
 
                if (slider) vol.setVolume( chid, slider->value() );
816
 
            }
817
 
      } // iterate over all sliders
818
 
   } // !stereoLinked()
819
 
 
820
 
   // --- Step 3: Write back the new volumes to the HW ---
821
 
}
822
 
 
823
 
 
824
 
/**
825
 
   This slot is called, when a user has clicked the recsrc button. Also it is called by any other
826
 
    associated KAction like the context menu.
827
 
*/
828
 
void MDWSlider::toggleRecsrc() {
829
 
   setRecsrc( m_mixdevice->isRecSource() );
830
 
}
831
 
 
832
 
void MDWSlider::setRecsrc(bool value )
833
 
{
834
 
   if (  m_mixdevice->captureVolume().hasSwitch() ) {
835
 
      m_mixdevice->setRecSource( value );
836
 
      m_mixdevice->mixer()->commitVolumeChange( m_mixdevice );
837
 
   }
838
 
}
839
 
 
840
 
 
841
 
/**
842
 
   This slot is called, when a user has clicked the mute button. Also it is called by any other
843
 
    associated KAction like the context menu.
844
 
*/
845
 
void MDWSlider::toggleMuted() {
846
 
    setMuted( ! m_mixdevice->isMuted() );
847
 
}
848
 
 
849
 
void MDWSlider::setMuted(bool value)
850
 
{
851
 
     if (  m_mixdevice->playbackVolume().hasSwitch() ) {
852
 
      m_mixdevice->setMuted( value );
853
 
      m_mixdevice->mixer()->commitVolumeChange(m_mixdevice);
854
 
    }
855
 
}
856
 
 
857
 
 
858
 
void MDWSlider::setDisabled()
859
 
{
860
 
    setDisabled( true );
861
 
}
862
 
 
863
 
void MDWSlider::setDisabled( bool value )
864
 
{
865
 
    if ( m_disabled!=value)
866
 
    {
867
 
        value ? hide() : show();
868
 
        m_disabled = value;
869
 
         m_view->configurationUpdate();
870
 
    }
871
 
}
872
 
 
873
 
 
874
 
/**
875
 
   This slot is called on a MouseWheel event. Also it is called by any other
876
 
    associated KAction like the context menu.
877
 
*/
878
 
void MDWSlider::increaseVolume()
879
 
{
880
 
   Volume& volP = m_mixdevice->playbackVolume();
881
 
    long inc = volP.maxVolume() / 20;
882
 
    if ( inc == 0 )
883
 
        inc = 1;
884
 
    for ( int i = 0; i < volP.count(); i++ ) {
885
 
        long newVal = (volP[i]) + inc;
886
 
        volP.setVolume( (Volume::ChannelID)i, newVal < volP.maxVolume() ? newVal : volP.maxVolume() );
887
 
    }
888
 
 
889
 
    Volume& volC = m_mixdevice->captureVolume();
890
 
    inc = volC.maxVolume() / 20;
891
 
    if ( inc == 0 )
892
 
        inc = 1;
893
 
    for ( int i = 0; i < volC.count(); i++ ) {
894
 
        long newVal = (volC[i]) + inc;
895
 
        volC.setVolume( (Volume::ChannelID)i, newVal < volC.maxVolume() ? newVal : volC.maxVolume() );
896
 
    }
897
 
    m_mixdevice->mixer()->commitVolumeChange(m_mixdevice);
898
 
}
899
 
 
900
 
/**
901
 
   This slot is called on a MouseWheel event. Also it is called by any other
902
 
    associated KAction like the context menu.
903
 
*/
904
 
void MDWSlider::decreaseVolume()
905
 
{
906
 
    Volume& volP = m_mixdevice->playbackVolume();
907
 
    long inc = volP.maxVolume() / 20;
908
 
    if ( inc == 0 )
909
 
        inc = 1;
910
 
    for ( int i = 0; i < volP.count(); i++ ) {
911
 
        long newVal = (volP[i]) - inc;
912
 
        volP.setVolume( (Volume::ChannelID)i, newVal > 0 ? newVal : 0 );
913
 
    }
914
 
 
915
 
    Volume& volC = m_mixdevice->captureVolume();
916
 
     inc = volC.maxVolume() / 20;
917
 
    if ( inc == 0 )
918
 
        inc = 1;
919
 
    for ( int i = 0; i < volC.count(); i++ ) {
920
 
        long newVal = (volC[i]) - inc;
921
 
        volC.setVolume( (Volume::ChannelID)i, newVal > 0 ? newVal : 0 );
922
 
    }
923
 
    m_mixdevice->mixer()->commitVolumeChange(m_mixdevice);
924
 
}
925
 
 
926
 
 
927
 
/**
928
 
   This is called whenever there are volume updates pending from the hardware for this MDW.
929
 
   At the moment it is called regulary via a QTimer (implicitely).
930
 
*/
931
 
void MDWSlider::update()
932
 
{
933
 
   if (m_slidersPlayback.count() != 0 || m_mixdevice->playbackVolume().hasSwitch())
934
 
      updateInternal(m_mixdevice->playbackVolume(), m_slidersPlayback, _slidersChidsPlayback);
935
 
   if (m_slidersCapture.count()  != 0 || m_mixdevice->captureVolume().hasSwitch())
936
 
      updateInternal(m_mixdevice->captureVolume(), m_slidersCapture , _slidersChidsCapture );
937
 
}
938
 
 
939
 
void MDWSlider::updateInternal(Volume& vol, QList<QWidget *>& ref_sliders, QList<Volume::ChannelID>& ref_slidersChids)
940
 
{
941
 
   // update volumes
942
 
   long useVolume = vol.getAvgVolume( Volume::MMAIN );
943
 
 
944
 
 
945
 
   QList<Volume::ChannelID>::Iterator it = ref_slidersChids.begin();
946
 
   for( int i=0; i<ref_sliders.count(); i++, ++it ) {
947
 
      if( ! isStereoLinked() ) {
948
 
         Volume::ChannelID chid = *it;
949
 
         useVolume = vol[chid];
950
 
      }
951
 
      QWidget *slider = ref_sliders.at( i );
952
 
 
953
 
      slider->blockSignals( true );
954
 
 
955
 
      if ( slider->inherits( "KSmallSlider" ) )
956
 
      {
957
 
         KSmallSlider *smallSlider = dynamic_cast<KSmallSlider *>(slider);
958
 
         if (smallSlider) {
959
 
            smallSlider->setValue( useVolume );
960
 
            smallSlider->setGray( m_mixdevice->isMuted() );
961
 
         }
962
 
      }
963
 
      else
964
 
      {
965
 
         QSlider *bigSlider = dynamic_cast<QSlider *>(slider);
966
 
         if (bigSlider)
967
 
               bigSlider->setValue( useVolume );
968
 
      }
969
 
 
970
 
      slider->blockSignals( false );
971
 
   } // for all sliders
972
 
 
973
 
 
974
 
   // update mute
975
 
 
976
 
   if( m_qcb != 0 ) {
977
 
/*
978
 
      m_iconLabelSimple->blockSignals( true );
979
 
      m_iconLabelSimple->setChecked( !m_mixdevice->isMuted() );
980
 
      m_iconLabelSimple->blockSignals( false );
981
 
*/
982
 
      m_qcb->blockSignals( true );
983
 
      m_qcb->setChecked( m_mixdevice->isMuted() );
984
 
      m_qcb->blockSignals( false );
985
 
   }
986
 
 
987
 
   // update recsrc
988
 
   if( m_captureLED ) {
989
 
      m_captureLED->blockSignals( true );
990
 
      m_captureLED->setChecked( m_mixdevice->isRecSource() );
991
 
 //     bool stateToShow = m_mixdevice->isRecSource();
992
 
//      m_captureLED->setState( stateToShow ? KLed::On : KLed::Off );
993
 
      m_captureLED->blockSignals( false );
994
 
   }
995
 
}
996
 
 
997
 
void MDWSlider::showContextMenu()
998
 
{
999
 
   if( m_view == 0 )
1000
 
      return;
1001
 
   
1002
 
   KMenu *menu = m_view->getPopup();
1003
 
   menu->addTitle( SmallIcon( "kmix" ), m_mixdevice->readableName() );
1004
 
   
1005
 
   if ( m_slidersPlayback.count()>1 || m_slidersCapture.count()>1) {
1006
 
      KToggleAction *stereo = (KToggleAction *)_mdwActions->action( "stereo" );
1007
 
      if ( stereo ) {
1008
 
         stereo->setChecked( !isStereoLinked() );
1009
 
         menu->addAction( stereo );
1010
 
      }
1011
 
   }
1012
 
   
1013
 
   if ( m_mixdevice->captureVolume().hasSwitch() ) {
1014
 
      KToggleAction *ta = (KToggleAction *)_mdwActions->action( "recsrc" );
1015
 
      if ( ta ) {
1016
 
         ta->setChecked( m_mixdevice->isRecSource() );
1017
 
         menu->addAction( ta );
1018
 
      }
1019
 
   }
1020
 
   
1021
 
   if ( m_mixdevice->playbackVolume().hasSwitch() ) {
1022
 
      KToggleAction *ta = ( KToggleAction* )_mdwActions->action( "mute" );
1023
 
      if ( ta ) {
1024
 
         ta->setChecked( m_mixdevice->isMuted() );
1025
 
         menu->addAction( ta );
1026
 
      }
1027
 
   }
1028
 
 
1029
 
   QAction *a = _mdwActions->action(  "hide" );
1030
 
   if ( a )
1031
 
      menu->addAction( a );
1032
 
   
1033
 
   QAction *b = _mdwActions->action( "keys" );
1034
 
   if ( b ) {
1035
 
//       QAction sep( _mdwPopupActions );
1036
 
//       sep.setSeparator( true );
1037
 
//       menu->addAction( &sep );
1038
 
      menu->addAction( b );
1039
 
   }
1040
 
   
1041
 
   QPoint pos = QCursor::pos();
1042
 
   menu->popup( pos );
1043
 
}
1044
 
 
1045
 
 
1046
 
/**
1047
 
 * An event filter for the various QWidgets. We watch for Mouse press Events, so
1048
 
 * that we can popup the context menu.
1049
 
 */
1050
 
bool MDWSlider::eventFilter( QObject* obj, QEvent* e )
1051
 
{
1052
 
    if (e->type() == QEvent::MouseButtonPress) {
1053
 
        QMouseEvent *qme = static_cast<QMouseEvent*>(e);
1054
 
        if (qme->button() == Qt::RightButton) {
1055
 
            showContextMenu();
1056
 
            return true;
1057
 
        }
1058
 
    }
1059
 
    // Attention: We don't filter WheelEvents for KSmallSlider, because it handles WheelEvents itself
1060
 
    else if ( (e->type() == QEvent::Wheel) 
1061
 
            && strcmp(obj->metaObject()->className(),"KSmallSlider") != 0)  {
1062
 
        QWheelEvent *qwe = static_cast<QWheelEvent*>(e);
1063
 
        if (qwe->delta() > 0) {
1064
 
            increaseVolume();
1065
 
        }
1066
 
        else {
1067
 
            decreaseVolume();
1068
 
        }
1069
 
        return true;
1070
 
    }
1071
 
    return QWidget::eventFilter(obj,e);
1072
 
}
1073
 
 
1074
 
#include "mdwslider.moc"