summaryrefslogtreecommitdiffstats
path: root/kjsembed/docs/examples/madminute/madminute.js
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /kjsembed/docs/examples/madminute/madminute.js
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
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/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kjsembed/docs/examples/madminute/madminute.js')
-rwxr-xr-xkjsembed/docs/examples/madminute/madminute.js161
1 files changed, 161 insertions, 0 deletions
diff --git a/kjsembed/docs/examples/madminute/madminute.js b/kjsembed/docs/examples/madminute/madminute.js
new file mode 100755
index 00000000..a2762cde
--- /dev/null
+++ b/kjsembed/docs/examples/madminute/madminute.js
@@ -0,0 +1,161 @@
+#!/usr/bin/env kjscmd
+
+StdDirs.addResourceType("madminute", StdDirs.kde_default("data") + "/madminute");
+try {
+ //var view = Factory.loadui( StdDirs.findResource("madminute", "madminute.ui"), this, mw );
+ var view = Factory.loadui( "madminute.ui" );
+
+} catch( err ) {
+ alert( err );
+ exit(0);
+}
+var Addition = 1;
+var Subtraction = 2;
+
+var config = new Config("madminute");
+config.setGroup("Game Options");
+// Timer
+var timer = new QTimer(this);
+// Current Argument 1
+var arg1 = 0;
+// Current Argument 2
+var arg2 = 0;
+// Current Operation
+var operation = Addition;
+// Acceptable operations 1 = Addition 2 = Subtraction 3 = Both
+var operations = config.readNumEntry("Operations", Addition);
+// Time to run the drill
+var drillTime = config.readNumEntry("Drill Time", 60);
+// maxInput is maximum value for the numbers in the question
+var maxInput = config.readNumEntry("Maximum Input", 10);
+var total = 0;
+
+view.connect(view.fileExitAction, 'activated()', application, 'quit()');
+view.connect(view.fileGoAction, 'activated()', this, 'start');
+view.connect(view.editPreferencesAction, 'activated()', this, 'configure');
+view.connect(view.helpAboutAction, 'activated()', this, 'about');
+view.connect(view.helpHelpAction, 'activated()', this, 'helpDialog');
+
+
+view.connect( view.qt_central_widget.answer, 'returnPressed()', this, 'checkAnswer' );
+view.connect( timer, 'timeout()', this, 'countdown');
+
+view.qt_central_widget.answer.enabled = false;
+
+view.show();
+// Run the main event loop.
+application.exec();
+
+function configure()
+{
+ //var configUI = Factory.loadui( StdDirs.findResource("madminute", "configdialog.ui"), this, mw );
+ var configUI = Factory.loadui( "configdialog.ui" );
+ configUI.connect( configUI.buttonHelp, 'clicked()', this, 'helpDialog');
+ configUI.addition.checked = false;
+ configUI.subtraction.checked == false;
+ configUI.time.value = drillTime;
+ configUI.maximum.value = maxInput;
+ if( operations == 1 )
+ configUI.addition.checked = true;
+ if( operations == 2 )
+ configUI.subtraction.checked = true;
+ if( operations == 3 )
+ {
+ configUI.addition.checked = true;
+ configUI.subtraction.checked = true;
+ }
+
+ if ( configUI.exec() == 1 )
+ {
+ operations = 0;
+ if( configUI.addition.checked == true )
+ operations += 1;
+ if( configUI.subtraction.checked == true )
+ operations += 2;
+ drillTime = configUI.time.value;
+ maxInput = configUI.maximum.value;
+ config.setGroup("Game Options");
+ config.writeNumEntry("Operations",operations);
+ config.writeNumEntry("Drill Time", drillTime );
+ config.writeNumEntry("Maximum Input", maxInput );
+ config.sync();
+ }
+}
+
+function about()
+{
+ alert("<h2>MadMinute 1.0</h2>A math tutoring drill to help students master basic math skills.<br>Copyright 2004 Ian Reinhart Geiser <a href='mailto:geiseri@kde.org'>geiseri@kde.org</a>");
+}
+
+function helpDialog()
+{
+ //var helpUI = Factory.loadui( StdDirs.findResource("madminute", "helpdialog.ui"), this, mw );
+ var helpUI = Factory.loadui( "helpdialog.ui" );
+ helpUI.exec();
+}
+
+function askQuestion()
+{
+ arg1 = Math.floor( Math.random() * maxInput );
+ arg2 = Math.floor( Math.random() * maxInput );
+ if( operations == 3 )
+ operation = Math.floor( (Math.random() * 2)+1);
+ else
+ operation = operations;
+
+ var operationText = "";
+ if( operation == Addition )
+ operationText = " + ";
+ else if( operation == Subtraction )
+ {
+ operationText = " - ";
+ if( arg1 < arg2 )
+ {
+ var arg = arg1;
+ arg1 = arg2;
+ arg2 = arg;
+ }
+ }
+ view.qt_central_widget.question.text = "<h2>" + arg1 + operationText + arg2 + "=</h2>";
+}
+
+function checkAnswer( )
+{
+ var answer = 0;
+ if( operation == Addition )
+ answer = (arg1 + arg2) ;
+ else if( operation == Subtraction )
+ answer = (arg1 - arg2) ;
+ if( view.qt_central_widget.answer.text == answer )
+ {
+ view.qt_central_widget.correct.value++;
+ }
+ total++;
+ askQuestion();
+ view.qt_central_widget.answer.text = "";
+}
+
+function start()
+{
+ askQuestion();
+ total = 0;
+ timer.start(1000);
+ view.fileGoAction.enabled = false;
+ view.qt_central_widget.answer.enabled = true;
+ view.qt_central_widget.answer.setFocus();
+ view.qt_central_widget.timeleft.progress = drillTime;
+ view.qt_central_widget.correct.value = 0;
+}
+
+function countdown()
+{
+ view.qt_central_widget.timeleft.progress--;
+ if( view.qt_central_widget.timeleft.progress == 0 )
+ {
+ timer.stop();
+ view.fileGoAction.enabled = true;
+ view.qt_central_widget.answer.enabled = false;
+ alert( "<h1>Times Up!</h1>You got " + view.qt_central_widget.correct.value + " out of " + total + " questions correct." );
+ }
+}
+