00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qtooltip.h>
00022 #include <qwhatsthis.h>
00023
00024 #include <kcombobox.h>
00025 #include <klocale.h>
00026 #include <kdebug.h>
00027 #include <kmenubar.h>
00028 #include <kmessagebox.h>
00029 #include <kstatusbar.h>
00030 #include <kkeydialog.h>
00031 #include <kfiledialog.h>
00032 #include <kedittoolbar.h>
00033 #include <kaction.h>
00034 #include <kfontdialog.h>
00035 #include <kautoconfigdialog.h>
00036
00037 #include "klettres.h"
00038 #include "fontsdlg.h"
00039
00040 #include <stdlib.h>
00041 #include <unistd.h>
00042
00043 const int ID_KIDB = 100;
00044 const int ID_GROWNB = 101;
00045 const int ID_MENUBARB = 102;
00046
00047 KLettres::KLettres()
00048 : KMainWindow( 0, "KLettres" )
00049 {
00050 m_view = new KLettresView(this);
00051 languages = 0;
00052
00053 setCentralWidget(m_view);
00054
00055 loadSettings();
00056
00057 soundFactory = new SoundFactory(this, "sounds", selectedLanguage);
00058
00059 setupActions();
00060
00061 menuBool=false;
00062 kidBool=false;
00063 grownBool=false;
00064
00065 tb = toolBar("mainToolBar");
00066
00067 lev_comb= new KComboBox(tb);
00068 lev_comb->insertItem( i18n( "Level 1" ) );
00069 lev_comb->insertItem( i18n( "Level 2" ) );
00070 lev_comb->insertItem( i18n( "Level 3" ) );
00071 lev_comb->insertItem( i18n( "Level 4" ) );
00072 tb->insertSeparator(3, 3);
00073 tb->insertWidget(4, 100, lev_comb, 4);
00074 connect( lev_comb, SIGNAL( activated(int) ), this, SLOT( slotChangeLevel(int) ) );
00075 QToolTip::add(lev_comb, i18n("Change the level of difficulty"));
00076 QWhatsThis::add(lev_comb, i18n( "Use this box to choose the level of difficulty" ));
00077 tb->insertSeparator(5, 5);
00078
00079
00080 secondToolbar = toolBar("secondToolbar");
00081
00082 KStatusBar *st=statusBar();
00083 langLabel = new QLabel(st);
00084 levLabel = new QLabel(st);
00085 st->addWidget(levLabel);
00086 st->insertFixedItem("", 1);
00087 st->addWidget(langLabel);
00088 statusBar();
00089
00090 if (style=="grownup") slotGrownup();
00091 else slotKid();
00092
00093 if (!m_view->niveau) m_view->niveau = 1;
00094
00095 updateLevMenu(m_view->niveau-1);
00096
00097 m_view->selectedLanguage = selectedLanguage;
00098 updateLanguage(selectedLanguage);
00099
00100 m_view->game();
00101 }
00102
00103 KLettres::~KLettres()
00104 {
00105 }
00106
00107 void KLettres::setupActions()
00108 {
00109 KStdAction::quit(kapp, SLOT(quit()), actionCollection());
00110
00111 m_action = new KToggleAction(i18n("Show &Menubar"),CTRL+Key_M, this, SLOT(slotMenubar()), actionCollection(), "menubar");
00112 m_action->setChecked(true);
00113
00114 createStandardStatusBarAction();
00115 setStandardToolBarMenuEnabled(true);
00116
00117 KStdAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection());
00118 KStdAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
00119 fontAct = new KAction(i18n("Change &Font"), "fonts", CTRL+Key_F, this, SLOT(optionsPreferences()), actionCollection(), "font");
00120 setAutoSaveSettings("General");
00121 createGUI();
00122 }
00123
00124
00125 void KLettres::registerLanguage(const QString &menuItem, const char *actionId, bool enabled)
00126 {
00127 KToggleAction *t = 0;
00128
00129 switch (languages)
00130 {
00131 case 0: t = new KToggleAction(i18n(menuItem.latin1()), 0, this, SLOT(language0()), actionCollection(), actionId);
00132 break;
00133 case 1: t = new KToggleAction(i18n(menuItem.latin1()), 0, this, SLOT(language1()), actionCollection(), actionId);
00134 break;
00135 case 2: t = new KToggleAction(i18n(menuItem.latin1()), 0, this, SLOT(language2()), actionCollection(), actionId);
00136 break;
00137 case 3: t = new KToggleAction(i18n(menuItem.latin1()), 0, this, SLOT(language3()), actionCollection(), actionId);
00138 break;
00139 case 4: t = new KToggleAction(i18n(menuItem.latin1()), 0, this, SLOT(language4()), actionCollection(), actionId);
00140 break;
00141 }
00142
00143 if( t ) {
00144 if (languages == selectedLanguage) t->setChecked(true);
00145 t->setEnabled(enabled);
00146 languageActions[languages] = actionId;
00147 languages++;
00148 }
00149 }
00150
00151 void KLettres::changeLanguage(uint newLanguage)
00152 {
00153
00154 if (newLanguage == selectedLanguage) {
00155
00156 ((KToggleAction*) actionCollection()->action(languageActions[newLanguage].latin1()))->setChecked(true);
00157 return;
00158 }
00159
00160 ((KToggleAction*) actionCollection()->action(languageActions[selectedLanguage].latin1()))->setChecked(false);
00161 ((KToggleAction*) actionCollection()->action(languageActions[newLanguage].latin1()))->setChecked(true);
00162
00163 selectedLanguage = newLanguage;
00164
00165 KConfig *config = kapp->config();
00166 if (config)
00167 {
00168 config->setGroup("General");
00169 config->writeEntry("LanguageNumber", selectedLanguage);
00170 }
00171
00172 updateLanguage(selectedLanguage);
00173
00174 soundFactory->change(newLanguage);
00175 m_view->game();
00176 }
00177
00178 bool KLettres::loadLayout(QDomDocument &layoutDocument)
00179 {
00180
00181 QFile layoutFile(locate("data", "klettres/data/sounds.xml"));
00182
00183 if (!layoutFile.exists())
00184 {
00185 kdWarning() << "sounds.xml file not found in $KDEDIR/share/apps/klettres/data/" << endl;
00186 QString mString=i18n("The file sounds.xml was not found in\n"
00187 "$KDEDIR/share/apps/klettres/data/\n\n"
00188 "Please install this file and start KLettres again.\n\n");
00189 KMessageBox::information( this, mString,"KLettres - Error" );
00190 exit(1);
00191 }
00192 if (!layoutFile.open(IO_ReadOnly))
00193 return false;
00195 if (!layoutDocument.setContent(&layoutFile))
00196 {
00197 layoutFile.close();
00198 return false;
00199 }
00200 layoutFile.close();
00201
00202 return true;
00203 }
00204
00206 void KLettres::language0()
00207 {
00208 changeLanguage(0);
00209 }
00210
00212 void KLettres::language1()
00213 {
00214 changeLanguage(1);
00215 }
00216
00218 void KLettres::language2()
00219 {
00220 changeLanguage(2);
00221 }
00222
00224 void KLettres::language3()
00225 {
00226 changeLanguage(3);
00227 }
00228
00230 void KLettres::language4()
00231 {
00232 changeLanguage(4);
00233 }
00234
00236 void KLettres::updateLanguage(int index)
00237 {
00238 switch(index){
00239 case 0:
00240 langString = i18n("Czech");
00241 break;
00242 case 1:
00243 langString = i18n("Danish");
00244 break;
00245 case 2:
00246 langString = i18n("French");
00247 break;
00248 case 3:
00249 langString = i18n("Dutch");
00250 break;
00251 case 4:
00252 langString = i18n("Slovak");
00253 break;
00254 }
00255 langLabel->setText(i18n("Current language is %1").arg(langString));
00256 loadLangToolBar();
00257 }
00258
00259 void KLettres::saveProperties(KConfig *)
00260 {
00261
00262
00263
00264 }
00265
00266 void KLettres::readProperties(KConfig *)
00267 {
00268
00269
00270
00271
00272 }
00273
00274 void KLettres::optionsConfigureKeys()
00275 {
00276 KKeyDialog::configure(actionCollection());
00277 }
00278
00279 void KLettres::optionsConfigureToolbars()
00280 {
00281
00282 saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
00283 KEditToolbar dlge(actionCollection());
00284 connect(&dlge, SIGNAL(newToolbarConfig()), this, SLOT(newToolbarConfig()));
00285 dlge.exec();
00286 }
00287
00288 void KLettres::newToolbarConfig()
00289 {
00290
00291
00292 createGUI();
00293 applyMainWindowSettings( KGlobal::config(), autoSaveGroup() );
00294 }
00295
00296 void KLettres::loadSettings()
00297 {
00298 loadLanguages();
00299 KConfig *config = kapp->config();
00300 config->setGroup("General");
00301
00302 selectedLanguage = config->readNumEntry("LanguageNumber", defaultLang);
00303 if (selectedLanguage >= (uint) m_languages.count())
00304 selectedLanguage = 2;
00305
00306 style=config->readEntry("myStyle", "grownup");
00307
00308 m_view->niveau=config->readNumEntry("myLevel", 1);
00309 config->setGroup("mFont");
00310
00311 QFont defaultFont = KGlobalSettings::largeFont();
00312 defaultFont.setPointSize(48);
00313 defaultFont.setBold(true);
00314
00315 m_view->setFont(config->readFontEntry("mFont", &defaultFont));
00316 }
00317
00318 void KLettres::loadLanguages()
00319 {
00320
00321 QStringList dirs = KGlobal::dirs()->findDirs("data", "klettres");
00322 for (QStringList::Iterator it = dirs.begin(); it != dirs.end(); ++it ) {
00323 QDir dir(*it);
00324 m_languages += dir.entryList(QDir::Dirs, QDir::Name);
00325 }
00326 m_languages.remove(m_languages.find("."));
00327 m_languages.remove(m_languages.find(".."));
00328 m_languages.remove(m_languages.find("pics"));
00329 m_languages.remove(m_languages.find("data"));
00330
00331
00332 KConfigBase *globalConf = KGlobal::config();
00333 globalConf->setGroup("Locale");
00334 userLanguage = globalConf->readEntry("Language");
00335
00336 userLanguage = userLanguage.left(2);
00337 defaultLang = m_languages.findIndex(userLanguage);
00338 if (defaultLang == -1)
00339 defaultLang = 2;
00340 }
00341
00342 void KLettres::optionsPreferences()
00343 {
00344 if(KAutoConfigDialog::showDialog("settings"))
00345 return;
00346
00347 KAutoConfigDialog *dialog = new KAutoConfigDialog(this, "settings");
00348 dialog->addPage(new fontsdlg(0, "mFont"), i18n("Font Settings"), "mFont", "fonts");
00349
00350
00351 connect(dialog, SIGNAL(settingsChanged()), this, SLOT(loadSettings()));
00352 dialog->show();
00353 }
00354
00355 void KLettres::slotGrownup()
00356 {
00357 QPalette pal;
00358 QColorGroup cg;
00359 cg.setColor( QColorGroup::Background, white);
00360 pal.setActive( cg );
00361 statusBar()->setPalette( pal );
00362 QFont f_lab( "times" , 12);
00363 levLabel->setFont(f_lab);
00364 langLabel->setFont(f_lab);
00365 m_action->setChecked(true);
00366 slotMenubar();
00367 if (grownBool) tb->removeItem(ID_GROWNB);
00368 tb->insertButton ("kids.png", ID_KIDB, SIGNAL( clicked() ), this, SLOT( slotKid()), true, i18n("Switch to the kid look"), 9 );
00369 kidBool=true;
00370 m_view->slotGrownup();
00371 style = m_view->style;
00372 KConfig *config = kapp->config();
00373 config->setGroup("General");
00374 config->writeEntry("myStyle", m_view->style);
00375 secondToolbar->setIconSize(22);
00376 setMinimumSize( QSize( 640, 538 ) );
00377 setMaximumSize( QSize( 640, 538 ) );
00378 }
00379
00380 void KLettres::slotKid()
00381 {
00382 QPalette pal;
00383 QColorGroup cg;
00384 cg.setColor( QColorGroup::Background, white);
00385 pal.setActive( cg );
00386 statusBar()->setPalette( pal );
00387 QFont f_lab( "times" , 14);
00388 levLabel->setFont(f_lab);
00389 langLabel->setFont(f_lab);
00390 m_action->setChecked(false);
00391 slotMenubar();
00392 if (kidBool) tb->removeItem(ID_KIDB);
00393 tb->insertButton ("grownup.png", ID_GROWNB, SIGNAL( clicked() ), this, SLOT( slotGrownup()), true, i18n("Switch to the grown-up look"),10 );
00394 grownBool=true;
00395 m_view->slotKid();
00396 style = m_view->style;
00397 KConfig *config = kapp->config();
00398 config->setGroup("General");
00399 config->writeEntry("myStyle", m_view->style);
00400 secondToolbar->setIconSize(32);
00401 setMinimumSize( QSize( 640, 480 ) );
00402 setMaximumSize( QSize( 640, 480 ) );
00403 }
00404
00406 void KLettres::slotMenubar()
00407 {
00408 switch (m_action->isChecked()){
00409 case false:
00410 m_action->setChecked(false);
00411 menuBar()->hide();
00412 if (menuBool) tb->removeItem(ID_MENUBARB);
00413 tb->insertButton ("menubar.png", ID_MENUBARB, SIGNAL( clicked() ), this, SLOT( slotShowM()), true, i18n("Show the MenuBar"), 8 );
00414 menuBool=true;
00415 break;
00416 case true:
00417 m_action->setChecked(true);
00418 menuBar()->show();
00419 if (menuBool) tb->removeItem(ID_MENUBARB);
00420 menuBool=false;
00421 break;
00422 }
00423 }
00424
00425 void KLettres::slotShowM()
00426 {
00427 m_action->setChecked(true);
00428 menuBar()->show();
00429 if (menuBool) tb->removeItem(ID_MENUBARB);
00430 menuBool=false;
00431 }
00432
00433 void KLettres::slotChangeLevel(int id)
00434 {
00435 m_view->niveau=id+1;
00436 updateLevMenu(id);
00437
00438 soundFactory->change(selectedLanguage);
00439
00440 KConfig *config = kapp->config();
00441 config->setGroup("General");
00442 config->writeEntry("myLevel", m_view->niveau);
00443
00444 m_view->game();
00445 }
00446
00447 void KLettres::updateLevMenu(int id)
00448 {
00449 lev_comb->setCurrentItem(id);
00450 levLabel->setText(i18n("Current level is %1").arg(m_view->niveau));
00451 }
00452
00453 void KLettres::loadLangToolBar()
00454 {
00455 secondToolbar->clear();
00456 if (selectedLanguage == 0)
00457 {
00458 secondToolbar->insertButton ("C_caron.png", 10, SIGNAL( clicked() ), this, SLOT( slotPasteCcaron()), true, i18n("Try ") + QString::fromUtf8("Č", -1), 1 );
00459 secondToolbar->insertButton ("D_caron.png", 20, SIGNAL( clicked() ), this, SLOT( slotPasteDcaron()), true, i18n("Try ")+ QString::fromUtf8("Ď", -1), 2 );
00460 secondToolbar->insertButton ("R_caron.png", 30, SIGNAL( clicked() ), this, SLOT( slotPasteRcaron()), true, i18n("Try ") + QString::fromUtf8("Ř", -1), 3 );
00461 secondToolbar->insertButton ("S_caron.png", 40, SIGNAL( clicked() ), this, SLOT( slotPasteScaron()), true, i18n("Try ") + QString::fromUtf8("Š", -1), 4 );
00462 secondToolbar->insertButton ("T_caron.png", 50, SIGNAL( clicked() ), this, SLOT( slotPasteTcaron()), true, i18n("Try ")+ QString::fromUtf8("Ť", -1), 5);
00463 secondToolbar->insertButton ("Z_caron.png", 60, SIGNAL( clicked() ), this, SLOT( slotPasteZcaron()), true, i18n("Try ") + QString::fromUtf8("Ž", -1), 6 );
00464 }
00465 else if (selectedLanguage == 1)
00466 {
00467 secondToolbar->insertButton ("A_circle.png", 10, SIGNAL( clicked() ), this, SLOT( slotPasteAcircle()), true, i18n("Try ") + QString::fromUtf8("Å", -1), 1 );
00468 secondToolbar->insertButton ("A_withE.png", 20, SIGNAL( clicked() ), this, SLOT( slotPasteAwithE()), true, i18n("Try ") + QString::fromUtf8("Æ", -1), 2 );
00469 secondToolbar->insertButton ("O_barre.png", 30, SIGNAL( clicked() ), this, SLOT( slotPasteObarre()), true, i18n("Try ")+ QString::fromUtf8("Ø", -1), 3 );
00470
00471 }
00472 else if (selectedLanguage == 2 || selectedLanguage==3)
00473 {
00474 if (secondToolbar) secondToolbar->hide();
00475 setMinimumSize( QSize( 640, 480 ) );
00476 setMaximumSize( QSize( 640, 480 ) );
00477 }
00478 else if (selectedLanguage == 4)
00479 {
00480 secondToolbar->insertButton ("A_acute.png", 10, SIGNAL( clicked() ), this, SLOT( slotPasteAacute()), true, i18n("Try ")+ QString::fromUtf8("Á", -1), 1 );
00481 secondToolbar->insertButton ("A_umlaut.png", 20, SIGNAL( clicked() ), this, SLOT( slotPasteAumlaut()), true, i18n("Try ")+ QString::fromUtf8("Ä", -1), 2 );
00482 secondToolbar->insertButton ("C_caron.png", 30, SIGNAL( clicked() ), this, SLOT( slotPasteCcaron()), true, i18n("Try ")+ QString::fromUtf8("Č", -1), 3 );
00483 secondToolbar->insertButton ("D_caron.png", 40, SIGNAL( clicked() ), this, SLOT( slotPasteDcaron()), true, i18n("Try ") + QString::fromUtf8("Ď", -1) , 4 );
00484 secondToolbar->insertButton ("E_acute.png", 50, SIGNAL( clicked() ), this, SLOT( slotPasteEacute()), true, i18n("Try ")+ QString::fromUtf8("É", -1) , 5 );
00485 secondToolbar->insertButton ("I_acute.png", 50, SIGNAL( clicked() ), this, SLOT( slotPasteIacute()), true, i18n("Try ") + QString::fromUtf8("Í", -1), 6 );
00486 secondToolbar->insertButton ("L_acute.png", 60, SIGNAL( clicked() ), this, SLOT( slotPasteLacute()), true, i18n("Try ") + QString::fromUtf8("Ĺ", -1), 7 );
00487 secondToolbar->insertButton ("L_apos.png", 70, SIGNAL( clicked() ), this, SLOT( slotPasteLapos()), true, i18n("Try ") + QString::fromUtf8("Ľ", -1), 8 );
00488 secondToolbar->insertButton ("N_caron.png", 40, SIGNAL( clicked() ), this, SLOT( slotPasteNcaron()), true, i18n("Try ") + QString::fromUtf8("Ň", -1), 9 );
00489 secondToolbar->insertButton ("O_acute.png", 50, SIGNAL( clicked() ), this, SLOT( slotPasteOacute()), true, i18n("Try ") + QString::fromUtf8("Ó", -1), 10 );
00490 secondToolbar->insertButton ("O_circ.png", 50, SIGNAL( clicked() ), this, SLOT( slotPasteOchap()), true, i18n("Try ") + QString::fromUtf8("Ô", -1), 11);
00491 secondToolbar->insertButton ("R_acute.png", 50, SIGNAL( clicked() ), this, SLOT( slotPasteRacute()), true, i18n("Try ")+ QString::fromUtf8("Ŕ", -1), 12 );
00492 secondToolbar->insertButton ("S_caron.png", 40, SIGNAL( clicked() ), this, SLOT( slotPasteScaron()), true, i18n("Try ")+ QString::fromUtf8("Š", -1), 13 );
00493 secondToolbar->insertButton ("T_caron.png", 50, SIGNAL( clicked() ), this, SLOT( slotPasteTcaron()), true, i18n("Try ") + QString::fromUtf8("Ť", -1), 14);
00494 secondToolbar->insertButton ("U_acute.png", 50, SIGNAL( clicked() ), this, SLOT( slotPasteRacute()), true, i18n("Try ")+ QString::fromUtf8("Ú", -1), 15 );
00495 secondToolbar->insertButton ("Z_caron.png", 60, SIGNAL( clicked() ), this, SLOT( slotPasteZcaron()), true, i18n("Try ")+ QString::fromUtf8("Ž", -1), 16 );
00496 }
00497 KConfig *config = kapp->config();
00498 config->setGroup("General Toolbar secondToolbar");
00499 if (config->readBoolEntry("Hidden"))
00500 secondToolbar->hide();
00501 else secondToolbar->show();
00502 }
00503
00504 void KLettres::slotPasteCcaron()
00505 {
00506 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Č", -1));
00507 }
00508
00509 void KLettres::slotPasteDcaron()
00510 {
00511 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ď", -1));
00512 }
00513
00514 void KLettres::slotPasteRcaron()
00515 {
00516 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ř", -1));
00517 }
00518
00519 void KLettres::slotPasteScaron()
00520 {
00521 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Š", -1));
00522 }
00523
00524 void KLettres::slotPasteTcaron()
00525 {
00526 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ť", -1));
00527 }
00528
00529 void KLettres::slotPasteZcaron()
00530 {
00531 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ž", -1));
00532 }
00533
00534 void KLettres::slotPasteAcircle()
00535 {
00536 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Å", -1));
00537 }
00538 void KLettres::slotPasteAwithE()
00539 {
00540 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Æ", -1));
00541 }
00542 void KLettres::slotPasteObarre()
00543 {
00544 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ø", -1));
00545 }
00546
00547 void KLettres::slotPasteAacute()
00548 {
00549 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Á", -1));
00550 }
00551
00552 void KLettres::slotPasteAumlaut()
00553 {
00554 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ä", -1));
00555 }
00556
00557 void KLettres::slotPasteEacute()
00558 {
00559 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("É", -1));
00560 }
00561
00562 void KLettres::slotPasteIacute()
00563 {
00564 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Í", -1));
00565 }
00566
00567 void KLettres::slotPasteLacute()
00568 {
00569 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ĺ", -1));
00570 }
00571
00572 void KLettres::slotPasteLapos()
00573 {
00574 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ľ", -1));
00575 }
00576
00577 void KLettres::slotPasteNcaron()
00578 {
00579 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ň", -1));
00580 }
00581
00582 void KLettres::slotPasteOacute()
00583 {
00584 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ó", -1));
00585 }
00586
00587 void KLettres::slotPasteOchap()
00588 {
00589 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ô", -1));
00590 }
00591
00592 void KLettres::slotPasteRacute()
00593 {
00594 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ŕ", -1));
00595 }
00596
00597 void KLettres::slotPasteUacute()
00598 {
00599 m_view->line1->setText(m_view->line1->text()+QString::fromUtf8("Ú", -1));
00600 }
00601
00602 #include "klettres.moc"