20 #include "tdeshortcut.h"
21 #include "kkeynative.h"
22 #include "kkeyserver.h"
25 #include <tqstringlist.h>
28 #include <tdeglobal.h>
30 #include <ksimpleconfig.h>
34 static KKey* g_pspec = 0;
86 return init( (
int) key );
91 int keyQt = pEvent->key();
92 if( pEvent->state() & TQt::ShiftButton ) keyQt |= Qt::SHIFT;
93 if( pEvent->state() & TQt::ControlButton ) keyQt |= Qt::CTRL;
94 if( pEvent->state() & TQt::AltButton ) keyQt |= Qt::ALT;
95 if( pEvent->state() & TQt::MetaButton ) keyQt |= Qt::META;
110 TQString sKey = sSpec.stripWhiteSpace();
111 if( sKey.startsWith(
"default(" ) && sKey.endsWith(
")" ) )
112 sKey = sKey.mid( 8, sKey.length() - 9 );
114 if( sKey.endsWith(
"++" ) )
115 sKey = sKey.left( sKey.length() - 1 ) +
"plus";
116 TQStringList rgs = TQStringList::split(
'+', sKey,
true );
120 for( i = 0; i < rgs.size(); i++ ) {
121 TQString s = rgs[i].lower();
122 if( s ==
"shift" ) m_mod |= KKey::SHIFT;
123 else if( s ==
"ctrl" ) m_mod |= KKey::CTRL;
124 else if( s ==
"alt" ) m_mod |= KKey::ALT;
125 else if( s ==
"win" ) m_mod |= KKey::WIN;
126 else if( s ==
"meta" ) m_mod |= KKey::WIN;
129 if( m != 0 ) m_mod |= m;
134 if( (i == rgs.size() - 1 && !rgs[i].isEmpty()) ) {
142 kdDebug(125) <<
"KKey::init( \"" << sSpec <<
"\" ):"
143 <<
" m_sym = " << TQString::number(m_sym, 16)
144 <<
", m_mod = " << TQString::number(m_mod, 16) <<
endl;
150 uint KKey::sym()
const {
return m_sym; }
151 uint KKey::modFlags()
const {
return m_mod; }
155 if( m_sym != spec.m_sym )
156 return m_sym - spec.m_sym;
157 if( m_mod != spec.m_mod )
158 return m_mod - spec.m_mod;
186 s = KKeyServer::modToStringInternal( m_mod );
217 KKeySequence::~KKeySequence()
224 m_bTriggerOnRelease =
false;
230 if( !seq.isEmpty() ) {
231 for( uint i = 0; i < seq.count(); i++ ) {
232 m_rgvar[i].
init( seq[i] );
236 m_nKeys = seq.count();
237 m_bTriggerOnRelease =
false;
246 m_rgvar[0].
init( key );
247 m_bTriggerOnRelease =
false;
255 m_bTriggerOnRelease =
false;
256 m_nKeys = seq.m_nKeys;
257 for( uint i = 0; i < m_nKeys; i++ ) {
258 if( seq.m_rgvar[i].
isNull() ) {
259 kdDebug(125) <<
"KKeySequence::init( seq ): key[" << i <<
"] is null." <<
endl;
263 m_rgvar[i] = seq.m_rgvar[i];
270 m_bTriggerOnRelease =
false;
272 TQStringList rgs = TQStringList::split(
',', s );
273 if( s ==
"none" || rgs.size() == 0 ) {
276 }
else if( rgs.size() <= MAX_KEYS ) {
277 m_nKeys = rgs.size();
278 for( uint i = 0; i < m_nKeys; i++ ) {
302 bool KKeySequence::isTriggerOnRelease()
const
303 {
return m_bTriggerOnRelease; }
307 if( iKey <= m_nKeys && iKey < MAX_KEYS ) {
308 m_rgvar[iKey].
init( key );
309 if( iKey == m_nKeys )
323 if( m_nKeys < seq.m_nKeys )
326 for( uint i = 0; i < seq.m_nKeys; i++ ) {
327 if( m_rgvar[i] != seq.m_rgvar[i] )
336 for( uint i = 0; i < m_nKeys && i < seq.m_nKeys; i++ ) {
337 int ret = m_rgvar[i].
compare( seq.m_rgvar[i] );
341 if( m_nKeys != seq.m_nKeys )
342 return m_nKeys - seq.m_nKeys;
349 int k[4] = { 0, 0, 0, 0 };
351 for( uint i = 0; i <
count(); i++ )
353 TQKeySequence seq( k[0], k[1], k[2], k[3] );
364 if( m_nKeys < 1 )
return TQString::null;
368 for( uint i = 1; i < m_nKeys; i++ ) {
376 TQString KKeySequence::toStringInternal()
const
378 if( m_nKeys < 1 )
return TQString::null;
382 for( uint i = 1; i < m_nKeys; i++ ) {
412 TDEShortcut::~TDEShortcut()
425 m_rgseq[0].
init( TQKeySequence(keyQt) );
436 m_rgseq[0].
init( key );
443 m_rgseq[0].
init( spec );
456 m_nSeqs = cut.m_nSeqs;
457 for( uint i = 0; i < m_nSeqs; i++ )
458 m_rgseq[i] = cut.m_rgseq[i];
465 TQStringList rgs = TQStringList::split(
';', s );
467 if( s ==
"none" || rgs.size() == 0 )
469 else if( rgs.size() <= MAX_SEQUENCES ) {
470 m_nSeqs = rgs.size();
471 for( uint i = 0; i < m_nSeqs; i++ ) {
472 TQString& sSeq = rgs[i];
473 if( sSeq.startsWith(
"default(" ) )
474 sSeq = sSeq.mid( 8, sSeq.length() - 9 );
475 m_rgseq[i].
init( sSeq );
485 TQTextStream os( &sDebug, IO_WriteOnly );
486 os <<
"TDEShortcut::init( \"" << s <<
"\" ): ";
487 for( uint i = 0; i < m_nSeqs; i++ ) {
488 os <<
" m_rgseq[" << i <<
"]: ";
490 vars.init( m_rgseq[i].key(0),
true );
491 for( uint j = 0; j < vars.count(); j++ )
492 os << TQString::number(vars.m_rgkey[j].
keyCodeQt(),16) <<
',';
494 kdDebug(125) << sDebug <<
endl;
514 return TQKeySequence();
524 for( uint i = 0; i < m_nSeqs && i < cut.m_nSeqs; i++ ) {
525 int ret = m_rgseq[i].
compare( cut.m_rgseq[i] );
529 return m_nSeqs - cut.m_nSeqs;
542 for( uint i = 0; i <
count(); i++ ) {
544 && m_rgseq[i].
count() == 1
545 && m_rgseq[i].
key(0) == key )
553 for( uint i = 0; i <
count(); i++ ) {
554 if( !m_rgseq[i].
isNull() && m_rgseq[i] ==
seq )
563 if( iSeq <= m_nSeqs && iSeq < MAX_SEQUENCES ) {
565 if( iSeq == m_nSeqs )
576 for( uint iSeq = 0; iSeq < m_nSeqs; iSeq++ )
578 if (m_rgseq[iSeq] == seq)
580 for( uint jSeq = iSeq + 1; jSeq < m_nSeqs; jSeq++)
581 m_rgseq[jSeq-1] = m_rgseq[jSeq];
589 if( m_nSeqs < MAX_SEQUENCES ) {
591 m_rgseq[m_nSeqs] =
seq;
601 if( m_nSeqs < MAX_SEQUENCES ) {
602 m_rgseq[m_nSeqs].
init( spec );
611 uint seqs = m_nSeqs, co = cut.
count();
612 for( uint i=0; i<co; i++ ) {
615 if( seqs > MAX_SEQUENCES )
return false;
617 for( uint i=0; i<co; i++ ) {
620 m_rgseq[m_nSeqs] =
seq;
627 TDEShortcut::operator TQKeySequence ()
const
630 return m_rgseq[0].qt();
632 return TQKeySequence();
639 for( uint i = 0; i <
count(); i++ ) {
641 if( i <
count() - 1 )
648 TQString TDEShortcut::toStringInternal(
const TDEShortcut* pcutDefault )
const
652 for( uint i = 0; i <
count(); i++ ) {
654 if( pcutDefault && i < pcutDefault->
count() && seq == (*pcutDefault).seq(i) ) {
656 s += seq.toStringInternal();
659 s += seq.toStringInternal();
660 if( i <
count() - 1 )
ModFlag
Flags to represent the modifiers.
KKey()
Creates a new null KKey.
const KKeySequence & seq(uint i) const
Returns the i'th key sequence of this shortcut.
static KKey & null()
Returns a null key.
int compare(const KKeySequence &keySeq) const
Compares this object with the given key sequence.
bool setKey(uint i, const KKey &key)
Sets the i'th key of the sequence.
int keyCodeQt() const
Returns the qt key code.
void clear()
Clears the key sequence.
bool contains(const KKey &key) const
Checks whether this shortcut contains a sequence that starts with the given key.
KKey key() const
Returns the KKey representation of this key.
TQKeySequence qt() const
Converts this key sequence to a TQKeySequence.
int keyCodeQt() const
Returns the qt key code of the first key.
bool isNull() const
Returns true if the shortcut is null (after clear() or empty constructor).
int keyCodeQt() const
Returns the key code of the first key sequence, or null if there is no first key sequence.
uint count() const
Returns the number of sequences that are in this shortcut.
TQString toString() const
Returns a human-readable representation of the key in the form "modifier+key".
TODO: please document this class.
bool init(const TQKeySequence &keySeq)
Copies the given qt key sequence over this key sequence.
TQString toString() const
Returns the string representation of the symbol.
bool isNull() const
Returns true if the key is null (after clear() or empty constructor).
bool init(int keyQt)
Initializes the key with the given Qt key code.
A KKeySequence object holds a sequence of up to 4 keys.
bool keyQtToMod(int keyQt, uint &mod)
Extracts the modifiers from the given Qt key and converts them in a mask of ORed KKey::ModFlag modifi...
int keyCodeQt() const
Returns the qt key code.
void clear()
Clears the key.
bool startsWith(const KKeySequence &keySeq) const
Returns true if this key sequence begins with the given sequence.
int compare(const TDEShortcut &shortcut) const
Compares this object with the given shortcut.
uint m_sym
the actual value of the symbol
const KKey & key(uint i) const
Return the i'th key of this sequence, or a null key if there are less then i keys.
static KKeySequence & null()
Returns a null key sequence.
KKeySequence()
Create a new null key sequence.
TQString toString() const
Returns the key sequence as a number of key presses as returned by KKey::toString(), separated by commas.
Representation of a key in the format native of the windowing system (eg.
TQString toString() const
Returns a description of the shortcut as semicolon-separated ket sequences, as returned by KKeySequen...
bool setSeq(uint i, const KKeySequence &keySeq)
Sets the i 'th key sequence of the shortcut.
uint stringUserToMod(const TQString &mod)
Converts the modifier given as user-readable string to KKey::ModFlag modifier, or 0...
TQString modToStringUser(uint mod)
Converts the mask of ORed KKey::ModFlag modifiers to a user-readable string.
A KKey object represents a single key with possible modifiers (Shift, Ctrl, Alt, Win).
The TDEShortcut class is used to represent a keyboard shortcut to an action.
TQString toStringInternal() const
Returns an untranslated text representation of the key in the form "modifier+key", suitable e.g.
int keyCodeQt() const
Returns the qt key code.
static TDEShortcut & null()
Returns a null shortcut.
bool append(const KKeySequence &keySeq)
Appends the given key sequence.
static TQString modFlagLabel(ModFlag f)
Returns a user-readable representation of the given modifiers.
TDEShortcut()
Creates a new null shortcut.
kndbgstream & endl(kndbgstream &s)
Does nothing.
bool isNull() const
Returns true if the key sequence is null (after clear() or empty constructor).
void remove(const KKeySequence &keySeq)
Removes the given key sequence from this shortcut.
void clear()
Clears the shortcut.
bool init(int keyQt)
Initializes the shortcut with the given Qt key code as the only key sequence.
int compare(const KKey &key) const
Compares this key with the given KKey object.
uint count() const
Returns the number of key strokes of this sequence.
bool keyQtToSym(int keyQt, uint &sym)
Extracts the symbol from the given Qt key and converts it to a symbol.