Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QtxDialog Class Reference

Generic dialog box class.

#include <QtxDialog.h>

Inheritance diagram for QtxDialog:
Inheritance graph

Classes

class  Area
 Area containing dialog box buttons. More...
 
class  Border
 Special label used as border widget (separator between main frame and button frame). More...
 

Public Types

enum  PlacePolicy { Position, Expand, Uniform }
 Buttons alignment type. More...
 
enum  ButtonArea { TopArea, BottomArea, LeftArea, RightArea }
 Buttons area. More...
 
enum  ButtonPosition {
  Left, Right, Center, Top = Left,
  Bottom = Right
}
 Button position. More...
 
enum  ButtonFlags {
  None = 0x00000000, OK = 0x00000001, Apply = 0x00000002, Cancel = 0x00000004,
  Yes = 0x00000008, No = 0x00000010, Close = 0x00000020, Help = 0x00000040,
  OKCancel = OK | Cancel, YesNo = Yes | No, Standard = OK | Cancel | Help, All = Standard | YesNo | Apply | Close
}
 Button ID flags. More...
 
enum  DialogFlags { Accept = 0x000001, Reject = 0x000002, AlignOnce = 0x000004, SetFocus = 0x000008 }
 Dialog box flags. More...
 

Public Slots

void update ()
 Update dialog box. More...
 
virtual void setVisible (bool)
 Show/hide dialog box, set keyboard focus to the dialog. More...
 

Signals

void dlgButton (int)
 Emitted when the user button is clicked. More...
 
void dlgParamChanged ()
 This signal can be used in successor classes to signalize about some dialog parameter changing. More...
 
void dlgHelp ()
 Emitted when the "Help" button is clicked. More...
 
void dlgApply ()
 Emitted when the "Apply" button is clicked. More...
 
void dlgOk ()
 Emitted when the "OK" button is clicked. More...
 
void dlgNo ()
 Emitted when the "No" button is clicked. More...
 
void dlgYes ()
 Emitted when the "Yes" button is clicked. More...
 
void dlgClose ()
 Emitted when the "Close" button is clicked. More...
 
void dlgCancel ()
 Emitted when the "Cancel" button is clicked. More...
 

Public Member Functions

 QtxDialog (QWidget *=0, bool=false, bool=false, const int=Standard, Qt::WindowFlags=0)
 Constructor. More...
 
virtual ~QtxDialog ()
 Destructor. More...
 
void setDialogFlags (const int)
 Set specified dialog box flags. More...
 
void clearDialogFlags (const int)
 Clear specified the dialog flags. More...
 
bool testDialogFlags (const int) const
 Test specified dialog flags. More...
 
void setButtonFlags (const int)
 Add specified control button(s) to the dialog box. More...
 
void clearButtonFlags (const int)
 Remove specified control button(s) from the dialog box. More...
 
bool testButtonFlags (const int) const
 Test specified buttons. More...
 
int buttonPosition (const int) const
 Get specified control button position. More...
 
void setButtonPosition (const int, const int=-1)
 Set the specified control button(s) position. More...
 
void setPlacePosition (const int, const int)
 Set button position for all buttons in specified area. More...
 
int placePolicy (const int) const
 Get buttons layouting policy for the specified area. More...
 
void setPlacePolicy (const int, const int)
 set buttons layouting policy for the specified area. More...
 
void setButtonPlace (const int, const int)
 Move specified button(s) into specified area. More...
 
QString buttonText (const int)
 Get specified button's text. More...
 
void setButtonText (const int, const QString &text)
 Set specified button's text. More...
 
void setButtonFocus (const int)
 Sets the keyboard focus to the specified button. More...
 
bool hasButtonFocus (const int) const
 Check if specified button has keyboard focus. More...
 
bool isButtonEnabled (const int) const
 Get "enabled" status of the specified button(s). More...
 
void setButtonEnabled (const bool, const int)
 Enable/disable specified button(s). More...
 
