1 // File: QtxDockWindow.cxx
2 // Author: Sergey TELKOV
4 #include "QtxDockWindow.h"
9 #include <qmainwindow.h>
10 #include <qapplication.h>
13 Class: QtxDockWindow::Watcher [Internal]
14 Descr: Internal object with event filter.
17 class QtxDockWindow::Watcher : public QObject
20 Watcher( QtxDockWindow* );
22 void shown( QtxDockWindow* );
23 void hided( QtxDockWindow* );
25 virtual bool eventFilter( QObject*, QEvent* );
28 virtual void customEvent( QCustomEvent* );
31 void installFilters();
38 void updateVisibility();
41 QtxDockWindow* myCont;
47 QtxDockWindow::Watcher::Watcher( QtxDockWindow* cont )
48 : QObject( cont ), myCont( cont ),
52 if ( myCont->mainWindow() )
53 myState = myCont->mainWindow()->appropriate( myCont );
55 myCont->installEventFilter( this );
56 myVisible = myCont->isVisibleTo( myCont->parentWidget() );
61 bool QtxDockWindow::Watcher::eventFilter( QObject* o, QEvent* e )
64 ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ||
65 e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ||
66 e->type() == QEvent::ChildInserted ) )
67 QApplication::postEvent( this, new QCustomEvent( QEvent::User ) );
69 if ( o != myCont && e->type() == QEvent::IconChange )
72 if ( o != myCont && e->type() == QEvent::CaptionChange )
76 ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ||
77 e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ||
78 e->type() == QEvent::ChildRemoved ) )
84 void QtxDockWindow::Watcher::shown( QtxDockWindow* dw )
92 void QtxDockWindow::Watcher::hided( QtxDockWindow* dw )
100 void QtxDockWindow::Watcher::showContainer()
105 QtxDockWindow* cont = myCont;
111 void QtxDockWindow::Watcher::hideContainer()
116 QtxDockWindow* cont = myCont;
122 void QtxDockWindow::Watcher::customEvent( QCustomEvent* e )
131 void QtxDockWindow::Watcher::installFilters()
136 QBoxLayout* bl = myCont->boxLayout();
140 for ( QLayoutIterator it = bl->iterator(); it.current(); ++it )
142 if ( it.current()->widget() )
143 it.current()->widget()->installEventFilter( this );
147 void QtxDockWindow::Watcher::updateVisibility()
152 QBoxLayout* bl = myCont->boxLayout();
157 for ( QLayoutIterator it = bl->iterator(); it.current() && !vis; ++it )
158 vis = it.current()->widget() && it.current()->widget()->isVisibleTo( myCont );
160 QMainWindow* mw = myCont->mainWindow();
161 if ( mw && myEmpty != vis )
165 mw->setAppropriate( myCont, myState );
168 myState = mw->appropriate( myCont );
169 mw->setAppropriate( myCont, false );
173 vis = myEmpty && myVisible;
174 if ( vis != myCont->isVisibleTo( myCont->parentWidget() ) )
175 vis ? showContainer() : hideContainer();
178 void QtxDockWindow::Watcher::updateIcon()
180 if ( !myCont || !myCont->widget() )
183 const QPixmap* ico = myCont->widget()->icon();
184 myCont->setIcon( ico ? *ico : QPixmap() );
187 void QtxDockWindow::Watcher::updateCaption()
189 if ( myCont && myCont->widget() && !myCont->widget()->caption().isNull() )
190 myCont->setCaption( myCont->widget()->caption() );
194 Class: QtxDockWindow [Public]
198 QtxDockWindow::QtxDockWindow( Place p, QWidget* parent, const char* name, WFlags f )
199 : QDockWindow( p, parent, name, f ),
205 QtxDockWindow::QtxDockWindow( const bool watch, QWidget* parent, const char* name, WFlags f )
206 : QDockWindow( InDock, parent, name, f ),
211 myWatcher = new Watcher( this );
214 QtxDockWindow::QtxDockWindow( QWidget* parent, const char* name, WFlags f )
215 : QDockWindow( InDock, parent, name, f ),
221 QtxDockWindow::~QtxDockWindow()
225 void QtxDockWindow::setWidget( QWidget* wid )
228 wid->reparent( this, QPoint( 0, 0 ), wid->isVisibleTo( wid->parentWidget() ) );
230 QDockWindow::setWidget( wid );
233 bool QtxDockWindow::isStretchable() const
238 void QtxDockWindow::setStretchable( const bool on )
240 if ( myStretch == on )
245 boxLayout()->setStretchFactor( widget(), myStretch ? 1 : 0 );
247 if ( myStretch != isHorizontalStretchable() ||
248 myStretch != isVerticalStretchable() )
250 if ( orientation() == Horizontal )
251 setHorizontalStretchable( myStretch );
253 setVerticalStretchable( myStretch );
257 QSize QtxDockWindow::sizeHint() const
259 QSize sz = QDockWindow::sizeHint();
261 if ( place() == InDock && isStretchable() && area() )
263 if ( orientation() == Horizontal )
264 sz.setWidth( area()->width() );
266 sz.setHeight( area()->height() );
272 QSize QtxDockWindow::minimumSizeHint() const
274 QSize sz = QDockWindow::minimumSizeHint();
276 if ( orientation() == Horizontal )
277 sz = QSize( 0, QDockWindow::minimumSizeHint().height() );
279 sz = QSize( QDockWindow::minimumSizeHint().width(), 0 );
281 if ( place() == InDock && isStretchable() && area() )
283 if ( orientation() == Horizontal )
284 sz.setWidth( area()->width() );
286 sz.setHeight( area()->height() );
292 QMainWindow* QtxDockWindow::mainWindow() const
296 QWidget* wid = parentWidget();
299 if ( wid->inherits( "QMainWindow" ) )
300 mw = (QMainWindow*)wid;
301 wid = wid->parentWidget();
307 void QtxDockWindow::show()
310 myWatcher->shown( this );
315 void QtxDockWindow::hide()
318 myWatcher->hided( this );