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.
25 #include "core/mixer.h"
30 #include <kactioncollection.h>
32 #include <kcombobox.h>
34 #include <kglobalaccel.h>
37 #include <ktoggleaction.h>
42 #include <QtGui/qevent.h>
47 * Class that represents an Enum element (a select one-from-many selector)
48 * The orientation (horizontal, vertical) is ignored
50 MDWEnum::MDWEnum( std::shared_ptr<MixDevice> md,
51 Qt::Orientation orientation,
52 QWidget* parent, ViewBase* view, ProfControl* par_pctl) :
53 MixDeviceWidget(md, false, orientation, parent, view, par_pctl),
54 _label(0), _enumCombo(0), _layout(0)
56 // create actions (on _mdwActions, see MixDeviceWidget)
58 // KStandardAction::showMenubar() is in MixDeviceWidget now
59 KToggleAction *action = _mdwActions->add<KToggleAction>( "hide" );
60 action->setText( i18n("&Hide") );
61 connect(action, SIGNAL(triggered(bool)), SLOT(setDisabled(bool)));
62 QAction *c = _mdwActions->addAction( "keys" );
63 c->setText( i18n("C&onfigure Shortcuts...") );
64 connect(c, SIGNAL(triggered(bool)), SLOT(defineKeys()));
69 /* remove this for production version
70 QAction *a = _mdwActions->addAction( "Next Value" );
71 c->setText( i18n( "Next Value" ) );
72 connect(a, SIGNAL(triggered(bool)), SLOT(nextEnumId()));
75 installEventFilter( this ); // filter for popup
83 void MDWEnum::createWidgets()
85 if ( _orientation == Qt::Vertical ) {
86 _layout = new QVBoxLayout( this );
87 _layout->setAlignment(Qt::AlignLeft);
90 _layout = new QHBoxLayout( this );
91 _layout->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
94 _label = new QLabel( m_mixdevice->readableName(), this);
95 _layout->addWidget(_label);
96 _enumCombo = new KComboBox( false, this);
97 _enumCombo->installEventFilter(this);
98 // ------------ fill ComboBox start ------------
99 int maxEnumId= m_mixdevice->enumValues().count();
100 for (int i=0; i<maxEnumId; i++ ) {
101 _enumCombo->addItem( m_mixdevice->enumValues().at(i));
103 // ------------ fill ComboBox end --------------
104 _layout->addWidget(_enumCombo);
105 connect( _enumCombo, SIGNAL(activated(int)), this, SLOT(setEnumId(int)) );
106 _enumCombo->setToolTip( m_mixdevice->readableName() );
107 _layout->addStretch(1);
110 void MDWEnum::update()
112 if ( m_mixdevice->isEnum() ) {
113 //kDebug(67100) << "MDWEnum::update() enumID=" << m_mixdevice->enumId();
114 _enumCombo->setCurrentIndex( m_mixdevice->enumId() );
117 kError(67100) << "MDWEnum::update() enumID=" << m_mixdevice->enumId() << " is no Enum ... skipped";
121 void MDWEnum::showContextMenu(const QPoint& pos )
126 KMenu *menu = m_view->getPopup();
132 QSizePolicy MDWEnum::sizePolicy() const
134 return QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
138 This slot is called, when a user has clicked the mute button. Also it is called by any other
139 associated KAction like the context menu.
141 void MDWEnum::nextEnumId() {
142 if( m_mixdevice->isEnum() ) {
143 int curEnum = enumId();
144 if ( curEnum < m_mixdevice->enumValues().count() ) {
146 setEnumId(curEnum+1);
155 void MDWEnum::setEnumId(int value)
157 if ( m_mixdevice->isEnum() ) {
158 m_mixdevice->setEnumId( value );
159 m_mixdevice->mixer()->commitVolumeChange( m_mixdevice );
163 int MDWEnum::enumId()
165 if ( m_mixdevice->isEnum() ) {
166 return m_mixdevice->enumId();
174 void MDWEnum::setDisabled( bool hide )
176 emit guiVisibilityChange(this, !hide);
180 * An event filter for the various QWidgets. We watch for Mouse press Events, so
181 * that we can popup the context menu.
183 bool MDWEnum::eventFilter( QObject* obj, QEvent* e )
185 if (e->type() == QEvent::MouseButtonPress) {
186 QMouseEvent *qme = static_cast<QMouseEvent*>(e);
187 if (qme->button() == Qt::RightButton) {
191 } else if (e->type() == QEvent::ContextMenu) {
192 QPoint pos = reinterpret_cast<QWidget *>(obj)->mapToGlobal(QPoint(0, 0));
193 showContextMenu(pos);
196 return QWidget::eventFilter(obj,e);
199 #include "moc_mdwenum.cpp"