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

inputdialog.cpp

Go to the documentation of this file.
00001 /*
00002 Opie-sh.  convinience app to allow you to use qdialogs in scripts (mainly shell scripts)
00003 Copyright (C) 2002 Thomas Stephens
00004 
00005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
00006 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
00007 version.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
00010 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00011 Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
00014 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00015 */
00016 #include "inputdialog.h"
00017 
00018 InputDialog::InputDialog(int w, int h, int newtype, QString labelString, QString title, QString filename, bool edit, QWidget *parent, const char *name, bool modal, WFlags f):QDialog(parent, name, modal, f)
00019 {
00020         type = newtype;
00021         QHBoxLayout *layout = new QHBoxLayout(this);
00022         layout->addStrut(32);
00023         QLabel *label = new QLabel(labelString, this, "label");
00024         setCaption(title);
00025         int x, y;
00026 
00027         layout->addSpacing(5);
00028         layout->addWidget(label);
00029         layout->addSpacing(5);
00030 
00031         switch(type)
00032         {
00033         case 0:
00034                 lineEdit = new QLineEdit(this, "line edit");
00035                 layout->addWidget(lineEdit);
00036                 break;
00037         case 1:
00038                 comboBox = new QComboBox(edit, this, "combo box");
00039                 layout->addWidget(comboBox);
00040                 if(!filename.isNull())
00041                 {
00042                         QFile file(filename);
00043                         file.open(IO_ReadOnly);
00044                         QTextStream stream(&file);
00045                         QString string = stream.read();
00046 
00047                         comboBox->insertStringList(QStringList::split('\n', string));
00048                 }
00049                 else
00050                 {
00051                         QFile file;
00052                         file.open(IO_ReadOnly, 0);
00053                         QTextStream stream(&file);
00054                         QString string = stream.read();
00055 
00056                         comboBox->insertStringList(QStringList::split('\n', string));
00057                 }
00058                 break;
00059         case 2:
00060                 listBox = new QListBox(this, "list box");
00061                 listBox->setSelectionMode(QListBox::Multi);
00062                 layout->addWidget(listBox);
00063                 if(!filename.isNull())
00064                 {
00065                         QFile file(filename);
00066                         file.open(IO_ReadOnly);
00067                         QTextStream stream(&file);
00068                         QString string = stream.read();
00069 
00070                         listBox->insertStringList(QStringList::split('\n', string));
00071                 }
00072                 else
00073                 {
00074                         QFile file;
00075                         file.open(IO_ReadOnly, 0);
00076                         QTextStream stream(&file);
00077                         QString string = stream.read();
00078 
00079                         listBox->insertStringList(QStringList::split('\n', string));
00080                 }
00081                 break;
00082         case 3:
00083                 lineEdit = new QLineEdit(this, "line edit");
00084                 lineEdit->setEchoMode(QLineEdit::Password);
00085                 layout->addWidget(lineEdit);
00086                 break;
00087         }
00088         layout->addSpacing(5);
00089 
00090         x=(w/2)-(width()/2);
00091         y=(h/2)-(height()/2);
00092 
00093         move(x,y);
00094 }
00095 
00096 QString InputDialog::getString()
00097 {
00098         switch (type)
00099         {
00100         case 0:
00101         case 3:
00102                 return ((QLineEdit *)child("line edit"))->text();
00103                 break;
00104         case 1:
00105                 return ((QComboBox *)child("combo box"))->currentText();
00106                 break;
00107         case 2:
00108                 QString string;
00109                 int i;
00110                 for(i = 0; i < listBox->count(); i++)
00111                 {
00112                         if(listBox->isSelected(i))
00113                         {
00114                                 string+=listBox->text(i)+'\n';
00115                         }
00116                 }
00117                 if(string[string.length()-1] == '\n')
00118                 {
00119                         string.truncate(string.length()-1);
00120                 }
00121                 return string;
00122         }
00123         return QString::null;
00124 }

Generated on Sat Nov 5 16:18:01 2005 for OPIE by  doxygen 1.4.2