X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FQtx%2FQtxToolBar.cxx;h=ae46ca5b87d603fff0c2d3b8207db40e16f79d3f;hb=4915803800e885696c8063715c30b2b0df170f91;hp=094923942b4516f467fd561f86c689a77c89f990;hpb=4d7899038653ed1ada6764e0afb3683bcdb47105;p=modules%2Fgui.git diff --git a/src/Qtx/QtxToolBar.cxx b/src/Qtx/QtxToolBar.cxx index 094923942..ae46ca5b8 100644 --- a/src/Qtx/QtxToolBar.cxx +++ b/src/Qtx/QtxToolBar.cxx @@ -20,6 +20,9 @@ class QtxToolBar::Watcher : public QObject public: Watcher( QtxToolBar* ); + void shown( QtxToolBar* ); + void hided( QtxToolBar* ); + virtual bool eventFilter( QObject*, QEvent* ); protected: @@ -31,24 +34,31 @@ private: private: void installFilters(); + void showContainer(); + void hideContainer(); + void updateIcon(); void updateCaption(); void updateVisibility(); private: - bool myVis; QtxToolBar* myCont; + bool myState; + bool myEmpty; + bool myVisible; }; QtxToolBar::Watcher::Watcher( QtxToolBar* cont ) : QObject( cont ), myCont( cont ), -myVis( true ) +myState( true ), +myEmpty( true ) { if ( myCont->mainWindow() ) - myVis = myCont->mainWindow()->appropriate( myCont ); + myState = myCont->mainWindow()->appropriate( myCont ); myCont->installEventFilter( this ); + myVisible = myCont->isVisibleTo( myCont->parentWidget() ); installFilters(); } @@ -66,7 +76,7 @@ bool QtxToolBar::Watcher::eventFilter( QObject* o, QEvent* e ) bool updVis = ( o != myCont && ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent || e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) || - ( o == myCont && e->type() == QEvent::ChildRemoved ); + ( o == myCont && ( e->type() == QEvent::ChildRemoved || e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) ); if ( updVis ) { @@ -80,6 +90,44 @@ bool QtxToolBar::Watcher::eventFilter( QObject* o, QEvent* e ) return false; } +void QtxToolBar::Watcher::shown( QtxToolBar* tb ) +{ + if ( tb != myCont ) + return; + + myVisible = true; +} + +void QtxToolBar::Watcher::hided( QtxToolBar* tb ) +{ + if ( tb != myCont ) + return; + + myVisible = false; +} + +void QtxToolBar::Watcher::showContainer() +{ + if ( !myCont ) + return; + + QtxToolBar* cont = myCont; + myCont = 0; + cont->show(); + myCont = cont; +} + +void QtxToolBar::Watcher::hideContainer() +{ + if ( !myCont ) + return; + + QtxToolBar* cont = myCont; + myCont = 0; + cont->hide(); + myCont = cont; +} + void QtxToolBar::Watcher::customEvent( QCustomEvent* e ) { switch ( e->type() ) @@ -132,19 +180,21 @@ void QtxToolBar::Watcher::updateVisibility() } QMainWindow* mw = myCont->mainWindow(); - if ( mw ) + if ( mw && myEmpty == vis ) { - if ( vis ) - mw->setAppropriate( myCont, myVis ); + myEmpty = !vis; + if ( !myEmpty ) + mw->setAppropriate( myCont, myState ); else { - myVis = mw->appropriate( myCont ); + myState = mw->appropriate( myCont ); mw->setAppropriate( myCont, false ); } } + vis = !myEmpty && myVisible; if ( vis != myCont->isVisibleTo( myCont->parentWidget() ) ) - vis ? myCont->show() : myCont->hide(); + vis ? showContainer() : hideContainer(); } void QtxToolBar::Watcher::updateIcon() @@ -278,3 +328,19 @@ QSize QtxToolBar::minimumSizeHint() const return sz; } + +void QtxToolBar::show() +{ + if ( myWatcher ) + myWatcher->shown( this ); + + QToolBar::show(); +} + +void QtxToolBar::hide() +{ + if ( myWatcher ) + myWatcher->hided( this ); + + QToolBar::hide(); +}