From: vsr Date: Mon, 14 May 2007 06:28:04 +0000 (+0000) Subject: Porting to Qt4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=52d48bb5b55ceebad5ab7bc9f6faa0f8595f5ea1;p=modules%2Fgui.git Porting to Qt4 --- diff --git a/src/Qtx/QtxToolBar.cxx b/src/Qtx/QtxToolBar.cxx index cf585db64..af3b3c3c8 100644 --- a/src/Qtx/QtxToolBar.cxx +++ b/src/Qtx/QtxToolBar.cxx @@ -21,16 +21,14 @@ #include "QtxToolBar.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include /*! - Class: QtxToolBar::Watcher [Internal] - Descr: Internal object with event filter. + \class QtxToolBar::Watcher + \internal + \brief Internal class which goal is to watch parent toolbar state changing. */ class QtxToolBar::Watcher : public QObject @@ -39,12 +37,12 @@ public: Watcher( QtxToolBar* ); void shown( QtxToolBar* ); - void hided( QtxToolBar* ); + void hidden( QtxToolBar* ); virtual bool eventFilter( QObject*, QEvent* ); protected: - virtual void customEvent( QCustomEvent* ); + virtual void customEvent( QEvent* ); private: enum { Install = QEvent::User, Update }; @@ -55,8 +53,6 @@ private: void showContainer(); void hideContainer(); - void updateIcon(); - void updateCaption(); void updateVisibility(); private: @@ -67,17 +63,19 @@ private: }; /*! - Constructor + \brief Constructor. + \param cont toolbar to be watched */ QtxToolBar::Watcher::Watcher( QtxToolBar* cont ) : QObject( cont ), -myCont( cont ), -myState( true ), -myEmpty( true ) + myCont( cont ), + myState( true ), + myEmpty( false ) { +/* if ( myCont->mainWindow() ) myState = myCont->mainWindow()->appropriate( myCont ); - +*/ myCont->installEventFilter( this ); myVisible = myCont->isVisibleTo( myCont->parentWidget() ); @@ -85,18 +83,15 @@ myEmpty( true ) } /*! - Custom event filter + \brief Custom event filter. + \param o event receiver object + \param e event sent to object + \return \c true if further event processing should be stopped */ bool QtxToolBar::Watcher::eventFilter( QObject* o, QEvent* e ) { - if ( o == myCont && e->type() == QEvent::ChildInserted ) - QApplication::postEvent( this, new QCustomEvent( Install ) ); - - if ( o != myCont && e->type() == QEvent::IconChange ) - updateIcon(); - - if ( o != myCont && e->type() == QEvent::CaptionChange ) - updateCaption(); + if ( o == myCont && e->type() == QEvent::ChildAdded ) + QApplication::postEvent( this, new QEvent( (QEvent::Type)Install ) ); bool updVis = ( o != myCont && ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent || e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) || @@ -108,14 +103,15 @@ bool QtxToolBar::Watcher::eventFilter( QObject* o, QEvent* e ) myCont = 0; QApplication::sendPostedEvents( this, Update ); myCont = cont; - QApplication::postEvent( this, new QCustomEvent( Update ) ); + QApplication::postEvent( this, new QEvent( (QEvent::Type)Update ) ); } return false; } /*! - Sets internal visibility state to true + \brief Set internal status to "shown" + \param tb toolbar */ void QtxToolBar::Watcher::shown( QtxToolBar* tb ) { @@ -126,9 +122,10 @@ void QtxToolBar::Watcher::shown( QtxToolBar* tb ) } /*! - Sets internal visibility state to false + \brief Set internal status to "hidden" + \param tb toolbar */ -void QtxToolBar::Watcher::hided( QtxToolBar* tb ) +void QtxToolBar::Watcher::hidden( QtxToolBar* tb ) { if ( tb != myCont ) return; @@ -137,7 +134,7 @@ void QtxToolBar::Watcher::hided( QtxToolBar* tb ) } /*! - Shows corresponding QtxToolBar + \brief Show the toolbar being watched */ void QtxToolBar::Watcher::showContainer() { @@ -151,7 +148,7 @@ void QtxToolBar::Watcher::showContainer() } /*! - Hides corresponding QtxToolBar + \brief Hide the toolbar being watched */ void QtxToolBar::Watcher::hideContainer() { @@ -165,43 +162,44 @@ void QtxToolBar::Watcher::hideContainer() } /*! - Event handler of custom events + \brief Proces custom events. + \param e custom event */ -void QtxToolBar::Watcher::customEvent( QCustomEvent* e ) +void QtxToolBar::Watcher::customEvent( QEvent* e ) { switch ( e->type() ) { case Install: installFilters(); - updateIcon(); - updateCaption(); + break; case Update: updateVisibility(); + break; + default: + break; } } /*! - Installs event filters + \brief Install this object as event dilter to all children widgets + of the toolbar being watched. */ void QtxToolBar::Watcher::installFilters() { if ( !myCont ) return; - const QObjectList* objList = myCont->children(); - if ( !objList ) - return; - - for ( QObjectListIt it( *objList ); it.current(); ++it ) + const QObjectList& objList = myCont->children(); + for ( QObjectList::const_iterator it = objList.begin(); it != objList.end(); ++it ) { - if ( it.current()->isWidgetType() && - qstrcmp( "qt_dockwidget_internal", it.current()->name() ) ) - it.current()->installEventFilter( this ); + if ( (*it)->isWidgetType() && qstrcmp( "qt_dockwidget_internal", (*it)->objectName().toLatin1() ) ) + (*it)->installEventFilter( this ); } } /*! - Update visibility state + \brief Update visibility state of all children widgets of the toolbar + being watched. */ void QtxToolBar::Watcher::updateVisibility() { @@ -210,18 +208,18 @@ void QtxToolBar::Watcher::updateVisibility() bool vis = false; - const QObjectList* objList = myCont->children(); - if ( objList ) + const QObjectList& objList = myCont->children(); + for ( QObjectList::const_iterator it = objList.begin(); it != objList.end() && !vis; ++it ) { - for ( QObjectListIt it( *objList ); it.current() && !vis; ++it ) - { - if ( !it.current()->isWidgetType() || - !qstrcmp( "qt_dockwidget_internal", it.current()->name() ) ) - continue; + QObject* obj = *it; + if ( !obj->isWidgetType() || !qstrcmp( "qt_dockwidget_internal", obj->objectName().toLatin1() ) ) + continue; - QWidget* wid = (QWidget*)it.current(); - vis = wid->isVisibleTo( wid->parentWidget() ); - } + if ( obj->inherits( "QToolBarHandle" ) || obj->inherits( "QToolBarExtension" ) ) + continue; + + QWidget* wid = (QWidget*)*it; + vis = wid->isVisibleTo( wid->parentWidget() ); } QMainWindow* mw = myCont->mainWindow(); @@ -229,11 +227,11 @@ void QtxToolBar::Watcher::updateVisibility() { myEmpty = !vis; if ( !myEmpty ) - mw->setAppropriate( myCont, myState ); + myCont->toggleViewAction()->setVisible( myState ); else { - myState = mw->appropriate( myCont ); - mw->setAppropriate( myCont, false ); + myState = myCont->toggleViewAction()->isVisible(); + myCont->toggleViewAction()->setVisible( false ); } } @@ -243,141 +241,79 @@ void QtxToolBar::Watcher::updateVisibility() } /*! - Updates icon -*/ -void QtxToolBar::Watcher::updateIcon() -{ - if ( !myCont || !myCont->widget() ) - return; - - const QPixmap* ico = myCont->widget()->icon(); - myCont->setIcon( ico ? *ico : QPixmap() ); -} - -/*! - Updates caption + \class QtxToolBar + \brief Enhanced toolbar class. */ -void QtxToolBar::Watcher::updateCaption() -{ - if ( myCont && myCont->widget() && !myCont->widget()->caption().isNull() ) - myCont->setCaption( myCont->widget()->caption() ); -} /*! - Constructor + \brief Constructor. + \param watch if \c true the event filter is installed to watch toolbar state changes + to update it properly + \param label toolbar title + \param parent parent widget */ -QtxToolBar::QtxToolBar( const bool watch, const QString& label, QMainWindow* main, - QWidget* parent, bool newLine, const char* name, WFlags f ) -: QToolBar( label, main, parent, newLine, name, f ), -myWatcher( 0 ), -myStretch( false ) +QtxToolBar::QtxToolBar( const bool watch, const QString& label, QWidget* parent ) +: QToolBar( label, parent ), + myWatcher( 0 ), + myStretch( false ) { if ( watch ) myWatcher = new Watcher( this ); } /*! - Constructor + \brief Constructor. + \param label toolbar title + \param parent parent widget */ -QtxToolBar::QtxToolBar( const QString& label, QMainWindow* main, - QWidget* parent, bool newLine, const char* name, WFlags f ) -: QToolBar( label, main, parent, newLine, name, f ), -myWatcher( 0 ), -myStretch( false ) +QtxToolBar::QtxToolBar( const QString& label, QWidget* parent ) +: QToolBar( label, parent ), + myWatcher( 0 ), + myStretch( false ) { } /*! - Constructor + \brief Constructor. + \param watch if \c true the event filter is installed to watch toolbar state changes + to update it properly + \param parent parent widget */ -QtxToolBar::QtxToolBar( const bool watch, QMainWindow* main, const char* name ) -: QToolBar( main, name ), -myWatcher( 0 ), -myStretch( false ) +QtxToolBar::QtxToolBar( const bool watch, QWidget* parent ) +: QToolBar( parent ), + myWatcher( 0 ), + myStretch( false ) { if ( watch ) myWatcher = new Watcher( this ); } /*! - Constructor + \brief Constructor. + \param parent parent widget */ -QtxToolBar::QtxToolBar( QMainWindow* main, const char* name ) -: QToolBar( main, name ), -myWatcher( 0 ), -myStretch( false ) +QtxToolBar::QtxToolBar( QWidget* parent ) +: QToolBar( parent ), + myWatcher( 0 ), + myStretch( false ) { } /*! - Destructor + \brief Destructor. */ QtxToolBar::~QtxToolBar() { } /*! - Change the toolbar's main widget - \param wid - new main widget -*/ -void QtxToolBar::setWidget( QWidget* wid ) -{ - if ( wid ) - wid->reparent( this, QPoint( 0, 0 ), wid->isVisibleTo( wid->parentWidget() ) ); - - QToolBar::setWidget( wid ); - - if ( !boxLayout() ) - return; - - for ( QLayoutIterator it = boxLayout()->iterator(); it.current(); ++it ) - { - if ( it.current()->widget() == wid ) - { - it.deleteCurrent(); - break; - } - } -} - -/*! - \return true if toolbar is stretchable -*/ -bool QtxToolBar::isStretchable() const -{ - return myStretch; -} - -/*! - Sets stretchable state of toolbar - \param on - new state -*/ -void QtxToolBar::setStretchable( const bool on ) -{ - if ( myStretch == on ) - return; - - myStretch = on; - - boxLayout()->setStretchFactor( widget(), myStretch ? 1 : 0 ); - - if ( myStretch != isHorizontalStretchable() || - myStretch != isVerticalStretchable() ) - { - if ( orientation() == Horizontal ) - setHorizontalStretchable( myStretch ); - else - setVerticalStretchable( myStretch ); - } -} - -/*! - \return the recommended size for the widget + \brief Get the recommended size for the widget. + \return recommended toolbar size */ QSize QtxToolBar::sizeHint() const { QSize sz = QToolBar::sizeHint(); - +/* if ( place() == InDock && isStretchable() && area() ) { if ( orientation() == Horizontal ) @@ -385,17 +321,18 @@ QSize QtxToolBar::sizeHint() const else sz.setHeight( area()->height() ); } - +*/ return sz; } /*! - \return the recommended minimum size for the widget + \brief Get the recommended minimum size for the widget. + \return recommended toolbar minimum size */ QSize QtxToolBar::minimumSizeHint() const { QSize sz = QToolBar::minimumSizeHint(); - +/* if ( place() == InDock && isStretchable() && area() ) { if ( orientation() == Horizontal ) @@ -403,28 +340,39 @@ QSize QtxToolBar::minimumSizeHint() const else sz.setHeight( area()->height() ); } - +*/ return sz; } /*! - Shows toolbar + \brief Show/hide the toolbar. + \param on new visibility state */ -void QtxToolBar::show() +void QtxToolBar::setVisible( bool visible ) { if ( myWatcher ) - myWatcher->shown( this ); + { + if ( visible ) + myWatcher->shown( this ); + else + myWatcher->hidden( this ); + } - QToolBar::show(); + QToolBar::setVisible( visible ); } /*! - Hides toolbar + \brief Get parent main window. + \return main window pointer */ -void QtxToolBar::hide() +QMainWindow* QtxToolBar::mainWindow() const { - if ( myWatcher ) - myWatcher->hided( this ); - - QToolBar::hide(); + QMainWindow* mw = 0; + QWidget* wid = parentWidget(); + while ( !mw && wid ) + { + mw = ::qobject_cast( wid ); + wid = wid->parentWidget(); + } + return mw; } diff --git a/src/Qtx/QtxToolBar.h b/src/Qtx/QtxToolBar.h index 57512f40d..7d0918fcf 100644 --- a/src/Qtx/QtxToolBar.h +++ b/src/Qtx/QtxToolBar.h @@ -21,7 +21,7 @@ #include "Qtx.h" -#include +#include class QTX_EXPORT QtxToolBar : public QToolBar { @@ -30,25 +30,21 @@ class QTX_EXPORT QtxToolBar : public QToolBar class Watcher; public: - QtxToolBar( const bool, const QString&, QMainWindow*, QWidget*, bool = false, const char* = 0, WFlags = 0 ); - QtxToolBar( const QString&, QMainWindow*, QWidget*, bool = false, const char* = 0, WFlags = 0 ); - QtxToolBar( const bool, QMainWindow* = 0, const char* = 0 ); - QtxToolBar( QMainWindow* = 0, const char* = 0 ); + QtxToolBar( const bool, const QString&, QWidget* ); + QtxToolBar( const QString&, QWidget* ); + QtxToolBar( const bool, QWidget* = 0 ); + QtxToolBar( QWidget* = 0 ); virtual ~QtxToolBar(); - virtual void setWidget( QWidget* ); - - bool isStretchable() const; - virtual void setStretchable( const bool ); - virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; + QMainWindow* mainWindow() const; + public slots: - virtual void show(); - virtual void hide(); + virtual void setVisible( bool ); private: - Watcher* myWatcher; - bool myStretch; + Watcher* myWatcher; //!< watcher object + bool myStretch; //!< stretching toolbar flag (not used) };