bool isBorderEnabled (const int) const
 Check if border is enabled. More...
 
void setBorderEnabled (const bool, const int)
 Show/hide border for the specified button area. More...
 
void removeButton (const int)
 Remove user button. More...
 
int insertButton (const QString &, const int=BottomArea)
 Add user button to the dialog box. More...
 
QIntList userButtonIds () const
 Get all user button IDs. More...
 
QAbstractButtonuserButton (const int) const
 Get user button by the specified id. More...
 
uint setAlignment (uint align)
 Sets alignment policy. More...
 

Static Public Member Functions

static void setUnits (QLabel *, const QString &)
 Set measure units to the specified label. More...
 

Protected Types

typedef QMap< int,
QAbstractButton * > 
ButtonMap
 button map More...
 

Protected Slots

virtual void accept ()
 Accept the dialog box. More...
 
virtual void reject ()
 Reject the dialog box. More...
 

Protected Member Functions

QFramemainFrame () const
 Get dialog box main frame widget. More...
 
virtual bool acceptData () const
 Check if data entered by the user is valid. More...
 
virtual bool rejectData () const
 Check if dialog box can be cancelled. More...
 
virtual QAbstractButtoncreateButton (QWidget *)
 Create new user button. More...
 
QAbstractButtonbutton (const int) const
 Get button by the specified ID. More...
 
ButtonMap buttons (const int=All) const
 Get buttons by the specified IDs. More...
 
int buttonId (const QAbstractButton *) const
 Get specified button's identifier. More...
 
int buttonPosition (QAbstractButton *) const
 Get position of specified button. More...
 
virtual void showEvent (QShowEvent *)
 Align this dialog according to the parent widget and alignment policy before the dialog box is shown. More...
 
virtual void hideEvent (QHideEvent *)
 Process all existing events when dialog box is hidden. More...
 
virtual void closeEvent (QCloseEvent *)
 Called when user closes dialog box. More...
 
virtual void childEvent (QChildEvent *)
 Update dialog box layout when the size grip is added. More...
 
virtual void keyPressEvent (QKeyEvent *)
 Process key pressing event. More...
 

Private Types

typedef QMap< int, Area * > AreaMap
 button area map More...
 
typedef QMap< int, int > PositionMap
 button position map More...
 

Private Slots

void onAccept ()
 This slot is called when user presses on of the buttons "OK", "Yes", etc. More...
 
void onReject ()
 This slot is called when user presses on of the buttons "Cancel", "No", "Close". More...
 
void onButton ()
 Process user button click event. More...
 
void onSizeGripDestroyed ()
 Update dialog box layout when the size grip is destroyed. More...
 
void onDestroyed (QObject *)
 Watch for the user button destroying. More...
 

Private Member Functions

void adjustButtons ()
 Adjust buttons (set equal size for all buttons). More...
 
void emitSignal ()
 Emit signal correspondingly to the control button. More...
 

Private Attributes

AreaMap myArea
 buttons areas map More...
 
ButtonMap myButton
 buttons map More...
 
PositionMap myPosition
 buttons position map More...
 
bool myInited
 dialog's "initialized" flag More...
 
const QObjectmySender
 signal sender More...
 
uint myAlignment
 dialog box alignment type More...
 
QFramemyMainFrame
 main frame More...
 
int myButtonFlags
 button flags More...
 
int myDialogFlags
 dialog flags More...
 

Friends

class Area
 

Member Typedef Documentation

typedef QMap<int, Area*> QtxDialog::AreaMap
private
typedef QMap<int, QAbstractButton*> QtxDialog::ButtonMap
protected
typedef QMap<int, int> QtxDialog::PositionMap
private

Member Enumeration Documentation

Enumerator
TopArea 

horizontal area at the top side of the dialog box

BottomArea 

horizontal area at the bottom side of the dialog box

LeftArea 

vertical area at the left side of the dialog box

RightArea 

vertical area at the right side of the dialog box

Enumerator
None 

no button used

OK 

OK button.

Apply 

Apply button.

Cancel 

Cancel button.

Yes 

Yes button.

No 

No button.

Close 

Close button.

Help 

Help button.

OKCancel 

OK & Cancel button.

YesNo 

Yes & No buttons.

Standard 

OK, Cancel & Help buttons.

All 

all buttons

Enumerator
Left 

set button left-most

Right 

set button right-most

Center 

place button in the center

Top 

set button top-most

Bottom 

set button bottom-most

Enumerator
Accept 

allow dialog box accepting control

Reject 

allow dialog box rejecting control

AlignOnce 

align dialog box only when it is first time shown

SetFocus 

allow to set focus on dialog box when it is shown (user can use setFocusProxy() and specify own initial focus widget)

Enumerator
Position 

buttons are placed according their position

Expand 

buttons occupy all available space

Uniform 

buttons are uniformly placed in the area

Constructor & Destructor Documentation

QtxDialog::QtxDialog ( QWidget parent = 0,
bool  modal = false,
bool  allowResize = false,
const int  f = Standard,
Qt::WindowFlags  wf = 0 
)

Construct a dialog with specified parent and name. By default non-modal, non-resizable with the OK, Cancel and Help buttons dialog box is created.

Parameters
parentparent widget
modalif true dialog box is modal
allowResizeif true then dialog can be resized by user
fspecified control buttons for dialog box (QtxDialog::ButtonFlags)
wfdialog box flags (Qt::WindowFlags)

References All, Apply, Area, BottomArea, Cancel, Center, Close, dlgApply(), dlgHelp(), Help, Horizontal, Left, LeftArea, main(), myArea, myButton, myButtonFlags, myMainFrame, No, OK, onAccept(), onDestroyed(), onReject(), Right, RightArea, QtxDialog::Area::setBorderWidget(), setButtonPlace(), setButtonPosition(), TopArea, update(), Vertical, and Yes.

QtxDialog::~QtxDialog ( )
virtual

Member Function Documentation

void QtxDialog::accept ( )
protectedvirtualslot

This method is used when any accept button is pressed (usually "OK", "Yes", etc).

If dialog flag QtxDialog::Accept is set, this function invokes acceptData() method, which should in this case return true to allow further processing.

If acceptData() returns false, this function just returns.

If acceptData() returns true, the Accepted result is set and signal according to the pressed control button is emitted. Then the default implementation of accept() method is called (which hides the dialog box and, depending on the dialog box flags, can close and destroy it).

See Also
acceptData()

Reimplemented in Style_PrefDlg, and LightApp_PreferencesDlg.

References Accept, acceptData(), button(), Close, emitSignal(), mySender, OK, testButtonFlags(), testDialogFlags(), and Yes.

bool QtxDialog::acceptData ( ) const
protectedvirtual

This method can be re-implemented in the successor class if it requires to check user input consistency. Default implementation returns true.

This method is called if dialog flag QtxDialog::Accept is set. If this method returns true, then dialog will be accepted and closed.

Returns
true if user input is valid
See Also
accept()

Reimplemented in QtxPathDialog.

void QtxDialog::adjustButtons ( )
private

References myArea.

QAbstractButton * QtxDialog::button ( const int  f) const
protected
Parameters
fcontrol button ID (QtxDialog::ButtonFlags)
Returns
button or 0 if id is invalid

References myButton.

int QtxDialog::buttonId ( const QAbstractButton b) const
protected
Parameters
bbutton
Returns
button ID

References myButton.

int QtxDialog::buttonPosition ( const int  id) const
Parameters
idcontrol button ID (QtxDialog::ButtonFlags)
Returns
button's position (QtxDialog::ButtonPosition) or -1 if it is not set or invalid id is given
See Also
setButtonPosition()

References myPosition.

int QtxDialog::buttonPosition ( QAbstractButton b) const
protected
Parameters
bbutton
Returns
button position (QtxDialog::ButtonPosition)

References buttonId(), and buttonPosition().

QtxDialog::ButtonMap QtxDialog::buttons ( const int  f = All) const
protected
Parameters
fcontrol button(s) ID(s) (QtxDialog::ButtonFlags)
Returns
button map

References myButton.

QString QtxDialog::buttonText ( const int  id)
Parameters
idcontrol button ID (QtxDialog::ButtonFlags)
Returns
button's text
See Also
setButtonText()

References button().

void QtxDialog::childEvent ( QChildEvent *  e)
protectedvirtual

Re-implemented from Qt.

Parameters
echild event

References onSizeGripDestroyed().

void QtxDialog::clearButtonFlags ( const int  f)
Parameters
fORed buttons flags (Qtx::ButtonFlags)
See Also
setButtonFlags(), testButtonFlags()

References myButtonFlags, and update().

void QtxDialog::clearDialogFlags ( const int  f)
Parameters
fdialog box flags (QtxDialog::DialogFlags)
See Also
setDialogFlags(), testDialogFlags()

References myDialogFlags.

void QtxDialog::closeEvent ( QCloseEvent *  )
protectedvirtual

Call reject() method.

Parameters
eclose event (not used)

References reject().

QAbstractButton * QtxDialog::createButton ( QWidget parent)
protectedvirtual

This method is invoked from method insertButton().

Parameters
parentparent widget
Returns
new user button
void QtxDialog::dlgApply ( )
signal
void QtxDialog::dlgButton ( int  id)
signal
Parameters
iduser button identificator
void QtxDialog::dlgCancel ( )
signal
void QtxDialog::dlgClose ( )
signal
void QtxDialog::dlgHelp ( )
signal
void QtxDialog::dlgNo ( )
signal
void QtxDialog::dlgOk ( )
signal
void QtxDialog::dlgParamChanged ( )
signal
void QtxDialog::dlgYes ( )
signal
void QtxDialog::emitSignal ( )
private
bool QtxDialog::hasButtonFocus ( const int  id) const
Parameters
idcontrol button ID (QtxDialog::ButtonFlags)
Returns
true if specified button has keyboard focus
See Also
setButtonFocus()

References button().

void QtxDialog::hideEvent ( QHideEvent *  e)
protectedvirtual

Re-implemented from Qt.

Parameters
ehide event
int QtxDialog::insertButton ( const QString &  text,
const int  area = BottomArea 
)

The button is inserted to the specified dialog box area. if the button is added successfully, the unique identificator of the added button is returned, otherwise -1 is returned.

Parameters
texttext of the added button
areabuttons area (QtxDialog::ButtonArea)
Returns
button ID
See Also
removeButton(), userButton(), userButtonIds()

References createButton(), QtxDialog::Area::insertButton(), Left, myArea, myButton, myPosition, onButton(), onDestroyed(), and update().

bool QtxDialog::isBorderEnabled ( const int  area) const
Parameters
areabuttons area (QtxDialog::ButtonArea)
Returns
true if border is enabled for specified button area.
See Also
setBorderEnabled()

References myArea.

bool QtxDialog::isButtonEnabled ( const int  id) const
Parameters
idcontrol button(s) ID (QtxDialog::ButtonFlags)
Returns
true if all specified buttons are enabled.
See Also
setButtonEnabled()

References buttons().

void QtxDialog::keyPressEvent ( QKeyEvent *  e)
protectedvirtual

Re-implemented from Qt.

Call reject() if "Escape" key is pressed. Call accept() if "Ctrl+Enter" key-sequence is pressed. Process "F1" key and emit signal dlgHelp(). Transfer "Ctrl+(Shift+)Tab" key-sequence press event to the child Tab widget (if there is any).

Parameters
ekey press event

Reimplemented in VTKViewer_MarkerDlg.

References accept(), Apply, dlgApply(), dlgHelp(), Help, isButtonEnabled(), OK, reject(), testButtonFlags(), and Yes.

QFrame * QtxDialog::mainFrame ( ) const
protected

Main frame is an internal widget which should contains all elements of dialog box except control buttons.

Returns
main frame widget

References myMainFrame.

void QtxDialog::onAccept ( )
privateslot

Call accept() method.

References accept(), mySender, and obj.

void QtxDialog::onButton ( )
privateslot

This method is called when user presses one of custom user buttons. Emits signal dlgButton(int) with identificator of the clicked user button passed as parameter.

References buttonId(), and dlgButton().

void QtxDialog::onDestroyed ( QObject obj)
privateslot
Parameters
objbutton being destroyed

References buttonId(), myArea, myButton, and myPosition.

void QtxDialog::onReject ( )
privateslot

Call reject() method.

References mySender, obj, and reject().

void QtxDialog::onSizeGripDestroyed ( )
privateslot
int QtxDialog::placePolicy ( const int  area) const
Parameters
areabuttons area (QtxDialog::ButtonArea)
See Also
setPlacePolicy()

References myArea.

void QtxDialog::reject ( )
protectedvirtualslot

This method is used when any reject button is pressed (usually "Close", "Cancel", "No", etc).

If dialog flag QtxDialog::Reject is set, this function invokes rejectData() method, which should in this case return true to allow further processing.

If rejectData() returns false, this function just returns.

If rejectData() returns true, the Rejected result is set and signal according to the pressed control button is emitted. Then the default implementation of reject() method is called (which hides the dialog box and, depending on the dialog box flags, can close and destroy it).

See Also
rejectData()

Reimplemented in LightApp_PreferencesDlg.

References button(), Cancel, Close, emitSignal(), mySender, No, Reject, rejectData(), testButtonFlags(), and testDialogFlags().

bool QtxDialog::rejectData ( ) const
protectedvirtual

This method can be re-implemented in the successor class if it requires to check possibility to cancel dialog box safely. Default implementation returns true.

This method is called if dialog flag QtxDialog::Reject is set. If this method returns true, then dialog will be rejected and closed.

Returns
true if dialog box can be cancelled
See Also
reject()
void QtxDialog::removeButton ( const int  id)

If id is -1, all user buttons are removed.

Parameters
iduser button ID
See Also
insertButton(), userButton(), userButtonIds()

References myArea, myButton, myPosition, and update().

uint QtxDialog::setAlignment ( uint  align)

Use the function before the the dialog is first time shown. If dialog flag AlignOnce is set then alignment is performed only once, otherwise the dialog is aligned each time when it is shown. Dialog box is aligned relatively to its parent. By default, dialog box is aligned to the center of the parent widget (usually desktop or another dialog box).

Parameters
alignalignment flag(s) (Qtx::AlignmentFlags)
Returns
previous alignment policy

References myAlignment.

void QtxDialog::setBorderEnabled ( const bool  on,
const int  area 
)

Border is a line which separate main frame and control buttons.

Parameters
areabuttons area (QtxDialog::ButtonArea)
onenable border flag
See Also
isBorderEnabled()

References isBorderEnabled(), and myArea.

void QtxDialog::setButtonEnabled ( const bool  on,
const int  id 
)
Parameters
onenable button(s) flag
idcontrol button(s) ID (QtxDialog::ButtonFlags)
See Also
isButtonEnabled()

References buttons().

void QtxDialog::setButtonFlags ( const int  f)
Parameters
fORed buttons flags (Qtx::ButtonFlags)
See Also
clearButtonFlags(), testButtonFlags()

References myButtonFlags, and update().

void QtxDialog::setButtonFocus ( const int  id)
Parameters
idcontrol button ID (QtxDialog::ButtonFlags)
See Also
hasButtonFocus()

References button().

