From 4aed2c8219774f5d797760606b8489a92ddc5163 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kdialog/widgets.cpp | 282 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 kdialog/widgets.cpp (limited to 'kdialog/widgets.cpp') diff --git a/kdialog/widgets.cpp b/kdialog/widgets.cpp new file mode 100644 index 000000000..41f5e452f --- /dev/null +++ b/kdialog/widgets.cpp @@ -0,0 +1,282 @@ +// +// Copyright (C) 1998 Matthias Hoelzer +// Copyright (C) 2002 David Faure +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the7 implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + + +#include +#include + +#include "widgets.h" +#include "klistboxdialog.h" +#include "progressdialog.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#if defined Q_WS_X11 && ! defined K_WS_QTONLY +#include +#endif + +void Widgets::handleXGeometry(QWidget * dlg) +{ +#ifdef Q_WS_X11 + if ( ! kapp->geometryArgument().isEmpty()) { + int x, y; + int w, h; + int m = XParseGeometry( kapp->geometryArgument().latin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h); + if ( (m & XNegative) ) + x = KApplication::desktop()->width() + x - w; + if ( (m & YNegative) ) + y = KApplication::desktop()->height() + y - h; + dlg->setGeometry(x, y, w, h); + // kdDebug() << "x: " << x << " y: " << y << " w: " << w << " h: " << h << endl; + } +#endif +} + +bool Widgets::inputBox(QWidget *parent, const QString& title, const QString& text, const QString& init, QString &result) +{ + bool ok; + QString str = KInputDialog::text( title, text, init, &ok, parent, 0, 0, QString::null ); + if ( ok ) + result = str; + return ok; +} + +bool Widgets::passwordBox(QWidget *parent, const QString& title, const QString& text, QCString &result) +{ + KPasswordDialog dlg( KPasswordDialog::Password, false, 0, parent ); + + kapp->setTopWidget( &dlg ); + dlg.setCaption(title); + dlg.setPrompt(text); + + handleXGeometry(&dlg); + + bool retcode = (dlg.exec() == QDialog::Accepted); + if ( retcode ) + result = dlg.password(); + return retcode; +} + +int Widgets::textBox(QWidget *parent, int width, int height, const QString& title, const QString& file) +{ +// KTextBox dlg(parent, 0, TRUE, width, height, file); + KDialogBase dlg( parent, 0, true, title, KDialogBase::Ok, KDialogBase::Ok ); + + kapp->setTopWidget( &dlg ); + KTextEdit *edit = new KTextEdit( dlg.makeVBoxMainWidget() ); + edit->setReadOnly(TRUE); + + QFile f(file); + if (!f.open(IO_ReadOnly)) + { + kdError() << i18n("kdialog: could not open file ") << file << endl; + return -1; + } + QTextStream s(&f); + + while (!s.eof()) + edit->append(s.readLine()); + + edit->moveCursor(QTextEdit::MoveHome, false); + + f.close(); + + if ( width > 0 && height > 0 ) + dlg.setInitialSize( QSize( width, height ) ); + + handleXGeometry(&dlg); + dlg.setCaption(title); + dlg.exec(); + return 0; +} + +int Widgets::textInputBox(QWidget *parent, int width, int height, const QString& title, const QStringList& args, QCString &result) +{ +// KTextBox dlg(parent, 0, TRUE, width, height, file); + KDialogBase dlg( parent, 0, true, title, KDialogBase::Ok, KDialogBase::Ok ); + + kapp->setTopWidget( &dlg ); + QVBox* vbox = dlg.makeVBoxMainWidget(); + + if( args.count() > 0 ) + { + QLabel *label = new QLabel(vbox); + label->setText(args[0]); + } + + KTextEdit *edit = new KTextEdit( vbox ); + edit->setReadOnly(FALSE); + edit->setTextFormat( Qt::PlainText ); + edit->setFocus(); + + if( args.count() > 1 ) + edit->setText( args[1] ); + + if ( width > 0 && height > 0 ) + dlg.setInitialSize( QSize( width, height ) ); + + handleXGeometry(&dlg); + dlg.setCaption(title); + dlg.exec(); + result = edit->text().local8Bit(); + return 0; +} + +bool Widgets::comboBox(QWidget *parent, const QString& title, const QString& text, const QStringList& args, + const QString& defaultEntry, QString &result) +{ + KDialogBase dlg( parent, 0, true, title, KDialogBase::Ok|KDialogBase::Cancel, + KDialogBase::Ok ); + + kapp->setTopWidget( &dlg ); + dlg.setCaption(title); + QVBox* vbox = dlg.makeVBoxMainWidget(); + + QLabel label (vbox); + label.setText (text); + KComboBox combo (vbox); + combo.insertStringList (args); + combo.setCurrentItem( defaultEntry, false ); + + handleXGeometry(&dlg); + + bool retcode = (dlg.exec() == QDialog::Accepted); + + if (retcode) + result = combo.currentText(); + + return retcode; +} + +bool Widgets::listBox(QWidget *parent, const QString& title, const QString& text, const QStringList& args, + const QString& defaultEntry, QString &result) +{ + KListBoxDialog box(text,parent); + + kapp->setTopWidget( &box ); + box.setCaption(title); + + for (unsigned int i = 0; i+1setTopWidget( &box ); + box.setCaption(title); + + for (unsigned int i=0; i+2setTopWidget( &box ); + box.setCaption(title); + + for (unsigned int i=0; i+2setTopWidget( &dlg ); + dlg.setCaption( title ); + handleXGeometry(&dlg); + dlg.exec(); + return dlg.wasCancelled(); +} -- cgit v1.2.3