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.
22
//#include <qcursor.h>
24
//#include <QMouseEvent>
27
//#include <klocale.h>
28
//#include <kconfig.h>
29
//#include <kaction.h>
31
//#include <kglobalaccel.h>
33
//#include <ktoggleaction.h>
34
//#include <kactioncollection.h>
36
//#include "mdwswitch.h"
37
//#include "core/mixer.h"
38
//#include "viewbase.h"
39
//#include "verticaltext.h"
42
// * Class that represents a single Switch
43
// * The orientation (horizontal, vertical) can be configured
45
//MDWSwitch::MDWSwitch(MixDevice* md,
46
// bool small, Qt::Orientation orientation,
47
// QWidget* parent, ViewBase* mw) :
48
// MixDeviceWidget(md,small,orientation,parent,mw),
49
// _label(0) , _labelV(0) , _switchLED(0), _layout(0)
51
// // create actions (on _mdwActions, see MixDeviceWidget)
53
// // KStandardAction::showMenubar() is in MixDeviceWidget now
54
// KToggleAction *action = _mdwActions->add<KToggleAction>( "hide" );
55
// action->setText( i18n("&Hide") );
56
// connect(action, SIGNAL(triggered(bool)), SLOT(setDisabled()));
57
// KAction *b = _mdwActions->addAction( "keys" );
58
// b->setText( i18n("C&onfigure Shortcuts...") );
59
// connect(b, SIGNAL(triggered(bool)), SLOT(defineKeys()));
64
// KAction *a = _mdwActions->addAction( "Toggle switch" );
65
// a->setText( i18n( "Toggle Switch" ) );
66
// connect(a, SIGNAL(triggered(bool)), SLOT(toggleSwitch()));
68
// // The accel keys are loaded in KMixerWidget::loadConfig, see kmixtoolbox.cpp
70
// installEventFilter( this ); // filter for popup
73
//MDWSwitch::~MDWSwitch()
78
//void MDWSwitch::createWidgets()
80
// if ( _orientation == Qt::Vertical ) {
81
// _layout = new QVBoxLayout( this );
82
// _layout->setAlignment(Qt::AlignHCenter);
85
// _layout = new QHBoxLayout( this );
86
// _layout->setAlignment(Qt::AlignVCenter);
88
// this->setToolTip( m_mixdevice->readableName() );
91
// _layout->addSpacing( 4 );
92
// // --- LEDS --------------------------
93
// if ( _orientation == Qt::Vertical ) {
94
// if( m_mixdevice->captureVolume().hasSwitch() )
95
// _switchLED = new QCheckBox( Qt::red,
96
// m_mixdevice->isRecSource()?KLed::On:KLed::Off,
97
// KLed::Sunken, KLed::Circular, this, "RecordLED" );
99
// _switchLED = new QCheckBox( Qt::yellow, KLed::On, KLed::Sunken, KLed::Circular, this, "SwitchLED" );
100
// _switchLED->setFixedSize(16,16);
101
// _labelV = new VerticalText( this, m_mixdevice->readableName().toUtf8().data() );
103
// _layout->addWidget( _switchLED );
104
// _layout->addSpacing( 2 );
105
// _layout->addWidget( _labelV );
107
// _switchLED->installEventFilter( this );
108
// _labelV->installEventFilter( this );
112
// if( m_mixdevice->captureVolume().hasSwitch() )
113
// _switchLED = new QCheckBox( Qt::red,
114
// m_mixdevice->isRecSource()?KLed::On:KLed::Off,
115
// KLed::Sunken, KLed::Circular, this, "RecordLED" );
117
// _switchLED = new QCheckBox( Qt::yellow, KLed::On, KLed::Sunken, KLed::Circular, this, "SwitchLED" );
118
// _switchLED->setFixedSize(16,16);
119
// _label = new QLabel(m_mixdevice->readableName(), this );
120
// _label->setObjectName( QLatin1String("SwitchName" ));
122
// _layout->addWidget( _switchLED );
123
// _layout->addSpacing( 1 );
124
// _layout->addWidget( _label );
125
// _switchLED->installEventFilter( this );
126
// _label->installEventFilter( this );
128
// connect( _switchLED, SIGNAL(stateChanged(bool)), this, SLOT(toggleSwitch()) );
129
// _layout->addSpacing( 4 );
132
//void MDWSwitch::update()
134
// if ( _switchLED != 0 ) {
135
// _switchLED->blockSignals( true );
136
// if( m_mixdevice->captureVolume().hasSwitch() )
137
// _switchLED->setState( m_mixdevice->isRecSource() ? KLed::On : KLed::Off );
139
// _switchLED->setState( m_mixdevice->isMuted() ? KLed::Off : KLed::On );
141
// _switchLED->blockSignals( false );
145
//void MDWSwitch::setBackgroundRole(QPalette::ColorRole m)
147
// if ( _label != 0 ){
148
// _label->setBackgroundRole(m);
150
// if ( _labelV != 0 ){
151
// _labelV->setBackgroundRole(m);
153
// _switchLED->setBackgroundRole(m);
154
// MixDeviceWidget::setBackgroundRole(m);
157
//void MDWSwitch::showContextMenu()
162
// KMenu *menu = m_view->getPopup();
164
// QPoint pos = QCursor::pos();
165
// menu->popup( pos );
169
//QSizePolicy MDWSwitch::sizePolicy() const
171
// if ( _orientation == Qt::Vertical ) {
172
// return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::MinimumExpanding );
175
// return QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
180
// This slot is called, when a user has clicked the mute button. Also it is called by any other
181
// associated KAction like the context menu.
183
//void MDWSwitch::toggleSwitch() {
184
// if( m_mixdevice->captureVolume().hasSwitch() )
185
// setSwitch( !m_mixdevice->isRecSource() );
187
// setSwitch( !m_mixdevice->isMuted() );
190
//void MDWSwitch::setSwitch(bool value)
192
// if ( m_mixdevice->playbackVolume().hasSwitch() ) {
193
// if ( m_mixdevice->captureVolume().hasSwitch() ) {
194
// m_mixdevice->mixer()->setRecordSource( m_mixdevice->id(), value );
197
// m_mixdevice->setMuted( value );
198
// m_mixdevice->mixer()->commitVolumeChange( m_mixdevice );
203
//void MDWSwitch::setDisabled()
205
// setDisabled( true );
208
//void MDWSwitch::setDisabled( bool value ) {
209
// if ( m_disabled!=value)
211
// value ? hide() : show();
212
// m_disabled = value;
217
// * An event filter for the various QWidgets. We watch for Mouse press Events, so
218
// * that we can popup the context menu.
220
//bool MDWSwitch::eventFilter( QObject* obj, QEvent* e )
222
// if (e->type() == QEvent::MouseButtonPress) {
223
// QMouseEvent *qme = static_cast<QMouseEvent*>(e);
224
// if (qme->button() == Qt::RightButton) {
225
// showContextMenu();
229
// return QWidget::eventFilter(obj,e);
232
//#include "mdwswitch.moc"