diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2 (patch) | |
tree | d3bb9f5d25a2dc09ca81adecf39621d871534297 /kpercentage | |
download | tdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.tar.gz tdeedu-ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2.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/kdeedu@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpercentage')
56 files changed, 2556 insertions, 0 deletions
diff --git a/kpercentage/Makefile.am b/kpercentage/Makefile.am new file mode 100644 index 00000000..a10ee998 --- /dev/null +++ b/kpercentage/Makefile.am @@ -0,0 +1,7 @@ +SUBDIRS = kpercentage + +EXTRA_DIST = kpercentage.kdevprj + +AUTOMAKE_OPTIONS = foreign + +include ../admin/Doxyfile.am diff --git a/kpercentage/TODO b/kpercentage/TODO new file mode 100644 index 00000000..06343aed --- /dev/null +++ b/kpercentage/TODO @@ -0,0 +1,10 @@ +Last modified: 26/05/2005 + +TODO for KDE 3.x release: + - a more motivating, animated feedback concept + > visualize the amount of right and wrong ansers by additional progrss bars (Geert) + - adding senseful icons for all the pushbuttons + - all help features (ToolTips, WhatsThis, About, etc.) + - a more educational section introducing to the meaning of percentages + - removing the splash scrren + - text related tasks diff --git a/kpercentage/kpercentage/Makefile.am b/kpercentage/kpercentage/Makefile.am new file mode 100644 index 00000000..c617e129 --- /dev/null +++ b/kpercentage/kpercentage/Makefile.am @@ -0,0 +1,49 @@ +bin_PROGRAMS = kpercentage +kpercentage_SOURCES = kanimation.cpp kanswer.cpp kpercentmain.cpp kpercentage.cpp ksplashscreen.cpp main.cpp +kpercentage_LDADD = $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET) + +SUBDIRS = icons pics + +EXTRA_DIST = main.cpp kpercentage.cpp kpercentage.h kpercentmain.cpp kanswer.h kanswer.cpp right.txt wrong.txt kpercentage.desktop ksplashscreen.cpp ksplashscreen.h kanimation.cpp kanimation.h + +text_DATA = right.txt wrong.txt +textdir = $(kde_datadir)/kpercentage + +# this 10 paths are KDE specific. Use them: +# kde_htmldir Where your docs should go to. (contains lang subdirs) +# kde_appsdir Where your application file (.kdelnk) should go to. +xdg_apps_DATA = kpercentage.desktop +# kde_icondir Where your icon should go to. +# kde_minidir Where your mini icon should go to. +# kde_datadir Where you install application data. (Use a subdir) +# kde_locale Where translation files should go to.(contains lang subdirs) +# kde_cgidir Where cgi-bin executables should go to. +# kde_confdir Where config files should go to. +# kde_mimedir Where mimetypes should go to. +# kde_toolbardir Where general toolbar icons should go to. +# kde_wallpaperdir Where general wallpapers should go to. + +# set the include path for X, qt and KDE +INCLUDES= $(all_includes) + +METASOURCES = AUTO + + +# the library search path. +kpercentage_LDFLAGS = $(all_libraries) $(KDE_RPATH) + + +stringstocpp: + rm -f feedback_i18n.cpp; \ + echo "# right.txt" >> feedback_i18n.cpp ;\ + cat right.txt | sed -e 's#^\(.*\)#i18n(\"\1\")#' >> feedback_i18n.cpp ;\ + echo "# wrong.txt" >> feedback_i18n.cpp ;\ + cat wrong.txt | sed -e 's#^\(.*\)#i18n(\"\1\")#' >> feedback_i18n.cpp + + +messages: stringstocpp rc.cpp + LIST=`find . -name \*.h -o -name \*.hh -o -name \*.H -o -name \*.hxx -o -name \*.hpp -o -name \*.cpp -o -name \*.cc -o -name \*.cxx -o -name \*.ecpp -o -name \*.C`; \ + if test -n "$$LIST"; then \ + $(XGETTEXT) $$LIST -o $(podir)/kpercentage.pot; \ + fi + diff --git a/kpercentage/kpercentage/icons/Makefile.am b/kpercentage/kpercentage/icons/Makefile.am new file mode 100644 index 00000000..48195256 --- /dev/null +++ b/kpercentage/kpercentage/icons/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = actions + +KDE_ICON = AUTO diff --git a/kpercentage/kpercentage/icons/actions/Makefile.am b/kpercentage/kpercentage/icons/actions/Makefile.am new file mode 100644 index 00000000..0e433e64 --- /dev/null +++ b/kpercentage/kpercentage/icons/actions/Makefile.am @@ -0,0 +1,2 @@ +kpercentageiconsdir = $(kde_datadir)/kpercentage/icons +kpercentageicons_ICON = AUTO diff --git a/kpercentage/kpercentage/icons/actions/cr22-action-button_cancel.png b/kpercentage/kpercentage/icons/actions/cr22-action-button_cancel.png Binary files differnew file mode 100644 index 00000000..96919575 --- /dev/null +++ b/kpercentage/kpercentage/icons/actions/cr22-action-button_cancel.png diff --git a/kpercentage/kpercentage/icons/actions/cr22-action-button_ok.png b/kpercentage/kpercentage/icons/actions/cr22-action-button_ok.png Binary files differnew file mode 100644 index 00000000..31c064ba --- /dev/null +++ b/kpercentage/kpercentage/icons/actions/cr22-action-button_ok.png diff --git a/kpercentage/kpercentage/icons/actions/cr32-action-button_cancel.png b/kpercentage/kpercentage/icons/actions/cr32-action-button_cancel.png Binary files differnew file mode 100644 index 00000000..c6464d90 --- /dev/null +++ b/kpercentage/kpercentage/icons/actions/cr32-action-button_cancel.png diff --git a/kpercentage/kpercentage/icons/actions/cr32-action-button_ok.png b/kpercentage/kpercentage/icons/actions/cr32-action-button_ok.png Binary files differnew file mode 100644 index 00000000..230de530 --- /dev/null +++ b/kpercentage/kpercentage/icons/actions/cr32-action-button_ok.png diff --git a/kpercentage/kpercentage/icons/actions/lo32-action-button_cancel.png b/kpercentage/kpercentage/icons/actions/lo32-action-button_cancel.png Binary files differnew file mode 100644 index 00000000..61f11054 --- /dev/null +++ b/kpercentage/kpercentage/icons/actions/lo32-action-button_cancel.png diff --git a/kpercentage/kpercentage/icons/actions/lo32-action-button_ok.png b/kpercentage/kpercentage/icons/actions/lo32-action-button_ok.png Binary files differnew file mode 100644 index 00000000..fab861e7 --- /dev/null +++ b/kpercentage/kpercentage/icons/actions/lo32-action-button_ok.png diff --git a/kpercentage/kpercentage/icons/hi128-app-kpercentage.png b/kpercentage/kpercentage/icons/hi128-app-kpercentage.png Binary files differnew file mode 100644 index 00000000..274585a1 --- /dev/null +++ b/kpercentage/kpercentage/icons/hi128-app-kpercentage.png diff --git a/kpercentage/kpercentage/icons/hi16-app-kpercentage.png b/kpercentage/kpercentage/icons/hi16-app-kpercentage.png Binary files differnew file mode 100644 index 00000000..8ed80516 --- /dev/null +++ b/kpercentage/kpercentage/icons/hi16-app-kpercentage.png diff --git a/kpercentage/kpercentage/icons/hi22-app-kpercentage.png b/kpercentage/kpercentage/icons/hi22-app-kpercentage.png Binary files differnew file mode 100644 index 00000000..a100c6ff --- /dev/null +++ b/kpercentage/kpercentage/icons/hi22-app-kpercentage.png diff --git a/kpercentage/kpercentage/icons/hi32-app-kpercentage.png b/kpercentage/kpercentage/icons/hi32-app-kpercentage.png Binary files differnew file mode 100644 index 00000000..db6bf2d6 --- /dev/null +++ b/kpercentage/kpercentage/icons/hi32-app-kpercentage.png diff --git a/kpercentage/kpercentage/icons/hi48-app-kpercentage.png b/kpercentage/kpercentage/icons/hi48-app-kpercentage.png Binary files differnew file mode 100644 index 00000000..d7d8e6a2 --- /dev/null +++ b/kpercentage/kpercentage/icons/hi48-app-kpercentage.png diff --git a/kpercentage/kpercentage/icons/hisc-app-kpercentage.svgz b/kpercentage/kpercentage/icons/hisc-app-kpercentage.svgz Binary files differnew file mode 100644 index 00000000..4a421a2a --- /dev/null +++ b/kpercentage/kpercentage/icons/hisc-app-kpercentage.svgz diff --git a/kpercentage/kpercentage/kanimation.cpp b/kpercentage/kpercentage/kanimation.cpp new file mode 100644 index 00000000..a0e77910 --- /dev/null +++ b/kpercentage/kpercentage/kanimation.cpp @@ -0,0 +1,224 @@ +// C/C++ includes +#include <stdlib.h> + +// Qt includes +#include <qfile.h> + +// KDE includes +#include <kdebug.h> + +// local includes +#include "kanimation.h" + +/////////// +// KFrame + +KFrame::KFrame( double nx, double ny, int nf ) +{ + x = nx; + y = ny; + f = nf; +} + +KFrame::~KFrame() +{ +} + + +//////////// +// KScene + +KScene::KScene() +{ + current_frame_number = 0; + setAutoDelete( TRUE ); + following = new QStrList( TRUE ); // deep copy + following->setAutoDelete( TRUE ); +} + +KScene::~KScene() +{ + delete following; +} + +KFrame *KScene::nextFrame() +{ + current_frame_number++; + if ( current_frame_number < count() ) + return at( current_frame_number ); + else + return 0; +} + +KFrame *KScene::currentFrame() +{ + if ( current_frame_number < count() ) + return at( current_frame_number ); + else + return 0; +} + +void KScene::addFollowingScene( const QString scene_name ) +{ + following->append( scene_name.latin1() ); +} + +void KScene::followingSceneName( QString& scene_name ) +{ + if ( following->count() == 0 ) + scene_name = ""; + else + scene_name = following->at( rand() % following->count() ); +} + +void KScene::setToStart() +{ + current_frame_number = 0; +} + + +///////////// +// KStoryBoard + +KStoryBoard::KStoryBoard( const QString filename ) : QDict<KScene>() +{ + current_scene = 0; + + QFile f( filename ); + KScene *c_scene = 0; + + if ( f.open( IO_ReadOnly ) ) // file opened successfully + { + QTextStream t( &f ); // use a text stream + + kdDebug() << "loading the story board..." << endl; + + while ( !t.eof() ) // until end of file... + { + QString s = t.readLine(); // line of text excluding '\n' + QString dbgString = s; + int pos = s.find ( "#"); + if (pos==-1) + pos = s.find ( ";"); + if ( pos > -1 ) + { + dbgString = s.mid( pos +1 ); + kdDebug() << "Comment: " << dbgString << endl; + s = s.left( pos ); + } + if ( !s.isEmpty() ) + { + QString command_word = s.section( " ", 0, 0 ); + // new scene beginning + if ( command_word == "name" ) + { + QString scene_name = s.section( " ", 1, 1 ); + c_scene = new KScene(); + insert( scene_name, c_scene ); + kdDebug() << "scene found: " << scene_name << endl; + } + // new frame + if ( c_scene && command_word == "move" ) + { + QString parameters = s.section( " ", 1, 1 ); + c_scene->append( new KFrame( + parameters.section( ",", 0, 0 ).toDouble(), + parameters.section( ",", 1, 1 ).toDouble(), + parameters.section( ",", 2, 2 ).toInt() ) ); + kdDebug() << parameters << endl; + } + // new following scene + if ( c_scene && command_word == "following" ) + { + kdDebug() << "following st..." << endl; + c_scene->addFollowingScene( s.section( " ", 1, 1 ) ); + } + } + } + } + f.close(); + // TODO check, if all scenes called by "following" exist + setToStart(); + } + + KStoryBoard::~KStoryBoard() + { + } + + KFrame *KStoryBoard::currentFrame() + { + if ( current_scene ) + return current_scene->currentFrame(); + else + return 0; + } + + KFrame *KStoryBoard::nextFrame() + { + if ( current_scene ) + { + if ( current_scene->nextFrame() ) + return current_scene->currentFrame(); + else + { + QString scene_name; + current_scene->followingSceneName( scene_name ); + current_scene = find( scene_name ); + if ( current_scene ) + { + current_scene->setToStart(); + return current_scene->currentFrame(); + } + else + return 0; + } + } + else + { + return 0; + } + } + + void KStoryBoard::setToStart() + { + current_scene = find( "init" ); + if ( current_scene ) + current_scene->setToStart(); + } + + ////////// + // KAnimation + + KAnimation::KAnimation( const QString story_filename, + QCanvasPixmapArray * a, QCanvas * canvas ) : + QCanvasSprite( a, canvas ) + { + story = new KStoryBoard( story_filename ); + } + + KAnimation::~KAnimation() + { + delete story; + } + + void KAnimation::advance( int phase ) + { + if ( phase == 1 ) + { + KFrame * f_ = story->nextFrame(); + if ( f_ ) + move( f_->x, f_->y, f_->f ); + } + } + + void KAnimation::setToStart() + { + story->setToStart(); + KFrame *f_ = story->currentFrame(); + if ( f_ ) + move( f_->x, f_->y, f_->f ); + } + + + + diff --git a/kpercentage/kpercentage/kanimation.h b/kpercentage/kpercentage/kanimation.h new file mode 100644 index 00000000..97d492f5 --- /dev/null +++ b/kpercentage/kpercentage/kanimation.h @@ -0,0 +1,104 @@ +#ifndef KANIMATION_H +#define KANIMATION_H + +#include <qcanvas.h> +#include <qdict.h> + +class QString; + +/** + * This class contains information about one frame. + */ +class KFrame +{ + public: + /** + * The constructor gets: + * @param nx the position x coordinate + * @param ny the position coordinate + * @param nf the frame number + */ + KFrame( double nx, double ny, int nf ); + /** + * The destructor is empty yet + */ + ~KFrame(); + + double x, y; // position + int f; // frame number +}; + +/** + * This class handles a list of frames, called "scene". + * Also a list of possibly following scene names is maintained. + */ +class KScene: public QPtrList<KFrame> +{ + public: + /** + * The constructor initiates the list of following scene names. + * Attention: this list uses the autoDelete functionality as the KScene itself do. + */ + KScene(); + /** + * The destructor deletes the list of following scene names. + */ + ~KScene(); + + /** + * @return a pointer to the current frame or 0, if the list is empty. + */ + KFrame *currentFrame(); + /** + * increases the current frame. Resets the scene, if the laste frame was reached. + * @return a pointer to the next frame or 0, if there is no frame left or the list is empty + */ + KFrame *nextFrame(); + + /** + * adds a scene name + */ + void addFollowingScene( const QString scene_name ); + /** + * selects a scene out of the list of possibly following scenes. + */ + void followingSceneName( QString& scene_name); + + void setToStart(); + + private: + QStrList *following; + unsigned int current_frame_number; +}; + +/** + * KStoryBoard + */ +class KStoryBoard: public QDict<KScene> +{ + public: + KStoryBoard( const QString filename ); + ~KStoryBoard(); + + KFrame *nextFrame(); + KFrame *currentFrame(); + void setToStart(); + + private: + KScene *current_scene; +}; + +class KAnimation: public QCanvasSprite +{ + public: + KAnimation( const QString stroy_filename, QCanvasPixmapArray *a, QCanvas *canvas ); + ~KAnimation(); + + virtual void advance( int phase ); + + void setToStart(); + + KStoryBoard *story; +}; + +#endif diff --git a/kpercentage/kpercentage/kanswer.cpp b/kpercentage/kpercentage/kanswer.cpp new file mode 100644 index 00000000..3042008c --- /dev/null +++ b/kpercentage/kpercentage/kanswer.cpp @@ -0,0 +1,255 @@ +/*************************************************************************** + kanswer.cpp - description + ------------------- + begin : Fri Nov 30 2001 + copyright : (C) 2001 by Matthias Messmer & + Carsten Niehaus & + Robert Gogolok + email : bmlmessmer@web.de & + cniehaus@gmx.de & + mail@robert-gogolok.de +***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// C/C++ includes +#include <stdlib.h> +#include <assert.h> + +// Qt includes +#include <qfile.h> +#include <qlabel.h> +#include <qlayout.h> + +// KDE includes +#include <kdebug.h> +#include <kiconloader.h> +#include <klocale.h> +#include <kpushbutton.h> +#include <kstandarddirs.h> +#include <kstdguiitem.h> + +// local includes +#include "kanimation.h" +#include "kanswer.h" + +KAnswer::KAnswer( QWidget *parent ): KDialog( parent, "answer", TRUE ) +{ + setFont( parent->font() ); + // fix size for the background pixmap + setFixedSize( QSize( 430, 190 ) ); + + // load background pixmap + QPixmap bgp( locate( "data", "kpercentage/pics/kanswer_bg.png" ) ); + setBackgroundPixmap( bgp ); + + setupSprite(); + + ButtonOK = new KPushButton( KStdGuiItem::ok(), this ); + // for the bottons edges + ButtonOK->setBackgroundOrigin( QPushButton::ParentOrigin ); + ButtonOK->setIconSet( QIconSet( DesktopIcon( "button_ok" ) ) ); +// ButtonOK->hide(); + + TextLabelAnswer = new QLabel( this ); + // make the label transparent + TextLabelAnswer->setBackgroundOrigin( QLabel::ParentOrigin ); + TextLabelAnswer->setBackgroundPixmap( bgp ); + + canvas->setBackgroundPixmap( bgp ); + canvas_view->setBackgroundOrigin( QCanvasView::ParentOrigin ); + canvas_view->setBackgroundPixmap( bgp ); + + /////// + // begin layouting + /////// + mainLayout = new QHBoxLayout( this ); + mainLayout->setDirection(QBoxLayout::LeftToRight); + +// mainLayout->addSpacing( 20 ); + + QVBoxLayout *leftLayout = new QVBoxLayout( mainLayout, -1, "main" ); +// leftLayout->addSpacing( 20 ); + leftLayout->addWidget( canvas_view ); + leftLayout->addSpacing( 20 ); + leftLayout->addStretch(); + + mainLayout->addSpacing( 60 ); + + QVBoxLayout *rightLayout = new QVBoxLayout( mainLayout, -1, "right" ); + + rightLayout->addStretch( 2 ); + + QHBoxLayout *topLayout = new QHBoxLayout( rightLayout, -1, "top" ); + topLayout->setDirection(QBoxLayout::LeftToRight); + topLayout->addStretch(); + topLayout->addWidget( TextLabelAnswer ); + topLayout->addStretch(); + + rightLayout->addStretch( 2 ); + + QHBoxLayout *bottomLayout = new QHBoxLayout( rightLayout, -1, "bottom" ); + bottomLayout->setDirection(QBoxLayout::LeftToRight); + bottomLayout->addStretch(); + bottomLayout->addWidget( ButtonOK ); + bottomLayout->addSpacing( 20 ); + + rightLayout->addSpacing( 20 ); + /////// + // end layouting + /////// + + connect( ButtonOK, SIGNAL( clicked() ), this, SLOT( accept() ) ); + loadAnswers(); +} + +void KAnswer::loadAnswers() +{ + // helping to manage the IO + QString s; + QFile f; + QTextStream t; + + //reading proper answers from file + f.setName( locate( "data", "kpercentage/right.txt" ) ); + if ( f.open( IO_ReadOnly ) ) // file opened successfully + { + QTextStream t( &f ); // use a text stream + while ( !t.eof() ) // until end of file... + { + s = t.readLine(); // line of text excluding '\n' + rightAnswerList.append( s ); + } + } + f.close(); + + // reading proper answers from file + f.setName( locate( "data", "kpercentage/wrong.txt" ) ); + if ( f.open( IO_ReadOnly ) ) // file opened successfully + { + QTextStream t( &f ); // use a text stream + while ( !t.eof() ) // until end of file... + { + s = t.readLine(); // line of text excluding '\n' + wrongAnswerList.append( s ); + } + } + f.close(); +} + +void KAnswer::setAnswer( int modus ) +{ + bool correct; + switch ( modus ) + { + case 1: + setCaption( i18n( "Congratulations!" ) ); + TextLabelAnswer->setText( getRightAnswer() ); + correct = true; + break; + case 2: + setCaption( i18n( "Error!" ) ); + TextLabelAnswer->setText( getWrongAnswer() ); + correct = false; + break; + case 3: + setCaption( i18n( "Oops!" ) ); + TextLabelAnswer->setText( i18n( "Mistyped!" ) ); + correct = false; + break; + case 4: + setCaption( i18n( "Congratulations!" ) ); + TextLabelAnswer->setText( i18n( "Great!\nYou managed all\nthe exercises!" ) ); + correct = true; + break; + default: + assert(false); + correct = false; + } + + if (correct) + { + wrong_animation->hide(); + right_animation->show(); + } + else + { + wrong_animation->show(); + right_animation->hide(); + } + + wrong_animation->setToStart(); + wrong_animation->setAnimated( !correct ); + right_animation->setToStart(); + right_animation->setAnimated( correct ); + canvas->setAllChanged(); + canvas->update(); + canvas->setAdvancePeriod( advPer ); + + // this seems to be needed for proper showing TextLabelAnswer :-( + resize( width(), height() ); +} + +// reads one answer out of the list by chance +QString KAnswer::getRightAnswer() +{ + return i18n( rightAnswerList[ random() % rightAnswerList.count() ].utf8() ); +} + +// reads one answer out of the list by chance +QString KAnswer::getWrongAnswer() +{ + return i18n( wrongAnswerList[ random() % wrongAnswerList.count() ].utf8() ); +} + + +// Animation stuff + +void KAnswer::setupSprite() +{ + + advPer = 80; + + canvas = new QCanvas( this ); + canvas->resize( size().width(), size().height() ); + pixs = new QCanvasPixmapArray( locate( "data", "kpercentage/pics/" )+"smily%1.png", 7 ); + + right_animation = new KAnimation( locate( "data", "kpercentage/story/right.story" ), pixs , canvas ); + right_animation->setAnimated( TRUE ); + wrong_animation = new KAnimation( locate( "data", "kpercentage/story/wrong.story" ), pixs , canvas ); + wrong_animation->setAnimated( TRUE ); + + canvas_view = new QCanvasView( canvas, this ); + canvas_view->resize( size() ); + canvas_view->setVScrollBarMode( QCanvasView::AlwaysOff ); + canvas_view->setHScrollBarMode( QCanvasView::AlwaysOff ); + canvas_view->setFrameStyle( QCanvasView::NoFrame ); +} + + +void KAnswer::timerEvent( QTimerEvent *event ) +{ + accept(); +} + +int KAnswer::exec() +{ + killTimers(); + startTimer( 3000 ); // 5 seconds + return KDialog::exec(); +} + +void KAnswer::accept() +{ + canvas->setAdvancePeriod( -1 ); // stop all animation + KDialog::accept(); +} + +#include "kanswer.moc" diff --git a/kpercentage/kpercentage/kanswer.h b/kpercentage/kpercentage/kanswer.h new file mode 100644 index 00000000..32519398 --- /dev/null +++ b/kpercentage/kpercentage/kanswer.h @@ -0,0 +1,104 @@ +/*************************************************************************** + kanswer.h - description + ------------------- + begin : Fri Nov 30 2001 + copyright : (C) 2001 by Matthias Messmer & + Carsten Niehaus & + Robert Gogolok + email : bmlmessmer@web.de & + cniehaus@gmx.de & + mail@robert-gogolok.de +***************************************************************************/ + +/*************************************************************************** + * * + * 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 KANSWER_H +#define KANSWER_H + +// Qt includes + +// KDE includes +#include <kdialog.h> + +class QCanvas; +class QCanvasPixmapArray; +class QCanvasSprite; +class QCanvasView; +class QHBoxLayout; +class QLabel; + +class KAnimation; + +class KPushButton; + +/** + * A small dialog, which gives feedback, if the input was wrong or false. + * It provides reading several sentences from file and selecting by chance. + * + * @author Matthias Messmer & Carsten Niehaus & Robert Gogolok + */ +class KAnswer : public KDialog +{ + Q_OBJECT + public: + /** + * The constructor doesn't need any parameters but the parent, + * because it will not be used in any other context. + * + * @param parent Parent widget for modal functionality + */ + KAnswer( QWidget *parent ); + + // public functions + /** setting/changing feedback text and pic */ + void setAnswer( int modus ); + + public slots: + /** reimplemented: close the window after some time */ + void timerEvent( QTimerEvent * ); + void accept(); + + int exec(); + + private: + // private functions + /** Loads feadback sentences from file */ + void loadAnswers(); + /** Gets a answer by chance for well solved tasks. */ + QString getRightAnswer(); + /** Gets a answer by chance for not solved tasks. */ + QString getWrongAnswer(); + + // GUI widgets + /** Label for the answer text */ + QLabel *TextLabelAnswer; + /** OK button */ + KPushButton *ButtonOK; + + /** List of feedback text for well solved tasks. */ + QStringList rightAnswerList; + /** List of feedback text for not solved tasks. */ + QStringList wrongAnswerList; + + QHBoxLayout *mainLayout; + + KAnimation *right_animation; + KAnimation *wrong_animation; + + int advPer; + + QCanvasView *canvas_view; + QCanvasPixmapArray *pixs; + QCanvas *canvas; + + void setupSprite(); +}; + +#endif diff --git a/kpercentage/kpercentage/kpercentage.cpp b/kpercentage/kpercentage/kpercentage.cpp new file mode 100644 index 00000000..d8ff8e34 --- /dev/null +++ b/kpercentage/kpercentage/kpercentage.cpp @@ -0,0 +1,231 @@ +/*************************************************************************** + kpercentage.cpp - description + ------------------- + begin : Fre Nov 16 14:52:33 CET 2001 + copyright : (C) 2001 by Matthias Messmer & + Carsten Niehaus & + Robert Gogolok + email : bmlmessmer@web.de & + cniehaus@gmx.de & + mail@robert-gogolok.de +***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// C/C++ includes +#include <stdlib.h> + +// Qt includes +#include <qlabel.h> +#include <qlayout.h> +#include <qtooltip.h> +#include <qwhatsthis.h> + +// KDE includes +#include <khelpmenu.h> +#include <kiconloader.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kpushbutton.h> +#include <kstandarddirs.h> + +//local includes +#include "kpercentage.h" +#include "ksplashscreen.h" + +KPercentage::KPercentage( const char *name ) : + KDialog ( 0, name ) +{ + // show splash screen + KSplashScreen * splash_screen = new KSplashScreen( this, "splashscreen" ); + splash_screen->show(); + splash_screen->raise(); + + // Icon loader for the button's icons + KIconLoader icon_loader; + + // let's set a suitable, not too small font size + QFont the_font( font() ); + the_font.setPointSize( 14 ); + //the_font.setBold(true); + setFont( the_font ); + + // prepare exercise window, that will use the fontsize above! + percent_main = new KPercentMain( this, "KPercentage" ); + + // fixed geometry bacause of background pixmap + setFixedSize( QSize( 548, 248 ) ); + + /** load and set background pixmap */ + QPixmap bgp( locate( "data", QApplication::reverseLayout() ? "kpercentage/pics/kpercentage_bg_rtl.png" : "kpercentage/pics/kpercentage_bg.png" ) ); + setBackgroundPixmap( bgp ); + + + QLabel *label_number = new QLabel( i18n( "Number of tasks:" ), this ); + QLabel *label_level = new QLabel( i18n( "Level:" ), this ); + QLabel *label_choose = new QLabel( i18n( "Choose an exercise type:" ), this ); + + /** make labels transparent */ + label_number->setBackgroundPixmap( bgp ); + label_number->setBackgroundOrigin( QLabel::ParentOrigin ); + label_level->setBackgroundPixmap( bgp ); + label_level->setBackgroundOrigin( QLabel::ParentOrigin ); + label_choose->setBackgroundPixmap( bgp ); + label_choose->setBackgroundOrigin( QLabel::ParentOrigin ); + + KPushButton *button_basevalue = new KPushButton( i18n( "x% &of ?? = y" ), this ); + KPushButton *button_percentvalue = new KPushButton( i18n( "x% of &y = ??" ), this ); + KPushButton *button_percentage = new KPushButton( i18n( "??% o&f x = y" ), this ); + KPushButton *button_random = new KPushButton( i18n( "??" ), this ); + KPushButton *button_help = new KPushButton( KStdGuiItem::help().text(), this ); + button_help->setIconSet( QIconSet( icon_loader.loadIcon( "help", KIcon::NoGroup, 32 ) ) ); + KHelpMenu *help_menu = new KHelpMenu( this, KGlobal::instance()->aboutData(), true ); + button_help->setPopup( ( QPopupMenu* ) ( help_menu->menu() ) ); + KPushButton *button_close = new KPushButton( i18n( "E&xit" ), this ); + button_close->setIconSet( QIconSet( icon_loader.loadIcon( "exit", KIcon::NoGroup, 32 ) ) ); + + combo_box_level = new KComboBox( this ); + combo_box_level->insertItem( i18n( "Easy" ) ); + combo_box_level->insertItem( i18n( "Medium" ) ); + combo_box_level->insertItem( i18n( "Crazy" ) ); + + spin_box_number = new QSpinBox( 1, 10, 1, this ); + spin_box_number->setValue( 5 ); + + // connecting all the slots + connect( button_basevalue, SIGNAL( clicked() ), this, SLOT( selBasevalue() ) ); + connect( button_percentvalue, SIGNAL( clicked() ), this, SLOT( selPercentvalue() ) ); + connect( button_percentage, SIGNAL( clicked() ), this, SLOT( selPercentage() ) ); + connect( button_random, SIGNAL( clicked() ), this, SLOT( selRandom() ) ); + connect( button_help, SIGNAL( clicked() ), this, SLOT( needHelp() ) ); + connect( button_close, SIGNAL( clicked() ), this, SLOT( accept() ) ); + + //////// + // begin layouting + //////// + QVBoxLayout *main_layout = new QVBoxLayout( this, 20, 20, "main_layout" ); + main_layout->setResizeMode( QLayout::FreeResize ); + + QHBoxLayout *top_layout = new QHBoxLayout( main_layout, -1, "top_layout" ); + top_layout->addWidget( label_number ); + top_layout->addWidget( spin_box_number ); + top_layout->addSpacing( 20 ); + top_layout->addStretch(); + top_layout->addWidget( label_level ); + top_layout->addWidget( combo_box_level ); + + main_layout->addSpacing( 40 ); + main_layout->addStretch(); + + QHBoxLayout *bottom_layout = new QHBoxLayout( main_layout, -1, "bottom_layout" ); + QVBoxLayout *bLeftLayout = new QVBoxLayout( bottom_layout ); + bLeftLayout->addWidget( label_choose ); + bLeftLayout->addSpacing( 10 ); + + QGridLayout *grid_layout = new QGridLayout( bLeftLayout, 2, 2, 10 ); + grid_layout->addWidget( button_basevalue, 0, 0 ); + grid_layout->addWidget( button_percentvalue, 1, 0 ); + grid_layout->addWidget( button_percentage, 0, 1 ); + grid_layout->addWidget( button_random, 1, 1 ); + + bottom_layout->addStretch(); + + QVBoxLayout *b_right_layout = new QVBoxLayout( bottom_layout ); + b_right_layout->addStretch(); + b_right_layout->addWidget( button_help ); + b_right_layout->addSpacing( 10 ); + b_right_layout->addWidget( button_close ); + + main_layout->addStretch(); + //////// + // end layouting + //////// + + //////// + // Tooltips + QToolTip::add( button_basevalue, i18n( "Exercises with base value omitted" ) ); + QToolTip::add( button_percentvalue, i18n( "Exercises with percent value omitted" ) ); + QToolTip::add( button_percentage, i18n( "Exercises with percentage omitted" ) ); + QToolTip::add( button_random, i18n( "Several exercise types in random" ) ); + QToolTip::add( spin_box_number, i18n( "Choose the number of exercises from 1 to 10." ) ); + QToolTip::add( combo_box_level, i18n( "Choose the level of difficulty." ) ); + QToolTip::add( button_close, i18n( "Close KPercentage." ) ); + QToolTip::add( button_help, i18n( "Get some help." ) ); + + //////// + // WhatsThis + QWhatsThis::add( button_basevalue, i18n( "Click here to start a sequence of exercises where the base value is omitted.") ); + QWhatsThis::add( button_percentvalue, i18n( "Click here to start a sequence of exercises where the percent value is omitted." ) ); + QWhatsThis::add( button_percentage, i18n( "Click here to start a sequence of exercises where the percentage is omitted." ) ); + QWhatsThis::add( button_random, i18n( "Click here to start a sequence of exercises where one value is omitted at random." ) ); + QWhatsThis::add( spin_box_number, i18n( "Here you can adjust the number of exercises from 1 to 10." ) ); + QWhatsThis::add( combo_box_level, i18n( "Choose one of the levels <i>easy</i>, <i>medium</i>, and <i>crazy</i>." ) ); + QWhatsThis::add( button_close, i18n( "Close KPercentage." ) ); + QWhatsThis::add( button_help, i18n( "Get some help." ) ); +} + +void KPercentage::selPercentage() +{ + // set the proper value for KPercentMain::selected_type + percent_main->selected_type = SEL_PERCENTAGE; + // and lets go! + startExercise(); +} + +void KPercentage::selBasevalue() +{ + // set the proper value for KPercentMain::selected_type + percent_main->selected_type = SEL_BASEVALUE; + // and lets go! + startExercise(); +} + +void KPercentage::selPercentvalue() +{ + // set the proper value for KPercentMain::selected_type + percent_main->selected_type = SEL_PERCENTVALUE; + // and lets go! + startExercise(); +} + +void KPercentage::selRandom() +{ + // set the proper value for KPercentMain::selected_type + percent_main->selected_type = SEL_RANDOM; + // and lets go! + startExercise(); +} + +/** No descriptions */ +void KPercentage::startExercise() +{ + // copy the actual settings to the KPercentMain instance + percent_main->setNumber( spin_box_number->value() ); + percent_main->selected_level = combo_box_level->currentItem(); + percent_main->initExercise(); + QPoint p = pos(); + hide(); + percent_main->move( p ); + percent_main->exec(); + move( p ); + show(); +} + +void KPercentage::needHelp() +{ + kapp->invokeHelp( "", "kpercentage" ); +} + +void KPercentage::closeEvent( QCloseEvent * ) +{ + exit( 0 ); +} + +#include "kpercentage.moc" diff --git a/kpercentage/kpercentage/kpercentage.desktop b/kpercentage/kpercentage/kpercentage.desktop new file mode 100644 index 00000000..e09e5eff --- /dev/null +++ b/kpercentage/kpercentage/kpercentage.desktop @@ -0,0 +1,82 @@ +[Desktop Entry] +Name=KPercentage +Name[af]=K-Persentasie +Name[ar]=النسبة المئوية +Name[bn]=কে-পারà§à¦¸à§‡à¦¨à§à¦Ÿà§‡à¦œ +Name[cy]=Kamran +Name[fo]=KProsent +Name[hi]=के-परसेंटेज +Name[hr]=KPostotak +Name[is]=KPrósentur +Name[mn]=KХувь +Name[ne]=केडीई पà¥à¤°à¤¤à¤¿à¤¶à¤¤ +Name[sv]=Kpercentage +Name[ta]=கேவிழà¯à®•à¯à®•à®¾à®Ÿà¯ +Name[ven]=Zwa nomboro ya dana +Name[vi]=Phần trăm K +GenericName=Exercise Percentages +GenericName[af]=Oefen Persentasies +GenericName[ar]=تمرين النسبة المئويّة +GenericName[be]=Практыкаванні з працÑнтамі +GenericName[bg]=Ð£Ð¿Ñ€Ð°Ð¶Ð½ÐµÐ½Ð¸Ñ Ñ Ð¿Ñ€Ð¾Ñ†ÐµÐ½Ñ‚Ð¸ +GenericName[bn]=শতাংশের অংক অনà§à¦¶à§€à¦²à¦¨ করà§à¦¨ +GenericName[bs]=Vježbajte postotke +GenericName[ca]=Exercita els percentatges +GenericName[cs]=ProcviÄovánà procent +GenericName[csb]=Cwiczënczi z procentów +GenericName[cy]=Ymarfer Canrannau +GenericName[da]=Øvelser med procent +GenericName[de]=Prozentrechnung üben +GenericName[el]=Εξάσκηση με ποσοστά +GenericName[eo]=Ekzercado de elcentoj +GenericName[es]=Ejercitar porcentajes +GenericName[et]=Harjutused protsentidega +GenericName[eu]=Entrenatu portzentaiak +GenericName[fa]=تمرین درصدها +GenericName[fi]=Harjoittele prosentteja +GenericName[fr]=Exercices pratiques avec des pourcentages +GenericName[gl]=Exercicios de Porcentaxes +GenericName[he]=מתרגל ××—×•×–×™× +GenericName[hi]=पà¥à¤°à¤¤à¤¿à¤¶à¤¤ अà¤à¥à¤¯à¤¾à¤¸ +GenericName[hr]=Vježbajte s postocima +GenericName[hu]=SzázalékszámÃtó +GenericName[is]=Æfa prósentureikninga +GenericName[it]=Esercizi con le percentuali +GenericName[ja]=パーセンテージ (百分率) ã®ç·´ç¿’ +GenericName[ka]=სáƒáƒ•áƒáƒ ჯიშáƒáƒ”ბი პრáƒáƒªáƒ”ნტებთáƒáƒœ +GenericName[km]=លំហាážáŸ‹â€‹áž—ាគរយ +GenericName[lt]=Procentų mokymosi priemonÄ— +GenericName[mk]=Вежбајте проценти +GenericName[ms]=Peratus Latihan +GenericName[nb]=Prosent-øvelser +GenericName[nds]=Perzentreken öven +GenericName[ne]=पà¥à¤°à¤¤à¤¿à¤¶à¤¤ अà¤à¥à¤¯à¤¾à¤¸ +GenericName[nl]=Percentages oefenen +GenericName[nn]=Prosentøvingar +GenericName[pa]=ਫੀ-ਸਦੀ ਅà¨à¨¿à¨†à¨¸ +GenericName[pl]=Ćwiczenia z procentów +GenericName[pt]=ExercÃcios com Percentagens +GenericName[pt_BR]=ExercÃcios de porcentagens +GenericName[ru]=Ð£Ð¿Ñ€Ð°Ð¶Ð½ÐµÐ½Ð¸Ñ Ñ Ð¿Ñ€Ð¾Ñ†ÐµÐ½Ñ‚Ð°Ð¼Ð¸ +GenericName[sk]=CviÄenie percent +GenericName[sl]=Vaje z odstotki +GenericName[sr]=Вежбајте проценте +GenericName[sr@Latn]=Vežbajte procente +GenericName[sv]=Öva procenttal +GenericName[ta]=பயிறà¯à®žà®¿ விழà¯à®•à¯à®•à®¾à®Ÿà¯ +GenericName[tg]=Машқҳо барои ҳиÑоби фоиз +GenericName[tr]=Çalışma Oranları +GenericName[uk]=Вправи з відÑотками +GenericName[vi]=Bà i táºp tÃnh Phần trăm +GenericName[zh_CN]=ç»ƒä¹ ç™¾åˆ†æ•° +GenericName[zh_TW]=練習百分率計算 +Comment= +Comment[bn]=মনà§à¦¤à¦¬à§à¦¯ +Comment[sl]=Periodna tabela elementov +Exec=kpercentage +Terminal=false +Icon=kpercentage +Type=Application +DocPath=kpercentage/index.html + +Categories=Qt;KDE;Education;Math; diff --git a/kpercentage/kpercentage/kpercentage.docbook b/kpercentage/kpercentage/kpercentage.docbook new file mode 100644 index 00000000..c356b9f8 --- /dev/null +++ b/kpercentage/kpercentage/kpercentage.docbook @@ -0,0 +1,556 @@ +<?xml version="1.0" ?> +<!DOCTYPE book PUBLIC "-//KDE//DTD DocBook XML V4.1-Based Variant V1.0//EN" "dtd/kdex.dtd" [ + <!ENTITY kappname "&kpercentage;"><!-- replace kpercentage here --> + <!ENTITY % addindex "IGNORE"> + <!ENTITY % English "INCLUDE"><!-- change language only here --> + + + <!-- Do not define any other entities; instead, use the entities + from kde-genent.entities and $LANG/user.entities. --> +]> +<!-- kdoctemplate v0.8 October 1 1999 + Minor update to "Credits and Licenses" section on August 24, 2000 + Removed "Revision history" section on 22 January 2001 --> + +<!-- +This template was designed by: David Rugge davidrugge@mindspring.com +with lots of help from: Eric Bischoff ebisch@cybercable.tm.fr +and Frederik Fouvry fouvry@sfs.nphil.uni-tuebingen.de +of the KDE DocBook team. + +You may freely use this template for writing any sort of KDE documentation. +If you have any changes or improvements, please let us know. + +In the future, we may want to change from SGML-based DocBook to XML-based +DocBook. To make this change easier, please be careful : +- in XML, the case of the <tags> and attributes is relevant ; +- also, quote all attributes. + +Please don't forget to remove all these comments in your final documentation, +thanks ;-). +--> + +<!-- ................................................................ --> + +<!-- The language must NOT be changed here. --> + +<book lang="&language;"> + +<!-- This header contains all of the meta-information for the document such +as Authors, publish date, the abstract, and Keywords --> + +<bookinfo> +<title>The KPercentage Handbook</title> + +<authorgroup> +<author> +<firstname>George</firstname> +<othername>N.</othername> +<surname>Ugnacious</surname> +<affiliation> +<address><email>gnu@kde.org</email></address> +</affiliation> +</author> +</authorgroup> + +<!-- TRANS:ROLES_OF_TRANSLATORS --> + +<copyright> +<year>1999</year> +<year>2000</year> +<holder>George N. Ugnacious</holder> +</copyright> +<!-- Translators: put here the copyright notice of the translation --> +<!-- Put here the FDL notice. Read the explanation in fdl-notice.docbook + and in the FDL itself on how to use it. --> +<legalnotice>&FDLNotice;</legalnotice> + +<!-- Date and version information of the documentation +Don't forget to include this last date and this last revision number, we +need them for translation coordination ! +Please respect the format of the date (DD/MM/YYYY) and of the version +(V.MM.LL), it could be used by automation scripts. +Do NOT change these in the translation. --> + +<date>03/04/1999</date> +<releaseinfo>1.01.00</releaseinfo> + +<!-- Abstract about this handbook --> + +<abstract> +<para> +&kpercentage; is an application specially designed to do nothing you would +ever want. +</para> +</abstract> + +<!-- This is a set of Keywords for indexing by search engines. +Please at least include KDE, the KDE package it is in, the name + of your application, and a few relevant keywords. --> + +<keywordset> +<keyword>KDE</keyword> +<keyword>kdeutils</keyword> +<keyword>Kapp</keyword> +<keyword>nothing</keyword> +<keyword>nothing else</keyword> +</keywordset> + +</bookinfo> + +<!-- The contents of the documentation begin here. Label +each chapter so with the id attribute. This is necessary for two reasons: it +allows you to easily reference the chapter from other chapters of your +document, and if there is no ID, the name of the generated HTML files will vary +from time to time making it hard to manage for maintainers and for the CVS +system. Any chapter labelled (OPTIONAL) may be left out at the author's +discretion. Other chapters should not be left out in order to maintain a +consistent documentation style across all KDE apps. --> + +<chapter id="introduction"> +<title>Introduction</title> + +<!-- The introduction chapter contains a brief introduction for the +application that explains what it does and where to report +problems. Basically a long version of the abstract. Don't include a +revision history. (see installation appendix comment) --> + +<para> +&kapp; is a program that lets you do absolutely nothing. Please report +any problems or feature requests to the KDE mailing lists. +</para> +</chapter> + +<chapter id="using-kapp"> +<title>Using KPercentage</title> + +<!-- This chapter should tell the user how to use your app. You should use as +many sections (Chapter, Sect1, Sect3, etc...) as is necessary to fully document +your application. --> + +<para> + +<!-- Note that all graphics should be in .png format. Use no gifs because of +patent issues. --> + +<screenshot> +<screeninfo>Here's a screenshot of &kapp;</screeninfo> + <mediaobject> + <imageobject> + <imagedata fileref="screenshot.png" format="PNG"/> + </imageobject> + <imageobject> + <imagedata fileref="screenshot.eps" format="EPS"/> + </imageobject> + <textobject> + <phrase>Screenshot</phrase> + </textobject> + </mediaobject> +</screenshot> +</para> + + +<sect1 id="kapp-features"> +<title>More Kapp features</title> + +<para>It slices! It dices! and it comes with a free toaster!</para> +<para> +The Squiggle Tool <guiicon><inlinemediaobject> + <imageobject> + <imagedata fileref="squiggle.png" format="PNG"/> + </imageobject> + <imageobject> + <imagedata fileref="squiggle.eps" format="EPS"/> + </imageobject> + <textobject> + <phrase>Squiggle</phrase> + </textobject> +</inlinemediaobject></guiicon> is used to draw squiggly lines all over +the &kpercentage; main window. It's not a bug, it's a feature! +</para> + +</sect1> +</chapter> + +<chapter id="commands"> +<title>Command Reference</title> + +<!-- (OPTIONAL, BUT RECOMMENDED) This chapter should list all of the +application windows and their menubar and toolbar commands for easy reference. +Also include any keys that have a special function but have no equivalent in the +menus or toolbars. This may not be necessary for small apps or apps with no tool +or menu bars. --> + +<sect1 id="kapp-mainwindow"> +<title>The main KPercentage window</title> +<para></para> + +<sect2> +<title>The File Menu</title> +<para> +<variablelist> +<varlistentry> +<term><menuchoice> +<shortcut> +<keycombo><keycap>Ctrl</keycap><keycap>n</keycap></keycombo> +</shortcut> +<guimenu>File</guimenu> +<guimenuitem>New</guimenuitem> +</menuchoice></term> +<listitem><para><action>Creates a new document</action></para></listitem> +</varlistentry> +<varlistentry> +<term><menuchoice> +<shortcut> +<keycombo><keycap>Ctrl</keycap><keycap>s</keycap></keycombo> +</shortcut> +<guimenu>File</guimenu> +<guimenuitem>Save</guimenuitem> +</menuchoice></term> +<listitem><para><action>Saves the document</action></para></listitem> +</varlistentry> +<varlistentry> +<term><menuchoice> +<shortcut> +<keycombo><keycap>Ctrl</keycap><keycap>q</keycap></keycombo> +</shortcut> +<guimenu>File</guimenu> +<guimenuitem>Quit</guimenuitem> +</menuchoice></term> +<listitem><para><action>Quits</action> &kapp;</para></listitem> +</varlistentry> +</variablelist> +</para> + +</sect2> + +</sect1> +</chapter> + +<chapter id="developers"> +<title>Developer's Guide to KPercentage</title> + +<!-- (OPTIONAL) A Programming/Scripting reference chapter should be +used for apps that use plugins or that provide their own scripting hooks +and/or development libraries. --> + +<para> +Programming &kpercentage; plugins is a joy to behold. Just read through the next +66 pages of API's to learn how! +</para> + +<!-- Use refentries to describe APIs. Refentries are fairly complicated and you +should consult the docbook reference for further details. The example below was +taken from that reference and shortened a bit for readability. --> + +<refentry id="re-1007-unmanagechildren-1"> +<refmeta> +<refentrytitle>XtUnmanageChildren</refentrytitle> +<refmiscinfo>Xt - Geometry Management</refmiscinfo> +</refmeta> +<refnamediv> +<refname>XtUnmanageChildren +</refname> +<refpurpose>remove a list of children from a parent widget's managed list. +</refpurpose> +<indexterm id="ix-1007-unmanagechildren-1"><primary>widgets</primary><secondary>removing</secondary></indexterm> +<indexterm id="ix-1007-unmanagechildren-2"><primary>XtUnmanageChildren</primary></indexterm> +</refnamediv> +<refsynopsisdiv> +<refsynopsisdivinfo> +<date>4 March 1996</date> +</refsynopsisdivinfo> +<synopsis> +void XtUnmanageChildren(<replaceable class="parameter">children</replaceable>, <replaceable class="parameter">num_children</replaceable>) + WidgetList <replaceable class="parameter">children</replaceable>; + Cardinal <replaceable class="parameter">num_children</replaceable>; +</synopsis> + +<refsect2 id="r2-1007-unmanagechildren-1"> +<title>Inputs</title> +<variablelist> +<varlistentry> +<term><replaceable class="parameter">children</replaceable> +</term> +<listitem> +<para>Specifies an array of child widgets. Each child must be of +class RectObj or any subclass thereof. +</para> +</listitem> +</varlistentry> +<varlistentry> +<term><replaceable class="parameter">num_children</replaceable> +</term> +<listitem> +<para>Specifies the number of elements in <replaceable class="parameter">children</replaceable>. +</para> +</listitem> +</varlistentry> +</variablelist> +</refsect2></refsynopsisdiv> + +<refsect1 id="r1-1007-unmanagechildren-1"> +<title>Description +</title> +<para><function>XtUnmanageChildren()</function> unmaps the specified widgets +and removes them from their parent's geometry management. +The widgets will disappear from the screen, and (depending +on its parent) may no longer have screen space allocated for +them. +</para> +<para>Each of the widgets in the <replaceable class="parameter">children</replaceable> array must have +the same parent. +</para> +<para>See the “Algorithm” section below for full details of the +widget unmanagement procedure. +</para> +</refsect1> + +<refsect1 id="r1-1007-unmanagechildren-2"> +<title>Usage</title> +<para>Unmanaging widgets is the usual method for temporarily +making them invisible. They can be re-managed with +<function>XtManageChildren()</function>. +</para> +<para>You can unmap a widget, but leave it under geometry +management by calling <function>XtUnmapWidget()</function>. You can +destroy a widget's window without destroying the widget by +calling <function>XtUnrealizeWidget()</function>. You can destroy a +widget completely with <function>XtDestroyWidget()</function>. +</para> +<para>If you are only going to unmanage a single widget, it is +more convenient to call <function>XtUnmanageChild()</function>. It is +often more convenient to call <function>XtUnmanageChild()</function> +several times than it is to declare and initialize an array +of widgets to pass to <function>XtUnmanageChildren()</function>. Calling +<function>XtUnmanageChildren()</function> is more efficient, however, +because it only calls the parent's <function>change_managed()</function> +method once. +</para> +</refsect1> + +<refsect1 id="r1-1007-unmanagechildren-3"> +<title>Algorithm +</title> +<para><function>XtUnmanageChildren()</function> performs the following: +</para> +<variablelist> +<varlistentry> +<term>- +</term> +<listitem> +<para>Ignores the child if it already is unmanaged or is being +destroyed. +</para> +</listitem> +</varlistentry> +<varlistentry> +<term>- +</term> +<listitem> +<para>Otherwise, if the child is realized, it makes it nonvisible +by unmapping it. +</para> +</listitem> +</varlistentry> +</variablelist> +<para> +</para> +</refsect1> + +<refsect1 id="r1-1007-unmanagechildren-4"> +<title>Structures</title> +<para>The <type>WidgetList</type> type is simply an array of widgets: +</para> +<screen id="sc-1007-unmanagechildren-1">typedef Widget *WidgetList; +</screen> +</refsect1> +</refentry> + +</chapter> + +<chapter id="faq"> +<title>Questions and Answers</title> + +<!-- (OPTIONAL but recommended) This chapter should include all of the silly +(and not-so-silly) newbie questions that fill up your mailbox. This chapter +should be reserved for BRIEF questions and answers! If one question uses more +than a page or so then it should probably be part of the +"Using this Application" chapter instead. You should use links to +cross-reference questions to the parts of your documentation that answer them. +This is also a great place to provide pointers to other FAQ's if your users +must do some complicated configuration on other programs in order for your +application work. --> + +&reporting.bugs; +&updating.documentation; + +<qandaset id="faqlist"> +<qandaentry> +<question> +<para>My Mouse doesn't work. How do I quit &kapp;?</para> +</question> +<answer> +<para>You silly goose! Check out the <link linkend="commands">Commands +Section</link> for the answer.</para> +</answer> +</qandaentry> +<qandaentry> +<question> +<para>Why can't I twiddle my documents?</para> +</question> +<answer> +<para>You can only twiddle your documents if you have the foobar.lib +installed.</para> +</answer> +</qandaentry> +</qandaset> +</chapter> + +<chapter id="credits"> + +<!-- Include credits for the programmers, documentation writers, and +contributors here. The license for your software should then be included below +the credits with a reference to the appropriate license file included in the KDE +distribution. --> + +<title>Credits and License</title> + +<para> +&kapp; +</para> +<para> +Program copyright 1997 John Q. Hacker <email>jqh@kde.org</email> +</para> +<para> +Contributors: +<itemizedlist> +<listitem><para>Konqui the KDE Dragon <email>konqui@kde.org</email></para> +</listitem> +<listitem><para>Tux the Linux Penguin <email>tux@linux.org</email></para> +</listitem> +</itemizedlist> +</para> + +<para> +Documentation copyright 1999 George N. Ugnacious <email>gnu@kde.org</email> +</para> + +<!-- TRANS:CREDIT_FOR_TRANSLATORS --> + +&underFDL; <!-- FDL: do not remove. Commercial development should --> +<!-- replace this with their copyright and either remove it or re-set this.--> + +<!-- Determine which license your application is licensed under, + and delete all the remaining licenses below: + + (NOTE: All documentation are licensed under the FDL, + regardless of what license the application uses) --> + +&underGPL; <!-- GPL License --> +&underBSDLicense; <!-- BSD License --> +&underArtisticLicense; <!-- BSD Artistic License --> +&underX11License; <!-- X11 License --> + +</chapter> + +<appendix id="installation"> +<title>Installation</title> + +<sect1 id="getting-kpercentage"> +<title>How to obtain KPercentage</title> + +<para> +&kpercentage; is part of the KDE project +<ulink url="http://www.kde.org">http://www.kde.org</ulink>. +&kpercentage; can be found in the kdeutils package on +<ulink url="ftp://ftp.kde.org/pub/kde/">ftp://ftp.kde.org/pub/kde/</ulink>, the +main ftp site of the KDE project. </para> +</sect1> + +<sect1 id="requirements"> +<title>Requirements</title> + +<!-- +List any special requirements for your application here. This should include: +.Libraries or other software that is not included in kdesupport, +kdelibs, or kdebase. +.Hardware requirements like amount of RAM, disk space, graphics card +capabilities, screen resolution, special expansion cards, etc. +.Operating systems the app will run on. If your app is designed only for a +specific OS, (you wrote a graphical LILO configurator for example) put this +information here. +--> + +<para> +In order to successfully use &kpercentage;, you need KDE 1.1. Foobar.lib is required +in order to support the advanced &kpercentage; features. &kpercentage; uses about 5 megs of +memory to run, but this may vary depending on your platform and +configuration. +</para> + +<para> +All required libraries as well as &kpercentage; itself can be found +on <ulink url="ftp://ftp.kapp.org">The &kpercentage; home page</ulink>. +</para> + +<!-- For a list of updates, you may refer to the application web site +or the ChangeLog file, or ... --> +<para> +You can find a list of changes at <ulink +url="http://apps.kde.org/kapp">http://apps.kde.org/kapp</ulink>. +</para> +</sect1> + +<sect1 id="compilation"> +<title>Compilation and Installation</title> + +<para> +In order to compile and install KApp on your system, type the following in the base +directory of the Icon Editor distribution: +<screen width="40"> +<prompt>%</prompt> <userinput>./configure</userinput> +<prompt>%</prompt> <userinput>make</userinput> +<prompt>%</prompt> <userinput>make install</userinput> +</screen> +</para> + +<para>Since KApp uses autoconf and automake you should have not trouble compiling it. +Should you run into problems please report them to the KDE mailing lists.</para> + +</sect1> + +<sect1 id="configuration"> +<title>Configuration</title> + +<para>Don't forget to tell your system to start the <filename>dtd</filename> +dicer-toaster daemon first, or KApp won't work !</para> + +</sect1> + +</appendix> + +&documentation.index; +</book> +<!-- +Local Variables: +mode: sgml +sgml-minimize-attributes:nil +sgml-general-insert-case:lower +sgml-indent-step:0 +sgml-indent-data:nil +End: +--> + + + + + + + + + + + + + diff --git a/kpercentage/kpercentage/kpercentage.h b/kpercentage/kpercentage/kpercentage.h new file mode 100644 index 00000000..ff06c102 --- /dev/null +++ b/kpercentage/kpercentage/kpercentage.h @@ -0,0 +1,85 @@ +/*************************************************************************** + kpercentage.h - description + ------------------- + begin : Fre Nov 16 14:52:33 CET 2001 + copyright : (C) 2001 by Matthias Messmer & + Carsten Niehaus & + Robert Gogolok + email : bmlmessmer@web.de & + cniehaus@gmx.de & + mail@robert-gogolok.de + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KPERCENTAGE_H +#define KPERCENTAGE_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +// Qt includes +#include <qspinbox.h> + +// KDE includes +#include <kapplication.h> +#include <kcombobox.h> + +// local includes +#include "kpercentmain.h" + +#define SEL_PERCENTAGE 0 +#define SEL_BASEVALUE 1 +#define SEL_PERCENTVALUE 2 +#define SEL_RANDOM 3 + +#define KPERCENTAGE_VERSION "1.2" + +/** + * KPercentage is the base class of the project. + */ +class KPercentage : public KDialog +{ + Q_OBJECT +public: + /** construtor */ + KPercentage( const char *name=0 ); + + /** The exercise dialog */ + KPercentMain * percent_main; + +public slots: // Public slots + /** connected to PushButtonRandom */ + void selRandom(); + /** connected to PushButtonPercentvalue */ + void selPercentvalue(); + /** connected to PushButtonBasevalue */ + void selBasevalue(); + /** connected to PushButtonPercentage */ + void selPercentage(); + /** invokes the HelpCenter. doc must be installed */ + void needHelp(); + +protected: + /** closes the application */ + void closeEvent(QCloseEvent *); + +private: + /** Choose the level: easy, medium, crazy */ + KComboBox *combo_box_level; + /** Choose the number of exercises. */ + QSpinBox *spin_box_number; + + /** common preparing the exercise */ + void startExercise(); +}; + +#endif diff --git a/kpercentage/kpercentage/kpercentmain.cpp b/kpercentage/kpercentage/kpercentmain.cpp new file mode 100644 index 00000000..276b787d --- /dev/null +++ b/kpercentage/kpercentage/kpercentmain.cpp @@ -0,0 +1,467 @@ +/*************************************************************************** + kpercentmain.cpp - description + ------------------- + begin : Fri Nov 16 2001 + copyright : (C) 2001 by Matthias Messmer & + Carsten Niehaus & + Robert Gogolok + email : bmlmessmer@web.de & + cniehaus@gmx.de & + mail@robert-gogolok.de +***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// C/C++ includes +#include <stdlib.h> +#include <time.h> + +// Qt includes +#include <qlayout.h> +#include <qlabel.h> +#include <qprogressbar.h> +#include <qpushbutton.h> +#include <qtooltip.h> + +// KDE includes +#include <kiconloader.h> +#include <klocale.h> +#include <kstandarddirs.h> +#include <kstdguiitem.h> +#include <knumvalidator.h> + +// local includes +#include "kpercentmain.h" +#include "kpercentage.h" + + +KPercentMain::KPercentMain( QWidget *parent, const char *name ) : + KDialog( parent, name, TRUE ) // TRUE for modal dialog +{ + setFont( parent->font() ); + /** load and set the background pixmap */ + QPixmap bgp( locate( "data", QApplication::reverseLayout() ? "kpercentage/pics/kpercentmain_bg_rtl.png" : "kpercentage/pics/kpercentmain_bg.png" ) ); +// resize( 520, 220 ); + setFixedSize( QSize( 520, 275 ) ); + setBackgroundPixmap( bgp ); + setBackgroundOrigin( QDialog::ParentOrigin ); + KIntValidator *validLine = new KIntValidator( this ); + + line_edit_percentage = new QLineEdit( this, "line_edit_percentage" ); + line_edit_percentage->setAlignment( int( QLineEdit::AlignHCenter ) ); + line_edit_percentage->setValidator( validLine ); + + line_edit_basevalue = new QLineEdit( this, "line_edit_basevalue" ); + line_edit_basevalue->setAlignment( int( QLineEdit::AlignHCenter ) ); + line_edit_basevalue->setValidator( validLine ); + + line_edit_percentvalue = new QLineEdit( this, "line_edit_percentvalue" ); + line_edit_percentvalue->setAlignment( int( QLineEdit::AlignHCenter ) ); + line_edit_percentvalue->setValidator( validLine ); + + progress_bar_count = new QProgressBar( this, "progress_bar_count" ); + progress_bar_count->setFrameShape( QProgressBar::Panel ); + progress_bar_count->setFrameShadow( QProgressBar::Sunken ); +// progress_bar_count->setFixedWidth( 250 ); + + progress_bar_right_wrong = new QProgressBar( this, "progress_bar_right" ); + progress_bar_right_wrong->setFrameShape( QProgressBar::Panel ); + progress_bar_right_wrong->setFrameShadow( QProgressBar::Sunken ); +// progress_bar_right_wrong->setFixedWidth( 250 ); + progress_bar_right_wrong->setPercentageVisible( FALSE ); + progress_bar_right_wrong->setPaletteBackgroundColor( QColor( "red" ) ); + + label_right = new QLabel( this, "" ); + label_right->setBackgroundPixmap( bgp ); + label_right->setBackgroundOrigin( QDialog::ParentOrigin ); + label_wrong = new QLabel( this, "" ); + label_wrong->setBackgroundPixmap( bgp ); + label_wrong->setBackgroundOrigin( QDialog::ParentOrigin ); + + push_button_apply = new QPushButton( this, "push_button_apply" ); + push_button_apply->setText( KStdGuiItem::apply().text() ); + push_button_apply->setDefault( TRUE ); + push_button_apply->setBackgroundPixmap( bgp); + push_button_apply->setBackgroundOrigin( QPushButton::ParentOrigin ); + + push_button_cancel = new QPushButton( this, "push_button_cancel" ); + push_button_cancel->setText( KStdGuiItem::cancel().text() ); + + KIconLoader icon_loader; + push_button_apply->setIconSet( QIconSet( icon_loader.loadIcon( "button_ok", KIcon::NoGroup, 32 ) ) ); + push_button_cancel->setIconSet( QIconSet( icon_loader.loadIcon( "button_cancel", KIcon::NoGroup, 32 ) ) ); + + label_1 = new QLabel( this, "label_1" ); + label_1->setText( i18n( " % of " ) ); + label_1->setBackgroundPixmap( bgp ); + label_1->setBackgroundOrigin( QDialog::ParentOrigin ); + + label_2 = new QLabel( this, "label_2" ); + label_2->setText( i18n( " = " ) ); + label_2->setBackgroundPixmap( bgp ); + label_2->setBackgroundOrigin( QDialog::ParentOrigin ); + + label_number = new QLabel( this, "label_number" ); + label_number->setBackgroundPixmap( bgp ); + label_number->setBackgroundOrigin( QDialog::ParentOrigin ); + label_number->setText( i18n( "Task no. MM:" ) ); // for the right width + + label_count = new QLabel( this, "label_count" ); + label_count->setText( i18n( "You got MM of MM." ) ); // for the right width + label_count->setBackgroundPixmap( bgp ); + label_count->setBackgroundOrigin( QDialog::ParentOrigin ); + + ////// + // begin layouting + ////// + QVBoxLayout *main_layout = new QVBoxLayout ( this, 0, -1, "main_layout" ); + main_layout->setMargin( 20 ); + main_layout->setSpacing( 10 ); + + QHBoxLayout *label_number_layout = new QHBoxLayout ( main_layout, -1, "label_number_layout" ); + label_number_layout->addWidget( label_number ); + label_number_layout->addStretch(); + + QHBoxLayout *line_edit_layout = new QHBoxLayout ( main_layout, -1, "line_edit_layout" ); + + line_edit_layout->addWidget( line_edit_percentage ); + line_edit_layout->addWidget( label_1 ); + line_edit_layout->addWidget( line_edit_basevalue ); + line_edit_layout->addWidget( label_2 ); + line_edit_layout->addWidget( line_edit_percentvalue ); + line_edit_layout->addStretch(); + + main_layout->addStretch(); + + QHBoxLayout *bottom_layout = new QHBoxLayout( main_layout, -1, "bottom_layout" ); + + QVBoxLayout *current_state_layout = new QVBoxLayout ( bottom_layout, -1, "current_state_layout" ); + + QHBoxLayout *label_count_layout = new QHBoxLayout ( current_state_layout, -1, "label_count_layout" ); + label_count_layout->addWidget( label_count ); + label_count_layout->addStretch(); + + current_state_layout->addSpacing( 10 ); + current_state_layout->addWidget( progress_bar_count ); + + QHBoxLayout *right_wrong_layout = new QHBoxLayout( current_state_layout, -1, "right_wrong_layout" ); + + right_wrong_layout->addWidget( label_right ); + right_wrong_layout->addWidget( progress_bar_right_wrong ); + right_wrong_layout->addWidget( label_wrong ); + + bottom_layout->addSpacing( 40 ); + + QVBoxLayout *button_layout = new QVBoxLayout ( bottom_layout, -1, "button_layout" ); + + button_layout->addWidget( push_button_apply ); + button_layout->addSpacing( 10 ); + button_layout->addWidget( push_button_cancel ); + + // END LAYOUT + // -------------------------------------------------------- + + // tab order + setTabOrder( line_edit_percentvalue, push_button_apply ); + setTabOrder( push_button_apply, push_button_cancel ); + + /////////// + // ToolTips + + QToolTip::add( progress_bar_count, i18n( "Number of managed exercises" ) ); + QToolTip::add( progress_bar_right_wrong, i18n( "Relation of right to wrong inputs" ) ); + QToolTip::add( push_button_apply, i18n( "Check your answer" ) ); + QToolTip::add( push_button_cancel, i18n( "Back to the main window" ) ); + + // signals and slots connections + connect( push_button_apply, SIGNAL( clicked() ), this, SLOT( slotApplyInput() ) ); + connect( push_button_cancel, SIGNAL( clicked() ), this, SLOT( accept() ) ); + + // build up the answer window + answer = new KAnswer( this ); + + + /** this is to tell rand() to be randomizing */ + srandom( time( 0 ) ); + +} + +/** No descriptions */ +void KPercentMain::newTask() +{ + // no Editline can be focused + line_edit_percentage->setFocusPolicy( NoFocus ); + line_edit_basevalue->setFocusPolicy( NoFocus ); + line_edit_percentvalue->setFocusPolicy( NoFocus ); + + // set the number of managed tasks into a label + label_count->setText( QString( i18n("You got %1 of %2 exercises.").arg(count).arg(number) ) ); // update Label for the Progress + +// progress_bar_count->setProgress( count*100 ); // updating Progrssbar + startTimer( 10 ); + // set string which task is just workin on (Task x of y) + QString taskNumber( i18n( "Exercise no. %1:" ).arg(count+1) ); + + label_number->setText( taskNumber ); + // label_number->adjustSize(); + + int selection; // which task is to be solved ? + if ( count == number ) // all tasks managed ? + { +// finished(); + } + else + { + if ( selected_type == SEL_RANDOM ) + { + selection = rand() % 3; // select one task by random + } + else + { + selection = selected_type; // or take the preselected one + } + // set the right line_edit_layout for input + switch ( selection ) + { + case SEL_PERCENTAGE: + line_edit_input = line_edit_percentage; + break; + case SEL_BASEVALUE: + line_edit_input = line_edit_basevalue; + break; + case SEL_PERCENTVALUE: + line_edit_input = line_edit_percentvalue; + break; + } + // show the numbers + showNumbers(); + // delete this one + line_edit_input->clear(); + // make the line_edit_layout accessable + line_edit_input->setFocusPolicy( StrongFocus ); + // set the focus on it + line_edit_input->setFocus(); + } +} + +/** checks, if the task is solved right */ +bool KPercentMain::validateTask() +{ + // here is some mathematics :) + return ( getPercentage() * getBasevalue() == 100 * getPercentvalue() ); +} + +/** gets the numbers from the line_edit_layouts */ +int KPercentMain::getPercentage() +{ + return line_edit_percentage->text().toInt(); // check for valid input is omitted (slotApplyInput) +} +int KPercentMain::getBasevalue() +{ + return line_edit_basevalue->text().toInt(); // check for valid input is omitted (slotApplyInput) +} +int KPercentMain::getPercentvalue() +{ + return line_edit_percentvalue->text().toInt(); // check for valid input is omitted (slotApplyInput) +} + +/* checks, if the input is a val. number + * calls validateTask then and if succeeds causes a newTask */ +void KPercentMain::slotApplyInput() +{ + bool ok; // conversion to int successful ? + line_edit_input->text().toInt( &ok ); + if ( !ok ) + { + showAnswer( 3 ); + } + else + { + if ( validateTask() ) // are the numbers right ? + { + showAnswer( 1 ); + count++; // one more solved + right_answers++; // one more right answer + total_answers++; + progress_bar_right_wrong->setTotalSteps( total_answers ); + progress_bar_right_wrong->setProgress( right_answers ); + label_right->setText( i18n( "%1%\nright" ).arg( (100*right_answers)/total_answers ) ); + label_wrong->setText( i18n( "%1%\nwrong" ).arg( 100-(100*right_answers)/total_answers ) ); + + newTask(); // next task, perhaps + } + else + { + showAnswer( 2 ); + wrong_answers++; // one more right answer + total_answers++; + progress_bar_right_wrong->setTotalSteps( total_answers ); + progress_bar_right_wrong->setProgress( right_answers ); + label_right->setText( i18n( "%1%\nright" ).arg( (100*right_answers)/total_answers ) ); + label_wrong->setText( i18n( "%1%\nwrong" ).arg( 100-(100*right_answers)/total_answers ) ); + } + } +} + +/** inserts the numbers of a new task in the line_edit_layouts */ +void KPercentMain::showNumbers() +{ + line_edit_percentage->setText( QString::number( percentage[ count ] ) ); + line_edit_basevalue->setText( QString::number( basevalue[ count ] ) ); + line_edit_percentvalue->setText( QString::number( percentvalue[ count ] ) ); +} + +/** called, if number tasks are managed */ +void KPercentMain::finished() +{ + showAnswer( 4 ); + accept(); // hides the dialog +} +/** shows the kanswer dialog modal with an proper answer about the success. */ +void KPercentMain::showAnswer( int modus ) +{ + answer->setAnswer( modus ); + answer->exec(); +} +/** sets the total amount of tasks selekted in opening screen */ +void KPercentMain::setNumber( int anumber ) +{ + number = anumber; + progress_bar_count->setTotalSteps( number*100 ); +} + +/** Prepares the exercise of number tasks */ +void KPercentMain::initExercise() +{ + count = 0; + progress_bar_count->setProgress( 0 ); + total_answers = 0; + right_answers = 0; + wrong_answers = 0; + + progress_bar_right_wrong->setProgress( 0 ); + label_right->setText( "" ); + label_wrong->setText( "" ); + switch ( selected_level ) + { + /** easy level */ + case 0: + { + /** easy percentages to calculate with */ + const int values[] = { 1, 10, 25, 50, 75, 100, 10, 25, 50, 75}; + ::memcpy(percentage, values, sizeof(values)); + } + + + int num; + if ( number < 6 ) /* for only few tasks, chose from the first 6 numbers */ + { + num = 6; + } + else + { + num = 10; /* else take them all! */ + } + /** swap 20 times in the array */ + for ( int i = 0; i < 20; i++ ) + { + int m = rand() % num; + int n = rand() % num; + if ( n == m ) /* not a swap */ + { + n = ( n + 1 ) % num; + } + int h = percentage[ m ]; + percentage[ m ] = percentage[ n ]; + percentage[ n ] = h; + } + for ( int i = 0; i < number; i++ ) + { + /** basevalue 100..2000 by chance */ + basevalue[ i ] = 100 * ( 1 + rand() % 20 ); + /** calc percentvalue */ + percentvalue[ i ] = percentage[ i ] * basevalue[ i ] / 100; + } + break; + case 1: + { + /** some more tricky percentages */ + const int values[] = { 0, 5, 10, 20, 60, 90, 100, 110, 150, 200}; + ::memcpy(percentage, values, sizeof(values)); + } + /** swap some times in this array */ + for ( int i = 0; i < 20; i++ ) + { + int m = rand() % 10; + int n = rand() % 10; + if ( n == m ) /** not a swap */ + { + n = ( n + 1 ) % 10; + } + int h = percentage[ m ]; + percentage[ m ] = percentage[ n ]; + percentage[ n ] = h; + } + for ( int i = 0; i < number; i++ ) + { + /** basevalue 0..2000 */ + basevalue[ i ] = 100 * ( rand() % 21 ); + /** calc percentvalue */ + percentvalue[ i ] = percentage[ i ] * basevalue[ i ] / 100; + } + break; + case 2: + int factor; + for ( int i = 0; i < number; i++ ) + { + /** this lines give you 3 integer by chance. percentage will be somewhere + * between 0 and 200. We use factorisation to have "almost" random numbers + * and _always_ valid numbers. */ + factor = 1; + if ( rand() % 2 == 1 ) + factor *= 2; + if ( rand() % 2 == 1 ) + factor *= 2; + if ( rand() % 2 == 1 ) + factor *= 5; + if ( rand() % 2 == 1 ) + factor *= 5; + percentage[ i ] = rand() % ( 200 / factor ); + basevalue[ i ] = rand() % ( 10 * factor ); + percentvalue[ i ] = percentage[ i ] * basevalue[ i ]; + percentage[ i ] *= factor; + basevalue[ i ] *= 100 / factor; + } + break; + } + newTask(); /** prepare the window for the first task */ +} + +void KPercentMain::timerEvent( QTimerEvent *event ) +{ + if( progress_bar_count->progress()<count*100 ) + { + progress_bar_count->setProgress(progress_bar_count->progress()+1); + } + else + { + killTimer( event->timerId() ); + } + if( progress_bar_count->progress()==number*100 ) finished(); +} + +void KPercentMain::keyPressEvent( QKeyEvent * e ) +{ + if ( e->key() == Key_Enter ) slotApplyInput(); + else + KDialog::keyPressEvent( e ); +} + +#include "kpercentmain.moc" diff --git a/kpercentage/kpercentage/kpercentmain.h b/kpercentage/kpercentage/kpercentmain.h new file mode 100644 index 00000000..6e6aea64 --- /dev/null +++ b/kpercentage/kpercentage/kpercentmain.h @@ -0,0 +1,137 @@ +/*************************************************************************** + kpercentmain.h - description + ------------------- + begin : Fri Nov 16 2001 + copyright : (C) 2001 by Matthias Messmer & + Carsten Niehaus & + Robert Gogolok + email : bmlmessmer@web.de & + cniehaus@gmx.de & + mail@robert-gogolok.de +***************************************************************************/ + +/*************************************************************************** + * * + * 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 KPERCENTMAIN_H +#define KPERCENTMAIN_H + +// Qt includes + +// KDE includes + +// local includes +#include "kanswer.h" + +class QGridLayout; +class QHBoxLayout; +class QLabel; +class QLineEdit; +class QProgressBar; +class QPushButton; +class QVBoxLayout; + +/** + * Dialog for the exercises + * @author Matthias Messmer & Rober Gogolok & Carsten Niehaus + */ +class KPercentMain : public KDialog +{ + Q_OBJECT + public: + KPercentMain( QWidget *parent, const char *name = 0 ); + /** checks, if the task is solved right */ + bool validateTask(); + /** prepares the dialog for a new task */ + void newTask(); + /** gets the numbers from the editlines */ + int getPercentvalue(); + int getBasevalue(); + int getPercentage(); + /** inserts the numbers of a new task in the editlines */ + void showNumbers(); + /** called, if number tasks are managed */ + void finished(); + /** shows the kanswer dialog modal with an proper answer about the success. */ + void showAnswer( int modus ); + /** sets the total amount of tasks selekted in opening screen */ + void setNumber( int anumber ); + /** Prepares the exercise for number tasks + * espacially fills the arrays with proper numbers */ + void initExercise(); + + // Public attributes + /** total number of exercises */ + int number; + /** actual number of managed exercises */ + int count; + + /** actual amount of given answers */ + int total_answers; + /** actual count of right answers */ + int right_answers; + /** actual count of wrong answers */ + int wrong_answers; + + /** in KPercentage selected type of task */ + int selected_type; + /** percentages to be calculated with */ + int percentage[ 10 ]; + /** basevalues to be calculated with */ + int basevalue[ 10 ]; + /** percentvalues to be calculated with */ + int percentvalue[ 10 ]; + + QLabel *label_1; + QLabel *label_2; + QLabel *label_number; + QLabel *label_count; + + /** editline for the actual task */ + QLineEdit *line_edit_input; + /** editline for the percentage */ + QLineEdit *line_edit_percentage; + /** editline for the basevalue */ + QLineEdit *line_edit_basevalue; + /** editline for the percentvalue */ + QLineEdit *line_edit_percentvalue; + + /** showing the effort of the user */ + QProgressBar *progress_bar_count; + /** button to apply the current input */ + QPushButton *push_button_apply; + /** button to cancel the exercise series */ + QPushButton *push_button_cancel; + + QProgressBar *progress_bar_right_wrong; + QLabel *label_right; + QLabel *label_wrong; + + /** the answer window */ + KAnswer *answer; + /** stores the level selected in KPercentage's combo_box_level */ + int selected_level; + + private: + void keyPressEvent( QKeyEvent * e ); + + + public slots: // Public slots + /** + * checks, if the input is a val. number + * calls validateTask then and if succeeds causes a newTask + * + * @see kpercentmain#validateTask kpercetmain#newTask + */ + void slotApplyInput(); + /** reimplemented: growing the progressbar step by step */ + void timerEvent( QTimerEvent * ); +}; + +#endif diff --git a/kpercentage/kpercentage/ksplashscreen.cpp b/kpercentage/kpercentage/ksplashscreen.cpp new file mode 100644 index 00000000..bd0adea1 --- /dev/null +++ b/kpercentage/kpercentage/ksplashscreen.cpp @@ -0,0 +1,68 @@ +/*************************************************************************** + splashscreen.h - description + ------------------- + begin : Fri Nov 30 2001 + copyright : (C) 2001 by Matthias Messmer & + Carsten Niehaus & + Robert Gogolok + email : bmlmessmer@web.de & + cniehaus@gmx.de & + mail@robert-gogolok.de +***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// Qt includes +#include <qcanvas.h> +#include <qtimer.h> + +// KDE includes +#include <kstandarddirs.h> + +// local includes +#include "kpercentage.h" +#include "ksplashscreen.h" + +/* creates the splash window without titlebar and border */ +KSplashScreen::KSplashScreen( KPercentage *percentage, const char *name ) : + KDialog( 0L, name, FALSE, QWidget::WStyle_Customize | QWidget::WStyle_NoBorder ) +{ + percentage_window = percentage; + resize( 380, 300 ); + /* load the background pixmap */ + QPixmap bgp( locate( "data", "kpercentage/pics/splash.png" ) ); + /* wait some time and start the main window */ + QCanvas *canvas = new QCanvas( this ); + canvas->resize( 400, 300 ); + /* set the background pixmap */ + canvas->setBackgroundPixmap( bgp ); + //remove version number from splash annma 14/02/2005 + //QCanvasText *t = new QCanvasText( KPERCENTAGE_VERSION, canvas ); + //t->move( 330.0, 260.0 ); + //t->show(); + canvas->setAllChanged(); + canvas->update(); + QCanvasView *view = new QCanvasView( canvas, this, "", QCanvasView::WStyle_Customize | QCanvasView::WStyle_NoBorder ); + view->resize( 380, 300 ); + view->setVScrollBarMode( QCanvasView::AlwaysOff ); + view->setHScrollBarMode( QCanvasView::AlwaysOff ); + view->setFrameStyle( QCanvasView::NoFrame ); + view->show(); + QTimer::singleShot( 2000, this, SLOT( showPercentage() ) ); +} + +/* show the main window and close the splah window */ +void KSplashScreen::showPercentage() +{ + percentage_window->show(); + delete( this ); +} + +#include "ksplashscreen.moc" diff --git a/kpercentage/kpercentage/ksplashscreen.h b/kpercentage/kpercentage/ksplashscreen.h new file mode 100644 index 00000000..3c051242 --- /dev/null +++ b/kpercentage/kpercentage/ksplashscreen.h @@ -0,0 +1,52 @@ +/*************************************************************************** + splashscreen.h - description + ------------------- + begin : Fri Nov 30 2001 + copyright : (C) 2001 by Matthias Messmer & + Carsten Niehaus & + Robert Gogolok + email : bmlmessmer@web.de & + cniehaus@gmx.de & + mail@robert-gogolok.de +***************************************************************************/ + +/*************************************************************************** + * * + * 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 SPLASHSCREEN_H +#define SPLASHSCREEN_H + +// KDE includes + +class QWidget; +class KPercentage; + +/** + * Spashscreen + * + * @author Matthias Messmer & Robert Gogolok + */ +class KSplashScreen : public KDialog +{ + Q_OBJECT + + public: + /** constructor */ + KSplashScreen( KPercentage *percentage, const char *name ); + + public slots: // public slots + /* called after some time to hide the splash and show the main window */ + void showPercentage(); + + private: + /** The KPercentage central window */ + KPercentage *percentage_window; +}; + +#endif diff --git a/kpercentage/kpercentage/main.cpp b/kpercentage/kpercentage/main.cpp new file mode 100644 index 00000000..b52bd324 --- /dev/null +++ b/kpercentage/kpercentage/main.cpp @@ -0,0 +1,70 @@ +/*************************************************************************** + main.cpp - description + ------------------- + begin : Fre Nov 16 14:52:33 CET 2001 + copyright : (C) 2001 by Matthias Messmer & + Carsten Niehaus & + Robert Gogolok + email : bmlmessmer@web.de & + cniehaus@gmx.de & + mail@robert-gogolok.de +***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// KDE includes +#include <kcmdlineargs.h> +#include <kaboutdata.h> + +// local includes +#include "kpercentage.h" + +static const char description[] = + I18N_NOOP( "A program to improve your skills in calculating with percentages" ); + +static KCmdLineOptions options[] = + { + KCmdLineLastOption + }; + +int main( int argc, char *argv[] ) +{ + KAboutData aboutData + ( + "kpercentage", + I18N_NOOP( "KPercentage" ), + KPERCENTAGE_VERSION, description, KAboutData::License_GPL, + "(c) 2001-2007, Matthias Messmer", + 0, 0, + "submit@bugs.kde.org" + ); + aboutData.addAuthor( "Matthias Messmer", I18N_NOOP( "coding, coding and coding" ), "bmlmessmer@web.de" ); + aboutData.addAuthor( "Carsten Niehaus", I18N_NOOP( "CVS, coding and sed-script" ), "cniehaus@gmx.de" ); + aboutData.addAuthor( "Robert Gogolok", I18N_NOOP( "CVS, coding and Makefile stuff" ), "mail@robert-gogolok.de" ); + aboutData.addCredit( "Elhay Achiam", I18N_NOOP( "Pixmaps" ), "e_achiam@netvision.net.il" ); + aboutData.addCredit( "Danny Allen", I18N_NOOP( "Pixmaps" ), "danny@dannyallen.co.uk" ); + aboutData.addCredit( "Jonathan Drews", I18N_NOOP( "Spelling and Language" ), "j.e.drews@att.net" ); + aboutData.addCredit( "Primoz Anzur", I18N_NOOP( "Cleaning and bugfixing code" ), "zerokode@gmx.net" ); + aboutData.addCredit("David Vignoni", I18N_NOOP("SVG icon"), "david80v@tin.it"); + + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. + + KApplication a; + KPercentage *kpercentage = new KPercentage( "kpercentage" ); + a.setMainWidget( kpercentage ); + + /* + * no window is shown here, cause constructor of KPercentage shows + * splash screen first, then the main window is shown. + */ + + return a.exec(); +} diff --git a/kpercentage/kpercentage/pics/Makefile.am b/kpercentage/kpercentage/pics/Makefile.am new file mode 100644 index 00000000..14a8cdd3 --- /dev/null +++ b/kpercentage/kpercentage/pics/Makefile.am @@ -0,0 +1,7 @@ +pics_DATA = smily_medium.png smily_right.png smily_wrong.png kanswer_bg.png kpercentage_bg.png kpercentage_bg_rtl.png kpercentmain_bg.png kpercentmain_bg_rtl.png splash.png \ + smily0000.png smily0001.png smily0002.png smily0003.png smily0004.png smily0005.png smily0006.png + +picsdir = $(kde_datadir)/kpercentage/pics + +story_DATA = right.story wrong.story +storydir = $(kde_datadir)/kpercentage/story diff --git a/kpercentage/kpercentage/pics/kanswer_bg.png b/kpercentage/kpercentage/pics/kanswer_bg.png Binary files differnew file mode 100644 index 00000000..0f5f09b9 --- /dev/null +++ b/kpercentage/kpercentage/pics/kanswer_bg.png diff --git a/kpercentage/kpercentage/pics/kpercentage_bg.png b/kpercentage/kpercentage/pics/kpercentage_bg.png Binary files differnew file mode 100644 index 00000000..ef3d488a --- /dev/null +++ b/kpercentage/kpercentage/pics/kpercentage_bg.png diff --git a/kpercentage/kpercentage/pics/kpercentage_bg.svgz b/kpercentage/kpercentage/pics/kpercentage_bg.svgz Binary files differnew file mode 100644 index 00000000..85a56ee4 --- /dev/null +++ b/kpercentage/kpercentage/pics/kpercentage_bg.svgz diff --git a/kpercentage/kpercentage/pics/kpercentage_bg_rtl.png b/kpercentage/kpercentage/pics/kpercentage_bg_rtl.png Binary files differnew file mode 100644 index 00000000..21275c07 --- /dev/null +++ b/kpercentage/kpercentage/pics/kpercentage_bg_rtl.png diff --git a/kpercentage/kpercentage/pics/kpercentage_bg_rtl.svgz b/kpercentage/kpercentage/pics/kpercentage_bg_rtl.svgz Binary files differnew file mode 100644 index 00000000..5864b7bb --- /dev/null +++ b/kpercentage/kpercentage/pics/kpercentage_bg_rtl.svgz diff --git a/kpercentage/kpercentage/pics/kpercentmain_bg.png b/kpercentage/kpercentage/pics/kpercentmain_bg.png Binary files differnew file mode 100644 index 00000000..cf45cd6a --- /dev/null +++ b/kpercentage/kpercentage/pics/kpercentmain_bg.png diff --git a/kpercentage/kpercentage/pics/kpercentmain_bg.svgz b/kpercentage/kpercentage/pics/kpercentmain_bg.svgz Binary files differnew file mode 100644 index 00000000..cd123cf7 --- /dev/null +++ b/kpercentage/kpercentage/pics/kpercentmain_bg.svgz diff --git a/kpercentage/kpercentage/pics/kpercentmain_bg_rtl.png b/kpercentage/kpercentage/pics/kpercentmain_bg_rtl.png Binary files differnew file mode 100644 index 00000000..34f1a547 --- /dev/null +++ b/kpercentage/kpercentage/pics/kpercentmain_bg_rtl.png diff --git a/kpercentage/kpercentage/pics/kpercentmain_bg_rtl.svgz b/kpercentage/kpercentage/pics/kpercentmain_bg_rtl.svgz Binary files differnew file mode 100644 index 00000000..f4ecf9e0 --- /dev/null +++ b/kpercentage/kpercentage/pics/kpercentmain_bg_rtl.svgz diff --git a/kpercentage/kpercentage/pics/right.story b/kpercentage/kpercentage/pics/right.story new file mode 100644 index 00000000..a739817c --- /dev/null +++ b/kpercentage/kpercentage/pics/right.story @@ -0,0 +1,17 @@ +# story board for right answer animation +name init +move 10,0,0 #smily face going down +move 10,3,0 #smily face going down +move 10,12,0 #smily face going down +move 10,27,0 #smily face going down +move 10,58,0 #smily face going down +move 10,58,1 #smily face going down +move 10,58,2 #smily face going down +move 10,58,3 #bounce +move 10,58,2 #smily face going up +move 10,58,1 #smily face going up +move 10,58,0 #smily face going up +move 10,27,0 #smily face going up +move 10,12,0 #smily face going up +move 10,3,0 #smily face going up +following init #forever loopback... diff --git a/kpercentage/kpercentage/pics/smily0000.png b/kpercentage/kpercentage/pics/smily0000.png Binary files differnew file mode 100644 index 00000000..347dd5d1 --- /dev/null +++ b/kpercentage/kpercentage/pics/smily0000.png diff --git a/kpercentage/kpercentage/pics/smily0001.png b/kpercentage/kpercentage/pics/smily0001.png Binary files differnew file mode 100644 index 00000000..c96f538c --- /dev/null +++ b/kpercentage/kpercentage/pics/smily0001.png diff --git a/kpercentage/kpercentage/pics/smily0002.png b/kpercentage/kpercentage/pics/smily0002.png Binary files differnew file mode 100644 index 00000000..3f3b1af1 --- /dev/null +++ b/kpercentage/kpercentage/pics/smily0002.png diff --git a/kpercentage/kpercentage/pics/smily0003.png b/kpercentage/kpercentage/pics/smily0003.png Binary files differnew file mode 100644 index 00000000..78b43212 --- /dev/null +++ b/kpercentage/kpercentage/pics/smily0003.png diff --git a/kpercentage/kpercentage/pics/smily0004.png b/kpercentage/kpercentage/pics/smily0004.png Binary files differnew file mode 100644 index 00000000..3aeb7b10 --- /dev/null +++ b/kpercentage/kpercentage/pics/smily0004.png diff --git a/kpercentage/kpercentage/pics/smily0005.png b/kpercentage/kpercentage/pics/smily0005.png Binary files differnew file mode 100644 index 00000000..66342946 --- /dev/null +++ b/kpercentage/kpercentage/pics/smily0005.png diff --git a/kpercentage/kpercentage/pics/smily0006.png b/kpercentage/kpercentage/pics/smily0006.png Binary files differnew file mode 100644 index 00000000..a4395fac --- /dev/null +++ b/kpercentage/kpercentage/pics/smily0006.png diff --git a/kpercentage/kpercentage/pics/smily_medium.png b/kpercentage/kpercentage/pics/smily_medium.png Binary files differnew file mode 100644 index 00000000..fe51c32d --- /dev/null +++ b/kpercentage/kpercentage/pics/smily_medium.png diff --git a/kpercentage/kpercentage/pics/smily_right.png b/kpercentage/kpercentage/pics/smily_right.png Binary files differnew file mode 100644 index 00000000..c20871da --- /dev/null +++ b/kpercentage/kpercentage/pics/smily_right.png diff --git a/kpercentage/kpercentage/pics/smily_wrong.png b/kpercentage/kpercentage/pics/smily_wrong.png Binary files differnew file mode 100644 index 00000000..3056c08f --- /dev/null +++ b/kpercentage/kpercentage/pics/smily_wrong.png diff --git a/kpercentage/kpercentage/pics/splash.png b/kpercentage/kpercentage/pics/splash.png Binary files differnew file mode 100644 index 00000000..7ee11378 --- /dev/null +++ b/kpercentage/kpercentage/pics/splash.png diff --git a/kpercentage/kpercentage/pics/splash.svgz b/kpercentage/kpercentage/pics/splash.svgz Binary files differnew file mode 100644 index 00000000..ce8ea9a1 --- /dev/null +++ b/kpercentage/kpercentage/pics/splash.svgz diff --git a/kpercentage/kpercentage/pics/wrong.story b/kpercentage/kpercentage/pics/wrong.story new file mode 100644 index 00000000..56d3edaa --- /dev/null +++ b/kpercentage/kpercentage/pics/wrong.story @@ -0,0 +1,10 @@ +# story board for wrong answer animation +name init +move 10,0,4 #smiley face going down +move 15,8,4 #smiley face going down +move 10,18,4 #smiley face going down +move 5,28,4 #smiley face going down +move 10,38,4 #smiley face going down +move 15,48,4 #smiley face going down +move 13,54,4 #smiley face going down +move 10,58,4 #smiley face going down diff --git a/kpercentage/kpercentage/right.txt b/kpercentage/kpercentage/right.txt new file mode 100644 index 00000000..ac657cc0 --- /dev/null +++ b/kpercentage/kpercentage/right.txt @@ -0,0 +1,8 @@ +Good choice! +Well done! +Pretty good! +Fine! +Right! +Yes! +Great! +Good work! diff --git a/kpercentage/kpercentage/wrong.txt b/kpercentage/kpercentage/wrong.txt new file mode 100644 index 00000000..58c6a5cf --- /dev/null +++ b/kpercentage/kpercentage/wrong.txt @@ -0,0 +1,8 @@ +Wrong! +Not right! +Think twice! +Sorry, no! +False! +Try again! +Oh no! +That's not right! |