mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
+! Those were meant to be commited as a part of the previous commit.
This commit is contained in:
parent
5efd7c52e1
commit
b7f65dc126
118
src/hotkeyedit.cc
Normal file
118
src/hotkeyedit.cc
Normal file
|
@ -0,0 +1,118 @@
|
|||
/* This file is (c) 2008-2009 Konstantin Isakov <ikm@users.berlios.de>
|
||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#include "hotkeyedit.hh"
|
||||
#include <QKeyEvent>
|
||||
|
||||
HotKeyEdit::HotKeyEdit( QWidget * parent ):
|
||||
QLineEdit( parent ),
|
||||
currentModifiers( 0 ), currentKey1( 0 ), currentKey2( 0 ),
|
||||
continuingCombo( false )
|
||||
{
|
||||
renderCurrentValue();
|
||||
}
|
||||
|
||||
void HotKeyEdit::setHotKey( Config::HotKey const & hk )
|
||||
{
|
||||
currentModifiers = hk.modifiers;
|
||||
currentKey1 = hk.key1;
|
||||
currentKey2 = hk.key2;
|
||||
|
||||
renderCurrentValue();
|
||||
}
|
||||
|
||||
Config::HotKey HotKeyEdit::getHotKey() const
|
||||
{
|
||||
Config::HotKey hk;
|
||||
|
||||
hk.modifiers = currentModifiers;
|
||||
hk.key1 = currentKey1;
|
||||
hk.key2 = currentKey2;
|
||||
|
||||
return hk;
|
||||
}
|
||||
|
||||
void HotKeyEdit::renderCurrentValue()
|
||||
{
|
||||
QString result;
|
||||
|
||||
if ( currentKey1 )
|
||||
{
|
||||
result = QKeySequence( currentKey1 | currentModifiers ).toString( QKeySequence::PortableText );
|
||||
|
||||
if ( currentKey2 )
|
||||
result += "+" + QKeySequence( currentKey2 ).toString( QKeySequence::PortableText );
|
||||
}
|
||||
|
||||
setText( result );
|
||||
}
|
||||
|
||||
void HotKeyEdit::keyPressEvent( QKeyEvent * event )
|
||||
{
|
||||
int key = event->key();
|
||||
|
||||
switch( key )
|
||||
{
|
||||
case 0:
|
||||
case Qt::Key_unknown:
|
||||
case Qt::Key_Shift:
|
||||
case Qt::Key_Control:
|
||||
case Qt::Key_Meta:
|
||||
case Qt::Key_Alt:
|
||||
case Qt::Key_AltGr:
|
||||
continuingCombo = false;
|
||||
QLineEdit::keyPressEvent( event );
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
if ( !event->modifiers() &&
|
||||
( ( key == Qt::Key_Backspace ) || ( key == Qt::Key_Delete ) ) )
|
||||
{
|
||||
// Delete current combo
|
||||
currentKey1 = 0;
|
||||
currentKey2 = 0;
|
||||
currentModifiers = 0;
|
||||
continuingCombo = false;
|
||||
}
|
||||
else
|
||||
if ( !continuingCombo )
|
||||
{
|
||||
if ( event->modifiers() || event->text().isEmpty() ) // Don't allow plain letters
|
||||
{
|
||||
currentKey2 = 0;
|
||||
currentKey1 = key;
|
||||
currentModifiers = event->modifiers();
|
||||
continuingCombo = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentKey2 = key;
|
||||
continuingCombo = false;
|
||||
}
|
||||
|
||||
renderCurrentValue();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void HotKeyEdit::keyReleaseEvent( QKeyEvent * event )
|
||||
{
|
||||
switch( event->key() )
|
||||
{
|
||||
case 0:
|
||||
case Qt::Key_unknown:
|
||||
case Qt::Key_Shift:
|
||||
case Qt::Key_Control:
|
||||
case Qt::Key_Meta:
|
||||
case Qt::Key_Alt:
|
||||
case Qt::Key_AltGr:
|
||||
continuingCombo = false;
|
||||
break;
|
||||
}
|
||||
|
||||
QLineEdit::keyReleaseEvent( event );
|
||||
}
|
||||
|
37
src/hotkeyedit.hh
Normal file
37
src/hotkeyedit.hh
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* This file is (c) 2008-2009 Konstantin Isakov <ikm@users.berlios.de>
|
||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#ifndef __HOTKEYEDIT_HH_INCLUDED__
|
||||
#define __HOTKEYEDIT_HH_INCLUDED__
|
||||
|
||||
#include "config.hh"
|
||||
#include <QLineEdit>
|
||||
|
||||
// This widget allows grabbing a hotkey
|
||||
class HotKeyEdit: public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Qt::KeyboardModifiers currentModifiers;
|
||||
int currentKey1, currentKey2;
|
||||
|
||||
bool continuingCombo;
|
||||
|
||||
public:
|
||||
|
||||
HotKeyEdit( QWidget * parent = 0 );
|
||||
|
||||
void setHotKey( Config::HotKey const & );
|
||||
Config::HotKey getHotKey() const;
|
||||
|
||||
protected:
|
||||
|
||||
void keyPressEvent( QKeyEvent * event );
|
||||
void keyReleaseEvent( QKeyEvent * event );
|
||||
|
||||
private:
|
||||
|
||||
void renderCurrentValue();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue