From: vsr Date: Thu, 10 May 2007 13:35:25 +0000 (+0000) Subject: Porting to Qt4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=50fe72f9964e7c19a04cf845f7d1ffcea91c33f6;p=modules%2Fgui.git Porting to Qt4 --- diff --git a/src/Qtx/QtxActionToolMgr.cxx b/src/Qtx/QtxActionToolMgr.cxx index ded6a5f1b..1da344416 100644 --- a/src/Qtx/QtxActionToolMgr.cxx +++ b/src/Qtx/QtxActionToolMgr.cxx @@ -27,7 +27,7 @@ #include /*! - \class ToolNode + \class QtxActionToolMgr::ToolNode \internal \brief Represents a toolbutton inside toolbar structure. */ @@ -669,7 +669,7 @@ void QtxActionToolMgr::triggerUpdate( const int tid ) /*! - \class QtxActionMenuMgr::ToolCreator + \class QtxActionToolMgr::ToolCreator \brief Toolbars creator. Used by Reader to create actions by reading descriptions from the file, diff --git a/src/Qtx/QtxDialog.cxx b/src/Qtx/QtxDialog.cxx index c52cb85fe..859dcb226 100755 --- a/src/Qtx/QtxDialog.cxx +++ b/src/Qtx/QtxDialog.cxx @@ -21,309 +21,319 @@ #include "QtxDialog.h" -#include "QtxGroupBox.h" - -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include /*! - Class: QtxDialog::Area - Level: Internal + \class QtxDialog::Area + \internal + \brief Area containing dialog box buttons. */ + class QtxDialog::Area : public QFrame { public: - Area( Orientation, QtxDialog*, QWidget* = 0 ); - virtual ~Area(); + Area( Qt::Orientation, QtxDialog*, QWidget* = 0 ); + virtual ~Area(); - bool isBorderEnabled() const; - void setBorderEnabled( const bool ); + bool isBorderEnabled() const; + void setBorderEnabled( const bool ); - void setBorderWidget( QLabel* ); + void setBorderWidget( QLabel* ); - void insertButton( QButton* ); - void removeButton( QButton* ); - bool contains( QButton* ) const; + void insertButton( QAbstractButton* ); + void removeButton( QAbstractButton* ); + bool contains( QAbstractButton* ) const; - int policy() const; - void setPolicy( const int ); + int policy() const; + void setPolicy( const int ); - void layoutButtons(); + void layoutButtons(); - const QPtrList& buttons() const; + const QList& buttons() const; private: - void updateBorder(); + void updateBorder(); private: - QtxDialog* myDlg; - QLabel* myLine; - bool myBorder; - int myPolicy; - QPtrList myButtons; - Orientation myOrientation; + QtxDialog* myDlg; //!< parent dialog box + QLabel* myLine; //!< border widget + bool myBorder; //!< "has border" flag + int myPolicy; //!< button layout type (QtxDialog::PlacePolicy) + QList myButtons; //!< buttons list + Qt::Orientation myOrientation; //!< buttons orientation (Qt::Orientation) }; /*! - Contructor + \brief Constructor. + \param o buttons orientation + \param dlg dialog box owning this area + \param parent parent widget */ -QtxDialog::Area::Area( Orientation o, QtxDialog* dlg, QWidget* parent ) +QtxDialog::Area::Area( Qt::Orientation o, QtxDialog* dlg, QWidget* parent ) : QFrame( parent ), -myDlg( dlg ), -myLine( 0 ), -myBorder( false ), -myPolicy( Position ), -myOrientation( o ) + myDlg( dlg ), + myLine( 0 ), + myBorder( false ), + myPolicy( Position ), + myOrientation( o ) { - if ( myOrientation == Qt::Horizontal ) - setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) ); - else - setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) ); + if ( myOrientation == Qt::Horizontal ) + setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) ); + else + setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) ); - hide(); + hide(); } /*! - Destructor + \brief Destructor. */ QtxDialog::Area::~Area() { } /*! - Inserts button to area - \param b - button + \brief Insert button to the area. + \param b button to be added + \sa removeButton() */ -void QtxDialog::Area::insertButton( QButton* b ) +void QtxDialog::Area::insertButton( QAbstractButton* b ) { - if ( !b || myButtons.findRef( b ) != -1 ) - return; + if ( !b || myButtons.contains( b ) ) + return; - QWidget* parent = b->parentWidget(); - if ( parent != this ) - b->reparent( this, 0, QPoint( 0, 0 ), b->isVisibleTo( parent ) ); + QWidget* parent = b->parentWidget(); + if ( parent != this ) + b->setParent( this ); - myButtons.append( b ); + myButtons.append( b ); - if ( myDlg ) - myDlg->adjustButtons(); - layoutButtons(); + if ( myDlg ) + myDlg->adjustButtons(); + layoutButtons(); - show(); + show(); - updateBorder(); + updateBorder(); } /*! - Removes button from area - \param b - button + \brief Remove button from the area. + \param b button to be removed + \sa insertButton() */ -void QtxDialog::Area::removeButton( QButton* b ) +void QtxDialog::Area::removeButton( QAbstractButton* b ) { - if ( !b ) - return; + if ( !b ) + return; - myButtons.removeRef( b ); + myButtons.removeAll( b ); - if ( myButtons.isEmpty() ) - hide(); + if ( myButtons.isEmpty() ) + hide(); - updateBorder(); + updateBorder(); - if ( myDlg ) - myDlg->adjustButtons(); + if ( myDlg ) + myDlg->adjustButtons(); - layoutButtons(); + layoutButtons(); } /*! - \return true if area contains button - \param b - button + \brief Check if area owns the button specified. + \param b button to be checked + \return \c true if area contains button */ -bool QtxDialog::Area::contains( QButton* b ) const +bool QtxDialog::Area::contains( QAbstractButton* b ) const { - return myButtons.containsRef( b ); + return myButtons.contains( b ); } /*! - \return policy of button layouting. + \brief Get buttons layout policy. + \return policy of button layouting (Qtx::PlacePolicy) + \sa setPolicy() */ int QtxDialog::Area::policy() const { - return myPolicy; + return myPolicy; } /*! - Changes policy of button layouting. - \param p - new policy + \brief Set buttons layout policy. + \param p new policy */ void QtxDialog::Area::setPolicy( const int p ) { - if ( myPolicy == p ) - return; + if ( myPolicy == p ) + return; - myPolicy = p; - layoutButtons(); + myPolicy = p; + layoutButtons(); } /*! - \return true if border enabled + \brief Check of the border is enabled. + \return \c true if border is enabled + \sa setBorderEnabled(), setBorderWidget() */ bool QtxDialog::Area::isBorderEnabled() const { - return myLine && myBorder; + return myLine && myBorder; } /*! - Enables/disable separator between main frame and button frame - \param on - new state + \brief Enable/disable border (separator between main frame and button frame) + \param on new state */ void QtxDialog::Area::setBorderEnabled( const bool on ) { - if ( !myLine || myBorder == on ) - return; + if ( !myLine || myBorder == on ) + return; - myBorder = on; - updateBorder(); + myBorder = on; + updateBorder(); } /*! - Sets label as separator between main frame and button frame - \param line - new separator + \brief Set border widget (separator between main frame and button frame). + \param line new separator widget */ void QtxDialog::Area::setBorderWidget( QLabel* line ) { - if ( myLine == line ) - return; + if ( myLine == line ) + return; - delete myLine; - myLine = line; - updateBorder(); + delete myLine; + myLine = line; + updateBorder(); } /*! - \return const reference to list of buttons + \brief Get all area buttons. + \return const reference to the list of buttons */ -const QPtrList& QtxDialog::Area::buttons() const +const QList& QtxDialog::Area::buttons() const { - return myButtons; + return myButtons; } /*! - Updates visibility of border + \brief Update border visibility. */ void QtxDialog::Area::updateBorder() { - if ( !myLine ) - return; + if ( !myLine ) + return; - bool isVis = isVisibleTo( parentWidget() ); -#if QT_VER >= 3 - if ( isVis ) -#else - if ( isVis && myBorder ) -#endif - myLine->show(); - else - myLine->hide(); + bool isVis = isVisibleTo( parentWidget() ); + myLine->setVisible( isVis ); - myLine->setLineWidth( myBorder ? 1 : 0 ); + myLine->setLineWidth( myBorder ? 1 : 0 ); } /*! - Installs buttons into layout + \brief Layout buttons in the area. */ void QtxDialog::Area::layoutButtons() { - int aPolicy = policy(); - - QMap buttonId; - for ( QPtrListIterator it1( myButtons ); it1.current(); ++it1 ) - buttonId.insert( it1.current(), 0 ); - - QPtrList src; - for ( ButtonMap::Iterator mit = myDlg->myButton.begin(); - mit != myDlg->myButton.end(); ++mit ) - { - if ( buttonId.contains( mit.data() ) ) - { - buttonId[mit.data()] = mit.key(); - if ( mit.key() >= 0 ) - src.append( mit.data() ); - } - } - - for ( QPtrListIterator it2( myButtons ); it2.current(); ++it2 ) - if ( buttonId[it2.current()] < 0 ) - src.append( it2.current() ); - - QPtrList left, right, center, other; - for ( QPtrListIterator it( src ); it.current(); ++it ) - { - if ( !it.current()->isVisibleTo( this ) ) - continue; - - int aPosition = myDlg->buttonPosition( it.current() ); - if ( aPosition == -1 ) - continue; - - if ( aPolicy != QtxDialog::Position ) - other.append( it.current() ); - else if ( aPosition == QtxDialog::Left ) - left.append( it.current() ); - else if ( aPosition == QtxDialog::Right ) - right.append( it.current() ); - else if ( aPosition == QtxDialog::Center ) - center.append( it.current() ); - } + int aPolicy = policy(); + + QMap buttonId; + for ( QList::iterator it1 = myButtons.begin(); it1 != myButtons.end(); ++it1 ) + buttonId.insert( *it1, 0 ); + + QList src; + for ( ButtonMap::Iterator mit = myDlg->myButton.begin(); mit != myDlg->myButton.end(); ++mit ) + { + if ( buttonId.contains( mit.value() ) ) + { + buttonId[mit.value()] = mit.key(); + if ( mit.key() >= 0 ) + src.append( mit.value() ); + } + } + + for ( QList::iterator it2 = myButtons.begin(); it2 != myButtons.end(); ++it2 ) + { + if ( buttonId[*it2] < 0 ) + src.append( *it2 ); + } + + QList left, right, center, other; + for ( QList::iterator it = src.begin(); it != src.end(); ++it ) + { + if ( !(*it)->isVisibleTo( this ) ) + continue; + + int aPosition = myDlg->buttonPosition( *it ); + if ( aPosition == -1 ) + continue; + + if ( aPolicy != QtxDialog::Position ) + other.append( *it ); + else if ( aPosition == QtxDialog::Left ) + left.append( *it ); + else if ( aPosition == QtxDialog::Right ) + right.append( *it ); + else if ( aPosition == QtxDialog::Center ) + center.append( *it ); + } delete layout(); - QBoxLayout* buttonLayout = 0; - if ( myOrientation == Qt::Vertical ) - buttonLayout = new QVBoxLayout( this, 0, 5 ); - else - buttonLayout = new QHBoxLayout( this, 0, 5 ); - - if ( !buttonLayout ) - return; - - if ( aPolicy == QtxDialog::Position ) - { - for ( QPtrListIterator lit( left ); lit.current(); ++lit ) - buttonLayout->addWidget( lit.current() ); - buttonLayout->addStretch( 1 ); - for ( QPtrListIterator cit( center ); cit.current(); ++cit ) - buttonLayout->addWidget( cit.current() ); - buttonLayout->addStretch( 1 ); - for ( QPtrListIterator rit( right ); rit.current(); ++rit ) - buttonLayout->addWidget( rit.current() ); - } - else - { - for ( QPtrListIterator oit( other ); oit.current(); ++oit ) - { - buttonLayout->addWidget( oit.current() ); - if ( aPolicy == QtxDialog::Uniform && !oit.atLast() ) - buttonLayout->addStretch( 1 ); - } - } + QBoxLayout* buttonLayout = 0; + if ( myOrientation == Qt::Vertical ) + buttonLayout = new QVBoxLayout( this ); + else + buttonLayout = new QHBoxLayout( this ); + + if ( !buttonLayout ) + return; + + buttonLayout->setMargin( 0 ); + buttonLayout->setSpacing( 5 ); + + if ( aPolicy == QtxDialog::Position ) + { + for ( QList::iterator lit = left.begin(); lit != left.end(); ++lit ) + buttonLayout->addWidget( *lit ); + buttonLayout->addStretch( 1 ); + for ( QList::iterator cit = center.begin(); cit != center.end(); ++cit ) + buttonLayout->addWidget( *cit ); + buttonLayout->addStretch( 1 ); + for ( QList::iterator rit = right.begin(); rit != right.end(); ++rit ) + buttonLayout->addWidget( *rit ); + } + else + { + for ( int i = 0; i < (int)other.count(); i++ ) + { + buttonLayout->addWidget( other[i] ); + if ( aPolicy == QtxDialog::Uniform && i < (int)other.count() - 1 ) + buttonLayout->addStretch( 1 ); + } + } QWidgetList wids; if ( layout() ) { - for ( QLayoutIterator it = layout()->iterator(); it.current(); ++it ) + for ( int i = 0; i < layout()->count(); i++ ) { - if ( !it.current()->widget() ) + if ( !layout()->itemAt( i ) || layout()->itemAt( i )->widget() ) continue; - if ( QApplication::reverseLayout() ) - wids.prepend( it.current()->widget() ); + if ( QApplication::layoutDirection() == Qt::RightToLeft ) + wids.prepend( layout()->itemAt( i )->widget() ); else - wids.append( it.current()->widget() ); + wids.append( layout()->itemAt( i )->widget() ); } } Qtx::setTabOrder( wids ); @@ -332,40 +342,43 @@ void QtxDialog::Area::layoutButtons() /*! \class QtxDialog::Border - - Special label used as separator between main frame and button frame + \internal + \brief Special label used as border widget (separator + between main frame and button frame). */ + class QtxDialog::Border : public QLabel { public: - Border( QWidget* = 0 ); - virtual ~Border(); + Border( QWidget* = 0 ); + virtual ~Border(); - virtual void setLineWidth( int ); + virtual void setLineWidth( int ); - virtual QSize sizeHint() const; - virtual QSize minimumSizeHint() const; + virtual QSize sizeHint() const; + virtual QSize minimumSizeHint() const; }; /*! - Constructor + \brief Constructor. + \param parent parent widget */ QtxDialog::Border::Border( QWidget* parent ) : QLabel( parent ) { - setAlignment( Qt::AlignCenter ); + setAlignment( Qt::AlignCenter ); } /*! - Destructor + \brief Destructor. */ QtxDialog::Border::~Border() { } /*! - Set line width of separator - \param lw - new line width + \brief Set separator line width. + \param lw new line width */ void QtxDialog::Border::setLineWidth( int lw ) { @@ -378,511 +391,528 @@ void QtxDialog::Border::setLineWidth( int lw ) } /*! - \return the recommended size for the widget + \brief Get recommended size for the widget. + \return recommended size for the widget */ QSize QtxDialog::Border::sizeHint() const { QSize sz( 5, 5 ); -#if QT_VER >= 3 if ( lineWidth() > 0 ) - { + { if ( frameShape() == VLine ) sz += QSize( 5 + lineWidth(), 0 ); - else if ( frameShape() == HLine ) + else if ( frameShape() == HLine ) sz += QSize( 0, 5 + lineWidth() ); - } -#endif + } return sz; } /*! - \return the recommended minimum size for the widget + \brief Get recommended minimum size for the widget. + \return recommended minimum size for the widget */ QSize QtxDialog::Border::minimumSizeHint() const { - return sizeHint(); + return sizeHint(); } /*! - Constructor + \class QtxDialog + \brief Generic dialog box class. +*/ + +/*! + \brief Constructor. + Construct a dialog with specified parent and name. - \param modal define modal status of dialog (default non modal dialog created). - \param allowResize - if it is true then dialog can be resize by user (default non resizable dialog created). - \param Button flags specified control buttons for dialog (default buttons is OK, Cancel and Help). - \param Widget flags used as in any widget. -*/ -QtxDialog::QtxDialog( QWidget* parent, const char* name, - bool modal, bool allowResize, const int f, WFlags wf ) -: QDialog( parent, name, modal, - wf | WStyle_Customize | WStyle_Title | WStyle_SysMenu | + By default non-modal, non-resizable with the OK, Cancel and Help buttons + dialog box is created. + + \param parent parent widget + \param modal if \c true dialog box is modal + \param allowResize if \c true then dialog can be resized by user + \param f specified control buttons for dialog box (QtxDialog::ButtonFlags) + \param wf dialog box flags (Qt::WindowFlags) +*/ +QtxDialog::QtxDialog( QWidget* parent, bool modal, bool allowResize, const int f, Qt::WindowFlags wf ) +: QDialog( parent, (Qt::WindowFlags)( wf | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::Dialog | #ifdef WIN32 - ( allowResize ? WStyle_NormalBorder : WStyle_NoBorderEx ) | -#else - WStyle_NormalBorder | + ( allowResize ? 0 : Qt::FramelessWindowHint ) | #endif - ( allowResize ? WStyle_Maximize : 0 ) ), -mySender( 0 ), -myAlignment( 0 ), -myInited( false ), -myDialogFlags( Accept | SetFocus ) -{ - QVBoxLayout* base = new QVBoxLayout( this, 5, 0 ); - QtxGroupBox* main = new QtxGroupBox( 1, Qt::Horizontal, "", this ); - main->setFrameStyle( QFrame::NoFrame ); - main->setInsideMargin( 0 ); - main->setInsideSpacing( 0 ); - base->addWidget( main ); - - Area* topArea = new Area( Qt::Horizontal, this, main ); - QLabel* topLine = new Border( main ); - QtxGroupBox* midGroup = new QtxGroupBox( 1, Qt::Vertical, "", main ); - QLabel* botLine = new Border( main ); - Area* botArea = new Area( Qt::Horizontal, this, main ); - - midGroup->setFrameStyle( QFrame::NoFrame ); - midGroup->setInsideMargin( 0 ); - midGroup->setInsideSpacing( 0 ); - - Area* leftArea = new Area( Qt::Vertical, this, midGroup ); - QLabel* leftLine = new Border( midGroup ); - myMainFrame = new QFrame( midGroup ); - QLabel* rightLine = new Border( midGroup ); - Area* rightArea = new Area( Qt::Vertical, this, midGroup ); - - myMainFrame->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, - QSizePolicy::Expanding ) ); - - topLine->setFrameStyle( QFrame::Sunken | QFrame::HLine ); - botLine->setFrameStyle( QFrame::Sunken | QFrame::HLine ); - leftLine->setFrameStyle( QFrame::Sunken | QFrame::VLine ); - rightLine->setFrameStyle( QFrame::Sunken | QFrame::VLine ); - topArea->setBorderWidget( topLine ); - botArea->setBorderWidget( botLine ); - leftArea->setBorderWidget( leftLine ); - rightArea->setBorderWidget( rightLine ); - - myArea.insert( TopArea, topArea ); - myArea.insert( BottomArea, botArea ); - myArea.insert( LeftArea, leftArea ); - myArea.insert( RightArea, rightArea ); - - for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++ itr ) - itr.data()->setBorderEnabled( false ); - - myButton.insert( OK, new QPushButton( tr( "&OK" ), this ) ); - myButton.insert( Cancel, new QPushButton( tr( "&Cancel" ), this ) ); - myButton.insert( Close, new QPushButton( tr( "C&lose" ), this ) ); - myButton.insert( Help, new QPushButton( tr( "&Help" ), this ) ); - myButton.insert( Apply, new QPushButton( tr( "&Apply" ), this ) ); - myButton.insert( Yes, new QPushButton( tr( "&Yes" ), this ) ); - myButton.insert( No, new QPushButton( tr( "&No" ), this ) ); - - for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) - { - ((QPushButton*)it.data())->setAutoDefault( false ); -#if QT_VER >= 3 - connect( it.data(), SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); + ( ( allowResize +#ifdef WIN32 + // in qwidget_win.cpp flag WStyle_ContextHelp will be unset in WStyle_MinMax in switched ON + && !( wf & Qt::WindowContextHelpButtonHint ) #endif - } + ) ? Qt::WindowMaximizeButtonHint : 0 ) ) ), + myInited( false ), + mySender( 0 ), + myAlignment( 0 ), + myDialogFlags( Accept | SetFocus ) +{ + setModal( modal ); + + QVBoxLayout* base = new QVBoxLayout( this ); + base->setMargin( 5 ); + base->setSpacing( 0 ); + + QWidget* main = new QWidget( this ); + base->addWidget( main ); + + QVBoxLayout* lMain = new QVBoxLayout( main ); + lMain->setMargin( 0 ); + lMain->setSpacing( 0 ); + + Area* topArea = new Area( Qt::Horizontal, this, main ); + QLabel* topLine = new Border( main ); + lMain->addWidget( topArea ); + lMain->addWidget( topLine ); + + QWidget* midGroup = new QWidget( main ); + lMain->addWidget( midGroup ); + + QVBoxLayout* midLyout = new QVBoxLayout( midGroup ); + midLyout->setMargin( 0 ); + midLyout->setSpacing( 0 ); + + QLabel* botLine = new Border( main ); + Area* botArea = new Area( Qt::Horizontal, this, main ); + lMain->addWidget( botLine ); + lMain->addWidget( botArea ); + + Area* leftArea = new Area( Qt::Vertical, this, midGroup ); + QLabel* leftLine = new Border( midGroup ); + midLyout->addWidget( leftArea ); + midLyout->addWidget( leftLine ); + + myMainFrame = new QFrame( midGroup ); + midLyout->addWidget( myMainFrame ); + + QLabel* rightLine = new Border( midGroup ); + Area* rightArea = new Area( Qt::Vertical, this, midGroup ); + midLyout->addWidget( rightLine ); + midLyout->addWidget( rightArea ); + + myMainFrame->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); + + topLine->setFrameStyle( QFrame::Sunken | QFrame::HLine ); + botLine->setFrameStyle( QFrame::Sunken | QFrame::HLine ); + leftLine->setFrameStyle( QFrame::Sunken | QFrame::VLine ); + rightLine->setFrameStyle( QFrame::Sunken | QFrame::VLine ); + + topArea->setBorderWidget( topLine ); + botArea->setBorderWidget( botLine ); + leftArea->setBorderWidget( leftLine ); + rightArea->setBorderWidget( rightLine ); + + myArea.insert( TopArea, topArea ); + myArea.insert( BottomArea, botArea ); + myArea.insert( LeftArea, leftArea ); + myArea.insert( RightArea, rightArea ); + + for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++ itr ) + itr.value()->setBorderEnabled( false ); + + myButton.insert( OK, new QPushButton( tr( "&OK" ), this ) ); + myButton.insert( Cancel, new QPushButton( tr( "&Cancel" ), this ) ); + myButton.insert( Close, new QPushButton( tr( "C&lose" ), this ) ); + myButton.insert( Help, new QPushButton( tr( "&Help" ), this ) ); + myButton.insert( Apply, new QPushButton( tr( "&Apply" ), this ) ); + myButton.insert( Yes, new QPushButton( tr( "&Yes" ), this ) ); + myButton.insert( No, new QPushButton( tr( "&No" ), this ) ); + + for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) + { + ((QPushButton*)it.value())->setAutoDefault( false ); + connect( it.value(), SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); + } + + setButtonPosition( Left, OK | Cancel | Apply ); + setButtonPosition( Center, Yes | No | Close ); + setButtonPosition( Right, Help ); + setButtonPlace( BottomArea, All ); - setButtonPosition( Left, OK | Cancel | Apply ); - setButtonPosition( Center, Yes | No | Close ); - setButtonPosition( Right, Help ); - setButtonPlace( BottomArea, All ); + connect( myButton[Apply], SIGNAL( clicked() ), this, SIGNAL( dlgApply() ) ); + connect( myButton[Help], SIGNAL( clicked() ), this, SIGNAL( dlgHelp() ) ); - connect( myButton[Apply], SIGNAL( clicked() ), this, SIGNAL( dlgApply() ) ); - connect( myButton[Help], SIGNAL( clicked() ), this, SIGNAL( dlgHelp() ) ); + connect( myButton[OK], SIGNAL( clicked() ), this, SLOT( onAccept() ) ); + connect( myButton[Cancel], SIGNAL( clicked() ), this, SLOT( onReject() ) ); + connect( myButton[Yes], SIGNAL( clicked() ), this, SLOT( onAccept() ) ); + connect( myButton[No], SIGNAL( clicked() ), this, SLOT( onReject() ) ); + connect( myButton[Close], SIGNAL( clicked() ), this, SLOT( onReject() ) ); - connect( myButton[OK], SIGNAL( clicked() ), this, SLOT( onAccept() ) ); - connect( myButton[Cancel], SIGNAL( clicked() ), this, SLOT( onReject() ) ); - connect( myButton[Yes], SIGNAL( clicked() ), this, SLOT( onAccept() ) ); - connect( myButton[No], SIGNAL( clicked() ), this, SLOT( onReject() ) ); - connect( myButton[Close], SIGNAL( clicked() ), this, SLOT( onReject() ) ); + QIcon icon; + QWidget* p = parentWidget(); + while( p && p->parentWidget() ) + p = p->parentWidget(); - QPixmap icon; - if ( qApp && qApp->mainWidget() && qApp->mainWidget()->icon() ) - setIcon( *qApp->mainWidget()->icon() ); + if ( p ) + setWindowIcon( p->windowIcon() ); - myButtonFlags = f; + myButtonFlags = f; #ifndef WIN32 - if ( !allowResize ) - setMaximumSize( minimumSize() ); + if ( !allowResize ) + setMaximumSize( minimumSize() ); #endif - update(); + update(); } /*! - Name: ~QtxDialog [public] - Desc: Destructor + \brief Destructor. */ - QtxDialog::~QtxDialog() { } /*! - Name: setButtonFlags [public] - Desc: Allow to set specified control button(s) into dialog. + \brief Add specified control button(s) to the dialog box. + \param f ORed buttons flags (Qtx::ButtonFlags) + \sa clearButtonFlags(), testButtonFlags() */ - void QtxDialog::setButtonFlags( const int f ) { - int old = myButtonFlags; - myButtonFlags = myButtonFlags | f; - if ( old != myButtonFlags ) - update(); + int old = myButtonFlags; + myButtonFlags = myButtonFlags | f; + if ( old != myButtonFlags ) + update(); } /*! - Name: clearButtonFlags [public] - Desc: Allow to unset specified control button(s) from dialog. + \brief Remove specified control button(s) from the dialog box. + \param f ORed buttons flags (Qtx::ButtonFlags) + \sa setButtonFlags(), testButtonFlags() */ - void QtxDialog::clearButtonFlags( const int f ) { - int old = myButtonFlags; - myButtonFlags = myButtonFlags & ~f; - if ( old != myButtonFlags ) - update(); + int old = myButtonFlags; + myButtonFlags = myButtonFlags & ~f; + if ( old != myButtonFlags ) + update(); } /*! - Name: testButtonFlags [public] - Desc: Return true if specified control button is used in dialog. + \brief Test specified buttons. + \return \c true if specified control buttons are used in the dialog box + \sa setButtonFlags(), clearButtonFlags() */ - bool QtxDialog::testButtonFlags( const int f ) const { - return ( myButtonFlags & f ) == f; + return ( myButtonFlags & f ) == f; } /*! - Name: setDialogFlags [public] - Desc: Allow to set the dialog flags. - - Following flags can be used: - Accept - Allow to control dialog accepting. See also acceptData(). - Reject - Allow to control dialog rejecting. See also rejectData(). - AlignOnce - Allow to align dialog only when it first time shown. - SetFocus - Allow to set focus on dialog when it shown. User can use - setFocusProxy() and specify own initial focus widget. + \brief Set specified dialog box flags. + \param f dialog box flags (QtxDialog::DialogFlags) + \sa clearDialogFlags(), testDialogFlags(), acceptData(), rejectData() */ - void QtxDialog::setDialogFlags( const int f ) { - myDialogFlags = myDialogFlags | f; + myDialogFlags = myDialogFlags | f; } /*! - Name: clearDialogFlags [public] - Desc: Allow to clear the dialog flags. See also setDialogFlags(). + \brief Clear specified the dialog flags. + \param f dialog box flags (QtxDialog::DialogFlags) + \sa setDialogFlags(), testDialogFlags() */ - void QtxDialog::clearDialogFlags( const int f ) { - myDialogFlags = myDialogFlags & ~f; + myDialogFlags = myDialogFlags & ~f; } /*! - Name: testDialogFlags [public] - Desc: Returns true if specified dialog flag is setted (see setDialogFlags()). + \brief Test specified dialog flags. + \return \c true if specified dialog box falgs are set + \sa setDialogFlags(), clearDialogFlags() */ - bool QtxDialog::testDialogFlags( const int f ) const { - return ( myDialogFlags & f ) == f; + return ( myDialogFlags & f ) == f; } /*! - Name: mainFrame [public] - Desc: Returns main frame of dialog. Main frame should contains all - elements of dialog except control buttons. -*/ + \brief Get dialog box main frame widget. + + Main frame is an internal widget which should contains all + elements of dialog box except control buttons. + \return main frame widget +*/ QFrame* QtxDialog::mainFrame() const { - return myMainFrame; + return myMainFrame; } /*! - Name: buttonPosition [public] - Desc: Returns position of specified button. + \brief Get specified control button position + \param id control button ID (QtxDialog::ButtonFlags) + \return button's position (QtxDialog::ButtonPosition) or -1 if it is not set or invalid \a id is given + \sa setButtonPosition() */ - int QtxDialog::buttonPosition( const int id ) const { - int pos = -1; - if ( myPosition.contains( id ) ) - pos = myPosition[id]; - return pos; + int pos = -1; + if ( myPosition.contains( id ) ) + pos = myPosition[id]; + return pos; } - /*! - Name: setButtonPosition [public] - Desc: Sets the position for specified button(s). Following positions - may be used: Left, Right, Center, Top, Bottom. + \brief Set the specified control button(s) position. + \param id control button(s) ID (QtxDialog::ButtonFlags) + \param pos button(s) position (QtxDialog::ButtonPosition) */ - void QtxDialog::setButtonPosition( const int pos, const int id ) { - ButtonMap map = buttons( id ); + ButtonMap map = buttons( id ); - QMap changed; - for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) - { - if ( myPosition[it.key()] == pos ) - continue; + QMap changed; + for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) + { + if ( myPosition[it.key()] == pos ) + continue; - myPosition[it.key()] = pos; - if ( button( it.key() ) ) - changed.insert( button( it.key() )->parent(), 0 ); - } - - for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr ) - if ( changed.contains( itr.data() ) ) - itr.data()->layoutButtons(); + myPosition[it.key()] = pos; + if ( button( it.key() ) ) + changed.insert( button( it.key() )->parent(), 0 ); + } + + for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr ) + { + if ( changed.contains( itr.value() ) ) + itr.value()->layoutButtons(); + } } /*! - Name: setPlacePosition [public] - Desc: Sets button position for all buttons in given place. + \brief Set button position for all buttons in specified \a area. + \param pos button(s) position (QtxDialog::ButtonPosition) + \param area buttons area (QtxDialog::ButtonArea) + \sa setButtonPosition() */ - void QtxDialog::setPlacePosition( const int pos, const int area ) { - if ( !myArea.contains( area ) ) - return; + if ( !myArea.contains( area ) ) + return; - Area* anArea = myArea[area]; + Area* anArea = myArea[area]; - bool changed = false; - for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) - { - if ( !anArea->contains( it.data() ) ) - continue; + bool changed = false; + for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) + { + if ( !anArea->contains( it.value() ) ) + continue; - changed = changed && myPosition[it.key()] != pos; + changed = changed && myPosition[it.key()] != pos; - myPosition[it.key()] = pos; - } + myPosition[it.key()] = pos; + } - if ( changed ) - anArea->layoutButtons(); + if ( changed ) + anArea->layoutButtons(); } /*! - Name: placePolicy [public] - Desc: Returns policy of button layouting for specified place. - - Following place may be used: - TopArea - Horizontal area in the top side of dialog. - BottomArea - Horizontal area in the bottom side of dialog. - LeftArea - Vertical area in the left side of dialog. - RightArea - Vertical area in the right side of dialog. - - Following policy may be used: - Position - Buttons placed according their position. - Expand - Buttons fills all available space. - Uniform - Buttons uniformly placed in area. + \brief Get buttons layouting policy for the specified \a area. + \param area buttons area (QtxDialog::ButtonArea) + \sa setPlacePolicy() */ - int QtxDialog::placePolicy( const int area ) const { - int res = -1; - if ( myArea.contains( area ) ) - res = myArea[area]->policy(); - return res; + int res = -1; + if ( myArea.contains( area ) ) + res = myArea[area]->policy(); + return res; } /*! - Name: setPlacePolicy [public] - Desc: Sets the policy of button layouting for specified place. - See also placePolicy(). + \brief set buttons layouting policy for the specified \a area. + \param policy buttons layouting policy (QtxDialog::PlacePolicy) + \param area buttons area (QtxDialog::ButtonArea) + \sa placePolicy() */ - void QtxDialog::setPlacePolicy( const int policy, const int area ) { - if ( area < 0 ) - for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr ) - itr.data()->setPolicy( policy ); - else if ( myArea.contains( area ) ) - myArea[area]->setPolicy( policy ); + if ( area < 0 ) + { + for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr ) + itr.value()->setPolicy( policy ); + } + else if ( myArea.contains( area ) ) + myArea[area]->setPolicy( policy ); } /*! - Name: setButtonPlace [public] - Desc: Move given button(s) into specified place. + \brief Move specified button(s) into specified area. + \param area buttons area (QtxDialog::ButtonArea) + \param id control button(s) ID (QtxDialog::ButtonFlags) */ - -void QtxDialog::setButtonPlace( const int area, const int ids ) +void QtxDialog::setButtonPlace( const int area, const int id ) { - if ( !myArea.contains( area ) ) - return; + if ( !myArea.contains( area ) ) + return; - Area* anArea = myArea[area]; + Area* anArea = myArea[area]; + ButtonMap map = buttons( id ); + QMap areaMap; + for ( AreaMap::ConstIterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt ) + areaMap.insert( aIt.value(), 0 ); - ButtonMap map = buttons( ids ); - - QMap areaMap; - for ( AreaMap::ConstIterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt ) - areaMap.insert( aIt.data(), 0 ); - - for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) - { - Area* old = (Area*)it.data()->parent(); - if ( old == anArea ) - continue; + for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) + { + Area* old = (Area*)it.value()->parent(); + if ( old == anArea ) + continue; - if ( areaMap.contains( old ) ) - old->removeButton( it.data() ); - anArea->insertButton( it.data() ); - } + if ( areaMap.contains( old ) ) + old->removeButton( it.value() ); + anArea->insertButton( it.value() ); + } } /*! - Name: isBorderEnabled [public] - Desc: Returns true if border is shown for specified button area. + \brief Check if border is enabled. + \param area buttons area (QtxDialog::ButtonArea) + \return \c true if border is enabled for specified button area. + \sa setBorderEnabled() */ - bool QtxDialog::isBorderEnabled( const int area ) const { - bool res = false; - if ( myArea.contains( area ) ) - res = myArea[area]->isBorderEnabled(); - return res; + bool res = false; + if ( myArea.contains( area ) ) + res = myArea[area]->isBorderEnabled(); + return res; } /*! - Name: setBorderEnabled [public] - Desc: Show/hide border for specified button area. Border are - line which separate main frame and control buttons. -*/ + \brief Show/hide border for the specified button area. + Border is a line which separate main frame and control buttons. + + \param area buttons area (QtxDialog::ButtonArea) + \param on enable border flag + \sa isBorderEnabled() +*/ void QtxDialog::setBorderEnabled( const bool on, const int area ) { - if ( !myArea.contains( area ) ) - return; + if ( !myArea.contains( area ) ) + return; - if ( myArea[area]->isBorderEnabled() == on ) - return; + if ( myArea[area]->isBorderEnabled() == on ) + return; - myArea[area]->setBorderEnabled( on ); + myArea[area]->setBorderEnabled( on ); - if ( isVisible() ) - { - QApplication::sendPostedEvents(); - adjustSize(); - } + if ( isVisible() ) + { + QApplication::sendPostedEvents(); + adjustSize(); + } } /*! - Name: isButtonEnabled [public] - Desc: Returns true if all specified button(s) is enabled. + \brief Get "enabled" status of the specified button(s). + \param id control button(s) ID (QtxDialog::ButtonFlags) + \return \c true if all specified buttons are enabled. + \sa setButtonEnabled() */ - -bool QtxDialog::isButtonEnabled( const int f ) const +bool QtxDialog::isButtonEnabled( const int id ) const { - ButtonMap map = buttons( f ); - bool result = !map.isEmpty(); - for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) - result = result && it.data()->isEnabled(); - return result; + ButtonMap map = buttons( id ); + bool result = !map.isEmpty(); + for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) + result = result && it.value()->isEnabled(); + return result; } /*! - Name: setButtonEnabled [public] - Desc: Enable/disable specified button(s). + \brief Enable/disable specified button(s). + \param on enable button(s) flag + \param id control button(s) ID (QtxDialog::ButtonFlags) + \sa isButtonEnabled() */ - -void QtxDialog::setButtonEnabled( const bool on, const int ids ) +void QtxDialog::setButtonEnabled( const bool on, const int id ) { - ButtonMap map = buttons( ids ); - for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) - it.data()->setEnabled( on ); + ButtonMap map = buttons( id ); + for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it ) + it.value()->setEnabled( on ); } /*! - Name: hasButtonFocus [public] - Desc: Retruns true if specified button has keyboard focus. + \brief Check if specified button has keyboard focus. + \param id control button ID (QtxDialog::ButtonFlags) + \return \c true if specified button has keyboard focus + \sa setButtonFocus() */ - bool QtxDialog::hasButtonFocus( const int id ) const { - bool res = false; - QButton* pb = button( id ); - if ( pb ) - res = pb->hasFocus(); - return res; + bool res = false; + QAbstractButton* pb = button( id ); + if ( pb ) + res = pb->hasFocus(); + return res; } /*! - Name: setButtonFocus [public] - Desc: Sets the keyboard focus on specified button. + \brief Sets the keyboard focus to the specified button. + \param id control button ID (QtxDialog::ButtonFlags) + \sa hasButtonFocus() */ - void QtxDialog::setButtonFocus( const int id ) { - QButton* pb = button( id ); - if ( pb ) - pb->setFocus(); + QAbstractButton* pb = button( id ); + if ( pb ) + pb->setFocus(); } /*! - Name: buttonText [public] - Desc: Return text of specified button. + \brief Get specified button's text. + \param id control button ID (QtxDialog::ButtonFlags) + \return button's text + \sa setButtonText() */ - QString QtxDialog::buttonText( const int id ) { - QString retval; - QButton* but = button( id ); - if ( but ) - retval = but->text(); - return retval; + QString retval; + QAbstractButton* but = button( id ); + if ( but ) + retval = but->text(); + return retval; } /*! - Name: setButtonText [public] - Desc: Sets text to specified button. + \brief Set specified button's text. + \param id control button ID (QtxDialog::ButtonFlags) + \param text button's text + \sa buttonText() */ - void QtxDialog::setButtonText( const int id, const QString& text ) { - QButton* but = button( id ); - if ( but && but->text() != text ) - { - but->setText( text ); - adjustButtons(); - } -} - -/*! - Name: setAlignment [public] - Desc: Sets alignment policy. Returns the previous alignment. - Use the function before the first show of the dialog. - If dialog flag AlignOnce is setted then align will performed - only one time otherwise dialog will be aligned every time - when it shown. Dialog will be aligned relative to it parent. - - Following align flags may be used: - Qtx::AlignAuto - Align to center of desktop (default). - Qtx::AlignLeft - Align left side of dialog to left side of parent. - Qtx::AlignRight - Align right side of dialog to right side of parent. - Qtx::AlignTop - Align top side of dialog to top side of parent. - Qtx::AlignBottom - Align bottom side of dialog to bottom side of parent. - Qtx::AlignHCenter - Align dialog to center of parent in horizontal dimension. - Qtx::AlignVCenter - Align dialog to center of parent in vertical dimension. - Qtx::AlignCenter - Align dialog to center of parent in both dimensions. - Qtx::AlignOutLeft - Align right side of dialog to left side of parent. - Qtx::AlignOutRight - Align left side of dialog to right side of parent. - Qtx::AlignOutTop - Align bottom side of dialog to top side of parent. - Qtx::AlignOutBottom - Align top side of dialog to bottom side of parent. -*/ + QAbstractButton* but = button( id ); + if ( but && but->text() != text ) + { + but->setText( text ); + adjustButtons(); + } +} +/*! + \brief Sets alignment policy. + + Use the function before the the dialog is first time shown. + If dialog flag AlignOnce is set then alignment is performed + only once, otherwise the dialog is aligned each time when it + is shown. + Dialog box is aligned relatively to its parent. + By default, dialog box is aligned to the center of the parent + widget (usually desktop or another dialog box). + + \param align alignment flag(s) (Qtx::AlignmentFlags) + \return previous alignment policy +*/ uint QtxDialog::setAlignment( uint align ) { uint oldAlign = myAlignment; @@ -891,498 +921,561 @@ uint QtxDialog::setAlignment( uint align ) } /*! - Name: update [virtual public slot] - Desc: Updates dialog, show selected buttons and hide unselected. + \brief Update dialog box. */ - void QtxDialog::update() { - for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) - if ( it.key() >= 0 ) - testButtonFlags( it.key() ) ? it.data()->show() : it.data()->hide(); + for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) + if ( it.key() >= 0 ) + it.value()->setVisible( testButtonFlags( it.key() ) ); - for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr ) - itr.data()->layoutButtons(); + for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr ) + itr.value()->layoutButtons(); - adjustButtons(); + adjustButtons(); - QDialog::update(); + QDialog::update(); } /*! - Name: show [virtual public] - Desc: Show dialog, set keyboard focus on dialog. + \brief Show/hide dialog box, set keyboard focus to the dialog. + + Re-implemented from Qt. + + \param on show/hide flag */ - -void QtxDialog::show() +void QtxDialog::setVisible( bool on ) { - QDialog::show(); - - if ( testDialogFlags( SetFocus ) ) - setFocus(); + QDialog::setVisible( on ); - myInited = true; + if ( on ) + { + if ( testDialogFlags( SetFocus ) ) + setFocus(); + myInited = true; + } + else + QApplication::instance()->processEvents(); } /*! - Name: hide [virtual public] - Desc: Hides dialog, processed all posted events. + \brief Get user button by the specified \a id. + \param id user button ID + \return user button or 0 if it is not found + \sa insertButton(), removeButton(), userButtonIds() */ - -void QtxDialog::hide() +QAbstractButton* QtxDialog::userButton( const int id ) const { - QDialog::hide(); - qApp->processEvents(); + QAbstractButton* b = 0; + if ( id < -1 && myButton.contains( id ) ) + b = myButton[id]; + return b; } /*! - Name: userButton [public] - Desc: Return user dialog button using specified identificator. + \brief Get all user button IDs. + \return list of user buttons identificators + \sa insertButton(), removeButton(), userButton() */ - -QButton* QtxDialog::userButton( const int id ) const +QIntList QtxDialog::userButtonIds() const { - QButton* b = 0; - if ( id < -1 && myButton.contains( id ) ) - b = myButton[id]; - return b; + QIntList retlist; + for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it ) + if ( it.key() < 0 ) + retlist.append( it.key() ); + return retlist; } /*! - Name: userButtonIds [public] - Desc: Return list of user dialog button identificators. -*/ + \brief Add user button to the dialog box. -QValueList QtxDialog::userButtonIds() const -{ - QValueList retlist; - for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it ) - if ( it.key() < 0 ) - retlist.append( it.key() ); - return retlist; -} + The button is inserted to the specified dialog box area. + if the button is added successfully, the unique identificator of + the added button is returned, otherwise -1 is returned. -/*! - Name: insertButton [public] - Desc: Add new user dialog button. Function return identificator of - newly added button in successfull case otherwise -1 will be returned. + \param text text of the added button + \param area buttons area (QtxDialog::ButtonArea) + \return button ID + \sa removeButton(), userButton(), userButtonIds() */ - int QtxDialog::insertButton( const QString& text, const int area ) { - if ( !myArea.contains( area ) ) - return -1; - - int id = -2; - while ( myButton.contains( id ) ) - id--; + if ( !myArea.contains( area ) ) + return -1; - Area* anArea = myArea[area]; - QButton* b = createButton( this ); - if ( b ) - { - b->setText( text ); - myButton.insert( id, b ); - myPosition.insert( id, Left ); + int id = -2; + while ( myButton.contains( id ) ) + id--; - connect( b, SIGNAL( clicked() ), this, SLOT( onButton() ) ); -#if QT_VER >= 3 - connect( b, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); -#endif + Area* anArea = myArea[area]; + QAbstractButton* b = createButton( this ); + if ( b ) + { + b->setText( text ); + myButton.insert( id, b ); + myPosition.insert( id, Left ); + + connect( b, SIGNAL( clicked() ), this, SLOT( onButton() ) ); + connect( b, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) ); - anArea->insertButton( b ); - update(); - } - else - id = -1; + anArea->insertButton( b ); + update(); + } + else + id = -1; - return id; + return id; } /*! - Name: removeButton [public] - Desc: Remove user dialog button with specified identificator. If - identificator equal -1 then method will remove all user dialog buttons. -*/ + \brief Remove user button. + + If \c id is -1, all user buttons are removed. + \param id user button ID + \sa insertButton(), userButton(), userButtonIds() +*/ void QtxDialog::removeButton( const int id ) { - if ( id >= 0 ) - return; - - ButtonMap map; - if ( id == -1 ) - { - for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) - { - if ( it.key() < 0 ) - map.insert( it.key(), it.data() ); - } - } - else if ( myButton.contains( id ) ) - map.insert( id, myButton[id] ); - - for ( ButtonMap::Iterator itr = map.begin(); itr != map.end(); ++itr ) - { - for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it ) - it.data()->removeButton( itr.data() ); - - myButton.remove( itr.key() ); - myPosition.remove( itr.key() ); - - delete itr.data(); - } - update(); + if ( id >= 0 ) + return; + + ButtonMap map; + if ( id == -1 ) + { + for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it ) + { + if ( it.key() < 0 ) + map.insert( it.key(), it.value() ); + } + } + else if ( myButton.contains( id ) ) + map.insert( id, myButton[id] ); + + for ( ButtonMap::Iterator itr = map.begin(); itr != map.end(); ++itr ) + { + for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it ) + it.value()->removeButton( itr.value() ); + + myButton.remove( itr.key() ); + myPosition.remove( itr.key() ); + + delete itr.value(); + } + update(); } /*! - Name: setUnits [static public] - Desc: Sets specified measure units in given label. Measure units close - in braces. If measure units not exist then they will be added. - For example: - 1. Label contains text 'Radius'. - setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm)' - setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm)' - 2. Label "aLabel" contains text 'Radius ():'. - setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm):' - setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm):' -*/ + \brief Set measure units to the specified label. + + In the dialog box label the measure units are closed in braces. + If measure units do not exist they will be added. + + For example: + \code + // create label "Radius" + QLabel* aLabel = new QLabel( "Radius", mainFrame() ); + // set measure units to "mm" + setUnits( aLabel, "mm" ) // => aLabel contains 'Radius (mm)' + // set measure units to "cm" + setUnits( aLabel, "cm" ) // => aLabel contains 'Radius (cm)' + + // create label "Radius" with initially not set measure units + QLabel* aLabel = new QLabel( "Radius ():", mainFrame() ); + // set measure units to "mm" + setUnits( aLabel, "mm" ) // => aLabel contains 'Radius (mm):' + // set measure units to "cm" + setUnits( aLabel, "cm" ) // => aLabel contains 'Radius (cm):' + \endcode + \param aLabel label widget + \param aUnits measure units +*/ void QtxDialog::setUnits( QLabel* aLabel, const QString& aUnits ) { - QString label = aLabel->text(); - int begin; - int end = label.findRev( ')' ); - - QString startLabel = label; - QString finalLabel; - - if ( end != -1 ) - { - begin = label.left( end ).findRev( '(' ); - if ( begin != -1 ) - { - startLabel = label.mid( 0, begin ); - finalLabel = label.mid( end + 1 ); - } - } - else - { - startLabel = startLabel.stripWhiteSpace(); - if ( startLabel.at( startLabel.length() - 1 ) == ':' ) - { - finalLabel = startLabel.mid( startLabel.length() - 1 ); - startLabel = startLabel.mid( 0, startLabel.length() - 1 ); - } - } - if ( aUnits.length() ) - label = startLabel.stripWhiteSpace() + - " (" + aUnits + ") " + finalLabel.stripWhiteSpace(); - else - label = startLabel.stripWhiteSpace() + - " " + finalLabel.stripWhiteSpace(); - aLabel->setText( label ); -} - -/*! - Name: acceptData [virtual protected] - Desc: If returns true dialog will be accepted and closed. This method - called if dialog flag Accept is setted. -*/ + QString label = aLabel->text(); + + int begin; + int end = label.lastIndexOf( ')' ); + + QString startLabel = label; + QString finalLabel; + + if ( end != -1 ) + { + begin = label.left( end ).lastIndexOf( '(' ); + if ( begin != -1 ) + { + startLabel = label.mid( 0, begin ); + finalLabel = label.mid( end + 1 ); + } + } + else + { + startLabel = startLabel.trimmed(); + if ( startLabel.at( startLabel.length() - 1 ) == ':' ) + { + finalLabel = startLabel.mid( startLabel.length() - 1 ); + startLabel = startLabel.mid( 0, startLabel.length() - 1 ); + } + } + if ( aUnits.length() ) + label = startLabel.trimmed() + " (" + aUnits + ") " + finalLabel.trimmed(); + else + label = startLabel.trimmed() + " " + finalLabel.trimmed(); + aLabel->setText( label ); +} + +/*! + \brief Check if data entered by the user is valid. + + This method can be re-implemented in the successor class if it + requires to check user input consistency. + Default implementation returns \c true. + This method is called if dialog flag QtxDialog::Accept is set. + If this method returns \c true, then dialog will be accepted and closed. + + \return \c true if user input is valid + \sa accept() +*/ bool QtxDialog::acceptData() const { return true; } /*! - Name: rejectData [virtual protected] - Desc: If returns true dialog will be rejected and closed. This method - called if dialog flag Reject is setted. -*/ + \brief Check if dialog box can be cancelled. + + This method can be re-implemented in the successor class if it + requires to check possibility to cancel dialog box safely. + Default implementation returns \c true. + This method is called if dialog flag QtxDialog::Reject is set. + If this method returns \c true, then dialog will be rejected and closed. + + \return \c true if dialog box can be cancelled + \sa reject() +*/ bool QtxDialog::rejectData() const { - return true; + return true; } /*! - Name: createButton [virtual protected] - Desc: Create new user button. Invoked from method "insertButton". -*/ + \brief Create new user button. + + This method is invoked from method insertButton(). -QButton* QtxDialog::createButton( QWidget* parent ) + \param parent parent widget + \return new user button +*/ +QAbstractButton* QtxDialog::createButton( QWidget* parent ) { - QPushButton* pb = new QPushButton( parent ); - pb->setAutoDefault( false ); - return pb; + QPushButton* pb = new QPushButton( parent ); + pb->setAutoDefault( false ); + return pb; } /*! - Name: button [protected] - Desc: Return pointer on control button specified by identifier. - If identifier is wrong then null pointer will returned. + \brief Get button by the specified ID. + \param f control button ID (QtxDialog::ButtonFlags) + \return button or 0 if \a id is invalid */ - -QButton* QtxDialog::button( const int f ) const +QAbstractButton* QtxDialog::button( const int f ) const { - QButton* retval = 0; - if ( myButton.contains( f ) ) - retval = myButton[f]; - return retval; + QAbstractButton* retval = 0; + if ( myButton.contains( f ) ) + retval = myButton[f]; + return retval; } /*! - Name: buttons [protected] - Desc: Return map with control dialog buttons accordance to given button flags. + \brief Get buttons by the specified IDs. + \param f control button(s) ID(s) (QtxDialog::ButtonFlags) + \return button map */ - QtxDialog::ButtonMap QtxDialog::buttons( const int f ) const { - ButtonMap retmap; - if ( f < -1 ) - { - if ( myButton.contains( f ) ) - retmap.insert( f, myButton[f] ); - } - else - { - for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it ) - if ( f == -1 || ( it.key() >= 0 && f & it.key() ) ) - retmap.insert( it.key(), it.data() ); - } - - return retmap; + ButtonMap retmap; + if ( f < -1 ) + { + if ( myButton.contains( f ) ) + retmap.insert( f, myButton[f] ); + } + else + { + for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it ) + if ( f == -1 || ( it.key() >= 0 && f & it.key() ) ) + retmap.insert( it.key(), it.value() ); + } + return retmap; } /*! - Name: buttonId [protected] - Desc: Return identifier of specified button. + \brief Get specified button's identifier. + \param b button + \return button ID */ - -int QtxDialog::buttonId( const QButton* b ) const +int QtxDialog::buttonId( const QAbstractButton* b ) const { - int id = -1; - for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end() && id == -1; ++it ) - if ( it.data() == b ) - id = it.key(); - return id; + int id = -1; + for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end() && id == -1; ++it ) + if ( it.value() == b ) + id = it.key(); + return id; } /*! - Name: buttonPosition - Desc: Returns position of specified button. [protected] + \brief Get position of specified button. + \param b button + \return button position (QtxDialog::ButtonPosition) */ - -int QtxDialog::buttonPosition( QButton* b ) const +int QtxDialog::buttonPosition( QAbstractButton* b ) const { - return buttonPosition( buttonId( b ) ); + return buttonPosition( buttonId( b ) ); } /*! - Name: showEvent [virtual protected] - Desc: Aligns this dialog according the parent widget and alignment - policy before the show. -*/ + \brief Align this dialog according to the parent widget and alignment + policy before the dialog box is shown. + + Re-implemented from Qt. + \param e show event +*/ void QtxDialog::showEvent( QShowEvent* e ) { - if ( !testDialogFlags( AlignOnce ) || !myInited ) - Qtx::alignWidget( this, parentWidget(), myAlignment ); - QDialog::showEvent( e ); + if ( !testDialogFlags( AlignOnce ) || !myInited ) + Qtx::alignWidget( this, parentWidget(), myAlignment ); + QDialog::showEvent( e ); } /*! - Name: hideEvent [virtual protected] - Desc: Process all existing events when dialog is closed. -*/ + \brief Process all existing events when dialog box is hidden. + Re-implemented from Qt. + + \param e hide event +*/ void QtxDialog::hideEvent( QHideEvent* e ) { - qApp->processEvents(); - QDialog::hideEvent( e ); + QApplication::instance()->processEvents(); + QDialog::hideEvent( e ); } /*! - Name: childEvent [virtual protected] - Desc: Setting up layout when size grip is added. -*/ + \brief Update dialog box layout when the size grip is added. + + Re-implemented from Qt. + \param e child event +*/ void QtxDialog::childEvent( QChildEvent* e ) { - QDialog::childEvent( e ); - if ( layout() && e->inserted() && e->child()->inherits( "QSizeGrip" ) ) - { - layout()->setMargin( 12 ); -#if QT_VER >= 3 - connect( e->child(), SIGNAL( destroyed() ), this, SLOT( onSizeGripDestroyed() ) ); -#endif - } + QDialog::childEvent( e ); + if ( layout() && e->added() && e->child()->inherits( "QSizeGrip" ) ) + { + layout()->setMargin( 12 ); + connect( e->child(), SIGNAL( destroyed() ), this, SLOT( onSizeGripDestroyed() ) ); + } } /*! - Name: keyPressEvent [virtual protected] - Desc: Calls reject() if key Escape is pressed. - Calls accept() if key "Ctrl+Enter" is pressed. - Process key "F1" and emit signal dlgHelp(). - Transfer key "Ctrl+(Shift+)Tab" press event to Tab Widget. -*/ + \brief Process key pressing event. + Re-implemented from Qt. + + Call reject() if "Escape" key is pressed. + Call accept() if "Ctrl+Enter" key-sequence is pressed. + Process "F1" key and emit signal dlgHelp(). + Transfer "Ctrl+(Shift+)Tab" key-sequence press event + to the child Tab widget (if there is any). + + \param e key press event +*/ void QtxDialog::keyPressEvent( QKeyEvent* e ) { - QDialog::keyPressEvent( e ); - if ( e->isAccepted() ) - return; + QDialog::keyPressEvent( e ); - if ( ( e->state() == 0 ) && ( e->key() == Key_Escape ) ) - reject(); + if ( e->isAccepted() ) + return; - if ( ( e->state() == ControlButton ) && ( e->key() == Key_Return ) ) - { - if ( testButtonFlags( OK ) || testButtonFlags( Yes ) ) - accept(); - else if ( testButtonFlags( Apply ) && isButtonEnabled( Apply ) ) - emit dlgApply(); - e->accept(); - } + if ( !e->modifiers() && e->key() == Qt::Key_Escape ) + reject(); - if ( e->key() == Key_F1 && testButtonFlags( Help ) && isButtonEnabled( Help ) ) - { - e->accept(); - emit dlgHelp(); - } + if ( e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Return ) + { + if ( testButtonFlags( OK ) || testButtonFlags( Yes ) ) + accept(); + else if ( testButtonFlags( Apply ) && isButtonEnabled( Apply ) ) + emit dlgApply(); + e->accept(); + } - if ( ( e->key() == Key_Tab ) && ( e->state() & ControlButton ) ) - { - QObject* tab = child( 0, "QTabWidget" ); - if ( tab ) - tab->event( e ); - } + if ( e->key() == Qt::Key_F1 && testButtonFlags( Help ) && isButtonEnabled( Help ) ) + { + e->accept(); + emit dlgHelp(); + } + + if ( e->key() == Qt::Key_Tab && e->modifiers() & Qt::ControlModifier ) + { + QObject* tab = qFindChild( this ); + if ( tab ) + QApplication::sendEvent( tab, e ); + } } /*! - Name: closeEvent [virtual protected] - Desc: Reject the dialog. + \brief Called when user closes dialog box. + + Call reject() method. + + \param e close event (not used) */ - -void QtxDialog::closeEvent( QCloseEvent* ) +void QtxDialog::closeEvent( QCloseEvent* /*e*/ ) { - reject(); + reject(); } /*! - Name: accept [virtual protected slot] - Desc: Invoke function acceptData() if it needed and if acceptData() return - false does nothing. Otherwise hides the dialog and sets the result code - to Accepted. Emit signal according to the pressed control button. -*/ + \brief Accept the dialog box. + + This method is used when any accept button is pressed (usually + "OK", "Yes", etc). + If dialog flag QtxDialog::Accept is set, this function invokes + acceptData() method, which should in this case return \c true to + allow further processing. + + If acceptData() returns \c false, this function just returns. + + If acceptData() returns \c true, the Accepted result is set + and signal according to the pressed control button is emitted. + Then the default implementation of accept() method is called + (which hides the dialog box and, depending on the dialog box flags, + can close and destroy it). + + \sa acceptData() +*/ void QtxDialog::accept() { - if ( !mySender ) - { - if ( testButtonFlags( OK ) ) - mySender = button( OK ); - else if ( testButtonFlags( Yes ) ) - mySender = button( Yes ); - else - mySender = button( Close ); - } + if ( !mySender ) + { + if ( testButtonFlags( OK ) ) + mySender = button( OK ); + else if ( testButtonFlags( Yes ) ) + mySender = button( Yes ); + else + mySender = button( Close ); + } if ( !mySender || !mySender->isWidgetType() || !((QWidget*)mySender)->isEnabled() ) - return; + return; - if ( testDialogFlags( Accept ) && !acceptData() ) - return; + if ( testDialogFlags( Accept ) && !acceptData() ) + return; - QDialog::accept(); + QDialog::accept(); - emitSignal(); + emitSignal(); } /*! - Name: reject [virtual protected slot] - Desc: Invoke function rejectData() if it needed and if rejectData() return - false does nothing. Otherwise hides the dialog and sets the result code - to Rejected. Emit signal according to the pressed control button. (If - dialog was closed by key Escape or by close event emit signal dlgCancel(), - or dlgClose(), or dlgNo(). -*/ + \brief Reject the dialog box. + + This method is used when any reject button is pressed (usually + "Close", "Cancel", "No", etc). + If dialog flag QtxDialog::Reject is set, this function invokes + rejectData() method, which should in this case return \c true to + allow further processing. + + If rejectData() returns \c false, this function just returns. + + If rejectData() returns \c true, the Rejected result is set + and signal according to the pressed control button is emitted. + Then the default implementation of reject() method is called + (which hides the dialog box and, depending on the dialog box flags, + can close and destroy it). + + \sa rejectData() +*/ void QtxDialog::reject() { - if ( testDialogFlags( Reject ) && !rejectData() ) - return; + if ( testDialogFlags( Reject ) && !rejectData() ) + return; - if ( !mySender ) - { - if ( testButtonFlags( Cancel ) ) - mySender = button( Cancel ); - else if ( testButtonFlags( No ) ) - mySender = button( No ); - else - mySender = button( Close ); - } + if ( !mySender ) + { + if ( testButtonFlags( Cancel ) ) + mySender = button( Cancel ); + else if ( testButtonFlags( No ) ) + mySender = button( No ); + else + mySender = button( Close ); + } - if ( !mySender || !mySender->isWidgetType() || - !((QWidget*)mySender)->isEnabled() ) - return; + if ( !mySender || !mySender->isWidgetType() || + !((QWidget*)mySender)->isEnabled() ) + return; - QDialog::reject(); + QDialog::reject(); - emitSignal(); + emitSignal(); } /*! - Name: reject [private] - Desc: Emit signal appropriate to control button. + \brief Emit signal correspondingly to the control button. */ - void QtxDialog::emitSignal() { - qApp->processEvents(); - QApplication::syncX(); + QApplication::instance()->processEvents(); + QApplication::syncX(); - int id = buttonId( (QButton*)mySender ); - mySender = 0; + int id = buttonId( (QAbstractButton*)mySender ); + mySender = 0; - switch ( id ) - { - case OK: - emit dlgOk(); - break; - case Cancel: - emit dlgCancel(); - break; - case Close: - emit dlgClose(); - break; - case Yes: - emit dlgYes(); - break; - case No: - emit dlgNo(); - break; - } + switch ( id ) + { + case OK: + emit dlgOk(); + break; + case Cancel: + emit dlgCancel(); + break; + case Close: + emit dlgClose(); + break; + case Yes: + emit dlgYes(); + break; + case No: + emit dlgNo(); + break; + } } /*! - Name: onAccept [private slot] - Desc: Process signals "clicked()" from control buttons "OK", "Yes". Invoke accept(). -*/ + \brief This slot is called when user presses on of the buttons + "OK", "Yes", etc. + Call accept() method. +*/ void QtxDialog::onAccept() { - const QObject* obj = sender(); - mySender = obj; - accept(); + const QObject* obj = sender(); + mySender = obj; + accept(); } /*! - Name: onReject [private slot] - Desc: Process signals "clicked()" from control buttons "Cancel", "No", "Close". - Invoke reject(). + \brief This slot is called when user presses on of the buttons + "Cancel", "No", "Close". + + Call reject() method. */ void QtxDialog::onReject() @@ -1393,62 +1486,64 @@ void QtxDialog::onReject() } /*! - Name: onButton [private slot] - Desc: Receive signal "clicked()" from user buttons and emit signal - "dlgButton( int )" with identificator of clicked user button. + \brief Process user button click event. + + This method is called when user presses one of custom user buttons. + Emits signal dlgButton(int) with identificator of the clicked user + button passed as parameter. */ - void QtxDialog::onButton() { - int id = buttonId( (QButton*)sender() ); - if ( id != -1 ) - emit dlgButton( id ); + int id = buttonId( (QAbstractButton*)sender() ); + if ( id != -1 ) + emit dlgButton( id ); } /*! - Name: onDestroyed [private slot] - Desc: Remove user button if it was destroyed. + \brief Watch for the user button destroying. + \param obj button being destroyed */ - void QtxDialog::onDestroyed( QObject* obj ) { - QButton* b = (QButton*)obj; - int id = buttonId( b ); - if ( id == -1 ) - return; + QAbstractButton* b = (QAbstractButton*)obj; + int id = buttonId( b ); + if ( id == -1 ) + return; - myButton.remove( id ); - myPosition.remove( id ); - for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it ) - it.data()->removeButton( b ); + myButton.remove( id ); + myPosition.remove( id ); + for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it ) + it.value()->removeButton( b ); } /*! - Name: onSizeGripDestroyed [private slot] - Desc: Setting up layout when size grip is destroyed. + \brief Update dialog box layout when the size grip is destroyed. */ - void QtxDialog::onSizeGripDestroyed() { - if ( layout() ) - layout()->setMargin( 5 ); + if ( layout() ) + layout()->setMargin( 5 ); } /*! - Name: adjustButtons [private] - Desc: Setting the equal with for all buttons. + \brief Adjust buttons (set equal size for all buttons). */ - void QtxDialog::adjustButtons() { - int minWidth = 0; - for ( AreaMap::Iterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt ) - for ( QPtrListIterator bIt( aIt.data()->buttons() ); bIt.current(); ++bIt ) - if ( bIt.current()->isVisibleTo( this ) ) - minWidth = QMAX( minWidth, bIt.current()->sizeHint().width() ); + int minWidth = 0; + for ( AreaMap::Iterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt ) + { + const QList& lst = aIt.value()->buttons(); + for ( QList::const_iterator bIt = lst.begin(); bIt != lst.end(); ++bIt ) + if ( (*bIt)->isVisibleTo( this ) ) + minWidth = qMax( minWidth, (*bIt)->sizeHint().width() ); + } - for ( AreaMap::Iterator aItr = myArea.begin(); aItr != myArea.end(); ++aItr ) - for ( QPtrListIterator bItr( aItr.data()->buttons() ); bItr.current(); ++bItr ) - if ( bItr.current()->isVisibleTo( this ) ) - bItr.current()->setMinimumWidth( minWidth ); + for ( AreaMap::Iterator aItr = myArea.begin(); aItr != myArea.end(); ++aItr ) + { + const QList& lst = aItr.value()->buttons(); + for ( QList::const_iterator bItr = lst.begin(); bItr != lst.end(); ++bItr ) + if ( (*bItr)->isVisibleTo( this ) ) + (*bItr)->setMinimumWidth( minWidth ); + } } diff --git a/src/Qtx/QtxDialog.h b/src/Qtx/QtxDialog.h index dbf4fbd9d..7eda0cce8 100755 --- a/src/Qtx/QtxDialog.h +++ b/src/Qtx/QtxDialog.h @@ -1,17 +1,17 @@ // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com @@ -24,13 +24,14 @@ #include "Qtx.h" -#include -#include -#include +#include +#include + +#include class QFrame; class QLabel; -class QButton; +class QAbstractButton; #ifdef WIN32 #pragma warning( disable:4251 ) @@ -38,149 +39,163 @@ class QButton; class QTX_EXPORT QtxDialog : public QDialog { - Q_OBJECT + Q_OBJECT - class Area; - class Border; + class Area; + class Border; public: - typedef enum { Position, Expand, Uniform } PlacePolicy; - typedef enum { TopArea, BottomArea, LeftArea, RightArea } ButtonArea; - typedef enum { Left, Right, Center, Top = Left, Bottom = Right } ButtonPosition; - - typedef enum { None = 0x00000000, - OK = 0x00000001, - Apply = 0x00000002, - Cancel = 0x00000004, - Yes = 0x00000008, - No = 0x00000010, - Close = 0x00000020, - Help = 0x00000040, - OKCancel = OK | Cancel, - YesNo = Yes | No, - Standard = OK | Cancel | Help, - All = Standard | YesNo | Apply | Close } ButtonFlags; - - typedef enum { Accept = 0x000001, - Reject = 0x000002, - AlignOnce = 0x000004, - SetFocus = 0x000008 } DialogFlags; - + //! Buttons alignment type + typedef enum { Position, //!< buttons are placed according their position + Expand, //!< buttons occupy all available space + Uniform //!< buttons are uniformly placed in the area + } PlacePolicy; + //! Buttons area + typedef enum { TopArea, //!< horizontal area at the top side of the dialog box + BottomArea, //!< horizontal area at the bottom side of the dialog box + LeftArea, //!< vertical area at the left side of the dialog box + RightArea //!< vertical area at the right side of the dialog box + } ButtonArea; + //! Button position + typedef enum { Left, //!< set button left-most + Right, //!< set button right-most + Center, //!< place button in the center + Top = Left, //!< set button top-most + Bottom = Right //!< set button bottom-most + } ButtonPosition; + //! Button ID flags + typedef enum { None = 0x00000000, //!< no button used + OK = 0x00000001, //!< OK button + Apply = 0x00000002, //!< Apply button + Cancel = 0x00000004, //!< Cancel button + Yes = 0x00000008, //!< Yes button + No = 0x00000010, //!< No button + Close = 0x00000020, //!< Close button + Help = 0x00000040, //!< Help button + OKCancel = OK | Cancel, //!< OK & Cancel button + YesNo = Yes | No, //!< Yes & No buttons + Standard = OK | Cancel | Help, //!< OK, Cancel & Help buttons + All = Standard | YesNo | Apply | Close //!< all buttons + } ButtonFlags; + //! Dialog box flags + typedef enum { Accept = 0x000001, //!< allow dialog box accepting control + Reject = 0x000002, //!< allow dialog box rejecting control + AlignOnce = 0x000004, //!< align dialog box only when it is first time shown + SetFocus = 0x000008 //!< allow to set focus on dialog box when it is shown (user can use setFocusProxy() and specify own initial focus widget) + } DialogFlags; + public: - QtxDialog( QWidget* = 0, const char* = 0, bool = false, - bool = false, const int = Standard, WFlags = 0 ); - virtual ~QtxDialog(); - - void setDialogFlags( const int ); - void clearDialogFlags( const int ); - bool testDialogFlags( const int ) const; - - void setButtonFlags( const int ); - void clearButtonFlags( const int ); - bool testButtonFlags( const int ) const; - - int buttonPosition( const int ) const; - void setButtonPosition( const int, const int = -1 ); - void setPlacePosition( const int, const int ); - - int placePolicy( const int ) const; - void setPlacePolicy( const int, const int ); - void setButtonPlace( const int, const int ); - - QString buttonText( const int ); - void setButtonText( const int, const QString& text ); - - void setButtonFocus( const int ); - bool hasButtonFocus( const int ) const; - - bool isButtonEnabled( const int ) const; - void setButtonEnabled( const bool, const int ); - - bool isBorderEnabled( const int ) const; - void setBorderEnabled( const bool, const int ); - - void removeButton( const int ); - int insertButton( const QString&, const int = BottomArea ); - - QValueList userButtonIds() const; - QButton* userButton( const int ) const; - - virtual void show(); - virtual void hide(); - - uint setAlignment( uint align ); - static void setUnits( QLabel*, const QString& ); - -signals: - void dlgButton( int ); - void dlgParamChanged(); - - void dlgHelp(); - void dlgApply(); - - void dlgOk(); - void dlgNo(); - void dlgYes(); - void dlgClose(); - void dlgCancel(); - -public slots: - void update(); - -protected slots: - virtual void accept(); - virtual void reject(); - -private slots: - void onAccept(); - void onReject(); - void onButton(); - void onSizeGripDestroyed(); - void onDestroyed( QObject* ); + QtxDialog( QWidget* = 0, bool = false, bool = false, const int = Standard, Qt::WindowFlags = 0 ); + virtual ~QtxDialog(); + + void setDialogFlags( const int ); + void clearDialogFlags( const int ); + bool testDialogFlags( const int ) const; + + void setButtonFlags( const int ); + void clearButtonFlags( const int ); + bool testButtonFlags( const int ) const; + + int buttonPosition( const int ) const; + void setButtonPosition( const int, const int = -1 ); + void setPlacePosition( const int, const int ); + + int placePolicy( const int ) const; + void setPlacePolicy( const int, const int ); + void setButtonPlace( const int, const int ); + + QString buttonText( const int ); + void setButtonText( const int, const QString& text ); + + void setButtonFocus( const int ); + bool hasButtonFocus( const int ) const; + + bool isButtonEnabled( const int ) const; + void setButtonEnabled( const bool, const int ); + + bool isBorderEnabled( const int ) const; + void setBorderEnabled( const bool, const int ); + + void removeButton( const int ); + int insertButton( const QString&, const int = BottomArea ); + + QIntList userButtonIds() const; + QAbstractButton* userButton( const int ) const; + + uint setAlignment( uint align ); + static void setUnits( QLabel*, const QString& ); + +Q_SIGNALS: + void dlgButton( int ); + void dlgParamChanged(); + + void dlgHelp(); + void dlgApply(); + + void dlgOk(); + void dlgNo(); + void dlgYes(); + void dlgClose(); + void dlgCancel(); + +public Q_SLOTS: + void update(); + virtual void setVisible( bool ); + +protected Q_SLOTS: + virtual void accept(); + virtual void reject(); + +private Q_SLOTS: + void onAccept(); + void onReject(); + void onButton(); + void onSizeGripDestroyed(); + void onDestroyed( QObject* ); protected: - typedef QMap ButtonMap; + typedef QMap ButtonMap; //!< button map protected: - QFrame* mainFrame() const; - - virtual bool acceptData() const; - virtual bool rejectData() const; - - virtual QButton* createButton( QWidget* ); - - QButton* button( const int ) const; - ButtonMap buttons( const int = All ) const; - int buttonId( const QButton* ) const; - int buttonPosition( QButton* ) const; - - virtual void showEvent( QShowEvent* ); - virtual void hideEvent( QHideEvent* ); - virtual void closeEvent( QCloseEvent* ); - virtual void childEvent( QChildEvent* ); - virtual void keyPressEvent( QKeyEvent* ); - + QFrame* mainFrame() const; + + virtual bool acceptData() const; + virtual bool rejectData() const; + + virtual QAbstractButton* createButton( QWidget* ); + + QAbstractButton* button( const int ) const; + ButtonMap buttons( const int = All ) const; + int buttonId( const QAbstractButton* ) const; + int buttonPosition( QAbstractButton* ) const; + + virtual void showEvent( QShowEvent* ); + virtual void hideEvent( QHideEvent* ); + virtual void closeEvent( QCloseEvent* ); + virtual void childEvent( QChildEvent* ); + virtual void keyPressEvent( QKeyEvent* ); + private: - void adjustButtons(); - void emitSignal(); - + void adjustButtons(); + void emitSignal(); + private: - typedef QMap AreaMap; - typedef QMap PositionMap; - - friend class Area; + typedef QMap AreaMap; //!< button area map + typedef QMap PositionMap; //!< button position map + + friend class Area; private: - AreaMap myArea; - ButtonMap myButton; - PositionMap myPosition; - - bool myInited; - const QObject* mySender; - uint myAlignment; - QFrame* myMainFrame; - int myButtonFlags; - int myDialogFlags; + AreaMap myArea; //!< buttons areas map + ButtonMap myButton; //!< buttons map + PositionMap myPosition; //!< buttons position map + + bool myInited; //!< dialog's "initialized" flag + const QObject* mySender; //!< signal sender + uint myAlignment; //!< dialog box alignment type + QFrame* myMainFrame; //!< main frame + int myButtonFlags; //!< button flags + int myDialogFlags; //!< dialog flags }; #ifdef WIN32