1 // File: QtxToolBar.cxx
2 // Author: Sergey TELKOV
4 #include "QtxToolBar.h"
9 #include <qobjectlist.h>
10 #include <qmainwindow.h>
11 #include <qapplication.h>
14 Class: QtxToolBar::Watcher [Internal]
15 Descr: Internal object with event filter.
18 class QtxToolBar::Watcher : public QObject
21 Watcher( QtxToolBar* );
23 virtual bool eventFilter( QObject*, QEvent* );
26 virtual void customEvent( QCustomEvent* );
29 enum { Install = QEvent::User, Update };
32 void installFilters();
36 void updateVisibility();
43 QtxToolBar::Watcher::Watcher( QtxToolBar* cont )
48 if ( myCont->mainWindow() )
49 myVis = myCont->mainWindow()->appropriate( myCont );
51 myCont->installEventFilter( this );
56 bool QtxToolBar::Watcher::eventFilter( QObject* o, QEvent* e )
58 if ( o == myCont && e->type() == QEvent::ChildInserted )
59 QApplication::postEvent( this, new QCustomEvent( Install ) );
61 if ( o != myCont && e->type() == QEvent::IconChange )
64 if ( o != myCont && e->type() == QEvent::CaptionChange )
67 bool updVis = ( o != myCont && ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ||
68 e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) ||
69 ( o == myCont && e->type() == QEvent::ChildRemoved );
73 QtxToolBar* cont = myCont;
75 QApplication::sendPostedEvents( this, Update );
77 QApplication::postEvent( this, new QCustomEvent( Update ) );
83 void QtxToolBar::Watcher::customEvent( QCustomEvent* e )
96 void QtxToolBar::Watcher::installFilters()
101 const QObjectList* objList = myCont->children();
105 for ( QObjectListIt it( *objList ); it.current(); ++it )
107 if ( it.current()->isWidgetType() &&
108 qstrcmp( "qt_dockwidget_internal", it.current()->name() ) )
109 it.current()->installEventFilter( this );
113 void QtxToolBar::Watcher::updateVisibility()
120 const QObjectList* objList = myCont->children();
123 for ( QObjectListIt it( *objList ); it.current() && !vis; ++it )
125 if ( !it.current()->isWidgetType() ||
126 !qstrcmp( "qt_dockwidget_internal", it.current()->name() ) )
129 QWidget* wid = (QWidget*)it.current();
130 vis = wid->isVisibleTo( wid->parentWidget() );
134 QMainWindow* mw = myCont->mainWindow();
138 mw->setAppropriate( myCont, myVis );
141 myVis = mw->appropriate( myCont );
142 mw->setAppropriate( myCont, false );
152 void QtxToolBar::Watcher::updateIcon()
154 if ( !myCont || !myCont->widget() )
157 const QPixmap* ico = myCont->widget()->icon();
158 myCont->setIcon( ico ? *ico : QPixmap() );
161 void QtxToolBar::Watcher::updateCaption()
163 if ( myCont && myCont->widget() && !myCont->widget()->caption().isNull() )
164 myCont->setCaption( myCont->widget()->caption() );
168 Class: QtxToolBar [Public]
172 QtxToolBar::QtxToolBar( const bool watch, const QString& label, QMainWindow* main,
173 QWidget* parent, bool newLine, const char* name, WFlags f )
174 : QToolBar( label, main, parent, newLine, name, f ),
179 myWatcher = new Watcher( this );
182 QtxToolBar::QtxToolBar( const QString& label, QMainWindow* main,
183 QWidget* parent, bool newLine, const char* name, WFlags f )
184 : QToolBar( label, main, parent, newLine, name, f ),
190 QtxToolBar::QtxToolBar( const bool watch, QMainWindow* main, const char* name )
191 : QToolBar( main, name ),
196 myWatcher = new Watcher( this );
199 QtxToolBar::QtxToolBar( QMainWindow* main, const char* name )
200 : QToolBar( main, name ),
206 QtxToolBar::~QtxToolBar()
210 void QtxToolBar::setWidget( QWidget* wid )
213 wid->reparent( this, QPoint( 0, 0 ), wid->isVisibleTo( wid->parentWidget() ) );
215 QToolBar::setWidget( wid );
220 for ( QLayoutIterator it = boxLayout()->iterator(); it.current(); ++it )
222 if ( it.current()->widget() == wid )
230 bool QtxToolBar::isStretchable() const
235 void QtxToolBar::setStretchable( const bool on )
237 if ( myStretch == on )
242 boxLayout()->setStretchFactor( widget(), myStretch ? 1 : 0 );
244 if ( myStretch != isHorizontalStretchable() ||
245 myStretch != isVerticalStretchable() )
247 if ( orientation() == Horizontal )
248 setHorizontalStretchable( myStretch );
250 setVerticalStretchable( myStretch );
254 QSize QtxToolBar::sizeHint() const
256 QSize sz = QToolBar::sizeHint();
258 if ( place() == InDock && isStretchable() && area() )
260 if ( orientation() == Horizontal )
261 sz.setWidth( area()->width() );
263 sz.setHeight( area()->height() );
269 QSize QtxToolBar::minimumSizeHint() const
271 QSize sz = QToolBar::minimumSizeHint();
273 if ( place() == InDock && isStretchable() && area() )
275 if ( orientation() == Horizontal )
276 sz.setWidth( area()->width() );
278 sz.setHeight( area()->height() );