[rkward-cvs] SF.net SVN: rkward: [2124] branches/KDE4_port

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Oct 24 23:23:25 UTC 2007


Revision: 2124
          http://rkward.svn.sourceforge.net/rkward/?rev=2124&view=rev
Author:   tfry
Date:     2007-10-24 16:23:23 -0700 (Wed, 24 Oct 2007)

Log Message:
-----------
I think RKSpinbox is fixed, now, but it certainly looks fairly hackish

Modified Paths:
--------------
    branches/KDE4_port/TODO_KDE4
    branches/KDE4_port/rkward/misc/rkspinbox.cpp
    branches/KDE4_port/rkward/misc/rkspinbox.h

Modified: branches/KDE4_port/TODO_KDE4
===================================================================
--- branches/KDE4_port/TODO_KDE4	2007-10-24 23:00:02 UTC (rev 2123)
+++ branches/KDE4_port/TODO_KDE4	2007-10-24 23:23:23 UTC (rev 2124)
@@ -72,10 +72,9 @@
 	- does locale switching / detection work? Does Qt have something, yet?
 
 rkspinbox:
-	- does it work at all? in both modes?
-	- seems to be at least partially broken
-	- does not work in real mode
-	- in int mode, does not update on typed input
+	- are all of these fixed? Do some thorough testing
+		- does not work in real mode
+		- does not update on typed input
 
 rkobjectlistview:
 	- do the tool-tips for the objects work?

Modified: branches/KDE4_port/rkward/misc/rkspinbox.cpp
===================================================================
--- branches/KDE4_port/rkward/misc/rkspinbox.cpp	2007-10-24 23:00:02 UTC (rev 2123)
+++ branches/KDE4_port/rkward/misc/rkspinbox.cpp	2007-10-24 23:23:23 UTC (rev 2124)
@@ -18,6 +18,7 @@
 
 #include <qvalidator.h>
 #include <qlineedit.h>
+#include <QTimer>
 
 #include <math.h>
 #include <limits.h>
@@ -30,13 +31,12 @@
 
 	validator = 0;
 	mode = Integer;
-	updating = updating_b = false;
 	real_value = 0;
 	int_value = 0;
 	int_min = INT_MIN;
 	int_max = INT_MAX;
 
-	connect (this, SIGNAL (valueChanged(int)), this, SLOT(updateValue(int)));
+	connect (this, SIGNAL (valueChanged(int)), this, SLOT (updateValue(int)));
 }
 
 RKSpinBox::~RKSpinBox () {
@@ -71,18 +71,20 @@
 int RKSpinBox::valueFromText (const QString & text) const {
 	if (mode == Real) {
 		bool ok;
-		double new_value = text.toFloat (&ok);
-		if (ok) {
+		double new_value = text.toDouble (&ok);
+		if (ok && (new_value != real_value)) {
 			double *cheat = const_cast<double*> (&real_value);
 			*cheat = new_value;
+			QTimer::singleShot (0, const_cast<RKSpinBox*>(this), SLOT (emitValueChange()));
 		}
 		return 0;
 	} else {
 		bool ok;
 		int new_value = text.toInt (&ok);
-		if (ok) {
+		if (ok && (new_value != int_value)) {
 			int *cheat = const_cast<int*> (&int_value);
 			*cheat = new_value;
+			QTimer::singleShot (0, const_cast<RKSpinBox*>(this), SLOT (emitValueChange()));
 		}
 		return 0;
 	}
@@ -98,44 +100,47 @@
 	return (validator->validate (input, pos));
 }
 
+void RKSpinBox::emitValueChange () {
+	RK_TRACE (MISC);
+
+	emit (valueChanged (0));
+}
+
 void RKSpinBox::updateValue (int change) {
 	RK_TRACE (MISC);
+	if (change == 0) return;
+
 	if (mode == Real) {
-		if (change != 0) {
-			setValue (0);
+		int power;
+		if (real_value != 0) {
+			power = (int) log10 (fabs (real_value)) - default_precision;
+			if (power < (-default_precision)) power = -default_precision;
+			if (power > 10) power = 10;
+		} else {
+			power = -default_precision;
+		}
+		double step = pow (10, power);
 
-			int power;
-			if (real_value != 0) {
-				power = (int) log10 (fabs (real_value)) - default_precision;
-				if (power < (-default_precision)) power = -default_precision;
-				if (power > 10) power = 10;
-			} else {
-				power = -default_precision;
-			}
-			double step = pow (10, power);
-
-			real_value += change * step;
-			if (real_value > real_max) real_value = real_max;
-			if (real_value < real_min) real_value = real_min;
+		real_value += change * step;
+		if (real_value > real_max) real_value = real_max;
+		if (real_value < real_min) real_value = real_min;
+	} else {
+		int power;
+		if (int_value != 0) {
+			power = (int) log10 (abs (int_value));
+		} else {
+			power = -default_precision;
 		}
-	} else {
-		if (change != 0) {
-			setValue (0);
+		int step = (int) pow (10, power-1);
+		if (step < 1) step = 1;
 
-			int power;
-			if (int_value != 0) {
-				power = (int) log10 (abs (int_value));
-			} else {
-				power = -default_precision;
-			}
-			int step = (int) pow (10, power-1);
-			if (step < 1) step = 1;
+		int_value += change * step;
+		if (int_value > int_max) int_value = int_max;
+		if (int_value < int_min) int_value = int_min;
+	}
 
-			int_value += change * step;
-			if (int_value > int_max) int_value = int_max;
-			if (int_value < int_min) int_value = int_min;
-		}
-	}
+	// update display and reset
+	setValue (0);
 }
 
 void RKSpinBox::setRealMode (double min, double max, double initial, int default_precision, int max_precision) {

Modified: branches/KDE4_port/rkward/misc/rkspinbox.h
===================================================================
--- branches/KDE4_port/rkward/misc/rkspinbox.h	2007-10-24 23:00:02 UTC (rev 2123)
+++ branches/KDE4_port/rkward/misc/rkspinbox.h	2007-10-24 23:23:23 UTC (rev 2124)
@@ -70,11 +70,10 @@
 	QValidator::State validate (QString &input, int &pos ) const;
 private slots:
 	void updateValue (int value);
+	void emitValueChange ();
 private:
 	enum Mode { Integer=0, Real=1 };
 	Mode mode;
-	bool updating;
-	bool updating_b;
 	double real_value;
 	double real_min;
 	double real_max;


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