2 // Author: Sergey TELKOV
6 #include "QtxGroupBox.h"
11 #include <qpushbutton.h>
12 #include <qapplication.h>
15 Class: QtxDialog::Area
19 class QtxDialog::Area : public QFrame
22 Area( Orientation, QtxDialog*, QWidget* = 0 );
25 bool isBorderEnabled() const;
26 void setBorderEnabled( const bool );
28 void setBorderWidget( QLabel* );
30 void insertButton( QButton* );
31 void removeButton( QButton* );
32 bool contains( QButton* ) const;
35 void setPolicy( const int );
39 const QPtrList<QButton>& buttons() const;
49 QPtrList<QButton> myButtons;
50 Orientation myOrientation;
53 QtxDialog::Area::Area( Orientation o, QtxDialog* dlg, QWidget* parent )
61 if ( myOrientation == Qt::Horizontal )
62 setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) );
64 setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) );
69 QtxDialog::Area::~Area()
73 void QtxDialog::Area::insertButton( QButton* b )
75 if ( !b || myButtons.findRef( b ) != -1 )
78 QWidget* parent = b->parentWidget();
80 b->reparent( this, 0, QPoint( 0, 0 ), b->isVisibleTo( parent ) );
82 myButtons.append( b );
85 myDlg->adjustButtons();
93 void QtxDialog::Area::removeButton( QButton* b )
98 myButtons.removeRef( b );
100 if ( myButtons.isEmpty() )
106 myDlg->adjustButtons();
111 bool QtxDialog::Area::contains( QButton* b ) const
113 return myButtons.containsRef( b );
116 int QtxDialog::Area::policy() const
121 void QtxDialog::Area::setPolicy( const int p )
130 bool QtxDialog::Area::isBorderEnabled() const
132 return myLine && myBorder;
135 void QtxDialog::Area::setBorderEnabled( const bool on )
137 if ( !myLine || myBorder == on )
144 void QtxDialog::Area::setBorderWidget( QLabel* line )
146 if ( myLine == line )
154 const QPtrList<QButton>& QtxDialog::Area::buttons() const
159 void QtxDialog::Area::updateBorder()
164 bool isVis = isVisibleTo( parentWidget() );
168 if ( isVis && myBorder )
174 myLine->setLineWidth( myBorder ? 1 : 0 );
177 void QtxDialog::Area::layoutButtons()
179 int aPolicy = policy();
181 QMap<QButton*, int> buttonId;
182 for ( QPtrListIterator<QButton> it1( myButtons ); it1.current(); ++it1 )
183 buttonId.insert( it1.current(), 0 );
185 QPtrList<QButton> src;
186 for ( ButtonMap::Iterator mit = myDlg->myButton.begin();
187 mit != myDlg->myButton.end(); ++mit )
189 if ( buttonId.contains( mit.data() ) )
191 buttonId[mit.data()] = mit.key();
192 if ( mit.key() >= 0 )
193 src.append( mit.data() );
197 for ( QPtrListIterator<QButton> it2( myButtons ); it2.current(); ++it2 )
198 if ( buttonId[it2.current()] < 0 )
199 src.append( it2.current() );
201 QPtrList<QButton> left, right, center, other;
202 for ( QPtrListIterator<QButton> it( src ); it.current(); ++it )
204 if ( !it.current()->isVisibleTo( this ) )
207 int aPosition = myDlg->buttonPosition( it.current() );
208 if ( aPosition == -1 )
211 if ( aPolicy != QtxDialog::Position )
212 other.append( it.current() );
213 else if ( aPosition == QtxDialog::Left )
214 left.append( it.current() );
215 else if ( aPosition == QtxDialog::Right )
216 right.append( it.current() );
217 else if ( aPosition == QtxDialog::Center )
218 center.append( it.current() );
223 QBoxLayout* buttonLayout = 0;
224 if ( myOrientation == Qt::Vertical )
225 buttonLayout = new QVBoxLayout( this, 0, 5 );
227 buttonLayout = new QHBoxLayout( this, 0, 5 );
232 if ( aPolicy == QtxDialog::Position )
234 for ( QPtrListIterator<QButton> lit( left ); lit.current(); ++lit )
235 buttonLayout->addWidget( lit.current() );
236 buttonLayout->addStretch( 1 );
237 for ( QPtrListIterator<QButton> cit( center ); cit.current(); ++cit )
238 buttonLayout->addWidget( cit.current() );
239 buttonLayout->addStretch( 1 );
240 for ( QPtrListIterator<QButton> rit( right ); rit.current(); ++rit )
241 buttonLayout->addWidget( rit.current() );
245 for ( QPtrListIterator<QButton> oit( other ); oit.current(); ++oit )
247 buttonLayout->addWidget( oit.current() );
248 if ( aPolicy == QtxDialog::Uniform && !oit.atLast() )
249 buttonLayout->addStretch( 1 );
255 Class: QtxDialog::Border
259 class QtxDialog::Border : public QLabel
262 Border( QWidget* = 0 );
265 virtual void setLineWidth( int );
267 virtual QSize sizeHint() const;
268 virtual QSize minimumSizeHint() const;
271 QtxDialog::Border::Border( QWidget* parent )
274 setAlignment( Qt::AlignCenter );
277 QtxDialog::Border::~Border()
281 void QtxDialog::Border::setLineWidth( int lw )
283 bool isOn = lineWidth() > 0;
285 QLabel::setLineWidth( lw );
287 if ( isOn != ( lineWidth() > 0 ) )
291 QSize QtxDialog::Border::sizeHint() const
296 if ( lineWidth() > 0 )
298 if ( frameShape() == VLine )
299 sz += QSize( 5 + lineWidth(), 0 );
300 else if ( frameShape() == HLine )
301 sz += QSize( 0, 5 + lineWidth() );
308 QSize QtxDialog::Border::minimumSizeHint() const
319 Name: QtxDialog [public]
320 Desc: Construct a dialog with specified parent and name.
321 Parameter 'modal' define modal status of dialog (default non modal
322 dialog created). If parameter 'allowResize' is true then dialog
323 can be resize by user (default non resizable dialog created).
324 Button flags specified control buttons for dialog (default buttons
325 is OK, Cancel and Help). Widget flags used as in any widget.
328 QtxDialog::QtxDialog( QWidget* parent, const char* name,
329 bool modal, bool allowResize, const int f, WFlags wf )
330 : QDialog( parent, name, modal,
332 wf | WStyle_Customize | WStyle_Title | WStyle_SysMenu |
333 ( allowResize ? WStyle_NormalBorder : WStyle_NoBorderEx ) ),
335 wf | WStyle_NormalBorder | WStyle_Customize | WStyle_Title | WStyle_SysMenu ),
339 myDialogFlags( Accept ),
342 QVBoxLayout* base = new QVBoxLayout( this, 5, 0 );
343 QtxGroupBox* main = new QtxGroupBox( 1, Qt::Horizontal, "", this );
344 main->setFrameStyle( QFrame::NoFrame );
345 main->setInsideMargin( 0 );
346 main->setInsideSpacing( 0 );
347 base->addWidget( main );
349 Area* topArea = new Area( Qt::Horizontal, this, main );
350 QLabel* topLine = new Border( main );
351 QtxGroupBox* midGroup = new QtxGroupBox( 1, Qt::Vertical, "", main );
352 QLabel* botLine = new Border( main );
353 Area* botArea = new Area( Qt::Horizontal, this, main );
355 midGroup->setFrameStyle( QFrame::NoFrame );
356 midGroup->setInsideMargin( 0 );
357 midGroup->setInsideSpacing( 0 );
359 Area* leftArea = new Area( Qt::Vertical, this, midGroup );
360 QLabel* leftLine = new Border( midGroup );
361 myMainFrame = new QFrame( midGroup );
362 QLabel* rightLine = new Border( midGroup );
363 Area* rightArea = new Area( Qt::Vertical, this, midGroup );
365 myMainFrame->setSizePolicy( QSizePolicy( QSizePolicy::Expanding,
366 QSizePolicy::Expanding ) );
368 topLine->setFrameStyle( QFrame::Sunken | QFrame::HLine );
369 botLine->setFrameStyle( QFrame::Sunken | QFrame::HLine );
370 leftLine->setFrameStyle( QFrame::Sunken | QFrame::VLine );
371 rightLine->setFrameStyle( QFrame::Sunken | QFrame::VLine );
372 topArea->setBorderWidget( topLine );
373 botArea->setBorderWidget( botLine );
374 leftArea->setBorderWidget( leftLine );
375 rightArea->setBorderWidget( rightLine );
377 myArea.insert( TopArea, topArea );
378 myArea.insert( BottomArea, botArea );
379 myArea.insert( LeftArea, leftArea );
380 myArea.insert( RightArea, rightArea );
382 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++ itr )
383 itr.data()->setBorderEnabled( false );
385 myButton.insert( OK, new QPushButton( tr( "&OK" ), this ) );
386 myButton.insert( Cancel, new QPushButton( tr( "&Cancel" ), this ) );
387 myButton.insert( Close, new QPushButton( tr( "C&lose" ), this ) );
388 myButton.insert( Help, new QPushButton( tr( "&Help" ), this ) );
389 myButton.insert( Apply, new QPushButton( tr( "&Apply" ), this ) );
390 myButton.insert( Yes, new QPushButton( tr( "&Yes" ), this ) );
391 myButton.insert( No, new QPushButton( tr( "&No" ), this ) );
393 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
395 ((QPushButton*)it.data())->setAutoDefault( false );
397 connect( it.data(), SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
401 setButtonPosition( Left, OK | Cancel | Apply );
402 setButtonPosition( Center, Yes | No | Close );
403 setButtonPosition( Right, Help );
404 setButtonPlace( BottomArea, All );
406 connect( myButton[Apply], SIGNAL( clicked() ), this, SIGNAL( dlgApply() ) );
407 connect( myButton[Help], SIGNAL( clicked() ), this, SIGNAL( dlgHelp() ) );
409 connect( myButton[OK], SIGNAL( clicked() ), this, SLOT( onAccept() ) );
410 connect( myButton[Cancel], SIGNAL( clicked() ), this, SLOT( onReject() ) );
411 connect( myButton[Yes], SIGNAL( clicked() ), this, SLOT( onAccept() ) );
412 connect( myButton[No], SIGNAL( clicked() ), this, SLOT( onReject() ) );
413 connect( myButton[Close], SIGNAL( clicked() ), this, SLOT( onReject() ) );
416 if ( qApp && qApp->mainWidget() && qApp->mainWidget()->icon() )
417 setIcon( *qApp->mainWidget()->icon() );
423 setMaximumSize( minimumSize() );
430 Name: ~QtxDialog [public]
434 QtxDialog::~QtxDialog()
439 Name: setButtonFlags [public]
440 Desc: Allow to set specified control button(s) into dialog.
443 void QtxDialog::setButtonFlags( const int f )
445 int old = myButtonFlags;
446 myButtonFlags = myButtonFlags | f;
447 if ( old != myButtonFlags )
452 Name: clearButtonFlags [public]
453 Desc: Allow to unset specified control button(s) from dialog.
456 void QtxDialog::clearButtonFlags( const int f )
458 int old = myButtonFlags;
459 myButtonFlags = myButtonFlags & ~f;
460 if ( old != myButtonFlags )
465 Name: testButtonFlags [public]
466 Desc: Return true if specified control button is used in dialog.
469 bool QtxDialog::testButtonFlags( const int f ) const
471 return ( myButtonFlags & f ) == f;
475 Name: setDialogFlags [public]
476 Desc: Allow to set the dialog flags.
478 Following flags can be used:
479 Accept - Allow to control dialog accepting. See also acceptData().
480 Reject - Allow to control dialog rejecting. See also rejectData().
481 AlignOnce - Allow to align dialog only whem it first time shown.
484 void QtxDialog::setDialogFlags( const int f )
486 myDialogFlags = myDialogFlags | f;
490 Name: clearDialogFlags [public]
491 Desc: Allow to clear the dialog flags. See also setDialogFlags().
494 void QtxDialog::clearDialogFlags( const int f )
496 myDialogFlags = myDialogFlags & ~f;
500 Name: testDialogFlags [public]
501 Desc: Returns true if specified dialog flag is setted (see setDialogFlags()).
504 bool QtxDialog::testDialogFlags( const int f ) const
506 return ( myDialogFlags & f ) == f;
510 Name: mainFrame [public]
511 Desc: Returns main frame of dialog. Main frame should contains all
512 elements of dialog except control buttons.
515 QFrame* QtxDialog::mainFrame() const
521 Name: buttonPosition [public]
522 Desc: Returns position of specified button.
525 int QtxDialog::buttonPosition( const int id ) const
528 if ( myPosition.contains( id ) )
529 pos = myPosition[id];
534 Name: setButtonPosition [public]
535 Desc: Sets the position for specified button(s). Following positions
536 may be used: Left, Right, Center, Top, Bottom.
539 void QtxDialog::setButtonPosition( const int pos, const int id )
541 ButtonMap map = buttons( id );
543 QMap<QObject*, int> changed;
544 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
546 if ( myPosition[it.key()] == pos )
549 myPosition[it.key()] = pos;
550 if ( button( it.key() ) )
551 changed.insert( button( it.key() )->parent(), 0 );
554 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
555 if ( changed.contains( itr.data() ) )
556 itr.data()->layoutButtons();
560 Name: setPlacePosition [public]
561 Desc: Sets button position for all buttons in given place.
564 void QtxDialog::setPlacePosition( const int pos, const int area )
566 if ( !myArea.contains( area ) )
569 Area* anArea = myArea[area];
571 bool changed = false;
572 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
574 if ( !anArea->contains( it.data() ) )
577 changed = changed && myPosition[it.key()] != pos;
579 myPosition[it.key()] = pos;
583 anArea->layoutButtons();
587 Name: placePolicy [public]
588 Desc: Returns policy of button layouting for specified place.
590 Following place may be used:
591 TopArea - Horizontal area in the top side of dialog.
592 BottomArea - Horizontal area in the bottom side of dialog.
593 LeftArea - Vertical area in the left side of dialog.
594 RightArea - Vertical area in the right side of dialog.
596 Following policy may be used:
597 Position - Buttons placed according their position.
598 Expand - Buttons fills all available space.
599 Uniform - Buttons uniformly placed in area.
602 int QtxDialog::placePolicy( const int area ) const
605 if ( myArea.contains( area ) )
606 res = myArea[area]->policy();
611 Name: setPlacePolicy [public]
612 Desc: Sets the policy of button layouting for specified place.
613 See also placePolicy().
616 void QtxDialog::setPlacePolicy( const int policy, const int area )
619 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
620 itr.data()->setPolicy( policy );
621 else if ( myArea.contains( area ) )
622 myArea[area]->setPolicy( policy );
626 Name: setButtonPlace [public]
627 Desc: Move given button(s) into specified place.
630 void QtxDialog::setButtonPlace( const int area, const int ids )
632 if ( !myArea.contains( area ) )
635 Area* anArea = myArea[area];
637 ButtonMap map = buttons( ids );
639 QMap<Area*, int> areaMap;
640 for ( AreaMap::ConstIterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt )
641 areaMap.insert( aIt.data(), 0 );
643 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
645 Area* old = (Area*)it.data()->parent();
649 if ( areaMap.contains( old ) )
650 old->removeButton( it.data() );
651 anArea->insertButton( it.data() );
656 Name: isBorderEnabled [public]
657 Desc: Returns true if border is shown for specified button area.
660 bool QtxDialog::isBorderEnabled( const int area ) const
663 if ( myArea.contains( area ) )
664 res = myArea[area]->isBorderEnabled();
669 Name: setBorderEnabled [public]
670 Desc: Show/hide border for specified button area. Border are
671 line which separate main frame and control buttons.
674 void QtxDialog::setBorderEnabled( const bool on, const int area )
676 if ( !myArea.contains( area ) )
679 if ( myArea[area]->isBorderEnabled() == on )
682 myArea[area]->setBorderEnabled( on );
686 QApplication::sendPostedEvents();
692 Name: isButtonEnabled [public]
693 Desc: Returns true if all specified button(s) is enabled.
696 bool QtxDialog::isButtonEnabled( const int f ) const
698 ButtonMap map = buttons( f );
699 bool result = !map.isEmpty();
700 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
701 result = result && it.data()->isEnabled();
706 Name: setButtonEnabled [public]
707 Desc: Enable/disable specified button(s).
710 void QtxDialog::setButtonEnabled( const bool on, const int ids )
712 ButtonMap map = buttons( ids );
713 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
714 it.data()->setEnabled( on );
718 Name: hasButtonFocus [public]
719 Desc: Retruns true if specified button has keyboard focus.
722 bool QtxDialog::hasButtonFocus( const int id ) const
725 QButton* pb = button( id );
727 res = pb->hasFocus();
732 Name: setButtonFocus [public]
733 Desc: Sets the keyboard focus on specified button.
736 void QtxDialog::setButtonFocus( const int id )
738 QButton* pb = button( id );
744 Name: buttonText [public]
745 Desc: Return text of specified button.
748 QString QtxDialog::buttonText( const int id )
751 QButton* but = button( id );
753 retval = but->text();
758 Name: setButtonText [public]
759 Desc: Sets text to specified button.
762 void QtxDialog::setButtonText( const int id, const QString& text )
764 QButton* but = button( id );
765 if ( but && but->text() != text )
767 but->setText( text );
773 Name: setAlignment [public]
774 Desc: Sets alignment policy. Returns the previous alignment.
775 Use the function before the first show of the dialog.
776 If dialog flag AlignOnce is setted then align will performed
777 only one time otherwise dialog will be aligned every time
778 when it shown. Dialog will be aligned relative to it parent.
780 Following align flags may be used:
781 Qtx::AlignAuto - Align to center of desktop (default).
782 Qtx::AlignLeft - Align left side of dialog to left side of parent.
783 Qtx::AlignRight - Align right side of dialog to right side of parent.
784 Qtx::AlignTop - Align top side of dialog to top side of parent.
785 Qtx::AlignBottom - Align bottom side of dialog to bottom side of parent.
786 Qtx::AlignHCenter - Align dialog to center of parent in horizontal dimension.
787 Qtx::AlignVCenter - Align dialog to center of parent in vertical dimension.
788 Qtx::AlignCenter - Align dialog to center of parent in both dimensions.
789 Qtx::AlignOutLeft - Align right side of dialog to left side of parent.
790 Qtx::AlignOutRight - Align left side of dialog to right side of parent.
791 Qtx::AlignOutTop - Align bottom side of dialog to top side of parent.
792 Qtx::AlignOutBottom - Align top side of dialog to bottom side of parent.
795 uint QtxDialog::setAlignment( uint align )
797 uint oldAlign = myAlignment;
803 Name: update [virtual public slot]
804 Desc: Updates dialog, show selected buttons and hide unselected.
807 void QtxDialog::update()
809 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
811 testButtonFlags( it.key() ) ? it.data()->show() : it.data()->hide();
813 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
814 itr.data()->layoutButtons();
822 Name: show [virtual public]
823 Desc: Show dialog, set keyboard focus on dialog.
826 void QtxDialog::show()
835 Name: hide [virtual public]
836 Desc: Hides dialog, processed all posted events.
839 void QtxDialog::hide()
842 qApp->processEvents();
846 Name: userButton [public]
847 Desc: Return user dialog button using specified identificator.
850 QButton* QtxDialog::userButton( const int id ) const
853 if ( id < -1 && myButton.contains( id ) )
859 Name: userButtonIds [public]
860 Desc: Return list of user dialog button identificators.
863 QValueList<int> QtxDialog::userButtonIds() const
865 QValueList<int> retlist;
866 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it )
868 retlist.append( it.key() );
873 Name: insertButton [public]
874 Desc: Add new user dialog button. Function return identificator of
875 newly added button in successfull case otherwise -1 will be returned.
878 int QtxDialog::insertButton( const QString& text, const int area )
880 if ( !myArea.contains( area ) )
884 while ( myButton.contains( id ) )
887 Area* anArea = myArea[area];
888 QButton* b = createButton( this );
892 myButton.insert( id, b );
893 myPosition.insert( id, Left );
895 connect( b, SIGNAL( clicked() ), this, SLOT( onButton() ) );
897 connect( b, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
900 anArea->insertButton( b );
910 Name: removeButton [public]
911 Desc: Remove user dialog button with specified identificator. If
912 identificator equal -1 then method will remove all user dialog buttons.
915 void QtxDialog::removeButton( const int id )
923 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
926 map.insert( it.key(), it.data() );
929 else if ( myButton.contains( id ) )
930 map.insert( id, myButton[id] );
932 for ( ButtonMap::Iterator itr = map.begin(); itr != map.end(); ++itr )
934 for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it )
935 it.data()->removeButton( itr.data() );
937 myButton.remove( itr.key() );
938 myPosition.remove( itr.key() );
946 Name: setUnits [static public]
947 Desc: Sets specified measure units in given label. Measure units close
948 in braces. If measure units not exist then they will be added.
950 1. Label contains text 'Radius'.
951 setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm)'
952 setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm)'
953 2. Label "aLabel" contains text 'Radius ():'.
954 setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm):'
955 setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm):'
958 void QtxDialog::setUnits( QLabel* aLabel, const QString& aUnits )
960 QString label = aLabel->text();
962 int end = label.findRev( ')' );
964 QString startLabel = label;
969 begin = label.left( end ).findRev( '(' );
972 startLabel = label.mid( 0, begin );
973 finalLabel = label.mid( end + 1 );
978 startLabel = startLabel.stripWhiteSpace();
979 if ( startLabel.at( startLabel.length() - 1 ) == ':' )
981 finalLabel = startLabel.mid( startLabel.length() - 1 );
982 startLabel = startLabel.mid( 0, startLabel.length() - 1 );
985 if ( aUnits.length() )
986 label = startLabel.stripWhiteSpace() +
987 " (" + aUnits + ") " + finalLabel.stripWhiteSpace();
989 label = startLabel.stripWhiteSpace() +
990 " " + finalLabel.stripWhiteSpace();
991 aLabel->setText( label );
995 Name: acceptData [virtual protected]
996 Desc: If returns true dialog will be accepted and closed. This method
997 called if dialog flag Accept is setted.
1000 bool QtxDialog::acceptData() const
1006 Name: rejectData [virtual protected]
1007 Desc: If returns true dialog will be rejected and closed. This method
1008 called if dialog flag Reject is setted.
1011 bool QtxDialog::rejectData() const
1017 Name: createButton [virtual protected]
1018 Desc: Create new user button. Invoked from method "insertButton".
1021 QButton* QtxDialog::createButton( QWidget* parent )
1023 QPushButton* pb = new QPushButton( parent );
1024 pb->setAutoDefault( false );
1029 Name: button [protected]
1030 Desc: Return pointer on control button specified by identifier.
1031 If identifier is wrong then null pointer will returned.
1034 QButton* QtxDialog::button( const int f ) const
1036 QButton* retval = 0;
1037 if ( myButton.contains( f ) )
1038 retval = myButton[f];
1043 Name: buttons [protected]
1044 Desc: Return map with control dialog buttons accordance to given button flags.
1047 QtxDialog::ButtonMap QtxDialog::buttons( const int f ) const
1052 if ( myButton.contains( f ) )
1053 retmap.insert( f, myButton[f] );
1057 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it )
1058 if ( f == -1 || ( it.key() >= 0 && f & it.key() ) )
1059 retmap.insert( it.key(), it.data() );
1066 Name: buttonId [protected]
1067 Desc: Return identifier of specified button.
1070 int QtxDialog::buttonId( const QButton* b ) const
1073 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end() && id == -1; ++it )
1074 if ( it.data() == b )
1080 Name: buttonPosition
1081 Desc: Returns position of specified button. [protected]
1084 int QtxDialog::buttonPosition( QButton* b ) const
1086 return buttonPosition( buttonId( b ) );
1090 Name: showEvent [virtual protected]
1091 Desc: Aligns this dialog according the parent widget and alignment
1092 policy before the show.
1095 void QtxDialog::showEvent( QShowEvent* e )
1097 if ( !testDialogFlags( AlignOnce ) || !myInited )
1098 Qtx::alignWidget( this, parentWidget(), myAlignment );
1099 QDialog::showEvent( e );
1103 Name: hideEvent [virtual protected]
1104 Desc: Process all existing events when dialog is closed.
1107 void QtxDialog::hideEvent( QHideEvent* e )
1109 qApp->processEvents();
1110 QDialog::hideEvent( e );
1114 Name: childEvent [virtual protected]
1115 Desc: Setting up layout when size grip is added.
1118 void QtxDialog::childEvent( QChildEvent* e )
1120 QDialog::childEvent( e );
1121 if ( layout() && e->inserted() && e->child()->inherits( "QSizeGrip" ) )
1123 layout()->setMargin( 12 );
1125 connect( e->child(), SIGNAL( destroyed() ), this, SLOT( onSizeGripDestroyed() ) );
1131 Name: keyPressEvent [virtual protected]
1132 Desc: Calls reject() if key Escape is pressed.
1133 Calls accept() if key "Ctrl+Enter" is pressed.
1134 Process key "F1" and emit signal dlgHelp().
1135 Transfer key "Ctrl+(Shift+)Tab" press event to Tab Widget.
1138 void QtxDialog::keyPressEvent( QKeyEvent* e )
1140 QDialog::keyPressEvent( e );
1141 if ( e->isAccepted() )
1144 if ( ( e->state() == 0 ) && ( e->key() == Key_Escape ) )
1147 if ( ( e->state() == ControlButton ) && ( e->key() == Key_Return ) )
1149 if ( testButtonFlags( OK ) || testButtonFlags( Yes ) )
1151 else if ( testButtonFlags( Apply ) && isButtonEnabled( Apply ) )
1156 if ( e->key() == Key_F1 && testButtonFlags( Help ) && isButtonEnabled( Help ) )
1162 if ( ( e->key() == Key_Tab ) && ( e->state() & ControlButton ) )
1164 QObject* tab = child( 0, "QTabWidget" );
1171 Name: closeEvent [virtual protected]
1172 Desc: Reject the dialog.
1175 void QtxDialog::closeEvent( QCloseEvent* )
1181 Name: accept [virtual protected slot]
1182 Desc: Invoke function acceptData() if it needed and if acceptData() return
1183 false does nothing. Otherwise hides the dialog and sets the result code
1184 to Accepted. Emit signal according to the pressed control button.
1187 void QtxDialog::accept()
1191 if ( testButtonFlags( OK ) )
1192 mySender = button( OK );
1193 else if ( testButtonFlags( Yes ) )
1194 mySender = button( Yes );
1196 mySender = button( Close );
1199 if ( !mySender || !mySender->isWidgetType() ||
1200 !((QWidget*)mySender)->isEnabled() )
1203 if ( testDialogFlags( Accept ) && !acceptData() )
1212 Name: reject [virtual protected slot]
1213 Desc: Invoke function rejectData() if it needed and if rejectData() return
1214 false does nothing. Otherwise hides the dialog and sets the result code
1215 to Rejected. Emit signal according to the pressed control button. (If
1216 dialog was closed by key Escape or by close event emit signal dlgCancel(),
1217 or dlgClose(), or dlgNo().
1220 void QtxDialog::reject()
1222 if ( testDialogFlags( Reject ) && !rejectData() )
1227 if ( testButtonFlags( Cancel ) )
1228 mySender = button( Cancel );
1229 else if ( testButtonFlags( No ) )
1230 mySender = button( No );
1232 mySender = button( Close );
1235 if ( !mySender || !mySender->isWidgetType() ||
1236 !((QWidget*)mySender)->isEnabled() )
1245 Name: reject [private]
1246 Desc: Emit signal appropriate to control button.
1249 void QtxDialog::emitSignal()
1251 qApp->processEvents();
1252 QApplication::syncX();
1254 int id = buttonId( (QButton*)mySender );
1278 Name: onAccept [private slot]
1279 Desc: Process signals "clicked()" from control buttons "OK", "Yes". Invoke accept().
1282 void QtxDialog::onAccept()
1284 const QObject* obj = sender();
1290 Name: onReject [private slot]
1291 Desc: Process signals "clicked()" from control buttons "Cancel", "No", "Close".
1295 void QtxDialog::onReject()
1297 const QObject* obj = sender();
1303 Name: onButton [private slot]
1304 Desc: Receive signal "clicked()" from user buttons and emit signal
1305 "dlgButton( int )" with identificator of clicked user button.
1308 void QtxDialog::onButton()
1310 int id = buttonId( (QButton*)sender() );
1312 emit dlgButton( id );
1316 Name: onDestroyed [private slot]
1317 Desc: Remove user button if it was destroyed.
1320 void QtxDialog::onDestroyed( QObject* obj )
1322 QButton* b = (QButton*)obj;
1323 int id = buttonId( b );
1327 myButton.remove( id );
1328 myPosition.remove( id );
1329 for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it )
1330 it.data()->removeButton( b );
1334 Name: onSizeGripDestroyed [private slot]
1335 Desc: Setting up layout when size grip is destroyed.
1338 void QtxDialog::onSizeGripDestroyed()
1341 layout()->setMargin( 5 );
1345 Name: adjustButtons [private]
1346 Desc: Setting the equal with for all buttons.
1349 void QtxDialog::adjustButtons()
1352 for ( AreaMap::Iterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt )
1353 for ( QPtrListIterator<QButton> bIt( aIt.data()->buttons() ); bIt.current(); ++bIt )
1354 if ( bIt.current()->isVisibleTo( this ) )
1355 minWidth = QMAX( minWidth, bIt.current()->sizeHint().width() );
1357 for ( AreaMap::Iterator aItr = myArea.begin(); aItr != myArea.end(); ++aItr )
1358 for ( QPtrListIterator<QButton> bItr( aItr.data()->buttons() ); bItr.current(); ++bItr )
1359 if ( bItr.current()->isVisibleTo( this ) )
1360 bItr.current()->setMinimumWidth( minWidth );