24 #ifndef KEYBOARDTRANSLATOR_H
25 #define KEYBOARDTRANSLATOR_H
28 #include <QtCore/QHash>
29 #include <QtCore/QList>
30 #include <QKeySequence>
31 #include <QtCore/QMetaType>
32 #include <QtCore/QVarLengthArray>
54 # define K_GLOBAL_STATIC_STRUCT_NAME(NAME)
56 #if QT_VERSION < 0x040400
57 # define Q_BASIC_ATOMIC_INITIALIZER Q_ATOMIC_INIT
58 # define testAndSetOrdered testAndSet
61 #define K_GLOBAL_STATIC(TYPE, NAME) K_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ())
63 #define K_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \
64 static QBasicAtomicPointer<TYPE > _k_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0); \
65 static bool _k_static_##NAME##_destroyed; \
66 static struct K_GLOBAL_STATIC_STRUCT_NAME(NAME) \
70 return _k_static_##NAME##_destroyed; \
72 inline operator TYPE*() \
74 return operator->(); \
76 inline TYPE *operator->() \
78 if (!_k_static_##NAME) { \
79 if (isDestroyed()) { \
80 qFatal("Fatal Error: Accessed global static '%s *%s()' after destruction. " \
81 "Defined at %s:%d", #TYPE, #NAME, __FILE__, __LINE__); \
83 TYPE *x = new TYPE ARGS; \
84 if (!_k_static_##NAME.testAndSetOrdered(0, x) \
85 && _k_static_##NAME != x ) { \
88 static CleanUpGlobalStatic cleanUpObject = { destroy }; \
91 return _k_static_##NAME; \
93 inline TYPE &operator*() \
95 return *operator->(); \
97 static void destroy() \
99 _k_static_##NAME##_destroyed = true; \
100 TYPE *x = _k_static_##NAME; \
101 _k_static_##NAME = 0; \
162 Q_DECLARE_FLAGS(States,
State)
186 Q_DECLARE_FLAGS(Commands,
Command)
210 void setCommand(
Command command);
224 QByteArray
text(
bool expandWildCards =
false,
225 Qt::KeyboardModifiers modifiers = Qt::NoModifier)
const;
228 void setText(
const QByteArray& text);
239 QByteArray escapedText(
bool expandWildCards =
false,
240 Qt::KeyboardModifiers modifiers = Qt::NoModifier)
const;
245 void setKeyCode(
int keyCode);
255 Qt::KeyboardModifiers modifiers()
const;
258 Qt::KeyboardModifiers modifierMask()
const;
261 void setModifiers( Qt::KeyboardModifiers modifiers );
263 void setModifierMask( Qt::KeyboardModifiers modifiers );
273 States
state()
const;
276 States stateMask()
const;
279 void setState( States state );
281 void setStateMask( States mask );
293 QString conditionToString()
const;
302 QString resultToString(
bool expandWildCards =
false,
303 Qt::KeyboardModifiers modifiers = Qt::NoModifier)
const;
309 bool matches(
int keyCode ,
310 Qt::KeyboardModifiers modifiers ,
311 States flags )
const;
316 void insertModifier( QString& item ,
int modifier )
const;
317 void insertState( QString& item ,
int state )
const;
318 QByteArray unescape(
const QByteArray& text)
const;
336 QString
name()
const;
359 Qt::KeyboardModifiers modifiers ,
390 Q_DECLARE_OPERATORS_FOR_FLAGS(KeyboardTranslator::States)
425 KeyboardTranslatorReader( QIODevice* source );
431 QString description()
const;
451 const QString& result );
469 bool decodeSequence(
const QString& ,
471 Qt::KeyboardModifiers& modifiers,
472 Qt::KeyboardModifiers& modifierMask,
473 KeyboardTranslator::States&
state,
474 KeyboardTranslator::States& stateFlags);
476 static bool parseAsModifier(
const QString& item , Qt::KeyboardModifier& modifier);
478 static bool parseAsKeyCode(
const QString& item ,
int& keyCode);
586 _modifiers = modifier;
592 _modifierMask = mask;
598 return ( *
this ==
Entry() );
609 _text = unescape(text);
613 return value ? 1 : 0;
617 QByteArray expandedText = _text;
621 int modifierValue = 1;
622 modifierValue +=
oneOrZero(modifiers & Qt::ShiftModifier);
623 modifierValue +=
oneOrZero(modifiers & Qt::AltModifier) << 1;
624 modifierValue +=
oneOrZero(modifiers & Qt::ControlModifier) << 2;
626 for (
int i=0;i<_text.length();i++)
628 if (expandedText[i] ==
'*')
629 expandedText[i] =
'0' + modifierValue;
644 _stateMask = stateMask;
649 #endif // KEYBOARDTRANSLATOR_H
void setKeyCode(int keyCode)
Sets the character code associated with this entry.
QHash< int, Entry > _entries
Scroll the terminal display up one page.
~KeyboardTranslatorManager()
Qt::KeyboardModifiers modifierMask() const
Returns the keyboard modifiers which are valid in this entry.
static const char * defaultTranslatorText
Command
This enum describes commands which are associated with particular key sequences.
Echos the operating system specific erase character.
Qt::KeyboardModifiers _modifierMask
Command command() const
Returns the commands associated with this entry.
static uint32_t state[624]
void writeHeader(const QString &description)
Writes the header for the keyboard translator.
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...
void addTranslator(KeyboardTranslator *translator)
Adds a new translator.
bool isNull() const
Returns true if this entry is null.
QString findTranslatorPath(const QString &name)
void setModifiers(Qt::KeyboardModifiers modifiers)
See modifiers()
Indicates that no special state is active.
bool deleteTranslator(const QString &name)
Deletes a translator.
QByteArray text(bool expandWildCards=false, Qt::KeyboardModifiers modifiers=Qt::NoModifier) const
Returns the character sequence associated with this entry, optionally replacing wildcard '*' characte...
State
The meaning of a particular key sequence may depend upon the state which the terminal emulation is in...
QString description() const
Returns the descriptive name of this keyboard translator.
const KeyboardTranslator * findTranslator(const QString &name)
Returns the keyboard translator with the given name or 0 if no translator with that name exists...
void writeEntry(const KeyboardTranslator::Entry &entry)
Writes a translator entry.
States state() const
Returns a bitwise-OR of the enabled state flags associated with this entry.
void setText(const QByteArray &text)
Sets the character sequence associated with this entry.
KeyboardTranslatorWriter(QIODevice *destination)
Constructs a new writer which saves data into destination.
KeyboardTranslator(const QString &name)
Constructs a new keyboard translator with the given name.
States stateMask() const
Returns the state flags which are valid in this entry.
QList< QString > allTranslators()
Returns a list of the names of available keyboard translators.
QList< Entry > entries() const
Returns a list of all entries in the translator.
Manages the keyboard translations available for use by terminal sessions, see KeyboardTranslator.
Indicates that the alternate screen ( typically used by interactive programs such as screen or vim ) ...
Indicates that the terminal is in 'Ansi' mode.
bool saveTranslator(const KeyboardTranslator *translator)
void setStateMask(States mask)
See stateMask()
void setDescription(const QString &description)
Sets the descriptive name of this keyboard translator.
static KeyboardTranslatorManager * instance()
Returns the global KeyboardTranslatorManager instance.
Indicates that no command is associated with this command sequence.
Scroll the terminal display up one line.
void setCommand(Command command)
Sets the command associated with this entry.
void setName(const QString &name)
Sets the name of this keyboard translator.
const KeyboardTranslator * defaultTranslator()
Returns the default translator for Konsole.
A convertor which maps between key sequences pressed by the user and the character strings which shou...
void setModifierMask(Qt::KeyboardModifiers modifiers)
See modifierMask() and modifiers()
KeyboardTranslator * loadTranslator(const QString &name)
Scroll the terminal display down one line.
Parses the contents of a Keyboard Translator (.keytab) file and returns the entries found in it...
bool operator==(const dim_vector &a, const dim_vector &b)
QString name() const
Returns the name of this keyboard translator.
void(* CleanUpFunction)()
Qt::KeyboardModifiers modifiers() const
Returns a bitwise-OR of the enabled keyboard modifiers associated with this entry.
void setState(States state)
See state()
KeyboardTranslator::Entry _nextEntry
void replaceEntry(const Entry &existing, const Entry &replacement)
Replaces an entry in the translator.
Represents an association between a key sequence pressed by the user and the character sequence and c...
~KeyboardTranslatorWriter()
Writes a keyboard translation to disk.
KeyboardTranslatorManager()
Constructs a new KeyboardTranslatorManager and loads the list of available keyboard translations...
Indicates that any of the modifier keys is active.
Scroll the terminal display down one page.
QHash< QString, KeyboardTranslator * > _translators
int keyCode() const
Returns the character code ( from the Qt::Key enum ) associated with this entry.
void removeEntry(const Entry &entry)
Removes an entry from the table.
Toggles scroll lock mode.
Qt::KeyboardModifiers _modifiers
void addEntry(const Entry &entry)
Adds an entry to this keyboard translator's table.