• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
KeyboardTranslator.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Konsole, a terminal emulator.
3 
4  Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301 USA.
20 */
21 
22 // Own
23 #include "KeyboardTranslator.h"
24 
25 // System
26 #include <ctype.h>
27 #include <stdio.h>
28 
29 // Qt
30 #include <QtCore/QBuffer>
31 #include <QtCore/QTextStream>
32 #include <QtGui/QKeySequence>
33 
34 // KDE
35 #include <KDebug>
36 #include <KLocalizedString>
37 
38 using namespace Konsole;
39 
40 KeyboardTranslatorWriter::KeyboardTranslatorWriter(QIODevice* destination)
41  : _destination(destination)
42 {
43  Q_ASSERT(destination && destination->isWritable());
44 
45  _writer = new QTextStream(_destination);
46 }
47 KeyboardTranslatorWriter::~KeyboardTranslatorWriter()
48 {
49  delete _writer;
50 }
51 void KeyboardTranslatorWriter::writeHeader(const QString& description)
52 {
53  *_writer << "keyboard \"" << description << '\"' << '\n';
54 }
55 void KeyboardTranslatorWriter::writeEntry(const KeyboardTranslator::Entry& entry)
56 {
57  QString result;
58  if (entry.command() != KeyboardTranslator::NoCommand)
59  result = entry.resultToString();
60  else
61  result = '\"' + entry.resultToString() + '\"';
62 
63  *_writer << "key " << entry.conditionToString() << " : " << result << '\n';
64 }
65 
66 // each line of the keyboard translation file is one of:
67 //
68 // - keyboard "name"
69 // - key KeySequence : "characters"
70 // - key KeySequence : CommandName
71 //
72 // KeySequence begins with the name of the key ( taken from the Qt::Key enum )
73 // and is followed by the keyboard modifiers and state flags ( with + or - in front
74 // of each modifier or flag to indicate whether it is required ). All keyboard modifiers
75 // and flags are optional, if a particular modifier or state is not specified it is
76 // assumed not to be a part of the sequence. The key sequence may contain whitespace
77 //
78 // eg: "key Up+Shift : scrollLineUp"
79 // "key PgDown-Shift : "\E[6~"
80 //
81 // (lines containing only whitespace are ignored, parseLine assumes that comments have
82 // already been removed)
83 //
84 
85 KeyboardTranslatorReader::KeyboardTranslatorReader(QIODevice* source)
86  : _source(source)
87  , _hasNext(false)
88 {
89  // read input until we find the description
90  while (_description.isEmpty() && !source->atEnd()) {
91  QList<Token> tokens = tokenize(QString::fromLocal8Bit(source->readLine()));
92  if (!tokens.isEmpty() && tokens.first().type == Token::TitleKeyword)
93  _description = i18n(tokens[1].text.toUtf8());
94  }
95  // read first entry (if any)
96  readNext();
97 }
98 void KeyboardTranslatorReader::readNext()
99 {
100  // find next entry
101  while (!_source->atEnd()) {
102  const QList<Token>& tokens = tokenize(QString::fromLocal8Bit(_source->readLine()));
103  if (!tokens.isEmpty() && tokens.first().type == Token::KeyKeyword) {
104  KeyboardTranslator::States flags = KeyboardTranslator::NoState;
105  KeyboardTranslator::States flagMask = KeyboardTranslator::NoState;
106  Qt::KeyboardModifiers modifiers = Qt::NoModifier;
107  Qt::KeyboardModifiers modifierMask = Qt::NoModifier;
108 
109  int keyCode = Qt::Key_unknown;
110 
111  decodeSequence(tokens[1].text.toLower(),
112  keyCode,
113  modifiers,
114  modifierMask,
115  flags,
116  flagMask);
117 
118  KeyboardTranslator::Command command = KeyboardTranslator::NoCommand;
119  QByteArray text;
120 
121  // get text or command
122  if (tokens[2].type == Token::OutputText) {
123  text = tokens[2].text.toLocal8Bit();
124  } else if (tokens[2].type == Token::Command) {
125  // identify command
126  if (!parseAsCommand(tokens[2].text, command))
127  kWarning() << "Key" << tokens[1].text << ", Command" << tokens[2].text << "not understood. ";
128  }
129 
130  KeyboardTranslator::Entry newEntry;
131  newEntry.setKeyCode(keyCode);
132  newEntry.setState(flags);
133  newEntry.setStateMask(flagMask);
134  newEntry.setModifiers(modifiers);
135  newEntry.setModifierMask(modifierMask);
136  newEntry.setText(text);
137  newEntry.setCommand(command);
138 
139  _nextEntry = newEntry;
140 
141  _hasNext = true;
142 
143  return;
144  }
145  }
146 
147  _hasNext = false;
148 }
149 
150 bool KeyboardTranslatorReader::parseAsCommand(const QString& text, KeyboardTranslator::Command& command)
151 {
152  if (text.compare("erase", Qt::CaseInsensitive) == 0)
153  command = KeyboardTranslator::EraseCommand;
154  else if (text.compare("scrollpageup", Qt::CaseInsensitive) == 0)
155  command = KeyboardTranslator::ScrollPageUpCommand;
156  else if (text.compare("scrollpagedown", Qt::CaseInsensitive) == 0)
157  command = KeyboardTranslator::ScrollPageDownCommand;
158  else if (text.compare("scrolllineup", Qt::CaseInsensitive) == 0)
159  command = KeyboardTranslator::ScrollLineUpCommand;
160  else if (text.compare("scrolllinedown", Qt::CaseInsensitive) == 0)
161  command = KeyboardTranslator::ScrollLineDownCommand;
162  else if (text.compare("scrolluptotop", Qt::CaseInsensitive) == 0)
163  command = KeyboardTranslator::ScrollUpToTopCommand;
164  else if (text.compare("scrolldowntobottom", Qt::CaseInsensitive) == 0)
165  command = KeyboardTranslator::ScrollDownToBottomCommand;
166  else
167  return false;
168 
169  return true;
170 }
171 
172 bool KeyboardTranslatorReader::decodeSequence(const QString& text,
173  int& keyCode,
174  Qt::KeyboardModifiers& modifiers,
175  Qt::KeyboardModifiers& modifierMask,
176  KeyboardTranslator::States& flags,
177  KeyboardTranslator::States& flagMask)
178 {
179  bool isWanted = true;
180  bool endOfItem = false;
181  QString buffer;
182 
183  Qt::KeyboardModifiers tempModifiers = modifiers;
184  Qt::KeyboardModifiers tempModifierMask = modifierMask;
185  KeyboardTranslator::States tempFlags = flags;
186  KeyboardTranslator::States tempFlagMask = flagMask;
187 
188  for (int i = 0 ; i < text.count() ; i++) {
189  const QChar& ch = text[i];
190  const bool isFirstLetter = (i == 0);
191  const bool isLastLetter = (i == text.count() - 1);
192  endOfItem = true;
193  if (ch.isLetterOrNumber()) {
194  endOfItem = false;
195  buffer.append(ch);
196  } else if (isFirstLetter) {
197  buffer.append(ch);
198  }
199 
200  if ((endOfItem || isLastLetter) && !buffer.isEmpty()) {
201  Qt::KeyboardModifier itemModifier = Qt::NoModifier;
202  int itemKeyCode = 0;
203  KeyboardTranslator::State itemFlag = KeyboardTranslator::NoState;
204 
205  if (parseAsModifier(buffer, itemModifier)) {
206  tempModifierMask |= itemModifier;
207 
208  if (isWanted)
209  tempModifiers |= itemModifier;
210  } else if (parseAsStateFlag(buffer, itemFlag)) {
211  tempFlagMask |= itemFlag;
212 
213  if (isWanted)
214  tempFlags |= itemFlag;
215  } else if (parseAsKeyCode(buffer, itemKeyCode)) {
216  keyCode = itemKeyCode;
217  } else {
218  kWarning() << "Unable to parse key binding item:" << buffer;
219  }
220 
221  buffer.clear();
222  }
223 
224  // check if this is a wanted / not-wanted flag and update the
225  // state ready for the next item
226  if (ch == '+')
227  isWanted = true;
228  else if (ch == '-')
229  isWanted = false;
230  }
231 
232  modifiers = tempModifiers;
233  modifierMask = tempModifierMask;
234  flags = tempFlags;
235  flagMask = tempFlagMask;
236 
237  return true;
238 }
239 
240 bool KeyboardTranslatorReader::parseAsModifier(const QString& item , Qt::KeyboardModifier& modifier)
241 {
242  if (item == "shift")
243  modifier = Qt::ShiftModifier;
244  else if (item == "ctrl" || item == "control")
245  modifier = Qt::ControlModifier;
246  else if (item == "alt")
247  modifier = Qt::AltModifier;
248  else if (item == "meta")
249  modifier = Qt::MetaModifier;
250  else if (item == "keypad")
251  modifier = Qt::KeypadModifier;
252  else
253  return false;
254 
255  return true;
256 }
257 bool KeyboardTranslatorReader::parseAsStateFlag(const QString& item , KeyboardTranslator::State& flag)
258 {
259  if (item == "appcukeys" || item == "appcursorkeys")
260  flag = KeyboardTranslator::CursorKeysState;
261  else if (item == "ansi")
262  flag = KeyboardTranslator::AnsiState;
263  else if (item == "newline")
264  flag = KeyboardTranslator::NewLineState;
265  else if (item == "appscreen")
266  flag = KeyboardTranslator::AlternateScreenState;
267  else if (item == "anymod" || item == "anymodifier")
268  flag = KeyboardTranslator::AnyModifierState;
269  else if (item == "appkeypad")
270  flag = KeyboardTranslator::ApplicationKeypadState;
271  else
272  return false;
273 
274  return true;
275 }
276 bool KeyboardTranslatorReader::parseAsKeyCode(const QString& item , int& keyCode)
277 {
278  QKeySequence sequence = QKeySequence::fromString(item);
279  if (!sequence.isEmpty()) {
280  keyCode = sequence[0];
281 
282  if (sequence.count() > 1) {
283  kWarning() << "Unhandled key codes in sequence: " << item;
284  }
285  // additional cases implemented for backwards compatibility with KDE 3
286  } else if (item == "prior") { // TODO: remove it in the future
287  keyCode = Qt::Key_PageUp;
288  } else if (item == "next") { // TODO: remove it in the future
289  keyCode = Qt::Key_PageDown;
290  } else {
291  return false;
292  }
293 
294  return true;
295 }
296 
297 QString KeyboardTranslatorReader::description() const
298 {
299  return _description;
300 }
301 bool KeyboardTranslatorReader::hasNextEntry()
302 {
303  return _hasNext;
304 }
305 KeyboardTranslator::Entry KeyboardTranslatorReader::createEntry(const QString& condition ,
306  const QString& result)
307 {
308  QString entryString("keyboard \"temporary\"\nkey ");
309  entryString.append(condition);
310  entryString.append(" : ");
311 
312  // if 'result' is the name of a command then the entry result will be that command,
313  // otherwise the result will be treated as a string to echo when the key sequence
314  // specified by 'condition' is pressed
315  KeyboardTranslator::Command command;
316  if (parseAsCommand(result, command))
317  entryString.append(result);
318  else
319  entryString.append('\"' + result + '\"');
320 
321  QByteArray array = entryString.toUtf8();
322  QBuffer buffer(&array);
323  buffer.open(QIODevice::ReadOnly);
324  KeyboardTranslatorReader reader(&buffer);
325 
326  KeyboardTranslator::Entry entry;
327  if (reader.hasNextEntry())
328  entry = reader.nextEntry();
329 
330  return entry;
331 }
332 
333 KeyboardTranslator::Entry KeyboardTranslatorReader::nextEntry()
334 {
335  Q_ASSERT(_hasNext);
336  KeyboardTranslator::Entry entry = _nextEntry;
337  readNext();
338  return entry;
339 }
340 bool KeyboardTranslatorReader::parseError()
341 {
342  return false;
343 }
344 QList<KeyboardTranslatorReader::Token> KeyboardTranslatorReader::tokenize(const QString& line)
345 {
346  QString text = line;
347 
348  // remove comments
349  bool inQuotes = false;
350  int commentPos = -1;
351  for (int i = text.length() - 1; i >= 0; i--) {
352  QChar ch = text[i];
353  if (ch == '\"')
354  inQuotes = !inQuotes;
355  else if (ch == '#' && !inQuotes)
356  commentPos = i;
357  }
358  if (commentPos != -1)
359  text.remove(commentPos, text.length());
360 
361  text = text.simplified();
362 
363  // title line: keyboard "title"
364  static QRegExp title("keyboard\\s+\"(.*)\"");
365  // key line: key KeySequence : "output"
366  // key line: key KeySequence : command
367  static QRegExp key("key\\s+([\\w\\+\\s\\-\\*\\.]+)\\s*:\\s*(\"(.*)\"|\\w+)");
368 
369  QList<Token> list;
370  if (text.isEmpty()) {
371  return list;
372  }
373 
374  if (title.exactMatch(text)) {
375  Token titleToken = { Token::TitleKeyword , QString() };
376  Token textToken = { Token::TitleText , title.capturedTexts()[1] };
377 
378  list << titleToken << textToken;
379  } else if (key.exactMatch(text)) {
380  Token keyToken = { Token::KeyKeyword , QString() };
381  Token sequenceToken = { Token::KeySequence , key.capturedTexts()[1].remove(' ') };
382 
383  list << keyToken << sequenceToken;
384 
385  if (key.capturedTexts()[3].isEmpty()) {
386  // capturedTexts()[2] is a command
387  Token commandToken = { Token::Command , key.capturedTexts()[2] };
388  list << commandToken;
389  } else {
390  // capturedTexts()[3] is the output string
391  Token outputToken = { Token::OutputText , key.capturedTexts()[3] };
392  list << outputToken;
393  }
394  } else {
395  kWarning() << "Line in keyboard translator file could not be understood:" << text;
396  }
397 
398  return list;
399 }
400 
401 KeyboardTranslator::Entry::Entry()
402  : _keyCode(0)
403  , _modifiers(Qt::NoModifier)
404  , _modifierMask(Qt::NoModifier)
405  , _state(NoState)
406  , _stateMask(NoState)
407  , _command(NoCommand)
408 {
409 }
410 
411 bool KeyboardTranslator::Entry::operator==(const Entry& rhs) const
412 {
413  return _keyCode == rhs._keyCode &&
414  _modifiers == rhs._modifiers &&
415  _modifierMask == rhs._modifierMask &&
416  _state == rhs._state &&
417  _stateMask == rhs._stateMask &&
418  _command == rhs._command &&
419  _text == rhs._text;
420 }
421 
422 bool KeyboardTranslator::Entry::matches(int testKeyCode,
423  Qt::KeyboardModifiers testKeyboardModifiers,
424  States testState) const
425 {
426  if (_keyCode != testKeyCode)
427  return false;
428 
429  if ((testKeyboardModifiers & _modifierMask) != (_modifiers & _modifierMask))
430  return false;
431 
432  // if testKeyboardModifiers is non-zero, the 'any modifier' state is implicit
433  if (testKeyboardModifiers != 0)
434  testState |= AnyModifierState;
435 
436  if ((testState & _stateMask) != (_state & _stateMask))
437  return false;
438 
439  // special handling for the 'Any Modifier' state, which checks for the presence of
440  // any or no modifiers. In this context, the 'keypad' modifier does not count.
441  bool anyModifiersSet = (testKeyboardModifiers != 0)
442  && (testKeyboardModifiers != Qt::KeypadModifier);
443  bool wantAnyModifier = _state & KeyboardTranslator::AnyModifierState;
444  if (_stateMask & KeyboardTranslator::AnyModifierState) {
445  if (wantAnyModifier != anyModifiersSet)
446  return false;
447  }
448 
449  return true;
450 }
451 QByteArray KeyboardTranslator::Entry::escapedText(bool expandWildCards,
452  Qt::KeyboardModifiers keyboardModifiers) const
453 {
454  QByteArray result(text(expandWildCards, keyboardModifiers));
455 
456  for (int i = 0 ; i < result.count() ; i++) {
457  const char ch = result[i];
458  char replacement = 0;
459 
460  switch (ch) {
461  case 27 : replacement = 'E'; break;
462  case 8 : replacement = 'b'; break;
463  case 12 : replacement = 'f'; break;
464  case 9 : replacement = 't'; break;
465  case 13 : replacement = 'r'; break;
466  case 10 : replacement = 'n'; break;
467  default:
468  // any character which is not printable is replaced by an equivalent
469  // \xhh escape sequence (where 'hh' are the corresponding hex digits)
470  if (!QChar(ch).isPrint())
471  replacement = 'x';
472  }
473 
474  if (replacement == 'x') {
475  result.replace(i, 1, "\\x" + QByteArray(1, ch).toHex());
476  } else if (replacement != 0) {
477  result.remove(i, 1);
478  result.insert(i, '\\');
479  result.insert(i + 1, replacement);
480  }
481  }
482 
483  return result;
484 }
485 QByteArray KeyboardTranslator::Entry::unescape(const QByteArray& input) const
486 {
487  QByteArray result(input);
488 
489  for (int i = 0 ; i < result.count() - 1 ; i++) {
490  QByteRef ch = result[i];
491  if (ch == '\\') {
492  char replacement[2] = {0, 0};
493  int charsToRemove = 2;
494  bool escapedChar = true;
495 
496  switch (result[i + 1]) {
497  case 'E' : replacement[0] = 27; break;
498  case 'b' : replacement[0] = 8 ; break;
499  case 'f' : replacement[0] = 12; break;
500  case 't' : replacement[0] = 9 ; break;
501  case 'r' : replacement[0] = 13; break;
502  case 'n' : replacement[0] = 10; break;
503  case 'x' : {
504  // format is \xh or \xhh where 'h' is a hexadecimal
505  // digit from 0-9 or A-F which should be replaced
506  // with the corresponding character value
507  char hexDigits[3] = {0};
508 
509  if ((i < result.count() - 2) && isxdigit(result[i + 2]))
510  hexDigits[0] = result[i + 2];
511  if ((i < result.count() - 3) && isxdigit(result[i + 3]))
512  hexDigits[1] = result[i + 3];
513 
514  unsigned charValue = 0;
515  sscanf(hexDigits, "%2x", &charValue);
516 
517  replacement[0] = static_cast<char>(charValue);
518  charsToRemove = 2 + qstrlen(hexDigits);
519  }
520  break;
521  default:
522  escapedChar = false;
523  }
524 
525  if (escapedChar)
526  result.replace(i, charsToRemove, replacement);
527  }
528  }
529 
530  return result;
531 }
532 
533 void KeyboardTranslator::Entry::insertModifier(QString& item , int modifier) const
534 {
535  if (!(modifier & _modifierMask))
536  return;
537 
538  if (modifier & _modifiers)
539  item += '+';
540  else
541  item += '-';
542 
543  if (modifier == Qt::ShiftModifier)
544  item += "Shift";
545  else if (modifier == Qt::ControlModifier)
546  item += "Ctrl";
547  else if (modifier == Qt::AltModifier)
548  item += "Alt";
549  else if (modifier == Qt::MetaModifier)
550  item += "Meta";
551  else if (modifier == Qt::KeypadModifier)
552  item += "KeyPad";
553 }
554 void KeyboardTranslator::Entry::insertState(QString& item, int aState) const
555 {
556  if (!(aState & _stateMask))
557  return;
558 
559  if (aState & _state)
560  item += '+';
561  else
562  item += '-';
563 
564  if (aState == KeyboardTranslator::AlternateScreenState)
565  item += "AppScreen";
566  else if (aState == KeyboardTranslator::NewLineState)
567  item += "NewLine";
568  else if (aState == KeyboardTranslator::AnsiState)
569  item += "Ansi";
570  else if (aState == KeyboardTranslator::CursorKeysState)
571  item += "AppCursorKeys";
572  else if (aState == KeyboardTranslator::AnyModifierState)
573  item += "AnyModifier";
574  else if (aState == KeyboardTranslator::ApplicationKeypadState)
575  item += "AppKeypad";
576 }
577 QString KeyboardTranslator::Entry::resultToString(bool expandWildCards,
578  Qt::KeyboardModifiers keyboardModifiers) const
579 {
580  if (!_text.isEmpty())
581  return escapedText(expandWildCards, keyboardModifiers);
582  else if (_command == EraseCommand)
583  return "Erase";
584  else if (_command == ScrollPageUpCommand)
585  return "ScrollPageUp";
586  else if (_command == ScrollPageDownCommand)
587  return "ScrollPageDown";
588  else if (_command == ScrollLineUpCommand)
589  return "ScrollLineUp";
590  else if (_command == ScrollLineDownCommand)
591  return "ScrollLineDown";
592  else if (_command == ScrollUpToTopCommand)
593  return "ScrollUpToTop";
594  else if (_command == ScrollDownToBottomCommand)
595  return "ScrollDownToBottom";
596 
597  return QString();
598 }
599 QString KeyboardTranslator::Entry::conditionToString() const
600 {
601  QString result = QKeySequence(_keyCode).toString();
602 
603  insertModifier(result , Qt::ShiftModifier);
604  insertModifier(result , Qt::ControlModifier);
605  insertModifier(result , Qt::AltModifier);
606  insertModifier(result , Qt::MetaModifier);
607  insertModifier(result , Qt::KeypadModifier);
608 
609  insertState(result , KeyboardTranslator::AlternateScreenState);
610  insertState(result , KeyboardTranslator::NewLineState);
611  insertState(result , KeyboardTranslator::AnsiState);
612  insertState(result , KeyboardTranslator::CursorKeysState);
613  insertState(result , KeyboardTranslator::AnyModifierState);
614  insertState(result , KeyboardTranslator::ApplicationKeypadState);
615 
616  return result;
617 }
618 
619 KeyboardTranslator::KeyboardTranslator(const QString& aName)
620  : _name(aName)
621 {
622 }
623 
624 FallbackKeyboardTranslator::FallbackKeyboardTranslator()
625  : KeyboardTranslator("fallback")
626 {
627  setDescription("Fallback Keyboard Translator");
628 
629  // Key "TAB" should send out '\t'
630  KeyboardTranslator::Entry entry;
631  entry.setKeyCode(Qt::Key_Tab);
632  entry.setText("\t");
633  addEntry(entry);
634 }
635 
636 void KeyboardTranslator::setDescription(const QString& aDescription)
637 {
638  _description = aDescription;
639 }
640 
641 QString KeyboardTranslator::description() const
642 {
643  return _description;
644 }
645 
646 void KeyboardTranslator::setName(const QString& aName)
647 {
648  _name = aName;
649 }
650 
651 QString KeyboardTranslator::name() const
652 {
653  return _name;
654 }
655 
656 QList<KeyboardTranslator::Entry> KeyboardTranslator::entries() const
657 {
658  return _entries.values();
659 }
660 
661 void KeyboardTranslator::addEntry(const Entry& entry)
662 {
663  const int keyCode = entry.keyCode();
664  _entries.insert(keyCode, entry);
665 }
666 
667 void KeyboardTranslator::replaceEntry(const Entry& existing , const Entry& replacement)
668 {
669  if (!existing.isNull())
670  _entries.remove(existing.keyCode(), existing);
671 
672  _entries.insert(replacement.keyCode(), replacement);
673 }
674 
675 void KeyboardTranslator::removeEntry(const Entry& entry)
676 {
677  _entries.remove(entry.keyCode(), entry);
678 }
679 
680 KeyboardTranslator::Entry KeyboardTranslator::findEntry(int keyCode, Qt::KeyboardModifiers modifiers, States state) const
681 {
682  foreach(const Entry & entry, _entries.values(keyCode)) {
683  if (entry.matches(keyCode, modifiers, state))
684  return entry;
685  }
686 
687  return Entry(); // No matching entry
688 }
QIODevice
Konsole::KeyboardTranslator::State
State
The meaning of a particular key sequence may depend upon the state which the terminal emulation is in...
Definition: KeyboardTranslator.h:63
Konsole::KeyboardTranslator::Entry::keyCode
int keyCode() const
Returns the character code ( from the Qt::Key enum ) associated with this entry.
Definition: KeyboardTranslator.h:442
Konsole::KeyboardTranslator
A converter which maps between key sequences pressed by the user and the character strings which shou...
Definition: KeyboardTranslator.h:52
QString::append
QString & append(QChar ch)
QIODevice::isWritable
bool isWritable() const
Konsole::KeyboardTranslator::EraseCommand
Echos the operating system specific erase character.
Definition: KeyboardTranslator.h:112
Konsole::FallbackKeyboardTranslator::FallbackKeyboardTranslator
FallbackKeyboardTranslator()
Definition: KeyboardTranslator.cpp:624
QIODevice::atEnd
virtual bool atEnd() const
Konsole::KeyboardTranslator::Entry::setKeyCode
void setKeyCode(int aKeyCode)
Sets the character code associated with this entry.
Definition: KeyboardTranslator.h:446
QByteArray
QKeySequence::count
uint count() const
Konsole::KeyboardTranslator::removeEntry
void removeEntry(const Entry &entry)
Removes an entry from the table.
Definition: KeyboardTranslator.cpp:675
Konsole::KeyboardTranslator::description
QString description() const
Returns the descriptive name of this keyboard translator.
Definition: KeyboardTranslator.cpp:641
Konsole::KeyboardTranslator::Entry::resultToString
QString resultToString(bool expandWildCards=false, Qt::KeyboardModifiers modifiers=Qt::NoModifier) const
Returns this entry's result ( ie.
Definition: KeyboardTranslator.cpp:577
Konsole::KeyboardTranslator::Entry::escapedText
QByteArray escapedText(bool expandWildCards=false, Qt::KeyboardModifiers modifiers=Qt::NoModifier) const
Returns the character sequence associated with this entry, with any non-printable characters replaced...
Definition: KeyboardTranslator.cpp:451
Konsole::KeyboardTranslator::ScrollLineDownCommand
Scroll the terminal display down one line.
Definition: KeyboardTranslator.h:106
QChar
Konsole::KeyboardTranslatorReader::hasNextEntry
bool hasNextEntry()
Returns true if there is another entry in the source stream.
Definition: KeyboardTranslator.cpp:301
Konsole::KeyboardTranslator::ScrollUpToTopCommand
Scroll the terminal display up to the start of history.
Definition: KeyboardTranslator.h:108
Konsole::KeyboardTranslator::CursorKeysState
TODO More documentation.
Definition: KeyboardTranslator.h:78
Konsole::KeyboardTranslator::Entry
Represents an association between a key sequence pressed by the user and the character sequence and c...
Definition: KeyboardTranslator.h:121
Konsole::KeyboardTranslatorWriter::KeyboardTranslatorWriter
KeyboardTranslatorWriter(QIODevice *destination)
Constructs a new writer which saves data into destination.
Definition: KeyboardTranslator.cpp:40
Konsole::KeyboardTranslator::AnyModifierState
Indicates that any of the modifier keys is active.
Definition: KeyboardTranslator.h:85
QString::simplified
QString simplified() const
QBuffer
QByteArray::insert
QByteArray & insert(int i, char ch)
Konsole::KeyboardTranslator::AlternateScreenState
Indicates that the alternate screen ( typically used by interactive programs such as screen or vim ) ...
Definition: KeyboardTranslator.h:83
Konsole::KeyboardTranslator::NoState
Indicates that no special state is active.
Definition: KeyboardTranslator.h:65
QString::remove
QString & remove(int position, int n)
Konsole::KeyboardTranslator::entries
QList< Entry > entries() const
Returns a list of all entries in the translator.
Definition: KeyboardTranslator.cpp:656
Konsole::KeyboardTranslatorReader::createEntry
static KeyboardTranslator::Entry createEntry(const QString &condition, const QString &result)
Parses a condition and result string for a translator entry and produces a keyboard translator entry...
Definition: KeyboardTranslator.cpp:305
Konsole::KeyboardTranslatorWriter::writeHeader
void writeHeader(const QString &description)
Writes the header for the keyboard translator.
Definition: KeyboardTranslator.cpp:51
Konsole::KeyboardTranslator::Entry::operator==
bool operator==(const Entry &rhs) const
Definition: KeyboardTranslator.cpp:411
QTextStream
QString::clear
void clear()
Konsole::KeyboardTranslatorReader
Parses the contents of a Keyboard Translator (.keytab) file and returns the entries found in it...
Definition: KeyboardTranslator.h:354
QRegExp
QChar::isPrint
bool isPrint() const
Konsole::KeyboardTranslatorReader::KeyboardTranslatorReader
KeyboardTranslatorReader(QIODevice *source)
Constructs a new reader which parses the given source.
Definition: KeyboardTranslator.cpp:85
Konsole::KeyboardTranslator::setName
void setName(const QString &name)
Sets the name of this keyboard translator.
Definition: KeyboardTranslator.cpp:646
QString::fromLocal8Bit
QString fromLocal8Bit(const char *str, int size)
QKeySequence::fromString
QKeySequence fromString(const QString &str, SequenceFormat format)
KeyboardTranslator.h
Konsole::KeyboardTranslator::KeyboardTranslator
KeyboardTranslator(const QString &name)
Constructs a new keyboard translator with the given name.
Definition: KeyboardTranslator.cpp:619
Konsole::KeyboardTranslator::AnsiState
Indicates that the terminal is in 'ANSI' mode.
Definition: KeyboardTranslator.h:74
Konsole::KeyboardTranslator::ScrollPageDownCommand
Scroll the terminal display down one page.
Definition: KeyboardTranslator.h:102
QList::isEmpty
bool isEmpty() const
QString::isEmpty
bool isEmpty() const
QByteArray::replace
QByteArray & replace(int pos, int len, const char *after)
Konsole::KeyboardTranslator::Entry::setModifiers
void setModifiers(Qt::KeyboardModifiers modifiers)
See modifiers()
Definition: KeyboardTranslator.h:451
Konsole::KeyboardTranslator::Entry::setModifierMask
void setModifierMask(Qt::KeyboardModifiers modifiers)
See modifierMask() and modifiers()
Definition: KeyboardTranslator.h:460
QBuffer::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > flags)
QByteArray::count
int count(char ch) const
Konsole::KeyboardTranslatorWriter::writeEntry
void writeEntry(const KeyboardTranslator::Entry &entry)
Writes a translator entry.
Definition: KeyboardTranslator.cpp:55
QList::first
T & first()
QString
Konsole::KeyboardTranslator::findEntry
Entry findEntry(int keyCode, Qt::KeyboardModifiers modifiers, States state=NoState) const
Looks for an entry in this keyboard translator which matches the given key code, keyboard modifiers a...
Definition: KeyboardTranslator.cpp:680
QList
Konsole::KeyboardTranslatorReader::description
QString description() const
Returns the description text.
Definition: KeyboardTranslator.cpp:297
Konsole::KeyboardTranslator::addEntry
void addEntry(const Entry &entry)
Adds an entry to this keyboard translator's table.
Definition: KeyboardTranslator.cpp:661
Konsole::KeyboardTranslator::Entry::Entry
Entry()
Constructs a new entry for a keyboard translator.
Definition: KeyboardTranslator.cpp:401
QKeySequence::isEmpty
bool isEmpty() const
Konsole::KeyboardTranslator::ScrollDownToBottomCommand
Scroll the terminal display down to the end of history.
Definition: KeyboardTranslator.h:110
Konsole::KeyboardTranslator::Entry::command
Command command() const
Returns the commands associated with this entry.
Definition: KeyboardTranslator.h:478
Konsole::KeyboardTranslator::Entry::isNull
bool isNull() const
Returns true if this entry is null.
Definition: KeyboardTranslator.h:469
Konsole::KeyboardTranslator::Entry::setState
void setState(States aState)
See state()
Definition: KeyboardTranslator.h:511
Konsole::KeyboardTranslator::name
QString name() const
Returns the name of this keyboard translator.
Definition: KeyboardTranslator.cpp:651
QKeySequence::toString
QString toString(SequenceFormat format) const
Konsole::KeyboardTranslator::NewLineState
TODO More documentation.
Definition: KeyboardTranslator.h:69
Konsole::KeyboardTranslator::Entry::setText
void setText(const QByteArray &aText)
Sets the character sequence associated with this entry.
Definition: KeyboardTranslator.h:483
QKeySequence
QString::count
int count() const
Konsole::KeyboardTranslator::NoCommand
Indicates that no command is associated with this command sequence.
Definition: KeyboardTranslator.h:96
Konsole::KeyboardTranslatorReader::nextEntry
KeyboardTranslator::Entry nextEntry()
Returns the next entry found in the source stream.
Definition: KeyboardTranslator.cpp:333
Konsole::KeyboardTranslator::Command
Command
This enum describes commands which are associated with particular key sequences.
Definition: KeyboardTranslator.h:94
Konsole::KeyboardTranslatorReader::parseError
bool parseError()
Returns true if an error occurred whilst parsing the input or false if no error occurred.
Definition: KeyboardTranslator.cpp:340
Konsole::KeyboardTranslator::ScrollPageUpCommand
Scroll the terminal display up one page.
Definition: KeyboardTranslator.h:100
QString::length
int length() const
Konsole::KeyboardTranslator::ScrollLineUpCommand
Scroll the terminal display up one line.
Definition: KeyboardTranslator.h:104
Konsole::KeyboardTranslator::Entry::conditionToString
QString conditionToString() const
Returns the key code and modifiers associated with this entry as a QKeySequence.
Definition: KeyboardTranslator.cpp:599
Konsole::KeyboardTranslator::ApplicationKeypadState
Indicates that the numpad is in application mode.
Definition: KeyboardTranslator.h:87
Konsole::KeyboardTranslator::Entry::setStateMask
void setStateMask(States aStateMask)
See stateMask()
Definition: KeyboardTranslator.h:520
Konsole::KeyboardTranslatorWriter::~KeyboardTranslatorWriter
~KeyboardTranslatorWriter()
Definition: KeyboardTranslator.cpp:47
Konsole::KeyboardTranslator::replaceEntry
void replaceEntry(const Entry &existing, const Entry &replacement)
Replaces an entry in the translator.
Definition: KeyboardTranslator.cpp:667
QString::compare
int compare(const QString &other) const
QByteArray::remove
QByteArray & remove(int pos, int len)
Konsole::KeyboardTranslator::Entry::setCommand
void setCommand(Command aCommand)
Sets the command associated with this entry.
Definition: KeyboardTranslator.h:474
Konsole::KeyboardTranslator::setDescription
void setDescription(const QString &description)
Sets the descriptive name of this keyboard translator.
Definition: KeyboardTranslator.cpp:636
Konsole::KeyboardTranslator::Entry::matches
bool matches(int keyCode, Qt::KeyboardModifiers modifiers, States flags) const
Returns true if this entry matches the given key sequence, specified as a combination of keyCode ...
Definition: KeyboardTranslator.cpp:422
QChar::isLetterOrNumber
bool isLetterOrNumber() const
QIODevice::readLine
qint64 readLine(char *data, qint64 maxSize)
Qt::KeyboardModifiers
typedef KeyboardModifiers
QString::toUtf8
QByteArray toUtf8() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal