30 #include <tqdockwindow.h>
35 #include <tqpainter.h>
36 #include <tqtooltip.h>
37 #include <tqdrawutil.h>
40 #include <tqobjectlist.h>
46 #include <kmainwindow.h>
47 #include <klineedit.h>
48 #include <kseparator.h>
50 #include <kapplication.h>
52 #include <kstdaction.h>
55 #include <kiconloader.h>
56 #include <kcombobox.h>
57 #include <kpopupmenu.h>
58 #include <kanimwidget.h>
59 #include <kedittoolbar.h>
63 #include <ktoolbarbutton.h>
74 CONTEXT_TEXTRIGHT = 8,
75 CONTEXT_TEXTUNDER = 9,
76 CONTEXT_ICONSIZES = 50
84 m_iconText = KToolBar::IconOnly;
89 m_enableContext =
true;
94 oldPos = TQt::DockUnmanaged;
96 modified = m_isHorizontal = positioned =
false;
99 IconTextDefault =
"IconOnly";
101 NewLineDefault =
false;
103 PositionDefault =
"Top";
104 HiddenDefault =
false;
105 idleButtons.setAutoDelete(
true);
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;
120 TQMainWindow::ToolBarDock oldPos;
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 ) {}
133 ToolBarInfo toolBarInfo;
134 TQValueList<int> iconSizes;
135 TQTimer repaintTimer;
140 TQString IconTextDefault;
143 TQString PositionDefault;
145 TQPtrList<TQWidget> idleButtons;
148 KToolBarSeparator::KToolBarSeparator(Orientation o ,
bool l, TQToolBar *parent,
150 :TQFrame( parent, name ), line( l )
152 connect( parent, TQT_SIGNAL(orientationChanged(Orientation)),
153 this, TQT_SLOT(setOrientation(Orientation)) );
155 setBackgroundMode( parent->backgroundMode() );
156 setBackgroundOrigin( ParentOrigin );
159 void KToolBarSeparator::setOrientation( Orientation o )
162 setFrameStyle( NoFrame );
165 void KToolBarSeparator::drawContents( TQPainter* p )
168 TQStyle::SFlags flags = TQStyle::Style_Default;
170 if ( orientation() == Qt::Horizontal )
171 flags = flags | TQStyle::Style_Horizontal;
173 style().tqdrawPrimitive(TQStyle::PE_DockWindowSeparator, p,
174 contentsRect(), colorGroup(), flags);
176 TQFrame::drawContents(p);
180 void KToolBarSeparator::styleChange( TQStyle& )
182 setOrientation( orient );
185 TQSize KToolBarSeparator::sizeHint()
const
187 int dim = style().pixelMetric( TQStyle::PM_DockWindowSeparatorExtent,
this );
188 return orientation() == Qt::Vertical ? TQSize( 0, dim ) : TQSize( dim, 0 );
191 TQSizePolicy KToolBarSeparator::sizePolicy()
const
193 return TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum );
197 : TQToolBar( TQString::fromLatin1( name ),
198 tqt_dynamic_cast<TQMainWindow*>(parent),
200 name ? name :
"mainToolBar")
202 init( readConfig, honorStyle );
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")
210 init( readConfig, honorStyle );
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")
218 init( readConfig, honorStyle );
227 void KToolBar::init(
bool readConfig,
bool honorStyle )
229 d =
new KToolBarPrivate();
232 d->m_honorStyle = honorStyle;
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() ) );
241 connect(kapp, TQT_SIGNAL(toolbarAppearanceChanged(
int)),
this, TQT_SLOT(slotAppearanceChanged()));
244 connect(kapp, TQT_SIGNAL(iconChanged(
int)),
this, TQT_SLOT(slotIconChanged(
int)));
252 connect( mainWindow(), TQT_SIGNAL( toolBarPositionChanged( TQToolBar * ) ),
253 this, TQT_SLOT( toolBarPosChanged( TQToolBar * ) ) );
256 connect(
this, TQT_SIGNAL(placeChanged(TQDockWindow::Place)), TQT_SLOT(rebuildLayout()) );
260 const TQString& text,
int index,
KInstance *_instance )
264 insertWidgetInternal( button, index,
id );
265 button->setEnabled( enabled );
266 doConnections( button );
272 const TQObject *receiver,
const char *slot,
273 bool enabled,
const TQString& text,
int index,
KInstance *_instance )
276 insertWidgetInternal( button, index,
id );
277 button->setEnabled( enabled );
278 connect( button, signal, receiver, slot );
279 doConnections( button );
285 const TQString& text,
int index )
288 insertWidgetInternal( button, index,
id );
289 button->setEnabled( enabled );
290 doConnections( button );
296 const TQObject *receiver,
const char *slot,
297 bool enabled,
const TQString& text,
301 insertWidgetInternal( button, index,
id );
302 button->setEnabled( enabled );
303 connect( button, signal, receiver, slot );
304 doConnections( button );
310 bool enabled,
const TQString &text,
int index )
313 insertWidgetInternal( button, index,
id );
314 button->setEnabled( enabled );
316 doConnections( button );
322 bool enabled,
const TQString &text,
int index )
325 insertWidgetInternal( button, index,
id );
326 button->setEnabled( enabled );
328 doConnections( button );
335 const TQObject *receiver,
const char *slot,
337 const TQString& toolTipText,
338 int size,
int index )
341 if ( !toolTipText.isEmpty() )
342 TQToolTip::add( lined, toolTipText );
344 lined->setMinimumWidth( size );
345 insertWidgetInternal( lined, index,
id );
346 connect( lined, signal, receiver, slot );
348 lined->setEnabled( enabled );
353 const char *signal,
const TQObject *receiver,
354 const char *slot,
bool enabled,
355 const TQString& tooltiptext,
357 TQComboBox::Policy policy )
361 insertWidgetInternal( combo, index,
id );
362 combo->insertStringList (list);
363 combo->setInsertionPolicy(policy);
364 combo->setEnabled( enabled );
366 combo->setMinimumWidth( size );
367 if (!tooltiptext.isNull())
368 TQToolTip::add( combo, tooltiptext );
370 if ( signal && receiver && slot )
371 connect ( combo, signal, receiver, slot );
377 const char *signal, TQObject *receiver,
378 const char *slot,
bool enabled,
379 const TQString& tooltiptext,
381 TQComboBox::Policy policy )
384 insertWidgetInternal( combo, index,
id );
385 combo->insertItem (text);
386 combo->setInsertionPolicy(policy);
387 combo->setEnabled( enabled );
389 combo->setMinimumWidth( size );
390 if (!tooltiptext.isNull())
391 TQToolTip::add( combo, tooltiptext );
392 connect (combo, signal, receiver, slot);
398 TQWidget *w =
new KToolBarSeparator( orientation(),
false,
this,
"tool bar separator" );
399 insertWidgetInternal( w, index,
id );
405 TQWidget *w =
new KToolBarSeparator( orientation(),
true,
this,
"tool bar separator" );
406 insertWidgetInternal( w, index,
id );
413 removeWidgetInternal( widget );
414 insertWidgetInternal( widget, index,
id );
419 const TQString& icons,
int index )
422 insertWidgetInternal( anim, index,
id );
425 connect( anim, TQT_SIGNAL(
clicked()), receiver, slot);
432 Id2WidgetMap::Iterator it = id2widget.find(
id );
433 if ( it == id2widget.end() )
438 TQObjectList *l = queryList(
"KAnimWidget" );
439 if ( !l || !l->first() ) {
444 for ( TQObject *o = l->first(); o; o = l->next() ) {
459 const TQObject *receiver,
const char *slot)
463 connect( w, signal, receiver, slot );
470 w->setEnabled( enabled );
509 button->setAutoRepeat( flag );
540 return button ? button->isOn() :
false;
555 return lineEdit ? lineEdit->text() : TQString::null;
563 comboBox->insertItem( text, index );
570 comboBox->insertStringList( list, index );
578 comboBox->removeItem( index );
594 comboBox->changeItem( text, index );
609 return comboBox ? comboBox->text( index ) : TQString::null;
615 Id2WidgetMap::Iterator it = id2widget.find(
id );
616 if ( it == id2widget.end() )
618 return tqt_dynamic_cast<
KComboBox *>( *it );
624 Id2WidgetMap::Iterator it = id2widget.find(
id );
625 if ( it == id2widget.end() )
627 return tqt_dynamic_cast<
KLineEdit *>( *it );
633 Id2WidgetMap::Iterator it = id2widget.find(
id );
634 if ( it == id2widget.end() )
642 Id2WidgetMap::Iterator it = id2widget.find(
id );
643 if ( it == id2widget.end() )
645 if ( rightAligned && !right && (*it) == rightAligned )
647 if ( (*it) && right )
648 rightAligned = (*it);
654 Id2WidgetMap::Iterator it = id2widget.find(
id );
655 return ( it == id2widget.end() ) ? 0 : (*it);
663 setStretchableWidget( w );
670 for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next())
671 w->blockSignals(
false);
672 d->idleButtons.clear();
682 Id2WidgetMap::Iterator it = id2widget.find(
id );
683 if ( it == id2widget.end() )
685 kdDebug(220) << name() <<
" KToolBar::removeItem item " <<
id <<
" not found" <<
endl;
688 TQWidget * w = (*it);
689 id2widget.remove(
id );
690 widget2id.remove( w );
691 widgets.removeRef( w );
698 Id2WidgetMap::Iterator it = id2widget.find(
id );
699 if ( it == id2widget.end() )
701 kdDebug(220) << name() <<
" KToolBar::removeItem item " <<
id <<
" not found" <<
endl;
704 TQWidget * w = (*it);
705 id2widget.remove(
id );
706 widget2id.remove( w );
707 widgets.removeRef( w );
709 w->blockSignals(
true);
710 d->idleButtons.append(w);
711 layoutTimer->start( 50,
true );
734 return w ? widgets.findRef(w) : -1;
739 TQWidget *w = widgets.at(index);
745 setHorizontalStretchable( flag );
746 setVerticalStretchable( flag );
752 return isHorizontalStretchable() || isVerticalStretchable();
758 setMovingEnabled(flag);
766 mainWindow()->moveDockWindow(
this, (Dock)bpos );
773 if ( !this->mainWindow() )
774 return place() == TQDockWindow::InDock ? KToolBar::Top : KToolBar::Floating;
778 this->mainWindow()->getLocation( (TQToolBar*)
this, dock, dm1, dm3, dm2 );
779 if ( dock == DockUnmanaged ) {
788 bool mystat = isVisible();
790 if ( (stat == Toggle && mystat) || stat == Hide )
795 return isVisible() == mystat;
801 setMaximumHeight( h );
806 return maximumHeight();
812 setMaximumWidth( dw );
818 return maximumWidth();
843 if (icontext != d->m_iconText) {
844 d->m_iconText = icontext;
859 TQMainWindow *mw = mainWindow();
861 mw->setUpdatesEnabled(
false );
864 mw->setCentralWidget(mw->centralWidget());
865 mw->setUpdatesEnabled(
true );
872 return d->m_iconText;
885 if ( size != d->m_iconSize ) {
886 d->m_iconSize = size;
897 if ( mainWindow() ) {
898 TQMainWindow *mw = mainWindow();
899 mw->setUpdatesEnabled(
false );
902 mw->setCentralWidget(mw->centralWidget());
903 mw->setUpdatesEnabled(
true );
909 if ( !d->m_iconSize )
912 return d->m_iconSize;
917 if (!::qstrcmp(name(),
"mainToolBar"))
925 d->m_enableContext =
enable;
931 return d->m_enableContext;
943 void KToolBar::setFlat (
bool flag)
948 mainWindow()->moveDockWindow(
this, DockMinimized );
950 mainWindow()->moveDockWindow(
this, DockTop );
960 return id2widget.count();
967 if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() ) {
969 TQString barname(!::qstrcmp(name(),
"unnamed") ?
"mainToolBar" : name());
973 TQDomElement current;
974 for( TQDomNode n = d->m_xmlguiClient->domDocument().documentElement().firstChild();
975 !n.isNull(); n = n.nextSibling()) {
976 current = n.toElement();
978 if ( current.tagName().lower() !=
"toolbar" )
981 TQString curname(current.attribute(
"name" ));
983 if ( curname == barname ) {
993 TQString local_xml(KXMLGUIFactory::readConfigFile(d->m_xmlguiClient->xmlFile(),
true, d->m_xmlguiClient->instance()));
995 local.setContent(local_xml);
998 bool just_append =
true;
1000 for( TQDomNode n = local.documentElement().firstChild();
1001 !n.isNull(); n = n.nextSibling()) {
1002 TQDomElement elem = n.toElement();
1004 if ( elem.tagName().lower() !=
"toolbar" )
1007 TQString curname(elem.attribute(
"name" ));
1009 if ( curname == barname ) {
1010 just_append =
false;
1011 local.documentElement().replaceChild( current, elem );
1017 local.documentElement().appendChild( current );
1019 KXMLGUIFactory::saveConfigFile(local, d->m_xmlguiClient->localXMLFile(), d->m_xmlguiClient->instance() );
1030 TQString KToolBar::settingsGroup()
const
1032 TQString configGroup;
1033 if (!::qstrcmp(name(),
"unnamed") || !::qstrcmp(name(),
"mainToolBar"))
1034 configGroup =
"Toolbar style";
1036 configGroup = TQString(name()) +
" Toolbar style";
1037 if ( this->mainWindow() )
1039 configGroup.prepend(
" ");
1040 configGroup.prepend( this->mainWindow()->name() );
1047 TQString configGroup = _configGroup;
1048 if (configGroup.isEmpty())
1049 configGroup = settingsGroup();
1052 TQString position, icontext;
1054 getAttributes( position, icontext, index );
1060 if(!config->
hasDefault(
"Position") && position == d->PositionDefault )
1067 if(d->m_honorStyle && icontext == d->IconTextDefault && !config->
hasDefault(
"IconText") )
1083 if(!config->
hasDefault(
"Hidden") && isHidden() == d->HiddenDefault )
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" ) )
1110 toolbarList.append( (
KToolBar*)tb );
1113 TQPtrListIterator<KToolBar> toolbarIterator( toolbarList );
1114 if ( !kmw || toolbarIterator.count() > 1 )
1119 if(!config->
hasDefault(
"Offset") && offset() == d->OffsetDefault )
1124 if(!config->
hasDefault(
"NewLine") && newLine() == d->NewLineDefault )
1133 d->m_xmlguiClient = client;
1138 setLabel( txt +
" (" + kapp->caption() +
") " );
1150 connect(button, TQT_SIGNAL(
clicked(
int)),
this, TQT_SIGNAL(
clicked(
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 ) ) );
1158 void KToolBar::mousePressEvent ( TQMouseEvent *m )
1160 if ( !mainWindow() )
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 );
1169 slotContextAboutToHide();
1174 mw->moveDockWindow(
this, DockLeft );
1177 mw->moveDockWindow(
this, DockRight );
1180 mw->moveDockWindow(
this, DockTop );
1182 case CONTEXT_BOTTOM:
1183 mw->moveDockWindow(
this, DockBottom );
1186 mw->moveDockWindow(
this, DockTornOff );
1189 mw->moveDockWindow(
this, DockMinimized );
1194 case CONTEXT_TEXTRIGHT:
1200 case CONTEXT_TEXTUNDER:
1204 if ( i >= CONTEXT_ICONSIZES )
1216 void KToolBar::doModeChange()
1218 for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next())
1219 w->blockSignals(
false);
1220 d->idleButtons.clear();
1225 void KToolBar::rebuildLayout()
1227 for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next())
1228 w->blockSignals(
false);
1229 d->idleButtons.clear();
1231 layoutTimer->stop();
1232 TQApplication::sendPostedEvents(
this, TQEvent::ChildInserted );
1233 TQBoxLayout *l = boxLayout();
1236 TQLayoutIterator it = l->iterator();
1237 while ( it.current() )
1240 for ( TQWidget *w = widgets.first(); w; w = widgets.next() ) {
1241 if ( w == rightAligned )
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() );
1249 if ( tqt_dynamic_cast<TQPopupMenu *>(w) )
1253 if ((orientation() == Qt::Horizontal) && tqt_dynamic_cast<TQLineEdit *>(w))
1256 if ( rightAligned ) {
1258 l->addWidget( rightAligned );
1259 rightAligned->show();
1263 if ( !rightAligned )
1265 if ( stretchableWidget )
1266 l->setStretchFactor( stretchableWidget, 10 );
1269 TQApplication::postEvent(
this,
new TQEvent( TQEvent::LayoutHint ) );
1272 void KToolBar::childEvent( TQChildEvent *e )
1274 if ( e->child()->isWidgetType() ) {
1275 TQWidget * w = tqt_dynamic_cast<TQWidget *>(e->child());
1276 if (!w || !(::qstrcmp(
"qt_dockwidget_internal", w->name())))
1278 TQToolBar::childEvent( e );
1281 if ( e->type() == TQEvent::ChildInserted ) {
1282 if ( !tqt_dynamic_cast<TQPopupMenu *>(w)) {
1285 if ( !widget2id.contains( w ) )
1288 insertWidgetInternal( w, dummy, -1 );
1292 removeWidgetInternal( w );
1294 if ( isVisibleTo( 0 ) )
1296 layoutTimer->start( 50,
true );
1297 TQBoxLayout *l = boxLayout();
1301 TQLayoutIterator it = l->iterator();
1302 while ( it.current() )
1306 TQToolBar::childEvent( e );
1309 void KToolBar::insertWidgetInternal( TQWidget *w,
int &index,
int id )
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 );
1321 widgets.insert( index, w );
1323 id = id2widget.count();
1324 id2widget.insert(
id, w );
1325 widget2id.insert( w,
id );
1328 void KToolBar::showEvent( TQShowEvent *e )
1330 TQToolBar::showEvent( e );
1334 void KToolBar::setStretchableWidget( TQWidget *w )
1336 TQToolBar::setStretchableWidget( w );
1337 stretchableWidget = w;
1340 TQSizePolicy KToolBar::sizePolicy()
const
1342 if ( orientation() == Qt::Horizontal )
1343 return TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed );
1345 return TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Expanding );
1348 TQSize KToolBar::sizeHint()
const
1350 TQSize minSize(0,0);
1355 int margin =
static_cast<TQWidget*
>(ncThis)->layout()->margin() + frameWidth();
1359 case KToolBar::Bottom:
1360 for ( TQWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() )
1362 TQSize sh = w->sizeHint();
1363 if ( w->sizePolicy().horData() == TQSizePolicy::Ignored )
1365 if ( w->sizePolicy().verData() == TQSizePolicy::Ignored )
1367 sh = sh.boundedTo( w->maximumSize() )
1368 .expandedTo( w->minimumSize() ).expandedTo( TQSize(1, 1) );
1370 minSize = minSize.expandedTo(TQSize(0, sh.height()));
1371 minSize += TQSize(sh.width()+1, 0);
1372 if (tqt_dynamic_cast<TQLineEdit *>(w))
1373 minSize += TQSize(2, 0);
1376 minSize += TQSize(TQApplication::style().pixelMetric( TQStyle::PM_DockWindowHandleExtent ), 0);
1377 minSize += TQSize(margin*2, margin*2);
1380 case KToolBar::Left:
1381 case KToolBar::Right:
1382 for ( TQWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() )
1384 TQSize sh = w->sizeHint();
1385 if ( w->sizePolicy().horData() == TQSizePolicy::Ignored )
1387 if ( w->sizePolicy().verData() == TQSizePolicy::Ignored )
1389 sh = sh.boundedTo( w->maximumSize() )
1390 .expandedTo( w->minimumSize() ).expandedTo( TQSize(1, 1) );
1392 minSize = minSize.expandedTo(TQSize(sh.width(), 0));
1393 minSize += TQSize(0, sh.height()+1);
1395 minSize += TQSize(0, TQApplication::style().pixelMetric( TQStyle::PM_DockWindowHandleExtent ));
1396 minSize += TQSize(margin*2, margin*2);
1400 minSize = TQToolBar::sizeHint();
1406 TQSize KToolBar::minimumSize()
const
1408 return minimumSizeHint();
1411 TQSize KToolBar::minimumSizeHint()
const
1416 bool KToolBar::highlight()
const
1418 return d->m_highlight;
1421 void KToolBar::hide()
1426 void KToolBar::show()
1431 void KToolBar::resizeEvent( TQResizeEvent *e )
1433 bool b = isUpdatesEnabled();
1434 setUpdatesEnabled(
false );
1435 TQToolBar::resizeEvent( e );
1438 if (layoutTimer->isActive())
1441 d->repaintTimer.start( 100,
true );
1455 void KToolBar::slotIconChanged(
int group)
1468 void KToolBar::slotReadConfig()
1477 void KToolBar::slotAppearanceChanged()
1491 TQString grpToolbar(TQString::fromLatin1(
"Toolbar style"));
1499 TQString grpToolbar(TQString::fromLatin1(
"Toolbar style"));
1507 TQString grpToolbar(TQString::fromLatin1(
"Toolbar style"));
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" )
1520 void KToolBar::applyAppearanceSettings(
KConfig *config,
const TQString &_configGroup,
bool forceGlobal)
1522 TQString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
1530 bool xmlgui = d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty();
1544 bool applyIconText = !xmlgui;
1545 bool applyIconSize = !xmlgui;
1548 TQString
iconText = d->IconTextDefault;
1551 TQString grpToolbar(TQString::fromLatin1(
"Toolbar style"));
1561 if (d->m_honorStyle)
1562 d->IconTextDefault = gconfig->
readEntry(attrIconText, d->IconTextDefault);
1564 d->IconTextDefault =
"IconOnly";
1567 d->IconSizeDefault = gconfig->
readNumEntry(attrIconSize, d->IconSizeDefault);
1569 iconSize = d->IconSizeDefault;
1570 iconText = d->IconTextDefault;
1572 if ( !forceGlobal && config->
hasGroup(configGroup) )
1577 highlight = config->
readBoolEntry(attrHighlight, highlight);
1578 transparent = config->
readBoolEntry(attrTrans, transparent);
1581 if ( config->
hasKey( attrIconText ) ) {
1582 iconText = config->
readEntry(attrIconText);
1583 applyIconText =
true;
1588 if ( config->
hasKey( attrIconSize ) ) {
1590 applyIconSize =
true;
1597 bool doUpdate =
false;
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;
1607 icon_text = IconOnly;
1610 if (icon_text != d->m_iconText && applyIconText) {
1617 if (iconSize != d->m_iconSize && applyIconSize) {
1622 TQMainWindow *mw = mainWindow();
1625 if ( highlight != d->m_highlight ) {
1626 d->m_highlight = highlight;
1631 if ( mw && transparent != (!mw->opaqueMoving()) ) {
1632 mw->setOpaqueMoving( !transparent );
1651 TQString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
1668 applyAppearanceSettings( config, configGroup );
1671 if ( config->
hasGroup(configGroup) || force )
1681 TQString position = config->
readEntry(attrPosition, d->PositionDefault);
1683 int offset = config->
readNumEntry(attrOffset, d->OffsetDefault);
1684 bool newLine = config->
readBoolEntry(attrNewLine, d->NewLineDefault);
1685 bool hidden = config->
readBoolEntry(attrHidden, d->HiddenDefault);
1688 if ( position ==
"Top" )
1690 else if ( position ==
"Bottom" )
1692 else if ( position ==
"Left" )
1694 else if ( position ==
"Right" )
1696 else if ( position ==
"Floating" )
1698 else if ( position ==
"Flat" )
1699 pos = DockMinimized;
1710 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( pos, index, newLine, offset );
1718 bool KToolBar::event( TQEvent *e )
1720 if ( (e->type() == TQEvent::LayoutHint) && isUpdatesEnabled() )
1721 d->repaintTimer.start( 100,
true );
1723 if (e->type() == TQEvent::ChildInserted )
1728 childEvent((TQChildEvent *)e);
1732 return TQToolBar::event( e );
1735 void KToolBar::slotRepaint()
1737 setUpdatesEnabled(
false );
1741 TQResizeEvent ev(size(), size());
1743 TQApplication::sendPostedEvents(
this, TQEvent::LayoutHint );
1744 setUpdatesEnabled(
true );
1748 void KToolBar::toolBarPosChanged( TQToolBar *tb )
1752 if ( d->oldPos == DockMinimized )
1754 d->oldPos = (TQMainWindow::ToolBarDock)
barPos();
1760 static KToolBar::Dock stringToDock(
const TQString& attrPosition )
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;
1783 TQMainWindow *mw = mainWindow();
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() )
1797 TQCString attrFullWidth = element.attribute(
"fullWidth" ).lower().latin1();
1798 if ( !attrFullWidth.isEmpty() )
1818 bool loadingAppDefaults =
true;
1819 if ( element.hasAttribute(
"offsetDefault" ) )
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" );
1832 Dock dock = stringToDock( element.attribute(
"position" ).lower() );
1835 TQCString attrIconText = element.attribute(
"iconText" ).lower().latin1();
1836 if ( !attrIconText.isEmpty() ) {
1838 if ( attrIconText ==
"icontextright" )
1840 else if ( attrIconText ==
"textonly" )
1842 else if ( attrIconText ==
"icontextbottom" )
1844 else if ( attrIconText ==
"icononly" )
1850 if (d->m_honorStyle)
1857 TQString attrIconSize = element.attribute(
"iconSize" ).lower();
1858 int iconSize = d->IconSizeDefault;
1859 if ( !attrIconSize.isEmpty() )
1860 iconSize = attrIconSize.toInt();
1866 TQString attrIndex = element.attribute(
"index" ).lower();
1867 if ( !attrIndex.isEmpty() )
1868 index = attrIndex.toInt();
1871 int offset = d->OffsetDefault;
1872 bool newLine = d->NewLineDefault;
1873 bool hidden = d->HiddenDefault;
1876 TQString attrOffset = element.attribute(
"offset" );
1877 if ( !attrOffset.isEmpty() )
1878 offset = attrOffset.toInt();
1882 TQString attrNewLine = element.attribute(
"newline" ).lower();
1883 if ( !attrNewLine.isEmpty() )
1884 newLine = attrNewLine ==
"true";
1888 TQString attrHidden = element.attribute(
"hidden" ).lower();
1889 if ( !attrHidden.isEmpty() ) {
1890 hidden = attrHidden ==
"true";
1894 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( dock, index, newLine, offset );
1895 mw->addDockWindow(
this, dock, newLine );
1896 mw->moveDockWindow(
this, dock, newLine, index, offset );
1906 if ( loadingAppDefaults )
1908 getAttributes( d->PositionDefault, d->IconTextDefault, index );
1910 d->OffsetDefault = offset;
1911 d->NewLineDefault = newLine;
1912 d->HiddenDefault = hidden;
1925 int KToolBar::dockWindowIndex()
1928 Q_ASSERT( mainWindow() );
1929 if ( mainWindow() ) {
1930 TQMainWindow::ToolBarDock dock;
1933 mainWindow()->getLocation(
this, dock, index, newLine, offset );
1938 void KToolBar::getAttributes( TQString &position, TQString &icontext,
int &index )
1942 case KToolBar::Flat:
1945 case KToolBar::Bottom:
1946 position =
"Bottom";
1948 case KToolBar::Left:
1951 case KToolBar::Right:
1954 case KToolBar::Floating:
1955 position =
"Floating";
1963 index = dockWindowIndex();
1965 switch (d->m_iconText) {
1966 case KToolBar::IconTextRight:
1967 icontext =
"IconTextRight";
1969 case KToolBar::IconTextBottom:
1970 icontext =
"IconTextBottom";
1972 case KToolBar::TextOnly:
1973 icontext =
"TextOnly";
1975 case KToolBar::IconOnly:
1977 icontext =
"IconOnly";
1985 Q_ASSERT( !current.isNull() );
1986 TQString position, icontext;
1988 getAttributes( position, icontext, index );
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() );
1997 current.setAttribute(
"hidden",
"true" );
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 );
2016 d->positioned =
false;
2018 if ( d->positioned || !mainWindow() )
2025 bool hidden = isHidden();
2027 mainWindow()->moveDockWindow(
this, d->toolBarInfo.dock,
2028 d->toolBarInfo.newline,
2029 d->toolBarInfo.index,
2030 d->toolBarInfo.offset );
2038 d->positioned =
true;
2047 context =
new KPopupMenu(
this,
"qt_dockwidget_internal" );
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 );
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 );
2066 size->insertItem( i18n(
"Default"), CONTEXT_ICONSIZES );
2069 TQValueList<int> avSizes;
2072 if (!::qstrcmp(name(),
"mainToolBar"))
2078 d->iconSizes = avSizes;
2081 TQValueList<int>::Iterator it;
2082 if (avSizes.count() < 10) {
2084 TQValueList<int>::Iterator
end(avSizes.end());
2085 for (it=avSizes.begin(); it!=
end; ++it) {
2088 text = i18n(
"Small (%1x%2)").arg(*it).arg(*it);
2090 text = i18n(
"Medium (%1x%2)").arg(*it).arg(*it);
2092 text = i18n(
"Large (%1x%2)").arg(*it).arg(*it);
2094 text = i18n(
"Huge (%1x%2)").arg(*it).arg(*it);
2096 size->insertItem( text, CONTEXT_ICONSIZES + *it );
2101 const int progression[] = {16, 22, 32, 48, 64, 96, 128, 192, 256};
2103 it = avSizes.begin();
2104 for (uint i = 0; i < 9; i++) {
2105 while (it++ != avSizes.end()) {
2106 if (*it >= progression[i]) {
2109 text = i18n(
"Small (%1x%2)").arg(*it).arg(*it);
2111 text = i18n(
"Medium (%1x%2)").arg(*it).arg(*it);
2113 text = i18n(
"Large (%1x%2)").arg(*it).arg(*it);
2115 text = i18n(
"Huge (%1x%2)").arg(*it).arg(*it);
2117 size->insertItem( text, CONTEXT_ICONSIZES + *it );
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 );
2130 connect( context, TQT_SIGNAL( aboutToShow() ),
this, TQT_SLOT( slotContextAboutToShow() ) );
2137 void KToolBar::slotContextAboutToShow()
2149 if ( tbAction && tbAction->containerCount() > 0 )
2150 tbAction->
plug(context);
2156 if ( d->m_xmlguiClient )
2157 configureAction = d->m_xmlguiClient->actionCollection()->action(actionName);
2158 if ( !configureAction && kmw )
2160 if ( configureAction )
2161 configureAction->
plug(context);
2164 for(
int i = CONTEXT_ICONS; i <= CONTEXT_TEXTUNDER; ++i)
2165 context->setItemChecked(i,
false);
2167 switch( d->m_iconText )
2171 context->setItemChecked(CONTEXT_ICONS,
true);
2174 context->setItemChecked(CONTEXT_TEXTRIGHT,
true);
2177 context->setItemChecked(CONTEXT_TEXT,
true);
2179 case IconTextBottom:
2180 context->setItemChecked(CONTEXT_TEXTUNDER,
true);
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 );
2189 context->setItemChecked( CONTEXT_ICONSIZES,
false );
2191 context->setItemChecked( CONTEXT_ICONSIZES + d->m_iconSize,
true );
2193 for (
int i = CONTEXT_TOP; i <= CONTEXT_FLAT; ++i )
2194 context->setItemChecked( i,
false );
2198 case KToolBar::Flat:
2199 context->setItemChecked( CONTEXT_FLAT,
true );
2201 case KToolBar::Bottom:
2202 context->setItemChecked( CONTEXT_BOTTOM,
true );
2204 case KToolBar::Left:
2205 context->setItemChecked( CONTEXT_LEFT,
true );
2207 case KToolBar::Right:
2208 context->setItemChecked( CONTEXT_RIGHT,
true );
2210 case KToolBar::Floating:
2211 context->setItemChecked( CONTEXT_FLOAT,
true );
2214 context->setItemChecked( CONTEXT_TOP,
true );
2220 void KToolBar::slotContextAboutToHide()
2232 if ( d->m_xmlguiClient )
2233 configureAction = d->m_xmlguiClient->actionCollection()->action(actionName);
2234 if ( !configureAction && kmw )
2236 if ( configureAction )
2237 configureAction->
unplug(context);
2239 TQPtrListIterator<TQWidget> it( widgets );
2241 while ( ( wdg = it.current() ) != 0 ) {
2242 if ( wdg->inherits( TQTOOLBUTTON_OBJECT_NAME_STRING ) )
2243 static_cast<TQToolButton*>( wdg )->setDown(
false );
2248 void KToolBar::widgetDestroyed()
2250 removeWidgetInternal( (TQWidget*)sender() );
2253 void KToolBar::removeWidgetInternal( TQWidget * w )
2255 widgets.removeRef( w );
2256 TQMap< TQWidget*, int >::Iterator it = widget2id.find( w );
2257 if ( it == widget2id.end() )
2259 id2widget.remove( *it );
2260 widget2id.remove( it );
2263 void KToolBar::virtual_hook(
int,
void* )
2266 #include "ktoolbar.moc"