1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File: QtxDialog.cxx
20 // Author: Sergey TELKOV
22 #include "QtxDialog.h"
24 #include "QtxGroupBox.h"
29 #include <qpushbutton.h>
30 #include <qapplication.h>
33 Class: QtxDialog::Area
36 class QtxDialog::Area : public QFrame
39 Area( Orientation, QtxDialog*, QWidget* = 0 );
42 bool isBorderEnabled() const;
43 void setBorderEnabled( const bool );
45 void setBorderWidget( QLabel* );
47 void insertButton( QButton* );
48 void removeButton( QButton* );
49 bool contains( QButton* ) const;
52 void setPolicy( const int );
56 const QPtrList<QButton>& buttons() const;
66 QPtrList<QButton> myButtons;
67 Orientation myOrientation;
73 QtxDialog::Area::Area( Orientation o, QtxDialog* dlg, QWidget* parent )
81 if ( myOrientation == Qt::Horizontal )
82 setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) );
84 setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) );
92 QtxDialog::Area::~Area()
97 Inserts button to area
100 void QtxDialog::Area::insertButton( QButton* b )
102 if ( !b || myButtons.findRef( b ) != -1 )
105 QWidget* parent = b->parentWidget();
106 if ( parent != this )
107 b->reparent( this, 0, QPoint( 0, 0 ), b->isVisibleTo( parent ) );
109 myButtons.append( b );
112 myDlg->adjustButtons();
121 Removes button from area
124 void QtxDialog::Area::removeButton( QButton* b )
129 myButtons.removeRef( b );
131 if ( myButtons.isEmpty() )
137 myDlg->adjustButtons();
143 \return true if area contains button
146 bool QtxDialog::Area::contains( QButton* b ) const
148 return myButtons.containsRef( b );
152 \return policy of button layouting.
154 int QtxDialog::Area::policy() const
160 Changes policy of button layouting.
161 \param p - new policy
163 void QtxDialog::Area::setPolicy( const int p )
173 \return true if border enabled
175 bool QtxDialog::Area::isBorderEnabled() const
177 return myLine && myBorder;
181 Enables/disable separator between main frame and button frame
182 \param on - new state
184 void QtxDialog::Area::setBorderEnabled( const bool on )
186 if ( !myLine || myBorder == on )
194 Sets label as separator between main frame and button frame
195 \param line - new separator
197 void QtxDialog::Area::setBorderWidget( QLabel* line )
199 if ( myLine == line )
208 \return const reference to list of buttons
210 const QPtrList<QButton>& QtxDialog::Area::buttons() const
216 Updates visibility of border
218 void QtxDialog::Area::updateBorder()
223 bool isVis = isVisibleTo( parentWidget() );
227 if ( isVis && myBorder )
233 myLine->setLineWidth( myBorder ? 1 : 0 );
237 Installs buttons into layout
239 void QtxDialog::Area::layoutButtons()
241 int aPolicy = policy();
243 QMap<QButton*, int> buttonId;
244 for ( QPtrListIterator<QButton> it1( myButtons ); it1.current(); ++it1 )
245 buttonId.insert( it1.current(), 0 );
247 QPtrList<QButton> src;
248 for ( ButtonMap::Iterator mit = myDlg->myButton.begin();
249 mit != myDlg->myButton.end(); ++mit )
251 if ( buttonId.contains( mit.data() ) )
253 buttonId[mit.data()] = mit.key();
254 if ( mit.key() >= 0 )
255 src.append( mit.data() );
259 for ( QPtrListIterator<QButton> it2( myButtons ); it2.current(); ++it2 )
260 if ( buttonId[it2.current()] < 0 )
261 src.append( it2.current() );
263 QPtrList<QButton> left, right, center, other;
264 for ( QPtrListIterator<QButton> it( src ); it.current(); ++it )
266 if ( !it.current()->isVisibleTo( this ) )
269 int aPosition = myDlg->buttonPosition( it.current() );
270 if ( aPosition == -1 )
273 if ( aPolicy != QtxDialog::Position )
274 other.append( it.current() );
275 else if ( aPosition == QtxDialog::Left )
276 left.append( it.current() );
277 else if ( aPosition == QtxDialog::Right )
278 right.append( it.current() );
279 else if ( aPosition == QtxDialog::Center )
280 center.append( it.current() );
285 QBoxLayout* buttonLayout = 0;
286 if ( myOrientation == Qt::Vertical )
287 buttonLayout = new QVBoxLayout( this, 0, 5 );
289 buttonLayout = new QHBoxLayout( this, 0, 5 );
294 if ( aPolicy == QtxDialog::Position )
296 for ( QPtrListIterator<QButton> lit( left ); lit.current(); ++lit )
297 buttonLayout->addWidget( lit.current() );
298 buttonLayout->addStretch( 1 );
299 for ( QPtrListIterator<QButton> cit( center ); cit.current(); ++cit )
300 buttonLayout->addWidget( cit.current() );
301 buttonLayout->addStretch( 1 );
302 for ( QPtrListIterator<QButton> rit( right ); rit.current(); ++rit )
303 buttonLayout->addWidget( rit.current() );
307 for ( QPtrListIterator<QButton> oit( other ); oit.current(); ++oit )
309 buttonLayout->addWidget( oit.current() );
310 if ( aPolicy == QtxDialog::Uniform && !oit.atLast() )
311 buttonLayout->addStretch( 1 );
318 for ( QLayoutIterator it = layout()->iterator(); it.current(); ++it )
320 if ( !it.current()->widget() )
323 if ( QApplication::reverseLayout() )
324 wids.prepend( it.current()->widget() );
326 wids.append( it.current()->widget() );
329 Qtx::setTabOrder( wids );
334 \class QtxDialog::Border
336 Special label used as separator between main frame and button frame
338 class QtxDialog::Border : public QLabel
341 Border( QWidget* = 0 );
344 virtual void setLineWidth( int );
346 virtual QSize sizeHint() const;
347 virtual QSize minimumSizeHint() const;
353 QtxDialog::Border::Border( QWidget* parent )
356 setAlignment( Qt::AlignCenter );
362 QtxDialog::Border::~Border()
367 Set line width of separator
368 \param lw - new line width
370 void QtxDialog::Border::setLineWidth( int lw )
372 bool isOn = lineWidth() > 0;
374 QLabel::setLineWidth( lw );
376 if ( isOn != ( lineWidth() > 0 ) )
381 \return the recommended size for the widget
383 QSize QtxDialog::Border::sizeHint() const
388 if ( lineWidth() > 0 )
390 if ( frameShape() == VLine )
391 sz += QSize( 5 + lineWidth(), 0 );
392 else if ( frameShape() == HLine )
393 sz += QSize( 0, 5 + lineWidth() );
401 \return the recommended minimum size for the widget
403 QSize QtxDialog::Border::minimumSizeHint() const
410 Construct a dialog with specified parent and name.
411 \param modal define modal status of dialog (default non modal dialog created).
412 \param allowResize - if it is true then dialog can be resize by user (default non resizable dialog created).
413 \param Button flags specified control buttons for dialog (default buttons is OK, Cancel and Help).
414 \param Widget flags used as in any widget.
416 QtxDialog::QtxDialog( QWidget* parent, const char* name,
417 bool modal, bool allowResize, const int f, WFlags wf )
418 : QDialog( parent, name, modal,
419 wf | WStyle_Customize | WStyle_Title | WStyle_SysMenu |
421 ( allowResize ? WStyle_NormalBorder : WStyle_NoBorderEx ) |
423 WStyle_NormalBorder |
425 ( allowResize ? WStyle_Maximize : 0 ) ),
429 myDialogFlags( Accept | SetFocus )
431 QVBoxLayout* base = new QVBoxLayout( this, 5, 0 );
432 QtxGroupBox* main = new QtxGroupBox( 1, Qt::Horizontal, "", this );
433 main->setFrameStyle( QFrame::NoFrame );
434 main->setInsideMargin( 0 );
435 main->setInsideSpacing( 0 );
436 base->addWidget( main );
438 Area* topArea = new Area( Qt::Horizontal, this, main );
439 QLabel* topLine = new Border( main );
440 QtxGroupBox* midGroup = new QtxGroupBox( 1, Qt::Vertical, "", main );
441 QLabel* botLine = new Border( main );
442 Area* botArea = new Area( Qt::Horizontal, this, main );
444 midGroup->setFrameStyle( QFrame::NoFrame );
445 midGroup->setInsideMargin( 0 );
446 midGroup->setInsideSpacing( 0 );
448 Area* leftArea = new Area( Qt::Vertical, this, midGroup );
449 QLabel* leftLine = new Border( midGroup );
450 myMainFrame = new QFrame( midGroup );
451 QLabel* rightLine = new Border( midGroup );
452 Area* rightArea = new Area( Qt::Vertical, this, midGroup );
454 myMainFrame->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,
455 QSizePolicy::Expanding ) );
457 topLine->setFrameStyle( QFrame::Sunken | QFrame::HLine );
458 botLine->setFrameStyle( QFrame::Sunken | QFrame::HLine );
459 leftLine->setFrameStyle( QFrame::Sunken | QFrame::VLine );
460 rightLine->setFrameStyle( QFrame::Sunken | QFrame::VLine );
461 topArea->setBorderWidget( topLine );
462 botArea->setBorderWidget( botLine );
463 leftArea->setBorderWidget( leftLine );
464 rightArea->setBorderWidget( rightLine );
466 myArea.insert( TopArea, topArea );
467 myArea.insert( BottomArea, botArea );
468 myArea.insert( LeftArea, leftArea );
469 myArea.insert( RightArea, rightArea );
471 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++ itr )
472 itr.data()->setBorderEnabled( false );
474 myButton.insert( OK, new QPushButton( tr( "&OK" ), this ) );
475 myButton.insert( Cancel, new QPushButton( tr( "&Cancel" ), this ) );
476 myButton.insert( Close, new QPushButton( tr( "C&lose" ), this ) );
477 myButton.insert( Help, new QPushButton( tr( "&Help" ), this ) );
478 myButton.insert( Apply, new QPushButton( tr( "&Apply" ), this ) );
479 myButton.insert( Yes, new QPushButton( tr( "&Yes" ), this ) );
480 myButton.insert( No, new QPushButton( tr( "&No" ), this ) );
482 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
484 ((QPushButton*)it.data())->setAutoDefault( false );
486 connect( it.data(), SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
490 setButtonPosition( Left, OK | Cancel | Apply );
491 setButtonPosition( Center, Yes | No | Close );
492 setButtonPosition( Right, Help );
493 setButtonPlace( BottomArea, All );
495 connect( myButton[Apply], SIGNAL( clicked() ), this, SIGNAL( dlgApply() ) );
496 connect( myButton[Help], SIGNAL( clicked() ), this, SIGNAL( dlgHelp() ) );
498 connect( myButton[OK], SIGNAL( clicked() ), this, SLOT( onAccept() ) );
499 connect( myButton[Cancel], SIGNAL( clicked() ), this, SLOT( onReject() ) );
500 connect( myButton[Yes], SIGNAL( clicked() ), this, SLOT( onAccept() ) );
501 connect( myButton[No], SIGNAL( clicked() ), this, SLOT( onReject() ) );
502 connect( myButton[Close], SIGNAL( clicked() ), this, SLOT( onReject() ) );
505 if ( qApp && qApp->mainWidget() && qApp->mainWidget()->icon() )
506 setIcon( *qApp->mainWidget()->icon() );
512 setMaximumSize( minimumSize() );
519 Name: ~QtxDialog [public]
523 QtxDialog::~QtxDialog()
528 Name: setButtonFlags [public]
529 Desc: Allow to set specified control button(s) into dialog.
532 void QtxDialog::setButtonFlags( const int f )
534 int old = myButtonFlags;
535 myButtonFlags = myButtonFlags | f;
536 if ( old != myButtonFlags )
541 Name: clearButtonFlags [public]
542 Desc: Allow to unset specified control button(s) from dialog.
545 void QtxDialog::clearButtonFlags( const int f )
547 int old = myButtonFlags;
548 myButtonFlags = myButtonFlags & ~f;
549 if ( old != myButtonFlags )
554 Name: testButtonFlags [public]
555 Desc: Return true if specified control button is used in dialog.
558 bool QtxDialog::testButtonFlags( const int f ) const
560 return ( myButtonFlags & f ) == f;
564 Name: setDialogFlags [public]
565 Desc: Allow to set the dialog flags.
567 Following flags can be used:
568 Accept - Allow to control dialog accepting. See also acceptData().
569 Reject - Allow to control dialog rejecting. See also rejectData().
570 AlignOnce - Allow to align dialog only when it first time shown.
571 SetFocus - Allow to set focus on dialog when it shown. User can use
572 setFocusProxy() and specify own initial focus widget.
575 void QtxDialog::setDialogFlags( const int f )
577 myDialogFlags = myDialogFlags | f;
581 Name: clearDialogFlags [public]
582 Desc: Allow to clear the dialog flags. See also setDialogFlags().
585 void QtxDialog::clearDialogFlags( const int f )
587 myDialogFlags = myDialogFlags & ~f;
591 Name: testDialogFlags [public]
592 Desc: Returns true if specified dialog flag is setted (see setDialogFlags()).
595 bool QtxDialog::testDialogFlags( const int f ) const
597 return ( myDialogFlags & f ) == f;
601 Name: mainFrame [public]
602 Desc: Returns main frame of dialog. Main frame should contains all
603 elements of dialog except control buttons.
606 QFrame* QtxDialog::mainFrame() const
612 Name: buttonPosition [public]
613 Desc: Returns position of specified button.
616 int QtxDialog::buttonPosition( const int id ) const
619 if ( myPosition.contains( id ) )
620 pos = myPosition[id];
625 Name: setButtonPosition [public]
626 Desc: Sets the position for specified button(s). Following positions
627 may be used: Left, Right, Center, Top, Bottom.
630 void QtxDialog::setButtonPosition( const int pos, const int id )
632 ButtonMap map = buttons( id );
634 QMap<QObject*, int> changed;
635 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
637 if ( myPosition[it.key()] == pos )
640 myPosition[it.key()] = pos;
641 if ( button( it.key() ) )
642 changed.insert( button( it.key() )->parent(), 0 );
645 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
646 if ( changed.contains( itr.data() ) )
647 itr.data()->layoutButtons();
651 Name: setPlacePosition [public]
652 Desc: Sets button position for all buttons in given place.
655 void QtxDialog::setPlacePosition( const int pos, const int area )
657 if ( !myArea.contains( area ) )
660 Area* anArea = myArea[area];
662 bool changed = false;
663 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
665 if ( !anArea->contains( it.data() ) )
668 changed = changed && myPosition[it.key()] != pos;
670 myPosition[it.key()] = pos;
674 anArea->layoutButtons();
678 Name: placePolicy [public]
679 Desc: Returns policy of button layouting for specified place.
681 Following place may be used:
682 TopArea - Horizontal area in the top side of dialog.
683 BottomArea - Horizontal area in the bottom side of dialog.
684 LeftArea - Vertical area in the left side of dialog.
685 RightArea - Vertical area in the right side of dialog.
687 Following policy may be used:
688 Position - Buttons placed according their position.
689 Expand - Buttons fills all available space.
690 Uniform - Buttons uniformly placed in area.
693 int QtxDialog::placePolicy( const int area ) const
696 if ( myArea.contains( area ) )
697 res = myArea[area]->policy();
702 Name: setPlacePolicy [public]
703 Desc: Sets the policy of button layouting for specified place.
704 See also placePolicy().
707 void QtxDialog::setPlacePolicy( const int policy, const int area )
710 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
711 itr.data()->setPolicy( policy );
712 else if ( myArea.contains( area ) )
713 myArea[area]->setPolicy( policy );
717 Name: setButtonPlace [public]
718 Desc: Move given button(s) into specified place.
721 void QtxDialog::setButtonPlace( const int area, const int ids )
723 if ( !myArea.contains( area ) )
726 Area* anArea = myArea[area];
728 ButtonMap map = buttons( ids );
730 QMap<Area*, int> areaMap;
731 for ( AreaMap::ConstIterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt )
732 areaMap.insert( aIt.data(), 0 );
734 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
736 Area* old = (Area*)it.data()->parent();
740 if ( areaMap.contains( old ) )
741 old->removeButton( it.data() );
742 anArea->insertButton( it.data() );
747 Name: isBorderEnabled [public]
748 Desc: Returns true if border is shown for specified button area.
751 bool QtxDialog::isBorderEnabled( const int area ) const
754 if ( myArea.contains( area ) )
755 res = myArea[area]->isBorderEnabled();
760 Name: setBorderEnabled [public]
761 Desc: Show/hide border for specified button area. Border are
762 line which separate main frame and control buttons.
765 void QtxDialog::setBorderEnabled( const bool on, const int area )
767 if ( !myArea.contains( area ) )
770 if ( myArea[area]->isBorderEnabled() == on )
773 myArea[area]->setBorderEnabled( on );
777 QApplication::sendPostedEvents();
783 Name: isButtonEnabled [public]
784 Desc: Returns true if all specified button(s) is enabled.
787 bool QtxDialog::isButtonEnabled( const int f ) const
789 ButtonMap map = buttons( f );
790 bool result = !map.isEmpty();
791 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
792 result = result && it.data()->isEnabled();
797 Name: setButtonEnabled [public]
798 Desc: Enable/disable specified button(s).
801 void QtxDialog::setButtonEnabled( const bool on, const int ids )
803 ButtonMap map = buttons( ids );
804 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
805 it.data()->setEnabled( on );
809 Name: hasButtonFocus [public]
810 Desc: Retruns true if specified button has keyboard focus.
813 bool QtxDialog::hasButtonFocus( const int id ) const
816 QButton* pb = button( id );
818 res = pb->hasFocus();
823 Name: setButtonFocus [public]
824 Desc: Sets the keyboard focus on specified button.
827 void QtxDialog::setButtonFocus( const int id )
829 QButton* pb = button( id );
835 Name: buttonText [public]
836 Desc: Return text of specified button.
839 QString QtxDialog::buttonText( const int id )
842 QButton* but = button( id );
844 retval = but->text();
849 Name: setButtonText [public]
850 Desc: Sets text to specified button.
853 void QtxDialog::setButtonText( const int id, const QString& text )
855 QButton* but = button( id );
856 if ( but && but->text() != text )
858 but->setText( text );
864 Name: setAlignment [public]
865 Desc: Sets alignment policy. Returns the previous alignment.
866 Use the function before the first show of the dialog.
867 If dialog flag AlignOnce is setted then align will performed
868 only one time otherwise dialog will be aligned every time
869 when it shown. Dialog will be aligned relative to it parent.
871 Following align flags may be used:
872 Qtx::AlignAuto - Align to center of desktop (default).
873 Qtx::AlignLeft - Align left side of dialog to left side of parent.
874 Qtx::AlignRight - Align right side of dialog to right side of parent.
875 Qtx::AlignTop - Align top side of dialog to top side of parent.
876 Qtx::AlignBottom - Align bottom side of dialog to bottom side of parent.
877 Qtx::AlignHCenter - Align dialog to center of parent in horizontal dimension.
878 Qtx::AlignVCenter - Align dialog to center of parent in vertical dimension.
879 Qtx::AlignCenter - Align dialog to center of parent in both dimensions.
880 Qtx::AlignOutLeft - Align right side of dialog to left side of parent.
881 Qtx::AlignOutRight - Align left side of dialog to right side of parent.
882 Qtx::AlignOutTop - Align bottom side of dialog to top side of parent.
883 Qtx::AlignOutBottom - Align top side of dialog to bottom side of parent.
886 uint QtxDialog::setAlignment( uint align )
888 uint oldAlign = myAlignment;
894 Name: update [virtual public slot]
895 Desc: Updates dialog, show selected buttons and hide unselected.
898 void QtxDialog::update()
900 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
902 testButtonFlags( it.key() ) ? it.data()->show() : it.data()->hide();
904 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
905 itr.data()->layoutButtons();
913 Name: show [virtual public]
914 Desc: Show dialog, set keyboard focus on dialog.
917 void QtxDialog::show()
921 if ( testDialogFlags( SetFocus ) )
928 Name: hide [virtual public]
929 Desc: Hides dialog, processed all posted events.
932 void QtxDialog::hide()
935 qApp->processEvents();
939 Name: userButton [public]
940 Desc: Return user dialog button using specified identificator.
943 QButton* QtxDialog::userButton( const int id ) const
946 if ( id < -1 && myButton.contains( id ) )
952 Name: userButtonIds [public]
953 Desc: Return list of user dialog button identificators.
956 QValueList<int> QtxDialog::userButtonIds() const
958 QValueList<int> retlist;
959 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it )
961 retlist.append( it.key() );
966 Name: insertButton [public]
967 Desc: Add new user dialog button. Function return identificator of
968 newly added button in successfull case otherwise -1 will be returned.
971 int QtxDialog::insertButton( const QString& text, const int area )
973 if ( !myArea.contains( area ) )
977 while ( myButton.contains( id ) )
980 Area* anArea = myArea[area];
981 QButton* b = createButton( this );
985 myButton.insert( id, b );
986 myPosition.insert( id, Left );
988 connect( b, SIGNAL( clicked() ), this, SLOT( onButton() ) );
990 connect( b, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
993 anArea->insertButton( b );
1003 Name: removeButton [public]
1004 Desc: Remove user dialog button with specified identificator. If
1005 identificator equal -1 then method will remove all user dialog buttons.
1008 void QtxDialog::removeButton( const int id )
1016 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
1019 map.insert( it.key(), it.data() );
1022 else if ( myButton.contains( id ) )
1023 map.insert( id, myButton[id] );
1025 for ( ButtonMap::Iterator itr = map.begin(); itr != map.end(); ++itr )
1027 for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it )
1028 it.data()->removeButton( itr.data() );
1030 myButton.remove( itr.key() );
1031 myPosition.remove( itr.key() );
1039 Name: setUnits [static public]
1040 Desc: Sets specified measure units in given label. Measure units close
1041 in braces. If measure units not exist then they will be added.
1043 1. Label contains text 'Radius'.
1044 setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm)'
1045 setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm)'
1046 2. Label "aLabel" contains text 'Radius ():'.
1047 setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm):'
1048 setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm):'
1051 void QtxDialog::setUnits( QLabel* aLabel, const QString& aUnits )
1053 QString label = aLabel->text();
1055 int end = label.findRev( ')' );
1057 QString startLabel = label;
1062 begin = label.left( end ).findRev( '(' );
1065 startLabel = label.mid( 0, begin );
1066 finalLabel = label.mid( end + 1 );
1071 startLabel = startLabel.stripWhiteSpace();
1072 if ( startLabel.at( startLabel.length() - 1 ) == ':' )
1074 finalLabel = startLabel.mid( startLabel.length() - 1 );
1075 startLabel = startLabel.mid( 0, startLabel.length() - 1 );
1078 if ( aUnits.length() )
1079 label = startLabel.stripWhiteSpace() +
1080 " (" + aUnits + ") " + finalLabel.stripWhiteSpace();
1082 label = startLabel.stripWhiteSpace() +
1083 " " + finalLabel.stripWhiteSpace();
1084 aLabel->setText( label );
1088 Name: acceptData [virtual protected]
1089 Desc: If returns true dialog will be accepted and closed. This method
1090 called if dialog flag Accept is setted.
1093 bool QtxDialog::acceptData() const
1099 Name: rejectData [virtual protected]
1100 Desc: If returns true dialog will be rejected and closed. This method
1101 called if dialog flag Reject is setted.
1104 bool QtxDialog::rejectData() const
1110 Name: createButton [virtual protected]
1111 Desc: Create new user button. Invoked from method "insertButton".
1114 QButton* QtxDialog::createButton( QWidget* parent )
1116 QPushButton* pb = new QPushButton( parent );
1117 pb->setAutoDefault( false );
1122 Name: button [protected]
1123 Desc: Return pointer on control button specified by identifier.
1124 If identifier is wrong then null pointer will returned.
1127 QButton* QtxDialog::button( const int f ) const
1129 QButton* retval = 0;
1130 if ( myButton.contains( f ) )
1131 retval = myButton[f];
1136 Name: buttons [protected]
1137 Desc: Return map with control dialog buttons accordance to given button flags.
1140 QtxDialog::ButtonMap QtxDialog::buttons( const int f ) const
1145 if ( myButton.contains( f ) )
1146 retmap.insert( f, myButton[f] );
1150 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it )
1151 if ( f == -1 || ( it.key() >= 0 && f & it.key() ) )
1152 retmap.insert( it.key(), it.data() );
1159 Name: buttonId [protected]
1160 Desc: Return identifier of specified button.
1163 int QtxDialog::buttonId( const QButton* b ) const
1166 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end() && id == -1; ++it )
1167 if ( it.data() == b )
1173 Name: buttonPosition
1174 Desc: Returns position of specified button. [protected]
1177 int QtxDialog::buttonPosition( QButton* b ) const
1179 return buttonPosition( buttonId( b ) );
1183 Name: showEvent [virtual protected]
1184 Desc: Aligns this dialog according the parent widget and alignment
1185 policy before the show.
1188 void QtxDialog::showEvent( QShowEvent* e )
1190 if ( !testDialogFlags( AlignOnce ) || !myInited )
1191 Qtx::alignWidget( this, parentWidget(), myAlignment );
1192 QDialog::showEvent( e );
1196 Name: hideEvent [virtual protected]
1197 Desc: Process all existing events when dialog is closed.
1200 void QtxDialog::hideEvent( QHideEvent* e )
1202 qApp->processEvents();
1203 QDialog::hideEvent( e );
1207 Name: childEvent [virtual protected]
1208 Desc: Setting up layout when size grip is added.
1211 void QtxDialog::childEvent( QChildEvent* e )
1213 QDialog::childEvent( e );
1214 if ( layout() && e->inserted() && e->child()->inherits( "QSizeGrip" ) )
1216 layout()->setMargin( 12 );
1218 connect( e->child(), SIGNAL( destroyed() ), this, SLOT( onSizeGripDestroyed() ) );
1224 Name: keyPressEvent [virtual protected]
1225 Desc: Calls reject() if key Escape is pressed.
1226 Calls accept() if key "Ctrl+Enter" is pressed.
1227 Process key "F1" and emit signal dlgHelp().
1228 Transfer key "Ctrl+(Shift+)Tab" press event to Tab Widget.
1231 void QtxDialog::keyPressEvent( QKeyEvent* e )
1233 QDialog::keyPressEvent( e );
1234 if ( e->isAccepted() )
1237 if ( ( e->state() == 0 ) && ( e->key() == Key_Escape ) )
1240 if ( ( e->state() == ControlButton ) && ( e->key() == Key_Return ) )
1242 if ( testButtonFlags( OK ) || testButtonFlags( Yes ) )
1244 else if ( testButtonFlags( Apply ) && isButtonEnabled( Apply ) )
1249 if ( e->key() == Key_F1 && testButtonFlags( Help ) && isButtonEnabled( Help ) )
1255 if ( ( e->key() == Key_Tab ) && ( e->state() & ControlButton ) )
1257 QObject* tab = child( 0, "QTabWidget" );
1264 Name: closeEvent [virtual protected]
1265 Desc: Reject the dialog.
1268 void QtxDialog::closeEvent( QCloseEvent* )
1274 Name: accept [virtual protected slot]
1275 Desc: Invoke function acceptData() if it needed and if acceptData() return
1276 false does nothing. Otherwise hides the dialog and sets the result code
1277 to Accepted. Emit signal according to the pressed control button.
1280 void QtxDialog::accept()
1284 if ( testButtonFlags( OK ) )
1285 mySender = button( OK );
1286 else if ( testButtonFlags( Yes ) )
1287 mySender = button( Yes );
1289 mySender = button( Close );
1292 if ( !mySender || !mySender->isWidgetType() ||
1293 !((QWidget*)mySender)->isEnabled() )
1296 if ( testDialogFlags( Accept ) && !acceptData() )
1305 Name: reject [virtual protected slot]
1306 Desc: Invoke function rejectData() if it needed and if rejectData() return
1307 false does nothing. Otherwise hides the dialog and sets the result code
1308 to Rejected. Emit signal according to the pressed control button. (If
1309 dialog was closed by key Escape or by close event emit signal dlgCancel(),
1310 or dlgClose(), or dlgNo().
1313 void QtxDialog::reject()
1315 if ( testDialogFlags( Reject ) && !rejectData() )
1320 if ( testButtonFlags( Cancel ) )
1321 mySender = button( Cancel );
1322 else if ( testButtonFlags( No ) )
1323 mySender = button( No );
1325 mySender = button( Close );
1328 if ( !mySender || !mySender->isWidgetType() ||
1329 !((QWidget*)mySender)->isEnabled() )
1338 Name: reject [private]
1339 Desc: Emit signal appropriate to control button.
1342 void QtxDialog::emitSignal()
1344 qApp->processEvents();
1345 QApplication::syncX();
1347 int id = buttonId( (QButton*)mySender );
1371 Name: onAccept [private slot]
1372 Desc: Process signals "clicked()" from control buttons "OK", "Yes". Invoke accept().
1375 void QtxDialog::onAccept()
1377 const QObject* obj = sender();
1383 Name: onReject [private slot]
1384 Desc: Process signals "clicked()" from control buttons "Cancel", "No", "Close".
1388 void QtxDialog::onReject()
1390 const QObject* obj = sender();
1396 Name: onButton [private slot]
1397 Desc: Receive signal "clicked()" from user buttons and emit signal
1398 "dlgButton( int )" with identificator of clicked user button.
1401 void QtxDialog::onButton()
1403 int id = buttonId( (QButton*)sender() );
1405 emit dlgButton( id );
1409 Name: onDestroyed [private slot]
1410 Desc: Remove user button if it was destroyed.
1413 void QtxDialog::onDestroyed( QObject* obj )
1415 QButton* b = (QButton*)obj;
1416 int id = buttonId( b );
1420 myButton.remove( id );
1421 myPosition.remove( id );
1422 for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it )
1423 it.data()->removeButton( b );
1427 Name: onSizeGripDestroyed [private slot]
1428 Desc: Setting up layout when size grip is destroyed.
1431 void QtxDialog::onSizeGripDestroyed()
1434 layout()->setMargin( 5 );
1438 Name: adjustButtons [private]
1439 Desc: Setting the equal with for all buttons.
1442 void QtxDialog::adjustButtons()
1445 for ( AreaMap::Iterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt )
1446 for ( QPtrListIterator<QButton> bIt( aIt.data()->buttons() ); bIt.current(); ++bIt )
1447 if ( bIt.current()->isVisibleTo( this ) )
1448 minWidth = QMAX( minWidth, bIt.current()->sizeHint().width() );
1450 for ( AreaMap::Iterator aItr = myArea.begin(); aItr != myArea.end(); ++aItr )
1451 for ( QPtrListIterator<QButton> bItr( aItr.data()->buttons() ); bItr.current(); ++bItr )
1452 if ( bItr.current()->isVisibleTo( this ) )
1453 bItr.current()->setMinimumWidth( minWidth );