30 #include <tqdockwindow.h>
35 #include <tqpainter.h>
36 #include <tqtooltip.h>
37 #include <tqdrawutil.h>
40 #include <tqobjectlist.h>
45 #include <tdetoolbar.h>
46 #include <tdemainwindow.h>
47 #include <klineedit.h>
48 #include <kseparator.h>
50 #include <tdeapplication.h>
51 #include <tdeaction.h>
52 #include <kstdaction.h>
53 #include <tdeglobal.h>
54 #include <tdeconfig.h>
55 #include <kiconloader.h>
56 #include <kcombobox.h>
57 #include <tdepopupmenu.h>
58 #include <kanimwidget.h>
59 #include <kedittoolbar.h>
63 #include <tdetoolbarbutton.h>
74 CONTEXT_TEXTRIGHT = 8,
75 CONTEXT_TEXTUNDER = 9,
76 CONTEXT_ICONSIZES = 50
79 class TDEToolBarPrivate
84 m_iconText = TDEToolBar::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 TDEToolBar::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 TDEToolBarSeparator::TDEToolBarSeparator(Orientation o ,
bool l, TQToolBar *parent,
150 :TQFrame( parent,
name ), line( l )
152 connect( parent, TQ_SIGNAL(orientationChanged(Orientation)),
153 this, TQ_SLOT(setOrientation(Orientation)) );
155 setBackgroundMode( parent->backgroundMode() );
156 setBackgroundOrigin( ParentOrigin );
159 void TDEToolBarSeparator::setOrientation( Orientation o )
162 setFrameStyle( NoFrame );
165 void TDEToolBarSeparator::drawContents( TQPainter* p )
168 TQStyle::SFlags flags = TQStyle::Style_Default;
170 if ( orientation() == TQt::Horizontal )
171 flags = flags | TQStyle::Style_Horizontal;
173 style().drawPrimitive(TQStyle::PE_DockWindowSeparator, p,
174 contentsRect(), colorGroup(), flags);
176 TQFrame::drawContents(p);
180 void TDEToolBarSeparator::styleChange( TQStyle& )
182 setOrientation( orient );
185 TQSize TDEToolBarSeparator::sizeHint()
const
187 int dim = style().pixelMetric( TQStyle::PM_DockWindowSeparatorExtent,
this );
188 return orientation() == TQt::Vertical ? TQSize( 0, dim ) : TQSize( dim, 0 );
191 TQSizePolicy TDEToolBarSeparator::sizePolicy()
const
193 return TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum );
197 : TQToolBar( TQString::fromLatin1( name ),
198 dynamic_cast<TQMainWindow*>(parent),
200 name ? name :
"mainToolBar")
202 init( readConfig, honorStyle );
205 TDEToolBar::TDEToolBar( 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 TDEToolBar::TDEToolBar( 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 TDEToolBar::init(
bool readConfig,
bool honorStyle )
229 d =
new TDEToolBarPrivate();
232 d->m_honorStyle = honorStyle;
234 layoutTimer =
new TQTimer(
this );
235 connect( layoutTimer, TQ_SIGNAL( timeout() ),
236 this, TQ_SLOT( rebuildLayout() ) );
237 connect( &(d->repaintTimer), TQ_SIGNAL( timeout() ),
238 this, TQ_SLOT( slotRepaint() ) );
241 connect(kapp, TQ_SIGNAL(toolbarAppearanceChanged(
int)),
this, TQ_SLOT(slotAppearanceChanged()));
243 kapp->addKipcEventMask(KIPC::IconChanged);
244 connect(kapp, TQ_SIGNAL(iconChanged(
int)),
this, TQ_SLOT(slotIconChanged(
int)));
252 connect( mainWindow(), TQ_SIGNAL( toolBarPositionChanged( TQToolBar * ) ),
253 this, TQ_SLOT( toolBarPosChanged( TQToolBar * ) ) );
256 connect(
this, TQ_SIGNAL(placeChanged(TQDockWindow::Place)), TQ_SLOT(rebuildLayout()) );
260 const TQString& text,
int index,
TDEInstance *_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,
TDEInstance *_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 TDEToolBarSeparator( orientation(),
false,
this,
"tool bar separator" );
399 insertWidgetInternal( w, index,
id );
405 TQWidget *w =
new TDEToolBarSeparator( 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, TQ_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() )
624 Id2WidgetMap::Iterator it = id2widget.find(
id );
625 if ( it == id2widget.end() )
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() <<
" TDEToolBar::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() <<
" TDEToolBar::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 ? TDEToolBar::Top : TDEToolBar::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 );
862 mw->setToolBarsMovable( !mw->toolBarsMovable() );
863 mw->setToolBarsMovable( !mw->toolBarsMovable() );
864 mw->setUpdatesEnabled(
true );
871 return d->m_iconText;
884 if ( size != d->m_iconSize ) {
885 d->m_iconSize = size;
896 if ( mainWindow() ) {
897 TQMainWindow *mw = mainWindow();
898 mw->setUpdatesEnabled(
false );
899 mw->setToolBarsMovable( !mw->toolBarsMovable() );
900 mw->setToolBarsMovable( !mw->toolBarsMovable() );
901 mw->setUpdatesEnabled(
true );
907 if ( !d->m_iconSize )
910 return d->m_iconSize;
915 if (!::qstrcmp(name(),
"mainToolBar"))
923 d->m_enableContext =
enable;
929 return d->m_enableContext;
941 void TDEToolBar::setFlat (
bool flag)
946 mainWindow()->moveDockWindow(
this, DockMinimized );
948 mainWindow()->moveDockWindow(
this, DockTop );
958 return id2widget.count();
965 if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() ) {
967 TQString barname(!::qstrcmp(name(),
"unnamed") ?
"mainToolBar" : name());
971 TQDomElement current;
972 for( TQDomNode n = d->m_xmlguiClient->domDocument().documentElement().firstChild();
973 !n.isNull(); n = n.nextSibling()) {
974 current = n.toElement();
976 if ( current.tagName().lower() !=
"toolbar" )
979 TQString curname(current.attribute(
"name" ));
981 if ( curname == barname ) {
991 TQString local_xml(KXMLGUIFactory::readConfigFile(d->m_xmlguiClient->xmlFile(),
true, d->m_xmlguiClient->instance()));
993 local.setContent(local_xml);
996 bool just_append =
true;
998 for( TQDomNode n = local.documentElement().firstChild();
999 !n.isNull(); n = n.nextSibling()) {
1000 TQDomElement elem = n.toElement();
1002 if ( elem.tagName().lower() !=
"toolbar" )
1005 TQString curname(elem.attribute(
"name" ));
1007 if ( curname == barname ) {
1008 just_append =
false;
1009 local.documentElement().replaceChild( current, elem );
1015 local.documentElement().appendChild( current );
1017 KXMLGUIFactory::saveConfigFile(local, d->m_xmlguiClient->localXMLFile(), d->m_xmlguiClient->instance() );
1028 TQString TDEToolBar::settingsGroup()
const
1030 TQString configGroup;
1031 if (!::qstrcmp(name(),
"unnamed") || !::qstrcmp(name(),
"mainToolBar"))
1032 configGroup =
"Toolbar style";
1034 configGroup = TQString(name()) +
" Toolbar style";
1035 if ( this->mainWindow() )
1037 configGroup.prepend(
" ");
1038 configGroup.prepend( this->mainWindow()->name() );
1045 TQString configGroup = _configGroup;
1046 if (configGroup.isEmpty())
1047 configGroup = settingsGroup();
1050 TQString position, icontext;
1052 getAttributes( position, icontext, index );
1058 if(!config->
hasDefault(
"Position") && position == d->PositionDefault )
1065 if(d->m_honorStyle && icontext == d->IconTextDefault && !config->
hasDefault(
"IconText") )
1081 if(!config->
hasDefault(
"Hidden") && isHidden() == d->HiddenDefault )
1101 TQPtrList<TDEToolBar> toolbarList;
1102 TQPtrList<TQToolBar> lst;
1103 for (
int i = (
int)TQMainWindow::DockUnmanaged; i <= (int)DockMinimized; ++i ) {
1104 lst = kmw->toolBars( (ToolBarDock)i );
1105 for ( TQToolBar *tb = lst.first(); tb; tb = lst.next() ) {
1106 if ( !tb->inherits(
"TDEToolBar" ) )
1111 TQPtrListIterator<TDEToolBar> toolbarIterator( toolbarList );
1112 if ( !kmw || toolbarIterator.count() > 1 )
1117 if(!config->
hasDefault(
"Offset") && offset() == d->OffsetDefault )
1122 if(!config->
hasDefault(
"NewLine") && newLine() == d->NewLineDefault )
1131 d->m_xmlguiClient = client;
1136 setLabel( txt +
" (" + kapp->caption() +
") " );
1148 connect(button, TQ_SIGNAL(
clicked(
int)),
this, TQ_SIGNAL(
clicked(
int ) ) );
1150 connect(button, TQ_SIGNAL(
released(
int)),
this, TQ_SIGNAL(
released(
int ) ) );
1151 connect(button, TQ_SIGNAL(
pressed(
int)),
this, TQ_SIGNAL(
pressed(
int ) ) );
1152 connect(button, TQ_SIGNAL(
toggled(
int)),
this, TQ_SIGNAL(
toggled(
int ) ) );
1156 void TDEToolBar::mousePressEvent ( TQMouseEvent *m )
1158 if ( !mainWindow() )
1160 TQMainWindow *mw = mainWindow();
1161 if ( mw->toolBarsMovable() && d->m_enableContext ) {
1162 if ( m->button() == TQt::RightButton ) {
1163 TQGuardedPtr<TDEToolBar> guard(
this );
1164 int i = contextMenu()->exec( m->globalPos(), 0 );
1167 slotContextAboutToHide();
1172 mw->moveDockWindow(
this, DockLeft );
1175 mw->moveDockWindow(
this, DockRight );
1178 mw->moveDockWindow(
this, DockTop );
1180 case CONTEXT_BOTTOM:
1181 mw->moveDockWindow(
this, DockBottom );
1184 mw->moveDockWindow(
this, DockTornOff );
1187 mw->moveDockWindow(
this, DockMinimized );
1192 case CONTEXT_TEXTRIGHT:
1198 case CONTEXT_TEXTUNDER:
1202 if ( i >= CONTEXT_ICONSIZES )
1214 void TDEToolBar::doModeChange()
1216 for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next())
1217 w->blockSignals(
false);
1218 d->idleButtons.clear();
1223 void TDEToolBar::rebuildLayout()
1225 for(TQWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next())
1226 w->blockSignals(
false);
1227 d->idleButtons.clear();
1229 layoutTimer->stop();
1230 TQApplication::sendPostedEvents(
this, TQEvent::ChildInserted );
1231 TQBoxLayout *l = boxLayout();
1234 TQLayoutIterator it = l->iterator();
1235 while ( it.current() )
1238 for ( TQWidget *w = widgets.first(); w; w = widgets.next() ) {
1239 if ( w == rightAligned )
1241 TDEToolBarSeparator *ktbs =
dynamic_cast<TDEToolBarSeparator *
>(w);
1242 if ( ktbs && !ktbs->showLine() ) {
1243 l->addSpacing( orientation() == TQt::Vertical ? w->sizeHint().height() : w->sizeHint().width() );
1247 if (
dynamic_cast<TQPopupMenu *
>(w) )
1251 if ((orientation() == TQt::Horizontal) &&
dynamic_cast<TQLineEdit *
>(w))
1254 if ( rightAligned ) {
1256 l->addWidget( rightAligned );
1257 rightAligned->show();
1261 if ( !rightAligned )
1263 if ( stretchableWidget )
1264 l->setStretchFactor( stretchableWidget, 10 );
1267 TQApplication::postEvent(
this,
new TQEvent( TQEvent::LayoutHint ) );
1270 void TDEToolBar::childEvent( TQChildEvent *e )
1272 if ( e->child()->isWidgetType() ) {
1273 TQWidget * w =
dynamic_cast<TQWidget *
>(e->child());
1274 if (!w || !(::qstrcmp(
"qt_dockwidget_internal", w->name())))
1276 TQToolBar::childEvent( e );
1279 if ( e->type() == TQEvent::ChildInserted ) {
1280 if ( !
dynamic_cast<TQPopupMenu *
>(w)) {
1283 if ( !widget2id.contains( w ) )
1286 insertWidgetInternal( w, dummy, -1 );
1290 removeWidgetInternal( w );
1292 if ( isVisibleTo( 0 ) )
1294 layoutTimer->start( 50,
true );
1295 TQBoxLayout *l = boxLayout();
1299 TQLayoutIterator it = l->iterator();
1300 while ( it.current() )
1304 TQToolBar::childEvent( e );
1307 void TDEToolBar::insertWidgetInternal( TQWidget *w,
int &index,
int id )
1312 connect( w, TQ_SIGNAL( destroyed() ),
1313 this, TQ_SLOT( widgetDestroyed() ) );
1314 if ( index == -1 || index > (
int)widgets.count() ) {
1315 index = (int)widgets.count();
1316 widgets.append( w );
1319 widgets.insert( index, w );
1321 id = id2widget.count();
1322 id2widget.insert(
id, w );
1323 widget2id.insert( w,
id );
1326 void TDEToolBar::showEvent( TQShowEvent *e )
1328 TQToolBar::showEvent( e );
1332 void TDEToolBar::setStretchableWidget( TQWidget *w )
1334 TQToolBar::setStretchableWidget( w );
1335 stretchableWidget = w;
1338 TQSizePolicy TDEToolBar::sizePolicy()
const
1340 if ( orientation() == TQt::Horizontal )
1341 return TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed );
1343 return TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Expanding );
1346 TQSize TDEToolBar::sizeHint()
const
1348 TQSize minSize(0,0);
1353 int margin = ncThis->layout()->margin() + frameWidth();
1356 case TDEToolBar::Top:
1357 case TDEToolBar::Bottom:
1358 for ( TQWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() )
1360 TQSize sh = w->sizeHint();
1361 if ( w->sizePolicy().horData() == TQSizePolicy::Ignored )
1363 if ( w->sizePolicy().verData() == TQSizePolicy::Ignored )
1365 sh = sh.boundedTo( w->maximumSize() )
1366 .expandedTo( w->minimumSize() ).expandedTo( TQSize(1, 1) );
1368 minSize = minSize.expandedTo(TQSize(0, sh.height()));
1369 minSize += TQSize(sh.width()+1, 0);
1370 if (
dynamic_cast<TQLineEdit *
>(w))
1371 minSize += TQSize(2, 0);
1374 minSize += TQSize(TQApplication::style().pixelMetric( TQStyle::PM_DockWindowHandleExtent ), 0);
1375 minSize += TQSize(margin*2, margin*2);
1378 case TDEToolBar::Left:
1379 case TDEToolBar::Right:
1380 for ( TQWidget *w = ncThis->widgets.first(); w; w = ncThis->widgets.next() )
1382 TQSize sh = w->sizeHint();
1383 if ( w->sizePolicy().horData() == TQSizePolicy::Ignored )
1385 if ( w->sizePolicy().verData() == TQSizePolicy::Ignored )
1387 sh = sh.boundedTo( w->maximumSize() )
1388 .expandedTo( w->minimumSize() ).expandedTo( TQSize(1, 1) );
1390 minSize = minSize.expandedTo(TQSize(sh.width(), 0));
1391 minSize += TQSize(0, sh.height()+1);
1393 minSize += TQSize(0, TQApplication::style().pixelMetric( TQStyle::PM_DockWindowHandleExtent ));
1394 minSize += TQSize(margin*2, margin*2);
1398 minSize = TQToolBar::sizeHint();
1404 TQSize TDEToolBar::minimumSize()
const
1406 return minimumSizeHint();
1409 TQSize TDEToolBar::minimumSizeHint()
const
1414 bool TDEToolBar::highlight()
const
1416 return d->m_highlight;
1419 void TDEToolBar::hide()
1424 void TDEToolBar::show()
1429 void TDEToolBar::resizeEvent( TQResizeEvent *e )
1431 bool b = isUpdatesEnabled();
1432 setUpdatesEnabled(
false );
1433 TQToolBar::resizeEvent( e );
1436 if (layoutTimer->isActive())
1439 d->repaintTimer.start( 100,
true );
1453 void TDEToolBar::slotIconChanged(
int group)
1466 void TDEToolBar::slotReadConfig()
1475 void TDEToolBar::slotAppearanceChanged()
1489 TQString grpToolbar(TQString::fromLatin1(
"Toolbar style"));
1497 TQString grpToolbar(TQString::fromLatin1(
"Toolbar style"));
1505 TQString grpToolbar(TQString::fromLatin1(
"Toolbar style"));
1508 if ( icontext ==
"IconTextRight" )
1509 return IconTextRight;
1510 else if ( icontext ==
"IconTextBottom" )
1511 return IconTextBottom;
1512 else if ( icontext ==
"TextOnly" )
1518 void TDEToolBar::applyAppearanceSettings(
TDEConfig *config,
const TQString &_configGroup,
bool forceGlobal)
1520 TQString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
1528 bool xmlgui = d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty();
1542 bool applyIconText = !xmlgui;
1543 bool applyIconSize = !xmlgui;
1546 TQString
iconText = d->IconTextDefault;
1549 TQString grpToolbar(TQString::fromLatin1(
"Toolbar style"));
1559 if (d->m_honorStyle)
1560 d->IconTextDefault = gconfig->
readEntry(attrIconText, d->IconTextDefault);
1562 d->IconTextDefault =
"IconOnly";
1565 d->IconSizeDefault = gconfig->
readNumEntry(attrIconSize, d->IconSizeDefault);
1570 if ( !forceGlobal && config->
hasGroup(configGroup) )
1575 highlight = config->
readBoolEntry(attrHighlight, highlight);
1576 transparent = config->
readBoolEntry(attrTrans, transparent);
1579 if ( config->
hasKey( attrIconText ) ) {
1581 applyIconText =
true;
1586 if ( config->
hasKey( attrIconSize ) ) {
1588 applyIconSize =
true;
1595 bool doUpdate =
false;
1599 icon_text = IconTextRight;
1600 else if (
iconText ==
"IconTextBottom" )
1601 icon_text = IconTextBottom;
1603 icon_text = TextOnly;
1605 icon_text = IconOnly;
1608 if (icon_text != d->m_iconText && applyIconText) {
1615 if (
iconSize != d->m_iconSize && applyIconSize) {
1620 TQMainWindow *mw = mainWindow();
1623 if ( highlight != d->m_highlight ) {
1624 d->m_highlight = highlight;
1629 if ( mw && transparent != (!mw->opaqueMoving()) ) {
1630 mw->setOpaqueMoving( !transparent );
1649 TQString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
1666 applyAppearanceSettings( config, configGroup );
1669 if ( config->
hasGroup(configGroup) || force )
1679 TQString position = config->
readEntry(attrPosition, d->PositionDefault);
1681 int offset = config->
readNumEntry(attrOffset, d->OffsetDefault);
1682 bool newLine = config->
readBoolEntry(attrNewLine, d->NewLineDefault);
1683 bool hidden = config->
readBoolEntry(attrHidden, d->HiddenDefault);
1686 if ( position ==
"Top" )
1688 else if ( position ==
"Bottom" )
1690 else if ( position ==
"Left" )
1692 else if ( position ==
"Right" )
1694 else if ( position ==
"Floating" )
1696 else if ( position ==
"Flat" )
1697 pos = DockMinimized;
1708 d->toolBarInfo = TDEToolBarPrivate::ToolBarInfo( pos, index, newLine, offset );
1716 bool TDEToolBar::event( TQEvent *e )
1718 if ( (e->type() == TQEvent::LayoutHint) && isUpdatesEnabled() )
1719 d->repaintTimer.start( 100,
true );
1721 if (e->type() == TQEvent::ChildInserted )
1726 childEvent((TQChildEvent *)e);
1730 return TQToolBar::event( e );
1733 void TDEToolBar::slotRepaint()
1735 setUpdatesEnabled(
false );
1739 TQResizeEvent ev(size(), size());
1741 TQApplication::sendPostedEvents(
this, TQEvent::LayoutHint );
1742 setUpdatesEnabled(
true );
1746 void TDEToolBar::toolBarPosChanged( TQToolBar *tb )
1750 if ( d->oldPos == DockMinimized )
1752 d->oldPos = (TQMainWindow::ToolBarDock)
barPos();
1758 static TDEToolBar::Dock stringToDock(
const TQString& attrPosition )
1760 TDEToolBar::Dock dock = TDEToolBar::DockTop;
1761 if ( !attrPosition.isEmpty() ) {
1762 if ( attrPosition ==
"top" )
1763 dock = TDEToolBar::DockTop;
1764 else if ( attrPosition ==
"left" )
1765 dock = TDEToolBar::DockLeft;
1766 else if ( attrPosition ==
"right" )
1767 dock = TDEToolBar::DockRight;
1768 else if ( attrPosition ==
"bottom" )
1769 dock = TDEToolBar::DockBottom;
1770 else if ( attrPosition ==
"floating" )
1771 dock = TDEToolBar::DockTornOff;
1772 else if ( attrPosition ==
"flat" )
1773 dock = TDEToolBar::DockMinimized;
1781 TQMainWindow *mw = mainWindow();
1787 TQCString
text = element.namedItem(
"text" ).toElement().text().utf8();
1788 if (
text.isEmpty() )
1789 text = element.namedItem(
"Text" ).toElement().text().utf8();
1790 if ( !
text.isEmpty() )
1795 TQCString attrFullWidth = element.attribute(
"fullWidth" ).lower().latin1();
1796 if ( !attrFullWidth.isEmpty() )
1816 bool loadingAppDefaults =
true;
1817 if ( element.hasAttribute(
"offsetDefault" ) )
1820 loadingAppDefaults =
false;
1821 d->OffsetDefault = element.attribute(
"offsetDefault" ).toInt();
1822 d->NewLineDefault = element.attribute(
"newlineDefault" ) ==
"true";
1823 d->HiddenDefault = element.attribute(
"hiddenDefault" ) ==
"true";
1824 d->IconSizeDefault = element.attribute(
"iconSizeDefault" ).toInt();
1825 d->PositionDefault = element.attribute(
"positionDefault" );
1826 d->IconTextDefault = element.attribute(
"iconTextDefault" );
1830 Dock dock = stringToDock( element.attribute(
"position" ).lower() );
1833 TQCString attrIconText = element.attribute(
"iconText" ).lower().latin1();
1834 if ( !attrIconText.isEmpty() ) {
1836 if ( attrIconText ==
"icontextright" )
1838 else if ( attrIconText ==
"textonly" )
1840 else if ( attrIconText ==
"icontextbottom" )
1842 else if ( attrIconText ==
"icononly" )
1848 if (d->m_honorStyle)
1855 TQString attrIconSize = element.attribute(
"iconSize" ).lower();
1857 if ( !attrIconSize.isEmpty() )
1864 TQString attrIndex = element.attribute(
"index" ).lower();
1865 if ( !attrIndex.isEmpty() )
1866 index = attrIndex.toInt();
1869 int offset = d->OffsetDefault;
1870 bool newLine = d->NewLineDefault;
1871 bool hidden = d->HiddenDefault;
1874 TQString attrOffset = element.attribute(
"offset" );
1875 if ( !attrOffset.isEmpty() )
1876 offset = attrOffset.toInt();
1880 TQString attrNewLine = element.attribute(
"newline" ).lower();
1881 if ( !attrNewLine.isEmpty() )
1882 newLine = attrNewLine ==
"true";
1886 TQString attrHidden = element.attribute(
"hidden" ).lower();
1887 if ( !attrHidden.isEmpty() ) {
1888 hidden = attrHidden ==
"true";
1892 d->toolBarInfo = TDEToolBarPrivate::ToolBarInfo( dock, index, newLine, offset );
1893 mw->addDockWindow(
this, dock, newLine );
1894 mw->moveDockWindow(
this, dock, newLine, index, offset );
1904 if ( loadingAppDefaults )
1906 getAttributes( d->PositionDefault, d->IconTextDefault, index );
1908 d->OffsetDefault = offset;
1909 d->NewLineDefault = newLine;
1910 d->HiddenDefault = hidden;
1923 int TDEToolBar::dockWindowIndex()
1926 Q_ASSERT( mainWindow() );
1927 if ( mainWindow() ) {
1928 TQMainWindow::ToolBarDock dock;
1931 mainWindow()->getLocation(
this, dock, index, newLine, offset );
1936 void TDEToolBar::getAttributes( TQString &position, TQString &icontext,
int &index )
1940 case TDEToolBar::Flat:
1943 case TDEToolBar::Bottom:
1944 position =
"Bottom";
1946 case TDEToolBar::Left:
1949 case TDEToolBar::Right:
1952 case TDEToolBar::Floating:
1953 position =
"Floating";
1955 case TDEToolBar::Top:
1961 index = dockWindowIndex();
1963 switch (d->m_iconText) {
1964 case TDEToolBar::IconTextRight:
1965 icontext =
"IconTextRight";
1967 case TDEToolBar::IconTextBottom:
1968 icontext =
"IconTextBottom";
1970 case TDEToolBar::TextOnly:
1971 icontext =
"TextOnly";
1973 case TDEToolBar::IconOnly:
1975 icontext =
"IconOnly";
1983 Q_ASSERT( !current.isNull() );
1984 TQString position, icontext;
1986 getAttributes( position, icontext, index );
1988 current.setAttribute(
"noMerge",
"1" );
1989 current.setAttribute(
"position", position );
1990 current.setAttribute(
"iconText", icontext );
1991 current.setAttribute(
"index", index );
1992 current.setAttribute(
"offset", offset() );
1993 current.setAttribute(
"newline", newLine() );
1995 current.setAttribute(
"hidden",
"true" );
2000 current.setAttribute(
"offsetDefault", d->OffsetDefault );
2001 current.setAttribute(
"newlineDefault", d->NewLineDefault );
2002 current.setAttribute(
"hiddenDefault", d->HiddenDefault ?
"true" :
"false" );
2003 current.setAttribute(
"iconSizeDefault", d->IconSizeDefault );
2004 current.setAttribute(
"positionDefault", d->PositionDefault );
2005 current.setAttribute(
"iconTextDefault", d->IconTextDefault );
2014 d->positioned =
false;
2016 if ( d->positioned || !mainWindow() )
2023 bool hidden = isHidden();
2025 mainWindow()->moveDockWindow(
this, d->toolBarInfo.dock,
2026 d->toolBarInfo.newline,
2027 d->toolBarInfo.index,
2028 d->toolBarInfo.offset );
2036 d->positioned =
true;
2045 context =
new TDEPopupMenu(
this,
"qt_dockwidget_internal" );
2049 orient->insertItem( i18n(
"toolbar position string",
"Top"), CONTEXT_TOP );
2050 orient->insertItem( i18n(
"toolbar position string",
"Left"), CONTEXT_LEFT );
2051 orient->insertItem( i18n(
"toolbar position string",
"Right"), CONTEXT_RIGHT );
2052 orient->insertItem( i18n(
"toolbar position string",
"Bottom"), CONTEXT_BOTTOM );
2053 orient->insertSeparator(-1);
2054 orient->insertItem( i18n(
"toolbar position string",
"Floating"), CONTEXT_FLOAT );
2055 orient->insertItem( i18n(
"min toolbar",
"Flat"), CONTEXT_FLAT );
2058 mode->insertItem( i18n(
"Icons Only"), CONTEXT_ICONS );
2059 mode->insertItem( i18n(
"Text Only"), CONTEXT_TEXT );
2060 mode->insertItem( i18n(
"Text Alongside Icons"), CONTEXT_TEXTRIGHT );
2061 mode->insertItem( i18n(
"Text Under Icons"), CONTEXT_TEXTUNDER );
2064 size->insertItem( i18n(
"Default"), CONTEXT_ICONSIZES );
2067 TQValueList<int> avSizes;
2070 if (!::qstrcmp(name(),
"mainToolBar"))
2076 d->iconSizes = avSizes;
2079 TQValueList<int>::Iterator it;
2080 if (avSizes.count() < 10) {
2082 TQValueList<int>::Iterator
end(avSizes.end());
2083 for (it=avSizes.begin(); it!=end; ++it) {
2086 text = i18n(
"Small (%1x%2)").arg(*it).arg(*it);
2088 text = i18n(
"Medium (%1x%2)").arg(*it).arg(*it);
2090 text = i18n(
"Large (%1x%2)").arg(*it).arg(*it);
2092 text = i18n(
"Huge (%1x%2)").arg(*it).arg(*it);
2094 size->insertItem(
text, CONTEXT_ICONSIZES + *it );
2099 const int progression[] = {16, 22, 32, 48, 64, 96, 128, 192, 256};
2101 it = avSizes.begin();
2102 for (uint i = 0; i < 9; i++) {
2103 while (it++ != avSizes.end()) {
2104 if (*it >= progression[i]) {
2107 text = i18n(
"Small (%1x%2)").arg(*it).arg(*it);
2109 text = i18n(
"Medium (%1x%2)").arg(*it).arg(*it);
2111 text = i18n(
"Large (%1x%2)").arg(*it).arg(*it);
2113 text = i18n(
"Huge (%1x%2)").arg(*it).arg(*it);
2115 size->insertItem(
text, CONTEXT_ICONSIZES + *it );
2122 context->insertItem( i18n(
"Orientation"), orient );
2123 orient->setItemChecked(CONTEXT_TOP,
true);
2124 context->insertItem( i18n(
"Text Position"), mode );
2125 context->setItemChecked(CONTEXT_ICONS,
true);
2126 context->insertItem( i18n(
"Icon Size"), size );
2128 connect( context, TQ_SIGNAL( aboutToShow() ),
this, TQ_SLOT( slotContextAboutToShow() ) );
2135 void TDEToolBar::slotContextAboutToShow()
2147 if ( tbAction && tbAction->containerCount() > 0 )
2148 tbAction->
plug(context);
2154 if ( d->m_xmlguiClient )
2155 configureAction = d->m_xmlguiClient->actionCollection()->action(actionName);
2156 if ( !configureAction && kmw )
2158 if ( configureAction )
2159 configureAction->
plug(context);
2162 for(
int i = CONTEXT_ICONS; i <= CONTEXT_TEXTUNDER; ++i)
2163 context->setItemChecked(i,
false);
2165 switch( d->m_iconText )
2169 context->setItemChecked(CONTEXT_ICONS,
true);
2172 context->setItemChecked(CONTEXT_TEXTRIGHT,
true);
2175 context->setItemChecked(CONTEXT_TEXT,
true);
2177 case IconTextBottom:
2178 context->setItemChecked(CONTEXT_TEXTUNDER,
true);
2182 TQValueList<int>::ConstIterator iIt = d->iconSizes.begin();
2183 TQValueList<int>::ConstIterator iEnd = d->iconSizes.end();
2184 for (; iIt != iEnd; ++iIt )
2185 context->setItemChecked( CONTEXT_ICONSIZES + *iIt,
false );
2187 context->setItemChecked( CONTEXT_ICONSIZES,
false );
2189 context->setItemChecked( CONTEXT_ICONSIZES + d->m_iconSize,
true );
2191 for (
int i = CONTEXT_TOP; i <= CONTEXT_FLAT; ++i )
2192 context->setItemChecked( i,
false );
2196 case TDEToolBar::Flat:
2197 context->setItemChecked( CONTEXT_FLAT,
true );
2199 case TDEToolBar::Bottom:
2200 context->setItemChecked( CONTEXT_BOTTOM,
true );
2202 case TDEToolBar::Left:
2203 context->setItemChecked( CONTEXT_LEFT,
true );
2205 case TDEToolBar::Right:
2206 context->setItemChecked( CONTEXT_RIGHT,
true );
2208 case TDEToolBar::Floating:
2209 context->setItemChecked( CONTEXT_FLOAT,
true );
2211 case TDEToolBar::Top:
2212 context->setItemChecked( CONTEXT_TOP,
true );
2218 void TDEToolBar::slotContextAboutToHide()
2230 if ( d->m_xmlguiClient )
2231 configureAction = d->m_xmlguiClient->actionCollection()->action(actionName);
2232 if ( !configureAction && kmw )
2234 if ( configureAction )
2235 configureAction->
unplug(context);
2237 TQPtrListIterator<TQWidget> it( widgets );
2239 while ( ( wdg = it.current() ) != 0 ) {
2240 if ( wdg->inherits(
"TQToolButton" ) )
2241 static_cast<TQToolButton*
>( wdg )->setDown(
false );
2246 void TDEToolBar::widgetDestroyed()
2248 removeWidgetInternal( (TQWidget*)sender() );
2251 void TDEToolBar::removeWidgetInternal( TQWidget * w )
2253 widgets.removeRef( w );
2254 TQMap< TQWidget*, int >::Iterator it = widget2id.find( w );
2255 if ( it == widget2id.end() )
2257 id2widget.remove( *it );
2258 widget2id.remove( it );
2261 void TDEToolBar::virtual_hook(
int,
void* )
2264 #include "tdetoolbar.moc"
void setCurrentItem(const TQString &item, bool insert=false, int index=-1)
Selects the first item that matches item.
An enhanced TQLineEdit widget for inputting text.
virtual void setText(const TQString &)
Re-implemented to enable text squeezing.
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document,...
virtual TDEActionCollection * actionCollection() const
Retrieves the entire action collection for the GUI client.
virtual TDEAction * action(int index) const
Return the TDEAction* at position "index" in the action collection.
Class to encapsulate user-driven action or event.
virtual void unplug(TQWidget *w)
"Unplug" or remove this action from a given widget.
virtual int plug(TQWidget *widget, int index=-1)
"Plug" or insert this action into a given widget.
bool hasDefault(const TQString &key) const
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
void revertToDefault(const TQString &key)
int readNumEntry(const TQString &pKey, int nDefault=0) const
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
bool hasGroup(const TQString &group) const
bool hasKey(const TQString &key) const
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void setGroup(const TQString &group)
static TDEIconLoader * iconLoader()
static TDEConfig * config()
static TDEInstance * instance()
static const TQString & staticQString(const char *str)
int currentSize(TDEIcon::Group group) const
TDEIconTheme * theme() const
TQValueList< int > querySizes(TDEIcon::Group group) const
TDEIconLoader * iconLoader() const
KDE top level main window
void setupToolbarMenuActions()
TDEAction * toolBarMenuAction()
Returns a pointer to the mainwindows action responsible for the toolbars menu.
void setSettingsDirty()
Apply a state change.
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
const char * name(StdAction id)
This will return the internal name of a given standard action.
TQString name(StdAccel id)
const TDEShortcut & end()