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 ),
35 kdDebug() << seq.toStringInternal() <<
endl;
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 );
70 TQString sSeq = seq.
key(m_seq.count()).toString();
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 )
83 kdDebug() <<
"keypress; " << pEvent->key() <<
endl;
86 switch( pEvent->key() ) {
97 int iItem = searchForKey(
key );
101 iItem = searchForKey(
key );
107 if( pEvent->key() == Qt::Key_Up || pEvent->key() == Qt::Key_Down ||
108 pEvent->key() == Qt::Key_Enter || pEvent->key() == Qt::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 )
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"
TQString toString() const
Returns a human-readable representation of the key in the form "modifier+key".
A KKeySequence object holds a sequence of up to 4 keys.
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.
const TDEShortcut & close()
Close current document.
A KKey object represents a single key with possible modifiers (Shift, Ctrl, Alt, Win).
static TQFont menuFont()
Returns the default menu font.
TQString toStringInternal() const
Returns an untranslated text representation of the key in the form "modifier+key", suitable e.g.
kndbgstream & endl(kndbgstream &s)
Does nothing.
uint count() const
Returns the number of key strokes of this sequence.