20 #include <tqkeysequence.h>
22 #include <tqpopupmenu.h>
24 #include "tdeaccelaction.h"
26 #include <tdeglobalsettings.h>
27 #include "tdeshortcutmenu.h"
30 TDEShortcutMenu::TDEShortcutMenu( TQWidget* pParent, TDEAccelActions* pActions,
KKeySequence seq )
31 : TQPopupMenu( pParent ),
32 m_pActions( pActions ),
38 fontTitle.setBold(
true );
40 pTitle =
new TQLabel(
"", (TQWidget*)0 );
41 pTitle->setFont( fontTitle );
42 pTitle->setFrameShape( TQFrame::Panel );
47 bool TDEShortcutMenu::insertAction( uint iAction,
KKeySequence seq )
49 TDEAccelAction* pAction = m_pActions->actionPtr( iAction );
52 insertItem(
"", iAction );
53 m_seqs[indexOf(iAction)] = seq;
60 void TDEShortcutMenu::updateShortcuts()
62 pTitle->setText( m_seq.toString() +
",..." );
64 for( uint iItem = 1; iItem < count(); iItem++ ) {
65 int iAction = idAt( iItem );
67 TDEAccelAction* pAction = m_pActions->actionPtr( iAction );
71 for( uint iKey = m_seq.count() + 1; iKey < seq.
count(); iKey++ )
74 kdDebug(125) <<
"seq = " << seq.toStringInternal() <<
" sSeq = " << sSeq <<
endl;
75 changeItem( iAction, pAction->label() +
"\t" + sSeq );
81 void TDEShortcutMenu::keyPressEvent( TQKeyEvent* pEvent )
86 switch( pEvent->key() ) {
97 int iItem = searchForKey( key );
101 iItem = searchForKey( key );
107 if( pEvent->key() == TQt::Key_Up || pEvent->key() == TQt::Key_Down ||
108 pEvent->key() == TQt::Key_Enter || pEvent->key() == TQt::Key_Return )
109 TQPopupMenu::keyPressEvent( pEvent );
113 else if( iItem == 0 )
114 keepItemsMatching( key );
116 activateItemAt( iItem );
120 int TDEShortcutMenu::searchForKey(
KKey key )
123 uint iKey = m_seq.count();
125 for( uint iItem = 1; iItem < count(); iItem++ ) {
126 if( m_seqs.contains( iItem ) ) {
127 KKey keyItem = m_seqs[iItem].key( iKey );
129 if( key == keyItem ) {
130 if( iItemFound == -1 )
141 void TDEShortcutMenu::keepItemsMatching(
KKey key )
143 kdDebug(125) <<
"MyAccel::keepItemsMatching( " <<
key.toStringInternal() <<
" )" <<
endl;
145 uint iKey = m_seq.count();
146 m_seq.setKey( iKey, key );
148 for( uint iItem = 1; iItem < count(); iItem++ ) {
149 if( m_seqs.contains( iItem ) ) {
150 KKey keyItem = m_seqs[iItem].key( iKey );
151 if( key != keyItem ) {
152 m_seqs.remove( iItem );
153 removeItemAt( iItem-- );
161 #include "tdeshortcutmenu.moc"
A KKeySequence object holds a sequence of up to 4 keys.
uint count() const
Returns the number of key strokes of this sequence.
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.
A KKey object represents a single key with possible modifiers (Shift, Ctrl, Alt, Win).
TQString toString() const
Returns a human-readable representation of the key in the form "modifier+key".
static TQFont menuFont()
Returns the default menu font.
kdbgstream kdDebug(int area=0)
Returns a debug stream.
kdbgstream & endl(kdbgstream &s)
Prints an "\n".
TDEAction * close(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)