summaryrefslogtreecommitdiffabout
path: root/qtcompat/qinputdialog.cpp
Side-by-side diff
Diffstat (limited to 'qtcompat/qinputdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r--qtcompat/qinputdialog.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/qtcompat/qinputdialog.cpp b/qtcompat/qinputdialog.cpp
index 770b281..64c581e 100644
--- a/qtcompat/qinputdialog.cpp
+++ b/qtcompat/qinputdialog.cpp
@@ -1,85 +1,87 @@
/****************************************************************************
** $Id$
**
** Implementation of QInputDialog class
**
** Created : 991212
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of the dialogs module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses may use this file in accordance with the Qt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
+//Edited Lutz Rogowski 2004-12-13
+
#include "qinputdialog.h"
#include <qlayout.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <qcombobox.h>
#include <qwidgetstack.h>
#include <qvalidator.h>
#include <qapplication.h>
class QInputDialogPrivate
{
public:
friend class QInputDialog;
QLineEdit *lineEdit;
QSpinBox *spinBox;
QComboBox *comboBox, *editComboBox;
QPushButton *ok;
QWidgetStack *stack;
QInputDialog::Type type;
};
/*!
\class QInputDialog qinputdialog.h
\brief A convenience dialog to get a simple input from the user
\ingroup dialogs
The QInputDialog is a simple dialog which can be used if you
need a simple input from the user. This can be text, a number or
an item from a list. Also a label has to be set to tell the user
what he/she should input.
In this Qt version only the 4 static convenience functions
getText(), getInteger(), getDouble() and getItem() of QInputDialog
are available.
Use it like this:
\code
bool ok = FALSE;
QString text = QInputDialog::getText( tr( "Make an input" ), tr( "Please enter your name" ), QString::null, &ok, this );
if ( ok && !text.isEmpty() )
;// user entered something and pressed ok
else
;// user entered nothing or pressed cancel
\endcode
@@ -408,88 +410,93 @@ double QInputDialog::getDouble( const QString &caption, const QString &label, do
delete dlg;
return result;
}
/*!
Static convenience function to let the user select an item from a string list. \a caption is the text
which is displayed in the title bar of the dialog. \a label is the text which
is shown to the user (it should mention to the user what he/she should input), \a list the
string list which is inserted into the combobox, \a current the number of the item which should
be initially the current item, \a editable specifies if the combobox should be editable (if it is TRUE)
or read-only (if \a editable is FALSE), \a ok a pointer to
a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the
user pressed cancel, \a parent the parent widget of the dialog and \a name
the name of it. The dialogs pops up modally!
This method returns the text of the current item, or if \a editable was TRUE, the current
text of the combobox.
You will use this static method like this:
\code
QStringList lst;
lst << "First" << "Second" << "Third" << "Fourth" << "Fifth";
bool ok = FALSE;
QString res = QInputDialog::getItem( tr( "Please select an item" ), lst, 1, TRUE, &ok, this );
if ( ok )
;// user selected an item and pressed ok
else
;// user pressed cancel
\endcode
*/
QString QInputDialog::getItem( const QString &caption, const QString &label, const QStringList &list,
int current, bool editable,
bool *ok, QWidget *parent, const char *name )
{
QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, editable ? EditableComboBox : ComboBox );
dlg->setCaption( caption );
if ( editable ) {
dlg->editableComboBox()->insertStringList( list );
dlg->editableComboBox()->setCurrentItem( current );
} else {
dlg->comboBox()->insertStringList( list );
dlg->comboBox()->setCurrentItem( current );
}
bool ok_ = FALSE;
QString result;
+ int fixWid = 320;
+ if ( QApplication::desktop()->width() <= 240 ) {
+ fixWid = 230;
+ }
+ dlg->setFixedWidth( fixWid);
ok_ = dlg->exec() == QDialog::Accepted;
if ( ok )
*ok = ok_;
if ( editable )
result = dlg->editableComboBox()->currentText();
else
result = dlg->comboBox()->currentText();
delete dlg;
return result;
}
/*!
\internal
*/
void QInputDialog::textChanged( const QString &s )
{
bool on;
if ( d->lineEdit->validator() ) {
QString str = d->lineEdit->text();
int index = d->lineEdit->cursorPosition();
on = ( d->lineEdit->validator()->validate(str, index) ==
QValidator::Acceptable );
} else {
on = !s.isEmpty();
}
d->ok->setEnabled( on );
}
/*!
\internal
*/
void QInputDialog::tryAccept()
{
if ( !d->lineEdit->text().isEmpty() )
accept();
}