24 #ifndef KEYBOARDTRANSLATOR_H
25 #define KEYBOARDTRANSLATOR_H
28 #include <QtCore/QHash>
29 #include <QtCore/QMultiHash>
30 #include <QtCore/QList>
31 #include <QKeySequence>
32 #include <QtCore/QMetaType>
33 #include <QtCore/QVarLengthArray>
36 #if QT_VERSION >= 0x050100
37 # define K_GLOBAL_STATIC Q_GLOBAL_STATIC
59 # define K_GLOBAL_STATIC_STRUCT_NAME(NAME)
61 #if QT_VERSION < 0x040400
62 # define Q_BASIC_ATOMIC_INITIALIZER Q_ATOMIC_INIT
63 # define testAndSetOrdered testAndSet
66 #define K_GLOBAL_STATIC(TYPE, NAME) K_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ())
68 #define K_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \
69 static QBasicAtomicPointer<TYPE > _k_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0); \
70 static bool _k_static_##NAME##_destroyed; \
71 static struct K_GLOBAL_STATIC_STRUCT_NAME(NAME) \
75 return _k_static_##NAME##_destroyed; \
77 inline operator TYPE*() \
79 return operator->(); \
81 inline TYPE *operator->() \
83 if (!_k_static_##NAME) { \
84 if (isDestroyed()) { \
85 qFatal("Fatal Error: Accessed global static '%s *%s()' after destruction. " \
86 "Defined at %s:%d", #TYPE, #NAME, __FILE__, __LINE__); \
88 TYPE *x = new TYPE ARGS; \
89 if (!_k_static_##NAME.testAndSetOrdered(0, x) \
90 && _k_static_##NAME != x ) { \
93 static CleanUpGlobalStatic cleanUpObject = { destroy }; \
96 return _k_static_##NAME; \
98 inline TYPE &operator*() \
100 return *operator->(); \
102 static void destroy() \
104 _k_static_##NAME##_destroyed = true; \
105 TYPE *x = _k_static_##NAME; \
106 _k_static_##NAME = 0; \
165 Q_DECLARE_FLAGS(States,
State)
189 Q_DECLARE_FLAGS(Commands,
Command)
213 void setCommand(
Command command);
227 QByteArray text(
bool expandWildCards =
false,
228 Qt::KeyboardModifiers modifiers = Qt::NoModifier)
const;
231 void setText(
const QByteArray& text);
242 QByteArray escapedText(
bool expandWildCards =
false,
243 Qt::KeyboardModifiers modifiers = Qt::NoModifier)
const;
248 void setKeyCode(
int keyCode);
258 Qt::KeyboardModifiers modifiers()
const;
261 Qt::KeyboardModifiers modifierMask()
const;
264 void setModifiers( Qt::KeyboardModifiers modifiers );
266 void setModifierMask( Qt::KeyboardModifiers modifiers );
276 States
state()
const;
279 States stateMask()
const;
282 void setState( States
state );
284 void setStateMask( States mask );
296 QString conditionToString()
const;
305 QString resultToString(
bool expandWildCards =
false,
306 Qt::KeyboardModifiers modifiers = Qt::NoModifier)
const;
312 bool matches(
int keyCode ,
313 Qt::KeyboardModifiers modifiers ,
314 States flags )
const;
319 void insertModifier( QString& item ,
int modifier )
const;
320 void insertState( QString& item ,
int state )
const;
321 QByteArray unescape(
const QByteArray& text)
const;
339 QString
name()
const;
362 Qt::KeyboardModifiers modifiers ,
393 Q_DECLARE_OPERATORS_FOR_FLAGS(KeyboardTranslator::States)
394 Q_DECLARE_OPERATORS_FOR_FLAGS(KeyboardTranslator::Commands)
434 QString description()
const;
454 const QString& result );
472 bool decodeSequence(
const QString& ,
474 Qt::KeyboardModifiers& modifiers,
475 Qt::KeyboardModifiers& modifierMask,
476 KeyboardTranslator::States&
state,
477 KeyboardTranslator::States& stateFlags);
479 static bool parseAsModifier(
const QString& item , Qt::KeyboardModifier& modifier);
481 static bool parseAsKeyCode(
const QString& item ,
int& keyCode);
589 _modifiers = modifier;
595 _modifierMask = mask;
601 return ( *
this ==
Entry() );
612 _text = unescape(text);
616 return value ? 1 : 0;
620 QByteArray expandedText = _text;
624 int modifierValue = 1;
625 modifierValue +=
oneOrZero(modifiers & Qt::ShiftModifier);
626 modifierValue +=
oneOrZero(modifiers & Qt::AltModifier) << 1;
627 modifierValue +=
oneOrZero(modifiers & Qt::ControlModifier) << 2;
629 for (
int i=0;i<_text.length();i++)
631 if (expandedText[i] ==
'*')
632 expandedText[i] =
'0' + modifierValue;
647 _stateMask = stateMask;
void(* CleanUpFunction)()
Manages the keyboard translations available for use by terminal sessions, see KeyboardTranslator.
KeyboardTranslatorManager()
Constructs a new KeyboardTranslatorManager and loads the list of available keyboard translations.
static const char * defaultTranslatorText
const KeyboardTranslator * defaultTranslator()
Returns the default translator for Konsole.
QList< QString > allTranslators()
Returns a list of the names of available keyboard translators.
bool saveTranslator(const KeyboardTranslator *translator)
~KeyboardTranslatorManager()
QString findTranslatorPath(const QString &name)
KeyboardTranslator * loadTranslator(const QString &name)
const KeyboardTranslator * findTranslator(const QString &name)
Returns the keyboard translator with the given name or 0 if no translator with that name exists.
QHash< QString, KeyboardTranslator * > _translators
void addTranslator(KeyboardTranslator *translator)
Adds a new translator.
bool deleteTranslator(const QString &name)
Deletes a translator.
static KeyboardTranslatorManager * instance()
Returns the global KeyboardTranslatorManager instance.
Parses the contents of a Keyboard Translator (.keytab) file and returns the entries found in it.
KeyboardTranslator::Entry _nextEntry
Writes a keyboard translation to disk.
~KeyboardTranslatorWriter()
void writeHeader(const QString &description)
Writes the header for the keyboard translator.
void writeEntry(const KeyboardTranslator::Entry &entry)
Writes a translator entry.
KeyboardTranslatorWriter(QIODevice *destination)
Constructs a new writer which saves data into destination.
Represents an association between a key sequence pressed by the user and the character sequence and c...
void setModifiers(Qt::KeyboardModifiers modifiers)
See modifiers()
QByteArray text(bool expandWildCards=false, Qt::KeyboardModifiers modifiers=Qt::NoModifier) const
Returns the character sequence associated with this entry, optionally replacing wildcard '*' characte...
void setText(const QByteArray &text)
Sets the character sequence associated with this entry.
States state() const
Returns a bitwise-OR of the enabled state flags associated with this entry.
void setKeyCode(int keyCode)
Sets the character code associated with this entry.
Qt::KeyboardModifiers _modifiers
Command command() const
Returns the commands associated with this entry.
Qt::KeyboardModifiers _modifierMask
Qt::KeyboardModifiers modifiers() const
Returns a bitwise-OR of the enabled keyboard modifiers associated with this entry.
int keyCode() const
Returns the character code ( from the Qt::Key enum ) associated with this entry.
bool isNull() const
Returns true if this entry is null.
void setStateMask(States mask)
See stateMask()
void setCommand(Command command)
Sets the command associated with this entry.
States stateMask() const
Returns the state flags which are valid in this entry.
Qt::KeyboardModifiers modifierMask() const
Returns the keyboard modifiers which are valid in this entry.
void setState(States state)
See state()
void setModifierMask(Qt::KeyboardModifiers modifiers)
See modifierMask() and modifiers()
A convertor which maps between key sequences pressed by the user and the character strings which shou...
QString name() const
Returns the name of this keyboard translator.
State
The meaning of a particular key sequence may depend upon the state which the terminal emulation is in...
@ NewLineState
TODO More documentation.
@ NoState
Indicates that no special state is active.
@ AnyModifierState
Indicates that any of the modifier keys is active.
@ AnsiState
Indicates that the terminal is in 'Ansi' mode.
@ AlternateScreenState
Indicates that the alternate screen ( typically used by interactive programs such as screen or vim ) ...
@ CursorKeysState
TODO More documentation.
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...
QString description() const
Returns the descriptive name of this keyboard translator.
Command
This enum describes commands which are associated with particular key sequences.
@ ScrollLineUpCommand
Scroll the terminal display up one line.
@ EraseCommand
Echos the operating system specific erase character.
@ SendCommand
TODO Document me.
@ ScrollPageUpCommand
Scroll the terminal display up one page.
@ ScrollPageDownCommand
Scroll the terminal display down one page.
@ NoCommand
Indicates that no command is associated with this command sequence.
@ ScrollLockCommand
Toggles scroll lock mode.
@ ScrollLineDownCommand
Scroll the terminal display down one line.
void replaceEntry(const Entry &existing, const Entry &replacement)
Replaces an entry in the translator.
void setName(const QString &name)
Sets the name of this keyboard translator.
QList< Entry > entries() const
Returns a list of all entries in the translator.
KeyboardTranslator(const QString &name)
Constructs a new keyboard translator with the given name.
QMultiHash< int, Entry > _entries
void setDescription(const QString &description)
Sets the descriptive name of this keyboard translator.
void addEntry(const Entry &entry)
Adds an entry to this keyboard translator's table.
void removeEntry(const Entry &entry)
Removes an entry from the table.
bool operator==(const dim_vector &a, const dim_vector &b)
static uint32_t state[624]