From 35620a64f798c66e4bdb454cf97c4a7c0dfcf001 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 31 May 2007 16:31:12 +0000 Subject: [PATCH] Porting to Qt 4 --- src/Qtx/Makefile.am | 39 +- src/Qtx/Qtx.pro | 24 +- src/Qtx/QtxDoubleSpinBox.cxx | 91 +++- src/Qtx/QtxDoubleSpinBox.h | 6 +- src/Qtx/QtxGridBox.cxx | 145 ++++++- src/Qtx/QtxGroupBox.cxx | 86 ++-- src/Qtx/QtxGroupBox.h | 1 - src/Qtx/QtxIntSpinBox.cxx | 79 +++- src/Qtx/QtxPathDialog.cxx | 779 +++++++++++++++++++---------------- 9 files changed, 790 insertions(+), 460 deletions(-) diff --git a/src/Qtx/Makefile.am b/src/Qtx/Makefile.am index 970eb6b10..16a7d085e 100755 --- a/src/Qtx/Makefile.am +++ b/src/Qtx/Makefile.am @@ -38,14 +38,20 @@ salomeinclude_HEADERS= \ QtxDialog.h \ QtxDockAction.h \ QtxDockWidget.h \ + QtxDoubleSpinBox.h \ QtxEvalExpr.h \ + QtxGridBox.h \ + QtxGroupBox.h \ + QtxIntSpinBox.h \ QtxListAction.h \ QtxLogoMgr.h \ QtxMainWindow.h \ QtxMap.h \ QtxMRUAction.h \ + QtxPathDialog.h \ QtxPopupMgr.h \ QtxResourceMgr.h \ + QtxSplash.h \ QtxToolBar.h \ QtxValidator.h \ QtxWorkspace.h \ @@ -55,18 +61,12 @@ salomeinclude_HEADERS= \ #VSR: not yet migrated to Qt4 files # \ - QtxDblSpinBox.h \ QtxDirListEditor.h \ - QtxGroupBox.h \ - QtxIntSpinBox.h \ QtxListBox.h \ QtxListResourceEdit.h \ QtxListView.h \ - QtxMenuButton.h \ - QtxPathDialog.h \ QtxPopupMenu.h \ QtxResourceEdit.h \ - QtxSplash.h \ QtxTable.h \ QtxToolTip.h @@ -87,15 +87,21 @@ dist_libqtx_la_SOURCES= \ QtxDialog.cxx \ QtxDockAction.cxx \ QtxDockWidget.cxx \ + QtxDoubleSpinBox.cxx \ QtxEvalExpr.cxx \ + QtxGridBox.cxx \ + QtxGroupBox.cxx \ + QtxIntSpinBox.cxx \ QtxListAction.cxx \ QtxLogoMgr.cxx \ QtxMainWindow.cxx \ QtxMRUAction.cxx \ + QtxPathDialog.cxx \ QtxPopupMgr.cxx \ QtxResourceMgr.cxx \ + QtxSplash.cxx \ QtxToolBar.cxx \ - QtxValidator.cxx \ + QtxValidator.cxx \ QtxWorkspace.cxx \ QtxWorkspaceAction.cxx \ QtxWorkstack.cxx \ @@ -103,18 +109,12 @@ dist_libqtx_la_SOURCES= \ #VSR: not yet migrated to Qt4 files # \ - QtxDblSpinBox.cxx \ QtxDirListEditor.cxx \ - QtxGroupBox.cxx \ - QtxIntSpinBox.cxx \ QtxListBox.cxx \ QtxListResourceEdit.cxx \ QtxListView.cxx \ - QtxMenuButton.cxx \ - QtxPathDialog.cxx \ QtxPopupMenu.cxx \ QtxResourceEdit.cxx \ - QtxSplash.cxx \ QtxTable.cxx \ QtxToolTip.cxx @@ -130,11 +130,17 @@ MOC_FILES= \ QtxDialog_moc.cxx \ QtxDockAction_moc.cxx \ QtxDockWidget_moc.cxx \ + QtxDoubleSpinBox_moc.cxx \ + QtxGridBox_moc.cxx \ + QtxGroupBox_moc.cxx \ + QtxIntSpinBox_moc.cxx \ QtxListAction_moc.cxx \ QtxLogoMgr_moc.cxx \ QtxMainWindow_moc.cxx \ QtxMRUAction_moc.cxx \ + QtxPathDialog_moc.cxx \ QtxPopupMgr_moc.cxx \ + QtxSplash_moc.cxx \ QtxToolBar_moc.cxx \ QtxValidator_moc.cxx \ QtxWorkspace_moc.cxx \ @@ -144,18 +150,11 @@ MOC_FILES= \ #VSR: not yet migrated to Qt4 files # \ - QtxDblSpinBox_moc.cxx \ - QtxDblValidator_moc.cxx \ QtxDirListEditor_moc.cxx \ - QtxGroupBox_moc.cxx \ - QtxIntSpinBox_moc.cxx \ QtxListBox_moc.cxx \ QtxListResourceEdit_moc.cxx \ QtxListView_moc.cxx \ - QtxMenuButton_moc.cxx \ - QtxPathDialog_moc.cxx \ QtxPopupMenu_moc.cxx \ - QtxSplash_moc.cxx \ QtxTable_moc.cxx \ QtxToolTip_moc.cxx diff --git a/src/Qtx/Qtx.pro b/src/Qtx/Qtx.pro index 8bc844e32..1fe4228e6 100644 --- a/src/Qtx/Qtx.pro +++ b/src/Qtx/Qtx.pro @@ -22,32 +22,32 @@ HEADERS += QtxComboBox.h HEADERS += QtxDialog.h HEADERS += QtxDockAction.h HEADERS += QtxDockWidget.h +HEADERS += QtxDoubleSpinBox.h HEADERS += QtxEvalExpr.h +HEADERS += QtxGridBox.h +HEADERS += QtxGroupBox.h +HEADERS += QtxIntSpinBox.h HEADERS += QtxListAction.h HEADERS += QtxLogoMgr.h HEADERS += QtxMainWindow.h HEADERS += QtxMap.h HEADERS += QtxMRUAction.h +HEADERS += QtxPathDialog.h HEADERS += QtxPopupMgr.h HEADERS += QtxResourceMgr.h +HEADERS += QtxSplash.h HEADERS += QtxToolBar.h HEADERS += QtxValidator.h HEADERS += QtxWorkspace.h HEADERS += QtxWorkspaceAction.h HEADERS += QtxWorkstack.h HEADERS += QtxWorkstackAction.h -#HEADERS += QtxDblSpinBox.h #HEADERS += QtxDirListEditor.h -#HEADERS += QtxGroupBox.h -#HEADERS += QtxIntSpinBox.h #HEADERS += QtxListBox.h #HEADERS += QtxListResourceEdit.h #HEADERS += QtxListView.h -#HEADERS += QtxMenuButton.h -#HEADERS += QtxPathDialog.h #HEADERS += QtxPopupMenu.h #HEADERS += QtxResourceEdit.h -#HEADERS += QtxSplash.h #HEADERS += QtxTable.h #HEADERS += QtxToolTip.h @@ -62,31 +62,31 @@ SOURCES += QtxComboBox.cxx SOURCES += QtxDialog.cxx SOURCES += QtxDockAction.cxx SOURCES += QtxDockWidget.cxx +SOURCES += QtxDblSpinBox.cxx SOURCES += QtxEvalExpr.cxx +SOURCES += QtxGridBox.cxx +SOURCES += QtxGroupBox.cxx +SOURCES += QtxIntSpinBox.cxx SOURCES += QtxListAction.cxx SOURCES += QtxLogoMgr.cxx SOURCES += QtxMainWindow.cxx SOURCES += QtxMRUAction.cxx +SOURCES += QtxPathDialog.cxx SOURCES += QtxPopupMgr.cxx SOURCES += QtxResourceMgr.cxx +SOURCES += QtxSplash.cxx SOURCES += QtxToolBar.cxx SOURCES += QtxValidator.cxx SOURCES += QtxWorkspace.cxx SOURCES += QtxWorkspaceAction.cxx SOURCES += QtxWorkstack.cxx SOURCES += QtxWorkstackAction.cxx -#SOURCES += QtxDblSpinBox.cxx #SOURCES += QtxDirListEditor.cxx -#SOURCES += QtxGroupBox.cxx -#SOURCES += QtxIntSpinBox.cxx #SOURCES += QtxListBox.cxx #SOURCES += QtxListResourceEdit.cxx #SOURCES += QtxListView.cxx -#SOURCES += QtxMenuButton.cxx -#SOURCES += QtxPathDialog.cxx #SOURCES += QtxPopupMenu.cxx #SOURCES += QtxResourceEdit.cxx -#SOURCES += QtxSplash.cxx #SOURCES += QtxTable.cxx #SOURCES += QtxToolTip.cxx diff --git a/src/Qtx/QtxDoubleSpinBox.cxx b/src/Qtx/QtxDoubleSpinBox.cxx index 3c6dd849f..c79e581c0 100644 --- a/src/Qtx/QtxDoubleSpinBox.cxx +++ b/src/Qtx/QtxDoubleSpinBox.cxx @@ -22,65 +22,119 @@ #include "QtxDoubleSpinBox.h" #include -#include /*! - Constructor + \class QtxDoubleSpinBox + \brief Enhanced version of the Qt's double spin box. + + The QtxDoubleSpinBox class represents the widget for entering the + floating point values. In addition to the functionality provided by + QDoubleSpinBox, this class supports "cleared" state - this is the + state corresponding to "None" (or empty) entered value. + + To set "cleared" state use setCleared() method. To check if the spin + box stores "cleared" state, use isCleared() method. + For example: + \code + if (myDblSpinBox->isCleared()) { + ... // process "None" state + } + else { + double value = myDblSpinBox->value(); + ... // process entered value + } + \endcode +*/ + +/*! + \brief Constructor. + + Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value, + a step value of 1.0 and a precision of 2 decimal places. + The value is initially set to 0.00. + + \param parent parent object */ QtxDoubleSpinBox::QtxDoubleSpinBox( QWidget* parent ) : QDoubleSpinBox( parent ), -myCleared( false ) + myCleared( false ) { - connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); + connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), + this, SLOT( onTextChanged( const QString& ) ) ); } /*! - Constructor + \brief Constructor. + + Constructs a spin box with specified minimum, maximum and step value. + The precision is set to 2 decimal places. + The value is initially set to the minimum value. + + \param min spin box minimum possible value + \param max spin box maximum possible value + \param step spin box increment/decrement value + \param parent parent object */ QtxDoubleSpinBox::QtxDoubleSpinBox( double min, double max, double step, QWidget* parent ) : QDoubleSpinBox( parent ), -myCleared( false ) + myCleared( false ) { setMinimum( min ); setMaximum( max ); setSingleStep( step ); - connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); + connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), + this, SLOT( onTextChanged( const QString& ) ) ); } /*! - Destructor + \brief Destructor. */ QtxDoubleSpinBox::~QtxDoubleSpinBox() { } /*! - \return true if spin box is cleared + \brief Check if spin box is in the "cleared" state. + \return \c true if spin box is cleared */ bool QtxDoubleSpinBox::isCleared() const { - return myCleared; + return myCleared; } /*! - Changes cleared status of spin box - \param on - new status + \brief Change "cleared" status of the spin box. + \param on new "cleared" status */ void QtxDoubleSpinBox::setCleared( const bool on ) { - if ( myCleared == on ) - return; - - myCleared = on; + if ( myCleared == on ) + return; + + myCleared = on; setSpecialValueText( specialValueText() ); } +/*! + \brief Convert value to the text. + \param val value being converted + \return string containing the converted value +*/ QString QtxDoubleSpinBox::textFromValue( double val ) const { return myCleared ? QString() : QDoubleSpinBox::textFromValue( val ); } +/*! + \brief Perform \a steps increment/decrement steps. + + The \a steps value can be any integer number. If it is > 0, + the value incrementing is done, otherwise value is decremented + \a steps times. + + \param steps number of increment/decrement steps +*/ void QtxDoubleSpinBox::stepBy( int steps ) { myCleared = false; @@ -89,9 +143,10 @@ void QtxDoubleSpinBox::stepBy( int steps ) } /*! - SLOT: called if text is changed + \brief Called when user enters the text in the spin box. + \param txt current spin box text (not used) */ -void QtxDoubleSpinBox::onTextChanged( const QString& ) +void QtxDoubleSpinBox::onTextChanged( const QString& /*txt*/ ) { myCleared = false; } diff --git a/src/Qtx/QtxDoubleSpinBox.h b/src/Qtx/QtxDoubleSpinBox.h index f800b6052..45ef5434b 100644 --- a/src/Qtx/QtxDoubleSpinBox.h +++ b/src/Qtx/QtxDoubleSpinBox.h @@ -24,12 +24,8 @@ #include "Qtx.h" -#include +#include -/*! - \class QtxDoubleSpinBox - Spin box for real numbers. -*/ class QTX_EXPORT QtxDoubleSpinBox : public QDoubleSpinBox { Q_OBJECT diff --git a/src/Qtx/QtxGridBox.cxx b/src/Qtx/QtxGridBox.cxx index f4d6685f7..bb2d33623 100644 --- a/src/Qtx/QtxGridBox.cxx +++ b/src/Qtx/QtxGridBox.cxx @@ -21,13 +21,15 @@ #include "QtxGridBox.h" -#include +#include #include /*! - \ class QtxGridBox::Space - Space in the grid box + \class QtxGridBox::Space + \internal + \brief Represents a space in the grid box. */ + class QtxGridBox::Space : public QWidget { public: @@ -42,23 +44,39 @@ private: QtxGridBox* myGrid; }; +/*! + \brief Constructor. + \param sz size + \param gb parent grid box +*/ QtxGridBox::Space::Space( const int sz, QtxGridBox* gb ) : QWidget( gb ), -mySize( sz ), -myGrid( gb ) + mySize( sz ), + myGrid( gb ) { setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); } +/*! + \brief Destructor. +*/ QtxGridBox::Space::~Space() { } +/*! + \brief Get recommended size for the widget. + \return recommended size for the widget +*/ QSize QtxGridBox::Space::sizeHint() const { return minimumSizeHint(); } +/*! + \brief Get recommended minimum size for the widget. + \return recommended minimum size for the widget +*/ QSize QtxGridBox::Space::minimumSizeHint() const { QSize sz( 0, 0 ); @@ -70,59 +88,100 @@ QSize QtxGridBox::Space::minimumSizeHint() const } /*! - \ class QtxGridBox + \class QtxGridBox + \brief A container widget with possibility to automatically layout + child widgets. +*/ + +/*! + \brief Constructor. + \param parent parent widget + \param m grid box margin + \param s grid box spacing */ QtxGridBox::QtxGridBox( QWidget* parent, const int m, const int s ) : QWidget( parent ), -myCols( 1 ), -myOrient( Qt::Vertical ), -mySkip( false ), -myCol( 0 ), -myRow( 0 ) + myCols( 1 ), + mySkip( false ), + myOrient( Qt::Vertical ), + myCol( 0 ), + myRow( 0 ) { myLayout = new QGridLayout( this ); myLayout->setMargin( m ); myLayout->setSpacing( s ); } +/*! + \brief Constructor. + \param cols number of grid box columns or rows (depending on the orientation) + \param o grid box orientation + \param parent parent widget + \param m grid box margin + \param s grid box spacing +*/ QtxGridBox::QtxGridBox( const int cols, Qt::Orientation o, QWidget* parent, const int m, const int s ) : QWidget( parent ), -myCols( cols ), -myOrient( o ), -myLayout( 0 ), -mySkip( false ), -myCol( 0 ), -myRow( 0 ) + myCols( cols ), + mySkip( false ), + myOrient( o ), + myLayout( 0 ), + myCol( 0 ), + myRow( 0 ) { myLayout = new QGridLayout( this ); myLayout->setMargin( m ); myLayout->setSpacing( s ); } +/*! + \brief Destructor. +*/ QtxGridBox::~QtxGridBox() { } +/*! + \brief Get number of grid box columns/rows (depending on the orientation). + \return number of columns (rows) +*/ int QtxGridBox::columns() const { return myCols; } +/*! + \brief Get the grid box orientation. + \return orientation +*/ Qt::Orientation QtxGridBox::orientation() const { return myOrient; } +/*! + \brief Set number of grid box columns/rows (depending on the orientation). + \param cols number of columns (rows) +*/ void QtxGridBox::setColumns( const int cols ) { setLayout( cols, orientation() ); } +/*! + \brief Set the grid box orientation. + \param o orientation +*/ void QtxGridBox::setOrientation( Qt::Orientation o ) { setLayout( columns(), o ); } +/*! + \brief Initialize internal layout. + \param cols number of columns (rows) + \param o orientation +*/ void QtxGridBox::setLayout( const int cols, Qt::Orientation o ) { if ( myCols == cols && myOrient == o ) @@ -134,11 +193,23 @@ void QtxGridBox::setLayout( const int cols, Qt::Orientation o ) arrangeWidgets(); } +/*! + \brief Get "skip invisible widgets" flags. + \return current flag state +*/ bool QtxGridBox::skipInvisible() const { return mySkip; } +/*! + \brief Set "skip invisible widgets" flags. + + If this flag is set to \c false, invisible widgets + are not taken into account when layouting widgets. + + \param on new flag state +*/ void QtxGridBox::setSkipInvisible( const bool on ) { if ( mySkip == on ) @@ -148,31 +219,57 @@ void QtxGridBox::setSkipInvisible( const bool on ) arrangeWidgets(); } +/*! + \brief Add space (empty cell) to the grid box. + \param sp requied space size +*/ void QtxGridBox::addSpace( const int sp ) { new Space( sp, this ); } +/*! + \brief Get grid box's inside margin size. + \return inside margin size +*/ int QtxGridBox::insideMargin() const { return myLayout->margin(); } +/*! + \brief Get grid box's inside spacing size. + \return inside spacing size +*/ int QtxGridBox::insideSpacing() const { return myLayout->spacing(); } +/*! + \brief Set grid box's inside margin size. + \param m new inside margin size +*/ void QtxGridBox::setInsideMargin( const int m ) { myLayout->setMargin( m ); } +/*! + \brief Set grid box's inside spacing size. + \param s new inside spacing size +*/ void QtxGridBox::setInsideSpacing( const int s ) { myLayout->setSpacing( s ); } +/*! + \brief Custom event filter. + \param o event receiver object. + \param e event + \return \c true if the event processing should be stopped +*/ bool QtxGridBox::eventFilter( QObject* o, QEvent* e ) { if ( skipInvisible() && ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent || @@ -182,6 +279,10 @@ bool QtxGridBox::eventFilter( QObject* o, QEvent* e ) return QWidget::eventFilter( o, e ); } +/*! + \brief Customize child event. + \param e child event +*/ void QtxGridBox::childEvent( QChildEvent* e ) { if ( e->child()->isWidgetType() ) @@ -198,6 +299,9 @@ void QtxGridBox::childEvent( QChildEvent* e ) QWidget::childEvent( e ); } +/*! + \brief Increment the grid box current cell. +*/ void QtxGridBox::skip() { if ( orientation() == Qt::Horizontal ) @@ -220,6 +324,9 @@ void QtxGridBox::skip() } } +/*! + \brief Arrange child widgets. +*/ void QtxGridBox::arrangeWidgets() { myRow = myCol = 0; @@ -243,6 +350,10 @@ void QtxGridBox::arrangeWidgets() updateGeometry(); } +/*! + \brief Place new widget to the current grid box cell. + \param wid widget being inserted +*/ void QtxGridBox::placeWidget( QWidget* wid ) { myLayout->addWidget( wid, myRow, myCol ); diff --git a/src/Qtx/QtxGroupBox.cxx b/src/Qtx/QtxGroupBox.cxx index 1ed871168..971b29c96 100644 --- a/src/Qtx/QtxGroupBox.cxx +++ b/src/Qtx/QtxGroupBox.cxx @@ -21,40 +21,55 @@ #include "QtxGroupBox.h" -#include +#include +#include +#include #include -#include #include /*! - Constructor + \brief class QtxGroupBox + \brief Enhanced group box widget. + + The QtxGroupBox class allows insereting custom widgets in the + group box title. Use insertTitleWidget() method to add + custom widget to the title and removeTitleWidget() to remove it. +*/ + +/*! + \brief Constructor. + \param parent parent widget */ QtxGroupBox::QtxGroupBox( QWidget* parent ) : QGroupBox( parent ), -myContainer( 0 ) + myContainer( 0 ) { initialize(); } /*! - Constructor + \brief Constructor. + \param title group box title text + \param parent parent widget */ QtxGroupBox::QtxGroupBox( const QString& title, QWidget* parent ) : QGroupBox( title, parent ), -myContainer( 0 ) + myContainer( 0 ) { initialize(); } /*! - Destructor + \brief Destructor. */ QtxGroupBox::~QtxGroupBox() { } /*! - Creates horizontal box as container + \brief Initialize the group box. + + Creates horizontal box as container for title widgets. */ void QtxGroupBox::initialize() { @@ -67,8 +82,8 @@ void QtxGroupBox::initialize() } /*! - Inserts title widget - \param wid - new title widget + \brief Add widget to the group box title. + \param wid widget being added to the title */ void QtxGroupBox::insertTitleWidget( QWidget* wid ) { @@ -82,8 +97,8 @@ void QtxGroupBox::insertTitleWidget( QWidget* wid ) } /*! - Removes title widget - \param wid - title widget + \brief Remove widget from the group box title. + \param wid widget to be removed from the title */ void QtxGroupBox::removeTitleWidget( QWidget* wid ) { @@ -99,7 +114,8 @@ void QtxGroupBox::removeTitleWidget( QWidget* wid ) } /*! - Shows group box + \brief Show/hide group box. + \param on if \c true, show group box, otherwise, hide it */ void QtxGroupBox::setVisible( bool on ) { @@ -110,7 +126,8 @@ void QtxGroupBox::setVisible( bool on ) } /*! - \return the recommended size for the widget + \brief Get recommended size for the widget. + \return recommended size for the widget */ QSize QtxGroupBox::sizeHint() const { @@ -118,7 +135,8 @@ QSize QtxGroupBox::sizeHint() const } /*! - \return the recommended minimum size for the widget + \brief Get recommended minimum size for the widget. + \return recommended minimum size for the widget */ QSize QtxGroupBox::minimumSizeHint() const { @@ -126,7 +144,10 @@ QSize QtxGroupBox::minimumSizeHint() const } /*! - Custom event filter + \brief Custom event filter. + \param obj event receiver + \param e event + \return \c true if event processing should be stopped */ bool QtxGroupBox::eventFilter( QObject* obj, QEvent* e ) { @@ -138,7 +159,10 @@ bool QtxGroupBox::eventFilter( QObject* obj, QEvent* e ) return QGroupBox::eventFilter( obj, e ); } - +/*! + \brief Get central widget (or first found one). + \return widget +*/ QWidget* QtxGroupBox::widget() const { if ( !layout() ) @@ -150,6 +174,10 @@ QWidget* QtxGroupBox::widget() const return w; } +/*! + \brief Set central widget to the group box. + \param wid widget being added to the group box +*/ void QtxGroupBox::setWidget( QWidget* wid ) { QWidget* w = widget(); @@ -176,7 +204,8 @@ void QtxGroupBox::setWidget( QWidget* wid ) } /*! - Custom resize event filter + \brief Customize resize event. + \param e resize event */ void QtxGroupBox::resizeEvent( QResizeEvent* e ) { @@ -186,7 +215,8 @@ void QtxGroupBox::resizeEvent( QResizeEvent* e ) } /*! - Custom child event filter + \brief Customize child event. + \param e child event */ void QtxGroupBox::childEvent( QChildEvent* e ) { @@ -198,15 +228,17 @@ void QtxGroupBox::childEvent( QChildEvent* e ) } /*! - Event filter of custom items + \brief Process custom events. + \param e custom event (not used) */ -void QtxGroupBox::customEvent( QEvent* ) +void QtxGroupBox::customEvent( QEvent* /*e*/ ) { updateTitle(); } /*! - \return size of title + \brief Get the group box title size. + \return title size */ QSize QtxGroupBox::titleSize() const { @@ -214,7 +246,7 @@ QSize QtxGroupBox::titleSize() const } /*! - Updates title + \brief Update the group box title. */ void QtxGroupBox::updateTitle() { @@ -271,6 +303,10 @@ void QtxGroupBox::updateTitle() updateGeometry(); } +/*! + \brief Expand group box to the specified size. + \param sz new size +*/ QSize QtxGroupBox::expandTo( const QSize& sz ) const { int sh = 0; @@ -287,6 +323,10 @@ QSize QtxGroupBox::expandTo( const QSize& sz ) const return QSize( qMax( sz.width(), sw ), qMax( sz.height(), sh ) ); } +/*! + \brief Set group box's inside margin size. + \param m new inside margin size +*/ void QtxGroupBox::setInsideMargin( const int m ) { QVBoxLayout* bl = ::qobject_cast( layout() ); diff --git a/src/Qtx/QtxGroupBox.h b/src/Qtx/QtxGroupBox.h index a2d0715d1..c2aa4e65b 100644 --- a/src/Qtx/QtxGroupBox.h +++ b/src/Qtx/QtxGroupBox.h @@ -25,7 +25,6 @@ #include "Qtx.h" #include -#include class QTX_EXPORT QtxGroupBox : public QGroupBox { diff --git a/src/Qtx/QtxIntSpinBox.cxx b/src/Qtx/QtxIntSpinBox.cxx index d8d4e1858..175a297ae 100755 --- a/src/Qtx/QtxIntSpinBox.cxx +++ b/src/Qtx/QtxIntSpinBox.cxx @@ -22,40 +22,78 @@ #include "QtxIntSpinBox.h" #include -//#include +/*! + \class QtxIntSpinBox + \brief Enhanced version of the Qt's spin box. + + The QtxIntSpinBox class represents the widget for entering the + integer values. In addition to the functionality provided by + QSpinBox, this class supports "cleared" state - this is the + state corresponding to "None" (or empty) entered value. + + To set "cleared" state use setCleared() method. To check if the spin + box stores "cleared" state, use isCleared() method. + For example: + \code + if (mySpinBox->isCleared()) { + ... // process "None" state + } + else { + int value = mySpinBox->value(); + ... // process entered value + } + \endcode +*/ /*! - Constructor + \brief Constructor. + + Constructs a spin box with 0 as minimum value and 99 as maximum value, + a step value of 1. The value is initially set to 0. + + \param parent parent object */ QtxIntSpinBox::QtxIntSpinBox( QWidget* parent ) : QSpinBox( parent ), -myCleared( false ) + myCleared( false ) { - connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); + connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), + this, SLOT( onTextChanged( const QString& ) ) ); } /*! - Constructor + \brief Constructor. + + Constructs a spin box with specified minimum, maximum and step value. + The value is initially set to the minimum value. + + \param min spin box minimum possible value + \param max spin box maximum possible value + \param step spin box increment/decrement value + \param parent parent object */ QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent ) : QSpinBox( parent ), -myCleared( false ) + myCleared( false ) { setMinimum( min ); setMaximum( max ); setSingleStep( step ); - connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); + + connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), + this, SLOT( onTextChanged( const QString& ) ) ); } /*! - Destructor + \brief Destructor. */ QtxIntSpinBox::~QtxIntSpinBox() { } /*! - \return true if spin box is cleared + \brief Check if spin box is in the "cleared" state. + \return \c true if spin box is cleared */ bool QtxIntSpinBox::isCleared() const { @@ -63,23 +101,37 @@ bool QtxIntSpinBox::isCleared() const } /*! - Changes cleared status of spin box - \param on - new status + \brief Change "cleared" status of the spin box. + \param on new "cleared" status */ void QtxIntSpinBox::setCleared( const bool on ) { if ( myCleared == on ) return; - + myCleared = on; setSpecialValueText( specialValueText() ); } +/*! + \brief Convert value to the text. + \param val value being converted + \return string containing the converted value +*/ QString QtxIntSpinBox::textFromValue( int val ) const { return myCleared ? QString() : QSpinBox::textFromValue( val ); } +/*! + \brief Perform \a steps increment/decrement steps. + + The \a steps value can be any integer number. If it is > 0, + the value incrementing is done, otherwise value is decremented + \a steps times. + + \param steps number of increment/decrement steps +*/ void QtxIntSpinBox::stepBy( int steps ) { myCleared = false; @@ -88,7 +140,8 @@ void QtxIntSpinBox::stepBy( int steps ) } /*! - SLOT: called if text is changed + \brief Called when user enters the text in the spin box. + \param txt current spin box text (not used) */ void QtxIntSpinBox::onTextChanged( const QString& ) { diff --git a/src/Qtx/QtxPathDialog.cxx b/src/Qtx/QtxPathDialog.cxx index a85719def..4aa71bc80 100755 --- a/src/Qtx/QtxPathDialog.cxx +++ b/src/Qtx/QtxPathDialog.cxx @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -61,585 +61,662 @@ static const char* open_icon[] = { }; /*! - Constructor. + \class QtxPathDialog + \brief The QtxPathDialog class provides a simple convenience dialog to + enter a path to the file or to the directory. + + The QtxPathDialog class adds possibility to browse the file system + with help of standard Open/Save dialog boxes or enter the file/directory + path manually. + + Default implementation provides only one "standard" file entry. + Sometimes it is necessary to select several different files/directories + from the same dialog box. In this case it is possible to derive from the + QtxPathDialog class and use createFileEntry() method to add required + number of file entries. +*/ + +/*! + \brief Constructor. + \param import if \c true, the dialog box is shown for "open" mode, + otherwise, it is shown in the "save" mode + \param parent parent widget + \param modal if \c true, the dialog box should be modal + \param resize if \c true, the dialog box is resizable + \param buttons required buttons (QtxDialog::ButtonFlags) + \param f window flags */ QtxPathDialog::QtxPathDialog( const bool import, QWidget* parent, const bool modal, const bool resize, const int buttons, Qt::WindowFlags f ) : QtxDialog( parent, modal, resize, buttons, f ), -myDefault( -1 ), -myEntriesFrame( 0 ), -myOptionsFrame( 0 ) + myDefault( -1 ), + myEntriesFrame( 0 ), + myOptionsFrame( 0 ) { - initialize(); - - setWindowTitle( tr( import ? "Open file" : "Save file" ) ); - - setDefaultEntry( createFileEntry( tr( "File name" ), import ? OpenFile : SaveFile ) ); - QLineEdit* le = fileEntry( defaultEntry() ); - if ( le ) - le->setMinimumWidth( 200 ); - - validate(); - - setFocusProxy( le ); + initialize(); + + setWindowTitle( tr( import ? "Open file" : "Save file" ) ); + + setDefaultEntry( createFileEntry( tr( "File name" ), import ? OpenFile : SaveFile ) ); + QLineEdit* le = fileEntry( defaultEntry() ); + if ( le ) + le->setMinimumWidth( 200 ); + + validate(); + + setFocusProxy( le ); updateVisibility(); } /*! - Constructor. + \brief Constructor. + \param parent parent widget + \param modal if \c true, the dialog box should be modal + \param resize if \c true, the dialog box is resizable + \param buttons required buttons (QtxDialog::ButtonFlags) + \param f window flags */ QtxPathDialog::QtxPathDialog( QWidget* parent, const bool modal, const bool resize, const int buttons, Qt::WindowFlags f ) : QtxDialog( parent, modal, resize, buttons, f ), -myDefault( -1 ), -myEntriesFrame( 0 ), -myOptionsFrame( 0 ) + myDefault( -1 ), + myEntriesFrame( 0 ), + myOptionsFrame( 0 ) { - initialize(); + initialize(); updateVisibility(); } /*! - Destructor. + \brief Destructor. */ QtxPathDialog::~QtxPathDialog() { } /*! + \brief Get selected file name. \return file name */ QString QtxPathDialog::fileName() const { - return fileName( defaultEntry() ); + return fileName( defaultEntry() ); } /*! - Sets file name - \param txt - new file name - \param autoExtension - auto extension determination by file + \brief Set the file name. + \param txt new file name + \param autoExtension if \c true an extension is determined automatically by file */ void QtxPathDialog::setFileName( const QString& txt, const bool autoExtension ) { - setFileName( defaultEntry(), txt, autoExtension ); + setFileName( defaultEntry(), txt, autoExtension ); } /*! - \return filter + \brief Get current file filter. + \return file filter */ QString QtxPathDialog::filter() const { - return filter( defaultEntry() ); + return filter( defaultEntry() ); } /*! - Changes filter (filter is a list of masks, separated by ';;') - \param fltr - new filter + \brief Change file filter. + + Filter is a list of file masks, separated by ';;'. For example, + "*.h;;*.cxx" + + \param fltr new file filter */ void QtxPathDialog::setFilter( const QString& fltr ) { - setFilter( defaultEntry(), fltr ); + setFilter( defaultEntry(), fltr ); } /*! - Shows/hides path dialog + \brief Show/hide the path dialog box/ + \param on new visibility state */ void QtxPathDialog::setVisible( bool on ) { if ( on ) updateVisibility(); - QtxDialog::setVisible( on ); + QtxDialog::setVisible( on ); } /*! - SLOT: called if user click button to show standard file dialog + \brief Called when user clicks a "browse" button + to open standard file dialog. */ void QtxPathDialog::onBrowse() { - const QObject* obj = sender(); - - int id = -1; + const QObject* obj = sender(); - for ( FileEntryMap::Iterator it = myEntries.begin(); it != myEntries.end() && id == -1; ++it ) + int id = -1; + + for ( FileEntryMap::Iterator it = myEntries.begin(); it != myEntries.end() && id == -1; ++it ) { - if ( it.value().btn == obj ) - id = it.key(); + if ( it.value().btn == obj ) + id = it.key(); } - - if ( id == -1 ) - return; - - FileEntry& entry = myEntries[id]; - - bool isDir = entry.mode != OpenFile && entry.mode != SaveFile; - - if ( !entry.dlg ) - { - entry.dlg = new QFileDialog( this, windowTitle(), QDir::current().path() ); - switch ( entry.mode ) - { - case NewDir: - case OpenDir: - case SaveDir: - isDir = true; - entry.dlg->setFileMode( QFileDialog::DirectoryOnly ); - break; - case SaveFile: - entry.dlg->setFileMode( QFileDialog::AnyFile ); - break; - case OpenFile: - default: - entry.dlg->setFileMode( QFileDialog::ExistingFiles ); - break; - } - } - - if ( !isDir ) + + if ( id == -1 ) + return; + + FileEntry& entry = myEntries[id]; + + bool isDir = entry.mode != OpenFile && entry.mode != SaveFile; + + if ( !entry.dlg ) + { + entry.dlg = new QFileDialog( this, windowTitle(), QDir::current().path() ); + switch ( entry.mode ) + { + case NewDir: + case OpenDir: + case SaveDir: + isDir = true; + entry.dlg->setFileMode( QFileDialog::DirectoryOnly ); + break; + case SaveFile: + entry.dlg->setFileMode( QFileDialog::AnyFile ); + break; + case OpenFile: + default: + entry.dlg->setFileMode( QFileDialog::ExistingFiles ); + break; + } + } + + if ( !isDir ) { QStringList fList = prepareFilters( entry.filter ); if ( !fList.isEmpty() ) - entry.dlg->setFilters( fList ); + entry.dlg->setFilters( fList ); } - entry.dlg->selectFile( fileName( id ) ); + entry.dlg->selectFile( fileName( id ) ); - if ( entry.dlg->exec() != Accepted ) - return; - - QStringList fileList = entry.dlg->selectedFiles(); + if ( entry.dlg->exec() != Accepted ) + return; + + QStringList fileList = entry.dlg->selectedFiles(); QString fName = !fileList.isEmpty() ? fileList.first() : QString(); - - if ( fName.isEmpty() ) - return; - + + if ( fName.isEmpty() ) + return; + if ( Qtx::extension( fName ).isEmpty() && !isDir ) - fName = autoExtension( fName, entry.dlg->selectedFilter() ); - - fName = QDir::convertSeparators( fName ); - QString prev = QDir::convertSeparators( fileName( id ) ); - if ( isDir ) - { - while ( prev.length() && prev.at( prev.length() - 1 ) == QDir::separator() ) - prev.remove( prev.length() - 1, 1 ); - while ( fName.length() && fName.at( fName.length() - 1 ) == QDir::separator() ) - fName.remove( fName.length() - 1, 1 ); - } + fName = autoExtension( fName, entry.dlg->selectedFilter() ); - if ( prev == fName ) - return; - - setFileName( id, fName ); - fileNameChanged( id, fName ); - - if ( id == defaultEntry() ) - emit fileNameChanged( fName ); + fName = QDir::convertSeparators( fName ); + QString prev = QDir::convertSeparators( fileName( id ) ); + if ( isDir ) + { + while ( prev.length() && prev.at( prev.length() - 1 ) == QDir::separator() ) + prev.remove( prev.length() - 1, 1 ); + while ( fName.length() && fName.at( fName.length() - 1 ) == QDir::separator() ) + fName.remove( fName.length() - 1, 1 ); + } + + if ( prev == fName ) + return; + + setFileName( id, fName ); + fileNameChanged( id, fName ); + + if ( id == defaultEntry() ) + emit fileNameChanged( fName ); } /*! - SLOT: called if user presses RETURN in line edit + \brief Called when user presses \c Return key being in the line edit. */ void QtxPathDialog::onReturnPressed() { - const QObject* obj = sender(); - - int id = -1; - for ( FileEntryMap::Iterator it = myEntries.begin(); it != myEntries.end() && id == -1; ++it ) + const QObject* obj = sender(); + + int id = -1; + for ( FileEntryMap::Iterator it = myEntries.begin(); it != myEntries.end() && id == -1; ++it ) { - if ( it.value().edit == obj ) - id = it.key(); + if ( it.value().edit == obj ) + id = it.key(); } - if ( id == -1 ) - return; - - fileNameChanged( id, fileName( id ) ); - - if ( id == defaultEntry() ) - emit fileNameChanged( fileName() ); + if ( id == -1 ) + return; + + fileNameChanged( id, fileName( id ) ); + + if ( id == defaultEntry() ) + emit fileNameChanged( fileName() ); } /*! - SLOT: called if text in line edit is changed + \brief Called when the text in the line edit is changed by the user. + \param txt current text (not used) */ -void QtxPathDialog::onTextChanged( const QString& ) +void QtxPathDialog::onTextChanged( const QString& /*txt*/ ) { - validate(); + validate(); } /*! - Checks validity of text and according to it enables/disables OK, Yes buttons + \brief Check validity of the entered text and enable/disable standard + \c OK, \c Yes buttons. */ void QtxPathDialog::validate() { - setButtonEnabled( isValid(), OK | Yes ); + setButtonEnabled( isValid(), OK | Yes ); } /*! - \return true if selected file is valid + \brief Check if the entered file/directory name is valid. + \return \c true if selected file name is valid */ bool QtxPathDialog::isValid() { - bool ok = true; - for ( FileEntryMap::Iterator it = myEntries.begin(); it != myEntries.end() && ok; ++it ) + bool ok = true; + for ( FileEntryMap::Iterator it = myEntries.begin(); it != myEntries.end() && ok; ++it ) { - if ( it.value().edit->isEnabled() ) - ok = !it.value().edit->text().trimmed().isEmpty(); + if ( it.value().edit->isEnabled() ) + ok = !it.value().edit->text().trimmed().isEmpty(); } - - return ok; + + return ok; } /*! - \return true entered data is accepted + \brief Check if the entered data is acceptable. + \return \c true if entered data is acceptable */ bool QtxPathDialog::acceptData() const { - bool ok = true; - - QWidget* parent = (QWidget*)this; + bool ok = true; + + QWidget* parent = (QWidget*)this; - FileEntryMap::ConstIterator it; - for ( it = myEntries.begin(); it != myEntries.end() && ok; ++it ) + FileEntryMap::ConstIterator it; + for ( it = myEntries.begin(); it != myEntries.end() && ok; ++it ) + { + const FileEntry& entry = it.value(); + QFileInfo fileInfo( entry.edit->text() ); + if ( entry.edit->text().isEmpty() ) + { + QMessageBox::critical( parent, windowTitle(), tr( "File name not specified" ), + QMessageBox::Ok, QMessageBox::NoButton ); + ok = false; + } + else switch ( entry.mode ) + { + case OpenFile: + if ( !fileInfo.exists() ) + { + QMessageBox::critical( parent, windowTitle(), tr( "File \"%1\" does not exist" ).arg( fileInfo.filePath() ), + QMessageBox::Ok, QMessageBox::NoButton ); + ok = false; + } + break; + case SaveFile: + if ( fileInfo.exists() ) + ok = QMessageBox::warning( parent, windowTitle(), tr( "File \"%1\" already exist. Do you want to overwrite it?" ).arg( fileInfo.filePath() ), + QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes; + break; + case OpenDir: + if ( !fileInfo.exists() || !fileInfo.isDir() ) + { + QMessageBox::critical( parent, windowTitle(), tr( "Directory \"%1\" does not exist" ).arg( fileInfo.filePath() ), + QMessageBox::Ok, QMessageBox::NoButton ); + ok = false; + } + break; + case SaveDir: + if ( fileInfo.exists() && !fileInfo.isDir() ) + { + QMessageBox::critical( parent, windowTitle(), tr( "Directory \"%1\" can't be created because file with the same name exist" ).arg( fileInfo.filePath() ), + QMessageBox::Ok, QMessageBox::NoButton ); + ok = false; + } + break; + case NewDir: + if ( fileInfo.exists() ) + { + if ( !fileInfo.isDir() ) { - const FileEntry& entry = it.value(); - QFileInfo fileInfo( entry.edit->text() ); - if ( entry.edit->text().isEmpty() ) - { - QMessageBox::critical( parent, windowTitle(), tr( "File name not specified" ), - QMessageBox::Ok, QMessageBox::NoButton ); - ok = false; - } - else switch ( entry.mode ) - { - case OpenFile: - if ( !fileInfo.exists() ) - { - QMessageBox::critical( parent, windowTitle(), tr( "File \"%1\" does not exist" ).arg( fileInfo.filePath() ), - QMessageBox::Ok, QMessageBox::NoButton ); - ok = false; - } - break; - case SaveFile: - if ( fileInfo.exists() ) - ok = QMessageBox::warning( parent, windowTitle(), tr( "File \"%1\" already exist. Do you want to overwrite it?" ).arg( fileInfo.filePath() ), - QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes; - break; - case OpenDir: - if ( !fileInfo.exists() || !fileInfo.isDir() ) - { - QMessageBox::critical( parent, windowTitle(), tr( "Directory \"%1\" does not exist" ).arg( fileInfo.filePath() ), - QMessageBox::Ok, QMessageBox::NoButton ); - ok = false; - } - break; - case SaveDir: - if ( fileInfo.exists() && !fileInfo.isDir() ) - { - QMessageBox::critical( parent, windowTitle(), tr( "Directory \"%1\" can't be created because file with the same name exist" ).arg( fileInfo.filePath() ), - QMessageBox::Ok, QMessageBox::NoButton ); - ok = false; - } - break; - case NewDir: - if ( fileInfo.exists() ) - { - if ( !fileInfo.isDir() ) - { - QMessageBox::critical( parent, windowTitle(), tr( "Directory \"%1\" can't be created because file with the same name exist" ).arg( fileInfo.filePath() ), - QMessageBox::Ok, QMessageBox::NoButton ); - ok = false; - } - else if ( QDir( fileInfo.filePath() ).count() > 2 ) - ok = QMessageBox::warning( parent, windowTitle(), tr( "Directory \"%1\" not empty. Do you want to remove all files in this directory?" ).arg( fileInfo.filePath() ), - QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes; - } - break; - default: - break; - } - - if ( !ok ) - entry.edit->setFocus(); + QMessageBox::critical( parent, windowTitle(), tr( "Directory \"%1\" can't be created because file with the same name exist" ).arg( fileInfo.filePath() ), + QMessageBox::Ok, QMessageBox::NoButton ); + ok = false; } - - return ok; + else if ( QDir( fileInfo.filePath() ).count() > 2 ) + ok = QMessageBox::warning( parent, windowTitle(), tr( "Directory \"%1\" not empty. Do you want to remove all files in this directory?" ).arg( fileInfo.filePath() ), + QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes; + } + break; + default: + break; + } + + if ( !ok ) + entry.edit->setFocus(); + } + + return ok; } /*! - Some custom activity on file name changing (must be redefined, default implementation is empty + \brief Perform custom actions when the file name is changed. + + This method can be redefined in the successor classes. + Default implementation does nothing. + + \param id file entry + \param fileName file name */ -void QtxPathDialog::fileNameChanged( int, QString ) +void QtxPathDialog::fileNameChanged( int /*id*/, QString /*fileName*/ ) { } /*! - \return frame with options + \fn void QtxPathDialog::fileNameChanged( QString fileName ); + \brief Emitted when the file name is changed. + \param fileName file name +*/ + +/*! + \brief Get options grame widget. + \return options frame widget */ QFrame* QtxPathDialog::optionsFrame() { - return myOptionsFrame; + return myOptionsFrame; } /*! - \return file name - \param id - id of file entry + \brief Get file name from specified entry. + \param id file entry ID + \return file name or null string if \a id is invalid */ QString QtxPathDialog::fileName( const int id ) const { - QString res; - if ( myEntries.contains( id ) ) - res = myEntries[id].edit->text(); - return res; + QString res; + if ( myEntries.contains( id ) ) + res = myEntries[id].edit->text(); + return res; } /*! - Change file name of file entry - \param id - id of file entry - \param txt - new file name - \param autoExt - assign extension automatically + \brief Change file name by specified file entry. + \param id file entry ID + \param txt new file name + \param autoExt if \c true, assign extension automatically */ void QtxPathDialog::setFileName( const int id, const QString& txt, const bool autoExt ) { - int mode; - QLineEdit* le = fileEntry( id, mode ); - - if ( le ) - { - if ( autoExt && ( mode == OpenFile || mode == SaveFile ) ) - le->setText( autoExtension( txt, filter( id ) ) ); - else - le->setText( txt ); - } + int mode; + QLineEdit* le = fileEntry( id, mode ); + + if ( le ) + { + if ( autoExt && ( mode == OpenFile || mode == SaveFile ) ) + le->setText( autoExtension( txt, filter( id ) ) ); + else + le->setText( txt ); + } } /*! - \return filter - \param id - id of file entry + \brief Get file filter from the specified file entry. + \param id file entry ID + \return file filter or null string if \a id is invalid */ QString QtxPathDialog::filter( const int id ) const { - QString res; - if ( myEntries.contains( id ) ) - res = myEntries[id].filter; - return res; + QString res; + if ( myEntries.contains( id ) ) + res = myEntries[id].filter; + return res; } +/*! + \brief Set file filter to the specified file entry. + \param id file entry ID + \param filter file filter or null string if \a id is invalid +*/ void QtxPathDialog::setFilter( const int id, const QString& filter ) { - if ( myEntries.contains( id ) ) - myEntries[id].filter = filter; + if ( myEntries.contains( id ) ) + myEntries[id].filter = filter; } /*! - \return line edit of file entry - \param id - id of file entry + \brief Get line edit widget for the specified file entry. + \param id file entry ID + \return line edit widget or 0 if \a id is invalid */ QLineEdit* QtxPathDialog::fileEntry( const int id ) const { - QLineEdit* le = 0; - if ( myEntries.contains( id ) ) - le = myEntries[id].edit; - - return le; + QLineEdit* le = 0; + if ( myEntries.contains( id ) ) + le = myEntries[id].edit; + + return le; } /*! - \return line edit and mode of file entry - \param id - id of file entry - \param theMode - for return mode of file entry + \brief Get line edit widget and file mode for the specified file entry. + \param id file entry ID + \param theMode to return file entry mode + \return line edit widget or 0 if \a id is invalid */ QLineEdit* QtxPathDialog::fileEntry( const int theId, int& theMode ) const { - QLineEdit* le = 0; - if ( myEntries.contains( theId ) ) - { - le = myEntries[theId].edit; - theMode = myEntries[theId].mode; - } - - return le; + QLineEdit* le = 0; + if ( myEntries.contains( theId ) ) + { + le = myEntries[theId].edit; + theMode = myEntries[theId].mode; + } + + return le; } /*! - Creates file entry - \return id of just created file entry - \param lab - title of entry - \param mode - mode of entry - \param id - proposed id (if it is -1, then id will be chosen automatically) + \brief Create new file entry. + + If required file entry is already in use or if specified \a id is < 0, + new ID is generated and returned. + + \param lab file entry title + \param mode file entry mode + \param id required file entry ID + \return created file entry ID */ -int QtxPathDialog::createFileEntry( const QString& lab, const int mode, const QString& filter, const int id ) +int QtxPathDialog::createFileEntry( const QString& lab, const int mode, + const QString& filter, const int id ) { - int num = id; - if ( num == -1 ) - { - num--; - while ( myEntries.contains( num ) ) - num--; - } - - FileEntry entry; - entry.dlg = 0; - entry.mode = mode; + int num = id; + if ( num == -1 ) + { + num--; + while ( myEntries.contains( num ) ) + num--; + } + + FileEntry entry; + entry.dlg = 0; + entry.mode = mode; entry.filter = filter; - - new QLabel( lab, myEntriesFrame ); - entry.edit = new QLineEdit( myEntriesFrame ); - entry.btn = new QPushButton( myEntriesFrame ); - entry.btn->setAutoDefault( false ); - entry.btn->setIcon( QPixmap( open_icon ) ); - - connect( entry.btn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) ); - connect( entry.edit, SIGNAL( returnPressed() ), this, SLOT( onReturnPressed() ) ); - connect( entry.edit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); - - myEntries.insert( num, entry ); - - return num; + + new QLabel( lab, myEntriesFrame ); + entry.edit = new QLineEdit( myEntriesFrame ); + entry.btn = new QPushButton( myEntriesFrame ); + entry.btn->setAutoDefault( false ); + entry.btn->setIcon( QPixmap( open_icon ) ); + + connect( entry.btn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) ); + connect( entry.edit, SIGNAL( returnPressed() ), this, SLOT( onReturnPressed() ) ); + connect( entry.edit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); + + myEntries.insert( num, entry ); + + return num; } /*! - \return id of default entry + \brief Get default file entry ID. + \return default entry ID */ int QtxPathDialog::defaultEntry() const { - return myDefault; + return myDefault; } /*! - Change default entry id - \param id - new default entry id + \brief Set default entry. + \param id new default entry ID */ void QtxPathDialog::setDefaultEntry( const int id ) { - myDefault = id; + myDefault = id; } /*! - Initialize dialog layout + \brief Initialize dialog layout. */ void QtxPathDialog::initialize() { - setWindowTitle( tr( "File dialog" ) ); + setWindowTitle( tr( "File dialog" ) ); - QVBoxLayout* main = new QVBoxLayout( mainFrame() ); + QVBoxLayout* main = new QVBoxLayout( mainFrame() ); main->setMargin( 0 ); - QtxGroupBox* base = new QtxGroupBox( "", mainFrame() ); - main->addWidget( base ); - + QtxGroupBox* base = new QtxGroupBox( "", mainFrame() ); + main->addWidget( base ); + QtxGridBox* mainGroup = new QtxGridBox( 1, Qt::Horizontal, base, 0 ); base->setWidget( mainGroup ); - - myEntriesFrame = new QtxGridBox( 3, Qt::Horizontal, mainGroup ); - myOptionsFrame = new QFrame( mainGroup ); + + myEntriesFrame = new QtxGridBox( 3, Qt::Horizontal, mainGroup ); + myOptionsFrame = new QFrame( mainGroup ); } /*! - \return list of filters + \brief Prepare file filters. + \param list of file masks, separated by ';;', for example, "*.h;;*.cxx" + \return list of processed file filters */ QStringList QtxPathDialog::prepareFilters( const QString& filter ) const { - QStringList res; + QStringList res; bool allFilter = false; - if ( !filter.isEmpty() ) - { - res = filter.split( ";;" ); - for ( QStringList::ConstIterator it = res.begin(); it != res.end() && !allFilter; ++it ) - { - QStringList wildCards = filterWildCards( *it ); - allFilter = wildCards.indexOf( "*.*" ) != -1; - } - } - + if ( !filter.isEmpty() ) + { + res = filter.split( ";;" ); + for ( QStringList::ConstIterator it = res.begin(); it != res.end() && !allFilter; ++it ) + { + QStringList wildCards = filterWildCards( *it ); + allFilter = wildCards.indexOf( "*.*" ) != -1; + } + } + if ( !allFilter ) - res.append( tr( "All files (*.*)" ) ); - - return res; + res.append( tr( "All files (*.*)" ) ); + + return res; } /*! + \brief Get wildcards from the specified file filter. + \param theFilter file filter being processed \return list of filters with filtered wild cards */ QStringList QtxPathDialog::filterWildCards( const QString& theFilter ) const { - QStringList res; + QStringList res; - int b = theFilter.lastIndexOf( "(" ); - int e = theFilter.lastIndexOf( ")" ); - if ( b != -1 && e != -1 ) - { - QString content = theFilter.mid( b + 1, e - b - 1 ).trimmed(); - QStringList lst = content.split( " " ); - for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) + int b = theFilter.lastIndexOf( "(" ); + int e = theFilter.lastIndexOf( ")" ); + if ( b != -1 && e != -1 ) + { + QString content = theFilter.mid( b + 1, e - b - 1 ).trimmed(); + QStringList lst = content.split( " " ); + for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) { - if ( (*it).indexOf( "." ) != -1 ) - res.append( (*it).trimmed() ); + if ( (*it).indexOf( "." ) != -1 ) + res.append( (*it).trimmed() ); } - } - return res; + } + return res; } /*! + \brief Get file file name with automatically assigned extension. + \param theFileName file name being processed + \param theFilter list of file filters \return file name with assigned extension - \param theFileName - source file name - \param theFilter - list of filters */ QString QtxPathDialog::autoExtension( const QString& theFileName, const QString& theFilter ) const { - QString fName = theFileName; + QString fName = theFileName; - if ( fName.isEmpty() ) - return fName; - - QString filter; + if ( fName.isEmpty() ) + return fName; + + QString filter; QStringList filters = prepareFilters( theFilter ); if ( !filters.isEmpty() ) filter = filters.first(); - QStringList wildCards = filterWildCards( filter ); - if ( !wildCards.isEmpty() ) - { - QString ext = wildCards.first(); - if ( ext.indexOf( "." ) != -1 ) - ext = ext.mid( ext.indexOf( "." ) + 1 ); - - if ( !ext.isEmpty() && !ext.contains( "*" ) ) - fName = QDir::convertSeparators( fName ) + QString( "." ) + ext; - } - - return fName; + QStringList wildCards = filterWildCards( filter ); + if ( !wildCards.isEmpty() ) + { + QString ext = wildCards.first(); + if ( ext.indexOf( "." ) != -1 ) + ext = ext.mid( ext.indexOf( "." ) + 1 ); + + if ( !ext.isEmpty() && !ext.contains( "*" ) ) + fName = QDir::convertSeparators( fName ) + QString( "." ) + ext; + } + + return fName; } /*! - \return true if widget has visible children - \param wid - widget + \brief Check if there are visible child widgets. + \param wid parent widget being checked + \return \c true if widget \a wid has visible children */ bool QtxPathDialog::hasVisibleChildren( QWidget* wid ) const { - bool res = false; - if ( wid ) - { - const QObjectList& aChildren = wid->children(); + bool res = false; + if ( wid ) + { + const QObjectList& aChildren = wid->children(); for ( QObjectList::const_iterator it = aChildren.begin(); it != aChildren.end() && !res; ++it ) - { - if ( (*it)->isWidgetType() ) - res = ((QWidget*)(*it))->isVisibleTo( wid ); + { + if ( (*it)->isWidgetType() ) + res = ((QWidget*)(*it))->isVisibleTo( wid ); } - } - return res; + } + return res; } +/*! + \brief Upadte dialof box's child widgets visibility state. +*/ void QtxPathDialog::updateVisibility() { if ( hasVisibleChildren( myEntriesFrame ) ) - myEntriesFrame->show(); + myEntriesFrame->show(); else - myEntriesFrame->hide(); - + myEntriesFrame->hide(); + if ( hasVisibleChildren( myOptionsFrame ) ) - myOptionsFrame->show(); + myOptionsFrame->show(); else - myOptionsFrame->hide(); + myOptionsFrame->hide(); } -- 2.39.2