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 virtual bool eventFilter( QObject*, QEvent* );
25 virtual void customEvent( QCustomEvent* );
28 void installFilters();
32 void updateVisibility();
36 QtxDockWindow* myCont;
39 QtxDockWindow::Watcher::Watcher( QtxDockWindow* cont )
40 : QObject( cont ), myCont( cont ),
43 if ( myCont->mainWindow() )
44 myVis = myCont->mainWindow()->appropriate( myCont );
46 myCont->installEventFilter( this );
51 bool QtxDockWindow::Watcher::eventFilter( QObject* o, QEvent* e )
54 ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ||
55 e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ||
56 e->type() == QEvent::ChildInserted ) )
57 QApplication::postEvent( this, new QCustomEvent( QEvent::User ) );
59 if ( o != myCont && e->type() == QEvent::IconChange )
62 if ( o != myCont && e->type() == QEvent::CaptionChange )
66 ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ||
67 e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ||
68 e->type() == QEvent::ChildRemoved ) )
74 void QtxDockWindow::Watcher::customEvent( QCustomEvent* e )
83 void QtxDockWindow::Watcher::installFilters()
88 QBoxLayout* bl = myCont->boxLayout();
92 for ( QLayoutIterator it = bl->iterator(); it.current(); ++it )
94 if ( it.current()->widget() )
95 it.current()->widget()->installEventFilter( this );
99 void QtxDockWindow::Watcher::updateVisibility()
104 QBoxLayout* bl = myCont->boxLayout();
109 for ( QLayoutIterator it = bl->iterator(); it.current() && !vis; ++it )
110 vis = it.current()->widget() && it.current()->widget()->isVisibleTo( myCont );
112 QMainWindow* mw = myCont->mainWindow();
116 mw->setAppropriate( myCont, myVis );
119 myVis = mw->appropriate( myCont );
120 mw->setAppropriate( myCont, false );
124 if ( vis != myCont->isVisibleTo( myCont->parentWidget() ) )
125 vis ? myCont->show() : myCont->hide();
128 void QtxDockWindow::Watcher::updateIcon()
130 if ( !myCont || !myCont->widget() )
133 const QPixmap* ico = myCont->widget()->icon();
134 myCont->setIcon( ico ? *ico : QPixmap() );
137 void QtxDockWindow::Watcher::updateCaption()
139 if ( myCont && myCont->widget() && !myCont->widget()->caption().isNull() )
140 myCont->setCaption( myCont->widget()->caption() );
144 Class: QtxDockWindow [Public]
148 QtxDockWindow::QtxDockWindow( Place p, QWidget* parent, const char* name, WFlags f )
149 : QDockWindow( p, parent, name, f ),
155 QtxDockWindow::QtxDockWindow( const bool watch, QWidget* parent, const char* name, WFlags f )
156 : QDockWindow( InDock, parent, name, f ),
161 myWatcher = new Watcher( this );
164 QtxDockWindow::QtxDockWindow( QWidget* parent, const char* name, WFlags f )
165 : QDockWindow( InDock, parent, name, f ),
171 QtxDockWindow::~QtxDockWindow()
175 void QtxDockWindow::setWidget( QWidget* wid )
178 wid->reparent( this, QPoint( 0, 0 ), wid->isVisibleTo( wid->parentWidget() ) );
180 QDockWindow::setWidget( wid );
183 bool QtxDockWindow::isStretchable() const
188 void QtxDockWindow::setStretchable( const bool on )
190 if ( myStretch == on )
195 boxLayout()->setStretchFactor( widget(), myStretch ? 1 : 0 );
197 if ( myStretch != isHorizontalStretchable() ||
198 myStretch != isVerticalStretchable() )
200 if ( orientation() == Horizontal )
201 setHorizontalStretchable( myStretch );
203 setVerticalStretchable( myStretch );
207 QSize QtxDockWindow::sizeHint() const
209 QSize sz = QDockWindow::sizeHint();
211 if ( place() == InDock && isStretchable() && area() )
213 if ( orientation() == Horizontal )
214 sz.setWidth( area()->width() );
216 sz.setHeight( area()->height() );
222 QSize QtxDockWindow::minimumSizeHint() const
224 QSize sz = QDockWindow::minimumSizeHint();
226 if ( orientation() == Horizontal )
227 sz = QSize( 0, QDockWindow::minimumSizeHint().height() );
229 sz = QSize( QDockWindow::minimumSizeHint().width(), 0 );
231 if ( place() == InDock && isStretchable() && area() )
233 if ( orientation() == Horizontal )
234 sz.setWidth( area()->width() );
236 sz.setHeight( area()->height() );
242 QMainWindow* QtxDockWindow::mainWindow() const
246 QWidget* wid = parentWidget();
249 if ( wid->inherits( "QMainWindow" ) )
250 mw = (QMainWindow*)wid;
251 wid = wid->parentWidget();