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

entrydlg.cpp

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

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