• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
tdeshortcutmenu.cpp
1/*
2 Copyright (c) 2002 Ellis Whitehead <ellis@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include <tqkeysequence.h>
21#include <tqlabel.h>
22#include <tqpopupmenu.h>
23
24#include "tdeaccelaction.h"
25#include <kdebug.h>
26#include <tdeglobalsettings.h>
27#include "tdeshortcutmenu.h"
28//#include <kkeynative.h>
29
30TDEShortcutMenu::TDEShortcutMenu( TQWidget* pParent, TDEAccelActions* pActions, KKeySequence seq )
31: TQPopupMenu( pParent ),
32 m_pActions( pActions ),
33 m_seq( seq )
34{
35 kdDebug() << seq.toStringInternal() << endl;
36
37 TQFont fontTitle = TDEGlobalSettings::menuFont();
38 fontTitle.setBold( true );
39
40 pTitle = new TQLabel( "", (TQWidget*)0 );
41 pTitle->setFont( fontTitle );
42 pTitle->setFrameShape( TQFrame::Panel );
43
44 insertItem( pTitle );
45}
46
47bool TDEShortcutMenu::insertAction( uint iAction, KKeySequence seq )
48{
49 TDEAccelAction* pAction = m_pActions->actionPtr( iAction );
50
51 if( pAction ) {
52 insertItem( "", iAction );
53 m_seqs[indexOf(iAction)] = seq;
54 return true;
55 } else
56 return false;
57}
58
59
60void TDEShortcutMenu::updateShortcuts()
61{
62 pTitle->setText( m_seq.toString() + ",..." );
63
64 for( uint iItem = 1; iItem < count(); iItem++ ) {
65 int iAction = idAt( iItem );
66 if( iAction >= 0 ) {
67 TDEAccelAction* pAction = m_pActions->actionPtr( iAction );
68 if( pAction ) {
69 KKeySequence seq = m_seqs[iItem];
70 TQString sSeq = seq.key(m_seq.count()).toString();
71 for( uint iKey = m_seq.count() + 1; iKey < seq.count(); iKey++ )
72 sSeq += TQString(",") + seq.key(iKey).toString();
73
74 kdDebug(125) << "seq = " << seq.toStringInternal() << " sSeq = " << sSeq << endl;
75 changeItem( iAction, pAction->label() + "\t" + sSeq );
76 }
77 }
78 }
79}
80
81void TDEShortcutMenu::keyPressEvent( TQKeyEvent* pEvent )
82{
83 kdDebug() << "keypress; " << pEvent->key() << endl;
84 KKey key( pEvent );
85
86 switch( pEvent->key() ) {
87 case Key_Shift:
88 case Key_Control:
89 case Key_Alt:
90 case Key_Meta:
91 case Key_Super_L:
92 case Key_Super_R:
93 case Key_Hyper_L:
94 case Key_Hyper_R:
95 break;
96 default:
97 int iItem = searchForKey( key );
98 // If key not found, look for unmodified version.
99 if( iItem == -1 ) {
100 key = pEvent->key();
101 iItem = searchForKey( key );
102 }
103
104 if( iItem == -1 ) {
105 // Let Up and Down keys navigate menu,
106 // And permit Enter, Return to select the item.
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 );
110 else
111 close();
112 }
113 else if( iItem == 0 )
114 keepItemsMatching( key );
115 else
116 activateItemAt( iItem );
117 }
118}
119
120int TDEShortcutMenu::searchForKey( KKey key )
121{
122 int iItemFound = -1; // -1 indicates no match
123 uint iKey = m_seq.count();
124
125 for( uint iItem = 1; iItem < count(); iItem++ ) {
126 if( m_seqs.contains( iItem ) ) {
127 KKey keyItem = m_seqs[iItem].key( iKey );
128 //kdDebug(125) << "iItem = " << iItem << " key = " << key.toStringInternal() << " keyItem = " << keyItem.toStringInternal() << endl;
129 if( key == keyItem ) {
130 if( iItemFound == -1 )
131 iItemFound = iItem;
132 else
133 return 0; // 0 indicates duplicate matches
134 }
135 }
136 }
137
138 return iItemFound;
139}
140
141void TDEShortcutMenu::keepItemsMatching( KKey key )
142{
143 kdDebug(125) << "MyAccel::keepItemsMatching( " << key.toStringInternal() << " )" << endl;
144
145 uint iKey = m_seq.count();
146 m_seq.setKey( iKey, key );
147
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-- );
154 }
155 }
156 }
157
158 updateShortcuts();
159}
160
161#include "tdeshortcutmenu.moc"
KKeySequence
A KKeySequence object holds a sequence of up to 4 keys.
Definition: tdeshortcut.h:289
KKeySequence::count
uint count() const
Returns the number of key strokes of this sequence.
Definition: tdeshortcut.cpp:289
KKeySequence::key
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.
Definition: tdeshortcut.cpp:294
KKey
A KKey object represents a single key with possible modifiers (Shift, Ctrl, Alt, Win).
Definition: tdeshortcut.h:41
KKey::toString
TQString toString() const
Returns a human-readable representation of the key in the form "modifier+key".
Definition: tdeshortcut.cpp:167
TDEGlobalSettings::menuFont
static TQFont menuFont()
Returns the default menu font.
Definition: tdeglobalsettings.cpp:518
TDEGlobal::kdDebug
kdbgstream kdDebug(int area=0)
Returns a debug stream.
Definition: kdebug.cpp:371
TDEGlobal::endl
kdbgstream & endl(kdbgstream &s)
Prints an "\n".
Definition: kdebug.h:430
KStdAction::close
TDEAction * close(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEStdAccel::key
int key(StdAccel id)
Definition: tdestdaccel.cpp:383

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.