29 #include <QTextStream>
30 #include <QDomDocument>
35 #include <KActionCollection>
37 #include <KConfigDialog>
41 #include <KMessageBox>
43 #include <KSelectAction>
44 #include <KStandardAction>
45 #include <KStandardDirs>
47 #include <KToggleAction>
50 #include <KApplication>
53 #include <knewstuff3/downloaddialog.h>
55 #include "ui_fontsdlg.h"
61 class fontsdlg :
public QWidget,
public Ui::fontsdlg
64 fontsdlg( QWidget * parent ) : QWidget(parent)
77 setObjectName( QLatin1String(
"KLettres") );
80 setMinimumSize( QSize( 800, 600 ) );
103 QFile layoutFile(KStandardDirs::locate(
"data",
"klettres/"+
Prefs::language()+
"/sounds.xml"));
105 if (!layoutFile.exists()) {
106 kWarning() <<
"sounds.xml file not found in $KDEDIR/share/apps/klettres/"+
Prefs::language() ;
107 QString mString=i18n(
"The file sounds.xml was not found in\n"
108 "$KDEDIR/share/apps/klettres/\n\n"
109 "Please install this file and start KLettres again.\n\n");
110 KMessageBox::information(
this, mString,i18n(
"KLettres - Error") );
114 if (!layoutFile.open(QIODevice::ReadOnly)) {
119 if (!layoutDocument.setContent(&layoutFile)) {
131 KAction *m_newAction = actionCollection()->addAction(
"play_new");
132 m_newAction->setText(i18n(
"New Sound"));
133 m_newAction->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_N));
134 m_newAction->setIcon(KIcon(
"document-new"));
135 connect(m_newAction, SIGNAL(triggered(
bool)),
m_view, SLOT(game()));
136 m_newAction->setToolTip(i18n(
"Play a new sound"));
137 m_newAction->setWhatsThis(i18n(
"You can play a new sound by clicking this button or using the File menu, New Sound."));
139 QAction *m_stuffAction = actionCollection()->addAction(
"downloadnewstuff");
140 m_stuffAction->setText(i18n(
"Get Alphabet in New Language..."));
141 m_stuffAction->setIcon(KIcon(
"get-hot-new-stuff"));
144 KAction *m_playAgainAction = actionCollection()->addAction(
"play_again");
145 m_playAgainAction->setText(i18n(
"Replay Sound"));
146 m_playAgainAction->setShortcut(QKeySequence(Qt::Key_F5));
147 m_playAgainAction->setIcon(KIcon(
"media-playback-start"));
148 m_playAgainAction->setToolTip(i18n(
"Play the same sound again"));
149 connect(m_playAgainAction, SIGNAL(triggered(
bool)),
m_view, SLOT(slotPlayAgain()));
150 m_playAgainAction->setWhatsThis(i18n(
"You can replay the same sound again by clicking this button or using the File menu, Replay Sound."));
151 KStandardAction::quit(kapp, SLOT(quit()), actionCollection());
155 m_levelAction = actionCollection()->add<KSelectAction>(
"levels");
156 m_levelAction->setText(i18nc(
"@label:listbox which difficulty level to use",
"L&evel"));
158 m_levelAction->setWhatsThis(i18n(
"You can select the level: level 1 displays a letter and you hear it; level 2 does not display the letter, you only hear it; level 3 displays a syllable and you hear it; level 4 does not display the syllable, you only hear it."));
164 m_levelsNames.append(i18ncp(
"@item:inlistbox choose level",
"Level %1" ,
"Level %1", 1));
165 m_levelsNames.append(i18ncp(
"@item:inlistbox choose level",
"Level %1" ,
"Level %1", 2));
166 m_levelsNames.append(i18ncp(
"@item:inlistbox choose level",
"Level %1" ,
"Level %1", 3));
167 m_levelsNames.append(i18ncp(
"@item:inlistbox choose level",
"Level %1" ,
"Level %1", 4));
171 m_themeAction = actionCollection()->add<KSelectAction>(
"looks");
176 m_themeAction->setWhatsThis(i18n(
"Here you can change the theme for KLettres. A theme consists in the background picture and the font color for the letter displayed."));
178 m_kidAction = actionCollection()->add<KToggleAction>(
"mode_kid");
180 m_kidAction->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_K));
183 m_kidAction->setWhatsThis(i18n(
"If you are in the Grown-up mode, clicking on this button will set up the Kid mode. The Kid mode has no menubar and the font is bigger in the statusbar."));
185 m_grownupAction = actionCollection()->add<KToggleAction>(
"mode_grownup");
190 m_grownupAction->setWhatsThis(i18n(
"The Grownup mode is the normal mode where you can see the menubar."));
203 KStatusBar *st=statusBar();
207 st->insertFixedItem(
"", 1);
221 if(KConfigDialog::showDialog(
"settings")) {
225 KConfigDialog *dialog =
new KConfigDialog(
this,
"settings",
Prefs::self());
226 dialog->addPage(
new fontsdlg(0), i18n(
"Font Settings"),
"preferences-desktop-font");
230 dialog->addPage(m_timer, i18n(
"Timer"),
"chronometer");
231 connect(dialog, SIGNAL(settingsChanged(
const QString &)),
this, SLOT(
slotUpdateSettings()));
232 dialog->setAttribute( Qt::WA_DeleteOnClose );
233 dialog->setHelp(QString(),
"klettres");
244 langString.remove(
'&');
264 QPointer<KNS3::DownloadDialog> dialog(
new KNS3::DownloadDialog(
"klettres.knsrc",
this));
265 if ( dialog->exec() == QDialog::Accepted ) {
325 langString.remove(
'&');
349 pal.setColor( QPalette::Background, Qt::white);
350 statusBar()->setPalette( pal );
351 QFont f_lab(
"Serif" , 10);
357 m_grownupAction->setToolTip(i18n(
"Grown-up mode is currently active"));
358 m_kidAction->setToolTip(i18n(
"Switch to Kid mode"));
368 pal.setColor( QPalette::Background, Qt::white);
369 statusBar()->setPalette( pal );
370 QFont f_lab(
"Serif" , 12);
376 m_kidAction->setToolTip(i18n(
"Kid mode is currently active"));
393 QString myString=QString(
"klettres/%1.txt").arg(lang);
395 myFile.setFileName(KStandardDirs::locate(
"data",myString));
397 if (!myFile.exists()) {
398 QString mString=i18n(
"File $KDEDIR/share/apps/klettres/%1.txt not found;\n"
399 "please check your installation.", lang);
400 KMessageBox::sorry(
this, mString,
406 QFile openFileStream(myFile.fileName());
407 openFileStream.open(QIODevice::ReadOnly);
408 QTextStream readFileStr(&openFileStream);
409 readFileStr.setCodec(
"UTF-8");
411 allData = readFileStr.readAll().split(
'\n');
412 openFileStream.close();
414 for (
int i=0; i<(int)
allData.count(); ++i) {
420 connect(act, SIGNAL(triggered(
bool)),
this, SLOT(
slotPasteChar()));
433 QAction *act = qobject_cast<QAction*>(sender());
439 int id = act->data().toInt(&ok);
441 if (!ok || id < 0 || id >=
allData.count()) {
451 QString s = KStandardDirs::locateLocal(
"icon",
"char" + QString::number(c.unicode()) +
".png");
453 QRect r(4, 4, 120, 120);
457 font.setFamily(
"Arial" );
458 font.setPixelSize(120);
459 font.setWeight(QFont::Normal);
462 QPixmap pm(128, 128);
467 p.drawText(r, Qt::AlignCenter, (QString) c);
470 QBitmap bm(128, 128);
474 b.setPen(Qt::color1);
475 b.drawText(r, Qt::AlignCenter, (QString) c);
486 #include "klettres.moc"
void slotChangeLanguage(int)
Set the new language.
void setupToolbars()
Create main and second toolbars.
QIcon charIcon(const QChar &c)
generates icons for the special characters toolbar
QStringList m_languageNames
All available language names.
void slotMenubar()
Hide/Show the menubar.
static void setMenuBarBool(bool v)
Set Whether the menubar is shown or hidden.
void game()
Start playing displaying a new letter/syllable, playing the associated sound.
static QString language()
Get Language.
void setupActions()
Build the main window menus.
void setTheme(KLTheme *theme)
set the chosen theme
QLabel * m_langLabel
Label stating the language in the statusbar.
static int level()
Get Difficulty level.
int m_timer
The timer value i.e. the time for displaying the letters/syllables.
void slotModeGrownup()
Switch to the grown-up look, menubar is shown.
This class serves as the view for KLettres.
void updateLevMenu(int id)
Update the level menu and level combobox.
bool loadLayout(QDomDocument &layoutDocument)
Load the xml file.
void slotUpdateSettings()
Set the new font and the new timers.
static bool menuBarBool()
Get Whether the menubar is shown or hidden.
static int grownTimer()
Get Grown-up Timer.
void slotChangeLevel(int)
Set the new level.
static int kidTimer()
Get Kid Timer.
KSelectAction * m_languageAction
Action that sets up the Language menu.
QLabel * m_levLabel
Label stating the level in the statusbar.
KLNewStuff * mNewStuff
Create a KNewStuff instance.
static QFont font()
Get Font.
void slotPasteChar()
When a button is clicked on the characters toolbar, the corresponding character is written in the lin...
This class manages the sounds to play in KLettres, reading the data about the sounds in the sounds...
KLineEdit * m_letterEdit
The line where the user enters his/her input.
SoundFactory * soundFactory
Sound class.
void change(const QString ¤tLanguage)
Change the language when the user changes the language in the Languages menu.
static int theme()
Get Theme.
KSelectAction * m_themeAction
Action that sets up the Look menu.
static KLThemeFactory * instance()
QStringList m_levelsNames
Holds the levels.
void slotModeKid()
Switch to the kid look, menubar is hidden.
static void setLevel(int v)
Set Difficulty level.
void loadLangToolBar()
Set the correct buttons on the second toolbar according to the language.
KSelectAction * m_levelAction
Action that sets up the Level menu.
static void setLanguage(const QString &v)
Set Language.
KToolBar * specialCharToolbar
Second toolbar with buttons of special characters per language.
void loadSettings()
Load the configuration settings and apply them.
static int mode()
Get Mode.
void slotChangeTheme(int)
Change Look from menu Look.
KLettresView * m_view
Call an instance of the KLettresView widget.
QStringList allData
All the special characters from a language file, these characters will be as buttons on the Special C...
void optionsPreferences()
Display the Configure KLettres dialog.
static void setTheme(int v)
Set Theme.
KToggleAction * m_kidAction
Action allowing the Kid mode.
static void setMode(int v)
Set Mode.
virtual ~KLettres()
Destructor.
Timer widget in Settings dialog.
void setupStatusbar()
Create and setup statusbar.
KToggleAction * m_menubarAction
Action that enables the ShowMenuBar item in the Settings menu.
int randomInt
The index to the random sequence.
KToggleAction * m_grownupAction
Action allowing the Grownup mode.
static QStringList getLanguagesNames(QStringList languagesList)
All available languages translated names.
QDomDocument m_layoutsDocument
The language document.
static bool hasSpecialChars(const QString &lang)
void slotDownloadNewStuff()
Call the Get New Stuff dialog.
static QStringList getLanguages()
Available languages ISO names.