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/
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
37 class QtxDialog::Area : public QFrame
40 Area( Orientation, QtxDialog*, QWidget* = 0 );
43 bool isBorderEnabled() const;
44 void setBorderEnabled( const bool );
46 void setBorderWidget( QLabel* );
48 void insertButton( QButton* );
49 void removeButton( QButton* );
50 bool contains( QButton* ) const;
53 void setPolicy( const int );
57 const QPtrList<QButton>& buttons() const;
67 QPtrList<QButton> myButtons;
68 Orientation myOrientation;
71 QtxDialog::Area::Area( Orientation o, QtxDialog* dlg, QWidget* parent )
79 if ( myOrientation == Qt::Horizontal )
80 setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) );
82 setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) );
87 QtxDialog::Area::~Area()
91 void QtxDialog::Area::insertButton( QButton* b )
93 if ( !b || myButtons.findRef( b ) != -1 )
96 QWidget* parent = b->parentWidget();
98 b->reparent( this, 0, QPoint( 0, 0 ), b->isVisibleTo( parent ) );
100 myButtons.append( b );
103 myDlg->adjustButtons();
111 void QtxDialog::Area::removeButton( QButton* b )
116 myButtons.removeRef( b );
118 if ( myButtons.isEmpty() )
124 myDlg->adjustButtons();
129 bool QtxDialog::Area::contains( QButton* b ) const
131 return myButtons.containsRef( b );
134 int QtxDialog::Area::policy() const
139 void QtxDialog::Area::setPolicy( const int p )
148 bool QtxDialog::Area::isBorderEnabled() const
150 return myLine && myBorder;
153 void QtxDialog::Area::setBorderEnabled( const bool on )
155 if ( !myLine || myBorder == on )
162 void QtxDialog::Area::setBorderWidget( QLabel* line )
164 if ( myLine == line )
172 const QPtrList<QButton>& QtxDialog::Area::buttons() const
177 void QtxDialog::Area::updateBorder()
182 bool isVis = isVisibleTo( parentWidget() );
186 if ( isVis && myBorder )
192 myLine->setLineWidth( myBorder ? 1 : 0 );
195 void QtxDialog::Area::layoutButtons()
197 int aPolicy = policy();
199 QMap<QButton*, int> buttonId;
200 for ( QPtrListIterator<QButton> it1( myButtons ); it1.current(); ++it1 )
201 buttonId.insert( it1.current(), 0 );
203 QPtrList<QButton> src;
204 for ( ButtonMap::Iterator mit = myDlg->myButton.begin();
205 mit != myDlg->myButton.end(); ++mit )
207 if ( buttonId.contains( mit.data() ) )
209 buttonId[mit.data()] = mit.key();
210 if ( mit.key() >= 0 )
211 src.append( mit.data() );
215 for ( QPtrListIterator<QButton> it2( myButtons ); it2.current(); ++it2 )
216 if ( buttonId[it2.current()] < 0 )
217 src.append( it2.current() );
219 QPtrList<QButton> left, right, center, other;
220 for ( QPtrListIterator<QButton> it( src ); it.current(); ++it )
222 if ( !it.current()->isVisibleTo( this ) )
225 int aPosition = myDlg->buttonPosition( it.current() );
226 if ( aPosition == -1 )
229 if ( aPolicy != QtxDialog::Position )
230 other.append( it.current() );
231 else if ( aPosition == QtxDialog::Left )
232 left.append( it.current() );
233 else if ( aPosition == QtxDialog::Right )
234 right.append( it.current() );
235 else if ( aPosition == QtxDialog::Center )
236 center.append( it.current() );
241 QBoxLayout* buttonLayout = 0;
242 if ( myOrientation == Qt::Vertical )
243 buttonLayout = new QVBoxLayout( this, 0, 5 );
245 buttonLayout = new QHBoxLayout( this, 0, 5 );
250 if ( aPolicy == QtxDialog::Position )
252 for ( QPtrListIterator<QButton> lit( left ); lit.current(); ++lit )
253 buttonLayout->addWidget( lit.current() );
254 buttonLayout->addStretch( 1 );
255 for ( QPtrListIterator<QButton> cit( center ); cit.current(); ++cit )
256 buttonLayout->addWidget( cit.current() );
257 buttonLayout->addStretch( 1 );
258 for ( QPtrListIterator<QButton> rit( right ); rit.current(); ++rit )
259 buttonLayout->addWidget( rit.current() );
263 for ( QPtrListIterator<QButton> oit( other ); oit.current(); ++oit )
265 buttonLayout->addWidget( oit.current() );
266 if ( aPolicy == QtxDialog::Uniform && !oit.atLast() )
267 buttonLayout->addStretch( 1 );
273 Class: QtxDialog::Border
277 class QtxDialog::Border : public QLabel
280 Border( QWidget* = 0 );
283 virtual void setLineWidth( int );
285 virtual QSize sizeHint() const;
286 virtual QSize minimumSizeHint() const;
289 QtxDialog::Border::Border( QWidget* parent )
292 setAlignment( Qt::AlignCenter );
295 QtxDialog::Border::~Border()
299 void QtxDialog::Border::setLineWidth( int lw )
301 bool isOn = lineWidth() > 0;
303 QLabel::setLineWidth( lw );
305 if ( isOn != ( lineWidth() > 0 ) )
309 QSize QtxDialog::Border::sizeHint() const
314 if ( lineWidth() > 0 )
316 if ( frameShape() == VLine )
317 sz += QSize( 5 + lineWidth(), 0 );
318 else if ( frameShape() == HLine )
319 sz += QSize( 0, 5 + lineWidth() );
326 QSize QtxDialog::Border::minimumSizeHint() const
337 Name: QtxDialog [public]
338 Desc: Construct a dialog with specified parent and name.
339 Parameter 'modal' define modal status of dialog (default non modal
340 dialog created). If parameter 'allowResize' is true then dialog
341 can be resize by user (default non resizable dialog created).
342 Button flags specified control buttons for dialog (default buttons
343 is OK, Cancel and Help). Widget flags used as in any widget.
346 QtxDialog::QtxDialog( QWidget* parent, const char* name,
347 bool modal, bool allowResize, const int f, WFlags wf )
348 : QDialog( parent, name, modal,
350 wf | WStyle_Customize | WStyle_Title | WStyle_SysMenu |
351 ( allowResize ? WStyle_NormalBorder : WStyle_NoBorderEx ) ),
353 wf | WStyle_NormalBorder | WStyle_Customize | WStyle_Title | WStyle_SysMenu ),
358 myDialogFlags( Accept | SetFocus )
360 QVBoxLayout* base = new QVBoxLayout( this, 5, 0 );
361 QtxGroupBox* main = new QtxGroupBox( 1, Qt::Horizontal, "", this );
362 main->setFrameStyle( QFrame::NoFrame );
363 main->setInsideMargin( 0 );
364 main->setInsideSpacing( 0 );
365 base->addWidget( main );
367 Area* topArea = new Area( Qt::Horizontal, this, main );
368 QLabel* topLine = new Border( main );
369 QtxGroupBox* midGroup = new QtxGroupBox( 1, Qt::Vertical, "", main );
370 QLabel* botLine = new Border( main );
371 Area* botArea = new Area( Qt::Horizontal, this, main );
373 midGroup->setFrameStyle( QFrame::NoFrame );
374 midGroup->setInsideMargin( 0 );
375 midGroup->setInsideSpacing( 0 );
377 Area* leftArea = new Area( Qt::Vertical, this, midGroup );
378 QLabel* leftLine = new Border( midGroup );
379 myMainFrame = new QFrame( midGroup );
380 QLabel* rightLine = new Border( midGroup );
381 Area* rightArea = new Area( Qt::Vertical, this, midGroup );
383 myMainFrame->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,
384 QSizePolicy::Expanding ) );
386 topLine->setFrameStyle( QFrame::Sunken | QFrame::HLine );
387 botLine->setFrameStyle( QFrame::Sunken | QFrame::HLine );
388 leftLine->setFrameStyle( QFrame::Sunken | QFrame::VLine );
389 rightLine->setFrameStyle( QFrame::Sunken | QFrame::VLine );
390 topArea->setBorderWidget( topLine );
391 botArea->setBorderWidget( botLine );
392 leftArea->setBorderWidget( leftLine );
393 rightArea->setBorderWidget( rightLine );
395 myArea.insert( TopArea, topArea );
396 myArea.insert( BottomArea, botArea );
397 myArea.insert( LeftArea, leftArea );
398 myArea.insert( RightArea, rightArea );
400 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++ itr )
401 itr.data()->setBorderEnabled( false );
403 myButton.insert( OK, new QPushButton( tr( "&OK" ), this ) );
404 myButton.insert( Cancel, new QPushButton( tr( "&Cancel" ), this ) );
405 myButton.insert( Close, new QPushButton( tr( "C&lose" ), this ) );
406 myButton.insert( Help, new QPushButton( tr( "&Help" ), this ) );
407 myButton.insert( Apply, new QPushButton( tr( "&Apply" ), this ) );
408 myButton.insert( Yes, new QPushButton( tr( "&Yes" ), this ) );
409 myButton.insert( No, new QPushButton( tr( "&No" ), this ) );
411 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
413 ((QPushButton*)it.data())->setAutoDefault( false );
415 connect( it.data(), SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
419 setButtonPosition( Left, OK | Cancel | Apply );
420 setButtonPosition( Center, Yes | No | Close );
421 setButtonPosition( Right, Help );
422 setButtonPlace( BottomArea, All );
424 connect( myButton[Apply], SIGNAL( clicked() ), this, SIGNAL( dlgApply() ) );
425 connect( myButton[Help], SIGNAL( clicked() ), this, SIGNAL( dlgHelp() ) );
427 connect( myButton[OK], SIGNAL( clicked() ), this, SLOT( onAccept() ) );
428 connect( myButton[Cancel], SIGNAL( clicked() ), this, SLOT( onReject() ) );
429 connect( myButton[Yes], SIGNAL( clicked() ), this, SLOT( onAccept() ) );
430 connect( myButton[No], SIGNAL( clicked() ), this, SLOT( onReject() ) );
431 connect( myButton[Close], SIGNAL( clicked() ), this, SLOT( onReject() ) );
434 if ( qApp && qApp->mainWidget() && qApp->mainWidget()->icon() )
435 setIcon( *qApp->mainWidget()->icon() );
441 setMaximumSize( minimumSize() );
448 Name: ~QtxDialog [public]
452 QtxDialog::~QtxDialog()
457 Name: setButtonFlags [public]
458 Desc: Allow to set specified control button(s) into dialog.
461 void QtxDialog::setButtonFlags( const int f )
463 int old = myButtonFlags;
464 myButtonFlags = myButtonFlags | f;
465 if ( old != myButtonFlags )
470 Name: clearButtonFlags [public]
471 Desc: Allow to unset specified control button(s) from dialog.
474 void QtxDialog::clearButtonFlags( const int f )
476 int old = myButtonFlags;
477 myButtonFlags = myButtonFlags & ~f;
478 if ( old != myButtonFlags )
483 Name: testButtonFlags [public]
484 Desc: Return true if specified control button is used in dialog.
487 bool QtxDialog::testButtonFlags( const int f ) const
489 return ( myButtonFlags & f ) == f;
493 Name: setDialogFlags [public]
494 Desc: Allow to set the dialog flags.
496 Following flags can be used:
497 Accept - Allow to control dialog accepting. See also acceptData().
498 Reject - Allow to control dialog rejecting. See also rejectData().
499 AlignOnce - Allow to align dialog only when it first time shown.
500 SetFocus - Allow to set focus on dialog when it shown. User can use
501 setFocusProxy() and specify own initial focus widget.
504 void QtxDialog::setDialogFlags( const int f )
506 myDialogFlags = myDialogFlags | f;
510 Name: clearDialogFlags [public]
511 Desc: Allow to clear the dialog flags. See also setDialogFlags().
514 void QtxDialog::clearDialogFlags( const int f )
516 myDialogFlags = myDialogFlags & ~f;
520 Name: testDialogFlags [public]
521 Desc: Returns true if specified dialog flag is setted (see setDialogFlags()).
524 bool QtxDialog::testDialogFlags( const int f ) const
526 return ( myDialogFlags & f ) == f;
530 Name: mainFrame [public]
531 Desc: Returns main frame of dialog. Main frame should contains all
532 elements of dialog except control buttons.
535 QFrame* QtxDialog::mainFrame() const
541 Name: buttonPosition [public]
542 Desc: Returns position of specified button.
545 int QtxDialog::buttonPosition( const int id ) const
548 if ( myPosition.contains( id ) )
549 pos = myPosition[id];
554 Name: setButtonPosition [public]
555 Desc: Sets the position for specified button(s). Following positions
556 may be used: Left, Right, Center, Top, Bottom.
559 void QtxDialog::setButtonPosition( const int pos, const int id )
561 ButtonMap map = buttons( id );
563 QMap<QObject*, int> changed;
564 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
566 if ( myPosition[it.key()] == pos )
569 myPosition[it.key()] = pos;
570 if ( button( it.key() ) )
571 changed.insert( button( it.key() )->parent(), 0 );
574 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
575 if ( changed.contains( itr.data() ) )
576 itr.data()->layoutButtons();
580 Name: setPlacePosition [public]
581 Desc: Sets button position for all buttons in given place.
584 void QtxDialog::setPlacePosition( const int pos, const int area )
586 if ( !myArea.contains( area ) )
589 Area* anArea = myArea[area];
591 bool changed = false;
592 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
594 if ( !anArea->contains( it.data() ) )
597 changed = changed && myPosition[it.key()] != pos;
599 myPosition[it.key()] = pos;
603 anArea->layoutButtons();
607 Name: placePolicy [public]
608 Desc: Returns policy of button layouting for specified place.
610 Following place may be used:
611 TopArea - Horizontal area in the top side of dialog.
612 BottomArea - Horizontal area in the bottom side of dialog.
613 LeftArea - Vertical area in the left side of dialog.
614 RightArea - Vertical area in the right side of dialog.
616 Following policy may be used:
617 Position - Buttons placed according their position.
618 Expand - Buttons fills all available space.
619 Uniform - Buttons uniformly placed in area.
622 int QtxDialog::placePolicy( const int area ) const
625 if ( myArea.contains( area ) )
626 res = myArea[area]->policy();
631 Name: setPlacePolicy [public]
632 Desc: Sets the policy of button layouting for specified place.
633 See also placePolicy().
636 void QtxDialog::setPlacePolicy( const int policy, const int area )
639 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
640 itr.data()->setPolicy( policy );
641 else if ( myArea.contains( area ) )
642 myArea[area]->setPolicy( policy );
646 Name: setButtonPlace [public]
647 Desc: Move given button(s) into specified place.
650 void QtxDialog::setButtonPlace( const int area, const int ids )
652 if ( !myArea.contains( area ) )
655 Area* anArea = myArea[area];
657 ButtonMap map = buttons( ids );
659 QMap<Area*, int> areaMap;
660 for ( AreaMap::ConstIterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt )
661 areaMap.insert( aIt.data(), 0 );
663 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
665 Area* old = (Area*)it.data()->parent();
669 if ( areaMap.contains( old ) )
670 old->removeButton( it.data() );
671 anArea->insertButton( it.data() );
676 Name: isBorderEnabled [public]
677 Desc: Returns true if border is shown for specified button area.
680 bool QtxDialog::isBorderEnabled( const int area ) const
683 if ( myArea.contains( area ) )
684 res = myArea[area]->isBorderEnabled();
689 Name: setBorderEnabled [public]
690 Desc: Show/hide border for specified button area. Border are
691 line which separate main frame and control buttons.
694 void QtxDialog::setBorderEnabled( const bool on, const int area )
696 if ( !myArea.contains( area ) )
699 if ( myArea[area]->isBorderEnabled() == on )
702 myArea[area]->setBorderEnabled( on );
706 QApplication::sendPostedEvents();
712 Name: isButtonEnabled [public]
713 Desc: Returns true if all specified button(s) is enabled.
716 bool QtxDialog::isButtonEnabled( const int f ) const
718 ButtonMap map = buttons( f );
719 bool result = !map.isEmpty();
720 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
721 result = result && it.data()->isEnabled();
726 Name: setButtonEnabled [public]
727 Desc: Enable/disable specified button(s).
730 void QtxDialog::setButtonEnabled( const bool on, const int ids )
732 ButtonMap map = buttons( ids );
733 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
734 it.data()->setEnabled( on );
738 Name: hasButtonFocus [public]
739 Desc: Retruns true if specified button has keyboard focus.
742 bool QtxDialog::hasButtonFocus( const int id ) const
745 QButton* pb = button( id );
747 res = pb->hasFocus();
752 Name: setButtonFocus [public]
753 Desc: Sets the keyboard focus on specified button.
756 void QtxDialog::setButtonFocus( const int id )
758 QButton* pb = button( id );
764 Name: buttonText [public]
765 Desc: Return text of specified button.
768 QString QtxDialog::buttonText( const int id )
771 QButton* but = button( id );
773 retval = but->text();
778 Name: setButtonText [public]
779 Desc: Sets text to specified button.
782 void QtxDialog::setButtonText( const int id, const QString& text )
784 QButton* but = button( id );
785 if ( but && but->text() != text )
787 but->setText( text );
793 Name: setAlignment [public]
794 Desc: Sets alignment policy. Returns the previous alignment.
795 Use the function before the first show of the dialog.
796 If dialog flag AlignOnce is setted then align will performed
797 only one time otherwise dialog will be aligned every time
798 when it shown. Dialog will be aligned relative to it parent.
800 Following align flags may be used:
801 Qtx::AlignAuto - Align to center of desktop (default).
802 Qtx::AlignLeft - Align left side of dialog to left side of parent.
803 Qtx::AlignRight - Align right side of dialog to right side of parent.
804 Qtx::AlignTop - Align top side of dialog to top side of parent.
805 Qtx::AlignBottom - Align bottom side of dialog to bottom side of parent.
806 Qtx::AlignHCenter - Align dialog to center of parent in horizontal dimension.
807 Qtx::AlignVCenter - Align dialog to center of parent in vertical dimension.
808 Qtx::AlignCenter - Align dialog to center of parent in both dimensions.
809 Qtx::AlignOutLeft - Align right side of dialog to left side of parent.
810 Qtx::AlignOutRight - Align left side of dialog to right side of parent.
811 Qtx::AlignOutTop - Align bottom side of dialog to top side of parent.
812 Qtx::AlignOutBottom - Align top side of dialog to bottom side of parent.
815 uint QtxDialog::setAlignment( uint align )
817 uint oldAlign = myAlignment;
823 Name: update [virtual public slot]
824 Desc: Updates dialog, show selected buttons and hide unselected.
827 void QtxDialog::update()
829 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
831 testButtonFlags( it.key() ) ? it.data()->show() : it.data()->hide();
833 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
834 itr.data()->layoutButtons();
842 Name: show [virtual public]
843 Desc: Show dialog, set keyboard focus on dialog.
846 void QtxDialog::show()
850 if ( testDialogFlags( SetFocus ) )
857 Name: hide [virtual public]
858 Desc: Hides dialog, processed all posted events.
861 void QtxDialog::hide()
864 qApp->processEvents();
868 Name: userButton [public]
869 Desc: Return user dialog button using specified identificator.
872 QButton* QtxDialog::userButton( const int id ) const
875 if ( id < -1 && myButton.contains( id ) )
881 Name: userButtonIds [public]
882 Desc: Return list of user dialog button identificators.
885 QValueList<int> QtxDialog::userButtonIds() const
887 QValueList<int> retlist;
888 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it )
890 retlist.append( it.key() );
895 Name: insertButton [public]
896 Desc: Add new user dialog button. Function return identificator of
897 newly added button in successfull case otherwise -1 will be returned.
900 int QtxDialog::insertButton( const QString& text, const int area )
902 if ( !myArea.contains( area ) )
906 while ( myButton.contains( id ) )
909 Area* anArea = myArea[area];
910 QButton* b = createButton( this );
914 myButton.insert( id, b );
915 myPosition.insert( id, Left );
917 connect( b, SIGNAL( clicked() ), this, SLOT( onButton() ) );
919 connect( b, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
922 anArea->insertButton( b );
932 Name: removeButton [public]
933 Desc: Remove user dialog button with specified identificator. If
934 identificator equal -1 then method will remove all user dialog buttons.
937 void QtxDialog::removeButton( const int id )
945 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
948 map.insert( it.key(), it.data() );
951 else if ( myButton.contains( id ) )
952 map.insert( id, myButton[id] );
954 for ( ButtonMap::Iterator itr = map.begin(); itr != map.end(); ++itr )
956 for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it )
957 it.data()->removeButton( itr.data() );
959 myButton.remove( itr.key() );
960 myPosition.remove( itr.key() );
968 Name: setUnits [static public]
969 Desc: Sets specified measure units in given label. Measure units close
970 in braces. If measure units not exist then they will be added.
972 1. Label contains text 'Radius'.
973 setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm)'
974 setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm)'
975 2. Label "aLabel" contains text 'Radius ():'.
976 setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm):'
977 setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm):'
980 void QtxDialog::setUnits( QLabel* aLabel, const QString& aUnits )
982 QString label = aLabel->text();
984 int end = label.findRev( ')' );
986 QString startLabel = label;
991 begin = label.left( end ).findRev( '(' );
994 startLabel = label.mid( 0, begin );
995 finalLabel = label.mid( end + 1 );
1000 startLabel = startLabel.stripWhiteSpace();
1001 if ( startLabel.at( startLabel.length() - 1 ) == ':' )
1003 finalLabel = startLabel.mid( startLabel.length() - 1 );
1004 startLabel = startLabel.mid( 0, startLabel.length() - 1 );
1007 if ( aUnits.length() )
1008 label = startLabel.stripWhiteSpace() +
1009 " (" + aUnits + ") " + finalLabel.stripWhiteSpace();
1011 label = startLabel.stripWhiteSpace() +
1012 " " + finalLabel.stripWhiteSpace();
1013 aLabel->setText( label );
1017 Name: acceptData [virtual protected]
1018 Desc: If returns true dialog will be accepted and closed. This method
1019 called if dialog flag Accept is setted.
1022 bool QtxDialog::acceptData() const
1028 Name: rejectData [virtual protected]
1029 Desc: If returns true dialog will be rejected and closed. This method
1030 called if dialog flag Reject is setted.
1033 bool QtxDialog::rejectData() const
1039 Name: createButton [virtual protected]
1040 Desc: Create new user button. Invoked from method "insertButton".
1043 QButton* QtxDialog::createButton( QWidget* parent )
1045 QPushButton* pb = new QPushButton( parent );
1046 pb->setAutoDefault( false );
1051 Name: button [protected]
1052 Desc: Return pointer on control button specified by identifier.
1053 If identifier is wrong then null pointer will returned.
1056 QButton* QtxDialog::button( const int f ) const
1058 QButton* retval = 0;
1059 if ( myButton.contains( f ) )
1060 retval = myButton[f];
1065 Name: buttons [protected]
1066 Desc: Return map with control dialog buttons accordance to given button flags.
1069 QtxDialog::ButtonMap QtxDialog::buttons( const int f ) const
1074 if ( myButton.contains( f ) )
1075 retmap.insert( f, myButton[f] );
1079 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it )
1080 if ( f == -1 || ( it.key() >= 0 && f & it.key() ) )
1081 retmap.insert( it.key(), it.data() );
1088 Name: buttonId [protected]
1089 Desc: Return identifier of specified button.
1092 int QtxDialog::buttonId( const QButton* b ) const
1095 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end() && id == -1; ++it )
1096 if ( it.data() == b )
1102 Name: buttonPosition
1103 Desc: Returns position of specified button. [protected]
1106 int QtxDialog::buttonPosition( QButton* b ) const
1108 return buttonPosition( buttonId( b ) );
1112 Name: showEvent [virtual protected]
1113 Desc: Aligns this dialog according the parent widget and alignment
1114 policy before the show.
1117 void QtxDialog::showEvent( QShowEvent* e )
1119 if ( !testDialogFlags( AlignOnce ) || !myInited )
1120 Qtx::alignWidget( this, parentWidget(), myAlignment );
1121 QDialog::showEvent( e );
1125 Name: hideEvent [virtual protected]
1126 Desc: Process all existing events when dialog is closed.
1129 void QtxDialog::hideEvent( QHideEvent* e )
1131 qApp->processEvents();
1132 QDialog::hideEvent( e );
1136 Name: childEvent [virtual protected]
1137 Desc: Setting up layout when size grip is added.
1140 void QtxDialog::childEvent( QChildEvent* e )
1142 QDialog::childEvent( e );
1143 if ( layout() && e->inserted() && e->child()->inherits( "QSizeGrip" ) )
1145 layout()->setMargin( 12 );
1147 connect( e->child(), SIGNAL( destroyed() ), this, SLOT( onSizeGripDestroyed() ) );
1153 Name: keyPressEvent [virtual protected]
1154 Desc: Calls reject() if key Escape is pressed.
1155 Calls accept() if key "Ctrl+Enter" is pressed.
1156 Process key "F1" and emit signal dlgHelp().
1157 Transfer key "Ctrl+(Shift+)Tab" press event to Tab Widget.
1160 void QtxDialog::keyPressEvent( QKeyEvent* e )
1162 QDialog::keyPressEvent( e );
1163 if ( e->isAccepted() )
1166 if ( ( e->state() == 0 ) && ( e->key() == Key_Escape ) )
1169 if ( ( e->state() == ControlButton ) && ( e->key() == Key_Return ) )
1171 if ( testButtonFlags( OK ) || testButtonFlags( Yes ) )
1173 else if ( testButtonFlags( Apply ) && isButtonEnabled( Apply ) )
1178 if ( e->key() == Key_F1 && testButtonFlags( Help ) && isButtonEnabled( Help ) )
1184 if ( ( e->key() == Key_Tab ) && ( e->state() & ControlButton ) )
1186 QObject* tab = child( 0, "QTabWidget" );
1193 Name: closeEvent [virtual protected]
1194 Desc: Reject the dialog.
1197 void QtxDialog::closeEvent( QCloseEvent* )
1203 Name: accept [virtual protected slot]
1204 Desc: Invoke function acceptData() if it needed and if acceptData() return
1205 false does nothing. Otherwise hides the dialog and sets the result code
1206 to Accepted. Emit signal according to the pressed control button.
1209 void QtxDialog::accept()
1213 if ( testButtonFlags( OK ) )
1214 mySender = button( OK );
1215 else if ( testButtonFlags( Yes ) )
1216 mySender = button( Yes );
1218 mySender = button( Close );
1221 if ( !mySender || !mySender->isWidgetType() ||
1222 !((QWidget*)mySender)->isEnabled() )
1225 if ( testDialogFlags( Accept ) && !acceptData() )
1234 Name: reject [virtual protected slot]
1235 Desc: Invoke function rejectData() if it needed and if rejectData() return
1236 false does nothing. Otherwise hides the dialog and sets the result code
1237 to Rejected. Emit signal according to the pressed control button. (If
1238 dialog was closed by key Escape or by close event emit signal dlgCancel(),
1239 or dlgClose(), or dlgNo().
1242 void QtxDialog::reject()
1244 if ( testDialogFlags( Reject ) && !rejectData() )
1249 if ( testButtonFlags( Cancel ) )
1250 mySender = button( Cancel );
1251 else if ( testButtonFlags( No ) )
1252 mySender = button( No );
1254 mySender = button( Close );
1257 if ( !mySender || !mySender->isWidgetType() ||
1258 !((QWidget*)mySender)->isEnabled() )
1267 Name: reject [private]
1268 Desc: Emit signal appropriate to control button.
1271 void QtxDialog::emitSignal()
1273 qApp->processEvents();
1274 QApplication::syncX();
1276 int id = buttonId( (QButton*)mySender );
1300 Name: onAccept [private slot]
1301 Desc: Process signals "clicked()" from control buttons "OK", "Yes". Invoke accept().
1304 void QtxDialog::onAccept()
1306 const QObject* obj = sender();
1312 Name: onReject [private slot]
1313 Desc: Process signals "clicked()" from control buttons "Cancel", "No", "Close".
1317 void QtxDialog::onReject()
1319 const QObject* obj = sender();
1325 Name: onButton [private slot]
1326 Desc: Receive signal "clicked()" from user buttons and emit signal
1327 "dlgButton( int )" with identificator of clicked user button.
1330 void QtxDialog::onButton()
1332 int id = buttonId( (QButton*)sender() );
1334 emit dlgButton( id );
1338 Name: onDestroyed [private slot]
1339 Desc: Remove user button if it was destroyed.
1342 void QtxDialog::onDestroyed( QObject* obj )
1344 QButton* b = (QButton*)obj;
1345 int id = buttonId( b );
1349 myButton.remove( id );
1350 myPosition.remove( id );
1351 for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it )
1352 it.data()->removeButton( b );
1356 Name: onSizeGripDestroyed [private slot]
1357 Desc: Setting up layout when size grip is destroyed.
1360 void QtxDialog::onSizeGripDestroyed()
1363 layout()->setMargin( 5 );
1367 Name: adjustButtons [private]
1368 Desc: Setting the equal with for all buttons.
1371 void QtxDialog::adjustButtons()
1374 for ( AreaMap::Iterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt )
1375 for ( QPtrListIterator<QButton> bIt( aIt.data()->buttons() ); bIt.current(); ++bIt )
1376 if ( bIt.current()->isVisibleTo( this ) )
1377 minWidth = QMAX( minWidth, bIt.current()->sizeHint().width() );
1379 for ( AreaMap::Iterator aItr = myArea.begin(); aItr != myArea.end(); ++aItr )
1380 for ( QPtrListIterator<QButton> bItr( aItr.data()->buttons() ); bItr.current(); ++bItr )
1381 if ( bItr.current()->isVisibleTo( this ) )
1382 bItr.current()->setMinimumWidth( minWidth );