summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /microkde/kdeui
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'microkde/kdeui') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdeui/kaction.cpp1215
-rw-r--r--microkde/kdeui/kaction.h624
-rw-r--r--microkde/kdeui/kactionclasses.cpp2058
-rw-r--r--microkde/kdeui/kactionclasses.h1223
-rw-r--r--microkde/kdeui/kactioncollection.cpp839
-rw-r--r--microkde/kdeui/kactioncollection.h329
-rw-r--r--microkde/kdeui/kbuttonbox.cpp300
-rw-r--r--microkde/kdeui/kbuttonbox.h139
-rw-r--r--microkde/kdeui/kcmodule.cpp106
-rw-r--r--microkde/kdeui/kcmodule.h266
-rw-r--r--microkde/kdeui/kguiitem.cpp205
-rw-r--r--microkde/kdeui/kguiitem.h87
-rw-r--r--microkde/kdeui/kjanuswidget.cpp1176
-rw-r--r--microkde/kdeui/kjanuswidget.h565
-rw-r--r--microkde/kdeui/klistbox.cpp314
-rw-r--r--microkde/kdeui/klistbox.h141
-rw-r--r--microkde/kdeui/klistview.cpp2191
-rw-r--r--microkde/kdeui/klistview.h1033
-rw-r--r--microkde/kdeui/kmainwindow.cpp994
-rw-r--r--microkde/kdeui/kmainwindow.h776
-rw-r--r--microkde/kdeui/knuminput.cpp1095
-rw-r--r--microkde/kdeui/knuminput.h948
-rw-r--r--microkde/kdeui/knumvalidator.cpp372
-rw-r--r--microkde/kdeui/knumvalidator.h209
-rw-r--r--microkde/kdeui/kseparator.cpp121
-rw-r--r--microkde/kdeui/kseparator.h77
-rw-r--r--microkde/kdeui/ksqueezedtextlabel.cpp107
-rw-r--r--microkde/kdeui/ksqueezedtextlabel.h76
-rw-r--r--microkde/kdeui/kstdaction.cpp362
-rw-r--r--microkde/kdeui/kstdaction.h568
-rw-r--r--microkde/kdeui/ktoolbar.cpp2260
-rw-r--r--microkde/kdeui/ktoolbar.h1107
-rw-r--r--microkde/kdeui/ktoolbarbutton.cpp756
-rw-r--r--microkde/kdeui/ktoolbarbutton.h313
-rw-r--r--microkde/kdeui/ktoolbarhandler.cpp253
-rw-r--r--microkde/kdeui/ktoolbarhandler.h70
-rw-r--r--microkde/kdeui/kxmlguiclient.cpp958
-rw-r--r--microkde/kdeui/kxmlguiclient.h361
38 files changed, 24594 insertions, 0 deletions
diff --git a/microkde/kdeui/kaction.cpp b/microkde/kdeui/kaction.cpp
new file mode 100644
index 0000000..77d36a5
--- a/dev/null
+++ b/microkde/kdeui/kaction.cpp
@@ -0,0 +1,1215 @@
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 "kaction.h"
27
28#include <assert.h>
29
30#include <qtooltip.h>
31//US#include <qwhatsthis.h>
32//US#include <kaccel.h>
33//US#include <kaccelbase.h>
34#include <kapplication.h>
35#include <kdebug.h>
36#include <kguiitem.h>
37//US#include <kmainwindow.h>
38//US#include <kmenubar.h>
39//US#include <kpopupmenu.h>
40#include <ktoolbar.h>
41#include <ktoolbarbutton.h>
42
43//US added this includefiles
44#include <qmenubar.h>
45#include <qtoolbar.h>
46#include <qpopupmenu.h>
47#include <qiconset.h>
48
49/**
50* How it works.
51* KActionCollection is an organizing container for KActions.
52* KActionCollection keeps track of the information necessary to handle
53* configuration and shortcuts.
54*
55* Focus Widget pointer:
56* This is the widget which is the focus for action shortcuts.
57* It is set either by passing a QWidget* to the KActionCollection constructor
58* or by calling setWidget() if the widget wasn't known when the object was
59* initially constructed (as in KXMLGUIClient and KParts::PartBase)
60*
61* Shortcuts:
62* An action's shortcut will not not be connected unless a focus widget has
63* been specified in KActionCollection.
64*
65* XML Filename:
66* This is used to save user-modified settings back to the *ui.rc file.
67* It is set by KXMLGUIFactory.
68*/
69
70int KAction::getToolButtonID()
71{
72 static int toolbutton_no = -2;
73 return toolbutton_no--;
74}
75
76//---------------------------------------------------------------------
77// KAction::KActionPrivate
78//---------------------------------------------------------------------
79
80class KAction::KActionPrivate : public KGuiItem
81{
82public:
83 KActionPrivate() : KGuiItem()
84 {
85 m_kaccel = 0;
86 m_configurable = true;
87 }
88
89 KAccel *m_kaccel;
90 QValueList<KAccel*> m_kaccelList;
91
92 QString m_groupText;
93 QString m_group;
94
95 KShortcut m_cut;
96 KShortcut m_cutDefault;
97
98 bool m_configurable;
99
100 struct Container
101 {
102 Container() { m_container = 0; m_representative = 0; m_id = 0; }
103 Container( const Container& s ) { m_container = s.m_container;
104 m_id = s.m_id; m_representative = s.m_representative; }
105 QWidget* m_container;
106 int m_id;
107 QWidget* m_representative;
108 };
109
110 QValueList<Container> m_containers;
111};
112
113//---------------------------------------------------------------------
114// KAction
115//---------------------------------------------------------------------
116KAction::KAction( const QString& text, const KShortcut& cut,
117 const QObject* receiver, const char* slot,
118 KActionCollection* parent, const char* name )
119: QObject( parent, name )
120{
121 initPrivate( text, cut, receiver, slot );
122}
123
124KAction::KAction( const QString& text, const QString& sIconName, const KShortcut& cut,
125 const QObject* receiver, const char* slot,
126 KActionCollection* parent, const char* name )
127: QObject( parent, name )
128{
129 initPrivate( text, cut, receiver, slot );
130 d->setIconName( sIconName );
131}
132
133KAction::KAction( const QString& text, const QIconSet& pix, const KShortcut& cut,
134 const QObject* receiver, const char* slot,
135 KActionCollection* parent, const char* name )
136: QObject( parent, name )
137{
138 initPrivate( text, cut, receiver, slot );
139 d->setIconSet( pix );
140}
141KAction::KAction( const KGuiItem& item, const KShortcut& cut,
142 const QObject* receiver, const char* slot,
143 KActionCollection* parent, const char* name )
144: QObject( parent, name )
145{
146 initPrivate( item.text(), cut, receiver, slot );
147 if( item.hasIconSet() )
148 setIcon( item.iconName() );
149 setToolTip( item.toolTip() );
150 setWhatsThis( item.whatsThis() );
151}
152
153// KDE 4: remove
154KAction::KAction( const QString& text, const KShortcut& cut,
155 QObject* parent, const char* name )
156 : QObject( parent, name )
157{
158 initPrivate( text, cut, 0, 0 );
159}
160KAction::KAction( const QString& text, const KShortcut& cut,
161 const QObject* receiver,
162 const char* slot, QObject* parent, const char* name )
163 : QObject( parent, name )
164{
165 initPrivate( text, cut, receiver, slot );
166}
167KAction::KAction( const QString& text, const QIconSet& pix,
168 const KShortcut& cut,
169 QObject* parent, const char* name )
170 : QObject( parent, name )
171{
172 initPrivate( text, cut, 0, 0 );
173 setIconSet( pix );
174}
175
176KAction::KAction( const QString& text, const QString& pix,
177 const KShortcut& cut,
178 QObject* parent, const char* name )
179: QObject( parent, name )
180{
181 initPrivate( text, cut, 0, 0 );
182 d->setIconName( pix );
183}
184
185KAction::KAction( const QString& text, const QIconSet& pix,
186 const KShortcut& cut,
187 const QObject* receiver, const char* slot, QObject* parent,
188 const char* name )
189 : QObject( parent, name )
190{
191 initPrivate( text, cut, receiver, slot );
192 setIconSet( pix );
193}
194
195KAction::KAction( const QString& text, const QString& pix,
196 const KShortcut& cut,
197 const QObject* receiver, const char* slot, QObject* parent,
198 const char* name )
199 : QObject( parent, name )
200{
201 initPrivate( text, cut, receiver, slot );
202 d->setIconName(pix);
203}
204
205KAction::KAction( QObject* parent, const char* name )
206 : QObject( parent, name )
207{
208
209 initPrivate( QString::null, KShortcut(), 0, 0 );
210}
211// KDE 4: remove end
212
213KAction::~KAction()
214{
215 kdDebug(129) << "KAction::~KAction( this = \"" << name() << "\" )" << endl; // -- ellis
216#ifndef KDE_NO_COMPAT
217 if (d->m_kaccel)
218 unplugAccel();
219#endif
220
221 // If actionCollection hasn't already been destructed,
222 if ( m_parentCollection ) {
223 m_parentCollection->take( this );
224 for( uint i = 0; i < d->m_kaccelList.count(); i++ )
225//US d->m_kaccelList[i]->remove( name() );
226 qDebug("KAction::KAction~ ...1 has top be fixed");
227 }
228
229 // Do not call unplugAll from here, as tempting as it sounds.
230 // KAction is designed around the idea that you need to plug
231 // _and_ to unplug it "manually". Unplugging leads to an important
232 // slowdown when e.g. closing the window, in which case we simply
233 // want to destroy everything asap, not to remove actions one by one
234 // from the GUI.
235
236 delete d; d = 0;
237}
238
239void KAction::initPrivate( const QString& text, const KShortcut& cut,
240 const QObject* receiver, const char* slot )
241{
242 d = new KActionPrivate;
243
244 d->m_cutDefault = cut;
245
246//US m_parentCollection = dynamic_cast<KActionCollection *>( parent() );
247 m_parentCollection = (KActionCollection *)( parent() );
248 kdDebug(129) << "KAction::initPrivate(): this = " << this << " name = \"" << name() << "\" cut = " << cut.toStringInternal() << " m_parentCollection = " << m_parentCollection << endl;
249 if ( m_parentCollection )
250 m_parentCollection->insert( this );
251
252 if ( receiver && slot )
253 connect( this, SIGNAL( activated() ), receiver, slot );
254
255 if( !cut.isNull() && qstrcmp( name(), "unnamed" ) == 0 )
256 kdWarning(129) << "KAction::initPrivate(): trying to assign a shortcut (" << cut.toStringInternal() << ") to an unnamed action." << endl;
257 d->setText( text );
258 initShortcut( cut );
259
260}
261
262bool KAction::isPlugged() const
263{
264 return (containerCount() > 0) || d->m_kaccel;
265}
266
267bool KAction::isPlugged( const QWidget *container ) const
268{
269 return findContainer( container ) > -1;
270}
271
272bool KAction::isPlugged( const QWidget *container, int id ) const
273{
274 int i = findContainer( container );
275 return ( i > -1 && itemId( i ) == id );
276}
277
278bool KAction::isPlugged( const QWidget *container, const QWidget *_representative ) const
279{
280 int i = findContainer( container );
281 return ( i > -1 && representative( i ) == _representative );
282}
283
284
285/*
286Three actionCollection conditions:
287 1) Scope is known on creation and KAccel object is created (e.g. KMainWindow)
288 2) Scope is unknown and no KAccel object is available (e.g. KXMLGUIClient)
289 a) addClient() will be called on object
290 b) we just want to add the actions to another KXMLGUIClient object
291
292The question is how to do we incorporate #2b into the XMLGUI framework?
293
294
295We have a KCommandHistory object with undo and redo actions in a passed actionCollection
296We have a KoDoc object which holds a KCommandHistory object and the actionCollection
297We have two KoView objects which both point to the same KoDoc object
298Undo and Redo should be available in both KoView objects, and
299 calling the undo->setEnabled() should affect both KoViews
300
301When addClient is called, it needs to be able to find the undo and redo actions
302When it calls plug() on them, they need to be inserted into the KAccel object of the appropriate KoView
303
304In this case, the actionCollection belongs to KoDoc and we need to let it know that its shortcuts
305have the same scope as the KoView actionCollection
306
307KXMLGUIClient::addSubActionCollection
308
309Document:
310 create document actions
311
312View
313 create view actions
314 add document actionCollection as sub-collection
315
316A parentCollection is created
317Scenario 1: parentCollection has a focus widget set (e.g. via KMainWindow)
318 A KAccel object is created in the parentCollection
319 A KAction is created with parent=parentCollection
320 The shortcut is inserted into this actionCollection
321 Scenario 1a: xml isn't used
322 done
323 Scenario 1b: KXMLGUIBuilder::addClient() called
324 setWidget is called -- ignore
325 shortcuts are set
326Scenario 2: parentCollection has no focus widget (e.g., KParts)
327 A KAction is created with parent=parentCollection
328 Scenario 2a: xml isn't used
329 no shortcuts
330 Scenario 2b: KXMLGUIBuilder::addClient() called
331 setWidget is called
332 shortcuts are inserted into current KAccel
333 shortcuts are set in all other KAccels, if the action is present in the other KAccels
334*/
335
336/*
337shortcut may be set:
338 - on construction
339 - on plug
340 - on reading XML
341 - on plugAccel (deprecated)
342
343On Construction: [via initShortcut()]
344 insert into KAccel of m_parentCollection,
345 if kaccel() && isAutoConnectShortcuts() exists
346
347On Plug: [via plug() -> plugShortcut()]
348 insert into KAccel of m_parentCollection, if exists and not already inserted into
349
350On Read XML: [via setShortcut()]
351 set in all current KAccels
352 insert into KAccel of m_parentCollection, if exists and not already inserted into
353*/
354
355KAccel* KAction::kaccelCurrent()
356{
357 if( m_parentCollection && m_parentCollection->builderKAccel() )
358 return m_parentCollection->builderKAccel();
359 else if( m_parentCollection && m_parentCollection->kaccel() )
360 return m_parentCollection->kaccel();
361 else
362 return 0L;
363}
364
365// Only to be called from initPrivate()
366bool KAction::initShortcut( const KShortcut& cut )
367{
368 d->m_cut = cut;
369
370 // Only insert action into KAccel if it has a valid name,
371 if( qstrcmp( name(), "unnamed" ) != 0 &&
372 m_parentCollection &&
373 m_parentCollection->isAutoConnectShortcuts() &&
374 m_parentCollection->kaccel() )
375 {
376 insertKAccel( m_parentCollection->kaccel() );
377 return true;
378 }
379 return false;
380 }
381
382// Only to be called from plug()
383void KAction::plugShortcut()
384{
385 KAccel* kaccel = kaccelCurrent();
386
387 //kdDebug(129) << "KAction::plugShortcut(): this = " << this << " kaccel() = " << (m_parentCollection ? m_parentCollection->kaccel() : 0) << endl;
388 if( kaccel && qstrcmp( name(), "unnamed" ) != 0 ) {
389 // Check if already plugged into current KAccel object
390 for( uint i = 0; i < d->m_kaccelList.count(); i++ ) {
391 if( d->m_kaccelList[i] == kaccel )
392 return;
393 }
394
395 insertKAccel( kaccel );
396 }
397}
398
399bool KAction::setShortcut( const KShortcut& cut )
400{
401 qDebug("KAction::setShortcut~ ...1 has top be fixed");
402/*US
403 bool bChanged = (d->m_cut != cut);
404 d->m_cut = cut;
405
406 KAccel* kaccel = kaccelCurrent();
407 bool bInsertRequired = true;
408 // Apply new shortcut to all existing KAccel objects
409 for( uint i = 0; i < d->m_kaccelList.count(); i++ ) {
410 // Check whether shortcut has already been plugged into
411 // the current kaccel object.
412 if( d->m_kaccelList[i] == kaccel )
413 bInsertRequired = false;
414 if( bChanged )
415 updateKAccelShortcut( d->m_kaccelList[i] );
416 }
417
418 // Only insert action into KAccel if it has a valid name,
419 if( kaccel && bInsertRequired && qstrcmp( name(), "unnamed" ) )
420 insertKAccel( kaccel );
421
422 if( bChanged ) {
423 // KDE 4: remove
424 if ( d->m_kaccel )
425 d->m_kaccel->setShortcut( name(), cut );
426 // KDE 4: remove end
427 int len = containerCount();
428 for( int i = 0; i < len; ++i )
429 updateShortcut( i );
430 }
431*/
432
433 return true;
434}
435
436bool KAction::updateKAccelShortcut( KAccel* kaccel )
437{
438 qDebug("KAction::updateKAccelShortcut~ ...1 has top be fixed");
439 // Check if action is permitted
440/*US
441 if (kapp && !kapp->authorizeKAction(name()))
442 return false;
443
444 bool b = true;
445
446 if ( !kaccel->actions().actionPtr( name() ) ) {
447 if(!d->m_cut.isNull() ) {
448 kdDebug(129) << "Inserting " << name() << ", " << d->text() << ", " << d->plainText() << endl;
449 b = kaccel->insert( name(), d->plainText(), QString::null,
450 d->m_cut,
451 this, SLOT(slotActivated()),
452 isShortcutConfigurable(), isEnabled() );
453 }
454 }
455 else
456 b = kaccel->setShortcut( name(), d->m_cut );
457
458 return b;
459*/
460 return true;
461}
462
463void KAction::insertKAccel( KAccel* kaccel )
464{
465 qDebug("KAction::updateKAccelShortcut~ ...1 has top be fixed");
466/*US
467 //kdDebug(129) << "KAction::insertKAccel( " << kaccel << " ): this = " << this << endl;
468 if ( !kaccel->actions().actionPtr( name() ) ) {
469 if( updateKAccelShortcut( kaccel ) ) {
470 d->m_kaccelList.append( kaccel );
471 connect( kaccel, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) );
472 }
473 }
474 else
475 kdWarning(129) << "KAction::insertKAccel( kaccel = " << kaccel << " ): KAccel object already contains an action name \"" << name() << "\"" << endl; // -- ellis
476*/
477}
478
479void KAction::removeKAccel( KAccel* kaccel )
480{
481 qDebug("KAction::removeKAccel~ ...1 has top be fixed");
482/*US
483 //kdDebug(129) << "KAction::removeKAccel( " << i << " ): this = " << this << endl;
484 for( uint i = 0; i < d->m_kaccelList.count(); i++ ) {
485 if( d->m_kaccelList[i] == kaccel ) {
486 kaccel->remove( name() );
487 d->m_kaccelList.remove( d->m_kaccelList.at( i ) );
488 disconnect( kaccel, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) );
489 break;
490 }
491 }
492*/
493}
494
495// KDE 4: remove
496void KAction::setAccel( int keyQt )
497{
498 setShortcut( KShortcut(keyQt) );
499}
500// KDE 4: remove end
501
502void KAction::updateShortcut( int i )
503{
504 int id = itemId( i );
505
506 QWidget* w = container( i );
507 if ( w->inherits( "QPopupMenu" ) ) {
508 QPopupMenu* menu = static_cast<QPopupMenu*>(w);
509 updateShortcut( menu, id );
510 }
511 else if ( w->inherits( "QMenuBar" ) )
512//US static_cast<QMenuBar*>(w)->setAccel( d->m_cut.keyCodeQt(), id );
513//US (QMenuBar*)(w)->setAccel( d->m_cut.keyCodeQt(), id );
514 qDebug("KAction::updateShortcut( int i ) ...1 has top be fixed");
515
516}
517
518void KAction::updateShortcut( QPopupMenu* menu, int id )
519{
520/*US
521 //kdDebug(129) << "KAction::updateShortcut(): this = " << this << " d->m_kaccelList.count() = " << d->m_kaccelList.count() << endl;
522 // If the action has a KAccel object,
523 // show the string representation of its shortcut.
524 if ( d->m_kaccel || d->m_kaccelList.count() ) {
525 QString s = menu->text( id );
526 int i = s.find( '\t' );
527 if ( i >= 0 )
528 s.replace( i+1, s.length()-i, d->m_cut.seq(0).toString() );
529 else
530 s += "\t" + d->m_cut.seq(0).toString();
531
532 menu->changeItem( id, s );
533 }
534 // Otherwise insert the shortcut itself into the popup menu.
535 else {
536 // This is a fall-hack in case the KAction is missing a proper parent collection.
537 // It should be removed eventually. --ellis
538 menu->setAccel( d->m_cut.keyCodeQt(), id );
539 kdWarning(129) << "KAction::updateShortcut(): name = \"" << name() << "\", cut = " << d->m_cut.toStringInternal() << "; No KAccel, probably missing a parent collection." << endl;
540 }
541*/
542 qDebug("KAction::updateShortcut( QPopupMenu* menu, int id ) ...1 has top be fixed");
543
544}
545
546const KShortcut& KAction::shortcut() const
547{
548 return d->m_cut;
549}
550
551const KShortcut& KAction::shortcutDefault() const
552{
553 return d->m_cutDefault;
554}
555
556QString KAction::shortcutText() const
557{
558 return d->m_cut.toStringInternal();
559}
560
561void KAction::setShortcutText( const QString& s )
562{
563 setShortcut( KShortcut(s) );
564}
565
566int KAction::accel() const
567{
568 qDebug("KAction::accel() ...1 has top be fixed");
569//US return d->m_cut.keyCodeQt();
570 return 0;
571}
572
573void KAction::setGroup( const QString& grp )
574{
575 d->m_group = grp;
576
577 int len = containerCount();
578 for( int i = 0; i < len; ++i )
579 updateGroup( i );
580}
581
582void KAction::updateGroup( int )
583{
584 // DO SOMETHING
585}
586
587QString KAction::group() const
588{
589 return d->m_group;
590}
591
592bool KAction::isEnabled() const
593{
594 return d->isEnabled();
595}
596
597bool KAction::isShortcutConfigurable() const
598{
599 return d->m_configurable;
600}
601
602void KAction::setToolTip( const QString& tt )
603{
604 qDebug("KAction::setToolTip ...1 has top be fixed");
605 d->setToolTip( tt );
606
607 int len = containerCount();
608 for( int i = 0; i < len; ++i )
609 updateToolTip( i );
610}
611
612void KAction::updateToolTip( int i )
613{
614 qDebug("KAction::updateToolTip ...1 has top be fixed");
615 QWidget *w = container( i );
616
617 if ( w->inherits( "KToolBar" ) )
618 QToolTip::add( static_cast<KToolBar*>(w)->getWidget( itemId( i ) ), d->toolTip() );
619 else if ( w->inherits( "QToolBar" ) )
620 QToolTip::add( static_cast<KToolBar*>(w)->getWidget( itemId( i ) ), d->toolTip() );
621}
622
623QString KAction::toolTip() const
624{
625 return d->toolTip();
626}
627
628int KAction::plug( QWidget *w, int index )
629{
630 //kdDebug(129) << "KAction::plug( " << w << ", " << index << " )" << endl;
631 if (w == 0) {
632 kdWarning(129) << "KAction::plug called with 0 argument\n";
633 return -1;
634 }
635
636#ifndef NDEBUG
637 KAccel* kaccel = kaccelCurrent();
638 // If there is a shortcut, but no KAccel available
639 if( !d->m_cut.isNull() && kaccel == 0 ) {
640 kdWarning(129) << "KAction::plug(): has no KAccel object; this = " << this << " name = " << name() << " parentCollection = " << m_parentCollection << endl; // ellis
641//US kdDebug(129) << kdBacktrace() << endl;
642 }
643#endif
644
645 // Check if action is permitted
646//US if (kapp && !kapp->authorizeKAction(name()))
647//US return -1;
648
649 plugShortcut();
650
651 if ( w->inherits("QPopupMenu") )
652 {
653 QPopupMenu* menu = static_cast<QPopupMenu*>( w );
654 int id;
655 // Don't insert shortcut into menu if it's already in a KAccel object.
656 //qDebug("KAction::plug warning: real shortcuts not available yet. ");
657//US int keyQt = (d->m_kaccelList.count() || d->m_kaccel) ? 0 : d->m_cut.keyCodeQt();
658 int keyQt = 0;
659
660 if ( d->hasIcon() )
661 {
662/*US
663 KInstance *instance;
664 if ( m_parentCollection )
665 instance = m_parentCollection->instance();
666 else
667 instance = KGlobal::instance();
668*/
669 id = menu->insertItem( d->iconSet( KIcon::Small, 0/*US , instance */), d->text(), this,//dsweet
670 SLOT( slotActivated() ), keyQt,
671 -1, index );
672 }
673 else
674 id = menu->insertItem( d->text(), this,
675 SLOT( slotActivated() ), //dsweet
676 keyQt, -1, index );
677
678 // If the shortcut is already in a KAccel object, then
679 // we need to set the menu item's shortcut text.
680/*US if ( d->m_kaccelList.count() || d->m_kaccel )
681 updateShortcut( menu, id );
682*/
683 // call setItemEnabled only if the item really should be disabled,
684 // because that method is slow and the item is per default enabled
685 if ( !d->isEnabled() )
686 menu->setItemEnabled( id, false );
687
688 if ( !d->whatsThis().isEmpty() )
689 menu->setWhatsThis( id, whatsThisWithIcon() );
690
691 addContainer( menu, id );
692 connect( menu, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
693
694 if ( m_parentCollection )
695 m_parentCollection->connectHighlight( menu, this );
696
697 return d->m_containers.count() - 1;
698 }
699 else if ( w->inherits( "KToolBar" ) )
700 {
701 KToolBar *bar = static_cast<KToolBar *>( w );
702
703 int id_ = getToolButtonID();
704/*US
705 KInstance *instance;
706 if ( m_parentCollection )
707 instance = m_parentCollection->instance();
708 else
709 instance = KGlobal::instance();
710*/
711 if ( icon().isEmpty() && !iconSet().pixmap().isNull() ) // old code using QIconSet directly
712 {
713 bar->insertButton( iconSet().pixmap(), id_, SIGNAL( clicked() ), this,
714 SLOT( slotActivated() ),
715 d->isEnabled(), d->plainText(), index );
716 }
717 else
718 {
719 QString icon = d->iconName();
720 if ( icon.isEmpty() )
721 icon = "unknown";
722 bar->insertButton( icon, id_, SIGNAL( clicked() ), this,
723 SLOT( slotActivated() ),
724 d->isEnabled(), d->plainText(), index/*US, instance*/ );
725 }
726 bar->getButton( id_ )->setName( QCString("toolbutton_")+name() );
727
728//US if ( !d->whatsThis().isEmpty() )
729//US QWhatsThis::add( bar->getButton(id_), whatsThisWithIcon() );
730 if ( !d->toolTip().isEmpty() )
731 QToolTip::add( bar->getButton(id_), d->toolTip() );
732
733 addContainer( bar, id_ );
734
735 connect( bar, SIGNAL( destroyed() ), this, SLOT( slotDestroyed() ) );
736
737 if ( m_parentCollection )
738 m_parentCollection->connectHighlight( bar, this );
739
740 return containerCount() - 1;
741
742 }
743
744 return -1;
745}
746
747void KAction::unplug( QWidget *w )
748{
749 int i = findContainer( w );
750 if ( i == -1 )
751 return;
752 int id = itemId( i );
753
754 if ( w->inherits( "QPopupMenu" ) )
755 {
756 QPopupMenu *menu = static_cast<QPopupMenu *>( w );
757 menu->removeItem( id );
758 }
759 else if ( w->inherits( "KToolBar" ) )
760 {
761 KToolBar *bar = static_cast<KToolBar *>( w );
762 bar->removeItemDelayed( id );
763 }
764 else if ( w->inherits( "QMenuBar" ) )
765 {
766 QMenuBar *bar = static_cast<QMenuBar *>( w );
767 bar->removeItem( id );
768 }
769
770 removeContainer( i );
771
772 if ( m_parentCollection )
773 m_parentCollection->disconnectHighlight( w, this );
774}
775
776void KAction::plugAccel(KAccel *kacc, bool configurable)
777{
778 qDebug("KAction::plugAccel ...1 has top be fixed");
779/*US
780 kdWarning(129) << "KAction::plugAccel(): call to deprecated action." << endl;
781 kdDebug(129) << kdBacktrace() << endl;
782 //kdDebug(129) << "KAction::plugAccel( kacc = " << kacc << " ): name \"" << name() << "\"" << endl;
783 if ( d->m_kaccel )
784 unplugAccel();
785
786 // If the parent collection's accel ptr isn't set yet
787 //if ( m_parentCollection && !m_parentCollection->accel() )
788 // m_parentCollection->setAccel( kacc );
789
790 // We can only plug this action into the given KAccel object
791 // if it does not already contain an action with the same name.
792 if ( !kacc->actions().actionPtr(name()) )
793 {
794 d->m_kaccel = kacc;
795 d->m_kaccel->insert(name(), d->plainText(), QString::null,
796 KShortcut(d->m_cut),
797 this, SLOT(slotActivated()),
798 configurable, isEnabled());
799 connect(d->m_kaccel, SIGNAL(destroyed()), this, SLOT(slotDestroyed()));
800 //connect(d->m_kaccel, SIGNAL(keycodeChanged()), this, SLOT(slotKeycodeChanged()));
801 }
802 else
803 kdWarning(129) << "KAction::plugAccel( kacc = " << kacc << " ): KAccel object already contains an action name \"" << name() << "\"" << endl; // -- ellis
804*/
805}
806
807void KAction::unplugAccel()
808{
809 qDebug("KAction::unplugAccel ...1 has top be fixed");
810/*US
811 //kdDebug(129) << "KAction::unplugAccel() " << this << " " << name() << endl;
812 if ( d->m_kaccel )
813 {
814 d->m_kaccel->remove(name());
815 d->m_kaccel = 0;
816 }
817*/
818}
819
820void KAction::plugMainWindowAccel( QWidget *w )
821{
822 qDebug("KAction::plugMainWindowAccel ...1 has top be fixed");
823/*US
824 // Note: topLevelWidget() stops too early, we can't use it.
825 QWidget * tl = w;
826 QWidget * n;
827 while ( !tl->isDialog() && ( n = tl->parentWidget() ) ) // lookup parent and store
828 tl = n;
829
830 KMainWindow * mw = dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow
831 if (mw)
832 plugAccel( mw->accel() );
833 else
834 kdDebug(129) << "KAction::plugMainWindowAccel: Toplevel widget isn't a KMainWindow, can't plug accel. " << tl << endl;
835*/
836}
837
838void KAction::setEnabled(bool enable)
839{
840 //kdDebug(129) << "KAction::setEnabled( " << enable << " ): this = " << this << " d->m_kaccelList.count() = " << d->m_kaccelList.count() << endl;
841 if ( enable == d->isEnabled() )
842 return;
843
844 // KDE 4: remove
845//US if (d->m_kaccel)
846//US d->m_kaccel->setEnabled(name(), enable);
847 // KDE 4: remove end
848
849//US for ( uint i = 0; i < d->m_kaccelList.count(); i++ )
850//US d->m_kaccelList[i]->setEnabled( name(), enable );
851
852 d->setEnabled( enable );
853
854 int len = containerCount();
855 for( int i = 0; i < len; ++i )
856 updateEnabled( i );
857
858 emit enabled( d->isEnabled() );
859}
860
861void KAction::updateEnabled( int i )
862{
863 QWidget *w = container( i );
864
865 if ( w->inherits("QPopupMenu") )
866 static_cast<QPopupMenu*>(w)->setItemEnabled( itemId( i ), d->isEnabled() );
867 else if ( w->inherits("QMenuBar") )
868 static_cast<QMenuBar*>(w)->setItemEnabled( itemId( i ), d->isEnabled() );
869 else if ( w->inherits( "KToolBar" ) )
870 {
871 static_cast<KToolBar*>(w)->setItemEnabled( itemId( i ), d->isEnabled() );
872 }
873}
874
875void KAction::setShortcutConfigurable( bool b )
876{
877 d->m_configurable = b;
878}
879
880void KAction::setText( const QString& text )
881{
882/*US
883 // KDE 4: remove
884 if (d->m_kaccel) {
885 KAccelAction* pAction = d->m_kaccel->actions().actionPtr(name());
886 if (pAction)
887 pAction->setLabel( text );
888 }
889 // KDE 4: remove end
890
891 for( uint i = 0; i < d->m_kaccelList.count(); i++ ) {
892 KAccelAction* pAction = d->m_kaccelList[i]->actions().actionPtr(name());
893 if (pAction)
894 pAction->setLabel( text );
895 }
896*/
897 d->setText( text );
898
899 int len = containerCount();
900 for( int i = 0; i < len; ++i )
901 updateText( i );
902
903}
904
905void KAction::updateText( int i )
906{
907 QWidget *w = container( i );
908
909 if ( w->inherits( "QPopupMenu" ) ) {
910 int id = itemId( i );
911 static_cast<QPopupMenu*>(w)->changeItem( id, d->text() );
912 updateShortcut( static_cast<QPopupMenu*>(w), id );
913 }
914 else if ( w->inherits( "QMenuBar" ) )
915 static_cast<QMenuBar*>(w)->changeItem( itemId( i ), d->text() );
916 else if ( w->inherits( "KToolBar" ) )
917 {
918 qDebug("KAction::updateText ...3 has top be fixed");
919 QWidget *button = static_cast<KToolBar *>(w)->getWidget( itemId( i ) );
920 if ( button->inherits( "KToolBarButton" ) )
921 static_cast<KToolBarButton *>(button)->setText( d->plainText() );
922
923 }
924}
925
926QString KAction::text() const
927{
928 return d->text();
929}
930
931QString KAction::plainText() const
932{
933 return d->plainText( );
934}
935
936void KAction::setIcon( const QString &icon )
937{
938 d->setIconName( icon );
939
940 // now handle any toolbars
941 int len = containerCount();
942 for ( int i = 0; i < len; ++i )
943 updateIcon( i );
944}
945
946void KAction::updateIcon( int id )
947{
948 QWidget* w = container( id );
949
950 if ( w->inherits( "QPopupMenu" ) ) {
951 int itemId_ = itemId( id );
952 static_cast<QPopupMenu*>(w)->changeItem( itemId_, d->iconSet( KIcon::Small ), d->text() );
953 updateShortcut( static_cast<QPopupMenu*>(w), itemId_ );
954 }
955 else if ( w->inherits( "QMenuBar" ) )
956 static_cast<QMenuBar*>(w)->changeItem( itemId( id ), d->iconSet( KIcon::Small ), d->text() );
957 else if ( w->inherits( "KToolBar" ) )
958 static_cast<KToolBar *>(w)->setButtonIcon( itemId( id ), d->iconName() );
959 else if ( w->inherits( "QToolBar" ) )
960 {
961 qDebug("KAction::updateIcon has top be fixed");
962//US static_cast<QToolBar *>(w)->setButtonIcon( itemId( id ), d->iconName() );
963 }
964}
965
966QString KAction::icon() const
967{
968 return d->iconName( );
969}
970
971void KAction::setIconSet( const QIconSet &iconset )
972{
973 d->setIconSet( iconset );
974
975 int len = containerCount();
976 for( int i = 0; i < len; ++i )
977 updateIconSet( i );
978}
979
980
981void KAction::updateIconSet( int id )
982{
983 QWidget *w = container( id );
984
985 if ( w->inherits( "QPopupMenu" ) )
986 {
987 int itemId_ = itemId( id );
988 static_cast<QPopupMenu*>(w)->changeItem( itemId_, d->iconSet(), d->text() );
989 updateShortcut( static_cast<QPopupMenu*>(w), itemId_ );
990 }
991 else if ( w->inherits( "QMenuBar" ) )
992 static_cast<QMenuBar*>(w)->changeItem( itemId( id ), d->iconSet(), d->text() );
993 else if ( w->inherits( "KToolBar" ) )
994 {
995 if ( icon().isEmpty() && d->hasIconSet() ) // only if there is no named icon ( scales better )
996 static_cast<KToolBar *>(w)->setButtonIconSet( itemId( id ), d->iconSet() );
997 else
998 static_cast<KToolBar *>(w)->setButtonIconSet( itemId( id ), d->iconSet( KIcon::Small ) );
999 }
1000}
1001
1002QIconSet KAction::iconSet( KIcon::Group group, int size ) const
1003{
1004 return d->iconSet( group, size );
1005}
1006
1007bool KAction::hasIcon() const
1008{
1009 return d->hasIcon();
1010}
1011
1012
1013void KAction::setWhatsThis( const QString& text )
1014{
1015 d->setWhatsThis( text );
1016
1017 int len = containerCount();
1018 for( int i = 0; i < len; ++i )
1019 updateWhatsThis( i );
1020}
1021
1022void KAction::updateWhatsThis( int i )
1023{
1024 qDebug("KAction::updateWhatsThis ...1 has top be fixed");
1025 QPopupMenu* pm = popupMenu( i );
1026 if ( pm )
1027 {
1028 pm->setWhatsThis( itemId( i ), d->whatsThis() );
1029 return;
1030 }
1031
1032 KToolBar *tb = toolBar( i );
1033 if ( tb )
1034 {
1035 QWidget *w = tb->getButton( itemId( i ) );
1036//US QWhatsThis::remove( w );
1037//US QWhatsThis::add( w, d->whatsThis() );
1038 return;
1039 }
1040}
1041
1042QString KAction::whatsThis() const
1043{
1044 return d->whatsThis();
1045}
1046
1047QString KAction::whatsThisWithIcon() const
1048{
1049 QString text = whatsThis();
1050 if (!d->iconName().isEmpty())
1051 return QString::fromLatin1("<img source=\"small|%1\"> %2").arg(d->iconName() ).arg(text);
1052 return text;
1053}
1054
1055QWidget* KAction::container( int index ) const
1056{
1057 assert( index < containerCount() );
1058 return d->m_containers[ index ].m_container;
1059}
1060
1061KToolBar* KAction::toolBar( int index ) const
1062{
1063//US return dynamic_cast<KToolBar *>( d->m_containers[ index ].m_container );
1064 return (KToolBar *)( d->m_containers[ index ].m_container );
1065}
1066
1067QPopupMenu* KAction::popupMenu( int index ) const
1068{
1069//US return dynamic_cast<QPopupMenu *>( d->m_containers[ index ].m_container );
1070 return (QPopupMenu *)( d->m_containers[ index ].m_container );
1071}
1072
1073QWidget* KAction::representative( int index ) const
1074{
1075 return d->m_containers[ index ].m_representative;
1076}
1077
1078int KAction::itemId( int index ) const
1079{
1080 return d->m_containers[ index ].m_id;
1081}
1082
1083int KAction::containerCount() const
1084{
1085 return d->m_containers.count();
1086}
1087
1088uint KAction::kaccelCount() const
1089{
1090 return d->m_kaccelList.count();
1091}
1092
1093void KAction::addContainer( QWidget* c, int id )
1094{
1095 KActionPrivate::Container p;
1096 p.m_container = c;
1097 p.m_id = id;
1098 d->m_containers.append( p );
1099}
1100
1101void KAction::addContainer( QWidget* c, QWidget* w )
1102{
1103 KActionPrivate::Container p;
1104 p.m_container = c;
1105 p.m_representative = w;
1106 d->m_containers.append( p );
1107}
1108
1109void KAction::activate()
1110{
1111 slotActivated();
1112}
1113
1114void KAction::slotActivated()
1115{
1116 emit activated();
1117}
1118
1119void KAction::slotDestroyed()
1120{
1121 kdDebug(129) << "KAction::slotDestroyed(): this = " << this << ", name = \"" << name() << "\", sender = " << sender() << endl;
1122 const QObject* o = sender();
1123
1124/*
1125
1126
1127 // KDE 4: remove
1128 if ( o == d->m_kaccel )
1129 {
1130 d->m_kaccel = 0;
1131 return;
1132 }
1133 // KDE 4: remove end
1134
1135 for( uint i = 0; i < d->m_kaccelList.count(); i++ )
1136 {
1137 if ( o == d->m_kaccelList[i] )
1138 {
1139 disconnect( d->m_kaccelList[i], SIGNAL(destroyed()), this, SLOT(slotDestroyed()) );
1140 d->m_kaccelList.remove( d->m_kaccelList.at( i ) );
1141 return;
1142 }
1143 }
1144*/
1145 int i;
1146 do
1147 {
1148 i = findContainer( static_cast<const QWidget*>( o ) );
1149 if ( i != -1 )
1150 removeContainer( i );
1151 } while ( i != -1 );
1152
1153}
1154
1155int KAction::findContainer( const QWidget* widget ) const
1156{
1157 int pos = 0;
1158 QValueList<KActionPrivate::Container>::ConstIterator it = d->m_containers.begin();
1159 while( it != d->m_containers.end() )
1160 {
1161 if ( (*it).m_representative == widget || (*it).m_container == widget )
1162 return pos;
1163 ++it;
1164 ++pos;
1165 }
1166
1167 return -1;
1168}
1169
1170void KAction::removeContainer( int index )
1171{
1172 int i = 0;
1173 QValueList<KActionPrivate::Container>::Iterator it = d->m_containers.begin();
1174 while( it != d->m_containers.end() )
1175 {
1176 if ( i == index )
1177 {
1178 d->m_containers.remove( it );
1179 return;
1180 }
1181 ++it;
1182 ++i;
1183 }
1184}
1185
1186// FIXME: Remove this (ellis)
1187void KAction::slotKeycodeChanged()
1188{
1189 qDebug("KAction::slotKeycodeChanged() ...44 has top be fixed");
1190/*US
1191 kdDebug(129) << "KAction::slotKeycodeChanged()" << endl; // -- ellis
1192 KAccelAction* pAction = d->m_kaccel->actions().actionPtr(name());
1193 if( pAction )
1194 setShortcut(pAction->shortcut());
1195*/
1196}
1197
1198KActionCollection *KAction::parentCollection() const
1199{
1200 return m_parentCollection;
1201}
1202
1203void KAction::unplugAll()
1204{
1205 while ( containerCount() != 0 )
1206 unplug( container( 0 ) );
1207}
1208
1209void KAction::virtual_hook( int, void* )
1210{ /*BASE::virtual_hook( id, data );*/ }
1211
1212/* vim: et sw=2 ts=2
1213 */
1214
1215//US #include "kaction.moc"
diff --git a/microkde/kdeui/kaction.h b/microkde/kdeui/kaction.h
new file mode 100644
index 0000000..13e2e1e
--- a/dev/null
+++ b/microkde/kdeui/kaction.h
@@ -0,0 +1,624 @@
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
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License version 2 as published by the Free Software Foundation.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.
23*/
24//$Id$
25
26#ifndef __kaction_h__
27#define __kaction_h__
28
29
30//US #include <qkeysequence.h>
31#include <qobject.h>
32#include <qvaluelist.h>
33#include <qguardedptr.h>
34#include <kguiitem.h>
35#include <kshortcut.h>
36#include <kstdaction.h>
37//US#include <kicontheme.h>
38
39//US added the following files
40#include <kiconloader.h>
41
42class QMenuBar;
43class QPopupMenu;
44//USclass QComboBox;
45//USclass QPoint;
46class QIconSet;
47class QString;
48class KToolBar;
49
50class KAccel;
51//USclass KAccelActions;
52//USclass KConfig;
53//USclass KConfigBase;
54//USclass KURL;
55//USclass KInstance;
56//USclass KToolBar;
57class KActionCollection;
58//USclass KPopupMenu;
59class KMainWindow;
60
61/**
62 * The KAction class (and derived and super classes) provides a way to
63 * easily encapsulate a "real" user-selected action or event in your
64 * program.
65 *
66 * For instance, a user may want to @p paste the contents of
67 * the clipboard or @p scroll @p down a document or @p quit the
68 * application. These are all @p actions -- events that the
69 * user causes to happen. The KAction class allows the developer to
70 * deal with these actions in an easy and intuitive manner.
71 *
72 * Specifically, the KAction class encapsulated the various attributes
73 * to an event/action. For instance, an action might have an icon
74 * that goes along with it (a clipboard for a "paste" action or
75 * scissors for a "cut" action). The action might have some text to
76 * describe the action. It will certainly have a method or function
77 * that actually @p executes the action! All these attributes
78 * are contained within the KAction object.
79 *
80 * The advantage of dealing with Actions is that you can manipulate
81 * the Action without regard to the GUI representation of it. For
82 * instance, in the "normal" way of dealing with actions like "cut",
83 * you would manually insert a item for Cut into a menu and a button
84 * into a toolbar. If you want to disable the cut action for a moment
85 * (maybe nothing is selected), you woud have to hunt down the pointer
86 * to the menu item and the toolbar button and disable both
87 * individually. Setting the menu item and toolbar item up uses very
88 * similar code - but has to be done twice!
89 *
90 * With the Action concept, you simply "plug" the Action into whatever
91 * GUI element you want. The KAction class will then take care of
92 * correctly defining the menu item (with icons, accelerators, text,
93 * etc) or toolbar button.. or whatever. From then on, if you
94 * manipulate the Action at all, the effect will propogate through all
95 * GUI representations of it. Back to the "cut" example: if you want
96 * to disable the Cut Action, you would simply do
97 * 'cutAction->setEnabled(false)' and the menuitem and button would
98 * instantly be disabled!
99 *
100 * This is the biggest advantage to the Action concept -- there is a
101 * one-to-one relationship between the "real" action and @p all
102 * GUI representations of it.
103 *
104 * KAction emits the activated() signal if the user activated the
105 * corresponding GUI element ( menu item, toolbar button, etc. )
106 *
107 * If you are in the situation of wanting to map the activated()
108 * signal of multiple action objects to one slot, with a special
109 * argument bound to each action, then you might consider using
110 * @ref QSignalMapper . A tiny example:
111 *
112 * <PRE>
113 * QSignalMapper *desktopNumberMapper = new QSignalMapper( this );
114 * connect( desktopNumberMapper, SIGNAL( mapped( int ) ),
115 * this, SLOT( moveWindowToDesktop( int ) ) );
116 *
117 * for ( uint i = 0; i < numberOfDesktops; ++i ) {
118 * KAction *desktopAction = new KAction( i18n( "Move Window to Desktop %i" ).arg( i ), ... );
119 * connect( desktopAction, SIGNAL( activated() ), desktopNumberMapper, SLOT( map() ) );
120 * desktopNumberMapper->setMapping( desktopAction, i );
121 * }
122 * </PRE>
123 *
124 * @sect General Usage:
125 *
126 * The steps to using actions are roughly as follows
127 *
128 * @li Decide which attributes you want to associate with a given
129 * action (icons, text, keyboard shortcut, etc)
130 * @li Create the action using KAction (or derived or super class).
131 * @li "Plug" the Action into whatever GUI element you want. Typically,
132 * this will be a menu or toolbar.
133 *
134 * @sect Detailed Example:
135 *
136 * Here is an example of enabling a "New [document]" action
137 * <PRE>
138 * KAction *newAct = new KAction(i18n("&New"), "filenew",
139 * KStdAccel::shortcut(KStdAccel::New),
140 * this, SLOT(fileNew()),
141 * actionCollection(), "new");
142 * </PRE>
143 * This line creates our action. It says that wherever this action is
144 * displayed, it will use "&New" as the text, the standard icon, and
145 * the standard shortcut. It further says that whenever this action
146 * is invoked, it will use the fileNew() slot to execute it.
147 *
148 * <PRE>
149 * QPopupMenu *file = new QPopupMenu;
150 * newAct->plug(file);
151 * </PRE>
152 * That just inserted the action into the File menu. The point is, it's not
153 * important in which menu it is: all manipulation of the item is
154 * done through the newAct object.
155 *
156 * <PRE>
157 * newAct->plug(toolBar());
158 * </PRE>
159 * And this inserted the Action into the main toolbar as a button.
160 *
161 * That's it!
162 *
163 * If you want to disable that action sometime later, you can do so
164 * with
165 * <PRE>
166 * newAct->setEnabled(false)
167 * </PRE>
168 * and both the menuitem in File and the toolbar button will instantly
169 * be disabled.
170 *
171 * Do not delete a KAction object without unplugging it from all its
172 * containers. The simplest way to do that is to use the unplugAll()
173 * as in the following example:
174 * <PRE>
175 * newAct->unplugAll();
176 * delete newAct;
177 * </PRE>
178 * Normally you will not need to do this as KActionCollection manages
179 * everything for you.
180 *
181 * Note: if you are using a "standard" action like "new", "paste",
182 * "quit", or any other action described in the KDE UI Standards,
183 * please use the methods in the @ref KStdAction class rather than
184 * defining your own.
185 *
186 * @sect Usage Within the XML Framework:
187 *
188 * If you are using KAction within the context of the XML menu and
189 * toolbar building framework, then there are a few tiny changes. The
190 * first is that you must insert your new action into an action
191 * collection. The action collection (a @ref KActionCollection) is,
192 * logically enough, a central collection of all of the actions
193 * defined in your application. The XML UI framework code in KXMLGUI
194 * classes needs access to this collection in order to build up the
195 * GUI (it's how the builder code knows which actions are valid and
196 * which aren't).
197 *
198 * Also, if you use the XML builder framework, then you do not ever
199 * have to plug your actions into containers manually. The framework
200 * does that for you.
201 *
202 * @see KStdAction
203 * @short Class to encapsulate user-driven action or event
204 */
205class KAction : public QObject
206{
207 friend class KActionCollection;
208 Q_OBJECT
209 Q_PROPERTY( int containerCount READ containerCount )
210 Q_PROPERTY( QString plainText READ plainText )
211 Q_PROPERTY( QString text READ text WRITE setText )
212 Q_PROPERTY( QString shortcut READ shortcutText WRITE setShortcutText )
213 Q_PROPERTY( bool enabled READ isEnabled WRITE setEnabled )
214 Q_PROPERTY( QString group READ group WRITE setGroup )
215 Q_PROPERTY( QString whatsThis READ whatsThis WRITE setWhatsThis )
216 Q_PROPERTY( QString toolTip READ toolTip WRITE setToolTip )
217 Q_PROPERTY( QString icon READ icon WRITE setIcon )
218public:
219 /**
220 * Constructs an action with text, potential keyboard
221 * shortcut, and a SLOT to call when this action is invoked by
222 * the user.
223 *
224 * If you do not want or have a keyboard shortcut,
225 * set the @p cut param to 0.
226 *
227 * This is the most common KAction used when you do not have a
228 * corresponding icon (note that it won't appear in the current version
229 * of the "Edit ToolBar" dialog, because an action needs an icon to be
230 * plugged in a toolbar...).
231 *
232 * @param text The text that will be displayed.
233 * @param cut The corresponding keyboard shortcut.
234 * @param receiver The SLOT's parent.
235 * @param slot The SLOT to invoke to execute this action.
236 * @param parent This action's parent.
237 * @param name An internal name for this action.
238 */
239 KAction( const QString& text, const KShortcut& cut,
240 const QObject* receiver, const char* slot,
241 KActionCollection* parent, const char* name );
242 /**
243 * Constructs an action with text, icon, potential keyboard
244 * shortcut, and a SLOT to call when this action is invoked by
245 * the user.
246 *
247 * If you do not want or have a keyboard shortcut, set the
248 * @p cut param to 0.
249 *
250 * This is the other common KAction used. Use it when you
251 * @p do have a corresponding icon.
252 *
253 * @param text The text that will be displayed.
254 * @param pix The icon to display.
255 * @param cut The corresponding keyboard shortcut.
256 * @param receiver The SLOT's parent.
257 * @param slot The SLOT to invoke to execute this action.
258 * @param parent This action's parent.
259 * @param name An internal name for this action.
260 */
261
262 KAction( const QString& text, const QIconSet& pix, const KShortcut& cut,
263 const QObject* receiver, const char* slot,
264 KActionCollection* parent, const char* name );
265
266 /**
267 * Constructs an action with text, icon, potential keyboard
268 * shortcut, and a SLOT to call when this action is invoked by
269 * the user. The icon is loaded on demand later based on where it
270 * is plugged in.
271 *
272 * If you do not want or have a keyboard shortcut, set the
273 * @p cut param to 0.
274 *
275 * This is the other common KAction used. Use it when you
276 * @p do have a corresponding icon.
277 *
278 * @param text The text that will be displayed.
279 * @param pix The icon to display.
280 * @param cut The corresponding keyboard shortcut (shortcut).
281 * @param receiver The SLOT's parent.
282 * @param slot The SLOT to invoke to execute this action.
283 * @param parent This action's parent.
284 * @param name An internal name for this action.
285 */
286 KAction( const QString& text, const QString& pix, const KShortcut& cut,
287 const QObject* receiver, const char* slot,
288 KActionCollection* parent, const char* name );
289
290 /**
291 * The same as the above constructor, but with a KGuiItem providing
292 * the text and icon.
293 *
294 * @param item The KGuiItem with the label and (optional) icon.
295 */
296 KAction( const KGuiItem& item, const KShortcut& cut,
297 const QObject* receiver, const char* slot,
298 KActionCollection* parent, const char* name );
299 /**
300 * @obsolete
301 */
302 KAction( const QString& text, const KShortcut& cut = KShortcut(), QObject* parent = 0, const char* name = 0 );
303 /**
304 * @obsolete
305 */
306 KAction( const QString& text, const KShortcut& cut,
307 const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 );
308 /**
309 * @obsolete
310 */
311 KAction( const QString& text, const QIconSet& pix, const KShortcut& cut = KShortcut(),
312 QObject* parent = 0, const char* name = 0 );
313 /**
314 * @obsolete
315 */
316 KAction( const QString& text, const QString& pix, const KShortcut& cut = KShortcut(),
317 QObject* parent = 0, const char* name = 0 );
318 /**
319 * @obsolete
320 */
321 KAction( const QString& text, const QIconSet& pix, const KShortcut& cut,
322 const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 );
323 /**
324 * @obsolete
325 */
326 KAction( const QString& text, const QString& pix, const KShortcut& cut,
327 const QObject* receiver, const char* slot, QObject* parent,
328 const char* name = 0 );
329 /**
330 * @obsolete
331 */
332 KAction( QObject* parent = 0, const char* name = 0 );
333
334 /**
335 * Standard destructor
336 */
337 virtual ~KAction();
338
339 /**
340 * "Plug" or insert this action into a given widget.
341 *
342 * This will
343 * typically be a menu or a toolbar. From this point on, you will
344 * never need to directly manipulate the item in the menu or
345 * toolbar. You do all enabling/disabling/manipulation directly
346 * with your KAction object.
347 *
348 * @param w The GUI element to display this action
349 */
350 virtual int plug( QWidget *w, int index = -1 );
351
352 /**
353 * @deprecated. Shouldn't be used. No substitute available.
354 *
355 * "Plug" or insert this action into a given KAccel.
356 *
357 * @param accel The KAccel collection which holds this accel
358 * @param configurable If the shortcut is configurable via
359 * the KAccel configuration dialog (this is somehow deprecated since
360 * there is now a KAction key configuration dialog).
361 */
362 virtual void plugAccel(KAccel *accel, bool configurable = true);
363
364 /**
365 * "Unplug" or remove this action from a given widget.
366 *
367 * This will typically be a menu or a toolbar. This is rarely
368 * used in "normal" application. Typically, it would be used if
369 * your application has several views or modes, each with a
370 * completely different menu structure. If you simply want to
371 * disable an action for a given period, use @ref setEnabled()
372 * instead.
373 *
374 * @param w Remove the action from this GUI element.
375 */
376 virtual void unplug( QWidget *w );
377
378 /**
379 * @deprecated. Complement method to plugAccel().
380 * Disconnect this action from the KAccel.
381 */
382 virtual void unplugAccel();
383
384 /**
385 * returns whether the action is plugged into any container widget or not.
386 * @since 3.1
387 */
388 virtual bool isPlugged() const;
389
390 /**
391 * returns whether the action is plugged into the given container
392 */
393 bool isPlugged( const QWidget *container ) const;
394
395 /**
396 * returns whether the action is plugged into the given container with the given, container specific, id (often
397 * menu or toolbar id ) .
398 */
399 virtual bool isPlugged( const QWidget *container, int id ) const;
400
401 /**
402 * returns whether the action is plugged into the given container with the given, container specific, representative
403 * container widget item.
404 */
405 virtual bool isPlugged( const QWidget *container, const QWidget *_representative ) const;
406
407 QWidget* container( int index ) const;
408 int itemId( int index ) const;
409 QWidget* representative( int index ) const;
410 int containerCount() const;
411 /// @since 3.1
412 uint kaccelCount() const;
413
414 virtual bool hasIcon() const;
415#ifndef KDE_NO_COMPAT
416 bool hasIconSet() const { return hasIcon(); }
417#endif
418 virtual QString plainText() const;
419
420 /**
421 * Get the text associated with this action.
422 */
423 virtual QString text() const;
424
425 /**
426 * Get the keyboard shortcut associated with this action.
427 */
428 virtual const KShortcut& shortcut() const;
429 /**
430 * Get the default shortcut for this action.
431 */
432 virtual const KShortcut& shortcutDefault() const;
433
434 // These two methods are for Q_PROPERTY
435 QString shortcutText() const;
436 void setShortcutText( const QString& );
437
438 /**
439 * Returns true if this action is enabled.
440 */
441 virtual bool isEnabled() const;
442
443 /**
444 * Returns true if this action's shortcut is configurable.
445 */
446 virtual bool isShortcutConfigurable() const;
447
448 virtual QString group() const;
449
450 /**
451 * Get the What's this text for the action.
452 */
453 virtual QString whatsThis() const;
454
455 /**
456 * Get the tooltip text for the action.
457 */
458 virtual QString toolTip() const;
459
460 /**
461 * Get the QIconSet from which the icons used to display this action will
462 * be chosen.
463 */
464 virtual QIconSet iconSet( KIcon::Group group, int size=0 ) const;
465
466#ifndef KDE_NO_COMPAT
467 QIconSet iconSet() const
468 {
469 return iconSet( KIcon::Small );
470 }
471#endif
472
473 virtual QString icon() const;
474
475 KActionCollection *parentCollection() const;
476
477 /**
478 * @internal
479 * Generate a toolbar button id. Made public for reimplementations.
480 */
481 static int getToolButtonID();
482
483
484 void unplugAll();
485
486public slots:
487 /**
488 * Sets the text associated with this action. The text is used for menu
489 * and toolbar labels etc.
490 */
491 virtual void setText(const QString &text);
492
493 /**
494 * Sets the keyboard shortcut associated with this action.
495 */
496 virtual bool setShortcut( const KShortcut& );
497
498 virtual void setGroup( const QString& );
499
500 /**
501 * Sets the What's this text for the action. This text will be displayed when
502 * a widget that has been created by plugging this action into a container
503 * is clicked on in What's this mode.
504 *
505 * The What's this text can include QML markup as well as raw text.
506 */
507 virtual void setWhatsThis( const QString& text );
508
509 /**
510 * Sets the tooltip text for the action.
511 * This will be used as a tooltip for a toolbar button, as a
512 * statusbar help-text for a menu item, and it also appears
513 * in the toolbar editor, to describe the action.
514 */
515 virtual void setToolTip( const QString& );
516
517 /**
518 * Sets the QIconSet from which the icons used to display this action will
519 * be chosen.
520 */
521 virtual void setIconSet( const QIconSet &iconSet );
522
523 virtual void setIcon( const QString& icon );
524
525 /**
526 * Enables or disables this action. All uses of this action (eg. in menus
527 * or toolbars) will be updated to reflect the state of the action.
528 */
529 virtual void setEnabled(bool enable);
530
531 /**
532 * Indicate whether the user may configure the action's shortcut.
533 */
534 virtual void setShortcutConfigurable( bool );
535
536 /**
537 * Emulate user's interaction programmatically, by activating the action.
538 * The implementation simply emits activated().
539 */
540 virtual void activate();
541
542protected slots:
543 virtual void slotDestroyed();
544 virtual void slotKeycodeChanged();
545 virtual void slotActivated();
546
547protected:
548 KToolBar* toolBar( int index ) const;
549 QPopupMenu* popupMenu( int index ) const;
550 void removeContainer( int index );
551 int findContainer( const QWidget* widget ) const;
552 void plugMainWindowAccel( QWidget *w );
553
554 void addContainer( QWidget* parent, int id );
555 void addContainer( QWidget* parent, QWidget* representative );
556
557 virtual void updateShortcut( int i );
558 virtual void updateShortcut( QPopupMenu* menu, int id );
559 virtual void updateGroup( int id );
560 virtual void updateText(int i );
561 virtual void updateEnabled(int i);
562 virtual void updateIconSet(int i);
563 virtual void updateIcon( int i);
564 virtual void updateToolTip( int id );
565 virtual void updateWhatsThis( int i );
566
567 KActionCollection *m_parentCollection;
568 QString whatsThisWithIcon() const;
569
570signals:
571 void activated();
572 void enabled( bool );
573
574private:
575 void initPrivate( const QString& text, const KShortcut& cut,
576 const QObject* receiver, const char* slot );
577 KAccel* kaccelCurrent();
578 bool initShortcut( const KShortcut& );
579 void plugShortcut();
580 bool updateKAccelShortcut( KAccel* kaccel );
581 void insertKAccel( KAccel* );
582 /** @internal To be used exclusively by KActionCollection::removeWidget(). */
583 void removeKAccel( KAccel* );
584
585#ifndef KDE_NO_COMPAT
586public:
587 /**
588 * @deprecated. Use shortcut().
589 * Get the keyboard accelerator associated with this action.
590 */
591 int accel() const;
592
593 QString statusText() const
594 { return toolTip(); }
595
596 /**
597 * @deprecated. Use setShortcut().
598 * Sets the keyboard accelerator associated with this action.
599 */
600 void setAccel( int key );
601
602 /**
603 * @deprecated. Use setToolTip instead (they do the same thing now).
604 */
605 void setStatusText( const QString &text )
606 { setToolTip( text ); }
607
608 /**
609 * @deprecated. for backwards compatibility.
610 */
611 int menuId( int i ) { return itemId( i ); }
612#endif // !KDE_NO_COMPAT
613
614protected:
615 virtual void virtual_hook( int id, void* data );
616private:
617 class KActionPrivate;
618 KActionPrivate *d;
619};
620
621#include <kactioncollection.h>
622#include <kactionclasses.h>
623
624#endif
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
59static QFontDatabase *fontDataBase = 0;
60
61static void cleanupFontDatabase()
62{
63 delete fontDataBase;
64 fontDataBase = 0;
65}
66
67static 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
86static QValueList<int> get_standard_font_sizes()
87{
88 if ( !fontDataBase ) {
89 fontDataBase = new QFontDatabase();
90 qAddPostRoutine( cleanupFontDatabase );
91 }
92 return fontDataBase->standardSizes();
93}
94
95class KToggleAction::KToggleActionPrivate
96{
97public:
98 KToggleActionPrivate()
99 {
100 m_checked = false;
101 }
102
103 bool m_checked;
104 QString m_exclusiveGroup;
105};
106
107KToggleAction::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
115KToggleAction::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
123KToggleAction::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
131KToggleAction::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
139KToggleAction::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
149KToggleAction::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
159KToggleAction::KToggleAction( QObject* parent, const char* name )
160 : KAction( parent, name )
161{
162 d = new KToggleActionPrivate;
163}
164
165KToggleAction::~KToggleAction()
166{
167 delete d;
168}
169
170int 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
203void 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
234void 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
250void KToggleAction::slotActivated()
251{
252 setChecked( !isChecked() );
253 emit activated();
254 emit toggled( isChecked() );
255}
256
257bool KToggleAction::isChecked() const
258{
259 return d->m_checked;
260}
261
262void KToggleAction::setExclusiveGroup( const QString& name )
263{
264 d->m_exclusiveGroup = name;
265}
266
267QString KToggleAction::exclusiveGroup() const
268{
269 return d->m_exclusiveGroup;
270}
271
272
273KRadioAction::KRadioAction( const QString& text, const KShortcut& cut,
274 QObject* parent, const char* name )
275: KToggleAction( text, cut, parent, name )
276{
277}
278
279KRadioAction::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
286KRadioAction::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
293KRadioAction::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
300KRadioAction::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
308KRadioAction::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
316KRadioAction::KRadioAction( QObject* parent, const char* name )
317: KToggleAction( parent, name )
318{
319}
320
321void 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
339class KSelectAction::KSelectActionPrivate
340{
341public:
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
375KSelectAction::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
382KSelectAction::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
390KSelectAction::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
398KSelectAction::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
406KSelectAction::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
416KSelectAction::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
426KSelectAction::KSelectAction( QObject* parent, const char* name )
427 : KAction( parent, name )
428{
429 d = new KSelectActionPrivate;
430}
431
432KSelectAction::~KSelectAction()
433{
434 assert(d);
435 delete d->m_menu;
436 delete d; d = 0;
437}
438
439void 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
469void 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}
482QPopupMenu* 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
497void 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
513void 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
531void 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
549void 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
565QStringList KSelectAction::items() const
566{
567 return d->m_list;
568}
569
570QString KSelectAction::currentText() const
571{
572 if ( currentItem() < 0 )
573 return QString::null;
574
575 return d->m_list[ currentItem() ];
576}
577
578int KSelectAction::currentItem() const
579{
580 return d->m_current;
581}
582
583void 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
598int KSelectAction::comboWidth() const
599{
600 return d->m_comboWidth;
601}
602
603void 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
616void 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
640int 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
709QStringList 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
732void 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
742void 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
755void 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
767void 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
790void 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
798void KSelectAction::setEditable( bool edit )
799{
800 d->m_edit = edit;
801}
802
803bool KSelectAction::isEditable() const
804{
805 return d->m_edit;
806}
807
808void KSelectAction::setRemoveAmpersandsInCombo( bool b )
809{
810 setMenuAccelsEnabled( b );
811}
812
813bool KSelectAction::removeAmpersandsInCombo() const
814{
815 return menuAccelsEnabled( );
816}
817
818void KSelectAction::setMenuAccelsEnabled( bool b )
819{
820 d->m_menuAccelsEnabled = b;
821}
822
823bool KSelectAction::menuAccelsEnabled() const
824{
825 return d->m_menuAccelsEnabled;
826}
827
828class KListAction::KListActionPrivate
829{
830public:
831 KListActionPrivate()
832 {
833 m_current = 0;
834 }
835 int m_current;
836};
837
838KListAction::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
845KListAction::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
855KListAction::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
863KListAction::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
871KListAction::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
882KListAction::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
893KListAction::KListAction( QObject* parent, const char* name )
894 : KSelectAction( parent, name )
895{
896 d = new KListActionPrivate;
897}
898
899KListAction::~KListAction()
900{
901 delete d; d = 0;
902}
903
904void 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
914QString KListAction::currentText() const
915{
916 if ( currentItem() < 0 )
917 return QString::null;
918
919 return items()[ currentItem() ];
920}
921
922int KListAction::currentItem() const
923{
924 return d->m_current;
925}
926
927class KRecentFilesAction::KRecentFilesActionPrivate
928{
929public:
930 KRecentFilesActionPrivate()
931 {
932 m_maxItems = 0;
933 }
934 uint m_maxItems;
935};
936
937KRecentFilesAction::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
949KRecentFilesAction::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
967KRecentFilesAction::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
980KRecentFilesAction::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
993KRecentFilesAction::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
1012KRecentFilesAction::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
1031KRecentFilesAction::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
1041void KRecentFilesAction::init()
1042{
1043 connect( this, SIGNAL( activated( const QString& ) ),
1044 this, SLOT( itemSelected( const QString& ) ) );
1045
1046 setMenuAccelsEnabled( false );
1047}
1048
1049KRecentFilesAction::~KRecentFilesAction()
1050{
1051 delete d; d = 0;
1052}
1053
1054uint KRecentFilesAction::maxItems() const
1055{
1056 return d->m_maxItems;
1057}
1058
1059void 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
1079void 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
1099void 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
1112void KRecentFilesAction::clearURLList()
1113{
1114 clear();
1115}
1116
1117void 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
1146void 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
1168void KRecentFilesAction::itemSelected( const QString& text )
1169{
1170 emit urlSelected( KURL( text ) );
1171}
1172
1173class KFontAction::KFontActionPrivate
1174{
1175public:
1176 KFontActionPrivate()
1177 {
1178 }
1179 QStringList m_fonts;
1180};
1181
1182KFontAction::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
1193KFontAction::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
1204KFontAction::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
1215KFontAction::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
1226KFontAction::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
1238KFontAction::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
1251KFontAction::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
1260KFontAction::~KFontAction()
1261{
1262 delete d;
1263 d = 0;
1264}
1265
1266/*
1267 * Maintenance note: Keep in sync with KFontCombo::setCurrentFont()
1268 */
1269void 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
1309int 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
1339class KFontSizeAction::KFontSizeActionPrivate
1340{
1341public:
1342 KFontSizeActionPrivate()
1343 {
1344 }
1345};
1346
1347KFontSizeAction::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
1355KFontSizeAction::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
1364KFontSizeAction::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
1372KFontSizeAction::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
1380KFontSizeAction::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
1390KFontSizeAction::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
1400KFontSizeAction::KFontSizeAction( QObject* parent, const char* name )
1401 : KSelectAction( parent, name )
1402{
1403 init();
1404}
1405
1406KFontSizeAction::~KFontSizeAction()
1407{
1408 delete d;
1409 d = 0;
1410}
1411
1412void 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
1425void 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
1448qDebug("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
1470int KFontSizeAction::fontSize() const
1471{
1472 return currentText().toInt();
1473}
1474
1475void KFontSizeAction::slotActivated( int index )
1476{
1477 KSelectAction::slotActivated( index );
1478
1479 emit fontSizeChanged( items()[ index ].toInt() );
1480}
1481
1482void KFontSizeAction::slotActivated( const QString& size )
1483{
1484 setFontSize( size.toInt() ); // insert sorted first
1485 KSelectAction::slotActivated( size );
1486 emit fontSizeChanged( size.toInt() );
1487}
1488
1489class KActionMenu::KActionMenuPrivate
1490{
1491public:
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
1510KActionMenu::KActionMenu( QObject* parent, const char* name )
1511 : KAction( parent, name )
1512{
1513 d = new KActionMenuPrivate;
1514 setShortcutConfigurable( false );
1515}
1516
1517KActionMenu::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
1525KActionMenu::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
1533KActionMenu::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
1541KActionMenu::~KActionMenu()
1542{
1543 unplugAll();
1544 kdDebug(129) << "KActionMenu::~KActionMenu()" << endl; // ellis
1545 delete d; d = 0;
1546}
1547
1548void KActionMenu::popup( const QPoint& global )
1549{
1550 popupMenu()->popup( global );
1551}
1552
1553
1554//US KPopupMenu* KActionMenu::popupMenu() const
1555QPopupMenu* KActionMenu::popupMenu() const
1556{
1557 return d->m_popup;
1558}
1559
1560void KActionMenu::insert( KAction* cmd, int index )
1561{
1562 if ( cmd )
1563 cmd->plug( d->m_popup, index );
1564}
1565
1566void KActionMenu::remove( KAction* cmd )
1567{
1568 if ( cmd )
1569 cmd->unplug( d->m_popup );
1570}
1571
1572bool KActionMenu::delayed() const {
1573 return d->m_delayed;
1574}
1575
1576void KActionMenu::setDelayed(bool _delayed) {
1577 d->m_delayed = _delayed;
1578}
1579
1580bool KActionMenu::stickyMenu() const {
1581 return d->m_stickyMenu;
1582}
1583
1584void KActionMenu::setStickyMenu(bool sticky) {
1585 d->m_stickyMenu = sticky;
1586}
1587
1588int 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
1680KToolBarPopupAction::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
1691KToolBarPopupAction::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
1704KToolBarPopupAction::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
1717KToolBarPopupAction::~KToolBarPopupAction()
1718{
1719 if ( m_popup )
1720 delete m_popup;
1721}
1722
1723bool KToolBarPopupAction::delayed() const {
1724 return m_delayed;
1725}
1726
1727void KToolBarPopupAction::setDelayed(bool delayed) {
1728 m_delayed = delayed;
1729}
1730
1731bool KToolBarPopupAction::stickyMenu() const {
1732 return m_stickyMenu;
1733}
1734
1735void KToolBarPopupAction::setStickyMenu(bool sticky) {
1736 m_stickyMenu = sticky;
1737}
1738
1739int 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
1784QPopupMenu *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
1796KToggleToolBarAction::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
1804KToggleToolBarAction::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
1812KToggleToolBarAction::~KToggleToolBarAction()
1813{
1814}
1815
1816int 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
1851void 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
1872KWidgetAction::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
1882KWidgetAction::~KWidgetAction()
1883{
1884}
1885
1886void 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
1906int 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
1938void 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
1952void 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
1966KActionSeparator::KActionSeparator( QObject *parent, const char *name )
1967 : KAction( parent, name )
1968{
1969}
1970
1971KActionSeparator::~KActionSeparator()
1972{
1973}
1974
1975int 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
2017void KToggleAction::virtual_hook( int id, void* data )
2018{ KAction::virtual_hook( id, data ); }
2019
2020void KRadioAction::virtual_hook( int id, void* data )
2021{ KToggleAction::virtual_hook( id, data ); }
2022
2023void KSelectAction::virtual_hook( int id, void* data )
2024{ KAction::virtual_hook( id, data ); }
2025
2026void KListAction::virtual_hook( int id, void* data )
2027{ KSelectAction::virtual_hook( id, data ); }
2028
2029void KRecentFilesAction::virtual_hook( int id, void* data )
2030{ KListAction::virtual_hook( id, data ); }
2031
2032void KFontAction::virtual_hook( int id, void* data )
2033{ KSelectAction::virtual_hook( id, data ); }
2034
2035void KFontSizeAction::virtual_hook( int id, void* data )
2036{ KSelectAction::virtual_hook( id, data ); }
2037
2038void KActionMenu::virtual_hook( int id, void* data )
2039{ KAction::virtual_hook( id, data ); }
2040
2041void KToolBarPopupAction::virtual_hook( int id, void* data )
2042{ KAction::virtual_hook( id, data ); }
2043
2044void KToggleToolBarAction::virtual_hook( int id, void* data )
2045{ KToggleAction::virtual_hook( id, data ); }
2046
2047void KWidgetAction::virtual_hook( int id, void* data )
2048{ KAction::virtual_hook( id, data ); }
2049
2050void 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*/
diff --git a/microkde/kdeui/kactionclasses.h b/microkde/kdeui/kactionclasses.h
new file mode 100644
index 0000000..f6e7a0f
--- a/dev/null
+++ b/microkde/kdeui/kactionclasses.h
@@ -0,0 +1,1223 @@
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
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License version 2 as published by the Free Software Foundation.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.
23*/
24//$Id$
25
26#ifndef __kactionclasses_h__
27#define __kactionclasses_h__
28
29#include <kaction.h>
30
31//US#include <qkeysequence.h>
32//US#include <qobject.h>
33//US#include <qvaluelist.h>
34//US#include <qguardedptr.h>
35//US#include <kguiitem.h>
36#include <kshortcut.h>
37//US#include <kstdaction.h>
38//US#include <kicontheme.h>
39
40class QMenuBar;
41class QPopupMenu;
42//USclass QComboBox;
43//USclass QPoint;
44//USclass QIconSet;
45//USclass QString;
46//USclass KToolBar;
47
48//USclass KAccel;
49//USclass KAccelActions;
50class KConfig;
51//USclass KConfigBase;
52class KURL;
53//USclass KInstance;
54
55
56//US class KToolBar needs to be replaced
57class KToolBar;
58class KActionCollection;
59
60//US class KPopupMenu needs to be replaced
61//US class KPopupMenu;
62//USclass KMainWindow;
63
64/**
65 * Checkbox like action.
66 *
67 * This action provides two states: checked or not.
68 *
69 * @short Checkbox like action.
70 */
71class KToggleAction : public KAction
72{
73 Q_OBJECT
74 Q_PROPERTY( bool checked READ isChecked WRITE setChecked )
75 Q_PROPERTY( QString exclusiveGroup READ exclusiveGroup WRITE setExclusiveGroup )
76public:
77
78 /**
79 * Constructs a toggle action with text and potential keyboard
80 * accelerator but nothing else. Use this only if you really
81 * know what you are doing.
82 *
83 * @param text The text that will be displayed.
84 * @param cut The corresponding keyboard accelerator (shortcut).
85 * @param parent This action's parent.
86 * @param name An internal name for this action.
87 */
88 KToggleAction( const QString& text, const KShortcut& cut = KShortcut(), QObject* parent = 0, const char* name = 0 );
89
90 /**
91 * @param text The text that will be displayed.
92 * @param cut The corresponding keyboard accelerator (shortcut).
93 * @param receiver The SLOT's parent.
94 * @param slot The SLOT to invoke to execute this action.
95 * @param parent This action's parent.
96 * @param name An internal name for this action.
97 */
98 KToggleAction( const QString& text, const KShortcut& cut,
99 const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 );
100
101 /**
102 * @param text The text that will be displayed.
103 * @param pix The icons that go with this action.
104 * @param cut The corresponding keyboard accelerator (shortcut).
105 * @param parent This action's parent.
106 * @param name An internal name for this action.
107 */
108 KToggleAction( const QString& text, const QIconSet& pix, const KShortcut& cut = KShortcut(),
109 QObject* parent = 0, const char* name = 0 );
110
111 /**
112 * @param text The text that will be displayed.
113 * @param pix The dynamically loaded icon that goes with this action.
114 * @param cut The corresponding keyboard accelerator (shortcut).
115 * @param parent This action's parent.
116 * @param name An internal name for this action.
117 */
118 KToggleAction( const QString& text, const QString& pix, const KShortcut& cut = KShortcut(),
119 QObject* parent = 0, const char* name = 0 );
120
121 /**
122 * @param text The text that will be displayed.
123 * @param pix The icons that go with this action.
124 * @param cut The corresponding keyboard accelerator (shortcut).
125 * @param receiver The SLOT's parent.
126 * @param slot The SLOT to invoke to execute this action.
127 * @param parent This action's parent.
128 * @param name An internal name for this action.
129 */
130 KToggleAction( const QString& text, const QIconSet& pix, const KShortcut& cut,
131 const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 );
132
133 /**
134 * @param text The text that will be displayed.
135 * @param pix The dynamically loaded icon that goes with this action.
136 * @param cut The corresponding keyboard accelerator (shortcut).
137 * @param receiver The SLOT's parent.
138 * @param slot The SLOT to invoke to execute this action.
139 * @param parent This action's parent.
140 * @param name An internal name for this action.
141 */
142 KToggleAction( const QString& text, const QString& pix, const KShortcut& cut,
143 const QObject* receiver, const char* slot,
144 QObject* parent, const char* name = 0 );
145
146 /**
147 * @param parent This action's parent.
148 * @param name An internal name for this action.
149 */
150 KToggleAction( QObject* parent = 0, const char* name = 0 );
151
152 /**
153 * Destructor
154 */
155 virtual ~KToggleAction();
156
157 /**
158 * "Plug" or insert this action into a given widget.
159 *
160 * This will typically be a menu or a toolbar. From this point
161 * on, you will never need to directly manipulate the item in the
162 * menu or toolbar. You do all enabling/disabling/manipulation
163 * directly with your KToggleAction object.
164 *
165 * @param widget The GUI element to display this action.
166 * @param index The index of the item.
167 */
168 virtual int plug( QWidget* widget, int index = -1 );
169
170 /**
171 * Returns the actual state of the action.
172 */
173 bool isChecked() const;
174
175 /**
176 * @return which "exclusive group" this action is part of.
177 * @see setExclusiveGroup
178 */
179 QString exclusiveGroup() const;
180
181 /**
182 * Defines which "exclusive group" this action is part of.
183 * In a given exclusive group, only one toggle action can be checked
184 * at a any moment. Checking an action unchecks the other actions
185 * of the group.
186 */
187 virtual void setExclusiveGroup( const QString& name );
188
189public slots:
190 /**
191 * Sets the state of the action.
192 */
193 virtual void setChecked( bool );
194
195protected slots:
196 virtual void slotActivated();
197
198protected:
199 virtual void updateChecked( int id );
200
201signals:
202 void toggled( bool );
203
204protected:
205 virtual void virtual_hook( int id, void* data );
206private:
207 class KToggleActionPrivate;
208 KToggleActionPrivate *d;
209};
210
211/**
212 * An action that operates like a radio button. At any given time
213 * only a single action from the group will be active.
214 */
215class KRadioAction : public KToggleAction
216{
217 Q_OBJECT
218public:
219 /**
220 * Constructs a radio action with text and potential keyboard
221 * accelerator but nothing else. Use this only if you really
222 * know what you are doing.
223 *
224 * @param text The text that will be displayed.
225 * @param cut The corresponding keyboard accelerator (shortcut).
226 * @param parent This action's parent.
227 * @param name An internal name for this action.
228 */
229 KRadioAction( const QString& text, const KShortcut& cut = KShortcut(), QObject* parent = 0, const char* name = 0 );
230
231 /**
232 * @param text The text that will be displayed.
233 * @param cut The corresponding keyboard accelerator (shortcut).
234 * @param receiver The SLOT's parent.
235 * @param slot The SLOT to invoke to execute this action.
236 * @param parent This action's parent.
237 * @param name An internal name for this action.
238 */
239 KRadioAction( const QString& text, const KShortcut& cut,
240 const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 );
241
242 /**
243 * @param text The text that will be displayed.
244 * @param pix The icons that go with this action.
245 * @param cut The corresponding keyboard accelerator (shortcut).
246 * @param parent This action's parent.
247 * @param name An internal name for this action.
248 */
249 KRadioAction( const QString& text, const QIconSet& pix, const KShortcut& cut = KShortcut(),
250 QObject* parent = 0, const char* name = 0 );
251
252 /**
253 * @param text The text that will be displayed.
254 * @param pix The dynamically loaded icon that goes with this action.
255 * @param cut The corresponding keyboard accelerator (shortcut).
256 * @param parent This action's parent.
257 * @param name An internal name for this action.
258 */
259 KRadioAction( const QString& text, const QString& pix, const KShortcut& cut = KShortcut(),
260 QObject* parent = 0, const char* name = 0 );
261
262 /**
263 * @param text The text that will be displayed.
264 * @param pix The icons that go with this action.
265 * @param cut The corresponding keyboard accelerator (shortcut).
266 * @param receiver The SLOT's parent.
267 * @param slot The SLOT to invoke to execute this action.
268 * @param parent This action's parent.
269 * @param name An internal name for this action.
270 */
271 KRadioAction( const QString& text, const QIconSet& pix, const KShortcut& cut,
272 const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 );
273
274 /**
275 * @param text The text that will be displayed.
276 * @param pix The dynamically loaded icon that goes with this action.
277 * @param cut The corresponding keyboard accelerator (shortcut).
278 * @param receiver The SLOT's parent.
279 * @param slot The SLOT to invoke to execute this action.
280 * @param parent This action's parent.
281 * @param name An internal name for this action.
282 */
283 KRadioAction( const QString& text, const QString& pix, const KShortcut& cut,
284 const QObject* receiver, const char* slot,
285 QObject* parent, const char* name = 0 );
286
287 /**
288 * @param parent This action's parent.
289 * @param name An internal name for this action.
290 */
291 KRadioAction( QObject* parent = 0, const char* name = 0 );
292
293protected:
294 virtual void slotActivated();
295
296protected:
297 virtual void virtual_hook( int id, void* data );
298private:
299 class KRadioActionPrivate;
300 KRadioActionPrivate *d;
301};
302
303/**
304 * Action for selecting one of several items.
305 *
306 * This action shows up a submenu with a list of items.
307 * One of them can be checked. If the user clicks on an item
308 * this item will automatically be checked,
309 * the formerly checked item becomes unchecked.
310 * There can be only one item checked at a time.
311 *
312 * @short Action for selecting one of several items
313 */
314class KSelectAction : public KAction
315{
316 Q_OBJECT
317 Q_PROPERTY( int currentItem READ currentItem WRITE setCurrentItem )
318 Q_PROPERTY( QStringList items READ items WRITE setItems )
319 Q_PROPERTY( bool editable READ isEditable WRITE setEditable )
320 Q_PROPERTY( int comboWidth READ comboWidth WRITE setComboWidth )
321 Q_PROPERTY( QString currentText READ currentText )
322 Q_PROPERTY( bool menuAccelsEnabled READ menuAccelsEnabled WRITE setMenuAccelsEnabled )
323public:
324
325 /**
326 * Constructs a select action with text and potential keyboard
327 * accelerator but nothing else. Use this only if you really
328 * know what you are doing.
329 *
330 * @param text The text that will be displayed.
331 * @param cut The corresponding keyboard accelerator (shortcut).
332 * @param parent This action's parent.
333 * @param name An internal name for this action.
334 */
335 KSelectAction( const QString& text, const KShortcut& cut = KShortcut(), QObject* parent = 0, const char* name = 0 );
336
337 /**
338 * @param text The text that will be displayed.
339 * @param cut The corresponding keyboard accelerator (shortcut).
340 * @param receiver The SLOT's parent.
341 * @param slot The SLOT to invoke to execute this action.
342 * @param parent This action's parent.
343 * @param name An internal name for this action.
344 */
345 KSelectAction( const QString& text, const KShortcut& cut,
346 const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 );
347
348 /**
349 * @param text The text that will be displayed.
350 * @param pix The icons that go with this action.
351 * @param cut The corresponding keyboard accelerator (shortcut).
352 * @param parent This action's parent.
353 * @param name An internal name for this action.
354 */
355 KSelectAction( const QString& text, const QIconSet& pix, const KShortcut& cut = KShortcut(),
356 QObject* parent = 0, const char* name = 0 );
357
358 /**
359 * @param text The text that will be displayed.
360 * @param pix The dynamically loaded icon that goes with this action.
361 * @param cut The corresponding keyboard accelerator (shortcut).
362 * @param parent This action's parent.
363 * @param name An internal name for this action.
364 */
365 KSelectAction( const QString& text, const QString& pix, const KShortcut& cut = KShortcut(),
366 QObject* parent = 0, const char* name = 0 );
367
368 /**
369 * @param text The text that will be displayed.
370 * @param pix The icons that go with this action.
371 * @param cut The corresponding keyboard accelerator (shortcut).
372 * @param receiver The SLOT's parent.
373 * @param slot The SLOT to invoke to execute this action.
374 * @param parent This action's parent.
375 * @param name An internal name for this action.
376 */
377 KSelectAction( const QString& text, const QIconSet& pix, const KShortcut& cut,
378 const QObject* receiver, const char* slot, QObject* parent, const char* name = 0 );
379
380 /**
381 * @param text The text that will be displayed.
382 * @param pix The dynamically loaded icon that goes with this action.
383 * @param cut The corresponding keyboard accelerator (shortcut).
384 * @param receiver The SLOT's parent.
385 * @param slot The SLOT to invoke to execute this action.
386 * @param parent This action's parent.
387 * @param name An internal name for this action.
388 */
389 KSelectAction( const QString& text, const QString& pix, const KShortcut& cut,
390 const QObject* receiver, const char* slot,
391 QObject* parent, const char* name = 0 );
392
393 /**
394 * @param parent This action's parent.
395 * @param name An internal name for this action.
396 */
397 KSelectAction( QObject* parent = 0, const char* name = 0 );
398
399 /**
400 * Destructor
401 */
402 virtual ~KSelectAction();
403
404 /**
405 * "Plug" or insert this action into a given widget.
406 *
407 * This will typically be a menu or a toolbar.
408 * From this point on, you will never need to directly
409 * manipulate the item in the menu or toolbar.
410 * You do all enabling/disabling/manipulation directly with your KSelectAction object.
411 *
412 * @param widget The GUI element to display this action.
413 * @param index The index of the item.
414 */
415 virtual int plug( QWidget* widget, int index = -1 );
416
417 /**
418 * When this action is plugged into a toolbar, it creates a combobox.
419 * @return true if the combo editable.
420 */
421 virtual bool isEditable() const;
422
423 /**
424 * @return the items that can be selected with this action.
425 * Use setItems to set them.
426 */
427 virtual QStringList items() const;
428
429 virtual void changeItem( int index, const QString& text );
430
431 virtual QString currentText() const;
432
433 virtual int currentItem() const;
434
435 /**
436 * When this action is plugged into a toolbar, it creates a combobox.
437 * This returns the maximum width set by setComboWidth
438 */
439 virtual int comboWidth() const;
440
441 QPopupMenu* popupMenu() const;
442
443 /**
444 * Deprecated. See @ref setMenuAccelsEnabled .
445 * @since 3.1
446 */
447 void setRemoveAmpersandsInCombo( bool b );
448 /// @since 3.1
449 bool removeAmpersandsInCombo() const;
450
451 /**
452 * Sets whether any occurence of the ampersand character ( &amp; ) in items
453 * should be interpreted as keyboard accelerator for items displayed in a
454 * menu or not.
455 * @since 3.1
456 */
457 void setMenuAccelsEnabled( bool b );
458 /// @since 3.1
459 bool menuAccelsEnabled() const;
460
461public slots:
462 /**
463 * Sets the currently checked item.
464 *
465 * @param index Index of the item (remember the first item is zero).
466 */
467 virtual void setCurrentItem( int index );
468
469 /**
470 * Sets the items to be displayed in this action
471 * You need to call this.
472 */
473 virtual void setItems( const QStringList &lst );
474
475 /**
476 * Clears up all the items in this action
477 */
478 virtual void clear();
479
480 /**
481 * When this action is plugged into a toolbar, it creates a combobox.
482 * This makes the combo editable or read-only.
483 */
484 virtual void setEditable( bool );
485
486 /**
487 * When this action is plugged into a toolbar, it creates a combobox.
488 * This gives a _maximum_ size to the combobox.
489 * The minimum size is automatically given by the contents (the items).
490 */
491 virtual void setComboWidth( int width );
492
493protected:
494 virtual void changeItem( int id, int index, const QString& text );
495
496 /**
497 * Depending on the menuAccelsEnabled property this method will return the
498 * actions items in a way for inclusion in a combobox with the ampersand
499 * character removed from all items or not.
500 * @since 3.1
501 */
502 QStringList comboItems() const;
503
504protected slots:
505 virtual void slotActivated( int id );
506 virtual void slotActivated( const QString &text );
507 virtual void slotActivated();
508
509signals:
510 void activated( int index );
511 void activated( const QString& text );
512
513protected:
514 virtual void updateCurrentItem( int id );
515
516 virtual void updateComboWidth( int id );
517
518 virtual void updateItems( int id );
519
520 virtual void updateClear( int id );
521
522protected:
523 virtual void virtual_hook( int id, void* data );
524private:
525 void setupMenu() const;
526 class KSelectActionPrivate;
527 KSelectActionPrivate *d;
528
529};
530
531/// Remove this class in KDE-4.0. It doesn't add _anything_ to KSelectAction
532/**
533 * @deprecated Use KSelectAction instead.
534 */
535class KListAction : public KSelectAction
536{
537 Q_OBJECT
538public:
539 /**
540 * Constructs a list action with text and potential keyboard
541 * accelerator but nothing else. Use this only if you really
542 * know what you are doing.
543 *
544 * @param text The text that will be displayed.
545 * @param cut The corresponding keyboard accelerator (shortcut).
546 * @param parent This action's parent.
547 * @param name An internal name for this action.
548 */
549 KListAction( const QString& text, const KShortcut& cut = KShortcut(), QObject* parent = 0,
550 const char* name = 0 );
551
552 /**
553 * @param text The text that will be displayed.
554 * @param cut The corresponding keyboard accelerator (shortcut).
555 * @param receiver The SLOT's parent.
556 * @param slot The SLOT to invoke to execute this action.
557 * @param parent This action's parent.
558 * @param name An internal name for this action.
559 */
560 KListAction( const QString& text, const KShortcut& cut, const QObject* receiver,
561 const char* slot, QObject* parent, const char* name = 0 );
562
563 /**
564 * @param text The text that will be displayed.
565 * @param pix The icons that go with this action.
566 * @param cut The corresponding keyboard accelerator (shortcut).
567 * @param parent This action's parent.
568 * @param name An internal name for this action.
569 */
570 KListAction( const QString& text, const QIconSet& pix, const KShortcut& cut = KShortcut(),
571 QObject* parent = 0, const char* name = 0 );
572
573 /**
574 * @param text The text that will be displayed.
575 * @param pix The dynamically loaded icon that goes with this action.
576 * @param cut The corresponding keyboard accelerator (shortcut).
577 * @param parent This action's parent.
578 * @param name An internal name for this action.
579 */
580 KListAction( const QString& text, const QString& pix, const KShortcut& cut = KShortcut(),
581 QObject* parent = 0, const char* name = 0 );
582
583 /**
584 * @param text The text that will be displayed.
585 * @param pix The icons that go with this action.
586 * @param cut The corresponding keyboard accelerator (shortcut).
587 * @param receiver The SLOT's parent.
588 * @param slot The SLOT to invoke to execute this action.
589 * @param parent This action's parent.
590 * @param name An internal name for this action.
591 */
592 KListAction( const QString& text, const QIconSet& pix, const KShortcut& cut,
593 const QObject* receiver, const char* slot, QObject* parent,
594 const char* name = 0 );
595
596 /**
597 * @param text The text that will be displayed.
598 * @param pix The dynamically loaded icon that goes with this action.
599 * @param cut The corresponding keyboard accelerator (shortcut).
600 * @param receiver The SLOT's parent.
601 * @param slot The SLOT to invoke to execute this action.
602 * @param parent This action's parent.
603 * @param name An internal name for this action.
604 */
605 KListAction( const QString& text, const QString& pix, const KShortcut& cut,
606 const QObject* receiver, const char* slot, QObject* parent,
607 const char* name = 0 );
608
609 /**
610 * @param parent This action's parent.
611 * @param name An internal name for this action.
612 */
613 KListAction( QObject* parent = 0, const char* name = 0 );
614
615 /**
616 * Destructor
617 */
618 virtual ~KListAction();
619
620
621 virtual QString currentText() const;
622 virtual int currentItem() const;
623
624
625public slots:
626 /**
627 * Sets the currently checked item.
628 *
629 * @param index Index of the item (remember the first item is zero).
630 */
631 virtual void setCurrentItem( int index );
632
633protected:
634 virtual void virtual_hook( int id, void* data );
635private:
636 class KListActionPrivate;
637 KListActionPrivate *d;
638};
639
640/**
641 * This class is an action to handle a recent files submenu.
642 * The best way to create the action is to use KStdAction::openRecent.
643 * Then you simply need to call @ref loadEntries on startup, @ref saveEntries
644 * on shutdown, @ref addURL when your application loads/saves a file.
645 *
646 * @author Michael Koch
647 * @short Recent files action
648 */
649class KRecentFilesAction : public KListAction // TODO public KSelectAction
650{
651 Q_OBJECT
652 Q_PROPERTY( uint maxItems READ maxItems WRITE setMaxItems )
653public:
654 /**
655 * @param text The text that will be displayed.
656 * @param cut The corresponding keyboard accelerator (shortcut).
657 * @param parent This action's parent.
658 * @param name An internal name for this action.
659 * @param maxItems The maximum number of files to display
660 */
661 KRecentFilesAction( const QString& text, const KShortcut& cut,
662 QObject* parent, const char* name = 0,
663 uint maxItems = 10 );
664
665 /**
666 * @param text The text that will be displayed.
667 * @param cut The corresponding keyboard accelerator (shortcut).
668 * @param receiver The SLOT's parent.
669 * @param slot The SLOT to invoke when a URL is selected.
670 * Its signature is of the form slotURLSelected( const KURL & ).
671 * @param parent This action's parent.
672 * @param name An internal name for this action.
673 * @param maxItems The maximum number of files to display
674 */
675 KRecentFilesAction( const QString& text, const KShortcut& cut,
676 const QObject* receiver, const char* slot,
677 QObject* parent, const char* name = 0,
678 uint maxItems = 10 );
679
680 /**
681 * @param text The text that will be displayed.
682 * @param pix The icons that go with this action.
683 * @param cut The corresponding keyboard accelerator (shortcut).
684 * @param parent This action's parent.
685 * @param name An internal name for this action.
686 * @param maxItems The maximum number of files to display
687 */
688 KRecentFilesAction( const QString& text, const QIconSet& pix, const KShortcut& cut,
689 QObject* parent, const char* name = 0,
690 uint maxItems = 10 );
691
692 /**
693 * @param text The text that will be displayed.
694 * @param pix The dynamically loaded icon that goes with this action.
695 * @param cut The corresponding keyboard accelerator (shortcut).
696 * @param parent This action's parent.
697 * @param name An internal name for this action.
698 * @param maxItems The maximum number of files to display
699 */
700 KRecentFilesAction( const QString& text, const QString& pix, const KShortcut& cut,
701 QObject* parent, const char* name = 0,
702 uint maxItems = 10 );
703
704 /**
705 * @param text The text that will be displayed.
706 * @param pix The icons that go with this action.
707 * @param cut The corresponding keyboard accelerator (shortcut).
708 * @param receiver The SLOT's parent.
709 * @param slot The SLOT to invoke when a URL is selected.
710 * Its signature is of the form slotURLSelected( const KURL & ).
711 * @param parent This action's parent.
712 * @param name An internal name for this action.
713 * @param maxItems The maximum number of files to display
714 */
715 KRecentFilesAction( const QString& text, const QIconSet& pix, const KShortcut& cut,
716 const QObject* receiver, const char* slot,
717 QObject* parent, const char* name = 0,
718 uint maxItems = 10 );
719
720 /**
721 * @param text The text that will be displayed.
722 * @param pix The dynamically loaded icon that goes with this action.
723 * @param cut The corresponding keyboard accelerator (shortcut).
724 * @param receiver The SLOT's parent.
725 * @param slot The SLOT to invoke when a URL is selected.
726 * Its signature is of the form slotURLSelected( const KURL & ).
727 * @param parent This action's parent.
728 * @param name An internal name for this action.
729 * @param maxItems The maximum number of files to display
730 */
731 KRecentFilesAction( const QString& text, const QString& pix, const KShortcut& cut,
732 const QObject* receiver, const char* slot,
733 QObject* parent, const char* name = 0,
734 uint maxItems = 10 );
735
736 /**
737 * @param parent This action's parent.
738 * @param name An internal name for this action.
739 * @param maxItems The maximum number of files to display
740 */
741 KRecentFilesAction( QObject* parent = 0, const char* name = 0,
742 uint maxItems = 10 );
743
744 /**
745 * Destructor.
746 */
747 virtual ~KRecentFilesAction();
748
749 /**
750 * Returns the maximum of items in the recent files list.
751 */
752 uint maxItems() const;
753
754public slots:
755 /**
756 * Sets the maximum of items in the recent files list.
757 * The default for this value is 10 set in the constructor.
758 *
759 * If this value is lesser than the number of items currently
760 * in the recent files list the last items are deleted until
761 * the number of items are equal to the new maximum.
762 */
763 void setMaxItems( uint maxItems );
764
765 /**
766 * Loads the recent files entries from a given KConfig object.
767 * You can provide the name of the group used to load the entries.
768 * If the groupname is empty, entries are load from a group called 'RecentFiles'
769 *
770 * This method does not effect the active group of KConfig.
771 */
772 void loadEntries( KConfig* config, QString groupname=QString::null );
773
774 /**
775 * Saves the current recent files entries to a given KConfig object.
776 * You can provide the name of the group used to load the entries.
777 * If the groupname is empty, entries are saved to a group called 'RecentFiles'
778 *
779 * This method does not effect the active group of KConfig.
780 */
781 void saveEntries( KConfig* config, QString groupname=QString::null );
782
783public slots:
784 /**
785 * Add URL to recent files list.
786 *
787 * @param url The URL of the file
788 */
789 void addURL( const KURL& url );
790
791 /**
792 * Remove an URL from the recent files list.
793 *
794 * @param url The URL of the file
795 */
796 void removeURL( const KURL& url );
797
798 /**
799 * Removes all entries from the recent files list.
800 */
801 void clearURLList();
802
803signals:
804
805 /**
806 * This signal gets emited when the user selects an URL.
807 *
808 * @param url The URL thats the user selected.
809 */
810 void urlSelected( const KURL& url );
811
812protected slots:
813 /**
814 *
815 */
816 void itemSelected( const QString& string );
817
818protected:
819 virtual void virtual_hook( int id, void* data );
820private:
821 void init();
822
823 class KRecentFilesActionPrivate;
824 KRecentFilesActionPrivate *d;
825};
826
827class KFontAction : public KSelectAction
828{
829 Q_OBJECT
830 Q_PROPERTY( QString font READ font WRITE setFont )
831public:
832 KFontAction( const QString& text, const KShortcut& cut = KShortcut(), QObject* parent = 0,
833 const char* name = 0 );
834 KFontAction( const QString& text, const KShortcut& cut,
835 const QObject* receiver, const char* slot, QObject* parent,
836 const char* name = 0 );
837 KFontAction( const QString& text, const QIconSet& pix, const KShortcut& cut = KShortcut(),
838 QObject* parent = 0, const char* name = 0 );
839 KFontAction( const QString& text, const QString& pix, const KShortcut& cut = KShortcut(),
840 QObject* parent = 0, const char* name = 0 );
841 KFontAction( const QString& text, const QIconSet& pix, const KShortcut& cut,
842 const QObject* receiver, const char* slot, QObject* parent,
843 const char* name = 0 );
844 KFontAction( const QString& text, const QString& pix, const KShortcut& cut,
845 const QObject* receiver, const char* slot, QObject* parent,
846 const char* name = 0 );
847
848 KFontAction( QObject* parent = 0, const char* name = 0 );
849 ~KFontAction();
850
851 QString font() const {
852 return currentText();
853 }
854
855 int plug( QWidget*, int index = -1 );
856
857public slots:
858 void setFont( const QString &family );
859
860protected:
861 virtual void virtual_hook( int id, void* data );
862private:
863 class KFontActionPrivate;
864 KFontActionPrivate *d;
865};
866
867class KFontSizeAction : public KSelectAction
868{
869 Q_OBJECT
870 Q_PROPERTY( int fontSize READ fontSize WRITE setFontSize )
871public:
872 KFontSizeAction( const QString& text, const KShortcut& cut = KShortcut(), QObject* parent = 0,
873 const char* name = 0 );
874 KFontSizeAction( const QString& text, const KShortcut& cut, const QObject* receiver,
875 const char* slot, QObject* parent, const char* name = 0 );
876 KFontSizeAction( const QString& text, const QIconSet& pix, const KShortcut& cut = KShortcut(),
877 QObject* parent = 0, const char* name = 0 );
878 KFontSizeAction( const QString& text, const QString& pix, const KShortcut& cut = KShortcut(),
879 QObject* parent = 0, const char* name = 0 );
880 KFontSizeAction( const QString& text, const QIconSet& pix, const KShortcut& cut,
881 const QObject* receiver, const char* slot,
882 QObject* parent, const char* name = 0 );
883 KFontSizeAction( const QString& text, const QString& pix, const KShortcut& cut,
884 const QObject* receiver, const char* slot,
885 QObject* parent, const char* name = 0 );
886 KFontSizeAction( QObject* parent = 0, const char* name = 0 );
887
888 virtual ~KFontSizeAction();
889
890 virtual int fontSize() const;
891
892public slots:
893 virtual void setFontSize( int size );
894
895protected slots:
896 virtual void slotActivated( int );
897 virtual void slotActivated( const QString& );
898 virtual void slotActivated() { KAction::slotActivated(); }
899
900signals:
901 void fontSizeChanged( int );
902
903private:
904 void init();
905
906
907protected:
908 virtual void virtual_hook( int id, void* data );
909private:
910 class KFontSizeActionPrivate;
911 KFontSizeActionPrivate *d;
912};
913
914
915/**
916 * A KActionMenu is an action that holds a sub-menu of other actions.
917 * insert() and remove() allow to insert and remove actions into this action-menu.
918 * Plugged in a popupmenu, it will create a submenu.
919 * Plugged in a toolbar, it will create a button with a popup menu.
920 *
921 * This is the action used by the XMLGUI since it holds other actions.
922 * If you want a submenu for selecting one tool among many (without icons), see KSelectAction.
923 * See also setDelayed about the main action.
924 */
925class KActionMenu : public KAction
926{
927 Q_OBJECT
928 Q_PROPERTY( bool delayed READ delayed WRITE setDelayed )
929 Q_PROPERTY( bool stickyMenu READ stickyMenu WRITE setStickyMenu )
930
931public:
932 KActionMenu( const QString& text, QObject* parent = 0,
933 const char* name = 0 );
934 KActionMenu( const QString& text, const QIconSet& icon,
935 QObject* parent = 0, const char* name = 0 );
936 KActionMenu( const QString& text, const QString& icon,
937 QObject* parent = 0, const char* name = 0 );
938 KActionMenu( QObject* parent = 0, const char* name = 0 );
939 virtual ~KActionMenu();
940
941 virtual void insert( KAction*, int index = -1 );
942 virtual void remove( KAction* );
943
944//US KPopupMenu* popupMenu() const;
945 QPopupMenu* popupMenu() const;
946 void popup( const QPoint& global );
947
948 /**
949 * Returns true if this action creates a delayed popup menu
950 * when plugged in a KToolbar.
951 */
952 bool delayed() const;
953 /**
954 * If set to true, this action will create a delayed popup menu
955 * when plugged in a KToolbar. Otherwise it creates a normal popup.
956 * Default: delayed
957 *
958 * Remember that if the "main" action (the toolbar button itself)
959 * cannot be clicked, then you should call setDelayed(false).
960 *
961 * On the opposite, if the main action can be clicked, it can only happen
962 * in a toolbar: in a menu, the parent of a submenu can't be activated.
963 * To get a "normal" menu item when plugged a menu (and no submenu)
964 * use KToolBarPopupAction.
965 */
966 void setDelayed(bool _delayed);
967
968 /**
969 * Returns true if this action creates a sticky popup menu.
970 * See @ref setStickyMenu.
971 */
972 bool stickyMenu() const;
973 /**
974 * If set to true, this action will create a sticky popup menu
975 * when plugged in a KToolbar.
976 * "Sticky", means it's visible until a selection is made or the mouse is
977 * clicked elsewhere. This feature allows you to make a selection without
978 * having to press and hold down the mouse while making a selection.
979 * Default: sticky.
980 */
981 void setStickyMenu(bool sticky);
982
983 virtual int plug( QWidget* widget, int index = -1 );
984
985protected:
986 virtual void virtual_hook( int id, void* data );
987private:
988 class KActionMenuPrivate;
989 KActionMenuPrivate *d;
990};
991
992/**
993 * This action is a normal action everywhere, except in a toolbar
994 * where it also has a popupmenu (optionnally delayed). This action is designed
995 * for history actions (back/forward, undo/redo) and for any other action
996 * that has more detail in a toolbar than in a menu (e.g. tool chooser
997 * with "Other" leading to a dialog...).
998 */
999class KToolBarPopupAction : public KAction
1000{
1001 Q_OBJECT
1002 Q_PROPERTY( bool delayed READ delayed WRITE setDelayed )
1003 Q_PROPERTY( bool stickyMenu READ stickyMenu WRITE setStickyMenu )
1004
1005public:
1006 //Not all constructors - because we need an icon, since this action only makes
1007 // sense when being plugged at least in a toolbar.
1008 /**
1009 * Create a KToolBarPopupAction, with a text, an icon, an optionnal accelerator,
1010 * parent and name.
1011 *
1012 * @param text The text that will be displayed.
1013 * @param icon The icon to display.
1014 * @param cut The corresponding keyboard accelerator (shortcut).
1015 * @param parent This action's parent.
1016 * @param name An internal name for this action.
1017 */
1018 KToolBarPopupAction( const QString& text, const QString& icon, const KShortcut& cut = KShortcut(),
1019 QObject* parent = 0, const char* name = 0 );
1020
1021 /**
1022 * Create a KToolBarPopupAction, with a text, an icon, an accelerator,
1023 * a slot connected to the action, parent and name.
1024 *
1025 * If you do not want or have a keyboard accelerator, set the
1026 * @p cut param to 0.
1027 *
1028 * @param text The text that will be displayed.
1029 * @param icon The icon to display.
1030 * @param cut The corresponding keyboard accelerator (shortcut).
1031 * @param receiver The SLOT's owner.
1032 * @param slot The SLOT to invoke to execute this action.
1033 * @param parent This action's parent.
1034 * @param name An internal name for this action.
1035 */
1036 KToolBarPopupAction( const QString& text, const QString& icon, const KShortcut& cut,
1037 const QObject* receiver, const char* slot,
1038 QObject* parent = 0, const char* name = 0 );
1039
1040 /**
1041 * Create a KToolBarPopupAction, with a KGuiItem, an accelerator,
1042 * a slot connected to the action, parent and name. The text and the
1043 * icon are taken from the KGuiItem.
1044 *
1045 * If you do not want or have a keyboard accelerator, set the
1046 * @p cut param to 0.
1047 *
1048 * @param item The text and icon that will be displayed.
1049 * @param cut The corresponding keyboard accelerator (shortcut).
1050 * @param receiver The SLOT's owner.
1051 * @param slot The SLOT to invoke to execute this action.
1052 * @param parent This action's parent.
1053 * @param name An internal name for this action.
1054 */
1055
1056 KToolBarPopupAction( const KGuiItem& item, const KShortcut& cut,
1057 const QObject* receiver, const char* slot,
1058 KActionCollection* parent, const char* name );
1059
1060 virtual ~KToolBarPopupAction();
1061
1062 virtual int plug( QWidget *widget, int index = -1 );
1063
1064 /**
1065 * The popup menu that is shown when clicking (some time) on the toolbar
1066 * button. You may want to plug items into it on creation, or connect to
1067 * aboutToShow for a more dynamic menu.
1068 */
1069//US KPopupMenu *popupMenu() const;
1070 QPopupMenu *popupMenu() const;
1071
1072 /**
1073 * Returns true if this action creates a delayed popup menu
1074 * when plugged in a KToolbar.
1075 */
1076 bool delayed() const;
1077 /**
1078 * If set to true, this action will create a delayed popup menu
1079 * when plugged in a KToolbar. Otherwise it creates a normal popup.
1080 * Default: delayed.
1081 */
1082 void setDelayed(bool delayed);
1083 /**
1084 * Returns true if this action creates a sticky popup menu.
1085 * See @ref setStickyMenu.
1086 */
1087 bool stickyMenu() const;
1088 /**
1089 * If set to true, this action will create a sticky popup menu
1090 * when plugged in a KToolbar.
1091 * "Sticky", means it's visible until a selection is made or the mouse is
1092 * clicked elsewhere. This feature allows you to make a selection without
1093 * having to press and hold down the mouse while making a selection.
1094 * Only available if delayed() is true.
1095 * Default: sticky.
1096 */
1097 void setStickyMenu(bool sticky);
1098
1099private:
1100//US KPopupMenu *m_popup;
1101 QPopupMenu *m_popup;
1102 bool m_delayed:1;
1103 bool m_stickyMenu:1;
1104protected:
1105 virtual void virtual_hook( int id, void* data );
1106private:
1107 class KToolBarPopupActionPrivate;
1108 KToolBarPopupActionPrivate *d;
1109};
1110
1111/**
1112 * An action that takes care of everything associated with
1113 * showing or hiding a toolbar by a menu action. It will
1114 * show or hide the toolbar with the given name when
1115 * activated, and check or uncheck itself if the toolbar
1116 * is manually shown or hidden.
1117 *
1118 * If you need to perfom some additional action when the
1119 * toolbar is shown or hidden, connect to the toggled(bool)
1120 * signal. It will be emitted after the toolbar's
1121 * visibility has changed, whenever it changes.
1122 * @since 3.1
1123 */
1124class KToggleToolBarAction : public KToggleAction
1125{
1126 Q_OBJECT
1127public:
1128 /**
1129 * Create a KToggleToolbarAction that manages the toolbar
1130 * named toolBarName. This can be either the name of a
1131 * toolbar in an xml ui file, or a toolbar programmatically
1132 * created with that name.
1133 */
1134 KToggleToolBarAction( const char* toolBarName, const QString& text,
1135 KActionCollection* parent, const char* name );
1136 KToggleToolBarAction( KToolBar *toolBar, const QString &text,
1137 KActionCollection *parent, const char *name );
1138 virtual ~KToggleToolBarAction();
1139
1140 virtual int plug( QWidget*, int index = -1 );
1141
1142 KToolBar *toolBar() {
1143 return m_toolBar;
1144 }
1145
1146public slots:
1147 virtual void setChecked( bool );
1148
1149private:
1150 QCString m_toolBarName;
1151 QGuardedPtr<KToolBar> m_toolBar;
1152protected:
1153 virtual void virtual_hook( int id, void* data );
1154private:
1155 class KToggleToolBarActionPrivate;
1156 KToggleToolBarActionPrivate *d;
1157};
1158
1159/**
1160 * An action that automatically embeds a widget into a
1161 * toolbar.
1162 */
1163class KWidgetAction : public KAction
1164{
1165 Q_OBJECT
1166public:
1167 /**
1168 * Create an action that will embed widget into a toolbar
1169 * when plugged. This action may only be plugged into
1170 * a toolbar.
1171 */
1172 KWidgetAction( QWidget* widget, const QString& text,
1173 const KShortcut& cut,
1174 const QObject* receiver, const char* slot,
1175 KActionCollection* parent, const char* name );
1176 virtual ~KWidgetAction();
1177
1178 /**
1179 * Returns the widget associated with this action.
1180 */
1181 QWidget* widget() { return m_widget; }
1182
1183 void setAutoSized( bool );
1184
1185 /**
1186 * Plug the action. The widget passed to the constructor
1187 * will be reparented to w, which must inherit KToolBar.
1188 */
1189 virtual int plug( QWidget* w, int index = -1 );
1190 /**
1191 * Unplug the action. Ensures that the action is not
1192 * destroyed. It will be hidden and reparented to 0L instead.
1193 */
1194 virtual void unplug( QWidget *w );
1195protected slots:
1196 void slotToolbarDestroyed();
1197private:
1198 QGuardedPtr<QWidget> m_widget;
1199 bool m_autoSized;
1200protected:
1201 virtual void virtual_hook( int id, void* data );
1202private:
1203 class KWidgetActionPrivate;
1204 KWidgetActionPrivate *d;
1205};
1206
1207class KActionSeparator : public KAction
1208{
1209 Q_OBJECT
1210public:
1211 KActionSeparator( QObject* parent = 0, const char* name = 0 );
1212 virtual ~KActionSeparator();
1213
1214 virtual int plug( QWidget*, int index = -1 );
1215
1216protected:
1217 virtual void virtual_hook( int id, void* data );
1218private:
1219 class KActionSeparatorPrivate;
1220 KActionSeparatorPrivate *d;
1221};
1222
1223#endif
diff --git a/microkde/kdeui/kactioncollection.cpp b/microkde/kdeui/kactioncollection.cpp
new file mode 100644
index 0000000..b819e76
--- a/dev/null
+++ b/microkde/kdeui/kactioncollection.cpp
@@ -0,0 +1,839 @@
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 "kactioncollection.h"
27//US#include "kactionshortcutlist.h"
28
29#include <qptrdict.h>
30//US#include <qvariant.h>
31
32//US#include <kaccel.h>
33//US#include <kaccelbase.h>
34//US#include <kapplication.h>
35#include <kdebug.h>
36//US#include <kxmlguifactory.h>
37
38//US I included the following files
39#include <qasciidict.h>
40#include <qptrlist.h>
41#include "kaction.h"
42#include <kglobal.h>
43#include <qobject.h>
44#include <qwidget.h>
45
46class KActionCollection::KActionCollectionPrivate
47{
48public:
49 KActionCollectionPrivate()
50 {
51//US m_instance = 0;
52 //m_bOneKAccelOnly = false;
53 //m_iWidgetCurrent = 0;
54 m_bAutoConnectShortcuts = true;
55 m_widget = 0;
56 m_kaccel = m_builderKAccel = 0;
57 m_dctHighlightContainers.setAutoDelete( true );
58 m_highlight = false;
59 m_currentHighlightAction = 0;
60 m_statusCleared = true;
61 }
62
63//US KInstance *m_instance;
64//US QString m_sXMLFile;
65 bool m_bAutoConnectShortcuts;
66 //bool m_bOneKAccelOnly;
67 //int m_iWidgetCurrent;
68 //QValueList<QWidget*> m_widgetList;
69 //QValueList<KAccel*> m_kaccelList;
70 QValueList<KActionCollection*> m_docList;
71 QWidget *m_widget;
72 KAccel *m_kaccel;
73 KAccel *m_builderKAccel;
74
75 QAsciiDict<KAction> m_actionDict;
76 QPtrDict< QPtrList<KAction> > m_dctHighlightContainers;
77 bool m_highlight;
78 KAction *m_currentHighlightAction;
79 bool m_statusCleared;
80};
81
82KActionCollection::KActionCollection( QWidget *parent, const char *name /*US,
83 KInstance *instance */)
84 : QObject( (QObject*)parent, name )
85{
86 kdDebug(129) << "KActionCollection::KActionCollection( " << parent << ", " << name << " ): this = " << this << endl; // ellis
87 d = new KActionCollectionPrivate;
88 if( parent )
89 setWidget( parent );
90 //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0);
91//US setInstance( instance );
92}
93
94
95KActionCollection::KActionCollection( QWidget *watch, QObject* parent, const char *name /*US,
96 KInstance *instance */)
97 : QObject( parent, name )
98{
99 kdDebug(129) << "KActionCollection::KActionCollection( " << watch << ", " << parent << ", " << name << " ): this = " << this << endl; //ellis
100 d = new KActionCollectionPrivate;
101 if( watch )
102 setWidget( watch );
103 //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0);
104//US setInstance( instance );
105}
106
107// KDE 4: remove
108KActionCollection::KActionCollection( QObject *parent, const char *name /*US,
109 KInstance *instance */)
110 : QObject( parent, name )
111{
112 kdWarning(129) << "KActionCollection::KActionCollection( QObject *parent, const char *name, KInstance *instance )" << endl; //ellis
113//US kdBacktrace not available
114//US kdDebug(129) << kdBacktrace() << endl;
115 d = new KActionCollectionPrivate;
116//US QWidget* w = dynamic_cast<QWidget*>( parent );
117 QWidget* w = (QWidget*)( parent );
118 if( w )
119 setWidget( w );
120 //d->m_bOneKAccelOnly = (d->m_kaccelList.count() > 0);
121//US setInstance( instance );
122}
123
124KActionCollection::KActionCollection( const KActionCollection &copy )
125 : QObject()
126{
127 kdWarning(129) << "KActionCollection::KActionCollection( const KActionCollection & ): function is severely deprecated." << endl;
128 d = new KActionCollectionPrivate;
129 *this = copy;
130}
131// KDE 4: remove end
132
133KActionCollection::~KActionCollection()
134{
135 kdDebug(129) << "KActionCollection::~KActionCollection(): this = " << this << endl;
136 for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) {
137 KAction* pAction = it.current();
138 if ( pAction->m_parentCollection == this )
139 pAction->m_parentCollection = 0L;
140 }
141
142//US delete d->m_kaccel;
143//US delete d->m_builderKAccel;
144 delete d; d = 0;
145}
146
147void KActionCollection::setWidget( QWidget* w )
148{
149 //if ( d->m_actionDict.count() > 0 ) {
150 // kdError(129) << "KActionCollection::setWidget(): must be called before any actions are added to collection!" << endl;
151 // kdDebug(129) << kdBacktrace() << endl;
152 //}
153 //else
154 if ( !d->m_widget ) {
155 d->m_widget = w;
156 qDebug("KActionCollection::setWidget: warning: KAccel is never used in microkde");
157//US d->m_kaccel = new KAccel( w, this, "KActionCollection-KAccel" );
158 }
159 else if ( d->m_widget != w )
160 kdWarning(129) << "KActionCollection::setWidget(): tried to change widget from " << d->m_widget << " to " << w << endl;
161}
162
163void KActionCollection::setAutoConnectShortcuts( bool b )
164{
165 d->m_bAutoConnectShortcuts = b;
166}
167
168bool KActionCollection::isAutoConnectShortcuts()
169{
170 return d->m_bAutoConnectShortcuts;
171}
172
173bool KActionCollection::addDocCollection( KActionCollection* pDoc )
174{
175 d->m_docList.append( pDoc );
176 return true;
177}
178
179void KActionCollection::beginXMLPlug( QWidget *widget )
180{
181 qDebug("KActionCollection::beginXMLPlug has to be fixed");
182/*US
183 kdDebug(129) << "KActionCollection::beginXMLPlug( buildWidget = " << widget << " ): this = " << this << " d->m_builderKAccel = " << d->m_builderKAccel << endl;
184
185 if( widget && !d->m_builderKAccel ) {
186 d->m_builderKAccel = new KAccel( widget, this, "KActionCollection-BuilderKAccel" );
187 }
188*/
189}
190
191void KActionCollection::endXMLPlug()
192{
193 kdDebug(129) << "KActionCollection::endXMLPlug(): this = " << this << endl;
194 //s_kaccelXML = 0;
195}
196
197void KActionCollection::prepareXMLUnplug()
198{
199 qDebug("KActionCollection::prepareXMLUnplug has to be fixed");
200/*US
201 kdDebug(129) << "KActionCollection::prepareXMLUnplug(): this = " << this << endl;
202 unplugShortcuts( d->m_kaccel );
203
204 if( d->m_builderKAccel ) {
205 unplugShortcuts( d->m_builderKAccel );
206 delete d->m_builderKAccel;
207 d->m_builderKAccel = 0;
208 }
209*/
210}
211
212void KActionCollection::unplugShortcuts( KAccel* kaccel )
213{
214 qDebug("KActionCollection::unplugShortcuts has to be fixed");
215/*US
216 for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) {
217 KAction* pAction = it.current();
218 pAction->removeKAccel( kaccel );
219 }
220
221 for( uint i = 0; i < d->m_docList.count(); i++ )
222 d->m_docList[i]->unplugShortcuts( kaccel );
223*/
224
225}
226
227/*void KActionCollection::addWidget( QWidget* w )
228{
229 if( !d->m_bOneKAccelOnly ) {
230 kdDebug(129) << "KActionCollection::addWidget( " << w << " ): this = " << this << endl;
231 for( uint i = 0; i < d->m_widgetList.count(); i++ ) {
232 if( d->m_widgetList[i] == w ) {
233 d->m_iWidgetCurrent = i;
234 return;
235 }
236 }
237 d->m_iWidgetCurrent = d->m_widgetList.count();
238 d->m_widgetList.append( w );
239 d->m_kaccelList.append( new KAccel( w, this, "KActionCollection-KAccel" ) );
240 }
241}
242
243void KActionCollection::removeWidget( QWidget* w )
244{
245 if( !d->m_bOneKAccelOnly ) {
246 kdDebug(129) << "KActionCollection::removeWidget( " << w << " ): this = " << this << endl;
247 for( uint i = 0; i < d->m_widgetList.count(); i++ ) {
248 if( d->m_widgetList[i] == w ) {
249 // Remove KAccel object from children.
250 KAccel* pKAccel = d->m_kaccelList[i];
251 for ( QAsciiDictIterator<KAction> it( d->m_actionDict ); it.current(); ++it ) {
252 KAction* pAction = it.current();
253 if ( pAction->m_parentCollection == this ) {
254 pAction->removeKAccel( pKAccel );
255 }
256 }
257 delete pKAccel;
258
259 d->m_widgetList.remove( d->m_widgetList.at( i ) );
260 d->m_kaccelList.remove( d->m_kaccelList.at( i ) );
261
262 if( d->m_iWidgetCurrent == (int)i )
263 d->m_iWidgetCurrent = -1;
264 else if( d->m_iWidgetCurrent > (int)i )
265 d->m_iWidgetCurrent--;
266 return;
267 }
268 }
269 kdWarning(129) << "KActionCollection::removeWidget( " << w << " ): widget not in list." << endl;
270 }
271}
272
273bool KActionCollection::ownsKAccel() const
274{
275 return d->m_bOneKAccelOnly;
276}
277
278uint KActionCollection::widgetCount() const
279{
280 return d->m_widgetList.count();
281}
282
283const KAccel* KActionCollection::widgetKAccel( uint i ) const
284{
285 return d->m_kaccelList[i];
286}*/
287
288//US we are using no accelerators so far. So just setup an empty implementation.
289KAccel* KActionCollection::kaccel()
290{
291 //if( d->m_kaccelList.count() > 0 )
292 // return d->m_kaccelList[d->m_iWidgetCurrent];
293 //else
294 // return 0;
295//US return d->m_kaccel;
296 return 0;
297}
298
299//US we are using no accelerators so far. So just setup an empty implementation.
300const KAccel* KActionCollection::kaccel() const
301{
302 //if( d->m_kaccelList.count() > 0 )
303 // return d->m_kaccelList[d->m_iWidgetCurrent];
304 //else
305 // return 0;
306 //USreturn d->m_kaccel;
307 return 0;
308}
309
310/*void KActionCollection::findMainWindow( QWidget *w )
311{
312 // Note: topLevelWidget() stops too early, we can't use it.
313 QWidget * tl = w;
314 while ( tl->parentWidget() ) // lookup parent and store
315 tl = tl->parentWidget();
316
317 KMainWindow * mw = dynamic_cast<KMainWindow *>(tl); // try to see if it's a kmainwindow
318 if (mw)
319 d->m_mainwindow = mw;
320 else
321 kdDebug(129) << "KAction::plugMainWindowAccel: Toplevel widget isn't a KMainWindow, can't plug accel. " << tl << endl;
322}*/
323
324void KActionCollection::_insert( KAction* action )
325{
326 char unnamed_name[100];
327 const char *name = action->name();
328 if( qstrcmp( name, "unnamed" ) == 0 )
329 {
330 sprintf(unnamed_name, "unnamed-%p", (void *)action);
331 name = unnamed_name;
332 }
333 KAction *a = d->m_actionDict[ name ];
334 if ( a == action )
335 return;
336
337 d->m_actionDict.insert( name, action );
338
339 emit inserted( action );
340}
341
342void KActionCollection::_remove( KAction* action )
343{
344 delete _take( action );
345}
346
347KAction* KActionCollection::_take( KAction* action )
348{
349 char unnamed_name[100];
350 const char *name = action->name();
351 if( qstrcmp( name, "unnamed" ) == 0 )
352 {
353 sprintf(unnamed_name, "unnamed-%p", (void *) action);
354 name = unnamed_name;
355 }
356
357 KAction *a = d->m_actionDict.take( name );
358 if ( !a || a != action )
359 return 0;
360
361 emit removed( action );
362 return a;
363}
364
365void KActionCollection::_clear()
366{
367 QAsciiDictIterator<KAction> it( d->m_actionDict );
368 while ( it.current() )
369 _remove( it.current() );
370}
371
372void KActionCollection::insert( KAction* action ) { _insert( action ); }
373void KActionCollection::remove( KAction* action ) { _remove( action ); }
374KAction* KActionCollection::take( KAction* action ) { return _take( action ); }
375void KActionCollection::clear() { _clear(); }
376KAccel* KActionCollection::accel() { return kaccel(); }
377const KAccel* KActionCollection::accel() const { return kaccel(); }
378KAccel* KActionCollection::builderKAccel() const { return d->m_builderKAccel; }
379
380KAction* KActionCollection::action( const char* name, const char* classname ) const
381{
382 KAction* pAction = 0;
383
384 if ( !classname && name )
385 pAction = d->m_actionDict[ name ];
386
387 else {
388 QAsciiDictIterator<KAction> it( d->m_actionDict );
389 for( ; it.current(); ++it )
390 {
391 if ( ( !name || strcmp( it.current()->name(), name ) == 0 ) &&
392 ( !classname || strcmp( it.current()->className(), classname ) == 0 ) ) {
393 pAction = it.current();
394 break;
395 }
396 }
397 }
398
399 if( !pAction ) {
400 for( uint i = 0; i < d->m_docList.count() && !pAction; i++ )
401 pAction = d->m_docList[i]->action( name, classname );
402 }
403
404 return pAction;
405}
406
407KAction* KActionCollection::action( int index ) const
408{
409 QAsciiDictIterator<KAction> it( d->m_actionDict );
410 it += index;
411 return it.current();
412// return d->m_actions.at( index );
413}
414/*US
415bool KActionCollection::readShortcutSettings( const QString& sConfigGroup, KConfigBase* pConfig )
416{
417 return KActionShortcutList(this).readSettings( sConfigGroup, pConfig );
418}
419
420bool KActionCollection::writeShortcutSettings( const QString& sConfigGroup, KConfigBase* pConfig ) const
421{
422 return KActionShortcutList((KActionCollection*)this).writeSettings( sConfigGroup, pConfig );
423}
424*/
425uint KActionCollection::count() const
426{
427 return d->m_actionDict.count();
428}
429
430QStringList KActionCollection::groups() const
431{
432 QStringList lst;
433
434 QAsciiDictIterator<KAction> it( d->m_actionDict );
435 for( ; it.current(); ++it )
436 if ( !it.current()->group().isEmpty() && !lst.contains( it.current()->group() ) )
437 lst.append( it.current()->group() );
438
439 return lst;
440}
441
442KActionPtrList KActionCollection::actions( const QString& group ) const
443{
444 KActionPtrList lst;
445
446 QAsciiDictIterator<KAction> it( d->m_actionDict );
447 for( ; it.current(); ++it )
448 if ( it.current()->group() == group )
449 lst.append( it.current() );
450 else if ( it.current()->group().isEmpty() && group.isEmpty() )
451 lst.append( it.current() );
452
453 return lst;
454}
455
456KActionPtrList KActionCollection::actions() const
457{
458 KActionPtrList lst;
459
460 QAsciiDictIterator<KAction> it( d->m_actionDict );
461 for( ; it.current(); ++it )
462 lst.append( it.current() );
463
464 return lst;
465}
466
467/*US we have no instance object. Use KGlobal instead
468void KActionCollection::setInstance( KInstance *instance )
469{
470 if ( instance )
471 d->m_instance = instance;
472qDebug("KActionCollection::setInstance has to be fixed");
473 else
474 d->m_instance = KGlobal::instance();
475}
476
477KInstance *KActionCollection::instance() const
478{
479 return d->m_instance;
480}
481*/
482
483/*US we have no XML facility in microkde
484void KActionCollection::setXMLFile( const QString& sXMLFile )
485{
486 d->m_sXMLFile = sXMLFile;
487}
488
489const QString& KActionCollection::xmlFile() const
490{
491 return d->m_sXMLFile;
492}
493*/
494
495void KActionCollection::setHighlightingEnabled( bool enable )
496{
497 d->m_highlight = enable;
498}
499
500bool KActionCollection::highlightingEnabled() const
501{
502 return d->m_highlight;
503}
504
505void KActionCollection::connectHighlight( QWidget *container, KAction *action )
506{
507 if ( !d->m_highlight )
508 return;
509
510 QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ container ];
511
512 if ( !actionList )
513 {
514 actionList = new QPtrList<KAction>;
515
516 if ( container->inherits( "QPopupMenu" ) )
517 {
518 connect( container, SIGNAL( highlighted( int ) ),
519 this, SLOT( slotMenuItemHighlighted( int ) ) );
520 connect( container, SIGNAL( aboutToHide() ),
521 this, SLOT( slotMenuAboutToHide() ) );
522 }
523//US else if ( container->inherits( "KToolBar" ) )
524 else if ( container->inherits( "QToolBar" ) )
525 {
526 connect( container, SIGNAL( highlighted( int, bool ) ),
527 this, SLOT( slotToolBarButtonHighlighted( int, bool ) ) );
528 }
529
530 connect( container, SIGNAL( destroyed() ),
531 this, SLOT( slotDestroyed() ) );
532
533 d->m_dctHighlightContainers.insert( container, actionList );
534 }
535
536 actionList->append( action );
537}
538
539void KActionCollection::disconnectHighlight( QWidget *container, KAction *action )
540{
541 if ( !d->m_highlight )
542 return;
543
544 QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ container ];
545
546 if ( !actionList )
547 return;
548
549 actionList->removeRef( action );
550
551 if ( actionList->count() == 0 )
552 d->m_dctHighlightContainers.remove( container );
553}
554
555void KActionCollection::slotMenuItemHighlighted( int id )
556{
557 if ( !d->m_highlight )
558 return;
559
560 if ( d->m_currentHighlightAction )
561 emit actionHighlighted( d->m_currentHighlightAction, false );
562
563 QWidget *container = static_cast<QWidget *>( const_cast<QObject *>( sender() ) );
564
565 d->m_currentHighlightAction = findAction( container, id );
566
567 if ( !d->m_currentHighlightAction )
568 {
569 if ( !d->m_statusCleared )
570 emit clearStatusText();
571 d->m_statusCleared = true;
572 return;
573 }
574
575 d->m_statusCleared = false;
576 emit actionHighlighted( d->m_currentHighlightAction );
577 emit actionHighlighted( d->m_currentHighlightAction, true );
578 emit actionStatusText( d->m_currentHighlightAction->toolTip() );
579}
580
581void KActionCollection::slotMenuAboutToHide()
582{
583 if ( d->m_currentHighlightAction )
584 emit actionHighlighted( d->m_currentHighlightAction, false );
585 d->m_currentHighlightAction = 0;
586
587 if ( !d->m_statusCleared )
588 emit clearStatusText();
589 d->m_statusCleared = true;
590}
591
592void KActionCollection::slotToolBarButtonHighlighted( int id, bool highlight )
593{
594 if ( !d->m_highlight )
595 return;
596
597 QWidget *container = static_cast<QWidget *>( const_cast<QObject *>( sender() ) );
598
599 KAction *action = findAction( container, id );
600
601 if ( !action )
602 {
603 d->m_currentHighlightAction = 0;
604 // use tooltip groups for toolbar status text stuff instead (Simon)
605// emit clearStatusText();
606 return;
607 }
608
609 emit actionHighlighted( action, highlight );
610
611 if ( highlight )
612 d->m_currentHighlightAction = action;
613 else
614 {
615 d->m_currentHighlightAction = 0;
616// emit clearStatusText();
617 }
618}
619
620void KActionCollection::slotDestroyed()
621{
622 d->m_dctHighlightContainers.remove( reinterpret_cast<void *>( const_cast<QObject *>(sender()) ) );
623}
624
625KAction *KActionCollection::findAction( QWidget *container, int id )
626{
627 QPtrList<KAction> *actionList = d->m_dctHighlightContainers[ reinterpret_cast<void *>( container ) ];
628
629 if ( !actionList )
630 return 0;
631
632 QPtrListIterator<KAction> it( *actionList );
633 for (; it.current(); ++it )
634 if ( it.current()->isPlugged( container, id ) )
635 return it.current();
636
637 return 0;
638}
639
640// KDE 4: remove
641KActionCollection KActionCollection::operator+(const KActionCollection &c ) const
642{
643 kdWarning(129) << "KActionCollection::operator+(): function is severely deprecated." << endl;
644 KActionCollection ret( *this );
645
646 QValueList<KAction *> actions = c.actions();
647 QValueList<KAction *>::ConstIterator it = actions.begin();
648 QValueList<KAction *>::ConstIterator end = actions.end();
649 for (; it != end; ++it )
650 ret.insert( *it );
651
652 return ret;
653}
654
655KActionCollection &KActionCollection::operator=( const KActionCollection &copy )
656{
657 kdWarning(129) << "KActionCollection::operator=(): function is severely deprecated." << endl;
658 //d->m_bOneKAccelOnly = copy.d->m_bOneKAccelOnly;
659 //d->m_iWidgetCurrent = copy.d->m_iWidgetCurrent;
660 //d->m_widgetList = copy.d->m_widgetList;
661 //d->m_kaccelList = copy.d->m_kaccelList;
662 d->m_widget = copy.d->m_widget;
663 d->m_kaccel = copy.d->m_kaccel;
664 d->m_actionDict = copy.d->m_actionDict;
665//US setInstance( copy.instance() );
666 return *this;
667}
668
669KActionCollection &KActionCollection::operator+=( const KActionCollection &c )
670{
671 kdWarning(129) << "KActionCollection::operator+=(): function is severely deprecated." << endl;
672 QAsciiDictIterator<KAction> it(c.d->m_actionDict);
673 for ( ; it.current(); ++it )
674 insert( it.current() );
675
676 return *this;
677}
678// KDE 4: remove end
679
680//---------------------------------------------------------------------
681// KActionShortcutList
682//---------------------------------------------------------------------
683/*US
684KActionShortcutList::KActionShortcutList( KActionCollection* pColl )
685: m_actions( *pColl )
686 { }
687KActionShortcutList::~KActionShortcutList()
688 { }
689uint KActionShortcutList::count() const
690 { return m_actions.count(); }
691QString KActionShortcutList::name( uint i ) const
692 { return m_actions.action(i)->name(); }
693QString KActionShortcutList::label( uint i ) const
694 { return m_actions.action(i)->text(); }
695QString KActionShortcutList::whatsThis( uint i ) const
696 { return m_actions.action(i)->whatsThis(); }
697const KShortcut& KActionShortcutList::shortcut( uint i ) const
698 { return m_actions.action(i)->shortcut(); }
699const KShortcut& KActionShortcutList::shortcutDefault( uint i ) const
700 { return m_actions.action(i)->shortcutDefault(); }
701bool KActionShortcutList::isConfigurable( uint i ) const
702 { return m_actions.action(i)->isShortcutConfigurable(); }
703bool KActionShortcutList::setShortcut( uint i, const KShortcut& cut )
704 { return m_actions.action(i)->setShortcut( cut ); }
705const KInstance* KActionShortcutList::instance() const
706 { return m_actions.instance(); }
707QVariant KActionShortcutList::getOther( Other, uint ) const
708 { return QVariant(); }
709bool KActionShortcutList::setOther( Other, uint, QVariant )
710 { return false; }
711
712bool KActionShortcutList::save() const
713{
714 kdDebug(129) << "KActionShortcutList::save(): xmlFile = " << m_actions.xmlFile() << endl;
715
716 if( m_actions.xmlFile().isEmpty() )
717 return writeSettings();
718
719 QString tagActionProp = QString::fromLatin1("ActionProperties");
720 QString tagAction = QString::fromLatin1("Action");
721 QString attrName = QString::fromLatin1("name");
722 QString attrShortcut = QString::fromLatin1("shortcut");
723 QString attrAccel = QString::fromLatin1("accel"); // Depricated attribute
724
725 // Read XML file
726 QString sXml( KXMLGUIFactory::readConfigFile( m_actions.xmlFile(), false, instance() ) );
727 QDomDocument doc;
728 doc.setContent( sXml );
729
730 // Process XML data
731
732 // first, lets see if we have existing properties
733 QDomElement elem;
734 QDomElement it = doc.documentElement();
735 // KXMLGUIFactory::removeDOMComments( it ); <-- What was this for? --ellis
736 it = it.firstChild().toElement();
737 for( ; !it.isNull(); it = it.nextSibling().toElement() ) {
738 if( it.tagName() == tagActionProp ) {
739 elem = it;
740 break;
741 }
742 }
743
744 // if there was none, create one
745 if( elem.isNull() ) {
746 elem = doc.createElement( tagActionProp );
747 doc.documentElement().appendChild( elem );
748 }
749
750 // now, iterate through our actions
751 uint nSize = count();
752 for( uint i = 0; i < nSize; i++ ) {
753 const QString& sName = name(i);
754
755 bool bSameAsDefault = (shortcut(i) == shortcutDefault(i));
756 //kdDebug(129) << "name = " << sName << " shortcut = " << shortcut(i).toStringInternal() << " def = " << shortcutDefault(i).toStringInternal() << endl;
757
758 // now see if this element already exists
759 QDomElement act_elem;
760 for( it = elem.firstChild().toElement(); !it.isNull(); it = it.nextSibling().toElement() ) {
761 if( it.attribute( attrName ) == sName ) {
762 act_elem = it;
763 break;
764 }
765 }
766
767 // nope, create a new one
768 if( act_elem.isNull() ) {
769 if( bSameAsDefault )
770 continue;
771 //kdDebug(129) << "\tnode doesn't exist." << endl;
772 act_elem = doc.createElement( tagAction );
773 act_elem.setAttribute( attrName, sName );
774 }
775
776 act_elem.removeAttribute( attrAccel );
777 if( bSameAsDefault ) {
778 act_elem.removeAttribute( attrShortcut );
779 //kdDebug(129) << "act_elem.attributes().count() = " << act_elem.attributes().count() << endl;
780 if( act_elem.attributes().count() == 1 )
781 elem.removeChild( act_elem );
782 } else {
783 act_elem.setAttribute( attrShortcut, shortcut(i).toStringInternal() );
784 elem.appendChild( act_elem );
785 }
786 }
787
788 // Write back to XML file
789 return KXMLGUIFactory::saveConfigFile( doc, m_actions.xmlFile(), instance() );
790}
791
792//---------------------------------------------------------------------
793// KActionPtrShortcutList
794//---------------------------------------------------------------------
795
796KActionPtrShortcutList::KActionPtrShortcutList( KActionPtrList& list )
797: m_actions( list )
798 { }
799KActionPtrShortcutList::~KActionPtrShortcutList()
800 { }
801uint KActionPtrShortcutList::count() const
802 { return m_actions.count(); }
803QString KActionPtrShortcutList::name( uint i ) const
804 { return m_actions[i]->name(); }
805QString KActionPtrShortcutList::label( uint i ) const
806 { return m_actions[i]->text(); }
807QString KActionPtrShortcutList::whatsThis( uint i ) const
808 { return m_actions[i]->whatsThis(); }
809const KShortcut& KActionPtrShortcutList::shortcut( uint i ) const
810 { return m_actions[i]->shortcut(); }
811const KShortcut& KActionPtrShortcutList::shortcutDefault( uint i ) const
812 { return m_actions[i]->shortcutDefault(); }
813bool KActionPtrShortcutList::isConfigurable( uint i ) const
814 { return m_actions[i]->isShortcutConfigurable(); }
815bool KActionPtrShortcutList::setShortcut( uint i, const KShortcut& cut )
816 { return m_actions[i]->setShortcut( cut ); }
817QVariant KActionPtrShortcutList::getOther( Other, uint ) const
818 { return QVariant(); }
819bool KActionPtrShortcutList::setOther( Other, uint, QVariant )
820 { return false; }
821bool KActionPtrShortcutList::save() const
822 { return false; }
823
824void KActionShortcutList::virtual_hook( int id, void* data )
825{ KShortcutList::virtual_hook( id, data ); }
826
827void KActionPtrShortcutList::virtual_hook( int id, void* data )
828{ KShortcutList::virtual_hook( id, data ); }
829*/
830
831void KActionCollection::virtual_hook( int, void* )
832{ /*BASE::virtual_hook( id, data );*/ }
833
834/* vim: et sw=2 ts=2
835 */
836
837/*US
838#include "kactioncollection.moc"
839*/
diff --git a/microkde/kdeui/kactioncollection.h b/microkde/kdeui/kactioncollection.h
new file mode 100644
index 0000000..b9466d0
--- a/dev/null
+++ b/microkde/kdeui/kactioncollection.h
@@ -0,0 +1,329 @@
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
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License version 2 as published by the Free Software Foundation.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.
23*/
24//$Id$
25
26#ifndef __kactioncollection_h__
27#define __kactioncollection_h__
28
29#include <kaction.h>
30
31//US #include <qkeysequence.h>
32#include <qobject.h>
33//US#include <qvaluelist.h>
34//US#include <qguardedptr.h>
35//US #include <kguiitem.h>
36//US#include <kshortcut.h>
37//US#include <kstdaction.h>
38//US#include <kicontheme.h>
39
40//USclass QMenuBar;
41//USclass QPopupMenu;
42//USclass QComboBox;
43//USclass QPoint;
44//USclass QIconSet;
45//USclass QString;
46//USclass KToolBar;
47
48//USclass KAccel;
49//USclass KAccelActions;
50//USclass KConfig;
51//USclass KConfigBase;
52//USclass KURL;
53//USclass KInstance;
54//USclass KToolBar;
55//USclass KActionCollection;
56//USclass KPopupMenu;
57//USclass KMainWindow;
58
59//US added inclidefiles
60class QWidget;
61
62
63typedef QValueList<KAction *> KActionPtrList;
64
65/**
66 * A managed set of KAction objects.
67 */
68class KActionCollection : public QObject
69{
70 friend class KAction;
71 friend class KXMLGUIClient;
72
73 Q_OBJECT
74public:
75 KActionCollection( QWidget *parent, const char *name = 0/*US , KInstance *instance = 0 */);
76 /**
77 * Use this constructor if you want the collection's actions to restrict
78 * their accelerator keys to @p watch rather than the @p parent. If
79 * you don't require shortcuts, you can pass a null to the @p watch parameter.
80 */
81 KActionCollection( QWidget *watch, QObject* parent, const char *name = 0/*US, KInstance *instance = 0 */);
82 KActionCollection( const KActionCollection &copy );
83 virtual ~KActionCollection();
84
85 /**
86 * This sets the widget to which the keyboard shortcuts should be attached.
87 * You only need to call this if a null pointer was passed in the constructor.
88 */
89 virtual void setWidget( QWidget *widget );
90
91 /**
92 * This indicates whether new actions which are created in this collection
93 * should have their keyboard shortcuts automatically connected on
94 * construction. Set to 'false' if you will be loading XML-based settings.
95 * This is automatically done by KParts. The default is 'true'.
96 * @see isAutoConnectShortcuts()
97 */
98 void setAutoConnectShortcuts( bool );
99
100 /**
101 * This indicates whether new actions which are created in this collection
102 * have their keyboard shortcuts automatically connected on
103 * construction.
104 * @see setAutoConnectShortcuts()
105 */
106 bool isAutoConnectShortcuts();
107
108 /**
109 * This sets the default shortcut scope for new actions created in this
110 * collection. The default is ScopeUnspecified. Ideally the default
111 * would have been ScopeWidget, but that would cause some backwards
112 * compatibility problems.
113 */
114 //void setDefaultScope( KAction::Scope );
115
116 /**
117 * Doc/View model. This lets you add the action collection of a document
118 * to a view's action collection.
119 */
120 bool addDocCollection( KActionCollection* pDoc );
121
122 /** Returns the number of widgets which this collection is associated with. */
123 //uint widgetCount() const;
124
125 /**
126 * Returns true if the collection has its own KAccel object. This will be
127 * the case if it was constructed with a valid widget ptr or if setWidget()
128 * was called.
129 */
130 //bool ownsKAccel() const;
131
132 /** @deprecated Deprecated because of ambiguous name. Use kaccel() */
133 virtual KAccel* accel();
134 /** @deprecated Deprecated because of ambiguous name. Use kaccel() */
135 virtual const KAccel* accel() const;
136
137 /** Returns the KAccel object of the most recently set widget. */
138 KAccel* kaccel();
139 /** Returns the KAccel object of the most recently set widget. Const version for convenience. */
140 const KAccel* kaccel() const;
141
142 /** @internal, for KAction::kaccelCurrent() */
143 KAccel* builderKAccel() const;
144 /** Returns the KAccel object associated with widget #. */
145 //KAccel* widgetKAccel( uint i );
146 //const KAccel* widgetKAccel( uint i ) const;
147
148 /** Returns the number of actions in the collection */
149 virtual uint count() const;
150 bool isEmpty() const { return count() == 0; }
151 /**
152 * Return the KAction* at position "index" in the action collection.
153 * @see count()
154 */
155 virtual KAction* action( int index ) const;
156 /**
157 * Find an action (optionally, of a given subclass of KAction) in the action collection.
158 * @param name Name of the KAction.
159 * @param classname Name of the KAction subclass.
160 * @return A pointer to the first KAction in the collection which matches the parameters or
161 * null if nothing matches.
162 */
163 virtual KAction* action( const char* name, const char* classname = 0 ) const;
164
165 /** Returns a list of all the groups of all the KActions in this action collection.
166 * @see KAction::group()
167 * @see KAction::setGroup()
168 */
169 virtual QStringList groups() const;
170 /**
171 * Returns the list of actions in a particular managed by this action collection.
172 * @param group The name of the group.
173 */
174 virtual KActionPtrList actions( const QString& group ) const;
175 /** Returns the list of actions managed by this action collection. */
176 virtual KActionPtrList actions() const;
177
178 /**
179 * Used for reading shortcut configuration from a non-XML rc file.
180 */
181//US bool readShortcutSettings( const QString& sConfigGroup = QString::null, KConfigBase* pConfig = 0 );
182 /**
183 * Used for writing shortcut configuration to a non-XML rc file.
184 */
185//US bool writeShortcutSettings( const QString& sConfigGroup = QString::null, KConfigBase* pConfig = 0 ) const;
186
187//US void setInstance( KInstance *instance );
188 /** The instance with which this class is associated. */
189//US KInstance *instance() const;
190
191 /**
192 * Use this to tell the KActionCollection what rc file its configuration
193 * is stored in.
194 */
195 void setXMLFile( const QString& );
196 /** The rc file in which the current configuration is stored. */
197 const QString& xmlFile() const;
198
199 /**
200 * Enable highlighting notification for specific KActions.
201 * @see connectHighlight()
202 * @see disconnectHighlight()
203 * @see actionHighlighted()
204 * @see actionHighlighted()
205 * @see highlightingEnabled()
206 */
207 void setHighlightingEnabled( bool enable );
208 /**
209 * Return whether highlighting notifications are enabled.
210 * @see connectHighlight()
211 * @see disconnectHighlight()
212 * @see actionHighlighted()
213 * @see setHighlightingEnabled()
214 * @see actionHighlighted()
215 */
216 bool highlightingEnabled() const;
217
218 /**
219 * Call this function if you want to receive a signal whenever a KAction is highlighted in a menu or a toolbar.
220 * @param container A container in which the KAction is plugged (must inherit QPopupMenu or KToolBar)
221 * @param action The action you are interested in
222 * @see disconnectHighlight()
223 * @see actionHighlighted()
224 * @see setHighlightingEnabled()
225 * @see highlightingEnabled()
226 * @see actionHighlighted()
227 */
228 void connectHighlight( QWidget *container, KAction *action );
229 /**
230 * Disconnect highlight notifications for a particular pair of contianer and action.
231 * @param container A container in which the KAction is plugged (must inherit QPopupMenu or KToolBar)
232 * @param action The action you are interested in
233 * @see connectHighlight()
234 * @see actionHighlighted()
235 * @see setHighlightingEnabled()
236 * @see highlightingEnabled()
237 * @see actionHighlighted()
238 */
239 void disconnectHighlight( QWidget *container, KAction *action );
240
241signals:
242 void inserted( KAction* );
243 void removed( KAction* );
244
245 /** Emitted when "action" is highlighted.
246 * @see connectHighlight()
247 * @see disconnectHighlight()
248 * @see actionHighlighted()
249 * @see setHighlightingEnabled()
250 * @see highlightingEnabled()
251 */
252 void actionHighlighted( KAction *action );
253 /** Emitted when "action" is highlighed or loses highlighting.
254 * @see connectHighlight()
255 * @see disconnectHighlight()
256 * @see actionHighlighted()
257 * @see setHighlightingEnabled()
258 * @see highlightingEnabled()
259 */
260 void actionHighlighted( KAction *action, bool highlight );
261
262 void actionStatusText( const QString &text );
263 void clearStatusText();
264
265private:
266 /**
267 * @internal Only to be called by KXMLGUIFactory::addClient().
268 * When actions are being connected, KAction needs to know what
269 * widget it should connect widget-scope actions to, and what
270 * main window it should connect
271 */
272 void beginXMLPlug( QWidget *widget );
273 void endXMLPlug();
274 /** @internal. Only to be called by KXMLGUIFactory::removeClient() */
275 void prepareXMLUnplug();
276 void unplugShortcuts( KAccel* kaccel );
277
278 void _clear();
279 void _insert( KAction* );
280 void _remove( KAction* );
281 KAction* _take( KAction* );
282
283private slots:
284 void slotMenuItemHighlighted( int id );
285 void slotToolBarButtonHighlighted( int id, bool highlight );
286 void slotMenuAboutToHide();
287 void slotDestroyed();
288
289private:
290 KAction *findAction( QWidget *container, int id );
291
292#ifndef KDE_NO_COMPAT
293public:
294 KActionCollection( QObject *parent, const char *name = 0 /*US, KInstance *instance = 0 */);
295
296 void insert( KAction* );
297
298 /**
299 * @deprecated Removes an action from the collection and deletes it.
300 * @param action The KAction to remove.
301 */
302 void remove( KAction* action );
303
304 /**
305 * @deprecated Removes an action from the collection.
306 * @return NULL if not found else returns action.
307 * @param action the KAction to remove.
308 */
309 KAction* take( KAction* action );
310
311 KActionCollection operator+ ( const KActionCollection& ) const;
312 KActionCollection& operator= ( const KActionCollection& );
313 KActionCollection& operator+= ( const KActionCollection& );
314
315public slots:
316 /**
317 * Clears the entire actionCollection, deleting all actions.
318 * @see #remove
319 */
320 void clear();
321#endif // !KDE_NO_COMPAT
322protected:
323 virtual void virtual_hook( int id, void* data );
324private:
325 class KActionCollectionPrivate;
326 KActionCollectionPrivate *d;
327};
328
329#endif
diff --git a/microkde/kdeui/kbuttonbox.cpp b/microkde/kdeui/kbuttonbox.cpp
new file mode 100644
index 0000000..16206e8
--- a/dev/null
+++ b/microkde/kdeui/kbuttonbox.cpp
@@ -0,0 +1,300 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Mario Weilguni (mweilguni@sime.com)
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., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18*/
19
20/*
21 * KButtonBox class
22 *
23 * A container widget for buttons. Uses Qt layout control to place the
24 * buttons, can handle both vertical and horizontal button placement.
25*
26 * HISTORY
27 *
28 * 03/08/2000 Mario Weilguni <mweilguni@kde.org>
29 * Removed all those long outdated Motif stuff
30 * Improved and clarified some if conditions (easier to understand)
31 *
32 * 11/13/98 Reginald Stadlbauer <reggie@kde.org>
33 * Now in Qt 1.4x motif default buttons have no extra width/height anymore.
34 * So the KButtonBox doesn't add this width/height to default buttons anymore
35 * which makes the buttons look better.
36 *
37 * 01/17/98 Mario Weilguni <mweilguni@sime.com>
38 * Fixed a bug in sizeHint()
39 * Improved the handling of Motif default buttons
40 *
41 * 01/09/98 Mario Weilguni <mweilguni@sime.com>
42 * The last button was to far right away from the right/bottom border.
43 * Fixed this. Removed old code. Buttons get now a minimum width.
44 * Programmer may now override minimum width and height of a button.
45 *
46 */
47
48//US #include "kbuttonbox.moc"
49
50#include <kbuttonbox.h>
51#include <qpushbutton.h>
52#include <qptrlist.h>
53#include <assert.h>
54
55#define minButtonWidth 50
56
57class KButtonBox::Item {
58public:
59 QPushButton *button;
60 bool noexpand;
61 unsigned short stretch;
62 unsigned short actual_size;
63};
64
65template class QPtrList<KButtonBox::Item>;
66
67class KButtonBoxPrivate {
68public:
69 unsigned short border;
70 unsigned short autoborder;
71 unsigned short orientation;
72 bool activated;
73 QPtrList<KButtonBox::Item> buttons;
74};
75
76KButtonBox::KButtonBox(QWidget *parent, Orientation _orientation,
77 int border, int autoborder)
78 : QWidget(parent)
79{
80 data = new KButtonBoxPrivate;
81 assert(data != 0);
82
83 data->orientation = _orientation;
84 data->border = border;
85 data->autoborder = autoborder < 0 ? border : autoborder;
86 data->buttons.setAutoDelete(TRUE);
87}
88
89KButtonBox::~KButtonBox() {
90 delete data;
91}
92
93QPushButton *KButtonBox::addButton(const QString& text, bool noexpand) {
94 Item *item = new Item;
95
96 item->button = new QPushButton(text, this);
97 item->noexpand = noexpand;
98 data->buttons.append(item);
99 item->button->adjustSize();
100
101 return item->button;
102}
103
104 QPushButton *
105KButtonBox::addButton(
106 const QString & text,
107 QObject * receiver,
108 const char * slot,
109 bool noexpand
110)
111{
112 QPushButton * pb = addButton(text, noexpand);
113
114 if ((0 != receiver) && (0 != slot))
115 QObject::connect(pb, SIGNAL(clicked()), receiver, slot);
116
117 return pb;
118}
119
120
121void KButtonBox::addStretch(int scale) {
122 if(scale > 0) {
123 Item *item = new Item;
124 item->button = 0;
125 item->noexpand = FALSE;
126 item->stretch = scale;
127 data->buttons.append(item);
128 }
129}
130
131void KButtonBox::layout() {
132 // resize all buttons
133 QSize bs = bestButtonSize();
134
135 for(unsigned int i = 0; i < data->buttons.count(); i++) {
136 Item *item = data->buttons.at(i);
137 QPushButton *b = item->button;
138 if(b != 0) {
139 if(item->noexpand)
140 b->setFixedSize(buttonSizeHint(b));
141 else
142 b->setFixedSize(bs);
143 }
144 }
145
146 setMinimumSize(sizeHint());
147}
148
149void KButtonBox::placeButtons() {
150 unsigned int i;
151
152 if(data->orientation == Horizontal) {
153 // calculate free size and stretches
154 int fs = width() - 2 * data->border;
155 int stretch = 0;
156 for(i = 0; i < data->buttons.count(); i++) {
157 Item *item = data->buttons.at(i);
158 if(item->button != 0) {
159 fs -= item->button->width();
160
161 // Last button?
162 if(i != data->buttons.count() - 1)
163 fs -= data->autoborder;
164 } else
165 stretch +=item->stretch;
166 }
167
168 // distribute buttons
169 int x_pos = data->border;
170 for(i = 0; i < data->buttons.count(); i++) {
171 Item *item = data->buttons.at(i);
172 if(item->button != 0) {
173 QPushButton *b = item->button;
174 b->move(x_pos, (height() - b->height()) / 2);
175
176 x_pos += b->width() + data->autoborder;
177 } else
178 x_pos += (int)((((double)fs) * item->stretch) / stretch);
179 }
180 } else { // VERTICAL
181 // calcualte free size and stretches
182 int fs = height() - 2 * data->border;
183 int stretch = 0;
184 for(i = 0; i < data->buttons.count(); i++) {
185 Item *item = data->buttons.at(i);
186 if(item->button != 0)
187 fs -= item->button->height() + data->autoborder;
188 else
189 stretch +=item->stretch;
190 }
191
192 // distribute buttons
193 int y_pos = data->border;
194 for(i = 0; i < data->buttons.count(); i++) {
195 Item *item = data->buttons.at(i);
196 if(item->button != 0) {
197 QPushButton *b = item->button;
198 b->move((width() - b->width()) / 2, y_pos);
199
200 y_pos += b->height() + data->autoborder;
201 } else
202 y_pos += (int)((((double)fs) * item->stretch) / stretch);
203 }
204 }
205}
206
207void KButtonBox::resizeEvent(QResizeEvent *) {
208 placeButtons();
209}
210
211QSize KButtonBox::bestButtonSize() const {
212 QSize s(0, 0);
213 unsigned int i;
214
215 // calculate optimal size
216 for(i = 0; i < data->buttons.count(); i++) {
217 KButtonBox *that = (KButtonBox*)this; // to remove the const ;(
218 Item *item = that->data->buttons.at(i);
219 QPushButton *b = item->button;
220
221 if(b != 0 && !item->noexpand) {
222 QSize bs = buttonSizeHint(b);
223
224 if(bs.width() > s.width())
225 s.setWidth(bs.width());
226 if(bs.height() > s.height())
227 s.setHeight(bs.height());
228 }
229 }
230
231 return s;
232}
233
234QSize KButtonBox::sizeHint() const {
235 unsigned int i, dw;
236
237 if(data->buttons.count() == 0)
238 return QSize(0, 0);
239 else {
240 dw = 2 * data->border;
241
242 QSize bs = bestButtonSize();
243 for(i = 0; i < data->buttons.count(); i++) {
244 KButtonBox *that = (KButtonBox*)this;
245 Item *item = that->data->buttons.at(i);
246 QPushButton *b = item->button;
247 if(b != 0) {
248 QSize s;
249 if(item->noexpand)
250 s = that->buttonSizeHint(b);
251 else
252 s = bs;
253
254 if(data->orientation == Horizontal)
255 dw += s.width();
256 else
257 dw += s.height();
258
259 if( i != data->buttons.count() - 1 )
260 dw += data->autoborder;
261 }
262 }
263
264 if(data->orientation == Horizontal)
265 return QSize(dw, bs.height() + 2 * data->border);
266 else
267 return QSize(bs.width() + 2 * data->border, dw);
268 }
269}
270
271QSizePolicy KButtonBox::sizePolicy() const
272{
273 return data->orientation == Horizontal?
274 QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) :
275 QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
276}
277
278/*
279 * Returns the best size for a button. If a button is less than
280 * minButtonWidth pixels wide, return minButtonWidth pixels
281 * as minimum width
282 */
283QSize KButtonBox::buttonSizeHint(QPushButton *b) const {
284 QSize s = b->sizeHint();
285 QSize ms = b->minimumSize();
286 if(s.width() < minButtonWidth)
287 s.setWidth(minButtonWidth);
288
289 // allows the programmer to override the settings
290 if(ms.width() > s.width())
291 s.setWidth(ms.width());
292 if(ms.height() > s.height())
293 s.setHeight(ms.height());
294
295 return s;
296}
297
298void KButtonBox::virtual_hook( int, void* )
299{ /*BASE::virtual_hook( id, data );*/ }
300
diff --git a/microkde/kdeui/kbuttonbox.h b/microkde/kdeui/kbuttonbox.h
new file mode 100644
index 0000000..1104366
--- a/dev/null
+++ b/microkde/kdeui/kbuttonbox.h
@@ -0,0 +1,139 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Mario Weilguni (mweilguni@sime.com)
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., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18*/
19
20#ifndef __KBUTTONBOX__H__
21#define __KBUTTONBOX__H__
22
23#include <qwidget.h>
24class QPushButton;
25
26class KButtonBoxPrivate;
27/**
28 * Container widget for buttons.
29 *
30 * This class uses Qt layout control to place the buttons; can handle
31 * both vertical and horizontal button placement. The default border
32 * is now @p 0 (making it easier to deal with layouts). The space
33 * between buttons is now more Motif compliant.
34 *
35 * @author Mario Weilguni <mweilguni@sime.com>
36 * @version $Id$
37 **/
38
39class KButtonBox : public QWidget
40{
41 Q_OBJECT
42
43public:
44 /**
45 * Create an empty container for buttons.
46 *
47 * If @p _orientation is @p Vertical, the buttons inserted with
48 * @ref addButton() are laid out from top to bottom, otherwise they
49 * are laid out from left to right.
50 */
51 KButtonBox(QWidget *parent, Orientation _orientation = Horizontal,
52 int border = 0, int _autoborder = 6);
53
54 /**
55 * Free private data field
56 */
57 ~KButtonBox();
58
59 /**
60 * @return The minimum size needed to fit all buttons.
61 *
62 * This size is
63 * calculated by the width/height of all buttons plus border/autoborder.
64 */
65 virtual QSize sizeHint() const;
66 /**
67 * @reimplemented
68 */
69 virtual QSizePolicy sizePolicy() const;
70 /**
71 * @reimplemented
72 */
73 virtual void resizeEvent(QResizeEvent *);
74
75 /**
76 * Add a new @ref QPushButton.
77 *
78 * @param noexpand If @p noexpand is @p false, the width
79 * of the button is adjusted to fit the other buttons (the maximum
80 * of all buttons is taken). If @p noexpand is @p true, the width of this
81 * button will be set to the minimum width needed for the given text).
82 *
83 * @return A pointer to the new button.
84 */
85 QPushButton *addButton(const QString& text, bool noexpand = FALSE);
86
87 /**
88 * Add a new @ref QPushButton.
89 *
90 * @param receiver An object to connect to.
91 * @param slot A Qt slot to connect the 'clicked()' signal to.
92 * @param noexpand If @p noexpand is @p false, the width
93 * of the button is adjusted to fit the other buttons (the maximum
94 * of all buttons is taken). If @p noexpand @p true, the width of this
95 * button will be set to the minimum width needed for the given text).
96 *
97 * @return A pointer to the new button.
98 */
99 QPushButton *addButton(const QString& text, QObject * receiver, const char * slot, bool noexpand = FALSE);
100
101 /**
102 * Add a stretch to the buttonbox.
103 *
104 * Can be used to separate buttons. That is, if you add the
105 * buttons OK and Cancel, add a stretch, and then add the button Help,
106 * the buttons OK and Cancel will be left-aligned (or top-aligned
107 * for vertical) whereas Help will be right-aligned (or
108 * bottom-aligned for vertical).
109 *
110 * @see QBoxLayout
111 */
112 void addStretch(int scale = 1);
113
114 /**
115 * This function must be called @em once after all buttons have been
116 * inserted.
117 *
118 * It will start layout control.
119 */
120 void layout();
121
122public: // as PrivateData needs Item, it has to be exported
123 class Item;
124protected:
125 /**
126 * @return the best size for a button. Checks all buttons and takes
127 * the maximum width/height.
128 */
129 QSize bestButtonSize() const;
130 void placeButtons();
131 QSize buttonSizeHint(QPushButton *) const;
132
133protected:
134 virtual void virtual_hook( int id, void* data );
135private:
136 KButtonBoxPrivate *data;
137};
138
139#endif
diff --git a/microkde/kdeui/kcmodule.cpp b/microkde/kdeui/kcmodule.cpp
new file mode 100644
index 0000000..915cd0f
--- a/dev/null
+++ b/microkde/kdeui/kcmodule.cpp
@@ -0,0 +1,106 @@
1/*
2 This file is part of the KDE libraries
3
4 Copyright (c) 2001 Michael Goffioul <goffioul@imec.be>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20
21*/
22
23#include "kcmodule.h"
24//US#include <kinstance.h>
25#include <kglobal.h>
26#include <klocale.h>
27#include <kdebug.h>
28
29class KCModulePrivate
30{
31public:
32//US KInstance *_instance;
33 QString _rootOnlyMsg;
34 bool _useRootOnlyMsg;
35 bool _hasOwnInstance;
36};
37
38KCModule::KCModule(QWidget *parent, const char *name, const QStringList &)
39 : QWidget(parent, name), _btn(Help|Default|Apply)
40{
41 kdDebug() << "KCModule " << name << endl;
42 d = new KCModulePrivate;
43 d->_useRootOnlyMsg = true;
44/*US
45 d->_instance = new KInstance(name);
46 if (name && strlen(name)) {
47 d->_instance = new KInstance(name);
48 KGlobal::locale()->insertCatalogue(name);
49 } else
50 d->_instance = new KInstance("kcmunnamed");
51*/
52 d->_hasOwnInstance = true;
53//US KGlobal::setActiveInstance(this->instance());
54}
55
56/*US
57KCModule::KCModule(KInstance *instance, QWidget *parent, const QStringList & )
58 : QWidget(parent, instance ? instance->instanceName().data() : 0), _btn(Help|Default|Apply)
59{
60 kdDebug() << "KCModule instance " << (instance ? instance->instanceName().data() : "none") << endl;
61 d = new KCModulePrivate;
62 d->_useRootOnlyMsg = true;
63 d->_instance = instance;
64 KGlobal::locale()->insertCatalogue(instance->instanceName());
65 d->_hasOwnInstance = false;
66 KGlobal::setActiveInstance(this->instance());
67}
68*/
69KCModule::~KCModule()
70{
71/*US
72 if (d->_hasOwnInstance)
73 delete d->_instance;
74*/
75 delete d;
76}
77
78void KCModule::setRootOnlyMsg(const QString& msg)
79{
80 d->_rootOnlyMsg = msg;
81}
82
83QString KCModule::rootOnlyMsg() const
84{
85 return d->_rootOnlyMsg;
86}
87
88void KCModule::setUseRootOnlyMsg(bool on)
89{
90 d->_useRootOnlyMsg = on;
91}
92
93bool KCModule::useRootOnlyMsg() const
94{
95 return d->_useRootOnlyMsg;
96}
97/*US
98KInstance *KCModule::instance() const
99{
100 return d->_instance;
101}
102*/
103void KCModule::virtual_hook( int, void* )
104{ /*BASE::virtual_hook( id, data );*/ }
105
106//US #include "kcmodule.moc"
diff --git a/microkde/kdeui/kcmodule.h b/microkde/kdeui/kcmodule.h
new file mode 100644
index 0000000..90a87c9
--- a/dev/null
+++ b/microkde/kdeui/kcmodule.h
@@ -0,0 +1,266 @@
1/*
2 This file is part of the KDE libraries
3
4 Copyright (c) 1999 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20
21*/
22#ifndef __KCMODULE_H__
23#define __KCMODULE_H__
24
25#include <qwidget.h>
26#include <qstringlist.h>
27//USclass KAboutData;
28class KCModulePrivate;
29//US class KInstance;
30
31/**
32 * The base class for control center modules.
33 *
34 * Starting from KDE 2.0, control center modules are realized as shared
35 * libraries that are loaded into the control center at runtime.
36 *
37 * The module in principle is a simple widget displaying the
38 * item to be changed. The module has a very small interface.
39 *
40 * All the necessary glue logic and the GUI bells and whistles
41 * are provided by the control center and must not concern
42 * the module author.
43 *
44 * To write a config module, you have to create a library
45 * that contains at one factory function like this:
46 *
47 * <pre>
48 * #include <kgenericfactory.h>
49 *
50 * typedef KGenericFactory<YourKCModule, QWidget> YourKCModuleFactory;
51 * K_EXPORT_COMPONENT_FACTORY( yourLibName, YourKCModuleFactory("name_of_the_po_file") );
52 * </pre>
53 *
54 * The parameter "name_of_the_po_file" has to correspond with the messages target
55 * that you created in your Makefile.am.
56 *
57 * See kdebase/kcontrol/HOWTO for more detailed documentation.
58 *
59 * @author Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
60 */
61
62class KCModule : public QWidget
63{
64 Q_OBJECT
65
66public:
67
68 /**
69 * An enumeration type for the buttons used by this module.
70 * You should only use Help, Default and Apply. The rest is obsolete.
71 *
72 * @see KCModule::buttons @see KCModule::setButtons
73 */
74 enum Button {Help=1, Default=2, Apply=16,
75 Reset=4, /* obsolete, do not use! */
76 Cancel=8, /* obsolete, do not use! */
77 Ok=32, /* obsolete, do not use! */
78 SysDefault=64 /* obsolete, do not use! */ };
79
80 /*
81 * Base class for all KControlModules.
82 * Make sure you have a QStringList argument in your
83 * implementation.
84 */
85 KCModule(QWidget *parent=0, const char *name=0, const QStringList &args=QStringList() );
86
87//US KCModule(KInstance *instance, QWidget *parent=0, const QStringList &args=QStringList() );
88
89 /*
90 * Destroys the module.
91 */
92 ~KCModule();
93
94 /**
95 * Load the configuration data into the module.
96 *
97 * The load method sets the user interface elements of the
98 * module to reflect the current settings stored in the
99 * configuration files.
100 *
101 * This method is invoked whenever the module should read its configuration
102 * (most of the times from a config file) and update the user interface.
103 * This happens when the user clicks the "Reset" button in the control
104 * center, to undo all of his changes and restore the currently valid
105 * settings. NOTE that this is not called after the modules is loaded,
106 * so you probably want to call this method in the constructor.
107 */
108 virtual void load() {};
109
110 /**
111 * Save the configuration data.
112 *
113 * The save method stores the config information as shown
114 * in the user interface in the config files.
115 *
116 * If necessary, this method also updates the running system,
117 * e.g. by restarting applications.
118 *
119 * save is called when the user clicks "Apply" or "Ok".
120 */
121 virtual void save() {};
122
123 /**
124 * Sets the configuration to sensible default values.
125 *
126 * This method is called when the user clicks the "Default"
127 * button. It should set the display to useful values.
128 */
129 virtual void defaults() {};
130
131 /**
132 * Set the configuration to system default values.
133 *
134 * This method is called when the user clicks the "System-Default"
135 * button. It should set the display to the system default values.
136 *
137 * NOTE: The default behaviour is to call defaults().
138 */
139 virtual void sysdefaults() { defaults(); };
140
141 /**
142 * Return a quick-help text.
143 *
144 * This method is called when the module is docked.
145 * The quick-help text should contain a short description of the module and
146 * links to the module's help files. You can use QML formating tags in the text.
147 *
148 * NOTE: Please make sure the quick help text gets translated (use i18n()).
149 */
150 virtual QString quickHelp() const { return QString::null; };
151
152 /**
153 * Returns a the KAboutData for this module
154 * This is generally only called for the KBugReport.
155 * Override and have it return a pointer to a constant
156 */
157//US virtual const KAboutData *aboutData() const { return 0; }
158
159 /**
160 * Indicate which buttons will be used.
161 *
162 * The return value is a value or'ed together from
163 * the Button enumeration type.
164 *
165 * @see KCModule::setButtons
166 */
167 int buttons() const { return _btn; };
168
169 /**
170 * Get the RootOnly message for this module.
171 *
172 * When the module must be run as root, or acts differently
173 * for root and a normal user, it is sometimes useful to
174 * customize the message that appears at the top of the module
175 * when used as a normal user. This function returns this
176 * customized message. If none has been set, a default message
177 * will be used.
178 *
179 * @see KCModule::setRootOnlyMsg
180 */
181 QString rootOnlyMsg() const;
182
183 /**
184 * Tell if KControl should show a RootOnly message when run as
185 * a normal user.
186 *
187 * In some cases, the module don't want a RootOnly message to
188 * appear (for example if it has already one). This function
189 * tells KControl if a RootOnly message should be shown
190 *
191 * @see KCModule::setUseRootOnlyMsg
192 */
193 bool useRootOnlyMsg() const;
194
195
196//US KInstance *instance() const;
197
198signals:
199
200 /**
201 * Indicate that the state of the modules contents has changed.
202 *
203 * This signal is emitted whenever the state of the configuration
204 * shown in the module changes. It allows the control center to
205 * keep track of unsaved changes.
206 *
207 */
208 void changed(bool state);
209
210 /**
211 * Indicate that the module's quickhelp has changed.
212 *
213 * Emit this signal whenever the module's quickhelp changes.
214 * Modules implemented as tabbed dialogs might want to implement
215 * per-tab quickhelp for example.
216 *
217 */
218 void quickHelpChanged();
219
220protected:
221
222 /**
223 * Sets the buttons to display.
224 *
225 * Help: shows a "Help" button.
226 * Default: shows a "Use Defaults" button
227 * Apply: in kcontrol this will show an "Apply" and "Reset" button
228 * in kcmshell this will show an "Ok", "Apply" and "Cancel" button
229 *
230 * If Apply is not specified, kcmshell will show a "Close" button.
231 *
232 * @see KCModule::buttons
233 */
234 void setButtons(int btn) { _btn = btn; };
235
236 /**
237 * Sets the RootOnly message.
238 *
239 * This message will be shown at the top of the module of the
240 * corresponding desktop file contains the line X-KDE-RootOnly=true.
241 * If no message is set, a default one will be used.
242 *
243 * @see KCModule::rootOnlyMessage
244 */
245 void setRootOnlyMsg(const QString& msg);
246
247 /**
248 * Change wether or not the RootOnly message should be shown.
249 *
250 * Following the value of @p on, the RootOnly message will be
251 * shown or not.
252 *
253 * @see KCModule::useRootOnlyMsg
254 */
255 void setUseRootOnlyMsg(bool on);
256
257private:
258
259 int _btn;
260protected:
261 virtual void virtual_hook( int id, void* data );
262private:
263 KCModulePrivate *d;
264};
265
266#endif
diff --git a/microkde/kdeui/kguiitem.cpp b/microkde/kdeui/kguiitem.cpp
new file mode 100644
index 0000000..828c5e6
--- a/dev/null
+++ b/microkde/kdeui/kguiitem.cpp
@@ -0,0 +1,205 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2001 Holger Freyther (freyher@yahoo.com)
3 based on ideas from Martijn and Simon
4 many thanks to Simon
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <qregexp.h>
22#include <qstring.h>
23#include <qiconset.h>
24#include <qpixmap.h>
25
26#include <assert.h>
27//US #include <kiconloader.h>
28#include <kdebug.h>
29
30#include "kguiitem.h"
31
32class KGuiItem::KGuiItemPrivate
33{
34public:
35 KGuiItemPrivate()
36 {
37 m_enabled = true;
38 m_hasIcon = false;
39 }
40
41 KGuiItemPrivate( const KGuiItemPrivate &rhs )
42 {
43 (*this ) = rhs;
44 }
45
46 KGuiItemPrivate &operator=( const KGuiItemPrivate &rhs )
47 {
48 m_text = rhs.m_text;
49 m_iconSet = rhs.m_iconSet;
50 m_iconName = rhs.m_iconName;
51 m_toolTip = rhs.m_toolTip;
52 m_whatsThis = rhs.m_whatsThis;
53 m_statusText = rhs.m_statusText;
54 m_enabled = rhs.m_enabled;
55 m_hasIcon = rhs.m_hasIcon;
56
57 return *this;
58 }
59
60 QString m_text;
61 QString m_toolTip;
62 QString m_whatsThis;
63 QString m_statusText;
64 QString m_iconName;
65 QIconSet m_iconSet;
66 bool m_hasIcon : 1;
67 bool m_enabled : 1;
68};
69
70
71KGuiItem::KGuiItem() {
72 d = new KGuiItemPrivate;
73}
74
75KGuiItem::KGuiItem( const QString &text, const QString &iconName,
76 const QString &toolTip, const QString &whatsThis )
77{
78 d = new KGuiItemPrivate;
79 d->m_text = text;
80 d->m_toolTip = toolTip;
81 d->m_whatsThis = whatsThis;
82 setIconName( iconName );
83}
84
85KGuiItem::KGuiItem( const QString &text, const QIconSet &iconSet,
86 const QString &toolTip, const QString &whatsThis )
87{
88 d = new KGuiItemPrivate;
89 d->m_text = text;
90 d->m_toolTip = toolTip;
91 d->m_whatsThis = whatsThis;
92 setIconSet( iconSet );
93}
94
95KGuiItem::KGuiItem( const KGuiItem &rhs )
96 : d( 0 )
97{
98 (*this) = rhs;
99}
100
101KGuiItem &KGuiItem::operator=( const KGuiItem &rhs ) {
102 if ( d == rhs.d )
103 return *this;
104
105 assert( rhs.d );
106
107 delete d;
108 d = new KGuiItemPrivate( *rhs.d );
109
110 return *this;
111}
112
113KGuiItem::~KGuiItem() {
114 delete d;
115}
116
117QString KGuiItem::text() const {
118 return d->m_text;
119}
120QString KGuiItem::plainText() const {
121 QString stripped( d->m_text );
122 stripped.replace( QRegExp( "&(?!&)" ), QString::null );
123
124 return stripped;
125}
126
127QIconSet KGuiItem::iconSet( KIcon::Group group, int size /*US, KInstance* instance */ ) const
128{
129 if( d->m_hasIcon )
130 {
131 if( !d->m_iconName.isEmpty())
132 {
133// some caching here would(?) come handy
134//US return instance->iconLoader()->loadIconSet( d->m_iconName, group, size );
135 return KGlobal::iconLoader()->loadIconSet( d->m_iconName);
136// here is a little problem that with delayed icon loading
137// we can't check if the icon really exists ... so what ...
138// if( set.isNull() )
139// {
140// d->m_hasIcon = false;
141// return QIconSet();
142// }
143// return set;
144 }
145 else
146 {
147 return d->m_iconSet;
148 }
149 }
150 else
151 return QIconSet();
152}
153
154QString KGuiItem::iconName() const
155{
156 return d->m_iconName;
157}
158
159QString KGuiItem::toolTip() const {
160 return d->m_toolTip;
161}
162QString KGuiItem::whatsThis() const {
163 return d->m_whatsThis;
164}
165
166bool KGuiItem::isEnabled() const
167{
168 return d->m_enabled;
169}
170
171bool KGuiItem::hasIcon() const
172{
173 return d->m_hasIcon;
174}
175
176void KGuiItem::setText( const QString &text ) {
177 d->m_text=text;
178}
179
180void KGuiItem::setIconSet( const QIconSet &iconset )
181{
182 d->m_iconSet = iconset;
183 d->m_iconName = QString::null;
184 d->m_hasIcon = !iconset.isNull();
185}
186
187void KGuiItem::setIconName( const QString &iconName )
188{
189 d->m_iconName = iconName;
190 d->m_iconSet = QIconSet();
191 d->m_hasIcon = !iconName.isEmpty();
192}
193
194void KGuiItem::setToolTip( const QString &toolTip) {
195 d->m_toolTip = toolTip;
196}
197void KGuiItem::setWhatsThis( const QString &whatsThis ) {
198 d->m_whatsThis = whatsThis;
199}
200void KGuiItem::setEnabled( bool enabled ){
201 d->m_enabled = enabled;
202}
203
204/* vim: et sw=4
205 */
diff --git a/microkde/kdeui/kguiitem.h b/microkde/kdeui/kguiitem.h
new file mode 100644
index 0000000..0079bb4
--- a/dev/null
+++ b/microkde/kdeui/kguiitem.h
@@ -0,0 +1,87 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2001 Holger Freyther (freyher@yahoo.com)
3 based on ideas from Martijn and Simon
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
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., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18
19 Many thanks to Simon tronical Hausmann
20*/
21
22#ifndef __kguiitem_h__
23#define __kguiitem_h__
24
25#include <qstring.h>
26#include <qiconset.h>
27#include <qpixmap.h>
28#include <qvaluelist.h>
29//US#include <kicontheme.h>
30#include <kglobal.h>
31
32//US added the following files
33#include <kiconloader.h>
34
35class KGuiItem
36{
37public:
38 KGuiItem();
39
40 KGuiItem( const QString &text,
41 const QString &iconName = QString::null,
42 const QString &toolTip = QString::null,
43 const QString &whatsThis = QString::null );
44
45 KGuiItem( const QString &text, const QIconSet &iconSet,
46 const QString &toolTip = QString::null,
47 const QString &whatsThis = QString::null );
48
49 KGuiItem( const KGuiItem &rhs );
50 KGuiItem &operator=( const KGuiItem &rhs );
51
52 ~KGuiItem();
53
54 QString text() const;
55 QString plainText() const;
56 QIconSet iconSet( KIcon::Group, int size = 0/*US , KInstance* instance = KGlobal::instance()*/) const;
57
58#ifndef KDE_NO_COMPAT
59 QIconSet iconSet() const { return iconSet( KIcon::Small); }
60#endif
61
62 QString iconName() const;
63 QString toolTip() const;
64 QString whatsThis() const;
65 bool isEnabled() const;
66 bool hasIcon() const;
67#ifndef KDE_NO_COMPAT
68 bool hasIconSet() const { return hasIcon(); }
69#endif
70
71 void setText( const QString &text );
72 void setIconSet( const QIconSet &iconset );
73 void setIconName( const QString &iconName );
74 void setToolTip( const QString &tooltip );
75 void setWhatsThis( const QString &whatsThis );
76 void setEnabled( bool enable );
77
78private:
79 class KGuiItemPrivate;
80 KGuiItemPrivate *d;
81};
82
83/* vim: et sw=4
84 */
85
86#endif
87
diff --git a/microkde/kdeui/kjanuswidget.cpp b/microkde/kdeui/kjanuswidget.cpp
new file mode 100644
index 0000000..7d25854
--- a/dev/null
+++ b/microkde/kdeui/kjanuswidget.cpp
@@ -0,0 +1,1176 @@
1/* This file is part of the KDE Libraries
2 * Copyright (C) 1999-2000 Espen Sand (espensa@online.no)
3 * Copyright (C) 2003 Ravikiran Rajagopal (ravi@kde.org)
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21#include <qpixmap.h>
22#include <qbitmap.h>
23#include <qlayout.h>
24#include <qlabel.h>
25#include <qwidgetstack.h>
26#include <qtabwidget.h>
27#include <qlistview.h>
28#include <qhbox.h>
29#include <qvbox.h>
30#include <qgrid.h>
31#include <qpainter.h>
32#include <qobjectlist.h>
33
34/*US
35#include <qbitmap.h>
36#include <qgrid.h>
37#include <qhbox.h>
38#include <qheader.h>
39#include <qlabel.h>
40#include <qlayout.h>
41#include <qobjectlist.h>
42#include <qpixmap.h>
43#include <qsplitter.h>
44#include <qtabwidget.h>
45#include <qvbox.h>
46#include <qwidgetstack.h>
47#include <qpainter.h>
48#include <qstyle.h>
49
50#include <kapplication.h>
51#include <klocale.h>
52#include <kglobal.h>
53#include <kglobalsettings.h>
54#include <kseparator.h>
55#include <kdebug.h>
56#include "kjanuswidget.h"
57#include <klistview.h>
58
59*/
60
61#include <kseparator.h>
62#include <kdialog.h> // Access to some static members
63#include <kdebug.h>
64#include <klistview.h>
65
66#include "kjanuswidget.h"
67
68class KJanusWidget::IconListItem : public QListBoxItem
69{
70 public:
71 IconListItem( QListBox *listbox, const QPixmap &pixmap,
72 const QString &text );
73 virtual int height( const QListBox *lb ) const;
74 virtual int width( const QListBox *lb ) const;
75 int expandMinimumWidth( int width );
76
77 protected:
78 const QPixmap &defaultPixmap();
79 void paint( QPainter *painter );
80
81 private:
82 QPixmap mPixmap;
83 int mMinimumWidth;
84};
85
86class KJanusWidget::KJanusWidgetPrivate
87{
88public:
89 KJanusWidgetPrivate() : mNextPageIndex(0) { }
90
91 int mNextPageIndex; // The next page index.
92
93 // Dictionary for multipage modes.
94 QMap<int,QWidget*> mIntToPage;
95 // Reverse dictionary. Used because showPage() may be performance critical.
96 QMap<QWidget*,int> mPageToInt;
97 // Dictionary of title string associated with page.
98 QMap<int, QString> mIntToTitle;
99};
100
101template class QPtrList<QListViewItem>;
102
103
104KJanusWidget::KJanusWidget( QWidget *parent, const char *name, int face )
105 : QWidget( parent, name ),
106 mValid(false), mPageList(0),
107 mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0),
108 mShowIconsInTreeList(false), d(0)
109{
110 QVBoxLayout *topLayout = new QVBoxLayout( this );
111 if( mFace == TreeList || mFace == IconList )
112 {
113 d = new KJanusWidgetPrivate;
114
115 QFrame *page = 0;
116 if( mFace == TreeList )
117 {
118 //US
119 qDebug("KJanusWidget::KJanusWidget TreeList not implemented yet");
120/*US
121 QSplitter *splitter = new QSplitter( this );
122 topLayout->addWidget( splitter, 10 );
123 mTreeListResizeMode = QSplitter::KeepSize;
124
125 mTreeList = new KListView( splitter );
126 mTreeList->addColumn( QString::null );
127 mTreeList->header()->hide();
128 mTreeList->setRootIsDecorated(true);
129 mTreeList->setSorting( -1 );
130 connect( mTreeList, SIGNAL(selectionChanged()), SLOT(slotShowPage()) );
131 connect( mTreeList, SIGNAL(clicked(QListViewItem *)), SLOT(slotItemClicked(QListViewItem *)));
132
133 //
134 // Page area. Title at top with a separator below and a pagestack using
135 // all available space at bottom.
136 //
137 QFrame *p = new QFrame( splitter );
138
139 QHBoxLayout *hbox = new QHBoxLayout( p, 0, 0 );
140 hbox->addSpacing( KDialog::marginHint() );
141
142 page = new QFrame( p );
143 hbox->addWidget( page, 10 );
144*/
145 }
146 else
147 {
148 QHBoxLayout *hbox = new QHBoxLayout( topLayout );
149 mIconList = new IconListBox( this );
150
151 QFont listFont( mIconList->font() );
152 listFont.setBold( true );
153 mIconList->setFont( listFont );
154
155 mIconList->verticalScrollBar()->installEventFilter( this );
156 hbox->addWidget( mIconList );
157 connect( mIconList, SIGNAL(selectionChanged()), SLOT(slotShowPage()));
158 hbox->addSpacing( KDialog::marginHint() );
159 page = new QFrame( this );
160 hbox->addWidget( page, 10 );
161 }
162
163 //
164 // Rest of page area. Title at top with a separator below and a
165 // pagestack using all available space at bottom.
166 //
167
168 QVBoxLayout *vbox = new QVBoxLayout( page, 0, KDialog::spacingHint() );
169
170 mTitleLabel = new QLabel( QString::fromLatin1("Empty page"), page, "KJanusWidgetTitleLabel" );
171 vbox->addWidget( mTitleLabel );
172
173 QFont titleFont( mTitleLabel->font() );
174 titleFont.setBold( true );
175 mTitleLabel->setFont( titleFont );
176
177 mTitleSep = new KSeparator( page );
178 mTitleSep->setFrameStyle( QFrame::HLine|QFrame::Plain );
179 vbox->addWidget( mTitleSep );
180
181 mPageStack = new QWidgetStack( page );
182 connect(mPageStack, SIGNAL(aboutToShow(QWidget *)),
183 SIGNAL(aboutToShowPage(QWidget *)));
184 vbox->addWidget( mPageStack, 10 );
185 }
186 else if( mFace == Tabbed )
187 {
188 d = new KJanusWidgetPrivate;
189
190 mTabControl = new QTabWidget( this );
191 mTabControl->setMargin (KDialog::marginHint());
192 topLayout->addWidget( mTabControl, 10 );
193 }
194 else if( mFace == Swallow )
195 {
196 mSwallowPage = new QWidget( this );
197 topLayout->addWidget( mSwallowPage, 10 );
198 }
199 else
200 {
201 mFace = Plain;
202 mPlainPage = new QFrame( this );
203 topLayout->addWidget( mPlainPage, 10 );
204 }
205/*US
206 if ( kapp )
207 connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()));
208*/
209 mValid = true;
210 setSwallowedWidget(0); // Set default size if 'mFace' is Swallow.
211}
212
213
214KJanusWidget::~KJanusWidget()
215{
216
217/*US the destroyed signal caused a segmentation fault while closing the dialog and destructing
218 all pages. Why not just remove all pages in the destructor??
219*/
220// LR we have all subwidgets with parent-child relation
221// LR we do not need to delete here anything by the private class
222/*
223 if( mFace == Tabbed )
224 {
225 QMap<QWidget*,int>::Iterator it;
226 for (it = d->mPageToInt.begin(); it != d->mPageToInt.end(); ++it) {
227 QObject*page = (QObject*)it.key();
228 pageGone(page);
229 }
230 }
231 else
232 qDebug("KJanusWidget::~KJanusWidget so far ");
233*/
234//US end
235
236 delete d;
237
238
239}
240
241
242bool KJanusWidget::isValid() const
243{
244 return( mValid );
245}
246
247
248QFrame *KJanusWidget::plainPage()
249{
250 return( mPlainPage );
251}
252
253
254int KJanusWidget::face() const
255{
256 return( mFace );
257}
258
259QWidget *KJanusWidget::FindParent()
260{
261 if( mFace == Tabbed ) {
262 return mTabControl;
263 }
264 else {
265 return this;
266 }
267}
268
269QFrame *KJanusWidget::addPage( const QStringList &items, const QString &header,
270 const QPixmap &pixmap )
271{
272 if( mValid == false )
273 {
274 kdDebug() << "addPage: Invalid object" << endl;
275 return( 0 );
276 }
277
278 QFrame *page = new QFrame( FindParent(), "page" );
279 addPageWidget( page, items, header, pixmap );
280
281 return page;
282}
283
284void KJanusWidget::pageGone( QObject *obj )
285{
286// QObject* obj = (QObject*)sender();
287 removePage( static_cast<QWidget*>( obj ) );
288}
289
290void KJanusWidget::slotReopen( QListViewItem * item )
291{
292 if( item )
293 item->setOpen( true );
294}
295
296QFrame *KJanusWidget::addPage( const QString &itemName, const QString &header,
297 const QPixmap &pixmap )
298{
299 QStringList items;
300 items << itemName;
301 return addPage(items, header, pixmap);
302}
303
304
305
306QVBox *KJanusWidget::addVBoxPage( const QStringList &items,
307 const QString &header,
308 const QPixmap &pixmap )
309{
310 if( mValid == false )
311 {
312 qDebug("addPage: Invalid object ");
313
314 return( 0 );
315 }
316
317 QVBox *page = new QVBox(FindParent() , "vbox_page" );
318 page->setSpacing( KDialog::spacingHintSmall() );
319 addPageWidget( page, items, header, pixmap );
320
321 return page;
322}
323
324QVBox *KJanusWidget::addVBoxPage( const QString &itemName,
325 const QString &header,
326 const QPixmap &pixmap )
327{
328 QStringList items;
329 items << itemName;
330 return addVBoxPage(items, header, pixmap);
331}
332
333QHBox *KJanusWidget::addHBoxPage( const QStringList &items,
334 const QString &header,
335 const QPixmap &pixmap )
336{
337 if( mValid == false ) {
338 kdDebug() << "addPage: Invalid object" << endl;
339 return( 0 );
340 }
341
342 QHBox *page = new QHBox(FindParent(), "hbox_page");
343 page->setSpacing( KDialog::spacingHint() );
344 addPageWidget( page, items, header, pixmap );
345
346 return page;
347}
348
349QHBox *KJanusWidget::addHBoxPage( const QString &itemName,
350 const QString &header,
351 const QPixmap &pixmap )
352{
353 QStringList items;
354 items << itemName;
355 return addHBoxPage(items, header, pixmap);
356}
357
358QGrid *KJanusWidget::addGridPage( int n, QGrid::Direction dir,
359 const QStringList &items,
360 const QString &header,
361 const QPixmap &pixmap )
362{
363 if( mValid == false )
364 {
365 kdDebug() << "addPage: Invalid object" << endl;
366 return( 0 );
367 }
368
369 QGrid *page = new QGrid( n, dir, FindParent(), "page" );
370 page->setSpacing( KDialog::spacingHint() );
371 addPageWidget( page, items, header, pixmap );
372
373 return page;
374}
375
376
377QGrid *KJanusWidget::addGridPage( int n, QGrid::Direction dir,
378 const QString &itemName,
379 const QString &header,
380 const QPixmap &pixmap )
381{
382 QStringList items;
383 items << itemName;
384 return addGridPage(n, dir, items, header, pixmap);
385}
386
387void KJanusWidget::InsertTreeListItem(const QStringList &items, const QPixmap &pixmap, QFrame *page)
388{
389 bool isTop = true;
390 QListViewItem *curTop = 0, *child, *last, *newChild;
391 unsigned int index = 1;
392 QStringList curPath;
393
394 for ( QStringList::ConstIterator it = items.begin(); it != items.end(); ++it, index++ ) {
395 QString name = (*it);
396 bool isPath = ( index != items.count() );
397
398 // Find the first child.
399 if (isTop) {
400 child = mTreeList->firstChild();
401 }
402 else {
403 child = curTop->firstChild();
404 }
405
406 // Now search for a child with the current Name, and if it we doesn't
407 // find it, then remember the location of the last child.
408 for (last = 0; child && child->text(0) != name ; last = child, child = child->nextSibling());
409
410 if (last == 0 && child == 0) {
411 // This node didn't have any children at all, lets just insert the
412 // new child.
413 if (isTop)
414 newChild = new QListViewItem(mTreeList, name);
415 else
416 newChild = new QListViewItem(curTop, name);
417
418 }
419 else if (child != 0) {
420 // we found the given name in this child.
421 if (!isPath) {
422 kdDebug() << "The element inserted was already in the TreeList box!" << endl;
423 return;
424 }
425 else {
426 // Ok we found the folder
427 newChild = child;
428 }
429 }
430 else {
431 // the node had some children, but we didn't find the given name
432 if (isTop)
433 newChild = new QListViewItem(mTreeList, last, name);
434 else
435 newChild = new QListViewItem(curTop, last, name);
436 }
437
438 // Now make the element expandable if it is a path component, and make
439 // ready for next loop
440 if (isPath) {
441 newChild->setExpandable(true);
442 curTop = newChild;
443 isTop = false;
444 curPath << name;
445
446 QString key = curPath.join("_/_");
447 if (mFolderIconMap.contains(key)) {
448 QPixmap p = mFolderIconMap[key];
449 newChild->setPixmap(0,p);
450 }
451 }
452 else {
453 if (mShowIconsInTreeList) {
454 newChild->setPixmap(0, pixmap);
455 }
456 mTreeListToPageStack.insert(newChild, page);
457 }
458 }
459}
460
461void KJanusWidget::addPageWidget( QFrame *page, const QStringList &items,
462 const QString &header,const QPixmap &pixmap )
463{
464/*US the following signal causes a segmentation fault while closing the dialog.
465 Why not just remove all pages in the destructor??
466*/
467//US connect(page, SIGNAL(destroyed(QObject*)), this, SLOT(pageGone(QObject*)));
468// we have the SIGNAL(destroyed(QObject*) only in Qt3
469#ifdef DESKTOP_VERSION
470 // connect(page, SIGNAL(destroyed(QObject*)), this, SLOT(pageGone(QObject*)));
471#endif
472 if( mFace == Tabbed )
473 {
474 mTabControl->addTab (page, items.last());
475 d->mIntToPage[d->mNextPageIndex] = static_cast<QWidget*>(page);
476 d->mPageToInt[static_cast<QWidget*>(page)] = d->mNextPageIndex;
477 d->mNextPageIndex++;
478 }
479 else if( mFace == TreeList || mFace == IconList )
480 {
481 d->mIntToPage[d->mNextPageIndex] = static_cast<QWidget*>(page);
482 d->mPageToInt[static_cast<QWidget*>(page)] = d->mNextPageIndex;
483 mPageStack->addWidget( page, 0 );
484
485 if (items.count() == 0) {
486 kdDebug() << "Invalid QStringList, with zero items" << endl;
487 return;
488 }
489
490 if( mFace == TreeList )
491 {
492 InsertTreeListItem(items, pixmap, page);
493 }
494 else // mFace == IconList
495 {
496 QString itemName = items.last();
497 IconListItem *item = new IconListItem( mIconList, pixmap, itemName );
498 mIconListToPageStack.insert(item, page);
499 mIconList->invalidateHeight();
500 mIconList->invalidateWidth();
501
502 if (mIconList->isVisible())
503 mIconList->updateWidth();
504 }
505
506 //
507 // Make sure the title label is sufficiently wide
508 //
509 QString lastName = items.last();
510 const QString &title = (!header.isNull() ? header : lastName);
511 QRect r = mTitleLabel->fontMetrics().boundingRect( title );
512 if( mTitleLabel->minimumWidth() < r.width() )
513 {
514 mTitleLabel->setMinimumWidth( r.width() );
515 }
516 d->mIntToTitle[d->mNextPageIndex] = title;
517 if( d->mIntToTitle.count() == 1 )
518 {
519 showPage(0);
520 }
521 d->mNextPageIndex++;
522 }
523 else
524 {
525 kdDebug() << "KJanusWidget::addPageWidget: can only add a page in Tabbed, TreeList or IconList modes" << endl;
526 }
527
528}
529
530void KJanusWidget::setFolderIcon(const QStringList &path, const QPixmap &pixmap)
531{
532 QString key = path.join("_/_");
533 mFolderIconMap.insert(key,pixmap);
534}
535
536
537
538bool KJanusWidget::setSwallowedWidget( QWidget *widget )
539{
540 if( mFace != Swallow || mValid == false )
541 {
542 return( false );
543 }
544
545 //
546 // Remove current layout and make a new.
547 //
548 if( mSwallowPage->layout() != 0 )
549 {
550 delete mSwallowPage->layout();
551 }
552 QGridLayout *gbox = new QGridLayout( mSwallowPage, 1, 1, 0 );
553
554 //
555 // Hide old children
556 //
557 QObjectList *l = (QObjectList*)mSwallowPage->children(); // silence please
558 for( uint i=0; i < l->count(); i++ )
559 {
560 QObject *o = l->at(i);
561 if( o->isWidgetType() )
562 {
563 ((QWidget*)o)->hide();
564 }
565 }
566
567 //
568 // Add new child or make default size
569 //
570 if( widget == 0 )
571 {
572 gbox->addRowSpacing(0,100);
573 gbox->addColSpacing(0,100);
574 mSwallowPage->setMinimumSize(100,100);
575 }
576 else
577 {
578 if( widget->parent() != mSwallowPage )
579 {
580 widget->reparent( mSwallowPage, 0, QPoint(0,0) );
581 }
582 gbox->addWidget(widget, 0, 0 );
583 gbox->activate();
584 mSwallowPage->setMinimumSize( widget->minimumSize() );
585 }
586
587 return( true );
588}
589
590bool KJanusWidget::slotShowPage()
591{
592 if( mValid == false )
593 {
594 return( false );
595 }
596
597 if( mFace == TreeList )
598 {
599 QListViewItem *node = mTreeList->selectedItem();
600 if( node == 0 ) { return( false ); }
601
602 QWidget *stackItem = mTreeListToPageStack[node];
603 // Make sure to call through the virtual function showPage(int)
604 return showPage(d->mPageToInt[stackItem]);
605 }
606 else if( mFace == IconList )
607 {
608 QListBoxItem *node = mIconList->item( mIconList->currentItem() );
609 if( node == 0 ) { return( false ); }
610 QWidget *stackItem = mIconListToPageStack[node];
611 // Make sure to call through the virtual function showPage(int)
612 return showPage(d->mPageToInt[stackItem]);
613 }
614
615 return( false );
616}
617
618
619bool KJanusWidget::showPage( int index )
620{
621 if( d == 0 || mValid == false )
622 {
623 return( false );
624 }
625 else
626 {
627 return showPage(d->mIntToPage[index]);
628 }
629}
630
631
632bool KJanusWidget::showPage( QWidget *w )
633{
634 if( w == 0 || mValid == false )
635 {
636 return( false );
637 }
638
639 if( mFace == TreeList || mFace == IconList )
640 {
641 mPageStack->raiseWidget( w );
642 mActivePageWidget = w;
643
644 int index = d->mPageToInt[w];
645 mTitleLabel->setText( d->mIntToTitle[index] );
646 if( mFace == TreeList )
647 {
648 QMap<QListViewItem *, QWidget *>::Iterator it;
649 for (it = mTreeListToPageStack.begin(); it != mTreeListToPageStack.end(); ++it){
650 QListViewItem *key = it.key();
651 QWidget *val = it.data();
652 if (val == w) {
653 mTreeList->setSelected(key, true );
654 break;
655 }
656 }
657 }
658 else
659 {
660 QMap<QListBoxItem *, QWidget *>::Iterator it;
661 for (it = mIconListToPageStack.begin(); it != mIconListToPageStack.end(); ++it){
662 QListBoxItem *key = it.key();
663 QWidget *val = it.data();
664 if (val == w) {
665 mIconList->setSelected( key, true );
666 break;
667 }
668 }
669 }
670 }
671 else if( mFace == Tabbed )
672 {
673 mTabControl->showPage(w);
674 mActivePageWidget = w;
675 }
676 else
677 {
678 return( false );
679 }
680
681 return( true );
682}
683
684
685int KJanusWidget::activePageIndex() const
686{
687 if( mFace == TreeList) {
688 QListViewItem *node = mTreeList->selectedItem();
689 if( node == 0 ) { return -1; }
690 QWidget *stackItem = mTreeListToPageStack[node];
691 return d->mPageToInt[stackItem];
692 }
693 else if (mFace == IconList) {
694 QListBoxItem *node = mIconList->item( mIconList->currentItem() );
695 if( node == 0 ) { return( false ); }
696 QWidget *stackItem = mIconListToPageStack[node];
697 return d->mPageToInt[stackItem];
698 }
699 else if( mFace == Tabbed ) {
700 QWidget *widget = mTabControl->currentPage();
701 return( widget == 0 ? -1 : d->mPageToInt[widget] );
702 }
703 else {
704 return( -1 );
705 }
706}
707
708
709int KJanusWidget::pageIndex( QWidget *widget ) const
710{
711 if( widget == 0 )
712 {
713 return( -1 );
714 }
715 else if( mFace == TreeList || mFace == IconList )
716 {
717 return( d->mPageToInt[widget] );
718 }
719 else if( mFace == Tabbed )
720 {
721 //
722 // The user gets the real page widget with addVBoxPage(), addHBoxPage()
723 // and addGridPage() but not with addPage() which returns a child of
724 // the toplevel page. addPage() returns a QFrame so I check for that.
725 //
726 if( widget->isA("QFrame") )
727 {
728 return( d->mPageToInt[widget->parentWidget()] );
729 }
730 else
731 {
732 return( d->mPageToInt[widget] );
733 }
734 }
735 else
736 {
737 return( -1 );
738 }
739}
740/*US not yet implemented
741void KJanusWidget::slotFontChanged()
742{
743 if( mTitleLabel != 0 )
744 {
745 mTitleLabel->setFont( KGlobalSettings::generalFont() );
746 QFont titleFont( mTitleLabel->font() );
747 titleFont.setBold( true );
748 mTitleLabel->setFont( titleFont );
749 }
750
751 if( mFace == IconList )
752 {
753 QFont listFont( mIconList->font() );
754 listFont.setBold( true );
755 mIconList->setFont( listFont );
756 mIconList->invalidateHeight();
757 mIconList->invalidateWidth();
758 }
759}
760*/
761
762// makes the treelist behave like the list of kcontrol
763void KJanusWidget::slotItemClicked(QListViewItem *it)
764{
765 if(it && (it->childCount()>0))
766 it->setOpen(!it->isOpen());
767}
768
769void KJanusWidget::setFocus()
770{
771 if( mValid == false ) { return; }
772 if( mFace == TreeList )
773 {
774 mTreeList->setFocus();
775 }
776 if( mFace == IconList )
777 {
778 mIconList->setFocus();
779 }
780 else if( mFace == Tabbed )
781 {
782 mTabControl->setFocus();
783 }
784 else if( mFace == Swallow )
785 {
786 mSwallowPage->setFocus();
787 }
788 else if( mFace == Plain )
789 {
790 mPlainPage->setFocus();
791 }
792}
793
794
795QSize KJanusWidget::minimumSizeHint() const
796{
797 if( mFace == TreeList || mFace == IconList )
798 {
799 QSize s1( KDialog::spacingHint(), KDialog::spacingHint()*2 );
800 QSize s2(0,0);
801 QSize s3(0,0);
802 QSize s4( mPageStack->sizeHint() );
803
804 if( mFace == TreeList )
805 {
806/*US
807 s1.rwidth() += style().pixelMetric( QStyle::PM_SplitterWidth );
808 s2 = mTreeList->minimumSize();
809*/
810 }
811 else
812 {
813 mIconList->updateMinimumHeight();
814 mIconList->updateWidth();
815 s2 = mIconList->minimumSize();
816 }
817
818 if( mTitleLabel->isVisible() == true )
819 {
820 s3 += mTitleLabel->sizeHint();
821 s3.rheight() += mTitleSep->minimumSize().height();
822 }
823
824 //
825 // Select the tallest item. It has only effect in IconList mode
826 //
827 int h1 = s1.rheight() + s3.rheight() + s4.height();
828 int h2 = QMAX( h1, s2.rheight() );
829
830 return( QSize( s1.width()+s2.width()+QMAX(s3.width(),s4.width()), h2 ) );
831 }
832 else if( mFace == Tabbed )
833 {
834 return( mTabControl->sizeHint() );
835 }
836 else if( mFace == Swallow )
837 {
838 return( mSwallowPage->minimumSize() );
839 }
840 else if( mFace == Plain )
841 {
842 return( mPlainPage->sizeHint() );
843 }
844 else
845 {
846 return( QSize( 100, 100 ) ); // Should never happen though.
847 }
848
849}
850
851
852QSize KJanusWidget::sizeHint() const
853{
854 return( minimumSizeHint() );
855}
856
857
858void KJanusWidget::setTreeListAutoResize( bool state )
859{
860 if( mFace == TreeList )
861 {
862/*US
863 mTreeListResizeMode = state == false ?
864 QSplitter::KeepSize : QSplitter::Stretch;
865 QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget());
866 splitter->setResizeMode( mTreeList, mTreeListResizeMode );
867*/
868 }
869}
870
871
872void KJanusWidget::setIconListAllVisible( bool state )
873{
874 if( mFace == IconList )
875 {
876 mIconList->setShowAll( state );
877 }
878}
879
880void KJanusWidget::setShowIconsInTreeList( bool state )
881{
882 mShowIconsInTreeList = state;
883}
884
885void KJanusWidget::setRootIsDecorated( bool state )
886{
887 if( mFace == TreeList ) {
888 mTreeList->setRootIsDecorated(state);
889 }
890}
891
892void KJanusWidget::unfoldTreeList( bool persist )
893{
894 if( mFace == TreeList )
895 {
896 if( persist )
897 connect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) );
898 else
899 disconnect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) );
900
901 for( QListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() )
902 item->setOpen( true );
903 }
904}
905
906void KJanusWidget::showEvent( QShowEvent * )
907{
908 if( mFace == TreeList )
909 {
910/*US
911 QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget());
912 splitter->setResizeMode( mTreeList, mTreeListResizeMode );
913*/
914 }
915}
916
917
918//
919// 2000-13-02 Espen Sand
920// It should be obvious that this eventfilter must only be
921// be installed on the vertical scrollbar of the mIconList.
922//
923bool KJanusWidget::eventFilter( QObject *o, QEvent *e )
924{
925 if( e->type() == QEvent::Show )
926 {
927 IconListItem *item = (IconListItem*)mIconList->item(0);
928 if( item != 0 )
929 {
930 int lw = item->width( mIconList );
931 int sw = mIconList->verticalScrollBar()->sizeHint().width();
932 mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 );
933 }
934 }
935 else if( e->type() == QEvent::Hide )
936 {
937 IconListItem *item = (IconListItem*)mIconList->item(0);
938 if( item != 0 )
939 {
940 int lw = item->width( mIconList );
941 mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 );
942 }
943 }
944 return QWidget::eventFilter( o, e );
945}
946
947
948
949//
950// Code for the icon list box
951//
952
953
954KJanusWidget::IconListBox::IconListBox( QWidget *parent, const char *name,
955 WFlags f )
956 :KListBox( parent, name, f ), mShowAll(false), mHeightValid(false),
957 mWidthValid(false)
958{
959}
960
961
962void KJanusWidget::IconListBox::updateMinimumHeight()
963{
964 if( mShowAll == true && mHeightValid == false )
965 {
966 int h = frameWidth()*2;
967 for( QListBoxItem *i = item(0); i != 0; i = i->next() )
968 {
969 h += i->height( this );
970 }
971 setMinimumHeight( h );
972 mHeightValid = true;
973 }
974}
975
976
977void KJanusWidget::IconListBox::updateWidth()
978{
979 if( mWidthValid == false )
980 {
981 int maxWidth = 10;
982 for( QListBoxItem *i = item(0); i != 0; i = i->next() )
983 {
984 int w = ((IconListItem *)i)->width(this);
985 maxWidth = QMAX( w, maxWidth );
986 }
987
988 for( QListBoxItem *i = item(0); i != 0; i = i->next() )
989 {
990 ((IconListItem *)i)->expandMinimumWidth( maxWidth );
991 }
992
993 if( verticalScrollBar()->isVisible() )
994 {
995 maxWidth += verticalScrollBar()->sizeHint().width();
996 }
997
998 setFixedWidth( maxWidth + frameWidth()*2 );
999 mWidthValid = true;
1000 }
1001}
1002
1003
1004void KJanusWidget::IconListBox::invalidateHeight()
1005{
1006 mHeightValid = false;
1007}
1008
1009
1010void KJanusWidget::IconListBox::invalidateWidth()
1011{
1012 mWidthValid = false;
1013}
1014
1015
1016void KJanusWidget::IconListBox::setShowAll( bool showAll )
1017{
1018 mShowAll = showAll;
1019 mHeightValid = false;
1020}
1021
1022
1023
1024KJanusWidget::IconListItem::IconListItem( QListBox *listbox, const QPixmap &pixmap,
1025 const QString &text )
1026 : QListBoxItem( listbox )
1027{
1028 mPixmap = pixmap;
1029 if( mPixmap.isNull() == true )
1030 {
1031 mPixmap = defaultPixmap();
1032 }
1033 setText( text );
1034 mMinimumWidth = 0;
1035}
1036
1037
1038int KJanusWidget::IconListItem::expandMinimumWidth( int width )
1039{
1040 mMinimumWidth = QMAX( mMinimumWidth, width );
1041 return( mMinimumWidth );
1042}
1043
1044
1045const QPixmap &KJanusWidget::IconListItem::defaultPixmap()
1046{
1047 static QPixmap *pix=0;
1048 if( pix == 0 )
1049 {
1050 pix = new QPixmap( 32, 32 );
1051 QPainter p( pix );
1052 p.eraseRect( 0, 0, pix->width(), pix->height() );
1053 p.setPen( Qt::red );
1054 p.drawRect ( 0, 0, pix->width(), pix->height() );
1055 p.end();
1056
1057 QBitmap mask( pix->width(), pix->height(), true);
1058 mask.fill( Qt::black );
1059 p.begin( &mask );
1060 p.setPen( Qt::white );
1061 p.drawRect ( 0, 0, pix->width(), pix->height() );
1062 p.end();
1063
1064 pix->setMask( mask );
1065 }
1066 return( *pix );
1067}
1068
1069
1070void KJanusWidget::IconListItem::paint( QPainter *painter )
1071{
1072 QFontMetrics fm = painter->fontMetrics();
1073 //int wt = fm.boundingRect(text()).width();
1074 int wp = mPixmap.width();
1075 int ht = fm.lineSpacing();
1076 int hp = mPixmap.height();
1077
1078 painter->drawPixmap( (mMinimumWidth-wp)/2, 5, mPixmap );
1079 if( text().isEmpty() == false )
1080 {
1081 painter->drawText( 0, hp+7, mMinimumWidth, ht, Qt::AlignCenter, text() );
1082 }
1083}
1084
1085int KJanusWidget::IconListItem::height( const QListBox *lb ) const
1086{
1087 if( text().isEmpty() == true )
1088 {
1089 return( mPixmap.height() );
1090 }
1091 else
1092 {
1093 return( mPixmap.height() + lb->fontMetrics().lineSpacing()+10 );
1094 }
1095}
1096
1097
1098int KJanusWidget::IconListItem::width( const QListBox *lb ) const
1099{
1100 int wt = lb->fontMetrics().boundingRect(text()).width()+10;
1101 int wp = mPixmap.width() + 10;
1102 int w = QMAX( wt, wp );
1103 return( QMAX( w, mMinimumWidth ) );
1104}
1105
1106
1107void KJanusWidget::virtual_hook( int, void* )
1108{ /*BASE::virtual_hook( id, data );*/ }
1109
1110// TODO: In TreeList, if the last child of a node is removed, and there is no corrsponding widget for that node, allow the caller to
1111// delete the node.
1112void KJanusWidget::removePage( QWidget *page )
1113{
1114//US qDebug("KJanusWidget::removePage 1 %lu , %lu, %lu", d, page, &(d->mPageToInt));
1115 if (!d || !(d->mPageToInt.contains(page)))
1116 {
1117 return;
1118 }
1119
1120 int index = d->mPageToInt[page];
1121
1122 if ( mFace == TreeList )
1123 {
1124 QMap<QListViewItem*, QWidget *>::Iterator i;
1125 for( i = mTreeListToPageStack.begin(); i != mTreeListToPageStack.end(); ++i )
1126 if (i.data()==page)
1127 {
1128 delete i.key();
1129 mPageStack->removeWidget(page);
1130 mTreeListToPageStack.remove(i);
1131 d->mIntToTitle.remove(index);
1132 d->mPageToInt.remove(page);
1133 d->mIntToPage.remove(index);
1134 break;
1135 }
1136 }
1137 else if ( mFace == IconList )
1138 {
1139 QMap<QListBoxItem*, QWidget *>::Iterator i;
1140 for( i = mIconListToPageStack.begin(); i != mIconListToPageStack.end(); ++i )
1141 if (i.data()==page)
1142 {
1143 delete i.key();
1144 mPageStack->removeWidget(page);
1145 mIconListToPageStack.remove(i);
1146 d->mIntToTitle.remove(index);
1147 d->mPageToInt.remove(page);
1148 d->mIntToPage.remove(index);
1149 break;
1150 }
1151 }
1152 else // Tabbed
1153 {
1154 mTabControl->removePage(page);
1155 d->mPageToInt.remove(page);
1156 d->mIntToPage.remove(index);
1157 }
1158}
1159
1160QString KJanusWidget::pageTitle(int index) const
1161{
1162 if (!d || !d->mIntToTitle.contains(index))
1163 return QString::null;
1164 else
1165 return d->mIntToTitle[index];
1166}
1167
1168QWidget *KJanusWidget::pageWidget(int index) const
1169{
1170 if (!d || !d->mIntToPage.contains(index))
1171 return 0;
1172 else
1173 return d->mIntToPage[index];
1174}
1175
1176//US #include "kjanuswidget.moc"
diff --git a/microkde/kdeui/kjanuswidget.h b/microkde/kdeui/kjanuswidget.h
new file mode 100644
index 0000000..6d3f23d
--- a/dev/null
+++ b/microkde/kdeui/kjanuswidget.h
@@ -0,0 +1,565 @@
1/* This file is part of the KDE Libraries
2 * Copyright (C) 1999-2000 Espen Sand (espen@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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20#ifndef _KJANUS_WIDGET_H_
21#define _KJANUS_WIDGET_H_
22
23#include <qptrlist.h>
24#include <qwidget.h>
25#include <qmap.h>
26#include <qgrid.h>
27#include <klistbox.h>
28
29/*US
30#include <qptrlist.h>
31#include <qpixmap.h>
32#include <qsplitter.h>
33
34#include <qstringlist.h>
35#include <qmap.h>
36
37*/
38
39class KSeparator;
40class KListView;
41class QWidgetStack;
42class QLabel;
43class QTabWidget;
44class QListViewItem;
45class QVBox;
46class QHBox;
47
48/**
49 * Provides a number of ready to use layouts (faces). It is used
50 * as an internal widget in @ref KDialogBase, but can also used as a
51 * widget of its own.
52 *
53 * It provides TreeList, IconList, Tabbed, Plain and Swallow layouts.
54 *
55 * The TreeList face provides a list in the left area and pages in the
56 * right. The area are separated by a movable splitter. The style is somewhat
57 * similar to the layout in the Control Center. A page is raised by
58 * selecting the corresponding tree list item.
59 *
60 * The IconList face provides an icon list in the left area and pages in the
61 * right. For each entry the Icon is on top with the text below. The style
62 * is somewhat similar to the layout of the Eudora configuation dialog box.
63 * A page is raised by selecting the corresponding icon list item. The
64 * preferred icon size is 32x32 pixels.
65 *
66 * The Tabbed face is a common tabbed widget. The procedure for creating a
67 * page is similar for creating a TreeList. This has the advantage that if
68 * your widget contain too many pages it is trivial to convert it into a
69 * TreeList. Just change the face in the KJanusWidget constructor to
70 * KJanusWidget::TreeList and you have a tree list layout instead.
71 *
72 * The Plain face provides an empty widget (QFrame) where you can place your
73 * widgets. The KJanusWidget makes no assumptions regarding the contents so
74 * you are free to add whatever you want.
75 *
76 * The Swallow face is provided in order to simplify the usage of existing
77 * widgets and to allow changing the visible widget. You specify the widget
78 * to be displayed by @ref #setSwallowedWidget(). Your widget will be
79 * reparented inside the widget. You can specify a Null (0) widget. A empty
80 * space is then displayed.
81 *
82 * For all modes it is important that you specify the @ref QWidget::minimumSize()
83 * on the page, plain widget or the swallowed widget. If you use a QLayout
84 * on the page, plain widget or the swallowed widget this will be taken care
85 * of automatically. The size is used when the KJanusWidget determines its
86 * own minimum size. You get the minimum size by using the
87 * @ref #minimumSizeHint() or @ref #sizeHint() methods.
88 *
89 * Pages that have been added in TreeList, IconList or Tabbed mode can be
90 * removed by simply deleting the page. However, it would be preferable to use
91 * the QObject::deleteLater() function on the page as the main event loop
92 * may have optimized UI update events of the page by scheduling them for later.
93 *
94 * @short Easy to use widget with many layouts
95 * @author Espen Sand (espen@kde.org)
96 */
97class KJanusWidget : public QWidget
98{
99 Q_OBJECT
100
101 private:
102 class IconListBox : public KListBox
103 {
104 public:
105 IconListBox( QWidget *parent=0, const char *name=0, WFlags f=0 );
106 void updateMinimumHeight();
107 void updateWidth();
108 void invalidateHeight();
109 void invalidateWidth();
110 void setShowAll( bool showAll );
111
112 private:
113 bool mShowAll;
114 bool mHeightValid;
115 bool mWidthValid;
116 };
117
118 public:
119 enum Face
120 {
121 TreeList = 0,
122 Tabbed,
123 Plain,
124 Swallow,
125 IconList
126 };
127
128 public:
129
130 /**
131 * Constructor where you specify the face.
132 *
133 * @param parent Parent of the widget.
134 * @param name Widget name.
135 * @param int face The kind of dialog, Use TreeList, Tabbed, Plain or
136 * Swallow.
137 */
138 KJanusWidget( QWidget *parent=0, const char *name=0, int face=Plain );
139
140 /**
141 * Destructor.
142 */
143 ~KJanusWidget();
144
145 /**
146 * Raises the page which was added by @ref addPage().
147 *
148 * @param index The index of the page you want to raise.
149 */
150 virtual bool showPage( int index );
151
152 /**
153 * Returns the index of the page that are currently displayed.
154 *
155 * @return The index or -1 if the face is not Tabbed, TreeList or
156 * IconList.
157 */
158 virtual int activePageIndex() const;
159
160 /**
161 * Use this to verify
162 * that no memory allocation failed.
163 *
164 * @return true if the widget was properly created.
165 */
166 virtual bool isValid() const;
167
168 /**
169 * Returns the face type.
170 *
171 * @return The face type.
172 */
173 virtual int face() const;
174
175 /**
176 * Returns the minimum size that must be made available for the widget
177 * so that UIs can be displayed properly
178 *
179 * @return The minimum size.
180 */
181 virtual QSize minimumSizeHint() const;
182
183 /**
184 * Returns the recommended size for the widget in order to be displayed
185 * properly.
186 *
187 * @return The recommended size.
188 */
189 virtual QSize sizeHint() const;
190
191 /**
192 * Returns the empty widget that is available in Plain mode.
193 *
194 * @return The widget or 0 if the face in not Plain.
195 */
196 virtual QFrame *plainPage();
197
198 /**
199 * Add a new page when the class is used in TreeList, IconList or Tabbed
200 * mode. The returned widget is empty and you must add your widgets
201 * as children to this widget. In most cases you must create a layout
202 * manager and associate it with this widget as well.
203 *
204 * Deleting the returned frame will cause the listitem or tab to be
205 * removed (you can re-add a page with the same name later.
206 *
207 * @param item String used in the list or Tab item.
208 * @param header A longer string used in TreeList and IconList mode to
209 * describe the contents of a page. If empty, the item string
210 * will be used instead.
211 * @param pixmap Used in IconList mode or in TreeList mode. You should
212 * prefer a pixmap with size 32x32 pixels.
213 *
214 * @return The empty page or 0 if the face is not TreeList, IconList or
215 * Tabbed.
216 */
217 virtual QFrame *addPage(const QString &item,const QString &header=QString::null,
218 const QPixmap &pixmap=QPixmap() );
219
220 /**
221 * This is like addPage just above, with the difference that the first
222 * element is a list of strings. These strings are used to form a path
223 * of folders down to the given page. The initial elements are names
224 * for the folders, while the last element is the name of the page.
225 * Note: This does yet only work for the TreeList face. Later this may
226 * be added for the IconList face too. In other faces than the
227 * TreeList, all the strings except the last one is ignored.
228 * Deleting the returned frame will cause the listitem or tab to be
229 * removed (you can re-add a page with the same name later.
230 *
231 * Deleting the returned frame will cause the listitem or tab to be
232 * removed (you can re-add a page with the same name later.
233 **/
234 virtual QFrame *addPage(const QStringList &items, const QString &header=QString::null,
235 const QPixmap &pixmap=QPixmap() );
236
237 /**
238 * Add a new page when the class is used in TreeList, IconList or Tabbed
239 * mode. The returned widget is empty and you must add your widgets
240 * as children to this widget. The returned widget is a @ref QVBox
241 * so it contains a QVBoxLayout layout that lines up the child widgets
242 * are vertically.
243 *
244 * Deleting the returned frame will cause the listitem or tab to be
245 * removed (you can re-add a page with the same name later.
246 *
247 * @param item String used in the list or Tab item.
248 * @param header A longer string used in TreeList and IconList mode to
249 * describe the contents of a page. If empty, the item string
250 * will be used instead.
251 * @param pixmap Used in IconList mode or in TreeList mode. You should
252 * prefer a pixmap with size 32x32 pixels.
253 *
254 * @return The empty page or 0 if the face is not TreeList, IconList or
255 * Tabbed. */
256 virtual QVBox *addVBoxPage( const QString &item,
257 const QString &header=QString::null,
258 const QPixmap &pixmap=QPixmap() );
259
260 /**
261 * This is like addVBoxPage just above, with the difference that the first
262 * element is a list of strings. These strings are used to form a path
263 * of folders down to the given page. The initial elements are names
264 * for the folders, while the last element is the name of the page.
265 * Note: This does yet only work for the TreeList face. Later this may
266 * be added for the IconList face too. In other faces than the
267 * TreeList, all the strings except the last one is ignored.
268 *
269 * Deleting the returned frame will cause the listitem or tab to be
270 * removed (you can re-add a page with the same name later.
271 **/
272 virtual QVBox *addVBoxPage( const QStringList &items,
273 const QString &header=QString::null,
274 const QPixmap &pixmap=QPixmap() );
275
276 /**
277 * Add a new page when the class is used in TreeList, IconList or Tabbed
278 * mode. The returned widget is empty and you must add your widgets
279 * as children to this widget. The returned widget is a @ref QHBox
280 * so it contains a QHBoxLayout layout that lines up the child widgets
281 * are horizontally.
282 *
283 * Deleting the returned frame will cause the listitem or tab to be
284 * removed (you can re-add a page with the same name later.
285 *
286 * @param item String used in the list or Tab item.
287 * @param header A longer string used in TreeList and IconList mode to
288 * describe the contents of a page. If empty, the item string
289 * will be used instead.
290 * @param pixmap Used in IconList mode or in TreeList mode. You should
291 * prefer a pixmap with size 32x32 pixels.
292 *
293 * @return The empty page or 0 if the face is not TreeList, IconList or
294 * Tabbed.
295 */
296 virtual QHBox *addHBoxPage( const QString &itemName,
297 const QString &header=QString::null,
298 const QPixmap &pixmap=QPixmap() );
299
300 /**
301 * This is like addHBoxPage just above, with the difference that the first
302 * element is a list of strings. These strings are used to form a path
303 * of folders down to the given page. The initial elements are names
304 * for the folders, while the last element is the name of the page.
305 * Note: This does yet only work for the TreeList face. Later this may
306 * be added for the IconList face too. In other faces than the
307 * TreeList, all the strings except the last one is ignored.
308 *
309 * Deleting the returned frame will cause the listitem or tab to be
310 * removed (you can re-add a page with the same name later.
311 **/
312 virtual QHBox *addHBoxPage( const QStringList &items,
313 const QString &header=QString::null,
314 const QPixmap &pixmap=QPixmap() );
315
316 /**
317 * Add a new page when the class is used in either TreeList or Tabbed
318 * mode. The returned widget is empty and you must add your widgets
319 * as children to this widget. The returned widget is a @ref QGrid
320 * so it contains a QGridLayout layout that places up the child widgets
321 * in a grid.
322 *
323 * Deleting the returned frame will cause the listitem or tab to be
324 * removed (you can re-add a page with the same name later.
325 *
326 * @param n Specifies the number of columns if 'dir' is QGrid::Horizontal
327 * or the number of rows if 'dir' is QGrid::Vertical.
328 * @param dir Can be QGrid::Horizontal or QGrid::Vertical.
329 * @param item String used in the list or Tab item.
330 * @param header A longer string used in TreeList and IconList mode to
331 * describe the contents of a page. If empty, the item string
332 * will be used instead.
333 * @param pixmap Used in IconList mode or in TreeList mode. You should
334 * prefer a pixmap with size 32x32 pixels.
335 *
336 * @return The empty page or 0 if the face is not TreeList, IconList or
337 * Tabbed.
338 */
339//US changed Orientation into Direction for compatibility
340 virtual QGrid *addGridPage( int n, QGrid::Direction dir,
341 const QString &itemName,
342 const QString &header=QString::null,
343 const QPixmap &pixmap=QPixmap() );
344
345 /**
346 * This is like addGridPage just above, with the difference that the first
347 * element is a list of strings. These strings are used to form a path
348 * of folders down to the given page. The initial elements are names
349 * for the folders, while the last element is the name of the page.
350 * Note: This does yet only work for the TreeList face. Later this may
351 * be added for the IconList face too. In other faces than the
352 * TreeList, all the strings except the last one is ignored.
353 *
354 * Deleting the returned frame will cause the listitem or tab to be
355 * removed (you can re-add a page with the same name later.
356 **/
357//US changed Orientation into Direction for compatibility
358 virtual QGrid *addGridPage( int n, QGrid::Direction dir,
359 const QStringList &items,
360 const QString &header=QString::null,
361 const QPixmap &pixmap=QPixmap() );
362
363 /**
364 * @short Removes a page created with @ref addPage, @ref addVBoxPage,
365 * @ref addHBoxPage or @ref addGridPage. If the page has already
366 * been deleted or has already been removed, nothing happens. The widget
367 * itself is not deleted.
368 *
369 * @param page The widget returned by @ref addPage , @ref addVBoxPage ,
370 * @ref addHBoxPage or @ref addGridPage .
371 */
372 void removePage( QWidget *page );
373
374
375 /**
376 * Returns the index of a page created with @ref addPage ,
377 * @ref addVBoxPage , @ref addHBoxPage or @ref addGridPage .
378 * You can can compare this index with the value returned from
379 * @ref activePageIndex if you need to do some page specific actions
380 * in your code.
381 *
382 * The returned index will never change so you can safely use this
383 * function once and save the value.
384 *
385 * @param widget The widget returned by @ref addPage , @ref addVBoxPage ,
386 * @ref addHBoxPage or @ref addGridPage .
387 *
388 * @return The index or -1 if the face is not Tabbed, TreeList or
389 * IconList
390 */
391 virtual int pageIndex( QWidget *widget ) const;
392
393 /**
394 * Defines the widget to be swallowed.
395 *
396 * This method can be used several
397 * times. Only the latest defined widget will be shown.
398 *
399 * @param widget The widget to be swallowed. If 0, then an empty rectangle
400 * is displayed.
401 */
402 virtual bool setSwallowedWidget( QWidget *widget );
403
404 /**
405 * This function has only effect in TreeList mode.
406 *
407 * Defines how the tree list is resized when the widget is resized
408 * horizontally. By default the tree list keeps its width when the
409 * widget becomes wider.
410 *
411 * @param state The resize mode. If false (default) the TreeList keeps
412 * its current width when the widget becomes wider.
413 */
414 virtual void setTreeListAutoResize( bool state );
415
416 /**
417 * This function has only effect in TreeList mode.
418 *
419 * This tells the widgets whether the icons given in the @ref addPage,
420 * @ref addVBoxPage, @ref addHBoxPage, or @ref addGridPage methods should
421 * be shown in the TreeList.
422 *
423 * Note: This method must be called before calling any of the methods
424 * which add icons to the page.
425 *
426 * @param state If true the icons are shown.
427 **/
428 virtual void setShowIconsInTreeList(bool state);
429
430 /**
431 * This function has only effect in TreeList mode.
432 *
433 * This tells the widgets whether the root should be decorated.
434 * For details see @ref QListView::setRootIsDecorated
435 *
436 * @param state Root will be decorated if true.
437 **/
438 virtual void setRootIsDecorated( bool state );
439
440 /**
441 * This function has only effect in TreeList mode.
442 *
443 * This tells the TreeList to unfold the whole tree so that all entries
444 * are visible.
445 *
446 * If the list is empty when you call this method newly created entries
447 * will not automatically be opened. If the @p persist flag is set opened
448 * entries cannot be closed again, though.
449 *
450 * @param persist If true the tree always stays unfolded.
451 * @since 3.2
452 */
453 /*virtual*/ void unfoldTreeList( bool persist = false ); //### KDE4 BIC add virtual
454
455 /**
456 * This function has only effect in IconList mode.
457 *
458 * Defines how the icon list widget is displayed. By default it is
459 * the widgets in the pages that decide the minimum height
460 * of the toplevel widget. A vertical scrollbar can be used in
461 * the icon list area.
462 *
463 * @param state The visibility mode. If true, the minimum height is
464 * adjusted so that every icon in the list is visible at the
465 * same time. The vertical scrollbar will never be visible.
466 */
467 virtual void setIconListAllVisible( bool state );
468
469 /**
470 * Sets the icon used in TreeList Mode for the given path.
471 * @param path The path for which this icon should be shown.
472 * @param pixmap The icon used.
473 **/
474 virtual void setFolderIcon(const QStringList &path, const QPixmap &pixmap);
475 /**
476 * Returns the title string associated with a page index in TreeList or IconList mode.
477 * @param index The index of the page or null if there is no such page.
478 * @see @ref #pageIndex()
479 * @since 3.2
480 */
481 /*virtual*/ QString pageTitle(int index) const;
482 /**
483 * Returns the page widget associated with a page index or null if there is
484 * no such page.
485 * @param index The index of the page.
486 * @see @ref #pageIndex()
487 * @since 3.2
488 */
489 /*virtual*/ QWidget *pageWidget(int index) const;
490
491 signals:
492 void aboutToShowPage(QWidget *page);
493
494 public slots:
495 /**
496 * Give the keyboard input focus to the widget.
497 */
498 virtual void setFocus();
499
500 protected:
501 /**
502 * Reimplemented to handle the splitter width when the the face
503 * is TreeList
504 */
505 virtual void showEvent( QShowEvent * );
506
507 /**
508 * This function is used internally when in IconList mode. If you
509 * reimplement this class a make your own event filter, make sure to
510 * call this function from your filter.
511 *
512 * @param o Object that has received an event.
513 * @param e The event.
514 */
515 virtual bool eventFilter( QObject *o, QEvent *e );
516
517 private slots:
518 bool slotShowPage();
519//US not yet implemented void slotFontChanged();
520 void slotItemClicked(QListViewItem *it);
521 void pageGone( QObject *obj); // signal from the added page's "destroyed" signal
522 void slotReopen(QListViewItem *item);
523
524 protected:
525 bool showPage( QWidget *w );
526 void addPageWidget( QFrame *page, const QStringList &items,
527 const QString &header, const QPixmap &pixmap );
528 void InsertTreeListItem(const QStringList &items, const QPixmap &pixmap, QFrame *page);
529 QWidget *FindParent();
530
531 private:
532 bool mValid;
533
534 // Obsolete members. Remove in KDE 4.
535 QPtrList<QWidget> *mPageList;
536 QStringList *mTitleList;
537
538 int mFace;
539 KListView *mTreeList;
540 IconListBox *mIconList;
541 QWidgetStack *mPageStack;
542 QLabel *mTitleLabel;
543 QTabWidget *mTabControl;
544 QFrame *mPlainPage;
545 QWidget *mSwallowPage;
546 QWidget *mActivePageWidget;
547 KSeparator *mTitleSep;
548//US QSplitter::ResizeMode mTreeListResizeMode;
549 bool mShowIconsInTreeList;
550 QMap<QListViewItem *, QWidget *> mTreeListToPageStack;
551 QMap<QListBoxItem *, QWidget *> mIconListToPageStack;
552 QMap<QString, QPixmap> mFolderIconMap;
553 QMap<QString, QStringList> mChildrenNames;
554 QMap<QString, QWidget *> mChildPages;
555
556 public:
557 class IconListItem;
558 protected:
559 virtual void virtual_hook( int id, void* data );
560 private:
561 class KJanusWidgetPrivate;
562 KJanusWidgetPrivate *d;
563};
564
565#endif
diff --git a/microkde/kdeui/klistbox.cpp b/microkde/kdeui/klistbox.cpp
new file mode 100644
index 0000000..c65b892
--- a/dev/null
+++ b/microkde/kdeui/klistbox.cpp
@@ -0,0 +1,314 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Reginald Stadlbauer <reggie@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 version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17*/
18#include <qtimer.h>
19
20#include <kglobalsettings.h>
21//US#include <kcursor.h>
22#include <kapplication.h>
23//US#include <kipc.h>
24#include <kdebug.h>
25
26#include "klistbox.h"
27
28#ifdef Q_WS_X11
29#include <X11/Xlib.h>
30#endif
31#ifdef _WIN32_
32#define Q_WS_QWS
33#endif
34KListBox::KListBox( QWidget *parent, const char *name, WFlags f )
35 : QListBox( parent, name, f )
36{
37 connect( this, SIGNAL( onViewport() ),
38 this, SLOT( slotOnViewport() ) );
39 connect( this, SIGNAL( onItem( QListBoxItem * ) ),
40 this, SLOT( slotOnItem( QListBoxItem * ) ) );
41
42 connect( this, SIGNAL( mouseButtonClicked( int, QListBoxItem *,
43 const QPoint & ) ),
44 this, SLOT( slotMouseButtonClicked( int, QListBoxItem *,
45 const QPoint & ) ) );
46/*US
47
48 slotSettingsChanged(KApplication::SETTINGS_MOUSE);
49 if (kapp)
50 {
51 connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) );
52 kapp->addKipcEventMask( KIPC::SettingsChanged );
53 }
54*/
55 m_pCurrentItem = 0L;
56//US set single to true
57 m_bUseSingle = true;
58 m_pAutoSelect = new QTimer( this );
59 connect( m_pAutoSelect, SIGNAL( timeout() ),
60 this, SLOT( slotAutoSelect() ) );
61}
62
63void KListBox::slotOnItem( QListBoxItem *item )
64{
65/*US
66 if ( item && m_bChangeCursorOverItem && m_bUseSingle )
67 viewport()->setCursor( KCursor().handCursor() );
68*/
69 if ( item && (m_autoSelectDelay > -1) && m_bUseSingle ) {
70 m_pAutoSelect->start( m_autoSelectDelay, true );
71 m_pCurrentItem = item;
72 }
73}
74
75void KListBox::slotOnViewport()
76{
77/*US
78 if ( m_bChangeCursorOverItem )
79 viewport()->unsetCursor();
80*/
81 m_pAutoSelect->stop();
82 m_pCurrentItem = 0L;
83}
84
85
86/*US
87void KListBox::slotSettingsChanged(int category)
88{
89 if (category != KApplication::SETTINGS_MOUSE)
90 return;
91
92 m_bUseSingle = KGlobalSettings::singleClick();
93 m_bUseSingle = true;
94
95 disconnect( this, SIGNAL( mouseButtonClicked( int, QListBoxItem *,
96 const QPoint & ) ),
97 this, SLOT( slotMouseButtonClicked( int, QListBoxItem *,
98 const QPoint & ) ) );
99// disconnect( this, SIGNAL( doubleClicked( QListBoxItem *,
100 // const QPoint & ) ),
101 // this, SLOT( slotExecute( QListBoxItem *,
102 // const QPoint & ) ) );
103
104 if( m_bUseSingle )
105 {
106 connect( this, SIGNAL( mouseButtonClicked( int, QListBoxItem *,
107 const QPoint & ) ),
108 this, SLOT( slotMouseButtonClicked( int, QListBoxItem *,
109 const QPoint & ) ) );
110 }
111 else
112 {
113// connect( this, SIGNAL( doubleClicked( QListBoxItem *,
114 // const QPoint & ) ),
115// this, SLOT( slotExecute( QListBoxItem *,
116 // const QPoint & ) ) );
117 }
118
119 m_bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon();
120 m_autoSelectDelay = KGlobalSettings::autoSelectDelay();
121
122 if( !m_bUseSingle || !m_bChangeCursorOverItem )
123 viewport()->unsetCursor();
124
125}
126*/
127void KListBox::slotAutoSelect()
128{
129 // check that the item still exists
130 if( index( m_pCurrentItem ) == -1 )
131 return;
132
133 //Give this widget the keyboard focus.
134 if( !hasFocus() )
135 setFocus();
136
137#ifdef Q_WS_X11 //FIXME
138 Window root;
139 Window child;
140 int root_x, root_y, win_x, win_y;
141 uint keybstate;
142 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
143 &root_x, &root_y, &win_x, &win_y, &keybstate );
144#endif
145
146 QListBoxItem* previousItem = item( currentItem() );
147 setCurrentItem( m_pCurrentItem );
148
149 if( m_pCurrentItem ) {
150#ifndef Q_WS_QWS //FIXME
151 //Shift pressed?
152 if( (keybstate & ShiftMask) ) {
153#endif
154 bool block = signalsBlocked();
155 blockSignals( true );
156
157#ifndef Q_WS_QWS //FIXME
158 //No Ctrl? Then clear before!
159 if( !(keybstate & ControlMask) )
160 clearSelection();
161#endif
162
163//US in my QT version it is called isSelected() So what is right?
164//US bool select = !m_pCurrentItem->isSelected();
165 bool select = !m_pCurrentItem->selected();
166 bool update = viewport()->isUpdatesEnabled();
167 viewport()->setUpdatesEnabled( false );
168
169 bool down = index( previousItem ) < index( m_pCurrentItem );
170 QListBoxItem* it = down ? previousItem : m_pCurrentItem;
171 for (;it ; it = it->next() ) {
172 if ( down && it == m_pCurrentItem ) {
173 setSelected( m_pCurrentItem, select );
174 break;
175 }
176 if ( !down && it == previousItem ) {
177 setSelected( previousItem, select );
178 break;
179 }
180 setSelected( it, select );
181 }
182
183 blockSignals( block );
184 viewport()->setUpdatesEnabled( update );
185 triggerUpdate( false );
186
187 emit selectionChanged();
188
189 if( selectionMode() == QListBox::Single )
190 emit selectionChanged( m_pCurrentItem );
191 }
192#ifndef Q_WS_QWS //FIXME
193 else if( (keybstate & ControlMask) )
194 setSelected( m_pCurrentItem, !m_pCurrentItem->isSelected() );
195#endif
196 else {
197 bool block = signalsBlocked();
198 blockSignals( true );
199
200//US in my QT version it is called isSelected() So what is right?
201//US if( !m_pCurrentItem->isSelected() )
202 if( !m_pCurrentItem->selected() )
203 clearSelection();
204
205 blockSignals( block );
206
207 setSelected( m_pCurrentItem, true );
208 }
209#ifndef Q_WS_QWS //FIXME
210 }
211 else
212 kdDebug() << "Thats not supposed to happen!!!!" << endl;
213#endif
214}
215
216void KListBox::emitExecute( QListBoxItem *item, const QPoint &pos )
217{
218#ifdef Q_WS_X11 //FIXME
219 Window root;
220 Window child;
221 int root_x, root_y, win_x, win_y;
222 uint keybstate;
223 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
224 &root_x, &root_y, &win_x, &win_y, &keybstate );
225#endif
226
227 m_pAutoSelect->stop();
228
229#ifndef Q_WS_QWS //FIXME
230 //Dont emit executed if in SC mode and Shift or Ctrl are pressed
231 if( !( m_bUseSingle && ((keybstate & ShiftMask) || (keybstate & ControlMask)) ) ) {
232#endif
233 emit executed( item );
234 emit executed( item, pos );
235#ifndef Q_WS_QWS //FIXME
236 }
237#endif
238}
239
240//
241// 2000-16-01 Espen Sand
242// This widget is used in dialogs. It should ignore
243// F1 (and combinations) and Escape since these are used
244// to start help or close the dialog. This functionality
245// should be done in QListView but it is not (at least now)
246//
247void KListBox::keyPressEvent(QKeyEvent *e)
248{
249 if( e->key() == Key_Escape )
250 {
251 e->ignore();
252 }
253 else if( e->key() == Key_F1 )
254 {
255 e->ignore();
256 }
257 else
258 {
259 QListBox::keyPressEvent(e);
260 }
261}
262
263void KListBox::focusOutEvent( QFocusEvent *fe )
264{
265 m_pAutoSelect->stop();
266
267 QListBox::focusOutEvent( fe );
268}
269
270void KListBox::leaveEvent( QEvent *e )
271{
272 m_pAutoSelect->stop();
273
274 QListBox::leaveEvent( e );
275}
276
277void KListBox::contentsMousePressEvent( QMouseEvent *e )
278{
279 if( (selectionMode() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) ) {
280 bool block = signalsBlocked();
281 blockSignals( true );
282
283 clearSelection();
284
285 blockSignals( block );
286 }
287
288 QListBox::contentsMousePressEvent( e );
289}
290
291void KListBox::contentsMouseDoubleClickEvent ( QMouseEvent * e )
292{
293 QListBox::contentsMouseDoubleClickEvent( e );
294
295 QListBoxItem* item = itemAt( e->pos() );
296
297 if( item ) {
298 emit doubleClicked( item, e->globalPos() );
299
300 if( (e->button() == LeftButton) && !m_bUseSingle )
301 emitExecute( item, e->globalPos() );
302 }
303}
304
305void KListBox::slotMouseButtonClicked( int btn, QListBoxItem *item, const QPoint &pos )
306{
307 if( (btn == LeftButton) && item )
308 emitExecute( item, pos );
309}
310
311void KListBox::virtual_hook( int, void* )
312{ /*BASE::virtual_hook( id, data );*/ }
313
314//US #include "klistbox.moc"
diff --git a/microkde/kdeui/klistbox.h b/microkde/kdeui/klistbox.h
new file mode 100644
index 0000000..8023780
--- a/dev/null
+++ b/microkde/kdeui/klistbox.h
@@ -0,0 +1,141 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Reginald Stadlbauer <reggie@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 version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17*/
18#ifndef KLISTBOX_H
19#define KLISTBOX_H
20
21#include <qlistbox.h>
22
23/**
24 * Extends the functionality of @ref QListBox to honor the system
25 * wide settings for Single Click/Double Click mode, Auto Selection and
26 * Change Cursor over Link.
27 *
28 * There is a new signal @ref executed(). It gets connected to either
29 * @ref QListBox::clicked() or @ref QListBox::doubleClicked()
30 * depending on the KDE wide Single Click/Double Click settings. It is
31 * strongly recomended that you use this signal instead of the above
32 * mentioned. This way you don't need to care about the current
33 * settings. If you want to get informed when the user selects
34 * something connect to the @ref QListBox::selectionChanged() signal.
35 *
36 * @short A variant of @ref QListBox that honors KDE's system-wide settings.
37 **/
38class KListBox : public QListBox
39{
40 Q_OBJECT
41
42public:
43 KListBox( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
44
45signals:
46
47 /**
48 * Emitted whenever the user executes an listbox item.
49 *
50 * That means depending on the KDE wide Single Click/Double Click
51 * setting the user clicked or double clicked on that item.
52 * @param item is the pointer to the executed listbox item.
53 *
54 * Note that you may not delete any @ref QListBoxItem objects in slots
55 * connected to this signal.
56 */
57 void executed( QListBoxItem *item );
58
59 /**
60 * Emitted whenever the user executes an listbox item.
61 *
62 * That means depending on the KDE wide Single Click/Double Click
63 * setting the user clicked or double clicked on that item.
64 * @param item is the pointer to the executed listbox item.
65 * @param pos is the position where the user has clicked
66 *
67 * Note that you may not delete any @ref QListBoxItem objects in slots
68 * connected to this signal.
69 */
70 void executed( QListBoxItem *item, const QPoint &pos );
71
72 /**
73 * This signal gets emitted whenever the user double clicks into the
74 * listbox.
75 *
76 * @param item The pointer to the clicked listbox item.
77 * @param pos The position where the user has clicked.
78 *
79 * Note that you may not delete any @ref QListBoxItem objects in slots
80 * connected to this signal.
81 *
82 * This signal is more or less here for the sake of completeness.
83 * You should normally not need to use this. In most cases it's better
84 * to use @ref executed() instead.
85 */
86 void doubleClicked( QListBoxItem *item, const QPoint &pos );
87
88protected slots:
89 void slotOnItem( QListBoxItem *item );
90 void slotOnViewport();
91
92//US void slotSettingsChanged(int);
93
94 /**
95 * Auto selection happend.
96 */
97 void slotAutoSelect();
98
99protected:
100 void emitExecute( QListBoxItem *item, const QPoint &pos );
101
102 /**
103 * @reimplemented
104 */
105 virtual void keyPressEvent(QKeyEvent *e);
106 /**
107 * @reimplemented
108 */
109 virtual void focusOutEvent( QFocusEvent *fe );
110 /**
111 * @reimplemented
112 */
113 virtual void leaveEvent( QEvent *e );
114 /**
115 * @reimplemented
116 */
117 virtual void contentsMousePressEvent( QMouseEvent *e );
118 /**
119 * @reimplemented
120 */
121 virtual void contentsMouseDoubleClickEvent ( QMouseEvent *e );
122
123 bool m_bUseSingle;
124//US bool m_bChangeCursorOverItem;
125
126 QListBoxItem* m_pCurrentItem;
127
128 QTimer* m_pAutoSelect;
129 int m_autoSelectDelay;
130
131private slots:
132 void slotMouseButtonClicked( int btn, QListBoxItem *item, const QPoint &pos );
133
134protected:
135 virtual void virtual_hook( int id, void* data );
136private:
137 class KListBoxPrivate;
138 KListBoxPrivate *d;
139};
140
141#endif
diff --git a/microkde/kdeui/klistview.cpp b/microkde/kdeui/klistview.cpp
new file mode 100644
index 0000000..b53a88a
--- a/dev/null
+++ b/microkde/kdeui/klistview.cpp
@@ -0,0 +1,2191 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2000 Charles Samuels <charles@kde.org>
4 Copyright (C) 2000 Peter Putzer
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include <qdragobject.h>
22#include <qtimer.h>
23#include <qheader.h>
24#include <qcursor.h>
25#include <qtooltip.h>
26#include <qstyle.h>
27#include <qpainter.h>
28
29#include <kglobalsettings.h>
30#include <kconfig.h>
31#include <kconfigbase.h>
32//US #include <kcursor.h>
33#include <kapplication.h>
34//US #include <kipc.h>
35#include <kdebug.h>
36#ifdef _WIN32_
37#define Q_WS_QWS
38#endif
39#ifndef _WIN32_
40#define private public
41#include <qlistview.h>
42#undef private
43#endif
44#include "klistview.h"
45//US #include "klistviewlineedit.h"
46#ifndef DESKTOP_VERSION
47#include <qpe/qpeapplication.h>
48#endif
49
50// /*US
51class KListView::Tooltip : public QToolTip
52{
53public:
54 Tooltip (KListView* parent, QToolTipGroup* group = 0L);
55 virtual ~Tooltip () {}
56
57protected:
58 // */
59 /**
60 * Reimplemented from QToolTip for internal reasons.
61 */
62 // /*US
63 virtual void maybeTip (const QPoint&);
64
65private:
66 KListView* mParent;
67};
68
69KListView::Tooltip::Tooltip (KListView* parent, QToolTipGroup* group)
70 : QToolTip (parent, group),
71 mParent (parent)
72{
73}
74
75void KListView::Tooltip::maybeTip (const QPoint&)
76{
77 // FIXME
78}
79// */
80
81class KListView::KListViewPrivate
82{
83public:
84 KListViewPrivate (KListView* listview)
85 : pCurrentItem (0L),
86 autoSelectDelay(1),
87//US dragDelay (KGlobalSettings::dndEventDelay()),
88
89 dragDelay (10),
90//US editor (new KListViewLineEdit (listview)),
91 cursorInExecuteArea(false),
92 bUseSingle(false),
93 bChangeCursorOverItem(false),
94 itemsMovable (true),
95 selectedBySimpleMove(false),
96 selectedUsingMouse(false),
97 showContextMenusOnPress(true),
98 itemsRenameable (false),
99 validDrag (false),
100 dragEnabled (false),
101 autoOpen (true),
102 dropVisualizer (true),
103 dropHighlighter (false),
104 createChildren (true),
105 pressedOnSelected (false),
106 wasShiftEvent (false),
107 fullWidth (false),
108 sortAscending(true),
109 tabRename(true),
110 sortColumn(0),
111 selectionDirection(0),
112 tooltipColumn (0),
113 selectionMode (Single),
114//US contextMenuKey (KGlobalSettings::contextMenuKey()),
115//US showContextMenusOnPress (KGlobalSettings::showContextMenusOnPress()),
116 mDropVisualizerWidth (4)
117 {
118 renameable += 0;
119//US connect(editor, SIGNAL(done(QListViewItem*,int)), listview, SLOT(doneEditing(QListViewItem*,int)));
120 }
121
122 ~KListViewPrivate ()
123 {
124//US delete editor;
125 }
126
127 QListViewItem* pCurrentItem;
128
129 QTimer autoSelect;
130 int autoSelectDelay;
131
132 QTimer dragExpand;
133 QListViewItem* dragOverItem;
134 QPoint dragOverPoint;
135
136 QPoint startDragPos;
137 int dragDelay;
138
139//US KListViewLineEdit *editor;
140 QValueList<int> renameable;
141
142 bool cursorInExecuteArea:1;
143 bool bUseSingle:1;
144 bool bChangeCursorOverItem:1;
145 bool itemsMovable:1;
146 bool selectedBySimpleMove : 1;
147 bool selectedUsingMouse:1;
148 bool itemsRenameable:1;
149 bool validDrag:1;
150 bool dragEnabled:1;
151 bool autoOpen:1;
152 bool dropVisualizer:1;
153 bool dropHighlighter:1;
154 bool createChildren:1;
155 bool pressedOnSelected:1;
156 bool wasShiftEvent:1;
157 bool fullWidth:1;
158 bool sortAscending:1;
159 bool tabRename:1;
160
161 int sortColumn;
162
163 //+1 means downwards (y increases, -1 means upwards, 0 means not selected), aleXXX
164 int selectionDirection;
165 int tooltipColumn;
166
167 SelectionModeExt selectionMode;
168 int contextMenuKey;
169 bool showContextMenusOnPress;
170
171 QRect mOldDropVisualizer;
172 int mDropVisualizerWidth;
173 QRect mOldDropHighlighter;
174 QListViewItem *afterItemDrop;
175 QListViewItem *parentItemDrop;
176
177 QColor alternateBackground;
178};
179
180/*US
181KListViewLineEdit::KListViewLineEdit(KListView *parent)
182 : KLineEdit(parent->viewport()), item(0), col(0), p(parent)
183{
184 setFrame( false );
185 hide();
186 connect( parent, SIGNAL( selectionChanged() ), SLOT( slotSelectionChanged() ));
187}
188
189KListViewLineEdit::~KListViewLineEdit()
190{
191}
192
193void KListViewLineEdit::load(QListViewItem *i, int c)
194{
195 item=i;
196 col=c;
197
198 QRect rect(p->itemRect(i));
199 setText(item->text(c));
200
201 int fieldX = rect.x() - 1;
202 int fieldW = p->columnWidth(col) + 2;
203
204 int pos = p->header()->mapToIndex(col);
205 for ( int index = 0; index < pos; index++ )
206 fieldX += p->columnWidth( p->header()->mapToSection( index ));
207
208 if ( col == 0 ) {
209 int d = i->depth() + (p->rootIsDecorated() ? 1 : 0);
210 d *= p->treeStepSize();
211 fieldX += d;
212 fieldW -= d;
213 }
214
215 if ( i->pixmap( col ) ) {// add width of pixmap
216 int d = i->pixmap( col )->width();
217 fieldX += d;
218 fieldW -= d;
219 }
220
221 setGeometry(fieldX, rect.y() - 1, fieldW, rect.height() + 2);
222 show();
223 setFocus();
224}
225*/
226 /*Helper functions to for
227 *tabOrderedRename functionality.
228 */
229
230static int nextCol (KListView *pl, QListViewItem *pi, int start, int dir)
231{
232 if (pi)
233 {
234 //Find the next renameable column in the current row
235 for (; ((dir == +1) ? (start < pl->columns()) : (start >= 0)); start += dir)
236 if (pl->isRenameable(start))
237 return start;
238 }
239
240 return -1;
241}
242
243static QListViewItem *prevItem (QListViewItem *pi)
244{
245 QListViewItem *pa = pi->itemAbove();
246
247 /*Does what the QListViewItem::previousSibling()
248 *of my dreams would do.
249 */
250 if (pa && pa->parent() == pi->parent())
251 return pa;
252
253 return NULL;
254}
255
256static QListViewItem *lastQChild (QListViewItem *pi)
257{
258 if (pi)
259 {
260 /*Since there's no QListViewItem::lastChild().
261 *This finds the last sibling for the given
262 *item.
263 */
264 for (QListViewItem *pt = pi->nextSibling(); pt; pt = pt->nextSibling())
265 pi = pt;
266 }
267
268 return pi;
269}
270/*US
271void KListViewLineEdit::selectNextCell (QListViewItem *pitem, int column, bool forward)
272{
273 const int ncols = p->columns();
274 const int dir = forward ? +1 : -1;
275 const int restart = forward ? 0 : (ncols - 1);
276 QListViewItem *top = (pitem && pitem->parent())
277 ? pitem->parent()->firstChild()
278 : p->firstChild();
279 QListViewItem *pi = pitem;
280
281 terminate(); //Save current changes
282
283 do
284 {
285*/
286 /*Check the rest of the current row for an editable column,
287 *if that fails, check the entire next/previous row. The
288 *last case goes back to the first item in the current branch
289 *or the last item in the current branch depending on the
290 *direction.
291 */
292/*US
293 if ((column = nextCol(p, pi, column + dir, dir)) != -1 ||
294 (column = nextCol(p, (pi = (forward ? pi->nextSibling() : prevItem(pi))), restart, dir)) != -1 ||
295 (column = nextCol(p, (pi = (forward ? top : lastQChild(pitem))), restart, dir)) != -1)
296 {
297 if (pi)
298 {
299 p->setCurrentItem(pi); //Calls terminate
300 p->rename(pi, column);
301*/
302 /*Some listviews may override rename() to
303 *prevent certain items from being renamed,
304 *if this is done, [m_]item will be NULL
305 *after the rename() call... try again.
306 */
307/*US
308 if (!item)
309 continue;
310
311 break;
312 }
313 }
314 }
315 while (pi && !item);
316}
317*/
318
319/*US
320#ifdef KeyPress
321#undef KeyPress
322#endif
323
324bool KListViewLineEdit::event (QEvent *pe)
325{
326 if (pe->type() == QEvent::KeyPress)
327 {
328 QKeyEvent *k = (QKeyEvent *) pe;
329
330 if ((k->key() == Qt::Key_Backtab || k->key() == Qt::Key_Tab) &&
331 p->tabOrderedRenaming() && p->itemsRenameable() &&
332 !(k->state() & ControlButton || k->state() & AltButton))
333 {
334 selectNextCell(item, col,
335 (k->key() == Key_Tab && !(k->state() & ShiftButton)));
336 return true;
337 }
338 }
339
340 return KLineEdit::event(pe);
341}
342
343void KListViewLineEdit::keyPressEvent(QKeyEvent *e)
344{
345 if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter )
346 terminate(true);
347 else if(e->key() == Qt::Key_Escape)
348 terminate(false);
349 else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Up)
350 {
351 terminate(true);
352 KLineEdit::keyPressEvent(e);
353 }
354 else
355 KLineEdit::keyPressEvent(e);
356}
357
358void KListViewLineEdit::terminate()
359{
360 terminate(true);
361}
362
363void KListViewLineEdit::terminate(bool commit)
364{
365 if ( item )
366 {
367 //kdDebug() << "KListViewLineEdit::terminate " << commit << endl;
368 if (commit)
369 item->setText(col, text());
370 int c=col;
371 QListViewItem *i=item;
372 col=0;
373 item=0;
374 hide(); // will call focusOutEvent, that's why we set item=0 before
375 emit done(i,c);
376 }
377}
378
379void KListViewLineEdit::focusOutEvent(QFocusEvent *ev)
380{
381 QFocusEvent * focusEv = static_cast<QFocusEvent*>(ev);
382 // Don't let a RMB close the editor
383 if (focusEv->reason() != QFocusEvent::Popup && focusEv->reason() != QFocusEvent::ActiveWindow)
384 terminate(true);
385}
386
387void KListViewLineEdit::paintEvent( QPaintEvent *e )
388{
389 KLineEdit::paintEvent( e );
390
391 if ( !frame() ) {
392 QPainter p( this );
393 p.setClipRegion( e->region() );
394 p.drawRect( rect() );
395 }
396}
397
398// selection changed -> terminate. As our "item" can be already deleted,
399// we can't call terminate(false), because that would emit done() with
400// a dangling pointer to "item".
401void KListViewLineEdit::slotSelectionChanged()
402{
403 item = 0;
404 col = 0;
405 hide();
406}
407*/
408
409KListView::KListView( QWidget *parent, const char *name )
410 : QListView( parent, name ),
411 d (new KListViewPrivate (this))
412{
413#ifndef DESKTOP_VERSION
414 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
415#endif
416//US setDragAutoScroll(true);
417
418 connect( this, SIGNAL( onViewport() ),
419 this, SLOT( slotOnViewport() ) );
420 connect( this, SIGNAL( onItem( QListViewItem * ) ),
421 this, SLOT( slotOnItem( QListViewItem * ) ) );
422
423 connect (this, SIGNAL(contentsMoving(int,int)),
424 this, SLOT(cleanDropVisualizer()));
425 connect (this, SIGNAL(contentsMoving(int,int)),
426 this, SLOT(cleanItemHighlighter()));
427
428/*US
429 slotSettingsChanged(KApplication::SETTINGS_MOUSE);
430
431 if (kapp)
432 {
433 connect( kapp, SIGNAL( settingsChanged(int) ), SLOT( slotSettingsChanged(int) ) );
434 kapp->addKipcEventMask( KIPC::SettingsChanged );
435 }
436*/
437 slotSettingsChanged(1); //US do this to initialize the connections
438
439
440 connect(&d->autoSelect, SIGNAL( timeout() ),
441 this, SLOT( slotAutoSelect() ) );
442 connect(&d->dragExpand, SIGNAL( timeout() ),
443 this, SLOT( slotDragExpand() ) );
444
445 // context menu handling
446 if (d->showContextMenusOnPress)
447 {
448 connect (this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)),
449 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
450 }
451 else
452 {
453 connect (this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)),
454 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
455 }
456
457 connect (this, SIGNAL (menuShortCutPressed (KListView*, QListViewItem*)),
458 this, SLOT (emitContextMenu (KListView*, QListViewItem*)));
459
460
461 //qDebug("KListView::KListView make alternate color configurable");
462//US d->alternateBackground = KGlobalSettings::alternateBackgroundColor();
463 d->alternateBackground = QColor(240, 240, 240);
464}
465
466
467
468KListView::~KListView()
469{
470 delete d;
471}
472
473bool KListView::isExecuteArea( const QPoint& point )
474{
475 if ( itemAt( point ) )
476 return isExecuteArea( point.x() );
477
478 return false;
479}
480
481bool KListView::isExecuteArea( int x )
482{
483 if( allColumnsShowFocus() )
484 return true;
485 else {
486 int offset = 0;
487 int width = columnWidth( 0 );
488 int pos = header()->mapToIndex( 0 );
489
490 for ( int index = 0; index < pos; index++ )
491 offset += columnWidth( header()->mapToSection( index ) );
492
493 x += contentsX(); // in case of a horizontal scrollbar
494 return ( x > offset && x < ( offset + width ) );
495 }
496}
497
498void KListView::slotOnItem( QListViewItem *item )
499{
500 QPoint vp = viewport()->mapFromGlobal( QCursor::pos() );
501 if ( item && isExecuteArea( vp.x() ) && (d->autoSelectDelay > -1) && d->bUseSingle ) {
502 d->autoSelect.start( d->autoSelectDelay, true );
503 d->pCurrentItem = item;
504 }
505}
506
507void KListView::slotOnViewport()
508{
509 if ( d->bChangeCursorOverItem )
510 viewport()->unsetCursor();
511
512 d->autoSelect.stop();
513 d->pCurrentItem = 0L;
514}
515
516void KListView::slotSettingsChanged(int category)
517{
518qDebug("KListView::slotSettingsChanged has to be verified");
519/*US
520
521 switch (category)
522 {
523 case KApplication::SETTINGS_MOUSE:
524 d->dragDelay = KGlobalSettings::dndEventDelay();
525 d->bUseSingle = KGlobalSettings::singleClick();
526
527 disconnect(this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)),
528 this, SLOT (slotMouseButtonClicked (int, QListViewItem*, const QPoint &, int)));
529
530 if( d->bUseSingle )
531 connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)),
532 this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int)));
533
534 d->bChangeCursorOverItem = KGlobalSettings::changeCursorOverIcon();
535 d->autoSelectDelay = KGlobalSettings::autoSelectDelay();
536
537 if( !d->bUseSingle || !d->bChangeCursorOverItem )
538 viewport()->unsetCursor();
539
540 break;
541
542 case KApplication::SETTINGS_POPUPMENU:
543 d->contextMenuKey = KGlobalSettings::contextMenuKey ();
544 d->showContextMenusOnPress = KGlobalSettings::showContextMenusOnPress ();
545
546 if (d->showContextMenusOnPress)
547 {
548 disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
549
550 connect(this, SIGNAL (rightButtonPressed (QListViewItem*, const QPoint&, int)),
551 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
552 }
553 else
554 {
555 disconnect (0L, 0L, this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
556
557 connect(this, SIGNAL (rightButtonClicked (QListViewItem*, const QPoint&, int)),
558 this, SLOT (emitContextMenu (QListViewItem*, const QPoint&, int)));
559 }
560 break;
561
562 default:
563 break;
564 }
565*/
566
567 if( d->bUseSingle )
568 connect (this, SIGNAL (mouseButtonClicked (int, QListViewItem*, const QPoint &, int)),
569 this, SLOT (slotMouseButtonClicked( int, QListViewItem*, const QPoint &, int)));
570
571}
572
573void KListView::slotAutoSelect()
574{
575 // check that the item still exists
576 if( itemIndex( d->pCurrentItem ) == -1 )
577 return;
578
579 if (!isActiveWindow())
580 {
581 d->autoSelect.stop();
582 return;
583 }
584
585 //Give this widget the keyboard focus.
586 if( !hasFocus() )
587 setFocus();
588
589 QListViewItem* previousItem = currentItem();
590 setCurrentItem( d->pCurrentItem );
591
592#if 0
593#ifndef Q_WS_QWS
594 // FIXME(E): Implement for Qt Embedded
595 if( d->pCurrentItem ) {
596 //Shift pressed?
597 if( (keybstate & ShiftMask) ) {
598 bool block = signalsBlocked();
599 blockSignals( true );
600
601 //No Ctrl? Then clear before!
602 if( !(keybstate & ControlMask) )
603 clearSelection();
604
605 bool select = !d->pCurrentItem->isSelected();
606 bool update = viewport()->isUpdatesEnabled();
607 viewport()->setUpdatesEnabled( false );
608
609 bool down = previousItem->itemPos() < d->pCurrentItem->itemPos();
610 QListViewItemIterator lit( down ? previousItem : d->pCurrentItem );
611 for ( ; lit.current(); ++lit ) {
612 if ( down && lit.current() == d->pCurrentItem ) {
613 d->pCurrentItem->setSelected( select );
614 break;
615 }
616 if ( !down && lit.current() == previousItem ) {
617 previousItem->setSelected( select );
618 break;
619 }
620 lit.current()->setSelected( select );
621 }
622
623 blockSignals( block );
624 viewport()->setUpdatesEnabled( update );
625 triggerUpdate();
626
627 emit selectionChanged();
628
629 if( selectionMode() == QListView::Single )
630 emit selectionChanged( d->pCurrentItem );
631 }
632 else if( (keybstate & ControlMask) )
633 setSelected( d->pCurrentItem, !d->pCurrentItem->isSelected() );
634 else {
635 bool block = signalsBlocked();
636 blockSignals( true );
637
638 if( !d->pCurrentItem->isSelected() )
639 clearSelection();
640
641 blockSignals( block );
642
643 setSelected( d->pCurrentItem, true );
644 }
645 }
646 else
647 kdDebug() << "KListView::slotAutoSelect: Thats not supposed to happen!!!!" << endl;
648#endif
649#endif
650}
651
652void KListView::slotHeaderChanged()
653{
654 if (d->fullWidth && columns())
655 {
656 int w = 0;
657 for (int i = 0; i < columns() - 1; ++i) w += columnWidth(i);
658 setColumnWidth( columns() - 1, viewport()->width() - w - 1 );
659 }
660}
661
662void KListView::emitExecute( QListViewItem *item, const QPoint &pos, int c )
663{
664 if( isExecuteArea( viewport()->mapFromGlobal(pos) ) ) {
665
666 // Double click mode ?
667 if ( !d->bUseSingle )
668 {
669 emit executed( item );
670 emit executed( item, pos, c );
671 }
672 else
673 {
674#if 0
675#ifndef Q_WS_QWS
676 // FIXME(E): Implement for Qt Embedded
677 Window root;
678 Window child;
679 int root_x, root_y, win_x, win_y;
680 uint keybstate;
681 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
682 &root_x, &root_y, &win_x, &win_y, &keybstate );
683
684 d->autoSelect.stop();
685
686 //Dont emit executed if in SC mode and Shift or Ctrl are pressed
687 if( !( ((keybstate & ShiftMask) || (keybstate & ControlMask)) ) ) {
688 emit executed( item );
689 emit executed( item, pos, c );
690 }
691#endif
692#endif
693 }
694 }
695}
696
697void KListView::focusInEvent( QFocusEvent *fe )
698{
699 // kdDebug()<<"KListView::focusInEvent()"<<endl;
700 QListView::focusInEvent( fe );
701 if ((d->selectedBySimpleMove)
702 && (d->selectionMode == FileManager)
703 && (fe->reason()!=QFocusEvent::Popup)
704 && (fe->reason()!=QFocusEvent::ActiveWindow)
705 && (currentItem()!=0))
706 {
707 currentItem()->setSelected(true);
708 currentItem()->repaint();
709 emit selectionChanged();
710 };
711}
712
713void KListView::focusOutEvent( QFocusEvent *fe )
714{
715 cleanDropVisualizer();
716 cleanItemHighlighter();
717
718 d->autoSelect.stop();
719
720 if ((d->selectedBySimpleMove)
721 && (d->selectionMode == FileManager)
722 && (fe->reason()!=QFocusEvent::Popup)
723 && (fe->reason()!=QFocusEvent::ActiveWindow)
724 && (currentItem()!=0)
725/*US && (!d->editor->isVisible()) */
726 )
727 {
728 currentItem()->setSelected(false);
729 currentItem()->repaint();
730 emit selectionChanged();
731 };
732
733 QListView::focusOutEvent( fe );
734}
735
736void KListView::leaveEvent( QEvent *e )
737{
738 d->autoSelect.stop();
739
740 QListView::leaveEvent( e );
741}
742
743bool KListView::event( QEvent *e )
744{
745 if (e->type() == QEvent::ApplicationPaletteChange) {
746qDebug("KListView::event make alternate color configurable");
747//US d->alternateBackground=KGlobalSettings::alternateBackgroundColor();
748 d->alternateBackground = QColor(240, 240, 240);
749 }
750
751 return QListView::event(e);
752}
753
754void KListView::contentsMousePressEvent( QMouseEvent *e )
755{
756 if( (selectionModeExt() == Extended) && (e->state() & ShiftButton) && !(e->state() & ControlButton) )
757 {
758 bool block = signalsBlocked();
759 blockSignals( true );
760
761 clearSelection();
762
763 blockSignals( block );
764 }
765 else if ((selectionModeExt()==FileManager) && (d->selectedBySimpleMove))
766 {
767 d->selectedBySimpleMove=false;
768 d->selectedUsingMouse=true;
769 if (currentItem()!=0)
770 {
771 currentItem()->setSelected(false);
772 currentItem()->repaint();
773// emit selectionChanged();
774 };
775 };
776
777 QPoint p( contentsToViewport( e->pos() ) );
778 QListViewItem *at = itemAt (p);
779
780 // true if the root decoration of the item "at" was clicked (i.e. the +/- sign)
781 bool rootDecoClicked = at
782 && ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) +
783 treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() )
784 && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) );
785
786 if (e->button() == LeftButton && !rootDecoClicked)
787 {
788 //Start a drag
789 d->startDragPos = e->pos();
790
791 if (at)
792 {
793 d->validDrag = true;
794 d->pressedOnSelected = at->isSelected();
795 }
796 }
797
798 QListView::contentsMousePressEvent( e );
799}
800
801void KListView::contentsMouseMoveEvent( QMouseEvent *e )
802{
803 if (!dragEnabled() || d->startDragPos.isNull() || !d->validDrag) {
804 QListView::contentsMouseMoveEvent (e);
805 return;
806 }
807
808 QPoint vp = contentsToViewport(e->pos());
809 QListViewItem *item = itemAt( vp );
810
811 //do we process cursor changes at all?
812 if ( item && d->bChangeCursorOverItem && d->bUseSingle )
813 {
814 //Cursor moved on a new item or in/out the execute area
815 if( (item != d->pCurrentItem) ||
816 (isExecuteArea(vp) != d->cursorInExecuteArea) )
817 {
818 d->cursorInExecuteArea = isExecuteArea(vp);
819qDebug("KListView::contentsMouseMoveEvent drag&drop not supported yet");
820/*US
821 if( d->cursorInExecuteArea ) //cursor moved in execute area
822 viewport()->setCursor( KCursor::handCursor() );
823 else //cursor moved out of execute area
824 viewport()->unsetCursor();
825*/
826 }
827 }
828
829 bool dragOn = dragEnabled();
830 QPoint newPos = e->pos();
831 if (dragOn && d->validDrag &&
832 (newPos.x() > d->startDragPos.x()+d->dragDelay ||
833 newPos.x() < d->startDragPos.x()-d->dragDelay ||
834 newPos.y() > d->startDragPos.y()+d->dragDelay ||
835 newPos.y() < d->startDragPos.y()-d->dragDelay))
836 //(d->startDragPos - e->pos()).manhattanLength() > QApplication::startDragDistance())
837 {
838 QListView::contentsMouseReleaseEvent( 0 );
839 startDrag();
840 d->startDragPos = QPoint();
841 d->validDrag = false;
842 }
843}
844
845void KListView::contentsMouseReleaseEvent( QMouseEvent *e )
846{
847 if (e->button() == LeftButton)
848 {
849 // If the row was already selected, maybe we want to start an in-place editing
850 if ( d->pressedOnSelected && itemsRenameable() )
851 {
852 QPoint p( contentsToViewport( e->pos() ) );
853 QListViewItem *at = itemAt (p);
854 if ( at )
855 {
856 // true if the root decoration of the item "at" was clicked (i.e. the +/- sign)
857 bool rootDecoClicked =
858 ( p.x() <= header()->cellPos( header()->mapToActual( 0 ) ) +
859 treeStepSize() * ( at->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() )
860 && ( p.x() >= header()->cellPos( header()->mapToActual( 0 ) ) );
861
862 if (!rootDecoClicked)
863 {
864 int col = header()->mapToLogical( header()->cellAt( p.x() ) );
865 if ( d->renameable.contains(col) )
866 rename(at, col);
867 }
868 }
869 }
870
871 d->pressedOnSelected = false;
872 d->validDrag = false;
873 d->startDragPos = QPoint();
874 }
875 QListView::contentsMouseReleaseEvent( e );
876}
877
878void KListView::contentsMouseDoubleClickEvent ( QMouseEvent *e )
879{
880 // We don't want to call the parent method because it does setOpen,
881 // whereas we don't do it in single click mode... (David)
882 //QListView::contentsMouseDoubleClickEvent( e );
883
884 QPoint vp = contentsToViewport(e->pos());
885 QListViewItem *item = itemAt( vp );
886 emit QListView::doubleClicked( item ); // we do it now
887
888 int col = item ? header()->mapToLogical( header()->cellAt( vp.x() ) ) : -1;
889
890 if( item ) {
891 emit doubleClicked( item, e->globalPos(), col );
892
893 if( (e->button() == LeftButton) && !d->bUseSingle )
894 emitExecute( item, e->globalPos(), col );
895 }
896}
897
898void KListView::slotMouseButtonClicked( int btn, QListViewItem *item, const QPoint &pos, int c )
899{
900 if( (btn == LeftButton) && item )
901 emitExecute(item, pos, c);
902}
903
904void KListView::contentsDropEvent(QDropEvent* e)
905{
906qDebug("KListView::contentsDropEvent drag&drop not supported yet");
907/*US
908 cleanDropVisualizer();
909 cleanItemHighlighter();
910 d->dragExpand.stop();
911
912 if (acceptDrag (e))
913 {
914 e->acceptAction();
915 QListViewItem *afterme;
916 QListViewItem *parent;
917 findDrop(e->pos(), parent, afterme);
918
919 if (e->source() == viewport() && itemsMovable())
920 movableDropEvent(parent, afterme);
921 else
922 {
923
924 emit dropped(e, afterme);
925 emit dropped(this, e, afterme);
926 emit dropped(e, parent, afterme);
927 emit dropped(this, e, parent, afterme);
928
929 }
930 }
931*/
932
933}
934
935void KListView::movableDropEvent (QListViewItem* parent, QListViewItem* afterme)
936{
937 QPtrList<QListViewItem> items, afterFirsts, afterNows;
938 QListViewItem *current=currentItem();
939 bool hasMoved=false;
940 for (QListViewItem *i = firstChild(), *iNext=0; i != 0; i = iNext)
941 {
942 iNext=i->itemBelow();
943 if (!i->isSelected())
944 continue;
945
946 // don't drop an item after itself, or else
947 // it moves to the top of the list
948 if (i==afterme)
949 continue;
950
951 i->setSelected(false);
952
953 QListViewItem *afterFirst = i->itemAbove();
954
955 if (!hasMoved)
956 {
957 emit aboutToMove();
958 hasMoved=true;
959 }
960
961 moveItem(i, parent, afterme);
962
963 // ###### This should include the new parent !!! -> KDE 3.0
964 // If you need this right now, have a look at keditbookmarks.
965 emit moved(i, afterFirst, afterme);
966
967 items.append (i);
968 afterFirsts.append (afterFirst);
969 afterNows.append (afterme);
970
971 afterme = i;
972 }
973 clearSelection();
974 for (QListViewItem *i=items.first(); i != 0; i=items.next() )
975 i->setSelected(true);
976 if (current)
977 setCurrentItem(current);
978
979 emit moved(items,afterFirsts,afterNows);
980
981 if (firstChild())
982 emit moved();
983}
984
985void KListView::contentsDragMoveEvent(QDragMoveEvent *event)
986{
987qDebug("KListView::contentsDropEvent drag&drop not supported yet");
988/*US
989 if (acceptDrag(event))
990 {
991 event->acceptAction();
992 //Clean up the view
993
994 findDrop(event->pos(), d->parentItemDrop, d->afterItemDrop);
995 QPoint vp = contentsToViewport( event->pos() );
996 QListViewItem *item = isExecuteArea( vp ) ? itemAt( vp ) : 0L;
997
998 if ( item != d->dragOverItem )
999 {
1000 d->dragExpand.stop();
1001 d->dragOverItem = item;
1002 d->dragOverPoint = vp;
1003 if ( d->dragOverItem && d->dragOverItem->isExpandable() && !d->dragOverItem->isOpen() )
1004 d->dragExpand.start( QApplication::startDragTime(), true );
1005 }
1006 if (dropVisualizer())
1007 {
1008 QRect tmpRect = drawDropVisualizer(0, d->parentItemDrop, d->afterItemDrop);
1009 if (tmpRect != d->mOldDropVisualizer)
1010 {
1011 cleanDropVisualizer();
1012 d->mOldDropVisualizer=tmpRect;
1013 viewport()->repaint(tmpRect);
1014 }
1015 }
1016 if (dropHighlighter())
1017 {
1018 QRect tmpRect = drawItemHighlighter(0, d->afterItemDrop);
1019 if (tmpRect != d->mOldDropHighlighter)
1020 {
1021 cleanItemHighlighter();
1022 d->mOldDropHighlighter=tmpRect;
1023 viewport()->repaint(tmpRect);
1024 }
1025 }
1026 }
1027 else
1028 event->ignore();
1029*/
1030}
1031
1032void KListView::slotDragExpand()
1033{
1034 if ( itemAt( d->dragOverPoint ) == d->dragOverItem )
1035 d->dragOverItem->setOpen( true );
1036}
1037
1038void KListView::contentsDragLeaveEvent (QDragLeaveEvent*)
1039{
1040 d->dragExpand.stop();
1041 cleanDropVisualizer();
1042 cleanItemHighlighter();
1043}
1044
1045void KListView::cleanDropVisualizer()
1046{
1047 if (d->mOldDropVisualizer.isValid())
1048 {
1049 QRect rect=d->mOldDropVisualizer;
1050 d->mOldDropVisualizer = QRect();
1051 viewport()->repaint(rect, true);
1052 }
1053}
1054
1055int KListView::depthToPixels( int depth )
1056{
1057 return treeStepSize() * ( depth + (rootIsDecorated() ? 1 : 0) ) + itemMargin();
1058}
1059
1060void KListView::findDrop(const QPoint &pos, QListViewItem *&parent, QListViewItem *&after)
1061{
1062 QPoint p (contentsToViewport(pos));
1063
1064 // Get the position to put it in
1065 QListViewItem *atpos = itemAt(p);
1066
1067 QListViewItem *above;
1068 if (!atpos) // put it at the end
1069 above = lastItem();
1070 else
1071 {
1072 // Get the closest item before us ('atpos' or the one above, if any)
1073 if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2))
1074 above = atpos->itemAbove();
1075 else
1076 above = atpos;
1077 }
1078
1079 if (above)
1080 {
1081 // Now, we know we want to go after "above". But as a child or as a sibling ?
1082 // We have to ask the "above" item if it accepts children.
1083 if (above->isExpandable())
1084 {
1085 // The mouse is sufficiently on the right ? - doesn't matter if 'above' has visible children
1086 if (p.x() >= depthToPixels( above->depth() + 1 ) ||
1087 (above->isOpen() && above->childCount() > 0) )
1088 {
1089 parent = above;
1090 after = 0L;
1091 return;
1092 }
1093 }
1094
1095 // Ok, there's one more level of complexity. We may want to become a new
1096 // sibling, but of an upper-level group, rather than the "above" item
1097 QListViewItem * betterAbove = above->parent();
1098 QListViewItem * last = above;
1099 while ( betterAbove )
1100 {
1101 // We are allowed to become a sibling of "betterAbove" only if we are
1102 // after its last child
1103 if ( last->nextSibling() == 0 )
1104 {
1105 if (p.x() < depthToPixels ( betterAbove->depth() + 1 ))
1106 above = betterAbove; // store this one, but don't stop yet, there may be a better one
1107 else
1108 break; // not enough on the left, so stop
1109 last = betterAbove;
1110 betterAbove = betterAbove->parent(); // up one level
1111 } else
1112 break; // we're among the child of betterAbove, not after the last one
1113 }
1114 }
1115 // set as sibling
1116 after = above;
1117 parent = after ? after->parent() : 0L ;
1118}
1119
1120QListViewItem* KListView::lastChild () const
1121{
1122 QListViewItem* lastchild = firstChild();
1123
1124 if (lastchild)
1125 for (; lastchild->nextSibling(); lastchild = lastchild->nextSibling());
1126
1127 return lastchild;
1128}
1129
1130QListViewItem *KListView::lastItem() const
1131{
1132 QListViewItem* last = lastChild();
1133
1134 for (QListViewItemIterator it (last); it.current(); ++it)
1135 last = it.current();
1136
1137 return last;
1138}
1139
1140KLineEdit *KListView::renameLineEdit() const
1141{
1142//US return d->editor;
1143qDebug("KListView::renameLineEdit returns 0. Might crash");
1144return 0;
1145}
1146
1147void KListView::startDrag()
1148{
1149qDebug("KListView::startDrag drag&drop not supported yet.");
1150/*US
1151 QDragObject *drag = dragObject();
1152
1153 if (!drag)
1154 return;
1155
1156 if (drag->drag() && drag->target() != viewport())
1157 emit moved();
1158*/
1159}
1160
1161QDragObject *KListView::dragObject()
1162{
1163 if (!currentItem())
1164 return 0;
1165
1166 return new QStoredDrag("application/x-qlistviewitem", viewport());
1167}
1168
1169void KListView::setItemsMovable(bool b)
1170{
1171 d->itemsMovable=b;
1172}
1173
1174bool KListView::itemsMovable() const
1175{
1176 return d->itemsMovable;
1177}
1178
1179void KListView::setItemsRenameable(bool b)
1180{
1181 d->itemsRenameable=b;
1182}
1183
1184bool KListView::itemsRenameable() const
1185{
1186 return d->itemsRenameable;
1187}
1188
1189
1190void KListView::setDragEnabled(bool b)
1191{
1192 d->dragEnabled=b;
1193}
1194
1195bool KListView::dragEnabled() const
1196{
1197 return d->dragEnabled;
1198}
1199
1200void KListView::setAutoOpen(bool b)
1201{
1202 d->autoOpen=b;
1203}
1204
1205bool KListView::autoOpen() const
1206{
1207 return d->autoOpen;
1208}
1209
1210bool KListView::dropVisualizer() const
1211{
1212 return d->dropVisualizer;
1213}
1214
1215void KListView::setDropVisualizer(bool b)
1216{
1217 d->dropVisualizer=b;
1218}
1219
1220QPtrList<QListViewItem> KListView::selectedItems() const
1221{
1222 QPtrList<QListViewItem> list;
1223 for (QListViewItem *i=firstChild(); i!=0; i=i->itemBelow())
1224 if (i->isSelected()) list.append(i);
1225 return list;
1226}
1227
1228
1229void KListView::moveItem(QListViewItem *item, QListViewItem *parent, QListViewItem *after)
1230{
1231 // sanity check - don't move a item into it's own child structure
1232 QListViewItem *i = parent;
1233 while(i)
1234 {
1235 if(i == item)
1236 return;
1237 i = i->parent();
1238 }
1239
1240 // Basically reimplementing the QListViewItem(QListViewItem*, QListViewItem*) constructor
1241 // in here, without ever deleting the item.
1242 if (item->parent())
1243 item->parent()->takeItem(item);
1244 else
1245 takeItem(item);
1246
1247 if (parent)
1248 parent->insertItem(item);
1249 else
1250 insertItem(item);
1251
1252 if (after)
1253 ;//item->moveToJustAfter(after);
1254}
1255
1256void KListView::contentsDragEnterEvent(QDragEnterEvent *event)
1257{
1258qDebug("KListView::contentsDragEnterEvent drag&drop not supported yet.");
1259/*US
1260 if (acceptDrag (event))
1261 event->accept();
1262*/
1263}
1264
1265void KListView::setDropVisualizerWidth (int w)
1266{
1267 d->mDropVisualizerWidth = w > 0 ? w : 1;
1268}
1269
1270QRect KListView::drawDropVisualizer(QPainter *p, QListViewItem *parent,
1271 QListViewItem *after)
1272{
1273 QRect insertmarker;
1274
1275 if (!after && !parent)
1276 insertmarker = QRect (0, 0, viewport()->width(), d->mDropVisualizerWidth/2);
1277 else
1278 {
1279 int level = 0;
1280 if (after)
1281 {
1282 QListViewItem* it = 0L;
1283 if (after->isOpen())
1284 {
1285 // Look for the last child (recursively)
1286 it = after->firstChild();
1287 if (it)
1288 while (it->nextSibling() || it->firstChild())
1289 if ( it->nextSibling() )
1290 it = it->nextSibling();
1291 else
1292 it = it->firstChild();
1293 }
1294
1295 insertmarker = itemRect (it ? it : after);
1296 level = after->depth();
1297 }
1298 else if (parent)
1299 {
1300 insertmarker = itemRect (parent);
1301 level = parent->depth() + 1;
1302 }
1303 insertmarker.setLeft( treeStepSize() * ( level + (rootIsDecorated() ? 1 : 0) ) + itemMargin() );
1304 insertmarker.setRight (viewport()->width());
1305 insertmarker.setTop (insertmarker.bottom() - d->mDropVisualizerWidth/2 + 1);
1306 insertmarker.setBottom (insertmarker.bottom() + d->mDropVisualizerWidth/2);
1307 }
1308
1309 // This is not used anymore, at least by KListView itself (see viewportPaintEvent)
1310 // Remove for KDE 3.0.
1311 if (p)
1312 p->fillRect(insertmarker, Dense4Pattern);
1313
1314 return insertmarker;
1315}
1316
1317QRect KListView::drawItemHighlighter(QPainter *painter, QListViewItem *item)
1318{
1319 QRect r;
1320
1321 if (item)
1322 {
1323 r = itemRect(item);
1324 r.setLeft(r.left()+(item->depth()+1)*treeStepSize());
1325 if (painter) {
1326//US style().drawPrimitive(QStyle::PE_FocusRect, painter, r, colorGroup(),
1327//US QStyle::Style_FocusAtBorder, colorGroup().highlight());
1328 const QColor* pHighl = &(colorGroup().highlight());
1329 //LR style().drawFocusRect(painter, r, colorGroup(), pHighl, true);
1330
1331qDebug("KListView::drawItemHighlighter has to be verified");
1332
1333 }
1334
1335 }
1336
1337 return r;
1338}
1339
1340void KListView::cleanItemHighlighter ()
1341{
1342 if (d->mOldDropHighlighter.isValid())
1343 {
1344 QRect rect=d->mOldDropHighlighter;
1345 d->mOldDropHighlighter = QRect();
1346 viewport()->repaint(rect, true);
1347 }
1348}
1349
1350void KListView::rename(QListViewItem *item, int c)
1351{
1352 if (d->renameable.contains(c))
1353 {
1354 ensureItemVisible(item);
1355//US d->editor->load(item,c);
1356qDebug("KListView::rename has to be verified");
1357
1358 }
1359}
1360
1361bool KListView::isRenameable (int col) const
1362{
1363 return d->renameable.contains(col);
1364}
1365
1366void KListView::setRenameable (int col, bool yesno)
1367{
1368 if (col>=header()->count()) return;
1369
1370 d->renameable.remove(col);
1371 if (yesno && d->renameable.find(col)==d->renameable.end())
1372 d->renameable+=col;
1373 else if (!yesno && d->renameable.find(col)!=d->renameable.end())
1374 d->renameable.remove(col);
1375}
1376
1377void KListView::doneEditing(QListViewItem *item, int row)
1378{
1379 emit itemRenamed(item, item->text(row), row);
1380 emit itemRenamed(item);
1381}
1382
1383bool KListView::acceptDrag(QDropEvent* e) const
1384{
1385qDebug("KListView::acceptDrag drag&drop not supported yet");
1386//US return acceptDrops() && itemsMovable() && (e->source()==viewport());
1387return false;
1388}
1389
1390void KListView::setCreateChildren(bool b)
1391{
1392 d->createChildren=b;
1393}
1394
1395bool KListView::createChildren() const
1396{
1397 return d->createChildren;
1398}
1399
1400
1401int KListView::tooltipColumn() const
1402{
1403 return d->tooltipColumn;
1404}
1405
1406void KListView::setTooltipColumn(int column)
1407{
1408 d->tooltipColumn=column;
1409}
1410
1411void KListView::setDropHighlighter(bool b)
1412{
1413 d->dropHighlighter=b;
1414}
1415
1416bool KListView::dropHighlighter() const
1417{
1418 return d->dropHighlighter;
1419}
1420
1421bool KListView::showTooltip(QListViewItem *item, const QPoint &, int column) const
1422{
1423 return ((tooltip(item, column).length()>0) && (column==tooltipColumn()));
1424}
1425
1426QString KListView::tooltip(QListViewItem *item, int column) const
1427{
1428 return item->text(column);
1429}
1430
1431void KListView::setTabOrderedRenaming(bool b)
1432{
1433 d->tabRename = b;
1434}
1435
1436bool KListView::tabOrderedRenaming() const
1437{
1438 return d->tabRename;
1439}
1440
1441void KListView::keyPressEvent (QKeyEvent* e)
1442{
1443 //don't we need a contextMenuModifier too ? (aleXXX)
1444 if (e->key() == d->contextMenuKey)
1445 {
1446 emit menuShortCutPressed (this, currentItem());
1447 return;
1448 }
1449 if (e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace)
1450 {
1451 emit signalDelete ( );
1452 return;
1453 }
1454
1455 if (d->selectionMode != FileManager)
1456 QListView::keyPressEvent (e);
1457 else
1458 fileManagerKeyPressEvent (e);
1459}
1460
1461void KListView::activateAutomaticSelection()
1462{
1463 d->selectedBySimpleMove=true;
1464 d->selectedUsingMouse=false;
1465 if (currentItem()!=0)
1466 {
1467 selectAll(false);
1468 currentItem()->setSelected(true);
1469 currentItem()->repaint();
1470 emit selectionChanged();
1471 };
1472}
1473
1474void KListView::deactivateAutomaticSelection()
1475{
1476 d->selectedBySimpleMove=false;
1477}
1478
1479bool KListView::automaticSelection() const
1480{
1481 return d->selectedBySimpleMove;
1482}
1483
1484void KListView::fileManagerKeyPressEvent (QKeyEvent* e)
1485{
1486 //don't care whether it's on the keypad or not
1487 int e_state=(e->state() & ~Keypad);
1488
1489 int oldSelectionDirection(d->selectionDirection);
1490
1491 if ((e->key()!=Key_Shift) && (e->key()!=Key_Control)
1492 && (e->key()!=Key_Meta) && (e->key()!=Key_Alt))
1493 {
1494 if ((e_state==ShiftButton) && (!d->wasShiftEvent) && (!d->selectedBySimpleMove))
1495 selectAll(FALSE);
1496 d->selectionDirection=0;
1497 d->wasShiftEvent = (e_state == ShiftButton);
1498 };
1499
1500 //d->wasShiftEvent = (e_state == ShiftButton);
1501
1502
1503 QListViewItem* item = currentItem();
1504 if (item==0) return;
1505
1506 QListViewItem* repaintItem1 = item;
1507 QListViewItem* repaintItem2 = 0L;
1508 QListViewItem* visItem = 0L;
1509
1510 QListViewItem* nextItem = 0L;
1511 int items = 0;
1512
1513 bool shiftOrCtrl((e_state==ControlButton) || (e_state==ShiftButton));
1514 int selectedItems(0);
1515 for (QListViewItem *tmpItem=firstChild(); tmpItem!=0; tmpItem=tmpItem->nextSibling())
1516 if (tmpItem->isSelected()) selectedItems++;
1517
1518 if (((selectedItems==0) || ((selectedItems==1) && (d->selectedUsingMouse)))
1519 && (e_state==NoButton)
1520 && ((e->key()==Key_Down)
1521 || (e->key()==Key_Up)
1522 || (e->key()==Key_Next)
1523 || (e->key()==Key_Prior)
1524 || (e->key()==Key_Home)
1525 || (e->key()==Key_End)))
1526 {
1527 d->selectedBySimpleMove=true;
1528 d->selectedUsingMouse=false;
1529 }
1530 else if (selectedItems>1)
1531 d->selectedBySimpleMove=false;
1532
1533 bool emitSelectionChanged(false);
1534
1535 switch (e->key())
1536 {
1537 case Key_Escape:
1538 selectAll(FALSE);
1539 emitSelectionChanged=TRUE;
1540 break;
1541
1542 case Key_Space:
1543 //toggle selection of current item
1544 if (d->selectedBySimpleMove)
1545 d->selectedBySimpleMove=false;
1546 item->setSelected(!item->isSelected());
1547 emitSelectionChanged=TRUE;
1548 break;
1549
1550 case Key_Insert:
1551 //toggle selection of current item and move to the next item
1552 if (d->selectedBySimpleMove)
1553 {
1554 d->selectedBySimpleMove=false;
1555 if (!item->isSelected()) item->setSelected(TRUE);
1556 }
1557 else
1558 {
1559 item->setSelected(!item->isSelected());
1560 };
1561
1562 nextItem=item->itemBelow();
1563
1564 if (nextItem!=0)
1565 {
1566 repaintItem2=nextItem;
1567 visItem=nextItem;
1568 setCurrentItem(nextItem);
1569 };
1570 d->selectionDirection=1;
1571 emitSelectionChanged=TRUE;
1572 break;
1573
1574 case Key_Down:
1575 nextItem=item->itemBelow();
1576 //toggle selection of current item and move to the next item
1577 if (shiftOrCtrl)
1578 {
1579 d->selectionDirection=1;
1580 if (d->selectedBySimpleMove)
1581 d->selectedBySimpleMove=false;
1582 else
1583 {
1584 if (oldSelectionDirection!=-1)
1585 {
1586 item->setSelected(!item->isSelected());
1587 emitSelectionChanged=TRUE;
1588 };
1589 };
1590 }
1591 else if ((d->selectedBySimpleMove) && (nextItem!=0))
1592 {
1593 item->setSelected(false);
1594 emitSelectionChanged=TRUE;
1595 };
1596
1597 if (nextItem!=0)
1598 {
1599 if (d->selectedBySimpleMove)
1600 nextItem->setSelected(true);
1601 repaintItem2=nextItem;
1602 visItem=nextItem;
1603 setCurrentItem(nextItem);
1604 };
1605 break;
1606
1607 case Key_Up:
1608 nextItem=item->itemAbove();
1609 d->selectionDirection=-1;
1610 //move to the prev. item and toggle selection of this one
1611 // => No, can't select the last item, with this. For symmetry, let's
1612 // toggle selection and THEN move up, just like we do in down (David)
1613 if (shiftOrCtrl)
1614 {
1615 if (d->selectedBySimpleMove)
1616 d->selectedBySimpleMove=false;
1617 else
1618 {
1619 if (oldSelectionDirection!=1)
1620 {
1621 item->setSelected(!item->isSelected());
1622 emitSelectionChanged=TRUE;
1623 };
1624 }
1625 }
1626 else if ((d->selectedBySimpleMove) && (nextItem!=0))
1627 {
1628 item->setSelected(false);
1629 emitSelectionChanged=TRUE;
1630 };
1631
1632 if (nextItem!=0)
1633 {
1634 if (d->selectedBySimpleMove)
1635 nextItem->setSelected(true);
1636 repaintItem2=nextItem;
1637 visItem=nextItem;
1638 setCurrentItem(nextItem);
1639 };
1640 break;
1641
1642 case Key_End:
1643 //move to the last item and toggle selection of all items inbetween
1644 nextItem=item;
1645 if (d->selectedBySimpleMove)
1646 item->setSelected(false);
1647 if (shiftOrCtrl)
1648 d->selectedBySimpleMove=false;
1649
1650 while(nextItem!=0)
1651 {
1652 if (shiftOrCtrl)
1653 nextItem->setSelected(!nextItem->isSelected());
1654 if (nextItem->itemBelow()==0)
1655 {
1656 if (d->selectedBySimpleMove)
1657 nextItem->setSelected(true);
1658 repaintItem2=nextItem;
1659 visItem=nextItem;
1660 setCurrentItem(nextItem);
1661 }
1662 nextItem=nextItem->itemBelow();
1663 }
1664 emitSelectionChanged=TRUE;
1665 break;
1666
1667 case Key_Home:
1668 // move to the first item and toggle selection of all items inbetween
1669 nextItem = firstChild();
1670 visItem = nextItem;
1671 repaintItem2 = visItem;
1672 if (d->selectedBySimpleMove)
1673 item->setSelected(false);
1674 if (shiftOrCtrl)
1675 {
1676 d->selectedBySimpleMove=false;
1677
1678 while ( nextItem != item )
1679 {
1680 nextItem->setSelected( !nextItem->isSelected() );
1681 nextItem = nextItem->itemBelow();
1682 }
1683 item->setSelected( !item->isSelected() );
1684 }
1685 setCurrentItem( firstChild() );
1686 emitSelectionChanged=TRUE;
1687 break;
1688
1689 case Key_Next:
1690 items=visibleHeight()/item->height();
1691 nextItem=item;
1692 if (d->selectedBySimpleMove)
1693 item->setSelected(false);
1694 if (shiftOrCtrl)
1695 {
1696 d->selectedBySimpleMove=false;
1697 d->selectionDirection=1;
1698 };
1699
1700 for (int i=0; i<items; i++)
1701 {
1702 if (shiftOrCtrl)
1703 nextItem->setSelected(!nextItem->isSelected());
1704 //the end
1705 if ((i==items-1) || (nextItem->itemBelow()==0))
1706
1707 {
1708 if (shiftOrCtrl)
1709 nextItem->setSelected(!nextItem->isSelected());
1710 if (d->selectedBySimpleMove)
1711 nextItem->setSelected(true);
1712 ensureItemVisible(nextItem);
1713 setCurrentItem(nextItem);
1714 update();
1715 if ((shiftOrCtrl) || (d->selectedBySimpleMove))
1716 {
1717 emit selectionChanged();
1718 }
1719 return;
1720 }
1721 nextItem=nextItem->itemBelow();
1722 }
1723 break;
1724
1725 case Key_Prior:
1726 items=visibleHeight()/item->height();
1727 nextItem=item;
1728 if (d->selectedBySimpleMove)
1729 item->setSelected(false);
1730 if (shiftOrCtrl)
1731 {
1732 d->selectionDirection=-1;
1733 d->selectedBySimpleMove=false;
1734 };
1735
1736 for (int i=0; i<items; i++)
1737 {
1738 if ((nextItem!=item) &&(shiftOrCtrl))
1739 nextItem->setSelected(!nextItem->isSelected());
1740 //the end
1741 if ((i==items-1) || (nextItem->itemAbove()==0))
1742
1743 {
1744 if (d->selectedBySimpleMove)
1745 nextItem->setSelected(true);
1746 ensureItemVisible(nextItem);
1747 setCurrentItem(nextItem);
1748 update();
1749 if ((shiftOrCtrl) || (d->selectedBySimpleMove))
1750 {
1751 emit selectionChanged();
1752 }
1753 return;
1754 }
1755 nextItem=nextItem->itemAbove();
1756 }
1757 break;
1758
1759 case Key_Minus:
1760 if ( item->isOpen() )
1761 setOpen( item, FALSE );
1762 break;
1763 case Key_Plus:
1764 if ( !item->isOpen() && (item->isExpandable() || item->childCount()) )
1765 setOpen( item, TRUE );
1766 break;
1767 default:
1768 bool realKey = ((e->key()!=Key_Shift) && (e->key()!=Key_Control)
1769 && (e->key()!=Key_Meta) && (e->key()!=Key_Alt));
1770
1771 bool selectCurrentItem = (d->selectedBySimpleMove) && (item->isSelected());
1772 if (realKey && selectCurrentItem)
1773 item->setSelected(false);
1774 //this is mainly for the "goto filename beginning with pressed char" feature (aleXXX)
1775 QListView::SelectionMode oldSelectionMode = selectionMode();
1776 setSelectionMode (QListView::Multi);
1777 QListView::keyPressEvent (e);
1778 setSelectionMode (oldSelectionMode);
1779 if (realKey && selectCurrentItem)
1780 {
1781 currentItem()->setSelected(true);
1782 emitSelectionChanged=TRUE;
1783 }
1784 repaintItem2=currentItem();
1785 if (realKey)
1786 visItem=currentItem();
1787 break;
1788 }
1789
1790 if (visItem)
1791 ensureItemVisible(visItem);
1792
1793 QRect ir;
1794 if (repaintItem1)
1795 ir = ir.unite( itemRect(repaintItem1) );
1796 if (repaintItem2)
1797 ir = ir.unite( itemRect(repaintItem2) );
1798
1799 if ( !ir.isEmpty() )
1800 { // rectangle to be repainted
1801 if ( ir.x() < 0 )
1802 ir.moveBy( -ir.x(), 0 );
1803 viewport()->repaint( ir, FALSE );
1804 }
1805 /*if (repaintItem1)
1806 repaintItem1->repaint();
1807 if (repaintItem2)
1808 repaintItem2->repaint();*/
1809 update();
1810 if (emitSelectionChanged)
1811 emit selectionChanged();
1812}
1813
1814void KListView::setSelectionModeExt (SelectionModeExt mode)
1815{
1816 d->selectionMode = mode;
1817
1818 switch (mode)
1819 {
1820 case Single:
1821 case Multi:
1822 case Extended:
1823 case NoSelection:
1824 setSelectionMode (static_cast<QListView::SelectionMode>(static_cast<int>(mode)));
1825 break;
1826
1827 case FileManager:
1828 setSelectionMode (QListView::Extended);
1829 break;
1830
1831 default:
1832 kdWarning () << "Warning: illegal selection mode " << int(mode) << " set!" << endl;
1833 break;
1834 }
1835}
1836
1837KListView::SelectionModeExt KListView::selectionModeExt () const
1838{
1839 return d->selectionMode;
1840}
1841
1842int KListView::itemIndex( const QListViewItem *item ) const
1843{
1844 if ( !item )
1845 return -1;
1846
1847 if ( item == firstChild() )
1848 return 0;
1849 else {
1850 QListViewItemIterator it(firstChild());
1851 uint j = 0;
1852 for (; it.current() && it.current() != item; ++it, ++j );
1853
1854 if( !it.current() )
1855 return -1;
1856
1857 return j;
1858 }
1859}
1860
1861QListViewItem* KListView::itemAtIndex(int index)
1862{
1863 if (index<0)
1864 return 0;
1865
1866 int j(0);
1867 for (QListViewItemIterator it=firstChild(); it.current(); it++)
1868 {
1869 if (j==index)
1870 return it.current();
1871 j++;
1872 };
1873 return 0;
1874}
1875
1876
1877void KListView::emitContextMenu (KListView*, QListViewItem* i)
1878{
1879 QPoint p;
1880 qDebug("KListView::emitContextMenu ");
1881
1882 if (i)
1883 p = viewport()->mapToGlobal(itemRect(i).center());
1884 else
1885 p = mapToGlobal(rect().center());
1886
1887 emit contextMenu (this, i, p);
1888}
1889
1890void KListView::emitContextMenu (QListViewItem* i, const QPoint& p, int)
1891{
1892 qDebug("KListView::emitContextMenu ");
1893 emit contextMenu (this, i, p);
1894}
1895
1896void KListView::setAcceptDrops (bool val)
1897{
1898 QListView::setAcceptDrops (val);
1899 viewport()->setAcceptDrops (val);
1900}
1901
1902int KListView::dropVisualizerWidth () const
1903{
1904 return d->mDropVisualizerWidth;
1905}
1906
1907
1908void KListView::viewportPaintEvent(QPaintEvent *e)
1909{
1910 QListView::viewportPaintEvent(e);
1911
1912 if (d->mOldDropVisualizer.isValid() && e->rect().intersects(d->mOldDropVisualizer))
1913 {
1914 QPainter painter(viewport());
1915
1916 // This is where we actually draw the drop-visualizer
1917 painter.fillRect(d->mOldDropVisualizer, Dense4Pattern);
1918 }
1919 if (d->mOldDropHighlighter.isValid() && e->rect().intersects(d->mOldDropHighlighter))
1920 {
1921 QPainter painter(viewport());
1922
1923qDebug("KListView::viewportPaintEvent has to be verified");
1924
1925 // This is where we actually draw the drop-highlighter
1926//US style().drawPrimitive(QStyle::PE_FocusRect, &painter, d->mOldDropHighlighter, colorGroup(),
1927//US QStyle::Style_FocusAtBorder);
1928
1929//LR style().drawFocusRect(&painter, d->mOldDropHighlighter, colorGroup(), (const QColor*)0, true);
1930
1931
1932 }
1933}
1934
1935void KListView::setFullWidth()
1936{
1937 setFullWidth(true);
1938}
1939
1940void KListView::setFullWidth(bool fullWidth)
1941{
1942 d->fullWidth = fullWidth;
1943//US header()->setStretchEnabled(fullWidth, columns()-1);
1944}
1945
1946bool KListView::fullWidth() const
1947{
1948 return d->fullWidth;
1949}
1950
1951int KListView::addColumn(const QString& label, int width)
1952{
1953 int result = QListView::addColumn(label, width);
1954 if (d->fullWidth) {
1955//US header()->setStretchEnabled(false, columns()-2);
1956//US header()->setStretchEnabled(true, columns()-1);
1957 }
1958 return result;
1959}
1960
1961int KListView::addColumn(const QIconSet& iconset, const QString& label, int width)
1962{
1963 int result = QListView::addColumn(iconset, label, width);
1964 if (d->fullWidth) {
1965//US header()->setStretchEnabled(false, columns()-2);
1966//US header()->setStretchEnabled(true, columns()-1);
1967 }
1968 return result;
1969}
1970
1971void KListView::removeColumn(int index)
1972{
1973 QListView::removeColumn(index);
1974//US if (d->fullWidth && index == columns()) header()->setStretchEnabled(true, columns()-1);
1975}
1976
1977void KListView::viewportResizeEvent(QResizeEvent* e)
1978{
1979 QListView::viewportResizeEvent(e);
1980}
1981
1982const QColor &KListView::alternateBackground() const
1983{
1984 return d->alternateBackground;
1985}
1986
1987void KListView::setAlternateBackground(const QColor &c)
1988{
1989 d->alternateBackground = c;
1990 repaint();
1991}
1992
1993void KListView::saveLayout(KConfig *config, const QString &group) const
1994{
1995 KConfigGroupSaver saver(config, group);
1996 QStringList widths, order;
1997 for (int i = 0; i < columns(); ++i)
1998 {
1999 widths << QString::number(columnWidth(i));
2000 order << QString::number(header()->mapToIndex(i));
2001 }
2002 config->writeEntry("ColumnWidths", widths);
2003 config->writeEntry("ColumnOrder", order);
2004 config->writeEntry("SortColumn", d->sortColumn);
2005 config->writeEntry("SortAscending", d->sortAscending);
2006}
2007
2008void KListView::restoreLayout(KConfig *config, const QString &group)
2009{
2010 KConfigGroupSaver saver(config, group);
2011 QStringList cols = config->readListEntry("ColumnWidths");
2012 int i = 0;
2013 for (QStringList::ConstIterator it = cols.begin(); it != cols.end(); ++it)
2014 setColumnWidth(i++, (*it).toInt());
2015
2016 cols = config->readListEntry("ColumnOrder");
2017 i = 0;
2018 for (QStringList::ConstIterator it = cols.begin(); it != cols.end(); ++it)
2019 header()->moveSection(i++, (*it).toInt());
2020
2021/*US I changed the following code, because hasKey is not available.
2022!!! check if my version is correct
2023 if (config->hasKey("SortColumn"))
2024 setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true));
2025*/
2026 QStringList langLst = config->readListEntry( "SortColumn" );
2027 if (!langLst.isEmpty())
2028 setSorting(config->readNumEntry("SortColumn"), config->readBoolEntry("SortAscending", true));
2029}
2030
2031void KListView::setSorting(int column, bool ascending)
2032{
2033 d->sortColumn = column;
2034 d->sortAscending = ascending;
2035 QListView::setSorting(column, ascending);
2036}
2037
2038int KListView::columnSorted(void) const
2039{
2040 return d->sortColumn;
2041}
2042
2043bool KListView::ascendingSort(void) const
2044{
2045 return d->sortAscending;
2046}
2047
2048KListViewItem::KListViewItem(QListView *parent)
2049 : QListViewItem(parent)
2050{
2051 init();
2052}
2053
2054KListViewItem::KListViewItem(QListViewItem *parent)
2055 : QListViewItem(parent)
2056{
2057 init();
2058}
2059
2060KListViewItem::KListViewItem(QListView *parent, QListViewItem *after)
2061 : QListViewItem(parent, after)
2062{
2063 init();
2064}
2065
2066KListViewItem::KListViewItem(QListViewItem *parent, QListViewItem *after)
2067 : QListViewItem(parent, after)
2068{
2069 init();
2070}
2071
2072KListViewItem::KListViewItem(QListView *parent,
2073 QString label1, QString label2, QString label3, QString label4,
2074 QString label5, QString label6, QString label7, QString label8)
2075 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
2076{
2077 init();
2078}
2079
2080KListViewItem::KListViewItem(QListViewItem *parent,
2081 QString label1, QString label2, QString label3, QString label4,
2082 QString label5, QString label6, QString label7, QString label8)
2083 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
2084{
2085 init();
2086}
2087
2088KListViewItem::KListViewItem(QListView *parent, QListViewItem *after,
2089 QString label1, QString label2, QString label3, QString label4,
2090 QString label5, QString label6, QString label7, QString label8)
2091 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
2092{
2093 init();
2094}
2095
2096KListViewItem::KListViewItem(QListViewItem *parent, QListViewItem *after,
2097 QString label1, QString label2, QString label3, QString label4,
2098 QString label5, QString label6, QString label7, QString label8)
2099 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
2100{
2101 init();
2102}
2103
2104KListViewItem::~KListViewItem()
2105{
2106}
2107
2108void KListViewItem::init()
2109{
2110 m_known = false;
2111}
2112
2113const QColor &KListViewItem::backgroundColor()
2114{
2115 if (isAlternate())
2116 return static_cast< KListView* >(listView())->alternateBackground();
2117 return listView()->viewport()->colorGroup().base();
2118}
2119
2120bool KListViewItem::isAlternate()
2121{
2122 KListView *lv = static_cast<KListView *>(listView());
2123 if (lv && lv->alternateBackground().isValid())
2124 {
2125 KListViewItem *above = 0;
2126//US above = dynamic_cast<KListViewItem *>(itemAbove());
2127 above = (KListViewItem *)(itemAbove());
2128 m_known = above ? above->m_known : true;
2129 if (m_known)
2130 {
2131 m_odd = above ? !above->m_odd : false;
2132 }
2133 else
2134 {
2135 KListViewItem *item;
2136 bool previous = true;
2137 if (parent())
2138 {
2139//US item = dynamic_cast<KListViewItem *>(parent());
2140 item = (KListViewItem *)(parent());
2141 if (item)
2142 previous = item->m_odd;
2143//US item = dynamic_cast<KListViewItem *>(parent()->firstChild());
2144 item = (KListViewItem *)(parent()->firstChild());
2145 }
2146 else
2147 {
2148//US item = dynamic_cast<KListViewItem *>(lv->firstChild());
2149 item = (KListViewItem *)(lv->firstChild());
2150 }
2151
2152 while(item)
2153 {
2154 item->m_odd = previous = !previous;
2155 item->m_known = true;
2156//US item = dynamic_cast<KListViewItem *>(item->nextSibling());
2157 item = (KListViewItem *)(item->nextSibling());
2158 }
2159 }
2160 return m_odd;
2161 }
2162 return false;
2163}
2164
2165void KListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
2166{
2167 QColorGroup _cg = cg;
2168 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
2169 if (pm && !pm->isNull())
2170 {
2171 _cg.setBrush(QColorGroup::Base, QBrush(backgroundColor(), *pm));
2172 QPoint o = p->brushOrigin();
2173 p->setBrushOrigin( o.x()-listView()->contentsX(), o.y()-listView()->contentsY() );
2174 }
2175 else if (isAlternate()) {
2176//US if (listView()->viewport()->backgroundMode()==Qt::FixedColor)
2177 if (listView()->viewport()->backgroundMode()==QWidget::PaletteBackground)
2178 _cg.setColor(QColorGroup::Background, static_cast< KListView* >(listView())->alternateBackground());
2179 else
2180 _cg.setColor(QColorGroup::Base, static_cast< KListView* >(listView())->alternateBackground());
2181 }
2182 QListViewItem::paintCell(p, _cg, column, width, alignment);
2183}
2184
2185void KListView::virtual_hook( int, void* )
2186{ /*BASE::virtual_hook( id, data );*/ }
2187
2188//US #include "klistview.moc"
2189//US #include "klistviewlineedit.moc"
2190
2191// vim: ts=2 sw=2 et
diff --git a/microkde/kdeui/klistview.h b/microkde/kdeui/klistview.h
new file mode 100644
index 0000000..f7d9f85
--- a/dev/null
+++ b/microkde/kdeui/klistview.h
@@ -0,0 +1,1033 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Reginald Stadlbauer <reggie@kde.org>
3 Copyright (C) 2000 Charles Samuels <charles@kde.org>
4 Copyright (C) 2000 Peter Putzer <putzer@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20#ifndef KLISTVIEW_H
21#define KLISTVIEW_H
22
23#include <qlistview.h>
24
25#include <qptrlist.h>
26
27//US
28class QDropEvent;
29class QDragLeaveEvent;
30class QDragMoveEvent;
31class QDragEnterEvent;
32
33class QDragObject;
34class KConfig;
35class KLineEdit;
36/**
37 * This Widget extends the functionality of QListView to honor the system
38 * wide settings for Single Click/Double Click mode, AutoSelection and
39 * ChangeCursorOverLink (TM).
40 *
41 * There is a new signal executed(). It gets connected to either
42 * @ref QListView::clicked() or @ref QListView::doubleClicked() depending on the KDE
43 * wide Single Click/Double Click settings. It is strongly recommended that
44 * you use this signal instead of the above mentioned. This way you dont
45 * need to care about the current settings.
46 * If you want to get informed when the user selects something connect to the
47 * QListView::selectionChanged() signal.
48 *
49 * Drag-and-Drop is supported with the signal @ref #dropped(), just @ref #setAcceptDrops(true)
50 * and connect it to a suitable slot.
51 * To see where you are dropping, @ref setDropVisualizer(true).
52 * And also you'll need @ref acceptDrag(QDropEvent*)
53 *
54 * KListView is drag-enabled, too: to benefit from that you've got derive from it.
55 * Reimplement @ref dragObject() and (possibly) @ref startDrag(),
56 * and @ref setDragEnabled(true).
57 *
58 * @version $Id$
59 */
60class KListView : public QListView
61{
62 Q_OBJECT
63 Q_ENUMS( SelectionModeExt )
64 Q_PROPERTY( bool fullWidth READ fullWidth WRITE setFullWidth )
65 Q_PROPERTY( bool itemsMovable READ itemsMovable WRITE setItemsMovable )
66 Q_PROPERTY( bool itemsRenameable READ itemsRenameable WRITE setItemsRenameable )
67 Q_PROPERTY( bool dragEnabled READ dragEnabled WRITE setDragEnabled )
68 Q_PROPERTY( bool autoOpen READ autoOpen WRITE setAutoOpen )
69 Q_PROPERTY( bool dropVisualizer READ dropVisualizer WRITE setDropVisualizer )
70//US Q_PROPERTY( int tooltipColumn READ tooltipColumn WRITE setTooltipColumn )
71 Q_PROPERTY( int dropVisualizerWidth READ dropVisualizerWidth WRITE setDropVisualizerWidth )
72 Q_PROPERTY( QColor alternateBackground READ alternateBackground WRITE setAlternateBackground )
73
74 Q_OVERRIDE( SelectionModeExt selectionMode READ selectionModeExt WRITE setSelectionModeExt )
75
76public:
77 /**
78 * Possible selection modes.
79 *
80 * The first four correspond directly to QListView::SelectionMode, while
81 * the FileManager selection mode is defined as follows:
82 * @li home: move to the first
83 * @li end: move to the last
84 * @li PgUp/PgDn: move one page up/down
85 * @li up/down: move one item up/down
86 * @li insert: toggle selection of current and move to the next
87 * @li space: toggle selection of the current
88 * @li CTRL+up: move to the previous item and toggle selection of this one
89 * @li CTRL+down: toggle selection of the current item and move to the next
90 * @li CTRL+end: toggle selection from (including) the current
91 * item to (including) the last item
92 * @li CTRL+home: toggle selection from (including) the current
93 * item to the (including) the first item
94 * @li CTRL+PgDn: toggle selection from (including) the current
95 * item to (excluding) the item one page down
96 * @li CTRL+PgUp: toggle selection from (excluding) the current
97 * item to (including) the item one page up
98 *
99 * The combinations work the same with SHIFT instead of CTRL, except
100 * that if you start selecting something using SHIFT everything selected
101 * before will be deselected first.
102 *
103 * Additionally the current item is always selected automatically when
104 * navigating using the keyboard, except other items were selected explicitely.
105 *
106 * This way e.g. SHIFT+up/PgUp then SHIFT+down/PgDn leaves no item selected
107 */
108 enum SelectionModeExt {
109 Single = QListView::Single,
110 Multi = QListView::Multi,
111 Extended = QListView::Extended,
112 NoSelection = QListView::NoSelection,
113 FileManager
114 };
115 void repaintContents( bool erase = true )
116 {
117 QScrollView::repaintContents( contentsX(), contentsY(),
118 visibleWidth(), visibleHeight(), erase );
119 };
120 /**
121 * Constructor.
122 *
123 * The parameters @p parent and @p name are handled by
124 * @ref QListView, as usual.
125 */
126 KListView (QWidget *parent = 0, const char *name = 0);
127
128 /**
129 * Destructor.
130 */
131 virtual ~KListView();
132
133 /**
134 * Reimplemented for internal reasons.
135 * Further reimplementations should call this function or else
136 * some features may not work correctly.
137 *
138 * The API is unaffected.
139 */
140 virtual void setAcceptDrops (bool);
141
142 /**
143 * This function determines whether the given coordinates are within the
144 * execute area. The execute area is the part of a @ref QListViewItem where mouse
145 * clicks or double clicks respectively generate a @ref #executed() signal.
146 * Depending on @ref QListView::allColumnsShowFocus() this is either the
147 * whole item or only the first column.
148 * @return true if point is inside execute area of an item, false in all
149 * other cases including the case that it is over the viewport.
150 */
151 virtual bool isExecuteArea( const QPoint& point );
152
153 /**
154 * Same thing, but from an x coordinate only. This only checks if x is in
155 * the first column (if all columns don't show focus), without testing if
156 * the y coordinate is over an item or not.
157 */
158 bool isExecuteArea( int x );
159
160 /**
161 * @return a list containing the currently selected items.
162 */
163 QPtrList<QListViewItem> selectedItems() const; // ### BIC: KDE 4: use an implicitly shared class! (QValueList?)
164
165 /**
166 * Arbitrarily move @p item to @p parent, positioned immediately after item @p after.
167 */
168 void moveItem(QListViewItem *item, QListViewItem *parent, QListViewItem *after);
169
170 /**
171 * @return the last item (not child!) of this listview.
172 *
173 * @see lastChild()
174 */
175 QListViewItem *lastItem() const;
176
177 /**
178 * @return the last child of this listview.
179 *
180 * @see lastItem()
181 */
182 QListViewItem* lastChild () const;
183
184 /**
185 * @return the lineedit used for inline renaming.
186 * Use that to setup a @ref KCompletion or @ref QValidator for the lineedit
187 *
188 * @since 3.2
189 */
190 KLineEdit* renameLineEdit() const;
191
192 /**
193 * @returns if it is legal to move items in the list view. True by default.
194 *
195 * @see #setDragEnabled()
196 * @see #setItemsMovable()
197 */
198 bool itemsMovable() const;
199
200 /**
201 * @return whether inplace-renaming has been enabled. False by default.
202 *
203 * @see #setItemsRenameable()
204 */
205 bool itemsRenameable() const;
206
207 /**
208 * @return whether dragging is enabled. False by default.
209 *
210 * @see #setDragEnabled()
211 */
212 bool dragEnabled() const;
213
214 /**
215 * @return true if AutoOpen is enabled (not implemented currently).
216 *
217 * @see #setAutoOpen()
218 */
219 bool autoOpen() const;
220
221 /**
222 * @return true if @p column is renamable.
223 *
224 * @see #setRenameable()
225 */
226 bool isRenameable (int column) const;
227
228 /**
229 * @return true if drawing of the drop-visualizer has been enabled. True by default.
230 *
231 * @see #setDropVisualizer()
232 */
233 bool dropVisualizer() const;
234
235 /**
236 * @return the column for which tooltips are displayed (or -1 if none set).
237 *
238 * @see #setTooltipColumn()
239 */
240 int tooltipColumn() const;
241
242 /**
243 * For future expansions.
244 *
245 * Do not use.
246 * @deprecated
247 */
248 bool createChildren() const;
249
250 /**
251 * @return true if drawing of the drop-highlighter has been enabled. False by default.
252 *
253 * @see #setDropHighlighter()
254 */
255 bool dropHighlighter() const;
256
257 /**
258 * The dropVisualizerWidth defaults to 4.
259 *
260 * @see #setDropVisualizerWidth()
261 * @return the current width of the drop-visualizer.
262 */
263 int dropVisualizerWidth () const;
264
265 /**
266 * @return the "extended" selection mode of this listview.
267 *
268 * @see SelectionModeExt
269 * @see setSelectionModeExt
270 */
271 SelectionModeExt selectionModeExt () const;
272
273 /**
274 * Returns the index of @p item within the item tree or -1 if
275 * @p item doesn't exist in this list view. This function takes
276 * all items into account not only the visible ones.
277 */
278 int itemIndex( const QListViewItem *item ) const;
279
280 /**
281 * Returns the item of @p index within the item tree or 0 if
282 * @p index doesn't exist in this list view. This function takes
283 * all items into account not only the visible ones.
284 */
285 QListViewItem* itemAtIndex(int index);
286
287 /**
288 * @deprecated
289 * @see #setFullWidth()
290 */
291 void setFullWidth();
292
293 /**
294 * Let the last column fit exactly all the available width.
295 *
296 * @see #fullWidth()
297 */
298 void setFullWidth(bool fullWidth);
299
300 /**
301 * Returns whether the last column is set to fit the available width.
302 *
303 * @see #setFullWidth()
304 */
305 bool fullWidth() const;
306
307 /**
308 * Reimplemented for full width support
309 *
310 * @see #removeColumn()
311 */
312 virtual int addColumn(const QString& label, int width = -1);
313 /**
314 * Reimplemented for full width support
315 */
316 virtual int addColumn(const QIconSet& iconset, const QString& label, int width = -1);
317 /**
318 * Reimplemented for full width support
319 *
320 * @see #addColumn()
321 */
322 virtual void removeColumn(int index);
323
324 /**
325 * sets the alternate background background color.
326 * This only has an effect if the items are KListViewItems
327 *
328 * @param c the color to use for every other item. Set to an invalid
329 * colour to disable alternate colours.
330 *
331 * @see #alternateBackground()
332 **/
333 void setAlternateBackground(const QColor &c);
334 /**
335 * @return the alternate background color
336 *
337 * @see #setAlternateBackground()
338 */
339 const QColor &alternateBackground() const;
340
341 /**
342 * Saves the list view's layout (column widtsh, column order, sort column)
343 * to a KConfig group
344 *
345 * @param config the @ref KConfig object to write to
346 * @param group the config group to use
347 */
348 void saveLayout(KConfig *config, const QString &group) const;
349 /**
350 * Reads the list view's layout from a KConfig group as stored with
351 * @ref #saveLayout
352 *
353 * @param config the @ref KConfig object to read from
354 * @param group the config group to use
355 */
356 void restoreLayout(KConfig *config, const QString &group);
357 /**
358 * Reimplemented to remember the current sort column and order.
359 * @param column is the column to be sorted, or -1 to sort in order of
360 * insertion
361 * @param whether to sort ascending (or descending)
362 */
363 virtual void setSorting(int column, bool ascending = true);
364
365 /**
366 * @return the currently sorted column, or -1 if none is sorted
367 */
368 int columnSorted(void) const;
369
370 /**
371 * @return whether the current sort is ascending (or descending)
372 */
373 bool ascendingSort(void) const;
374
375signals:
376
377 /**
378 * This signal is emitted whenever the user executes an listview item.
379 * That means depending on the KDE wide Single Click/Double Click
380 * setting the user clicked or double clicked on that item.
381 * @param item is the pointer to the executed listview item.
382 *
383 * Note that you may not delete any @ref QListViewItem objects in slots
384 * connected to this signal.
385 */
386 void executed( QListViewItem *item );
387
388 /**
389 * This signal is emitted whenever the user executes an listview item.
390 * That means depending on the KDE wide Single Click/Double Click
391 * setting the user clicked or double clicked on that item.
392 * @param item is the pointer to the executed listview item.
393 * @param pos is the position where the user has clicked
394 * @param c is the column into which the user clicked.
395 *
396 * Note that you may not delete any @ref QListViewItem objects in slots
397 * connected to this signal.
398 */
399 void executed( QListViewItem *item, const QPoint &pos, int c );
400
401 /**
402 * This signal gets emitted whenever the user double clicks into the
403 * listview.
404 * @param item is the pointer to the clicked listview item.
405 * @param pos is the position where the user has clicked, and
406 * @param c is the column into which the user clicked.
407 *
408 * Note that you may not delete any @ref QListViewItem objects in slots
409 * connected to this signal.
410 *
411 * This signal is more or less here for the sake of completeness.
412 * You should normally not need to use this. In most cases its better
413 * to use @ref #executed() instead.
414 */
415 void doubleClicked( QListViewItem *item, const QPoint &pos, int c );
416
417 /**
418 * This signal gets emitted whenever something acceptable is
419 * dropped onto the listview.
420 *
421 * @param e is the drop event itself (it has already been accepted)
422 * @param after is the item after which the drop occured (or 0L, if
423 * the drop was above all items)
424 *
425 * @see #acceptDrop()
426 */
427 void dropped (QDropEvent * e, QListViewItem *after);
428
429 /**
430 * This signal gets emitted whenever something acceptable is
431 * dropped onto the listview.
432 *
433 * This is an overloaded version of the above (provided to simplify
434 * processing drops outside of the class).
435 *
436 * @param list is the listview
437 * @param e is the drop event itself (it has already been accepted)
438 * @param after is the item after which the drop occured (or 0L, if
439 * the drop was above all items
440 */
441 void dropped (KListView* list, QDropEvent* e, QListViewItem* after);
442
443 /**
444 * This signal gets emitted whenever something acceptable is
445 * dropped onto the listview.
446 *
447 * This function also provides a parent, in the event that your listview
448 * is a tree
449 * @param list is the listview
450 * @param e is the drop event itself (it has already been accepted)
451 * @param parent the item that is to be the parent of the new item
452 * @param after is the item after which the drop occured (or 0L, if
453 * the drop was above all items
454 */
455 void dropped (KListView* list, QDropEvent* e, QListViewItem* parent, QListViewItem* after);
456
457 /**
458 * This signal gets emitted whenever something acceptable is
459 * dropped onto the listview.
460 *
461 * This function also provides a parent, in the event that your listview
462 * is a tree
463 * @param e is the drop event itself (it has already been accepted)
464 * @param parent the item that is to be the parent of the new item
465 * @param after is the item after which the drop occured (or 0L, if
466 * the drop was above all items
467 */
468 void dropped (QDropEvent* e, QListViewItem* parent, QListViewItem* after);
469
470 /**
471 * This signal is emitted when ever the user moves an item in the list via
472 * DnD.
473 * If more than one item is moved at the same time, this signal is only emitted
474 * once.
475 */
476 void moved();
477
478 /**
479 * Connect to this signal if you want to do some preprocessing before
480 * a move is made, for example, to disable sorting
481 *
482 * This is sent only once per each groups of moves. That is, for each
483 * drop that is a move this will be emitted once, before KListView calls
484 * @see moveItem()
485 */
486 void aboutToMove();
487
488 /**
489 * This signal is emitted when ever the user moves an item in the list via
490 * DnD.
491 * If more than one item is moved at the same time, @p afterFirst and
492 * @p afterNow will reflect what was true before the move.
493 * This differs from @ref moved(), so be careful. All the items will have been
494 * moved before @ref moved() is emitted, which is not true in this method. // FIXME
495 * @param item the item that was moved
496 * @param afterFirst the item that parameter item was in before the move, in the list
497 * @param afterNow the item it's currently after.
498 */
499 void moved (QListViewItem *item, QListViewItem *afterFirst, QListViewItem *afterNow);
500
501
502 /**
503 * This signal is emitted after all the items have been moved. It reports info for
504 * each and every item moved, in order. The first element in @p items associates
505 * with the first of afterFirst and afterNow.
506 */
507 void moved(QPtrList<QListViewItem> &items, QPtrList<QListViewItem> &afterFirst, QPtrList<QListViewItem> &afterNow);
508
509 /**
510 * This signal gets emitted when an item is renamed via in-place renaming.
511 *
512 * @param item is the renamed item.
513 * @param str is the new value of column @p col.
514 * @param col is the renamed column.
515 */
516 void itemRenamed(QListViewItem* item, const QString &str, int col);
517
518 /**
519 * Same as above, but without the extra information.
520 */
521 void itemRenamed(QListViewItem* item);
522 void signalDelete();
523
524 /**
525 * This signal is emitted when the shortcut key for popup-menus is pressed.
526 *
527 * Normally you should not use this, just connect a slot to signal
528 * @ref contextMenu (KListView*, QListViewItem*, const QPoint&) to correctly
529 * handle showing context menus regardless of settings.
530 *
531 * @param list is this listview.
532 * @param item is the @ref currentItem() at the time the key was pressed. May be 0L.
533 */
534 void menuShortCutPressed (KListView* list, QListViewItem* item);
535
536 /**
537 * This signal is emitted whenever a context-menu should be shown for item @p i.
538 * It automatically adjusts for all settings involved (Menu key, showMenuOnPress/Click).
539 *
540 * @param l is this listview.
541 * @param i is the item for which the menu should be shown. May be 0L.
542 * @param p is the point at which the menu should be shown.
543 */
544 void contextMenu (KListView* l, QListViewItem* i, const QPoint& p);
545
546public slots:
547 /**
548 * Rename column @p c of @p item.
549 */
550 virtual void rename(QListViewItem *item, int c);
551
552 /**
553 * By default, if you called setItemsRenameable(true),
554 * only the first column is renameable.
555 * Use this function to enable the feature on other columns.
556 *
557 * If you want more intelligent (dynamic) selection,
558 * you'll have to derive from KListView,
559 * and override @ref rename() and call only call it
560 * if you want the item to be renamed.
561 */
562 void setRenameable (int column, bool yesno=true);
563
564 /**
565 * Set whether items in the list view can be moved.
566 * It is enabled by default.
567 *
568 * @see itemsMovable()
569 */
570 virtual void setItemsMovable(bool b);
571
572 /**
573 * Enables inplace-renaming of items.
574 * It is disabled by default.
575 *
576 * @see itemsRenameable()
577 * @see setRenameable()
578 */
579 virtual void setItemsRenameable(bool b);
580
581 /**
582 * Enable/Disable the dragging of items.
583 * It is disabled by default.
584 */
585 virtual void setDragEnabled(bool b);
586
587 /**
588 * Enable/Disable AutoOpen (not implemented currently).
589 */
590 virtual void setAutoOpen(bool b);
591
592 /**
593 * Enable/Disable the drawing of a drop-visualizer
594 * (a bar that shows where a dropped item would be inserted).
595 * It is enabled by default, if dragging is enabled
596 */
597 virtual void setDropVisualizer(bool b);
598
599 /**
600 * Set the width of the (default) drop-visualizer.
601 * If you don't call this method, the width is set to 4.
602 */
603 void setDropVisualizerWidth (int w);
604
605 /**
606 * Set which column should be used for automatic tooltips.
607 *
608 * @param column is the column for which tooltips will be shown.
609 * Set -1 to disable this feature.
610 */
611 virtual void setTooltipColumn(int column);
612
613 /**
614 * Enable/Disable the drawing of a drop-highlighter
615 * (a rectangle around the item under the mouse cursor).
616 * It is disabled by default.
617 */
618 virtual void setDropHighlighter(bool b);
619
620 /**
621 * For future expansions.
622 *
623 * Do not use.
624 * @deprecated
625 */
626 virtual void setCreateChildren(bool b);
627
628 /**
629 * Set the selection mode.
630 *
631 * A different name was chosen to avoid API-clashes with @ref QListView::setSelectionMode().
632 */
633 void setSelectionModeExt (SelectionModeExt mode);
634
635 /**
636 * Enable/disable tabbing between editable cells
637 * @since 3.1
638 */
639 void setTabOrderedRenaming(bool b);
640
641 /**
642 * Returns whether tab ordered renaming is enabled
643 * @since 3.1
644 */
645 bool tabOrderedRenaming() const;
646
647protected:
648 /**
649 * Determine whether a drop on position @p p would count as
650 * being above or below the QRect @p rect.
651 *
652 * @param rect is the rectangle we examine.
653 * @param p is the point located in the rectangle, p is assumed to be in
654 * viewport coordinates.
655 */
656 inline bool below (const QRect& rect, const QPoint& p)
657 {
658 return (p.y() > (rect.top() + (rect.bottom() - rect.top())/2));
659 }
660
661 /**
662 * An overloaded version of below(const QRect&, const QPoint&).
663 *
664 * It differs from the above only in what arguments it takes.
665 *
666 * @param i the item whose rect() is passed to the above function.
667 * @param p is translated from contents coordinates to viewport coordinates
668 * before being passed to the above function.
669 */
670 inline bool below (QListViewItem* i, const QPoint& p)
671 {
672 return below (itemRect(i), contentsToViewport(p));
673 }
674
675 /**
676 * Reimplemented to reload the alternate background in palette changes.
677 * @internal
678 */
679 virtual bool event( QEvent * );
680
681 /**
682 * Emit signal @ref #executed.
683 * @internal
684 */
685 void emitExecute( QListViewItem *item, const QPoint &pos, int c );
686
687 /**
688 * Reimplemented for internal reasons.
689 * Further reimplementations should call this function or else
690 * some features may not work correctly.
691 *
692 * The API is unaffected.
693 */
694 virtual void focusInEvent(QFocusEvent* fe);
695
696 /**
697 * Reimplemented for internal reasons.
698 * Further reimplementations should call this function or else
699 * some features may not work correctly.
700 *
701 * The API is unaffected.
702 */
703 virtual void focusOutEvent( QFocusEvent *fe );
704
705 /**
706 * Reimplemented for internal reasons.
707 * Further reimplementations should call this function or else
708 * some features may not work correctly.
709 *
710 * The API is unaffected.
711 */
712 virtual void leaveEvent( QEvent *e );
713
714 /**
715 * @return the tooltip for @p column of @p item.
716 */
717 virtual QString tooltip(QListViewItem* item, int column) const;
718
719 /**
720 * @return whether the tooltip for @p column of @p item shall be shown at point @p pos.
721 */
722 virtual bool showTooltip(QListViewItem *item, const QPoint &pos, int column) const;
723
724 /**
725 * Reimplemented for internal reasons.
726 * Further reimplementations should call this function or else
727 * some features may not work correctly.
728 *
729 * The API is unaffected.
730 */
731 virtual void contentsDragMoveEvent (QDragMoveEvent *event);
732
733 /**
734 * Reimplemented for internal reasons.
735 * Further reimplementations should call this function or else
736 * some features may not work correctly.
737 *
738 * The API is unaffected.
739 */
740 virtual void contentsMousePressEvent( QMouseEvent *e );
741
742 /**
743 * Reimplemented for internal reasons.
744 * Further reimplementations should call this function or else
745 * some features may not work correctly.
746 *
747 * The API is unaffected.
748 */
749 virtual void contentsMouseMoveEvent( QMouseEvent *e );
750
751 /**
752 * Reimplemented for internal reasons.
753 * Further reimplementations should call this function or else
754 * some features may not work correctly.
755 *
756 * The API is unaffected.
757 */
758 virtual void contentsMouseDoubleClickEvent ( QMouseEvent *e );
759
760 /**
761 * Reimplemented for internal reasons.
762 * Further reimplementations should call this function or else
763 * some features may not work correctly.
764 *
765 * The API is unaffected.
766 */
767 virtual void contentsDragLeaveEvent (QDragLeaveEvent *event);
768
769 /**
770 * Reimplemented for internal reasons.
771 * Further reimplementations should call this function or else
772 * some features may not work correctly.
773 *
774 * The API is unaffected.
775 */
776 virtual void contentsMouseReleaseEvent (QMouseEvent*);
777
778 /**
779 * Reimplemented for internal reasons.
780 * Further reimplementations should call this function or else
781 * some features may not work correctly.
782 *
783 * The API is unaffected.
784 */
785 virtual void contentsDropEvent (QDropEvent*);
786
787 /**
788 * Reimplemented for internal reasons.
789 * Further reimplementations should call this function or else
790 * some features may not work correctly.
791 *
792 * The API is unaffected.
793 */
794 virtual void contentsDragEnterEvent (QDragEnterEvent *);
795
796 /**
797 * @return a dragobject encoding the current selection.
798 *
799 * @see setDragEnabled()
800 */
801 virtual QDragObject *dragObject();
802
803 /**
804 * @return true if the @p event provides some acceptable
805 * format.
806 * A common mistake is to forget the "const" in your reimplementation
807 */
808 virtual bool acceptDrag (QDropEvent* event) const;
809
810 /**
811 * Paint the drag line. If painter is null, don't try to :)
812 *
813 * If after == 0 then the marker should be drawn at the top.
814 *
815 * @return the rectangle that you painted to.
816 */
817 virtual QRect drawDropVisualizer (QPainter *p, QListViewItem *parent, QListViewItem *after);
818
819 /**
820 * Paint the drag rectangle. If painter is null, don't try to :)
821 *
822 *
823 * @return the rectangle that you painted to.
824 */
825 virtual QRect drawItemHighlighter(QPainter *painter, QListViewItem *item);
826
827 /**
828 * This method calls @ref dragObject() and starts the drag.
829 *
830 * Reimplement it to do fancy stuff like setting a pixmap or
831 * using a non-default DragMode
832 */
833 virtual void startDrag();
834
835 /**
836 * Reimplemented for internal reasons.
837 * Further reimplementations should call this function or else
838 * some features may not work correctly.
839 *
840 * The API is unaffected.
841 */
842 virtual void keyPressEvent (QKeyEvent*);
843
844 /**
845 * Reimplemented for internal reasons.
846 * Further reimplementations should call this function or else
847 * some features may not work correctly.
848 *
849 * The API is unaffected.
850 */
851 virtual void viewportPaintEvent(QPaintEvent*);
852
853 /**
854 * In FileManager selection mode: explicitely activate the mode
855 * in which the current item is automatically selected.
856 */
857 void activateAutomaticSelection();
858 /**
859 * In FileManager selection mode: explicitely deactivate the mode
860 * in which the current item is automatically selected.
861 */
862 void deactivateAutomaticSelection();
863 /**
864 * In FileManager selection mode: return whether it is currently in the mode
865 * where the current item is selected automatically.
866 * Returns false if items were selected explicitely, e.g. using the mouse.
867 */
868 bool automaticSelection() const;
869
870 /**
871 * Reimplemented for setFullWidth()
872 */
873 virtual void viewportResizeEvent(QResizeEvent* e);
874
875protected slots:
876 /**
877 * Update internal settings whenever the global ones change.
878 * @internal
879 */
880 void slotSettingsChanged(int);
881
882 void slotMouseButtonClicked( int btn, QListViewItem *item, const QPoint &pos, int c );
883 void doneEditing(QListViewItem *item, int row);
884
885 /**
886 * Repaint the rect where I was drawing the drop line.
887 */
888 void cleanDropVisualizer();
889
890 /**
891 * Repaint the rect where I was drawing the drop rectangle.
892 */
893 void cleanItemHighlighter();
894
895 /**
896 * Emit the @ref contextMenu signal. This slot is for mouse actions.
897 */
898 void emitContextMenu (QListViewItem*, const QPoint&, int);
899
900 /**
901 * Emit the @ref #contextMenu signal. This slot is for key presses.
902 */
903 void emitContextMenu (KListView*, QListViewItem*);
904
905 /**
906 * Accessory slot for AutoSelect
907 * @internal
908 */
909 void slotOnItem( QListViewItem *item );
910
911 /**
912 * Accessory slot for AutoSelect/ChangeCursorOverItem
913 * @internal
914 */
915 void slotOnViewport();
916
917 /**
918 * Process AutoSelection.
919 * @internal
920 */
921 void slotAutoSelect();
922
923 void slotDragExpand();
924
925 /**
926 * Reacts to header changes in full width mode
927 * @internal
928 */
929 void slotHeaderChanged();
930
931protected:
932 /**
933 * Handle dropEvent when itemsMovable() is set to true.
934 */
935 virtual void movableDropEvent (QListViewItem* parent, QListViewItem* afterme);
936
937 /**
938 * Where is the nearest QListViewItem that I'm going to drop?
939 *
940 * FIXME KDE 4.0: Make this method const so it can be called from an
941 * acceptDrag method without ugly casts
942 */
943 virtual void findDrop(const QPoint &pos, QListViewItem *&parent, QListViewItem *&after);
944
945 /**
946 * A special keyPressEvent (for FileManager selection mode).
947 */
948 void fileManagerKeyPressEvent (QKeyEvent*);
949
950 /**
951 * Convert the depth of an item into its indentation in pixels
952 */
953 int depthToPixels( int depth );
954
955private:
956 class Tooltip;
957protected:
958 virtual void virtual_hook( int id, void* data );
959private:
960 class KListViewPrivate;
961 KListViewPrivate *d;
962};
963
964/**
965 * A listview item with support for alternate background colours. It is
966 * a drop-in replacement for @ref QListViewItem
967 *
968 * @short listview item with alternate background colour support
969 */
970class KListViewItem : public QListViewItem
971{
972public:
973 /**
974 * constructors. The semantics remain as in @ref QListViewItem.
975 * Although they accept a @ref QListViewItem as parent, please
976 * don't mix KListViewItem (or subclasses) with QListViewItem
977 * (or subclasses).
978 */
979 KListViewItem(QListView *parent);
980 KListViewItem(QListViewItem *parent);
981 KListViewItem(QListView *parent, QListViewItem *after);
982 KListViewItem(QListViewItem *parent, QListViewItem *after);
983
984 KListViewItem(QListView *parent,
985 QString, QString = QString::null,
986 QString = QString::null, QString = QString::null,
987 QString = QString::null, QString = QString::null,
988 QString = QString::null, QString = QString::null);
989
990 KListViewItem(QListViewItem *parent,
991 QString, QString = QString::null,
992 QString = QString::null, QString = QString::null,
993 QString = QString::null, QString = QString::null,
994 QString = QString::null, QString = QString::null);
995
996 KListViewItem(QListView *parent, QListViewItem *after,
997 QString, QString = QString::null,
998 QString = QString::null, QString = QString::null,
999 QString = QString::null, QString = QString::null,
1000 QString = QString::null, QString = QString::null);
1001
1002 KListViewItem(QListViewItem *parent, QListViewItem *after,
1003 QString, QString = QString::null,
1004 QString = QString::null, QString = QString::null,
1005 QString = QString::null, QString = QString::null,
1006 QString = QString::null, QString = QString::null);
1007
1008 virtual ~KListViewItem();
1009
1010 /**
1011 * retuns true if this item is to be drawn with the alternate background
1012 */
1013 bool isAlternate();
1014 /**
1015 * returns the background colour for this item
1016 */
1017 const QColor &backgroundColor();
1018
1019 virtual void paintCell(QPainter *p, const QColorGroup &cg,
1020 int column, int width, int alignment);
1021
1022private:
1023 void init();
1024
1025private:
1026 uint m_odd : 1;
1027 uint m_known : 1;
1028 uint m_unused : 30;
1029};
1030
1031#endif
1032
1033// vim: ts=2 sw=2 et
diff --git a/microkde/kdeui/kmainwindow.cpp b/microkde/kdeui/kmainwindow.cpp
new file mode 100644
index 0000000..3a2a4d0
--- a/dev/null
+++ b/microkde/kdeui/kmainwindow.cpp
@@ -0,0 +1,994 @@
1 /* This file is part of the KDE libraries
2 Copyright
3 (C) 2000 Reginald Stadlbauer (reggie@kde.org)
4 (C) 1997 Stephan Kulow (coolo@kde.org)
5 (C) 1997-2000 Sven Radej (radej@kde.org)
6 (C) 1997-2000 Matthias Ettrich (ettrich@kde.org)
7 (C) 1999 Chris Schlaeger (cs@kde.org)
8 (C) 2002 Joseph Wenninger (jowenn@kde.org)
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License version 2 as published by the Free Software Foundation.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA.
23 */
24#include <qobjectlist.h>
25#include <qstringlist.h>
26#include <qtimer.h>
27#include <qmenubar.h>
28#include <qstatusbar.h>
29#include <qapplication.h>
30
31
32#include "kdebug.h"
33#include "kmainwindow.h"
34#include "kglobalsettings.h"
35#include "kactioncollection.h"
36
37class KMainWindowPrivate {
38public:
39//US bool showHelpMenu:1;
40
41 bool autoSaveSettings:1;
42 bool settingsDirty:1;
43 bool autoSaveWindowSize:1;
44 bool care_about_geometry:1;
45 QString autoSaveGroup;
46//US KAccel * kaccel;
47//US KMainWindowInterface *m_interface;
48 KDEPrivate::ToolBarHandler *toolBarHandler;
49 QTimer* settingsTimer;
50 KToggleAction *showStatusBarAction;
51 QRect defaultWindowSize;
52};
53
54static bool no_query_exit = false;
55
56KMainWindow::KMainWindow( QWidget* parent, const char *name, WFlags f )
57 : QMainWindow( parent, name, f )/*US, KXMLGUIBuilder( this ), helpMenu2( 0 ), factory_( 0 )*/
58{
59 mQToolBar = 0;
60 initKMainWindow(name);
61}
62
63void KMainWindow::parseGeometry(bool parsewidth)
64{
65//US the following code is not getting used in the embedded version !! So disable it for now
66/*US
67
68 assert ( !kapp->geometryArgument().isNull() );
69 assert ( d->care_about_geometry );
70
71#ifndef Q_WS_QWS
72 // FIXME: (E) Implement something similar for Qt Embedded (or decide we don't need it)
73 int x, y;
74 int w, h;
75 int m = XParseGeometry( kapp->geometryArgument().latin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h);
76 if (parsewidth) {
77 QSize minSize = minimumSize();
78 QSize maxSize = maximumSize();
79 if ( (m & WidthValue) == 0 )
80 w = width();
81 if ( (m & HeightValue) == 0 )
82 h = height();
83 w = QMIN(w,maxSize.width());
84 h = QMIN(h,maxSize.height());
85 w = QMAX(w,minSize.width());
86 h = QMAX(h,minSize.height());
87 resize(w, h);
88 } else {
89 if ( parsewidth && (m & XValue) == 0 )
90 x = geometry().x();
91 if ( parsewidth && (m & YValue) == 0 )
92 y = geometry().y();
93 if ( (m & XNegative) )
94 x = KApplication::desktop()->width() + x - w;
95 if ( (m & YNegative) )
96 y = KApplication::desktop()->height() + y - h;
97 move(x, y);
98 }
99#endif
100*/
101}
102
103KMainWindow::~KMainWindow()
104{
105 delete d->settingsTimer;
106 QMenuBar* mb = internalMenuBar();
107 delete mb;
108//US delete d->m_interface;
109
110 delete d;
111//US memberList->remove( this );
112}
113
114void KMainWindow::initKMainWindow(const char *name)
115{
116 setDockMenuEnabled( FALSE );
117//US mHelpMenu = 0;
118
119//US kapp->setTopWidget( this );
120 actionCollection()->setWidget( this );
121//US connect(kapp, SIGNAL(shutDown()), this, SLOT(shuttingDown()));
122//US if( !memberList )
123//US memberList = new QPtrList<KMainWindow>;
124/*US
125
126 if ( !ksm )
127 ksm = ksmd.setObject(new KMWSessionManaged());
128 // set a unique object name. Required by session management.
129 QCString objname;
130 QCString s;
131 int unusedNumber;
132 if ( !name )
133 { // no name given
134 objname = kapp->instanceName() + "-mainwindow#";
135 s = objname + '1'; // start adding number immediately
136 unusedNumber = 1;
137 }
138 else if( name[ strlen( name ) - 1 ] == '#' )
139 { // trailing # - always add a number
140 objname = name;
141 s = objname + '1'; // start adding number immediately
142 unusedNumber = 1;
143 }
144 else
145 {
146 objname = name;
147 s = objname;
148 unusedNumber = 0; // add numbers only when needed
149 }
150 for(;;) {
151 QWidgetList* list = kapp->topLevelWidgets();
152 QWidgetListIt it( *list );
153 bool found = false;
154 for( QWidget* w = it.current();
155 w != NULL;
156 ++it, w = it.current())
157 if( w != this && w->name() == s )
158 {
159 found = true;
160 break;
161 }
162 delete list;
163 if( !found )
164 break;
165 s.setNum( ++unusedNumber );
166 s = objname + s;
167 }
168 setName( s );
169 memberList->append( this );
170*/
171
172 d = new KMainWindowPrivate;
173//US d->showHelpMenu = true;
174 d->settingsDirty = false;
175 d->autoSaveSettings = false;
176 d->autoSaveWindowSize = true; // for compatibility
177//US d->kaccel = actionCollection()->kaccel();
178 d->toolBarHandler = 0;
179 d->settingsTimer = 0;
180 d->showStatusBarAction = NULL;
181/*US
182 if ((d->care_about_geometry == beeing_first)) {
183 beeing_first = false;
184 if ( kapp->geometryArgument().isNull() ) // if there is no geometry, it doesn't mater
185 d->care_about_geometry = false;
186 else
187 parseGeometry(false);
188 }
189*/
190 d->care_about_geometry = false;
191
192//US setCaption( kapp->caption() );
193 // attach dcop interface
194//US d->m_interface = new KMainWindowInterface(this);
195
196//US if (!kapp->authorize("movable_toolbars"))
197//US setDockWindowsMovable(false);
198}
199
200KAction *KMainWindow::toolBarMenuAction()
201{
202 if ( !d->toolBarHandler )
203 return 0;
204
205 return d->toolBarHandler->toolBarMenuAction();
206}
207
208bool KMainWindow::canBeRestored( int number )
209{
210/*US we do not have and want to save sessioninformation. Use info from the default
211application config.
212*/
213//US if ( !kapp->isRestored() )
214//US return FALSE;
215//US KConfig *config = kapp->sessionConfig();
216 KConfig *config = KGlobal::config();
217 if ( !config )
218 return FALSE;
219 config->setGroup( QString::fromLatin1("Number") );
220 int n = config->readNumEntry( QString::fromLatin1("NumberOfWindows") , 1 );
221 return number >= 1 && number <= n;
222
223}
224
225const QString KMainWindow::classNameOfToplevel( int number )
226{
227/*US we do not have and want to save sessioninformation. Use info from the default
228application config.
229*/
230//US if ( !kapp->isRestored() )
231//US return QString::null;
232//US KConfig *config = kapp->sessionConfig();
233 KConfig *config = KGlobal::config();
234 if ( !config )
235 return QString::null;
236 QString s;
237 s.setNum( number );
238 s.prepend( QString::fromLatin1("WindowProperties") );
239 config->setGroup( s );
240 if ( !config->hasKey( QString::fromLatin1("ClassName") ) )
241 return QString::null;
242 else
243 return config->readEntry( QString::fromLatin1("ClassName") );
244}
245
246bool KMainWindow::restore( int number, bool show )
247{
248/*US we do not have and want to save sessioninformation. Use info from the default
249application config.
250*/
251 if ( !canBeRestored( number ) )
252 return FALSE;
253//US KConfig *config = kapp->sessionConfig();
254 KConfig *config = KGlobal::config();
255
256 if ( readPropertiesInternal( config, number ) ){
257 if ( show )
258 KMainWindow::show();
259 return FALSE;
260 }
261 return FALSE;
262
263}
264
265void KMainWindow::setCaption( const QString &caption )
266{
267//US setPlainCaption( kapp->makeStdCaption(caption) );
268 setPlainCaption( caption );
269}
270
271void KMainWindow::setCaption( const QString &caption, bool modified )
272{
273//US setPlainCaption( kapp->makeStdCaption(caption, true, modified) );
274 setPlainCaption( caption + "modified:" );
275}
276
277void KMainWindow::setPlainCaption( const QString &caption )
278{
279 QMainWindow::setCaption( caption );
280#ifndef Q_WS_QWS
281//US the following is disabled for the embedded version
282//US NETWinInfo info( qt_xdisplay(), winId(), qt_xrootwin(), 0 );
283//US info.setName( caption.utf8().data() );
284#endif
285}
286
287void KMainWindow::slotStateChanged(const QString &newstate)
288{
289 stateChanged(newstate, KXMLGUIClient::StateNoReverse);
290}
291
292/*
293 * Get rid of this for KDE 4.0
294 */
295void KMainWindow::slotStateChanged(const QString &newstate,
296 KXMLGUIClient::ReverseStateChange reverse)
297{
298 stateChanged(newstate, reverse);
299}
300
301void KMainWindow::closeEvent ( QCloseEvent *e )
302{
303 // Save settings if auto-save is enabled, and settings have changed
304 if (d->settingsDirty && d->autoSaveSettings)
305 saveAutoSaveSettings();
306
307 if (queryClose()) {
308 e->accept();
309
310 int not_withdrawn = 0;
311/*US
312 QPtrListIterator<KMainWindow> it(*KMainWindow::memberList);
313 for (it.toFirst(); it.current(); ++it){
314 if ( !it.current()->isHidden() && it.current()->isTopLevel() && it.current() != this )
315 not_withdrawn++;
316 }
317*/
318 if ( !no_query_exit && not_withdrawn <= 0 ) { // last window close accepted?
319/*US
320 if ( queryExit() && !kapp->sessionSaving()) { // Yes, Quit app?
321 // don't call queryExit() twice
322 disconnect(kapp, SIGNAL(shutDown()), this, SLOT(shuttingDown()));
323 kapp->deref(); // ...and quit aplication.
324 } else {
325 // cancel closing, it's stupid to end up with no windows at all....
326 e->ignore();
327 }
328*/
329//US we have no sessionmanagement. Simply close app.
330 if ( queryExit() ) { // Yes, Quit app?
331 qDebug("KMainWindow::closeEvent: Exit application ???");
332 // don't call queryExit() twice
333//US disconnect(kapp, SIGNAL(shutDown()), this, SLOT(shuttingDown()));
334 }
335
336 }
337 }
338}
339
340bool KMainWindow::queryExit()
341{
342 return TRUE;
343}
344
345bool KMainWindow::queryClose()
346{
347 return TRUE;
348}
349
350void KMainWindow::saveGlobalProperties( KConfig* )
351{
352}
353
354void KMainWindow::readGlobalProperties( KConfig* )
355{
356}
357
358void KMainWindow::savePropertiesInternal( KConfig *config, int number )
359{
360 bool oldASWS = d->autoSaveWindowSize;
361 d->autoSaveWindowSize = true; // make saveMainWindowSettings save the window size
362
363 QString s;
364 s.setNum(number);
365 s.prepend(QString::fromLatin1("WindowProperties"));
366 config->setGroup(s);
367
368 // store objectName, className, Width and Height for later restoring
369 // (Only useful for session management)
370 config->writeEntry(QString::fromLatin1("ObjectName"), name());
371 config->writeEntry(QString::fromLatin1("ClassName"), className());
372
373 saveMainWindowSettings(config); // Menubar, statusbar and Toolbar settings.
374
375 s.setNum(number);
376 config->setGroup(s);
377 saveProperties(config);
378
379 d->autoSaveWindowSize = oldASWS;
380}
381
382void KMainWindow::setStandardToolBarMenuEnabled( bool enable )
383{
384 if ( enable )
385 {
386 if ( d->toolBarHandler )
387 return;
388
389 d->toolBarHandler = new KDEPrivate::ToolBarHandler( this );
390
391/*US if ( factory() )
392 factory()->addClient( d->toolBarHandler );
393*/
394 }
395 else
396 {
397 if ( !d->toolBarHandler )
398 return;
399/*US
400 if ( factory() )
401 factory()->removeClient( d->toolBarHandler );
402*/
403 delete d->toolBarHandler;
404 d->toolBarHandler = 0;
405 }
406
407}
408
409bool KMainWindow::isStandardToolBarMenuEnabled() const
410{
411 return ( d->toolBarHandler != 0 );
412}
413
414void KMainWindow::createStandardStatusBarAction(){
415 if(!d->showStatusBarAction){
416 d->showStatusBarAction = KStdAction::showStatusbar(this, SLOT(setSettingsDirty()), actionCollection());
417 connect(d->showStatusBarAction, SIGNAL(toggled(bool)), statusBar(), SLOT(setShown(bool)));
418 if(internalStatusBar())
419 d->showStatusBarAction->setChecked(!internalStatusBar()->isHidden());
420 }
421}
422
423QToolBar *KMainWindow::tBar( )
424{
425 if ( ! mQToolBar )
426 mQToolBar = new QToolBar( this );
427 return mQToolBar;
428}
429
430KToolBar *KMainWindow::toolBar( const char * name )
431{
432
433 if (!name)
434 name = "mainToolBar";
435 KToolBar *tb = (KToolBar*)child( name, "KToolBar" );
436 if ( tb )
437 return tb;
438 bool honor_mode = (name == "mainToolBar");
439
440/*US
441 if ( builderClient() )
442 return new KToolBar(this, name, honor_mode); // XMLGUI constructor
443 else
444*/
445 return new KToolBar(this, Top, false, name, honor_mode ); // non-XMLGUI
446}
447
448QPtrListIterator<KToolBar> KMainWindow::toolBarIterator()
449{
450 toolbarList.clear();
451 QPtrList<QToolBar> lst;
452 for ( int i = (int)QMainWindow::Unmanaged; i <= (int)Minimized; ++i ) {
453 lst = toolBars( (ToolBarDock)i );
454 for ( QToolBar *tb = lst.first(); tb; tb = lst.next() ) {
455 if ( !tb->inherits( "KToolBar" ) )
456 continue;
457 toolbarList.append( (KToolBar*)tb );
458 }
459 }
460 return QPtrListIterator<KToolBar>( toolbarList );
461}
462
463void KMainWindow::setAutoSaveSettings( const QString & groupName, bool saveWindowSize )
464{
465 d->autoSaveSettings = true;
466 d->autoSaveGroup = groupName;
467 d->autoSaveWindowSize = saveWindowSize;
468 // Get notified when the user moves a toolbar around
469//US connect( this, SIGNAL( dockWindowPositionChanged( QDockWindow * ) ),
470//US this, SLOT( setSettingsDirty() ) );
471 connect( this, SIGNAL( toolBarPositionChanged(QToolBar *) ),
472 this, SLOT( setSettingsDirty() ) );
473
474
475 // Get default values
476//US int scnum = QApplication::desktop()->screenNumber(parentWidget());
477//US QRect desk = QApplication::desktop()->screenGeometry(scnum);
478 QRect desk = KGlobalSettings::desktopGeometry(0);
479
480 d->defaultWindowSize = QRect(desk.width(), width(), desk.height(), height());
481 // Now read the previously saved settings
482 applyMainWindowSettings( KGlobal::config(), groupName );
483}
484
485
486void KMainWindow::resetAutoSaveSettings()
487{
488 d->autoSaveSettings = false;
489 if ( d->settingsTimer )
490 d->settingsTimer->stop();
491}
492
493bool KMainWindow::autoSaveSettings() const
494{
495 return d->autoSaveSettings;
496}
497
498QString KMainWindow::autoSaveGroup() const
499{
500 return d->autoSaveGroup;
501}
502
503void KMainWindow::saveAutoSaveSettings()
504{
505 ASSERT( d->autoSaveSettings );
506 //kdDebug(200) << "KMainWindow::saveAutoSaveSettings -> saving settings" << endl;
507 saveMainWindowSettings( KGlobal::config(), d->autoSaveGroup );
508 KGlobal::config()->sync();
509 d->settingsDirty = false;
510 if ( d->settingsTimer )
511 d->settingsTimer->stop();
512}
513
514void KMainWindow::createGUI( const QString &xmlfile, bool _conserveMemory )
515{
516 // disabling the updates prevents unnecessary redraws
517 setUpdatesEnabled( false );
518
519 // just in case we are rebuilding, let's remove our old client
520//US guiFactory()->removeClient( this );
521
522 // make sure to have an empty GUI
523 QMenuBar* mb = internalMenuBar();
524 if ( mb )
525 mb->clear();
526
527 (void)toolBarIterator(); // make sure toolbarList is most-up-to-date
528 toolbarList.setAutoDelete( true );
529 toolbarList.clear();
530 toolbarList.setAutoDelete( false );
531/*US
532 // don't build a help menu unless the user ask for it
533 if (d->showHelpMenu) {
534 // we always want a help menu
535 if (helpMenu2 == 0)
536 helpMenu2 = new KHelpMenu(this, instance()->aboutData(), true,
537 actionCollection());
538 }
539
540 // we always want to load in our global standards file
541 setXMLFile( locate( "config", "ui/ui_standards.rc", instance() ) );
542
543 // now, merge in our local xml file. if this is null, then that
544 // means that we will be only using the global file
545 if ( !xmlfile.isNull() ) {
546 setXMLFile( xmlfile, true );
547 } else {
548 QString auto_file(instance()->instanceName() + "ui.rc");
549 setXMLFile( auto_file, true );
550 }
551
552 // make sure we don't have any state saved already
553 setXMLGUIBuildDocument( QDomDocument() );
554
555 // do the actual GUI building
556 guiFactory()->addClient( this );
557
558 // try and get back *some* of our memory
559 if ( _conserveMemory )
560 {
561 // before freeing the memory allocated by the DOM document we also
562 // free all memory allocated internally in the KXMLGUIFactory for
563 // the menubar and the toolbars . This however implies that we
564 // have to take care of deleting those widgets ourselves. For
565 // destruction this is no problem, but when rebuilding we have
566 // to take care of that (and we want to rebuild the GUI when
567 // using stuff like the toolbar editor ).
568 // In addition we have to take care of not removing containers
569 // like popupmenus, defined in the XML document.
570 // this code should probably go into a separate method in KMainWindow.
571 // there's just one problem: I'm bad in finding names ;-) , so
572 // I skipped this ;-)
573
574 QDomDocument doc = domDocument();
575
576 QDomElement e = doc.documentElement().firstChild().toElement();
577 for (; !e.isNull(); e = e.nextSibling().toElement() ) {
578 if ( e.tagName().lower() == "toolbar" )
579 factory_->resetContainer( e.attribute( "name" ) );
580 else if ( e.tagName().lower() == "menubar" )
581 factory_->resetContainer( e.tagName(), true );
582 }
583
584 conserveMemory();
585 }
586*/
587 setUpdatesEnabled( true );
588 updateGeometry();
589}
590
591void KMainWindow::saveMainWindowSettings(KConfig *config, const QString &configGroup)
592{
593 kdDebug(200) << "KMainWindow::saveMainWindowSettings " << configGroup << endl;
594//US QStrList entryList;
595 QStringList entryList;
596 QString oldGroup;
597
598 if (!configGroup.isEmpty())
599 {
600 oldGroup = config->group();
601 config->setGroup(configGroup);
602 }
603
604 // Called by session management - or if we want to save the window size anyway
605 if ( d->autoSaveWindowSize )
606 saveWindowSize( config );
607
608 QStatusBar* sb = internalStatusBar();
609 if (sb) {
610 entryList.clear();
611 if ( sb->isHidden() )
612 entryList.append("Disabled");
613 else
614 entryList.append("Enabled");
615
616 if(sb->isHidden())
617 //US config->writeEntry(QString::fromLatin1("StatusBar"), entryList, ';');
618 config->writeEntry(QString::fromLatin1("StatusBar"), entryList);
619 else
620 config->deleteEntry(QString::fromLatin1("StatusBar"));
621 }
622
623 QMenuBar* mb = internalMenuBar();
624 if (mb) {
625 entryList.clear();
626 if ( mb->isHidden() )
627 entryList.append("Disabled");
628 else
629 entryList.append("Enabled");
630
631 // By default we don't hide.
632 if(mb->isHidden())
633 //US config->writeEntry(QString::fromLatin1("MenuBar"), entryList, ';');
634 config->writeEntry(QString::fromLatin1("MenuBar"), entryList);
635 else
636 config->deleteEntry(QString::fromLatin1("MenuBar"));
637 }
638
639 int n = 1; // Toolbar counter. toolbars are counted from 1,
640 KToolBar *toolbar = 0;
641 QPtrListIterator<KToolBar> it( toolBarIterator() );
642 while ( ( toolbar = it.current() ) ) {
643 ++it;
644 QString group;
645 if (!configGroup.isEmpty())
646 {
647 // Give a number to the toolbar, but prefer a name if there is one,
648 // because there's no real guarantee on the ordering of toolbars
649 group = (!::qstrcmp(toolbar->name(), "unnamed") ? QString::number(n) : QString(" ")+toolbar->name());
650 group.prepend(" Toolbar");
651 group.prepend(configGroup);
652 }
653 toolbar->saveSettings(config, group);
654 n++;
655 }
656 if (!configGroup.isEmpty())
657 config->setGroup(oldGroup);
658}
659
660bool KMainWindow::readPropertiesInternal( KConfig *config, int number )
661{
662 if ( number == 1 )
663 readGlobalProperties( config );
664
665 // in order they are in toolbar list
666 QString s;
667 s.setNum(number);
668 s.prepend(QString::fromLatin1("WindowProperties"));
669
670 config->setGroup(s);
671
672 // restore the object name (window role)
673 if ( config->hasKey(QString::fromLatin1("ObjectName" )) )
674 setName( config->readEntry(QString::fromLatin1("ObjectName")).latin1()); // latin1 is right here
675
676 applyMainWindowSettings(config); // Menubar, statusbar and toolbar settings.
677
678 s.setNum(number);
679 config->setGroup(s);
680 readProperties(config);
681 return true;
682}
683
684void KMainWindow::applyMainWindowSettings(KConfig *config, const QString &configGroup)
685{
686 kdDebug(200) << "KMainWindow::applyMainWindowSettings" << endl;
687 QString entry;
688//US QStrList entryList;
689 QStringList entryList;
690 int i = 0; // Number of entries in list
691
692 if (!configGroup.isEmpty())
693 config->setGroup(configGroup);
694
695 restoreWindowSize(config);
696
697 QStatusBar* sb = internalStatusBar();
698 if (sb) {
699 entryList.clear();
700//US i = config->readListEntry (QString::fromLatin1("StatusBar"), entryList, ';');
701 entryList = config->readListEntry (QString::fromLatin1("StatusBar"));
702 entry = entryList.first();
703 if (entry == QString::fromLatin1("Disabled"))
704 sb->hide();
705 else
706 sb->show();
707 if(d->showStatusBarAction)
708 d->showStatusBarAction->setChecked(!sb->isHidden());
709 }
710
711 QMenuBar* mb = internalMenuBar();
712 if (mb) {
713 entryList.clear();
714//US i = config->readListEntry (QString::fromLatin1("MenuBar"), entryList, ';');
715 entryList = config->readListEntry (QString::fromLatin1("MenuBar"));
716 entry = entryList.first();
717 if (entry==QString::fromLatin1("Disabled"))
718 {
719 mb->hide();
720 } else
721 {
722 mb->show();
723 }
724 }
725
726 int n = 1; // Toolbar counter. toolbars are counted from 1,
727 KToolBar *toolbar;
728 QPtrListIterator<KToolBar> it( toolBarIterator() ); // must use own iterator
729
730 for ( ; it.current(); ++it) {
731 toolbar= it.current();
732 QString group;
733 if (!configGroup.isEmpty())
734 {
735 // Give a number to the toolbar, but prefer a name if there is one,
736 // because there's no real guarantee on the ordering of toolbars
737 group = (!::qstrcmp(toolbar->name(), "unnamed") ? QString::number(n) : QString(" ")+toolbar->name());
738 group.prepend(" Toolbar");
739 group.prepend(configGroup);
740 }
741 toolbar->applySettings(config, group);
742 n++;
743 }
744
745 finalizeGUI( true );
746 }
747
748void KMainWindow::finalizeGUI( bool force )
749{
750 //kdDebug(200) << "KMainWindow::finalizeGUI force=" << force << endl;
751 // The whole reason for this is that moveToolBar relies on the indexes
752 // of the other toolbars, so in theory it should be called only once per
753 // toolbar, but in increasing order of indexes.
754 // Since we can't do that immediately, we move them, and _then_
755 // we call positionYourself again for each of them, but this time
756 // the toolbariterator should give them in the proper order.
757 // Both the XMLGUI and applySettings call this, hence "force" for the latter.
758 QPtrListIterator<KToolBar> it( toolBarIterator() );
759 for ( ; it.current() ; ++ it )
760 it.current()->positionYourself( force );
761
762 d->settingsDirty = false;
763}
764
765void KMainWindow::saveWindowSize( KConfig * config ) const
766{
767/*US
768 int scnum = QApplication::desktop()->screenNumber(parentWidget());
769 QRect desk = QApplication::desktop()->screenGeometry(scnum);
770*/
771 QRect desk = KGlobalSettings::desktopGeometry(0);
772
773 QRect size( desk.width(), width(), desk.height(), height() );
774 if(size != d->defaultWindowSize){
775 config->writeEntry(QString::fromLatin1("Width %1").arg(desk.width()), width() );
776 config->writeEntry(QString::fromLatin1("Height %1").arg(desk.height()), height() );
777 }
778 else{
779 config->deleteEntry(QString::fromLatin1("Width %1").arg(desk.width()));
780 config->deleteEntry(QString::fromLatin1("Height %1").arg(desk.height()));
781 }
782}
783
784void KMainWindow::restoreWindowSize( KConfig * config )
785{
786 if (d->care_about_geometry) {
787 parseGeometry(true);
788 } else {
789 // restore the size
790/*US int scnum = QApplication::desktop()->screenNumber(parentWidget());
791 QRect desk = QApplication::desktop()->screenGeometry(scnum);
792*/
793 QRect desk = KGlobalSettings::desktopGeometry(0);
794
795 QSize size( config->readNumEntry( QString::fromLatin1("Width %1").arg(desk.width()), 0 ),
796 config->readNumEntry( QString::fromLatin1("Height %1").arg(desk.height()), 0 ) );
797 if (size.isEmpty()) {
798 // try the KDE 2.0 way
799 size = QSize( config->readNumEntry( QString::fromLatin1("Width"), 0 ),
800 config->readNumEntry( QString::fromLatin1("Height"), 0 ) );
801 if (!size.isEmpty()) {
802 // make sure the other resolutions don't get old settings
803 config->writeEntry( QString::fromLatin1("Width"), 0 );
804 config->writeEntry( QString::fromLatin1("Height"), 0 );
805 }
806 }
807 if ( !size.isEmpty() )
808 resize( size );
809 }
810}
811
812bool KMainWindow::initialGeometrySet() const
813{
814 return d->care_about_geometry;
815}
816
817void KMainWindow::ignoreInitialGeometry()
818{
819 d->care_about_geometry = false;
820}
821
822void KMainWindow::setSettingsDirty()
823{
824 //kdDebug(200) << "KMainWindow::setSettingsDirty" << endl;
825 d->settingsDirty = true;
826 if ( d->autoSaveSettings )
827 {
828 // Use a timer to save "immediately" user-wise, but not too immediately
829 // (to compress calls and save only once, in case of multiple changes)
830 if ( !d->settingsTimer )
831 {
832 d->settingsTimer = new QTimer( this );
833 connect( d->settingsTimer, SIGNAL( timeout() ), SLOT( saveAutoSaveSettings() ) );
834 }
835 d->settingsTimer->start( 500, true );
836 }
837}
838
839bool KMainWindow::settingsDirty() const
840{
841 return d->settingsDirty;
842}
843
844QString KMainWindow::settingsGroup() const
845{
846 return d->autoSaveGroup;
847}
848
849void KMainWindow::resizeEvent( QResizeEvent * )
850{
851 if ( d->autoSaveWindowSize )
852 setSettingsDirty();
853}
854
855bool KMainWindow::hasMenuBar()
856{
857 return (internalMenuBar());
858}
859
860//US KMenuBar *KMainWindow::menuBar()
861QMenuBar *KMainWindow::menuBar()
862{
863//US KMenuBar * mb = internalMenuBar();
864 QMenuBar * mb = internalMenuBar();
865 if ( !mb ) {
866//US mb = new KMenuBar( this );
867 mb = new QMenuBar( this );
868 // trigger a re-layout and trigger a call to the private
869 // setMenuBar method.
870 QMainWindow::menuBar();
871 }
872 return mb;
873}
874
875//US KStatusBar *KMainWindow::statusBar()
876QStatusBar *KMainWindow::statusBar()
877{
878//US KStatusBar * sb = internalStatusBar();
879 QStatusBar * sb = internalStatusBar();
880 if ( !sb ) {
881//US sb = new KStatusBar( this );
882 sb = new QStatusBar( this );
883 // trigger a re-layout and trigger a call to the private
884 // setStatusBar method.
885 QMainWindow::statusBar();
886 }
887 return sb;
888}
889
890void KMainWindow::shuttingDown()
891{
892 // Needed for Qt <= 3.0.3 at least to prevent reentrancy
893 // when queryExit() shows a dialog. Check before removing!
894 static bool reentrancy_protection = false;
895 if (!reentrancy_protection)
896 {
897 reentrancy_protection = true;
898 // call the virtual queryExit
899 queryExit();
900 reentrancy_protection = false;
901 }
902
903}
904
905//US KMenuBar *KMainWindow::internalMenuBar()
906QMenuBar *KMainWindow::internalMenuBar()
907{
908//US QObjectList *l = queryList( "KMenuBar", 0, false, false );
909 QObjectList *l = queryList( "QMenuBar", 0, false, false );
910 if ( !l || !l->first() ) {
911 delete l;
912 return 0;
913 }
914
915//US KMenuBar *m = (KMenuBar*)l->first();
916 QMenuBar *m = (QMenuBar*)l->first();
917 delete l;
918 return m;
919}
920
921//US KStatusBar *KMainWindow::internalStatusBar()
922QStatusBar *KMainWindow::internalStatusBar()
923{
924//US QObjectList *l = queryList( "KStatusBar", 0, false, false );
925 QObjectList *l = queryList( "QStatusBar", 0, false, false );
926 if ( !l || !l->first() ) {
927 delete l;
928 return 0;
929 }
930
931//US KStatusBar *s = (KStatusBar*)l->first();
932 QStatusBar *s = (QStatusBar*)l->first();
933 delete l;
934 return s;
935}
936
937void KMainWindow::childEvent( QChildEvent* e)
938{
939 QMainWindow::childEvent( e );
940}
941
942void KMainWindow::paintEvent( QPaintEvent * )
943{
944 // do nothing
945}
946
947QSize KMainWindow::sizeForCentralWidgetSize(QSize size)
948{
949 KToolBar *tb = (KToolBar*)child( "mainToolBar", "KToolBar" );
950 if (tb && !tb->isHidden()) {
951 switch( tb->barPos() )
952 {
953 case KToolBar::Top:
954 case KToolBar::Bottom:
955 size += QSize(0, tb->sizeHint().height());
956 break;
957
958 case KToolBar::Left:
959 case KToolBar::Right:
960 size += QSize(toolBar()->sizeHint().width(), 0);
961 break;
962
963 case KToolBar::Flat:
964//US size += QSize(0, 3+kapp->style().pixelMetric( QStyle::PM_DockWindowHandleExtent ));
965 size += QSize(0, tb->sizeHint().height());
966 break;
967
968 default:
969 break;
970 }
971 }
972//US KMenuBar *mb = menuBar();
973 QMenuBar *mb = menuBar();
974 if (!mb->isHidden()) {
975 size += QSize(0,mb->heightForWidth(size.width()));
976/*US if (style().styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, this))
977 size += QSize( 0, dockWindowsMovable() ? 1 : 2);
978*/
979 size += QSize( 0, 2);
980 }
981 QStatusBar *sb = internalStatusBar();
982 if( sb && !sb->isHidden() )
983 size += QSize(0, sb->sizeHint().height());
984
985 return size;
986}
987
988// why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI;
989void KMainWindow::finalizeGUI( KXMLGUIClient *client )
990{ /*US KXMLGUIBuilder::finalizeGUI( client );*/ }
991
992void KMainWindow::virtual_hook( int id, void* data )
993{ /*US KXMLGUIBuilder::virtual_hook( id, data );*/
994 KXMLGUIClient::virtual_hook( id, data ); }
diff --git a/microkde/kdeui/kmainwindow.h b/microkde/kdeui/kmainwindow.h
new file mode 100644
index 0000000..e76e732
--- a/dev/null
+++ b/microkde/kdeui/kmainwindow.h
@@ -0,0 +1,776 @@
1/*
2 This file is part of the KDE libraries
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 version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17
18 $Id$
19
20*/
21
22
23
24#ifndef KMAINWINDOW_H
25#define KMAINWINDOW_H
26
27/*US
28#include "kxmlguifactory.h"
29#include "kxmlguiclient.h"
30#include "kxmlguibuilder.h"
31#include <qmetaobject.h>
32
33class KPopupMenu;
34class KXMLGUIFactory;
35class KConfig;
36class KHelpMenu;
37class KStatusBar;
38class QStatusBar;
39class KMenuBar;
40class KMWSessionManaged;
41class KAccel;
42class KToolBarMenuAction;
43*/
44
45class QMenuBar;
46class QStatusBar;
47class KMainWindowPrivate;
48class KAction;
49
50#include <ktoolbar.h>
51#include <ktoolbarhandler.h>
52#include <kxmlguiclient.h>
53#include <qmainwindow.h>
54#include <qptrlist.h>
55
56class KActionCollection;
57
58class KMainWindow : public QMainWindow, virtual public KXMLGUIClient
59{
60 Q_OBJECT
61
62private:
63//US create private defaultconstructor
64 KMainWindow() {;};
65
66public:
67public:
68 /**
69 * Construct a main window.
70 *
71 * @param parent The widget parent. This is usually 0 but it may also be the window
72 * group leader. In that case, the KMainWindow becomes sort of a
73 * secondary window.
74 *
75 * @param name The object name. For session management and window management to work
76 * properly, all main windows in the application should have a
77 * different name. When passing 0 (the default), KMainWindow will create
78 * a unique name, but it's recommended to explicitly pass a window name that will
79 * also describe the type of the window. If there can be several windows of the same
80 * type, append '#' (hash) to the name, and KMainWindow will append numbers to make
81 * the names unique. For example, for a mail client which has one main window showing
82 * the mails and folders, and which can also have one or more windows for composing
83 * mails, the name for the folders window should be e.g. "mainwindow" and
84 * for the composer windows "composer#".
85 *
86 * @param f Specify the widget flags. The default is
87 * WType_TopLevel and WDestructiveClose. TopLevel indicates that a
88 * main window is a toplevel window, regardless of whether it has a
89 * parent or not. DestructiveClose indicates that a main window is
90 * automatically destroyed when its window is closed. Pass 0 if
91 * you do not want this behavior.
92 *
93 * KMainWindows must be created on the heap with 'new', like:
94 * <pre> KMainWindow *kmw = new KMainWindow (...</pre>
95 **/
96 KMainWindow( QWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose );
97
98
99 /**
100 * Destructor.
101 *
102 * Will also destroy the toolbars, and menubar if
103 * needed.
104 */
105 virtual ~KMainWindow();
106
107 /**
108 * Retrieve the standard help menu.
109 *
110 * It contains entires for the
111 * help system (activated by F1), an optional "What's This?" entry
112 * (activated by Shift F1), an application specific dialog box,
113 * and an "About KDE" dialog box.
114 *
115 * Example (adding a standard help menu to your application):
116 * <pre>
117 * KPopupMenu *help = helpMenu( <myTextString> );
118 * menuBar()->insertItem( i18n("&Help"), help );
119 * </pre>
120 *
121 * @param aboutAppText The string that is used in the application
122 * specific dialog box. If you leave this string empty the
123 * information in the global @ref KAboutData of the
124 * application will be used to make a standard dialog box.
125 *
126 * @param showWhatsThis Set this to false if you do not want to include
127 * the "What's This" menu entry.
128 *
129 * @return A standard help menu.
130 */
131//US KPopupMenu* helpMenu( const QString &aboutAppText = QString::null,
132//US bool showWhatsThis = TRUE );
133
134 /**
135 * Returns the help menu. Creates a standard help menu if none exists yet.
136 *
137 * It contains entries for the
138 * help system (activated by F1), an optional "What's This?" entry
139 * (activated by Shift F1), an application specific dialog box,
140 * and an "About KDE" dialog box. You must create the application
141 * specific dialog box yourself. When the "About application"
142 * menu entry is activated, a signal will trigger the
143 * @ref showAboutApplication slot. See @ref showAboutApplication for more
144 * information.
145 *
146 * Example (adding a help menu to your application):
147 * <pre>
148 * menuBar()->insertItem( i18n("&Help"), customHelpMenu() );
149 * </pre>
150 *
151 * @param showWhatsThis Set this to @p false if you do not want to include
152 * the "What's This" menu entry.
153 *
154 * @return A standard help menu.
155 */
156//US KPopupMenu* customHelpMenu( bool showWhatsThis = TRUE );
157
158 /**
159 * @sect Session Management
160 *
161 * Try to restore the toplevel widget as defined by the number (1..X).
162 *
163 * If the session did not contain so high a number, the configuration
164 * is not changed and @p false returned.
165 *
166 * That means clients could simply do the following:
167 * <pre>
168 * if (kapp->isRestored()){
169 * int n = 1;
170 * while (KMainWindow::canBeRestored(n)){
171 * (new childMW)->restore(n);
172 * n++;
173 * }
174 * } else {
175 * // create default application as usual
176 * }
177 * </pre>
178 * Note that @ref QWidget::show() is called implicitly in restore.
179 *
180 * With this you can easily restore all toplevel windows of your
181 * application.
182 *
183 * If your application uses different kinds of toplevel
184 * windows, then you can use @ref KMainWindow::classNameOfToplevel(n)
185 * to determine the exact type before calling the childMW
186 * constructor in the example from above.
187 *
188 * If your client has only one kind of toplevel widgets (which
189 * should be pretty usual) then you should use the RESTORE-macro
190 * for backwards compatibility with 3.1 and 3.0 branches:
191 *
192 * <pre>
193 * if (kapp->isRestored())
194 * RESTORE(childMW)
195 * else {
196 * // create default application as usual
197 * }
198 * </pre>
199 *
200 * The macro expands to the term above but is easier to use and
201 * less code to write.
202 *
203 * For new code or if you have more than one kind of toplevel
204 * widget (each derived from @ref KMainWindow, of course), you can
205 * use the templated @ref kRestoreMainWindows global functions:
206 *
207 * <pre>
208 * if (kapp->isRestored())
209 * kRestoreMainWindows< childMW1, childMW2, childMW3 >();
210 * else {
211 * // create default application as usual
212 * }
213 * </pre>
214 *
215 * Currently, these functions are provided for up to three
216 * template arguments. If you need more, tell us. To help you in
217 * deciding whether or not you can use @ref kRestoreMainWindows, a
218 * define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS is provided.
219 *
220 * @see restore()
221 * @see classNameOfToplevel()
222 *
223 **/
224 static bool canBeRestored( int number );
225
226 /**
227 * Returns the @ref className() of the @p number of the toplevel window which
228 * should be restored.
229 *
230 * This is only useful if your application uses
231 * different kinds of toplevel windows.
232 */
233 static const QString classNameOfToplevel( int number );
234
235 /**
236 * Restore the session specified by @p number.
237 *
238 * Returns @p false if this
239 * fails, otherwise returns @p true and shows the window.
240 * You should call @ref canBeRestored() first.
241 * If @p show is true (default), this widget will be shown automatically.
242 */
243 bool restore( int number, bool show = TRUE );
244
245//US virtual KXMLGUIFactory *guiFactory();
246
247 /**
248 * Create a GUI given a local XML file.
249 *
250 * If @p xmlfile is NULL,
251 * then it will try to construct a local XML filename like
252 * appnameui.rc where 'appname' is your app's name. If that file
253 * does not exist, then the XML UI code will only use the global
254 * (standard) XML file for the layout purposes.
255 *
256 * Note that when passing true for the conserveMemory argument subsequent
257 * calls to guiFactory()->addClient/removeClient may not work as expected.
258 * Also retrieving references to containers like popup menus or toolbars using
259 * the container method will not work.
260 *
261 * @param xmlfile The local xmlfile (relative or absolute)
262 * @param _conserveMemory Specify whether createGUI() should call
263 * @ref KXMLGuiClient::conserveMemory() to free all memory
264 * allocated by the @ref QDomDocument and by the KXMLGUIFactory.
265 */
266 void createGUI( const QString &xmlfile = QString::null, bool _conserveMemory = TRUE );
267
268 /**
269 * Enables the build of a standard help menu when calling createGUI().
270 *
271 * The default behavior is to build one, you must call this function
272 * to disable it
273 */
274 void setHelpMenuEnabled(bool showHelpMenu = true);
275
276 /**
277 * Return @p true when the help menu is enabled
278 */
279 bool isHelpMenuEnabled();
280
281
282 /**
283 * Returns true, if there is a menubar
284 * @since 3.1
285 */
286 bool hasMenuBar();
287
288 /**
289 * Returns a pointer to the menu bar.
290 *
291 * If there is no menu bar yet one will be created.
292 **/
293//US KMenuBar *menuBar();
294 QMenuBar *menuBar();
295
296 /**
297 * Returns a pointer to the status bar.
298 *
299 * If there is no
300 * status bar yet one will be created.
301 */
302//US KStatusBar *statusBar();
303 QStatusBar *statusBar();
304
305 /**
306 * List of members of KMainWindow class.
307 */
308//US static QPtrList<KMainWindow>* memberList;
309
310 /**
311 * Returns a pointer to the toolbar with the specified name.
312 * This refers to toolbars created dynamically from the XML UI
313 * framework. If the toolbar does not exist one will be created.
314 *
315 * @param name The internal name of the toolbar. If no name is
316 * specified "mainToolBar" is assumed.
317 *
318 * @return A pointer to the toolbar
319 **/
320 KToolBar *toolBar( const char *name=0 );
321 // method for getting rid of KDE-Crap
322 QToolBar *tBar( );
323
324 /**
325 * @return An iterator over the list of all toolbars for this window.
326 */
327 QPtrListIterator<KToolBar> toolBarIterator();
328
329 /**
330 * @return A KAccel instance bound to this mainwindow. Used automatically
331 * by KAction to make keybindings work in all cases.
332 */
333 KAccel *accel();
334
335 void setFrameBorderWidth( int ) {}
336
337 /**
338 * Call this to enable "auto-save" of toolbar/menubar/statusbar settings
339 * (and optionally window size).
340 * If the *bars were moved around/shown/hidden when the window is closed,
341 * saveMainWindowSettings( KGlobal::config(), groupName ) will be called.
342 *
343 * @param groupName a name that identifies this "type of window".
344 * You can have several types of window in the same application.
345 *
346 * @param saveWindowSize set it to true to include the window size
347 * when saving.
348 *
349 * Typically, you will call setAutoSaveSettings() in your
350 * KMainWindow-inherited class constructor, and it will take care
351 * of restoring and saving automatically. Make sure you call this
352 * _after all_ your *bars have been created.
353 */
354 void setAutoSaveSettings( const QString & groupName = QString::fromLatin1("MainWindow"),
355 bool saveWindowSize = true );
356
357 /**
358 * Disable the auto-save-settings feature.
359 * You don't normally need to call this, ever.
360 */
361 void resetAutoSaveSettings();
362
363 /**
364 * @return the current autosave setting, i.e. true if setAutoSaveSettings() was called,
365 * false by default or if resetAutoSaveSettings() was called.
366 * @since 3.1
367 */
368 bool autoSaveSettings() const;
369
370 /**
371 * @return the group used for setting-autosaving.
372 * Only meaningful if setAutoSaveSettings() was called.
373 * This can be useful for forcing a save or an apply, e.g. before and after
374 * using KEditToolbar.
375 * @since 3.1
376 */
377 QString autoSaveGroup() const;
378
379 /**
380 * Read settings for statusbar, menubar and toolbar from their respective
381 * groups in the config file and apply them.
382 *
383 * @param config Config file to read the settings from.
384 * @param groupName Group name to use. If not specified, the last used
385 * group name is used.
386 */
387 void applyMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
388
389 /**
390 * Save settings for statusbar, menubar and toolbar to their respective
391 * groups in the config file @p config.
392 *
393 * @param config Config file to save the settings to.
394 * @param groupName Group name to use. If not specified, the last used
395 * group name is used
396 */
397 void saveMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
398
399 /**
400 * Sets whether KMainWindow should provide a menu that allows showing/hiding
401 * the available toolbars ( using @ref KToggleToolBarAction ) . In case there
402 * is only one toolbar configured a simple 'Show <toolbar name here>' menu item
403 * is shown.
404 *
405 * The menu / menu item is implemented using xmlgui. It will be inserted in your
406 * menu structure in the 'Settings' menu.
407 *
408 * If your application uses a non-standard xmlgui resource file then you can
409 * specify the exact position of the menu / menu item by adding a
410 * &lt;Merge name="StandardToolBarMenuHandler" /&gt;
411 * line to the settings menu section of your resource file ( usually appname.rc ).
412 *
413 * Note that you should enable this feature before calling createGUI() ( or similar ) .
414 * You enable/disable it anytime if you pass false to the conserveMemory argument of createGUI.
415 * @since 3.1
416 */
417 void setStandardToolBarMenuEnabled( bool enable );
418 /// @since 3.1
419 bool isStandardToolBarMenuEnabled() const;
420
421
422 /**
423 * Sets whether KMainWindow should provide a menu that allows showing/hiding
424 * of the statusbar ( using @ref KToggleStatusBarAction ).
425 *
426 * The menu / menu item is implemented using xmlgui. It will be inserted
427 * in your menu structure in the 'Settings' menu.
428 *
429 * Note that you should enable this feature before calling createGUI()
430 * ( or similar ).
431 *
432 * If an application maintains the action on its own (i.e. never calls
433 * this function) a connection needs to be made to let KMainWindow
434 * know when that status (hidden/shown) of the statusbar has changed.
435 * For example:
436 * connect(action, SIGNAL(activated()),
437 * kmainwindow, SLOT(setSettingsDirty()));
438 * Otherwise the status (hidden/show) of the statusbar might not be saved
439 * by KMainWindow.
440 * @since 3.2
441 */
442 void createStandardStatusBarAction();
443
444
445 /**
446 * Returns a pointer to the mainwindows action responsible for the toolbars menu
447 * @since 3.1
448 */
449 KAction *toolBarMenuAction();
450
451 // why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI;
452 /// @since 3.1
453 virtual void finalizeGUI( KXMLGUIClient *client );
454
455 /**
456 * @internal
457 */
458 void finalizeGUI( bool force );
459
460 /**
461 * @return true if a -geometry argument was given on the command line,
462 * and this is the first window created (the one on which this option applies)
463 */
464 bool initialGeometrySet() const;
465
466 /**
467 * @internal
468 * Used from Konqueror when reusing the main window.
469 */
470 void ignoreInitialGeometry();
471
472 /**
473 * @return the size the mainwindow should have so that the central
474 * widget will be of @p size.
475 */
476 QSize sizeForCentralWidgetSize(QSize size);
477
478public slots:
479 /**
480 * Makes a KDE compliant caption.
481 *
482 * @param caption Your caption. @em Do @em not include the application name
483 * in this string. It will be added automatically according to the KDE
484 * standard.
485 */
486 virtual void setCaption( const QString &caption );
487 /**
488 * Makes a KDE compliant caption.
489 *
490 * @param caption Your caption. @em Do @em not include the application name
491 * in this string. It will be added automatically according to the KDE
492 * standard.
493 * @param modified Specify whether the document is modified. This displays
494 * an additional sign in the title bar, usually "**".
495 */
496 virtual void setCaption( const QString &caption, bool modified );
497
498 /**
499 * Make a plain caption without any modifications.
500 *
501 * @param caption Your caption. This is the string that will be
502 * displayed in the window title.
503 */
504 virtual void setPlainCaption( const QString &caption );
505
506 /**
507 * Open the help page for the application.
508 *
509 * The application name is
510 * used as a key to determine what to display and the system will attempt
511 * to open <appName>/index.html.
512 *
513 * This method is intended for use by a help button in the toolbar or
514 * components outside the regular help menu. Use @ref helpMenu() when you
515 * want to provide access to the help system from the help menu.
516 *
517 * Example (adding a help button to the first toolbar):
518 *
519 * <pre>
520 * KIconLoader &loader = *KGlobal::iconLoader();
521 * QPixmap pixmap = loader.loadIcon( "help" );
522 * toolBar(0)->insertButton( pixmap, 0, SIGNAL(clicked()),
523 * this, SLOT(appHelpActivated()), true, i18n("Help") );
524 * </pre>
525 *
526 */
527//US void appHelpActivated( void );
528
529 /**
530 * Apply a state change
531 *
532 * Enable and disable actions as defined in the XML rc file
533 * @since 3.1
534 */
535 virtual void slotStateChanged(const QString &newstate);
536
537 /**
538 * Apply a state change
539 *
540 * Enable and disable actions as defined in the XML rc file,
541 * can "reverse" the state (disable the actions which should be
542 * enabled, and vice-versa) if specified.
543 * @since 3.1
544 */
545 void slotStateChanged(const QString &newstate,
546 KXMLGUIClient::ReverseStateChange); // KDE 4.0: remove this
547
548
549 /**
550 * Apply a state change
551 *
552 * Enable and disable actions as defined in the XML rc file,
553 * can "reverse" the state (disable the actions which should be
554 * enabled, and vice-versa) if specified.
555 */
556// void slotStateChanged(const QString &newstate,
557// bool reverse); // KDE 4.0: enable this
558
559 /**
560 * Tell the main window that it should save its settings when being closed.
561 * This is part of the auto-save-settings feature.
562 * For everything related to toolbars this happens automatically,
563 * but you have to call setSettingsDirty() in the slot that toggles
564 * the visibility of the statusbar.
565 */
566 void setSettingsDirty();
567
568protected:
569 void paintEvent( QPaintEvent* e );
570 void childEvent( QChildEvent* e);
571 void resizeEvent( QResizeEvent* e);
572 /**
573 * Reimplemented to call the queryClose() and queryExit() handlers.
574 *
575 * We recommend that you reimplement the handlers rather than @ref closeEvent().
576 * If you do it anyway, ensure to call the base implementation to keep
577 * @ref queryExit() running.
578 */
579 virtual void closeEvent ( QCloseEvent *);
580
581 // KDE4 This seems to be flawed to me. Either the app has only one
582 // mainwindow, so queryClose() is enough, or if it can have more of them,
583 // then the windows should take care of themselves, and queryExit()
584 // would be useful only for the annoying 'really quit' dialog, which
585 // also doesn't make sense in apps with multiple mainwindows.
586 // And saving configuration in something called queryExit()? IMHO
587 // one can e.g. use KApplication::shutDown(), which if nothing else
588 // has at least better fitting name.
589 // See also KApplication::sessionSaving().
590 // This stuff should get changed somehow, so that it at least doesn't
591 // mess with session management.
592 /**
593 Called before the very last window is closed, either by the
594 user or indirectly by the session manager.
595
596 It is not recommended to do any user interaction in this
597 function other than indicating severe errors. Better ask the
598 user on @ref queryClose() (see below).
599
600 A typical usage of @ref queryExit() is to write configuration data back.
601 Note that the application may continue to run after @ref queryExit()
602 (the user may have cancelled a shutdown), so you should not do any cleanups
603 here. The purpose of @ref queryExit() is purely to prepare the application
604 (with possible user interaction) so it can safely be closed later (without
605 user interaction).
606
607 If you need to do serious things on exit (like shutting a
608 dial-up connection down), connect to the signal
609 @ref KApplication::shutDown().
610
611 Default implementation returns @p true. Returning @p false will
612 cancel the exiting. In the latter case, the last window will
613 remain visible. If KApplication::sessionSaving() is true, refusing
614 the exit will also cancel KDE logout.
615
616 @see queryClose()
617 @see KApplication::sessionSaving()
618 */
619 virtual bool queryExit();
620
621 /**
622 Called before the window is closed, either by the user or indirectly by
623 the session manager.
624
625 The purpose of this function is to prepare the window in a way that it is
626 safe to close it, i.e. without the user losing some data.
627
628 Default implementation returns true. Returning @p false will cancel
629 the closing, and, if KApplication::sessionSaving() is true, it will also
630 cancel KDE logout.
631
632 Reimplement this function to prevent the user from losing data.
633 Example:
634 <pre>
635
636 switch ( KMessageBox::warningYesNoCancel( this,
637 i18n("Save changes to document foo?")) ) {
638 case KMessageBox::Yes :
639 // save document here. If saving fails, return FALSE;
640 return TRUE;
641 case KMessageBox::No :
642 return TRUE;
643 default: // cancel
644 return FALSE;
645
646 </pre>
647
648 @see queryExit()
649 @see KApplication::sessionSaving()
650
651 */
652 virtual bool queryClose();
653 /**
654 * Save your instance-specific properties. The function is
655 * invoked when the session manager requests your application
656 * to save its state.
657 *
658 * You @em must @em not change the group of the @p kconfig object, since
659 * KMainWindow uses one group for each window. Please
660 * reimplement these function in childclasses.
661 *
662 * Note: No user interaction is allowed
663 * in this function!
664 *
665 */
666 virtual void saveProperties( KConfig* ) {}
667
668 /**
669 * Read your instance-specific properties.
670 */
671 virtual void readProperties( KConfig* ) {}
672
673 /**
674 * Save your application-wide properties. The function is
675 * invoked when the session manager requests your application
676 * to save its state.
677 *
678 * This function is similar to @ref saveProperties() but is only called for
679 * the very first main window, regardless how many main window are open.
680
681 * Override it if you need to save other data about your documents on
682 * session end. sessionConfig is a config to which that data should be
683 * saved. Normally, you don't need this function. But if you want to save
684 * data about your documents that are not in opened windows you might need
685 * it.
686 *
687 * Default implementation does nothing.
688 */
689 virtual void saveGlobalProperties( KConfig* sessionConfig );
690
691 /**
692 * The counterpart of @ref saveGlobalProperties().
693 *
694 * Read the application-specific properties in again.
695 */
696 virtual void readGlobalProperties( KConfig* sessionConfig );
697 void savePropertiesInternal( KConfig*, int );
698 bool readPropertiesInternal( KConfig*, int );
699
700 /**
701 * For inherited classes
702 */
703 bool settingsDirty() const;
704 /**
705 * For inherited classes
706 */
707 QString settingsGroup() const;
708 /**
709 * For inherited classes
710 * Note that the group must be set before calling
711 */
712 void saveWindowSize( KConfig * config ) const;
713 /**
714 * For inherited classes
715 * Note that the group must be set before calling, and that
716 * a -geometry on the command line has priority.
717 */
718 void restoreWindowSize( KConfig * config );
719
720 /// parse the geometry from the geometry command line argument
721 void parseGeometry(bool parsewidth);
722
723protected slots:
724
725 /**
726 * This slot does nothing.
727 *
728 * It must be reimplemented if you want
729 * to use a custom About Application dialog box. This slot is
730 * connected to the About Application entry in the menu returned
731 * by @ref customHelpMenu.
732 *
733 * Example:
734 * <pre>
735 *
736 * void MyMainLevel::setupInterface()
737 * {
738 * ..
739 * menuBar()->insertItem( i18n("&Help"), customHelpMenu() );
740 * ..
741 * }
742 *
743 * void MyMainLevel::showAboutApplication()
744 * {
745 * <activate your custom dialog>
746 * }
747 * </pre>
748 */
749//US virtual void showAboutApplication();
750
751private slots:
752 /**
753 * Called when the app is shutting down.
754 */
755 void shuttingDown();
756
757 void saveAutoSaveSettings();
758
759private:
760 QToolBar * mQToolBar;
761//US KMenuBar *internalMenuBar();
762 QMenuBar *internalMenuBar();
763//US KStatusBar *internalStatusBar();
764 QStatusBar *internalStatusBar();
765
766 KMainWindowPrivate *d;
767 void initKMainWindow(const char *name);
768
769 QPtrList<KToolBar> toolbarList;
770
771protected:
772 virtual void virtual_hook( int id, void* data );
773
774};
775
776#endif
diff --git a/microkde/kdeui/knuminput.cpp b/microkde/kdeui/knuminput.cpp
new file mode 100644
index 0000000..335d6f4
--- a/dev/null
+++ b/microkde/kdeui/knuminput.cpp
@@ -0,0 +1,1095 @@
1// -*- c-basic-offset: 4 -*-
2/*
3 * knuminput.cpp
4 *
5 * Initial implementation:
6 * Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca>
7 * Rewritten and maintained by:
8 * Copyright (c) 2000 Dirk A. Mueller <mueller@kde.org>
9 * KDoubleSpinBox:
10 * Copyright (c) 2002 Marc Mutz <mutz@kde.org>
11 *
12 * Requires the Qt widget libraries, available at no cost at
13 * http://www.troll.no/
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Library General Public
17 * License as published by the Free Software Foundation; either
18 * version 2 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Library General Public License for more details.
24 *
25 * You should have received a copy of the GNU Library General Public License
26 * along with this library; see the file COPYING.LIB. If not, write to
27 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 * Boston, MA 02111-1307, USA.
29 */
30
31//US #include <config.h>
32#ifdef HAVE_LIMITS_H
33#include <limits.h>
34#endif
35#include <assert.h>
36#include <math.h>
37#include <algorithm>
38
39#include <qlabel.h>
40#include <qlineedit.h>
41#include <qsize.h>
42#include <qslider.h>
43#include <qspinbox.h>
44#include <qstyle.h>
45
46#include <kglobal.h>
47#include <klocale.h>
48#include <kdebug.h>
49
50#include "knumvalidator.h"
51#include "knuminput.h"
52
53static inline int calcDiffByTen( int x, int y ) {
54 // calculate ( x - y ) / 10 without overflowing ints:
55 return ( x / 10 ) - ( y / 10 ) + ( x % 10 - y % 10 ) / 10;
56}
57
58// ----------------------------------------------------------------------------
59
60KNumInput::KNumInput(QWidget* parent, const char* name)
61 : QWidget(parent, name)
62{
63 init();
64}
65
66KNumInput::KNumInput(KNumInput* below, QWidget* parent, const char* name)
67 : QWidget(parent, name)
68{
69 init();
70
71 if(below) {
72 m_next = below->m_next;
73 m_prev = below;
74 below->m_next = this;
75 if(m_next)
76 m_next->m_prev = this;
77 }
78}
79
80void KNumInput::init()
81{
82 m_prev = m_next = 0;
83 m_colw1 = m_colw2 = 0;
84
85 m_label = 0;
86 m_slider = 0;
87 m_alignment = 0;
88}
89
90KNumInput::~KNumInput()
91{
92 if(m_prev)
93 m_prev->m_next = m_next;
94
95 if(m_next)
96 m_next->m_prev = m_prev;
97}
98
99void KNumInput::setLabel(const QString & label, int a)
100{
101 if(label.isEmpty()) {
102 delete m_label;
103 m_label = 0;
104 m_alignment = 0;
105 }
106 else {
107 if (m_label) m_label->setText(label);
108 else m_label = new QLabel(label, this, "KNumInput::QLabel");
109 m_label->setAlignment((a & (~(AlignTop|AlignBottom|AlignVCenter)))
110 | AlignVCenter);
111 // if no vertical alignment set, use Top alignment
112 if(!(a & (AlignTop|AlignBottom|AlignVCenter)))
113 a |= AlignTop;
114 m_alignment = a;
115 }
116
117 layout(true);
118}
119
120QString KNumInput::label() const
121{
122 if (m_label) return m_label->text();
123 return QString::null;
124}
125
126void KNumInput::layout(bool deep)
127{
128 int w1 = m_colw1;
129 int w2 = m_colw2;
130
131 // label sizeHint
132 m_sizeLabel = (m_label ? m_label->sizeHint() : QSize(0,0));
133
134 if(m_label && (m_alignment & AlignVCenter))
135 m_colw1 = m_sizeLabel.width() + 4;
136 else
137 m_colw1 = 0;
138
139 // slider sizeHint
140 m_sizeSlider = (m_slider ? m_slider->sizeHint() : QSize(0, 0));
141
142 doLayout();
143
144 if(!deep) {
145 m_colw1 = w1;
146 m_colw2 = w2;
147 return;
148 }
149
150 KNumInput* p = this;
151 while(p) {
152 p->doLayout();
153 w1 = QMAX(w1, p->m_colw1);
154 w2 = QMAX(w2, p->m_colw2);
155 p = p->m_prev;
156 }
157
158 p = m_next;
159 while(p) {
160 p->doLayout();
161 w1 = QMAX(w1, p->m_colw1);
162 w2 = QMAX(w2, p->m_colw2);
163 p = p->m_next;
164 }
165
166 p = this;
167 while(p) {
168 p->m_colw1 = w1;
169 p->m_colw2 = w2;
170 p = p->m_prev;
171 }
172
173 p = m_next;
174 while(p) {
175 p->m_colw1 = w1;
176 p->m_colw2 = w2;
177 p = p->m_next;
178 }
179
180// kdDebug() << "w1 " << w1 << " w2 " << w2 << endl;
181}
182
183QSizePolicy KNumInput::sizePolicy() const
184{
185 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
186}
187
188QSize KNumInput::sizeHint() const
189{
190 return minimumSizeHint();
191}
192
193void KNumInput::setSteps(int minor, int major)
194{
195 if(m_slider)
196 m_slider->setSteps( minor, major );
197}
198
199
200// ----------------------------------------------------------------------------
201
202KIntSpinBox::KIntSpinBox(QWidget *parent, const char *name)
203 : QSpinBox(0, 99, 1, parent, name)
204{
205 editor()->setAlignment(AlignRight);
206 val_base = 10;
207 setValue(0);
208}
209
210KIntSpinBox::~KIntSpinBox()
211{
212}
213
214KIntSpinBox::KIntSpinBox(int lower, int upper, int step, int value, int base,
215 QWidget* parent, const char* name)
216 : QSpinBox(lower, upper, step, parent, name)
217{
218 editor()->setAlignment(AlignRight);
219 val_base = base;
220 setValue(value);
221}
222
223void KIntSpinBox::setBase(int base)
224{
225 val_base = base;
226}
227
228
229int KIntSpinBox::base() const
230{
231 return val_base;
232}
233
234QString KIntSpinBox::mapValueToText(int v)
235{
236 return QString::number(v, val_base);
237}
238
239int KIntSpinBox::mapTextToValue(bool* ok)
240{
241 return cleanText().toInt(ok, val_base);
242}
243
244void KIntSpinBox::setEditFocus(bool mark)
245{
246 editor()->setFocus();
247 if(mark)
248 editor()->selectAll();
249}
250
251
252// ----------------------------------------------------------------------------
253
254class KIntNumInput::KIntNumInputPrivate {
255public:
256 int referencePoint;
257 short blockRelative;
258 KIntNumInputPrivate( int r )
259 : referencePoint( r ),
260 blockRelative( 0 ) {}
261};
262
263
264KIntNumInput::KIntNumInput(KNumInput* below, int val, QWidget* parent,
265 int _base, const char* name)
266 : KNumInput(below, parent, name)
267{
268 init(val, _base);
269}
270
271KIntNumInput::KIntNumInput(QWidget *parent, const char *name)
272 : KNumInput(parent, name)
273{
274 init(0, 10);
275}
276
277KIntNumInput::KIntNumInput(int val, QWidget *parent, int _base, const char *name)
278 : KNumInput(parent, name)
279{
280 init(val, _base);
281
282}
283
284void KIntNumInput::init(int val, int _base)
285{
286 d = new KIntNumInputPrivate( val );
287 m_spin = new KIntSpinBox(INT_MIN, INT_MAX, 1, val, _base, this, "KIntNumInput::KIntSpinBox");
288 m_spin->setValidator(new KIntValidator(this, _base, "KNumInput::KIntValidtr"));
289 connect(m_spin, SIGNAL(valueChanged(int)), SLOT(spinValueChanged(int)));
290 connect(this, SIGNAL(valueChanged(int)),
291 SLOT(slotEmitRelativeValueChanged(int)));
292
293 setFocusProxy(m_spin);
294 layout(true);
295}
296
297void KIntNumInput::setReferencePoint( int ref ) {
298 // clip to valid range:
299 ref = kMin( maxValue(), kMax( minValue(), ref ) );
300 d->referencePoint = ref;
301}
302
303int KIntNumInput::referencePoint() const {
304 return d->referencePoint;
305}
306
307void KIntNumInput::spinValueChanged(int val)
308{
309 if(m_slider)
310 m_slider->setValue(val);
311
312 emit valueChanged(val);
313}
314
315void KIntNumInput::slotEmitRelativeValueChanged( int value ) {
316 if ( d->blockRelative || !d->referencePoint ) return;
317 emit relativeValueChanged( double( value ) / double( d->referencePoint ) );
318}
319
320void KIntNumInput::setRange(int lower, int upper, int step, bool slider)
321{
322 upper = kMax(upper, lower);
323 lower = kMin(upper, lower);
324 m_spin->setMinValue(lower);
325 m_spin->setMaxValue(upper);
326 m_spin->setLineStep(step);
327
328 step = m_spin->lineStep(); // maybe QRangeControl didn't like out lineStep?
329
330 if(slider) {
331 if (m_slider)
332 m_slider->setRange(lower, upper);
333 else {
334 m_slider = new QSlider(lower, upper, step, m_spin->value(),
335 QSlider::Horizontal, this);
336 m_slider->setTickmarks(QSlider::Below);
337 connect(m_slider, SIGNAL(valueChanged(int)),
338 m_spin, SLOT(setValue(int)));
339 }
340
341 // calculate (upper-lower)/10 without overflowing int's:
342 int major = calcDiffByTen( upper, lower );
343 if ( major==0 ) major = step; // #### workaround Qt bug in 2.1-beta4
344
345 m_slider->setSteps(step, major);
346 m_slider->setTickInterval(major);
347 }
348 else {
349 delete m_slider;
350 m_slider = 0;
351 }
352
353 // check that reference point is still inside valid range:
354 setReferencePoint( referencePoint() );
355
356 layout(true);
357}
358
359void KIntNumInput::setMinValue(int min)
360{
361 setRange(min, m_spin->maxValue(), m_spin->lineStep(), m_slider);
362}
363
364int KIntNumInput::minValue() const
365{
366 return m_spin->minValue();
367}
368
369void KIntNumInput::setMaxValue(int max)
370{
371 setRange(m_spin->minValue(), max, m_spin->lineStep(), m_slider);
372}
373
374int KIntNumInput::maxValue() const
375{
376 return m_spin->maxValue();
377}
378
379void KIntNumInput::setSuffix(const QString &suffix)
380{
381 m_spin->setSuffix(suffix);
382
383 layout(true);
384}
385
386QString KIntNumInput::suffix() const
387{
388 return m_spin->suffix();
389}
390
391void KIntNumInput::setPrefix(const QString &prefix)
392{
393 m_spin->setPrefix(prefix);
394
395 layout(true);
396}
397
398QString KIntNumInput::prefix() const
399{
400 return m_spin->prefix();
401}
402
403void KIntNumInput::setEditFocus(bool mark)
404{
405 m_spin->setEditFocus(mark);
406}
407
408QSize KIntNumInput::minimumSizeHint() const
409{
410 constPolish();
411
412 int w;
413 int h;
414
415 h = 2 + QMAX(m_sizeSpin.height(), m_sizeSlider.height());
416
417 // if in extra row, then count it here
418 if(m_label && (m_alignment & (AlignBottom|AlignTop)))
419 h += 4 + m_sizeLabel.height();
420 else
421 // label is in the same row as the other widgets
422 h = QMAX(h, m_sizeLabel.height() + 2);
423
424 w = m_slider ? m_slider->sizeHint().width() + 8 : 0;
425 w += m_colw1 + m_colw2;
426
427 if(m_alignment & (AlignTop|AlignBottom))
428 w = QMAX(w, m_sizeLabel.width() + 4);
429
430 return QSize(w, h);
431}
432
433void KIntNumInput::doLayout()
434{
435 m_sizeSpin = m_spin->sizeHint();
436 m_colw2 = m_sizeSpin.width();
437
438 if (m_label)
439 m_label->setBuddy(m_spin);
440}
441
442void KIntNumInput::resizeEvent(QResizeEvent* e)
443{
444 int w = m_colw1;
445 int h = 0;
446
447 if(m_label && (m_alignment & AlignTop)) {
448 m_label->setGeometry(0, 0, e->size().width(), m_sizeLabel.height());
449 h += m_sizeLabel.height() + 4;
450 }
451
452 if(m_label && (m_alignment & AlignVCenter))
453 m_label->setGeometry(0, 0, w, m_sizeSpin.height());
454
455 m_spin->setGeometry(w, h, m_slider ? m_colw2 : QMAX(m_colw2, e->size().width() - w), m_sizeSpin.height());
456 w += m_colw2 + 8;
457
458 if(m_slider)
459 m_slider->setGeometry(w, h, e->size().width() - w, m_sizeSpin.height());
460
461 h += m_sizeSpin.height() + 2;
462
463 if(m_label && (m_alignment & AlignBottom))
464 m_label->setGeometry(0, h, m_sizeLabel.width(), m_sizeLabel.height());
465}
466
467KIntNumInput::~KIntNumInput()
468{
469 delete d;
470}
471
472void KIntNumInput::setValue(int val)
473{
474 m_spin->setValue(val);
475 // slider value is changed by spinValueChanged
476}
477
478void KIntNumInput::setRelativeValue( double r ) {
479 if ( !d->referencePoint ) return;
480 ++d->blockRelative;
481 setValue( int( d->referencePoint * r + 0.5 ) );
482 --d->blockRelative;
483}
484
485double KIntNumInput::relativeValue() const {
486 if ( !d->referencePoint ) return 0;
487 return double( value() ) / double ( d->referencePoint );
488}
489
490int KIntNumInput::value() const
491{
492 return m_spin->value();
493}
494
495void KIntNumInput::setSpecialValueText(const QString& text)
496{
497 m_spin->setSpecialValueText(text);
498 layout(true);
499}
500
501QString KIntNumInput::specialValueText() const
502{
503 return m_spin->specialValueText();
504}
505
506void KIntNumInput::setLabel(const QString & label, int a)
507{
508 KNumInput::setLabel(label, a);
509
510 if(m_label)
511 m_label->setBuddy(m_spin);
512}
513
514// ----------------------------------------------------------------------------
515
516class KDoubleNumInput::KDoubleNumInputPrivate {
517public:
518 KDoubleNumInputPrivate( double r )
519 : spin( 0 ),
520 referencePoint( r ),
521 blockRelative ( 0 ) {}
522 KDoubleSpinBox * spin;
523 double referencePoint;
524 short blockRelative;
525};
526
527KDoubleNumInput::KDoubleNumInput(QWidget *parent, const char *name)
528 : KNumInput(parent, name)
529{
530 init(0.0, 0.0, 9999.0, 0.01, 2);
531}
532
533KDoubleNumInput::KDoubleNumInput(double lower, double upper, double value,
534 double step, int precision, QWidget* parent,
535 const char *name)
536 : KNumInput(parent, name)
537{
538 init(value, lower, upper, step, precision);
539}
540
541KDoubleNumInput::KDoubleNumInput(KNumInput *below,
542 double lower, double upper, double value,
543 double step, int precision, QWidget* parent,
544 const char *name)
545 : KNumInput(below, parent, name)
546{
547 init(value, lower, upper, step, precision);
548}
549
550KDoubleNumInput::KDoubleNumInput(double value, QWidget *parent, const char *name)
551 : KNumInput(parent, name)
552{
553 init(value, kMin(0.0, value), kMax(0.0, value), 0.01, 2 );
554}
555
556KDoubleNumInput::KDoubleNumInput(KNumInput* below, double value, QWidget* parent,
557 const char* name)
558 : KNumInput(below, parent, name)
559{
560 init( value, kMin(0.0, value), kMax(0.0, value), 0.01, 2 );
561}
562
563KDoubleNumInput::~KDoubleNumInput()
564{
565 delete d;
566}
567
568// ### remove when BIC changes are allowed again:
569
570bool KDoubleNumInput::eventFilter( QObject * o, QEvent * e ) {
571 return KNumInput::eventFilter( o, e );
572}
573
574void KDoubleNumInput::resetEditBox() {
575
576}
577
578// ### end stuff to remove when BIC changes are allowed again
579
580
581
582void KDoubleNumInput::init(double value, double lower, double upper,
583 double step, int precision )
584{
585 // ### init no longer used members:
586 edit = 0;
587 m_range = true;
588 m_value = 0.0;
589 m_precision = 2;
590 // ### end
591
592 d = new KDoubleNumInputPrivate( value );
593
594 d->spin = new KDoubleSpinBox( lower, upper, step, value, precision,
595 this, "KDoubleNumInput::d->spin" );
596 setFocusProxy(d->spin);
597 connect( d->spin, SIGNAL(valueChanged(double)),
598 this, SIGNAL(valueChanged(double)) );
599 connect( this, SIGNAL(valueChanged(double)),
600 this, SLOT(slotEmitRelativeValueChanged(double)) );
601
602 updateLegacyMembers();
603
604 layout(true);
605}
606
607void KDoubleNumInput::updateLegacyMembers() {
608 // ### update legacy members that are either not private or for
609 // which an inlined getter exists:
610 m_lower = minValue();
611 m_upper = maxValue();
612 m_step = d->spin->lineStep();
613 m_specialvalue = specialValueText();
614}
615
616
617double KDoubleNumInput::mapSliderToSpin( int val ) const
618{
619 // map [slidemin,slidemax] to [spinmin,spinmax]
620 double spinmin = d->spin->minValue();
621 double spinmax = d->spin->maxValue();
622 double slidemin = m_slider->minValue(); // cast int to double to avoid
623 double slidemax = m_slider->maxValue(); // overflow in rel denominator
624 double rel = ( double(val) - slidemin ) / ( slidemax - slidemin );
625 return spinmin + rel * ( spinmax - spinmin );
626}
627
628void KDoubleNumInput::sliderMoved(int val)
629{
630 d->spin->setValue( mapSliderToSpin( val ) );
631}
632
633void KDoubleNumInput::slotEmitRelativeValueChanged( double value )
634{
635 if ( !d->referencePoint ) return;
636 emit relativeValueChanged( value / d->referencePoint );
637}
638
639QSize KDoubleNumInput::minimumSizeHint() const
640{
641 constPolish();
642
643 int w;
644 int h;
645
646 h = 2 + QMAX(m_sizeEdit.height(), m_sizeSlider.height());
647
648 // if in extra row, then count it here
649 if(m_label && (m_alignment & (AlignBottom|AlignTop)))
650 h += 4 + m_sizeLabel.height();
651 else
652 // label is in the same row as the other widgets
653 h = QMAX(h, m_sizeLabel.height() + 2);
654
655 w = m_slider ? m_slider->sizeHint().width() + 8 : 0;
656 w += m_colw1 + m_colw2;
657
658 if(m_alignment & (AlignTop|AlignBottom))
659 w = QMAX(w, m_sizeLabel.width() + 4);
660
661 return QSize(w, h);
662}
663
664void KDoubleNumInput::resizeEvent(QResizeEvent* e)
665{
666 int w = m_colw1;
667 int h = 0;
668
669 if(m_label && (m_alignment & AlignTop)) {
670 m_label->setGeometry(0, 0, e->size().width(), m_sizeLabel.height());
671 h += m_sizeLabel.height() + 4;
672 }
673
674 if(m_label && (m_alignment & AlignVCenter))
675 m_label->setGeometry(0, 0, w, m_sizeEdit.height());
676
677 d->spin->setGeometry(w, h, m_slider ? m_colw2
678 : e->size().width() - w, m_sizeEdit.height());
679 w += m_colw2 + 8;
680
681 if(m_slider)
682 m_slider->setGeometry(w, h, e->size().width() - w, m_sizeEdit.height());
683
684 h += m_sizeEdit.height() + 2;
685
686 if(m_label && (m_alignment & AlignBottom))
687 m_label->setGeometry(0, h, m_sizeLabel.width(), m_sizeLabel.height());
688}
689
690void KDoubleNumInput::doLayout()
691{
692 m_sizeEdit = d->spin->sizeHint();
693 m_colw2 = m_sizeEdit.width();
694}
695
696void KDoubleNumInput::setValue(double val)
697{
698 d->spin->setValue( val );
699}
700
701void KDoubleNumInput::setRelativeValue( double r )
702{
703 if ( !d->referencePoint ) return;
704 ++d->blockRelative;
705 setValue( r * d->referencePoint );
706 --d->blockRelative;
707}
708
709void KDoubleNumInput::setReferencePoint( double ref )
710{
711 // clip to valid range:
712 ref = kMin( maxValue(), kMax( minValue(), ref ) );
713 d->referencePoint = ref;
714}
715
716void KDoubleNumInput::setRange(double lower, double upper, double step,
717 bool slider)
718{
719 if( m_slider ) {
720 // don't update the slider to avoid an endless recursion
721 QSpinBox * spin = d->spin;
722 disconnect(spin, SIGNAL(valueChanged(int)),
723 m_slider, SLOT(setValue(int)) );
724 }
725 d->spin->setRange( lower, upper, step, d->spin->precision() );
726
727 if(slider) {
728 // upcast to base type to get the min/maxValue in int form:
729 QSpinBox * spin = d->spin;
730 int slmax = spin->maxValue();
731 int slmin = spin->minValue();
732 int slvalue = spin->value();
733 int slstep = spin->lineStep();
734 if (m_slider) {
735 m_slider->setRange(slmin, slmax);
736 m_slider->setLineStep(slstep);
737 m_slider->setValue(slvalue);
738 } else {
739 m_slider = new QSlider(slmin, slmax, slstep, slvalue,
740 QSlider::Horizontal, this);
741 m_slider->setTickmarks(QSlider::Below);
742 // feedback line: when one moves, the other moves, too:
743 connect(m_slider, SIGNAL(valueChanged(int)),
744 SLOT(sliderMoved(int)) );
745 }
746 connect(spin, SIGNAL(valueChanged(int)),
747 m_slider, SLOT(setValue(int)) );
748 // calculate ( slmax - slmin ) / 10 without overflowing ints:
749 int major = calcDiffByTen( slmax, slmin );
750 if ( !major ) major = slstep; // ### needed?
751 m_slider->setTickInterval(major);
752 } else {
753 delete m_slider;
754 m_slider = 0;
755 }
756
757 setReferencePoint( referencePoint() );
758
759 layout(true);
760 updateLegacyMembers();
761}
762
763void KDoubleNumInput::setMinValue(double min)
764{
765 setRange(min, maxValue(), d->spin->lineStep(), m_slider);
766}
767
768double KDoubleNumInput::minValue() const
769{
770 return d->spin->minValue();
771}
772
773void KDoubleNumInput::setMaxValue(double max)
774{
775 setRange(minValue(), max, d->spin->lineStep(), m_slider);
776}
777
778double KDoubleNumInput::maxValue() const
779{
780 return d->spin->maxValue();
781}
782
783double KDoubleNumInput::value() const
784{
785 return d->spin->value();
786}
787
788double KDoubleNumInput::relativeValue() const
789{
790 if ( !d->referencePoint ) return 0;
791 return value() / d->referencePoint;
792}
793
794double KDoubleNumInput::referencePoint() const
795{
796 return d->referencePoint;
797}
798
799QString KDoubleNumInput::suffix() const
800{
801 return d->spin->suffix();
802}
803
804QString KDoubleNumInput::prefix() const
805{
806 return d->spin->prefix();
807}
808
809void KDoubleNumInput::setSuffix(const QString &suffix)
810{
811 d->spin->setSuffix( suffix );
812
813 layout(true);
814}
815
816void KDoubleNumInput::setPrefix(const QString &prefix)
817{
818 d->spin->setPrefix( prefix );
819
820 layout(true);
821}
822
823void KDoubleNumInput::setPrecision(int precision)
824{
825 d->spin->setPrecision( precision );
826
827 layout(true);
828}
829
830int KDoubleNumInput::precision() const
831{
832 return d->spin->precision();
833}
834
835void KDoubleNumInput::setSpecialValueText(const QString& text)
836{
837 d->spin->setSpecialValueText( text );
838
839 layout(true);
840 updateLegacyMembers();
841}
842
843void KDoubleNumInput::setLabel(const QString & label, int a)
844{
845 KNumInput::setLabel(label, a);
846
847 if(m_label)
848 m_label->setBuddy(d->spin);
849
850}
851
852// ----------------------------------------------------------------------------
853
854
855// We use a kind of fixed-point arithmetic to represent the range of
856// doubles [mLower,mUpper] in steps of 10^(-mPrecision). Thus, the
857// following relations hold:
858//
859// 1. factor = 10^mPrecision
860// 2. basicStep = 1/factor = 10^(-mPrecision);
861// 3. lowerInt = lower * factor;
862// 4. upperInt = upper * factor;
863// 5. lower = lowerInt * basicStep;
864// 6. upper = upperInt * basicStep;
865class KDoubleSpinBox::Private {
866public:
867 Private( int precision=1 )
868 : mPrecision( precision ),
869 mValidator( 0 )
870 {
871 }
872
873 int factor() const {
874 int f = 1;
875 for ( int i = 0 ; i < mPrecision ; ++i ) f *= 10;
876 return f;
877 }
878
879 double basicStep() const {
880 return 1.0/double(factor());
881 }
882
883 int mapToInt( double value, bool * ok ) const {
884 assert( ok );
885 const double f = factor();
886 if ( value > double(INT_MAX) / f ) {
887 kdWarning() << "KDoubleSpinBox: can't represent value " << value
888 << "in terms of fixed-point numbers with precision "
889 << mPrecision << endl;
890 *ok = false;
891 return INT_MAX;
892 } else if ( value < double(INT_MIN) / f ) {
893 kdWarning() << "KDoubleSpinBox: can't represent value " << value
894 << "in terms of fixed-point numbers with precision "
895 << mPrecision << endl;
896 *ok = false;
897 return INT_MIN;
898 } else {
899 *ok = true;
900 return int( value * f + ( value < 0 ? -0.5 : 0.5 ) );
901 }
902 }
903
904 double mapToDouble( int value ) const {
905 return double(value) * basicStep();
906 }
907
908 int mPrecision;
909 KDoubleValidator * mValidator;
910};
911
912KDoubleSpinBox::KDoubleSpinBox( QWidget * parent, const char * name )
913 : QSpinBox( parent, name )
914{
915 editor()->setAlignment( Qt::AlignRight );
916 d = new Private();
917 updateValidator();
918}
919
920KDoubleSpinBox::KDoubleSpinBox( double lower, double upper, double step,
921 double value, int precision,
922 QWidget * parent, const char * name )
923 : QSpinBox( parent, name )
924{
925 editor()->setAlignment( Qt::AlignRight );
926 d = new Private();
927 setRange( lower, upper, step, precision );
928 setValue( value );
929 connect( this, SIGNAL(valueChanged(int)), SLOT(slotValueChanged(int)) );
930}
931
932KDoubleSpinBox::~KDoubleSpinBox() {
933 delete d; d = 0;
934}
935
936bool KDoubleSpinBox::acceptLocalizedNumbers() const {
937 if ( !d->mValidator ) return true; // we'll set one that does;
938 // can't do it now, since we're const
939 return d->mValidator->acceptLocalizedNumbers();
940}
941
942void KDoubleSpinBox::setAcceptLocalizedNumbers( bool accept ) {
943 if ( !d->mValidator ) updateValidator();
944 d->mValidator->setAcceptLocalizedNumbers( accept );
945}
946
947void KDoubleSpinBox::setRange( double lower, double upper, double step,
948 int precision ) {
949 lower = kMin(upper, lower);
950 upper = kMax(upper, lower);
951 setPrecision( precision, true ); // disable bounds checking, since
952 setMinValue( lower ); // it's done in set{Min,Max}Value
953 setMaxValue( upper ); // anyway and we want lower, upper
954 setLineStep( step ); // and step to have the right precision
955}
956
957int KDoubleSpinBox::precision() const {
958 return d->mPrecision;
959}
960
961void KDoubleSpinBox::setPrecision( int precision ) {
962 setPrecision( precision, false );
963}
964
965void KDoubleSpinBox::setPrecision( int precision, bool force ) {
966 if ( precision < 1 ) return;
967 if ( !force ) {
968 int maxPrec = maxPrecision();
969 if ( precision > maxPrec )
970 precision = maxPrec;
971 }
972 d->mPrecision = precision;
973 updateValidator();
974}
975
976int KDoubleSpinBox::maxPrecision() const {
977 // INT_MAX must be > maxAbsValue * 10^precision
978 // ==> 10^precision < INT_MAX / maxAbsValue
979 // ==> precision < log10 ( INT_MAX / maxAbsValue )
980 // ==> maxPrecision = floor( log10 ( INT_MAX / maxAbsValue ) );
981 double maxAbsValue = kMax( fabs(minValue()), fabs(maxValue()) );
982 if ( maxAbsValue == 0 ) return 6; // return arbitrary value to avoid dbz...
983
984 return int( floor( log10( double(INT_MAX) / maxAbsValue ) ) );
985}
986
987double KDoubleSpinBox::value() const {
988 return d->mapToDouble( base::value() );
989}
990
991void KDoubleSpinBox::setValue( double value ) {
992 if ( value == this->value() ) return;
993 if ( value < minValue() )
994 base::setValue( base::minValue() );
995 else if ( value > maxValue() )
996 base::setValue( base::maxValue() );
997 else {
998 bool ok = false;
999 base::setValue( d->mapToInt( value, &ok ) );
1000 assert( ok );
1001 }
1002}
1003
1004double KDoubleSpinBox::minValue() const {
1005 return d->mapToDouble( base::minValue() );
1006}
1007
1008void KDoubleSpinBox::setMinValue( double value ) {
1009 bool ok = false;
1010 int min = d->mapToInt( value, &ok );
1011 if ( !ok ) return;
1012 base::setMinValue( min );
1013 updateValidator();
1014}
1015
1016
1017double KDoubleSpinBox::maxValue() const {
1018 return d->mapToDouble( base::maxValue() );
1019}
1020
1021void KDoubleSpinBox::setMaxValue( double value ) {
1022 bool ok = false;
1023 int max = d->mapToInt( value, &ok );
1024 if ( !ok ) return;
1025 base::setMaxValue( max );
1026 updateValidator();
1027}
1028
1029double KDoubleSpinBox::lineStep() const {
1030 return d->mapToDouble( base::lineStep() );
1031}
1032
1033void KDoubleSpinBox::setLineStep( double step ) {
1034 bool ok = false;
1035 if ( step > maxValue() - minValue() )
1036 base::setLineStep( 1 );
1037 else
1038 base::setLineStep( kMax( d->mapToInt( step, &ok ), 1 ) );
1039}
1040
1041QString KDoubleSpinBox::mapValueToText( int value ) {
1042 if ( acceptLocalizedNumbers() )
1043 return KGlobal::locale()
1044 ->formatNumber( d->mapToDouble( value ), d->mPrecision );
1045 else
1046 return QString().setNum( d->mapToDouble( value ), 'f', d->mPrecision );
1047}
1048
1049int KDoubleSpinBox::mapTextToValue( bool * ok ) {
1050 double value;
1051 if ( acceptLocalizedNumbers() )
1052 value = KGlobal::locale()->readNumber( cleanText(), ok );
1053 else
1054 value = cleanText().toDouble( ok );
1055 if ( !*ok ) return 0;
1056 if ( value > maxValue() )
1057 value = maxValue();
1058 else if ( value < minValue() )
1059 value = minValue();
1060 return d->mapToInt( value, ok );
1061}
1062
1063void KDoubleSpinBox::setValidator( const QValidator * ) {
1064 // silently discard the new validator. We don't want another one ;-)
1065}
1066
1067void KDoubleSpinBox::slotValueChanged( int value ) {
1068 emit valueChanged( d->mapToDouble( value ) );
1069}
1070
1071void KDoubleSpinBox::updateValidator() {
1072 if ( !d->mValidator ) {
1073 d->mValidator = new KDoubleValidator( minValue(), maxValue(), precision(),
1074 this, "d->mValidator" );
1075 base::setValidator( d->mValidator );
1076 } else
1077 d->mValidator->setRange( minValue(), maxValue(), precision() );
1078}
1079
1080void KNumInput::virtual_hook( int, void* )
1081{ /*BASE::virtual_hook( id, data );*/ }
1082
1083void KIntNumInput::virtual_hook( int id, void* data )
1084{ KNumInput::virtual_hook( id, data ); }
1085
1086void KDoubleNumInput::virtual_hook( int id, void* data )
1087{ KNumInput::virtual_hook( id, data ); }
1088
1089void KIntSpinBox::virtual_hook( int, void* )
1090{ /*BASE::virtual_hook( id, data );*/ }
1091
1092void KDoubleSpinBox::virtual_hook( int, void* )
1093{ /*BASE::virtual_hook( id, data );*/ }
1094
1095//US #include "knuminput.moc"
diff --git a/microkde/kdeui/knuminput.h b/microkde/kdeui/knuminput.h
new file mode 100644
index 0000000..123fefa
--- a/dev/null
+++ b/microkde/kdeui/knuminput.h
@@ -0,0 +1,948 @@
1/*
2 * knuminput.h
3 *
4 * Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca>
5 * Copyright (c) 2000 Dirk A. Mueller <mueller@kde.org>
6 * Copyright (c) 2002 Marc Mutz <mutz@kde.org>
7 *
8 * Requires the Qt widget libraries, available at no cost at
9 * http://www.troll.no/
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 as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
25 */
26
27#ifndef K_NUMINPUT_H
28#define K_NUMINPUT_H
29
30#include <qwidget.h>
31#include <qspinbox.h>
32
33class QLabel;
34class QSlider;
35class QLineEdit;
36class QLayout;
37class QValidator;
38
39class KIntSpinBox;
40
41/* ------------------------------------------------------------------------ */
42
43/**
44 * You need to inherit from this class if you want to implement K*NumInput
45 * for a different variable type
46 *
47 */
48class KNumInput : public QWidget
49{
50 Q_OBJECT
51 Q_PROPERTY( QString label READ label WRITE setLabel )
52public:
53 /**
54 * Default constructor
55 *
56 */
57 KNumInput(QWidget* parent=0, const char* name=0);
58
59 /**
60 * @param below A pointer to another KNumInput.
61 *
62 */
63 KNumInput(KNumInput* below, QWidget* parent=0, const char* name=0);
64 ~KNumInput();
65
66 /**
67 * Sets the text and alignment of the main description label.
68 *
69 * @param label The text of the label.
70 * Use QString::null to remove an existing one.
71 *
72 * @param a one of @p AlignLeft, @p AlignHCenter, YAlignRight and
73 * @p AlignTop, @p AlignVCenter, @p AlignBottom.
74 * default is @p AlignLeft | @p AlignTop.
75 *
76 * The vertical alignment flags have special meaning with this
77 * widget:
78 *
79 * @li @p AlignTop The label is placed above the edit/slider
80 * @li @p AlignVCenter The label is placed left beside the edit
81 * @li @p AlignBottom The label is placed below the edit/slider
82 *
83 */
84 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
85
86 /**
87 * @return the text of the label.
88 */
89 QString label() const;
90
91 /**
92 * @return if the num input has a slider.
93 * @since 3.1
94 */
95 bool showSlider() const { return m_slider; }
96
97 /**
98 * Sets the spacing of tickmarks for the slider.
99 *
100 * @param minor Minor tickmark separation.
101 * @param major Major tickmark separation.
102 */
103 void setSteps(int minor, int major);
104
105 /**
106 * Specifies that this widget may stretch horizontally, but is
107 * fixed vertically (like @ref QSpinBox itself).
108 */
109 QSizePolicy sizePolicy() const;
110
111 /**
112 * Returns a size which fits the contents of the control.
113 *
114 * @return the preferred size necessary to show the control
115 */
116 virtual QSize sizeHint() const;
117
118protected:
119 /**
120 * Call this function whenever you change something in the geometry
121 * of your KNumInput child.
122 *
123 */
124 void layout(bool deep);
125
126 /**
127 * You need to overwrite this method and implement your layout
128 * calculations there.
129 *
130 * See KIntNumInput::doLayout and KDoubleNumInput::doLayout implementation
131 * for details.
132 *
133 */
134 virtual void doLayout() = 0;
135
136 KNumInput* m_prev, *m_next;
137 int m_colw1, m_colw2;
138
139 QLabel* m_label;
140 QSlider* m_slider;
141 QSize m_sizeSlider, m_sizeLabel;
142
143 int m_alignment;
144
145private:
146 void init();
147
148protected:
149 virtual void virtual_hook( int id, void* data );
150private:
151 class KNumInputPrivate;
152 KNumInputPrivate *d;
153};
154
155/* ------------------------------------------------------------------------ */
156
157/**
158 * KIntNumInput combines a @ref QSpinBox and optionally a @ref QSlider
159 * with a label to make an easy to use control for setting some integer
160 * parameter. This is especially nice for configuration dialogs,
161 * which can have many such combinated controls.
162 *
163 * The slider is created only when the user specifies a range
164 * for the control using the setRange function with the slider
165 * parameter set to "true".
166 *
167 * A special feature of KIntNumInput, designed specifically for
168 * the situation when there are several KIntNumInputs in a column,
169 * is that you can specify what portion of the control is taken by the
170 * QSpinBox (the remaining portion is used by the slider). This makes
171 * it very simple to have all the sliders in a column be the same size.
172 *
173 * It uses @ref KIntValidator validator class. KIntNumInput enforces the
174 * value to be in the given range, and can display it in any base
175 * between 2 and 36.
176 *
177 * @short An input widget for integer numbers, consisting of a spinbox and a slider.
178 * @version $Id$
179 */
180
181class KIntNumInput : public KNumInput
182{
183 Q_OBJECT
184 Q_PROPERTY( int value READ value WRITE setValue )
185 Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
186 Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
187 Q_PROPERTY( int referencePoint READ referencePoint WRITE setReferencePoint )
188 Q_PROPERTY( QString suffix READ suffix WRITE setSuffix )
189 Q_PROPERTY( QString prefix READ prefix WRITE setPrefix )
190 Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText )
191
192public:
193 /**
194 * Constructs an input control for integer values
195 * with base 10 and initial value 0.
196 */
197 KIntNumInput(QWidget *parent=0, const char *name=0);
198 /**
199 * Constructor
200 * It constructs a QSpinBox that allows the input of integer numbers
201 * in the range of -INT_MAX to +INT_MAX. To set a descriptive label,
202 * use setLabel(). To enforce the value being in a range and optionally to
203 * attach a slider to it, use setRange().
204 *
205 * @param value initial value for the control
206 * @param base numeric base used for display
207 * @param parent parent QWidget
208 * @param name internal name for this widget
209 */
210 KIntNumInput(int value, QWidget* parent=0, int base = 10, const char *name=0);
211
212 /**
213 * Constructor
214 *
215 * the difference to the one above is the "below" parameter. It tells
216 * this instance that it is visually put below some other KNumInput widget.
217 * Note that these two KNumInput's need not to have the same parent widget
218 * or be in the same layout group.
219 * The effect is that it'll adjust it's layout in correspondence
220 * with the layout of the other KNumInput's (you can build an arbitary long
221 * chain).
222 *
223 * @param below append KIntNumInput to the KNumInput chain
224 * @param value initial value for the control
225 * @param base numeric base used for display
226 * @param parent parent QWidget
227 * @param name internal name for this widget
228 */
229 KIntNumInput(KNumInput* below, int value, QWidget* parent=0, int base = 10, const char *name=0);
230
231 /**
232 * Destructor
233 *
234 *
235 */
236 virtual ~KIntNumInput();
237
238 /**
239 * @return the current value.
240 */
241 int value() const;
242
243 /**
244 * @return the curent value in units of the @ref referencePoint.
245 * @since 3.1
246 */
247 double relativeValue() const;
248
249 /**
250 * @return the current reference point
251 * @since 3.1
252 */
253 int referencePoint() const;
254
255 /**
256 * @return the suffix displayed behind the value.
257 * @see #setSuffix()
258 */
259 QString suffix() const;
260 /**
261 * @return the prefix displayed in front of the value.
262 * @see #setPrefix()
263 */
264 QString prefix() const;
265 /**
266 * @return the string displayed for a special value.
267 * @see #setSpecialValueText()
268 */
269 QString specialValueText() const;
270
271 /**
272 * @param min minimum value
273 * @param max maximum value
274 * @param step step size for the QSlider
275 */
276 void setRange(int min, int max, int step=1, bool slider=true);
277 /**
278 * Sets the minimum value.
279 */
280 void setMinValue(int min);
281 /**
282 * @return the minimum value.
283 */
284 int minValue() const;
285 /**
286 * Sets the maximum value.
287 */
288 void setMaxValue(int max);
289 /**
290 * @return the maximum value.
291 */
292 int maxValue() const;
293
294 /**
295 * Sets the special value text. If set, the SpinBox will display
296 * this text instead of the numeric value whenever the current
297 * value is equal to minVal(). Typically this is used for indicating
298 * that the choice has a special (default) meaning.
299 */
300 void setSpecialValueText(const QString& text);
301
302 /**
303 * @reimplemented
304 */
305 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
306
307 /**
308 * This method returns the minimum size necessary to display the
309 * control. The minimum size is enough to show all the labels
310 * in the current font (font change may invalidate the return value).
311 *
312 * @return the minimum size necessary to show the control
313 */
314 virtual QSize minimumSizeHint() const;
315
316public slots:
317 /**
318 * Sets the value of the control.
319 */
320 void setValue(int);
321
322 /**
323 * Sets the value in units of the @ref referencePoint
324 * @since 3.1
325 */
326 void setRelativeValue(double);
327
328 /**
329 * Sets the reference point for @ref relativeValue.
330 * @since 3.1
331 */
332 void setReferencePoint(int);
333
334 /**
335 * Sets the suffix to @p suffix.
336 * Use QString::null to disable this feature.
337 * Formatting has to be provided (e.g. a space separator between the
338 * prepended @p value and the suffix's text has to be provided
339 * as the first character in the suffix).
340 *
341 * @see QSpinBox::setSuffix(), #setPrefix()
342 */
343 void setSuffix(const QString &suffix);
344
345 /**
346 * Sets the prefix to @p prefix.
347 * Use QString::null to disable this feature.
348 * Formatting has to be provided (see above).
349 *
350 * @see QSpinBox::setPrefix(), #setSuffix()
351 */
352 void setPrefix(const QString &prefix);
353
354 /**
355 * sets focus to the edit widget and marks all text in if mark == true
356 *
357 */
358 void setEditFocus( bool mark = true );
359
360signals:
361 /**
362 * Emitted every time the value changes (by calling @ref setValue() or
363 * by user interaction).
364 */
365 void valueChanged(int);
366
367 /**
368 * Emitted whenever @ref #valueChanged is. Contains the change
369 * relative to the @ref referencePoint.
370 * @since 3.1
371 */
372 void relativeValueChanged(double);
373
374private slots:
375 void spinValueChanged(int);
376 void slotEmitRelativeValueChanged(int);
377
378protected:
379 /**
380 * @reimplemented
381 */
382 virtual void doLayout();
383 /**
384 * @reimplemented
385 */
386 void resizeEvent ( QResizeEvent * );
387
388 KIntSpinBox* m_spin;
389 QSize m_sizeSpin;
390
391private:
392 void init(int value, int _base);
393
394protected:
395 virtual void virtual_hook( int id, void* data );
396private:
397 class KIntNumInputPrivate;
398 KIntNumInputPrivate *d;
399};
400
401
402/* ------------------------------------------------------------------------ */
403
404class KDoubleLine;
405
406/**
407 * KDoubleNumInput combines a @ref QSpinBox and optionally a @ref QSlider
408 * with a label to make an easy to use control for setting some float
409 * parameter. This is especially nice for configuration dialogs,
410 * which can have many such combinated controls.
411 *
412 * The slider is created only when the user specifies a range
413 * for the control using the setRange function with the slider
414 * parameter set to "true".
415 *
416 * A special feature of KDoubleNumInput, designed specifically for
417 * the situation when there are several instances in a column,
418 * is that you can specify what portion of the control is taken by the
419 * QSpinBox (the remaining portion is used by the slider). This makes
420 * it very simple to have all the sliders in a column be the same size.
421 *
422 * It uses the @ref KDoubleValidator validator class. KDoubleNumInput
423 * enforces the value to be in the given range, but see the class
424 * documentation of @ref KDoubleSpinBox for the tricky
425 * interrelationship of precision and values. All of what is said
426 * there applies here, too.
427 *
428 * @see KIntNumInput, KDoubleSpinBox
429 * @short An input control for real numbers, consisting of a spinbox and a slider.
430 */
431
432class KDoubleNumInput : public KNumInput
433{
434 Q_OBJECT
435 Q_PROPERTY( double value READ value WRITE setValue )
436 Q_PROPERTY( double minValue READ minValue WRITE setMinValue )
437 Q_PROPERTY( double maxValue READ maxValue WRITE setMaxValue )
438 Q_PROPERTY( QString suffix READ suffix WRITE setSuffix )
439 Q_PROPERTY( QString prefix READ prefix WRITE setPrefix )
440 Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText )
441 Q_PROPERTY( int precision READ precision WRITE setPrecision )
442
443public:
444 /**
445 * Constructs an input control for double values
446 * with initial value 0.00.
447 */
448 KDoubleNumInput(QWidget *parent=0, const char *name=0);
449
450 /**
451 * @deprecated (value is rounded to a multiple of 1/100)
452 * Constructor
453 *
454 * @param value initial value for the control
455 * @param parent parent QWidget
456 * @param name internal name for this widget
457 */
458 KDoubleNumInput(double value, QWidget *parent=0, const char *name=0);
459
460 /**
461 * Constructor
462 *
463 * @param lower lower boundary value
464 * @param upper upper boundary value
465 * @param value initial value for the control
466 * @param step step size to use for up/down arrow clicks
467 * @param precision number of digits after the decimal point
468 * @param parent parent QWidget
469 * @param name internal name for this widget
470 * @since 3.1
471 */
472 KDoubleNumInput(double lower, double upper, double value, double step=0.01,
473 int precision=2, QWidget *parent=0, const char *name=0);
474
475 /**
476 * destructor
477 */
478 virtual ~KDoubleNumInput();
479
480 /**
481 * @deprecated (rounds @p value to a mulitple of 1/100)
482 * Constructor
483 *
484 * puts it below other KNumInput
485 *
486 * @param below
487 * @param value initial value for the control
488 * @param parent parent QWidget
489 * @param name internal name for this widget
490 **/
491 KDoubleNumInput(KNumInput* below, double value, QWidget* parent=0, const char* name=0);
492
493 /**
494 * Constructor
495 *
496 * puts it below other KNumInput
497 *
498 * @param lower lower boundary value
499 * @param upper upper boundary value
500 * @param value initial value for the control
501 * @param step step size to use for up/down arrow clicks
502 * @param precision number of digits after the decimal point
503 * @param parent parent QWidget
504 * @param name internal name for this widget
505 * @since 3.1
506 */
507 KDoubleNumInput(KNumInput* below,
508 double lower, double upper, double value, double step=0.02,
509 int precision=2, QWidget *parent=0, const char *name=0);
510
511 /**
512 * @return the current value.
513 */
514 double value() const;
515
516 /**
517 * @return the suffix.
518 * @see #setSuffix()
519 */
520 QString suffix() const;
521
522 /**
523 * @return the prefix.
524 * @see #setPrefix()
525 */
526 QString prefix() const;
527
528 /**
529 * @return the precision.
530 * @see #setPrecision()
531 */
532 int precision() const;
533
534 /**
535 * @return the string displayed for a special value.
536 * @see #setSpecialValueText()
537 */
538 QString specialValueText() const { return m_specialvalue; }
539
540 /**
541 * @param min minimum value
542 * @param max maximum value
543 * @param step step size for the QSlider
544 */
545 void setRange(double min, double max, double step=1, bool slider=true);
546 /**
547 * Sets the minimum value.
548 */
549 void setMinValue(double min);
550 /**
551 * @return the minimum value.
552 */
553 double minValue() const;
554 /**
555 * Sets the maximum value.
556 */
557 void setMaxValue(double max);
558 /**
559 * @return the maximum value.
560 */
561 double maxValue() const;
562
563 /**
564 * Specifies the number of digits to use.
565 */
566 void setPrecision(int precision);
567
568 /**
569 * @return the reference point for @ref #relativeValue calculation
570 * @since 3.1
571 */
572 double referencePoint() const;
573
574 /**
575 * @return the current value in units of @ref #referencePoint.
576 * @since 3.1
577 */
578 double relativeValue() const;
579
580 /**
581 * Sets the special value text. If set, the spin box will display
582 * this text instead of the numeric value whenever the current
583 * value is equal to @ref #minVal(). Typically this is used for indicating
584 * that the choice has a special (default) meaning.
585 */
586 void setSpecialValueText(const QString& text);
587
588 /**
589 * @reimplemented
590 */
591 virtual void setLabel(const QString & label, int a = AlignLeft | AlignTop);
592 /**
593 * @reimplemented
594 */
595 virtual QSize minimumSizeHint() const;
596 /**
597 * @reimplemented
598 */
599 virtual bool eventFilter(QObject*, QEvent*);
600
601public slots:
602 /**
603 * Sets the value of the control.
604 */
605 void setValue(double);
606
607 /**
608 * Sets the value in units of @ref #referencePoint.
609 * @since 3.1
610 */
611 void setRelativeValue(double);
612
613 /**
614 * Sets the reference Point to @p ref. It @p ref == 0, emitting of
615 * @ref #relativeValueChanged is blocked and @ref #relativeValue
616 * just returns 0.
617 * @since 3.1
618 */
619 void setReferencePoint(double ref);
620
621 /**
622 * Sets the suffix to be displayed to @p suffix. Use QString::null to disable
623 * this feature. Note that the suffix is attached to the value without any
624 * spacing. So if you prefer to display a space separator, set suffix
625 * to something like " cm".
626 * @see #setSuffix()
627 */
628 void setSuffix(const QString &suffix);
629
630 /**
631 * Sets the prefix to be displayed to @p prefix. Use QString::null to disable
632 * this feature. Note that the prefix is attached to the value without any
633 * spacing.
634 * @see #setPrefix()
635 */
636 void setPrefix(const QString &prefix);
637
638signals:
639 /**
640 * Emitted every time the value changes (by calling @ref setValue() or
641 * by user interaction).
642 */
643 void valueChanged(double);
644 /**
645 * This is an overloaded member function, provided for
646 * convenience. It essentially behaves like the above function.
647 *
648 * Contains the value in units of @ref #referencePoint.
649 * @since 3.1
650 */
651 void relativeValueChanged(double);
652
653private slots:
654 void sliderMoved(int);
655 void slotEmitRelativeValueChanged(double);
656
657protected:
658
659 /**
660 * @reimplemented
661 */
662 virtual void doLayout();
663 /**
664 * @reimplemented
665 */
666 void resizeEvent ( QResizeEvent * );
667 virtual void resetEditBox();
668
669 // ### no longer used, remove when BIC allowed
670 KDoubleLine* edit;
671
672 bool m_range;
673 double m_lower, m_upper, m_step;
674 // ### end no longer used
675
676 QSize m_sizeEdit;
677
678 friend class KDoubleLine;
679private:
680 void init(double value, double lower, double upper,
681 double step, int precision);
682 double mapSliderToSpin(int) const;
683 void updateLegacyMembers();
684 // ### no longer used, remove when BIC allowed:
685 QString m_specialvalue, m_prefix, m_suffix;
686 double m_value;
687 short m_precision;
688 // ### end remove when BIC allowed
689
690protected:
691 virtual void virtual_hook( int id, void* data );
692private:
693 class KDoubleNumInputPrivate;
694 KDoubleNumInputPrivate *d;
695};
696
697
698/* ------------------------------------------------------------------------ */
699
700/**
701 * A @ref QSpinBox with support for arbitrary base numbers
702 * (e.g. hexadecimal).
703 *
704 * The class provides an easy interface to use other
705 * numeric systems than the decimal.
706 *
707 * @short A @ref QSpinBox with support for arbitrary base numbers.
708 */
709class KIntSpinBox : public QSpinBox
710{
711 Q_OBJECT
712 Q_PROPERTY( int base READ base WRITE setBase )
713
714public:
715
716 /**
717 * Constructor.
718 *
719 * Constructs a widget with an integer inputline with a little scrollbar
720 * and a slider, with minimal value 0, maximal value 99, step 1, base 10
721 * and initial value 0.
722 */
723 KIntSpinBox( QWidget *parent=0, const char *name=0);
724
725 /**
726 * Constructor.
727 *
728 * Constructs a widget with an integer inputline with a little scrollbar
729 * and a slider.
730 *
731 * @param lower The lowest valid value.
732 * @param upper The greatest valid value.
733 * @param step The step size of the scrollbar.
734 * @param value The actual value.
735 * @param base The base of the used number system.
736 * @param parent The parent of the widget.
737 * @param name The Name of the widget.
738 */
739 KIntSpinBox(int lower, int upper, int step, int value, int base = 10,
740 QWidget* parent = 0, const char* name = 0);
741
742 /**
743 * Destructor.
744 */
745 virtual ~KIntSpinBox();
746
747 /**
748 * Sets the base in which the numbers in the spin box are represented.
749 */
750 void setBase(int base);
751 /**
752 * @return the base in which numbers in the spin box are represented.
753 */
754 int base() const;
755 /**
756 * sets focus and optionally marks all text
757 *
758 */
759 void setEditFocus(bool mark);
760
761protected:
762
763 /**
764 * Overloaded the method in QSpinBox
765 * to make use of the base given in the constructor.
766 */
767 virtual QString mapValueToText(int);
768
769 /**
770 * Overloaded the method in QSpinBox
771 * to make use of the base given in the constructor.
772 */
773 virtual int mapTextToValue(bool*);
774
775private:
776 int val_base;
777protected:
778 virtual void virtual_hook( int id, void* data );
779private:
780 class KIntSpinBoxPrivate;
781 KIntSpinBoxPrivate *d;
782};
783
784
785/* --------------------------------------------------------------------------- */
786
787/**
788 This class provides a spin box for fractional numbers.
789
790 @sect Parameters
791
792 There are a number of interdependent parameters whose relation to
793 each other you need to understand in order to make successful use
794 of the spin box.
795
796 @li precision: The number of decimals after the decimal point.
797 @li maxValue/minValue: upper and lower bound of the valid range
798 @li lineStep: the size of the step that is taken when the user hits
799 the up or down buttons
800
801 Since we work with fixed-point numbers internally, the maximum
802 precision is a function of the valid range and vice versa. More
803 precisely, the following relations hold:
804 <pre>
805 max( abs(minValue()), abs(maxValue() ) <= INT_MAX/10^precision
806 maxPrecision = floor( log10( INT_MAX/max(abs(minValue()),abs(maxValue())) ) )
807 </pre>
808
809 Since the value, bounds and step are rounded to the current
810 precision, you may experience that the order of setting above
811 parameters matters. E.g. the following are @em not equivalent (try
812 it!):
813
814 <pre>
815 // sets precision,
816 // then min/max value (rounded to precison and clipped to obtainable range if needed)
817 // then value and lineStep
818 KDoubleSpinBox * spin = new KDoubleSpinBox( 0, 9.999, 0.001, 4.321, 3, this );
819
820 // sets minValue to 0; maxValue to 10.00(!); value to 4.32(!) and only then
821 // increases the precision - too late, since e.g. value has already been rounded...
822 KDpubleSpinBox * spin = new KDoubleSpinBox( this );
823 spin->setMinValue( 0 );
824 spin->setMaxValue( 9.999 );
825 spin->setValue( 4.321 );
826 spin->setPrecision( 3 );
827 </pre>
828
829 @short A spin box for fractional numbers.
830 @author Marc Mutz <mutz@kde.org>
831 @version $Id$
832 @since 3.1
833**/
834
835class KDoubleSpinBox : public QSpinBox {
836 Q_OBJECT
837 Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers )
838 Q_OVERRIDE( double maxValue READ maxValue WRITE setMaxValue )
839 Q_OVERRIDE( double minValue READ minValue WRITE setMinValue )
840 Q_OVERRIDE( double lineStep READ lineStep WRITE setLineStep )
841 Q_OVERRIDE( double value READ value WRITE setValue )
842 Q_PROPERTY( int precision READ precision WRITE setPrecision )
843
844public:
845 /** Constructs a @ref KDoubleSpinBox with parent @p parent and
846 default values for range and value (whatever @ref QRangeControl
847 uses) and precision (2). */
848 KDoubleSpinBox( QWidget * parent=0, const char * name=0 );
849 /** Constructs a @ref KDoubleSpinBox with parent @p parent, range
850 [@p lower,@p upper], @ref lineStep @p step, @ref precision @p
851 precision and initial value @p value. */
852 KDoubleSpinBox( double lower, double upper, double step, double value,
853 int precision=2, QWidget * parent=0, const char * name=0 );
854
855 virtual ~KDoubleSpinBox();
856
857 /** @return whether the spinbox uses localized numbers */
858 bool acceptLocalizedNumbers() const;
859 /** Sets whether to use and accept localized numbers as returned by
860 @ref KLocale::formatNumber() */
861 virtual void setAcceptLocalizedNumbers( bool accept );
862
863 /** Sets a new range for the spin box values. Note that @p lower, @p
864 upper and @p step are rounded to @p precision decimal points
865 first. */
866 void setRange( double lower, double upper, double step=0.01, int precision=2 );
867
868 /** @return the current number of decimal points displayed. */
869 int precision() const;
870 /** Equivalent to @ref setPrecsion( @p precison, @p false ); Needed
871 since Qt's moc doesn't ignore trailing parameters with default
872 args when searching for a property setter method. */
873 void setPrecision( int precision );
874 /** Sets the number of decimal points to use. Note that there is a
875 tradeoff between the precision used and the available range of
876 values. See the class docs for more.
877 @param precision the new number of decimal points to use
878
879 @param force disables checking of bound violations that can
880 arise if you increase the precision so much that the
881 minimum and maximum values can't be represented
882 anymore. Disabling is useful if you don't want to keep
883 the current min and max values anyway. This is what
884 e.g. @ref setRange() does.
885 **/
886 virtual void setPrecision( int precision, bool force );
887
888 /** @return the current value */
889 double value() const;
890 /** @return the current lower bound */
891 double minValue() const;
892 /** Sets the lower bound of the range to @p value, subject to the
893 contraints that @p value is first rounded to the current
894 precision and then clipped to the maximum representable
895 interval.
896 @see maxValue, minValue, setMaxValue, setRange
897 */
898 void setMinValue( double value );
899 /** @return the current upper bound */
900 double maxValue() const;
901 /** Sets the upper bound of the range to @p value, subject to the
902 contraints that @p value is first rounded to the current
903 precision and then clipped to the maximum representable
904 interval.
905 @see minValue, maxValue, setMinValue, setRange
906 */
907 void setMaxValue( double value );
908
909 /** @return the current step size */
910 double lineStep() const;
911 /** Sets the step size for clicking the up/down buttons to @p step,
912 subject to the constraints that @p step is first rounded to the
913 current precision and then clipped to the meaningful interval
914 [1, @p maxValue - @p minValue]. */
915 void setLineStep( double step );
916
917 /** Overridden to ignore any setValidator() calls. */
918 void setValidator( const QValidator * );
919
920signals:
921 /** Emitted whenever @ref QSpinBox::valueChanged( int ) is emitted. */
922 void valueChanged( double value );
923
924public slots:
925 /** Sets the current value to @p value, cubject to the constraints
926 that @p value is frist rounded to the current precision and then
927 clipped to the interval [@p minvalue(),@p maxValue()]. */
928 virtual void setValue( double value );
929
930protected:
931 virtual QString mapValueToText(int);
932 virtual int mapTextToValue(bool*);
933
934protected slots:
935 void slotValueChanged( int value );
936
937protected:
938 virtual void virtual_hook( int id, void* data );
939private:
940 typedef QSpinBox base;
941 void updateValidator();
942 int maxPrecision() const;
943
944 class Private;
945 Private * d;
946};
947
948#endif // K_NUMINPUT_H
diff --git a/microkde/kdeui/knumvalidator.cpp b/microkde/kdeui/knumvalidator.cpp
new file mode 100644
index 0000000..78a8471
--- a/dev/null
+++ b/microkde/kdeui/knumvalidator.cpp
@@ -0,0 +1,372 @@
1/**********************************************************************
2**
3** $Id$
4**
5** KIntValidator, KFloatValidator:
6** Copyright (C) 1999 Glen Parker <glenebob@nwlink.com>
7** KDoubleValidator:
8** Copyright (c) 2002 Marc Mutz <mutz@kde.org>
9**
10** This library is free software; you can redistribute it and/or
11** modify it under the terms of the GNU Library General Public
12** License as published by the Free Software Foundation; either
13** version 2 of the License, or (at your option) any later version.
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
21** License along with this library; if not, write to the Free
22** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23**
24*****************************************************************************/
25
26#include <qwidget.h>
27#include <qstring.h>
28
29#include "knumvalidator.h"
30#include <klocale.h>
31#include <kglobal.h>
32#include <kdebug.h>
33
34///////////////////////////////////////////////////////////////
35// Implementation of KIntValidator
36//
37
38KIntValidator::KIntValidator ( QWidget * parent, int base, const char * name )
39 : QValidator(parent, name)
40{
41 _base = base;
42 if (_base < 2) _base = 2;
43 if (_base > 36) _base = 36;
44
45 _min = _max = 0;
46}
47
48KIntValidator::KIntValidator ( int bottom, int top, QWidget * parent, int base, const char * name )
49 : QValidator(parent, name)
50{
51 _base = base;
52 if (_base > 36) _base = 36;
53
54 _min = bottom;
55 _max = top;
56}
57
58KIntValidator::~KIntValidator ()
59{}
60
61QValidator::State KIntValidator::validate ( QString &str, int & ) const
62{
63 bool ok;
64 int val = 0;
65 QString newStr;
66
67 newStr = str.stripWhiteSpace();
68 if (_base > 10)
69 newStr = newStr.upper();
70
71 if (newStr == QString::fromLatin1("-")) // a special case
72 if ((_min || _max) && _min >= 0)
73 ok = false;
74 else
75 return QValidator::Acceptable;
76 else if (newStr.length())
77 val = newStr.toInt(&ok, _base);
78 else {
79 val = 0;
80 ok = true;
81 }
82
83 if (! ok)
84 return QValidator::Invalid;
85
86 if ((! _min && ! _max) || (val >= _min && val <= _max))
87 return QValidator::Acceptable;
88
89 if (_max && _min >= 0 && val < 0)
90 return QValidator::Invalid;
91
92 return QValidator::Valid;
93}
94
95void KIntValidator::fixup ( QString &str ) const
96{
97 int dummy;
98 int val;
99 QValidator::State state;
100
101 state = validate(str, dummy);
102
103 if (state == QValidator::Invalid || state == QValidator::Acceptable)
104 return;
105
106 if (! _min && ! _max)
107 return;
108
109 val = str.toInt(0, _base);
110
111 if (val < _min) val = _min;
112 if (val > _max) val = _max;
113
114 str.setNum(val, _base);
115}
116
117void KIntValidator::setRange ( int bottom, int top )
118{
119 _min = bottom;
120 _max = top;
121
122 if (_max < _min)
123 _max = _min;
124}
125
126void KIntValidator::setBase ( int base )
127{
128 _base = base;
129 if (_base < 2) _base = 2;
130}
131
132int KIntValidator::bottom () const
133{
134 return _min;
135}
136
137int KIntValidator::top () const
138{
139 return _max;
140}
141
142int KIntValidator::base () const
143{
144 return _base;
145}
146
147
148///////////////////////////////////////////////////////////////
149// Implementation of KFloatValidator
150//
151
152class KFloatValidatorPrivate
153{
154public:
155 KFloatValidatorPrivate()
156 {
157 }
158 ~KFloatValidatorPrivate()
159 {
160 }
161 bool acceptLocalizedNumbers;
162};
163
164
165KFloatValidator::KFloatValidator ( QWidget * parent, const char * name )
166 : QValidator(parent, name)
167{
168 d = new KFloatValidatorPrivate;
169 d->acceptLocalizedNumbers=false;
170 _min = _max = 0;
171}
172
173KFloatValidator::KFloatValidator ( double bottom, double top, QWidget * parent, const char * name )
174 : QValidator(parent, name)
175{
176 d = new KFloatValidatorPrivate;
177 d->acceptLocalizedNumbers=false;
178 _min = bottom;
179 _max = top;
180}
181
182KFloatValidator::KFloatValidator ( double bottom, double top, bool localeAware, QWidget * parent, const char * name )
183 : QValidator(parent, name)
184{
185 d = new KFloatValidatorPrivate;
186 d->acceptLocalizedNumbers = localeAware;
187 _min = bottom;
188 _max = top;
189}
190
191KFloatValidator::~KFloatValidator ()
192{
193 delete d;
194}
195
196void KFloatValidator::setAcceptLocalizedNumbers(bool _b)
197{
198 d->acceptLocalizedNumbers=_b;
199}
200
201bool KFloatValidator::acceptLocalizedNumbers() const
202{
203 return d->acceptLocalizedNumbers;
204}
205
206QValidator::State KFloatValidator::validate ( QString &str, int & ) const
207{
208 bool ok;
209 double val = 0;
210 QString newStr;
211 newStr = str.stripWhiteSpace();
212
213 if (newStr == QString::fromLatin1("-")) // a special case
214 if ((_min || _max) && _min >= 0)
215 ok = false;
216 else
217 return QValidator::Acceptable;
218 else if (newStr == QString::fromLatin1(".") || (d->acceptLocalizedNumbers && newStr==KGlobal::locale()->decimalSymbol())) // another special case
219 return QValidator::Acceptable;
220 else if (newStr.length())
221 {
222 val = newStr.toDouble(&ok);
223 if(!ok && d->acceptLocalizedNumbers)
224 val= KGlobal::locale()->readNumber(newStr,&ok);
225 }
226 else {
227 val = 0;
228 ok = true;
229 }
230
231 if (! ok)
232 return QValidator::Invalid;
233
234 if (( !_min && !_max) || (val >= _min && val <= _max))
235 return QValidator::Acceptable;
236
237 if (_max && _min >= 0 && val < 0)
238 return QValidator::Invalid;
239
240 if ( (_min || _max) && (val < _min || val > _max))
241 return QValidator::Invalid;
242
243 return QValidator::Valid;
244}
245
246void KFloatValidator::fixup ( QString &str ) const
247{
248 int dummy;
249 double val;
250 QValidator::State state;
251
252 state = validate(str, dummy);
253
254 if (state == QValidator::Invalid || state == QValidator::Acceptable)
255 return;
256
257 if (! _min && ! _max)
258 return;
259
260 val = str.toDouble();
261
262 if (val < _min) val = _min;
263 if (val > _max) val = _max;
264
265 str.setNum(val);
266}
267
268void KFloatValidator::setRange ( double bottom, double top )
269{
270 _min = bottom;
271 _max = top;
272
273 if (_max < _min)
274 _max = _min;
275}
276
277double KFloatValidator::bottom () const
278{
279 return _min;
280}
281
282double KFloatValidator::top () const
283{
284 return _max;
285}
286
287
288
289
290///////////////////////////////////////////////////////////////
291// Implementation of KDoubleValidator
292//
293
294class KDoubleValidator::Private {
295public:
296 Private( bool accept=true ) : acceptLocalizedNumbers( accept ) {}
297
298 bool acceptLocalizedNumbers;
299};
300
301KDoubleValidator::KDoubleValidator( QObject * parent, const char * name )
302 : QDoubleValidator( (QWidget*)parent, name ), d( 0 )
303{
304 d = new Private();
305}
306
307KDoubleValidator::KDoubleValidator( double bottom, double top, int decimals,
308 QObject * parent, const char * name )
309 : QDoubleValidator( bottom, top, decimals, (QWidget*)parent, name ), d( 0 )
310{
311 d = new Private();
312}
313
314KDoubleValidator::~KDoubleValidator()
315{
316 delete d;
317}
318
319bool KDoubleValidator::acceptLocalizedNumbers() const {
320 return d->acceptLocalizedNumbers;
321}
322
323void KDoubleValidator::setAcceptLocalizedNumbers( bool accept ) {
324 d->acceptLocalizedNumbers = accept;
325}
326
327QValidator::State KDoubleValidator::validate( QString & input, int & p ) const {
328 QString s = input;
329 if ( acceptLocalizedNumbers() ) {
330 KLocale * l = KGlobal::locale();
331 // ok, we have to re-format the number to have:
332 // 1. decimalSymbol == '.'
333 // 2. negativeSign == '-'
334 // 3. positiveSign == <empty>
335 // 4. thousandsSeparator() == <empty> (we don't check that there
336 // are exactly three decimals between each separator):
337 QString d = l->decimalSymbol(),
338 n = l->negativeSign(),
339 p = l->positiveSign(),
340 t = l->thousandsSeparator();
341 // first, delete p's and t's:
342 if ( !p.isEmpty() )
343 for ( int idx = s.find( p ) ; idx >= 0 ; idx = s.find( p, idx ) )
344 s.remove( idx, p.length() );
345
346
347 if ( !t.isEmpty() )
348 for ( int idx = s.find( t ) ; idx >= 0 ; idx = s.find( t, idx ) )
349 s.remove( idx, t.length() );
350
351 // then, replace the d's and n's
352 if ( ( !n.isEmpty() && n.find('.') != -1 ) ||
353 ( !d.isEmpty() && d.find('-') != -1 ) ) {
354 // make sure we don't replace something twice:
355 kdWarning() << "KDoubleValidator: decimal symbol contains '-' or "
356 "negative sign contains '.' -> improve algorithm" << endl;
357 return Invalid;
358 }
359
360 if ( !d.isEmpty() && d != "." )
361 for ( int idx = s.find( d ) ; idx >= 0 ; idx = s.find( d, idx + 1 ) )
362 s.replace( idx, d.length(), ".");
363
364 if ( !n.isEmpty() && n != "-" )
365 for ( int idx = s.find( n ) ; idx >= 0 ; idx = s.find( n, idx + 1 ) )
366 s.replace( idx, n.length(), "-" );
367 }
368
369 return base::validate( s, p );
370}
371
372//US #include "knumvalidator.moc"
diff --git a/microkde/kdeui/knumvalidator.h b/microkde/kdeui/knumvalidator.h
new file mode 100644
index 0000000..2f0a937
--- a/dev/null
+++ b/microkde/kdeui/knumvalidator.h
@@ -0,0 +1,209 @@
1/**********************************************************************
2**
3** $Id$
4**
5** Copyright (C) 1999 Glen Parker <glenebob@nwlink.com>
6** Copyright (C) 2002 Marc Mutz <mutz@kde.org>
7**
8** This library is free software; you can redistribute it and/or
9** modify it under the terms of the GNU Library General Public
10** License as published by the Free Software Foundation; either
11** version 2 of the License, or (at your option) any later version.
12**
13** This library is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16** Library General Public License for more details.
17**
18** You should have received a copy of the GNU Library General Public
19** License along with this library; if not, write to the Free
20** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21**
22*****************************************************************************/
23
24#ifndef __KNUMVALIDATOR_H
25#define __KNUMVALIDATOR_H
26
27#include <qvalidator.h>
28
29class QWidget;
30class QString;
31
32/**
33 * @ref QValidator for integers.
34
35 This can be used by @ref QLineEdit or subclass to provide validated
36 text entry. Can be provided with a base value (default is 10), to allow
37 the proper entry of hexadecimal, octal, or any other base numeric data.
38
39 @author Glen Parker <glenebob@nwlink.com>
40 @version 0.0.1
41*/
42class KIntValidator : public QValidator {
43
44 public:
45 /**
46 Constuctor. Also sets the base value.
47 */
48 KIntValidator ( QWidget * parent, int base = 10, const char * name = 0 );
49 /**
50 * Constructor. Also sets the minimum, maximum, and numeric base values.
51 */
52 KIntValidator ( int bottom, int top, QWidget * parent, int base = 10, const char * name = 0 );
53 /**
54 * Destructs the validator.
55 */
56 virtual ~KIntValidator ();
57 /**
58 * Validates the text, and return the result. Does not modify the parameters.
59 */
60 virtual State validate ( QString &, int & ) const;
61 /**
62 * Fixes the text if possible, providing a valid string. The parameter may be modified.
63 */
64 virtual void fixup ( QString & ) const;
65 /**
66 * Sets the minimum and maximum values allowed.
67 */
68 virtual void setRange ( int bottom, int top );
69 /**
70 * Sets the numeric base value.
71 */
72 virtual void setBase ( int base );
73 /**
74 * Returns the current minimum value allowed.
75 */
76 virtual int bottom () const;
77 /**
78 * Returns the current maximum value allowed.
79 */
80 virtual int top () const;
81 /**
82 * Returns the current numeric base.
83 */
84 virtual int base () const;
85
86 private:
87 int _base;
88 int _min;
89 int _max;
90
91};
92
93class KFloatValidatorPrivate;
94
95/**
96 @obsolete Use @ref KDoubleValidator
97
98 @ref QValidator for floating point entry.
99 Extends the QValidator class to properly validate double numeric data.
100 This can be used by @ref QLineEdit or subclass to provide validated
101 text entry.
102
103 @author Glen Parker <glenebob@nwlink.com>
104 @version 0.0.1
105*/
106class KFloatValidator : public QValidator {
107
108 public:
109 /**
110 * Constructor.
111 */
112 KFloatValidator ( QWidget * parent, const char * name = 0 );
113 /**
114 * Constructor. Also sets the minimum and maximum values.
115 */
116 KFloatValidator ( double bottom, double top, QWidget * parent, const char * name = 0 );
117 /**
118 * Constructor. Sets the validator to be locale aware if @p localeAware is true.
119 */
120 KFloatValidator ( double bottom, double top, bool localeAware, QWidget * parent, const char * name = 0 );
121 /**
122 * Destructs the validator.
123 */
124 virtual ~KFloatValidator ();
125 /**
126 * Validates the text, and return the result. Does not modify the parameters.
127 */
128 virtual State validate ( QString &, int & ) const;
129 /**
130 * Fixes the text if possible, providing a valid string. The parameter may be modified.
131 */
132 virtual void fixup ( QString & ) const;
133 /**
134 * Sets the minimum and maximum value allowed.
135 */
136 virtual void setRange ( double bottom, double top );
137 /**
138 * Returns the current minimum value allowed.
139 */
140 virtual double bottom () const;
141 /**
142 * Returns the current maximum value allowed.
143 */
144 virtual double top () const;
145 /**
146 * Sets the validator to be locale aware if @p is true. In this case, the
147 * character KLocale::decimalSymbol() from the global locale is recognized
148 * as decimal separator.
149 */
150 void setAcceptLocalizedNumbers(bool b);
151 /**
152 * Returns true if the validator is locale aware.
153 * @see setAcceptLocalizedNumbers().
154 */
155 bool acceptLocalizedNumbers() const;
156
157 private:
158 double _min;
159 double _max;
160
161 KFloatValidatorPrivate *d;
162};
163
164/**
165 KDoubleValidator extends @ref QDoubleValidator to be
166 locale-aware. That means that - subject to not being disabled -
167 @ref KLocale::decimalPoint(), @ref KLocale::thousandsSeparator()
168 and @ref KLocale::positiveSign() and @ref KLocale::negativeSign()
169 are respected.
170
171 @short A locale-aware @ref QDoubleValidator
172 @author Marc Mutz <mutz@kde.org>
173 @version $Id$
174 @see KIntValidator
175 @since 3.1
176**/
177
178class KDoubleValidator : public QDoubleValidator {
179 Q_OBJECT
180 Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers )
181public:
182 /** Constuct a locale-aware KDoubleValidator with default range
183 (whatever @ref QDoubleValidator uses for that) and parent @p
184 parent */
185 KDoubleValidator( QObject * parent, const char * name=0 );
186 /** Constuct a locale-aware KDoubleValidator for range [@p bottom,@p
187 top] and a precision of @p decimals decimals after the decimal
188 point. */
189 KDoubleValidator( double bottom, double top, int decimals,
190 QObject * parent, const char * name=0 );
191 /** Destructs the validator.
192 */
193 virtual ~KDoubleValidator();
194
195 /** Overloaded for internal reasons. The API is not affected. */
196 virtual QValidator::State validate( QString & input, int & pos ) const;
197
198 /** @return whether localized numbers are accepted (default: true) */
199 bool acceptLocalizedNumbers() const;
200 /** Sets whether to accept localized numbers (default: true) */
201 void setAcceptLocalizedNumbers( bool accept );
202
203private:
204 typedef QDoubleValidator base;
205 class Private;
206 Private * d;
207};
208
209#endif
diff --git a/microkde/kdeui/kseparator.cpp b/microkde/kdeui/kseparator.cpp
new file mode 100644
index 0000000..d028420
--- a/dev/null
+++ b/microkde/kdeui/kseparator.cpp
@@ -0,0 +1,121 @@
1/*
2 * Copyright (C) 1997 Michael Roth <mroth@wirlweb.de>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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
12 * GNU 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 program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 */
19
20#include <qstyle.h>
21
22#include <kdebug.h>
23//US #include <kapplication.h>
24
25//US #include "kseparator.moc"
26
27#include "kseparator.h"
28
29KSeparator::KSeparator(QWidget* parent, const char* name, WFlags f)
30 : QFrame(parent, name, f)
31{
32 setLineWidth(1);
33 setMidLineWidth(0);
34 setOrientation( HLine );
35}
36
37
38
39KSeparator::KSeparator(int orientation, QWidget* parent, const char* name, WFlags f)
40 : QFrame(parent, name, f)
41{
42 setLineWidth(1);
43 setMidLineWidth(0);
44 setOrientation( orientation );
45}
46
47
48
49void KSeparator::setOrientation(int orientation)
50{
51 switch(orientation)
52 {
53 case Vertical:
54 case VLine:
55 setFrameStyle( QFrame::VLine | QFrame::Sunken );
56 setMinimumSize(2, 0);
57 break;
58
59 default:
60 kdWarning() << "KSeparator::setOrientation(): invalid orientation, using default orientation HLine" << endl;
61
62 case Horizontal:
63 case HLine:
64 setFrameStyle( QFrame::HLine | QFrame::Sunken );
65 setMinimumSize(0, 2);
66 break;
67 }
68}
69
70
71
72int KSeparator::orientation() const
73{
74 if ( frameStyle() & VLine )
75 return VLine;
76
77 if ( frameStyle() & HLine )
78 return HLine;
79
80 return 0;
81}
82
83void KSeparator::drawFrame(QPainter *p)
84{
85 QPointp1, p2;
86 QRectr = frameRect();
87 const QColorGroup & g = colorGroup();
88
89 if ( frameStyle() & HLine ) {
90 p1 = QPoint( r.x(), r.height()/2 );
91 p2 = QPoint( r.x()+r.width(), p1.y() );
92 }
93 else {
94 p1 = QPoint( r.x()+r.width()/2, 0 );
95 p2 = QPoint( p1.x(), r.height() );
96 }
97
98/*US
99 QStyleOption opt( lineWidth(), midLineWidth() );
100 style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g,
101 QStyle::Style_Sunken, opt );
102*/
103//LRstyle().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, lineWidth(), midLineWidth());
104
105}
106
107
108QSize KSeparator::sizeHint() const
109{
110 if ( frameStyle() & VLine )
111 return QSize(2, 0);
112
113 if ( frameStyle() & HLine )
114 return QSize(0, 2);
115
116 return QSize(-1, -1);
117}
118
119void KSeparator::virtual_hook( int, void* )
120{ /*BASE::virtual_hook( id, data );*/ }
121
diff --git a/microkde/kdeui/kseparator.h b/microkde/kdeui/kseparator.h
new file mode 100644
index 0000000..6d2712a
--- a/dev/null
+++ b/microkde/kdeui/kseparator.h
@@ -0,0 +1,77 @@
1/*
2 * Copyright (C) 1997 Michael Roth <mroth@wirlweb.de>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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
12 * GNU 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 program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 */
19
20#ifndef __KSEPARATOR_H__
21#define __KSEPARATOR_H__
22
23#include <qframe.h>
24
25/**
26 * Standard horizontal or vertical separator.
27 *
28 * @author Michael Roth <mroth@wirlweb.de>
29 * @version $Id$
30*/
31class KSeparator : public QFrame
32{
33 Q_OBJECT
34 Q_PROPERTY( int orientation READ orientation WRITE setOrientation )
35 public:
36 /**
37 * Constructor.
38 **/
39 KSeparator(QWidget* parent=0, const char* name=0, WFlags f=0);
40 /**
41 * Constructor.
42 *
43 * @param orientation Set the orientation of the separator.
44 * Possible values are HLine or Horizontal and VLine or Vertical.
45 **/
46 KSeparator(int orientation, QWidget* parent=0, const char* name=0,
47 WFlags f=0);
48
49 /**
50 * Returns the orientation of the separator.
51 *
52 * Possible values are VLine and HLine.
53 **/
54 int orientation() const;
55
56 /**
57 * Set the orientation of the separator to @p orient
58 *
59 * Possible values are VLine and HLine.
60 */
61 void setOrientation(int orient);
62
63 /**
64 * The recommended height (width) for a horizontal (vertical) separator.
65 **/
66 virtual QSize sizeHint() const;
67
68protected:
69 virtual void drawFrame( QPainter * );
70protected:
71 virtual void virtual_hook( int id, void* data );
72private:
73 class KSeparatorPrivate* d;
74};
75
76
77#endif // __KSEPARATOR_H__
diff --git a/microkde/kdeui/ksqueezedtextlabel.cpp b/microkde/kdeui/ksqueezedtextlabel.cpp
new file mode 100644
index 0000000..37fa29a
--- a/dev/null
+++ b/microkde/kdeui/ksqueezedtextlabel.cpp
@@ -0,0 +1,107 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Ronny Standtke <Ronny.Standtke@gmx.de>
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 version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17*/
18
19#include "ksqueezedtextlabel.h"
20#include <qtooltip.h>
21
22KSqueezedTextLabel::KSqueezedTextLabel( const QString &text , QWidget *parent, const char *name )
23 : QLabel ( parent, name ) {
24 setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
25 fullText = text;
26 squeezeTextToLabel();
27}
28
29KSqueezedTextLabel::KSqueezedTextLabel( QWidget *parent, const char *name )
30 : QLabel ( parent, name ) {
31 setSizePolicy(QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
32}
33
34void KSqueezedTextLabel::resizeEvent( QResizeEvent * ) {
35 squeezeTextToLabel();
36}
37
38QSize KSqueezedTextLabel::minimumSizeHint() const
39{
40 QSize sh = QLabel::minimumSizeHint();
41 sh.setWidth(-1);
42 return sh;
43}
44
45void KSqueezedTextLabel::setText( const QString &text ) {
46 fullText = text;
47 squeezeTextToLabel();
48}
49
50void KSqueezedTextLabel::squeezeTextToLabel() {
51 QFontMetrics fm(fontMetrics());
52 int labelWidth = size().width();
53 int textWidth = fm.width(fullText);
54 if (textWidth > labelWidth) {
55 // start with the dots only
56 QString squeezedText = "...";
57 int squeezedWidth = fm.width(squeezedText);
58
59 // estimate how many letters we can add to the dots on both sides
60 int letters = fullText.length() * (labelWidth - squeezedWidth) / textWidth / 2;
61 if (labelWidth < squeezedWidth) letters=1;
62 squeezedText = fullText.left(letters) + "..." + fullText.right(letters);
63 squeezedWidth = fm.width(squeezedText);
64
65 if (squeezedWidth < labelWidth) {
66 // we estimated too short
67 // add letters while text < label
68 do {
69 letters++;
70 squeezedText = fullText.left(letters) + "..." + fullText.right(letters);
71 squeezedWidth = fm.width(squeezedText);
72 } while (squeezedWidth < labelWidth);
73 letters--;
74 squeezedText = fullText.left(letters) + "..." + fullText.right(letters);
75 } else if (squeezedWidth > labelWidth) {
76 // we estimated too long
77 // remove letters while text > label
78 do {
79 letters--;
80 squeezedText = fullText.left(letters) + "..." + fullText.right(letters);
81 squeezedWidth = fm.width(squeezedText);
82 } while (letters && squeezedWidth > labelWidth);
83 }
84
85 if (letters < 5) {
86 // too few letters added -> we give up squeezing
87 QLabel::setText(fullText);
88 } else {
89 QLabel::setText(squeezedText);
90 }
91
92//US QToolTip::remove( this );
93//US QToolTip::add( this, fullText );
94
95 } else {
96 QLabel::setText(fullText);
97
98//US QToolTip::remove( this );
99//US QToolTip::hide();
100
101 };
102}
103
104void KSqueezedTextLabel::virtual_hook( int, void* )
105{ /*BASE::virtual_hook( id, data );*/ }
106
107//US #include "ksqueezedtextlabel.moc"
diff --git a/microkde/kdeui/ksqueezedtextlabel.h b/microkde/kdeui/ksqueezedtextlabel.h
new file mode 100644
index 0000000..1634adc
--- a/dev/null
+++ b/microkde/kdeui/ksqueezedtextlabel.h
@@ -0,0 +1,76 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Ronny Standtke <Ronny.Standtke@gmx.de>
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 version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17*/
18
19#ifndef KSQUEEZEDTEXTLABEL_H
20#define KSQUEEZEDTEXTLABEL_H
21
22#include <qlabel.h>
23
24/**
25 * A label class that squeezes its text into the label
26 *
27 * If the text is too long to fit into the label it is divided into
28 * remaining left and right parts which are separated by three dots.
29 *
30 * Example:
31 * http://www.kde.org/documentation/index.html could be squeezed to
32 * http://www.kde...ion/index.html
33
34 * @short A replacement for QLabel that squeezes its text
35 * @author Ronny Standtke <Ronny.Standtke@gmx.de>
36 * @version $Id$
37 *
38 */
39
40/*
41 * @ref QLabel
42 */
43class KSqueezedTextLabel : public QLabel {
44 Q_OBJECT
45
46public:
47 /**
48 * Default constructor.
49 */
50 KSqueezedTextLabel( QWidget *parent, const char *name = 0 );
51 KSqueezedTextLabel( const QString &text, QWidget *parent, const char *name = 0 );
52
53 virtual QSize minimumSizeHint() const;
54
55public slots:
56 void setText( const QString & );
57
58protected:
59 /**
60 * used when widget is resized
61 */
62 void resizeEvent( QResizeEvent * );
63 /**
64 * does the dirty work
65 */
66 void squeezeTextToLabel();
67 QString fullText;
68
69protected:
70 virtual void virtual_hook( int id, void* data );
71private:
72 class KSqueezedTextLabelPrivate;
73 KSqueezedTextLabelPrivate *d;
74};
75
76#endif // KSQUEEZEDTEXTLABEL_H
diff --git a/microkde/kdeui/kstdaction.cpp b/microkde/kdeui/kstdaction.cpp
new file mode 100644
index 0000000..cfd7b54
--- a/dev/null
+++ b/microkde/kdeui/kstdaction.cpp
@@ -0,0 +1,362 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 1999,2000 Kurt Granroth <granroth@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 version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17*/
18
19#include "kstdaction.h"
20
21#include <qtoolbutton.h>
22#include <qwhatsthis.h>
23
24//US #include <kaboutdata.h>
25#include <kaction.h>
26#include <kapplication.h>
27#include <kdebug.h>
28#include <kglobal.h>
29#include <kiconloader.h>
30#include <klocale.h>
31//US #include <kstdaccel.h>
32//US #include <kmainwindow.h>
33
34namespace KStdAction
35{
36
37struct KStdActionInfo
38{
39 StdAction id;
40 /*USKStdAccel::StdAccel idAccel;*/
41 const char* psName;
42 const char* psLabel;
43 const char* psWhatsThis;
44 const char* psIconName;
45};
46
47const KStdActionInfo g_rgActionInfo[] =
48{
49 { New, /*USKStdAccel::New,*/ "file_new", I18N_NOOP("&New"), 0, "filenew" },
50 { Open, /*USKStdAccel::Open,*/ "file_open", I18N_NOOP("&Open..."), 0, "fileopen" },
51 { OpenRecent, /*USKStdAccel::AccelNone,*/ "file_open_recent", I18N_NOOP("Open &Recent"), 0, 0 },
52 { Save, /*USKStdAccel::Save,*/ "file_save", I18N_NOOP("&Save"), 0, "filesave" },
53 { SaveAs, /*USKStdAccel::AccelNone,*/ "file_save_as", I18N_NOOP("Save &As..."), 0, "filesaveas" },
54 { Revert, /*USKStdAccel::AccelNone,*/ "file_revert", I18N_NOOP("Re&vert"), 0, "revert" },
55 { Close, /*USKStdAccel::Close,*/ "file_close", I18N_NOOP("&Close"), 0, "fileclose" },
56 { Print, /*USKStdAccel::Print,*/ "file_print", I18N_NOOP("&Print..."), 0, "fileprint" },
57 { PrintPreview, /*USKStdAccel::AccelNone,*/ "file_print_preview", I18N_NOOP("Print Previe&w..."), 0, "filequickprint" },
58 { Mail, /*USKStdAccel::AccelNone,*/ "file_mail", I18N_NOOP("&Mail..."), 0, "mail_send" },
59 { Quit, /*USKStdAccel::Quit,*/ "file_quit", I18N_NOOP("&Exit"), 0, "exit" },
60
61 { Undo, /*USKStdAccel::Undo,*/ "edit_undo", I18N_NOOP("&Undo"), 0, "undo" },
62 { Redo, /*USKStdAccel::Redo,*/ "edit_redo", I18N_NOOP("Re&do"), 0, "redo" },
63 { Cut, /*USKStdAccel::Cut,*/ "edit_cut", I18N_NOOP("Cu&t"), 0, "editcut" },
64 { Copy, /*USKStdAccel::Copy,*/ "edit_copy", I18N_NOOP("&Copy"), 0, "editcopy" },
65 { Paste, /*USKStdAccel::Paste,*/ "edit_paste", I18N_NOOP("&Paste"), 0, "editpaste" },
66 { SelectAll, /*USKStdAccel::SelectAll,*/ "edit_select_all", I18N_NOOP("Select &All"), 0, 0 },
67 { Deselect, /*USKStdAccel::Deselect,*/ "edit_deselect", I18N_NOOP("Dese&lect"), 0, 0 },
68 { Find, /*USKStdAccel::Find,*/ "edit_find", I18N_NOOP("&Find..."), 0, "find" },
69 { FindNext, /*USKStdAccel::FindNext,*/ "edit_find_next", I18N_NOOP("Find &Next"), 0, "next" },
70 // FIXME: rename edit_find_last to edit_find_prev for KDE 4
71 { FindPrev, /*USKStdAccel::FindPrev,*/ "edit_find_last", I18N_NOOP("Find Pre&vious"), 0, "previous" },
72 { Replace, /*USKStdAccel::Replace,*/ "edit_replace", I18N_NOOP("&Replace..."), 0, 0 },
73
74 { ActualSize, /*USKStdAccel::AccelNone,*/ "view_actual_size", I18N_NOOP("&Actual Size"), 0, 0 },
75 { FitToPage, /*USKStdAccel::AccelNone,*/ "view_fit_to_page", I18N_NOOP("&Fit to Page"), 0, 0 },
76 { FitToWidth, /*USKStdAccel::AccelNone,*/ "view_fit_to_width", I18N_NOOP("Fit to Page &Width"), 0, 0 },
77 { FitToHeight, /*USKStdAccel::AccelNone,*/ "view_fit_to_height", I18N_NOOP("Fit to Page &Height"), 0, 0 },
78 { ZoomIn, /*USKStdAccel::ZoomIn,*/ "view_zoom_in", I18N_NOOP("Zoom &In"), 0, "viewmag+" },
79 { ZoomOut, /*USKStdAccel::ZoomOut,*/ "view_zoom_out", I18N_NOOP("Zoom &Out"), 0, "viewmag-" },
80 { Zoom, /*USKStdAccel::AccelNone,*/ "view_zoom", I18N_NOOP("&Zoom..."), 0, "viewmag" },
81 { Redisplay, /*USKStdAccel::AccelNone,*/ "view_redisplay", I18N_NOOP("&Redisplay"), 0, "reload" },
82
83 { Up, /*USKStdAccel::Up,*/ "go_up", I18N_NOOP("&Up"), 0, "up" },
84 // The following three have special i18n() needs for sLabel
85 { Back, /*USKStdAccel::Back,*/ "go_back", 0, 0, "back" },
86 { Forward, /*USKStdAccel::Forward,*/ "go_forward", 0, 0, "forward" },
87 { Home, /*USKStdAccel::Home,*/ "go_home", 0, 0, "gohome" },
88 { Prior, /*USKStdAccel::Prior,*/ "go_previous", I18N_NOOP("&Previous Page"), 0, "previous" },
89 { Next, /*USKStdAccel::Next,*/ "go_next", I18N_NOOP("&Next Page"), 0, "next" },
90 { Goto, /*USKStdAccel::AccelNone,*/ "go_goto", I18N_NOOP("&Go To..."), 0, 0 },
91 { GotoPage, /*USKStdAccel::AccelNone,*/ "go_goto_page", I18N_NOOP("&Go to Page..."), 0, "goto" },
92 { GotoLine, /*USKStdAccel::GotoLine,*/ "go_goto_line", I18N_NOOP("&Go to Line..."), 0, 0 },
93 { FirstPage, /*USKStdAccel::Home,*/ "go_first", I18N_NOOP("&First Page"), 0, "top" },
94 { LastPage, /*USKStdAccel::End,*/ "go_last", I18N_NOOP("&Last Page"), 0, "bottom" },
95
96 { AddBookmark, /*USKStdAccel::AddBookmark,*/ "bookmark_add", I18N_NOOP("&Add Bookmark"), 0, "bookmark_add" },
97 { EditBookmarks, /*USKStdAccel::AccelNone,*/ "bookmark_edit", I18N_NOOP("&Edit Bookmarks"), 0, "bookmark" },
98
99 { Spelling, /*USKStdAccel::AccelNone,*/ "tools_spelling", I18N_NOOP("&Spelling..."), 0, "spellcheck" },
100
101 { ShowMenubar, /*USKStdAccel::ShowMenubar,*/ "options_show_menubar", I18N_NOOP("Show &Menubar"), 0, "showmenu" },
102 { ShowToolbar, /*USKStdAccel::AccelNone,*/ "options_show_toolbar", I18N_NOOP("Show &Toolbar"), 0, 0 },
103 { ShowStatusbar, /*USKStdAccel::AccelNone,*/ "options_show_statusbar", I18N_NOOP("Show St&atusbar"), 0, 0 },
104 { SaveOptions, /*USKStdAccel::AccelNone,*/ "options_save_options", I18N_NOOP("&Save Settings"), 0, 0 },
105 { KeyBindings, /*USKStdAccel::AccelNone,*/ "options_configure_keybinding", I18N_NOOP("Configure S&hortcuts..."), 0,"configure_shortcuts" },
106 { Preferences, /*USKStdAccel::AccelNone,*/ "options_configure", I18N_NOOP("&Configure %1..."), 0, "configure" },
107 { ConfigureToolbars, /*USKStdAccel::AccelNone,*/ "options_configure_toolbars", I18N_NOOP("Configure Tool&bars..."), 0,"configure_toolbars" },
108 { ConfigureNotifications, /*USKStdAccel::AccelNone,*/ "options_configure_notifications", I18N_NOOP("Configure &Notifications..."), 0, "knotify" },
109
110 { Help, /*USKStdAccel::Help,*/ "help", 0, 0, "help" },
111 { HelpContents, /*USKStdAccel::AccelNone,*/ "help_contents", I18N_NOOP("%1 &Handbook"), 0, "contents" },
112 { WhatsThis, /*USKStdAccel::WhatsThis,*/ "help_whats_this", I18N_NOOP("What's &This?"), 0, "contexthelp" },
113 { TipofDay, /*USKStdAccel::AccelNone,*/ "help_show_tip", I18N_NOOP("Tip of the &Day"), 0, "idea" },
114 { ReportBug, /*USKStdAccel::AccelNone,*/ "help_report_bug", I18N_NOOP("&Report Bug..."), 0, 0 },
115 { AboutApp, /*USKStdAccel::AccelNone,*/ "help_about_app", I18N_NOOP("&About %1"), 0, 0 },
116 { AboutKDE, /*USKStdAccel::AccelNone,*/ "help_about_kde", I18N_NOOP("About &KDE"), 0,"about_kde" },
117 { ActionNone, /*USKStdAccel::AccelNone,*/ 0, 0, 0, 0 }
118};
119
120static const KStdActionInfo* infoPtr( StdAction id )
121{
122 for( uint i = 0; g_rgActionInfo[i].id != ActionNone; i++ ) {
123 if( g_rgActionInfo[i].id == id )
124 return &g_rgActionInfo[i];
125 }
126 return 0;
127}
128
129QStringList stdNames()
130{
131 QStringList result;
132
133 for( uint i = 0; g_rgActionInfo[i].id != ActionNone; i++ )
134 if (g_rgActionInfo[i].psLabel)
135 result.append(i18n(g_rgActionInfo[i].psLabel));
136 return result;
137}
138
139KAction* create( StdAction id, const char *name, const QObject *recvr, const char *slot, KActionCollection* parent )
140{
141 KAction* pAction = 0;
142 const KStdActionInfo* pInfo = infoPtr( id );
143 kdDebug(125) << "KStdAction::create( " << id << "=" << (pInfo ? pInfo->psName : (const char*)0) << ", " << parent << ", " << name << " )" << endl; // ellis
144 if( pInfo ) {
145 QString sLabel, iconName = pInfo->psIconName;
146 switch( id ) {
147 case Back: sLabel = i18n("go back", "&Back");
148 //US if (QApplication::reverseLayout() )
149 //US iconName = "forward";
150 break;
151
152 case Forward: sLabel = i18n("go forward", "&Forward");
153 //US if (QApplication::reverseLayout() )
154 //US iconName = "back";
155 break;
156
157 case Home: sLabel = i18n("beginning (of line)", "&Home"); break;
158 case Help: sLabel = i18n("show help", "&Help"); break;
159 //US case AboutApp: iconName = kapp->miniIconName();
160 case Preferences:
161 case HelpContents:
162 {
163 //US const KAboutData *aboutData = KGlobal::instance()->aboutData();
164 //US QString appName = (aboutData) ? aboutData->programName() : QString::fromLatin1(qApp->name());
165 QString appName = QString::fromLatin1(KGlobal::getAppName());
166 sLabel = i18n(pInfo->psLabel).arg(appName);
167 }
168 break;
169 default: sLabel = i18n(pInfo->psLabel);
170 }
171
172 /*US if (QApplication::reverseLayout()){
173 if (id == Prior) iconName = "next";
174 if (id == Next ) iconName = "previous";
175 }
176 */
177 //US KShortcut cut = KStdAccel::shortcut(pInfo->idAccel);
178 KShortcut cut;
179 switch( id ) {
180 case OpenRecent:
181 pAction = new KRecentFilesAction( sLabel, cut,
182 recvr, slot,
183 parent, (name) ? name : pInfo->psName );
184 break;
185 case ShowMenubar:
186 case ShowToolbar:
187 case ShowStatusbar:
188 KToggleAction *ret;
189 ret = new KToggleAction( sLabel, pInfo->psIconName, cut,
190 recvr, slot,
191 parent, (name) ? name : pInfo->psName );
192 ret->setChecked( true );
193 pAction = ret;
194 break;
195 default:
196 pAction = new KAction( sLabel, iconName, cut,
197 recvr, slot,
198 parent, (name) ? name : pInfo->psName );
199 break;
200 }
201 }
202 return pAction;
203}
204
205const char* name( StdAction id )
206{
207 const KStdActionInfo* pInfo = infoPtr( id );
208 return (pInfo) ? pInfo->psName : 0;
209}
210
211KAction *openNew( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
212 { return KStdAction::create( New, name, recvr, slot, parent ); }
213KAction *open( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
214 { return KStdAction::create( Open, name, recvr, slot, parent ); }
215KRecentFilesAction *openRecent( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
216 { return (KRecentFilesAction*) KStdAction::create( OpenRecent, name, recvr, slot, parent ); }
217KAction *save( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
218 { return KStdAction::create( Save, name, recvr, slot, parent ); }
219KAction *saveAs( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
220 { return KStdAction::create( SaveAs, name, recvr, slot, parent ); }
221KAction *revert( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
222 { return KStdAction::create( Revert, name, recvr, slot, parent ); }
223KAction *print( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
224 { return KStdAction::create( Print, name, recvr, slot, parent ); }
225KAction *printPreview( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
226 { return KStdAction::create( PrintPreview, name, recvr, slot, parent ); }
227KAction *close( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
228 { return KStdAction::create( Close, name, recvr, slot, parent ); }
229KAction *mail( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
230 { return KStdAction::create( Mail, name, recvr, slot, parent ); }
231KAction *quit( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
232 { return KStdAction::create( Quit, name, recvr, slot, parent ); }
233KAction *undo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
234 { return KStdAction::create( Undo, name, recvr, slot, parent ); }
235KAction *redo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
236 { return KStdAction::create( Redo, name, recvr, slot, parent ); }
237KAction *cut( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
238 { return KStdAction::create( Cut, name, recvr, slot, parent ); }
239KAction *copy( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
240 { return KStdAction::create( Copy, name, recvr, slot, parent ); }
241KAction *paste( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
242 { return KStdAction::create( Paste, name, recvr, slot, parent ); }
243KAction *selectAll( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
244 { return KStdAction::create( SelectAll, name, recvr, slot, parent ); }
245KAction *deselect( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
246 { return KStdAction::create( Deselect, name, recvr, slot, parent ); }
247KAction *find( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
248 { return KStdAction::create( Find, name, recvr, slot, parent ); }
249KAction *findNext( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
250 { return KStdAction::create( FindNext, name, recvr, slot, parent ); }
251KAction *findPrev( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
252 { return KStdAction::create( FindPrev, name, recvr, slot, parent ); }
253KAction *replace( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
254 { return KStdAction::create( Replace, name, recvr, slot, parent ); }
255KAction *actualSize( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
256 { return KStdAction::create( ActualSize, name, recvr, slot, parent ); }
257KAction *fitToPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
258 { return KStdAction::create( FitToPage, name, recvr, slot, parent ); }
259KAction *fitToWidth( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
260 { return KStdAction::create( FitToWidth, name, recvr, slot, parent ); }
261KAction *fitToHeight( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
262 { return KStdAction::create( FitToHeight, name, recvr, slot, parent ); }
263KAction *zoomIn( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
264 { return KStdAction::create( ZoomIn, name, recvr, slot, parent ); }
265KAction *zoomOut( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
266 { return KStdAction::create( ZoomOut, name, recvr, slot, parent ); }
267KAction *zoom( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
268 { return KStdAction::create( Zoom, name, recvr, slot, parent ); }
269KAction *redisplay( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
270 { return KStdAction::create( Redisplay, name, recvr, slot, parent ); }
271KAction *up( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
272 { return KStdAction::create( Up, name, recvr, slot, parent ); }
273KAction *back( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
274 { return KStdAction::create( Back, name, recvr, slot, parent ); }
275KAction *forward( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
276 { return KStdAction::create( Forward, name, recvr, slot, parent ); }
277KAction *home( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
278 { return KStdAction::create( Home, name, recvr, slot, parent ); }
279KAction *prior( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
280 { return KStdAction::create( Prior, name, recvr, slot, parent ); }
281KAction *next( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
282 { return KStdAction::create( Next, name, recvr, slot, parent ); }
283KAction *goTo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
284 { return KStdAction::create( Goto, name, recvr, slot, parent ); }
285KAction *gotoPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
286 { return KStdAction::create( GotoPage, name, recvr, slot, parent ); }
287KAction *gotoLine( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
288 { return KStdAction::create( GotoLine, name, recvr, slot, parent ); }
289KAction *firstPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
290 { return KStdAction::create( FirstPage, name, recvr, slot, parent ); }
291KAction *lastPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
292 { return KStdAction::create( LastPage, name, recvr, slot, parent ); }
293KAction *addBookmark( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
294 { return KStdAction::create( AddBookmark, name, recvr, slot, parent ); }
295KAction *editBookmarks( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
296 { return KStdAction::create( EditBookmarks, name, recvr, slot, parent ); }
297KAction *spelling( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
298 { return KStdAction::create( Spelling, name, recvr, slot, parent ); }
299
300KToggleAction *showMenubar( const QObject *recvr, const char *slot, KActionCollection* parent, const char *_name )
301{
302 KToggleAction *ret;
303 ret = new KToggleAction(i18n("Show &Menubar"), "showmenu", /*US KStdAccel::shortcut(KStdAccel::ShowMenubar)*/0, recvr, slot,
304 parent, _name ? _name : name(ShowMenubar));
305 ret->setChecked(true);
306 return ret;
307}
308
309KToggleAction *showToolbar( const QObject *recvr, const char *slot, KActionCollection* parent, const char *_name )
310{
311 KToggleAction *ret;
312 ret = new KToggleAction(i18n("Show &Toolbar"), 0, recvr, slot, parent,
313 _name ? _name : name(ShowToolbar));
314 ret->setChecked(true);
315 return ret;
316
317}
318
319KToggleToolBarAction *showToolbar( const char* toolBarName, KActionCollection* parent, const char *_name )
320{
321 KToggleToolBarAction *ret;
322 ret = new KToggleToolBarAction(toolBarName, i18n("Show &Toolbar"), parent,
323 _name ? _name : name(ShowToolbar));
324 return ret;
325}
326
327KToggleAction *showStatusbar( const QObject *recvr, const char *slot,
328 KActionCollection* parent, const char *_name )
329{
330 KToggleAction *ret;
331 ret = new KToggleAction(i18n("Show St&atusbar"), 0, recvr, slot, parent,
332 _name ? _name : name(ShowStatusbar));
333 ret->setChecked(true);
334 return ret;
335}
336
337KAction *saveOptions( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
338 { return KStdAction::create( SaveOptions, name, recvr, slot, parent ); }
339KAction *keyBindings( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
340 { return KStdAction::create( KeyBindings, name, recvr, slot, parent ); }
341KAction *preferences( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
342 { return KStdAction::create( Preferences, name, recvr, slot, parent ); }
343KAction *configureToolbars( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
344 { return KStdAction::create( ConfigureToolbars, name, recvr, slot, parent ); }
345KAction *configureNotifications( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
346 { return KStdAction::create( ConfigureNotifications, name, recvr, slot, parent ); }
347KAction *help( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
348 { return KStdAction::create( Help, name, recvr, slot, parent ); }
349KAction *helpContents( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
350 { return KStdAction::create( HelpContents, name, recvr, slot, parent ); }
351KAction *whatsThis( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
352 { return KStdAction::create( WhatsThis, name, recvr, slot, parent ); }
353KAction *tipOfDay( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
354 { return KStdAction::create( TipofDay, name, recvr, slot, parent ); }
355KAction *reportBug( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
356 { return KStdAction::create( ReportBug, name, recvr, slot, parent ); }
357KAction *aboutApp( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
358 { return KStdAction::create( AboutApp, name, recvr, slot, parent ); }
359KAction *aboutKDE( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
360 { return KStdAction::create( AboutKDE, name, recvr, slot, parent ); }
361
362}
diff --git a/microkde/kdeui/kstdaction.h b/microkde/kdeui/kstdaction.h
new file mode 100644
index 0000000..bc712b3
--- a/dev/null
+++ b/microkde/kdeui/kstdaction.h
@@ -0,0 +1,568 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 1999,2000 Kurt Granroth <granroth@kde.org>
3 Copyright (C) 2001,2002 Ellis Whitehead <ellis@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
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., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18*/
19#ifndef KSTDACTION_H
20#define KSTDACTION_H
21
22class QObject;
23class KAction;
24class KActionCollection;
25class KRecentFilesAction;
26class KToggleAction;
27class KToggleToolBarAction;
28
29#include <qstringlist.h>
30
31/**
32 * Convenience methods to access all standard KDE actions.
33 *
34 * These actions should be used instead of hardcoding menubar and
35 * toolbar items. Using these actions helps your application easily
36 * conform to the KDE UI Style Guide
37 * @see http://developer.kde.org/documentation/standards/kde/style/basics/index.html .
38 *
39 * All of the documentation for @ref KAction holds for KStdAction
40 * also. When in doubt on how things work, check the @ref KAction
41 * documention first.
42 *
43 * @sect Simple Example:
44 *
45 * In general, using standard actions should be a drop in replacement
46 * for regular actions. For example, if you previously had:
47 *
48 * <PRE>
49 * KAction *newAct = new KAction(i18n("&New"), QIconSet(BarIcon("filenew")),
50 * KStdAccel::key(KStdAccel::New), this,
51 * SLOT(fileNew()), actionCollection());
52 * </PRE>
53 *
54 * You could drop that and replace it with:
55 *
56 * <PRE>
57 * KAction *newAct = KStdAction::openNew(this, SLOT(fileNew()),
58 * actionCollection());
59 * </PRE>
60 *
61 * @sect Non-standard Usages
62 *
63 * It is possible to use the standard actions in various
64 * non-recommended ways. Say, for instance, you wanted to have a
65 * standard action (with the associated correct text and icon and
66 * accelerator, etc) but you didn't want it to go in the standard
67 * place (this is not recommended, by the way). One way to do this is
68 * to simply not use the XML UI framework and plug it into wherever
69 * you want. If you do want to use the XML UI framework (good!), then
70 * it is still possible.
71 *
72 * Basically, the XML building code matches names in the XML code with
73 * the internal names of the actions. You can find out the internal
74 * names of each of the standard actions by using the @ref stdName
75 * action like so: @ref KStdAction::stdName(KStdAction::Cut) would return
76 * 'edit_cut'. The XML building code will match 'edit_cut' to the
77 * attribute in the global XML file and place your action there.
78 *
79 * However, you can change the internal name. In this example, just
80 * do something like:
81 *
82 * <PRE>
83 * (void)KStdAction::cut(this, SLOT(editCut()), actionCollection(), "my_cut");
84 * </PRE>
85 *
86 * Now, in your local XML resource file (e.g., yourappui.rc), simply
87 * put 'my_cut' where you want it to go.
88 *
89 * Another non-standard usage concerns getting a pointer to an
90 * existing action if, say, you want to enable or disable the action.
91 * You could do it the recommended way and just grab a pointer when
92 * you instantiate it as in the the 'openNew' example above... or you
93 * could do it the hard way:
94 *
95 * <pre>
96 * KAction *cut = actionCollection()->action(KStdAction::stdName(KStdAction::Cut));
97 * </pre>
98 *
99 * Another non-standard usage concerns instantiating the action in the
100 * first place. Usually, you would use the member functions as
101 * shown above (e.g., KStdAction::cut(this, SLOT, parent)). You
102 * may, however, do this using the enums provided. This author can't
103 * think of a reason why you would want to, but, hey, if you do,
104 * here's how:
105 *
106 * <pre>
107 * (void)KStdAction::action(KStdAction::New, this, SLOT(fileNew()), actionCollection());
108 * (void)KStdAction::action(KStdAction::Cut, this, SLOT(editCut()), actionCollection());
109 * </pre>
110 *
111 * @author Kurt Granroth <granroth@kde.org>
112 */
113namespace KStdAction
114{
115 /**
116 * The standard menubar and toolbar actions.
117 */
118 enum StdAction {
119 ActionNone,
120
121 // File Menu
122 New, Open, OpenRecent, Save, SaveAs, Revert, Close,
123 Print, PrintPreview, Mail, Quit,
124
125 // Edit Menu
126 Undo, Redo, Cut, Copy, Paste, SelectAll, Deselect, Find, FindNext, FindPrev,
127 Replace,
128
129 // View Menu
130 ActualSize, FitToPage, FitToWidth, FitToHeight, ZoomIn, ZoomOut,
131 Zoom, Redisplay,
132
133 // Go Menu
134 Up, Back, Forward, Home, Prior, Next, Goto, GotoPage, GotoLine,
135 FirstPage, LastPage,
136
137 // Bookmarks Menu
138 AddBookmark, EditBookmarks,
139
140 // Tools Menu
141 Spelling,
142
143 // Settings Menu
144 ShowMenubar, ShowToolbar, ShowStatusbar, SaveOptions, KeyBindings,
145 Preferences, ConfigureToolbars,
146
147 // Help Menu
148 Help, HelpContents, WhatsThis, ReportBug, AboutApp, AboutKDE,
149 TipofDay, ///< @since 3.1
150
151 // Another settings menu item
152 ConfigureNotifications
153 };
154
155 /**
156 * Creates an action corresponding to the
157 * @ref KStdAction::StdAction enum.
158 */
159 KAction* create( StdAction id, const char *name,
160 const QObject *recvr, const char *slot,
161 KActionCollection* parent );
162
163 inline KAction* create( StdAction id,
164 const QObject *recvr, const char *slot,
165 KActionCollection* parent )
166 { return KStdAction::create( id, 0, recvr, slot, parent ); }
167
168 /**
169 * @obsolete. Creates an action corresponding to the
170 * @ref KStdAction::StdAction enum.
171 */
172 inline KAction *action(StdAction act_enum,
173 const QObject *recvr, const char *slot,
174 KActionCollection *parent, const char *name = 0L )
175 { return KStdAction::create( act_enum, name, recvr, slot, parent ); }
176
177 /**
178 * This will return the internal name of a given standard action.
179 */
180 const char* name( StdAction id );
181
182 /// @obsolete. Use #name
183 inline const char* stdName(StdAction act_enum) { return name( act_enum ); }
184
185 /**
186 * Returns a list of all standard names. Used by @ref KAccelManager
187 * to give those heigher weight.
188 * @since 3.1
189 */
190 QStringList stdNames();
191
192 /**
193 * Create a new document or window.
194 */
195 KAction *openNew(const QObject *recvr, const char *slot, KActionCollection* parent, const char *name = 0 );
196
197 /**
198 * Open an existing file.
199 */
200 KAction *open(const QObject *recvr, const char *slot, KActionCollection* parent, const char *name = 0 );
201
202 /**
203 * Open a recently used document.
204 * @param slot The SLOT to invoke when a URL is selected.
205 * Its signature is of the form slotURLSelected( const KURL & ).
206 */
207 KRecentFilesAction *openRecent(const QObject *recvr, const char *slot, KActionCollection* parent, const char *name = 0 );
208
209 /**
210 * Save the current document.
211 */
212 KAction *save(const QObject *recvr, const char *slot,
213 KActionCollection* parent, const char *name = 0 );
214
215 /**
216 * Save the current document under a different name.
217 */
218 KAction *saveAs(const QObject *recvr, const char *slot,
219 KActionCollection* parent, const char *name = 0 );
220
221 /**
222 * Revert the current document to the last saved version
223 * (essentially will undo all changes).
224 */
225 KAction *revert(const QObject *recvr, const char *slot,
226 KActionCollection* parent, const char *name = 0 );
227
228 /**
229 * Close the current document.
230 */
231 KAction *close(const QObject *recvr, const char *slot,
232 KActionCollection* parent, const char *name = 0 );
233
234 /**
235 * Print the current document.
236 */
237 KAction *print(const QObject *recvr, const char *slot,
238 KActionCollection* parent, const char *name = 0 );
239
240 /**
241 * Show a print preview of the current document.
242 */
243 KAction *printPreview(const QObject *recvr, const char *slot,
244 KActionCollection* parent, const char *name = 0 );
245
246 /**
247 * Mail this document.
248 */
249 KAction *mail(const QObject *recvr, const char *slot,
250 KActionCollection* parent, const char *name = 0 );
251
252 /**
253 * Quit the program.
254 */
255 KAction *quit(const QObject *recvr, const char *slot,
256 KActionCollection* parent, const char *name = 0 );
257
258 /**
259 * Undo the last operation.
260 */
261 KAction *undo(const QObject *recvr, const char *slot,
262 KActionCollection* parent, const char *name = 0 );
263
264 /**
265 * Redo the last operation.
266 */
267 KAction *redo(const QObject *recvr, const char *slot,
268 KActionCollection* parent, const char *name = 0 );
269
270 /**
271 * Cut selected area and store it in the clipboard.
272 */
273 KAction *cut(const QObject *recvr, const char *slot,
274 KActionCollection* parent, const char *name = 0 );
275
276 /**
277 * Copy the selected area into the clipboard.
278 */
279 KAction *copy(const QObject *recvr, const char *slot,
280 KActionCollection* parent, const char *name = 0 );
281
282 /**
283 * Paste the contents of clipboard at the current mouse or cursor
284 * position.
285 */
286 KAction *paste(const QObject *recvr, const char *slot,
287 KActionCollection* parent, const char *name = 0 );
288
289 /**
290 * Select all elements in the current document.
291 */
292 KAction *selectAll(const QObject *recvr, const char *slot,
293 KActionCollection* parent, const char *name = 0 );
294
295 /**
296 * Deselect any selected elements in the current document.
297 */
298 KAction *deselect(const QObject *recvr, const char *slot,
299 KActionCollection* parent, const char *name = 0 );
300
301 /**
302 * Initiate a 'find' request in the current document.
303 */
304 KAction *find(const QObject *recvr, const char *slot,
305 KActionCollection* parent, const char *name = 0 );
306
307 /**
308 * Find the next instance of a stored 'find'.
309 */
310 KAction *findNext(const QObject *recvr, const char *slot,
311 KActionCollection* parent, const char *name = 0 );
312
313 /**
314 * Find a previous instance of a stored 'find'.
315 */
316 KAction *findPrev(const QObject *recvr, const char *slot,
317 KActionCollection* parent, const char *name = 0 );
318
319 /**
320 * Find and replace matches.
321 */
322 KAction *replace(const QObject *recvr, const char *slot,
323 KActionCollection* parent, const char *name = 0 );
324
325 /**
326 * View the document at its actual size.
327 */
328 KAction *actualSize(const QObject *recvr, const char *slot,
329 KActionCollection* parent, const char *name = 0 );
330
331 /**
332 * Fit the document view to the size of the current window.
333 */
334 KAction *fitToPage(const QObject *recvr, const char *slot,
335 KActionCollection* parent, const char *name = 0 );
336
337 /**
338 * Fit the document view to the width of the current window.
339 */
340 KAction *fitToWidth(const QObject *recvr, const char *slot,
341 KActionCollection* parent, const char *name = 0 );
342
343 /**
344 * Fit the document view to the height of the current window.
345 */
346 KAction *fitToHeight(const QObject *recvr, const char *slot,
347 KActionCollection* parent, const char *name = 0 );
348
349 /**
350 * Zoom in.
351 */
352 KAction *zoomIn(const QObject *recvr, const char *slot,
353 KActionCollection* parent, const char *name = 0 );
354
355 /**
356 * Zoom out.
357 */
358 KAction *zoomOut(const QObject *recvr, const char *slot,
359 KActionCollection* parent, const char *name = 0 );
360
361 /**
362 * Popup a zoom dialog.
363 */
364 KAction *zoom(const QObject *recvr, const char *slot,
365 KActionCollection* parent, const char *name = 0 );
366
367 /**
368 * Redisplay or redraw the document.
369 */
370 KAction *redisplay(const QObject *recvr, const char *slot,
371 KActionCollection* parent, const char *name = 0 );
372
373 /**
374 * Move up (web style menu).
375 */
376 KAction *up(const QObject *recvr, const char *slot,
377 KActionCollection* parent, const char *name = 0 );
378
379 /**
380 * Move back (web style menu).
381 */
382 KAction *back(const QObject *recvr, const char *slot,
383 KActionCollection* parent, const char *name = 0 );
384
385 /**
386 * Move forward (web style menu).
387 */
388 KAction *forward(const QObject *recvr, const char *slot,
389 KActionCollection* parent, const char *name = 0 );
390
391 /**
392 * Go to the "Home" position or document.
393 */
394 KAction *home(const QObject *recvr, const char *slot,
395 KActionCollection* parent, const char *name = 0 );
396
397 /**
398 * Scroll up one page.
399 */
400 KAction *prior(const QObject *recvr, const char *slot,
401 KActionCollection* parent, const char *name = 0 );
402
403 /**
404 * Scroll down one page.
405 */
406 KAction *next(const QObject *recvr, const char *slot,
407 KActionCollection* parent, const char *name = 0 );
408
409 /**
410 * Go to somewhere in general.
411 */
412 KAction *goTo(const QObject *recvr, const char *slot,
413 KActionCollection* parent, const char *name = 0 );
414
415
416 /**
417 * Go to a specific page (dialog).
418 */
419 KAction *gotoPage(const QObject *recvr, const char *slot,
420 KActionCollection* parent, const char *name = 0 );
421
422 /**
423 * Go to a specific line (dialog).
424 */
425 KAction *gotoLine(const QObject *recvr, const char *slot,
426 KActionCollection* parent, const char *name = 0 );
427
428 /**
429 * Jump to the first page.
430 */
431 KAction *firstPage(const QObject *recvr, const char *slot,
432 KActionCollection* parent, const char *name = 0 );
433
434 /**
435 * Jump to the last page.
436 */
437 KAction *lastPage(const QObject *recvr, const char *slot,
438 KActionCollection* parent, const char *name = 0 );
439
440 /**
441 * Add the current page to the bookmarks tree.
442 */
443 KAction *addBookmark(const QObject *recvr, const char *slot,
444 KActionCollection* parent, const char *name = 0 );
445
446 /**
447 * Edit the application bookmarks.
448 */
449 KAction *editBookmarks(const QObject *recvr, const char *slot,
450 KActionCollection* parent, const char *name = 0 );
451
452 /**
453 * Pop up the spell checker.
454 */
455 KAction *spelling(const QObject *recvr, const char *slot,
456 KActionCollection* parent, const char *name = 0 );
457
458
459 /**
460 * Show/Hide the menubar.
461 */
462 KToggleAction *showMenubar(const QObject *recvr, const char *slot,
463 KActionCollection* parent, const char *name = 0 );
464
465 /**
466 * @obsolete. toolbar actions are created automatically now in the
467 * Settings menu. Don't use this anymore.
468 * See: @ref KMainWindow::createStandardStatusBarAction()
469 * Show/Hide the primary toolbar.
470 * @since 3.1
471 */
472 KToggleAction *showToolbar(const QObject *recvr, const char *slot,
473 KActionCollection* parent, const char *name = 0 );
474 /**
475 * @obsolete. toolbar actions are created automatically now in the
476 * Settings menu. Don't use this anymore.
477 * See: @ref KMainWindow::setStandardToolBarMenuEnabled(bool);
478 * Show/Hide the primary toolbar.
479 */
480 KToggleToolBarAction *showToolbar(const char* toolBarName,
481 KActionCollection* parent, const char *name = 0 );
482
483 /**
484 * Show/Hide the statusbar.
485 */
486 KToggleAction *showStatusbar(const QObject *recvr, const char *slot,
487 KActionCollection* parent, const char *name = 0 );
488
489 /**
490 * Display the save options dialog.
491 */
492 KAction *saveOptions(const QObject *recvr, const char *slot,
493 KActionCollection* parent, const char *name = 0 );
494
495 /**
496 * Display the configure key bindings dialog.
497 */
498 KAction *keyBindings(const QObject *recvr, const char *slot,
499 KActionCollection* parent, const char *name = 0 );
500
501 /**
502 * Display the preferences/options dialog.
503 */
504 KAction *preferences(const QObject *recvr, const char *slot,
505 KActionCollection* parent, const char *name = 0 );
506
507 /**
508 * The Customize Toolbar dialog.
509 */
510 KAction *configureToolbars(const QObject *recvr,
511 const char *slot,
512 KActionCollection* parent,
513 const char *name = 0 );
514
515 /**
516 * The Configure Notifications dialo
517 * @since 3.1
518 */
519 KAction *configureNotifications(const QObject *recvr,
520 const char *slot,
521 KActionCollection *parent,
522 const char *name = 0);
523
524 /**
525 * Display the help.
526 */
527 KAction *help(const QObject *recvr, const char *slot,
528 KActionCollection* parent, const char *name = 0 );
529
530 /**
531 * Display the help contents.
532 */
533 KAction *helpContents(const QObject *recvr, const char *slot,
534 KActionCollection* parent, const char *name = 0 );
535
536 /**
537 * Trigger the What's This cursor.
538 */
539 KAction *whatsThis(const QObject *recvr, const char *slot,
540 KActionCollection* parent, const char *name = 0 );
541
542 /**
543 * Display "Tip of the Day"
544 * @since 3.1
545 */
546 KAction *tipOfDay(const QObject *recvr, const char *slot,
547 KActionCollection* parent, const char *name = 0 );
548
549 /**
550 * Open up the Report Bug dialog.
551 */
552 KAction *reportBug(const QObject *recvr, const char *slot,
553 KActionCollection* parent, const char *name = 0 );
554
555 /**
556 * Display the application's About box.
557 */
558 KAction *aboutApp(const QObject *recvr, const char *slot,
559 KActionCollection* parent, const char *name = 0 );
560
561 /**
562 * Display the About KDE dialog.
563 */
564 KAction *aboutKDE(const QObject *recvr, const char *slot,
565 KActionCollection* parent, const char *name = 0 );
566}
567
568#endif // KSTDACTION_H
diff --git a/microkde/kdeui/ktoolbar.cpp b/microkde/kdeui/ktoolbar.cpp
new file mode 100644
index 0000000..92cb8d2
--- a/dev/null
+++ b/microkde/kdeui/ktoolbar.cpp
@@ -0,0 +1,2260 @@
1/* This file is part of the KDE libraries
2 Copyright
3 (C) 2000 Reginald Stadlbauer (reggie@kde.org)
4 (C) 1997, 1998 Stephan Kulow (coolo@kde.org)
5 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org)
6 (C) 1997, 1998 Sven Radej (radej@kde.org)
7 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org)
8 (C) 1999 Chris Schlaeger (cs@kde.org)
9 (C) 1999 Kurt Granroth (granroth@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#ifdef KDE_USE_FINAL
27#undef Always
28#include <qdockwindow.h>
29#endif
30
31
32
33#include "ktoolbar.h"
34#include "kmainwindow.h"
35
36#include <string.h>
37
38#include <qpainter.h>
39#include <qtooltip.h>
40#include <qdrawutil.h>
41#include <qstring.h>
42#include <qrect.h>
43#include <qobjectlist.h>
44#include <qtimer.h>
45#include <qstyle.h>
46#include <qapplication.h>
47
48//US #include <config.h>
49
50#include "klineedit.h"
51#include "kseparator.h"
52#include <klocale.h>
53#include <kapplication.h>
54#include <kaction.h>
55#include <kstdaction.h>
56#include <kglobal.h>
57#include <kconfig.h>
58#include <kiconloader.h>
59#include <kcombobox.h>
60//US #include <kpopupmenu.h>
61//US #include <kanimwidget.h>
62//US #include <kipc.h>
63//US #include <kwin.h>
64#include <kdebug.h>
65#include <qlayout.h>
66
67#include "ktoolbarbutton.h"
68
69//US
70#include "kconfigbase.h"
71
72#include <qpopupmenu.h>
73#include <qmainwindow.h>
74
75enum {
76 CONTEXT_TOP = 0,
77 CONTEXT_LEFT = 1,
78 CONTEXT_RIGHT = 2,
79 CONTEXT_BOTTOM = 3,
80 CONTEXT_FLOAT = 4,
81 CONTEXT_FLAT = 5,
82 CONTEXT_ICONS = 6,
83 CONTEXT_TEXT = 7,
84 CONTEXT_TEXTRIGHT = 8,
85 CONTEXT_TEXTUNDER = 9,
86 CONTEXT_ICONSIZES = 50 // starting point for the icon size list, put everything else before
87};
88
89class KToolBarPrivate
90{
91public:
92 KToolBarPrivate() {
93 m_iconSize = 0;
94 m_iconText = KToolBar::IconOnly;
95 m_highlight = true;
96 m_transparent = true;
97 m_honorStyle = false;
98
99 m_enableContext = true;
100
101 m_xmlguiClient = 0;
102 m_configurePlugged = false;
103
104//US oldPos = Qt::DockUnmanaged;
105 oldPos = QMainWindow::Unmanaged;
106
107 modified = m_isHorizontal = positioned = FALSE;
108
109 HiddenDefault = false;
110 IconSizeDefault = 0;
111 IconTextDefault = "IconOnly";
112 IndexDefault = -1;
113 NewLineDefault = false;
114 OffsetDefault = -1;
115 PositionDefault = "Top";
116 idleButtons.setAutoDelete(true);
117 }
118
119 int m_iconSize;
120 KToolBar::IconText m_iconText;
121 bool m_highlight : 1;
122 bool m_transparent : 1;
123 bool m_honorStyle : 1;
124 bool m_isHorizontal : 1;
125 bool m_enableContext : 1;
126 bool m_configurePlugged : 1;
127 bool modified : 1;
128 bool positioned : 1;
129
130 QWidget *m_parent;
131
132 QMainWindow::ToolBarDock oldPos;
133
134 KXMLGUIClient *m_xmlguiClient;
135
136 struct ToolBarInfo
137 {
138//US ToolBarInfo() : index( 0 ), offset( -1 ), newline( FALSE ), dock( Qt::DockTop ) {}
139 ToolBarInfo() : index( 0 ), offset( -1 ), newline( FALSE ), dock( QMainWindow::Top ) {}
140//US ToolBarInfo( Qt::Dock d, int i, bool n, int o ) : index( i ), offset( o ), newline( n ), dock( d ) {}
141 ToolBarInfo( QMainWindow::ToolBarDock d, int i, bool n, int o ) : index( i ), offset( o ), newline( n ), dock( d ) {}
142 int index, offset;
143 bool newline;
144//US Qt::Dock dock;
145 QMainWindow::ToolBarDock dock;
146 };
147
148 ToolBarInfo toolBarInfo;
149 QValueList<int> iconSizes;
150 QTimer repaintTimer;
151
152 // Default Values.
153 bool HiddenDefault;
154 int IconSizeDefault;
155 QString IconTextDefault;
156 int IndexDefault;
157 bool NewLineDefault;
158 int OffsetDefault;
159 QString PositionDefault;
160
161 QPtrList<QWidget> idleButtons;
162};
163
164KToolBarSeparator::KToolBarSeparator(Orientation o , bool l, QToolBar *parent,
165 const char* name )
166 :QFrame( parent, name ), line( l )
167{
168 connect( parent, SIGNAL(orientationChanged(Orientation)),
169 this, SLOT(setOrientation(Orientation)) );
170 setOrientation( o );
171 setBackgroundMode( parent->backgroundMode() );
172 setBackgroundOrigin( ParentOrigin );
173}
174
175void KToolBarSeparator::setOrientation( Orientation o )
176{
177 orient = o;
178 if ( line ) {
179 if ( orientation() == Vertical )
180 setFrameStyle( HLine + Sunken );
181 else
182 setFrameStyle( VLine + Sunken );
183 } else {
184 setFrameStyle( NoFrame );
185 }
186}
187
188void KToolBarSeparator::styleChange( QStyle& )
189{
190 setOrientation( orient );
191}
192
193QSize KToolBarSeparator::sizeHint() const
194{
195 return orientation() == Vertical ? QSize( 0, 6 ) : QSize( 6, 0 );
196}
197
198QSizePolicy KToolBarSeparator::sizePolicy() const
199{
200 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
201}
202
203KToolBar::KToolBar( QWidget *parent, const char *name, bool honorStyle, bool readConfig )
204#ifdef DESKTOP_VERSION
205 : QToolBar( QString::fromLatin1( name ),
206 parent && parent->inherits( "QMainWindow" ) ? static_cast<QMainWindow*>(parent) : 0,
207 parent, FALSE,
208 name ? name : "mainToolBar")
209#else
210 : QPEToolBar( parent && parent->inherits( "QMainWindow" ) ? static_cast<QMainWindow*>(parent) : 0,
211 QString::fromLatin1( name ))
212
213
214#endif
215{
216 init( readConfig, honorStyle );
217}
218
219KToolBar::KToolBar( QMainWindow *parentWindow, QMainWindow::ToolBarDock dock, bool newLine, const char *name, bool honorStyle, bool readConfig )
220#ifdef DESKTOP_VERSION
221 : QToolBar( QString::fromLatin1( name ),
222 parentWindow, dock, newLine,
223 name ? name : "mainToolBar")
224#else
225 : QPEToolBar( parentWindow,QString::fromLatin1( name ))
226
227
228#endif
229
230{
231 init( readConfig, honorStyle );
232}
233
234KToolBar::KToolBar( QMainWindow *parentWindow, QWidget *dock, bool newLine, const char *name, bool honorStyle, bool readConfig )
235#ifdef DESKTOP_VERSION
236 : QToolBar( QString::fromLatin1( name ),
237 parentWindow, dock, newLine,
238 name ? name : "mainToolBar")
239#else
240 : QPEToolBar( parentWindow,QString::fromLatin1( name ))
241
242
243#endif
244
245{
246 init( readConfig, honorStyle );
247}
248
249KToolBar::~KToolBar()
250{
251 inshutdownprocess = true;
252 emit toolbarDestroyed();
253 delete d;
254}
255
256void KToolBar::init( bool readConfig, bool honorStyle )
257{
258 inshutdownprocess = false;
259 d = new KToolBarPrivate;
260 setFullSize( TRUE );
261 d->m_honorStyle = honorStyle;
262 context = 0;
263 layoutTimer = new QTimer( this );
264 connect( layoutTimer, SIGNAL( timeout() ),
265 this, SLOT( rebuildLayout() ) );
266 connect( &(d->repaintTimer), SIGNAL( timeout() ),
267 this, SLOT( slotRepaint() ) );
268/*US
269 if ( kapp ) { // may be null when started inside designer
270 connect(kapp, SIGNAL(toolbarAppearanceChanged(int)), this, SLOT(slotAppearanceChanged()));
271 // request notification of changes in icon style
272 kapp->addKipcEventMask(KIPC::IconChanged);
273 connect(kapp, SIGNAL(iconChanged(int)), this, SLOT(slotIconChanged(int)));
274 }
275*/
276 // finally, read in our configurable settings
277 if ( readConfig )
278 slotReadConfig();
279
280 if ( mainWindow() )
281 connect( mainWindow(), SIGNAL( toolBarPositionChanged( QToolBar * ) ),
282 this, SLOT( toolBarPosChanged( QToolBar * ) ) );
283
284 // Hack to make sure we recalculate our size when we dock.
285//US connect( this, SIGNAL(placeChanged(QDockWindow::Place)), SLOT(rebuildLayout()) );
286}
287
288int KToolBar::insertButton(const QString& icon, int id, bool enabled,
289 const QString& text, int index/*US, KInstance *_instance*/ )
290{
291 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text/*US, _instance*/ );
292
293 insertWidgetInternal( button, index, id );
294 button->setEnabled( enabled );
295 doConnections( button );
296 return index;
297}
298
299
300int KToolBar::insertButton(const QString& icon, int id, const char *signal,
301 const QObject *receiver, const char *slot,
302 bool enabled, const QString& text, int index/*US, KInstance *_instance*/ )
303{
304 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text/*US, _instance*/);
305 insertWidgetInternal( button, index, id );
306 button->setEnabled( enabled );
307 connect( button, signal, receiver, slot );
308 doConnections( button );
309 return index;
310}
311
312
313int KToolBar::insertButton(const QPixmap& pixmap, int id, bool enabled,
314 const QString& text, int index )
315{
316 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text);
317 insertWidgetInternal( button, index, id );
318 button->setEnabled( enabled );
319 doConnections( button );
320 return index;
321}
322#if 0
323 bar->insertButton( icon, id_, SIGNAL( clicked() ), this,
324 SLOT( slotActivated() ),
325 d->isEnabled(), d->plainText(), index/*US, instance*/ );
326#endif
327
328int KToolBar::insertButton(const QPixmap& pixmap, int id, const char *signal,
329 const QObject *receiver, const char *slot,
330 bool enabled, const QString& text,
331 int index )
332{
333 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text);
334 insertWidgetInternal( button, index, id );
335 button->setEnabled( enabled );
336 connect( button, signal, receiver, slot );
337 doConnections( button );
338 return index;
339}
340
341
342int KToolBar::insertButton(const QString& icon, int id, QPopupMenu *popup,
343 bool enabled, const QString &text, int index )
344{
345 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text );
346 insertWidgetInternal( button, index, id );
347 button->setEnabled( enabled );
348 button->setPopup( popup );
349 doConnections( button );
350 return index;
351}
352
353
354int KToolBar::insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup,
355 bool enabled, const QString &text, int index )
356{
357 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text );
358 insertWidgetInternal( button, index, id );
359 button->setEnabled( enabled );
360 button->setPopup( popup );
361 doConnections( button );
362 return index;
363}
364
365
366int KToolBar::insertLined (const QString& text, int id,
367 const char *signal,
368 const QObject *receiver, const char *slot,
369 bool enabled ,
370 const QString& toolTipText,
371 int size, int index )
372{
373 KLineEdit *lined = new KLineEdit ( this, 0 );
374 if ( !toolTipText.isEmpty() )
375 QToolTip::add( lined, toolTipText );
376 if ( size > 0 )
377 lined->setMinimumWidth( size );
378 insertWidgetInternal( lined, index, id );
379 connect( lined, signal, receiver, slot );
380 lined->setText(text);
381 lined->setEnabled( enabled );
382 return index;
383}
384
385int KToolBar::insertCombo (const QStringList &list, int id, bool writable,
386 const char *signal, const QObject *receiver,
387 const char *slot, bool enabled,
388 const QString& tooltiptext,
389 int size, int index,
390 QComboBox::Policy policy )
391{
392//US KComboBox *combo = new KComboBox ( writable, this );
393 KComboBox *combo = new KComboBox ( this );
394 combo->setEditable(writable);
395
396 insertWidgetInternal( combo, index, id );
397 combo->insertStringList (list);
398 combo->setInsertionPolicy(policy);
399 combo->setEnabled( enabled );
400 if ( !tooltiptext.isEmpty() )
401 QToolTip::add( combo, tooltiptext );
402 if ( size > 0 )
403 combo->setMinimumWidth( size );
404 if (!tooltiptext.isNull())
405 QToolTip::add( combo, tooltiptext );
406
407 if ( signal && receiver && slot )
408 connect ( combo, signal, receiver, slot );
409 return index;
410}
411
412
413int KToolBar::insertCombo (const QString& text, int id, bool writable,
414 const char *signal, QObject *receiver,
415 const char *slot, bool enabled,
416 const QString& tooltiptext,
417 int size, int index,
418 QComboBox::Policy policy )
419{
420//US KComboBox *combo = new KComboBox ( writable, this );
421 KComboBox *combo = new KComboBox ( this );
422 combo->setEditable(writable);
423
424 insertWidgetInternal( combo, index, id );
425 combo->insertItem (text);
426 combo->setInsertionPolicy(policy);
427 combo->setEnabled( enabled );
428 if ( !tooltiptext.isEmpty() )
429 QToolTip::add( combo, tooltiptext );
430 if ( size > 0 )
431 combo->setMinimumWidth( size );
432 if (!tooltiptext.isNull())
433 QToolTip::add( combo, tooltiptext );
434 connect (combo, signal, receiver, slot);
435 return index;
436}
437
438int KToolBar::insertSeparator(int index, int id)
439{
440 QWidget *w = new KToolBarSeparator( orientation(), FALSE, this, "tool bar separator" );
441 insertWidgetInternal( w, index, id );
442 return index;
443}
444
445int KToolBar::insertLineSeparator(int index, int id)
446{
447 QWidget *w = new KToolBarSeparator( orientation(), TRUE, this, "tool bar separator" );
448 insertWidgetInternal( w, index, id );
449 return index;
450}
451
452
453int KToolBar::insertWidget(int id, int /*width*/, QWidget *widget, int index)
454{
455 // removeWidgetInternal( widget ); // in case we already have it ?
456 insertWidgetInternal( widget, index, id );
457 return index;
458}
459/*US
460int KToolBar::insertAnimatedWidget(int id, QObject *receiver, const char *slot,
461 const QString& icons, int index )
462{
463 KAnimWidget *anim = new KAnimWidget( icons, d->m_iconSize, this );
464 insertWidgetInternal( anim, index, id );
465
466 if ( receiver )
467 connect( anim, SIGNAL(clicked()), receiver, slot);
468
469 return index;
470}
471
472KAnimWidget *KToolBar::animatedWidget( int id )
473{
474 Id2WidgetMap::Iterator it = id2widget.find( id );
475 if ( it == id2widget.end() )
476 return 0;
477 if ( (*it) && (*it)->inherits( "KAnimWidget" ) )
478 return (KAnimWidget*)(*it);
479 QObjectList *l = queryList( "KAnimWidget" );
480 if ( !l || !l->first() ) {
481 delete l;
482 return 0;
483 }
484
485 for ( QObject *o = l->first(); o; o = l->next() ) {
486 if ( o->inherits( "KAnimWidget" ) )
487 {
488 delete l;
489 return (KAnimWidget*)o;
490 }
491 }
492
493 delete l;
494 return 0;
495}
496*/
497
498void KToolBar::addConnection (int id, const char *signal,
499 const QObject *receiver, const char *slot)
500{
501 Id2WidgetMap::Iterator it = id2widget.find( id );
502 if ( it == id2widget.end() )
503 return;
504 if ( (*it) )
505 connect( (*it), signal, receiver, slot );
506}
507
508void KToolBar::setItemEnabled( int id, bool enabled )
509{
510 Id2WidgetMap::Iterator it = id2widget.find( id );
511 if ( it == id2widget.end() )
512 return;
513 if ( (*it) )
514 (*it)->setEnabled( enabled );
515}
516
517
518void KToolBar::setButtonPixmap( int id, const QPixmap& _pixmap )
519{
520 Id2WidgetMap::Iterator it = id2widget.find( id );
521 if ( it == id2widget.end() )
522 return;
523//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
524 KToolBarButton * button = (KToolBarButton *)( *it );
525 if ( button )
526 button->setPixmap( _pixmap );
527}
528
529
530void KToolBar::setButtonIcon( int id, const QString& _icon )
531{
532 Id2WidgetMap::Iterator it = id2widget.find( id );
533 if ( it == id2widget.end() )
534 return;
535//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
536 KToolBarButton * button = (KToolBarButton *)( *it );
537 if ( button )
538 button->setIcon( _icon );
539}
540
541void KToolBar::setButtonIconSet( int id, const QIconSet& iconset )
542{
543 Id2WidgetMap::Iterator it = id2widget.find( id );
544 if ( it == id2widget.end() )
545 return;
546//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
547 KToolBarButton * button = (KToolBarButton *)( *it );
548 if ( button )
549 button->setIconSet( iconset );
550}
551
552
553void KToolBar::setDelayedPopup (int id , QPopupMenu *_popup, bool toggle )
554{
555 Id2WidgetMap::Iterator it = id2widget.find( id );
556 if ( it == id2widget.end() )
557 return;
558//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
559 KToolBarButton * button = (KToolBarButton *)( *it );
560 if ( button )
561 button->setDelayedPopup( _popup, toggle );
562}
563
564
565void KToolBar::setAutoRepeat (int id, bool flag)
566{
567 Id2WidgetMap::Iterator it = id2widget.find( id );
568 if ( it == id2widget.end() )
569 return;
570//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
571 KToolBarButton * button = (KToolBarButton *)( *it );
572 if ( button )
573 button->setAutoRepeat( flag );
574}
575
576
577void KToolBar::setToggle (int id, bool flag )
578{
579 Id2WidgetMap::Iterator it = id2widget.find( id );
580 if ( it == id2widget.end() )
581 return;
582//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
583 KToolBarButton * button = (KToolBarButton *)( *it );
584 if ( button )
585 button->setToggle( flag );
586}
587
588
589void KToolBar::toggleButton (int id)
590{
591 Id2WidgetMap::Iterator it = id2widget.find( id );
592 if ( it == id2widget.end() )
593 return;
594//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
595 KToolBarButton * button = (KToolBarButton *)( *it );
596 if ( button )
597 button->toggle();
598}
599
600
601void KToolBar::setButton (int id, bool flag)
602{
603 Id2WidgetMap::Iterator it = id2widget.find( id );
604 if ( it == id2widget.end() )
605 return;
606//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
607 KToolBarButton * button = (KToolBarButton *)( *it );
608 if ( button )
609 button->on( flag );
610}
611
612
613bool KToolBar::isButtonOn (int id) const
614{
615 Id2WidgetMap::ConstIterator it = id2widget.find( id );
616 if ( it == id2widget.end() )
617 return false;
618//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
619 KToolBarButton * button = (KToolBarButton *)( *it );
620 return button ? button->isOn() : false;
621}
622
623
624void KToolBar::setLinedText (int id, const QString& text)
625{
626 Id2WidgetMap::Iterator it = id2widget.find( id );
627 if ( it == id2widget.end() )
628 return;
629//US QLineEdit * lineEdit = dynamic_cast<QLineEdit *>( *it );
630 QLineEdit * lineEdit = (QLineEdit *)( *it );
631 if ( lineEdit )
632 lineEdit->setText( text );
633}
634
635
636QString KToolBar::getLinedText (int id) const
637{
638 Id2WidgetMap::ConstIterator it = id2widget.find( id );
639 if ( it == id2widget.end() )
640 return QString::null;
641//US QLineEdit * lineEdit = dynamic_cast<QLineEdit *>( *it );
642 QLineEdit * lineEdit = (QLineEdit *)( *it );
643 return lineEdit ? lineEdit->text() : QString::null;
644}
645
646
647void KToolBar::insertComboItem (int id, const QString& text, int index)
648{
649 Id2WidgetMap::Iterator it = id2widget.find( id );
650 if ( it == id2widget.end() )
651 return;
652//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
653 QComboBox * comboBox = (QComboBox *)( *it );
654 if (comboBox)
655 comboBox->insertItem( text, index );
656}
657
658void KToolBar::insertComboList (int id, const QStringList &list, int index)
659{
660 Id2WidgetMap::Iterator it = id2widget.find( id );
661 if ( it == id2widget.end() )
662 return;
663//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
664 QComboBox * comboBox = (QComboBox *)( *it );
665 if (comboBox)
666 comboBox->insertStringList( list, index );
667}
668
669
670void KToolBar::removeComboItem (int id, int index)
671{
672 Id2WidgetMap::Iterator it = id2widget.find( id );
673 if ( it == id2widget.end() )
674 return;
675//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
676 QComboBox * comboBox = (QComboBox *)( *it );
677 if (comboBox)
678 comboBox->removeItem( index );
679}
680
681
682void KToolBar::setCurrentComboItem (int id, int index)
683{
684 Id2WidgetMap::Iterator it = id2widget.find( id );
685 if ( it == id2widget.end() )
686 return;
687//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
688 QComboBox * comboBox = (QComboBox *)( *it );
689 if (comboBox)
690 comboBox->setCurrentItem( index );
691}
692
693
694void KToolBar::changeComboItem (int id, const QString& text, int index)
695{
696 Id2WidgetMap::Iterator it = id2widget.find( id );
697 if ( it == id2widget.end() )
698 return;
699//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
700 QComboBox * comboBox = (QComboBox *)( *it );
701 if (comboBox)
702 comboBox->changeItem( text, index );
703}
704
705
706void KToolBar::clearCombo (int id)
707{
708 Id2WidgetMap::Iterator it = id2widget.find( id );
709 if ( it == id2widget.end() )
710 return;
711//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
712 QComboBox * comboBox = (QComboBox *)( *it );
713 if (comboBox)
714 comboBox->clear();
715}
716
717
718QString KToolBar::getComboItem (int id, int index) const
719{
720 Id2WidgetMap::ConstIterator it = id2widget.find( id );
721 if ( it == id2widget.end() )
722 return QString::null;
723//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
724 QComboBox * comboBox = (QComboBox *)( *it );
725 return comboBox ? comboBox->text( index ) : QString::null;
726}
727
728
729KComboBox * KToolBar::getCombo(int id)
730{
731 Id2WidgetMap::Iterator it = id2widget.find( id );
732 if ( it == id2widget.end() )
733 return 0;
734//US return dynamic_cast<KComboBox *>( *it );
735 return (KComboBox *)( *it );
736}
737
738
739KLineEdit * KToolBar::getLined (int id)
740{
741 Id2WidgetMap::Iterator it = id2widget.find( id );
742 if ( it == id2widget.end() )
743 return 0;
744//US return dynamic_cast<KLineEdit *>( *it );
745 return (KLineEdit *)( *it );
746}
747
748
749KToolBarButton * KToolBar::getButton (int id)
750{
751 Id2WidgetMap::Iterator it = id2widget.find( id );
752 if ( it == id2widget.end() )
753 return 0;
754//US return dynamic_cast<KToolBarButton *>( *it );
755 return (KToolBarButton *)( *it );
756}
757
758
759void KToolBar::alignItemRight (int id, bool right )
760{
761 Id2WidgetMap::Iterator it = id2widget.find( id );
762 if ( it == id2widget.end() )
763 return;
764 if ( rightAligned && !right && (*it) == rightAligned )
765 rightAligned = 0;
766 if ( (*it) && right )
767 rightAligned = (*it);
768}
769
770
771QWidget *KToolBar::getWidget (int id)
772{
773 Id2WidgetMap::Iterator it = id2widget.find( id );
774 return ( it == id2widget.end() ) ? 0 : (*it);
775}
776
777
778void KToolBar::setItemAutoSized (int id, bool yes )
779{
780 QWidget *w = getWidget(id);
781 if ( w && yes )
782 setStretchableWidget( w );
783}
784
785
786void KToolBar::clear ()
787{
788 QToolBar::clear();
789 widget2id.clear();
790 id2widget.clear();
791}
792
793
794void KToolBar::removeItem(int id)
795{
796 Id2WidgetMap::Iterator it = id2widget.find( id );
797 if ( it == id2widget.end() )
798 {
799 kdDebug(220) << "KToolBar::removeItem item " << id << " not found" << endl;
800 return;
801 }
802 QWidget * w = (*it);
803 id2widget.remove( id );
804 widget2id.remove( w );
805 widgets.removeRef( w );
806 delete w;
807}
808
809
810void KToolBar::removeItemDelayed(int id)
811{
812 Id2WidgetMap::Iterator it = id2widget.find( id );
813 if ( it == id2widget.end() )
814 {
815 kdDebug(220) << "KToolBar::removeItem item " << id << " not found" << endl;
816 return;
817 }
818 QWidget * w = (*it);
819 id2widget.remove( id );
820 widget2id.remove( w );
821 widgets.removeRef( w );
822
823 w->blockSignals(true);
824 d->idleButtons.append(w);
825 layoutTimer->start( 50, TRUE );
826}
827
828
829void KToolBar::hideItem (int id)
830{
831 QWidget *w = getWidget(id);
832 if ( w )
833 w->hide();
834}
835
836
837void KToolBar::showItem (int id)
838{
839 QWidget *w = getWidget(id);
840 if ( w )
841 w->show();
842}
843
844
845int KToolBar::itemIndex (int id)
846{
847 QWidget *w = getWidget(id);
848 return w ? widgets.findRef(w) : -1;
849}
850
851
852void KToolBar::setFullSize(bool flag )
853{
854 setHorizontalStretchable( flag );
855 setVerticalStretchable( flag );
856}
857
858
859bool KToolBar::fullSize() const
860{
861 return isHorizontalStretchable() || isVerticalStretchable();
862}
863
864
865void KToolBar::enableMoving(bool flag )
866{
867//US setMovingEnabled(flag);
868 this->mainWindow()->setToolBarsMovable(flag);
869}
870
871
872void KToolBar::setBarPos (BarPosition bpos)
873{
874 if ( !mainWindow() )
875 return;
876//US mainWindow()->moveDockWindow( this, (Dock)bpos );
877 mainWindow()->moveToolBar( this, (QMainWindow::ToolBarDock)bpos );
878}
879
880
881KToolBar::BarPosition KToolBar::barPos()
882{
883 if ( !(QMainWindow*)mainWindow() )
884 return KToolBar::Top;
885//US Dock dock;
886 QMainWindow::ToolBarDock dock;
887 int dm1, dm2;
888 bool dm3;
889 ((QMainWindow*)mainWindow())->getLocation( (QToolBar*)this, dock, dm1, dm3, dm2 );
890//US if ( dock == DockUnmanaged ) {
891 if ( dock == QMainWindow::Unmanaged ) {
892 return (KToolBar::BarPosition)Top;
893 }
894 return (BarPosition)dock;
895}
896
897
898bool KToolBar::enable(BarStatus stat)
899{
900 bool mystat = isVisible();
901
902 if ( (stat == Toggle && mystat) || stat == Hide )
903 hide();
904 else
905 show();
906
907 return isVisible() == mystat;
908}
909
910
911void KToolBar::setMaxHeight ( int h )
912{
913 setMaximumHeight( h );
914}
915
916int KToolBar::maxHeight()
917{
918 return maximumHeight();
919}
920
921
922void KToolBar::setMaxWidth (int dw)
923{
924 setMaximumWidth( dw );
925}
926
927
928int KToolBar::maxWidth()
929{
930 return maximumWidth();
931}
932
933
934void KToolBar::setTitle (const QString& _title)
935{
936 setLabel( _title );
937}
938
939
940void KToolBar::enableFloating (bool )
941{
942}
943
944
945void KToolBar::setIconText(IconText it)
946{
947 setIconText( it, true );
948}
949
950
951void KToolBar::setIconText(IconText icontext, bool update)
952{
953 bool doUpdate=false;
954
955 if (icontext != d->m_iconText) {
956 d->m_iconText = icontext;
957 doUpdate=true;
958 }
959
960 if (update == false)
961 return;
962
963 if (doUpdate)
964 emit modechange(); // tell buttons what happened
965
966 // ugly hack to force a QMainWindow::triggerLayout( TRUE )
967 if ( mainWindow() ) {
968 QMainWindow *mw = mainWindow();
969 mw->setUpdatesEnabled( FALSE );
970 mw->setToolBarsMovable( !mw->toolBarsMovable() );
971 mw->setToolBarsMovable( !mw->toolBarsMovable() );
972 mw->setUpdatesEnabled( TRUE );
973 }
974}
975
976
977KToolBar::IconText KToolBar::iconText() const
978{
979 return d->m_iconText;
980}
981
982
983void KToolBar::setIconSize(int size)
984{
985 setIconSize( size, true );
986}
987
988void KToolBar::setIconSize(int size, bool update)
989{
990 bool doUpdate=false;
991
992 if ( size != d->m_iconSize ) {
993 d->m_iconSize = size;
994 doUpdate=true;
995 }
996
997 if (update == false)
998 return;
999
1000 if (doUpdate)
1001 emit modechange(); // tell buttons what happened
1002
1003 // ugly hack to force a QMainWindow::triggerLayout( TRUE )
1004 if ( mainWindow() ) {
1005 QMainWindow *mw = mainWindow();
1006 mw->setUpdatesEnabled( FALSE );
1007 mw->setToolBarsMovable( !mw->toolBarsMovable() );
1008 mw->setToolBarsMovable( !mw->toolBarsMovable() );
1009 mw->setUpdatesEnabled( TRUE );
1010 }
1011}
1012
1013
1014int KToolBar::iconSize() const
1015{
1016/*US
1017 if ( !d->m_iconSize ) // default value?
1018 {
1019 if (!::qstrcmp(QObject::name(), "mainToolBar"))
1020 return KGlobal::iconLoader()->currentSize(KIcon::MainToolbar);
1021 else
1022 return KGlobal::iconLoader()->currentSize(KIcon::Toolbar);
1023 }
1024 return d->m_iconSize;
1025*/
1026 int ret = 18;
1027 if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 )
1028 ret = 30;
1029 return ret;
1030}
1031
1032
1033void KToolBar::setEnableContextMenu(bool enable )
1034{
1035 d->m_enableContext = enable;
1036}
1037
1038
1039bool KToolBar::contextMenuEnabled() const
1040{
1041 return d->m_enableContext;
1042}
1043
1044
1045void KToolBar::setItemNoStyle(int id, bool no_style )
1046{
1047 Id2WidgetMap::Iterator it = id2widget.find( id );
1048 if ( it == id2widget.end() )
1049 return;
1050//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
1051 KToolBarButton * button = (KToolBarButton *)( *it );
1052 if (button)
1053 button->setNoStyle( no_style );
1054}
1055
1056
1057void KToolBar::setFlat (bool flag)
1058{
1059 if ( !mainWindow() )
1060 return;
1061 if ( flag )
1062//US mainWindow()->moveDockWindow( this, DockMinimized );
1063 mainWindow()->moveToolBar( this, QMainWindow::Minimized );
1064 else
1065//US mainWindow()->moveDockWindow( this, DockTop );
1066 mainWindow()->moveToolBar( this, QMainWindow::Top );
1067 // And remember to save the new look later
1068/*US
1069 if ( mainWindow()->inherits( "KMainWindow" ) )
1070 static_cast<KMainWindow *>(mainWindow())->setSettingsDirty();
1071*/
1072}
1073
1074
1075int KToolBar::count() const
1076{
1077 return id2widget.count();
1078}
1079
1080
1081void KToolBar::saveState()
1082{
1083/*US
1084 // first, try to save to the xml file
1085 if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() ) {
1086 // go down one level to get to the right tags
1087 QDomElement elem = d->m_xmlguiClient->domDocument().documentElement().toElement();
1088 elem = elem.firstChild().toElement();
1089 QString barname(!::qstrcmp(name(), "unnamed") ? "mainToolBar" : name());
1090 QDomElement current;
1091 // now try to find our toolbar
1092 d->modified = false;
1093 for( ; !elem.isNull(); elem = elem.nextSibling().toElement() ) {
1094 current = elem;
1095
1096 if ( current.tagName().lower() != "toolbar" )
1097 continue;
1098
1099 QString curname(current.attribute( "name" ));
1100
1101 if ( curname == barname ) {
1102 saveState( current );
1103 break;
1104 }
1105 }
1106 // if we didn't make changes, then just return
1107 if ( !d->modified )
1108 return;
1109
1110 // now we load in the (non-merged) local file
1111 QString local_xml(KXMLGUIFactory::readConfigFile(d->m_xmlguiClient->xmlFile(), true, d->m_xmlguiClient->instance()));
1112 QDomDocument local;
1113 local.setContent(local_xml);
1114
1115 // make sure we don't append if this toolbar already exists locally
1116 bool just_append = true;
1117 elem = local.documentElement().toElement();
1118 KXMLGUIFactory::removeDOMComments( elem );
1119 elem = elem.firstChild().toElement();
1120 for( ; !elem.isNull(); elem = elem.nextSibling().toElement() ) {
1121 if ( elem.tagName().lower() != "toolbar" )
1122 continue;
1123
1124 QString curname(elem.attribute( "name" ));
1125
1126 if ( curname == barname ) {
1127 just_append = false;
1128 local.documentElement().replaceChild( current, elem );
1129 break;
1130 }
1131 }
1132
1133 if (just_append)
1134 local.documentElement().appendChild( current );
1135
1136 KXMLGUIFactory::saveConfigFile(local, d->m_xmlguiClient->localXMLFile(), d->m_xmlguiClient->instance() );
1137
1138 return;
1139 }
1140*/
1141 // if that didn't work, we save to the config file
1142 KConfig *config = KGlobal::config();
1143 saveSettings(config, QString::null);
1144 config->sync();
1145}
1146
1147QString KToolBar::settingsGroup()
1148{
1149 QString configGroup;
1150 if (!::qstrcmp(name(), "unnamed") || !::qstrcmp(name(), "mainToolBar"))
1151 configGroup = "Toolbar style";
1152 else
1153 configGroup = QString(name()) + " Toolbar style";
1154 if ( this->mainWindow() )
1155 {
1156 configGroup.prepend(" ");
1157 configGroup.prepend( this->mainWindow()->name() );
1158 }
1159 return configGroup;
1160}
1161
1162void KToolBar::saveSettings(KConfig *config, const QString &_configGroup)
1163{
1164 QString configGroup = _configGroup;
1165 if (configGroup.isEmpty())
1166 configGroup = settingsGroup();
1167 //kdDebug(220) << "KToolBar::saveSettings group=" << _configGroup << " -> " << configGroup << endl;
1168
1169 QString position, icontext;
1170 int index;
1171 getAttributes( position, icontext, index );
1172
1173 //kdDebug(220) << "KToolBar::saveSettings " << name() << " newLine=" << newLine << endl;
1174
1175 KConfigGroupSaver saver(config, configGroup);
1176
1177 if ( position != d->PositionDefault )
1178 config->writeEntry("Position", position);
1179 else
1180 config->deleteEntry("Position");
1181
1182 if ( icontext != d->IconTextDefault )
1183 config->writeEntry("IconText", icontext);
1184 else
1185 config->deleteEntry("IconText");
1186
1187 if ( iconSize() != d->IconSizeDefault )
1188 config->writeEntry("IconSize", iconSize());
1189 else
1190 config->deleteEntry("IconSize");
1191
1192 if ( isHidden() != d->HiddenDefault )
1193 config->writeEntry("Hidden", isHidden());
1194 else
1195 config->deleteEntry("Hidden");
1196
1197 if ( index != d->IndexDefault )
1198 config->writeEntry( "Index", index );
1199 else
1200 config->deleteEntry("Index");
1201//US the older version of KDE (used on the Zaurus) has no Offset property
1202/* if ( offset() != d->OffsetDefault )
1203 config->writeEntry( "Offset", offset() );
1204 else
1205*/
1206 config->deleteEntry("Offset");
1207
1208//US the older version of KDE (used on the Zaurus) has no NewLine property
1209/*
1210 if ( newLine() != d->NewLineDefault )
1211 config->writeEntry( "NewLine", newLine() );
1212 else
1213*/
1214 config->deleteEntry("NewLine");
1215}
1216
1217void KToolBar::setXMLGUIClient( KXMLGUIClient *client )
1218{
1219 d->m_xmlguiClient = client;
1220}
1221
1222void KToolBar::setText( const QString & txt )
1223{
1224//US setLabel( txt + " ( " + kapp->caption() + " ) " );
1225 setLabel( txt + " ( " + KGlobal::getAppName() + " ) " );
1226}
1227
1228
1229QString KToolBar::text() const
1230{
1231 return label();
1232}
1233
1234
1235void KToolBar::doConnections( KToolBarButton *button )
1236{
1237 connect(button, SIGNAL(clicked(int)), this, SIGNAL( clicked( int ) ) );
1238 connect(button, SIGNAL(doubleClicked(int)), this, SIGNAL( doubleClicked( int ) ) );
1239 connect(button, SIGNAL(released(int)), this, SIGNAL( released( int ) ) );
1240 connect(button, SIGNAL(pressed(int)), this, SIGNAL( pressed( int ) ) );
1241 connect(button, SIGNAL(toggled(int)), this, SIGNAL( toggled( int ) ) );
1242 connect(button, SIGNAL(highlighted(int, bool)), this, SIGNAL( highlighted( int, bool ) ) );
1243}
1244
1245void KToolBar::mousePressEvent ( QMouseEvent *m )
1246{
1247 if ( !mainWindow() )
1248 return;
1249 QMainWindow *mw = mainWindow();
1250 if ( mw->toolBarsMovable() && d->m_enableContext ) {
1251 if ( m->button() == RightButton ) {
1252 int i = contextMenu()->exec( m->globalPos(), 0 );
1253 switch ( i ) {
1254 case -1:
1255 return; // popup cancelled
1256 case CONTEXT_LEFT:
1257//US mw->moveDockWindow( this, DockLeft );
1258 mw->moveToolBar( this, QMainWindow::Left );
1259 break;
1260 case CONTEXT_RIGHT:
1261//US mw->moveDockWindow( this, DockRight );
1262 mw->moveToolBar( this, QMainWindow::Right );
1263 break;
1264 case CONTEXT_TOP:
1265//US mw->moveDockWindow( this, DockTop );
1266 mw->moveToolBar( this, QMainWindow::Top );
1267 break;
1268 case CONTEXT_BOTTOM:
1269//US mw->moveDockWindow( this, DockBottom );
1270 mw->moveToolBar( this, QMainWindow::Bottom );
1271 break;
1272 case CONTEXT_FLOAT:
1273 break;
1274 case CONTEXT_FLAT:
1275//US mw->moveDockWindow( this, DockMinimized );
1276 mw->moveToolBar( this, QMainWindow::Minimized );
1277 break;
1278 case CONTEXT_ICONS:
1279 setIconText( IconOnly );
1280 break;
1281 case CONTEXT_TEXTRIGHT:
1282 setIconText( IconTextRight );
1283 break;
1284 case CONTEXT_TEXT:
1285 setIconText( TextOnly );
1286 break;
1287 case CONTEXT_TEXTUNDER:
1288 setIconText( IconTextBottom );
1289 break;
1290 default:
1291 if ( i >= CONTEXT_ICONSIZES )
1292 setIconSize( i - CONTEXT_ICONSIZES );
1293 else
1294 return; // assume this was an action handled elsewhere, no need for setSettingsDirty()
1295 }
1296/*US
1297 if ( mw->inherits("KMainWindow") )
1298 static_cast<KMainWindow *>(mw)->setSettingsDirty();
1299*/
1300 }
1301 }
1302}
1303
1304
1305void KToolBar::rebuildLayout()
1306{
1307
1308 for(QWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next())
1309 w->blockSignals(false);
1310 d->idleButtons.clear();
1311
1312 layoutTimer->stop();
1313 QApplication::sendPostedEvents( this, QEvent::ChildInserted );
1314 QBoxLayout *l = boxLayout();
1315 l->setMargin( 1 );
1316 // clear the old layout
1317 QLayoutIterator it = l->iterator();
1318
1319 while ( it.current() ) {
1320 it.deleteCurrent();
1321 }
1322 for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {
1323 if ( w == rightAligned ) {
1324 continue;
1325 }
1326 if ( w->inherits( "KToolBarSeparator" ) &&
1327 !( (KToolBarSeparator*)w )->showLine() ) {
1328 l->addSpacing( 6 );
1329 w->hide();
1330 continue;
1331 }
1332 if ( w->inherits( "QPopupMenu" ) )
1333 continue;
1334 l->addWidget( w );
1335 w->show();
1336 }
1337 if ( rightAligned ) {
1338 l->addStretch();
1339 l->addWidget( rightAligned );
1340 rightAligned->show();
1341 }
1342
1343 if ( fullSize() ) {
1344 // This code sucks. It makes the last combo in a toolbar VERY big (e.g. zoom combo in kword).
1345 //if ( !stretchableWidget && widgets.last() &&
1346 // !widgets.last()->inherits( "QButton" ) && !widgets.last()->inherits( "KAnimWidget" ) )
1347 // setStretchableWidget( widgets.last() );
1348 if ( !rightAligned )
1349 l->addStretch();
1350 if ( stretchableWidget )
1351 l->setStretchFactor( stretchableWidget, 10 );
1352 }
1353 l->invalidate();
1354 QApplication::postEvent( this, new QEvent( QEvent::LayoutHint ) );
1355 //#endif //DESKTOP_VERSION
1356}
1357
1358void KToolBar::childEvent( QChildEvent *e )
1359{
1360
1361 if ( e->child()->isWidgetType() ) {
1362 QWidget * w = (QWidget*)e->child();
1363 if ( e->type() == QEvent::ChildInserted ) {
1364 if ( !e->child()->inherits( "QPopupMenu" ) &&
1365 ::qstrcmp( "qt_dockwidget_internal", e->child()->name() ) != 0 ) {
1366
1367 // prevent items that have been explicitly inserted by insert*() from
1368 // being inserted again
1369 if ( !widget2id.contains( w ) )
1370 {
1371 int dummy = -1;
1372 insertWidgetInternal( w, dummy, -1 );
1373 }
1374 }
1375 } else {
1376 removeWidgetInternal( w );
1377 }
1378 if ( isVisibleTo( 0 ) )
1379 {
1380 QBoxLayout *l = boxLayout();
1381 // QLayout *l = layout();
1382
1383 // clear the old layout so that we don't get unnecassery layout
1384 // changes till we have rebuild the thing
1385 QLayoutIterator it = l->iterator();
1386 while ( it.current() ) {
1387 it.deleteCurrent();
1388 }
1389 layoutTimer->start( 50, TRUE );
1390 }
1391 }
1392 QToolBar::childEvent( e );
1393}
1394
1395void KToolBar::insertWidgetInternal( QWidget *w, int &index, int id )
1396{
1397 // we can't have it in widgets, or something is really wrong
1398 //widgets.removeRef( w );
1399
1400 connect( w, SIGNAL( destroyed() ),
1401 this, SLOT( widgetDestroyed() ) );
1402 if ( index == -1 || index > (int)widgets.count() ) {
1403 widgets.append( w );
1404 index = (int)widgets.count();
1405 }
1406 else
1407 widgets.insert( index, w );
1408 if ( id == -1 )
1409 id = id2widget.count();
1410 id2widget.insert( id, w );
1411 widget2id.insert( w, id );
1412}
1413
1414void KToolBar::showEvent( QShowEvent *e )
1415{
1416 QToolBar::showEvent( e );
1417 rebuildLayout();
1418}
1419
1420void KToolBar::setStretchableWidget( QWidget *w )
1421{
1422 QToolBar::setStretchableWidget( w );
1423 stretchableWidget = w;
1424}
1425
1426QSizePolicy KToolBar::sizePolicy() const
1427{
1428 if ( orientation() == Horizontal )
1429 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
1430 else
1431 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding );
1432}
1433
1434QSize KToolBar::sizeHint() const
1435{
1436 return QToolBar::sizeHint();
1437#if 0
1438 QWidget::polish();
1439 static int iii = 0;
1440 ++iii;
1441 qDebug("++++++++ KToolBar::sizeHint() %d ", iii );
1442 int margin = static_cast<QWidget*>(ncThis)->layout()->margin();
1443 switch( barPos() )
1444 {
1445 case KToolBar::Top:
1446 case KToolBar::Bottom:
1447 for ( QWidget *w = widgets.first(); w; w =widgets.next() )
1448 {
1449 if ( w->inherits( "KToolBarSeparator" ) &&
1450 !( static_cast<KToolBarSeparator*>(w)->showLine() ) )
1451 {
1452 minSize += QSize(6, 0);
1453 }
1454 else
1455 {
1456 QSize sh = w->sizeHint();
1457 if (!sh.isValid())
1458 sh = w->minimumSize();
1459 minSize = minSize.expandedTo(QSize(0, sh.height()));
1460 minSize += QSize(sh.width()+1, 0);
1461 }
1462 }
1463/*US
1464 minSize += QSize(QApplication::style().pixelMetric( QStyle::PM_DockWindowHandleExtent ), 0);
1465*/
1466 minSize += QSize(margin*2, margin*2);
1467 break;
1468
1469 case KToolBar::Left:
1470 case KToolBar::Right:
1471 for ( QWidget *w = widgets.first(); w; w = widgets.next() )
1472 {
1473 if ( w->inherits( "KToolBarSeparator" ) &&
1474 !( static_cast<KToolBarSeparator*>(w)->showLine() ) )
1475 {
1476 minSize += QSize(0, 6);
1477 }
1478 else
1479 {
1480 QSize sh = w->sizeHint();
1481 if (!sh.isValid())
1482 sh = w->minimumSize();
1483 minSize = minSize.expandedTo(QSize(sh.width(), 0));
1484 minSize += QSize(0, sh.height()+1);
1485 }
1486 }
1487/*US
1488 minSize += QSize(0, QApplication::style().pixelMetric( QStyle::PM_DockWindowHandleExtent ));
1489*/
1490 minSize += QSize(margin*2, margin*2);
1491 break;
1492
1493 default:
1494 minSize = QToolBar::sizeHint();
1495 break;
1496 }
1497 return minSize;
1498#endif
1499}
1500
1501QSize KToolBar::minimumSize() const
1502{
1503 return minimumSizeHint();
1504}
1505
1506QSize KToolBar::minimumSizeHint() const
1507{
1508 return sizeHint();
1509}
1510
1511bool KToolBar::highlight() const
1512{
1513 return d->m_highlight;
1514}
1515
1516void KToolBar::hide()
1517{
1518 QToolBar::hide();
1519}
1520
1521void KToolBar::show()
1522{
1523 QToolBar::show();
1524}
1525
1526void KToolBar::resizeEvent( QResizeEvent *e )
1527{
1528 bool b = isUpdatesEnabled();
1529 setUpdatesEnabled( FALSE );
1530 QToolBar::resizeEvent( e );
1531 if (b)
1532 d->repaintTimer.start( 100, true );
1533}
1534
1535void KToolBar::slotIconChanged(int group)
1536{
1537 if ((group != KIcon::Toolbar) && (group != KIcon::MainToolbar))
1538 return;
1539 if ((group == KIcon::MainToolbar) != !::qstrcmp(name(), "mainToolBar"))
1540 return;
1541
1542 emit modechange();
1543 if (isVisible())
1544 updateGeometry();
1545}
1546
1547void KToolBar::slotReadConfig()
1548{
1549 //kdDebug(220) << "KToolBar::slotReadConfig" << endl;
1550 // Read appearance settings (hmm, we used to do both here,
1551 // but a well behaved application will call applyMainWindowSettings
1552 // anyway, right ?)
1553 applyAppearanceSettings(KGlobal::config(), QString::null );
1554}
1555
1556void KToolBar::slotAppearanceChanged()
1557{
1558 // Read appearance settings from global file.
1559 applyAppearanceSettings(KGlobal::config(), QString::null, true /* lose local settings */ );
1560 // And remember to save the new look later
1561/*US
1562 if ( mainWindow() && mainWindow()->inherits( "KMainWindow" ) )
1563 static_cast<KMainWindow *>(mainWindow())->setSettingsDirty();
1564*/
1565}
1566
1567//static
1568bool KToolBar::highlightSetting()
1569{
1570 QString grpToolbar(QString::fromLatin1("Toolbar style"));
1571 KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
1572 return KGlobal::config()->readBoolEntry(QString::fromLatin1("Highlighting"),true);
1573}
1574
1575//static
1576bool KToolBar::transparentSetting()
1577{
1578 QString grpToolbar(QString::fromLatin1("Toolbar style"));
1579 KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
1580 return KGlobal::config()->readBoolEntry(QString::fromLatin1("TransparentMoving"),true);
1581}
1582
1583//static
1584KToolBar::IconText KToolBar::iconTextSetting()
1585{
1586 QString grpToolbar(QString::fromLatin1("Toolbar style"));
1587 KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
1588 QString icontext = KGlobal::config()->readEntry(QString::fromLatin1("IconText"),QString::fromLatin1("IconOnly"));
1589 if ( icontext == "IconTextRight" )
1590 return IconTextRight;
1591 else if ( icontext == "IconTextBottom" )
1592 return IconTextBottom;
1593 else if ( icontext == "TextOnly" )
1594 return TextOnly;
1595 else
1596 return IconOnly;
1597}
1598
1599void KToolBar::applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal)
1600{
1601 QString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
1602 //kdDebug(220) << "KToolBar::applyAppearanceSettings: configGroup=" << configGroup << endl;
1603 // We have application-specific settings in the XML file,
1604 // and nothing in the application's config file
1605 // -> don't apply the global defaults, the XML ones are preferred
1606 // See applySettings for a full explanation
1607/*US :we do not support xml files
1608 if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() &&
1609 !config->hasGroup(configGroup) )
1610 {
1611 //kdDebug(220) << "skipping global defaults, using XML ones instead" << endl;
1612 return;
1613 }
1614*/
1615 if ( !config->hasGroup(configGroup) )
1616 {
1617 //kdDebug(220) << "skipping global defaults, using XML ones instead" << endl;
1618 return;
1619 }
1620
1621
1622 KConfig *gconfig = KGlobal::config();
1623/*US
1624 static const QString &attrIconText = KGlobal::staticQString("IconText");
1625 static const QString &attrHighlight = KGlobal::staticQString("Highlighting");
1626 static const QString &attrTrans = KGlobal::staticQString("TransparentMoving");
1627 static const QString &attrSize = KGlobal::staticQString("IconSize");
1628*/
1629 // we actually do this in two steps.
1630 // First, we read in the global styles [Toolbar style] (from the KControl module).
1631 // Then, if the toolbar is NOT 'mainToolBar', we will also try to read in [barname Toolbar style]
1632 bool highlight;
1633 int transparent;
1634 QString icontext;
1635 int iconsize = 0;
1636
1637 // this is the first iteration
1638 QString grpToolbar(QString::fromLatin1("Toolbar style"));
1639 { // start block for KConfigGroupSaver
1640 KConfigGroupSaver saver(gconfig, grpToolbar);
1641
1642 // first, get the generic settings
1643//US highlight = gconfig->readBoolEntry(attrHighlight, true);
1644 highlight = gconfig->readBoolEntry("Highlighting", true);
1645//US transparent = gconfig->readBoolEntry(attrTrans, true);
1646 transparent = gconfig->readBoolEntry("TransparentMoving", true);
1647
1648 // we read in the IconText property *only* if we intend on actually
1649 // honoring it
1650 if (d->m_honorStyle)
1651//US d->IconTextDefault = gconfig->readEntry(attrIconText, d->IconTextDefault);
1652 d->IconTextDefault = gconfig->readEntry("IconText", d->IconTextDefault);
1653 else
1654 d->IconTextDefault = "IconOnly";
1655
1656 // Use the default icon size for toolbar icons.
1657//US d->IconSizeDefault = gconfig->readNumEntry(attrSize, d->IconSizeDefault);
1658 d->IconSizeDefault = gconfig->readNumEntry("IconSize", d->IconSizeDefault);
1659
1660 if ( !forceGlobal && config->hasGroup(configGroup) )
1661 {
1662 config->setGroup(configGroup);
1663
1664 // first, get the generic settings
1665//US highlight = config->readBoolEntry(attrHighlight, highlight);
1666 highlight = config->readBoolEntry("Highlighting", highlight);
1667//US transparent = config->readBoolEntry(attrTrans, transparent);
1668 transparent = config->readBoolEntry("TransparentMoving", transparent);
1669 // now we always read in the IconText property
1670//US icontext = config->readEntry(attrIconText, d->IconTextDefault);
1671 icontext = config->readEntry("IconText", d->IconTextDefault);
1672
1673 // now get the size
1674//US iconsize = config->readNumEntry(attrSize, d->IconSizeDefault);
1675 iconsize = config->readNumEntry("IconSize", d->IconSizeDefault);
1676 }
1677 else
1678 {
1679 iconsize = d->IconSizeDefault;
1680 icontext = d->IconTextDefault;
1681 }
1682
1683 // revert back to the old group
1684 } // end block for KConfigGroupSaver
1685
1686 bool doUpdate = false;
1687
1688 IconText icon_text;
1689 if ( icontext == "IconTextRight" )
1690 icon_text = IconTextRight;
1691 else if ( icontext == "IconTextBottom" )
1692 icon_text = IconTextBottom;
1693 else if ( icontext == "TextOnly" )
1694 icon_text = TextOnly;
1695 else
1696 icon_text = IconOnly;
1697
1698 // check if the icon/text has changed
1699 if (icon_text != d->m_iconText) {
1700 //kdDebug(220) << "KToolBar::applyAppearanceSettings setIconText " << icon_text << endl;
1701 setIconText(icon_text, false);
1702 doUpdate = true;
1703 }
1704
1705 // ...and check if the icon size has changed
1706 if (iconsize != d->m_iconSize) {
1707 setIconSize(iconsize, false);
1708 doUpdate = true;
1709 }
1710
1711 QMainWindow *mw = mainWindow();
1712
1713 // ...and if we should highlight
1714 if ( highlight != d->m_highlight ) {
1715 d->m_highlight = highlight;
1716 doUpdate = true;
1717 }
1718
1719 // ...and if we should move transparently
1720 if ( mw && transparent != (!mw->opaqueMoving()) ) {
1721 mw->setOpaqueMoving( !transparent );
1722 }
1723
1724 if (doUpdate)
1725 emit modechange(); // tell buttons what happened
1726 if (isVisible ())
1727 updateGeometry();
1728}
1729
1730void KToolBar::applySettings(KConfig *config, const QString &_configGroup)
1731{
1732 //kdDebug(220) << "KToolBar::applySettings group=" << _configGroup << endl;
1733
1734 QString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
1735
1736 /*
1737 Let's explain this a bit more in details.
1738 The order in which we apply settings is :
1739 Global config / <appnamerc> user settings if no XMLGUI is used
1740 Global config / App-XML attributes / <appnamerc> user settings if XMLGUI is used
1741
1742 So in the first case, we simply read everything from KConfig as below,
1743 but in the second case we don't do anything here if there is no app-specific config,
1744 and the XMLGUI uses the static methods of this class to get the global defaults.
1745
1746 Global config doesn't include position (index, offset, newline and hidden/shown).
1747 */
1748
1749 // First the appearance stuff - the one which has a global config
1750 applyAppearanceSettings( config, _configGroup );
1751
1752 // ...and now the position stuff
1753 if ( config->hasGroup(configGroup) )
1754 {
1755 KConfigGroupSaver cgs(config, configGroup);
1756/*US
1757 static const QString &attrPosition = KGlobal::staticQString("Position");
1758 static const QString &attrIndex = KGlobal::staticQString("Index");
1759 static const QString &attrOffset = KGlobal::staticQString("Offset");
1760 static const QString &attrNewLine = KGlobal::staticQString("NewLine");
1761 static const QString &attrHidden = KGlobal::staticQString("Hidden");
1762
1763 QString position = config->readEntry(attrPosition, d->PositionDefault);
1764 int index = config->readNumEntry(attrIndex, d->IndexDefault);
1765 int offset = config->readNumEntry(attrOffset, d->OffsetDefault);
1766 bool newLine = config->readBoolEntry(attrNewLine, d->NewLineDefault);
1767 bool hidden = config->readBoolEntry(attrHidden, d->HiddenDefault);
1768*/
1769
1770 QString position = config->readEntry("Position", d->PositionDefault);
1771 int index = config->readNumEntry("Index", d->IndexDefault);
1772 int offset = config->readNumEntry("Offset", d->OffsetDefault);
1773 bool newLine = config->readBoolEntry("NewLine", d->NewLineDefault);
1774 bool hidden = config->readBoolEntry("Hidden", d->HiddenDefault);
1775
1776/*US Dock pos(DockTop);
1777 if ( position == "Top" )
1778 pos = DockTop;
1779 else if ( position == "Bottom" )
1780 pos = DockBottom;
1781 else if ( position == "Left" )
1782 pos = DockLeft;
1783 else if ( position == "Right" )
1784 pos = DockRight;
1785 else if ( position == "Floating" )
1786 pos = DockTornOff;
1787 else if ( position == "Flat" )
1788 pos = DockMinimized;
1789*/
1790 QMainWindow::ToolBarDock pos(QMainWindow::Top);
1791 if ( position == "Top" )
1792 pos = QMainWindow::Top;
1793 else if ( position == "Bottom" )
1794 pos = QMainWindow::Bottom;
1795 else if ( position == "Left" )
1796 pos = QMainWindow::Left;
1797 else if ( position == "Right" )
1798 pos = QMainWindow::Right;
1799 else if ( position == "Floating" )
1800 pos = QMainWindow::TornOff;
1801 else if ( position == "Flat" )
1802 pos = QMainWindow::Minimized;
1803
1804 //kdDebug(220) << "KToolBar::applySettings hidden=" << hidden << endl;
1805 if (hidden)
1806 hide();
1807 else
1808 show();
1809
1810 if ( mainWindow() )
1811 {
1812 QMainWindow *mw = mainWindow();
1813
1814 //kdDebug(220) << "KToolBar::applySettings updating ToolbarInfo" << endl;
1815 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( pos, index, newLine, offset );
1816
1817 // moveDockWindow calls QDockArea which does a reparent() on us with
1818 // showIt = true, so we loose our visibility status
1819 bool doHide = isHidden();
1820
1821//US mw->moveDockWindow( this, pos, newLine, index, offset );
1822 mw->moveToolBar( this, pos, newLine, index, offset );
1823
1824 //kdDebug(220) << "KToolBar::applySettings " << name() << " moveDockWindow with pos=" << pos << " newLine=" << newLine << " idx=" << index << " offs=" << offset << endl;
1825 if ( doHide )
1826 hide();
1827 }
1828 if (isVisible ())
1829 updateGeometry();
1830 }
1831}
1832
1833bool KToolBar::event( QEvent *e )
1834{
1835 if ( (e->type() == QEvent::LayoutHint) && isUpdatesEnabled() )
1836 d->repaintTimer.start( 100, true );
1837
1838 if (e->type() == QEvent::ChildInserted )
1839 {
1840 // By pass QToolBar::event,
1841 // it will show() the inserted child and we don't want to
1842 // do that until we have rebuild the layout.
1843 childEvent((QChildEvent *)e);
1844 return true;
1845 }
1846
1847 return QToolBar::event( e );
1848}
1849
1850void KToolBar::slotRepaint()
1851{
1852 setUpdatesEnabled( FALSE );
1853 // Send a resizeEvent to update the "toolbar extension arrow"
1854 // (The button you get when your toolbar-items don't fit in
1855 // the available space)
1856 QResizeEvent ev(size(), size());
1857 resizeEvent(&ev);
1858 //#ifdef DESKTOP_VERSION
1859 QApplication::sendPostedEvents( this, QEvent::LayoutHint );
1860 //#endif //DESKTOP_VERSION
1861 setUpdatesEnabled( TRUE );
1862 repaint( TRUE );
1863}
1864
1865void KToolBar::toolBarPosChanged( QToolBar *tb )
1866{
1867 if ( tb != this )
1868 return;
1869//US if ( d->oldPos == DockMinimized )
1870 if ( d->oldPos == QMainWindow::Minimized )
1871 rebuildLayout();
1872 d->oldPos = (QMainWindow::ToolBarDock)barPos();
1873/*US
1874 if ( mainWindow() && mainWindow()->inherits( "KMainWindow" ) )
1875 static_cast<KMainWindow *>(mainWindow())->setSettingsDirty();
1876*/
1877}
1878
1879/*US
1880void KToolBar::loadState( const QDomElement &element )
1881{
1882 //kdDebug(220) << "KToolBar::loadState " << this << endl;
1883 if ( !mainWindow() )
1884 return;
1885
1886 {
1887 QCString text = element.namedItem( "text" ).toElement().text().utf8();
1888 if ( text.isEmpty() )
1889 text = element.namedItem( "Text" ).toElement().text().utf8();
1890 if ( !text.isEmpty() )
1891 setText( i18n( text ) );
1892 }
1893
1894 {
1895 QCString attrFullWidth = element.attribute( "fullWidth" ).lower().latin1();
1896 if ( !attrFullWidth.isEmpty() )
1897 setFullSize( attrFullWidth == "true" );
1898 }
1899
1900 Dock dock = DockTop;
1901 {
1902 QCString attrPosition = element.attribute( "position" ).lower().latin1();
1903 //kdDebug(220) << "KToolBar::loadState attrPosition=" << attrPosition << endl;
1904 if ( !attrPosition.isEmpty() ) {
1905 if ( attrPosition == "top" )
1906 dock = DockTop;
1907 else if ( attrPosition == "left" )
1908 dock = DockLeft;
1909 else if ( attrPosition == "right" )
1910 dock = DockRight;
1911 else if ( attrPosition == "bottom" )
1912 dock = DockBottom;
1913 else if ( attrPosition == "floating" )
1914 dock = DockTornOff;
1915 else if ( attrPosition == "flat" )
1916 dock = DockMinimized;
1917 }
1918 }
1919
1920 {
1921 QCString attrIconText = element.attribute( "iconText" ).lower().latin1();
1922 if ( !attrIconText.isEmpty() ) {
1923 //kdDebug(220) << "KToolBar::loadState attrIconText=" << attrIconText << endl;
1924 if ( attrIconText == "icontextright" )
1925 setIconText( KToolBar::IconTextRight );
1926 else if ( attrIconText == "textonly" )
1927 setIconText( KToolBar::TextOnly );
1928 else if ( attrIconText == "icontextbottom" )
1929 setIconText( KToolBar::IconTextBottom );
1930 else if ( attrIconText == "icononly" )
1931 setIconText( KToolBar::IconOnly );
1932 } else
1933 // Use global setting
1934 setIconText( iconTextSetting() );
1935 }
1936
1937 {
1938 QString attrIconSize = element.attribute( "iconSize" ).lower();
1939 if ( !attrIconSize.isEmpty() )
1940 d->IconSizeDefault = attrIconSize.toInt();
1941 setIconSize( d->IconSizeDefault );
1942 }
1943
1944 {
1945 QString attrIndex = element.attribute( "index" ).lower();
1946 if ( !attrIndex.isEmpty() )
1947 d->IndexDefault = attrIndex.toInt();
1948 }
1949
1950 {
1951 QString attrOffset = element.attribute( "offset" ).lower();
1952 if ( !attrOffset.isEmpty() )
1953 d->OffsetDefault = attrOffset.toInt();
1954 }
1955
1956 {
1957 QString attrNewLine = element.attribute( "newline" ).lower();
1958 if ( !attrNewLine.isEmpty() )
1959 d->NewLineDefault = attrNewLine == "true";
1960 }
1961
1962 {
1963 QString attrHidden = element.attribute( "hidden" ).lower();
1964 if ( !attrHidden.isEmpty() )
1965 d->HiddenDefault = attrHidden == "true";
1966 }
1967
1968 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( dock, d->IndexDefault, d->NewLineDefault, d->OffsetDefault );
1969 mainWindow()->addDockWindow( this, dock, d->NewLineDefault );
1970//US mainWindow()->moveDockWindow( this, dock, d->NewLineDefault, d->IndexDefault, d->OffsetDefault );
1971 mainWindow()->moveToolBar( this, dock, d->NewLineDefault, d->IndexDefault, d->OffsetDefault );
1972
1973 // Apply the highlight button setting
1974 d->m_highlight = highlightSetting();
1975
1976 // Apply transparent-toolbar-moving setting (ok, this is global to the mainwindow,
1977 // but we do it only if there are toolbars...)
1978 if ( transparentSetting() != !mainWindow()->opaqueMoving() )
1979 mainWindow()->setOpaqueMoving( !transparentSetting() );
1980
1981 if ( d->HiddenDefault )
1982 hide();
1983 else
1984 show();
1985
1986 getAttributes( d->PositionDefault, d->IconTextDefault, d->IndexDefault );
1987}
1988*/
1989
1990void KToolBar::getAttributes( QString &position, QString &icontext, int &index )
1991{
1992 // get all of the stuff to save
1993 switch ( barPos() ) {
1994 case KToolBar::Flat:
1995 position = "Flat";
1996 break;
1997 case KToolBar::Bottom:
1998 position = "Bottom";
1999 break;
2000 case KToolBar::Left:
2001 position = "Left";
2002 break;
2003 case KToolBar::Right:
2004 position = "Right";
2005 break;
2006 case KToolBar::Floating:
2007 position = "Floating";
2008 break;
2009 case KToolBar::Top:
2010 default:
2011 position = "Top";
2012 break;
2013 }
2014
2015 if ( mainWindow() ) {
2016 QMainWindow::ToolBarDock dock;
2017 bool newLine;
2018 int offset;
2019 mainWindow()->getLocation( this, dock, index, newLine, offset );
2020 }
2021
2022 switch (d->m_iconText) {
2023 case KToolBar::IconTextRight:
2024 icontext = "IconTextRight";
2025 break;
2026 case KToolBar::IconTextBottom:
2027 icontext = "IconTextBottom";
2028 break;
2029 case KToolBar::TextOnly:
2030 icontext = "TextOnly";
2031 break;
2032 case KToolBar::IconOnly:
2033 default:
2034 icontext = "IconOnly";
2035 break;
2036 }
2037}
2038/*US
2039void KToolBar::saveState( QDomElement &current )
2040{
2041 QString position, icontext;
2042 int index = -1;
2043 getAttributes( position, icontext, index );
2044
2045 current.setAttribute( "noMerge", "1" );
2046 current.setAttribute( "position", position );
2047 current.setAttribute( "iconText", icontext );
2048 current.setAttribute( "index", index );
2049 current.setAttribute( "offset", offset() );
2050 current.setAttribute( "newline", newLine() );
2051 if ( isHidden() )
2052 current.setAttribute( "hidden", "true" );
2053 d->modified = true;
2054}
2055*/
2056
2057void KToolBar::positionYourself( bool force )
2058{
2059 if (force)
2060 d->positioned = false;
2061
2062 if ( d->positioned || !mainWindow() )
2063 {
2064 //kdDebug(220) << "KToolBar::positionYourself d->positioned=true ALREADY DONE" << endl;
2065 return;
2066 }
2067 // we can't test for ForceHide after moveDockWindow because QDockArea
2068 // does a reparent() with showIt == true
2069 bool doHide = isHidden();
2070 //kdDebug(220) << "positionYourself " << name() << " dock=" << d->toolBarInfo.dock << " newLine=" << d->toolBarInfo.newline << " offset=" << d->toolBarInfo.offset << endl;
2071/*US mainWindow()->moveDockWindow( this, d->toolBarInfo.dock,
2072 d->toolBarInfo.newline,
2073 d->toolBarInfo.index,
2074 d->toolBarInfo.offset );
2075*/
2076 mainWindow()->moveToolBar( this, d->toolBarInfo.dock, d->NewLineDefault, d->IndexDefault, d->OffsetDefault );
2077
2078 if ( doHide )
2079 hide();
2080 // This method can only have an effect once - unless force is set
2081 d->positioned = TRUE;
2082}
2083
2084//US KPopupMenu *KToolBar::contextMenu()
2085QPopupMenu *KToolBar::contextMenu()
2086{
2087 if ( context )
2088 return context;
2089
2090 // Construct our context popup menu. Name it qt_dockwidget_internal so it
2091 // won't be deleted by QToolBar::clear().
2092//US context = new KPopupMenu( this, "qt_dockwidget_internal" );
2093 context = new QPopupMenu( this, "qt_dockwidget_internal" );
2094//US context->insertTitle(i18n("Toolbar Menu"));
2095
2096//US KPopupMenu *orient = new KPopupMenu( context, "orient" );
2097 QPopupMenu *orient = new QPopupMenu( context, "orient" );
2098 orient->insertItem( i18n("toolbar position string","Top"), CONTEXT_TOP );
2099 orient->insertItem( i18n("toolbar position string","Left"), CONTEXT_LEFT );
2100 orient->insertItem( i18n("toolbar position string","Right"), CONTEXT_RIGHT );
2101 orient->insertItem( i18n("toolbar position string","Bottom"), CONTEXT_BOTTOM );
2102 orient->insertSeparator(-1);
2103 //orient->insertItem( i18n("toolbar position string","Floating"), CONTEXT_FLOAT );
2104 orient->insertItem( i18n("min toolbar", "Flat"), CONTEXT_FLAT );
2105
2106//US KPopupMenu *mode = new KPopupMenu( context, "mode" );
2107 QPopupMenu *mode = new QPopupMenu( context, "mode" );
2108 mode->insertItem( i18n("Icons Only"), CONTEXT_ICONS );
2109 mode->insertItem( i18n("Text Only"), CONTEXT_TEXT );
2110 mode->insertItem( i18n("Text Alongside Icons"), CONTEXT_TEXTRIGHT );
2111 mode->insertItem( i18n("Text Under Icons"), CONTEXT_TEXTUNDER );
2112
2113//US KPopupMenu *size = new KPopupMenu( context, "size" );
2114 QPopupMenu *size = new QPopupMenu( context, "size" );
2115 size->insertItem( i18n("Default"), CONTEXT_ICONSIZES );
2116 // Query the current theme for available sizes
2117 QValueList<int> avSizes;
2118/*US
2119 KIconTheme *theme = KGlobal::instance()->iconLoader()->theme();
2120 if (!::qstrcmp(QObject::name(), "mainToolBar"))
2121 avSizes = theme->querySizes( KIcon::MainToolbar);
2122 else
2123 avSizes = theme->querySizes( KIcon::Toolbar);
2124*/
2125 avSizes << 16;
2126 avSizes << 32;
2127
2128 d->iconSizes = avSizes;
2129
2130 QValueList<int>::Iterator it;
2131 for (it=avSizes.begin(); it!=avSizes.end(); it++) {
2132 QString text;
2133 if ( *it < 19 )
2134 text = i18n("Small (%1x%2)").arg(*it).arg(*it);
2135 else if (*it < 25)
2136 text = i18n("Medium (%1x%2)").arg(*it).arg(*it);
2137 else
2138 text = i18n("Large (%1x%2)").arg(*it).arg(*it);
2139 //we use the size as an id, with an offset
2140 size->insertItem( text, CONTEXT_ICONSIZES + *it );
2141 }
2142
2143 context->insertItem( i18n("Orientation"), orient );
2144 orient->setItemChecked(CONTEXT_TOP, true);
2145 context->insertItem( i18n("Text Position"), mode );
2146 context->setItemChecked(CONTEXT_ICONS, true);
2147 context->insertItem( i18n("Icon Size"), size );
2148
2149/*US
2150 if (mainWindow()->inherits("KMainWindow"))
2151 {
2152 if ( (static_cast<KMainWindow*>(mainWindow())->toolBarMenuAction()) &&
2153 (static_cast<KMainWindow*>(mainWindow())->hasMenuBar()) )
2154
2155 (static_cast<KMainWindow*>(mainWindow()))->toolBarMenuAction()->plug(context);
2156 }
2157*/
2158
2159 connect( context, SIGNAL( aboutToShow() ), this, SLOT( slotContextAboutToShow() ) );
2160 return context;
2161}
2162
2163void KToolBar::slotContextAboutToShow()
2164{
2165 if (!d->m_configurePlugged)
2166 {
2167 // try to find "configure toolbars" action
2168
2169 KXMLGUIClient *xmlGuiClient = d->m_xmlguiClient;
2170 if ( !xmlGuiClient && mainWindow() && mainWindow()->inherits( "KMainWindow" ) )
2171 xmlGuiClient = (KXMLGUIClient *)mainWindow();
2172 if ( xmlGuiClient )
2173 {
2174 KAction *configureAction = xmlGuiClient->actionCollection()->action(KStdAction::stdName(KStdAction::ConfigureToolbars));
2175 if ( configureAction )
2176 {
2177 configureAction->plug(context);
2178 d->m_configurePlugged = true;
2179 }
2180 }
2181 }
2182
2183 for(int i = CONTEXT_ICONS; i <= CONTEXT_TEXTUNDER; ++i)
2184 context->setItemChecked(i, false);
2185
2186 switch( d->m_iconText )
2187 {
2188 case IconOnly:
2189 default:
2190 context->setItemChecked(CONTEXT_ICONS, true);
2191 break;
2192 case IconTextRight:
2193 context->setItemChecked(CONTEXT_TEXTRIGHT, true);
2194 break;
2195 case TextOnly:
2196 context->setItemChecked(CONTEXT_TEXT, true);
2197 break;
2198 case IconTextBottom:
2199 context->setItemChecked(CONTEXT_TEXTUNDER, true);
2200 break;
2201 }
2202
2203 QValueList<int>::ConstIterator iIt = d->iconSizes.begin();
2204 QValueList<int>::ConstIterator iEnd = d->iconSizes.end();
2205 for (; iIt != iEnd; ++iIt )
2206 context->setItemChecked( CONTEXT_ICONSIZES + *iIt, false );
2207
2208 context->setItemChecked( CONTEXT_ICONSIZES, false );
2209
2210 context->setItemChecked( CONTEXT_ICONSIZES + d->m_iconSize, true );
2211
2212 for ( int i = CONTEXT_TOP; i <= CONTEXT_FLAT; ++i )
2213 context->setItemChecked( i, false );
2214
2215 switch ( barPos() )
2216 {
2217 case KToolBar::Flat:
2218 context->setItemChecked( CONTEXT_FLAT, true );
2219 break;
2220 case KToolBar::Bottom:
2221 context->setItemChecked( CONTEXT_BOTTOM, true );
2222 break;
2223 case KToolBar::Left:
2224 context->setItemChecked( CONTEXT_LEFT, true );
2225 break;
2226 case KToolBar::Right:
2227 context->setItemChecked( CONTEXT_RIGHT, true );
2228 break;
2229 case KToolBar::Floating:
2230 context->setItemChecked( CONTEXT_FLOAT, true );
2231 break;
2232 case KToolBar::Top:
2233 context->setItemChecked( CONTEXT_TOP, true );
2234 break;
2235 default: break;
2236 }
2237}
2238
2239void KToolBar::widgetDestroyed()
2240{
2241 removeWidgetInternal( (QWidget*)sender() );
2242}
2243
2244void KToolBar::removeWidgetInternal( QWidget * w )
2245{
2246 if ( inshutdownprocess )
2247 return;
2248 widgets.removeRef( w );
2249 QMap< QWidget*, int >::Iterator it = widget2id.find( w );
2250 if ( it == widget2id.end() )
2251 return;
2252 id2widget.remove( *it );
2253 widget2id.remove( it );
2254}
2255
2256void KToolBar::virtual_hook( int, void* )
2257{ /*BASE::virtual_hook( id, data );*/ }
2258
2259//US #include "ktoolbar.moc"
2260
diff --git a/microkde/kdeui/ktoolbar.h b/microkde/kdeui/ktoolbar.h
new file mode 100644
index 0000000..2c061b5
--- a/dev/null
+++ b/microkde/kdeui/ktoolbar.h
@@ -0,0 +1,1107 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Reginald Stadlbauer (reggie@kde.org)
3 (C) 1997, 1998 Stephan Kulow (coolo@kde.org)
4 (C) 1997, 1998 Sven Radej (radej@kde.org)
5 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org)
6 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org)
7 (C) 1999, 2000 Kurt Granroth (granroth@kde.org)
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License version 2 as published by the Free Software Foundation.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
22 */
23
24#ifndef KTOOLBAR_H
25#define KTOOLBAR_H
26
27#ifndef DESKTOP_VERSION
28#define private public
29#include <qtoolbar.h>
30#undef private
31#include <qpe/qpetoolbar.h>
32#else
33#include <qtoolbar.h>
34#endif
35
36
37#include <qmainwindow.h>
38#include <qcombobox.h>
39#include <qmap.h>
40#include <qptrlist.h>
41#include <kglobal.h>
42#include <qguardedptr.h>
43#include <qframe.h>
44#include <qiconset.h>
45
46class QDomElement;
47class QSize;
48class QPixmap;
49class QPopupMenu;
50class QStringList;
51class QDomDocument;
52class QTimer;
53
54class KLineEdit;
55class KToolBar;
56class KToolBarButton;
57class KToolBoxManager;
58//US class KAnimWidget;
59//US class KPopupMenu;
60//US class KInstance;
61class KComboBox;
62class KXMLGUIClient;
63
64class KToolBarPrivate;
65
66class KToolBarSeparator : public QFrame
67{
68 Q_OBJECT
69public:
70 KToolBarSeparator( Orientation, bool l, QToolBar *parent, const char* name=0 );
71
72 QSize sizeHint() const;
73 Orientation orientation() const { return orient; }
74 QSizePolicy sizePolicy() const;
75 bool showLine() const { return line; }
76public slots:
77 void setOrientation( Orientation );
78protected:
79 void styleChange( QStyle& );
80private:
81 Orientation orient;
82 bool line;
83};
84
85
86 /**
87 * A KDE-style toolbar.
88 *
89 * KToolBar can be dragged around in and between different docks.
90 *
91 * A KToolBar can contain all sorts of widgets.
92 *
93 * KToolBar can be used as a standalone widget, but @ref KMainWindow
94 * provides easy factories and management of one or more toolbars.
95 * Once you have a KToolBar object, you can insert items into it with the
96 * insert... methods, or remove them with the @ref removeItem() method. This
97 * can be done at any time; the toolbar will be automatically updated.
98 * There are also many methods to set per-child properties like alignment
99 * and toggle behaviour.
100 *
101 * KToolBar uses a global config group to load toolbar settings on
102 * construction. It will reread this config group on a
103 * @ref KApplication::appearanceChanged() signal.
104 *
105 * @short Floatable toolbar with auto resize.
106 * @version $Id$
107 * @author Reginald Stadlbauer <reggie@kde.org>, Stephan Kulow <coolo@kde.org>, Sven Radej <radej@kde.org>.
108 */
109
110// strange things are happening ... so I have to use strange define methods ...
111// porting KToolBar back to Qt2 really needs some strange hacks
112
113#ifndef DESKTOP_VERSION
114#define QToolBar QPEToolBar
115#endif
116
117 class KToolBar : public QToolBar
118{
119 Q_OBJECT
120
121
122 Q_ENUMS( IconText BarPosition )
123
124 Q_PROPERTY( IconText iconText READ iconText WRITE setIconText )
125 Q_PROPERTY( BarPosition barPos READ barPos WRITE setBarPos )
126 Q_PROPERTY( bool fullSize READ fullSize WRITE setFullSize )
127 Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize )
128 Q_PROPERTY( QString text READ text WRITE setText )
129#ifndef DESKTOP_VERSION
130#undef QToolBar
131#endif
132public:
133 enum IconText{IconOnly = 0, IconTextRight, TextOnly, IconTextBottom};
134 /**
135 * The state of the status bar.
136 * @deprecated
137 **/
138 enum BarStatus{Toggle, Show, Hide};
139 /**
140 * Possible bar positions.
141 **/
142 enum BarPosition{ Unmanaged, Floating, Top, Bottom, Right, Left, Flat};
143
144 /**
145 * Constructor.
146 * This constructor is used by the XML-GUI. If you use it, you need
147 * to call QMainWindow::addToolBar to specify the position of the toolbar.
148 * So it's simpler to use the other constructor.
149 *
150 * The toolbar will read in various global config settings for
151 * things like icon size and text position, etc. However, some of
152 * the settings will be honored only if @ref #_honor_mode is set to
153 * true. All other toolbars will be IconOnly and use Medium icons.
154 *
155 * @param parent The standard toolbar parent (usually a
156 * @ref KMainWindow)
157 * @param name The standard internal name
158 * @param honor_style If true, then global settings for IconSize and IconText will be honored
159 * @param readConfig whether to apply the configuration (global and application-specific)
160 */
161 KToolBar( QWidget *parent, const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE );
162
163 /**
164 * Constructor for non-XML-GUI applications.
165 *
166 * The toolbar will read in various global config settings for
167 * things like icon size and text position, etc. However, some of
168 * the settings will be honored only if @ref #_honor_mode is set to
169 * true. All other toolbars will be IconOnly and use Medium icons.
170 *
171 * @param parentWindow The window that should be the parent of this toolbar
172 * @param dock The position of the toolbar. Usually QMainWindow::Top.
173 * @param newLine If true, start a new line in the dock for this toolbar.
174 * @param name The standard internal name
175 * @param honor_style If true, then global settings for IconSize and IconText will be honored
176 * @param readConfig whether to apply the configuration (global and application-specific)
177 */
178 KToolBar( QMainWindow *parentWindow, QMainWindow::ToolBarDock dock /*= QMainWindow::Top*/, bool newLine = false,
179 const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE );
180
181 /**
182 * Constructor for non-XML-GUI applications.
183 *
184 * The toolbar will read in various global config settings for
185 * things like icon size and text position, etc. However, some of
186 * the settings will be honored only if @ref #_honor_mode is set to
187 * true. All other toolbars will be IconOnly and use Medium icons.
188 *
189 * @param parentWindow The window that should be the parent of this toolbar
190 * @param dock Another widget than the mainwindow to dock toolbar to.
191 * @param newLine If true, start a new line in the dock for this toolbar.
192 * @param name The standard internal name
193 * @param honor_style If true, then global settings for IconSize and IconText will be honored
194 * @param readConfig whether to apply the configuration (global and application-specific)
195 */
196 KToolBar( QMainWindow *parentWindow, QWidget *dock, bool newLine = false,
197 const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE );
198
199 virtual ~KToolBar();
200
201 /**
202 * Insert a button (a @ref KToolBarButton) with a pixmap. The
203 * pixmap is loaded by the button itself based on the global icon
204 * settings.
205 *
206 * You should connect to one or more signals in KToolBar:
207 * @ref clicked() , @ref pressed() , @ref released() , or
208 * @ref highlighted() and if the button is a toggle button
209 * (@ref setToggle() ) @ref toggled() . Those signals have @p id
210 * of a button that caused the signal. If you want to bind a popup
211 * to button, see @ref setButton().
212 *
213 * @param icon The name of the icon to use as the active pixmap
214 * @param id The id of this button
215 * @param enabled Enable or disable the button at startup
216 * @param text The tooltip or toolbar text (depending on state)
217 * @param index The position of the button. (-1 = at end).
218 *
219 * @return The item index.
220 */
221 int insertButton(const QString& icon, int id, bool enabled = true,
222 const QString& text = QString::null, int index=-1/*US ,
223 KInstance *_instance = KGlobal::instance()*/);
224
225 /**
226 * This is the same as above, but with specified signals and
227 * slots to which this button will be connected.
228 *
229 * You can add more signals with @ref addConnection().
230 *
231 * @param icon The name of the icon to use as the active pixmap
232 * @param id The id of this button
233 * @param signal The signal to connect to
234 * @param receiver The slot's parent
235 * @param enabled Enable or disable the button at startup
236 * @param text The tooltip or toolbar text (depending on state)
237 * @param index The position of the button. (-1 = at end).
238 *
239 * @return The item index.
240 */
241 int insertButton(const QString& icon, int id, const char *signal,
242 const QObject *receiver, const char *slot,
243 bool enabled = true, const QString& text = QString::null,
244 int index=-1/*US, KInstance *_instance = KGlobal::instance()*/ );
245
246 /**
247 * Inserts a button (a @ref KToolBarButton) with the specified
248 * pixmap. This pixmap will be used as the "active" one and the
249 * disabled and default ones will be autogenerated.
250 *
251 * It is recommended that you use the insertButton function that
252 * allows you to specify the icon name rather then the pixmap
253 * itself. Specifying the icon name is much more flexible.
254 *
255 * You should connect to one or more signals in KToolBar:
256 * @ref clicked() , @ref pressed() , @ref released() , or
257 * @ref highlighted() and if the button is a toggle button
258 * (@ref setToggle() ) @ref toggled() . Those signals have @p id
259 * of a button that caused the signal. If you want to bind a popup
260 * to button, see @ref setButton().
261 *
262 * @param pixmap The active pixmap
263 * @param id The id of this button
264 * @param enabled Enable or disable the button at startup
265 * @param text The tooltip or toolbar text (depending on state)
266 * @param index The position of the button. (-1 = at end).
267 *
268 * @return The item index.
269 */
270 int insertButton(const QPixmap& pixmap, int id, bool enabled = true,
271 const QString& text = QString::null, int index=-1 );
272
273 /**
274 * This is the same as above, but with specified signals and
275 * slots to which this button will be connected.
276 *
277 * You can add more signals with @ref addConnection().
278 *
279 * @param icon The name of the icon to use as the active pixmap
280 * @param id The id of this button
281 * @param signal The signal to connect to
282 * @param receiver The slot's parent
283 * @param enabled Enable or disable the button at startup
284 * @param text The tooltip or toolbar text (depending on state)
285 * @param index The position of the button. (-1 = at end).
286 *
287 * @return The item index.
288 */
289 int insertButton(const QPixmap& pixmap, int id, const char *signal,
290 const QObject *receiver, const char *slot,
291 bool enabled = true, const QString& text = QString::null,
292 int index=-1 );
293
294 /**
295 * Inserts a button with popupmenu.
296 *
297 * Button will have small
298 * triangle. You have to connect to popup's signals. The
299 * signals @ref KButton::pressed(), @ref KButton::released(),
300 * @ref KButton::clicked() or @ref KButton::doubleClicked() are @p not
301 * emmited by
302 * this button (see @ref setDelayedPopup() for that).
303 * You can add custom popups which inherit @ref QPopupMenu to get popups
304 * with tables, drawings etc. Just don't fiddle with events there.
305 */
306 int insertButton(const QString& icon, int id, QPopupMenu *popup,
307 bool enabled, const QString&_text, int index=-1);
308
309 /**
310 * Inserts a button with popupmenu.
311 *
312 * Button will have small
313 * triangle. You have to connect to popup's signals. The
314 * signals @ref KButton::pressed(), @ref KButton::released(),
315 * @ref KButton::clicked() or @ref KButton::doubleClicked() are @p not
316 * emmited by
317 * this button (see @ref setDelayedPopup() for that).
318 * You can add custom popups which inherit @ref QPopupMenu to get popups
319 * with tables, drawings etc. Just don't fiddle with events there.
320 */
321 int insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup,
322 bool enabled, const QString&_text, int index=-1);
323
324 /**
325 * Inserts a @ref KLineEdit. You have to specify signals and slots to
326 * which KLineEdit will be connected. KLineEdit has all slots QLineEdit
327 * has, plus signals @ref KLineEdit::completion and @ref KLineEdit::textRotation
328 * KLineEdit can be set to autoresize itself to full free width
329 * in toolbar, that is to last right aligned item. For that,
330 * toolbar must be set to full width (which it is by default).
331 * @see setFullWidth()
332 * @see setItemAutoSized()
333 * @see KLineEdit
334 * @return Item index.
335 */
336 int insertLined (const QString& text, int id,
337 const char *signal,
338 const QObject *receiver, const char *slot,
339 bool enabled = true,
340 const QString& toolTipText = QString::null,
341 int size = 70, int index =-1);
342
343 /**
344 * Inserts a @ref KComboBox with list.
345 *
346 * Can be writable, but cannot contain
347 * pixmaps. By default inserting policy is AtBottom, i.e. typed items
348 * are placed at the bottom of the list. Can be autosized. If the size
349 * argument is specified as -1, the width of the combobox is automatically
350 * computed.
351 *
352 * @see setFullWidth()
353 * @see setItemAutoSized()
354 * @see KComboBox
355 * @return Item index.
356 */
357 int insertCombo (const QStringList &list, int id, bool writable,
358 const char *signal, const QObject *receiver,
359 const char *slot, bool enabled=true,
360 const QString& tooltiptext=QString::null,
361 int size=70, int index=-1,
362 QComboBox::Policy policy = QComboBox::AtBottom);
363
364 /**
365 * Insert a @ref KComboBox with text.
366 *
367 * The rest is the same as above.
368 * @see setItemAutoSized()
369 *
370 * @see KComboBox
371 * @return Item index.
372 */
373 int insertCombo (const QString& text, int id, bool writable,
374 const char *signal, QObject *recevier,
375 const char *slot, bool enabled=true,
376 const QString& tooltiptext=QString::null,
377 int size=70, int index=-1,
378 QComboBox::Policy policy = QComboBox::AtBottom);
379
380 /**
381 * Inserts a separator into the toolbar with the given id.
382 * Returns the separator's index
383 */
384 int insertSeparator( int index = -1, int id = -1 );
385
386 /**
387 * Inserts a line separator into the toolbar with the given id.
388 * Returns the separator's index
389 */
390 int insertLineSeparator( int index = -1, int id = -1 );
391
392 /**
393 * Inserts a user-defined widget. The widget @p must have this
394 * toolbar as its parent.
395 *
396 * Widget must have a QWidget for base class. Widget can be
397 * autosized to full width. If you forget about it, you can get a
398 * pointer to this widget with @ref getWidget().
399 * @see setItemAutoSized()
400 * @return Item index.
401 */
402 int insertWidget(int id, int width, QWidget *_widget, int index=-1);
403
404 /**
405 * Inserts an animated widget. A @ref KAnimWidget will be created
406 * internally using the icon name you provide.
407 * This will emit a signal (clicked()) whenever the
408 * animation widget is clicked.
409 *
410 * @see animatedWidget()
411 *
412 * @param id The id for this toolbar item
413 * @param receiver The parent of your slot
414 * @param slot The slot to receive the clicked() signal
415 * @param icons The name of the animation icon group to use
416 * @param index The item index
417 *
418 * @return The item index
419 */
420/*US
421 int insertAnimatedWidget(int id, QObject *receiver, const char *slot,
422 const QString& icons, int index = -1);
423*/
424 /**
425 * This will return a pointer to the given animated widget, if it
426 * exists.
427 *
428 * @see insertAnimatedWidget
429 *
430 * @param id The id for the widget you want to get a pointer to
431 *
432 * @return A pointer to the current animated widget or 0L
433 */
434//US KAnimWidget *animatedWidget( int id );
435
436 /**
437 * Adds connections to items.
438 *
439 * It is important that you
440 * know the @p id of particular item. Nothing happens if you forget @p id.
441 */
442 void addConnection (int id, const char *signal,
443 const QObject *receiver, const char *slot);
444 /**
445 * Enables/disables item.
446 */
447 void setItemEnabled( int id, bool enabled );
448
449 /**
450 * Sets the icon for a button.
451 *
452 * Can be used while button is visible.
453 */
454 void setButtonIcon( int id, const QString& _icon );
455
456 /**
457 * Sets button pixmap.
458 *
459 * Can be used while button is visible.
460 */
461 void setButtonPixmap( int id, const QPixmap& _pixmap );
462
463 /**
464 * Sets a button icon from a QIconSet.
465 *
466 * Can be used while button is visible.
467 */
468 void setButtonIconSet( int id, const QIconSet& iconset );
469
470 /**
471 * Sets a delayed popup for a button.
472 *
473 * Delayed popup is what you see in
474 * Netscape Navigator's Previous and Next buttons: If you click them you
475 * go back
476 * or forth. If you press them long enough, you get a history-menu.
477 * This is exactly what we do here.
478 *
479 * You will insert normal a button with connection (or use signals from
480 * toolbar):
481 * <pre>
482 * bar->insertButton(icon, id, SIGNAL(clicked ()), this,
483 * SLOT (slotClick()), true, "click or wait for popup");
484 * </pre> And then add a delayed popup:
485 * <pre>
486 * bar->setDelayedPopup (id, historyPopup); </pre>
487 *
488 * Don't add delayed popups to buttons which have normal popups.
489 *
490 * You may add popups which are derived from @ref QPopupMenu. You may
491 * add popups that are already in the menu bar or are submenus of
492 * other popups.
493 */
494 void setDelayedPopup (int id , QPopupMenu *_popup, bool toggle = false);
495
496 /**
497 * Turns a button into an autorepeat button.
498 *
499 * Toggle buttons, buttons with menus, or
500 * buttons with delayed menus cannot be made into autorepeat buttons.
501 * Moreover, you can and will receive
502 * only the signal clicked(), but not pressed() or released().
503 * When the user presses this button, you will receive the signal clicked(),
504 * and if the button is still pressed after some time,
505 * you will receive more clicked() signals separated by regular
506 * intervals. Since this uses @ref QButton::setAutoRepeat() ,
507 * I can't quantify 'some'.
508 */
509 void setAutoRepeat (int id, bool flag=true);
510
511
512 /**
513 * Turns button into a toggle button if @p flag is true.
514 */
515 void setToggle (int id, bool flag = true);
516
517 /**
518 * Toggles a togglebutton.
519 *
520 * If the button is a toggle button (see @ref setToggle())
521 * the button state will be toggled. This will also cause the toolbar to
522 * emit the signal @ref KButton::toggled() with parameter @p id. You must connect to
523 * this signal, or use @ref addConnection() to connect directly to the
524 * button signal @ref KButton::toggled().
525 */
526 void toggleButton (int id);
527
528 /**
529 * Sets a toggle button state.
530 *
531 * If the button is a toggle button (see @ref setToggle())
532 * this will set its state flag. This will also emit the signal
533 * @ref KButton::toggled().
534 *
535 * @see setToggle()
536 */
537 void setButton (int id, bool flag);
538
539 /**
540 * @return @p true if button is on, @p false if button is off or if the
541 * button is not a toggle button.
542 * @see setToggle()
543 */
544 bool isButtonOn (int id) const;
545
546 /**
547 * Sets the text of a line editor.
548 *
549 * Cursor is set at end of text.
550 */
551 void setLinedText (int id, const QString& text);
552
553 /**
554 * Returns a line editor text.
555 */
556 QString getLinedText (int id) const;
557
558 /**
559 * Inserts @p text in combobox @p id at position @p index.
560 */
561 void insertComboItem (int id, const QString& text, int index);
562
563 /**
564 * Inserts @p list in combobox @p id at position @p index.
565 */
566 void insertComboList (int id, const QStringList &list, int index);
567
568 /**
569 * Removes item @p index from combobox @p id.
570 */
571 void removeComboItem (int id, int index);
572
573 /**
574 * Sets item @p index to be current item in combobox @p id.
575 */
576 void setCurrentComboItem (int id, int index);
577
578 /**
579 * Changes item @p index in combobox @p id to text.
580 *
581 * @p index = -1 refers current item (one displayed in the button).
582 */
583 void changeComboItem (int id, const QString& text, int index=-1);
584
585 /**
586 * Clears the combobox @p id.
587 *
588 * Does not delete it or hide it.
589 */
590 void clearCombo (int id);
591
592 /**
593 * Returns text of item @p index from combobox @p id.
594 *
595 * @p index = -1 refers to current item.
596 */
597
598 QString getComboItem (int id, int index=-1) const;
599
600 /**
601 * Returns a pointer to the combobox.
602 *
603 * Example:
604 * <pre>
605 * KComboBox *combo = toolbar->getCombo(combo_id);
606 * </pre>
607 * That way you can get access to other public methods
608 * that @ref KComboBox provides.
609 */
610 KComboBox * getCombo(int id);
611
612 /**
613 * Returns a pointer to KToolBarLined.
614 *
615 * Example:
616 * <pre>
617 * KLineEdit * lined = toolbar->getKToolBarLined(lined_id);
618 * </pre>
619 * That way you can get access to other public methods
620 * that @ref KLineEdit provides. @ref KLineEdit is the same thing
621 * as @ref QLineEdit plus completion signals.
622 */
623 KLineEdit * getLined (int id);
624
625 /**
626 * Returns a pointer to KToolBarButton.
627 *
628 * Example:
629 * <pre>
630 * KToolBarButton * button = toolbar->getButton(button_id);
631 * </pre>
632 * That way you can get access to other public methods
633 * that @ref KToolBarButton provides.
634 *
635 * Using this method is not recommended.
636 */
637 KToolBarButton * getButton (int id);
638
639 /**
640 * Align item to the right.
641 *
642 * This works only if toolbar is set to full width.
643 * @see setFullWidth()
644 */
645 void alignItemRight (int id, bool right = true);
646
647 /**
648 * Returns a pointer to an inserted widget.
649 *
650 * Wrong ids are not tested.
651 * You can do with this whatever you want,
652 * except change its height (hardcoded). If you change its width
653 * you will probably have to call QToolBar::updateRects(true)
654 * @see QWidget
655 * @see updateRects()
656 *
657 * KDE4: make this const!
658 */
659 QWidget *getWidget (int id);
660
661 /**
662 * Set item autosized.
663 *
664 * This works only if the toolbar is set to full width.
665 * Only @p one item can be autosized, and it has to be
666 * the last left-aligned item. Items that come after this must be right
667 * aligned. Items that can be right aligned are Lineds, Frames, Widgets and
668 * Combos. An autosized item will resize itself whenever the toolbar geometry
669 * changes to the last right-aligned item (or to end of toolbar if there
670 * are no right-aligned items.)
671 * @see setFullWidth()
672 * @see alignItemRight()
673 */
674 void setItemAutoSized (int id, bool yes = true);
675
676 /**
677 * Remove all items.
678 *
679 * The toolbar is redrawn after it.
680 */
681 void clear ();
682
683 /**
684 * Remove item @p id.
685 *
686 * Item is deleted. Toolbar is redrawn after it.
687 */
688 void removeItem (int id);
689
690 /**
691 * Remove item @p id.
692 *
693 * Item is deleted when toolbar is redrawn.
694 */
695 void removeItemDelayed (int id);
696
697 /**
698 * Hide item.
699 */
700 void hideItem (int id);
701
702 /**
703 * Show item.
704 */
705 void showItem (int id);
706
707 /**
708 * Returns the index of the given item.
709 *
710 * KDE4: make this const!
711 */
712 int itemIndex (int id);
713
714 /**
715 * Set toolbar to full parent size (default).
716 *
717 * In full size mode the bar
718 * extends over the parent's full width or height. If the mode is disabled
719 * the toolbar tries to take as much space as it needs without wrapping, but
720 * it does not exceed the parent box. You can force a certain width or
721 * height with @ref setMaxWidth() or @ref setMaxHeight().
722 *
723 * If you want to use right-aligned items or auto-sized items you must use
724 * full size mode.
725 */
726 void setFullSize(bool flag = true);
727
728 /**
729 * @return @p true if the full-size mode is enabled. Otherwise
730 * it returns @false.
731 */
732 bool fullSize() const;
733
734 /**
735 * @deprecated use setMovingEnabled(bool) instead.
736 * Enable or disable moving of toolbar.
737 */
738 void enableMoving(bool flag = true);
739
740 /**
741 * Set position of toolbar.
742 * @see BarPosition()
743 */
744 void setBarPos (BarPosition bpos);
745
746 /**
747 * Returns position of toolbar.
748 */
749 BarPosition barPos();
750
751 /**
752 * @deprecated
753 * Show, hide, or toggle toolbar.
754 *
755 * This method is provided for compatibility only,
756 * please use show() and/or hide() instead.
757 * @see BarStatus
758 */
759 bool enable(BarStatus stat);
760
761 /**
762 * @deprecated
763 * Use setMaximumHeight() instead.
764 */
765 void setMaxHeight (int h); // Set max height for vertical toolbars
766
767 /**
768 * @deprecated
769 * Use maximumHeight() instead.
770 * Returns the value that was set with @ref setMaxHeight().
771 */
772 int maxHeight();
773
774 /**
775 * @deprecated
776 * Use setMaximumWidth() instead.
777 * Set maximal width of horizontal (top or bottom) toolbar.
778 */
779 void setMaxWidth (int dw);
780
781 /**
782 * @deprecated
783 * Use maximumWidth() instead.
784 * Returns the value that was set with @ref setMaxWidth().
785 */
786 int maxWidth();
787
788 /**
789 * Set title for toolbar when it floats.
790 *
791 * Titles are however not (yet)
792 * visible. You can't change toolbar's title while it's floating.
793 */
794 void setTitle (const QString& _title);
795
796 /**
797 * @deprecated
798 * Use enableMoving() instead.
799 */
800 void enableFloating (bool arrrrrrgh);
801
802 /**
803 * Set the kind of painting for buttons.
804 *
805 * Choose from:
806 * @li IconOnly (only icons),
807 * @li IconTextRight (icon and text, text is left from icons),
808 * @li TextOnly (only text),
809 * @li IconTextBottom (icons and text, text is under icons).
810 * @see IconText
811 *
812 */
813 void setIconText(IconText it);
814 // Note: don't merge with the next one, it breaks Qt properties
815
816 /**
817 * Similar to @ref setIconText(IconText it) but allows you to
818 * disable or enable updating. If @p update is false, then the
819 * buttons will not be updated. This is useful only if you know
820 * that you will be forcing an update later.
821 */
822 void setIconText(IconText it, bool update);
823
824 /**
825 * @return The current text style for buttons.
826 */
827 IconText iconText() const;
828
829 /**
830 * Set the icon size to load. Usually you should not call
831 * this, the icon size is taken care of by KIconLoader
832 * and globally configured.
833 * By default, the toolbar will load icons of size 32 for main
834 * toolbars and 22 for other toolbars
835 * @see KIconLoader.
836 *
837 * @param size The size to use
838 */
839 void setIconSize(int size);
840 // Note: don't merge with the next one, it breaks Qt properties
841
842 /**
843 * Same as @ref setIconText(int size) but allows you
844 * to disable the toolbar update.
845 *
846 * @param size The size to use
847 * @param update If true, then the toolbar will be updated after
848 * this
849 */
850 void setIconSize(int size, bool update);
851
852 /**
853 * @return The current icon size for buttons.
854 */
855 int iconSize() const;
856
857 /**
858 * This allows you to enable or disable the context menu.
859 *
860 * @param enable If false, then the context menu will be disabled
861 */
862 void setEnableContextMenu(bool enable = true);
863
864 /**
865 * Returns whether or not the context menu is disabled
866 *
867 * @return The context menu state
868 */
869 bool contextMenuEnabled() const;
870
871 /**
872 * This will inform a toolbar button to ignore certain style
873 * changes. Specifically, it will ignore IconText (always IconOnly)
874 * and will not allow image effects to apply.
875 *
876 * @param id The button to exclude from styles
877 * @param no_style If true, then it is excluded (default: true).
878 */
879 void setItemNoStyle(int id, bool no_style = true);
880
881 void setFlat (bool flag);
882
883 /**
884 * @return the number of items in the toolbar
885 */
886 int count() const;
887
888 /**
889 * Instruct the toolbar to save it's current state to either the app
890 * config file or to the XML-GUI resource file (whichever has
891 * precedence).
892 */
893 void saveState();
894
895 /**
896 * Save the toolbar settings to group @p configGroup in @p config.
897 */
898 void saveSettings(KConfig *config, const QString &configGroup);
899
900 /**
901 * Read the toolbar settings from group @p configGroup in @p config
902 * and apply them.
903 */
904 void applySettings(KConfig *config, const QString &configGroup);
905
906 /**
907 * Tell the toolbar what XML-GUI resource file it should use to save
908 * it's state. The state of the toolbar (position, size, etc) is
909 * saved in KConfig files if the application does not use XML-GUI..
910 * but if the app does, then it's saved the XML file. This function
911 * allows this to happen.
912 *
913 * @param xmlfile The XML-GUI resource file to write to
914 * @param xml The DOM document for the XML-GUI building
915 */
916 // void setXML(const QString& xmlfile, const QDomDocument& xml);
917 /* @internal */
918 void setXMLGUIClient( KXMLGUIClient *client );
919
920 /**
921 * Assign a (translated) text to this toolbar. This is used
922 * for the tooltip on the handle, and when listing the toolbars.
923 */
924 void setText( const QString & txt );
925
926 /**
927 * @return the toolbar's text.
928 */
929 QString text() const;
930
931 void setStretchableWidget( QWidget *w );
932 QSizePolicy sizePolicy() const;
933 bool highlight() const;
934 QSize sizeHint() const;
935 QSize minimumSizeHint() const;
936 QSize minimumSize() const;
937
938 void hide();
939 void show();
940
941 void updateRects( bool = FALSE ) {}
942
943//US void loadState( const QDomElement &e );
944//US void saveState( QDomElement &e );
945
946 /**
947 * @internal
948 */
949 void positionYourself( bool force = false);
950
951signals:
952 /**
953 * Emitted when button @p id is clicked.
954 */
955 void clicked(int id);
956
957 /**
958 * Emitted when button @p id is double-clicked.
959 *
960 * Note: you will always
961 * recive two @ref clicked() , @ref pressed() and @ref released() signals.
962 * There is no way to avoid it - at least no easy way.
963 * If you need to resolve this all you can do is set up timers
964 * which wait for @ref QApplication::doubleClickInterval() to expire.
965 * If in that time you don't get this signal, you may belive that
966 * button was only clicked and not double-clicked.
967 * And please note that butons with popup menus do not emit this signal,
968 * but those with delayed popup do.
969 */
970 void doubleClicked (int id);
971
972 /**
973 * Emitted when button @p id is pressed.
974 */
975 void pressed(int);
976
977 /**
978 * Emits when button @p id is released.
979 */
980 void released(int);
981
982 /**
983 * Emitted when a toggle button changes state.
984 *
985 * Emitted also if you change state
986 * with @ref setButton() or @ref toggleButton()
987 * If you make a button normal again, with
988 * setToggle(false), this signal won't
989 * be emitted.
990 */
991 void toggled(int);
992
993 /**
994 * This signal is emitted when item id gets highlighted/unhighlighted
995 * (i.e when mouse enters/exits).
996 *
997 * Note that this signal is emitted from
998 * all buttons (normal, disabled and toggle) even when there is no visible
999 * change in buttons (i.e., buttons do not raise when mouse enters).
1000 * The parameter @p isHighlighted is @p true when mouse enters and @p false when
1001 * mouse exits.
1002 */
1003 void highlighted(int id, bool isHighlighted);
1004
1005 /**
1006 * This signal is emitted when item id gets highlighted/unhighlighted
1007 * (i.e when mouse enters/exits).
1008 *
1009 * Note that this signal is emitted from
1010 * all buttons (normal, disabled and toggle) even when there is no visible
1011 * change in buttons (i.e., buttons do not raise when mouse enters).
1012 */
1013 void highlighted(int id );
1014
1015 /**
1016 * Emitted when toolbar changes position, or when
1017 * an item is removed from toolbar.
1018 *
1019 * If you subclass @ref KMainWindow and reimplement
1020 * @ref KMainWindow::resizeEvent() be sure to connect to
1021 * this signal. Note: You can connect this signal to a slot that
1022 * doesn't take parameter.
1023 */
1024 void moved( BarPosition );
1025
1026 /**
1027 * @internal
1028 * This signal is emitted when toolbar detects changing of
1029 * following parameters:
1030 * highlighting, button-size, button-mode. This signal is
1031 * internal, aimed to buttons.
1032 */
1033 void modechange ();
1034
1035 /**
1036 * This signal is emitted when the toolbar is getting deleted,
1037 * and before ~KToolbar finishes (so it's still time to remove
1038 * widgets from the toolbar).
1039 * Used by KWidgetAction.
1040 * @since 3.2
1041 */
1042 void toolbarDestroyed();
1043
1044public:
1045 /**
1046 * @return global setting for "Highlight buttons under mouse"
1047 */
1048 static bool highlightSetting();
1049
1050 /**
1051 * @return global setting for "Toolbars transparent when moving"
1052 */
1053 static bool transparentSetting();
1054
1055 /**
1056 * @return global setting for "Icon Text"
1057 */
1058 static IconText iconTextSetting();
1059
1060public slots:
1061 virtual void setIconText( const QString &txt )
1062 { QToolBar::setIconText( txt ); }
1063
1064protected:
1065 void mousePressEvent( QMouseEvent * );
1066 void childEvent( QChildEvent *e );
1067 void showEvent( QShowEvent *e );
1068 void resizeEvent( QResizeEvent *e );
1069 bool event( QEvent *e );
1070 void applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal = false);
1071 QString settingsGroup();
1072
1073private slots:
1074 void rebuildLayout();
1075 void slotReadConfig ();
1076 void slotAppearanceChanged();
1077 void slotIconChanged(int);
1078 void slotRepaint();
1079 void toolBarPosChanged( QToolBar *tb );
1080 void slotContextAboutToShow();
1081 void widgetDestroyed();
1082
1083private:
1084 void init( bool readConfig = true, bool honorStyle = false );
1085 void doConnections( KToolBarButton *button );
1086 void insertWidgetInternal( QWidget *w, int &index, int id );
1087 void removeWidgetInternal( QWidget *w );
1088 void getAttributes( QString &position, QString &icontext, int &index );
1089//US KPopupMenu *contextMenu();
1090 QPopupMenu *contextMenu();
1091
1092 QMap<QWidget*, int > widget2id;
1093 typedef QMap<int, QWidget* > Id2WidgetMap;
1094 Id2WidgetMap id2widget;
1095//US KPopupMenu *context;
1096 QPopupMenu *context;
1097 QPtrList<QWidget> widgets;
1098 QTimer *layoutTimer;
1099 QGuardedPtr<QWidget> stretchableWidget, rightAligned;
1100protected:
1101 virtual void virtual_hook( int id, void* data );
1102private:
1103 KToolBarPrivate *d;
1104 bool inshutdownprocess;
1105};
1106
1107#endif
diff --git a/microkde/kdeui/ktoolbarbutton.cpp b/microkde/kdeui/ktoolbarbutton.cpp
new file mode 100644
index 0000000..1d5d0e5
--- a/dev/null
+++ b/microkde/kdeui/ktoolbarbutton.cpp
@@ -0,0 +1,756 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org)
3 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org)
4 (C) 1997, 1998 Sven Radej (radej@kde.org)
5 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org)
6 (C) 1999 Chris Schlaeger (cs@kde.org)
7 (C) 1999 Kurt Granroth (granroth@kde.org)
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License version 2 as published by the Free Software Foundation.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
22*/
23
24//US #include <config.h>
25#include <string.h>
26
27#include "ktoolbarbutton.h"
28#include "ktoolbar.h"
29
30#include <qstyle.h>
31#include <qimage.h>
32#include <qtimer.h>
33#include <qdrawutil.h>
34#include <qtooltip.h>
35#include <qbitmap.h>
36#include <qpopupmenu.h>
37#include <qcursor.h>
38#include <qpainter.h>
39#include <qlayout.h>
40
41#include <kapplication.h>
42#include <kdebug.h>
43#include <kglobal.h>
44#include <kglobalsettings.h>
45//US #include <kiconeffect.h>
46#include <kiconloader.h>
47
48// needed to get our instance
49#include <kmainwindow.h>
50
51template class QIntDict<KToolBarButton>;
52
53class KToolBarButtonPrivate
54{
55public:
56 KToolBarButtonPrivate()
57 {
58 m_noStyle = false;
59 m_isSeparator = false;
60 m_isRadio = false;
61 m_highlight = false;
62 m_isRaised = false;
63 m_isActive = false;
64
65 m_iconName = QString::null;
66 m_iconText = KToolBar::IconOnly;
67 m_iconSize = 0;
68
69//US m_instance = KGlobal::instance();
70 }
71 ~KToolBarButtonPrivate()
72 {
73 }
74
75 int m_id;
76 bool m_noStyle: 1;
77 bool m_isSeparator: 1;
78 bool m_isRadio: 1;
79 bool m_highlight: 1;
80 bool m_isRaised: 1;
81 bool m_isActive: 1;
82
83 QString m_iconName;
84
85 KToolBar *m_parent;
86 KToolBar::IconText m_iconText;
87 int m_iconSize;
88 QSize size;
89
90 QPoint m_mousePressPos;
91
92//US KInstance *m_instance;
93};
94
95// This will construct a separator
96KToolBarButton::KToolBarButton( QWidget *_parent, const char *_name )
97 : QToolButton( _parent , _name)
98{
99 d = new KToolBarButtonPrivate;
100
101 resize(6,6);
102 hide();
103 d->m_isSeparator = true;
104}
105
106KToolBarButton::KToolBarButton( const QString& _icon, int _id,
107 QWidget *_parent, const char *_name,
108 const QString &_txt/*US, KInstance *_instance*/ )
109 : QToolButton( _parent, _name ), d( 0 )
110{
111 d = new KToolBarButtonPrivate;
112
113 d->m_id = _id;
114 d->m_parent = (KToolBar*)_parent;
115 QToolButton::setTextLabel(_txt);
116//US d->m_instance = _instance;
117
118 setFocusPolicy( NoFocus );
119
120 // connect all of our slots and start trapping events
121 connect(d->m_parent, SIGNAL( modechange() ),
122 this, SLOT( modeChange() ));
123
124 connect(this, SIGNAL( clicked() ),
125 this, SLOT( slotClicked() ) );
126 connect(this, SIGNAL( pressed() ),
127 this, SLOT( slotPressed() ) );
128 connect(this, SIGNAL( released() ),
129 this, SLOT( slotReleased() ) );
130 installEventFilter(this);
131
132 d->m_iconName = _icon;
133
134 // do our initial setup
135 modeChange();
136}
137
138KToolBarButton::KToolBarButton( const QPixmap& pixmap, int _id,
139 QWidget *_parent, const char *name,
140 const QString& txt)
141 : QToolButton( _parent, name ), d( 0 )
142{
143 d = new KToolBarButtonPrivate;
144
145 d->m_id = _id;
146 d->m_parent = (KToolBar *) _parent;
147 QToolButton::setTextLabel(txt);
148
149 setFocusPolicy( NoFocus );
150
151 // connect all of our slots and start trapping events
152 connect(d->m_parent, SIGNAL( modechange()),
153 this, SLOT(modeChange()));
154
155 connect(this, SIGNAL( clicked() ),
156 this, SLOT( slotClicked() ));
157 connect(this, SIGNAL( pressed() ),
158 this, SLOT( slotPressed() ));
159 connect(this, SIGNAL( released() ),
160 this, SLOT( slotReleased() ));
161 installEventFilter(this);
162
163 // set our pixmap and do our initial setup
164 setIconSet( QIconSet( pixmap ));
165 modeChange();
166}
167
168KToolBarButton::~KToolBarButton()
169{
170 delete d; d = 0;
171}
172
173void KToolBarButton::modeChange()
174{
175 QSize mysize;
176
177 // grab a few global variables for use in this function and others
178 d->m_highlight = d->m_parent->highlight();
179 d->m_iconText = d->m_parent->iconText();
180
181 d->m_iconSize = d->m_parent->iconSize();
182 if (!d->m_iconName.isNull())
183 setIcon(d->m_iconName);
184
185 // we'll start with the size of our pixmap
186 int pix_width = d->m_iconSize;
187
188 if ( d->m_iconSize == 0 ) {
189 if (!strcmp(d->m_parent->name(), "mainToolBar"))
190/*US
191 pix_width = IconSize( KIcon::MainToolbar );
192 else
193 pix_width = IconSize( KIcon::Toolbar );
194*/
195//qDebug("KToolBarButton::modeChange make iconsize configurable");
196 pix_width = 16;
197 }
198 int pix_height = pix_width;
199
200 int text_height = 0;
201 int text_width = 0;
202
203 QToolTip::remove(this);
204 if (d->m_iconText != KToolBar::IconOnly)
205 {
206 // okay, we have to deal with fonts. let's get our information now
207/*US
208 QFont tmp_font = KGlobalSettings::toolBarFont();
209
210 // now parse out our font sizes from our chosen font
211 QFontMetrics fm(tmp_font);
212
213 text_height = fm.lineSpacing();
214 text_width = fm.width(textLabel());
215*/
216//qDebug("KToolBarButton::modeChange make textsize configurable");
217
218 // none of the other modes want tooltips
219 }
220 else
221 {
222 QToolTip::add(this, textLabel());
223 }
224
225 switch (d->m_iconText)
226 {
227 case KToolBar::IconOnly:
228 mysize = QSize(pix_width, pix_height);
229 break;
230
231 case KToolBar::IconTextRight:
232 mysize = QSize(pix_width + text_width + 4, pix_height);
233 break;
234
235 case KToolBar::TextOnly:
236 mysize = QSize(text_width + 4, text_height);
237 break;
238
239 case KToolBar::IconTextBottom:
240 mysize = QSize((text_width + 4 > pix_width) ? text_width + 4 : pix_width, pix_height + text_height);
241 break;
242
243 default:
244 break;
245 }
246/*US
247 mysize = style().sizeFromContents(QStyle::CT_ToolButton, this, mysize).
248 expandedTo(QApplication::globalStrut());
249*/
250 // make sure that this isn't taller then it is wide
251 if (mysize.height() > mysize.width())
252 mysize.setWidth(mysize.height());
253
254 d->size = mysize;
255 setFixedSize(mysize);
256 updateGeometry();
257}
258
259void KToolBarButton::setTextLabel( const QString& text, bool tipToo)
260{
261 if (text.isNull())
262 return;
263
264 QString txt(text);
265 if (txt.right(3) == QString::fromLatin1("..."))
266 txt.truncate(txt.length() - 3);
267
268 QToolButton::setTextLabel(txt, tipToo);
269 update();
270}
271
272void KToolBarButton::setText( const QString& text)
273{
274 setTextLabel(text, true);
275 modeChange();
276}
277
278void KToolBarButton::setIcon( const QString &icon )
279{
280 d->m_iconName = icon;
281 d->m_iconSize = d->m_parent->iconSize();
282 // QObject::name() return "const char *" instead of QString.
283 if (!strcmp(d->m_parent->name(), "mainToolBar"))
284/*US QToolButton::setIconSet( d->m_instance->iconLoader()->loadIconSet(
285 d->m_iconName, KIcon::MainToolbar, d->m_iconSize ));
286*/
287 QToolButton::setIconSet( KGlobal::iconLoader()->loadIconSet(d->m_iconName ));
288 else
289/*US QToolButton::setIconSet(d->m_instance->iconLoader()->loadIconSet(
290 d->m_iconName, KIcon::Toolbar, d->m_iconSize ));
291*/
292 QToolButton::setIconSet(KGlobal::iconLoader()->loadIconSet(d->m_iconName));
293}
294
295void KToolBarButton::setIconSet( const QIconSet &iconset )
296{
297 QToolButton::setIconSet( iconset );
298}
299
300// remove?
301void KToolBarButton::setPixmap( const QPixmap &pixmap )
302{
303 if( pixmap.isNull()) // called by QToolButton
304 {
305 QToolButton::setPixmap( pixmap );
306 return;
307 }
308 QIconSet set = iconSet();
309 set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Active );
310 QToolButton::setIconSet( set );
311}
312
313void KToolBarButton::setDefaultPixmap( const QPixmap &pixmap )
314{
315 QIconSet set = iconSet();
316 set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Normal );
317 QToolButton::setIconSet( set );
318}
319
320void KToolBarButton::setDisabledPixmap( const QPixmap &pixmap )
321{
322 QIconSet set = iconSet();
323 set.setPixmap( pixmap, QIconSet::Automatic, QIconSet::Disabled );
324 QToolButton::setIconSet( set );
325}
326
327void KToolBarButton::setDefaultIcon( const QString& icon )
328{
329 QIconSet set = iconSet();
330 QPixmap pm;
331 if (!strcmp(d->m_parent->name(), "mainToolBar"))
332 pm = /*US d->m_instance->iconLoader()*/KGlobal::iconLoader()->loadIcon( icon, KIcon::MainToolbar,
333 d->m_iconSize );
334 else
335 pm = /*US d->m_instance->iconLoader()*/KGlobal::iconLoader()->loadIcon( icon, KIcon::Toolbar,
336 d->m_iconSize );
337 set.setPixmap( pm, QIconSet::Automatic, QIconSet::Normal );
338 QToolButton::setIconSet( set );
339}
340
341void KToolBarButton::setDisabledIcon( const QString& icon )
342{
343 QIconSet set = iconSet();
344 QPixmap pm;
345 if (!strcmp(d->m_parent->name(), "mainToolBar"))
346 pm = /*US d->m_instance->iconLoader()*/ KGlobal::iconLoader()->loadIcon( icon, KIcon::MainToolbar,
347 d->m_iconSize );
348 else
349 pm = /*US d->m_instance->iconLoader()*/ KGlobal::iconLoader()->loadIcon( icon, KIcon::Toolbar,
350 d->m_iconSize );
351 set.setPixmap( pm, QIconSet::Automatic, QIconSet::Disabled );
352 QToolButton::setIconSet( set );
353}
354
355QPopupMenu *KToolBarButton::popup()
356{
357 // obsolete
358 // KDE4: remove me
359 return QToolButton::popup();
360}
361
362void KToolBarButton::setPopup(QPopupMenu *p, bool)
363{
364 QToolButton::setPopup(p);
365 QToolButton::setPopupDelay(1);
366}
367
368
369void KToolBarButton::setDelayedPopup (QPopupMenu *p, bool)
370{
371 QToolButton::setPopup(p);
372//US QToolButton::setPopupDelay(QApplication::startDragTime());
373}
374
375void KToolBarButton::leaveEvent(QEvent *)
376{
377 if( d->m_isRaised || d->m_isActive )
378 {
379 d->m_isRaised = false;
380 d->m_isActive = false;
381 repaint(false);
382 }
383
384 emit highlighted(d->m_id, false);
385}
386
387void KToolBarButton::enterEvent(QEvent *)
388{
389 if (d->m_highlight)
390 {
391 if (isEnabled())
392 {
393 d->m_isActive = true;
394 if (!isToggleButton())
395 d->m_isRaised = true;
396 }
397 else
398 {
399 d->m_isRaised = false;
400 d->m_isActive = false;
401 }
402
403 repaint(false);
404 }
405 emit highlighted(d->m_id, true);
406}
407
408bool KToolBarButton::eventFilter(QObject *o, QEvent *ev)
409{
410 if ((KToolBarButton *)o == this)
411 {
412
413 // Popup the menu when the left mousebutton is pressed and the mouse
414 // is moved by a small distance.
415 if (QToolButton::popup())
416 {
417 if (ev->type() == QEvent::MouseButtonPress)
418 {
419 QMouseEvent* mev = static_cast<QMouseEvent*>(ev);
420 d->m_mousePressPos = mev->pos();
421 }
422 else if (ev->type() == QEvent::MouseMove)
423 {
424 QMouseEvent* mev = static_cast<QMouseEvent*>(ev);
425 if ((mev->pos() - d->m_mousePressPos).manhattanLength()
426//US > KGlobalSettings::dndEventDelay())
427 > 5 )
428 {
429//US openPopup();
430 return true;
431 }
432 }
433 }
434
435 if ((ev->type() == QEvent::MouseButtonPress ||
436 ev->type() == QEvent::MouseButtonRelease ||
437 ev->type() == QEvent::MouseButtonDblClick) && d->m_isRadio && isOn())
438 return true;
439
440 // From Kai-Uwe Sattler <kus@iti.CS.Uni-Magdeburg.De>
441 if (ev->type() == QEvent::MouseButtonDblClick)
442 {
443 emit doubleClicked(d->m_id);
444 return true;
445 }
446 }
447
448 return QToolButton::eventFilter(o, ev);
449}
450
451void KToolBarButton::drawButton( QPainter *_painter )
452{
453#ifdef DESKTOP_VERSION
454 QStyle::SFlags flags = QStyle::Style_Default;
455 QStyle::SCFlags active = QStyle::SC_None;
456
457 if (isDown()) {
458 flags |= QStyle::Style_Down;
459 active |= QStyle::SC_ToolButton;
460 }
461 if (isEnabled()) flags |= QStyle::Style_Enabled;
462 if (isOn()) flags |= QStyle::Style_On;
463 if (isEnabled() && d->m_isRaised)flags |= QStyle::Style_Raised;
464 if (hasFocus())flags |= QStyle::Style_HasFocus;
465
466 // Draw a styled toolbutton
467 style().drawComplexControl(QStyle::CC_ToolButton, _painter, this, rect(),
468 colorGroup(), flags, QStyle::SC_ToolButton, active, QStyleOption());
469
470#else
471 style().drawToolButton(_painter, rect().x(), rect().y(), rect().width(), rect().height(), colorGroup());
472#endif
473 int dx, dy;
474 QFont tmp_font(KGlobalSettings::toolBarFont());
475 QFontMetrics fm(tmp_font);
476 QRect textRect;
477 int textFlags = 0;
478
479 if (d->m_iconText == KToolBar::IconOnly) // icon only
480 {
481/*US
482 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
483 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
484 QIconSet::Disabled,
485 isOn() ? QIconSet::On : QIconSet::Off );
486*/
487 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
488 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
489 QIconSet::Disabled);
490
491 if( !pixmap.isNull())
492 {
493 dx = ( width() - pixmap.width() ) / 2;
494 dy = ( height() - pixmap.height() ) / 2;
495 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
496 {
497 ++dx;
498 ++dy;
499 }
500 _painter->drawPixmap( dx, dy, pixmap );
501 }
502 }
503 else if (d->m_iconText == KToolBar::IconTextRight) // icon and text (if any)
504 {
505/*US
506 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
507 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
508 QIconSet::Disabled,
509 isOn() ? QIconSet::On : QIconSet::Off );
510*/
511 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
512 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
513 QIconSet::Disabled);
514
515 if( !pixmap.isNull())
516 {
517 dx = 4;
518 dy = ( height() - pixmap.height() ) / 2;
519 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
520 {
521 ++dx;
522 ++dy;
523 }
524 _painter->drawPixmap( dx, dy, pixmap );
525 }
526
527 if (!textLabel().isNull())
528 {
529 textFlags = AlignVCenter|AlignLeft;
530 if (!pixmap.isNull())
531 dx = 4 + pixmap.width() + 2;
532 else
533 dx = 4;
534 dy = 0;
535 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
536 {
537 ++dx;
538 ++dy;
539 }
540 textRect = QRect(dx, dy, width()-dx, height());
541 }
542 }
543 else if (d->m_iconText == KToolBar::TextOnly)
544 {
545 if (!textLabel().isNull())
546 {
547 textFlags = AlignVCenter|AlignLeft;
548 dx = (width() - fm.width(textLabel())) / 2;
549 dy = (height() - fm.lineSpacing()) / 2;
550 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
551 {
552 ++dx;
553 ++dy;
554 }
555 textRect = QRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() );
556 }
557 }
558 else if (d->m_iconText == KToolBar::IconTextBottom)
559 {
560/*US
561 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
562 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
563 QIconSet::Disabled,
564 isOn() ? QIconSet::On : QIconSet::Off );
565*/
566 QPixmap pixmap = iconSet().pixmap( QIconSet::Automatic,
567 isEnabled() ? (d->m_isActive ? QIconSet::Active : QIconSet::Normal) :
568 QIconSet::Disabled);
569
570 if( !pixmap.isNull())
571 {
572 dx = (width() - pixmap.width()) / 2;
573 dy = (height() - fm.lineSpacing() - pixmap.height()) / 2;
574 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
575 {
576 ++dx;
577 ++dy;
578 }
579 _painter->drawPixmap( dx, dy, pixmap );
580 }
581
582 if (!textLabel().isNull())
583 {
584 textFlags = AlignBottom|AlignHCenter;
585 dx = (width() - fm.width(textLabel())) / 2;
586 dy = height() - fm.lineSpacing() - 4;
587
588 if ( isDown() /*US && style().styleHint(QStyle::SH_GUIStyle) == WindowsStyle*/ )
589 {
590 ++dx;
591 ++dy;
592 }
593 textRect = QRect( dx, dy, fm.width(textLabel()), fm.lineSpacing() );
594 }
595 }
596
597 // Draw the text at the position given by textRect, and using textFlags
598 if (!textLabel().isNull() && !textRect.isNull())
599 {
600 _painter->setFont(KGlobalSettings::toolBarFont());
601 if (!isEnabled())
602 _painter->setPen(palette().disabled().dark());
603 else if(d->m_isRaised)
604 _painter->setPen(KGlobalSettings::toolBarHighlightColor());
605 else
606 _painter->setPen( colorGroup().buttonText() );
607 _painter->drawText(textRect, textFlags, textLabel());
608 }
609
610 if (QToolButton::popup())
611 {
612#ifdef DESKTOP_VERSION
613 QStyle::SFlags arrowFlags = QStyle::Style_Default;
614
615 if (isDown())arrowFlags |= QStyle::Style_Down;
616 if (isEnabled()) arrowFlags |= QStyle::Style_Enabled;
617
618 style().drawPrimitive(QStyle::PE_ArrowDown, _painter,
619 QRect(width()-7, height()-7, 7, 7), colorGroup(),
620 arrowFlags, QStyleOption() );
621#else
622 style().drawArrow(_painter, Qt::DownArrow, isDown(),
623 width()-7, height()-7, 7, 7, colorGroup(), isEnabled() );
624#endif
625
626 }
627}
628
629void KToolBarButton::paletteChange(const QPalette &)
630{
631 if(!d->m_isSeparator)
632 {
633 modeChange();
634 repaint(false); // no need to delete it first therefore only false
635 }
636}
637
638void KToolBarButton::showMenu()
639{
640 // obsolete
641 // KDE4: remove me
642}
643
644void KToolBarButton::slotDelayTimeout()
645{
646 // obsolete
647 // KDE4: remove me
648}
649
650void KToolBarButton::slotClicked()
651{
652 emit clicked( d->m_id );
653}
654
655void KToolBarButton::slotPressed()
656{
657 emit pressed( d->m_id );
658}
659
660void KToolBarButton::slotReleased()
661{
662 emit released( d->m_id );
663}
664
665void KToolBarButton::slotToggled()
666{
667 emit toggled( d->m_id );
668}
669
670void KToolBarButton::setNoStyle(bool no_style)
671{
672 d->m_noStyle = no_style;
673
674 modeChange();
675 d->m_iconText = KToolBar::IconTextRight;
676 repaint(false);
677}
678
679void KToolBarButton::setRadio (bool f)
680{
681 if ( d )
682 d->m_isRadio = f;
683}
684
685void KToolBarButton::on(bool flag)
686{
687 if(isToggleButton() == true)
688 setOn(flag);
689 else
690 {
691 setDown(flag);
692 leaveEvent((QEvent *) 0);
693 }
694 repaint();
695}
696
697void KToolBarButton::toggle()
698{
699 setOn(!isOn());
700 repaint();
701}
702
703void KToolBarButton::setToggle(bool flag)
704{
705 setToggleButton(flag);
706 if (flag == true)
707 connect(this, SIGNAL(toggled(bool)), this, SLOT(slotToggled()));
708 else
709 disconnect(this, SIGNAL(toggled(bool)), this, SLOT(slotToggled()));
710}
711
712QSize KToolBarButton::sizeHint() const
713{
714 return d->size;
715}
716
717QSize KToolBarButton::minimumSizeHint() const
718{
719 return d->size;
720}
721
722QSize KToolBarButton::minimumSize() const
723{
724 return d->size;
725}
726
727bool KToolBarButton::isRaised() const
728{
729 return d->m_isRaised;
730}
731
732bool KToolBarButton::isActive() const
733{
734 return d->m_isActive;
735}
736
737int KToolBarButton::iconTextMode() const
738{
739 return static_cast<int>( d->m_iconText );
740}
741
742int KToolBarButton::id() const
743{
744 return d->m_id;
745}
746
747// KToolBarButtonList
748KToolBarButtonList::KToolBarButtonList()
749{
750 setAutoDelete(false);
751}
752
753void KToolBarButton::virtual_hook( int, void* )
754{ /*BASE::virtual_hook( id, data );*/ }
755
756//US #include "ktoolbarbutton.moc"
diff --git a/microkde/kdeui/ktoolbarbutton.h b/microkde/kdeui/ktoolbarbutton.h
new file mode 100644
index 0000000..9aaa13c
--- a/dev/null
+++ b/microkde/kdeui/ktoolbarbutton.h
@@ -0,0 +1,313 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org)
3 (C) 1997, 1998 Sven Radej (radej@kde.org)
4 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org)
5 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org)
6 (C) 2000 Kurt Granroth (granroth@kde.org)
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License version 2 as published by the Free Software Foundation.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
21*/
22
23// $Id$
24#ifndef _KTOOLBARBUTTON_H
25#define _KTOOLBARBUTTON_H
26
27#include <qpixmap.h>
28#include <qtoolbutton.h>
29#include <qintdict.h>
30#include <qstring.h>
31#include <kglobal.h>
32
33class KToolBar;
34class KToolBarButtonPrivate;
35//USclass KInstance;
36class QEvent;
37class QPopupMenu;
38class QPainter;
39
40/**
41 * A toolbar button. This is used internally by @ref KToolBar, use the
42 * KToolBar methods instead.
43 * @internal
44 */
45class KToolBarButton : public QToolButton
46{
47 Q_OBJECT
48
49public:
50 /**
51 * Construct a button with an icon loaded by the button itself.
52 * This will trust the button to load the correct icon with the
53 * correct size.
54 *
55 * @param icon Name of icon to load (may be absolute or relative)
56 * @param id Id of this button
57 * @param parent This button's parent
58 * @param name This button's internal name
59 * @param txt This button's text (in a tooltip or otherwise)
60 */
61 KToolBarButton(const QString& icon, int id, QWidget *parent,
62 const char *name=0L, const QString &txt=QString::null/*US,
63 KInstance *_instance = KGlobal::instance()*/);
64
65 /**
66 * Construct a button with an existing pixmap. It is not
67 * recommended that you use this as the internal icon loading code
68 * will almost always get it "right".
69 *
70 * @param icon Name of icon to load (may be absolute or relative)
71 * @param id Id of this button
72 * @param parent This button's parent
73 * @param name This button's internal name
74 * @param txt This button's text (in a tooltip or otherwise)
75 */
76 KToolBarButton(const QPixmap& pixmap, int id, QWidget *parent,
77 const char *name=0L, const QString &txt=QString::null);
78
79 /**
80 * Construct a separator button
81 *
82 * @param parent This button's parent
83 * @param name This button's internal name
84 */
85 KToolBarButton(QWidget *parent=0L, const char *name=0L);
86
87 /**
88 * Standard destructor
89 */
90 ~KToolBarButton();
91 QSize sizeHint() const;
92 QSize minimumSizeHint() const;
93 QSize minimumSize() const;
94
95#ifndef KDE_NO_COMPAT
96 /**
97 * @deprecated
98 * Set the pixmap directly for this button. This pixmap should be
99 * the active one... the dimmed and disabled pixmaps are constructed
100 * based on this one. However, don't use this function unless you
101 * are positive that you don't want to use @ref setIcon.
102 *
103 * @param pixmap The active pixmap
104 */
105 // this one is from QButton, so #ifdef-ing it out doesn't break BC
106 virtual void setPixmap(const QPixmap &pixmap);
107
108 /**
109 * @deprecated
110 * Force the button to use this pixmap as the default one rather
111 * then generating it using effects.
112 *
113 * @param pixmap The pixmap to use as the default (normal) one
114 */
115 void setDefaultPixmap(const QPixmap& pixmap);
116
117 /**
118 * @deprecated
119 * Force the button to use this pixmap when disabled one rather then
120 * generating it using effects.
121 *
122 * @param pixmap The pixmap to use when disabled
123 */
124 void setDisabledPixmap(const QPixmap& pixmap);
125#endif
126
127 /**
128 * Set the text for this button. The text will be either used as a
129 * tooltip (IconOnly) or will be along side the icon
130 *
131 * @param text The button (or tooltip) text
132 */
133 virtual void setText(const QString &text);
134
135 /**
136 * Set the icon for this button. The icon will be loaded internally
137 * with the correct size. This function is preferred over @ref setIconSet
138 *
139 * @param icon The name of the icon
140 */
141 virtual void setIcon(const QString &icon);
142
143 /// @since 3.1
144 virtual void setIcon( const QPixmap &pixmap )
145 { QToolButton::setIcon( pixmap ); }
146
147 /**
148 * Set the pixmaps for this toolbar button from a QIconSet.
149 * If you call this you don't need to call any of the other methods
150 * that set icons or pixmaps.
151 * @param iconset The iconset to use
152 */
153 virtual void setIconSet( const QIconSet &iconset );
154
155#ifndef KDE_NO_COMPAT
156 /**
157 * @deprecated
158 * Set the active icon for this button. The pixmap itself is loaded
159 * internally based on the icon size... .. the disabled and default
160 * pixmaps, however will only be constructed if @ref #generate is
161 * true. This function is preferred over @ref setPixmap
162 *
163 * @param icon The name of the active icon
164 * @param generate If true, then the other icons are automagically
165 * generated from this one
166 */
167 void setIcon(const QString &icon, bool /*generate*/ ) { setIcon( icon ); }
168
169 /**
170 * @deprecated
171 * Force the button to use this icon as the default one rather
172 * then generating it using effects.
173 *
174 * @param icon The icon to use as the default (normal) one
175 */
176 void setDefaultIcon(const QString& icon);
177
178 /**
179 * @deprecated
180 * Force the button to use this icon when disabled one rather then
181 * generating it using effects.
182 *
183 * @param icon The icon to use when disabled
184 */
185 void setDisabledIcon(const QString& icon);
186#endif
187
188 /**
189 * Turn this button on or off
190 *
191 * @param flag true or false
192 */
193 void on(bool flag = true);
194
195 /**
196 * Toggle this button
197 */
198 void toggle();
199
200 /**
201 * Turn this button into a toggle button or disable the toggle
202 * aspects of it. This does not toggle the button itself.
203 * Use @ref toggle() for that.
204 *
205 * @param toggle true or false
206 */
207 void setToggle(bool toggle = true);
208
209 /**
210 * Return a pointer to this button's popup menu (if it exists)
211 */
212 QPopupMenu *popup();
213
214 /**
215 * Returns the button's id.
216 * @since 3.2
217 */
218 int id() const;
219
220 /**
221 * Give this button a popup menu. There will not be a delay when
222 * you press the button. Use @ref setDelayedPopup if you want that
223 * behavior.
224 *
225 * @param p The new popup menu
226 */
227 void setPopup (QPopupMenu *p, bool unused = false);
228
229 /**
230 * Gives this button a delayed popup menu.
231 *
232 * This function allows you to add a delayed popup menu to the button.
233 * The popup menu is then only displayed when the button is pressed and
234 * held down for about half a second.
235 *
236 * @param p the new popup menu
237 */
238 void setDelayedPopup(QPopupMenu *p, bool unused = false);
239
240 /**
241 * Turn this button into a radio button
242 *
243 * @param f true or false
244 */
245 void setRadio(bool f = true);
246
247 /**
248 * Toolbar buttons naturally will assume the global styles
249 * concerning icons, icons sizes, etc. You can use this function to
250 * explicitely turn this off, if you like.
251 *
252 * @param no_style Will disable styles if true
253 */
254 void setNoStyle(bool no_style = true);
255
256signals:
257 void clicked(int);
258 void doubleClicked(int);
259 void pressed(int);
260 void released(int);
261 void toggled(int);
262 void highlighted(int, bool);
263
264public slots:
265 /**
266 * This slot should be called whenever the toolbar mode has
267 * potentially changed. This includes such events as text changing,
268 * orientation changing, etc.
269 */
270 void modeChange();
271 virtual void setTextLabel(const QString&, bool tipToo);
272
273protected:
274 void paletteChange(const QPalette &);
275 void leaveEvent(QEvent *e);
276 void enterEvent(QEvent *e);
277 void drawButton(QPainter *p);
278 bool eventFilter (QObject *o, QEvent *e);
279 void showMenu();
280
281 /// @since 3.1
282 bool isRaised() const;
283 /// @since 3.1
284 bool isActive() const;
285 /// @since 3.1
286 int iconTextMode() const;
287
288protected slots:
289 void slotClicked();
290 void slotPressed();
291 void slotReleased();
292 void slotToggled();
293 void slotDelayTimeout();
294
295protected:
296 virtual void virtual_hook( int id, void* data );
297private:
298 KToolBarButtonPrivate *d;
299};
300
301/**
302* List of @ref KToolBarButton objects.
303* @internal
304* @version $Id$
305*/
306class KToolBarButtonList : public QIntDict<KToolBarButton>
307{
308public:
309 KToolBarButtonList();
310 ~KToolBarButtonList() {}
311};
312
313#endif
diff --git a/microkde/kdeui/ktoolbarhandler.cpp b/microkde/kdeui/ktoolbarhandler.cpp
new file mode 100644
index 0000000..7b97233
--- a/dev/null
+++ b/microkde/kdeui/ktoolbarhandler.cpp
@@ -0,0 +1,253 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2002 Simon Hausmann <hausmann@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 version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17*/
18
19#include "ktoolbarhandler.h"
20
21#include <qpopupmenu.h>
22#include <kapplication.h>
23#include <ktoolbar.h>
24#include <kmainwindow.h>
25#include <klocale.h>
26#include <kaction.h>
27#include <assert.h>
28
29namespace
30{
31 const char *actionListName = "show_menu_and_toolbar_actionlist";
32
33 const char *guiDescription = ""
34 "<!DOCTYPE kpartgui><kpartgui name=\"StandardToolBarMenuHandler\">"
35 "<MenuBar>"
36 " <Menu name=\"settings\">"
37 " <ActionList name=\"%1\" />"
38 " </Menu>"
39 "</MenuBar>"
40 "</kpartgui>";
41
42 const char *resourceFileName = "barhandler.rc";
43
44 class BarActionBuilder
45 {
46 public:
47 BarActionBuilder( KActionCollection *actionCollection, KMainWindow *mainWindow, QPtrList<KToolBar> &oldToolBarList )
48 : m_actionCollection( actionCollection ), m_mainWindow( mainWindow ), m_needsRebuild( false )
49 {
50/*US
51 QPtrList<QDockWindow> dockWindows = m_mainWindow->dockWindows();
52 QPtrListIterator<QDockWindow> dockWindowIt( dockWindows );
53 for ( ; dockWindowIt.current(); ++dockWindowIt ) {
54
55//US KToolBar *toolBar = dynamic_cast<KToolBar *>( dockWindowIt.current() );
56 KToolBar *toolBar = (KToolBar *)( dockWindowIt.current() );
57 if ( !toolBar )
58 continue;
59
60 if ( oldToolBarList.findRef( toolBar ) == -1 )
61 m_needsRebuild = true;
62
63 m_toolBars.append( toolBar );
64 }
65*/
66 if ( !m_needsRebuild )
67 m_needsRebuild = ( oldToolBarList.count() != m_toolBars.count() );
68
69 }
70
71 bool needsRebuild() const { return m_needsRebuild; }
72
73 QPtrList<KAction> create()
74 {
75 if ( !m_needsRebuild )
76 return QPtrList<KAction>();
77
78 QPtrListIterator<KToolBar> toolBarIt( m_toolBars );
79 for ( ; toolBarIt.current(); ++toolBarIt )
80 handleToolBar( toolBarIt.current() );
81
82 QPtrList<KAction> actions;
83
84 if ( m_toolBarActions.count() == 0 )
85 return actions;
86
87 if ( m_toolBarActions.count() == 1 ) {
88 m_toolBarActions.getFirst()->setText( i18n( "Show Toolbar" ) );
89 return m_toolBarActions;
90 }
91
92 KActionMenu *menuAction = new KActionMenu( i18n( "Toolbars" ), m_actionCollection, "toolbars_submenu_action" );
93
94 QPtrListIterator<KAction> actionIt( m_toolBarActions );
95 for ( ; actionIt.current(); ++actionIt )
96 menuAction->insert( actionIt.current() );
97
98 actions.append( menuAction );
99 return actions;
100 }
101
102 const QPtrList<KToolBar> &toolBars() const { return m_toolBars; }
103
104 private:
105 void handleToolBar( KToolBar *toolBar )
106 {
107 KAction *action = new KToggleToolBarAction( toolBar,
108 i18n( "Show %1" ).arg( toolBar->label() ),
109 m_actionCollection,
110 toolBar->name() );
111
112 m_toolBarActions.append( action );
113 }
114
115 KActionCollection *m_actionCollection;
116 KMainWindow *m_mainWindow;
117
118 QPtrList<KToolBar> m_toolBars;
119 QPtrList<KAction> m_toolBarActions;
120
121 bool m_needsRebuild : 1;
122 };
123}
124
125using namespace KDEPrivate;
126
127ToolBarHandler::ToolBarHandler( KMainWindow *mainWindow, const char *name )
128 : QObject( mainWindow, name ), KXMLGUIClient( mainWindow )
129{
130 init( mainWindow );
131}
132
133ToolBarHandler::ToolBarHandler( KMainWindow *mainWindow, QObject *parent, const char *name )
134 : QObject( parent, name ), KXMLGUIClient( mainWindow )
135{
136 init( mainWindow );
137}
138
139ToolBarHandler::~ToolBarHandler()
140{
141 m_actions.setAutoDelete( true );
142 m_actions.clear();
143}
144
145KAction *ToolBarHandler::toolBarMenuAction()
146{
147 assert( m_actions.count() == 1 );
148 return m_actions.getFirst();
149}
150
151void ToolBarHandler::setupActions()
152{
153//US if ( !factory() || !m_mainWindow )
154 if ( !m_mainWindow )
155 return;
156
157 BarActionBuilder builder( actionCollection(), m_mainWindow, m_toolBars );
158
159 if ( !builder.needsRebuild() )
160 return;
161
162 unplugActionList( actionListName );
163
164 m_actions.setAutoDelete( true );
165
166 m_actions.clear();
167 m_actions.setAutoDelete( false );
168
169 m_actions = builder.create();
170
171 /*
172 for ( QPtrListIterator<KToolBar> toolBarIt( m_toolBars );
173 toolBarIt.current(); ++toolBarIt )
174 toolBarIt.current()->disconnect( this );
175 */
176
177 m_toolBars = builder.toolBars();
178
179 /*
180 for ( QPtrListIterator<KToolBar> toolBarIt( m_toolBars );
181 toolBarIt.current(); ++toolBarIt )
182 connect( toolBarIt.current(), SIGNAL( destroyed() ),
183 this, SLOT( setupActions() ) );
184 */
185
186//US if (kapp && kapp->authorizeKAction("options_show_toolbar"))
187 plugActionList( actionListName, m_actions );
188
189 connectToActionContainers();
190}
191
192/*US
193void ToolBarHandler::clientAdded( KXMLGUIClient *client )
194{
195 if ( client == this )
196 setupActions();
197}
198*/
199
200void ToolBarHandler::init( KMainWindow *mainWindow )
201{
202 d = 0;
203 m_mainWindow = mainWindow;
204
205/*US
206 connect( m_mainWindow->guiFactory(), SIGNAL( clientAdded( KXMLGUIClient * ) ),
207 this, SLOT( clientAdded( KXMLGUIClient * ) ) );
208*/
209 /* re-use an existing resource file if it exists. can happen if the user launches the
210 * toolbar editor */
211 /*
212 setXMLFile( resourceFileName );
213 */
214/*US
215 if ( domDocument().documentElement().isNull() ) {
216
217 QString completeDescription = QString::fromLatin1( guiDescription )
218 .arg( actionListName );
219
220 setXML( completeDescription, false*/ /*merge*/ /*);
221 }
222*/
223}
224
225void ToolBarHandler::connectToActionContainers()
226{
227 QPtrListIterator<KAction> actionIt( m_actions );
228 for ( ; actionIt.current(); ++actionIt )
229 connectToActionContainer( actionIt.current() );
230}
231
232void ToolBarHandler::connectToActionContainer( KAction *action )
233{
234 uint containerCount = action->containerCount();
235 for ( uint i = 0; i < containerCount; ++i )
236 connectToActionContainer( action->container( i ) );
237}
238
239void ToolBarHandler::connectToActionContainer( QWidget *container )
240{
241//US QPopupMenu *popupMenu = dynamic_cast<QPopupMenu *>( container );
242 QPopupMenu *popupMenu = (QPopupMenu *)( container );
243 if ( !popupMenu )
244 return;
245
246 connect( popupMenu, SIGNAL( aboutToShow() ),
247 this, SLOT( setupActions() ) );
248}
249
250//US #include "ktoolbarhandler.moc"
251
252/* vim: et sw=4 ts=4
253 */
diff --git a/microkde/kdeui/ktoolbarhandler.h b/microkde/kdeui/ktoolbarhandler.h
new file mode 100644
index 0000000..a1340ae
--- a/dev/null
+++ b/microkde/kdeui/ktoolbarhandler.h
@@ -0,0 +1,70 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2002 Simon Hausmann <hausmann@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 version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17*/
18
19#ifndef KBARHANDLER_H
20#define KBARHANDLER_H
21
22#include <qobject.h>
23#include <qguardedptr.h>
24#include <qptrlist.h>
25#include <kxmlguiclient.h>
26#include <kaction.h>
27
28class KMainWindow;
29class KToolBar;
30
31namespace KDEPrivate
32{
33
34/// @since 3.1
35class ToolBarHandler : public QObject, public KXMLGUIClient
36{
37 Q_OBJECT
38public:
39 ToolBarHandler( KMainWindow *mainWindow, const char *name = 0 );
40 ToolBarHandler( KMainWindow *mainWindow, QObject *parent, const char *name = 0 );
41 virtual ~ToolBarHandler();
42
43 KAction *toolBarMenuAction();
44
45public slots:
46 void setupActions();
47
48private slots:
49//US void clientAdded( KXMLGUIClient *client );
50
51private:
52 void init( KMainWindow *mainWindow );
53 void connectToActionContainers();
54 void connectToActionContainer( KAction *action );
55 void connectToActionContainer( QWidget *container );
56
57 struct Data;
58 Data *d;
59
60 QGuardedPtr<KMainWindow> m_mainWindow;
61 QPtrList<KAction> m_actions;
62 QPtrList<KToolBar> m_toolBars;
63};
64
65} // namespace KDEPrivate
66
67#endif // KBARHANDLER_H
68
69/* vim: et sw=4 ts=4
70 */
diff --git a/microkde/kdeui/kxmlguiclient.cpp b/microkde/kdeui/kxmlguiclient.cpp
new file mode 100644
index 0000000..073e30b
--- a/dev/null
+++ b/microkde/kdeui/kxmlguiclient.cpp
@@ -0,0 +1,958 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
3 Copyright (C) 2000 Kurt Granroth <granroth@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
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., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18*/
19
20#include "kxmlguiclient.h"
21
22/*US
23#include "kxmlguifactory.h"
24#include "kxmlguibuilder.h"
25*/
26
27/*US
28#include <qdir.h>
29#include <qfile.h>
30#include <qdom.h>
31#include <qtextstream.h>
32#include <qregexp.h>
33*/
34
35//US #include <kinstance.h>
36#include <kstandarddirs.h>
37#include <kdebug.h>
38#include <kaction.h>
39#include <kapplication.h>
40
41#include <assert.h>
42
43class KXMLGUIClientPrivate
44{
45public:
46 KXMLGUIClientPrivate()
47 {
48//US m_instance = KGlobal::instance();
49//US m_factory = 0L;
50 m_parent = 0L;
51//US m_builder = 0L;
52 m_actionCollection = 0;
53 }
54 ~KXMLGUIClientPrivate()
55 {
56 }
57
58//US KInstance *m_instance;
59
60//US QDomDocument m_doc;
61 KActionCollection *m_actionCollection;
62//US QDomDocument m_buildDocument;
63//US KXMLGUIFactory *m_factory;
64 KXMLGUIClient *m_parent;
65 //QPtrList<KXMLGUIClient> m_supers;
66 QPtrList<KXMLGUIClient> m_children;
67//US KXMLGUIBuilder *m_builder;
68//US QString m_xmlFile;
69//US QString m_localXMLFile;
70};
71
72KXMLGUIClient::KXMLGUIClient()
73{
74 d = new KXMLGUIClientPrivate;
75}
76
77KXMLGUIClient::KXMLGUIClient( KXMLGUIClient *parent )
78{
79 d = new KXMLGUIClientPrivate;
80 parent->insertChildClient( this );
81}
82
83KXMLGUIClient::~KXMLGUIClient()
84{
85 if ( d->m_parent )
86 d->m_parent->removeChildClient( this );
87
88 QPtrListIterator<KXMLGUIClient> it( d->m_children );
89 for ( ; it.current(); ++it ) {
90 assert( it.current()->d->m_parent == this );
91 it.current()->d->m_parent = 0;
92 }
93
94 delete d->m_actionCollection;
95 delete d;
96}
97
98KAction *KXMLGUIClient::action( const char *name ) const
99{
100 KAction* act = actionCollection()->action( name );
101 if ( !act ) {
102 QPtrListIterator<KXMLGUIClient> childIt( d->m_children );
103 for (; childIt.current(); ++childIt ) {
104 act = childIt.current()->actionCollection()->action( name );
105 if ( act )
106 break;
107 }
108 }
109 return act;
110}
111
112KActionCollection *KXMLGUIClient::actionCollection() const
113{
114 if ( !d->m_actionCollection )
115 d->m_actionCollection = new KActionCollection( 0, 0,
116 "KXMLGUILClient-KActionCollection" );
117 return d->m_actionCollection;
118}
119
120/*US
121KAction *KXMLGUIClient::action( const QDomElement &element ) const
122{
123 static const QString &attrName = KGlobal::staticQString( "name" );
124 return actionCollection()->action( element.attribute( attrName ).latin1() );
125}
126
127KInstance *KXMLGUIClient::instance() const
128{
129 return d->m_instance;
130}
131
132QDomDocument KXMLGUIClient::domDocument() const
133{
134 return d->m_doc;
135}
136
137QString KXMLGUIClient::xmlFile() const
138{
139 return d->m_xmlFile;
140}
141
142QString KXMLGUIClient::localXMLFile() const
143{
144 if ( !d->m_localXMLFile.isEmpty() )
145 return d->m_localXMLFile;
146
147 if ( d->m_xmlFile[0] == '/' )
148 return QString::null; // can't save anything here
149
150 return locateLocal( "data", QString::fromLatin1( instance()->instanceName() + '/' ) + d->m_xmlFile );
151}
152
153
154void KXMLGUIClient::reloadXML()
155{
156 QString file( xmlFile() );
157 if ( !file.isEmpty() )
158 setXMLFile( file );
159}
160
161void KXMLGUIClient::setInstance( KInstance *instance )
162{
163 d->m_instance = instance;
164 actionCollection()->setInstance( instance );
165 if ( d->m_builder )
166 d->m_builder->setBuilderClient( this );
167}
168
169void KXMLGUIClient::setXMLFile( const QString& _file, bool merge, bool setXMLDoc )
170{
171 // store our xml file name
172 if ( !_file.isNull() ) {
173 d->m_xmlFile = _file;
174 actionCollection()->setXMLFile( _file );
175 }
176
177 if ( !setXMLDoc )
178 return;
179
180 QString file = _file;
181 if ( file[0] != '/' )
182 {
183 QString doc;
184
185 QString filter = QString::fromLatin1( instance()->instanceName() + '/' ) + _file;
186
187 QStringList allFiles = instance()->dirs()->findAllResources( "data", filter ) + instance()->dirs()->findAllResources( "data", _file );
188
189 file = findMostRecentXMLFile( allFiles, doc );
190
191 if ( file.isEmpty() )
192 {
193 // this might or might not be an error. for the time being,
194 // let's treat this as if it isn't a problem and the user just
195 // wants the global standards file
196 setXML( QString::null, true );
197 return;
198 }
199 else if ( !doc.isEmpty() )
200 {
201 setXML( doc, merge );
202 return;
203 }
204 }
205
206 QString xml = KXMLGUIFactory::readConfigFile( file );
207 setXML( xml, merge );
208}
209
210void KXMLGUIClient::setLocalXMLFile( const QString &file )
211{
212 d->m_localXMLFile = file;
213}
214
215void KXMLGUIClient::setXML( const QString &document, bool merge )
216{
217 QDomDocument doc;
218 doc.setContent( document );
219 setDOMDocument( doc, merge );
220}
221
222void KXMLGUIClient::setDOMDocument( const QDomDocument &document, bool merge )
223{
224 if ( merge )
225 {
226 QDomElement base = d->m_doc.documentElement();
227
228 QDomElement e = document.documentElement();
229 KXMLGUIFactory::removeDOMComments( e );
230
231 // merge our original (global) xml with our new one
232 mergeXML(base, e, actionCollection());
233
234 // reassign our pointer as mergeXML might have done something
235 // strange to it
236 base = d->m_doc.documentElement();
237
238 // we want some sort of failsafe.. just in case
239 if ( base.isNull() )
240 d->m_doc = document;
241 }
242 else
243 {
244 d->m_doc = document;
245 KXMLGUIFactory::removeDOMComments( d->m_doc );
246 }
247
248 setXMLGUIBuildDocument( QDomDocument() );
249}
250*/
251
252/*US
253bool KXMLGUIClient::mergeXML( QDomElement &base, const QDomElement &additive, KActionCollection *actionCollection )
254{
255 static const QString &tagAction = KGlobal::staticQString( "Action" );
256 static const QString &tagMerge = KGlobal::staticQString( "Merge" );
257 static const QString &tagSeparator = KGlobal::staticQString( "Separator" );
258 static const QString &attrName = KGlobal::staticQString( "name" );
259 static const QString &attrAppend = KGlobal::staticQString( "append" );
260 static const QString &attrWeakSeparator = KGlobal::staticQString( "weakSeparator" );
261 static const QString &tagMergeLocal = KGlobal::staticQString( "MergeLocal" );
262 static const QString &tagText = KGlobal::staticQString( "text" );
263 static const QString &attrAlreadyVisited = KGlobal::staticQString( "alreadyVisited" );
264 static const QString &attrNoMerge = KGlobal::staticQString( "noMerge" );
265 static const QString &attrOne = KGlobal::staticQString( "1" );
266
267 // there is a possibility that we don't want to merge in the
268 // additive.. rather, we might want to *replace* the base with the
269 // additive. this can be for any container.. either at a file wide
270 // level or a simple container level. we look for the 'noMerge'
271 // tag, in any event and just replace the old with the new
272 if ( additive.attribute(attrNoMerge) == attrOne ) // ### use toInt() instead? (Simon)
273 {
274 base.parentNode().replaceChild(additive, base);
275 return true;
276 }
277
278 QString tag;
279
280 QDomElement e = base.firstChild().toElement();
281 // iterate over all elements in the container (of the global DOM tree)
282 while ( !e.isNull() )
283 {
284 tag = e.tagName();
285
286 // if there's an action tag in the global tree and the action is
287 // not implemented, then we remove the element
288 if ( tag == tagAction )
289 {
290 QCString name = e.attribute( attrName ).utf8(); // WABA
291 if ( !actionCollection->action( name ) ||
292 (kapp && !kapp->authorizeKAction(name)))
293 {
294 // remove this child as we aren't using it
295 QDomElement oldChild = e;
296 e = e.nextSibling().toElement();
297 base.removeChild( oldChild );
298 continue;
299 }
300 }
301
302 // if there's a separator defined in the global tree, then add an
303 // attribute, specifying that this is a "weak" separator
304 else if ( tag == tagSeparator )
305 {
306 e.setAttribute( attrWeakSeparator, (uint)1 );
307
308 // okay, hack time. if the last item was a weak separator OR
309 // this is the first item in a container, then we nuke the
310 // current one
311 QDomElement prev = e.previousSibling().toElement();
312 if ( prev.isNull() ||
313 ( prev.tagName() == tagSeparator && !prev.attribute( attrWeakSeparator ).isNull() ) ||
314 ( prev.tagName() == tagText ) )
315 {
316 // the previous element was a weak separator or didn't exist
317 QDomElement oldChild = e;
318 e = e.nextSibling().toElement();
319 base.removeChild( oldChild );
320 continue;
321 }
322 }
323
324 // the MergeLocal tag lets us specify where non-standard elements
325 // of the local tree shall be merged in. After inserting the
326 // elements we delete this element
327 else if ( tag == tagMergeLocal )
328 {
329 QDomElement currElement = e;
330
331 // switch our iterator "e" to the next sibling, so that we don't
332 // process the local tree's inserted items!
333 e = e.nextSibling().toElement();
334
335 QDomElement it = additive.firstChild().toElement();
336 while ( !it.isNull() )
337 {
338 QDomElement newChild = it;
339
340 it = it.nextSibling().toElement();
341
342 if ( newChild.tagName() == tagText )
343 continue;
344
345 if ( newChild.attribute( attrAlreadyVisited ) == attrOne )
346 continue;
347
348 QString itAppend( newChild.attribute( attrAppend ) );
349 QString elemName( currElement.attribute( attrName ) );
350
351 if ( ( itAppend.isNull() && elemName.isEmpty() ) ||
352 ( itAppend == elemName ) )
353 {
354 // first, see if this new element matches a standard one in
355 // the global file. if it does, then we skip it as it will
356 // be merged in, later
357 QDomElement matchingElement = findMatchingElement( newChild, base );
358 if ( matchingElement.isNull() || newChild.tagName() == tagSeparator )
359 base.insertBefore( newChild, currElement );
360 }
361 }
362
363 base.removeChild( currElement );
364 continue;
365 }
366
367 // in this last case we check for a separator tag and, if not, we
368 // can be sure that its a container --> proceed with child nodes
369 // recursively and delete the just proceeded container item in
370 // case its empty (if the recursive call returns true)
371 else if ( tag != tagMerge )
372 {
373 // handle the text tag
374 if ( tag == tagText )
375 {
376 e = e.nextSibling().toElement();
377 continue;
378 }
379
380 QDomElement matchingElement = findMatchingElement( e, additive );
381
382 QDomElement currElement = e;
383 e = e.nextSibling().toElement();
384
385 if ( !matchingElement.isNull() )
386 {
387 matchingElement.setAttribute( attrAlreadyVisited, (uint)1 );
388
389 if ( mergeXML( currElement, matchingElement, actionCollection ) )
390 {
391 base.removeChild( currElement );
392 continue;
393 }
394
395 // Merge attributes
396 QDomNamedNodeMap attribs = matchingElement.attributes();
397 for(uint i = 0; i < attribs.count(); i++)
398 {
399 QDomNode node = attribs.item(i);
400 currElement.setAttribute(node.nodeName(), node.nodeValue());
401 }
402
403 continue;
404 }
405 else
406 {
407 // this is an important case here! We reach this point if the
408 // "local" tree does not contain a container definition for
409 // this container. However we have to call mergeXML recursively
410 // and make it check if there are actions implemented for this
411 // container. *If* none, then we can remove this container now
412 if ( mergeXML( currElement, QDomElement(), actionCollection ) )
413 base.removeChild( currElement );
414 continue;
415 }
416 }
417
418 //I think this can be removed ;-)
419 e = e.nextSibling().toElement();
420 }
421
422 //here we append all child elements which were not inserted
423 //previously via the LocalMerge tag
424 e = additive.firstChild().toElement();
425 while ( !e.isNull() )
426 {
427 QDomElement matchingElement = findMatchingElement( e, base );
428
429 if ( matchingElement.isNull() )
430 {
431 QDomElement newChild = e;
432 e = e.nextSibling().toElement();
433 base.appendChild( newChild );
434 }
435 else
436 e = e.nextSibling().toElement();
437 }
438
439 // do one quick check to make sure that the last element was not
440 // a weak separator
441 QDomElement last = base.lastChild().toElement();
442 if ( (last.tagName() == tagSeparator) && (!last.attribute( attrWeakSeparator ).isNull()) )
443 {
444 base.removeChild( base.lastChild() );
445 }
446
447 // now we check if we are empty (in which case we return "true", to
448 // indicate the caller that it can delete "us" (the base element
449 // argument of "this" call)
450 bool deleteMe = true;
451 e = base.firstChild().toElement();
452 for ( ; !e.isNull(); e = e.nextSibling().toElement() )
453 {
454 tag = e.tagName();
455
456 if ( tag == tagAction )
457 {
458 // if base contains an implemented action, then we must not get
459 // deleted (note that the actionCollection contains both,
460 // "global" and "local" actions
461 if ( actionCollection->action( e.attribute( attrName ).utf8() ) )
462 {
463 deleteMe = false;
464 break;
465 }
466 }
467 else if ( tag == tagSeparator )
468 {
469 // if we have a separator which has *not* the weak attribute
470 // set, then it must be owned by the "local" tree in which case
471 // we must not get deleted either
472 QString weakAttr = e.attribute( attrWeakSeparator );
473 if ( weakAttr.isEmpty() || weakAttr.toInt() != 1 )
474 {
475 deleteMe = false;
476 break;
477 }
478 }
479
480 // in case of a merge tag we have unlimited lives, too ;-)
481 else if ( tag == tagMerge )
482 {
483// deleteMe = false;
484// break;
485 continue;
486 }
487
488 // a text tag is NOT enough to spare this container
489 else if ( tag == tagText )
490 {
491 continue;
492 }
493
494 // what's left are non-empty containers! *don't* delete us in this
495 // case (at this position we can be *sure* that the container is
496 // *not* empty, as the recursive call for it was in the first loop
497 // which deleted the element in case the call returned "true"
498 else
499 {
500 deleteMe = false;
501 break;
502 }
503 }
504
505 return deleteMe;
506}
507
508QDomElement KXMLGUIClient::findMatchingElement( const QDomElement &base, const QDomElement &additive )
509{
510 static const QString &tagAction = KGlobal::staticQString( "Action" );
511 static const QString &tagMergeLocal = KGlobal::staticQString( "MergeLocal" );
512 static const QString &attrName = KGlobal::staticQString( "name" );
513
514 QDomElement e = additive.firstChild().toElement();
515 for ( ; !e.isNull(); e = e.nextSibling().toElement() )
516 {
517 // skip all action and merge tags as we will never use them
518 if ( ( e.tagName() == tagAction ) || ( e.tagName() == tagMergeLocal ) )
519 {
520 continue;
521 }
522
523 // now see if our tags are equivalent
524 if ( ( e.tagName() == base.tagName() ) &&
525 ( e.attribute( attrName ) == base.attribute( attrName ) ) )
526 {
527 return e;
528 }
529 }
530
531 // nope, return a (now) null element
532 return e;
533}
534
535void KXMLGUIClient::conserveMemory()
536{
537 d->m_doc = QDomDocument();
538 d->m_buildDocument = QDomDocument();
539}
540
541void KXMLGUIClient::setXMLGUIBuildDocument( const QDomDocument &doc )
542{
543 d->m_buildDocument = doc;
544}
545
546QDomDocument KXMLGUIClient::xmlguiBuildDocument() const
547{
548 return d->m_buildDocument;
549}
550*/
551
552/*US
553void KXMLGUIClient::setFactory( KXMLGUIFactory *factory )
554{
555 d->m_factory = factory;
556}
557
558KXMLGUIFactory *KXMLGUIClient::factory() const
559{
560 return d->m_factory;
561}
562*/
563KXMLGUIClient *KXMLGUIClient::parentClient() const
564{
565 return d->m_parent;
566}
567
568void KXMLGUIClient::insertChildClient( KXMLGUIClient *child )
569{
570 if ( child->d->m_parent )
571 child->d->m_parent->removeChildClient( child );
572 d->m_children.append( child );
573 child->d->m_parent = this;
574}
575
576void KXMLGUIClient::removeChildClient( KXMLGUIClient *child )
577{
578 assert( d->m_children.containsRef( child ) );
579 d->m_children.removeRef( child );
580 child->d->m_parent = 0;
581}
582
583/*bool KXMLGUIClient::addSuperClient( KXMLGUIClient *super )
584{
585 if ( d->m_supers.contains( super ) )
586 return false;
587 d->m_supers.append( super );
588 return true;
589}*/
590
591const QPtrList<KXMLGUIClient> *KXMLGUIClient::childClients()
592{
593 return &d->m_children;
594}
595/*US
596void KXMLGUIClient::setClientBuilder( KXMLGUIBuilder *builder )
597{
598 d->m_builder = builder;
599 if ( builder )
600 builder->setBuilderInstance( instance() );
601}
602
603KXMLGUIBuilder *KXMLGUIClient::clientBuilder() const
604{
605 return d->m_builder;
606}
607*/
608
609void KXMLGUIClient::plugActionList( const QString &name, const QPtrList<KAction> &actionList )
610{
611/*US
612 if ( !d->m_factory )
613 return;
614
615 d->m_factory->plugActionList( this, name, actionList );
616*/
617}
618
619void KXMLGUIClient::unplugActionList( const QString &name )
620{
621/*US
622 if ( !d->m_factory )
623 return;
624
625 d->m_factory->unplugActionList( this, name );
626*/
627}
628
629/*US
630QString KXMLGUIClient::findMostRecentXMLFile( const QStringList &files, QString &doc )
631{
632
633 QValueList<DocStruct> allDocuments;
634
635 QStringList::ConstIterator it = files.begin();
636 QStringList::ConstIterator end = files.end();
637 for (; it != end; ++it )
638 {
639 //kdDebug() << "KXMLGUIClient::findMostRecentXMLFile " << *it << endl;
640 QString data = KXMLGUIFactory::readConfigFile( *it );
641 DocStruct d;
642 d.file = *it;
643 d.data = data;
644 allDocuments.append( d );
645 }
646
647 QValueList<DocStruct>::Iterator best = allDocuments.end();
648 uint bestVersion = 0;
649
650 QValueList<DocStruct>::Iterator docIt = allDocuments.begin();
651 QValueList<DocStruct>::Iterator docEnd = allDocuments.end();
652 for (; docIt != docEnd; ++docIt )
653 {
654 QString versionStr = findVersionNumber( (*docIt).data );
655 if ( versionStr.isEmpty() )
656 continue;
657
658 bool ok = false;
659 uint version = versionStr.toUInt( &ok );
660 if ( !ok )
661 continue;
662 //kdDebug() << "FOUND VERSION " << version << endl;
663
664 if ( version > bestVersion )
665 {
666 best = docIt;
667 //kdDebug() << "best version is now " << version << endl;
668 bestVersion = version;
669 }
670 }
671
672 if ( best != docEnd )
673 {
674 if ( best != allDocuments.begin() )
675 {
676 QValueList<DocStruct>::Iterator local = allDocuments.begin();
677
678 // load the local document and extract the action properties
679 QDomDocument document;
680 document.setContent( (*local).data );
681
682 ActionPropertiesMap properties = extractActionProperties( document );
683
684 // in case the document has a ActionProperties section
685 // we must not delete it but copy over the global doc
686 // to the local and insert the ActionProperties section
687 if ( !properties.isEmpty() )
688 {
689 // now load the global one with the higher version number
690 // into memory
691 document.setContent( (*best).data );
692 // and store the properties in there
693 storeActionProperties( document, properties );
694
695 (*local).data = document.toString();
696 // make sure we pick up the new local doc, when we return later
697 best = local;
698
699 // write out the new version of the local document
700 QFile f( (*local).file );
701 if ( f.open( IO_WriteOnly ) )
702 {
703 QCString utf8data = (*local).data.utf8();
704 f.writeBlock( utf8data.data(), utf8data.length() );
705 f.close();
706 }
707 }
708 else
709 {
710 QString f = (*local).file;
711 QString backup = f + QString::fromLatin1( ".backup" );
712 QDir dir;
713 dir.rename( f, backup );
714 }
715 }
716 doc = (*best).data;
717 return (*best).file;
718 }
719 else if ( files.count() > 0 )
720 {
721 //kdDebug() << "returning first one..." << endl;
722 doc = (*allDocuments.begin()).data;
723 return (*allDocuments.begin()).file;
724 }
725
726 return QString::null;
727}
728
729
730
731QString KXMLGUIClient::findVersionNumber( const QString &xml )
732{
733 enum { ST_START, ST_AFTER_OPEN, ST_AFTER_GUI,
734 ST_EXPECT_VERSION, ST_VERSION_NUM} state = ST_START;
735 for (unsigned int pos = 0; pos < xml.length(); pos++)
736 {
737 switch (state)
738 {
739 case ST_START:
740 if (xml[pos] == '<')
741 state = ST_AFTER_OPEN;
742 break;
743 case ST_AFTER_OPEN:
744 {
745 //Jump to gui..
746 int guipos = xml.find("gui", pos, false);
747 if (guipos == -1)
748 return QString::null; //Reject
749
750 pos = guipos + 2; //Position at i, so we're moved ahead to the next character by the ++;
751 state = ST_AFTER_GUI;
752 break;
753 }
754 case ST_AFTER_GUI:
755 state = ST_EXPECT_VERSION;
756 break;
757 case ST_EXPECT_VERSION:
758 {
759 int verpos = xml.find("version=\"", pos, false );
760 if (verpos == -1)
761 return QString::null; //Reject
762
763 pos = verpos + 8; //v = 0, e = +1, r = +2, s = +3 , i = +4, o = +5, n = +6, = = +7, " = + 8
764 state = ST_VERSION_NUM;
765 break;
766 }
767 case ST_VERSION_NUM:
768 {
769 unsigned int endpos;
770 for (endpos = pos; endpos < xml.length(); endpos++)
771 {
772 if (xml[endpos].unicode() >= '0' && xml[endpos].unicode() <= '9')
773 continue; //Number..
774 if (xml[endpos].unicode() == '"') //End of parameter
775 break;
776 else //This shouldn't be here..
777 {
778 endpos = xml.length();
779 }
780 }
781
782 if (endpos != pos && endpos < xml.length() )
783 {
784 QString matchCandidate = xml.mid(pos, endpos - pos); //Don't include " ".
785 return matchCandidate;
786 }
787
788 state = ST_EXPECT_VERSION; //Try to match a well-formed version..
789 break;
790 } //case..
791 } //switch
792 } //for
793
794 return QString::null;
795}
796
797KXMLGUIClient::ActionPropertiesMap KXMLGUIClient::extractActionProperties( const QDomDocument &doc )
798{
799 ActionPropertiesMap properties;
800
801 QDomElement actionPropElement = doc.documentElement().namedItem( "ActionProperties" ).toElement();
802
803 if ( actionPropElement.isNull() )
804 return properties;
805
806 QDomNode n = actionPropElement.firstChild();
807 for (; !n.isNull(); n = n.nextSibling() )
808 {
809 QDomElement e = n.toElement();
810 if ( e.isNull() )
811 continue;
812
813 if ( e.tagName().lower() != "action" )
814 continue;
815
816 QString actionName = e.attribute( "name" );
817
818 if ( actionName.isEmpty() )
819 continue;
820
821 QMap<QString, QMap<QString, QString> >::Iterator propIt = properties.find( actionName );
822 if ( propIt == properties.end() )
823 propIt = properties.insert( actionName, QMap<QString, QString>() );
824
825 QDomNamedNodeMap attributes = e.attributes();
826 for ( uint i = 0; i < attributes.length(); ++i )
827 {
828 QDomAttr attr = attributes.item( i ).toAttr();
829
830 if ( attr.isNull() )
831 continue;
832
833 QString name = attr.name();
834
835 if ( name == "name" || name.isEmpty() )
836 continue;
837
838 (*propIt)[ name ] = attr.value();
839 }
840
841 }
842
843 return properties;
844}
845
846void KXMLGUIClient::storeActionProperties( QDomDocument &doc, const ActionPropertiesMap &properties )
847{
848 QDomElement actionPropElement = doc.documentElement().namedItem( "ActionProperties" ).toElement();
849
850 if ( actionPropElement.isNull() )
851 {
852 actionPropElement = doc.createElement( "ActionProperties" );
853 doc.documentElement().appendChild( actionPropElement );
854 }
855
856 while ( !actionPropElement.firstChild().isNull() )
857 actionPropElement.removeChild( actionPropElement.firstChild() );
858
859 ActionPropertiesMap::ConstIterator it = properties.begin();
860 ActionPropertiesMap::ConstIterator end = properties.end();
861 for (; it != end; ++it )
862 {
863 QDomElement action = doc.createElement( "Action" );
864 action.setAttribute( "name", it.key() );
865 actionPropElement.appendChild( action );
866
867 QMap<QString, QString> attributes = (*it);
868 QMap<QString, QString>::ConstIterator attrIt = attributes.begin();
869 QMap<QString, QString>::ConstIterator attrEnd = attributes.end();
870 for (; attrIt != attrEnd; ++attrIt )
871 action.setAttribute( attrIt.key(), attrIt.data() );
872 }
873}
874*/
875
876void KXMLGUIClient::addStateActionEnabled(const QString& state,
877 const QString& action)
878{
879 StateChange stateChange = getActionsToChangeForState(state);
880
881 stateChange.actionsToEnable.append( action );
882 //kdDebug() << "KXMLGUIClient::addStateActionEnabled( " << state << ", " << action << ")" << endl;
883
884 m_actionsStateMap.replace( state, stateChange );
885}
886
887
888void KXMLGUIClient::addStateActionDisabled(const QString& state,
889 const QString& action)
890{
891 StateChange stateChange = getActionsToChangeForState(state);
892
893 stateChange.actionsToDisable.append( action );
894 //kdDebug() << "KXMLGUIClient::addStateActionDisabled( " << state << ", " << action << ")" << endl;
895
896 m_actionsStateMap.replace( state, stateChange );
897}
898
899
900KXMLGUIClient::StateChange KXMLGUIClient::getActionsToChangeForState(const QString& state)
901{
902 return m_actionsStateMap[state];
903}
904
905
906void KXMLGUIClient::stateChanged(const QString &newstate, KXMLGUIClient::ReverseStateChange reverse)
907{
908 StateChange stateChange = getActionsToChangeForState(newstate);
909
910 bool setTrue = (reverse == StateNoReverse);
911 bool setFalse = !setTrue;
912
913 // Enable actions which need to be enabled...
914 //
915 for ( QStringList::Iterator it = stateChange.actionsToEnable.begin();
916 it != stateChange.actionsToEnable.end(); ++it ) {
917
918 KAction *action = actionCollection()->action((*it).latin1());
919 if (action) action->setEnabled(setTrue);
920 }
921
922 // and disable actions which need to be disabled...
923 //
924 for ( QStringList::Iterator it = stateChange.actionsToDisable.begin();
925 it != stateChange.actionsToDisable.end(); ++it ) {
926
927 KAction *action = actionCollection()->action((*it).latin1());
928 if (action) action->setEnabled(setFalse);
929 }
930
931}
932/*US
933void KXMLGUIClient::beginXMLPlug( QWidget *w )
934{
935 actionCollection()->beginXMLPlug( w );
936 QPtrListIterator<KXMLGUIClient> childIt( d->m_children );
937 for (; childIt.current(); ++childIt )
938 childIt.current()->actionCollection()->beginXMLPlug( w );
939}
940
941void KXMLGUIClient::endXMLPlug()
942{
943 actionCollection()->endXMLPlug();
944 QPtrListIterator<KXMLGUIClient> childIt( d->m_children );
945 for (; childIt.current(); ++childIt )
946 childIt.current()->actionCollection()->endXMLPlug();
947}
948
949void KXMLGUIClient::prepareXMLUnplug( QWidget * )
950{
951 actionCollection()->prepareXMLUnplug();
952 QPtrListIterator<KXMLGUIClient> childIt( d->m_children );
953 for (; childIt.current(); ++childIt )
954 childIt.current()->actionCollection()->prepareXMLUnplug();
955}
956*/
957void KXMLGUIClient::virtual_hook( int, void* )
958{ /*BASE::virtual_hook( id, data );*/ }
diff --git a/microkde/kdeui/kxmlguiclient.h b/microkde/kdeui/kxmlguiclient.h
new file mode 100644
index 0000000..cd74c8e
--- a/dev/null
+++ b/microkde/kdeui/kxmlguiclient.h
@@ -0,0 +1,361 @@
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
3 Copyright (C) 2000 Kurt Granroth <granroth@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
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., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18*/
19#ifndef _KXMLGUICLIENT_H
20#define _KXMLGUICLIENT_H
21
22
23//US #include <qdom.h>
24#include <qptrlist.h>
25#include <qmap.h>
26#include <qstringlist.h>
27
28class QWidget;
29class KAction;
30class KActionCollection;
31class KInstance;
32
33class KXMLGUIClientPrivate;
34class KXMLGUIFactory;
35class KXMLGUIBuilder;
36
37/**
38 *
39 * A KXMLGUIClient can be used with @ref KXMLGUIFactory to create a
40 * GUI from actions and an XML document, and can be dynamically merged
41 * with other KXMLGUIClients.
42 */
43class KXMLGUIClient
44{
45 friend class KEditToolbarWidget; // for setXMLFile(3 args)
46public:
47 /**
48 * Constructs a KXMLGUIClient which can be used with a
49 * @ref KXMLGUIFactory to create a GUI from actions and an XML document, and
50 * which can be dynamically merged with other KXMLGUIClients.
51 */
52 KXMLGUIClient();
53
54 /**
55 * Constructs a KXMLGUIClient which can be used with a @ref KXMLGUIFactory
56 * to create a GUI from actions and an XML document,
57 * and which can be dynamically merged with other KXMLGUIClients.
58 *
59 * This constructor takes an additional @p parent argument, which makes
60 * the client a child client of the parent.
61 *
62 * Child clients are automatically added to the GUI if the parent is added.
63 *
64 */
65 KXMLGUIClient( KXMLGUIClient *parent );
66
67 /**
68 * Destructs the KXMLGUIClient.
69 */
70 virtual ~KXMLGUIClient();
71
72 /**
73 * Retrieves an action of the client by name. If not found, it looks in its child clients.
74 * This method is provided for convenience, as it uses @ref #actionCollection()
75 * to get the action object.
76 */
77 KAction* action( const char* name ) const;
78
79 /**
80 * Retrieves an action for a given @ref QDomElement. The default
81 * implementation uses the "name" attribute to query the action
82 * object via the other action() method.
83 */
84//US virtual KAction *action( const QDomElement &element ) const;
85
86 /**
87 * Retrieves the entire action collection for the GUI client
88 */
89 virtual KActionCollection* actionCollection() const;
90
91 /**
92 * @return The instance (@ref KInstance) for this part.
93 */
94//US virtual KInstance *instance() const;
95
96 /**
97 * @return The parsed XML in a @ref QDomDocument, set by @ref
98 * setXMLFile() or @ref setXML().
99 * This document describes the layout of the GUI.
100 */
101//US virtual QDomDocument domDocument() const;
102
103 /**
104 * This will return the name of the XML file as set by @ref #setXMLFile().
105 * If @ref #setXML() is used directly, then this will return NULL.
106 *
107 * The filename that this returns is obvious for components as each
108 * component has exactly one XML file. In non-components, however,
109 * there are usually two: the global file and the local file. This
110 * function doesn't really care about that, though. It will always
111 * return the last XML file set. This, in almost all cases, will
112 * be the local XML file.
113 *
114 * @return The name of the XML file or QString::null
115 */
116//US virtual QString xmlFile() const;
117
118//US virtual QString localXMLFile() const;
119
120 /**
121 * @internal
122 */
123//US void setXMLGUIBuildDocument( const QDomDocument &doc );
124 /**
125 * @internal
126 */
127//US QDomDocument xmlguiBuildDocument() const;
128
129 /**
130 * This method is called by the @ref KXMLGUIFactory as soon as the client
131 * is added to the KXMLGUIFactory's GUI.
132 */
133//US void setFactory( KXMLGUIFactory *factory );
134 /**
135 * Retrieves a pointer to the @ref KXMLGUIFactory this client is
136 * associated with (will return 0L if the client's GUI has not been built
137 * by a KXMLGUIFactory.
138 */
139//US KXMLGUIFactory *factory() const;
140
141 /**
142 * KXMLGUIClients can form a simple child/parent object tree. This
143 * method returns a pointer to the parent client or 0L if it has no
144 * parent client assigned.
145 */
146 KXMLGUIClient *parentClient() const;
147
148 /**
149 * Use this method to make a client a child client of another client.
150 * Usually you don't need to call this method, as it is called
151 * automatically when using the second constructor, which takes a
152 * arent argument.
153 */
154 void insertChildClient( KXMLGUIClient *child );
155
156 /**
157 * Removes the given @p child from the client's children list.
158 */
159 void removeChildClient( KXMLGUIClient *child );
160
161 /**
162 * Retrieves a list of all child clients.
163 */
164 const QPtrList<KXMLGUIClient> *childClients();
165
166 /**
167 * A client can have an own @ref KXMLGUIBuilder.
168 * Use this method to assign your builder instance to the client (so that the
169 * @ref KXMLGUIFactory can use it when building the client's GUI)
170 *
171 * Client specific guibuilders are useful if you want to create
172 * custom container widgets for your GUI.
173 */
174//US void setClientBuilder( KXMLGUIBuilder *builder );
175
176 /**
177 * Retrieves the client's GUI builder or 0L if no client specific
178 * builder has been assigned via @ref #setClientBuilder()
179 */
180//US KXMLGUIBuilder *clientBuilder() const;
181
182 /**
183 * Forces this client to re-read its XML resource file. This is
184 * intended to be used when you know that the resource file has
185 * changed and you will soon be rebuilding the GUI. It has no
186 * useful effect with non-KParts GUIs, so don't bother using it
187 * unless your app is component based.
188 */
189//US void reloadXML();
190
191 /**
192 * ActionLists are a way for XMLGUI to support dynamic lists of
193 * actions. E.g. if you are writing a file manager, and there is a
194 * menu file whose contents depend on the mimetype of the file that
195 * is selected, then you can achieve this using ActionLists. It
196 * works as follows:
197 * In your xxxui.rc file ( the one that you set in @ref setXMLFile()
198 * ), you put an <ActionList name="xxx"> tag. E.g.
199 * \verbatim
200 * <kpartgui name="xxx_part" version="1">
201 * <MenuBar>
202 * <Menu name="file">
203 * ... <!-- some useful actions-->
204 * <ActionList name="xxx_file_actionlist" />
205 * ... <!-- even more useful actions-->
206 * </Menu>
207 * ...
208 * </MenuBar>
209 * </kpartgui>
210 * \endverbatim
211 *
212 * This tag will get expanded to a list of actions. In the example
213 * above ( a file manager with a dynamic file menu ), you would call
214 * \code
215 * QPtrList<KAction> file_actions;
216 * for( ... )
217 * if( ... )
218 * file_actions.append( cool_action );
219 * unplugActionList( "xxx_file_actionlist" );
220 * plugActionList( "xxx_file_actionlist", file_actions );
221 * \endcode
222 * every time a file is selected, unselected or ...
223 *
224 * \note You should not call createGUI() after calling this
225 * function. In fact, that would remove the newly added
226 * actionlists again...
227 * \note Forgetting to call unplugActionList() before
228 * plugActionList() would leave the previous actions in the
229 * menu too..
230 */
231 void plugActionList( const QString &name, const QPtrList<KAction> &actionList );
232
233 /**
234 * The complement of \ref plugActionList() ...
235 */
236 void unplugActionList( const QString &name );
237
238//US static QString findMostRecentXMLFile( const QStringList &files, QString &doc );
239
240 void addStateActionEnabled(const QString& state, const QString& action);
241
242 void addStateActionDisabled(const QString& state, const QString& action);
243
244 enum ReverseStateChange { StateNoReverse, StateReverse };
245 struct StateChange
246 {
247 QStringList actionsToEnable;
248 QStringList actionsToDisable;
249 };
250
251 StateChange getActionsToChangeForState(const QString& state);
252
253 /// @since 3.1
254//US void beginXMLPlug( QWidget * );
255 /// @since 3.1
256//US void endXMLPlug();
257 /// @since 3.1
258//US void prepareXMLUnplug( QWidget * );
259
260protected:
261 /**
262 * Returns true if client was added to super client list.
263 * Returns false if client was already in list.
264 */
265 //bool addSuperClient( KXMLGUIClient * );
266
267 /**
268 * Sets the instance (@ref KInstance) for this part.
269 *
270 * Call this first in the inherited class constructor.
271 * (At least before @ref setXMLFile().)
272 */
273//US virtual void setInstance( KInstance *instance );
274
275 /**
276 * Sets the name of the rc file containing the XML for the part.
277 *
278 * Call this in the Part-inherited class constructor.
279 *
280 * @param file Either an absolute path for the file, or simply the
281 * filename, which will then be assumed to be installed
282 * in the "data" resource, under a directory named like
283 * the instance.
284 * @param setXML Specify whether to call setXML. Default is true.
285 * and the DOM document at once.
286 **/
287//US virtual void setXMLFile( const QString& file, bool merge = false, bool setXMLDoc = true );
288
289//US virtual void setLocalXMLFile( const QString &file );
290
291 /**
292 * Sets the XML for the part.
293 *
294 * Call this in the Part-inherited class constructor if you
295 * don't call @ref setXMLFile().
296 **/
297//US virtual void setXML( const QString &document, bool merge = false );
298
299 /**
300 * Sets the Document for the part, describing the layout of the GUI.
301 *
302 * Call this in the Part-inherited class constructor if you don't call
303 * @ref setXMLFile or @ref setXML .
304 */
305//US virtual void setDOMDocument( const QDomDocument &document, bool merge = false );
306
307 /**
308 * This function will attempt to give up some memory after the GUI
309 * is built. It should never be used in apps where the GUI may be
310 * rebuilt at some later time (components, for instance).
311 */
312//US virtual void conserveMemory();
313
314 /**
315 * Actions can collectively be assigned a "State". To accomplish this
316 * the respective actions are tagged as <enable> or <disable> in
317 * a <State> </State> group of the XMLfile. During program execution the
318 * programmer can call stateChanged() to set actions to a defined state.
319 *
320 * @param newstate Name of a State in the XMLfile.
321 * @param reverse If the flag reverse is set to StateReverse, the State is reversed.
322 * (actions to be enabled will be disabled and action to be disabled will be enabled)
323 * Default is reverse=false.
324 */
325 virtual void stateChanged(const QString &newstate, ReverseStateChange reverse = StateNoReverse);
326
327 // Use this one for KDE 4.0
328 //virtual void stateChanged(const QString &newstate, bool reverse = false);
329
330private:
331/*US
332 struct DocStruct
333 {
334 QString file;
335 QString data;
336 };
337
338 bool mergeXML( QDomElement &base, const QDomElement &additive,
339 KActionCollection *actionCollection );
340
341 QDomElement findMatchingElement( const QDomElement &base,
342 const QDomElement &additive );
343*/
344 typedef QMap<QString, QMap<QString, QString> > ActionPropertiesMap;
345
346//US static ActionPropertiesMap extractActionProperties( const QDomDocument &doc );
347
348//US static void storeActionProperties( QDomDocument &doc, const ActionPropertiesMap &properties );
349
350//US static QString findVersionNumber( const QString &_xml );
351
352 // Actions to enable/disable on a state change
353 QMap<QString,StateChange> m_actionsStateMap;
354
355protected:
356 virtual void virtual_hook( int id, void* data );
357private:
358 KXMLGUIClientPrivate *d;
359};
360
361#endif