kde-workspace/kstyles/oxygen/oxygenmnemonics.cpp
Ivailo Monev 798516d74e kstyle: indentation corrections
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2021-06-15 16:59:08 +03:00

99 lines
2.7 KiB
C++

//////////////////////////////////////////////////////////////////////////////
// oxygenmnemonics.cpp
// enable/disable mnemonics display
// -------------------
//
// Copyright (C) 2011 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License version 2 as published by the Free Software Foundation.
//
// This library 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 library; see the file COPYING.LIB. If not, write to
// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301, USA.
//////////////////////////////////////////////////////////////////////////////
#include "oxygenmnemonics.h"
#include <QtGui/qevent.h>
#include <QtGui/QWidget>
namespace Oxygen
{
//____________________________________________________
void Mnemonics::setMode( int mode )
{
switch( mode )
{
case StyleConfigData::MN_NEVER:
qApp->removeEventFilter( this );
setEnabled( false );
break;
case StyleConfigData::MN_AUTO:
qApp->removeEventFilter( this );
qApp->installEventFilter( this );
setEnabled( false );
break;
case StyleConfigData::MN_ALWAYS:
default:
qApp->removeEventFilter( this );
setEnabled( true );
break;
}
return;
}
//____________________________________________________
bool Mnemonics::eventFilter( QObject*, QEvent* event )
{
switch( event->type() )
{
case QEvent::KeyPress:
if( static_cast<QKeyEvent*>(event)->key() == Qt::Key_Alt )
{ setEnabled( true ); }
break;
case QEvent::KeyRelease:
if( static_cast<QKeyEvent*>(event)->key() == Qt::Key_Alt )
{ setEnabled( false ); }
break;
default:
break;
}
return false;
}
//____________________________________________________
void Mnemonics::setEnabled( bool value )
{
if( _enabled == value ) return;
_enabled = value;
// update all top level widgets
foreach( QWidget* widget, qApp->topLevelWidgets() )
{ widget->update(); }
}
}