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

tdecore

  • tdecore
tdeaccelmanager.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Matthias H�lzer-Kl�pfel <mhk@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 "tdeaccelmanager.h"
21
22#include <tqapplication.h>
23#include <tqcheckbox.h>
24#include <tqcombobox.h>
25#include <tqgroupbox.h>
26#include <tqlabel.h>
27#include <tqlineedit.h>
28#include <tqmenubar.h>
29#include <tqmemarray.h>
30#include <tqmetaobject.h>
31#include <tqmainwindow.h>
32#include <tqobjectlist.h>
33#include <tqpopupmenu.h>
34#include <tqptrlist.h>
35#include <tqpushbutton.h>
36#include <tqradiobutton.h>
37#include <tqspinbox.h>
38#include <tqtabbar.h>
39#include <tqtextview.h>
40#include <tqwidget.h>
41#include <tqwidgetstack.h>
42
43#include <kstdaction.h>
44#include <kstaticdeleter.h>
45#include <kdebug.h>
46
47
48#include "tdeaccelmanager_private.h"
49#include "../tdeui/kstdaction_p.h"
50
51
52/*********************************************************************
53
54 class Item - helper class containing widget information
55
56 This class stores information about the widgets the need accelerators,
57 as well as about their relationship.
58
59 *********************************************************************/
60
61
62
63/*********************************************************************
64
65 class TDEAcceleratorManagerPrivate - internal helper class
66
67 This class does all the work to find accelerators for a hierarchy of
68 widgets.
69
70 *********************************************************************/
71
72
73class TDEAcceleratorManagerPrivate
74{
75public:
76
77 static void manage(TQWidget *widget);
78 static bool programmers_mode;
79 static bool standardName(const TQString &str);
80
81 static bool checkChange(const TDEAccelString &as) {
82 TQString t2 = as.accelerated();
83 TQString t1 = as.originalText();
84 if (t1 != t2)
85 {
86 if (as.accel() == -1) {
87 removed_string += "<tr><td>" + TQStyleSheet::escape(t1) + "</td></tr>";
88 } else if (as.originalAccel() == -1) {
89 added_string += "<tr><td>" + TQStyleSheet::escape(t2) + "</td></tr>";
90 } else {
91 changed_string += "<tr><td>" + TQStyleSheet::escape(t1) + "</td>";
92 changed_string += "<td>" + TQStyleSheet::escape(t2) + "</td></tr>";
93 }
94 return true;
95 }
96 return false;
97 }
98 static TQString changed_string;
99 static TQString added_string;
100 static TQString removed_string;
101 static TQMap<TQWidget *, int> ignored_widgets;
102
103private:
104 class Item;
105public:
106 typedef TQPtrList<Item> ItemList;
107
108private:
109 static void traverseChildren(TQWidget *widget, Item *item);
110
111 static void manageWidget(TQWidget *widget, Item *item);
112 static void manageMenuBar(TQMenuBar *mbar, Item *item);
113 static void manageTabBar(TQTabBar *bar, Item *item);
114
115 static void calculateAccelerators(Item *item, TQString &used);
116
117 class Item
118 {
119 public:
120
121 Item() : m_widget(0), m_children(0), m_index(-1) {}
122 ~Item();
123
124 void addChild(Item *item);
125
126 TQWidget *m_widget;
127 TDEAccelString m_content;
128 ItemList *m_children;
129 int m_index;
130
131 };
132};
133
134
135bool TDEAcceleratorManagerPrivate::programmers_mode = false;
136TQString TDEAcceleratorManagerPrivate::changed_string;
137TQString TDEAcceleratorManagerPrivate::added_string;
138TQString TDEAcceleratorManagerPrivate::removed_string;
139static TQStringList *kaccmp_sns = 0;
140static KStaticDeleter<TQStringList> kaccmp_sns_d;
141TQMap<TQWidget*, int> TDEAcceleratorManagerPrivate::ignored_widgets;
142
143bool TDEAcceleratorManagerPrivate::standardName(const TQString &str)
144{
145 if (!kaccmp_sns)
146 kaccmp_sns_d.setObject(kaccmp_sns, new TQStringList(KStdAction::internal_stdNames()));
147 return kaccmp_sns->contains(str);
148}
149
150TDEAcceleratorManagerPrivate::Item::~Item()
151{
152 delete m_children;
153}
154
155
156void TDEAcceleratorManagerPrivate::Item::addChild(Item *item)
157{
158 if (!m_children) {
159 m_children = new ItemList;
160 m_children->setAutoDelete(true);
161 }
162
163 m_children->append(item);
164}
165
166void TDEAcceleratorManagerPrivate::manage(TQWidget *widget)
167{
168 if (!widget)
169 {
170 kdDebug(131) << "null pointer given to manage" << endl;
171 return;
172 }
173
174 if (dynamic_cast<TQPopupMenu*>(widget))
175 {
176 // create a popup accel manager that can deal with dynamic menus
177 TDEPopupAccelManager::manage(static_cast<TQPopupMenu*>(widget));
178 return;
179 }
180
181 Item *root = new Item;
182
183 manageWidget(widget, root);
184
185 TQString used;
186 calculateAccelerators(root, used);
187 delete root;
188}
189
190
191void TDEAcceleratorManagerPrivate::calculateAccelerators(Item *item, TQString &used)
192{
193 if (!item->m_children)
194 return;
195
196 // collect the contents
197 TDEAccelStringList contents;
198 for (Item *it = item->m_children->first(); it != 0;
199 it = item->m_children->next())
200 {
201 contents << it->m_content;
202 }
203
204 // find the right accelerators
205 TDEAccelManagerAlgorithm::findAccelerators(contents, used);
206
207 // write them back into the widgets
208 int cnt = -1;
209 for (Item *it = item->m_children->first(); it != 0;
210 it = item->m_children->next())
211 {
212 cnt++;
213
214 TQTabBar *tabBar = dynamic_cast<TQTabBar*>(it->m_widget);
215 if (tabBar)
216 {
217 if (checkChange(contents[cnt]))
218 tabBar->tabAt(it->m_index)->setText(contents[cnt].accelerated());
219 continue;
220 }
221 TQMenuBar *menuBar = dynamic_cast<TQMenuBar*>(it->m_widget);
222 if (menuBar)
223 {
224 if (it->m_index >= 0)
225 {
226 TQMenuItem *mitem = menuBar->findItem(menuBar->idAt(it->m_index));
227 if (mitem)
228 {
229 checkChange(contents[cnt]);
230 mitem->setText(contents[cnt].accelerated());
231 }
232 continue;
233 }
234 }
235 // we possibly reserved an accel, but we won't set it as it looks silly
236 if ( dynamic_cast<TQGroupBox*>( it->m_widget ) )
237 continue;
238 // links look weird with ampersands
239 if ( dynamic_cast<TQLabel*>( it->m_widget ) && it->m_widget->inherits("KURLLabel") )
240 continue;
241
242 int tprop = it->m_widget->metaObject()->findProperty("text", true);
243 if (tprop != -1) {
244 if (checkChange(contents[cnt]))
245 it->m_widget->setProperty("text", contents[cnt].accelerated());
246 } else {
247 tprop = it->m_widget->metaObject()->findProperty("title", true);
248 if (tprop != -1 && checkChange(contents[cnt]))
249 it->m_widget->setProperty("title", contents[cnt].accelerated());
250 }
251 }
252
253 // calculate the accelerators for the children
254 for (Item *it = item->m_children->first(); it != 0;
255 it = item->m_children->next())
256 {
257 if (it->m_widget && it->m_widget->isVisibleTo( item->m_widget ) )
258 calculateAccelerators(it, used);
259 }
260}
261
262
263void TDEAcceleratorManagerPrivate::traverseChildren(TQWidget *widget, Item *item)
264{
265 TQObjectList *childList = widget->queryList("TQWidget", 0, false, false);
266 for ( TQObject *it = childList->first(); it; it = childList->next() )
267 {
268 TQWidget *w = static_cast<TQWidget*>(it);
269
270 if ( !w->isVisibleTo( widget ) || ( w->isTopLevel() && dynamic_cast<TQPopupMenu*>(w) == NULL ) )
271 continue;
272
273 if ( TDEAcceleratorManagerPrivate::ignored_widgets.find( w ) != TDEAcceleratorManagerPrivate::ignored_widgets.end() )
274 continue;
275
276 manageWidget(w, item);
277 }
278 delete childList;
279}
280
281void TDEAcceleratorManagerPrivate::manageWidget(TQWidget *w, Item *item)
282{
283 // first treat the special cases
284
285 TQTabBar *tabBar = dynamic_cast<TQTabBar*>(w);
286 if (tabBar)
287 {
288 manageTabBar(tabBar, item);
289 return;
290 }
291
292 TQWidgetStack *wds = dynamic_cast<TQWidgetStack*>( w );
293 if ( wds )
294 {
295 QWidgetStackAccelManager::manage( wds );
296 // return;
297 }
298
299 TQPopupMenu *popupMenu = dynamic_cast<TQPopupMenu*>(w);
300 if (popupMenu)
301 {
302 // create a popup accel manager that can deal with dynamic menus
303 TDEPopupAccelManager::manage(popupMenu);
304 return;
305 }
306
307 TQWidgetStack *wdst = dynamic_cast<TQWidgetStack*>( w );
308 if ( wdst )
309 {
310 QWidgetStackAccelManager::manage( wdst );
311 // return;
312 }
313
314 TQMenuBar *menuBar = dynamic_cast<TQMenuBar*>(w);
315 if (menuBar)
316 {
317 manageMenuBar(menuBar, item);
318 return;
319 }
320
321 if (dynamic_cast<TQComboBox*>(w) || dynamic_cast<TQLineEdit*>(w) ||
322 dynamic_cast<TQTextEdit*>(w) || dynamic_cast<TQTextView*>(w) ||
323 dynamic_cast<TQSpinBox*>(w) || w->tqt_cast("KMultiTabBar"))
324 return;
325
326 // now treat 'ordinary' widgets
327 TQLabel *label = dynamic_cast<TQLabel*>(w);
328 if ( label ) {
329 if ( !label->buddy() )
330 label = 0;
331 else {
332 if ( label->textFormat() == TQt::RichText ||
333 ( label->textFormat() == TQt::AutoText &&
334 TQStyleSheet::mightBeRichText( label->text() ) ) )
335 label = 0;
336 }
337 }
338
339 if (w->isFocusEnabled() || label || dynamic_cast<TQGroupBox*>(w) || dynamic_cast<TQRadioButton*>( w ))
340 {
341 TQString content;
342 TQVariant variant;
343 int tprop = w->metaObject()->findProperty("text", true);
344 if (tprop != -1) {
345 const TQMetaProperty* p = w->metaObject()->property( tprop, true );
346 if ( p && p->isValid() )
347 w->tqt_property( tprop, 1, &variant );
348 else
349 tprop = -1;
350 }
351
352 if (tprop == -1) {
353 tprop = w->metaObject()->findProperty("title", true);
354 if (tprop != -1) {
355 const TQMetaProperty* p = w->metaObject()->property( tprop, true );
356 if ( p && p->isValid() )
357 w->tqt_property( tprop, 1, &variant );
358 }
359 }
360
361 if (variant.isValid())
362 content = variant.toString();
363
364 if (!content.isEmpty())
365 {
366 Item *i = new Item;
367 i->m_widget = w;
368
369 // put some more weight on the usual action elements
370 int weight = TDEAccelManagerAlgorithm::DEFAULT_WEIGHT;
371 if (dynamic_cast<TQPushButton*>(w) || dynamic_cast<TQCheckBox*>(w) || dynamic_cast<TQRadioButton*>(w) || dynamic_cast<TQLabel*>(w))
372 weight = TDEAccelManagerAlgorithm::ACTION_ELEMENT_WEIGHT;
373
374 // don't put weight on group boxes, as usually the contents are more important
375 if (dynamic_cast<TQGroupBox*>(w))
376 weight = TDEAccelManagerAlgorithm::GROUP_BOX_WEIGHT;
377
378 // put a lot of extra weight on the KDialogBaseButton's
379 if (w->inherits("KDialogBaseButton"))
380 weight += TDEAccelManagerAlgorithm::DIALOG_BUTTON_EXTRA_WEIGHT;
381
382 i->m_content = TDEAccelString(content, weight);
383 item->addChild(i);
384 }
385 }
386 traverseChildren(w, item);
387}
388
389void TDEAcceleratorManagerPrivate::manageTabBar(TQTabBar *bar, Item *item)
390{
391 for (int i=0; i<bar->count(); i++)
392 {
393 TQString content = bar->tabAt(i)->text();
394 if (content.isEmpty())
395 continue;
396
397 Item *it = new Item;
398 item->addChild(it);
399 it->m_widget = bar;
400 it->m_index = i;
401 it->m_content = TDEAccelString(content);
402 }
403}
404
405void TDEAcceleratorManagerPrivate::manageMenuBar(TQMenuBar *mbar, Item *item)
406{
407 TQMenuItem *mitem;
408 TQString s;
409
410 for (uint i=0; i<mbar->count(); ++i)
411 {
412 mitem = mbar->findItem(mbar->idAt(i));
413 if (!mitem)
414 continue;
415
416 // nothing to do for separators
417 if (mitem->isSeparator())
418 continue;
419
420 s = mitem->text();
421 if (!s.isEmpty())
422 {
423 Item *it = new Item;
424 item->addChild(it);
425 it->m_content =
426 TDEAccelString(s,
427 // menu titles are important, so raise the weight
428 TDEAccelManagerAlgorithm::MENU_TITLE_WEIGHT);
429
430 it->m_widget = mbar;
431 it->m_index = i;
432 }
433
434 // have a look at the popup as well, if present
435 if (mitem->popup())
436 TDEPopupAccelManager::manage(mitem->popup());
437 }
438}
439
440
441/*********************************************************************
442
443 class TDEAcceleratorManager - main entry point
444
445 This class is just here to provide a clean public API...
446
447 *********************************************************************/
448
449void TDEAcceleratorManager::manage(TQWidget *widget)
450{
451 TDEAcceleratorManager::manage(widget, false);
452}
453
454void TDEAcceleratorManager::manage(TQWidget *widget, bool programmers_mode)
455{
456 kdDebug(131) << "TDEAcceleratorManager::manage\n";
457 TDEAcceleratorManagerPrivate::changed_string = TQString::null;
458 TDEAcceleratorManagerPrivate::added_string = TQString::null;
459 TDEAcceleratorManagerPrivate::removed_string = TQString::null;
460 TDEAcceleratorManagerPrivate::programmers_mode = programmers_mode;
461 TDEAcceleratorManagerPrivate::manage(widget);
462}
463
464void TDEAcceleratorManager::last_manage(TQString &added, TQString &changed, TQString &removed)
465{
466 added = TDEAcceleratorManagerPrivate::added_string;
467 changed = TDEAcceleratorManagerPrivate::changed_string;
468 removed = TDEAcceleratorManagerPrivate::removed_string;
469}
470
471
472/*********************************************************************
473
474 class TDEAccelString - a string with weighted characters
475
476 *********************************************************************/
477
478TDEAccelString::TDEAccelString(const TQString &input, int initialWeight)
479 : m_pureText(input), m_weight()
480{
481 m_orig_accel = m_pureText.find("(!)&");
482 if (m_orig_accel != -1)
483 m_pureText.remove(m_orig_accel, 4);
484
485 m_orig_accel = m_pureText.find("(&&)");
486 if (m_orig_accel != -1)
487 m_pureText.replace(m_orig_accel, 4, "&");
488
489 m_origText = m_pureText;
490
491 if (m_pureText.contains('\t'))
492 m_pureText = m_pureText.left(m_pureText.find('\t'));
493
494 m_orig_accel = m_accel = stripAccelerator(m_pureText);
495
496 if (initialWeight == -1)
497 initialWeight = TDEAccelManagerAlgorithm::DEFAULT_WEIGHT;
498
499 calculateWeights(initialWeight);
500
501 // dump();
502}
503
504
505TQString TDEAccelString::accelerated() const
506{
507 TQString result = m_origText;
508 if (result.isEmpty())
509 return result;
510
511 if (TDEAcceleratorManagerPrivate::programmers_mode)
512 {
513 if (m_accel != m_orig_accel) {
514 int oa = m_orig_accel;
515
516 if (m_accel >= 0) {
517 result.insert(m_accel, "(!)&");
518 if (m_accel < m_orig_accel)
519 oa += 4;
520 }
521 if (m_orig_accel >= 0)
522 result.replace(oa, 1, "(&&)");
523 }
524 } else {
525 if (m_accel >= 0 && m_orig_accel != m_accel) {
526 result.remove(m_orig_accel, 1);
527 result.insert(m_accel, "&");
528 }
529 }
530 return result;
531}
532
533
534TQChar TDEAccelString::accelerator() const
535{
536 if ((m_accel < 0) || (m_accel > (int)m_pureText.length()))
537 return TQChar();
538
539 return m_pureText[m_accel].lower();
540}
541
542
543void TDEAccelString::calculateWeights(int initialWeight)
544{
545 m_weight.resize(m_pureText.length());
546
547 uint pos = 0;
548 bool start_character = true;
549
550 while (pos<m_pureText.length())
551 {
552 TQChar c = m_pureText[pos];
553
554 int weight = initialWeight+1;
555
556 // add special weight to first character
557 if (pos == 0)
558 weight += TDEAccelManagerAlgorithm::FIRST_CHARACTER_EXTRA_WEIGHT;
559
560 // add weight to word beginnings
561 if (start_character)
562 {
563 weight += TDEAccelManagerAlgorithm::WORD_BEGINNING_EXTRA_WEIGHT;
564 start_character = false;
565 }
566
567 // add decreasing weight to left characters
568 if (pos < 50)
569 weight += (50-pos);
570
571 // try to preserve the wanted accelarators
572 if ((int)pos == accel()) {
573 weight += TDEAccelManagerAlgorithm::WANTED_ACCEL_EXTRA_WEIGHT;
574 // kdDebug(131) << "wanted " << m_pureText << " " << TDEAcceleratorManagerPrivate::standardName(m_origText) << endl;
575 if (TDEAcceleratorManagerPrivate::standardName(m_origText)) {
576 weight += TDEAccelManagerAlgorithm::STANDARD_ACCEL;
577 }
578 }
579
580 // skip non typeable characters
581 if (!c.isLetterOrNumber())
582 {
583 weight = 0;
584 start_character = true;
585 }
586
587 m_weight[pos] = weight;
588
589 ++pos;
590 }
591}
592
593
594int TDEAccelString::stripAccelerator(TQString &text)
595{
596 // Note: this code is derived from TQAccel::shortcutKey
597 int p = 0;
598
599 while (p >= 0)
600 {
601 p = text.find('&', p)+1;
602
603 if (p <= 0 || p >= (int)text.length())
604 return -1;
605
606 if (text[p] != '&')
607 {
608 TQChar c = text[p];
609 if (c.isPrint())
610 {
611 text.remove(p-1,1);
612 return p-1;
613 }
614 }
615
616 p++;
617 }
618
619 return -1;
620}
621
622
623int TDEAccelString::maxWeight(int &index, const TQString &used)
624{
625 int max = 0;
626 index = -1;
627
628 for (uint pos=0; pos<m_pureText.length(); ++pos)
629 if (used.find(m_pureText[pos], 0, FALSE) == -1 && m_pureText[pos].latin1() != 0)
630 if (m_weight[pos] > max)
631 {
632 max = m_weight[pos];
633 index = pos;
634 }
635
636 return max;
637}
638
639
640void TDEAccelString::dump()
641{
642 TQString s;
643 for (uint i=0; i<m_weight.count(); ++i)
644 s += TQString("%1(%2) ").arg(pure()[i]).arg(m_weight[i]);
645 kdDebug() << "s " << s << endl;
646}
647
648
649/*********************************************************************
650
651 findAccelerators - the algorithm determining the new accelerators
652
653 The algorithm is very crude:
654
655 * each character in each widget text is assigned a weight
656 * the character with the highest weight over all is picked
657 * that widget is removed from the list
658 * the weights are recalculated
659 * the process is repeated until no more accelerators can be found
660
661 The algorithm has some advantages:
662
663 * it favors 'nice' accelerators (first characters in a word, etc.)
664 * it is quite fast, O(N�)
665 * it is easy to understand :-)
666
667 The disadvantages:
668
669 * it does not try to find as many accelerators as possible
670
671 TODO:
672
673 * The result is always correct, but not neccesarily optimal. Perhaps
674 it would be a good idea to add another algorithm with higher complexity
675 that gets used when this one fails, i.e. leaves widgets without
676 accelerators.
677
678 * The weights probably need some tweaking so they make more sense.
679
680 *********************************************************************/
681
682void TDEAccelManagerAlgorithm::findAccelerators(TDEAccelStringList &result, TQString &used)
683{
684 kdDebug(131) << "findAccelerators\n";
685 TDEAccelStringList accel_strings = result;
686
687 // initally remove all accelerators
688 for (TDEAccelStringList::Iterator it = result.begin(); it != result.end(); ++it) {
689 (*it).setAccel(-1);
690 }
691
692 // pick the highest bids
693 for (uint cnt=0; cnt<accel_strings.count(); ++cnt)
694 {
695 int max = 0, index = -1, accel = -1;
696
697 // find maximum weight
698 for (uint i=0; i<accel_strings.count(); ++i)
699 {
700 int a;
701 int m = accel_strings[i].maxWeight(a, used);
702 if (m>max)
703 {
704 max = m;
705 index = i;
706 accel = a;
707 }
708 }
709
710 // stop if no more accelerators can be found
711 if (index < 0)
712 return;
713
714 // insert the accelerator
715 if (accel >= 0)
716 {
717 result[index].setAccel(accel);
718 used.append(result[index].accelerator());
719 }
720
721 // make sure we don't visit this one again
722 accel_strings[index] = TDEAccelString();
723 }
724}
725
726
727/*********************************************************************
728
729 class TDEPopupAccelManager - managing TQPopupMenu widgets dynamically
730
731 *********************************************************************/
732
733TDEPopupAccelManager::TDEPopupAccelManager(TQPopupMenu *popup)
734 : TQObject(popup), m_popup(popup), m_count(-1)
735{
736 aboutToShow(); // do one check and then connect to show
737 connect(popup, TQ_SIGNAL(aboutToShow()), TQ_SLOT(aboutToShow()));
738}
739
740
741void TDEPopupAccelManager::aboutToShow()
742{
743 // Note: we try to be smart and avoid recalculating the accelerators
744 // whenever possible. Unfortunately, there is no way to know if an
745 // item has been added or removed, so we can not do much more than
746 // to compare the items each time the menu is shown :-(
747
748 if (m_count != (int)m_popup->count())
749 {
750 findMenuEntries(m_entries);
751 calculateAccelerators();
752 m_count = m_popup->count();
753 }
754 else
755 {
756 TDEAccelStringList entries;
757 findMenuEntries(entries);
758 if (entries != m_entries)
759 {
760 m_entries = entries;
761 calculateAccelerators();
762 }
763 }
764}
765
766
767void TDEPopupAccelManager::calculateAccelerators()
768{
769 // find the new accelerators
770 TQString used;
771 TDEAccelManagerAlgorithm::findAccelerators(m_entries, used);
772
773 // change the menu entries
774 setMenuEntries(m_entries);
775}
776
777
778void TDEPopupAccelManager::findMenuEntries(TDEAccelStringList &list)
779{
780 TQMenuItem *mitem;
781 TQString s;
782
783 list.clear();
784
785 // read out the menu entries
786 for (uint i=0; i<m_popup->count(); i++)
787 {
788 mitem = m_popup->findItem(m_popup->idAt(i));
789 if (mitem->isSeparator())
790 continue;
791
792 s = mitem->text();
793
794 // in full menus, look at entries with global accelerators last
795 int weight = 50;
796 if (s.contains('\t'))
797 weight = 0;
798
799 list.append(TDEAccelString(s, weight));
800
801 // have a look at the popup as well, if present
802 if (mitem->popup())
803 TDEPopupAccelManager::manage(mitem->popup());
804 }
805}
806
807
808void TDEPopupAccelManager::setMenuEntries(const TDEAccelStringList &list)
809{
810 TQMenuItem *mitem;
811
812 uint cnt = 0;
813 for (uint i=0; i<m_popup->count(); i++)
814 {
815 mitem = m_popup->findItem(m_popup->idAt(i));
816 if (mitem->isSeparator())
817 continue;
818
819 if (TDEAcceleratorManagerPrivate::checkChange(list[cnt]))
820 mitem->setText(list[cnt].accelerated());
821 cnt++;
822 }
823}
824
825
826void TDEPopupAccelManager::manage(TQPopupMenu *popup)
827{
828 // don't add more than one manager to a popup
829 if (popup->child(0, "TDEPopupAccelManager", false) == 0 )
830 new TDEPopupAccelManager(popup);
831}
832
833void QWidgetStackAccelManager::manage( TQWidgetStack *stack )
834{
835 if ( stack->child( 0, "QWidgetStackAccelManager", false ) == 0 )
836 new QWidgetStackAccelManager( stack );
837}
838
839QWidgetStackAccelManager::QWidgetStackAccelManager(TQWidgetStack *stack)
840 : TQObject(stack), m_stack(stack)
841{
842 aboutToShow(stack->visibleWidget()); // do one check and then connect to show
843 connect(stack, TQ_SIGNAL(aboutToShow(TQWidget *)), TQ_SLOT(aboutToShow(TQWidget *)));
844}
845
846bool QWidgetStackAccelManager::eventFilter ( TQObject * watched, TQEvent * e )
847{
848 if ( e->type() == TQEvent::Show && tqApp->activeWindow() ) {
849 TDEAcceleratorManager::manage( tqApp->activeWindow() );
850 watched->removeEventFilter( this );
851 }
852 return false;
853}
854
855void QWidgetStackAccelManager::aboutToShow(TQWidget *child)
856{
857 if (!child)
858 {
859 kdDebug(131) << "null pointer given to aboutToShow" << endl;
860 return;
861 }
862
863 child->installEventFilter( this );
864}
865
866void TDEAcceleratorManager::setNoAccel( TQWidget *widget )
867{
868 TDEAcceleratorManagerPrivate::ignored_widgets[widget] = 1;
869}
870
871#include "tdeaccelmanager_private.moc"
KStaticDeleter
Little helper class to clean up static objects that are held as pointer.
Definition: kstaticdeleter.h:74
TDEAccelManagerAlgorithm::findAccelerators
static void findAccelerators(TDEAccelStringList &result, TQString &used)
Method to call to find the best distribution of accelerators.
Definition: tdeaccelmanager.cpp:682
TDEAccelManagerAlgorithm::FIRST_CHARACTER_EXTRA_WEIGHT
@ FIRST_CHARACTER_EXTRA_WEIGHT
Additional weight for first character in string.
Definition: tdeaccelmanager_private.h:99
TDEAccelManagerAlgorithm::STANDARD_ACCEL
@ STANDARD_ACCEL
Additional weight for KDE standard accelerators.
Definition: tdeaccelmanager_private.h:113
TDEAccelManagerAlgorithm::MENU_TITLE_WEIGHT
@ MENU_TITLE_WEIGHT
Default weight for menu titles.
Definition: tdeaccelmanager_private.h:111
TDEAccelManagerAlgorithm::GROUP_BOX_WEIGHT
@ GROUP_BOX_WEIGHT
Default weight for group boxes (low priority)
Definition: tdeaccelmanager_private.h:109
TDEAccelManagerAlgorithm::DIALOG_BUTTON_EXTRA_WEIGHT
@ DIALOG_BUTTON_EXTRA_WEIGHT
Additional weight for the dialog buttons (large, we basically never want these reassigned)
Definition: tdeaccelmanager_private.h:103
TDEAccelManagerAlgorithm::WANTED_ACCEL_EXTRA_WEIGHT
@ WANTED_ACCEL_EXTRA_WEIGHT
Additional weight for a 'wanted' accelerator.
Definition: tdeaccelmanager_private.h:105
TDEAccelManagerAlgorithm::DEFAULT_WEIGHT
@ DEFAULT_WEIGHT
Default control weight.
Definition: tdeaccelmanager_private.h:97
TDEAccelManagerAlgorithm::WORD_BEGINNING_EXTRA_WEIGHT
@ WORD_BEGINNING_EXTRA_WEIGHT
Additional weight for the beginning of a word.
Definition: tdeaccelmanager_private.h:101
TDEAccelManagerAlgorithm::ACTION_ELEMENT_WEIGHT
@ ACTION_ELEMENT_WEIGHT
Default weight for an 'action' widget (ie, pushbuttons)
Definition: tdeaccelmanager_private.h:107
TDEAccelString
A string class handling accelerators.
Definition: tdeaccelmanager_private.h:43
TDEAcceleratorManager::setNoAccel
static void setNoAccel(TQWidget *widget)
Use this method for a widget (and its children) you want no accels to be set on.
Definition: tdeaccelmanager.cpp:866
TDEAcceleratorManager::manage
static void manage(TQWidget *widget)
Manages the accelerators of a widget.
Definition: tdeaccelmanager.cpp:449
TDEPopupAccelManager
This class manages a popup menu.
Definition: tdeaccelmanager_private.h:135
endl
kndbgstream & endl(kndbgstream &s)
Does nothing.
Definition: kdebug.h:583
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::find
TDEAction * find(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEStdAccel::label
TQString label(StdAccel id)
Returns a localized label for user-visible display.
Definition: tdestdaccel.cpp:156

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.