public:
Watcher( QtxToolBar* );
+ void shown( QtxToolBar* );
+ void hided( QtxToolBar* );
+
virtual bool eventFilter( QObject*, QEvent* );
protected:
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();
}
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 )
{
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() )
}
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 );
}
}
- if ( vis )
- myCont->show();
- else
- myCont->hide();
+ vis = !myEmpty && myVisible;
+ if ( vis != myCont->isVisibleTo( myCont->parentWidget() ) )
+ vis ? showContainer() : hideContainer();
}
void QtxToolBar::Watcher::updateIcon()
return sz;
}
+
+void QtxToolBar::show()
+{
+ if ( myWatcher )
+ myWatcher->shown( this );
+
+ QToolBar::show();
+}
+
+void QtxToolBar::hide()
+{
+ if ( myWatcher )
+ myWatcher->hided( this );
+
+ QToolBar::hide();
+}