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 )
75 if ( ( o != myCont && ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) ||
76 ( o == myCont && ( e->type() == QEvent::ChildRemoved ) ) ||
77 ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) )
83 void QtxDockWindow::Watcher::shown( QtxDockWindow* dw )
91 void QtxDockWindow::Watcher::hided( QtxDockWindow* dw )
99 void QtxDockWindow::Watcher::showContainer()
104 QtxDockWindow* cont = myCont;
110 void QtxDockWindow::Watcher::hideContainer()
115 QtxDockWindow* cont = myCont;
121 void QtxDockWindow::Watcher::customEvent( QCustomEvent* e )
130 void QtxDockWindow::Watcher::installFilters()
135 QBoxLayout* bl = myCont->boxLayout();
139 for ( QLayoutIterator it = bl->iterator(); it.current(); ++it )
141 if ( it.current()->widget() )
142 it.current()->widget()->installEventFilter( this );
146 void QtxDockWindow::Watcher::updateVisibility()
151 QBoxLayout* bl = myCont->boxLayout();
156 for ( QLayoutIterator it = bl->iterator(); it.current() && !vis; ++it )
157 vis = it.current()->widget() && it.current()->widget()->isVisibleTo( myCont );
159 QMainWindow* mw = myCont->mainWindow();
160 if ( mw && myEmpty == vis )
164 mw->setAppropriate( myCont, myState );
167 myState = mw->appropriate( myCont );
168 mw->setAppropriate( myCont, false );
172 vis = !myEmpty && myVisible;
173 if ( vis != myCont->isVisibleTo( myCont->parentWidget() ) )
174 vis ? showContainer() : hideContainer();
177 void QtxDockWindow::Watcher::updateIcon()
179 if ( !myCont || !myCont->widget() )
182 const QPixmap* ico = myCont->widget()->icon();
183 myCont->setIcon( ico ? *ico : QPixmap() );
186 void QtxDockWindow::Watcher::updateCaption()
188 if ( myCont && myCont->widget() && !myCont->widget()->caption().isNull() )
189 myCont->setCaption( myCont->widget()->caption() );
193 Class: QtxDockWindow [Public]
197 QtxDockWindow::QtxDockWindow( Place p, QWidget* parent, const char* name, WFlags f )
198 : QDockWindow( p, parent, name, f ),
204 QtxDockWindow::QtxDockWindow( const bool watch, QWidget* parent, const char* name, WFlags f )
205 : QDockWindow( InDock, parent, name, f ),
210 myWatcher = new Watcher( this );
213 QtxDockWindow::QtxDockWindow( QWidget* parent, const char* name, WFlags f )
214 : QDockWindow( InDock, parent, name, f ),
220 QtxDockWindow::~QtxDockWindow()
224 void QtxDockWindow::setWidget( QWidget* wid )
227 wid->reparent( this, QPoint( 0, 0 ), wid->isVisibleTo( wid->parentWidget() ) );
229 QDockWindow::setWidget( wid );
232 bool QtxDockWindow::isStretchable() const
237 void QtxDockWindow::setStretchable( const bool on )
239 if ( myStretch == on )
244 boxLayout()->setStretchFactor( widget(), myStretch ? 1 : 0 );
246 if ( myStretch != isHorizontalStretchable() ||
247 myStretch != isVerticalStretchable() )
249 if ( orientation() == Horizontal )
250 setHorizontalStretchable( myStretch );
252 setVerticalStretchable( myStretch );
256 QSize QtxDockWindow::sizeHint() const
258 QSize sz = QDockWindow::sizeHint();
260 if ( place() == InDock && isStretchable() && area() )
262 if ( orientation() == Horizontal )
263 sz.setWidth( area()->width() );
265 sz.setHeight( area()->height() );
271 QSize QtxDockWindow::minimumSizeHint() const
273 QSize sz = QDockWindow::minimumSizeHint();
275 if ( orientation() == Horizontal )
276 sz = QSize( 0, QDockWindow::minimumSizeHint().height() );
278 sz = QSize( QDockWindow::minimumSizeHint().width(), 0 );
280 if ( place() == InDock && isStretchable() && area() )
282 if ( orientation() == Horizontal )
283 sz.setWidth( area()->width() );
285 sz.setHeight( area()->height() );
291 QMainWindow* QtxDockWindow::mainWindow() const
295 QWidget* wid = parentWidget();
298 if ( wid->inherits( "QMainWindow" ) )
299 mw = (QMainWindow*)wid;
300 wid = wid->parentWidget();
306 void QtxDockWindow::show()
309 myWatcher->shown( this );
314 void QtxDockWindow::hide()
317 myWatcher->hided( this );