author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /microkde/kdeui/kactionclasses.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
Diffstat (limited to 'microkde/kdeui/kactionclasses.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/kdeui/kactionclasses.cpp | 2058 |
1 files changed, 2058 insertions, 0 deletions
diff --git a/microkde/kdeui/kactionclasses.cpp b/microkde/kdeui/kactionclasses.cpp new file mode 100644 index 0000000..82e6c8b --- a/dev/null +++ b/microkde/kdeui/kactionclasses.cpp | |||
@@ -0,0 +1,2058 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org> | ||
3 | (C) 1999 Simon Hausmann <hausmann@kde.org> | ||
4 | (C) 2000 Nicolas Hadacek <haadcek@kde.org> | ||
5 | (C) 2000 Kurt Granroth <granroth@kde.org> | ||
6 | (C) 2000 Michael Koch <koch@kde.org> | ||
7 | (C) 2001 Holger Freyther <freyther@kde.org> | ||
8 | (C) 2002 Ellis Whitehead <ellis@kde.org> | ||
9 | (C) 2002 Joseph Wenninger <jowenn@kde.org> | ||
10 | |||
11 | This library is free software; you can redistribute it and/or | ||
12 | modify it under the terms of the GNU Library General Public | ||
13 | License version 2 as published by the Free Software Foundation. | ||
14 | |||
15 | This library is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | Library General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU Library General Public License | ||
21 | along with this library; see the file COPYING.LIB. If not, write to | ||
22 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
23 | Boston, MA 02111-1307, USA. | ||
24 | */ | ||
25 | |||
26 | #include "kactionclasses.h" | ||
27 | |||
28 | #include <assert.h> | ||
29 | |||
30 | #include <qfontdatabase.h> | ||
31 | #include <qobjectlist.h> | ||
32 | //US#include <qwhatsthis.h> | ||
33 | #include <qtimer.h> | ||
34 | |||
35 | //US#include <kaccel.h> | ||
36 | //US#include <kapplication.h> | ||
37 | #include <kconfig.h> | ||
38 | #include <kdebug.h> | ||
39 | //US#include <kfontcombo.h> | ||
40 | //US#include <kmainwindow.h> | ||
41 | //US#include <kmenubar.h> | ||
42 | //US#include <kpopupmenu.h> | ||
43 | #include <kcombobox.h> | ||
44 | #include <ktoolbar.h> | ||
45 | #include <ktoolbarbutton.h> | ||
46 | #include <kurl.h> | ||
47 | |||
48 | //US added the following includefiles | ||
49 | #include <kconfigbase.h> | ||
50 | #include <qwidget.h> | ||
51 | #include <qpopupmenu.h> | ||
52 | #include <qmenubar.h> | ||
53 | #include <qmainwindow.h> | ||
54 | #include <qtoolbar.h> | ||
55 | #include <qcombobox.h> | ||
56 | #include <qmainwindow.h> | ||
57 | |||
58 | |||
59 | static QFontDatabase *fontDataBase = 0; | ||
60 | |||
61 | static void cleanupFontDatabase() | ||
62 | { | ||
63 | delete fontDataBase; | ||
64 | fontDataBase = 0; | ||
65 | } | ||
66 | |||
67 | static void get_fonts( QStringList &lst ) | ||
68 | { | ||
69 | if ( !fontDataBase ) { | ||
70 | fontDataBase = new QFontDatabase(); | ||
71 | qAddPostRoutine( cleanupFontDatabase ); | ||
72 | } | ||
73 | lst.clear(); | ||
74 | QStringList families = fontDataBase->families(); | ||
75 | for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) | ||
76 | { | ||
77 | QString family = *it; | ||
78 | if ( family. contains('-') ) // remove foundry | ||
79 | family = family.right( family.length() - family.find('-' ) - 1); | ||
80 | if ( !lst.contains( family ) ) | ||
81 | lst.append( family ); | ||
82 | } | ||
83 | lst.sort(); | ||
84 | } | ||
85 | |||
86 | static QValueList<int> get_standard_font_sizes() | ||
87 | { | ||
88 | if ( !fontDataBase ) { | ||
89 | fontDataBase = new QFontDatabase(); | ||
90 | qAddPostRoutine( cleanupFontDatabase ); | ||
91 | } | ||
92 | return fontDataBase->standardSizes(); | ||
93 | } | ||
94 | |||
95 | class KToggleAction::KToggleActionPrivate | ||
96 | { | ||
97 | public: | ||
98 | KToggleActionPrivate() | ||
99 | { | ||
100 | m_checked = false; | ||
101 | } | ||
102 | |||
103 | bool m_checked; | ||
104 | QString m_exclusiveGroup; | ||
105 | }; | ||
106 | |||
107 | KToggleAction::KToggleAction( const QString& text, const KShortcut& cut, | ||
108 | QObject* parent, | ||
109 | const char* name ) | ||
110 | : KAction( text, cut, parent, name ) | ||
111 | { | ||
112 | d = new KToggleActionPrivate; | ||
113 | } | ||
114 | |||
115 | KToggleAction::KToggleAction( const QString& text, const KShortcut& cut, | ||
116 | const QObject* receiver, const char* slot, | ||
117 | QObject* parent, const char* name ) | ||
118 | : KAction( text, cut, receiver, slot, parent, name ) | ||
119 | { | ||
120 | d = new KToggleActionPrivate; | ||
121 | } | ||
122 | |||
123 | KToggleAction::KToggleAction( const QString& text, const QIconSet& pix, | ||
124 | const KShortcut& cut, | ||
125 | QObject* parent, const char* name ) | ||
126 | : KAction( text, pix, cut, parent, name ) | ||
127 | { | ||
128 | d = new KToggleActionPrivate; | ||
129 | } | ||
130 | |||
131 | KToggleAction::KToggleAction( const QString& text, const QString& pix, | ||
132 | const KShortcut& cut, | ||
133 | QObject* parent, const char* name ) | ||
134 | : KAction( text, pix, cut, parent, name ) | ||
135 | { | ||
136 | d = new KToggleActionPrivate; | ||
137 | } | ||
138 | |||
139 | KToggleAction::KToggleAction( const QString& text, const QIconSet& pix, | ||
140 | const KShortcut& cut, | ||
141 | const QObject* receiver, | ||
142 | const char* slot, QObject* parent, | ||
143 | const char* name ) | ||
144 | : KAction( text, pix, cut, receiver, slot, parent, name ) | ||
145 | { | ||
146 | d = new KToggleActionPrivate; | ||
147 | } | ||
148 | |||
149 | KToggleAction::KToggleAction( const QString& text, const QString& pix, | ||
150 | const KShortcut& cut, | ||
151 | const QObject* receiver, | ||
152 | const char* slot, QObject* parent, | ||
153 | const char* name ) | ||
154 | : KAction( text, pix, cut, receiver, slot, parent, name ) | ||
155 | { | ||
156 | d = new KToggleActionPrivate; | ||
157 | } | ||
158 | |||
159 | KToggleAction::KToggleAction( QObject* parent, const char* name ) | ||
160 | : KAction( parent, name ) | ||
161 | { | ||
162 | d = new KToggleActionPrivate; | ||
163 | } | ||
164 | |||
165 | KToggleAction::~KToggleAction() | ||
166 | { | ||
167 | delete d; | ||
168 | } | ||
169 | |||
170 | int KToggleAction::plug( QWidget* widget, int index ) | ||
171 | { | ||
172 | if ( !widget->inherits("QPopupMenu") && !widget->inherits("KToolBar") ) | ||
173 | { | ||
174 | kdWarning() << "Can not plug KToggleAction in " << widget->className() << endl; | ||
175 | return -1; | ||
176 | } | ||
177 | |||
178 | /*US | ||
179 | if (kapp && !kapp->authorizeKAction(name())) | ||
180 | return -1; | ||
181 | */ | ||
182 | |||
183 | int _index = KAction::plug( widget, index ); | ||
184 | if ( _index == -1 ) | ||
185 | return _index; | ||
186 | |||
187 | if ( widget->inherits("QPopupMenu") ) | ||
188 | { | ||
189 | int id = itemId( _index ); | ||
190 | |||
191 | static_cast<QPopupMenu*>(widget)->setItemChecked( id, d->m_checked ); | ||
192 | } else if ( widget->inherits( "KToolBar" ) ) { | ||
193 | |||
194 | KToolBar *bar = static_cast<KToolBar *>( widget ); | ||
195 | |||
196 | bar->setToggle( itemId( _index ), true ); | ||
197 | bar->setButton( itemId( _index ), isChecked() ); | ||
198 | } | ||
199 | |||
200 | return _index; | ||
201 | } | ||
202 | |||
203 | void KToggleAction::setChecked( bool c ) | ||
204 | { | ||
205 | if ( c == d->m_checked ) | ||
206 | return; | ||
207 | //kdDebug(129) << "KToggleAction::setChecked(" << c << ") " << this << " " << name() << endl; | ||
208 | |||
209 | d->m_checked = c; | ||
210 | |||
211 | int len = containerCount(); | ||
212 | |||
213 | for( int i = 0; i < len; ++i ) | ||
214 | updateChecked( i ); | ||
215 | |||
216 | if ( c && parent() && !exclusiveGroup().isEmpty() ) { | ||
217 | const QObjectList *list = parent()->children(); | ||
218 | if ( list ) { | ||
219 | QObjectListIt it( *list ); | ||
220 | for( ; it.current(); ++it ) { | ||
221 | if ( it.current()->inherits( "KToggleAction" ) && it.current() != this && | ||
222 | static_cast<KToggleAction*>(it.current())->exclusiveGroup() == exclusiveGroup() ) { | ||
223 | KToggleAction *a = static_cast<KToggleAction*>(it.current()); | ||
224 | if( a->isChecked() ) { | ||
225 | a->setChecked( false ); | ||
226 | emit a->toggled( false ); | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | } | ||
233 | |||
234 | void KToggleAction::updateChecked( int id ) | ||
235 | { | ||
236 | QWidget *w = container( id ); | ||
237 | |||
238 | if ( w->inherits( "QPopupMenu" ) ) | ||
239 | static_cast<QPopupMenu*>(w)->setItemChecked( itemId( id ), d->m_checked ); | ||
240 | else if ( w->inherits( "QMenuBar" ) ) | ||
241 | static_cast<QMenuBar*>(w)->setItemChecked( itemId( id ), d->m_checked ); | ||
242 | else if ( w->inherits( "KToolBar" ) ) | ||
243 | { | ||
244 | QWidget* r = static_cast<KToolBar*>( w )->getButton( itemId( id ) ); | ||
245 | if ( r && r->inherits( "KToolBarButton" ) ) | ||
246 | static_cast<KToolBar*>( w )->setButton( itemId( id ), d->m_checked ); | ||
247 | } | ||
248 | } | ||
249 | |||
250 | void KToggleAction::slotActivated() | ||
251 | { | ||
252 | setChecked( !isChecked() ); | ||
253 | emit activated(); | ||
254 | emit toggled( isChecked() ); | ||
255 | } | ||
256 | |||
257 | bool KToggleAction::isChecked() const | ||
258 | { | ||
259 | return d->m_checked; | ||
260 | } | ||
261 | |||
262 | void KToggleAction::setExclusiveGroup( const QString& name ) | ||
263 | { | ||
264 | d->m_exclusiveGroup = name; | ||
265 | } | ||
266 | |||
267 | QString KToggleAction::exclusiveGroup() const | ||
268 | { | ||
269 | return d->m_exclusiveGroup; | ||
270 | } | ||
271 | |||
272 | |||
273 | KRadioAction::KRadioAction( const QString& text, const KShortcut& cut, | ||
274 | QObject* parent, const char* name ) | ||
275 | : KToggleAction( text, cut, parent, name ) | ||
276 | { | ||
277 | } | ||
278 | |||
279 | KRadioAction::KRadioAction( const QString& text, const KShortcut& cut, | ||
280 | const QObject* receiver, const char* slot, | ||
281 | QObject* parent, const char* name ) | ||
282 | : KToggleAction( text, cut, receiver, slot, parent, name ) | ||
283 | { | ||
284 | } | ||
285 | |||
286 | KRadioAction::KRadioAction( const QString& text, const QIconSet& pix, | ||
287 | const KShortcut& cut, | ||
288 | QObject* parent, const char* name ) | ||
289 | : KToggleAction( text, pix, cut, parent, name ) | ||
290 | { | ||
291 | } | ||
292 | |||
293 | KRadioAction::KRadioAction( const QString& text, const QString& pix, | ||
294 | const KShortcut& cut, | ||
295 | QObject* parent, const char* name ) | ||
296 | : KToggleAction( text, pix, cut, parent, name ) | ||
297 | { | ||
298 | } | ||
299 | |||
300 | KRadioAction::KRadioAction( const QString& text, const QIconSet& pix, | ||
301 | const KShortcut& cut, | ||
302 | const QObject* receiver, const char* slot, | ||
303 | QObject* parent, const char* name ) | ||
304 | : KToggleAction( text, pix, cut, receiver, slot, parent, name ) | ||
305 | { | ||
306 | } | ||
307 | |||
308 | KRadioAction::KRadioAction( const QString& text, const QString& pix, | ||
309 | const KShortcut& cut, | ||
310 | const QObject* receiver, const char* slot, | ||
311 | QObject* parent, const char* name ) | ||
312 | : KToggleAction( text, pix, cut, receiver, slot, parent, name ) | ||
313 | { | ||
314 | } | ||
315 | |||
316 | KRadioAction::KRadioAction( QObject* parent, const char* name ) | ||
317 | : KToggleAction( parent, name ) | ||
318 | { | ||
319 | } | ||
320 | |||
321 | void KRadioAction::slotActivated() | ||
322 | { | ||
323 | if ( isChecked() ) | ||
324 | { | ||
325 | const QObject *senderObj = sender(); | ||
326 | |||
327 | if ( !senderObj || !senderObj->inherits( "KToolBarButton" ) ) | ||
328 | return; | ||
329 | |||
330 | qDebug("KRadioAction::slotActivated has to be fixed"); | ||
331 | const_cast<KToolBarButton *>( static_cast<const KToolBarButton *>( senderObj ) )->on( true ); | ||
332 | |||
333 | return; | ||
334 | } | ||
335 | |||
336 | KToggleAction::slotActivated(); | ||
337 | } | ||
338 | |||
339 | class KSelectAction::KSelectActionPrivate | ||
340 | { | ||
341 | public: | ||
342 | KSelectActionPrivate() | ||
343 | { | ||
344 | m_edit = false; | ||
345 | m_menuAccelsEnabled = true; | ||
346 | m_menu = 0; | ||
347 | m_current = -1; | ||
348 | m_comboWidth = -1; | ||
349 | } | ||
350 | bool m_edit; | ||
351 | bool m_menuAccelsEnabled; | ||
352 | QPopupMenu *m_menu; | ||
353 | int m_current; | ||
354 | int m_comboWidth; | ||
355 | QStringList m_list; | ||
356 | |||
357 | QString makeMenuText( const QString &_text ) | ||
358 | { | ||
359 | if ( m_menuAccelsEnabled ) | ||
360 | return _text; | ||
361 | QString text = _text; | ||
362 | uint i = 0; | ||
363 | while ( i < text.length() ) { | ||
364 | if ( text.at( i ) == '&' ) { | ||
365 | text.insert( i, '&' ); | ||
366 | i += 2; | ||
367 | } | ||
368 | else | ||
369 | ++i; | ||
370 | } | ||
371 | return text; | ||
372 | } | ||
373 | }; | ||
374 | |||
375 | KSelectAction::KSelectAction( const QString& text, const KShortcut& cut, | ||
376 | QObject* parent, const char* name ) | ||
377 | : KAction( text, cut, parent, name ) | ||
378 | { | ||
379 | d = new KSelectActionPrivate; | ||
380 | } | ||
381 | |||
382 | KSelectAction::KSelectAction( const QString& text, const KShortcut& cut, | ||
383 | const QObject* receiver, const char* slot, | ||
384 | QObject* parent, const char* name ) | ||
385 | : KAction( text, cut, receiver, slot, parent, name ) | ||
386 | { | ||
387 | d = new KSelectActionPrivate; | ||
388 | } | ||
389 | |||
390 | KSelectAction::KSelectAction( const QString& text, const QIconSet& pix, | ||
391 | const KShortcut& cut, | ||
392 | QObject* parent, const char* name ) | ||
393 | : KAction( text, pix, cut, parent, name ) | ||
394 | { | ||
395 | d = new KSelectActionPrivate; | ||
396 | } | ||
397 | |||
398 | KSelectAction::KSelectAction( const QString& text, const QString& pix, | ||
399 | const KShortcut& cut, | ||
400 | QObject* parent, const char* name ) | ||
401 | : KAction( text, pix, cut, parent, name ) | ||
402 | { | ||
403 | d = new KSelectActionPrivate; | ||
404 | } | ||
405 | |||
406 | KSelectAction::KSelectAction( const QString& text, const QIconSet& pix, | ||
407 | const KShortcut& cut, | ||
408 | const QObject* receiver, | ||
409 | const char* slot, QObject* parent, | ||
410 | const char* name ) | ||
411 | : KAction( text, pix, cut, receiver, slot, parent, name ) | ||
412 | { | ||
413 | d = new KSelectActionPrivate; | ||
414 | } | ||
415 | |||
416 | KSelectAction::KSelectAction( const QString& text, const QString& pix, | ||
417 | const KShortcut& cut, | ||
418 | const QObject* receiver, | ||
419 | const char* slot, QObject* parent, | ||
420 | const char* name ) | ||
421 | : KAction( text, pix, cut, receiver, slot, parent, name ) | ||
422 | { | ||
423 | d = new KSelectActionPrivate; | ||
424 | } | ||
425 | |||
426 | KSelectAction::KSelectAction( QObject* parent, const char* name ) | ||
427 | : KAction( parent, name ) | ||
428 | { | ||
429 | d = new KSelectActionPrivate; | ||
430 | } | ||
431 | |||
432 | KSelectAction::~KSelectAction() | ||
433 | { | ||
434 | assert(d); | ||
435 | delete d->m_menu; | ||
436 | delete d; d = 0; | ||
437 | } | ||
438 | |||
439 | void KSelectAction::setCurrentItem( int id ) | ||
440 | { | ||
441 | if ( id >= (int)d->m_list.count() ) { | ||
442 | ASSERT(id < (int)d->m_list.count()); | ||
443 | return; | ||
444 | } | ||
445 | |||
446 | if ( d->m_menu ) | ||
447 | { | ||
448 | if ( d->m_current >= 0 ) | ||
449 | d->m_menu->setItemChecked( d->m_current, false ); | ||
450 | if ( id >= 0 ) | ||
451 | { | ||
452 | //US qDebug("KSelectAction::setCurrentItem %i", id); | ||
453 | d->m_menu->setItemChecked( id, true ); | ||
454 | } | ||
455 | } | ||
456 | |||
457 | d->m_current = id; | ||
458 | |||
459 | int len = containerCount(); | ||
460 | |||
461 | for( int i = 0; i < len; ++i ) | ||
462 | updateCurrentItem( i ); | ||
463 | |||
464 | // emit KAction::activated(); | ||
465 | // emit activated( currentItem() ); | ||
466 | // emit activated( currentText() ); | ||
467 | } | ||
468 | |||
469 | void KSelectAction::setComboWidth( int width ) | ||
470 | { | ||
471 | if ( width < 0 ) | ||
472 | return; | ||
473 | |||
474 | d->m_comboWidth=width; | ||
475 | |||
476 | int len = containerCount(); | ||
477 | |||
478 | for( int i = 0; i < len; ++i ) | ||
479 | updateComboWidth( i ); | ||
480 | |||
481 | } | ||
482 | QPopupMenu* KSelectAction::popupMenu() const | ||
483 | { | ||
484 | kdDebug(129) << "KSelectAction::popupMenu()" << endl; // remove -- ellis | ||
485 | if ( !d->m_menu ) | ||
486 | { | ||
487 | //US d->m_menu = new KPopupMenu(0L, "KSelectAction::popupMenu()"); | ||
488 | d->m_menu = new QPopupMenu(0L, "QSelectAction::popupMenu()"); | ||
489 | setupMenu(); | ||
490 | if ( d->m_current >= 0 ) | ||
491 | d->m_menu->setItemChecked( d->m_current, true ); | ||
492 | } | ||
493 | |||
494 | return d->m_menu; | ||
495 | } | ||
496 | |||
497 | void KSelectAction::setupMenu() const | ||
498 | { | ||
499 | if ( !d->m_menu ) | ||
500 | return; | ||
501 | d->m_menu->clear(); | ||
502 | |||
503 | QStringList::ConstIterator it = d->m_list.begin(); | ||
504 | for( uint id = 0; it != d->m_list.end(); ++it, ++id ) { | ||
505 | QString text = *it; | ||
506 | if ( !text.isEmpty() ) | ||
507 | d->m_menu->insertItem( d->makeMenuText( text ), this, SLOT( slotActivated( int ) ), 0, id ); | ||
508 | else | ||
509 | d->m_menu->insertSeparator(); | ||
510 | } | ||
511 | } | ||
512 | |||
513 | void KSelectAction::changeItem( int index, const QString& text ) | ||
514 | { | ||
515 | if ( index < 0 || index >= (int)d->m_list.count() ) | ||
516 | { | ||
517 | kdWarning() << "KSelectAction::changeItem Index out of scope" << endl; | ||
518 | return; | ||
519 | } | ||
520 | |||
521 | d->m_list[ index ] = text; | ||
522 | |||
523 | if ( d->m_menu ) | ||
524 | d->m_menu->changeItem( index, d->makeMenuText( text ) ); | ||
525 | |||
526 | int len = containerCount(); | ||
527 | for( int i = 0; i < len; ++i ) | ||
528 | changeItem( i, index, text ); | ||
529 | } | ||
530 | |||
531 | void KSelectAction::changeItem( int id, int index, const QString& text) | ||
532 | { | ||
533 | if ( index < 0 ) | ||
534 | return; | ||
535 | |||
536 | QWidget* w = container( id ); | ||
537 | if ( w->inherits( "KToolBar" ) ) | ||
538 | { | ||
539 | QWidget* r = (static_cast<KToolBar*>( w ))->getWidget( itemId( id ) ); | ||
540 | if ( r->inherits( "QComboBox" ) ) | ||
541 | { | ||
542 | QComboBox *b = static_cast<QComboBox*>( r ); | ||
543 | b->changeItem(text, index ); | ||
544 | } | ||
545 | } | ||
546 | |||
547 | } | ||
548 | |||
549 | void KSelectAction::setItems( const QStringList &lst ) | ||
550 | { | ||
551 | kdDebug(129) << "KAction::setItems()" << endl; // remove -- ellis | ||
552 | d->m_list = lst; | ||
553 | d->m_current = -1; | ||
554 | |||
555 | setupMenu(); | ||
556 | |||
557 | int len = containerCount(); | ||
558 | for( int i = 0; i < len; ++i ) | ||
559 | updateItems( i ); | ||
560 | |||
561 | // Disable if empty and not editable | ||
562 | setEnabled ( lst.count() > 0 || d->m_edit ); | ||
563 | } | ||
564 | |||
565 | QStringList KSelectAction::items() const | ||
566 | { | ||
567 | return d->m_list; | ||
568 | } | ||
569 | |||
570 | QString KSelectAction::currentText() const | ||
571 | { | ||
572 | if ( currentItem() < 0 ) | ||
573 | return QString::null; | ||
574 | |||
575 | return d->m_list[ currentItem() ]; | ||
576 | } | ||
577 | |||
578 | int KSelectAction::currentItem() const | ||
579 | { | ||
580 | return d->m_current; | ||
581 | } | ||
582 | |||
583 | void KSelectAction::updateCurrentItem( int id ) | ||
584 | { | ||
585 | if ( d->m_current < 0 ) | ||
586 | return; | ||
587 | |||
588 | QWidget* w = container( id ); | ||
589 | if ( w->inherits( "KToolBar" ) ) { | ||
590 | QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) ); | ||
591 | if ( r->inherits( "QComboBox" ) ) { | ||
592 | QComboBox *b = static_cast<QComboBox*>( r ); | ||
593 | b->setCurrentItem( d->m_current ); | ||
594 | } | ||
595 | } | ||
596 | } | ||
597 | |||
598 | int KSelectAction::comboWidth() const | ||
599 | { | ||
600 | return d->m_comboWidth; | ||
601 | } | ||
602 | |||
603 | void KSelectAction::updateComboWidth( int id ) | ||
604 | { | ||
605 | QWidget* w = container( id ); | ||
606 | if ( w->inherits( "KToolBar" ) ) { | ||
607 | QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) ); | ||
608 | if ( r->inherits( "QComboBox" ) ) { | ||
609 | QComboBox *cb = static_cast<QComboBox*>( r ); | ||
610 | cb->setMinimumWidth( d->m_comboWidth ); | ||
611 | cb->setMaximumWidth( d->m_comboWidth ); | ||
612 | } | ||
613 | } | ||
614 | } | ||
615 | |||
616 | void KSelectAction::updateItems( int id ) | ||
617 | { | ||
618 | kdDebug(129) << "KAction::updateItems( " << id << ", lst )" << endl; // remove -- ellis | ||
619 | |||
620 | QWidget* w = container( id ); | ||
621 | if ( w->inherits( "KToolBar" ) ) { | ||
622 | |||
623 | QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) ); | ||
624 | if ( r->inherits( "QComboBox" ) ) { | ||
625 | QComboBox *cb = static_cast<QComboBox*>( r ); | ||
626 | cb->clear(); | ||
627 | QStringList lst = comboItems(); | ||
628 | QStringList::ConstIterator it = lst.begin(); | ||
629 | for( ; it != lst.end(); ++it ) | ||
630 | cb->insertItem( *it ); | ||
631 | // Ok, this currently doesn't work due to a bug in QComboBox | ||
632 | // (the sizehint is cached for ever and never recalculated) | ||
633 | // Bug reported (against Qt 2.3.1). | ||
634 | cb->setMinimumWidth( cb->sizeHint().width() ); | ||
635 | } | ||
636 | } | ||
637 | |||
638 | } | ||
639 | |||
640 | int KSelectAction::plug( QWidget *widget, int index ) | ||
641 | { | ||
642 | //US if (kapp && !kapp->authorizeKAction(name())) | ||
643 | //US return -1; | ||
644 | |||
645 | kdDebug(129) << "KAction::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis | ||
646 | if ( widget->inherits("QPopupMenu") ) | ||
647 | { | ||
648 | // Create the PopupMenu and store it in m_menu | ||
649 | (void)popupMenu(); | ||
650 | |||
651 | QPopupMenu* menu = static_cast<QPopupMenu*>( widget ); | ||
652 | int id; | ||
653 | |||
654 | if ( hasIconSet() ) | ||
655 | id = menu->insertItem( iconSet(), text(), d->m_menu, -1, index ); | ||
656 | else | ||
657 | id = menu->insertItem( text(), d->m_menu, -1, index ); | ||
658 | |||
659 | if ( !isEnabled() ) | ||
660 | menu->setItemEnabled( id, false ); | ||
661 | |||
662 | QString wth = whatsThis(); | ||
663 | if ( !wth.isEmpty() ) | ||
664 | menu->setWhatsThis( id, wth ); | ||
665 | |||
666 | addContainer( menu, id ); | ||
667 | connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); | ||
668 | |||
669 | return containerCount() - 1; | ||
670 | } | ||
671 | else if ( widget->inherits("KToolBar") ) | ||
672 | { | ||
673 | |||
674 | KToolBar* bar = static_cast<KToolBar*>( widget ); | ||
675 | int id_ = KAction::getToolButtonID(); | ||
676 | bar->insertCombo( comboItems(), id_, isEditable(), | ||
677 | SIGNAL( activated( const QString & ) ), this, | ||
678 | SLOT( slotActivated( const QString & ) ), isEnabled(), | ||
679 | toolTip(), -1, index ); | ||
680 | |||
681 | KComboBox *cb = bar->getCombo( id_ ); | ||
682 | if ( cb ) | ||
683 | { | ||
684 | cb->setMaximumHeight( 34 ); | ||
685 | if (!isEditable()) cb->setFocusPolicy(QWidget::NoFocus); | ||
686 | cb->setMinimumWidth( cb->sizeHint().width() ); | ||
687 | if ( d->m_comboWidth > 0 ) | ||
688 | { | ||
689 | cb->setMinimumWidth( d->m_comboWidth ); | ||
690 | cb->setMaximumWidth( d->m_comboWidth ); | ||
691 | } | ||
692 | cb->setInsertionPolicy( QComboBox::NoInsertion ); | ||
693 | //US QWhatsThis::add( cb, whatsThis() ); | ||
694 | } | ||
695 | |||
696 | addContainer( bar, id_ ); | ||
697 | |||
698 | connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); | ||
699 | |||
700 | updateCurrentItem( containerCount() - 1 ); | ||
701 | |||
702 | return containerCount() - 1; | ||
703 | |||
704 | } | ||
705 | kdWarning() << "Can not plug KAction in " << widget->className() << endl; | ||
706 | return -1; | ||
707 | } | ||
708 | |||
709 | QStringList KSelectAction::comboItems() const | ||
710 | { | ||
711 | //qDebug("KSelectAction::comboItems has to be fixed"); | ||
712 | if( d->m_menuAccelsEnabled ) | ||
713 | { | ||
714 | QStringList lst; | ||
715 | QStringList::ConstIterator it = d->m_list.begin(); | ||
716 | for( ; it != d->m_list.end(); ++it ) | ||
717 | { | ||
718 | QString item = *it; | ||
719 | int i = item.find( '&' ); | ||
720 | if ( i > -1 ) | ||
721 | item = item.remove( i, 1 ); | ||
722 | lst.append( item ); | ||
723 | } | ||
724 | return lst; | ||
725 | } | ||
726 | else | ||
727 | { | ||
728 | return d->m_list; | ||
729 | } | ||
730 | } | ||
731 | |||
732 | void KSelectAction::clear() | ||
733 | { | ||
734 | if ( d->m_menu ) | ||
735 | d->m_menu->clear(); | ||
736 | |||
737 | int len = containerCount(); | ||
738 | for( int i = 0; i < len; ++i ) | ||
739 | updateClear( i ); | ||
740 | } | ||
741 | |||
742 | void KSelectAction::updateClear( int id ) | ||
743 | { | ||
744 | |||
745 | QWidget* w = container( id ); | ||
746 | if ( w->inherits( "KToolBar" ) ) { | ||
747 | QWidget* r = static_cast<KToolBar*>( w )->getWidget( itemId( id ) ); | ||
748 | if ( r->inherits( "QComboBox" ) ) { | ||
749 | QComboBox *b = static_cast<QComboBox*>( r ); | ||
750 | b->clear(); | ||
751 | } | ||
752 | } | ||
753 | } | ||
754 | |||
755 | void KSelectAction::slotActivated( int id ) | ||
756 | { | ||
757 | if ( d->m_current == id ) | ||
758 | return; | ||
759 | |||
760 | setCurrentItem( id ); | ||
761 | // Delay this. Especially useful when the slot connected to activated() will re-create | ||
762 | // the menu, e.g. in the recent files action. This prevents a crash. | ||
763 | |||
764 | QTimer::singleShot( 0, this, SLOT( slotActivated() ) ); | ||
765 | } | ||
766 | |||
767 | void KSelectAction::slotActivated( const QString &text ) | ||
768 | { | ||
769 | if ( isEditable() ) | ||
770 | { | ||
771 | QStringList lst = items(); | ||
772 | if(lst.contains(text)==0) | ||
773 | { | ||
774 | lst.append( text ); | ||
775 | setItems( lst ); | ||
776 | } | ||
777 | } | ||
778 | |||
779 | int i = items().findIndex( text ); | ||
780 | if ( i > -1 ) | ||
781 | setCurrentItem( i ); | ||
782 | else | ||
783 | setCurrentItem( comboItems().findIndex( text ) ); | ||
784 | // Delay this. Especially useful when the slot connected to activated() will re-create | ||
785 | // the menu, e.g. in the recent files action. This prevents a crash. | ||
786 | |||
787 | QTimer::singleShot( 0, this, SLOT( slotActivated() ) ); | ||
788 | } | ||
789 | |||
790 | void KSelectAction::slotActivated() | ||
791 | { | ||
792 | KAction::slotActivated(); | ||
793 | kdDebug(129) << "KSelectAction::slotActivated currentItem=" << currentItem() << " currentText=" << currentText() << endl; | ||
794 | emit activated( currentItem() ); | ||
795 | emit activated( currentText() ); | ||
796 | } | ||
797 | |||
798 | void KSelectAction::setEditable( bool edit ) | ||
799 | { | ||
800 | d->m_edit = edit; | ||
801 | } | ||
802 | |||
803 | bool KSelectAction::isEditable() const | ||
804 | { | ||
805 | return d->m_edit; | ||
806 | } | ||
807 | |||
808 | void KSelectAction::setRemoveAmpersandsInCombo( bool b ) | ||
809 | { | ||
810 | setMenuAccelsEnabled( b ); | ||
811 | } | ||
812 | |||
813 | bool KSelectAction::removeAmpersandsInCombo() const | ||
814 | { | ||
815 | return menuAccelsEnabled( ); | ||
816 | } | ||
817 | |||
818 | void KSelectAction::setMenuAccelsEnabled( bool b ) | ||
819 | { | ||
820 | d->m_menuAccelsEnabled = b; | ||
821 | } | ||
822 | |||
823 | bool KSelectAction::menuAccelsEnabled() const | ||
824 | { | ||
825 | return d->m_menuAccelsEnabled; | ||
826 | } | ||
827 | |||
828 | class KListAction::KListActionPrivate | ||
829 | { | ||
830 | public: | ||
831 | KListActionPrivate() | ||
832 | { | ||
833 | m_current = 0; | ||
834 | } | ||
835 | int m_current; | ||
836 | }; | ||
837 | |||
838 | KListAction::KListAction( const QString& text, const KShortcut& cut, | ||
839 | QObject* parent, const char* name ) | ||
840 | : KSelectAction( text, cut, parent, name ) | ||
841 | { | ||
842 | d = new KListActionPrivate; | ||
843 | } | ||
844 | |||
845 | KListAction::KListAction( const QString& text, const KShortcut& cut, | ||
846 | const QObject* receiver, const char* slot, | ||
847 | QObject* parent, const char* name ) | ||
848 | : KSelectAction( text, cut, parent, name ) | ||
849 | { | ||
850 | d = new KListActionPrivate; | ||
851 | if ( receiver ) | ||
852 | connect( this, SIGNAL( activated( int ) ), receiver, slot ); | ||
853 | } | ||
854 | |||
855 | KListAction::KListAction( const QString& text, const QIconSet& pix, | ||
856 | const KShortcut& cut, | ||
857 | QObject* parent, const char* name ) | ||
858 | : KSelectAction( text, pix, cut, parent, name ) | ||
859 | { | ||
860 | d = new KListActionPrivate; | ||
861 | } | ||
862 | |||
863 | KListAction::KListAction( const QString& text, const QString& pix, | ||
864 | const KShortcut& cut, | ||
865 | QObject* parent, const char* name ) | ||
866 | : KSelectAction( text, pix, cut, parent, name ) | ||
867 | { | ||
868 | d = new KListActionPrivate; | ||
869 | } | ||
870 | |||
871 | KListAction::KListAction( const QString& text, const QIconSet& pix, | ||
872 | const KShortcut& cut, const QObject* receiver, | ||
873 | const char* slot, QObject* parent, | ||
874 | const char* name ) | ||
875 | : KSelectAction( text, pix, cut, parent, name ) | ||
876 | { | ||
877 | d = new KListActionPrivate; | ||
878 | if ( receiver ) | ||
879 | connect( this, SIGNAL( activated( int ) ), receiver, slot ); | ||
880 | } | ||
881 | |||
882 | KListAction::KListAction( const QString& text, const QString& pix, | ||
883 | const KShortcut& cut, const QObject* receiver, | ||
884 | const char* slot, QObject* parent, | ||
885 | const char* name ) | ||
886 | : KSelectAction( text, pix, cut, parent, name ) | ||
887 | { | ||
888 | d = new KListActionPrivate; | ||
889 | if ( receiver ) | ||
890 | connect( this, SIGNAL( activated( int ) ), receiver, slot ); | ||
891 | } | ||
892 | |||
893 | KListAction::KListAction( QObject* parent, const char* name ) | ||
894 | : KSelectAction( parent, name ) | ||
895 | { | ||
896 | d = new KListActionPrivate; | ||
897 | } | ||
898 | |||
899 | KListAction::~KListAction() | ||
900 | { | ||
901 | delete d; d = 0; | ||
902 | } | ||
903 | |||
904 | void KListAction::setCurrentItem( int index ) | ||
905 | { | ||
906 | KSelectAction::setCurrentItem( index ); | ||
907 | d->m_current = index; | ||
908 | |||
909 | // emit KAction::activated(); | ||
910 | // emit activated( currentItem() ); | ||
911 | // emit activated( currentText() ); | ||
912 | } | ||
913 | |||
914 | QString KListAction::currentText() const | ||
915 | { | ||
916 | if ( currentItem() < 0 ) | ||
917 | return QString::null; | ||
918 | |||
919 | return items()[ currentItem() ]; | ||
920 | } | ||
921 | |||
922 | int KListAction::currentItem() const | ||
923 | { | ||
924 | return d->m_current; | ||
925 | } | ||
926 | |||
927 | class KRecentFilesAction::KRecentFilesActionPrivate | ||
928 | { | ||
929 | public: | ||
930 | KRecentFilesActionPrivate() | ||
931 | { | ||
932 | m_maxItems = 0; | ||
933 | } | ||
934 | uint m_maxItems; | ||
935 | }; | ||
936 | |||
937 | KRecentFilesAction::KRecentFilesAction( const QString& text, | ||
938 | const KShortcut& cut, | ||
939 | QObject* parent, const char* name, | ||
940 | uint maxItems ) | ||
941 | : KListAction( text, cut, parent, name) | ||
942 | { | ||
943 | d = new KRecentFilesActionPrivate; | ||
944 | d->m_maxItems = maxItems; | ||
945 | |||
946 | init(); | ||
947 | } | ||
948 | |||
949 | KRecentFilesAction::KRecentFilesAction( const QString& text, | ||
950 | const KShortcut& cut, | ||
951 | const QObject* receiver, | ||
952 | const char* slot, | ||
953 | QObject* parent, const char* name, | ||
954 | uint maxItems ) | ||
955 | : KListAction( text, cut, parent, name) | ||
956 | { | ||
957 | d = new KRecentFilesActionPrivate; | ||
958 | d->m_maxItems = maxItems; | ||
959 | |||
960 | init(); | ||
961 | |||
962 | if ( receiver ) | ||
963 | connect( this, SIGNAL(urlSelected(const KURL&)), | ||
964 | receiver, slot ); | ||
965 | } | ||
966 | |||
967 | KRecentFilesAction::KRecentFilesAction( const QString& text, | ||
968 | const QIconSet& pix, | ||
969 | const KShortcut& cut, | ||
970 | QObject* parent, const char* name, | ||
971 | uint maxItems ) | ||
972 | : KListAction( text, pix, cut, parent, name) | ||
973 | { | ||
974 | d = new KRecentFilesActionPrivate; | ||
975 | d->m_maxItems = maxItems; | ||
976 | |||
977 | init(); | ||
978 | } | ||
979 | |||
980 | KRecentFilesAction::KRecentFilesAction( const QString& text, | ||
981 | const QString& pix, | ||
982 | const KShortcut& cut, | ||
983 | QObject* parent, const char* name, | ||
984 | uint maxItems ) | ||
985 | : KListAction( text, pix, cut, parent, name) | ||
986 | { | ||
987 | d = new KRecentFilesActionPrivate; | ||
988 | d->m_maxItems = maxItems; | ||
989 | |||
990 | init(); | ||
991 | } | ||
992 | |||
993 | KRecentFilesAction::KRecentFilesAction( const QString& text, | ||
994 | const QIconSet& pix, | ||
995 | const KShortcut& cut, | ||
996 | const QObject* receiver, | ||
997 | const char* slot, | ||
998 | QObject* parent, const char* name, | ||
999 | uint maxItems ) | ||
1000 | : KListAction( text, pix, cut, parent, name) | ||
1001 | { | ||
1002 | d = new KRecentFilesActionPrivate; | ||
1003 | d->m_maxItems = maxItems; | ||
1004 | |||
1005 | init(); | ||
1006 | |||
1007 | if ( receiver ) | ||
1008 | connect( this, SIGNAL(urlSelected(const KURL&)), | ||
1009 | receiver, slot ); | ||
1010 | } | ||
1011 | |||
1012 | KRecentFilesAction::KRecentFilesAction( const QString& text, | ||
1013 | const QString& pix, | ||
1014 | const KShortcut& cut, | ||
1015 | const QObject* receiver, | ||
1016 | const char* slot, | ||
1017 | QObject* parent, const char* name, | ||
1018 | uint maxItems ) | ||
1019 | : KListAction( text, pix, cut, parent, name) | ||
1020 | { | ||
1021 | d = new KRecentFilesActionPrivate; | ||
1022 | d->m_maxItems = maxItems; | ||
1023 | |||
1024 | init(); | ||
1025 | |||
1026 | if ( receiver ) | ||
1027 | connect( this, SIGNAL(urlSelected(const KURL&)), | ||
1028 | receiver, slot ); | ||
1029 | } | ||
1030 | |||
1031 | KRecentFilesAction::KRecentFilesAction( QObject* parent, const char* name, | ||
1032 | uint maxItems ) | ||
1033 | : KListAction( parent, name ) | ||
1034 | { | ||
1035 | d = new KRecentFilesActionPrivate; | ||
1036 | d->m_maxItems = maxItems; | ||
1037 | |||
1038 | init(); | ||
1039 | } | ||
1040 | |||
1041 | void KRecentFilesAction::init() | ||
1042 | { | ||
1043 | connect( this, SIGNAL( activated( const QString& ) ), | ||
1044 | this, SLOT( itemSelected( const QString& ) ) ); | ||
1045 | |||
1046 | setMenuAccelsEnabled( false ); | ||
1047 | } | ||
1048 | |||
1049 | KRecentFilesAction::~KRecentFilesAction() | ||
1050 | { | ||
1051 | delete d; d = 0; | ||
1052 | } | ||
1053 | |||
1054 | uint KRecentFilesAction::maxItems() const | ||
1055 | { | ||
1056 | return d->m_maxItems; | ||
1057 | } | ||
1058 | |||
1059 | void KRecentFilesAction::setMaxItems( uint maxItems ) | ||
1060 | { | ||
1061 | QStringList lst = items(); | ||
1062 | uint oldCount = lst.count(); | ||
1063 | |||
1064 | // set new maxItems | ||
1065 | d->m_maxItems = maxItems; | ||
1066 | |||
1067 | // remove all items that are too much | ||
1068 | while( lst.count() > maxItems ) | ||
1069 | { | ||
1070 | // remove last item | ||
1071 | lst.remove( lst.last() ); | ||
1072 | } | ||
1073 | |||
1074 | // set new list if changed | ||
1075 | if( lst.count() != oldCount ) | ||
1076 | setItems( lst ); | ||
1077 | } | ||
1078 | |||
1079 | void KRecentFilesAction::addURL( const KURL& url ) | ||
1080 | { | ||
1081 | QString file = url.prettyURL(); | ||
1082 | QStringList lst = items(); | ||
1083 | |||
1084 | // remove file if already in list | ||
1085 | lst.remove( file ); | ||
1086 | |||
1087 | // remove las item if already maxitems in list | ||
1088 | if( lst.count() == d->m_maxItems ) | ||
1089 | { | ||
1090 | // remove last item | ||
1091 | lst.remove( lst.last() ); | ||
1092 | } | ||
1093 | |||
1094 | // add file to list | ||
1095 | lst.prepend( file ); | ||
1096 | setItems( lst ); | ||
1097 | } | ||
1098 | |||
1099 | void KRecentFilesAction::removeURL( const KURL& url ) | ||
1100 | { | ||
1101 | QStringList lst = items(); | ||
1102 | QString file = url.prettyURL(); | ||
1103 | |||
1104 | // remove url | ||
1105 | if( lst.count() > 0 ) | ||
1106 | { | ||
1107 | lst.remove( file ); | ||
1108 | setItems( lst ); | ||
1109 | } | ||
1110 | } | ||
1111 | |||
1112 | void KRecentFilesAction::clearURLList() | ||
1113 | { | ||
1114 | clear(); | ||
1115 | } | ||
1116 | |||
1117 | void KRecentFilesAction::loadEntries( KConfig* config, QString groupname) | ||
1118 | { | ||
1119 | QString key; | ||
1120 | QString value; | ||
1121 | QString oldGroup; | ||
1122 | QStringList lst; | ||
1123 | |||
1124 | oldGroup = config->group(); | ||
1125 | |||
1126 | if (groupname.isEmpty()) | ||
1127 | groupname = "RecentFiles"; | ||
1128 | config->setGroup( groupname ); | ||
1129 | |||
1130 | // read file list | ||
1131 | for( unsigned int i = 1 ; i <= d->m_maxItems ; i++ ) | ||
1132 | { | ||
1133 | key = QString( "File%1" ).arg( i ); | ||
1134 | value = config->readEntry( key, QString::null ); | ||
1135 | |||
1136 | if (!value.isNull()) | ||
1137 | lst.append( value ); | ||
1138 | } | ||
1139 | |||
1140 | // set file | ||
1141 | setItems( lst ); | ||
1142 | |||
1143 | config->setGroup( oldGroup ); | ||
1144 | } | ||
1145 | |||
1146 | void KRecentFilesAction::saveEntries( KConfig* config, QString groupname ) | ||
1147 | { | ||
1148 | QString key; | ||
1149 | QString value; | ||
1150 | QStringList lst = items(); | ||
1151 | |||
1152 | if (groupname.isEmpty()) | ||
1153 | groupname = "RecentFiles"; | ||
1154 | |||
1155 | config->deleteGroup( groupname); | ||
1156 | |||
1157 | KConfigGroupSaver( config, groupname ); | ||
1158 | |||
1159 | // write file list | ||
1160 | for( unsigned int i = 1 ; i <= lst.count() ; i++ ) | ||
1161 | { | ||
1162 | key = QString( "File%1" ).arg( i ); | ||
1163 | value = lst[ i - 1 ]; | ||
1164 | config->writeEntry( key, value ); | ||
1165 | } | ||
1166 | } | ||
1167 | |||
1168 | void KRecentFilesAction::itemSelected( const QString& text ) | ||
1169 | { | ||
1170 | emit urlSelected( KURL( text ) ); | ||
1171 | } | ||
1172 | |||
1173 | class KFontAction::KFontActionPrivate | ||
1174 | { | ||
1175 | public: | ||
1176 | KFontActionPrivate() | ||
1177 | { | ||
1178 | } | ||
1179 | QStringList m_fonts; | ||
1180 | }; | ||
1181 | |||
1182 | KFontAction::KFontAction( const QString& text, | ||
1183 | const KShortcut& cut, QObject* parent, | ||
1184 | const char* name ) | ||
1185 | : KSelectAction( text, cut, parent, name ) | ||
1186 | { | ||
1187 | d = new KFontActionPrivate; | ||
1188 | get_fonts( d->m_fonts ); | ||
1189 | KSelectAction::setItems( d->m_fonts ); | ||
1190 | setEditable( true ); | ||
1191 | } | ||
1192 | |||
1193 | KFontAction::KFontAction( const QString& text, const KShortcut& cut, | ||
1194 | const QObject* receiver, const char* slot, | ||
1195 | QObject* parent, const char* name ) | ||
1196 | : KSelectAction( text, cut, receiver, slot, parent, name ) | ||
1197 | { | ||
1198 | d = new KFontActionPrivate; | ||
1199 | get_fonts( d->m_fonts ); | ||
1200 | KSelectAction::setItems( d->m_fonts ); | ||
1201 | setEditable( true ); | ||
1202 | } | ||
1203 | |||
1204 | KFontAction::KFontAction( const QString& text, const QIconSet& pix, | ||
1205 | const KShortcut& cut, | ||
1206 | QObject* parent, const char* name ) | ||
1207 | : KSelectAction( text, pix, cut, parent, name ) | ||
1208 | { | ||
1209 | d = new KFontActionPrivate; | ||
1210 | get_fonts( d->m_fonts ); | ||
1211 | KSelectAction::setItems( d->m_fonts ); | ||
1212 | setEditable( true ); | ||
1213 | } | ||
1214 | |||
1215 | KFontAction::KFontAction( const QString& text, const QString& pix, | ||
1216 | const KShortcut& cut, | ||
1217 | QObject* parent, const char* name ) | ||
1218 | : KSelectAction( text, pix, cut, parent, name ) | ||
1219 | { | ||
1220 | d = new KFontActionPrivate; | ||
1221 | get_fonts( d->m_fonts ); | ||
1222 | KSelectAction::setItems( d->m_fonts ); | ||
1223 | setEditable( true ); | ||
1224 | } | ||
1225 | |||
1226 | KFontAction::KFontAction( const QString& text, const QIconSet& pix, | ||
1227 | const KShortcut& cut, | ||
1228 | const QObject* receiver, const char* slot, | ||
1229 | QObject* parent, const char* name ) | ||
1230 | : KSelectAction( text, pix, cut, receiver, slot, parent, name ) | ||
1231 | { | ||
1232 | d = new KFontActionPrivate; | ||
1233 | get_fonts( d->m_fonts ); | ||
1234 | KSelectAction::setItems( d->m_fonts ); | ||
1235 | setEditable( true ); | ||
1236 | } | ||
1237 | |||
1238 | KFontAction::KFontAction( const QString& text, const QString& pix, | ||
1239 | const KShortcut& cut, | ||
1240 | const QObject* receiver, const char* slot, | ||
1241 | QObject* parent, const char* name ) | ||
1242 | : KSelectAction( text, pix, cut, receiver, slot, parent, name ) | ||
1243 | { | ||
1244 | d = new KFontActionPrivate; | ||
1245 | get_fonts( d->m_fonts ); | ||
1246 | KSelectAction::setItems( d->m_fonts ); | ||
1247 | setEditable( true ); | ||
1248 | } | ||
1249 | |||
1250 | |||
1251 | KFontAction::KFontAction( QObject* parent, const char* name ) | ||
1252 | : KSelectAction( parent, name ) | ||
1253 | { | ||
1254 | d = new KFontActionPrivate; | ||
1255 | get_fonts( d->m_fonts ); | ||
1256 | KSelectAction::setItems( d->m_fonts ); | ||
1257 | setEditable( true ); | ||
1258 | } | ||
1259 | |||
1260 | KFontAction::~KFontAction() | ||
1261 | { | ||
1262 | delete d; | ||
1263 | d = 0; | ||
1264 | } | ||
1265 | |||
1266 | /* | ||
1267 | * Maintenance note: Keep in sync with KFontCombo::setCurrentFont() | ||
1268 | */ | ||
1269 | void KFontAction::setFont( const QString &family ) | ||
1270 | { | ||
1271 | QString lowerName = family.lower(); | ||
1272 | int i = 0; | ||
1273 | for ( QStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) | ||
1274 | { | ||
1275 | if ((*it).lower() == lowerName) | ||
1276 | { | ||
1277 | setCurrentItem(i); | ||
1278 | return; | ||
1279 | } | ||
1280 | } | ||
1281 | i = lowerName.find(" ["); | ||
1282 | if (i>-1) | ||
1283 | { | ||
1284 | lowerName = lowerName.left(i); | ||
1285 | i = 0; | ||
1286 | for ( QStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) | ||
1287 | { | ||
1288 | if ((*it).lower() == lowerName) | ||
1289 | { | ||
1290 | setCurrentItem(i); | ||
1291 | return; | ||
1292 | } | ||
1293 | } | ||
1294 | } | ||
1295 | |||
1296 | lowerName += " ["; | ||
1297 | i = 0; | ||
1298 | for ( QStringList::Iterator it = d->m_fonts.begin(); it != d->m_fonts.end(); ++it, ++i ) | ||
1299 | { | ||
1300 | if ((*it).lower().startsWith(lowerName)) | ||
1301 | { | ||
1302 | setCurrentItem(i); | ||
1303 | return; | ||
1304 | } | ||
1305 | } | ||
1306 | kdDebug(129) << "Font not found " << family.lower() << endl; | ||
1307 | } | ||
1308 | |||
1309 | int KFontAction::plug( QWidget *w, int index ) | ||
1310 | { | ||
1311 | qDebug("KFontAction::plug ha to be fixed"); | ||
1312 | /*US | ||
1313 | if (kapp && !kapp->authorizeKAction(name())) | ||
1314 | return -1; | ||
1315 | if ( w->inherits("KToolBar") ) | ||
1316 | { | ||
1317 | KToolBar* bar = static_cast<KToolBar*>( w ); | ||
1318 | int id_ = KAction::getToolButtonID(); | ||
1319 | KFontCombo *cb = new KFontCombo( items(), bar ); | ||
1320 | connect( cb, SIGNAL( activated( const QString & ) ), | ||
1321 | SLOT( slotActivated( const QString & ) ) ); | ||
1322 | cb->setEnabled( isEnabled() ); | ||
1323 | bar->insertWidget( id_, comboWidth(), cb, index ); | ||
1324 | cb->setMinimumWidth( cb->sizeHint().width() ); | ||
1325 | |||
1326 | addContainer( bar, id_ ); | ||
1327 | |||
1328 | connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); | ||
1329 | |||
1330 | updateCurrentItem( containerCount() - 1 ); | ||
1331 | |||
1332 | return containerCount() - 1; | ||
1333 | } | ||
1334 | else return KSelectAction::plug( w, index ); | ||
1335 | */ | ||
1336 | return 3; | ||
1337 | } | ||
1338 | |||
1339 | class KFontSizeAction::KFontSizeActionPrivate | ||
1340 | { | ||
1341 | public: | ||
1342 | KFontSizeActionPrivate() | ||
1343 | { | ||
1344 | } | ||
1345 | }; | ||
1346 | |||
1347 | KFontSizeAction::KFontSizeAction( const QString& text, | ||
1348 | const KShortcut& cut, | ||
1349 | QObject* parent, const char* name ) | ||
1350 | : KSelectAction( text, cut, parent, name ) | ||
1351 | { | ||
1352 | init(); | ||
1353 | } | ||
1354 | |||
1355 | KFontSizeAction::KFontSizeAction( const QString& text, | ||
1356 | const KShortcut& cut, | ||
1357 | const QObject* receiver, const char* slot, | ||
1358 | QObject* parent, const char* name ) | ||
1359 | : KSelectAction( text, cut, receiver, slot, parent, name ) | ||
1360 | { | ||
1361 | init(); | ||
1362 | } | ||
1363 | |||
1364 | KFontSizeAction::KFontSizeAction( const QString& text, const QIconSet& pix, | ||
1365 | const KShortcut& cut, | ||
1366 | QObject* parent, const char* name ) | ||
1367 | : KSelectAction( text, pix, cut, parent, name ) | ||
1368 | { | ||
1369 | init(); | ||
1370 | } | ||
1371 | |||
1372 | KFontSizeAction::KFontSizeAction( const QString& text, const QString& pix, | ||
1373 | const KShortcut& cut, | ||
1374 | QObject* parent, const char* name ) | ||
1375 | : KSelectAction( text, pix, cut, parent, name ) | ||
1376 | { | ||
1377 | init(); | ||
1378 | } | ||
1379 | |||
1380 | KFontSizeAction::KFontSizeAction( const QString& text, const QIconSet& pix, | ||
1381 | const KShortcut& cut, | ||
1382 | const QObject* receiver, | ||
1383 | const char* slot, QObject* parent, | ||
1384 | const char* name ) | ||
1385 | : KSelectAction( text, pix, cut, receiver, slot, parent, name ) | ||
1386 | { | ||
1387 | init(); | ||
1388 | } | ||
1389 | |||
1390 | KFontSizeAction::KFontSizeAction( const QString& text, const QString& pix, | ||
1391 | const KShortcut& cut, | ||
1392 | const QObject* receiver, | ||
1393 | const char* slot, QObject* parent, | ||
1394 | const char* name ) | ||
1395 | : KSelectAction( text, pix, cut, receiver, slot, parent, name ) | ||
1396 | { | ||
1397 | init(); | ||
1398 | } | ||
1399 | |||
1400 | KFontSizeAction::KFontSizeAction( QObject* parent, const char* name ) | ||
1401 | : KSelectAction( parent, name ) | ||
1402 | { | ||
1403 | init(); | ||
1404 | } | ||
1405 | |||
1406 | KFontSizeAction::~KFontSizeAction() | ||
1407 | { | ||
1408 | delete d; | ||
1409 | d = 0; | ||
1410 | } | ||
1411 | |||
1412 | void KFontSizeAction::init() | ||
1413 | { | ||
1414 | d = new KFontSizeActionPrivate; | ||
1415 | |||
1416 | setEditable( true ); | ||
1417 | QValueList<int> sizes = get_standard_font_sizes(); | ||
1418 | QStringList lst; | ||
1419 | for ( QValueList<int>::Iterator it = sizes.begin(); it != sizes.end(); ++it ) | ||
1420 | lst.append( QString::number( *it ) ); | ||
1421 | |||
1422 | setItems( lst ); | ||
1423 | } | ||
1424 | |||
1425 | void KFontSizeAction::setFontSize( int size ) | ||
1426 | { | ||
1427 | if ( size == fontSize() ) { | ||
1428 | setCurrentItem( items().findIndex( QString::number( size ) ) ); | ||
1429 | return; | ||
1430 | } | ||
1431 | |||
1432 | if ( size < 1 ) { | ||
1433 | kdWarning() << "KFontSizeAction: Size " << size << " is out of range" << endl; | ||
1434 | return; | ||
1435 | } | ||
1436 | |||
1437 | int index = items().findIndex( QString::number( size ) ); | ||
1438 | if ( index == -1 ) { | ||
1439 | // Insert at the correct position in the list (to keep sorting) | ||
1440 | QValueList<int> lst; | ||
1441 | // Convert to list of ints | ||
1442 | QStringList itemsList = items(); | ||
1443 | for (QStringList::Iterator it = itemsList.begin() ; it != itemsList.end() ; ++it) | ||
1444 | lst.append( (*it).toInt() ); | ||
1445 | // New size | ||
1446 | lst.append( size ); | ||
1447 | // Sort the list | ||
1448 | qDebug("KFontSizeAction::setFontSize heapsort not found."); | ||
1449 | //US has to be fixed | ||
1450 | //US qHeapSort( lst ); | ||
1451 | // Convert back to string list | ||
1452 | QStringList strLst; | ||
1453 | for (QValueList<int>::Iterator it = lst.begin() ; it != lst.end() ; ++it) | ||
1454 | strLst.append( QString::number(*it) ); | ||
1455 | KSelectAction::setItems( strLst ); | ||
1456 | // Find new current item | ||
1457 | index = lst.findIndex( size ); | ||
1458 | setCurrentItem( index ); | ||
1459 | } | ||
1460 | else | ||
1461 | setCurrentItem( index ); | ||
1462 | |||
1463 | |||
1464 | //emit KAction::activated(); | ||
1465 | //emit activated( index ); | ||
1466 | //emit activated( QString::number( size ) ); | ||
1467 | //emit fontSizeChanged( size ); | ||
1468 | } | ||
1469 | |||
1470 | int KFontSizeAction::fontSize() const | ||
1471 | { | ||
1472 | return currentText().toInt(); | ||
1473 | } | ||
1474 | |||
1475 | void KFontSizeAction::slotActivated( int index ) | ||
1476 | { | ||
1477 | KSelectAction::slotActivated( index ); | ||
1478 | |||
1479 | emit fontSizeChanged( items()[ index ].toInt() ); | ||
1480 | } | ||
1481 | |||
1482 | void KFontSizeAction::slotActivated( const QString& size ) | ||
1483 | { | ||
1484 | setFontSize( size.toInt() ); // insert sorted first | ||
1485 | KSelectAction::slotActivated( size ); | ||
1486 | emit fontSizeChanged( size.toInt() ); | ||
1487 | } | ||
1488 | |||
1489 | class KActionMenu::KActionMenuPrivate | ||
1490 | { | ||
1491 | public: | ||
1492 | KActionMenuPrivate() | ||
1493 | { | ||
1494 | //US m_popup = new KPopupMenu(0L,"KActionMenu::KActionMenuPrivate"); | ||
1495 | m_popup = new QPopupMenu(0L,"KActionMenu::KActionMenuPrivate"); | ||
1496 | m_delayed = true; | ||
1497 | m_stickyMenu = true; | ||
1498 | } | ||
1499 | ~KActionMenuPrivate() | ||
1500 | { | ||
1501 | delete m_popup; m_popup = 0; | ||
1502 | } | ||
1503 | |||
1504 | //US KPopupMenu *m_popup; | ||
1505 | QPopupMenu *m_popup; | ||
1506 | bool m_delayed; | ||
1507 | bool m_stickyMenu; | ||
1508 | }; | ||
1509 | |||
1510 | KActionMenu::KActionMenu( QObject* parent, const char* name ) | ||
1511 | : KAction( parent, name ) | ||
1512 | { | ||
1513 | d = new KActionMenuPrivate; | ||
1514 | setShortcutConfigurable( false ); | ||
1515 | } | ||
1516 | |||
1517 | KActionMenu::KActionMenu( const QString& text, QObject* parent, | ||
1518 | const char* name ) | ||
1519 | : KAction( text, 0, parent, name ) | ||
1520 | { | ||
1521 | d = new KActionMenuPrivate; | ||
1522 | setShortcutConfigurable( false ); | ||
1523 | } | ||
1524 | |||
1525 | KActionMenu::KActionMenu( const QString& text, const QIconSet& icon, | ||
1526 | QObject* parent, const char* name ) | ||
1527 | : KAction( text, icon, 0, parent, name ) | ||
1528 | { | ||
1529 | d = new KActionMenuPrivate; | ||
1530 | setShortcutConfigurable( false ); | ||
1531 | } | ||
1532 | |||
1533 | KActionMenu::KActionMenu( const QString& text, const QString& icon, | ||
1534 | QObject* parent, const char* name ) | ||
1535 | : KAction( text, icon, 0, parent, name ) | ||
1536 | { | ||
1537 | d = new KActionMenuPrivate; | ||
1538 | setShortcutConfigurable( false ); | ||
1539 | } | ||
1540 | |||
1541 | KActionMenu::~KActionMenu() | ||
1542 | { | ||
1543 | unplugAll(); | ||
1544 | kdDebug(129) << "KActionMenu::~KActionMenu()" << endl; // ellis | ||
1545 | delete d; d = 0; | ||
1546 | } | ||
1547 | |||
1548 | void KActionMenu::popup( const QPoint& global ) | ||
1549 | { | ||
1550 | popupMenu()->popup( global ); | ||
1551 | } | ||
1552 | |||
1553 | |||
1554 | //US KPopupMenu* KActionMenu::popupMenu() const | ||
1555 | QPopupMenu* KActionMenu::popupMenu() const | ||
1556 | { | ||
1557 | return d->m_popup; | ||
1558 | } | ||
1559 | |||
1560 | void KActionMenu::insert( KAction* cmd, int index ) | ||
1561 | { | ||
1562 | if ( cmd ) | ||
1563 | cmd->plug( d->m_popup, index ); | ||
1564 | } | ||
1565 | |||
1566 | void KActionMenu::remove( KAction* cmd ) | ||
1567 | { | ||
1568 | if ( cmd ) | ||
1569 | cmd->unplug( d->m_popup ); | ||
1570 | } | ||
1571 | |||
1572 | bool KActionMenu::delayed() const { | ||
1573 | return d->m_delayed; | ||
1574 | } | ||
1575 | |||
1576 | void KActionMenu::setDelayed(bool _delayed) { | ||
1577 | d->m_delayed = _delayed; | ||
1578 | } | ||
1579 | |||
1580 | bool KActionMenu::stickyMenu() const { | ||
1581 | return d->m_stickyMenu; | ||
1582 | } | ||
1583 | |||
1584 | void KActionMenu::setStickyMenu(bool sticky) { | ||
1585 | d->m_stickyMenu = sticky; | ||
1586 | } | ||
1587 | |||
1588 | int KActionMenu::plug( QWidget* widget, int index ) | ||
1589 | { | ||
1590 | /*US | ||
1591 | if (kapp && !kapp->authorizeKAction(name())) | ||
1592 | return -1; | ||
1593 | */ | ||
1594 | kdDebug(129) << "KAction::plug( " << widget << ", " << index << " )" << endl; // remove -- ellis | ||
1595 | if ( widget->inherits("QPopupMenu") ) | ||
1596 | { | ||
1597 | QPopupMenu* menu = static_cast<QPopupMenu*>( widget ); | ||
1598 | int id; | ||
1599 | if ( hasIconSet() ) | ||
1600 | id = menu->insertItem( iconSet(), text(), d->m_popup, -1, index ); | ||
1601 | else | ||
1602 | id = menu->insertItem( text(), d->m_popup, -1, index ); | ||
1603 | |||
1604 | if ( !isEnabled() ) | ||
1605 | menu->setItemEnabled( id, false ); | ||
1606 | |||
1607 | addContainer( menu, id ); | ||
1608 | connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); | ||
1609 | |||
1610 | if ( m_parentCollection ) | ||
1611 | m_parentCollection->connectHighlight( menu, this ); | ||
1612 | |||
1613 | return containerCount() - 1; | ||
1614 | } | ||
1615 | else if ( widget->inherits( "KToolBar" ) ) | ||
1616 | { | ||
1617 | KToolBar *bar = static_cast<KToolBar *>( widget ); | ||
1618 | |||
1619 | int id_ = KAction::getToolButtonID(); | ||
1620 | |||
1621 | if ( icon().isEmpty() && !iconSet().isNull() ) | ||
1622 | bar->insertButton( iconSet().pixmap(), id_, SIGNAL( clicked() ), this, | ||
1623 | SLOT( slotActivated() ), isEnabled(), plainText(), | ||
1624 | index ); | ||
1625 | else | ||
1626 | { | ||
1627 | /*US | ||
1628 | KInstance *instance; | ||
1629 | |||
1630 | if ( m_parentCollection ) | ||
1631 | instance = m_parentCollection->instance(); | ||
1632 | else | ||
1633 | instance = KGlobal::instance(); | ||
1634 | */ | ||
1635 | bar->insertButton( icon(), id_, SIGNAL( clicked() ), this, | ||
1636 | SLOT( slotActivated() ), isEnabled(), plainText(), | ||
1637 | index/*US, instance */); | ||
1638 | } | ||
1639 | |||
1640 | addContainer( bar, id_ ); | ||
1641 | /*US | ||
1642 | if (!whatsThis().isEmpty()) | ||
1643 | QWhatsThis::add( bar->getButton(id_), whatsThis() ); | ||
1644 | */ | ||
1645 | connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); | ||
1646 | |||
1647 | if (delayed()) { | ||
1648 | bar->setDelayedPopup( id_, popupMenu(), stickyMenu() ); | ||
1649 | } else { | ||
1650 | bar->getButton(id_)->setPopup(popupMenu(), stickyMenu() ); | ||
1651 | } | ||
1652 | |||
1653 | if ( m_parentCollection ) | ||
1654 | m_parentCollection->connectHighlight( bar, this ); | ||
1655 | |||
1656 | return containerCount() - 1; | ||
1657 | } | ||
1658 | else if ( widget->inherits( "QMenuBar" ) ) | ||
1659 | { | ||
1660 | QMenuBar *bar = static_cast<QMenuBar *>( widget ); | ||
1661 | |||
1662 | int id; | ||
1663 | |||
1664 | id = bar->insertItem( text(), popupMenu(), -1, index ); | ||
1665 | |||
1666 | if ( !isEnabled() ) | ||
1667 | bar->setItemEnabled( id, false ); | ||
1668 | |||
1669 | addContainer( bar, id ); | ||
1670 | connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); | ||
1671 | |||
1672 | return containerCount() - 1; | ||
1673 | } | ||
1674 | |||
1675 | return -1; | ||
1676 | } | ||
1677 | |||
1678 | //////// | ||
1679 | |||
1680 | KToolBarPopupAction::KToolBarPopupAction( const QString& text, | ||
1681 | const QString& icon, | ||
1682 | const KShortcut& cut, | ||
1683 | QObject* parent, const char* name ) | ||
1684 | : KAction( text, icon, cut, parent, name ) | ||
1685 | { | ||
1686 | m_popup = 0; | ||
1687 | m_delayed = true; | ||
1688 | m_stickyMenu = true; | ||
1689 | } | ||
1690 | |||
1691 | KToolBarPopupAction::KToolBarPopupAction( const QString& text, | ||
1692 | const QString& icon, | ||
1693 | const KShortcut& cut, | ||
1694 | const QObject* receiver, | ||
1695 | const char* slot, QObject* parent, | ||
1696 | const char* name ) | ||
1697 | : KAction( text, icon, cut, receiver, slot, parent, name ) | ||
1698 | { | ||
1699 | m_popup = 0; | ||
1700 | m_delayed = true; | ||
1701 | m_stickyMenu = true; | ||
1702 | } | ||
1703 | |||
1704 | KToolBarPopupAction::KToolBarPopupAction( const KGuiItem& item, | ||
1705 | const KShortcut& cut, | ||
1706 | const QObject* receiver, | ||
1707 | const char* slot, KActionCollection* parent, | ||
1708 | const char* name ) | ||
1709 | : KAction( item, cut, receiver, slot, parent, name ) | ||
1710 | { | ||
1711 | m_popup = 0; | ||
1712 | m_delayed = true; | ||
1713 | m_stickyMenu = true; | ||
1714 | } | ||
1715 | |||
1716 | |||
1717 | KToolBarPopupAction::~KToolBarPopupAction() | ||
1718 | { | ||
1719 | if ( m_popup ) | ||
1720 | delete m_popup; | ||
1721 | } | ||
1722 | |||
1723 | bool KToolBarPopupAction::delayed() const { | ||
1724 | return m_delayed; | ||
1725 | } | ||
1726 | |||
1727 | void KToolBarPopupAction::setDelayed(bool delayed) { | ||
1728 | m_delayed = delayed; | ||
1729 | } | ||
1730 | |||
1731 | bool KToolBarPopupAction::stickyMenu() const { | ||
1732 | return m_stickyMenu; | ||
1733 | } | ||
1734 | |||
1735 | void KToolBarPopupAction::setStickyMenu(bool sticky) { | ||
1736 | m_stickyMenu = sticky; | ||
1737 | } | ||
1738 | |||
1739 | int KToolBarPopupAction::plug( QWidget *widget, int index ) | ||
1740 | { | ||
1741 | /*US | ||
1742 | if (kapp && !kapp->authorizeKAction(name())) | ||
1743 | return -1; | ||
1744 | */ | ||
1745 | // This is very related to KActionMenu::plug. | ||
1746 | // In fact this class could be an interesting base class for KActionMenu | ||
1747 | if ( widget->inherits( "KToolBar" ) ) | ||
1748 | { | ||
1749 | KToolBar *bar = (KToolBar *)widget; | ||
1750 | |||
1751 | int id_ = KAction::getToolButtonID(); | ||
1752 | /*US | ||
1753 | KInstance * instance; | ||
1754 | if ( m_parentCollection ) | ||
1755 | instance = m_parentCollection->instance(); | ||
1756 | else | ||
1757 | instance = KGlobal::instance(); | ||
1758 | */ | ||
1759 | bar->insertButton( icon(), id_, SIGNAL( clicked() ), this, | ||
1760 | SLOT( slotActivated() ), isEnabled(), plainText(), | ||
1761 | index/*US, instance*/ ); | ||
1762 | |||
1763 | addContainer( bar, id_ ); | ||
1764 | |||
1765 | connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); | ||
1766 | |||
1767 | if (delayed()) { | ||
1768 | bar->setDelayedPopup( id_, popupMenu(), stickyMenu() ); | ||
1769 | } else { | ||
1770 | bar->getButton(id_)->setPopup(popupMenu(), stickyMenu()); | ||
1771 | } | ||
1772 | /*US | ||
1773 | if ( !whatsThis().isEmpty() ) | ||
1774 | QWhatsThis::add( bar->getButton( id_ ), whatsThisWithIcon() ); | ||
1775 | */ | ||
1776 | return containerCount() - 1; | ||
1777 | } | ||
1778 | |||
1779 | |||
1780 | return KAction::plug( widget, index ); | ||
1781 | } | ||
1782 | |||
1783 | //US KPopupMenu *KToolBarPopupAction::popupMenu() const | ||
1784 | QPopupMenu *KToolBarPopupAction::popupMenu() const | ||
1785 | { | ||
1786 | if ( !m_popup ) { | ||
1787 | KToolBarPopupAction *that = const_cast<KToolBarPopupAction*>(this); | ||
1788 | //US that->m_popup = new KPopupMenu; | ||
1789 | that->m_popup = new QPopupMenu; | ||
1790 | } | ||
1791 | return m_popup; | ||
1792 | } | ||
1793 | |||
1794 | //////// | ||
1795 | |||
1796 | KToggleToolBarAction::KToggleToolBarAction( const char* toolBarName, | ||
1797 | const QString& text, KActionCollection* parent, const char* name ) | ||
1798 | : KToggleAction( text, KShortcut(), parent, name ) | ||
1799 | , m_toolBarName( toolBarName ) | ||
1800 | , m_toolBar( 0L ) | ||
1801 | { | ||
1802 | } | ||
1803 | |||
1804 | KToggleToolBarAction::KToggleToolBarAction( KToolBar *toolBar, const QString &text, | ||
1805 | KActionCollection *parent, const char *name ) | ||
1806 | : KToggleAction( text, KShortcut(), parent, name ) | ||
1807 | , m_toolBarName( 0 ) | ||
1808 | , m_toolBar( toolBar ) | ||
1809 | { | ||
1810 | } | ||
1811 | |||
1812 | KToggleToolBarAction::~KToggleToolBarAction() | ||
1813 | { | ||
1814 | } | ||
1815 | |||
1816 | int KToggleToolBarAction::plug( QWidget* w, int index ) | ||
1817 | { | ||
1818 | qDebug("KToggleToolBarAction::plug has to be fixed"); | ||
1819 | /*US | ||
1820 | if (kapp && !kapp->authorizeKAction(name())) | ||
1821 | return -1; | ||
1822 | |||
1823 | if ( !m_toolBar ) { | ||
1824 | // Note: topLevelWidget() stops too early, we can't use it. | ||
1825 | QWidget * tl = w; | ||
1826 | QWidget * n; | ||
1827 | while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store | ||
1828 | tl = n; | ||
1829 | |||
1830 | //US KMainWindow * mw = dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow | ||
1831 | QMainWindow * mw = 0; | ||
1832 | if ( tl->inherits("QMainWindow") ) | ||
1833 | mw = (QMainWindow *)(tl); // try to see if it's a kmainwindow | ||
1834 | |||
1835 | if ( mw ) | ||
1836 | m_toolBar = mw->toolBar( m_toolBarName ); | ||
1837 | } | ||
1838 | |||
1839 | if( m_toolBar ) { | ||
1840 | setChecked( m_toolBar->isVisible() ); | ||
1841 | connect( m_toolBar, SIGNAL(visibilityChanged(bool)), this, SLOT(setChecked(bool)) ); | ||
1842 | // Also emit toggled when the toolbar's visibility changes (see comment in header) | ||
1843 | connect( m_toolBar, SIGNAL(visibilityChanged(bool)), this, SIGNAL(toggled(bool)) ); | ||
1844 | } else { | ||
1845 | setEnabled( false ); | ||
1846 | } | ||
1847 | */ | ||
1848 | return KToggleAction::plug( w, index ); | ||
1849 | } | ||
1850 | |||
1851 | void KToggleToolBarAction::setChecked( bool c ) | ||
1852 | { | ||
1853 | if( m_toolBar && c != m_toolBar->isVisible() ) { | ||
1854 | if( c ) { | ||
1855 | m_toolBar->show(); | ||
1856 | } else { | ||
1857 | m_toolBar->hide(); | ||
1858 | } | ||
1859 | qDebug("KToggleToolBarAction::setChecked has to be fixed"); | ||
1860 | /*US | ||
1861 | QMainWindow* mw = m_toolBar->mainWindow(); | ||
1862 | if ( mw && mw->inherits( "KMainWindow" ) ) | ||
1863 | static_cast<KMainWindow *>( mw )->setSettingsDirty(); | ||
1864 | */ | ||
1865 | } | ||
1866 | KToggleAction::setChecked( c ); | ||
1867 | |||
1868 | } | ||
1869 | |||
1870 | //////// | ||
1871 | |||
1872 | KWidgetAction::KWidgetAction( QWidget* widget, | ||
1873 | const QString& text, const KShortcut& cut, | ||
1874 | const QObject* receiver, const char* slot, | ||
1875 | KActionCollection* parent, const char* name ) | ||
1876 | : KAction( text, cut, receiver, slot, parent, name ) | ||
1877 | , m_widget( widget ) | ||
1878 | , m_autoSized( false ) | ||
1879 | { | ||
1880 | } | ||
1881 | |||
1882 | KWidgetAction::~KWidgetAction() | ||
1883 | { | ||
1884 | } | ||
1885 | |||
1886 | void KWidgetAction::setAutoSized( bool autoSized ) | ||
1887 | { | ||
1888 | if( m_autoSized == autoSized ) | ||
1889 | return; | ||
1890 | |||
1891 | m_autoSized = autoSized; | ||
1892 | |||
1893 | if( !m_widget || !isPlugged() ) | ||
1894 | return; | ||
1895 | |||
1896 | KToolBar* toolBar = (KToolBar*)m_widget->parent(); | ||
1897 | int i = findContainer( toolBar ); | ||
1898 | if ( i == -1 ) | ||
1899 | return; | ||
1900 | int id = itemId( i ); | ||
1901 | |||
1902 | toolBar->setItemAutoSized( id, m_autoSized ); | ||
1903 | |||
1904 | } | ||
1905 | |||
1906 | int KWidgetAction::plug( QWidget* w, int index ) | ||
1907 | { | ||
1908 | /*US | ||
1909 | if (kapp && !kapp->authorizeKAction(name())) | ||
1910 | return -1; | ||
1911 | */ | ||
1912 | if ( !w->inherits( "KToolBar" ) ) { | ||
1913 | kdError() << "KWidgetAction::plug: KWidgetAction must be plugged into KToolBar." << endl; | ||
1914 | return -1; | ||
1915 | } | ||
1916 | if ( !m_widget ) { | ||
1917 | kdError() << "KWidgetAction::plug: Widget was deleted or null!" << endl; | ||
1918 | return -1; | ||
1919 | } | ||
1920 | |||
1921 | KToolBar* toolBar = static_cast<KToolBar*>( w ); | ||
1922 | |||
1923 | int id = KAction::getToolButtonID(); | ||
1924 | |||
1925 | m_widget->reparent( toolBar, QPoint() ); | ||
1926 | toolBar->insertWidget( id, 0, m_widget, index ); | ||
1927 | toolBar->setItemAutoSized( id, m_autoSized ); | ||
1928 | |||
1929 | //US QWhatsThis::add( m_widget, whatsThis() ); | ||
1930 | addContainer( toolBar, id ); | ||
1931 | |||
1932 | connect( toolBar, SIGNAL( toolbarDestroyed() ), this, SLOT( slotToolbarDestroyed() ) ); | ||
1933 | connect( toolBar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); | ||
1934 | |||
1935 | return containerCount() - 1; | ||
1936 | } | ||
1937 | |||
1938 | void KWidgetAction::unplug( QWidget *w ) | ||
1939 | { | ||
1940 | if( !m_widget || !isPlugged() ) | ||
1941 | return; | ||
1942 | |||
1943 | KToolBar* toolBar = (KToolBar*)m_widget->parent(); | ||
1944 | if ( toolBar == w ) | ||
1945 | { | ||
1946 | disconnect( toolBar, SIGNAL( toolbarDestroyed() ), this, SLOT( slotToolbarDestroyed() ) ); | ||
1947 | m_widget->reparent( 0L, QPoint(), false ); // false = showit | ||
1948 | } | ||
1949 | KAction::unplug( w ); | ||
1950 | } | ||
1951 | |||
1952 | void KWidgetAction::slotToolbarDestroyed() | ||
1953 | { | ||
1954 | //Q_ASSERT( m_widget ); // When exiting the app the widget could be destroyed before the toolbar. | ||
1955 | |||
1956 | ASSERT( isPlugged() ); | ||
1957 | if( !m_widget || !isPlugged() ) | ||
1958 | return; | ||
1959 | |||
1960 | // Don't let a toolbar being destroyed, delete my widget. | ||
1961 | m_widget->reparent( 0L, QPoint(), false /*showIt*/ ); | ||
1962 | } | ||
1963 | |||
1964 | //////// | ||
1965 | |||
1966 | KActionSeparator::KActionSeparator( QObject *parent, const char *name ) | ||
1967 | : KAction( parent, name ) | ||
1968 | { | ||
1969 | } | ||
1970 | |||
1971 | KActionSeparator::~KActionSeparator() | ||
1972 | { | ||
1973 | } | ||
1974 | |||
1975 | int KActionSeparator::plug( QWidget *widget, int index ) | ||
1976 | { | ||
1977 | if ( widget->inherits("QPopupMenu") ) | ||
1978 | { | ||
1979 | QPopupMenu* menu = static_cast<QPopupMenu*>( widget ); | ||
1980 | |||
1981 | int id = menu->insertSeparator( index ); | ||
1982 | |||
1983 | addContainer( menu, id ); | ||
1984 | connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); | ||
1985 | |||
1986 | return containerCount() - 1; | ||
1987 | } | ||
1988 | else if ( widget->inherits( "QMenuBar" ) ) | ||
1989 | { | ||
1990 | QMenuBar *menuBar = static_cast<QMenuBar *>( widget ); | ||
1991 | |||
1992 | int id = menuBar->insertSeparator( index ); | ||
1993 | |||
1994 | addContainer( menuBar, id ); | ||
1995 | |||
1996 | connect( menuBar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); | ||
1997 | |||
1998 | return containerCount() - 1; | ||
1999 | } | ||
2000 | else if ( widget->inherits( "KToolBar" ) ) | ||
2001 | { | ||
2002 | KToolBar *toolBar = static_cast<KToolBar *>( widget ); | ||
2003 | |||
2004 | int id = toolBar->insertSeparator( index ); | ||
2005 | // toolBar->addSeparator(); | ||
2006 | |||
2007 | addContainer( toolBar, id ); | ||
2008 | |||
2009 | connect( toolBar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) ); | ||
2010 | |||
2011 | return containerCount() - 1; | ||
2012 | } | ||
2013 | |||
2014 | return -1; | ||
2015 | } | ||
2016 | |||
2017 | void KToggleAction::virtual_hook( int id, void* data ) | ||
2018 | { KAction::virtual_hook( id, data ); } | ||
2019 | |||
2020 | void KRadioAction::virtual_hook( int id, void* data ) | ||
2021 | { KToggleAction::virtual_hook( id, data ); } | ||
2022 | |||
2023 | void KSelectAction::virtual_hook( int id, void* data ) | ||
2024 | { KAction::virtual_hook( id, data ); } | ||
2025 | |||
2026 | void KListAction::virtual_hook( int id, void* data ) | ||
2027 | { KSelectAction::virtual_hook( id, data ); } | ||
2028 | |||
2029 | void KRecentFilesAction::virtual_hook( int id, void* data ) | ||
2030 | { KListAction::virtual_hook( id, data ); } | ||
2031 | |||
2032 | void KFontAction::virtual_hook( int id, void* data ) | ||
2033 | { KSelectAction::virtual_hook( id, data ); } | ||
2034 | |||
2035 | void KFontSizeAction::virtual_hook( int id, void* data ) | ||
2036 | { KSelectAction::virtual_hook( id, data ); } | ||
2037 | |||
2038 | void KActionMenu::virtual_hook( int id, void* data ) | ||
2039 | { KAction::virtual_hook( id, data ); } | ||
2040 | |||
2041 | void KToolBarPopupAction::virtual_hook( int id, void* data ) | ||
2042 | { KAction::virtual_hook( id, data ); } | ||
2043 | |||
2044 | void KToggleToolBarAction::virtual_hook( int id, void* data ) | ||
2045 | { KToggleAction::virtual_hook( id, data ); } | ||
2046 | |||
2047 | void KWidgetAction::virtual_hook( int id, void* data ) | ||
2048 | { KAction::virtual_hook( id, data ); } | ||
2049 | |||
2050 | void KActionSeparator::virtual_hook( int id, void* data ) | ||
2051 | { KAction::virtual_hook( id, data ); } | ||
2052 | |||
2053 | /* vim: et sw=2 ts=2 | ||
2054 | */ | ||
2055 | |||
2056 | /*US | ||
2057 | #include "kactionclasses.moc" | ||
2058 | */ | ||