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

kdeui

  • kdeui
ktoolbar.cpp
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., 51 Franklin Street, Fifth Floor,
23  Boston, MA 02110-1301, USA.
24 */
25 
26 #include <config.h>
27 
28 #ifdef KDE_USE_FINAL
29 #undef Always
30 #include <tqdockwindow.h>
31 #endif
32 
33 #include <string.h>
34 
35 #include <tqpainter.h>
36 #include <tqtooltip.h>
37 #include <tqdrawutil.h>
38 #include <tqstring.h>
39 #include <tqrect.h>
40 #include <tqobjectlist.h>
41 #include <tqtimer.h>
42 #include <tqstyle.h>
43 #include <tqlayout.h>
44 
45 #include <ktoolbar.h>
46 #include <kmainwindow.h>
47 #include <klineedit.h>
48 #include <kseparator.h>
49 #include <klocale.h>
50 #include <kapplication.h>
51 #include <kaction.h>
52 #include <kstdaction.h>
53 #include <kglobal.h>
54 #include <kconfig.h>
55 #include <kiconloader.h>
56 #include <kcombobox.h>
57 #include <kpopupmenu.h>
58 #include <kanimwidget.h>
59 #include <kedittoolbar.h>
60 #include <kipc.h>
61 #include <kwin.h>
62 #include <kdebug.h>
63 #include <ktoolbarbutton.h>
64 
65 enum {
66  CONTEXT_TOP = 0,
67  CONTEXT_LEFT = 1,
68  CONTEXT_RIGHT = 2,
69  CONTEXT_BOTTOM = 3,
70  CONTEXT_FLOAT = 4,
71  CONTEXT_FLAT = 5,
72  CONTEXT_ICONS = 6,
73  CONTEXT_TEXT = 7,
74  CONTEXT_TEXTRIGHT = 8,
75  CONTEXT_TEXTUNDER = 9,
76  CONTEXT_ICONSIZES = 50 // starting point for the icon size list, put everything else before
77 };
78 
79 class KToolBarPrivate
80 {
81 public:
82  KToolBarPrivate() {
83  m_iconSize = 0;
84  m_iconText = KToolBar::IconOnly;
85  m_highlight = true;
86  m_transparent = true;
87  m_honorStyle = false;
88 
89  m_enableContext = true;
90 
91  m_parent = NULL;
92  m_xmlguiClient = 0;
93 
94  oldPos = TQt::DockUnmanaged;
95 
96  modified = m_isHorizontal = positioned = false;
97 
98  IconSizeDefault = 0;
99  IconTextDefault = "IconOnly";
100 
101  NewLineDefault = false;
102  OffsetDefault = 0;
103  PositionDefault = "Top";
104  HiddenDefault = false;
105  idleButtons.setAutoDelete(true);
106  }
107 
108  int m_iconSize;
109  KToolBar::IconText m_iconText;
110  bool m_highlight : 1;
111  bool m_transparent : 1;
112  bool m_honorStyle : 1;
113  bool m_isHorizontal : 1;
114  bool m_enableContext : 1;
115  bool modified : 1;
116  bool positioned : 1;
117 
118  TQWidget *m_parent;
119 
120  TQMainWindow::ToolBarDock oldPos;
121 
122  KXMLGUIClient *m_xmlguiClient;
123 
124  struct ToolBarInfo
125  {
126  ToolBarInfo() : index( -1 ), offset( -1 ), newline( false ), dock( TQt::DockTop ) {}
127  ToolBarInfo( TQt::Dock d, int i, bool n, int o ) : index( i ), offset( o ), newline( n ), dock( d ) {}
128  int index, offset;
129  bool newline;
130  TQt::Dock dock;
131  };
132 
133  ToolBarInfo toolBarInfo;
134  TQValueList<int> iconSizes;
135  TQTimer repaintTimer;
136 
137  // Default Values.
138  bool HiddenDefault;
139  int IconSizeDefault;
140  TQString IconTextDefault;
141  bool NewLineDefault;
142  int OffsetDefault;
143  TQString PositionDefault;
144 
145  TQPtrList<TQWidget> idleButtons;
146 };
147 
148 KToolBarSeparator::KToolBarSeparator(Orientation o , bool l, TQToolBar *parent,
149  const char* name )
150  :TQFrame( parent, name ), line( l )
151 {
152  connect( parent, TQT_SIGNAL(orientationChanged(Orientation)),
153  this, TQT_SLOT(setOrientation(Orientation)) );
154  setOrientation( o );
155  setBackgroundMode( parent->backgroundMode() );
156  setBackgroundOrigin( ParentOrigin );
157 }
158 
159 void KToolBarSeparator::setOrientation( Orientation o )
160 {
161  orient = o;
162  setFrameStyle( NoFrame );
163 }
164 
165 void KToolBarSeparator::drawContents( TQPainter* p )
166 {
167  if ( line ) {
168  TQStyle::SFlags flags = TQStyle::Style_Default;
169 
170  if ( orientation() == Qt::Horizontal )
171  flags = flags | TQStyle::Style_Horizontal;
172 
173  style().tqdrawPrimitive(TQStyle::PE_DockWindowSeparator, p,
174  contentsRect(), colorGroup(), flags);
175  } else {
176  TQFrame::drawContents(p);
177  }
178 }
179 
180 void KToolBarSeparator::styleChange( TQStyle& )
181 {
182  setOrientation( orient );
183 }
184 
185 TQSize KToolBarSeparator::sizeHint() const
186 {
187  int dim = style().pixelMetric( TQStyle::PM_DockWindowSeparatorExtent, this );
188  return orientation() == Qt::Vertical ? TQSize( 0, dim ) : TQSize( dim, 0 );
189 }
190 
191 TQSizePolicy KToolBarSeparator::sizePolicy() const
192 {
193  return TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum );
194 }
195 
196 KToolBar::KToolBar( TQWidget *parent, const char *name, bool honorStyle, bool readConfig )
197  : TQToolBar( TQString::fromLatin1( name ),
198  tqt_dynamic_cast<TQMainWindow*>(parent),
199  parent, false,
200  name ? name : "mainToolBar")
201 {
202  init( readConfig, honorStyle );
203 }
204 
205 KToolBar::KToolBar( TQMainWindow *parentWindow, TQMainWindow::ToolBarDock dock, bool newLine, const char *name, bool honorStyle, bool readConfig )
206  : TQToolBar( TQString::fromLatin1( name ),
207  parentWindow, dock, newLine,
208  name ? name : "mainToolBar")
209 {
210  init( readConfig, honorStyle );
211 }
212 
213 KToolBar::KToolBar( TQMainWindow *parentWindow, TQWidget *dock, bool newLine, const char *name, bool honorStyle, bool readConfig )
214  : TQToolBar( TQString::fromLatin1( name ),
215  parentWindow, dock, newLine,
216  name ? name : "mainToolBar")
217 {
218  init( readConfig, honorStyle );
219 }
220 
221 KToolBar::~KToolBar()
222 {
223  emit toolbarDestroyed();
224  delete d;
225 }
226 
227 void KToolBar::init( bool readConfig, bool honorStyle )
228 {
229  d = new KToolBarPrivate();
230 
231  setFullSize( true );
232  d->m_honorStyle = honorStyle;
233  context = 0;
234  layoutTimer = new TQTimer( this );
235  connect( layoutTimer, TQT_SIGNAL( timeout() ),
236  this, TQT_SLOT( rebuildLayout() ) );
237  connect( &(d->repaintTimer), TQT_SIGNAL( timeout() ),
238  this, TQT_SLOT( slotRepaint() ) );
239 
240  if ( kapp ) { // may be null when started inside designer
241  connect(kapp, TQT_SIGNAL(toolbarAppearanceChanged(int)), this, TQT_SLOT(slotAppearanceChanged()));
242  // request notification of changes in icon style
243  kapp->addKipcEventMask(KIPC::IconChanged);
244  connect(kapp, TQT_SIGNAL(iconChanged(int)), this, TQT_SLOT(slotIconChanged(int)));
245  }
246 
247  // finally, read in our configurable settings
248  if ( readConfig )
249  slotReadConfig();
250 
251  if ( mainWindow() )
252  connect( mainWindow(), TQT_SIGNAL( toolBarPositionChanged( TQToolBar * ) ),
253  this, TQT_SLOT( toolBarPosChanged( TQToolBar * ) ) );
254 
255  // Hack to make sure we recalculate our size when we dock.
256  connect( this, TQT_SIGNAL(placeChanged(TQDockWindow::Place)), TQT_SLOT(rebuildLayout()) );
257 }
258 
259 int KToolBar::insertButton(const TQString& icon, int id, bool enabled,
260  const TQString& text, int index, KInstance *_instance )
261 {
262  KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text, _instance );
263 
264  insertWidgetInternal( button, index, id );
265  button->setEnabled( enabled );
266  doConnections( button );
267  return index;
268 }
269 
270 
271 int KToolBar::insertButton(const TQString& icon, int id, const char *signal,
272  const TQObject *receiver, const char *slot,
273  bool enabled, const TQString& text, int index, KInstance *_instance )
274 {
275  KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text, _instance);
276  insertWidgetInternal( button, index, id );
277  button->setEnabled( enabled );
278  connect( button, signal, receiver, slot );
279  doConnections( button );
280  return index;
281 }
282 
283 
284 int KToolBar::insertButton(const TQPixmap& pixmap, int id, bool enabled,
285  const TQString& text, int index )
286 {
287  KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text);
288  insertWidgetInternal( button, index, id );
289  button->setEnabled( enabled );
290  doConnections( button );
291  return index;
292 }
293 
294 
295 int KToolBar::insertButton(const TQPixmap& pixmap, int id, const char *signal,
296  const TQObject *receiver, const char *slot,
297  bool enabled, const TQString& text,
298  int index )
299 {
300  KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text);
301  insertWidgetInternal( button, index, id );
302  button->setEnabled( enabled );
303  connect( button, signal, receiver, slot );
304  doConnections( button );
305  return index;
306 }
307 
308 
309 int KToolBar::insertButton(const TQString& icon, int id, TQPopupMenu *popup,
310  bool enabled, const TQString &text, int index )
311 {
312  KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text );
313  insertWidgetInternal( button, index, id );
314  button->setEnabled( enabled );
315  button->setPopup( popup );
316  doConnections( button );
317  return index;
318 }
319 
320 
321 int KToolBar::insertButton(const TQPixmap& pixmap, int id, TQPopupMenu *popup,
322  bool enabled, const TQString &text, int index )
323 {
324  KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text );
325  insertWidgetInternal( button, index, id );
326  button->setEnabled( enabled );
327  button->setPopup( popup );
328  doConnections( button );
329  return index;
330 }
331 
332 
333 int KToolBar::insertLined (const TQString& text, int id,
334  const char *signal,
335  const TQObject *receiver, const char *slot,
336  bool enabled ,
337  const TQString& toolTipText,
338  int size, int index )
339 {
340  KLineEdit *lined = new KLineEdit ( this, 0 );
341  if ( !toolTipText.isEmpty() )
342  TQToolTip::add( lined, toolTipText );
343  if ( size > 0 )
344  lined->setMinimumWidth( size );
345  insertWidgetInternal( lined, index, id );
346  connect( lined, signal, receiver, slot );
347  lined->setText(text);
348  lined->setEnabled( enabled );
349  return index;
350 }
351 
352 int KToolBar::insertCombo (const TQStringList &list, int id, bool writable,
353  const char *signal, const TQObject *receiver,
354  const char *slot, bool enabled,
355  const TQString& tooltiptext,
356  int size, int index,
357  TQComboBox::Policy policy )
358 {
359  KComboBox *combo = new KComboBox ( writable, this );
360 
361  insertWidgetInternal( combo, index, id );
362  combo->insertStringList (list);
363  combo->setInsertionPolicy(policy);
364  combo->setEnabled( enabled );
365  if ( size > 0 )
366  combo->setMinimumWidth( size );
367  if (!tooltiptext.isNull())
368  TQToolTip::add( combo, tooltiptext );
369 
370  if ( signal && receiver && slot )
371  connect ( combo, signal, receiver, slot );
372  return index;
373 }
374 
375 
376 int KToolBar::insertCombo (const TQString& text, int id, bool writable,
377  const char *signal, TQObject *receiver,
378  const char *slot, bool enabled,
379  const TQString& tooltiptext,
380  int size, int index,
381  TQComboBox::Policy policy )
382 {
383  KComboBox *combo = new KComboBox ( writable, this );
384  insertWidgetInternal( combo, index, id );
385  combo->insertItem (text);
386  combo->setInsertionPolicy(policy);
387  combo->setEnabled( enabled );
388  if ( size > 0 )
389  combo->setMinimumWidth( size );
390  if (!tooltiptext.isNull())
391  TQToolTip::add( combo, tooltiptext );
392  connect (combo, signal, receiver, slot);
393  return index;
394 }
395 
396 int KToolBar::insertSeparator(int index, int id)
397 {
398  TQWidget *w = new KToolBarSeparator( orientation(), false, this, "tool bar separator" );
399  insertWidgetInternal( w, index, id );
400  return index;
401 }
402 
403 int KToolBar::insertLineSeparator(int index, int id)
404 {
405  TQWidget *w = new KToolBarSeparator( orientation(), true, this, "tool bar separator" );
406  insertWidgetInternal( w, index, id );
407  return index;
408 }
409 
410 
411 int KToolBar::insertWidget(int id, int /*width*/, TQWidget *widget, int index)
412 {
413  removeWidgetInternal( widget ); // in case we already have it ?
414  insertWidgetInternal( widget, index, id );
415  return index;
416 }
417 
418 int KToolBar::insertAnimatedWidget(int id, TQObject *receiver, const char *slot,
419  const TQString& icons, int index )
420 {
421  KAnimWidget *anim = new KAnimWidget( icons, d->m_iconSize, this );
422  insertWidgetInternal( anim, index, id );
423 
424  if ( receiver )
425  connect( anim, TQT_SIGNAL(clicked()), receiver, slot);
426 
427  return index;
428 }
429 
430 KAnimWidget *KToolBar::animatedWidget( int id )
431 {
432  Id2WidgetMap::Iterator it = id2widget.find( id );
433  if ( it == id2widget.end() )
434  return 0;
435  KAnimWidget *aw = tqt_dynamic_cast<KAnimWidget *>(*it);
436  if ( aw )
437  return aw;
438  TQObjectList *l = queryList( "KAnimWidget" );
439  if ( !l || !l->first() ) {
440  delete l;
441  return 0;
442  }
443 
444  for ( TQObject *o = l->first(); o; o = l->next() ) {
445  KAnimWidget *aw = tqt_dynamic_cast<KAnimWidget *>(o);
446  if ( aw )
447  {
448  delete l;
449  return aw;
450  }
451  }
452 
453  delete l;
454  return 0;
455 }
456 
457 
458 void KToolBar::addConnection (int id, const char *signal,
459  const TQObject *receiver, const char *slot)
460 {
461  TQWidget* w = getWidget( id );
462  if ( w )
463  connect( w, signal, receiver, slot );
464 }
465 
466 void KToolBar::setItemEnabled( int id, bool enabled )
467 {
468  TQWidget* w = getWidget( id );
469  if ( w )
470  w->setEnabled( enabled );
471 }
472 
473 
474 void KToolBar::setButtonPixmap( int id, const TQPixmap& _pixmap )
475 {
476  KToolBarButton * button = getButton( id );
477  if ( button )
478  button->setPixmap( _pixmap );
479 }
480 
481 
482 void KToolBar::setButtonIcon( int id, const TQString& _icon )
483 {
484  KToolBarButton * button = getButton( id );
485  if ( button )
486  button->setIcon( _icon );
487 }
488 
489 void KToolBar::setButtonIconSet( int id, const TQIconSet& iconset )
490 {
491  KToolBarButton * button = getButton( id );
492  if ( button )
493  button->setIconSet( iconset );
494 }
495 
496 
497 void KToolBar::setDelayedPopup (int id , TQPopupMenu *_popup, bool toggle )
498 {
499  KToolBarButton * button = getButton( id );
500  if ( button )
501  button->setDelayedPopup( _popup, toggle );
502 }
503 
504 
505 void KToolBar::setAutoRepeat (int id, bool flag)
506 {
507  KToolBarButton * button = getButton( id );
508  if ( button )
509  button->setAutoRepeat( flag );
510 }
511 
512 
513 void KToolBar::setToggle (int id, bool flag )
514 {
515  KToolBarButton * button = getButton( id );
516  if ( button )
517  button->setToggle( flag );
518 }
519 
520 
521 void KToolBar::toggleButton (int id)
522 {
523  KToolBarButton * button = getButton( id );
524  if ( button )
525  button->toggle();
526 }
527 
528 
529 void KToolBar::setButton (int id, bool flag)
530 {
531  KToolBarButton * button = getButton( id );
532  if ( button )
533  button->on( flag );
534 }
535 
536 
537 bool KToolBar::isButtonOn (int id) const
538 {
539  KToolBarButton * button = const_cast<KToolBar*>( this )->getButton( id );
540  return button ? button->isOn() : false;
541 }
542 
543 
544 void KToolBar::setLinedText (int id, const TQString& text)
545 {
546  KLineEdit * lineEdit = getLined( id );
547  if ( lineEdit )
548  lineEdit->setText( text );
549 }
550 
551 
552 TQString KToolBar::getLinedText (int id) const
553 {
554  KLineEdit * lineEdit = const_cast<KToolBar*>( this )->getLined( id );
555  return lineEdit ? lineEdit->text() : TQString::null;
556 }
557 
558 
559 void KToolBar::insertComboItem (int id, const TQString& text, int index)
560 {
561  KComboBox * comboBox = getCombo( id );
562  if (comboBox)
563  comboBox->insertItem( text, index );
564 }
565 
566 void KToolBar::insertComboList (int id, const TQStringList &list, int index)
567 {
568  KComboBox * comboBox = getCombo( id );
569  if (comboBox)
570  comboBox->insertStringList( list, index );
571 }
572 
573 
574 void KToolBar::removeComboItem (int id, int index)
575 {
576  KComboBox * comboBox = getCombo( id );
577  if (comboBox)
578  comboBox->removeItem( index );
579 }
580 
581 
582 void KToolBar::setCurrentComboItem (int id, int index)
583 {
584  KComboBox * comboBox = getCombo( id );
585  if (comboBox)
586  comboBox->setCurrentItem( index );
587 }
588 
589 
590 void KToolBar::changeComboItem (int id, const TQString& text, int index)
591 {
592  KComboBox * comboBox = getCombo( id );
593  if (comboBox)
594  comboBox->changeItem( text, index );
595 }
596 
597 
598 void KToolBar::clearCombo (int id)
599 {
600  KComboBox * comboBox = getCombo( id );
601  if (comboBox)
602  comboBox->clear();
603 }
604 
605 
606 TQString KToolBar::getComboItem (int id, int index) const
607 {
608  KComboBox * comboBox = const_cast<KToolBar*>( this )->getCombo( id );
609  return comboBox ? comboBox->text( index ) : TQString::null;
610 }
611 
612 
613 KComboBox * KToolBar::getCombo(int id)
614 {
615  Id2WidgetMap::Iterator it = id2widget.find( id );
616  if ( it == id2widget.end() )
617  return 0;
618  return tqt_dynamic_cast<KComboBox *>( *it );
619 }
620 
621 
622 KLineEdit * KToolBar::getLined (int id)
623 {
624  Id2WidgetMap::Iterator it = id2widget.find( id );
625  if ( it == id2widget.end() )
626  return 0;
627  return tqt_dynamic_cast<KLineEdit *>( *it );
628 }
629 
630 
631 KToolBarButton * KToolBar::getButton (int id)
632 {
633  Id2WidgetMap::Iterator it = id2widget.find( id );
634  if ( it == id2widget.end() )
635  return 0;
636  return tqt_dynamic_cast<KToolBarButton *>( *it );
637 }
638 
639 
640 void KToolBar::alignItemRight (int id, bool right )
641 {
642  Id2WidgetMap::Iterator it = id2widget.find( id );
643  if ( it == id2widget.end() )
644  return;
645  if ( rightAligned && !right && (*it) == rightAligned )
646  rightAligned = 0;
647  if ( (*it) && right )
648  rightAligned = (*it);
649 }
650 
651 
652 TQWidget *KToolBar::getWidget (int id)
653 {
654  Id2WidgetMap::Iterator it = id2widget.find( id );
655  return ( it == id2widget.end() ) ? 0 : (*it);
656 }
657 
658 
659 void KToolBar::setItemAutoSized (int id, bool yes )
660 {
661  TQWidget *w = getWidget(id);
662  if ( w && yes )
663  setStretchableWidget( w );
664 }
665 
666 
667 void KToolBar::clear ()
668 {
669  /* Delete any idle buttons, so TQToolBar doesn't delete them itself, making a mess */
670  for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next())
671  w->blockSignals(false);
672  d->idleButtons.clear();
673 
674  TQToolBar::clear();
675  widget2id.clear();
676  id2widget.clear();
677 }
678 
679 
680 void KToolBar::removeItem(int id)
681 {
682  Id2WidgetMap::Iterator it = id2widget.find( id );
683  if ( it == id2widget.end() )
684  {
685  kdDebug(220) << name() << " KToolBar::removeItem item " << id << " not found" << endl;
686  return;
687  }
688  TQWidget * w = (*it);
689  id2widget.remove( id );
690  widget2id.remove( w );
691  widgets.removeRef( w );
692  delete w;
693 }
694 
695 
696 void KToolBar::removeItemDelayed(int id)
697 {
698  Id2WidgetMap::Iterator it = id2widget.find( id );
699  if ( it == id2widget.end() )
700  {
701  kdDebug(220) << name() << " KToolBar::removeItem item " << id << " not found" << endl;
702  return;
703  }
704  TQWidget * w = (*it);
705  id2widget.remove( id );
706  widget2id.remove( w );
707  widgets.removeRef( w );
708 
709  w->blockSignals(true);
710  d->idleButtons.append(w);
711  layoutTimer->start( 50, true );
712 }
713 
714 
715 void KToolBar::hideItem (int id)
716 {
717  TQWidget *w = getWidget(id);
718  if ( w )
719  w->hide();
720 }
721 
722 
723 void KToolBar::showItem (int id)
724 {
725  TQWidget *w = getWidget(id);
726  if ( w )
727  w->show();
728 }
729 
730 
731 int KToolBar::itemIndex (int id)
732 {
733  TQWidget *w = getWidget(id);
734  return w ? widgets.findRef(w) : -1;
735 }
736 
737 int KToolBar::idAt (int index)
738 {
739  TQWidget *w = widgets.at(index);
740  return widget2id[w];
741 }
742 
743 void KToolBar::setFullSize(bool flag )
744 {
745  setHorizontalStretchable( flag );
746  setVerticalStretchable( flag );
747 }
748 
749 
750 bool KToolBar::fullSize() const
751 {
752  return isHorizontalStretchable() || isVerticalStretchable();
753 }
754 
755 
756 void KToolBar::enableMoving(bool flag )
757 {
758  setMovingEnabled(flag);
759 }
760 
761 
762 void KToolBar::setBarPos (BarPosition bpos)
763 {
764  if ( !mainWindow() )
765  return;
766  mainWindow()->moveDockWindow( this, (Dock)bpos );
767  //kdDebug(220) << name() << " setBarPos dockWindowIndex=" << dockWindowIndex() << endl;
768 }
769 
770 
771 KToolBar::BarPosition KToolBar::barPos() const
772 {
773  if ( !this->mainWindow() )
774  return place() == TQDockWindow::InDock ? KToolBar::Top : KToolBar::Floating;
775  Dock dock;
776  int dm1, dm2;
777  bool dm3;
778  this->mainWindow()->getLocation( (TQToolBar*)this, dock, dm1, dm3, dm2 );
779  if ( dock == DockUnmanaged ) {
780  return (KToolBar::BarPosition)DockTop;
781  }
782  return (BarPosition)dock;
783 }
784 
785 
786 bool KToolBar::enable(BarStatus stat)
787 {
788  bool mystat = isVisible();
789 
790  if ( (stat == Toggle && mystat) || stat == Hide )
791  hide();
792  else
793  show();
794 
795  return isVisible() == mystat;
796 }
797 
798 
799 void KToolBar::setMaxHeight ( int h )
800 {
801  setMaximumHeight( h );
802 }
803 
804 int KToolBar::maxHeight()
805 {
806  return maximumHeight();
807 }
808 
809 
810 void KToolBar::setMaxWidth (int dw)
811 {
812  setMaximumWidth( dw );
813 }
814 
815 
816 int KToolBar::maxWidth()
817 {
818  return maximumWidth();
819 }
820 
821 
822 void KToolBar::setTitle (const TQString& _title)
823 {
824  setLabel( _title );
825 }
826 
827 
828 void KToolBar::enableFloating (bool )
829 {
830 }
831 
832 
833 void KToolBar::setIconText(IconText it)
834 {
835  setIconText( it, true );
836 }
837 
838 
839 void KToolBar::setIconText(IconText icontext, bool update)
840 {
841  bool doUpdate=false;
842 
843  if (icontext != d->m_iconText) {
844  d->m_iconText = icontext;
845  doUpdate=true;
846  //kdDebug(220) << name() << " icontext has changed, doUpdate=true" << endl;
847  }
848  else {
849  //kdDebug(220) << name() << " icontext hasn't changed, doUpdate=false" << endl;
850  }
851 
852  if (!update)
853  return;
854 
855  if (doUpdate)
856  doModeChange(); // tell buttons what happened
857 
858  // ugly hack to force a TQMainWindow::triggerLayout( true )
859  TQMainWindow *mw = mainWindow();
860  if ( mw ) {
861  mw->setUpdatesEnabled( false );
862 // mw->setToolBarsMovable( !mw->toolBarsMovable() ); // Old way
863 // mw->setToolBarsMovable( !mw->toolBarsMovable() );
864  mw->setCentralWidget(mw->centralWidget()); // This is a faster hack
865  mw->setUpdatesEnabled( true );
866  }
867 }
868 
869 
870 KToolBar::IconText KToolBar::iconText() const
871 {
872  return d->m_iconText;
873 }
874 
875 
876 void KToolBar::setIconSize(int size)
877 {
878  setIconSize( size, true );
879 }
880 
881 void KToolBar::setIconSize(int size, bool update)
882 {
883  bool doUpdate=false;
884 
885  if ( size != d->m_iconSize ) {
886  d->m_iconSize = size;
887  doUpdate=true;
888  }
889 
890  if (!update)
891  return;
892 
893  if (doUpdate)
894  doModeChange(); // tell buttons what happened
895 
896  // ugly hack to force a TQMainWindow::triggerLayout( true )
897  if ( mainWindow() ) {
898  TQMainWindow *mw = mainWindow();
899  mw->setUpdatesEnabled( false );
900 // mw->setToolBarsMovable( !mw->toolBarsMovable() ); // Old way
901 // mw->setToolBarsMovable( !mw->toolBarsMovable() );
902  mw->setCentralWidget(mw->centralWidget()); // This is a faster hack
903  mw->setUpdatesEnabled( true );
904  }
905 }
906 
907 int KToolBar::iconSize() const
908 {
909  if ( !d->m_iconSize ) // default value?
910  return iconSizeDefault();
911 
912  return d->m_iconSize;
913 }
914 
915 int KToolBar::iconSizeDefault() const
916 {
917  if (!::qstrcmp(name(), "mainToolBar"))
918  return KGlobal::iconLoader()->currentSize(KIcon::MainToolbar);
919 
920  return KGlobal::iconLoader()->currentSize(KIcon::Toolbar);
921 }
922 
923 void KToolBar::setEnableContextMenu(bool enable )
924 {
925  d->m_enableContext = enable;
926 }
927 
928 
929 bool KToolBar::contextMenuEnabled() const
930 {
931  return d->m_enableContext;
932 }
933 
934 
935 void KToolBar::setItemNoStyle(int id, bool no_style )
936 {
937  KToolBarButton * button = getButton( id );
938  if (button)
939  button->setNoStyle( no_style );
940 }
941 
942 
943 void KToolBar::setFlat (bool flag)
944 {
945  if ( !mainWindow() )
946  return;
947  if ( flag )
948  mainWindow()->moveDockWindow( this, DockMinimized );
949  else
950  mainWindow()->moveDockWindow( this, DockTop );
951  // And remember to save the new look later
952  KMainWindow *kmw = tqt_dynamic_cast<KMainWindow *>(mainWindow());
953  if ( kmw )
954  kmw->setSettingsDirty();
955 }
956 
957 
958 int KToolBar::count() const
959 {
960  return id2widget.count();
961 }
962 
963 
964 void KToolBar::saveState()
965 {
966  // first, try to save to the xml file
967  if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() ) {
968  //kdDebug(220) << name() << " saveState: saving to " << d->m_xmlguiClient->xmlFile() << endl;
969  TQString barname(!::qstrcmp(name(), "unnamed") ? "mainToolBar" : name());
970  // try to find our toolbar
971  d->modified = false;
972  // go down one level to get to the right tags
973  TQDomElement current;
974  for( TQDomNode n = d->m_xmlguiClient->domDocument().documentElement().firstChild();
975  !n.isNull(); n = n.nextSibling()) {
976  current = n.toElement();
977 
978  if ( current.tagName().lower() != "toolbar" )
979  continue;
980 
981  TQString curname(current.attribute( "name" ));
982 
983  if ( curname == barname ) {
984  saveState( current );
985  break;
986  }
987  }
988  // if we didn't make changes, then just return
989  if ( !d->modified )
990  return;
991 
992  // now we load in the (non-merged) local file
993  TQString local_xml(KXMLGUIFactory::readConfigFile(d->m_xmlguiClient->xmlFile(), true, d->m_xmlguiClient->instance()));
994  TQDomDocument local;
995  local.setContent(local_xml);
996 
997  // make sure we don't append if this toolbar already exists locally
998  bool just_append = true;
999 
1000  for( TQDomNode n = local.documentElement().firstChild();
1001  !n.isNull(); n = n.nextSibling()) {
1002  TQDomElement elem = n.toElement();
1003 
1004  if ( elem.tagName().lower() != "toolbar" )
1005  continue;
1006 
1007  TQString curname(elem.attribute( "name" ));
1008 
1009  if ( curname == barname ) {
1010  just_append = false;
1011  local.documentElement().replaceChild( current, elem );
1012  break;
1013  }
1014  }
1015 
1016  if (just_append)
1017  local.documentElement().appendChild( current );
1018 
1019  KXMLGUIFactory::saveConfigFile(local, d->m_xmlguiClient->localXMLFile(), d->m_xmlguiClient->instance() );
1020 
1021  return;
1022  }
1023 
1024  // if that didn't work, we save to the config file
1025  KConfig *config = KGlobal::config();
1026  saveSettings(config, TQString::null);
1027  config->sync();
1028 }
1029 
1030 TQString KToolBar::settingsGroup() const
1031 {
1032  TQString configGroup;
1033  if (!::qstrcmp(name(), "unnamed") || !::qstrcmp(name(), "mainToolBar"))
1034  configGroup = "Toolbar style";
1035  else
1036  configGroup = TQString(name()) + " Toolbar style";
1037  if ( this->mainWindow() )
1038  {
1039  configGroup.prepend(" ");
1040  configGroup.prepend( this->mainWindow()->name() );
1041  }
1042  return configGroup;
1043 }
1044 
1045 void KToolBar::saveSettings(KConfig *config, const TQString &_configGroup)
1046 {
1047  TQString configGroup = _configGroup;
1048  if (configGroup.isEmpty())
1049  configGroup = settingsGroup();
1050  //kdDebug(220) << name() << " saveSettings() group=" << _configGroup << " -> " << configGroup << endl;
1051 
1052  TQString position, icontext;
1053  int index;
1054  getAttributes( position, icontext, index );
1055 
1056  //kdDebug(220) << name() << " position=" << position << " index=" << index << " offset=" << offset() << " newLine=" << newLine() << endl;
1057 
1058  KConfigGroupSaver saver(config, configGroup);
1059 
1060  if(!config->hasDefault("Position") && position == d->PositionDefault )
1061  config->revertToDefault("Position");
1062  else
1063  config->writeEntry("Position", position);
1064 
1065  //kdDebug(220) << name() << " icontext=" << icontext << " hasDefault:" << config->hasDefault( "IconText" ) << " d->IconTextDefault=" << d->IconTextDefault << endl;
1066 
1067  if(d->m_honorStyle && icontext == d->IconTextDefault && !config->hasDefault("IconText") )
1068  {
1069  //kdDebug(220) << name() << " reverting icontext to default" << endl;
1070  config->revertToDefault("IconText");
1071  }
1072  else
1073  {
1074  //kdDebug(220) << name() << " writing icontext " << icontext << endl;
1075  config->writeEntry("IconText", icontext);
1076  }
1077 
1078  if(!config->hasDefault("IconSize") && iconSize() == iconSizeDefault() )
1079  config->revertToDefault("IconSize");
1080  else
1081  config->writeEntry("IconSize", iconSize());
1082 
1083  if(!config->hasDefault("Hidden") && isHidden() == d->HiddenDefault )
1084  config->revertToDefault("Hidden");
1085  else
1086  config->writeEntry("Hidden", isHidden());
1087 
1088  // Note that index, unlike the other settings, depends on the other toolbars
1089  // So on the first run with a clean local config file, even the usual
1090  // hasDefault/==IndexDefault test would save the toolbar indexes
1091  // (IndexDefault was 0, whereas index is the real index in the GUI)
1092  //
1093  // Saving the whole set of indexes is necessary though. When moving only
1094  // one toolbar, if we only saved the changed indexes, the toolbars wouldn't
1095  // reappear at the same position the next time.
1096  // The whole set of indexes has to be saved.
1097  //kdDebug(220) << name() << " writing index " << index << endl;
1098  KMainWindow *kmw = tqt_dynamic_cast<KMainWindow *>(mainWindow());
1099  // don't save if there's only one toolbar
1100 
1101  // Don't use kmw->toolBarIterator() because you might
1102  // mess up someone else's iterator. Make the list on your own
1103  TQPtrList<KToolBar> toolbarList;
1104  TQPtrList<TQToolBar> lst;
1105  for ( int i = (int)TQMainWindow::DockUnmanaged; i <= (int)DockMinimized; ++i ) {
1106  lst = kmw->toolBars( (ToolBarDock)i );
1107  for ( TQToolBar *tb = lst.first(); tb; tb = lst.next() ) {
1108  if ( !tb->inherits( "KToolBar" ) )
1109  continue;
1110  toolbarList.append( (KToolBar*)tb );
1111  }
1112  }
1113  TQPtrListIterator<KToolBar> toolbarIterator( toolbarList );
1114  if ( !kmw || toolbarIterator.count() > 1 )
1115  config->writeEntry("Index", index);
1116  else
1117  config->revertToDefault("Index");
1118 
1119  if(!config->hasDefault("Offset") && offset() == d->OffsetDefault )
1120  config->revertToDefault("Offset");
1121  else
1122  config->writeEntry("Offset", offset());
1123 
1124  if(!config->hasDefault("NewLine") && newLine() == d->NewLineDefault )
1125  config->revertToDefault("NewLine");
1126  else
1127  config->writeEntry("NewLine", newLine());
1128 }
1129 
1130 
1131 void KToolBar::setXMLGUIClient( KXMLGUIClient *client )
1132 {
1133  d->m_xmlguiClient = client;
1134 }
1135 
1136 void KToolBar::setText( const TQString & txt )
1137 {
1138  setLabel( txt + " (" + kapp->caption() + ") " );
1139 }
1140 
1141 
1142 TQString KToolBar::text() const
1143 {
1144  return label();
1145 }
1146 
1147 
1148 void KToolBar::doConnections( KToolBarButton *button )
1149 {
1150  connect(button, TQT_SIGNAL(clicked(int)), this, TQT_SIGNAL( clicked( int ) ) );
1151  connect(button, TQT_SIGNAL(doubleClicked(int)), this, TQT_SIGNAL( doubleClicked( int ) ) );
1152  connect(button, TQT_SIGNAL(released(int)), this, TQT_SIGNAL( released( int ) ) );
1153  connect(button, TQT_SIGNAL(pressed(int)), this, TQT_SIGNAL( pressed( int ) ) );
1154  connect(button, TQT_SIGNAL(toggled(int)), this, TQT_SIGNAL( toggled( int ) ) );
1155  connect(button, TQT_SIGNAL(highlighted(int, bool)), this, TQT_SIGNAL( highlighted( int, bool ) ) );
1156 }
1157 
1158 void KToolBar::mousePressEvent ( TQMouseEvent *m )
1159 {
1160  if ( !mainWindow() )
1161  return;
1162  TQMainWindow *mw = mainWindow();
1163  if ( mw->toolBarsMovable() && d->m_enableContext ) {
1164  if ( m->button() == Qt::RightButton ) {
1165  TQGuardedPtr<KToolBar> guard( this );
1166  int i = contextMenu()->exec( m->globalPos(), 0 );
1167  // "Configure Toolbars" recreates toolbars, so we might not exist anymore.
1168  if ( guard )
1169  slotContextAboutToHide();
1170  switch ( i ) {
1171  case -1:
1172  return; // popup canceled
1173  case CONTEXT_LEFT:
1174  mw->moveDockWindow( this, DockLeft );
1175  break;
1176  case CONTEXT_RIGHT:
1177  mw->moveDockWindow( this, DockRight );
1178  break;
1179  case CONTEXT_TOP:
1180  mw->moveDockWindow( this, DockTop );
1181  break;
1182  case CONTEXT_BOTTOM:
1183  mw->moveDockWindow( this, DockBottom );
1184  break;
1185  case CONTEXT_FLOAT:
1186  mw->moveDockWindow( this, DockTornOff );
1187  break;
1188  case CONTEXT_FLAT:
1189  mw->moveDockWindow( this, DockMinimized );
1190  break;
1191  case CONTEXT_ICONS:
1192  setIconText( IconOnly );
1193  break;
1194  case CONTEXT_TEXTRIGHT:
1195  setIconText( IconTextRight );
1196  break;
1197  case CONTEXT_TEXT:
1198  setIconText( TextOnly );
1199  break;
1200  case CONTEXT_TEXTUNDER:
1201  setIconText( IconTextBottom );
1202  break;
1203  default:
1204  if ( i >= CONTEXT_ICONSIZES )
1205  setIconSize( i - CONTEXT_ICONSIZES );
1206  else
1207  return; // assume this was an action handled elsewhere, no need for setSettingsDirty()
1208  }
1209  KMainWindow *kmw = tqt_dynamic_cast<KMainWindow *>(mw);
1210  if ( kmw )
1211  kmw->setSettingsDirty();
1212  }
1213  }
1214 }
1215 
1216 void KToolBar::doModeChange()
1217 {
1218  for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next())
1219  w->blockSignals(false);
1220  d->idleButtons.clear();
1221 
1222  emit modechange();
1223 }
1224 
1225 void KToolBar::rebuildLayout()
1226 {
1227  for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next())
1228  w->blockSignals(false);
1229  d->idleButtons.clear();
1230 
1231  layoutTimer->stop();
1232  TQApplication::sendPostedEvents( this, TQEvent::ChildInserted );
1233  TQBoxLayout *l = boxLayout();
1234 
1235  // clear the old layout
1236  TQLayoutIterator it = l->iterator();
1237  while ( it.current() )
1238  it.deleteCurrent();
1239 
1240  for ( TQWidget *w = widgets.first(); w; w = widgets.next() ) {
1241  if ( w == rightAligned )
1242  continue;
1243  KToolBarSeparator *ktbs = tqt_dynamic_cast<KToolBarSeparator *>(w);
1244  if ( ktbs && !ktbs->showLine() ) {
1245  l->addSpacing( orientation() == Qt::Vertical ? w->sizeHint().height() : w->sizeHint().width() );
1246  w->hide();
1247  continue;
1248  }
1249  if ( tqt_dynamic_cast<TQPopupMenu *>(w) ) // w is a QPopupMenu?
1250  continue;
1251  l->addWidget( w );
1252  w->show();
1253  if ((orientation() == Qt::Horizontal) && tqt_dynamic_cast<TQLineEdit *>(w)) // w is TQLineEdit ?
1254  l->addSpacing(2); // A little bit extra spacing behind it.
1255  }
1256  if ( rightAligned ) {
1257  l->addStretch();
1258  l->addWidget( rightAligned );
1259  rightAligned->show();
1260  }
1261 
1262  if ( fullSize() ) {
1263  if ( !rightAligned )
1264  l->addStretch();
1265  if ( stretchableWidget )
1266  l->setStretchFactor( stretchableWidget, 10 );
1267  }
1268  l->invalidate();
1269  TQApplication::postEvent( this, new TQEvent( TQEvent::LayoutHint ) );
1270 }
1271 
1272 void KToolBar::childEvent( TQChildEvent *e )
1273 {
1274  if ( e->child()->isWidgetType() ) {
1275  TQWidget * w = tqt_dynamic_cast<TQWidget *>(e->child());
1276  if (!w || !(::qstrcmp( "qt_dockwidget_internal", w->name())))
1277  {
1278  TQToolBar::childEvent( e );
1279  return;
1280  }
1281  if ( e->type() == TQEvent::ChildInserted ) {
1282  if ( !tqt_dynamic_cast<TQPopupMenu *>(w)) { // e->child() is not a QPopupMenu
1283  // prevent items that have been explicitly inserted by insert*() from
1284  // being inserted again
1285  if ( !widget2id.contains( w ) )
1286  {
1287  int dummy = -1;
1288  insertWidgetInternal( w, dummy, -1 );
1289  }
1290  }
1291  } else {
1292  removeWidgetInternal( w );
1293  }
1294  if ( isVisibleTo( 0 ) )
1295  {
1296  layoutTimer->start( 50, true );
1297  TQBoxLayout *l = boxLayout();
1298 
1299  // clear the old layout so that we don't get unnecessary layout
1300  // changes until we have rebuilt the thing
1301  TQLayoutIterator it = l->iterator();
1302  while ( it.current() )
1303  it.deleteCurrent();
1304  }
1305  }
1306  TQToolBar::childEvent( e );
1307 }
1308 
1309 void KToolBar::insertWidgetInternal( TQWidget *w, int &index, int id )
1310 {
1311  // we can't have it in widgets, or something is really wrong
1312  //widgets.removeRef( w );
1313 
1314  connect( w, TQT_SIGNAL( destroyed() ),
1315  this, TQT_SLOT( widgetDestroyed() ) );
1316  if ( index == -1 || index > (int)widgets.count() ) {
1317  index = (int)widgets.count();
1318  widgets.append( w );
1319  }
1320  else
1321  widgets.insert( index, w );
1322  if ( id == -1 )
1323  id = id2widget.count();
1324  id2widget.insert( id, w );
1325  widget2id.insert( w, id );
1326 }
1327 
1328 void KToolBar::showEvent( TQShowEvent *e )
1329 {
1330  TQToolBar::showEvent( e );
1331  rebuildLayout();
1332 }
1333 
1334 void KToolBar::setStretchableWidget( TQWidget *w )
1335 {
1336  TQToolBar::setStretchableWidget( w );
1337  stretchableWidget = w;
1338 }
1339 
1340 TQSizePolicy KToolBar::sizePolicy() const
1341 {
1342  if ( orientation() == Qt::Horizontal )
1343  return TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed );
1344  else
1345  return TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Expanding );
1346 }
1347 
1348 TQSize KToolBar::sizeHint() const
1349 {
1350  TQSize minSize(0,0);
1351  KToolBar *ncThis = const_cast<KToolBar *>(this);
1352 
1353  ncThis->polish();
1354 
1355  int margin = static_cast<TQWidget*>(ncThis)->layout()->margin() + frameWidth();
1356  switch( barPos() )
1357  {
1358  case KToolBar::Top:
1359  case KToolBar::Bottom:
1360  for ( TQWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() )
1361  {
1362  TQSize sh = w->sizeHint();
1363  if ( w->sizePolicy().horData() == TQSizePolicy::Ignored )
1364  sh.setWidth( 1 );
1365  if ( w->sizePolicy().verData() == TQSizePolicy::Ignored )
1366  sh.setHeight( 1 );
1367  sh = sh.boundedTo( w->maximumSize() )
1368  .expandedTo( w->minimumSize() ).expandedTo( TQSize(1, 1) );
1369 
1370  minSize = minSize.expandedTo(TQSize(0, sh.height()));
1371  minSize += TQSize(sh.width()+1, 0);
1372  if (tqt_dynamic_cast<TQLineEdit *>(w)) // w is a TQLineEdit ?
1373  minSize += TQSize(2, 0); // A little bit extra spacing behind it.
1374  }
1375 
1376  minSize += TQSize(TQApplication::style().pixelMetric( TQStyle::PM_DockWindowHandleExtent ), 0);
1377  minSize += TQSize(margin*2, margin*2);
1378  break;
1379 
1380  case KToolBar::Left:
1381  case KToolBar::Right:
1382  for ( TQWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() )
1383  {
1384  TQSize sh = w->sizeHint();
1385  if ( w->sizePolicy().horData() == TQSizePolicy::Ignored )
1386  sh.setWidth( 1 );
1387  if ( w->sizePolicy().verData() == TQSizePolicy::Ignored )
1388  sh.setHeight( 1 );
1389  sh = sh.boundedTo( w->maximumSize() )
1390  .expandedTo( w->minimumSize() ).expandedTo( TQSize(1, 1) );
1391 
1392  minSize = minSize.expandedTo(TQSize(sh.width(), 0));
1393  minSize += TQSize(0, sh.height()+1);
1394  }
1395  minSize += TQSize(0, TQApplication::style().pixelMetric( TQStyle::PM_DockWindowHandleExtent ));
1396  minSize += TQSize(margin*2, margin*2);
1397  break;
1398 
1399  default:
1400  minSize = TQToolBar::sizeHint();
1401  break;
1402  }
1403  return minSize;
1404 }
1405 
1406 TQSize KToolBar::minimumSize() const
1407 {
1408  return minimumSizeHint();
1409 }
1410 
1411 TQSize KToolBar::minimumSizeHint() const
1412 {
1413  return sizeHint();
1414 }
1415 
1416 bool KToolBar::highlight() const
1417 {
1418  return d->m_highlight;
1419 }
1420 
1421 void KToolBar::hide()
1422 {
1423  TQToolBar::hide();
1424 }
1425 
1426 void KToolBar::show()
1427 {
1428  TQToolBar::show();
1429 }
1430 
1431 void KToolBar::resizeEvent( TQResizeEvent *e )
1432 {
1433  bool b = isUpdatesEnabled();
1434  setUpdatesEnabled( false );
1435  TQToolBar::resizeEvent( e );
1436  if (b)
1437  {
1438  if (layoutTimer->isActive())
1439  {
1440  // Wait with repainting till layout is complete.
1441  d->repaintTimer.start( 100, true );
1442  }
1443  else
1444  {
1445  // Repaint now
1446  slotRepaint();
1447  }
1448  }
1449 // else {
1450 // printf("[WARNING] In KToolBar::resizeEvent, but this code block should not be executing. Preventing toolbar lockup. [Code 0045]\n");
1451 // setUpdatesEnabled( true );
1452 // }
1453 }
1454 
1455 void KToolBar::slotIconChanged(int group)
1456 {
1457  if ((group != KIcon::Toolbar) && (group != KIcon::MainToolbar))
1458  return;
1459  if ((group == KIcon::MainToolbar) != !::qstrcmp(name(), "mainToolBar"))
1460  return;
1461 
1462  doModeChange();
1463 
1464  if (isVisible())
1465  updateGeometry();
1466 }
1467 
1468 void KToolBar::slotReadConfig()
1469 {
1470  //kdDebug(220) << name() << " slotReadConfig" << endl;
1471  // Read appearance settings (hmm, we used to do both here,
1472  // but a well behaved application will call applyMainWindowSettings
1473  // anyway, right ?)
1474  applyAppearanceSettings(KGlobal::config(), TQString::null );
1475 }
1476 
1477 void KToolBar::slotAppearanceChanged()
1478 {
1479  // Read appearance settings from global file.
1480  applyAppearanceSettings(KGlobal::config(), TQString::null, true /* lose local settings */ );
1481 
1482  // And remember to save the new look later
1483  KMainWindow *kmw = tqt_dynamic_cast<KMainWindow *>(mainWindow());
1484  if ( kmw )
1485  kmw->setSettingsDirty();
1486 }
1487 
1488 //static
1489 bool KToolBar::highlightSetting()
1490 {
1491  TQString grpToolbar(TQString::fromLatin1("Toolbar style"));
1492  KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
1493  return KGlobal::config()->readBoolEntry(TQString::fromLatin1("Highlighting"),true);
1494 }
1495 
1496 //static
1497 bool KToolBar::transparentSetting()
1498 {
1499  TQString grpToolbar(TQString::fromLatin1("Toolbar style"));
1500  KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
1501  return KGlobal::config()->readBoolEntry(TQString::fromLatin1("TransparentMoving"),true);
1502 }
1503 
1504 //static
1505 KToolBar::IconText KToolBar::iconTextSetting()
1506 {
1507  TQString grpToolbar(TQString::fromLatin1("Toolbar style"));
1508  KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
1509  TQString icontext = KGlobal::config()->readEntry(TQString::fromLatin1("IconText"),TQString::fromLatin1("IconOnly"));
1510  if ( icontext == "IconTextRight" )
1511  return IconTextRight;
1512  else if ( icontext == "IconTextBottom" )
1513  return IconTextBottom;
1514  else if ( icontext == "TextOnly" )
1515  return TextOnly;
1516  else
1517  return IconOnly;
1518 }
1519 
1520 void KToolBar::applyAppearanceSettings(KConfig *config, const TQString &_configGroup, bool forceGlobal)
1521 {
1522  TQString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
1523  //kdDebug(220) << name() << " applyAppearanceSettings: configGroup=" << configGroup << " forceGlobal=" << forceGlobal << endl;
1524 
1525  // If we have application-specific settings in the XML file,
1526  // and nothing in the application's config file, then
1527  // we don't apply the global defaults, the XML ones are preferred
1528  // (see applySettings for a full explanation)
1529  // This is the reason for the xmlgui tests below.
1530  bool xmlgui = d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty();
1531 
1532  KConfig *gconfig = KGlobal::config();
1533 
1534  static const TQString &attrIconText = KGlobal::staticQString("IconText");
1535  static const TQString &attrHighlight = KGlobal::staticQString("Highlighting");
1536  static const TQString &attrTrans = KGlobal::staticQString("TransparentMoving");
1537  static const TQString &attrIconSize = KGlobal::staticQString("IconSize");
1538 
1539  // we actually do this in two steps.
1540  // First, we read in the global styles [Toolbar style] (from the KControl module).
1541  // Then, if the toolbar is NOT 'mainToolBar', we will also try to read in [barname Toolbar style]
1542  bool highlight;
1543  int transparent;
1544  bool applyIconText = !xmlgui; // if xmlgui is used, global defaults won't apply
1545  bool applyIconSize = !xmlgui;
1546 
1547  int iconSize = d->IconSizeDefault;
1548  TQString iconText = d->IconTextDefault;
1549 
1550  // this is the first iteration
1551  TQString grpToolbar(TQString::fromLatin1("Toolbar style"));
1552  { // start block for KConfigGroupSaver
1553  KConfigGroupSaver saver(gconfig, grpToolbar);
1554 
1555  // first, get the generic settings
1556  highlight = gconfig->readBoolEntry(attrHighlight, true);
1557  transparent = gconfig->readBoolEntry(attrTrans, true);
1558 
1559  // we read in the IconText property *only* if we intend on actually
1560  // honoring it
1561  if (d->m_honorStyle)
1562  d->IconTextDefault = gconfig->readEntry(attrIconText, d->IconTextDefault);
1563  else
1564  d->IconTextDefault = "IconOnly";
1565 
1566  // Use the default icon size for toolbar icons.
1567  d->IconSizeDefault = gconfig->readNumEntry(attrIconSize, d->IconSizeDefault);
1568 
1569  iconSize = d->IconSizeDefault;
1570  iconText = d->IconTextDefault;
1571 
1572  if ( !forceGlobal && config->hasGroup(configGroup) )
1573  {
1574  config->setGroup(configGroup);
1575 
1576  // first, get the generic settings
1577  highlight = config->readBoolEntry(attrHighlight, highlight);
1578  transparent = config->readBoolEntry(attrTrans, transparent);
1579 
1580  // read in the IconText property
1581  if ( config->hasKey( attrIconText ) ) {
1582  iconText = config->readEntry(attrIconText);
1583  applyIconText = true;
1584  //kdDebug(220) << name() << " read icontext=" << d->IconTextDefault << ", that will be the default" << endl;
1585  }
1586 
1587  // now get the size
1588  if ( config->hasKey( attrIconSize ) ) {
1589  iconSize = config->readNumEntry(attrIconSize);
1590  applyIconSize = true;
1591  }
1592  }
1593 
1594  // revert back to the old group
1595  } // end block for KConfigGroupSaver
1596 
1597  bool doUpdate = false;
1598 
1599  IconText icon_text;
1600  if ( iconText == "IconTextRight" )
1601  icon_text = IconTextRight;
1602  else if ( iconText == "IconTextBottom" )
1603  icon_text = IconTextBottom;
1604  else if ( iconText == "TextOnly" )
1605  icon_text = TextOnly;
1606  else
1607  icon_text = IconOnly;
1608 
1609  // check if the icon/text has changed
1610  if (icon_text != d->m_iconText && applyIconText) {
1611  //kdDebug(220) << name() << " applyAppearanceSettings setIconText " << icon_text << endl;
1612  setIconText(icon_text, false);
1613  doUpdate = true;
1614  }
1615 
1616  // ...and check if the icon size has changed
1617  if (iconSize != d->m_iconSize && applyIconSize) {
1618  setIconSize(iconSize, false);
1619  doUpdate = true;
1620  }
1621 
1622  TQMainWindow *mw = mainWindow();
1623 
1624  // ...and if we should highlight
1625  if ( highlight != d->m_highlight ) {
1626  d->m_highlight = highlight;
1627  doUpdate = true;
1628  }
1629 
1630  // ...and if we should move transparently
1631  if ( mw && transparent != (!mw->opaqueMoving()) ) {
1632  mw->setOpaqueMoving( !transparent );
1633  }
1634 
1635  if (doUpdate)
1636  doModeChange(); // tell buttons what happened
1637 
1638  if (isVisible ())
1639  updateGeometry();
1640 }
1641 
1642 void KToolBar::applySettings(KConfig *config, const TQString &_configGroup)
1643 {
1644  return applySettings(config,_configGroup,false);
1645 }
1646 
1647 void KToolBar::applySettings(KConfig *config, const TQString &_configGroup, bool force)
1648 {
1649  //kdDebug(220) << name() << " applySettings group=" << _configGroup << endl;
1650 
1651  TQString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
1652 
1653  /*
1654  Let's explain this a bit more in details.
1655  The order in which we apply settings is :
1656  Global config / <appnamerc> user settings if no XMLGUI is used
1657  Global config / App-XML attributes / <appnamerc> user settings if XMLGUI is used
1658 
1659  So in the first case, we simply read everything from KConfig as below,
1660  but in the second case we don't do anything here if there is no app-specific config,
1661  and the XMLGUI-related code (loadState()) uses the static methods of this class
1662  to get the global defaults.
1663 
1664  Global config doesn't include position (index, offset, newline and hidden/shown).
1665  */
1666 
1667  // First the appearance stuff - the one which has a global config
1668  applyAppearanceSettings( config, configGroup );
1669 
1670  // ...and now the position stuff
1671  if ( config->hasGroup(configGroup) || force )
1672  {
1673  KConfigGroupSaver cgs(config, configGroup);
1674 
1675  static const TQString &attrPosition = KGlobal::staticQString("Position");
1676  static const TQString &attrIndex = KGlobal::staticQString("Index");
1677  static const TQString &attrOffset = KGlobal::staticQString("Offset");
1678  static const TQString &attrNewLine = KGlobal::staticQString("NewLine");
1679  static const TQString &attrHidden = KGlobal::staticQString("Hidden");
1680 
1681  TQString position = config->readEntry(attrPosition, d->PositionDefault);
1682  int index = config->readNumEntry(attrIndex, -1);
1683  int offset = config->readNumEntry(attrOffset, d->OffsetDefault);
1684  bool newLine = config->readBoolEntry(attrNewLine, d->NewLineDefault);
1685  bool hidden = config->readBoolEntry(attrHidden, d->HiddenDefault);
1686 
1687  Dock pos(DockTop);
1688  if ( position == "Top" )
1689  pos = DockTop;
1690  else if ( position == "Bottom" )
1691  pos = DockBottom;
1692  else if ( position == "Left" )
1693  pos = DockLeft;
1694  else if ( position == "Right" )
1695  pos = DockRight;
1696  else if ( position == "Floating" )
1697  pos = DockTornOff;
1698  else if ( position == "Flat" )
1699  pos = DockMinimized;
1700 
1701  //kdDebug(220) << name() << " applySettings hidden=" << hidden << endl;
1702  if (hidden)
1703  hide();
1704  else
1705  show();
1706 
1707  if ( mainWindow() )
1708  {
1709  //kdDebug(220) << name() << " applySettings updating ToolbarInfo" << endl;
1710  d->toolBarInfo = KToolBarPrivate::ToolBarInfo( pos, index, newLine, offset );
1711  positionYourself( true );
1712  }
1713  if (isVisible ())
1714  updateGeometry();
1715  }
1716 }
1717 
1718 bool KToolBar::event( TQEvent *e )
1719 {
1720  if ( (e->type() == TQEvent::LayoutHint) && isUpdatesEnabled() )
1721  d->repaintTimer.start( 100, true );
1722 
1723  if (e->type() == TQEvent::ChildInserted )
1724  {
1725  // Bypass TQToolBar::event,
1726  // it will show() the inserted child and we don't want to
1727  // do that until we have rebuilt the layout.
1728  childEvent((TQChildEvent *)e);
1729  return true;
1730  }
1731 
1732  return TQToolBar::event( e );
1733 }
1734 
1735 void KToolBar::slotRepaint()
1736 {
1737  setUpdatesEnabled( false );
1738  // Send a resizeEvent to update the "toolbar extension arrow"
1739  // (The button you get when your toolbar-items don't fit in
1740  // the available space)
1741  TQResizeEvent ev(size(), size());
1742  resizeEvent(&ev);
1743  TQApplication::sendPostedEvents( this, TQEvent::LayoutHint );
1744  setUpdatesEnabled( true );
1745  repaint( true );
1746 }
1747 
1748 void KToolBar::toolBarPosChanged( TQToolBar *tb )
1749 {
1750  if ( tb != this )
1751  return;
1752  if ( d->oldPos == DockMinimized )
1753  rebuildLayout();
1754  d->oldPos = (TQMainWindow::ToolBarDock)barPos();
1755  KMainWindow *kmw = tqt_dynamic_cast<KMainWindow *>(mainWindow());
1756  if ( kmw )
1757  kmw->setSettingsDirty();
1758 }
1759 
1760 static KToolBar::Dock stringToDock( const TQString& attrPosition )
1761 {
1762  KToolBar::Dock dock = KToolBar::DockTop;
1763  if ( !attrPosition.isEmpty() ) {
1764  if ( attrPosition == "top" )
1765  dock = KToolBar::DockTop;
1766  else if ( attrPosition == "left" )
1767  dock = KToolBar::DockLeft;
1768  else if ( attrPosition == "right" )
1769  dock = KToolBar::DockRight;
1770  else if ( attrPosition == "bottom" )
1771  dock = KToolBar::DockBottom;
1772  else if ( attrPosition == "floating" )
1773  dock = KToolBar::DockTornOff;
1774  else if ( attrPosition == "flat" )
1775  dock = KToolBar::DockMinimized;
1776  }
1777  return dock;
1778 }
1779 
1780 
1781 void KToolBar::loadState( const TQDomElement &element )
1782 {
1783  TQMainWindow *mw = mainWindow();
1784 
1785  if ( !mw )
1786  return;
1787 
1788  {
1789  TQCString text = element.namedItem( "text" ).toElement().text().utf8();
1790  if ( text.isEmpty() )
1791  text = element.namedItem( "Text" ).toElement().text().utf8();
1792  if ( !text.isEmpty() )
1793  setText( i18n( text ) );
1794  }
1795 
1796  {
1797  TQCString attrFullWidth = element.attribute( "fullWidth" ).lower().latin1();
1798  if ( !attrFullWidth.isEmpty() )
1799  setFullSize( attrFullWidth == "true" );
1800  }
1801 
1802  /*
1803  This method is called in order to load toolbar settings from XML.
1804  However this can be used in two rather different cases:
1805  - for the initial loading of the app's XML. In that case the settings
1806  are only the defaults, the user's KConfig settings will override them
1807  (KDE4 TODO: how about saving those user settings into the local XML file instead?
1808  Then this whole thing would be simpler, no KConfig settings to apply afterwards.
1809  OTOH we'd have to migrate those settings when the .rc version increases,
1810  like we do for shortcuts)
1811 
1812  - for later re-loading when switching between parts in KXMLGUIFactory.
1813  In that case the XML contains the final settings, not the defaults.
1814  We do need the defaults, and the toolbar might have been completely
1815  deleted and recreated meanwhile. So we store the app-default settings
1816  into the XML.
1817  */
1818  bool loadingAppDefaults = true;
1819  if ( element.hasAttribute( "offsetDefault" ) )
1820  {
1821  // this isn't the first time, so the defaults have been saved into the (in-memory) XML
1822  loadingAppDefaults = false;
1823  d->OffsetDefault = element.attribute( "offsetDefault" ).toInt();
1824  d->NewLineDefault = element.attribute( "newlineDefault" ) == "true";
1825  d->HiddenDefault = element.attribute( "hiddenDefault" ) == "true";
1826  d->IconSizeDefault = element.attribute( "iconSizeDefault" ).toInt();
1827  d->PositionDefault = element.attribute( "positionDefault" );
1828  d->IconTextDefault = element.attribute( "iconTextDefault" );
1829  }
1830  //kdDebug(220) << name() << " loadState loadingAppDefaults=" << loadingAppDefaults << endl;
1831 
1832  Dock dock = stringToDock( element.attribute( "position" ).lower() );
1833 
1834  {
1835  TQCString attrIconText = element.attribute( "iconText" ).lower().latin1();
1836  if ( !attrIconText.isEmpty() ) {
1837  //kdDebug(220) << name() << " loadState attrIconText=" << attrIconText << endl;
1838  if ( attrIconText == "icontextright" )
1839  setIconText( KToolBar::IconTextRight );
1840  else if ( attrIconText == "textonly" )
1841  setIconText( KToolBar::TextOnly );
1842  else if ( attrIconText == "icontextbottom" )
1843  setIconText( KToolBar::IconTextBottom );
1844  else if ( attrIconText == "icononly" )
1845  setIconText( KToolBar::IconOnly );
1846  } else
1847  {
1848  //kdDebug(220) << name() << " loadState no iconText attribute in XML, using iconTextSetting=" << iconTextSetting() << endl;
1849  // Use global setting
1850  if (d->m_honorStyle)
1851  setIconText( iconTextSetting() );
1852  else
1853  setIconText( d->IconTextDefault );
1854  }
1855  }
1856 
1857  TQString attrIconSize = element.attribute( "iconSize" ).lower();
1858  int iconSize = d->IconSizeDefault;
1859  if ( !attrIconSize.isEmpty() )
1860  iconSize = attrIconSize.toInt();
1861  setIconSize( iconSize );
1862 
1863  int index = -1; // append by default. This is very important, otherwise
1864  // with all 0 indexes, we keep reversing the toolbars.
1865  {
1866  TQString attrIndex = element.attribute( "index" ).lower();
1867  if ( !attrIndex.isEmpty() )
1868  index = attrIndex.toInt();
1869  }
1870 
1871  int offset = d->OffsetDefault;
1872  bool newLine = d->NewLineDefault;
1873  bool hidden = d->HiddenDefault;
1874 
1875  {
1876  TQString attrOffset = element.attribute( "offset" );
1877  if ( !attrOffset.isEmpty() )
1878  offset = attrOffset.toInt();
1879  }
1880 
1881  {
1882  TQString attrNewLine = element.attribute( "newline" ).lower();
1883  if ( !attrNewLine.isEmpty() )
1884  newLine = attrNewLine == "true";
1885  }
1886 
1887  {
1888  TQString attrHidden = element.attribute( "hidden" ).lower();
1889  if ( !attrHidden.isEmpty() ) {
1890  hidden = attrHidden == "true";
1891  }
1892  }
1893 
1894  d->toolBarInfo = KToolBarPrivate::ToolBarInfo( dock, index, newLine, offset );
1895  mw->addDockWindow( this, dock, newLine );
1896  mw->moveDockWindow( this, dock, newLine, index, offset );
1897 
1898  // Apply the highlight button setting
1899  d->m_highlight = highlightSetting();
1900 
1901  if ( hidden )
1902  hide();
1903  else
1904  show();
1905 
1906  if ( loadingAppDefaults )
1907  {
1908  getAttributes( d->PositionDefault, d->IconTextDefault, index );
1909  //kdDebug(220) << name() << " loadState IconTextDefault=" << d->IconTextDefault << endl;
1910  d->OffsetDefault = offset;
1911  d->NewLineDefault = newLine;
1912  d->HiddenDefault = hidden;
1913  d->IconSizeDefault = iconSize;
1914  }
1915  //kdDebug(220) << name() << " loadState hidden=" << hidden << endl;
1916 
1917  // Apply transparent-toolbar-moving setting (ok, this is global to the mainwindow,
1918  // but we do it only if there are toolbars...)
1919  // KDE4: move to KMainWindow
1920  if ( transparentSetting() != !mw->opaqueMoving() ) {
1921  mw->setOpaqueMoving( !transparentSetting() );
1922  }
1923 }
1924 
1925 int KToolBar::dockWindowIndex()
1926 {
1927  int index = 0;
1928  Q_ASSERT( mainWindow() );
1929  if ( mainWindow() ) {
1930  TQMainWindow::ToolBarDock dock;
1931  bool newLine;
1932  int offset;
1933  mainWindow()->getLocation( this, dock, index, newLine, offset );
1934  }
1935  return index;
1936 }
1937 
1938 void KToolBar::getAttributes( TQString &position, TQString &icontext, int &index )
1939 {
1940  // get all of the stuff to save
1941  switch ( barPos() ) {
1942  case KToolBar::Flat:
1943  position = "Flat";
1944  break;
1945  case KToolBar::Bottom:
1946  position = "Bottom";
1947  break;
1948  case KToolBar::Left:
1949  position = "Left";
1950  break;
1951  case KToolBar::Right:
1952  position = "Right";
1953  break;
1954  case KToolBar::Floating:
1955  position = "Floating";
1956  break;
1957  case KToolBar::Top:
1958  default:
1959  position = "Top";
1960  break;
1961  }
1962 
1963  index = dockWindowIndex();
1964 
1965  switch (d->m_iconText) {
1966  case KToolBar::IconTextRight:
1967  icontext = "IconTextRight";
1968  break;
1969  case KToolBar::IconTextBottom:
1970  icontext = "IconTextBottom";
1971  break;
1972  case KToolBar::TextOnly:
1973  icontext = "TextOnly";
1974  break;
1975  case KToolBar::IconOnly:
1976  default:
1977  icontext = "IconOnly";
1978  break;
1979  }
1980  //kdDebug(220) << name() << " getAttributes: icontext=" << icontext << endl;
1981 }
1982 
1983 void KToolBar::saveState( TQDomElement &current )
1984 {
1985  Q_ASSERT( !current.isNull() );
1986  TQString position, icontext;
1987  int index = -1;
1988  getAttributes( position, icontext, index );
1989 
1990  current.setAttribute( "noMerge", "1" );
1991  current.setAttribute( "position", position );
1992  current.setAttribute( "iconText", icontext );
1993  current.setAttribute( "index", index );
1994  current.setAttribute( "offset", offset() );
1995  current.setAttribute( "newline", newLine() );
1996  if ( isHidden() )
1997  current.setAttribute( "hidden", "true" );
1998  d->modified = true;
1999 
2000  // TODO if this method is used by more than KXMLGUIBuilder, e.g. to save XML settings to *disk*,
2001  // then the stuff below shouldn't always be done.
2002  current.setAttribute( "offsetDefault", d->OffsetDefault );
2003  current.setAttribute( "newlineDefault", d->NewLineDefault );
2004  current.setAttribute( "hiddenDefault", d->HiddenDefault ? "true" : "false" );
2005  current.setAttribute( "iconSizeDefault", d->IconSizeDefault );
2006  current.setAttribute( "positionDefault", d->PositionDefault );
2007  current.setAttribute( "iconTextDefault", d->IconTextDefault );
2008 
2009  //kdDebug(220) << name() << " saveState: saving index=" << index << " iconText=" << icontext << " hidden=" << isHidden() << endl;
2010 }
2011 
2012 // Called by KMainWindow::finalizeGUI
2013 void KToolBar::positionYourself( bool force )
2014 {
2015  if (force)
2016  d->positioned = false;
2017 
2018  if ( d->positioned || !mainWindow() )
2019  {
2020  //kdDebug(220) << name() << " positionYourself d->positioned=true ALREADY DONE" << endl;
2021  return;
2022  }
2023  // we can't test for ForceHide after moveDockWindow because QDockArea
2024  // does a reparent() with showIt == true
2025  bool hidden = isHidden();
2026  //kdDebug(220) << name() << " positionYourself dock=" << d->toolBarInfo.dock << " newLine=" << d->toolBarInfo.newline << " index=" << d->toolBarInfo.index << " offset=" << d->toolBarInfo.offset << endl;
2027  mainWindow()->moveDockWindow( this, d->toolBarInfo.dock,
2028  d->toolBarInfo.newline,
2029  d->toolBarInfo.index,
2030  d->toolBarInfo.offset );
2031 
2032  //kdDebug(220) << name() << " positionYourself dockWindowIndex=" << dockWindowIndex() << endl;
2033  if ( hidden )
2034  hide();
2035  else
2036  show();
2037  // This method can only have an effect once - unless force is set
2038  d->positioned = true;
2039 }
2040 
2041 KPopupMenu *KToolBar::contextMenu()
2042 {
2043  if ( context )
2044  return context;
2045  // Construct our context popup menu. Name it qt_dockwidget_internal so it
2046  // won't be deleted by TQToolBar::clear().
2047  context = new KPopupMenu( this, "qt_dockwidget_internal" );
2048  context->insertTitle(i18n("Toolbar Menu"));
2049 
2050  KPopupMenu *orient = new KPopupMenu( context, "orient" );
2051  orient->insertItem( i18n("toolbar position string","Top"), CONTEXT_TOP );
2052  orient->insertItem( i18n("toolbar position string","Left"), CONTEXT_LEFT );
2053  orient->insertItem( i18n("toolbar position string","Right"), CONTEXT_RIGHT );
2054  orient->insertItem( i18n("toolbar position string","Bottom"), CONTEXT_BOTTOM );
2055  orient->insertSeparator(-1);
2056  orient->insertItem( i18n("toolbar position string","Floating"), CONTEXT_FLOAT );
2057  orient->insertItem( i18n("min toolbar", "Flat"), CONTEXT_FLAT );
2058 
2059  KPopupMenu *mode = new KPopupMenu( context, "mode" );
2060  mode->insertItem( i18n("Icons Only"), CONTEXT_ICONS );
2061  mode->insertItem( i18n("Text Only"), CONTEXT_TEXT );
2062  mode->insertItem( i18n("Text Alongside Icons"), CONTEXT_TEXTRIGHT );
2063  mode->insertItem( i18n("Text Under Icons"), CONTEXT_TEXTUNDER );
2064 
2065  KPopupMenu *size = new KPopupMenu( context, "size" );
2066  size->insertItem( i18n("Default"), CONTEXT_ICONSIZES );
2067  // Query the current theme for available sizes
2068  KIconTheme *theme = KGlobal::instance()->iconLoader()->theme();
2069  TQValueList<int> avSizes;
2070  if (theme)
2071  {
2072  if (!::qstrcmp(name(), "mainToolBar"))
2073  avSizes = theme->querySizes( KIcon::MainToolbar);
2074  else
2075  avSizes = theme->querySizes( KIcon::Toolbar);
2076  }
2077 
2078  d->iconSizes = avSizes;
2079  qHeapSort(avSizes);
2080 
2081  TQValueList<int>::Iterator it;
2082  if (avSizes.count() < 10) {
2083  // Fixed or threshold type icons
2084  TQValueList<int>::Iterator end(avSizes.end());
2085  for (it=avSizes.begin(); it!=end; ++it) {
2086  TQString text;
2087  if ( *it < 19 )
2088  text = i18n("Small (%1x%2)").arg(*it).arg(*it);
2089  else if (*it < 25)
2090  text = i18n("Medium (%1x%2)").arg(*it).arg(*it);
2091  else if (*it < 35)
2092  text = i18n("Large (%1x%2)").arg(*it).arg(*it);
2093  else
2094  text = i18n("Huge (%1x%2)").arg(*it).arg(*it);
2095  //we use the size as an id, with an offset
2096  size->insertItem( text, CONTEXT_ICONSIZES + *it );
2097  }
2098  }
2099  else {
2100  // Scalable icons.
2101  const int progression[] = {16, 22, 32, 48, 64, 96, 128, 192, 256};
2102 
2103  it = avSizes.begin();
2104  for (uint i = 0; i < 9; i++) {
2105  while (it++ != avSizes.end()) {
2106  if (*it >= progression[i]) {
2107  TQString text;
2108  if ( *it < 19 )
2109  text = i18n("Small (%1x%2)").arg(*it).arg(*it);
2110  else if (*it < 25)
2111  text = i18n("Medium (%1x%2)").arg(*it).arg(*it);
2112  else if (*it < 35)
2113  text = i18n("Large (%1x%2)").arg(*it).arg(*it);
2114  else
2115  text = i18n("Huge (%1x%2)").arg(*it).arg(*it);
2116  //we use the size as an id, with an offset
2117  size->insertItem( text, CONTEXT_ICONSIZES + *it );
2118  break;
2119  }
2120  }
2121  }
2122  }
2123 
2124  context->insertItem( i18n("Orientation"), orient );
2125  orient->setItemChecked(CONTEXT_TOP, true);
2126  context->insertItem( i18n("Text Position"), mode );
2127  context->setItemChecked(CONTEXT_ICONS, true);
2128  context->insertItem( i18n("Icon Size"), size );
2129 
2130  connect( context, TQT_SIGNAL( aboutToShow() ), this, TQT_SLOT( slotContextAboutToShow() ) );
2131  // Unplugging a submenu from abouttohide leads to the popupmenu floating around
2132  // So better simply call that code from after exec() returns (DF)
2133  //connect( context, TQT_SIGNAL( aboutToHide() ), this, TQT_SLOT( slotContextAboutToHide() ) );
2134  return context;
2135 }
2136 
2137 void KToolBar::slotContextAboutToShow()
2138 {
2139  // The idea here is to reuse the "static" part of the menu to save time.
2140  // But the "Toolbars" action is dynamic (can be a single action or a submenu)
2141  // and ToolBarHandler::setupActions() deletes it, so better not keep it around.
2142  // So we currently plug/unplug the last two actions of the menu.
2143  // Another way would be to keep around the actions and plug them all into a (new each time) popupmenu.
2144  KMainWindow *kmw = tqt_dynamic_cast<KMainWindow *>(mainWindow());
2145  if ( kmw ) {
2146  kmw->setupToolbarMenuActions();
2147  // Only allow hiding a toolbar if the action is also plugged somewhere else (e.g. menubar)
2148  KAction *tbAction = kmw->toolBarMenuAction();
2149  if ( tbAction && tbAction->containerCount() > 0 )
2150  tbAction->plug(context);
2151  }
2152 
2153  // try to find "configure toolbars" action
2154  KAction *configureAction = 0;
2155  const char* actionName = KStdAction::name(KStdAction::ConfigureToolbars);
2156  if ( d->m_xmlguiClient )
2157  configureAction = d->m_xmlguiClient->actionCollection()->action(actionName);
2158  if ( !configureAction && kmw )
2159  configureAction = kmw->actionCollection()->action(actionName);
2160  if ( configureAction )
2161  configureAction->plug(context);
2162  KEditToolbar::setDefaultToolbar(name());
2163 
2164  for(int i = CONTEXT_ICONS; i <= CONTEXT_TEXTUNDER; ++i)
2165  context->setItemChecked(i, false);
2166 
2167  switch( d->m_iconText )
2168  {
2169  case IconOnly:
2170  default:
2171  context->setItemChecked(CONTEXT_ICONS, true);
2172  break;
2173  case IconTextRight:
2174  context->setItemChecked(CONTEXT_TEXTRIGHT, true);
2175  break;
2176  case TextOnly:
2177  context->setItemChecked(CONTEXT_TEXT, true);
2178  break;
2179  case IconTextBottom:
2180  context->setItemChecked(CONTEXT_TEXTUNDER, true);
2181  break;
2182  }
2183 
2184  TQValueList<int>::ConstIterator iIt = d->iconSizes.begin();
2185  TQValueList<int>::ConstIterator iEnd = d->iconSizes.end();
2186  for (; iIt != iEnd; ++iIt )
2187  context->setItemChecked( CONTEXT_ICONSIZES + *iIt, false );
2188 
2189  context->setItemChecked( CONTEXT_ICONSIZES, false );
2190 
2191  context->setItemChecked( CONTEXT_ICONSIZES + d->m_iconSize, true );
2192 
2193  for ( int i = CONTEXT_TOP; i <= CONTEXT_FLAT; ++i )
2194  context->setItemChecked( i, false );
2195 
2196  switch ( barPos() )
2197  {
2198  case KToolBar::Flat:
2199  context->setItemChecked( CONTEXT_FLAT, true );
2200  break;
2201  case KToolBar::Bottom:
2202  context->setItemChecked( CONTEXT_BOTTOM, true );
2203  break;
2204  case KToolBar::Left:
2205  context->setItemChecked( CONTEXT_LEFT, true );
2206  break;
2207  case KToolBar::Right:
2208  context->setItemChecked( CONTEXT_RIGHT, true );
2209  break;
2210  case KToolBar::Floating:
2211  context->setItemChecked( CONTEXT_FLOAT, true );
2212  break;
2213  case KToolBar::Top:
2214  context->setItemChecked( CONTEXT_TOP, true );
2215  break;
2216  default: break;
2217  }
2218 }
2219 
2220 void KToolBar::slotContextAboutToHide()
2221 {
2222  // We have to unplug whatever slotContextAboutToShow plugged into the menu.
2223  // Unplug the toolbar menu action
2224  KMainWindow *kmw = tqt_dynamic_cast<KMainWindow *>(mainWindow());
2225  if ( kmw && kmw->toolBarMenuAction() )
2226  if ( kmw->toolBarMenuAction()->containerCount() > 1 )
2227  kmw->toolBarMenuAction()->unplug(context);
2228 
2229  // Unplug the configure toolbars action too, since it's afterwards anyway
2230  KAction *configureAction = 0;
2231  const char* actionName = KStdAction::name(KStdAction::ConfigureToolbars);
2232  if ( d->m_xmlguiClient )
2233  configureAction = d->m_xmlguiClient->actionCollection()->action(actionName);
2234  if ( !configureAction && kmw )
2235  configureAction = kmw->actionCollection()->action(actionName);
2236  if ( configureAction )
2237  configureAction->unplug(context);
2238 
2239  TQPtrListIterator<TQWidget> it( widgets );
2240  TQWidget *wdg;
2241  while ( ( wdg = it.current() ) != 0 ) {
2242  if ( wdg->inherits( TQTOOLBUTTON_OBJECT_NAME_STRING ) )
2243  static_cast<TQToolButton*>( wdg )->setDown( false );
2244  ++it;
2245  }
2246 }
2247 
2248 void KToolBar::widgetDestroyed()
2249 {
2250  removeWidgetInternal( (TQWidget*)sender() );
2251 }
2252 
2253 void KToolBar::removeWidgetInternal( TQWidget * w )
2254 {
2255  widgets.removeRef( w );
2256  TQMap< TQWidget*, int >::Iterator it = widget2id.find( w );
2257  if ( it == widget2id.end() )
2258  return;
2259  id2widget.remove( *it );
2260  widget2id.remove( it );
2261 }
2262 
2263 void KToolBar::virtual_hook( int, void* )
2264 { /*BASE::virtual_hook( id, data );*/ }
2265 
2266 #include "ktoolbar.moc"
2267 

kdeui

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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |