Source Code (Use browser search to find items of interest.)
Class Index
qt'QDialog (./qt-2.1.0/src/kernel/qdialog.h:39)
class Q_EXPORT QDialog : public QWidget // dialog widget
{
friend class QPushButton;
Q_OBJECT
public:
QDialog( QWidget *parent=0, const char *name=0, bool modal=FALSE,
WFlags f=0 );
~QDialog();
enum DialogCode { Rejected, Accepted };
int exec();
int result() const { return rescode; }
void show();
void hide();
void move( int x, int y );
void move( const QPoint &p );
void resize( int w, int h );
void resize( const QSize & );
void setGeometry( int x, int y, int w, int h );
void setGeometry( const QRect & );
protected slots:
virtual void done( int );
virtual void accept();
virtual void reject();
protected:
void setResult( int r ) { rescode = r; }
void keyPressEvent( QKeyEvent * );
void closeEvent( QCloseEvent * );
private:
virtual void setDefault( QPushButton * ); // ## remove virtual 3.0
void hideDefault();
int rescode;
uint did_move : 1;
uint did_resize : 1;
QPushButton* mainDef;
private: // Disabled copy constructor and operator=
#if defined(Q_DISABLE_COPY)
QDialog( const QDialog & );
QDialog &operator=( const QDialog & );
#endif
};
qt'QDialog::QDialog() (./qt-2.1.0/src/kernel/qdialog.cpp:119)
QDialog::QDialog( QWidget *parent, const char *name, bool modal, WFlags f )
: QWidget( parent, name, (modal ? (f | WType_Modal) : f) | WType_TopLevel | WStyle_Dialog )
{
rescode = 0;
did_move = FALSE;
did_resize = FALSE;
mainDef = 0;
}
/*!
Destructs the QDialog, deleting all its children.
*/
qt'QDialog::~QDialog() (./qt-2.1.0/src/kernel/qdialog.cpp:132)
QDialog::~QDialog()
{
// Need to hide() here, as our (to-be) overridden hide()
// will not be called in ~QWidget.
hide();
}
/*!
\internal
This function is called by the push button \e pushButton when it
becomes the default button. If \a pushButton is 0, the dialogs
default default button becomes the default button. This is what a
push button calls when it looses focus.
*/
qt'QDialog::setDefault() (./qt-2.1.0/src/kernel/qdialog.cpp:147)
void QDialog::setDefault( QPushButton *pushButton )
{
QObjectList *list = queryList( "QPushButton" );
QObjectListIt it( *list );
QPushButton *pb;
bool hasMain = FALSE;
while ( (pb = (QPushButton*)it.current()) ) {
++it;
if ( pb == mainDef )
hasMain = TRUE;
if ( pb != pushButton )
pb->setDefault( FALSE );
}
if (!pushButton && hasMain)
mainDef->setDefault( TRUE );
if (!hasMain)
mainDef = pushButton;
delete list;
}
/*!
\internal
Hides the default button indicator. Called when non auto-default
push button get focus.
*/
qt'QDialog::hideDefault() (./qt-2.1.0/src/kernel/qdialog.cpp:172)
void QDialog::hideDefault()
{
QObjectList *list = queryList( "QPushButton" );
QObjectListIt it( *list );
QPushButton *pb;
while ( (pb = (QPushButton*)it.current()) ) {
++it;
pb->setDefault( FALSE );
}
}
/*!
\fn int QDialog::result() const
Returns the result code of the dialog.
*/
/*!
\fn void QDialog::setResult( int )
Sets the result code of the dialog.
*/
/*!
For modal dialogs: Starts the dialog and returns the result code.
Equivalent to calling show(), then result().
This function is very useful for modal dialogs, but makes no sense for
modeless dialog. It enters a new local event loop. The event loop is
terminated when the dialog is hidden, usually by calling done().
A warning message is printed if you call this function for a modeless
dialog.
\sa show(), result()
*/
qt'QDialog::exec() (./qt-2.1.0/src/kernel/qdialog.cpp:212)
int QDialog::exec()
{
#if defined(CHECK_STATE)
if ( !testWFlags(WType_Modal) )
qWarning( "QDialog::exec: Calling this function for a modeless dialog "
"makes no sense" );
#endif
setResult( 0 );
show();
return result();
}
/*!
Closes the dialog and sets the result code to \e r.
Equivalent to calling hide(), then setResult(\e r ).
This function is very useful for modal dialogs. It leaves the local
event loop and returns from the exec() or show() function.
\warning Although done() will return to the caller also if this
dialog is modal, the local event loop is then marked for
termination. Hence, a program should not try to do anything that
depends on event handling before the corresponding exec() or show()
has returned.
\sa accept(), reject()
*/
qt'QDialog::done() (./qt-2.1.0/src/kernel/qdialog.cpp:242)
void QDialog::done( int r )
{
hide();
setResult( r );
}
/*!
Closes the dialog and sets the result code to \c Accepted.
Equivalent to done(Accepted);
*/
qt'QDialog::accept() (./qt-2.1.0/src/kernel/qdialog.cpp:254)
void QDialog::accept()
{
done( Accepted );
}
/*!
Closes the dialog and sets the result code to \c Rejected.
Equivalent to done(Rejected);
*/
qt'QDialog::reject() (./qt-2.1.0/src/kernel/qdialog.cpp:265)
void QDialog::reject()
{
done( Rejected );
}
/*****************************************************************************
Event handlers
*****************************************************************************/
/*!\reimp
*/
qt'QDialog::keyPressEvent() (./qt-2.1.0/src/kernel/qdialog.cpp:277)
void QDialog::keyPressEvent( QKeyEvent *e )
{
// Calls reject() if Escape is pressed. Simulates a button click
// for the default button if Enter is pressed. All other keys are
// ignored.
if ( e->state() == 0 ) {
switch ( e->key() ) {
case Key_Enter:
case Key_Return: {
QObjectList *list = queryList( "QPushButton" );
QObjectListIt it( *list );
QPushButton *pb;
while ( (pb = (QPushButton*)it.current()) ) {
if ( pb->isDefault() && pb->isVisible() ) {
delete list;
if ( pb->isEnabled() ) {
emit pb->clicked();
}
return;
}
++it;
}
delete list;
}
break;
case Key_Escape:
reject();
break;
case Key_Up:
case Key_Left:
if ( focusWidget() &&
( focusWidget()->focusPolicy() == QWidget::StrongFocus ||
focusWidget()->focusPolicy() == QWidget::WheelFocus ) ) {
e->ignore();
break;
}
// call ours, since c++ blocks us from calling the one
// belonging to focusWidget().
focusNextPrevChild( FALSE );
break;
case Key_Down:
case Key_Right:
if ( focusWidget() &&
( focusWidget()->focusPolicy() == QWidget::StrongFocus ||
focusWidget()->focusPolicy() == QWidget::WheelFocus ) ) {
e->ignore();
break;
}
focusNextPrevChild( TRUE );
break;
default:
e->ignore();
return;
}
} else {
e->ignore();
}
}
/*!
Calls reject() if it is a modal dialog, or accepts the close event
if it is a modeless dialog.
*/
qt'QDialog::closeEvent() (./qt-2.1.0/src/kernel/qdialog.cpp:341)
void QDialog::closeEvent( QCloseEvent *e )
{
e->accept();
reject(); // same as Cancel
}
/*****************************************************************************
Geometry management.
*****************************************************************************/
/*!
Shows the dialog box on the screen, as QWidget::show() and enters a
local event loop if this dialog is modal (see constructor).
This implementation also does automatic resizing and automatic
positioning. If you have not already resized or moved the dialog, it
will find a size that fits the contents and a position near the middle
of the screen (or centered relative to the parent widget if any).
\warning Calling show() for a modal dialog enters a local event loop.
The event loop is terminated when the dialog is hidden, usually by
calling done().
\sa exec()
*/
qt'QDialog::show() (./qt-2.1.0/src/kernel/qdialog.cpp:368)
void QDialog::show()
{
if ( testWState(WState_Visible) )
return;
if ( !did_resize )
adjustSize();
if ( !did_move ) {
QWidget *w = parentWidget();
QPoint p( 0, 0 );
int extraw = 0, extrah = 0;
QWidget * desk = QApplication::desktop();
if ( w )
w = w->topLevelWidget();
QWidgetList *list = QApplication::topLevelWidgets();
QWidgetListIt it( *list );
while ( (extraw == 0 || extrah == 0) &&
it.current() != 0 ) {
int w, h;
QWidget * current = it.current();
++it;
w = current->geometry().x() - current->x();
h = current->geometry().y() - current->y();
extraw = QMAX( extraw, w );
extrah = QMAX( extrah, h );
}
delete list;
if ( w )
p = QPoint( w->geometry().x() + w->width()/2,
w->geometry().y() + w->height()/ 2 );
else
p = QPoint( desk->width()/2, desk->height()/2 );
p = QPoint( p.x()-width()/2 - extraw,
p.y()-height()/2 - extrah );
if ( p.x() + extraw + width() > desk->width() )
p.setX( desk->width() - width() - extraw );
if ( p.x() < 0 )
p.setX( 0 );
if ( p.y() + extrah + height() > desk->height() )
p.setY( desk->height() - height() - extrah );
if ( p.y() < 0 )
p.setY( 0 );
move( p );
}
QWidget::show();
if ( testWFlags(WType_Modal) )
qApp->enter_loop();
}
/*!\reimp
*/
qt'QDialog::hide() (./qt-2.1.0/src/kernel/qdialog.cpp:425)
void QDialog::hide()
{
// Reimplemented to exit a modal when the dialog is hidden.
bool ex = testWState(WState_Visible) && testWFlags(WType_Modal);
QWidget::hide();
if ( ex )
qApp->exit_loop();
}
/*****************************************************************************
Detects any widget geometry changes done by the user.
*****************************************************************************/
/*!
Reimplements QWidget::move() for internal purposes.
*/
qt'QDialog::move() (./qt-2.1.0/src/kernel/qdialog.cpp:443)
void QDialog::move( int x, int y )
{
did_move = TRUE;
QWidget::move( x, y );
}
/*!
Reimplements QWidget::move() for internal purposes.
*/
qt'QDialog::move() (./qt-2.1.0/src/kernel/qdialog.cpp:453)
void QDialog::move( const QPoint &p )
{
did_move = TRUE;
QWidget::move( p );
}
/*!
Reimplements QWidget::resize() for internal purposes.
*/
qt'QDialog::resize() (./qt-2.1.0/src/kernel/qdialog.cpp:463)
void QDialog::resize( int w, int h )
{
did_resize = TRUE;
QWidget::resize( w, h );
}
/*!
Reimplements QWidget::resize() for internal purposes.
*/
qt'QDialog::resize() (./qt-2.1.0/src/kernel/qdialog.cpp:473)
void QDialog::resize( const QSize &s )
{
did_resize = TRUE;
QWidget::resize( s );
}
/*!
Reimplements QWidget::setGeometry() for internal purposes.
*/
qt'QDialog::setGeometry() (./qt-2.1.0/src/kernel/qdialog.cpp:483)
void QDialog::setGeometry( int x, int y, int w, int h )
{
did_move = TRUE;
did_resize = TRUE;
QWidget::setGeometry( x, y, w, h );
}
/*!
Reimplements QWidget::setGeometry() for internal purposes.
*/
qt'QDialog::setGeometry() (./qt-2.1.0/src/kernel/qdialog.cpp:494)
void QDialog::setGeometry( const QRect &r )
{
did_move = TRUE;
did_resize = TRUE;
QWidget::setGeometry( r );
}