[rkward-cvs] rkward/rkward/dialogs rkreadlinedialog.cpp, NONE, 1.1 rkreadlinedialog.h, NONE, 1.1 Makefile.am, 1.2, 1.3

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Sep 15 17:23:14 UTC 2006


Update of /cvsroot/rkward/rkward/rkward/dialogs
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv31419/rkward/dialogs

Modified Files:
	Makefile.am 
Added Files:
	rkreadlinedialog.cpp rkreadlinedialog.h 
Log Message:
Show output context for readline() calls

--- NEW FILE: rkreadlinedialog.h ---
/***************************************************************************
                          rkreadlinedialog  -  description
                             -------------------
    begin                : Fri Sep 15 2006
    copyright            : (C) 2006 by Thomas Friedrichsmeier
    email                : tfry at users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef RKREADLINEDIALOG_H
#define RKREADLINEDIALOG_H

#include <kdialogbase.h>

class QLineEdit;
class QWidget;
class RCommand;

/** This class represent a dialog asking for a line of input. It is used, when the backend calls readline().
This dialog displays the question asked, the output context (as often times the question is not meaningful without that context), and a QLineEdit to get the user response.

@author Thomas Friedrichsmeier
*/
class RKReadLineDialog : public KDialogBase {
public:
	/** ctor. Use the static readLine() instead. */
	RKReadLineDialog (QWidget *parent, const QString &caption, const QString &prompt, RCommand *command);
	/** destructor */
	~RKReadLineDialog ();

	/** Construct and run modal RKReadLineDialog.
	@param parent QWidget to center the modal dialog on (0 for application)
	@param prompt The question
	@param command The command the readline() has arisen from. This is used to get the relevant output context
	@param result The answer to the question (the line read) will be stored in this string
	@returns true if ok was pressed (or the dialog was closed), false if cancel was pressed (i.e. the command should be cancelled) */
	static bool readLine (QWidget *parent, const QString &caption, const QString &prompt, RCommand *command, QString *result);
private:
	QLineEdit *input;
};

#endif

Index: Makefile.am
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dialogs/Makefile.am,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Makefile.am	6 Sep 2004 15:27:25 -0000	1.2
--- Makefile.am	15 Sep 2006 17:23:12 -0000	1.3
***************
*** 2,5 ****
  METASOURCES = AUTO
  noinst_LIBRARIES =  libdialogs.a
! noinst_HEADERS = startupdialog.h rkloadlibsdialog.h
! libdialogs_a_SOURCES = startupdialog.cpp rkloadlibsdialog.cpp
--- 2,5 ----
  METASOURCES = AUTO
  noinst_LIBRARIES =  libdialogs.a
! noinst_HEADERS = startupdialog.h rkloadlibsdialog.h rkreadlinedialog.h
! libdialogs_a_SOURCES = startupdialog.cpp rkloadlibsdialog.cpp rkreadlinedialog.cpp

--- NEW FILE: rkreadlinedialog.cpp ---
/***************************************************************************
                          rkreadlinedialog  -  description
                             -------------------
    begin                : Fri Sep 15 2006
    copyright            : (C) 2006 by Thomas Friedrichsmeier
    email                : tfry at users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "rkreadlinedialog.h"

#include <qlineedit.h>
#include <qtextedit.h>
#include <qlabel.h>
#include <qvbox.h>

#include <klocale.h>

#include "../rbackend/rcommand.h"

#include "../debug.h"

RKReadLineDialog::RKReadLineDialog (QWidget *parent, const QString &caption, const QString &prompt, RCommand *command) : KDialogBase (parent, 0, true, caption, KDialogBase::Ok | KDialogBase::Cancel) {
	RK_TRACE (DIALOGS);

	QVBox *page = makeVBoxMainWidget ();
	new QLabel (caption, page);

	QString context = command->fullOutput ();
	if (!context.isEmpty ()) {
		new QLabel (i18n ("Context:"), page);

		QTextEdit *output = new QTextEdit (page);
		output->setUndoRedoEnabled (false);
		output->setTextFormat (QTextEdit::PlainText);
		output->setCurrentFont (QFont ("Courier"));
		output->setWordWrap (QTextEdit::NoWrap);
		output->setText (context);
		output->setReadOnly (true);
		setMinimumWidth (output->contentsWidth ());		// TODO: should never be wider than screen
		output->scrollToBottom ();
	}

	new QLabel (prompt, page);

	input = new QLineEdit (QString (), page);
	input->setMinimumWidth (fontMetrics ().maxWidth ()*20);
}

RKReadLineDialog::~RKReadLineDialog () {
	RK_TRACE (DIALOGS);
}

//static
bool RKReadLineDialog::readLine (QWidget *parent, const QString &caption, const QString &prompt, RCommand *command, QString *result) {
	RK_TRACE (DIALOGS);
	RK_ASSERT (result);

	RKReadLineDialog *dialog = new RKReadLineDialog (parent, caption, prompt, command);
	int res = dialog->exec ();
	*result = dialog->input->text ();

	if (res == KDialogBase::Cancel) return false;
	return true;
}





More information about the rkward-tracker mailing list