2
* KMix -- KDE's full featured mini mixer
5
* Copyright (C) 2004 Christian Esken <esken@kde.org>
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.
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.
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.
24
#include <QMouseEvent>
32
#include <kglobalaccel.h>
34
#include <ktoggleaction.h>
35
#include <kactioncollection.h>
37
#include "kledbutton.h"
38
#include "mdwswitch.h"
41
#include "verticaltext.h"
44
* Class that represents a single Switch
45
* The orientation (horizontal, vertical) can be configured and whether it should
46
* be "small" (uses KSmallSlider instead of QSlider then).
48
MDWSwitch::MDWSwitch(MixDevice* md,
49
bool small, Qt::Orientation orientation,
50
QWidget* parent, ViewBase* mw) :
51
MixDeviceWidget(md,small,orientation,parent,mw),
52
_label(0) , _labelV(0) , _switchLED(0), _layout(0)
54
// create actions (on _mdwActions, see MixDeviceWidget)
56
// KStandardAction::showMenubar() is in MixDeviceWidget now
57
KToggleAction *action = _mdwActions->add<KToggleAction>( "hide" );
58
action->setText( i18n("&Hide") );
59
connect(action, SIGNAL(triggered(bool) ), SLOT(setDisabled()));
60
KAction *b = _mdwActions->addAction( "keys" );
61
b->setText( i18n("C&onfigure Shortcuts...") );
62
connect(b, SIGNAL(triggered(bool) ), SLOT(defineKeys()));
67
KAction *a = _mdwActions->addAction( "Toggle switch" );
68
a->setText( i18n( "Toggle Switch" ) );
69
connect(a, SIGNAL(triggered(bool) ), SLOT( toggleSwitch() ));
71
// The accel keys are loaded in KMixerWidget::loadConfig, see kmixtoolbox.cpp
73
installEventFilter( this ); // filter for popup
76
MDWSwitch::~MDWSwitch()
81
void MDWSwitch::createWidgets()
83
if ( _orientation == Qt::Vertical ) {
84
_layout = new QVBoxLayout( this );
85
_layout->setAlignment(Qt::AlignHCenter);
88
_layout = new QHBoxLayout( this );
89
_layout->setAlignment(Qt::AlignVCenter);
91
this->setToolTip( m_mixdevice->readableName() );
94
_layout->addSpacing( 4 );
95
// --- LEDS --------------------------
96
if ( _orientation == Qt::Vertical ) {
97
if( m_mixdevice->captureVolume().hasSwitch() )
98
_switchLED = new KLedButton( Qt::red,
99
m_mixdevice->isRecSource()?KLed::On:KLed::Off,
100
KLed::Sunken, KLed::Circular, this, "RecordLED" );
102
_switchLED = new KLedButton( Qt::yellow, KLed::On, KLed::Sunken, KLed::Circular, this, "SwitchLED" );
103
_switchLED->setFixedSize(16,16);
104
_labelV = new VerticalText( this, m_mixdevice->readableName().toUtf8().data() );
106
_layout->addWidget( _switchLED );
107
_layout->addSpacing( 2 );
108
_layout->addWidget( _labelV );
110
_switchLED->installEventFilter( this );
111
_labelV->installEventFilter( this );
115
if( m_mixdevice->captureVolume().hasSwitch() )
116
_switchLED = new KLedButton( Qt::red,
117
m_mixdevice->isRecSource()?KLed::On:KLed::Off,
118
KLed::Sunken, KLed::Circular, this, "RecordLED" );
120
_switchLED = new KLedButton( Qt::yellow, KLed::On, KLed::Sunken, KLed::Circular, this, "SwitchLED" );
121
_switchLED->setFixedSize(16,16);
122
_label = new QLabel(m_mixdevice->readableName(), this );
123
_label->setObjectName("SwitchName");
125
_layout->addWidget( _switchLED );
126
_layout->addSpacing( 1 );
127
_layout->addWidget( _label );
128
_switchLED->installEventFilter( this );
129
_label->installEventFilter( this );
131
connect( _switchLED, SIGNAL(stateChanged(bool)), this, SLOT(toggleSwitch()) );
132
_layout->addSpacing( 4 );
135
void MDWSwitch::update()
137
if ( _switchLED != 0 ) {
138
_switchLED->blockSignals( true );
139
if( m_mixdevice->captureVolume().hasSwitch() )
140
_switchLED->setState( m_mixdevice->isRecSource() ? KLed::On : KLed::Off );
142
_switchLED->setState( m_mixdevice->isMuted() ? KLed::Off : KLed::On );
144
_switchLED->blockSignals( false );
148
void MDWSwitch::setBackgroundRole(QPalette::ColorRole m)
151
_label->setBackgroundRole(m);
154
_labelV->setBackgroundRole(m);
156
_switchLED->setBackgroundRole(m);
157
MixDeviceWidget::setBackgroundRole(m);
160
void MDWSwitch::showContextMenu()
165
KMenu *menu = m_view->getPopup();
167
QPoint pos = QCursor::pos();
172
QSizePolicy MDWSwitch::sizePolicy() const
174
if ( _orientation == Qt::Vertical ) {
175
return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::MinimumExpanding );
178
return QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
183
This slot is called, when a user has clicked the mute button. Also it is called by any other
184
associated KAction like the context menu.
186
void MDWSwitch::toggleSwitch() {
187
if( m_mixdevice->captureVolume().hasSwitch() )
188
setSwitch( !m_mixdevice->isRecSource() );
190
setSwitch( !m_mixdevice->isMuted() );
193
void MDWSwitch::setSwitch(bool value)
195
if ( m_mixdevice->playbackVolume().hasSwitch() ) {
196
if ( m_mixdevice->captureVolume().hasSwitch() ) {
197
m_mixdevice->mixer()->setRecordSource( m_mixdevice->id(), value );
200
m_mixdevice->setMuted( value );
201
m_mixdevice->mixer()->commitVolumeChange( m_mixdevice );
206
void MDWSwitch::setDisabled()
211
void MDWSwitch::setDisabled( bool value ) {
212
if ( m_disabled!=value)
214
value ? hide() : show();
220
* An event filter for the various QWidgets. We watch for Mouse press Events, so
221
* that we can popup the context menu.
223
bool MDWSwitch::eventFilter( QObject* obj, QEvent* e )
225
if (e->type() == QEvent::MouseButtonPress) {
226
QMouseEvent *qme = static_cast<QMouseEvent*>(e);
227
if (qme->button() == Qt::RightButton) {
232
return QWidget::eventFilter(obj,e);
235
#include "mdwswitch.moc"