Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

inputdlg.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the OPIE Project
00003                              
00004                =.            Copyright (c)  2002 Andy Qua <andy.qua@blueyonder.co.uk>
00005              .=l.                                Dan Williams <drw@handhelds.org>
00006            .>+-=
00007  _;:,     .>    :=|.         This file is free software; you can
00008 .> <`_,   >  .   <=          redistribute it and/or modify it under
00009 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00010 .="- .-=="i,     .._         License as published by the Free Software
00011  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00012      ._= =}       :          or (at your option) any later version.
00013     .%`+i>       _;_.
00014     .i_,=:_.      -<s.       This file is distributed in the hope that
00015      +  .  -:.       =       it will be useful, but WITHOUT ANY WARRANTY;
00016     : ..    .:,     . . .    without even the implied warranty of
00017     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00018   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU General
00019 ..}^=.=       =       ;      Public License for more details.
00020 ++=   -.     .`     .:
00021  :     =  ...= . :.=-        You should have received a copy of the GNU
00022  -.   .:....=;==+<;          General Public License along with this file;
00023   -_. . .   )=.  =           see the file COPYING. If not, write to the
00024     --        :-=`           Free Software Foundation, Inc.,
00025                              59 Temple Place - Suite 330,
00026                              Boston, MA 02111-1307, USA.
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 }

Generated on Sat Nov 5 16:17:46 2005 for OPIE by  doxygen 1.4.2