1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 // File: QtxDockWindow.cxx
20 // Author: Sergey TELKOV
22 #include "QtxDockWindow.h"
26 #include <qdockarea.h>
27 #include <qmainwindow.h>
28 #include <qapplication.h>
31 Class: QtxDockWindow::Watcher [Internal]
32 Descr: Internal object with event filter.
35 class QtxDockWindow::Watcher : public QObject
38 Watcher( QtxDockWindow* );
40 void shown( QtxDockWindow* );
41 void hided( QtxDockWindow* );
43 virtual bool eventFilter( QObject*, QEvent* );
46 virtual void customEvent( QCustomEvent* );
49 void installFilters();
56 void updateVisibility();
59 QtxDockWindow* myCont;
65 QtxDockWindow::Watcher::Watcher( QtxDockWindow* cont )
66 : QObject( cont ), myCont( cont ),
70 if ( myCont->mainWindow() )
71 myState = myCont->mainWindow()->appropriate( myCont );
73 myCont->installEventFilter( this );
74 myVisible = myCont->isVisibleTo( myCont->parentWidget() );
79 bool QtxDockWindow::Watcher::eventFilter( QObject* o, QEvent* e )
82 ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ||
83 e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ||
84 e->type() == QEvent::ChildInserted ) )
85 QApplication::postEvent( this, new QCustomEvent( QEvent::User ) );
87 if ( o != myCont && e->type() == QEvent::IconChange )
90 if ( o != myCont && e->type() == QEvent::CaptionChange )
93 if ( ( o != myCont && ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) ||
94 ( o == myCont && ( e->type() == QEvent::ChildRemoved ) ) ||
95 ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) )
101 void QtxDockWindow::Watcher::shown( QtxDockWindow* dw )
109 void QtxDockWindow::Watcher::hided( QtxDockWindow* dw )
117 void QtxDockWindow::Watcher::showContainer()
122 QtxDockWindow* cont = myCont;
128 void QtxDockWindow::Watcher::hideContainer()
133 QtxDockWindow* cont = myCont;
139 void QtxDockWindow::Watcher::customEvent( QCustomEvent* e )
148 void QtxDockWindow::Watcher::installFilters()
153 QBoxLayout* bl = myCont->boxLayout();
157 for ( QLayoutIterator it = bl->iterator(); it.current(); ++it )
159 if ( it.current()->widget() )
160 it.current()->widget()->installEventFilter( this );
164 void QtxDockWindow::Watcher::updateVisibility()
169 QBoxLayout* bl = myCont->boxLayout();
174 for ( QLayoutIterator it = bl->iterator(); it.current() && !vis; ++it )
175 vis = it.current()->widget() && it.current()->widget()->isVisibleTo( myCont );
177 QMainWindow* mw = myCont->mainWindow();
178 if ( mw && myEmpty == vis )
182 mw->setAppropriate( myCont, myState );
185 myState = mw->appropriate( myCont );
186 mw->setAppropriate( myCont, false );
190 vis = !myEmpty && myVisible;
191 if ( vis != myCont->isVisibleTo( myCont->parentWidget() ) )
192 vis ? showContainer() : hideContainer();
195 void QtxDockWindow::Watcher::updateIcon()
197 if ( !myCont || !myCont->widget() )
200 const QPixmap* ico = myCont->widget()->icon();
201 myCont->setIcon( ico ? *ico : QPixmap() );
204 void QtxDockWindow::Watcher::updateCaption()
206 if ( myCont && myCont->widget() && !myCont->widget()->caption().isNull() )
207 myCont->setCaption( myCont->widget()->caption() );
211 Class: QtxDockWindow [Public]
215 QtxDockWindow::QtxDockWindow( Place p, QWidget* parent, const char* name, WFlags f )
216 : QDockWindow( p, parent, name, f ),
222 QtxDockWindow::QtxDockWindow( const bool watch, QWidget* parent, const char* name, WFlags f )
223 : QDockWindow( InDock, parent, name, f ),
228 myWatcher = new Watcher( this );
231 QtxDockWindow::QtxDockWindow( QWidget* parent, const char* name, WFlags f )
232 : QDockWindow( InDock, parent, name, f ),
238 QtxDockWindow::~QtxDockWindow()
242 void QtxDockWindow::setWidget( QWidget* wid )
245 wid->reparent( this, QPoint( 0, 0 ), wid->isVisibleTo( wid->parentWidget() ) );
247 QDockWindow::setWidget( wid );
250 bool QtxDockWindow::isStretchable() const
255 void QtxDockWindow::setStretchable( const bool on )
257 if ( myStretch == on )
262 boxLayout()->setStretchFactor( widget(), myStretch ? 1 : 0 );
264 if ( myStretch != isHorizontalStretchable() ||
265 myStretch != isVerticalStretchable() )
267 if ( orientation() == Horizontal )
268 setHorizontalStretchable( myStretch );
270 setVerticalStretchable( myStretch );
274 QSize QtxDockWindow::sizeHint() const
276 QSize sz = QDockWindow::sizeHint();
278 if ( place() == InDock && isStretchable() && area() )
280 if ( orientation() == Horizontal )
281 sz.setWidth( area()->width() );
283 sz.setHeight( area()->height() );
289 QSize QtxDockWindow::minimumSizeHint() const
291 QSize sz = QDockWindow::minimumSizeHint();
293 if ( orientation() == Horizontal )
294 sz = QSize( 0, QDockWindow::minimumSizeHint().height() );
296 sz = QSize( QDockWindow::minimumSizeHint().width(), 0 );
298 if ( place() == InDock && isStretchable() && area() )
300 if ( orientation() == Horizontal )
301 sz.setWidth( area()->width() );
303 sz.setHeight( area()->height() );
309 QMainWindow* QtxDockWindow::mainWindow() const
313 QWidget* wid = parentWidget();
316 if ( wid->inherits( "QMainWindow" ) )
317 mw = (QMainWindow*)wid;
318 wid = wid->parentWidget();
324 void QtxDockWindow::show()
327 myWatcher->shown( this );
332 void QtxDockWindow::hide()
335 myWatcher->hided( this );