00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <qtimer.h>
00020 #include <qtooltip.h>
00021
00022 #include <kdebug.h>
00023 #include <klocale.h>
00024
00025 #include <stdlib.h>
00026 #include <string.h>
00027 #include <time.h>
00028
00029 #include "klettres.h"
00030 #include "klettresview.h"
00031
00032
00033 KLettresView::KLettresView(KLettres *parent)
00034 : QWidget(parent)
00035 {
00036 klettres = parent;
00037
00038 setMinimumSize( QSize( 640, 538 ) );
00039 setMaximumSize( QSize( 640, 538 ) );
00040
00041
00042 button1 = new QLabel( this, "button1" );
00043 button1->setGeometry( QRect( 50, 100, 160, 160 ) );
00044 cg.setColor( QColorGroup::Foreground, white );
00045 cg.setColor( QColorGroup::Background, QColor(53,87,158));
00046 pal.setActive( cg );
00047 button1->setPalette( pal );
00048 button1->setText( i18n( "A" ) );
00049 QToolTip::add( button1, i18n( "You must type the letter/syllable you hear and/or see in the field below" ) );
00050
00051 line1 = new QLineEdit( this, "line1" );
00052 line1->setGeometry( QRect( 40, 310, 161, 160 ) );
00053 QToolTip::add( line1, i18n( "Type the letter or syllable that you just heard" ) );
00054
00055
00056 pm_a.load(locate("data","klettres/pics/background1.png"));
00057 pm_k.load(locate("data","klettres/pics/klettres_back.jpeg"));
00058
00059 n = 0;
00060 temp=-1;
00061
00062 }
00063
00064 KLettresView::~KLettresView()
00065 {
00066 }
00067
00069 void KLettresView::slotGrownup()
00070 {
00071 style="grownup";
00072 setMinimumSize( QSize( 640, 480 ) );
00073 setMaximumSize( QSize( 640, 480 ) );
00074 setBackgroundPixmap(pm_a);
00075
00076 cg.setColor( QColorGroup::Foreground, white );
00077 cg.setColor( QColorGroup::Background, QColor(53,87,158));
00078 pal.setActive( cg );
00079 button1->setPalette( pal );
00080 }
00081
00083 void KLettresView::slotKid()
00084 {
00085 style="kid";
00086 setMinimumSize( QSize( 640, 480 ) );
00087 setMaximumSize( QSize( 640, 480 ) );
00088 setBackgroundPixmap(pm_k);
00089
00090 cg.setColor( QColorGroup::Foreground, white );
00091 cg.setColor( QColorGroup::Background, black);
00092 pal.setActive( cg );
00093 button1->setPalette( pal );
00094 }
00095
00097 void KLettresView::game()
00098 {
00099
00100
00101 QObject::disconnect(line1, SIGNAL(textChanged(const
00102 QString&)),this,SLOT(slotLet2(const QString&)) );
00103 input = 1;
00104 line1->clear();
00105 line1->setCursorPosition(0);
00106 line1->setFocus();
00107
00108 if (niveau==1)
00109 button1->show();
00110
00111 if (niveau==2)
00112 button1->hide();
00113
00114 if (niveau==1||niveau==2)
00115 {
00116 button1->setMinimumSize( QSize( 200, 160 ) );
00117 button1->setMaximumSize( QSize( 200, 160 ) );
00118 line1->setMinimumSize( QSize( 140, 160 ) );
00119 line1->setMaximumSize( QSize( 140, 160 ) );
00120 chooseSound();
00121
00122 QObject::connect(line1, SIGNAL(textChanged(const
00123 QString&)),this,SLOT(treat1(const QString&)) );
00124 QObject::disconnect(line1, SIGNAL(textChanged(const
00125 QString&)),this,SLOT(slotLet2(const QString&)) );
00126 }
00127
00128 if (niveau==3)
00129 button1->show();
00130
00131 if (niveau==4)
00132 button1->hide();
00133
00134 if (niveau==3 || niveau==4)
00135 {
00136 chooseSound();
00137 if (length==2)
00138 {
00139 button1->setMinimumSize( QSize( 200, 160 ) );
00140 button1->setMaximumSize( QSize( 200, 160 ) );
00141 line1->setMinimumSize( QSize( 200, 160 ) );
00142 line1->setMaximumSize( QSize( 200, 160 ) );
00143 }
00144 if (length==3)
00145 {
00146 button1->setMinimumSize( QSize(250, 160 ) );
00147 button1->setMaximumSize( QSize( 250, 160 ) );
00148 line1->setMinimumSize( QSize( 250, 160 ) );
00149 line1->setMaximumSize( QSize( 250, 160 ) );
00150 }
00151 QObject::connect(line1, SIGNAL(textChanged(const
00152 QString&)),this,SLOT(slotLet2(const QString&)) );
00153 QObject::disconnect(line1, SIGNAL(textChanged(const
00154 QString&)),this,SLOT(treat1(const QString&)) );
00155 }
00156 line1->setMaxLength( 1 );
00157 line1->setCursorPosition(0);
00158 line1->setFocus();
00159 }
00160
00161 void KLettresView::treat1(const QString& )
00162 {
00163 QObject::disconnect(line1, SIGNAL(textChanged(const
00164 QString&)),this,SLOT(treat1(const QString&)) );
00165 QObject::disconnect(line1, SIGNAL(textChanged(const
00166 QString&)),this,SLOT(slotLet2(const QString&)) );
00167 a1=line1->text();
00168 if (!a1.at(0).isLetter())
00169 {
00170 QObject::connect(line1, SIGNAL(textChanged(const
00171 QString&)),this,SLOT(treat1(const QString&)) );
00172 QObject::connect(line1, SIGNAL(textChanged(const
00173 QString&)),this,SLOT(slotLet2(const QString&)) );
00174 }
00175 t1 = a1.upper();
00176 line1->selectAll();
00177 line1->cut();
00178 line1->setText(t1);
00179 if (niveau==2)
00180 button1->hide();
00181 QTimer *timer = new QTimer( this );
00182 connect( timer, SIGNAL(timeout()),
00183 this, SLOT(timer1()) );
00184 timer->start( 2000, TRUE );
00185 }
00186
00187 void KLettresView::timer1()
00188 {
00189 line1->selectAll();
00190 if ((button1->text())==t1)
00191 {
00192 chooseSound();
00193 }
00194 else
00195 {
00196 if (niveau==2)
00197 button1->show();
00198 klettres->soundFactory->playSound(n);
00199 }
00200
00201 line1->cut();
00202
00203 QObject::connect(line1, SIGNAL(textChanged(const
00204 QString&)),this,SLOT(treat1(const QString&)) );
00205 line1->setFocus();
00206 }
00207
00208
00209 void KLettresView::slotLet2(const QString& )
00210 {
00211 line1->clearFocus();
00212
00213 QObject::disconnect(line1, SIGNAL(textChanged(const
00214 QString&)),this,SLOT(slotLet2(const QString&)) );
00215
00216 line1->setSelection(input-1,1);
00217 a1=line1->selectedText();
00218 t1 = a1.upper();
00219 line1->cut();
00220 line1->setText(line1->text()+t1);
00221 t1=line1->text();
00222 sj=st.left(input);
00223 QTimer *timer = new QTimer( this );
00224 connect( timer, SIGNAL(timeout()),
00225 this, SLOT(timerDone()) );
00226 timer->start( 1000, TRUE );
00227 }
00228
00229 void KLettresView::timerDone()
00230 {
00231 if (t1==sj)
00232 {
00233 if (sj!=st)
00234 {
00235 line1->setMaxLength( input+1 );
00236 line1->setCursorPosition( input );
00237 line1->setFocus();
00238 input++;
00239 QObject::connect(line1, SIGNAL(textChanged(const
00240 QString&)),this,SLOT(slotLet2(const QString&)) );
00241 }
00242 else
00243 {
00244 line1->selectAll();
00245 line1->cut();
00246 line1->setCursorPosition(0 );
00247 line1->setFocus();
00248 line1->setMaxLength( 1 );
00249 if (niveau==4)
00250 button1->hide();
00251 game();
00252 }
00253 }
00254 else
00255 {
00256 line1->backspace();
00257 line1->setFocus();
00258
00259 klettres->soundFactory->playSound(n);
00260
00261 QObject::connect(line1, SIGNAL(textChanged(const
00262 QString&)),this,SLOT(slotLet2(const QString&)) );
00263 }
00264 }
00265
00266 void KLettresView::chooseSound()
00267 {
00268 input =1;
00269 srand((unsigned int)time((time_t *)NULL));
00270
00271 if (klettres->soundFactory->sounds ==0)
00272 return;
00273 n=rand()%(klettres->soundFactory->sounds);
00274
00275 if (temp<0)
00276 temp=n;
00277 else
00278 {
00279 while (n==temp)
00280 n=rand()%(klettres->soundFactory->sounds);
00281 temp=n;
00282 }
00283
00284
00285 klettres->soundFactory->playSound(n);
00286
00287 button1->setText(klettres->soundFactory->namesList[n]);
00288
00289 st = klettres->soundFactory->namesList[n];
00290
00291 length=klettres->soundFactory->namesList[n].length();
00292 }
00293
00294 #include "klettresview.moc"