00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <qlayout.h>
00031 #include <qlabel.h>
00032 #include <qlineedit.h>
00033 #include <qpushbutton.h>
00034 #include <qspinbox.h>
00035 #include <qcombobox.h>
00036 #include <qwidgetstack.h>
00037 #include <qvalidator.h>
00038 #include <qapplication.h>
00039
00040 #include "inputdlg.h"
00041 #include "global.h"
00042
00043
00044 InputDialog :: InputDialog( const QString &label, QWidget* parent, const char* name,
00045 bool modal )
00046 : QDialog( parent, name, modal )
00047 {
00048 lineEdit = 0;
00049
00050 QVBoxLayout *vbox = new QVBoxLayout( this, 6, 6 );
00051
00052 QLabel* l = new QLabel( label, this );
00053 vbox->addWidget( l );
00054
00055 lineEdit = new QLineEdit( this );
00056 vbox->addWidget( lineEdit );
00057
00058 QHBoxLayout *hbox = new QHBoxLayout( 6 );
00059 vbox->addLayout( hbox, AlignRight );
00060
00061 ok = new QPushButton( tr( "&OK" ), this );
00062 ok->setDefault( TRUE );
00063 QPushButton *cancel = new QPushButton( tr( "&Cancel" ), this );
00064
00065 QSize bs( ok->sizeHint() );
00066 if ( cancel->sizeHint().width() > bs.width() )
00067 bs.setWidth( cancel->sizeHint().width() );
00068
00069 ok->setFixedSize( bs );
00070 cancel->setFixedSize( bs );
00071
00072 hbox->addWidget( new QWidget( this ) );
00073 hbox->addWidget( ok );
00074 hbox->addWidget( cancel );
00075
00076 connect( lineEdit, SIGNAL( returnPressed() ),
00077 this, SLOT( tryAccept() ) );
00078 connect( lineEdit, SIGNAL( textChanged(const QString&) ),
00079 this, SLOT( textChanged(const QString&) ) );
00080
00081 connect( ok, SIGNAL( clicked() ), this, SLOT( accept() ) );
00082 connect( cancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00083
00084 resize( QMAX( sizeHint().width(), 240 ), sizeHint().height() );
00085 }
00086
00091 InputDialog::~InputDialog()
00092 {
00093 }
00094
00095 void InputDialog :: setText( const QString &text )
00096 {
00097 lineEdit->setText( text );
00098 lineEdit->selectAll();
00099 }
00100
00101 QString InputDialog :: getText()
00102 {
00103 return lineEdit->text();
00104 }
00105
00106 QString InputDialog::getText( const QString &caption, const QString &label,
00107 const QString &text, bool *ok, QWidget *parent,
00108 const char *name )
00109 {
00110 InputDialog *dlg = new InputDialog( label, parent, name, true );
00111 dlg->setCaption( caption );
00112 dlg->setText( text );
00113
00114 QString result;
00115 *ok = dlg->exec() == QDialog::Accepted;
00116 if ( *ok )
00117 result = dlg->getText();
00118
00119 delete dlg;
00120 return result;
00121 }
00122
00123
00124
00125 void InputDialog :: textChanged( const QString &s )
00126 {
00127 ok->setEnabled( !s.isEmpty() );
00128 }
00129
00130 void InputDialog :: tryAccept()
00131 {
00132 if ( !lineEdit->text().isEmpty() )
00133 accept();
00134 }