Commit 4a35037a authored by Robert Knight's avatar Robert Knight
Browse files

Use type-safe QFlags for State and Command enums and Qt::KeyboardModifiers...

Use type-safe QFlags for State and Command enums and Qt::KeyboardModifiers instead of Qt::KeyboardModifier where appropriate.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=680117
parent 1397ace2
......@@ -227,10 +227,10 @@ void KeyboardTranslatorReader::readNext()
const QList<Token>& tokens = tokenize( QString(_source->readLine()) );
if ( !tokens.isEmpty() && tokens.first().type == Token::KeyKeyword )
{
KeyboardTranslator::State flags = KeyboardTranslator::NoState;
KeyboardTranslator::State flagMask = KeyboardTranslator::NoState;
Qt::KeyboardModifier modifiers = Qt::NoModifier;
Qt::KeyboardModifier modifierMask = Qt::NoModifier;
KeyboardTranslator::States flags = KeyboardTranslator::NoState;
KeyboardTranslator::States flagMask = KeyboardTranslator::NoState;
Qt::KeyboardModifiers modifiers = Qt::NoModifier;
Qt::KeyboardModifiers modifierMask = Qt::NoModifier;
int keyCode = Qt::Key_unknown;
......@@ -294,19 +294,19 @@ void KeyboardTranslatorReader::readNext()
bool KeyboardTranslatorReader::decodeSequence(const QString& text,
int& keyCode,
Qt::KeyboardModifier& modifiers,
Qt::KeyboardModifier& modifierMask,
KeyboardTranslator::State& flags,
KeyboardTranslator::State& flagMask)
Qt::KeyboardModifiers& modifiers,
Qt::KeyboardModifiers& modifierMask,
KeyboardTranslator::States& flags,
KeyboardTranslator::States& flagMask)
{
bool isWanted = true;
bool endOfItem = false;
QString buffer;
int tempModifiers = modifiers;
int tempModifierMask = modifierMask;
int tempFlags = flags;
int tempFlagMask = flagMask;
Qt::KeyboardModifiers tempModifiers = modifiers;
Qt::KeyboardModifiers tempModifierMask = modifierMask;
KeyboardTranslator::States tempFlags = flags;
KeyboardTranslator::States tempFlagMask = flagMask;
// qDebug() << "Input text:" << text;
......@@ -324,9 +324,9 @@ bool KeyboardTranslatorReader::decodeSequence(const QString& text,
if ( (endOfItem || isLastLetter) && !buffer.isEmpty() )
{
int itemModifier = 0;
Qt::KeyboardModifier itemModifier = Qt::NoModifier;
int itemKeyCode = 0;
int itemFlag = 0;
KeyboardTranslator::State itemFlag = KeyboardTranslator::NoState;
if ( parseAsModifier(buffer,itemModifier) )
{
......@@ -368,15 +368,15 @@ bool KeyboardTranslatorReader::decodeSequence(const QString& text,
isWanted = false;
}
modifiers = (Qt::KeyboardModifier)tempModifiers;
modifierMask = (Qt::KeyboardModifier)tempModifierMask;
flags = (KeyboardTranslator::State)tempFlags;
flagMask = (KeyboardTranslator::State)tempFlagMask;
modifiers = tempModifiers;
modifierMask = tempModifierMask;
flags = tempFlags;
flagMask = tempFlagMask;
return true;
}
bool KeyboardTranslatorReader::parseAsModifier(const QString& item , int& modifier)
bool KeyboardTranslatorReader::parseAsModifier(const QString& item , Qt::KeyboardModifier& modifier)
{
if ( item == "shift" )
modifier = Qt::ShiftModifier;
......@@ -391,7 +391,7 @@ bool KeyboardTranslatorReader::parseAsModifier(const QString& item , int& modifi
return true;
}
bool KeyboardTranslatorReader::parseAsStateFlag(const QString& item , int& flag)
bool KeyboardTranslatorReader::parseAsStateFlag(const QString& item , KeyboardTranslator::State& flag)
{
if ( item == "appcukeys" )
flag = KeyboardTranslator::CursorKeysState;
......@@ -660,8 +660,9 @@ bool KeyboardTranslator::Entry::operator==(const Entry& rhs) const
_text == rhs._text;
}
bool KeyboardTranslator::Entry::matches(int keyCode , Qt::KeyboardModifier modifiers,
State state) const
bool KeyboardTranslator::Entry::matches(int keyCode ,
Qt::KeyboardModifiers modifiers,
States state) const
{
//qDebug() << "Checking for match" << conditionToString();
......@@ -679,7 +680,7 @@ bool KeyboardTranslator::Entry::matches(int keyCode , Qt::KeyboardModifier modif
// if modifiers is non-zero, the 'any modifier' state is implicit
if ( modifiers != 0 )
state = (State)(state | AnyModifierState);
state |= AnyModifierState;
if ( (state & _stateMask) != (_state & _stateMask) )
return false;
......@@ -922,7 +923,7 @@ void KeyboardTranslator::removeEntry(const Entry& entry)
{
_entries.remove(entry.keyCode(),entry);
}
KeyboardTranslator::Entry KeyboardTranslator::findEntry(int keyCode, Qt::KeyboardModifier modifiers, State state) const
KeyboardTranslator::Entry KeyboardTranslator::findEntry(int keyCode, Qt::KeyboardModifiers modifiers, States state) const
{
//qDebug() << "Searching for entry for key code =" << keyCode << ", modifiers =" << modifiers;
//qDebug() << "Translator keys, count: " << _entries.count() << _entries.keys();
......
......@@ -84,6 +84,7 @@ public:
/** Indicates that any of the modifier keys is active. */
AnyModifierState = 16
};
Q_DECLARE_FLAGS(States,State)
/**
* This enum describes commands which are associated with particular key sequences.
......@@ -105,6 +106,7 @@ public:
/** Toggles scroll lock mode */
ScrollLockCommand = 32
};
Q_DECLARE_FLAGS(Commands,Command)
/**
* Represents an association between a key sequence pressed by the user
......@@ -156,15 +158,15 @@ public:
* If a modifier is not set in modifierMask() then the entry matches whether the modifier
* is pressed or not.
*/
Qt::KeyboardModifier modifiers() const;
Qt::KeyboardModifiers modifiers() const;
/** Returns the keyboard modifiers which are valid in this entry. See modifiers() */
Qt::KeyboardModifier modifierMask() const;
Qt::KeyboardModifiers modifierMask() const;
/** See modifiers() */
void setModifiers( Qt::KeyboardModifier modifiers );
void setModifiers( Qt::KeyboardModifiers modifiers );
/** See modifierMask() and modifiers() */
void setModifierMask( Qt::KeyboardModifier modifiers );
void setModifierMask( Qt::KeyboardModifiers modifiers );
/**
* Returns a bitwise-OR of the enabled state flags associated with this entry.
......@@ -174,15 +176,15 @@ public:
* If a state is not set in stateMask() then the entry matches whether the terminal
* is in that state or not.
*/
State state() const;
States state() const;
/** Returns the state flags which are valid in this entry. See state() */
State stateMask() const;
States stateMask() const;
/** See state() */
void setState( State state );
void setState( States state );
/** See stateMask() */
void setStateMask( State mask );
void setStateMask( States mask );
/**
* Returns the key code and modifiers associated with this entry
......@@ -206,7 +208,9 @@ public:
* Returns true if this entry matches the given key sequence, specified
* as a combination of @p keyCode , @p modifiers and @p state.
*/
bool matches( int keyCode , Qt::KeyboardModifier modifiers , State flags ) const;
bool matches( int keyCode ,
Qt::KeyboardModifiers modifiers ,
States flags ) const;
bool operator==(const Entry& rhs) const;
......@@ -216,10 +220,10 @@ public:
QByteArray unescape(const QByteArray& text) const;
int _keyCode;
Qt::KeyboardModifier _modifiers;
Qt::KeyboardModifier _modifierMask;
State _state;
State _stateMask;
Qt::KeyboardModifiers _modifiers;
Qt::KeyboardModifiers _modifierMask;
States _state;
States _stateMask;
Command _command;
QByteArray _text;
......@@ -253,7 +257,9 @@ public:
* @param modifiers A combination of modifiers
* @param state Optional flags which specify the current state of the terminal
*/
Entry findEntry(int keyCode , Qt::KeyboardModifier modifiers , State state = NoState) const;
Entry findEntry(int keyCode ,
Qt::KeyboardModifiers modifiers ,
States state = NoState) const;
/**
* Adds an entry to this keyboard translator's table. Entries can be looked up according
......@@ -282,6 +288,8 @@ private:
QString _name;
QString _description;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(KeyboardTranslator::States);
Q_DECLARE_OPERATORS_FOR_FLAGS(KeyboardTranslator::Commands);
/**
* Parses the contents of a Keyboard Translator (.keytab) file and
......@@ -361,14 +369,14 @@ private:
void readNext();
bool decodeSequence(const QString& ,
int& keyCode,
Qt::KeyboardModifier& modifiers,
Qt::KeyboardModifier& modifierMask,
KeyboardTranslator::State& state,
KeyboardTranslator::State& stateFlags);
static bool parseAsModifier(const QString& item , int& modifier);
static bool parseAsStateFlag(const QString& item , int& modifier);
static bool parseAsKeyCode(const QString& item , int& modifier);
Qt::KeyboardModifiers& modifiers,
Qt::KeyboardModifiers& modifierMask,
KeyboardTranslator::States& state,
KeyboardTranslator::States& stateFlags);
static bool parseAsModifier(const QString& item , Qt::KeyboardModifier& modifier);
static bool parseAsStateFlag(const QString& item , KeyboardTranslator::State& state);
static bool parseAsKeyCode(const QString& item , int& keyCode);
QIODevice* _source;
QString _description;
......@@ -471,17 +479,17 @@ private:
inline int KeyboardTranslator::Entry::keyCode() const { return _keyCode; }
inline void KeyboardTranslator::Entry::setKeyCode(int keyCode) { _keyCode = keyCode; }
inline void KeyboardTranslator::Entry::setModifiers( Qt::KeyboardModifier modifier )
inline void KeyboardTranslator::Entry::setModifiers( Qt::KeyboardModifiers modifier )
{
_modifiers = modifier;
}
inline Qt::KeyboardModifier KeyboardTranslator::Entry::modifiers() const { return _modifiers; }
inline Qt::KeyboardModifiers KeyboardTranslator::Entry::modifiers() const { return _modifiers; }
inline void KeyboardTranslator::Entry::setModifierMask( Qt::KeyboardModifier mask )
inline void KeyboardTranslator::Entry::setModifierMask( Qt::KeyboardModifiers mask )
{
_modifierMask = mask;
}
inline Qt::KeyboardModifier KeyboardTranslator::Entry::modifierMask() const { return _modifierMask; }
inline Qt::KeyboardModifiers KeyboardTranslator::Entry::modifierMask() const { return _modifierMask; }
inline bool KeyboardTranslator::Entry::isNull() const
{
......@@ -500,17 +508,17 @@ inline void KeyboardTranslator::Entry::setText( const QByteArray& text )
}
inline QByteArray KeyboardTranslator::Entry::text() const { return _text; }
inline void KeyboardTranslator::Entry::setState( State state )
inline void KeyboardTranslator::Entry::setState( States state )
{
_state = state;
}
inline KeyboardTranslator::State KeyboardTranslator::Entry::state() const { return _state; }
inline KeyboardTranslator::States KeyboardTranslator::Entry::state() const { return _state; }
inline void KeyboardTranslator::Entry::setStateMask( State stateMask )
inline void KeyboardTranslator::Entry::setStateMask( States stateMask )
{
_stateMask = stateMask;
}
inline KeyboardTranslator::State KeyboardTranslator::Entry::stateMask() const { return _stateMask; }
inline KeyboardTranslator::States KeyboardTranslator::Entry::stateMask() const { return _stateMask; }
}
......
......@@ -963,8 +963,8 @@ void Vt102Emulation::sendText( const QString& text )
void Vt102Emulation::sendKeyEvent( QKeyEvent* event )
{
int modifiers = event->modifiers();
int states = KeyboardTranslator::NoState;
Qt::KeyboardModifiers modifiers = event->modifiers();
KeyboardTranslator::States states = KeyboardTranslator::NoState;
// get current states
if ( getMode(MODE_NewLine) ) states |= KeyboardTranslator::NewLineState;
......@@ -977,8 +977,8 @@ void Vt102Emulation::sendKeyEvent( QKeyEvent* event )
{
KeyboardTranslator::Entry entry = _keyTranslator->findEntry(
event->key() ,
(Qt::KeyboardModifier)modifiers,
(KeyboardTranslator::State)states );
modifiers,
states );
// send result to terminal
QByteArray textToSend;
......@@ -1329,8 +1329,8 @@ char Vt102Emulation::getErase() const
{
KeyboardTranslator::Entry entry = _keyTranslator->findEntry(
Qt::Key_Backspace,
(Qt::KeyboardModifier)0,
(KeyboardTranslator::State)0);
0,
0);
if ( entry.text().count() > 0 )
return entry.text()[0];
else
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment