1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
/***************************************************************************
kwordquizprefs.cpp - description
-------------------
begin : Sun Aug 18 2002
copyright : (C) 2002-2005 by Peter Hedlund
email : peter.hedlund@kdemail.net
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include <qwidgetstack.h>
#include <qlayout.h>
#include <qradiobutton.h>
#include <qcheckbox.h>
#include <qlistview.h>
#include <qlabel.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kiconloader.h>
#include <krestrictedline.h>
#include <kmessagebox.h>
#include <kpushbutton.h>
#include <kdebug.h>
#include <kconfigskeleton.h>
#include <kcolorbutton.h>
#include <kfontrequester.h>
#include "kwordquizprefs.h"
#include "prefeditor.h"
#include "prefquiz.h"
#include "prefcharacter.h"
#include "prefcardappearance.h"
#include "kwordquiz.h"
#include "dlgspecchar.h"
KWordQuizPrefs::KWordQuizPrefs(QWidget *parent, const char *name, KConfigSkeleton *config, DialogType dialogType, int /*dialogButtons*/, ButtonCode /*defaultButton*/, bool /*modal*/)
: KConfigDialog(parent, name, config, dialogType, Default|Ok|Apply|Cancel|Help, Ok, false)
{
m_config = config;
m_prefEditor = new PrefEditor(0, "Editor Settings");
addPage(m_prefEditor, i18n("Editor"), "editor", i18n("Editor Settings"), true);
m_prefQuiz = new PrefQuiz(0, "Quiz Settings");
addPage(m_prefQuiz, i18n("Quiz"), "qa", i18n("Quiz Settings"), true);
m_prefCardAppearance = new PrefCardAppearance(0, "Flashcard Appearance");
addPage(m_prefCardAppearance, i18n("Flashcard\nAppearance"), "flash", i18n("Flashcard Appearance Settings"), true);
m_prefCharacter = new PrefCharacter(0, "Special Characters");
addPage(m_prefCharacter, i18n("Special\nCharacters"), "kcharselect", i18n("Special Characters"), true);
m_dlgSpecChar = 0L;
connect(m_prefCharacter->lstCharacters, SIGNAL(selectionChanged()), this, SLOT(slotCharListSelectionChanged()));
connect(m_prefCharacter->btnCharacter, SIGNAL(clicked()), this, SLOT(slotSelectSpecChar()));
KWordQuizApp *win=(KWordQuizApp *) parent;
int i=0;
KConfigSkeletonItem * item = m_config->findItem("SpecialCharacters");
QString ds = item->property().toString();
for ( QListViewItemIterator it = m_prefCharacter->lstCharacters; it.current(); ++it)
{
it.current()->setText(2, (QString) ds[i++] ) ;
it.current()->setText(1, win->actionCollection()->action(QString("char_" + QString::number(i)).latin1())->shortcut().toString());
}
m_prefCharacter->lstCharacters->setSelected(m_prefCharacter->lstCharacters->firstChild(), true);
m_prefCharacter->lstCharacters->setItemMargin(2);
kapp->processEvents();
}
void KWordQuizPrefs::slotCharListSelectionChanged()
{
m_prefCharacter->lblPreview->setText(m_prefCharacter->lstCharacters->currentItem()->text(2));
}
void KWordQuizPrefs::slotSelectSpecChar( )
{
KConfigSkeletonItem * item = m_config->findItem("EditorFont");
QString f = item->property().toFont().family();
QString s = m_prefCharacter->lstCharacters->currentItem()->text(2);
QChar c = s[0];
if (m_dlgSpecChar == 0)
{
m_dlgSpecChar = new DlgSpecChar( this, "insert special char", f, c, true );
connect(m_dlgSpecChar, SIGNAL(insertChar(QChar)), this, SLOT(slotSpecChar(QChar)));
connect(m_dlgSpecChar, SIGNAL(finished()), this, SLOT(slotDlgSpecCharClosed()));
}
m_dlgSpecChar->show();
}
void KWordQuizPrefs::slotDlgSpecCharClosed()
{
if ( m_dlgSpecChar )
{
disconnect(m_dlgSpecChar, SIGNAL(insertChar(QChar)), this, SLOT(slotSpecChar(QChar)));
disconnect(m_dlgSpecChar, SIGNAL(finished()), this, SLOT(slotDlgSpecCharClosed()));
m_dlgSpecChar->deleteLater();
m_dlgSpecChar = 0L;
}
}
void KWordQuizPrefs::slotSpecChar(QChar c)
{
m_prefCharacter->lstCharacters->currentItem()->setText(2, c);
m_prefCharacter->lblPreview->setText(m_prefCharacter->lstCharacters->currentItem()->text(2));
updateButtons();
}
bool KWordQuizPrefs::hasChanged()
{
bool result;
QString s;
for (QListViewItemIterator it = m_prefCharacter->lstCharacters; it.current(); ++it)
{
s.append(it.current()->text(2));
}
KConfigSkeletonItem * item = m_config->findItem("SpecialCharacters");
QString ds = item->property().toString();
if (ds == s.stripWhiteSpace())
result = KConfigDialog::hasChanged();
else
result = true;
return result;
}
bool KWordQuizPrefs::isDefault()
{
bool bUseDefaults = m_config->useDefaults(true);
bool result;
QString s;
for (QListViewItemIterator it = m_prefCharacter->lstCharacters; it.current(); ++it)
{
s.append(it.current()->text(2));
}
KConfigSkeletonItem * item = m_config->findItem("SpecialCharacters");
QString ds = item->property().toString();
if (ds == s.stripWhiteSpace())
result = KConfigDialog::isDefault();
else
result = false;
m_config->useDefaults(bUseDefaults);
return result;
}
void KWordQuizPrefs::updateSettings( )
{
QString s;
for (QListViewItemIterator it = m_prefCharacter->lstCharacters; it.current(); ++it)
{
s.append(it.current()->text(2));
}
KConfigSkeletonItem * item = m_config->findItem("SpecialCharacters");
item->setProperty(QVariant(s));
emit settingsChanged();
}
void KWordQuizPrefs::updateWidgetsDefault( )
{
bool bUseDefaults = m_config->useDefaults(true);
QString s;
for (QListViewItemIterator it = m_prefCharacter->lstCharacters; it.current(); ++it)
{
s.append(it.current()->text(2));
}
KConfigSkeletonItem * item = m_config->findItem("SpecialCharacters");
QString ds = item->property().toString();
int i=0;
for (QListViewItemIterator it = m_prefCharacter->lstCharacters; it.current(); ++it)
{
it.current()->setText(2, (QString) ds[i++] ) ;
}
m_prefCharacter->lblPreview->setText(m_prefCharacter->lstCharacters->currentItem()->text(2));
m_config->useDefaults(bUseDefaults);
}
#include "kwordquizprefs.moc"
|