diff --git a/gui/mdwenum.cpp b/gui/mdwenum.cpp index d59b151c..190fe3f1 100644 --- a/gui/mdwenum.cpp +++ b/gui/mdwenum.cpp @@ -1,196 +1,162 @@ /* * KMix -- KDE's full featured mini mixer * * * Copyright (C) 2004 Christian Esken * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // KMix #include "mdwenum.h" -#include "core/mixer.h" #include "viewbase.h" +#include "core/mixer.h" // KDE #include -#include -#include #include #include // Qt #include #include #include #include #include #include #include /** * Class that represents an Enum element (a select one-from-many selector) * The orientation (horizontal, vertical) is ignored */ MDWEnum::MDWEnum( shared_ptr md, Qt::Orientation orientation, QWidget* parent, ViewBase* view, ProfControl* par_pctl) : MixDeviceWidget(md, false, orientation, parent, view, par_pctl), _label(0), _enumCombo(0), _layout(0) { // create actions (on _mdwActions, see MixDeviceWidget) // KStandardAction::showMenubar() is in MixDeviceWidget now KToggleAction *action = _mdwActions->add( "hide" ); action->setText( i18n("&Hide") ); connect(action, SIGNAL(triggered(bool)), SLOT(setDisabled(bool))); QAction *c = _mdwActions->addAction( "keys" ); c->setText( i18n("C&onfigure Shortcuts...") ); connect(c, SIGNAL(triggered(bool)), SLOT(defineKeys())); // create widgets createWidgets(); - - /* remove this for production version - QAction *a = _mdwActions->addAction( "Next Value" ); - c->setText( i18n( "Next Value" ) ); - connect(a, SIGNAL(triggered(bool)), SLOT(nextEnumId())); - */ - - installEventFilter( this ); // filter for popup -} - -MDWEnum::~MDWEnum() -{ } void MDWEnum::createWidgets() { if ( m_orientation == Qt::Vertical ) { _layout = new QVBoxLayout( this ); _layout->setAlignment(Qt::AlignLeft); } else { _layout = new QHBoxLayout( this ); _layout->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); } _label = new QLabel( m_mixdevice->readableName(), this); _layout->addWidget(_label); _enumCombo = new QComboBox(this); - _enumCombo->installEventFilter(this); + _enumCombo->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + // ------------ fill ComboBox start ------------ int maxEnumId= m_mixdevice->enumValues().count(); for (int i=0; iaddItem( m_mixdevice->enumValues().at(i)); } // ------------ fill ComboBox end -------------- _layout->addWidget(_enumCombo); connect( _enumCombo, SIGNAL(activated(int)), this, SLOT(setEnumId(int)) ); _enumCombo->setToolTip( m_mixdevice->readableName() ); _layout->addStretch(1); } void MDWEnum::update() { if ( m_mixdevice->isEnum() ) { //qCDebug(KMIX_LOG) << "MDWEnum::update() enumID=" << m_mixdevice->enumId(); _enumCombo->setCurrentIndex( m_mixdevice->enumId() ); } else { qCCritical(KMIX_LOG) << "MDWEnum::update() enumID=" << m_mixdevice->enumId() << " is no Enum ... skipped"; } } void MDWEnum::showContextMenu(const QPoint& pos ) { if( m_view == 0 ) return; QMenu *menu = m_view->getPopup(); menu->popup( pos ); } QSizePolicy MDWEnum::sizePolicy() const { return QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ); } /** This slot is called, when a user has clicked the mute button. Also it is called by any other associated KAction like the context menu. */ void MDWEnum::nextEnumId() { if( m_mixdevice->isEnum() ) { int curEnum = enumId(); if ( curEnum < m_mixdevice->enumValues().count() ) { // next enum value setEnumId(curEnum+1); } else { // wrap around setEnumId(0); } } // isEnum } void MDWEnum::setEnumId(int value) { if ( m_mixdevice->isEnum() ) { m_mixdevice->setEnumId( value ); m_mixdevice->mixer()->commitVolumeChange( m_mixdevice ); } } int MDWEnum::enumId() { if ( m_mixdevice->isEnum() ) { return m_mixdevice->enumId(); } else { return 0; } } void MDWEnum::setDisabled( bool hide ) { emit guiVisibilityChange(this, !hide); } - -/** - * An event filter for the various QWidgets. We watch for Mouse press Events, so - * that we can popup the context menu. - */ -bool MDWEnum::eventFilter( QObject* obj, QEvent* e ) -{ - if (e->type() == QEvent::MouseButtonPress) { - QMouseEvent *qme = static_cast(e); - if (qme->button() == Qt::RightButton) { - showContextMenu(); - return true; - } - } else if (e->type() == QEvent::ContextMenu) { - QPoint pos = reinterpret_cast(obj)->mapToGlobal(QPoint(0, 0)); - showContextMenu(pos); - return true; - } - return QWidget::eventFilter(obj,e); -} - diff --git a/gui/mdwenum.h b/gui/mdwenum.h index 6d523abc..f6585f72 100644 --- a/gui/mdwenum.h +++ b/gui/mdwenum.h @@ -1,74 +1,70 @@ //-*-C++-*- /* * KMix -- KDE's full featured mini mixer * * * Copyright (C) 2004 Chrisitan Esken * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MDWENUM_H #define MDWENUM_H -#include -#include "core/volume.h" - // KMix class MixDevice; class ViewBase; // Qt class QBoxLayout; class QComboBox; class QLabel; #include "gui/mixdevicewidget.h" class MDWEnum : public MixDeviceWidget { Q_OBJECT public: MDWEnum( shared_ptr md, Qt::Orientation orientation, QWidget* parent, ViewBase* view, ProfControl* pctl); - ~MDWEnum(); + virtual ~MDWEnum() = default; void addActionToPopup( QAction *action ); QSizePolicy sizePolicy() const; - bool eventFilter( QObject* obj, QEvent* e ) Q_DECL_OVERRIDE; public slots: // GUI hide and show void setDisabled(bool) Q_DECL_OVERRIDE; // Enum handling: next and selecting void nextEnumId(); int enumId(); void setEnumId(int value); void update() Q_DECL_OVERRIDE; void showContextMenu(const QPoint& pos = QCursor::pos()) Q_DECL_OVERRIDE; private: void createWidgets(); QLabel *_label; QComboBox *_enumCombo; QBoxLayout *_layout; }; #endif