23 #include <QStringList>
28 KateViKeyParser::KateViKeyParser()
40 if ( m_instance == NULL ) {
47 void KateViKeyParser::initKeyTables()
52 m_qt2katevi->
insert( Qt::Key_Backspace,
QString(
"backspace" ) );
68 m_qt2katevi->
insert( Qt::Key_PageDown,
QString(
"pagedown" ) );
74 m_qt2katevi->
insert( Qt::Key_CapsLock,
QString(
"capslock" ) );
76 m_qt2katevi->
insert( Qt::Key_ScrollLock,
QString(
"scrolllock" ) );
112 m_qt2katevi->
insert( Qt::Key_Super_L,
QString(
"super_l" ) );
113 m_qt2katevi->
insert( Qt::Key_Super_R,
QString(
"super_r" ) );
115 m_qt2katevi->
insert( Qt::Key_Hyper_L,
QString(
"hyper_l" ) );
116 m_qt2katevi->
insert( Qt::Key_Hyper_R,
QString(
"hyper_r" ) );
118 m_qt2katevi->
insert( Qt::Key_Direction_L,
QString(
"direction_l" ) );
119 m_qt2katevi->
insert( Qt::Key_Direction_R,
QString(
"direction_r" ) );
120 m_qt2katevi->
insert( Qt::Key_Multi_key,
QString(
"multi_key" ) );
121 m_qt2katevi->
insert( Qt::Key_Codeinput,
QString(
"codeinput" ) );
122 m_qt2katevi->
insert( Qt::Key_SingleCandidate,
QString(
"singlecandidate" ) );
123 m_qt2katevi->
insert( Qt::Key_MultipleCandidate,
QString(
"multiplecandidate" ) );
124 m_qt2katevi->
insert( Qt::Key_PreviousCandidate,
QString(
"previouscandidate" ) );
125 m_qt2katevi->
insert( Qt::Key_Mode_switch,
QString(
"mode_switch" ) );
127 m_qt2katevi->
insert( Qt::Key_Muhenkan,
QString(
"muhenkan" ) );
130 m_qt2katevi->
insert( Qt::Key_Hiragana,
QString(
"hiragana" ) );
131 m_qt2katevi->
insert( Qt::Key_Katakana,
QString(
"katakana" ) );
132 m_qt2katevi->
insert( Qt::Key_Hiragana_Katakana,
QString(
"hiragana_katakana" ) );
133 m_qt2katevi->
insert( Qt::Key_Zenkaku,
QString(
"zenkaku" ) );
134 m_qt2katevi->
insert( Qt::Key_Hankaku,
QString(
"hankaku" ) );
135 m_qt2katevi->
insert( Qt::Key_Zenkaku_Hankaku,
QString(
"zenkaku_hankaku" ) );
136 m_qt2katevi->
insert( Qt::Key_Touroku,
QString(
"touroku" ) );
138 m_qt2katevi->
insert( Qt::Key_Kana_Lock,
QString(
"kana_lock" ) );
139 m_qt2katevi->
insert( Qt::Key_Kana_Shift,
QString(
"kana_shift" ) );
140 m_qt2katevi->
insert( Qt::Key_Eisu_Shift,
QString(
"eisu_shift" ) );
141 m_qt2katevi->
insert( Qt::Key_Eisu_toggle,
QString(
"eisu_toggle" ) );
143 m_qt2katevi->
insert( Qt::Key_Hangul_Start,
QString(
"hangul_start" ) );
144 m_qt2katevi->
insert( Qt::Key_Hangul_End,
QString(
"hangul_end" ) );
145 m_qt2katevi->
insert( Qt::Key_Hangul_Hanja,
QString(
"hangul_hanja" ) );
146 m_qt2katevi->
insert( Qt::Key_Hangul_Jamo,
QString(
"hangul_jamo" ) );
147 m_qt2katevi->
insert( Qt::Key_Hangul_Romaja,
QString(
"hangul_romaja" ) );
148 m_qt2katevi->
insert( Qt::Key_Hangul_Jeonja,
QString(
"hangul_jeonja" ) );
149 m_qt2katevi->
insert( Qt::Key_Hangul_Banja,
QString(
"hangul_banja" ) );
150 m_qt2katevi->
insert( Qt::Key_Hangul_PreHanja,
QString(
"hangul_prehanja" ) );
151 m_qt2katevi->
insert( Qt::Key_Hangul_PostHanja,
QString(
"hangul_posthanja" ) );
152 m_qt2katevi->
insert( Qt::Key_Hangul_Special,
QString(
"hangul_special" ) );
153 m_qt2katevi->
insert( Qt::Key_Dead_Grave,
QString(
"dead_grave" ) );
154 m_qt2katevi->
insert( Qt::Key_Dead_Acute,
QString(
"dead_acute" ) );
155 m_qt2katevi->
insert( Qt::Key_Dead_Circumflex,
QString(
"dead_circumflex" ) );
156 m_qt2katevi->
insert( Qt::Key_Dead_Tilde,
QString(
"dead_tilde" ) );
157 m_qt2katevi->
insert( Qt::Key_Dead_Macron,
QString(
"dead_macron" ) );
158 m_qt2katevi->
insert( Qt::Key_Dead_Breve,
QString(
"dead_breve" ) );
159 m_qt2katevi->
insert( Qt::Key_Dead_Abovedot,
QString(
"dead_abovedot" ) );
160 m_qt2katevi->
insert( Qt::Key_Dead_Diaeresis,
QString(
"dead_diaeresis" ) );
161 m_qt2katevi->
insert( Qt::Key_Dead_Abovering,
QString(
"dead_abovering" ) );
162 m_qt2katevi->
insert( Qt::Key_Dead_Doubleacute,
QString(
"dead_doubleacute" ) );
163 m_qt2katevi->
insert( Qt::Key_Dead_Caron,
QString(
"dead_caron" ) );
164 m_qt2katevi->
insert( Qt::Key_Dead_Cedilla,
QString(
"dead_cedilla" ) );
165 m_qt2katevi->
insert( Qt::Key_Dead_Ogonek,
QString(
"dead_ogonek" ) );
166 m_qt2katevi->
insert( Qt::Key_Dead_Iota,
QString(
"dead_iota" ) );
167 m_qt2katevi->
insert( Qt::Key_Dead_Voiced_Sound,
QString(
"dead_voiced_sound" ) );
168 m_qt2katevi->
insert( Qt::Key_Dead_Semivoiced_Sound,
QString(
"dead_semivoiced_sound" ) );
169 m_qt2katevi->
insert( Qt::Key_Dead_Belowdot,
QString(
"dead_belowdot" ) );
170 m_qt2katevi->
insert( Qt::Key_Dead_Hook,
QString(
"dead_hook" ) );
171 m_qt2katevi->
insert( Qt::Key_Dead_Horn,
QString(
"dead_horn" ) );
173 m_qt2katevi->
insert( Qt::Key_Forward,
QString(
"forward" ) );
175 m_qt2katevi->
insert( Qt::Key_Refresh,
QString(
"refresh" ) );
176 m_qt2katevi->
insert( Qt::Key_VolumeDown,
QString(
"volumedown" ) );
177 m_qt2katevi->
insert( Qt::Key_VolumeMute,
QString(
"volumemute" ) );
178 m_qt2katevi->
insert( Qt::Key_VolumeUp,
QString(
"volumeup" ) );
179 m_qt2katevi->
insert( Qt::Key_BassBoost,
QString(
"bassboost" ) );
181 m_qt2katevi->
insert( Qt::Key_BassDown,
QString(
"bassdown" ) );
182 m_qt2katevi->
insert( Qt::Key_TrebleUp,
QString(
"trebleup" ) );
183 m_qt2katevi->
insert( Qt::Key_TrebleDown,
QString(
"trebledown" ) );
184 m_qt2katevi->
insert( Qt::Key_MediaPlay,
QString(
"mediaplay" ) );
185 m_qt2katevi->
insert( Qt::Key_MediaStop,
QString(
"mediastop" ) );
186 m_qt2katevi->
insert( Qt::Key_MediaPrevious,
QString(
"mediaprevious" ) );
187 m_qt2katevi->
insert( Qt::Key_MediaNext,
QString(
"medianext" ) );
188 m_qt2katevi->
insert( Qt::Key_MediaRecord,
QString(
"mediarecord" ) );
189 m_qt2katevi->
insert( Qt::Key_HomePage,
QString(
"homepage" ) );
190 m_qt2katevi->
insert( Qt::Key_Favorites,
QString(
"favorites" ) );
192 m_qt2katevi->
insert( Qt::Key_Standby,
QString(
"standby" ) );
193 m_qt2katevi->
insert( Qt::Key_OpenUrl,
QString(
"openurl" ) );
194 m_qt2katevi->
insert( Qt::Key_LaunchMail,
QString(
"launchmail" ) );
195 m_qt2katevi->
insert( Qt::Key_LaunchMedia,
QString(
"launchmedia" ) );
196 m_qt2katevi->
insert( Qt::Key_Launch0,
QString(
"launch0" ) );
197 m_qt2katevi->
insert( Qt::Key_Launch1,
QString(
"launch1" ) );
198 m_qt2katevi->
insert( Qt::Key_Launch2,
QString(
"launch2" ) );
199 m_qt2katevi->
insert( Qt::Key_Launch3,
QString(
"launch3" ) );
200 m_qt2katevi->
insert( Qt::Key_Launch4,
QString(
"launch4" ) );
201 m_qt2katevi->
insert( Qt::Key_Launch5,
QString(
"launch5" ) );
202 m_qt2katevi->
insert( Qt::Key_Launch6,
QString(
"launch6" ) );
203 m_qt2katevi->
insert( Qt::Key_Launch7,
QString(
"launch7" ) );
204 m_qt2katevi->
insert( Qt::Key_Launch8,
QString(
"launch8" ) );
205 m_qt2katevi->
insert( Qt::Key_Launch9,
QString(
"launch9" ) );
206 m_qt2katevi->
insert( Qt::Key_LaunchA,
QString(
"launcha" ) );
207 m_qt2katevi->
insert( Qt::Key_LaunchB,
QString(
"launchb" ) );
208 m_qt2katevi->
insert( Qt::Key_LaunchC,
QString(
"launchc" ) );
209 m_qt2katevi->
insert( Qt::Key_LaunchD,
QString(
"launchd" ) );
210 m_qt2katevi->
insert( Qt::Key_LaunchE,
QString(
"launche" ) );
211 m_qt2katevi->
insert( Qt::Key_LaunchF,
QString(
"launchf" ) );
212 m_qt2katevi->
insert( Qt::Key_MediaLast,
QString(
"medialast" ) );
213 m_qt2katevi->
insert( Qt::Key_unknown,
QString(
"unknown" ) );
215 m_qt2katevi->
insert( Qt::Key_Context1,
QString(
"context1" ) );
216 m_qt2katevi->
insert( Qt::Key_Context2,
QString(
"context2" ) );
217 m_qt2katevi->
insert( Qt::Key_Context3,
QString(
"context3" ) );
218 m_qt2katevi->
insert( Qt::Key_Context4,
QString(
"context4" ) );
224 m_qt2katevi->
insert( Qt::Key_Execute,
QString(
"execute" ) );
225 m_qt2katevi->
insert( Qt::Key_Printer,
QString(
"printer" ) );
232 i != m_qt2katevi->
constEnd(); ++i) {
233 m_katevi2qt->
insert( i.value(), i.key() );
311 m_nameToKeyCode->
insert(
QString(
"singlecandidate" ), 174 );
312 m_nameToKeyCode->
insert(
QString(
"multiplecandidate" ), 175 );
313 m_nameToKeyCode->
insert(
QString(
"previouscandidate" ), 176 );
321 m_nameToKeyCode->
insert(
QString(
"hiragana_katakana" ), 184 );
324 m_nameToKeyCode->
insert(
QString(
"zenkaku_hankaku" ), 187 );
339 m_nameToKeyCode->
insert(
QString(
"hangul_prehanja" ), 202 );
340 m_nameToKeyCode->
insert(
QString(
"hangul_posthanja" ), 203 );
344 m_nameToKeyCode->
insert(
QString(
"dead_circumflex" ), 207 );
351 m_nameToKeyCode->
insert(
QString(
"dead_doubleacute" ), 214 );
356 m_nameToKeyCode->
insert(
QString(
"dead_voiced_sound" ), 219 );
357 m_nameToKeyCode->
insert(
QString(
"dead_semivoiced_sound" ), 220 );
493 i != m_nameToKeyCode->
constEnd(); ++i) {
494 m_keyCodeToName->
insert( i.value(), i.key() );
500 return ( m_qt2katevi->
contains( key ) ? m_qt2katevi->
value( key ) :
"invalid" );
505 return ( m_katevi2qt->
contains( keypress ) ? m_katevi2qt->
value( keypress ) : -1 );
517 return (m_katevi2qt->
contains(key) ? m_katevi2qt->
value(key) : -1);
523 unsigned int keyCodeTemp = 0;
525 bool insideTag =
false;
527 for (
int i = 0; i < keys.
length(); i++ ) {
532 temp.
setNum( 0xE000+keyCodeTemp, 16);
533 QChar code(0xE000+keyCodeTemp );
534 encodedSequence.
append( code );
550 while ((nextHypen = untilClosing.
indexOf(
QChar(
'-'), currentPos)) != -1)
552 tokens << untilClosing.
mid(currentPos, nextHypen - currentPos + 1);
553 currentPos = nextHypen + 1;
555 tokens << untilClosing.
mid(currentPos);
557 foreach (
const QString& str, tokens ) {
558 if ( str ==
"s-" && ( keyCodeTemp & 0x01 ) != 0x1 )
560 else if ( str ==
"c-" && ( keyCodeTemp & 0x02 ) != 0x2 )
562 else if ( str ==
"a-" && ( keyCodeTemp & 0x04 ) != 0x4 )
564 else if ( str ==
"m-" && ( keyCodeTemp & 0x08 ) != 0x8 )
568 if ( m_nameToKeyCode->
contains( str ) ) {
569 keyCodeTemp += m_nameToKeyCode->
value( str ) * 0x10;
571 keyCodeTemp += str.
at( 0 ).
unicode() * 0x10;
574 int endOfBlock = keys.
indexOf(
'>' );
575 if ( endOfBlock -= -1 ) {
576 endOfBlock = keys.
length()-1;
578 encodedSequence.
clear();
579 encodedSequence.
append( m_nameToKeyCode->
value(
"invalid" ) );
588 if ( m_nameToKeyCode->
contains( str ) ) {
589 keyCodeTemp += m_nameToKeyCode->
value( str ) * 0x10;
591 keyCodeTemp += str.
at( 0 ).
unicode() * 0x10;
594 int endOfBlock = keys.
indexOf(
'>' );
595 if ( endOfBlock -= -1 ) {
596 endOfBlock = keys.
length()-1;
598 encodedSequence.
clear();
599 keyCodeTemp = m_nameToKeyCode->
value(
"invalid" ) * 0x10;
611 if (rest.
indexOf(
'>', 1) != -1 && rest.
mid(1, rest.
indexOf(
'>', 1) - 1) ==
"space")
613 encodedSequence.
append(
" ");
618 encodedSequence.
append( c );
624 encodedSequence.
append( c );
629 return encodedSequence;
636 for (
int i = 0; i < keys.
length(); i++ ) {
640 if ( ( keycode & 0xE000 ) != 0xE000 ) {
645 if ( ( keycode & 0x1 ) == 0x1 ) {
649 if ( ( keycode & 0x2 ) == 0x2 ) {
653 if ( ( keycode & 0x4 ) == 0x4 ) {
657 if ( ( keycode & 0x8 ) == 0x8 ) {
662 if ( ( keycode & 0xE000 ) == 0xE000 ) {
663 ret.
append( m_keyCodeToName->
value( ( keycode-0xE000 )/0x10 ) );
676 const int keyCode = keyEvent.
key();
683 if ( mods & Qt::GroupSwitchModifier ) {
687 if ( text.
isEmpty() || ( text.
length() == 1 && text.
at(0) < 0x20 ) || keyCode == Qt::Key_Delete
688 || ( mods != Qt::NoModifier && mods != Qt::ShiftModifier && mods != Qt::KeypadModifier) ) {
692 keyPress.
append( ( mods & Qt::ShiftModifier ) ?
"s-" :
"" );
693 keyPress.
append( ( mods & Qt::ControlModifier ) ?
"c-" :
"" );
694 keyPress.
append( ( mods & Qt::AltModifier ) ?
"a-" :
"" );
695 keyPress.
append( ( mods & Qt::MetaModifier ) ?
"m-" :
"" );
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
Qt::KeyboardModifiers modifiers() const
QString & append(QChar ch)
iterator insert(const Key &key, const T &value)
QString qt2vi(int key) const
const QChar KeyEventToQChar(const QKeyEvent &keyEvent)
const_iterator constEnd() const
const QString decodeKeySequence(const QString &keys) const
const QString encodeKeySequence(const QString &keys) const
const T value(const Key &key) const
const_iterator constBegin() const
QString mid(int position, int n) const
int encoded2qt(const QString &keypress) const
QString & setNum(short n, int base)
const QChar at(int position) const
for encoding keypresses w/ modifiers into an internal QChar representation and back again to a descri...
bool contains(const Key &key) const
static KateViKeyParser * self()
int vi2qt(const QString &keypress) const
bool isLetterOrNumber() const
typedef KeyboardModifiers