1 /***************************************************************************
2 kwordquizprefs.cpp - description
4 begin : Sun Aug 18 2002
5 copyright : (C) 2002-2003 by Peter Hedlund
6 email : peter@peterandlinda.com
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include <qwidgetstack.h>
20 #include <qradiobutton.h>
21 #include <qcheckbox.h>
22 #include <qlistview.h>
26 #include <kstandarddirs.h>
27 #include <kiconloader.h>
28 #include <krestrictedline.h>
29 #include <kmessagebox.h>
30 #include <kpushbutton.h>
32 #include <kconfigskeleton.h>
33 #include <kcolorbutton.h>
34 #include <kfontrequester.h>
36 #include "kwordquizprefs.h"
37 #include "prefeditor.h"
39 #include "prefcharacter.h"
40 #include "prefcardappearance.h"
41 #include "kwordquiz.h"
42 #include "dlgspecchar.h"
44 KWordQuizPrefs::KWordQuizPrefs(QWidget
*parent
, const char *name
, KConfigSkeleton
*config
, DialogType dialogType
, int /*dialogButtons*/, ButtonCode
/*defaultButton*/, bool /*modal*/)
45 : KConfigDialog(parent
, name
, config
, dialogType
, Default
|Ok
|Apply
|Cancel
|Help
, Ok
, false)
49 m_prefEditor
= new PrefEditor(0, "Editor Settings");
50 addPage(m_prefEditor
, i18n("Editor"), "editor", i18n("Editor Settings"), true);
52 m_prefQuiz
= new PrefQuiz(0, "Quiz Settings");
53 addPage(m_prefQuiz
, i18n("Quiz"), "qa", i18n("Quiz Settings"), true);
55 m_prefCardAppearance
= new PrefCardAppearance(0, "Flashcard Appearance");
56 addPage(m_prefCardAppearance
, i18n("Flashcard\nAppearance"), "flash", i18n("Flashcard Appearance Settings"), true);
58 m_prefCharacter
= new PrefCharacter(0, "Special Characters");
59 addPage(m_prefCharacter
, i18n("Special\nCharacters"), "kcharselect", i18n("Special Characters"), true);
63 connect(m_prefCharacter
->lstCharacters
, SIGNAL(selectionChanged()), this, SLOT(slotCharListSelectionChanged()));
64 connect(m_prefCharacter
->btnCharacter
, SIGNAL(clicked()), this, SLOT(slotSelectSpecChar()));
66 KWordQuizApp
*win
=(KWordQuizApp
*) parent
;
69 KConfigSkeletonItem
* item
= m_config
->findItem("SpecialCharacters");
70 QString ds
= item
->property().toString();
72 for ( QListViewItemIterator it
= m_prefCharacter
->lstCharacters
; it
.current(); ++it
)
74 it
.current()->setText(2, (QString
) ds
[i
++] ) ;
75 it
.current()->setText(1, win
->actionCollection()->action(QString("char_" + QString::number(i
)).latin1())->shortcut().toString());
78 m_prefCharacter
->lstCharacters
->setSelected(m_prefCharacter
->lstCharacters
->firstChild(), true);
79 m_prefCharacter
->lstCharacters
->setItemMargin(2);
82 kapp
->processEvents();
85 KWordQuizPrefs::~KWordQuizPrefs(){
88 void KWordQuizPrefs::slotCharListSelectionChanged( )
90 m_prefCharacter
->lblPreview
->setText(m_prefCharacter
->lstCharacters
->currentItem()->text(2));
93 void KWordQuizPrefs::slotSelectSpecChar( )
95 KConfigSkeletonItem
* item
= m_config
->findItem("EditorFont");
96 QString f
= item
->property().toFont().family();
97 QString s
= m_prefCharacter
->lstCharacters
->currentItem()->text(2);
100 if (m_dlgSpecChar
== 0)
102 m_dlgSpecChar
= new DlgSpecChar( this, "insert special char", f
, c
, true );
103 connect( m_dlgSpecChar
, SIGNAL(insertChar(QChar
)), this, SLOT(slotSpecChar(QChar
)));
104 connect( m_dlgSpecChar
, SIGNAL(finished()), this, SLOT( slotDlgSpecCharClosed() ) );
106 m_dlgSpecChar
->show();
109 void KWordQuizPrefs::slotDlgSpecCharClosed( )
113 disconnect( m_dlgSpecChar
, SIGNAL(insertChar(QChar
)), this, SLOT(slotSpecChar(QChar
)));
114 disconnect( m_dlgSpecChar
, SIGNAL( finished() ), this, SLOT( slotDlgSpecCharClosed() ) );
115 m_dlgSpecChar
->deleteLater();
120 void KWordQuizPrefs::slotSpecChar(QChar c
)
122 m_prefCharacter
->lstCharacters
->currentItem()->setText(2, c
);
123 m_prefCharacter
->lblPreview
->setText(m_prefCharacter
->lstCharacters
->currentItem()->text(2));
128 bool KWordQuizPrefs::hasChanged( )
130 kdDebug() << "hasChanged" << endl
;
135 result
= KConfigDialog::hasChanged();
136 kdDebug() << result
<< endl
;
140 bool KWordQuizPrefs::isDefault( )
142 kdDebug() << "isDefault" << endl
;
143 bool bUseDefaults
= m_config
->useDefaults(true);
144 bool result
/*= !hasChanged()*/;
147 for ( QListViewItemIterator it
= m_prefCharacter
->lstCharacters
; it
.current(); ++it
)
149 s
.append(it
.current()->text(2));
152 KConfigSkeletonItem
* item
= m_config
->findItem("SpecialCharacters");
153 QString ds
= item
->property().toString();
155 if (ds
== s
.stripWhiteSpace())
156 result
= KConfigDialog::isDefault();
160 m_config
->useDefaults(bUseDefaults
);
164 void KWordQuizPrefs::updateSettings( )
166 kdDebug() << "updateSettings" << endl
;
168 for ( QListViewItemIterator it
= m_prefCharacter
->lstCharacters
; it
.current(); ++it
)
170 s
.append(it
.current()->text(2));
173 KConfigSkeletonItem
* item
= m_config
->findItem("SpecialCharacters");
174 item
->setProperty(QVariant(s
));
176 emit
settingsChanged();
177 m_hasChanged
= false;
180 void KWordQuizPrefs::updateWidgetsDefault( )
182 bool bUseDefaults
= m_config
->useDefaults(true);
185 for ( QListViewItemIterator it
= m_prefCharacter
->lstCharacters
; it
.current(); ++it
)
187 s
.append(it
.current()->text(2));
190 KConfigSkeletonItem
* item
= m_config
->findItem("SpecialCharacters");
191 QString ds
= item
->property().toString();
194 for ( QListViewItemIterator it
= m_prefCharacter
->lstCharacters
; it
.current(); ++it
)
196 it
.current()->setText(2, (QString
) ds
[i
++] ) ;
198 m_prefCharacter
->lblPreview
->setText(m_prefCharacter
->lstCharacters
->currentItem()->text(2));
199 m_hasChanged
= (ds
!= s
);
200 m_config
->useDefaults(bUseDefaults
);
203 #include "kwordquizprefs.moc"