From: nds Date: Tue, 7 Oct 2008 04:20:41 +0000 (+0000) Subject: Merging GUI_SRC module with the BR_HDF_dev_merged branch, which has been merged with... X-Git-Tag: TG_mergeto_BR_V5_DEV_finished~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=50562398d36cbe63f33912b606eb198a8fdc776c;p=modules%2Fgui.git Merging GUI_SRC module with the BR_HDF_dev_merged branch, which has been merged with the BR_V5_DEV branch. --- diff --git a/src/Qtx/QtxActionToolMgr.cxx b/src/Qtx/QtxActionToolMgr.cxx index 47b339edd..cf02d31d7 100644 --- a/src/Qtx/QtxActionToolMgr.cxx +++ b/src/Qtx/QtxActionToolMgr.cxx @@ -92,23 +92,26 @@ QMainWindow* QtxActionToolMgr::mainWindow() const \param title toolbar title \param tid requested toolbar ID + \param mw parent main window; if it is null, the tool manager's main window is used \return id of created/found toolbar */ -int QtxActionToolMgr::createToolBar( const QString& title, const int tid ) +int QtxActionToolMgr::createToolBar( const QString& title, const int tid, QMainWindow* mw ) { static int _toolBarId = -1; int tbId = -1; for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && tbId == -1; ++it ) { - if ( it.value().toolBar->windowTitle().toLower() == title.toLower() ) + if( it.value().toolBar->windowTitle().toLower() == title.toLower() && + ( !mw || it.value().toolBar->parent()==mw ) ) tbId = it.key(); } if ( tbId != -1 ) return tbId; - QToolBar* tb = find( title, mainWindow() ); + QMainWindow* tbw = mw ? mw : mainWindow(); + QToolBar* tb = find( title, tbw ); tbId = tid < 0 ? --_toolBarId : tid; @@ -117,11 +120,12 @@ int QtxActionToolMgr::createToolBar( const QString& title, const int tid ) if ( !tb ) { - tb = new QtxToolBar( true, mainWindow() ); - mainWindow()->addToolBar( tb ); + tb = new QtxToolBar( true, tbw ); + //mainWindow()->addToolBar( tb ); tb->setWindowTitle( title ); tb->setObjectName( title ); - } + tb->setToolTip( title ); + } tInfo.toolBar = tb; connect( tInfo.toolBar, SIGNAL( destroyed() ), this, SLOT( onToolBarDestroyed() ) ); @@ -499,6 +503,11 @@ void QtxActionToolMgr::updateToolBar( const int tid ) } simplifySeparators( tb ); + + // fix of 19921 --> + if ( !tb->isVisible() ) + tb->adjustSize(); + // fix of 19921 <-- } /*! diff --git a/src/Qtx/QtxActionToolMgr.h b/src/Qtx/QtxActionToolMgr.h index be8bda268..b774dda33 100644 --- a/src/Qtx/QtxActionToolMgr.h +++ b/src/Qtx/QtxActionToolMgr.h @@ -61,7 +61,7 @@ public: QMainWindow* mainWindow() const; - int createToolBar( const QString&, int = -1 ); + int createToolBar( const QString&, int = -1, QMainWindow* = 0 ); void removeToolBar( const QString& ); void removeToolBar( const int ); @@ -101,11 +101,12 @@ public: virtual bool load( const QString&, QtxActionMgr::Reader& ); + int find( QToolBar* ) const; + protected slots: void onToolBarDestroyed(); protected: - int find( QToolBar* ) const; int find( const QString& ) const; QToolBar* find( const QString&, QMainWindow* ) const; diff --git a/src/Qtx/QtxColorScale.cxx b/src/Qtx/QtxColorScale.cxx index 97b61a2b3..44589c9c1 100755 --- a/src/Qtx/QtxColorScale.cxx +++ b/src/Qtx/QtxColorScale.cxx @@ -269,7 +269,7 @@ void QtxColorScale::setRange( const double min, const double max ) myMin = min; myMax = max; - myPrecise = QString::null; + myPrecise = QString(); if ( colorMode() == Auto || labelMode() == Auto ) updateScale(); @@ -299,7 +299,7 @@ void QtxColorScale::setFormat( const QString& format ) return; myFormat = format; - myPrecise = QString::null; + myPrecise = QString(); if ( colorMode() == Auto ) updateScale(); } @@ -314,7 +314,7 @@ void QtxColorScale::setIntervalsNumber( const int num ) return; myInterval = num; - myPrecise = QString::null; + myPrecise = QString(); updateScale(); } @@ -698,6 +698,17 @@ void QtxColorScale::hide() QFrame::hide(); } +/*! + \brief Paint widget + \param e paint event +*/ +void QtxColorScale::paintEvent( QPaintEvent* e ) +{ + QPainter p( this ); + drawFrame( &p ); + drawContents( &p ); +} + /*! \brief Draw color scale (reimplemented from QFrame). \param p painter diff --git a/src/Qtx/QtxColorScale.h b/src/Qtx/QtxColorScale.h index ae9e985f2..10014c8d9 100755 --- a/src/Qtx/QtxColorScale.h +++ b/src/Qtx/QtxColorScale.h @@ -59,12 +59,12 @@ public: } DumpMode; //! Color scale flags (bitwise). typedef enum { - AtBorder = 0x001, - Reverse = 0x002, - Integer = 0x004, - WrapTitle = 0x008, - PreciseFormat = 0x010, - Transparent = 0x020 + AtBorder = 0x001, //!< diplay values at colors boundaries + Reverse = 0x002, //!< display color scale in reverse order + Integer = 0x004, //!< round numbers to integer values + WrapTitle = 0x008, //!< wrap title to several lines + PreciseFormat = 0x010, //!< autodetect decimal point precision for color scale values + Transparent = 0x020 //!< transparent background (not implemented yet!) } Flags; public: @@ -123,6 +123,7 @@ public: virtual void hide(); protected: + virtual void paintEvent( QPaintEvent* ); virtual void drawContents( QPainter* ); private: diff --git a/src/Qtx/QtxComboBox.cxx b/src/Qtx/QtxComboBox.cxx index eaffefbdf..831cb18c5 100755 --- a/src/Qtx/QtxComboBox.cxx +++ b/src/Qtx/QtxComboBox.cxx @@ -21,7 +21,96 @@ #include "QtxComboBox.h" +#include #include +#include +#include + +/*! + \class QtxComboBox::Model + \brief Internal view model, used to process 'cleared' state of the combo box. + \internal +*/ +class QtxComboBox::Model : public QStandardItemModel +{ +public: + Model( QObject* parent = 0 ); + ~Model(); + void setCleared( const bool ); + + QVariant data( const QModelIndex&, int = Qt::DisplayRole ) const; + +private: + bool myCleared; +}; + +/*! + \brief Constructor + \internal + \param parent parent object +*/ +QtxComboBox::Model::Model( QObject* parent ) + : QStandardItemModel( 0, 1, parent ), + myCleared( false ) +{ +} + +/*! + \brief Destructor + \internal +*/ +QtxComboBox::Model::~Model() +{ +} + +/*! + \brief Set 'cleared' state + \param isClear new 'cleared' state + \internal +*/ +void QtxComboBox::Model::setCleared( const bool isClear ) +{ + if ( myCleared == isClear ) + return; + + myCleared = isClear; +} + +/*! + \brief Get model data. + \param index model index + \param role data role + \return data of role \a role for the \a index + \internal +*/ +QVariant QtxComboBox::Model::data( const QModelIndex& index, int role ) const +{ + return ( myCleared && ( role == Qt::DisplayRole || role == Qt::DecorationRole ) ) ? + QVariant() : QStandardItemModel::data( index, role ); +} + +/*! + \class QtxComboBox::ClearEvent + \brief Custom event, used to process 'cleared' state of the combo box + in the editable mode. + \internal +*/ + +#define CLEAR_EVENT QEvent::Type( QEvent::User + 123 ) + +class QtxComboBox::ClearEvent : public QEvent +{ +public: + ClearEvent(); +}; + +/*! + \brief Constructor + \internal +*/ +QtxComboBox::ClearEvent::ClearEvent() : QEvent( CLEAR_EVENT ) +{ +} /*! \class QtxComboBox @@ -41,8 +130,9 @@ QtxComboBox::QtxComboBox( QWidget* parent ) : QComboBox( parent ), myCleared( false ) { - connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) ); - connect( this, SIGNAL( activated( const QString& ) ), this, SLOT( onActivated( const QString& ) ) ); + connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) ); + connect( this, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onCurrentChanged( int ) ) ); + setModel( new Model( this ) ); } /*! @@ -73,32 +163,11 @@ void QtxComboBox::setCleared( const bool isClear ) return; myCleared = isClear; - - if ( isEditable() ) - { - if ( myCleared ) - lineEdit()->setText( "" ); - else - lineEdit()->setText( itemText( currentIndex() ) ); - } - - update(); -} - -/*! - \brief Set current item. - Does nothing if the item index is out of range. + if ( lineEdit() ) + lineEdit()->setText( myCleared ? QString( "" ) : itemText( currentIndex() ) ); - \param idx item index -*/ -void QtxComboBox::setCurrentIndex( int idx ) -{ - if ( idx < 0 || idx >= count() ) - return; - - myCleared = false; - QComboBox::setCurrentIndex( idx ); + update(); } /*! @@ -135,10 +204,32 @@ void QtxComboBox::setId( const int index, const int id ) */ void QtxComboBox::paintEvent( QPaintEvent* e ) { - if ( !count() || !myCleared || isEditable() ) - QComboBox::paintEvent( e ); - else - paintClear( e ); + Model* m = dynamic_cast( model() ); + if ( m ) + m->setCleared( myCleared ); + QComboBox::paintEvent( e ); + if ( m ) + m->setCleared( false ); +} + +/*! + \brief Customize child addition/removal event + \param e child event +*/ +void QtxComboBox::childEvent( QChildEvent* e ) +{ + if ( ( e->added() || e->polished() ) && qobject_cast( e->child() ) ) + QApplication::postEvent( this, new ClearEvent() ); +} + +/*! + \brief Process custom events + \param e custom event +*/ +void QtxComboBox::customEvent( QEvent* e ) +{ + if ( e->type() == CLEAR_EVENT && lineEdit() && myCleared ) + lineEdit()->setText( "" ); } /*! @@ -148,17 +239,17 @@ void QtxComboBox::paintEvent( QPaintEvent* e ) void QtxComboBox::onActivated( int idx ) { resetClear(); - emit activatedId( id( idx ) ); } /*! - \brief Called when any item is activated by the user. - \param txt activated item text (not used) + \brief Called when current item is chaned (by the user or programmatically). + \param idx item being set current */ -void QtxComboBox::onActivated( const QString& /*txt*/ ) +void QtxComboBox::onCurrentChanged( int idx ) { - resetClear(); + if ( idx != -1 ) + resetClear(); } /*! @@ -173,30 +264,6 @@ void QtxComboBox::resetClear() update(); } -/*! - \brief Draw combobox in the "cleared" state. - \param e paint event -*/ -void QtxComboBox::paintClear( QPaintEvent* e ) -{ - int curIndex = currentIndex(); - QString curText = itemText( curIndex ); - QIcon curIcon = itemIcon( curIndex ); - - bool upd = updatesEnabled(); - setUpdatesEnabled( false ); - - setItemIcon( curIndex, QIcon() ); - setItemText( curIndex, QString::null ); - - QComboBox::paintEvent( e ); - - setItemText( curIndex, curText ); - setItemIcon( curIndex, curIcon ); - - setUpdatesEnabled( upd ); -} - /*! \brief Get item ID by the index. \param idx item index @@ -242,9 +309,3 @@ bool QtxComboBox::hasId( const int idx ) const \brief Emitted when the item with identificator \a id is activated. \param id item ID */ - -/*! - \fn void QtxComboBox::highlightedId( int id ) - \brief Emitted when the item with identificator \a id is highlighted. - \param id item ID -*/ diff --git a/src/Qtx/QtxComboBox.h b/src/Qtx/QtxComboBox.h index c821ffaed..f1b4f91ec 100755 --- a/src/Qtx/QtxComboBox.h +++ b/src/Qtx/QtxComboBox.h @@ -35,6 +35,9 @@ class QTX_EXPORT QtxComboBox : public QComboBox { Q_OBJECT + class Model; + class ClearEvent; + public: QtxComboBox( QWidget* = 0 ); virtual ~QtxComboBox(); @@ -42,8 +45,6 @@ public: bool isCleared() const; void setCleared( const bool ); - virtual void setCurrentIndex( int ); - int currentId() const; void setCurrentId( int ); @@ -55,18 +56,18 @@ public: signals: void activatedId( int ); - void highlightedId( int ); private slots: void onActivated( int ); - void onActivated( const QString& ); + void onCurrentChanged( int ); protected: virtual void paintEvent( QPaintEvent* ); + virtual void childEvent( QChildEvent* ); + virtual void customEvent( QEvent* ); private: void resetClear(); - void paintClear( QPaintEvent* ); private: enum { IdRole = Qt::UserRole + 10 }; diff --git a/src/Qtx/QtxIntSpinBox.cxx b/src/Qtx/QtxIntSpinBox.cxx index 175a297ae..b4cff2238 100755 --- a/src/Qtx/QtxIntSpinBox.cxx +++ b/src/Qtx/QtxIntSpinBox.cxx @@ -57,6 +57,7 @@ QtxIntSpinBox::QtxIntSpinBox( QWidget* parent ) : QSpinBox( parent ), myCleared( false ) { + setCorrectionMode( QSpinBox::CorrectToNearestValue ); connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); } @@ -79,6 +80,7 @@ QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent ) setMinimum( min ); setMaximum( max ); setSingleStep( step ); + setCorrectionMode( QSpinBox::CorrectToNearestValue ); connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); diff --git a/src/Qtx/QtxListAction.cxx b/src/Qtx/QtxListAction.cxx index efa47e765..44961ddb8 100755 --- a/src/Qtx/QtxListAction.cxx +++ b/src/Qtx/QtxListAction.cxx @@ -570,7 +570,7 @@ void QtxListAction::ListFrame::removePostedEvens( QObject* o, int type ) \param parent parent object */ QtxListAction::QtxListAction( QObject* parent ) -: QWidgetAction( parent ), +: QtxAction( parent ), myFrame( 0 ) { initialize(); @@ -585,13 +585,9 @@ QtxListAction::QtxListAction( QObject* parent ) */ QtxListAction::QtxListAction( const QIcon& icon, const QString& menuText, int accel, QObject* parent ) -: QWidgetAction( parent ), +: QtxAction( menuText, icon, menuText, accel, parent ), myFrame( 0 ) { - setIcon( icon ); - setText( menuText ); - setShortcut( accel ); - initialize(); } @@ -602,12 +598,9 @@ QtxListAction::QtxListAction( const QIcon& icon, const QString& menuText, \param parent parent object */ QtxListAction::QtxListAction( const QString& menuText, int accel, QObject* parent ) -: QWidgetAction( parent ), +: QtxAction( menuText, menuText, accel, parent ), myFrame( 0 ) { - setText( menuText ); - setShortcut( accel ); - initialize(); } @@ -620,14 +613,9 @@ QtxListAction::QtxListAction( const QString& menuText, int accel, QObject* paren */ QtxListAction::QtxListAction( const QString& text, const QString& menuText, int accel, QObject* parent ) -: QWidgetAction( parent ), +: QtxAction( text, menuText, accel, parent ), myFrame( 0 ) { - setText( menuText ); - setShortcut( accel ); - setToolTip( text ); - setStatusTip( text ); - initialize(); } @@ -641,15 +629,9 @@ QtxListAction::QtxListAction( const QString& text, const QString& menuText, */ QtxListAction::QtxListAction( const QString& text, const QIcon& icon, const QString& menuText, int accel, QObject* parent ) -: QWidgetAction( parent ), +: QtxAction( text, icon, menuText, accel, parent ), myFrame( 0 ) { - setIcon( icon ); - setText( menuText ); - setShortcut( accel ); - setToolTip( text ); - setStatusTip( text ); - initialize(); } diff --git a/src/Qtx/QtxListAction.h b/src/Qtx/QtxListAction.h index 182698551..956f65c73 100755 --- a/src/Qtx/QtxListAction.h +++ b/src/Qtx/QtxListAction.h @@ -23,15 +23,14 @@ #define QTXLISTACTION_H #include "Qtx.h" - +#include "QtxAction.h" #include -#include #ifdef WIN32 #pragma warning( disable:4251 ) #endif -class QTX_EXPORT QtxListAction : public QWidgetAction +class QTX_EXPORT QtxListAction : public QtxAction { Q_OBJECT diff --git a/src/Qtx/QtxMainWindow.cxx b/src/Qtx/QtxMainWindow.cxx index 7ca329ac2..8e77da2e1 100644 --- a/src/Qtx/QtxMainWindow.cxx +++ b/src/Qtx/QtxMainWindow.cxx @@ -238,7 +238,7 @@ QString QtxMainWindow::storeGeometry() const else y = QString( "+%1" ).arg( frame.top() ); - QString geom = QString( "%1x%2%3%4" ).arg( frame.width() ).arg( frame.height() ).arg( x ).arg( y ); + QString geom = QString( "%1x%2%3%4" ).arg( width() ).arg( height() ).arg( x ).arg( y ); QString state; switch ( windowState() ) @@ -339,7 +339,9 @@ void QtxMainWindow::retrieveGeometry( const QString& str ) state = Qt::WindowFullScreen; } - setGeometry( rect ); + resize( rect.size() ); + move( rect.topLeft() ); + if ( state != Qt::WindowNoState ) setWindowState( state ); } diff --git a/src/Qtx/QtxPathDialog.h b/src/Qtx/QtxPathDialog.h index 57b887756..29dbac051 100755 --- a/src/Qtx/QtxPathDialog.h +++ b/src/Qtx/QtxPathDialog.h @@ -94,7 +94,7 @@ private: QStringList prepareFilters( const QString& ) const; bool hasVisibleChildren( QWidget* ) const; QStringList filterWildCards( const QString& ) const; - QString autoExtension( const QString&, const QString& = QString::null ) const; + QString autoExtension( const QString&, const QString& = QString() ) const; protected: enum { OpenFile, SaveFile, OpenDir, SaveDir, NewDir }; diff --git a/src/Qtx/QtxPopupMgr.cxx b/src/Qtx/QtxPopupMgr.cxx index 36ecc8011..970b2676f 100644 --- a/src/Qtx/QtxPopupMgr.cxx +++ b/src/Qtx/QtxPopupMgr.cxx @@ -39,13 +39,10 @@ bool operator<( const QVariant& v1, const QVariant& v2 ) { case QVariant::Int: return v1.toInt() < v2.toInt(); - break; case QVariant::Double: return v1.toDouble() < v2.toDouble(); - break; case QVariant::String: return v1.toString() < v2.toString(); - break; case QVariant::StringList: case QVariant::List: { @@ -58,15 +55,12 @@ bool operator<( const QVariant& v1, const QVariant& v2 ) return (*anIt1)<(*anIt2); } return anIt1 == aLast1 && anIt2 != aLast2; - break; } default: return v1.toString() < v2.toString(); - break; } } - else - return t1 < t2; + return t1 < t2; } /*! diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 45f5a2609..273c49159 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -20,12 +20,12 @@ // Author: Alexander SOLOVYOV, Sergey TELKOV #include "QtxResourceMgr.h" +#include "QtxTranslator.h" #include #include #include #include -#include #include #ifndef QT_NO_DOM #include @@ -387,47 +387,9 @@ QPixmap QtxResourceMgr::Resources::loadPixmap( const QString& sect, const QStrin */ QTranslator* QtxResourceMgr::Resources::loadTranslator( const QString& sect, const QString& prefix, const QString& name ) const { - QTranslator* trans = new QTranslator( 0 ); + QTranslator* trans = new QtxTranslator( 0 ); QString fname = fileName( sect, prefix, name ); -#ifdef EMULATE_GLOBAL_CONTEXT - char* buf = 0; - QFile file( fname ); - int len = file.size(); - if ( len ) - { - buf = new char[len]; - if ( !file.open( QIODevice::ReadOnly ) || len != (int)file.read( buf, len ) ) - { - delete buf; - buf = 0; - } - file.close(); - } - if ( buf ) - { - char* pattern = "@default"; - size_t pl = strlen( pattern ); - for ( size_t i = 0; i < len - pl; i++ ) - { - char* cur = buf + i; - if ( !strncmp( cur, pattern, pl ) ) - { - *cur = '\0'; - i += pl - 1; - } - } - - if ( !trans->load( (uchar*)buf, len ) ) - { - delete buf; - buf = 0; - } - } - - if ( !buf ) -#else if ( !trans->load( Qtx::file( fname, false ), Qtx::dir( fname ) ) ) -#endif { delete trans; trans = 0; @@ -658,7 +620,7 @@ bool QtxResourceMgr::IniFormat::save( const QString& fname, const QMapmyResources.append( new Resources( that, userFileName( appName() ) ) ); - for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end(); ++it ) + for ( QStringList::ConstIterator it = myDirList.begin(); it != myDirList.end(); ++it ) { QString path = Qtx::addSlash( *it ) + globalFileName( appName() ); that->myResources.append( new Resources( that, path ) ); @@ -1266,7 +1227,7 @@ void QtxResourceMgr::setIsPixmapCached( const bool on ) */ void QtxResourceMgr::clear() { - for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it ) + for ( ResList::Iterator it = myResources.begin(); it != myResources.end(); ++it ) (*it)->clear(); } @@ -1448,7 +1409,7 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QByteArray baVal.clear(); QStringList lst = val.split( QRegExp( "[\\s|,]" ), QString::SkipEmptyParts ); - for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it ) + for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) { int base = 10; QString str = *it; @@ -1533,7 +1494,7 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QString& v bool ok = false; - ResList::const_iterator it = myResources.begin(); + ResList::ConstIterator it = myResources.begin(); if ( ignoreUserValues() ) ++it; @@ -1743,7 +1704,7 @@ bool QtxResourceMgr::hasValue( const QString& sect, const QString& name ) const initialize(); bool ok = false; - for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && !ok; ++it ) + for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && !ok; ++it ) ok = (*it)->hasValue( sect, name ); return ok; @@ -1759,7 +1720,7 @@ bool QtxResourceMgr::hasSection( const QString& sect ) const initialize(); bool ok = false; - for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && !ok; ++it ) + for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && !ok; ++it ) ok = (*it)->hasSection( sect ); return ok; @@ -1940,7 +1901,7 @@ void QtxResourceMgr::remove( const QString& sect ) { initialize(); - for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it ) + for ( ResList::Iterator it = myResources.begin(); it != myResources.end(); ++it ) (*it)->removeSection( sect ); } @@ -1953,7 +1914,7 @@ void QtxResourceMgr::remove( const QString& sect, const QString& name ) { initialize(); - for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it ) + for ( ResList::Iterator it = myResources.begin(); it != myResources.end(); ++it ) (*it)->removeValue( sect, name ); } @@ -1985,14 +1946,14 @@ void QtxResourceMgr::setCurrentFormat( const QString& fmt ) if ( myResources.isEmpty() ) return; - ResList::iterator resIt = myResources.begin(); + ResList::Iterator resIt = myResources.begin(); if ( myResources.count() > myDirList.count() && resIt != myResources.end() ) { (*resIt)->setFile( userFileName( appName() ) ); ++resIt; } - for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end() && resIt != myResources.end(); ++it, ++resIt ) + for ( QStringList::ConstIterator it = myDirList.begin(); it != myDirList.end() && resIt != myResources.end(); ++it, ++resIt ) (*resIt)->setFile( Qtx::addSlash( *it ) + globalFileName( appName() ) ); } @@ -2004,7 +1965,7 @@ void QtxResourceMgr::setCurrentFormat( const QString& fmt ) QtxResourceMgr::Format* QtxResourceMgr::format( const QString& fmt ) const { Format* form = 0; - for ( FormatList::const_iterator it = myFormats.begin(); it != myFormats.end() && !form; ++it ) + for ( FormatList::ConstIterator it = myFormats.begin(); it != myFormats.end() && !form; ++it ) { if ( (*it)->format() == fmt ) form = *it; @@ -2086,7 +2047,7 @@ bool QtxResourceMgr::load() return false; bool res = true; - for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it ) + for ( ResList::Iterator it = myResources.begin(); it != myResources.end(); ++it ) res = fmt->load( *it ) && res; return res; @@ -2141,10 +2102,10 @@ QStringList QtxResourceMgr::sections() const initialize(); QMap map; - for ( ResList::const_iterator it = myResources.begin(); it != myResources.end(); ++it ) + for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end(); ++it ) { QStringList lst = (*it)->sections(); - for ( QStringList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) + for ( QStringList::ConstIterator itr = lst.begin(); itr != lst.end(); ++itr ) map.insert( *itr, 0 ); } @@ -2170,14 +2131,13 @@ QStringList QtxResourceMgr::parameters( const QString& sec ) const typedef IMap PMap; #endif PMap pmap; - ResList lst; - for ( ResList::const_iterator itr = myResources.begin(); itr != myResources.end(); ++itr ) - lst.prepend( *itr ); - for ( ResList::const_iterator it = lst.begin(); it != lst.end(); ++it ) + ResList::ConstIterator it = myResources.end(); + while ( it != myResources.begin() ) { + --it; QStringList lst = (*it)->parameters( sec ); - for ( QStringList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr ) + for ( QStringList::ConstIterator itr = lst.begin(); itr != lst.end(); ++itr ) pmap.insert( *itr, 0, false ); } @@ -2205,7 +2165,7 @@ QStringList QtxResourceMgr::parameters( const QString& sec ) const QString QtxResourceMgr::path( const QString& sect, const QString& prefix, const QString& name ) const { QString res; - for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && res.isEmpty(); ++it ) + for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && res.isEmpty(); ++it ) res = (*it)->path( sect, prefix, name ); return res; } @@ -2318,7 +2278,7 @@ QPixmap QtxResourceMgr::loadPixmap( const QString& prefix, const QString& name, initialize(); QPixmap pix; - for ( ResList::const_iterator it = myResources.begin(); it != myResources.end() && pix.isNull(); ++it ) + for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && pix.isNull(); ++it ) pix = (*it)->loadPixmap( resSection(), prefix, name ); if ( pix.isNull() ) pix = defPix; @@ -2348,7 +2308,36 @@ QPixmap QtxResourceMgr::loadPixmap( const QString& prefix, const QString& name, */ void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l ) { - initialize(); + loadLanguage( true, pref, l ); +} + +/*! + \brief Load translation files according to the specified language. + + Names of the translation files are calculated according to the pattern specified + by the "translators" option (this option is read from the section "language" of resources files). + By default, "%P_msg_%L.qm" pattern is used. + Keywords \%A, \%P, \%L in the pattern are substituted by the application name, prefix and language name + correspondingly. + For example, for prefix "SUIT" and language "en", all translation files "SUIT_msg_en.qm" are searched and + loaded. + + If prefix is empty or null string, all translation files specified in the "resources" section of resources + files are loaded (actually, the section is retrieved from resSection() method). + If language is not specified, it is retrieved from the langSection() method, and if the latest is also empty, + by default "en" (English) language is used. + By default, settings from the user preferences file are also loaded (if user resource file is valid, + see userFileName()). To avoid loading user settings, pass \c false as first parameter. + + \param loadUser if \c true then user settings are also loaded + \param pref parameter which defines translation context (for example, package name) + \param l language name + + \sa resSection(), langSection(), loadTranslators() +*/ +void QtxResourceMgr::loadLanguage( const bool loadUser, const QString& pref, const QString& l ) +{ + initialize( true, loadUser ); QMap substMap; substMap.insert( 'A', appName() ); @@ -2391,13 +2380,13 @@ void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l ) else prefixList = parameters( resSection() ); - for ( QStringList::const_iterator iter = prefixList.begin(); iter != prefixList.end(); ++iter ) + for ( QStringList::ConstIterator iter = prefixList.begin(); iter != prefixList.end(); ++iter ) { QString prefix = *iter; substMap.insert( 'P', prefix ); QStringList trs; - for ( QStringList::const_iterator it = trList.begin(); it != trList.end(); ++it ) + for ( QStringList::ConstIterator it = trList.begin(); it != trList.end(); ++it ) trs.append( substMacro( *it, substMap ).trimmed() ); loadTranslators( prefix, trs ); @@ -2415,14 +2404,14 @@ void QtxResourceMgr::loadTranslators( const QString& prefix, const QStringList& initialize(); ResList lst; - for ( ResList::iterator iter = myResources.begin(); iter != myResources.end(); ++iter ) + for ( ResList::Iterator iter = myResources.begin(); iter != myResources.end(); ++iter ) lst.prepend( *iter ); QTranslator* trans = 0; - for ( ResList::iterator it = lst.begin(); it != lst.end(); ++it ) + for ( ResList::Iterator it = lst.begin(); it != lst.end(); ++it ) { - for ( QStringList::const_iterator itr = translators.begin(); itr != translators.end(); ++itr ) + for ( QStringList::ConstIterator itr = translators.begin(); itr != translators.end(); ++itr ) { trans = (*it)->loadTranslator( resSection(), prefix, *itr ); if ( trans ) @@ -2446,9 +2435,11 @@ void QtxResourceMgr::loadTranslator( const QString& prefix, const QString& name initialize(); QTranslator* trans = 0; - ResList::iterator it = myResources.end(); - for ( ; it != myResources.begin(); --it ) + + ResList::ConstIterator it = myResources.end(); + while ( it != myResources.begin() ) { + --it; trans = (*it)->loadTranslator( resSection(), prefix, name ); if ( trans ) { @@ -2468,7 +2459,7 @@ void QtxResourceMgr::removeTranslators( const QString& prefix ) if ( !myTranslator.contains( prefix ) ) return; - for ( TransList::iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it ) + for ( TransList::Iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it ) { QApplication::instance()->removeTranslator( *it ); delete *it; @@ -2487,7 +2478,7 @@ void QtxResourceMgr::raiseTranslators( const QString& prefix ) if ( !myTranslator.contains( prefix ) ) return; - for ( TransList::iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it ) + for ( TransList::Iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it ) { QApplication::instance()->removeTranslator( *it ); QApplication::instance()->installTranslator( *it ); @@ -2501,10 +2492,10 @@ void QtxResourceMgr::raiseTranslators( const QString& prefix ) void QtxResourceMgr::refresh() { QStringList sl = sections(); - for ( QStringList::const_iterator it = sl.begin(); it != sl.end(); ++it ) + for ( QStringList::ConstIterator it = sl.begin(); it != sl.end(); ++it ) { QStringList pl = parameters( *it ); - for ( QStringList::const_iterator itr = pl.begin(); itr != pl.end(); ++itr ) + for ( QStringList::ConstIterator itr = pl.begin(); itr != pl.end(); ++itr ) setResource( *it, *itr, stringValue( *it, *itr ) ); } } @@ -2519,7 +2510,7 @@ void QtxResourceMgr::refresh() void QtxResourceMgr::setDirList( const QStringList& dl ) { myDirList = dl; - for ( ResList::iterator it = myResources.begin(); it != myResources.end(); ++it ) + for ( ResList::Iterator it = myResources.begin(); it != myResources.end(); ++it ) delete *it; myResources.clear(); diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index 9e5ba1716..550c14e30 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -138,6 +138,7 @@ public: QPixmap loadPixmap( const QString&, const QString&, const bool ) const; QPixmap loadPixmap( const QString&, const QString&, const QPixmap& ) const; void loadLanguage( const QString& = QString(), const QString& = QString() ); + void loadLanguage( const bool, const QString& = QString(), const QString& = QString() ); void raiseTranslators( const QString& ); void removeTranslators( const QString& ); @@ -163,7 +164,7 @@ protected: virtual QString globalFileName( const QString& ) const; private: - void initialize( const bool = true ) const; + void initialize( const bool = true, const bool = true ) const; QString substMacro( const QString&, const QMap& ) const; private: diff --git a/src/Qtx/QtxSplash.cxx b/src/Qtx/QtxSplash.cxx index d57c843a1..044d8fe88 100644 --- a/src/Qtx/QtxSplash.cxx +++ b/src/Qtx/QtxSplash.cxx @@ -70,20 +70,25 @@ private: /*! \class QtxSplash - \brief The QtxSplash widget provides a splash screen that can be shown during application startup.. - - A splash screen is a widget that is usually displayed when an application is being started. - Splash screens are often used for applications that have long start up times to provide - the user with feedback that the application is loading. - - Only one instance of the QtxSplash widget can be created. To access to the splash screen widget, - use static method QtxSplash::splash(), which creates and instance of the QtxSplash widget if - necessary and returns pointer to it. You should not destroy yhis instance - it is done automatically - after application main window is shown. Just use methods finish() to make splash screen wait untill - main window is shown. - - The splash screen appears in the center of the screen. The most common usage is to show a splash - screen before the main widget is displayed on the screen. + \brief The QtxSplash widget provides a splash screen that can be shown + during application startup. + + A splash screen is a widget that is usually displayed when an application + is being started. + Splash screens are often used for applications that have long start up times + to provide the user with feedback that the application is loading. + + Only one instance of the QtxSplash widget can be created. To access the splash + screen widget, use static method QtxSplash::splash(), which creates an + instance of the QtxSplash widget (if it is not yet creaed) and returns a + pointer to it. + You should not destroy this instance - it is done automatically after + application main window is shown. Just use methods finish() to make splash + screen wait untill main window is shown. + + The splash screen appears in the center of the screen. + The most common usage is to show a splash screen before the main widget + is displayed on the screen. For example, \code int main(int argc, char *argv[]) @@ -101,54 +106,71 @@ private: } \endcode - The user can hide the splash screen by clicking on it with the mouse. Since the splash screen is - typically displayed before the event loop has started running, it is necessary to periodically call + The user can hide the splash screen by clicking on it with the mouse. + Since the splash screen is typically displayed before the event loop + has started running, it is necessary to periodically call QApplication::processEvents() to receive the mouse clicks. - This feature can be switched off by using method setHideOnClick() with \c false parameter. + To activate the possibility of hiding the splash screen on the mouse + click, use setHideOnClick() method passing \c true as parameter. + By default, this feature is switched off. - It is sometimes useful to update the splash screen with messages and/or progress information, - for example, announcing connections established or modules loaded as the application starts up. - QtxSplash class provides the functionality to show status messages and(or) progress bar. + It is sometimes useful to update the splash screen with any status messages + and/or progress information, for example, announcing connections established + or modules loaded as the application starts up. + QtxSplash class provides the functionality to show status messages + and(or) progress bar. \code QPixmap pixmap(":/splash.png"); QtxSplash* splash = QtxSplash::splash(pixmap); - splash->setProgress(0, 5); + splash->setProgress(0, 5); // progress from 0 to 5 splash->show(); app.processEvents(); // doing first step splash->setMessage("Step 1"); - splash->ress(1); + splash->setProgress(1); // progress is 20% qApp->processEvents(); // ... perform some actions // doing second step splash->setMessage("Step 2"); - splash->setProgress(2); + splash->setProgress(2); // progress is 40% qApp->processEvents(); // ... perform some actions ... et cetera \endcode - There is a static function QtxSplash::setStatus() which allows to put next status message - and progress with one call. It can substitue two calls: setMessage() and setProgress(). - - QtxSplash class provides alos a lot of functions to set-up its behavior. Set progress - bar width with setProgressWidth() method, its position and direction with setProgressFlags(). - It can be single-colored or gradient-colored. Use setProgressColors() method for this. - You can even set your own gradient scale with QLinearGradient and use it for the progress - bar coloring: setProgressGradient(). - - To change the progress bar and status message transparency, use setOpacity() function. - The methods setTextAlignment(), setTextColor() and setTextColors() can be used to change - the attributes of the status message. - - The displayed message text includes constant info and status message. The constant info - is set by setConstantInfo() method and status message is set by setMessage(). - - Sometimes it is useful to splay an error message above the splash screen window. - For example, it can be necessary if an error occurs when loading the application. - Method setError() can be used to show the error message and set the error code which - can be then retrieved with the error() function. + There is a static function QtxSplash::setStatus() which allows to put the + next status message and current progress with one call. + It can substitue two calls: setMessage() and setProgress(). + + QtxSplash class provides also a lot of functions to customize its behavior. + Set progress bar width with setProgressWidth() method, its position and + direction with setProgressFlags(). + It can be single-colored or gradient-colored. Use setProgressColors() methods + for this. You can even set your own gradient scale with QLinearGradient, + QRadialGradient or QConicalGradient and use it for the progress + bar coloring. In addition, it is possible to enable/disable displaying + of the progress percentage with setPercentageVisible() method. + + Displaying of the progress bar and status messages can be switched on/off with + setProgressVisible() and setMessageVisible() methods. + + To change the progress bar and status message transparency, use + setOpacity() function. The methods setTextAlignment() and setTextColors() + can be used to change the attributes of the status messages. + + The displayed message text can include constant info and status message. + The constant info is set by setConstantInfo() method and status message + is set by setMessage(). + + Sometimes it is useful to display an error message above the splash screen + window. For example, it can be necessary if an error occurs when loading + the application. Method setError() can be used to show the error message + and set the error code which can be then retrieved with the error() function. + + There is one more helpful feature. The QtxSplash class can read all the + settings from the resource file with help of resource manager + (QtxResourceMgr class). Refer to the method readSettings() for more details. */ //! The only one instance of splash screen @@ -156,8 +178,11 @@ QtxSplash* QtxSplash::mySplash = 0; /*! \brief Constructor. - \brief Construct a splash screen that will display the \a pixmap. + + Construct a splash screen that will display the \a pixmap. + \param pixmap splash screen pixmap + \sa setPixmap(), pixmap() */ QtxSplash::QtxSplash( const QPixmap& pixmap ) : QWidget( 0, Qt::SplashScreen | Qt::WindowStaysOnTopHint ), @@ -166,14 +191,14 @@ QtxSplash::QtxSplash( const QPixmap& pixmap ) myHideOnClick( false ), myProgress( 0 ), myTotal( 0 ), - myStartColor( Qt::red ), - myGradientType( Vertical ), myProgressWidth( 10 ), myProgressFlags( BottomSide | LeftToRight ), myMargin( 5 ), myOpacity( 1.0 ), myError( 0 ), - myGradientUsed( false ) + myShowPercent( true ), + myShowProgress( true ), + myShowMessage( true ) { setAttribute( Qt::WA_DeleteOnClose, true ); setPixmap( pixmap ); @@ -195,6 +220,7 @@ QtxSplash::~QtxSplash() \param px splash screen pixmap \return splash screen widget + \sa setPixmap(), pixmap() */ QtxSplash* QtxSplash::splash( const QPixmap& px ) { @@ -313,6 +339,69 @@ bool QtxSplash::hideOnClick() const return myHideOnClick; } +/*! + \brief Enable/disable displaying of the progress bar. + \param on if \c true, progress bar will be enabled + \sa progressVisible(), setMessageVisible() +*/ +void QtxSplash::setProgressVisible( const bool on ) +{ + myShowProgress = on; + repaint(); +} + +/*! + \brief Check if the progress bar is displayed. + \return \c true if progress bar is enabled + \sa setProgressVisible() +*/ +bool QtxSplash::progressVisible() const +{ + return myShowProgress; +} + +/*! + \brief Enable/disable displaying of the status message. + \param on if \c true, status message will be enabled + \sa messageVisible(), setProgressVisible() +*/ +void QtxSplash::setMessageVisible( const bool on ) +{ + myShowMessage = on; + repaint(); +} + +/*! + \brief Check if the status message is displayed. + \return \c true if status message is enabled + \sa setMessageVisible() +*/ +bool QtxSplash::messageVisible() const +{ + return myShowMessage; +} + +/*! + \brief Enable/disable displaying progress percentage. + \param enable if \c true, percentage will be displayed + \sa percentageVisible() +*/ +void QtxSplash::setPercentageVisible( const bool enable ) +{ + myShowPercent = enable; + repaint(); +} + +/*! + \brief Check if the progress percentage is displayed. + \return \c true if percentage displaying is enabled + \sa setPercentageVisible() +*/ +bool QtxSplash::percentageVisible() const +{ + return myShowPercent; +} + /*! \brief Set total progress steps to \a total. \param total total number of progress steps @@ -369,7 +458,11 @@ void QtxSplash::setProgress( const int progress, const int total ) } /*! - \brief Set margin (a border width). + \brief Set splash window margin (a border width). + + Note, that margin is used only for drawing the progress bar and status + messages. + \param margin new margin width \sa margin() */ @@ -380,7 +473,7 @@ void QtxSplash::setMargin( const int margin ) } /*! - \brief Get margin (a border width). + \brief Get splash window margin (a border width). \return current margin width \sa setMargin() */ @@ -414,7 +507,7 @@ int QtxSplash::progressWidth() const \brief Set progress bar position and direction. By default, progress bar is displayed at the bottom side and - shows progress from left to right. + shows progress from left to right but this behaviour can be changed. \param flags ORed progress bar flags (QtxSplash::ProgressBarFlags) \sa progressFlags() @@ -442,54 +535,57 @@ int QtxSplash::progressFlags() const /*! \brief Set progress bar colors. - If the colors differ the gradient color bar is drawn. + If the colors differ the two-colored gradient bar is drawn. If the \a endColor is not valid, \a startColor is used instead - (no gradient coloring). + (i.e. simple, one-colored progress bar is drawn). - The parameter \a gradientType defines the type of gradient + The parameter \a orientation defines the type of gradient to be drawn - horizontal or vertical. Default is vertical. - Note, that methods setProgressGradient() and setProgressColors() are - alternative. Only the latest used is taken into account. - \param startColor start gradient color (or mono-color) \param endColor end gradient color - \param gradientType gradient type (QtxSplash::GradientType) - \sa progressColors(), setProgressGradient() + \param orientation gradient type (Qt::Orientation) + \sa progressColors() */ -void QtxSplash::setProgressColors( const QColor& startColor, - const QColor& endColor, - const GradientType gradientType ) +void QtxSplash::setProgressColors( const QColor& startColor, + const QColor& endColor, + const Qt::Orientation orientation ) { - if ( startColor.isValid() ) - myStartColor = startColor; - myEndColor = endColor; - myGradientType = gradientType; - myGradientUsed = false; - repaint(); -} + if ( !startColor.isValid() ) + return; -/*! - \brief Get progress colors and gradient type. - \param startColor start gradient color (or mono-color) - \param endColor end gradient color - \return gradient type (QtxSplash::GradientType) - \sa setProgressColors() -*/ -QtxSplash::GradientType QtxSplash::progressColors( QColor& startColor, - QColor& endColor ) const -{ - startColor = myStartColor; - endColor = myEndColor; - return myGradientType; + QLinearGradient l; + if ( orientation == Qt::Vertical ) { + l.setStart( 0., 0. ); + l.setFinalStop( 0., 1. ); + } + else { + l.setStart( 0., 0. ); + l.setFinalStop( 1., 0. ); + } + l.setColorAt( 0., startColor ); + l.setColorAt( 1., endColor.isValid() ? endColor : startColor ); + + setProgressColors( l ); } /*! - \brief Set custom progress bar colors. + \brief Set progress bar colors. - The gradient start and final stops are scaled to the actual progress - bar size. For example: + Use this method to display multi-colored gradient progress bar. + You have to use QLinearGradient, QRadialGradient or QConicalGradient + classes to define the gradient. + + Note, that progress bar coordinates can be defined in absolute or + relative mode. + In absolute mode the actual coordinates of the gradient key points + (like start and final point for linear gradient, center and focal point + for radial gradient, etc) are calculated from the top-left progress bar's corner. + In relative mode you have to use values from 0 to 1 (including) to define + the key points positions. + + For example: \code QLinearGradient lg(0.5, 0, 1, 1); lg.setColorAt(0.2, Qt::blue); @@ -498,31 +594,26 @@ QtxSplash::GradientType QtxSplash::progressColors( QColor& startColor, splash->setProgressGradient(lg); \endcode The above code creates linear gradient, which sets start stop to the - center of the progress bar; the final stop is always in the end of - the progress bar. The color scale (blue to red) is changed by the - progress bar diagonal. - - Note, that methods setProgressGradient() and setProgressColors() are - alternative. Only the latest used is taken into account. + center of the progress bar; the final stop is assigned to its right-bottom corner. + The color scale (blue to red) is changed by the progress bar diagonal. \param gradient color gradient to be used for progress bar coloring - \sa progressGradient(), setProgressColors() + \sa progressColors() */ -void QtxSplash::setProgressGradient( const QLinearGradient& gradient ) +void QtxSplash::setProgressColors( const QGradient& gradient ) { myGradient = gradient; - myGradientUsed = true; repaint(); } /*! \brief Get custom progress bar colors. \return color gradient used for progress bar coloring - \sa setProgressGradient() + \sa setProgressColors() */ -QLinearGradient QtxSplash::progressGradient() const +const QGradient* QtxSplash::progressColors() const { - return myGradient; + return &myGradient; } /*! @@ -575,50 +666,32 @@ int QtxSplash::textAlignment() const } /*! - \brief Set message text color. + \brief Set message text colors. - Default message color is white. - - \param color message text color - \sa setTextColors() -*/ -void QtxSplash::setTextColor( const QColor& color ) -{ - if ( myColor.isValid() ) - myColor = color; - myShadowColor = QColor(); - repaint(); -} + If \a shadow parameter is invalid color, the simple one-colored + text is drawn. Otherwise, second parameter is used to draw the text + shadow. -/*! - \brief Get message text color. - \return color message text color - \sa setTextColor() -*/ -QColor QtxSplash::textColor() const -{ - return myColor; -} - -/*! - \brief Set message text color and text shadow color. \param color message text color \param shadow message text shadow color - \sa textColors(), textColor(), setTextColor() + \sa textColors() */ void QtxSplash::setTextColors( const QColor& color, const QColor& shadow ) { - if ( myColor.isValid() ) - myColor = color; + if ( !myColor.isValid() ) + return; + + myColor = color; myShadowColor = shadow; + repaint(); } /*! - \brief Get message text color and text shadow color. + \brief Get message text colors. \param color message text color \param shadow message text shadow color - \sa setTextColors(), textColor(), setTextColor() + \sa setTextColors() */ void QtxSplash::textColors( QColor& color, QColor& shadow ) const { @@ -634,7 +707,7 @@ void QtxSplash::textColors( QColor& color, QColor& shadow ) const message is set by setMessage(). \param info constant info text - \sa constantInfo(), message(), setMessage() + \sa constantInfo(), message(), setMessage(), option(), setOption() */ void QtxSplash::setConstantInfo( const QString& info ) { @@ -659,14 +732,22 @@ QString QtxSplash::constantInfo() const which is replaced at the time of the displaying. The following options are supported: - - %A - could be used as application name - - %V - could be used as application version - - %L - could be used as application license information - - %C - could be used as application copyright information + - \c \%A - could be used as application name + - \c \%V - could be used as application version + - \c \%L - could be used as application license information + - \c \%C - could be used as application copyright information + For example, + \code + splash->setContantInfo("%A [%V]\n%C"); + splash->setOption("%A", "MyApplication" ); + splash->setOption("%V", "Version 1.0" ); + splash->setOption("%C", "Copyright (C) MyCompany 2008" ); + \endcode + \param name option name \param option value - \sa option() + \sa option(), setConstantInfo(), constantInfo() */ void QtxSplash::setOption( const QString& name, const QString& value ) { @@ -678,7 +759,7 @@ void QtxSplash::setOption( const QString& name, const QString& value ) \brief Get constant information option value. \param name option name \return option value or empty string if option is not set - \sa setOption() + \sa setOption(), setConstantInfo(), constantInfo() */ QString QtxSplash::option( const QString& name ) const { @@ -701,8 +782,8 @@ QString QtxSplash::message() const /*! \brief Get error code. - This function returns error code, set previoiusly with - error(const QString&, const QString&, const int) method. + This function returns error code, set previously with + setError() method. If no error code has been set, 0 is returned. \return last error code @@ -744,12 +825,33 @@ void QtxSplash::repaint() /*! \brief Read splash settings from the resources manager. + + This method can be used to setup the splash screen look-n-feel. + By default, "splash" section of the resources file is used, but you can + use any other section. + All the splash screen parameters can be defined via resources file: + - \c "image" : splash screen image, see setPixmap() + - \c "margin" : splash window margin, see setMargin() + - \c "show_progress" : show progress bar flag, see setProgressVisible() + - \c "show_message" : show status messages flag, see setMessageVisible() + - \c "show_percents" : show progress percentage flag, see setPercentageVisible() + - \c "progress_width" : progress bar width(), see setProgressWidth() + - \c "progress_flags" : progress bar position and direction, see setProgressFlags() + - \c "constant_info" : status messages constant info, see setConstantInfo() + - \c "text_colors" : status messages color(s), see setTextColors() + - \c "progress_colors" : progress bar color(s), see setProgressColors() + - \c "opacity" : progress bar and status messages opacity, see setOpacity() + - \c "font" : status messages font + - \c "alignment" : status messages alignment flags, see setTextAlignment() + - \c "hide_on_click" : hide-on-click flag, see setHideOnClick() + \param resMgr resources manager - \param section resources file section name (if empty, the default name is used). + \param section resources file section name (if empty, the default "splash" + section is used). */ void QtxSplash::readSettings( QtxResourceMgr* resMgr, const QString& section ) { - QString resSection = section.isEmpty() ? "splash" : section; + QString resSection = section.isEmpty() ? QString( "splash" ) : section; // pixmap QString pxname; @@ -769,6 +871,18 @@ void QtxSplash::readSettings( QtxResourceMgr* resMgr, const QString& section ) } #endif + // enable progress bar + bool bShowProgress; + if ( resMgr->value( resSection, "show_progress", bShowProgress ) ) { + setProgressVisible( bShowProgress ); + } + + // enable status message + bool bShowMessage; + if ( resMgr->value( resSection, "show_message", bShowMessage ) ) { + setMessageVisible( bShowMessage ); + } + // margin int m; if ( resMgr->value( resSection, "margin", m ) ) { @@ -850,20 +964,32 @@ void QtxSplash::readSettings( QtxResourceMgr* resMgr, const QString& section ) } setTextAlignment( fl ); } - // progress color(s) QString pc; - QLinearGradient grad; - if ( resMgr->value( resSection, "progress_gradient", grad ) ) { - // gradient-colored progress bar - setProgressGradient( grad ); + QLinearGradient lgrad; + QRadialGradient rgrad; + QConicalGradient cgrad; + if ( resMgr->value( resSection, "progress_color", lgrad ) || + resMgr->value( resSection, "progress_colors", lgrad ) ) { + // linear gradient-colored progress bar + setProgressColors( lgrad ); + } + else if ( resMgr->value( resSection, "progress_color", rgrad ) || + resMgr->value( resSection, "progress_colors", rgrad ) ) { + // radial gradient-colored progress bar + setProgressColors( rgrad ); + } + else if ( resMgr->value( resSection, "progress_color", cgrad ) || + resMgr->value( resSection, "progress_colors", cgrad ) ) { + // conical gradient-colored progress bar + setProgressColors( cgrad ); } else if ( resMgr->value( resSection, "progress_color", pc ) || resMgr->value( resSection, "progress_colors", pc ) ) { // one/two-colored progress bar QStringList colors = pc.split( "|", QString::SkipEmptyParts ); QColor c1, c2; - QtxSplash::GradientType gradType = QtxSplash::Vertical; + Qt::Orientation o = Qt::Vertical; if ( colors.count() > 0 ) c1 = QColor( colors[0] ); if ( colors.count() > 1 ) c2 = QColor( colors[1] ); int gt; @@ -871,17 +997,20 @@ void QtxSplash::readSettings( QtxResourceMgr* resMgr, const QString& section ) bool bOk; gt = colors[2].toInt( &bOk ); if ( bOk ) { - if ( gt >= QtxSplash::Horizontal && gt <= QtxSplash::Vertical ) - gradType = (QtxSplash::GradientType)gt; + if ( gt == 0 ) + o = Qt::Horizontal; } else { - if ( colors[2].toLower() == "horizontal" ) - gradType = QtxSplash::Horizontal; - else if ( colors[2].toLower() == "vertical" ) - gradType = QtxSplash::Vertical; + if ( colors[2].toLower().startsWith( "h" ) ) + o = Qt::Horizontal; } } - setProgressColors( c1, c2, gradType ); + setProgressColors( c1, c2, o ); + } + // show percents + bool bPercent; + if ( resMgr->value( resSection, "show_percents", bPercent ) ) { + setPercentageVisible( bPercent ); } // text color(s) @@ -938,7 +1067,10 @@ void QtxSplash::setMessage( const QString& msg ) /*! \brief Remove the message being displayed on the splash screen. - \sa message() + + This is equivalent to setMessage(""); + + \sa message(), setMessage() */ void QtxSplash::clear() { @@ -948,19 +1080,19 @@ void QtxSplash::clear() /*! \brief Draw the contents of the splash screen. - \param painter painter + \param p painter */ void QtxSplash::drawContents( QPainter* p ) { // draw progress bar - if ( myTotal > 0 ) { + if ( myTotal > 0 && progressVisible() ) { p->save(); drawProgressBar( p ); p->restore(); } // draw status message - if ( !fullMessage().isEmpty() ) { + if ( !fullMessage().isEmpty() && messageVisible() ) { p->save(); drawMessage( p ); p->restore(); @@ -1013,9 +1145,40 @@ void QtxSplash::customEvent( QEvent* ce ) } } +/*! + \brief Check if the gradient is defined in the relative coordinates [static]. + \internal + \return \c true if gradient is defined in the relative coordinates +*/ +static bool checkGradient( const QGradient* g ) +{ +#define BOUNDED( a, min, max ) ( a >= min && a <= max ) + if ( g->type() == QGradient::LinearGradient ) { + const QLinearGradient* lg = static_cast( g ); + return BOUNDED( lg->start().x(), 0.0, 1.0 ) && + BOUNDED( lg->start().y(), 0.0, 1.0 ) && + BOUNDED( lg->finalStop().x(), 0.0, 1.0 ) && + BOUNDED( lg->finalStop().y(), 0.0, 1.0 ); + } + if ( g->type() == QGradient::RadialGradient ) { + const QRadialGradient* rg = static_cast( g ); + return BOUNDED( rg->center().x(), 0.0, 1.0 ) && + BOUNDED( rg->center().y(), 0.0, 1.0 ) && + BOUNDED( rg->focalPoint().x(), 0.0, 1.0 ) && + BOUNDED( rg->focalPoint().y(), 0.0, 1.0 ); // && BOUNDED( rg->radius(), 0.0, 1.0 ); + } + if ( g->type() == QGradient::ConicalGradient ) { + const QConicalGradient* cg = static_cast( g ); + return BOUNDED( cg->center().x(), 0.0, 1.0 ) && + BOUNDED( cg->center().y(), 0.0, 1.0 ); + } + return false; +} + /*! \brief Draw progress bar. \param p painter + \sa drawMessage() */ void QtxSplash::drawProgressBar( QPainter* p ) { @@ -1046,35 +1209,90 @@ void QtxSplash::drawProgressBar( QPainter* p ) if ( myProgressFlags & RightToLeft) cr.translate( 0, r.height() - cr.height() ); } - int x1, x2, y1, y2; - if ( myGradientType == Horizontal ) { - x1 = r.left(); x2 = r.right(); y1 = y2 = 0; - } - else { - x1 = x2 = 0; y1 = r.top(); y2 = r.bottom(); - } - QLinearGradient lg; - if ( myGradientUsed ) { - QPointF start = myGradient.start(); - QPointF final = myGradient.finalStop(); - qreal xd = final.x() - start.x(); - qreal yd = final.y() - start.y(); - lg.setStart( xd != 0 ? r.left() + r.width() * start.x() / xd : 0, - yd != 0 ? r.top() + r.height() * start.y() / yd : 0 ); - lg.setFinalStop( xd != 0 ? r.right() : 0, yd != 0 ? r.bottom() : 0 ); - lg.setStops( myGradient.stops() ); - lg.setSpread( myGradient.spread() ); - } - else { - lg.setStart( x1, y1 ); - lg.setFinalStop( x2, y2 ); - lg.setColorAt( 0, myStartColor ); - lg.setColorAt( 1, myEndColor.isValid() ? myEndColor : myStartColor ); + QBrush b; + switch ( progressColors()->type() ) { + case QGradient::LinearGradient: + { + QLinearGradient lg; + const QLinearGradient* other = static_cast( progressColors() ); + if ( checkGradient( other ) ) { + // gradient is defined in relative coordinates [0.0 - 1.0] + lg.setStart( r.left() + r.width() * other->start().x(), + r.top() + r.height() * other->start().y() ); + lg.setFinalStop( r.left() + r.width() * other->finalStop().x(), + r.top() + r.height() * other->finalStop().y() ); + } + else { + // gradient is defined in absolute coordinates + // according to its dimensions + lg.setStart( r.topLeft() + other->start() ); + lg.setFinalStop( r.topLeft() + other->finalStop() ); + } + + lg.setStops( other->stops() ); + lg.setSpread( other->spread() ); + + b = QBrush( lg ); + + break; + } // case QGradient::LinearGradient + case QGradient::RadialGradient: + { + QRadialGradient rg; + const QRadialGradient* other = static_cast( progressColors() ); + if ( checkGradient( other ) ) { + // gradient is defined in relative coordinates [0.0 - 1.0] + rg.setCenter( r.left() + r.width() * other->center().x(), + r.top() + r.height() * other->center().y() ); + rg.setFocalPoint( r.left() + r.width() * other->focalPoint().x(), + r.top() + r.height() * other->focalPoint().y() ); + } + else { + // gradient is defined in absolute coordinates + // according to its dimensions + rg.setCenter( r.topLeft() + other->center() ); + rg.setFocalPoint( r.topLeft() + other->focalPoint() ); + } + + // only width is taken into account for the radius in relative mode + rg.setRadius( other->radius() > 1.0 ? other->radius() : r.width() * other->radius() ); + + rg.setStops( other->stops() ); + rg.setSpread( other->spread() ); + + b = QBrush( rg ); + + break; + } // case QGradient::RadialGradient + case QGradient::ConicalGradient: + { + QConicalGradient cg; + const QConicalGradient* other = static_cast( progressColors() ); + if ( checkGradient( other ) ) { + // gradient is defined in relative coordinates [0.0 - 1.0] + cg.setCenter( r.left() + r.width() * other->center().x(), + r.top() + r.height() * other->center().y() ); + } + else { + // gradient is defined in absolute coordinates + // according to its dimensions + cg.setCenter( r.topLeft() + other->center() ); + } + + cg.setAngle( other->angle() ); + cg.setStops( other->stops() ); + cg.setSpread( other->spread() ); + + b = QBrush( cg ); + + break; + } // case QGradient::RadialGradient + default: + b = QBrush( Qt::red ); // default is simple red-colored progress bar + break; } + p->setOpacity( myOpacity ); - p->setClipRect( cr ); - p->fillRect( r, lg ); - p->setClipping( false ); // draw progress bar outline rectangle p->setPen( palette().color( QPalette::Dark ) ); @@ -1083,18 +1301,40 @@ void QtxSplash::drawProgressBar( QPainter* p ) p->setPen( palette().color( QPalette::Light ) ); p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() ); p->drawLine( r.right(), r.top(), r.right(), r.bottom() ); + + r.setCoords( r.left()+1, r.top()+1, r.right()-1, r.bottom()-1 ); + p->setClipRect( cr ); + p->fillRect( r, b ); + p->setClipping( false ); + + if ( myShowPercent ) { + int percent = ( int )( ( myProgress > 0 ? myProgress : 0 ) * 100 / myTotal ); + QFont f = font(); + f.setPixelSize( r.height() - 4 ); + p->setFont( f ); + // draw shadow status text + if ( myShadowColor.isValid() ) { + QRect rs = r; + rs.moveTopLeft( rs.topLeft() + QPoint( 1,1 ) ); + p->setPen( myShadowColor ); + p->drawText( rs, Qt::AlignCenter, QString( "%1%" ).arg( percent ) ); + } + p->setPen( myColor ); + p->drawText( r, Qt::AlignCenter, QString( "%1%" ).arg( percent ) ); + } } /*! \brief Draw status message. \param p painter + \sa drawProgressBar() */ void QtxSplash::drawMessage( QPainter* p ) { // get rect, margin, progress bar width QRect r = rect(); int m = margin(); - int pw = progressWidth(); + int pw = progressVisible() ? progressWidth() : 0; // calculate drawing rect QFontMetrics f( font() ); @@ -1142,6 +1382,7 @@ void QtxSplash::drawMessage( QPainter* p ) /*! \brief Draw the splash screen window contents. + \internal */ void QtxSplash::drawContents() { @@ -1157,6 +1398,7 @@ void QtxSplash::drawContents() /*! \brief Sets error code. \param code error code + \internal */ void QtxSplash::setError( const int code ) { @@ -1167,6 +1409,7 @@ void QtxSplash::setError( const int code ) \brief Get full message which includes constant info and status message. \return get fill message text \sa constantInfo(), setConstantInfo(), message(), setMessage() + \internal */ QString QtxSplash::fullMessage() const { diff --git a/src/Qtx/QtxSplash.h b/src/Qtx/QtxSplash.h index 1d92e70fb..cfebac158 100644 --- a/src/Qtx/QtxSplash.h +++ b/src/Qtx/QtxSplash.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include #ifdef WIN32 @@ -44,12 +44,6 @@ private: QtxSplash( const QPixmap& ); public: - //! Gradient type - typedef enum { - Horizontal, //!< horizontal - Vertical //!< vertical - } GradientType; - //! Progress bar position and direction typedef enum { LeftSide = 0x0001, //!< progress bar is displayed at the left side @@ -72,7 +66,16 @@ public: void setHideOnClick( const bool ); bool hideOnClick() const; - + + void setProgressVisible( const bool ); + bool progressVisible() const; + + void setMessageVisible( const bool ); + bool messageVisible() const; + + void setPercentageVisible( const bool ); + bool percentageVisible() const; + void setTotalSteps( const int ); int totalSteps() const; @@ -85,17 +88,15 @@ public: void setProgressWidth( const int ); int progressWidth() const; - + void setProgressFlags( const int ); int progressFlags() const; void setProgressColors( const QColor&, const QColor& = QColor(), - const GradientType = Vertical ); - GradientType progressColors( QColor&, QColor& ) const; - - void setProgressGradient( const QLinearGradient& ); - QLinearGradient progressGradient() const; + const Qt::Orientation = Qt::Vertical ); + void setProgressColors( const QGradient& ); + const QGradient* progressColors() const; void setOpacity( const double ); double opacity() const; @@ -103,8 +104,6 @@ public: void setTextAlignment( const int ); int textAlignment() const; - void setTextColor( const QColor& ); - QColor textColor() const; void setTextColors( const QColor&, const QColor& = QColor() ); void textColors( QColor&, QColor& ) const; @@ -160,17 +159,16 @@ private: bool myHideOnClick; //!< 'hide on click' flag int myProgress; //!< current progress int myTotal; //!< total progress steps - QColor myStartColor; //!< progress bar gradient starting color - QColor myEndColor; //!< progress bar gradient ending color - GradientType myGradientType; //!< progress bar gradient direction - QLinearGradient myGradient; //!< progress bar custom gradient + QGradient myGradient; //!< progress bar custom gradient int myProgressWidth; //!< progress bar width int myProgressFlags; //!< progress bar flags (QtxSplash::ProgressBarFlags) int myMargin; //!< margin (for progress bar and status message) double myOpacity; //!< progress bar / status message opacity int myError; //!< error code - bool myGradientUsed; //!< 'use custom gradient color scale' flag OptMap myOptions; //!< constant info options + bool myShowProgress; //!< 'show progress bar' flag + bool myShowMessage; //!< 'show status message' flag + bool myShowPercent; //!< 'show percentage' flag }; #endif diff --git a/src/Qtx/QtxToolBar.cxx b/src/Qtx/QtxToolBar.cxx index f450db201..ec881d05a 100644 --- a/src/Qtx/QtxToolBar.cxx +++ b/src/Qtx/QtxToolBar.cxx @@ -41,6 +41,9 @@ public: virtual bool eventFilter( QObject*, QEvent* ); + bool isEmpty() const; + bool isVisible() const; + protected: virtual void customEvent( QEvent* ); @@ -55,11 +58,13 @@ private: void updateVisibility(); + void setEmpty( const bool ); + void setVisible( const bool ); + private: QtxToolBar* myCont; bool myState; bool myEmpty; - bool myVisible; }; /*! @@ -72,8 +77,9 @@ QtxToolBar::Watcher::Watcher( QtxToolBar* cont ) myState( true ), myEmpty( false ) { + setVisible( myCont->isVisibleTo( myCont->parentWidget() ) ); + myCont->installEventFilter( this ); - myVisible = myCont->isVisibleTo( myCont->parentWidget() ); installFilters(); } @@ -116,7 +122,7 @@ void QtxToolBar::Watcher::shown( QtxToolBar* tb ) if ( tb != myCont ) return; - myVisible = true; + setVisible( true ); } /*! @@ -128,7 +134,36 @@ void QtxToolBar::Watcher::hidden( QtxToolBar* tb ) if ( tb != myCont ) return; - myVisible = false; + setVisible( false ); +} + +bool QtxToolBar::Watcher::isEmpty() const +{ + return myEmpty; +} + +bool QtxToolBar::Watcher::isVisible() const +{ + bool vis = false; + if ( myCont && myCont->toggleViewAction() ) + vis = myCont->toggleViewAction()->isChecked(); + return vis; +} + +void QtxToolBar::Watcher::setEmpty( const bool on ) +{ + myEmpty = on; +} + +void QtxToolBar::Watcher::setVisible( const bool on ) +{ + if ( !myCont || !myCont->toggleViewAction() ) + return; + + bool block = myCont->toggleViewAction()->signalsBlocked(); + myCont->toggleViewAction()->blockSignals( true ); + myCont->toggleViewAction()->setChecked( on ); + myCont->toggleViewAction()->blockSignals( block ); } /*! @@ -139,10 +174,14 @@ void QtxToolBar::Watcher::showContainer() if ( !myCont ) return; + bool vis = isVisible(); + QtxToolBar* cont = myCont; myCont = 0; cont->show(); myCont = cont; + + setVisible( vis ); } /*! @@ -153,10 +192,14 @@ void QtxToolBar::Watcher::hideContainer() if ( !myCont ) return; + bool vis = isVisible(); + QtxToolBar* cont = myCont; myCont = 0; cont->hide(); myCont = cont; + + setVisible( vis ); } /*! @@ -205,9 +248,7 @@ void QtxToolBar::Watcher::updateVisibility() return; bool vis = false; - QList actList = myCont->actions(); - for ( QList::const_iterator it = actList.begin(); it != actList.end() && !vis; ++it ) { if ( (*it)->isSeparator() ) @@ -217,10 +258,12 @@ void QtxToolBar::Watcher::updateVisibility() } QMainWindow* mw = myCont->mainWindow(); - if ( mw && myEmpty == vis ) + bool empty = isEmpty(); + if ( mw && empty == vis ) { - myEmpty = !vis; - if ( !myEmpty ) + empty = !vis; + setEmpty( empty ); + if ( !empty ) myCont->toggleViewAction()->setVisible( myState ); else { @@ -229,7 +272,7 @@ void QtxToolBar::Watcher::updateVisibility() } } - vis = !myEmpty && myVisible; + vis = !empty && isVisible(); if ( vis != myCont->isVisibleTo( myCont->parentWidget() ) ) vis ? showContainer() : hideContainer(); } diff --git a/src/Qtx/QtxTreeView.cxx b/src/Qtx/QtxTreeView.cxx index bd07c1206..c57192b03 100644 --- a/src/Qtx/QtxTreeView.cxx +++ b/src/Qtx/QtxTreeView.cxx @@ -42,13 +42,12 @@ public: bool sortMenuEnabled() const; void addMenuAction( QAction* ); - protected: void contextMenuEvent( QContextMenuEvent* ); private: typedef QMap ActionsMap; - bool myEnableSortMenu; + bool myEnableSortMenu; ActionsMap myActions; }; @@ -307,6 +306,26 @@ void QtxTreeView::addHeaderMenuAction( QAction* action ) h->addMenuAction( action ); } +/*! + \brief Resizes the given column in order to enclose its contents. + The size will be changed only if it is smaller than the size of + contents. + \param column number of column +*/ +void QtxTreeView::resizeColumnToEncloseContents( int column ) +{ + if (column < 0 || column >= header()->count()) + return; + + int contentsSizeHint = sizeHintForColumn(column); + int headerSizeHint = header()->isHidden() ? 0 : header()->sectionSizeHint(column); + int sizeHint = qMax(contentsSizeHint, headerSizeHint); + + int currentSize = columnWidth( column ); + if (currentSize < sizeHint) + setColumnWidth( column, sizeHint ); +} + /* \brief Called when the header section is clicked. \param column header column index @@ -345,6 +364,18 @@ void QtxTreeView::drawRow( const QModelIndex& index ) emit drawedRow( index ); } +/*! + \brief Called when rows are about to be removed. + \param parent model index + \param start first row to remove + \param end last row to remove +*/ +void QtxTreeView::rowsAboutToBeRemoved( const QModelIndex& parent, int start, int end ) +{ + setCurrentIndex( QModelIndex() ); + QTreeView::rowsAboutToBeRemoved( parent, start, end ); +} + /*! \brief Expand/collapse the specified item (recursively). \param index model index diff --git a/src/Qtx/QtxTreeView.h b/src/Qtx/QtxTreeView.h index 8106afcb8..dfa3a5268 100644 --- a/src/Qtx/QtxTreeView.h +++ b/src/Qtx/QtxTreeView.h @@ -53,8 +53,11 @@ public: void addHeaderMenuAction( QAction* ); + void resizeColumnToEncloseContents( int ); + protected slots: void onHeaderClicked( int ); + void rowsAboutToBeRemoved( const QModelIndex&, int, int ); void selectionChanged( const QItemSelection&, const QItemSelection& ); protected: diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index 27e8cdd0a..9a5794f29 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -23,22 +23,20 @@ #include "QtxAction.h" -#include #include -#include -#include #include +#include #include +#include #include +#include +#include #include #include +#include #include #include #include -#include -#include - -#define DARK_COLOR_LIGHT 250 /*! \class QtxWorkstackArea::WidgetEvent @@ -1495,6 +1493,13 @@ QtxWorkstack::QtxWorkstack( QWidget* parent ) connect( myActionsMap[Close], SIGNAL( triggered( bool ) ), this, SLOT( onCloseWindow() ) ); connect( myActionsMap[Rename], SIGNAL( triggered( bool ) ), this, SLOT( onRename() ) ); + // Action shortcut will work when action added in any widget. + for ( QMap::iterator it = myActionsMap.begin(); it != myActionsMap.end(); ++it ) + { + addAction( it.value() ); + it.value()->setShortcutContext( Qt::ApplicationShortcut ); + } + QVBoxLayout* base = new QVBoxLayout( this ); base->setMargin( 0 ); @@ -1511,13 +1516,25 @@ QtxWorkstack::~QtxWorkstack() } /*! - \brief Get all child widgets in all workareas. - \return list of widgets in all workareas + \brief Get list of all widgets in all areas or in specified area which given + widget belongs to + \param wid widget specifying area if it is equal to null when widgets of all + areas are retuned + \return list of widgets */ -QWidgetList QtxWorkstack::windowList() const +QWidgetList QtxWorkstack::windowList( QWidget* wid ) const { QList lst; - areas( mySplit, lst, true ); + if ( !wid ) + { + areas( mySplit, lst, true ); + } + else + { + QtxWorkstackArea* area = wgArea( wid ); + if ( area ) + lst.append( area ); + } QWidgetList widList; for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) @@ -2783,7 +2800,7 @@ void QtxWorkstack::splitterInfo( QSplitter* split, QString& info ) const if ( !split ) return; - const QObjectList& objs = split->children(); + /*const QObjectList& objs = */split->children(); // VSR: is it needed ??? QString sizesStr; QList sizes = split->sizes(); @@ -3114,3 +3131,95 @@ QtxWorkstack& QtxWorkstack::operator>>( QString& outParameters ) \brief Emitted when the workstack's child widget \w is activated. \param w widget being activated */ + +/*! + \brief Gets area containing given widget + \param wid widget + \return pointer to QtxWorkstackArea* object +*/ +QtxWorkstackArea* QtxWorkstack::wgArea( QWidget* wid ) const +{ + QtxWorkstackArea* resArea = 0; + + QList areaList; + areas( mySplit, areaList, true ); + + QList::ConstIterator it; + for ( it = areaList.begin(); it != areaList.end() && !resArea; ++it ) + { + if ( (*it)->contains( wid ) ) + resArea = *it; + } + + return resArea; +} + +/*! + \brief Moves the first widget to the same area which the second widget belongs to + \param wid widget to be moved + \param wid_to widget specified the destination area + \param before specifies whether the first widget has to be moved before or after + the second widget + \return TRUE if operation is completed successfully, FALSE otherwise +*/ +bool QtxWorkstack::move( QWidget* wid, QWidget* wid_to, const bool before ) +{ + if ( wid && wid_to ) + { + QtxWorkstackArea* area_src = wgArea( wid ); + QtxWorkstackArea* area_to = wgArea( wid_to ); + if ( area_src && area_to ) + { + // find index of the second widget + QWidgetList wgList = area_to->widgetList(); + QWidgetList::ConstIterator it; + int idx = 0; + for ( it = wgList.begin(); it != wgList.begin(); ++it, idx++ ) + { + if ( *it == wid_to ) + break; + } + + if ( idx < wgList.count() ) // paranoidal check + { + if ( !before ) + idx++; + area_src->removeWidget( wid, true ); + area_to->insertWidget( wid, idx ); + return true; + } + } + } + return false; +} + +/*! + \brief Group all windows in one area + \return TRUE if operation is completed successfully, FALSE otherwise +*/ +void QtxWorkstack::stack() +{ + QWidgetList wgList = windowList(); + if ( !wgList.count() ) + return; // nothing to do + + QtxWorkstackArea* area_to = 0; + QWidgetList::ConstIterator it; + for ( it = wgList.begin(); it != wgList.end(); ++it ) + { + QtxWorkstackArea* area_src = 0; + if ( !area_to ) + { + area_to = wgArea( *it ); + area_src = area_to; + } + else + area_src = wgArea( *it ); + + if ( area_src != area_to ) + { + area_src->removeWidget( *it, true ); + area_to->insertWidget( *it, -1 ); + } + } +} diff --git a/src/Qtx/QtxWorkstack.h b/src/Qtx/QtxWorkstack.h index 22425c869..21d1b5f30 100644 --- a/src/Qtx/QtxWorkstack.h +++ b/src/Qtx/QtxWorkstack.h @@ -71,7 +71,7 @@ public: QtxWorkstack( QWidget* = 0 ); virtual ~QtxWorkstack(); - QWidgetList windowList() const; + QWidgetList windowList( QWidget* = 0 ) const; QWidgetList splitWindowList() const; QWidget* activeWindow() const; @@ -86,6 +86,8 @@ public: int menuActions() const; void split( const int ); + bool move( QWidget* wid, QWidget* wid_to, const bool before ); + void stack(); QWidget* addWindow( QWidget*, Qt::WindowFlags = 0 ); @@ -125,6 +127,7 @@ private: void insertWidget( QWidget*, QWidget*, QWidget* ); QtxWorkstackArea* areaAt( const QPoint& ) const; + QtxWorkstackArea* wgArea( QWidget* ) const; QtxWorkstackArea* targetArea(); QtxWorkstackArea* activeArea() const;