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