void QtxDialog::setButtonPlace ( const int  area,
const int  id 
)
Parameters
areabuttons area (QtxDialog::ButtonArea)
idcontrol button(s) ID (QtxDialog::ButtonFlags)

References buttons(), QtxDialog::Area::insertButton(), myArea, and QtxDialog::Area::removeButton().

void QtxDialog::setButtonPosition ( const int  pos,
const int  id = -1 
)
Parameters
idcontrol button(s) ID (QtxDialog::ButtonFlags)
posbutton(s) position (QtxDialog::ButtonPosition)

References button(), buttons(), myArea, and myPosition.

void QtxDialog::setButtonText ( const int  id,
const QString &  text 
)
Parameters
idcontrol button ID (QtxDialog::ButtonFlags)
textbutton's text
See Also
buttonText()

References adjustButtons(), and button().

void QtxDialog::setDialogFlags ( const int  f)
void QtxDialog::setPlacePolicy ( const int  policy,
const int  area 
)
Parameters
policybuttons layouting policy (QtxDialog::PlacePolicy)
areabuttons area (QtxDialog::ButtonArea)
See Also
placePolicy()

References myArea.

void QtxDialog::setPlacePosition ( const int  pos,
const int  area 
)
void QtxDialog::setUnits ( QLabel aLabel,
const QString &  aUnits 
)
static

In the dialog box label the measure units are closed in braces. If measure units do not exist they will be added.

For example:

// create label "Radius"
QLabel* aLabel = new QLabel( "Radius", mainFrame() );
// set measure units to "mm"
setUnits( aLabel, "mm" ) // => aLabel contains 'Radius (mm)'
// set measure units to "cm"
setUnits( aLabel, "cm" ) // => aLabel contains 'Radius (cm)'
// create label "Radius" with initially not set measure units
QLabel* aLabel = new QLabel( "Radius ():", mainFrame() );
// set measure units to "mm"
setUnits( aLabel, "mm" ) // => aLabel contains 'Radius (mm):'
// set measure units to "cm"
setUnits( aLabel, "cm" ) // => aLabel contains 'Radius (cm):'
Parameters
aLabellabel widget
aUnitsmeasure units
void QtxDialog::setVisible ( bool  on)
virtualslot

Re-implemented from Qt.

Parameters
onshow/hide flag

Reimplemented in LightApp_PreferencesDlg.

References myInited, SetFocus, and testDialogFlags().

void QtxDialog::showEvent ( QShowEvent *  e)
protectedvirtual

Re-implemented from Qt.

Parameters
eshow event

References AlignOnce, Qtx::alignWidget(), myAlignment, myInited, and testDialogFlags().

bool QtxDialog::testButtonFlags ( const int  f) const
Returns
true if specified control buttons are used in the dialog box
See Also
setButtonFlags(), clearButtonFlags()

References myButtonFlags.

bool QtxDialog::testDialogFlags ( const int  f) const
Returns
true if specified dialog box falgs are set
See Also
setDialogFlags(), clearDialogFlags()

References myDialogFlags.

void QtxDialog::update ( )
slot
QAbstractButton * QtxDialog::userButton ( const int  id) const
Parameters
iduser button ID
Returns
user button or 0 if it is not found
See Also
insertButton(), removeButton(), userButtonIds()

References myButton.

QIntList QtxDialog::userButtonIds ( ) const
Returns
list of user buttons identificators
See Also
insertButton(), removeButton(), userButton()

References myButton.

Friends And Related Function Documentation

friend class Area
friend

Member Data Documentation

uint QtxDialog::myAlignment
private
AreaMap QtxDialog::myArea
private
ButtonMap QtxDialog::myButton
private
int QtxDialog::myButtonFlags
private
int QtxDialog::myDialogFlags
private
bool QtxDialog::myInited
private
QFrame* QtxDialog::myMainFrame
private
PositionMap QtxDialog::myPosition
private
const QObject* QtxDialog::mySender
private

The documentation for this class was generated from the following files: