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 ),
340 myDialogFlags( Accept | SetFocus )
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 when it first time shown.
482 SetFocus - Allow to set focus on dialog when it shown. User can use
483 setFocusProxy() and specify own initial focus widget.
486 void QtxDialog::setDialogFlags( const int f )
488 myDialogFlags = myDialogFlags | f;
492 Name: clearDialogFlags [public]
493 Desc: Allow to clear the dialog flags. See also setDialogFlags().
496 void QtxDialog::clearDialogFlags( const int f )
498 myDialogFlags = myDialogFlags & ~f;
502 Name: testDialogFlags [public]
503 Desc: Returns true if specified dialog flag is setted (see setDialogFlags()).
506 bool QtxDialog::testDialogFlags( const int f ) const
508 return ( myDialogFlags & f ) == f;
512 Name: mainFrame [public]
513 Desc: Returns main frame of dialog. Main frame should contains all
514 elements of dialog except control buttons.
517 QFrame* QtxDialog::mainFrame() const
523 Name: buttonPosition [public]
524 Desc: Returns position of specified button.
527 int QtxDialog::buttonPosition( const int id ) const
530 if ( myPosition.contains( id ) )
531 pos = myPosition[id];
536 Name: setButtonPosition [public]
537 Desc: Sets the position for specified button(s). Following positions
538 may be used: Left, Right, Center, Top, Bottom.
541 void QtxDialog::setButtonPosition( const int pos, const int id )
543 ButtonMap map = buttons( id );
545 QMap<QObject*, int> changed;
546 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
548 if ( myPosition[it.key()] == pos )
551 myPosition[it.key()] = pos;
552 if ( button( it.key() ) )
553 changed.insert( button( it.key() )->parent(), 0 );
556 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
557 if ( changed.contains( itr.data() ) )
558 itr.data()->layoutButtons();
562 Name: setPlacePosition [public]
563 Desc: Sets button position for all buttons in given place.
566 void QtxDialog::setPlacePosition( const int pos, const int area )
568 if ( !myArea.contains( area ) )
571 Area* anArea = myArea[area];
573 bool changed = false;
574 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
576 if ( !anArea->contains( it.data() ) )
579 changed = changed && myPosition[it.key()] != pos;
581 myPosition[it.key()] = pos;
585 anArea->layoutButtons();
589 Name: placePolicy [public]
590 Desc: Returns policy of button layouting for specified place.
592 Following place may be used:
593 TopArea - Horizontal area in the top side of dialog.
594 BottomArea - Horizontal area in the bottom side of dialog.
595 LeftArea - Vertical area in the left side of dialog.
596 RightArea - Vertical area in the right side of dialog.
598 Following policy may be used:
599 Position - Buttons placed according their position.
600 Expand - Buttons fills all available space.
601 Uniform - Buttons uniformly placed in area.
604 int QtxDialog::placePolicy( const int area ) const
607 if ( myArea.contains( area ) )
608 res = myArea[area]->policy();
613 Name: setPlacePolicy [public]
614 Desc: Sets the policy of button layouting for specified place.
615 See also placePolicy().
618 void QtxDialog::setPlacePolicy( const int policy, const int area )
621 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
622 itr.data()->setPolicy( policy );
623 else if ( myArea.contains( area ) )
624 myArea[area]->setPolicy( policy );
628 Name: setButtonPlace [public]
629 Desc: Move given button(s) into specified place.
632 void QtxDialog::setButtonPlace( const int area, const int ids )
634 if ( !myArea.contains( area ) )
637 Area* anArea = myArea[area];
639 ButtonMap map = buttons( ids );
641 QMap<Area*, int> areaMap;
642 for ( AreaMap::ConstIterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt )
643 areaMap.insert( aIt.data(), 0 );
645 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
647 Area* old = (Area*)it.data()->parent();
651 if ( areaMap.contains( old ) )
652 old->removeButton( it.data() );
653 anArea->insertButton( it.data() );
658 Name: isBorderEnabled [public]
659 Desc: Returns true if border is shown for specified button area.
662 bool QtxDialog::isBorderEnabled( const int area ) const
665 if ( myArea.contains( area ) )
666 res = myArea[area]->isBorderEnabled();
671 Name: setBorderEnabled [public]
672 Desc: Show/hide border for specified button area. Border are
673 line which separate main frame and control buttons.
676 void QtxDialog::setBorderEnabled( const bool on, const int area )
678 if ( !myArea.contains( area ) )
681 if ( myArea[area]->isBorderEnabled() == on )
684 myArea[area]->setBorderEnabled( on );
688 QApplication::sendPostedEvents();
694 Name: isButtonEnabled [public]
695 Desc: Returns true if all specified button(s) is enabled.
698 bool QtxDialog::isButtonEnabled( const int f ) const
700 ButtonMap map = buttons( f );
701 bool result = !map.isEmpty();
702 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
703 result = result && it.data()->isEnabled();
708 Name: setButtonEnabled [public]
709 Desc: Enable/disable specified button(s).
712 void QtxDialog::setButtonEnabled( const bool on, const int ids )
714 ButtonMap map = buttons( ids );
715 for ( ButtonMap::Iterator it = map.begin(); it != map.end(); ++it )
716 it.data()->setEnabled( on );
720 Name: hasButtonFocus [public]
721 Desc: Retruns true if specified button has keyboard focus.
724 bool QtxDialog::hasButtonFocus( const int id ) const
727 QButton* pb = button( id );
729 res = pb->hasFocus();
734 Name: setButtonFocus [public]
735 Desc: Sets the keyboard focus on specified button.
738 void QtxDialog::setButtonFocus( const int id )
740 QButton* pb = button( id );
746 Name: buttonText [public]
747 Desc: Return text of specified button.
750 QString QtxDialog::buttonText( const int id )
753 QButton* but = button( id );
755 retval = but->text();
760 Name: setButtonText [public]
761 Desc: Sets text to specified button.
764 void QtxDialog::setButtonText( const int id, const QString& text )
766 QButton* but = button( id );
767 if ( but && but->text() != text )
769 but->setText( text );
775 Name: setAlignment [public]
776 Desc: Sets alignment policy. Returns the previous alignment.
777 Use the function before the first show of the dialog.
778 If dialog flag AlignOnce is setted then align will performed
779 only one time otherwise dialog will be aligned every time
780 when it shown. Dialog will be aligned relative to it parent.
782 Following align flags may be used:
783 Qtx::AlignAuto - Align to center of desktop (default).
784 Qtx::AlignLeft - Align left side of dialog to left side of parent.
785 Qtx::AlignRight - Align right side of dialog to right side of parent.
786 Qtx::AlignTop - Align top side of dialog to top side of parent.
787 Qtx::AlignBottom - Align bottom side of dialog to bottom side of parent.
788 Qtx::AlignHCenter - Align dialog to center of parent in horizontal dimension.
789 Qtx::AlignVCenter - Align dialog to center of parent in vertical dimension.
790 Qtx::AlignCenter - Align dialog to center of parent in both dimensions.
791 Qtx::AlignOutLeft - Align right side of dialog to left side of parent.
792 Qtx::AlignOutRight - Align left side of dialog to right side of parent.
793 Qtx::AlignOutTop - Align bottom side of dialog to top side of parent.
794 Qtx::AlignOutBottom - Align top side of dialog to bottom side of parent.
797 uint QtxDialog::setAlignment( uint align )
799 uint oldAlign = myAlignment;
805 Name: update [virtual public slot]
806 Desc: Updates dialog, show selected buttons and hide unselected.
809 void QtxDialog::update()
811 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
813 testButtonFlags( it.key() ) ? it.data()->show() : it.data()->hide();
815 for ( AreaMap::Iterator itr = myArea.begin(); itr != myArea.end(); ++itr )
816 itr.data()->layoutButtons();
824 Name: show [virtual public]
825 Desc: Show dialog, set keyboard focus on dialog.
828 void QtxDialog::show()
832 if ( testDialogFlags( SetFocus ) )
839 Name: hide [virtual public]
840 Desc: Hides dialog, processed all posted events.
843 void QtxDialog::hide()
846 qApp->processEvents();
850 Name: userButton [public]
851 Desc: Return user dialog button using specified identificator.
854 QButton* QtxDialog::userButton( const int id ) const
857 if ( id < -1 && myButton.contains( id ) )
863 Name: userButtonIds [public]
864 Desc: Return list of user dialog button identificators.
867 QValueList<int> QtxDialog::userButtonIds() const
869 QValueList<int> retlist;
870 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it )
872 retlist.append( it.key() );
877 Name: insertButton [public]
878 Desc: Add new user dialog button. Function return identificator of
879 newly added button in successfull case otherwise -1 will be returned.
882 int QtxDialog::insertButton( const QString& text, const int area )
884 if ( !myArea.contains( area ) )
888 while ( myButton.contains( id ) )
891 Area* anArea = myArea[area];
892 QButton* b = createButton( this );
896 myButton.insert( id, b );
897 myPosition.insert( id, Left );
899 connect( b, SIGNAL( clicked() ), this, SLOT( onButton() ) );
901 connect( b, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
904 anArea->insertButton( b );
914 Name: removeButton [public]
915 Desc: Remove user dialog button with specified identificator. If
916 identificator equal -1 then method will remove all user dialog buttons.
919 void QtxDialog::removeButton( const int id )
927 for ( ButtonMap::Iterator it = myButton.begin(); it != myButton.end(); ++it )
930 map.insert( it.key(), it.data() );
933 else if ( myButton.contains( id ) )
934 map.insert( id, myButton[id] );
936 for ( ButtonMap::Iterator itr = map.begin(); itr != map.end(); ++itr )
938 for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it )
939 it.data()->removeButton( itr.data() );
941 myButton.remove( itr.key() );
942 myPosition.remove( itr.key() );
950 Name: setUnits [static public]
951 Desc: Sets specified measure units in given label. Measure units close
952 in braces. If measure units not exist then they will be added.
954 1. Label contains text 'Radius'.
955 setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm)'
956 setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm)'
957 2. Label "aLabel" contains text 'Radius ():'.
958 setUnits( aLabel, "mm" ) => aLabel contains 'Radius (mm):'
959 setUnits( aLabel, "cm" ) => aLabel contains 'Radius (cm):'
962 void QtxDialog::setUnits( QLabel* aLabel, const QString& aUnits )
964 QString label = aLabel->text();
966 int end = label.findRev( ')' );
968 QString startLabel = label;
973 begin = label.left( end ).findRev( '(' );
976 startLabel = label.mid( 0, begin );
977 finalLabel = label.mid( end + 1 );
982 startLabel = startLabel.stripWhiteSpace();
983 if ( startLabel.at( startLabel.length() - 1 ) == ':' )
985 finalLabel = startLabel.mid( startLabel.length() - 1 );
986 startLabel = startLabel.mid( 0, startLabel.length() - 1 );
989 if ( aUnits.length() )
990 label = startLabel.stripWhiteSpace() +
991 " (" + aUnits + ") " + finalLabel.stripWhiteSpace();
993 label = startLabel.stripWhiteSpace() +
994 " " + finalLabel.stripWhiteSpace();
995 aLabel->setText( label );
999 Name: acceptData [virtual protected]
1000 Desc: If returns true dialog will be accepted and closed. This method
1001 called if dialog flag Accept is setted.
1004 bool QtxDialog::acceptData() const
1010 Name: rejectData [virtual protected]
1011 Desc: If returns true dialog will be rejected and closed. This method
1012 called if dialog flag Reject is setted.
1015 bool QtxDialog::rejectData() const
1021 Name: createButton [virtual protected]
1022 Desc: Create new user button. Invoked from method "insertButton".
1025 QButton* QtxDialog::createButton( QWidget* parent )
1027 QPushButton* pb = new QPushButton( parent );
1028 pb->setAutoDefault( false );
1033 Name: button [protected]
1034 Desc: Return pointer on control button specified by identifier.
1035 If identifier is wrong then null pointer will returned.
1038 QButton* QtxDialog::button( const int f ) const
1040 QButton* retval = 0;
1041 if ( myButton.contains( f ) )
1042 retval = myButton[f];
1047 Name: buttons [protected]
1048 Desc: Return map with control dialog buttons accordance to given button flags.
1051 QtxDialog::ButtonMap QtxDialog::buttons( const int f ) const
1056 if ( myButton.contains( f ) )
1057 retmap.insert( f, myButton[f] );
1061 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end(); ++it )
1062 if ( f == -1 || ( it.key() >= 0 && f & it.key() ) )
1063 retmap.insert( it.key(), it.data() );
1070 Name: buttonId [protected]
1071 Desc: Return identifier of specified button.
1074 int QtxDialog::buttonId( const QButton* b ) const
1077 for ( ButtonMap::ConstIterator it = myButton.begin(); it != myButton.end() && id == -1; ++it )
1078 if ( it.data() == b )
1084 Name: buttonPosition
1085 Desc: Returns position of specified button. [protected]
1088 int QtxDialog::buttonPosition( QButton* b ) const
1090 return buttonPosition( buttonId( b ) );
1094 Name: showEvent [virtual protected]
1095 Desc: Aligns this dialog according the parent widget and alignment
1096 policy before the show.
1099 void QtxDialog::showEvent( QShowEvent* e )
1101 if ( !testDialogFlags( AlignOnce ) || !myInited )
1102 Qtx::alignWidget( this, parentWidget(), myAlignment );
1103 QDialog::showEvent( e );
1107 Name: hideEvent [virtual protected]
1108 Desc: Process all existing events when dialog is closed.
1111 void QtxDialog::hideEvent( QHideEvent* e )
1113 qApp->processEvents();
1114 QDialog::hideEvent( e );
1118 Name: childEvent [virtual protected]
1119 Desc: Setting up layout when size grip is added.
1122 void QtxDialog::childEvent( QChildEvent* e )
1124 QDialog::childEvent( e );
1125 if ( layout() && e->inserted() && e->child()->inherits( "QSizeGrip" ) )
1127 layout()->setMargin( 12 );
1129 connect( e->child(), SIGNAL( destroyed() ), this, SLOT( onSizeGripDestroyed() ) );
1135 Name: keyPressEvent [virtual protected]
1136 Desc: Calls reject() if key Escape is pressed.
1137 Calls accept() if key "Ctrl+Enter" is pressed.
1138 Process key "F1" and emit signal dlgHelp().
1139 Transfer key "Ctrl+(Shift+)Tab" press event to Tab Widget.
1142 void QtxDialog::keyPressEvent( QKeyEvent* e )
1144 QDialog::keyPressEvent( e );
1145 if ( e->isAccepted() )
1148 if ( ( e->state() == 0 ) && ( e->key() == Key_Escape ) )
1151 if ( ( e->state() == ControlButton ) && ( e->key() == Key_Return ) )
1153 if ( testButtonFlags( OK ) || testButtonFlags( Yes ) )
1155 else if ( testButtonFlags( Apply ) && isButtonEnabled( Apply ) )
1160 if ( e->key() == Key_F1 && testButtonFlags( Help ) && isButtonEnabled( Help ) )
1166 if ( ( e->key() == Key_Tab ) && ( e->state() & ControlButton ) )
1168 QObject* tab = child( 0, "QTabWidget" );
1175 Name: closeEvent [virtual protected]
1176 Desc: Reject the dialog.
1179 void QtxDialog::closeEvent( QCloseEvent* )
1185 Name: accept [virtual protected slot]
1186 Desc: Invoke function acceptData() if it needed and if acceptData() return
1187 false does nothing. Otherwise hides the dialog and sets the result code
1188 to Accepted. Emit signal according to the pressed control button.
1191 void QtxDialog::accept()
1195 if ( testButtonFlags( OK ) )
1196 mySender = button( OK );
1197 else if ( testButtonFlags( Yes ) )
1198 mySender = button( Yes );
1200 mySender = button( Close );
1203 if ( !mySender || !mySender->isWidgetType() ||
1204 !((QWidget*)mySender)->isEnabled() )
1207 if ( testDialogFlags( Accept ) && !acceptData() )
1216 Name: reject [virtual protected slot]
1217 Desc: Invoke function rejectData() if it needed and if rejectData() return
1218 false does nothing. Otherwise hides the dialog and sets the result code
1219 to Rejected. Emit signal according to the pressed control button. (If
1220 dialog was closed by key Escape or by close event emit signal dlgCancel(),
1221 or dlgClose(), or dlgNo().
1224 void QtxDialog::reject()
1226 if ( testDialogFlags( Reject ) && !rejectData() )
1231 if ( testButtonFlags( Cancel ) )
1232 mySender = button( Cancel );
1233 else if ( testButtonFlags( No ) )
1234 mySender = button( No );
1236 mySender = button( Close );
1239 if ( !mySender || !mySender->isWidgetType() ||
1240 !((QWidget*)mySender)->isEnabled() )
1249 Name: reject [private]
1250 Desc: Emit signal appropriate to control button.
1253 void QtxDialog::emitSignal()
1255 qApp->processEvents();
1256 QApplication::syncX();
1258 int id = buttonId( (QButton*)mySender );
1282 Name: onAccept [private slot]
1283 Desc: Process signals "clicked()" from control buttons "OK", "Yes". Invoke accept().
1286 void QtxDialog::onAccept()
1288 const QObject* obj = sender();
1294 Name: onReject [private slot]
1295 Desc: Process signals "clicked()" from control buttons "Cancel", "No", "Close".
1299 void QtxDialog::onReject()
1301 const QObject* obj = sender();
1307 Name: onButton [private slot]
1308 Desc: Receive signal "clicked()" from user buttons and emit signal
1309 "dlgButton( int )" with identificator of clicked user button.
1312 void QtxDialog::onButton()
1314 int id = buttonId( (QButton*)sender() );
1316 emit dlgButton( id );
1320 Name: onDestroyed [private slot]
1321 Desc: Remove user button if it was destroyed.
1324 void QtxDialog::onDestroyed( QObject* obj )
1326 QButton* b = (QButton*)obj;
1327 int id = buttonId( b );
1331 myButton.remove( id );
1332 myPosition.remove( id );
1333 for ( AreaMap::Iterator it = myArea.begin(); it != myArea.end(); ++it )
1334 it.data()->removeButton( b );
1338 Name: onSizeGripDestroyed [private slot]
1339 Desc: Setting up layout when size grip is destroyed.
1342 void QtxDialog::onSizeGripDestroyed()
1345 layout()->setMargin( 5 );
1349 Name: adjustButtons [private]
1350 Desc: Setting the equal with for all buttons.
1353 void QtxDialog::adjustButtons()
1356 for ( AreaMap::Iterator aIt = myArea.begin(); aIt != myArea.end(); ++aIt )
1357 for ( QPtrListIterator<QButton> bIt( aIt.data()->buttons() ); bIt.current(); ++bIt )
1358 if ( bIt.current()->isVisibleTo( this ) )
1359 minWidth = QMAX( minWidth, bIt.current()->sizeHint().width() );
1361 for ( AreaMap::Iterator aItr = myArea.begin(); aItr != myArea.end(); ++aItr )
1362 for ( QPtrListIterator<QButton> bItr( aItr.data()->buttons() ); bItr.current(); ++bItr )
1363 if ( bItr.current()->isVisibleTo( this ) )
1364 bItr.current()->setMinimumWidth( minWidth );