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
00031 #include "entrydlg.h"
00032
00033 #include <opie2/ofiledialog.h>
00034 #include <opie2/oresource.h>
00035
00036 #include <qpe/qpeapplication.h>
00037
00038 #include <qlabel.h>
00039 #include <qlayout.h>
00040 #include <qlineedit.h>
00041 #include <qpushbutton.h>
00042
00043 EntryDlg::EntryDlg( const QString &label, QWidget* parent, const char* name, bool modal )
00044 : QDialog( parent, name, modal )
00045 {
00046 QGridLayout *layout = new QGridLayout( this, 3, 2, 2, 4 );
00047
00048 QLabel *l = new QLabel( label, this );
00049 l->setAlignment( AlignLeft | AlignTop | WordBreak );
00050 layout->addMultiCellWidget( l, 0, 0, 0, 1 );
00051
00052 m_entry = new QLineEdit( this );
00053 layout->addWidget( m_entry, 1, 0 );
00054 connect( m_entry, SIGNAL(returnPressed()), this, SLOT(slotTryAccept()) );
00055
00056 QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "folder", Opie::Core::OResource::SmallIcon ),
00057 QString::null, this );
00058 btn->setMinimumHeight( AppLnk::smallIconSize()+4 );
00059 btn->setMaximumWidth( btn->height() );
00060 connect( btn, SIGNAL(clicked()), this, SLOT(slotSelectPath()) );
00061 layout->addWidget( btn, 1, 1 );
00062
00063 layout->setRowStretch( 2, 10 );
00064
00065 resize( width(), l->height() + btn->height() + 8 );
00066 }
00067
00068 void EntryDlg::setText( const QString &text )
00069 {
00070 m_entry->setText( text );
00071 m_entry->selectAll();
00072 }
00073
00074 QString EntryDlg::getText()
00075 {
00076 return m_entry->text();
00077 }
00078
00079 QString EntryDlg::getText( const QString &caption, const QString &label, const QString &text, bool *ok,
00080 QWidget *parent, const char *name )
00081 {
00082 EntryDlg *dlg = new EntryDlg( label, parent, name, true );
00083 dlg->setCaption( caption );
00084 dlg->setText( text );
00085
00086 QString result;
00087
00088 *ok = ( QPEApplication::execDialog( dlg ) == QDialog::Accepted );
00089 if ( *ok )
00090 result = dlg->getText();
00091
00092 delete dlg;
00093 return result;
00094 }
00095 void EntryDlg::slotTryAccept()
00096 {
00097 if ( !m_entry->text().isEmpty() )
00098 accept();
00099 }
00100
00101 void EntryDlg::slotSelectPath()
00102 {
00103 QString path = Opie::Ui::OFileDialog::getDirectory( 0, m_entry->text() );
00104 if ( path.at( path.length() - 1 ) == '/' )
00105 path.truncate( path.length() - 1 );
00106 if ( !path.isNull() )
00107 m_entry->setText( path );
00108 }