[rkward-cvs] SF.net SVN: rkward: [1356] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Feb 8 13:06:07 UTC 2007


Revision: 1356
          http://svn.sourceforge.net/rkward/?rev=1356&view=rev
Author:   tfry
Date:     2007-02-08 05:06:06 -0800 (Thu, 08 Feb 2007)

Log Message:
-----------
Single line input fields no longer accept newlines

Modified Paths:
--------------
    trunk/rkward/TODO
    trunk/rkward/rkward/plugin/rkinput.cpp
    trunk/rkward/rkward/plugin/rkinput.h

Modified: trunk/rkward/TODO
===================================================================
--- trunk/rkward/TODO	2007-02-08 13:05:08 UTC (rev 1355)
+++ trunk/rkward/TODO	2007-02-08 13:06:06 UTC (rev 1356)
@@ -149,6 +149,9 @@
 			- static members should be moved to the respective classes. Much cleaner!
 
 R plugins:
+	- Spinbox:
+		- find a solution for "pending changes". Currently, if the user enters a value, manually, then presses submit, the old value will be used (the new value is only set, when the focus changes to another widget). Probably the RKSpinbox should emit signals for "pending" and "ready". The plugin spinbox should listen to those and not be satisfied as long as a change is pending. Maybe mark the spinbox in yellow, while a change is pending.
+		- options min_inclusive / max_inclusive for real number spinboxes (defaulting to true)
 	- create grid() plugin
 	- create a (simple) color option plugin (~ 30 colors) for embedding
 	- a function rk.describe.alternative() for use in hypothesis test plugins

Modified: trunk/rkward/rkward/plugin/rkinput.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkinput.cpp	2007-02-08 13:05:08 UTC (rev 1355)
+++ trunk/rkward/rkward/plugin/rkinput.cpp	2007-02-08 13:06:06 UTC (rev 1356)
@@ -19,6 +19,7 @@
 
 #include <qlayout.h>
 #include <qtextedit.h>
+#include <qlineedit.h>
 #include <qlabel.h>
 
 #include <klocale.h>
@@ -30,12 +31,15 @@
 RKInput::RKInput (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) {
 	RK_TRACE (PLUGIN);
 
+	textedit = 0;
+	lineedit = 0;
+
 	// get xml-helper
 	XMLHelper *xml = XMLHelper::getStaticHelper ();
 
 	// create and add property
 	addChild ("text", text = new RKComponentPropertyBase (this, false));
-	connect (text, SIGNAL (valueChanged (RKComponentPropertyBase *)), this, SLOT (textChanged ( RKComponentPropertyBase *)));
+	connect (text, SIGNAL (valueChanged (RKComponentPropertyBase *)), this, SLOT (textChanged (RKComponentPropertyBase *)));
 
 	setRequired (xml->getBoolAttribute (element, "required", false, DL_INFO));
 	connect (requirednessProperty (), SIGNAL (valueChanged (RKComponentPropertyBase*)), this, SLOT (requirednessChanged (RKComponentPropertyBase*)));
@@ -45,30 +49,27 @@
 	QLabel *label = new QLabel (xml->getStringAttribute (element, "label", i18n ("Enter text"), DL_INFO), this);
 	vbox->addWidget (label);
 
-	textedit = new QTextEdit (this);
 	int size = xml->getMultiChoiceAttribute (element, "size", "small;medium;large", 1, DL_INFO);
-	int lheight = textedit->fontMetrics ().lineSpacing ();
-	int margin = textedit->height () - textedit->visibleHeight () + textedit->fontMetrics ().descent () + 2;
-	if (size == 0) {
-		textedit->setFixedSize (100, lheight + margin);
-	} else if (size == 1) {
-		textedit->setFixedSize (250, lheight + margin);
-	} else if (size == 2) {
+	if (size == 2) {
+		textedit = new QTextEdit (this);
+		int lheight = textedit->fontMetrics ().lineSpacing ();
+		int margin = textedit->height () - textedit->visibleHeight () + textedit->fontMetrics ().descent () + 2;
 		textedit->setMinimumSize (250, lheight * 4 + margin);
+
+		vbox->addWidget (textedit);
+		connect (textedit, SIGNAL (textChanged ()), SLOT (textChanged ()));
+	} else {
+		lineedit = new QLineEdit (this);
+		vbox->addWidget (lineedit);
+		connect (lineedit, SIGNAL (textChanged (const QString&)), SLOT (textChanged (const QString&)));
 	}
-	if (size < 2) {
-		textedit->setHScrollBarMode (QScrollView::AlwaysOff);
-		textedit->setVScrollBarMode (QScrollView::AlwaysOff);
-		textedit->setTabChangesFocus (true);
-	}
-	vbox->addWidget (textedit);
-	connect (textedit, SIGNAL (textChanged ()), SLOT (textChanged ()));
 
 	vbox->addStretch (1);		// to keep the label attached
 
 	// initialize
 	updating = false;
-	text->setValue (xml->getStringAttribute (element, "initial", QString::null, DL_INFO));
+	// DO NOT replace "" with QString::null, here! it is important, that this is actually an empty string, not a null string.
+	text->setValue (xml->getStringAttribute (element, "initial", "", DL_INFO));
 }
 
 RKInput::~RKInput () {
@@ -86,14 +87,18 @@
 void RKInput::updateColor () {
 	RK_TRACE (PLUGIN);
 
+	QWidget *widget = lineedit;
+	if (!widget) widget = textedit;
+	RK_ASSERT (widget);
+
 	if (isEnabled ()) {
 		if (isSatisfied ()) {
-			textedit->setPaletteBackgroundColor (QColor (255, 255, 255));
+			widget->setPaletteBackgroundColor (QColor (255, 255, 255));
 		} else {
-			textedit->setPaletteBackgroundColor (QColor (255, 0, 0));
+			widget->setPaletteBackgroundColor (QColor (255, 0, 0));
 		}
 	} else {
-		textedit->setPaletteBackgroundColor (QColor (200, 200, 200));
+		widget->setPaletteBackgroundColor (QColor (200, 200, 200));
 	}
 }
 
@@ -109,25 +114,35 @@
 	if (updating) return;
 	updating = true;
 
-	textedit->setText (text->value ());
+	RK_ASSERT (textedit || lineedit);
+	if (textedit) textedit->setText (text->value ());
+	else lineedit->setText (text->value ());
+
 	updateColor ();
 
 	updating = false;
 	changed ();
 }
 
-void RKInput::textChanged () {
+void RKInput::textChanged (const QString &new_text) {
 	RK_TRACE (PLUGIN);
 
 	updating = true;
 
-	text->setValue (textedit->text ());
+	text->setValue (new_text);
 	updateColor ();
 
 	updating = false;
 	changed ();
 }
 
+void RKInput::textChanged () {
+	RK_TRACE (PLUGIN);
+
+	RK_ASSERT (textedit);
+	textChanged (textedit->text ());
+}
+
 bool RKInput::isValid () {
 	RK_TRACE (PLUGIN);
 

Modified: trunk/rkward/rkward/plugin/rkinput.h
===================================================================
--- trunk/rkward/rkward/plugin/rkinput.h	2007-02-08 13:05:08 UTC (rev 1355)
+++ trunk/rkward/rkward/plugin/rkinput.h	2007-02-08 13:06:06 UTC (rev 1356)
@@ -23,6 +23,7 @@
 #include "rkcomponentproperties.h"
 
 class QTextEdit;
+class QLineEdit;
 class QDomElement;
 
 /** A component to enter plain text
@@ -43,6 +44,7 @@
 	bool isValid ();
 public slots:
 	void textChanged ();
+	void textChanged (const QString &new_text);
 	void textChanged (RKComponentPropertyBase *);
 	void requirednessChanged (RKComponentPropertyBase *);
 protected:
@@ -52,6 +54,7 @@
 	void updateColor ();
 	bool updating;
 	QTextEdit *textedit;
+	QLineEdit *lineedit;
 };
 
 #endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list