moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kvoctrain / kvoctrain / common-dialogs / thresholdoptions.cpp
blob2d24fa73d5ba6b66d06390cff63cd0ba04354107
1 /***************************************************************************
3 threshold options for kvoctrain
5 -----------------------------------------------------------------------
7 begin : Tue Apr 5 2005
9 copyright :(C) 2005 Peter Hedlund
11 email : peter@peterandlinda.com
13 -----------------------------------------------------------------------
15 ***************************************************************************/
17 /***************************************************************************
18 * *
19 * This program is free software; you can redistribute it and/or modify *
20 * it under the terms of the GNU General Public License as published by *
21 * the Free Software Foundation; either version 2 of the License, or *
22 * (at your option) any later version. *
23 * *
24 ***************************************************************************/
26 #include <qlistbox.h>
27 #include <qpushbutton.h>
28 #include <qlabel.h>
29 #include <qcombobox.h>
31 #include <kcombobox.h>
32 #include <klocale.h>
34 #include "thresholdoptions.h"
35 #include "QueryManager.h"
36 #include "prefs.h"
39 static Prefs::EnumCompType::type bad_complist[] =
40 {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::MoreThan, Prefs::EnumCompType::MoreEqThan,
41 Prefs::EnumCompType::EqualTo, Prefs::EnumCompType::NotEqual, Prefs::EnumCompType::LessEqThan,
42 Prefs::EnumCompType::LessThan, Prefs::EnumCompType::type(-1)};
44 static Prefs::EnumCompType::type query_complist[] =
45 {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::MoreThan, Prefs::EnumCompType::MoreEqThan,
46 Prefs::EnumCompType::EqualTo, Prefs::EnumCompType::NotEqual, Prefs::EnumCompType::LessEqThan,
47 Prefs::EnumCompType::LessThan, Prefs::EnumCompType::type(-1)};
49 static Prefs::EnumCompType::type grade_complist[] =
50 {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::WorseThan, Prefs::EnumCompType::WorseEqThan,
51 Prefs::EnumCompType::EqualTo, Prefs::EnumCompType::NotEqual, Prefs::EnumCompType::BetterEqThan,
52 Prefs::EnumCompType::BetterThan, Prefs::EnumCompType::type(-1)};
54 static Prefs::EnumCompType::type type_complist[] =
55 {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::EqualTo, Prefs::EnumCompType::NotEqual,
56 Prefs::EnumCompType::type(-1)};
58 static Prefs::EnumCompType::type date_complist[] =
59 {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::Before, Prefs::EnumCompType::Within,
60 Prefs::EnumCompType::NotQueried, Prefs::EnumCompType::type(-1)};
62 static Prefs::EnumCompType::type less_complist[] =
63 {Prefs::EnumCompType::DontCare, Prefs::EnumCompType::OneOf, Prefs::EnumCompType::NotOneOf,
64 Prefs::EnumCompType::Current, Prefs::EnumCompType::NotAssigned, Prefs::EnumCompType::type(-1)};
66 struct ThreshListRef
68 const char *text;
69 long int num;
72 static ThreshListRef Threshdate_itemlist [] =
74 {I18N_NOOP("30 Min"), 30*60},
75 {I18N_NOOP("1 Hour"), 1 * 60*60},
76 {I18N_NOOP("2 Hours"), 2 * 60*60},
77 {I18N_NOOP("4 Hours"), 4 * 60*60},
78 {I18N_NOOP("8 Hours"), 8 * 60*60},
79 {I18N_NOOP("12 Hours"), 12 * 60*60},
80 {I18N_NOOP("18 Hours"), 18 * 60*60},
82 {I18N_NOOP("1 Day"), 1 * 60*60*24},
83 {I18N_NOOP("2 Days"), 2 * 60*60*24},
84 {I18N_NOOP("3 Days"), 3 * 60*60*24},
85 {I18N_NOOP("4 Days"), 4 * 60*60*24},
86 {I18N_NOOP("5 Days"), 5 * 60*60*24},
87 {I18N_NOOP("6 Days"), 6 * 60*60*24},
89 {I18N_NOOP("1 Week"), 1 * 60*60*24*7},
90 {I18N_NOOP("2 Weeks"), 2 * 60*60*24*7},
91 {I18N_NOOP("3 Weeks"), 3 * 60*60*24*7},
92 {I18N_NOOP("4 Weeks"), 4 * 60*60*24*7},
94 {I18N_NOOP("1 Month"), 1 * 60*60*24*30},
95 {I18N_NOOP("2 Months"), 2 * 60*60*24*30},
96 {I18N_NOOP("3 Months"), 3 * 60*60*24*30},
97 {I18N_NOOP("4 Months"), 4 * 60*60*24*30},
98 {I18N_NOOP("5 Months"), 5 * 60*60*24*30},
99 {I18N_NOOP("6 Months"), 6 * 60*60*24*30},
100 {0, 0}
104 ThresholdOptions::ThresholdOptions(KComboBox * lessons, QueryManager * m, QWidget* parent, const char* name, WFlags fl)
105 : ThresholdOptionsBase(parent, name, fl), m_lessons(lessons)
107 connect(lessoncomp, SIGNAL(activated(int)), SLOT(slotSetLessonComp(int)));
108 connect(lessonlist, SIGNAL(selectionChanged()), SIGNAL(widgetModified()));
109 connect(b_all_less, SIGNAL(clicked()), SLOT(slotSelectAll()));
110 connect(b_none_less, SIGNAL(clicked()), SLOT(slotSelectNone()));
111 connect(typecomp, SIGNAL(activated(int)), SLOT(slotSetTypeComp(int)));
112 connect(typelist, SIGNAL(activated(int)), SLOT(slotComboActivated(int)));
113 connect(gradecomp, SIGNAL(activated(int)), SLOT(slotSetGradeComp(int)));
114 connect(gradelist, SIGNAL(activated(int)), SLOT(slotComboActivated(int)));
115 connect(querycomp, SIGNAL(activated(int)), SLOT(slotSetQueryComp(int)));
116 connect(querylist, SIGNAL(activated(int)), SLOT(slotComboActivated(int)));
117 connect(badcomp, SIGNAL(activated(int)), SLOT(slotSetBadComp(int)));
118 connect(badlist, SIGNAL(activated(int)), SLOT(slotComboActivated(int)));
119 connect(datecomp, SIGNAL(activated(int)), SLOT(slotSetDateComp(int)));
120 connect(datelist, SIGNAL(activated(int)), SLOT(slotComboActivated(int)));
122 m_queryManager = m;
123 fillWidgets();
124 updateWidgets();
127 void ThresholdOptions::fillWidgets()
129 Prefs::EnumCompType::type *ct;
130 ThreshListRef *ref;
132 lessonlist->clear();
133 for (int i = 1; i < (int) m_lessons->count(); i++ ) // first in lessons is <no lesson> !
134 lessonlist->insertItem (m_lessons->text(i));
136 // limits and threshholds (the five comboboxes on the right)
137 gradelist->clear();
138 for (int i = 1; i <= KV_MAX_GRADE; i++)
139 gradelist->insertItem (m_queryManager->gradeStr(i));
141 typelist->clear();
142 all_maintypes = QueryManager::getRelation(true); // collect main types
143 for (int i = 0; i < (int) all_maintypes.size(); i++)
144 typelist->insertItem (all_maintypes[i].longStr());
146 badlist->clear();
147 querylist->clear();
148 for (int i; i <= 15; i++)
150 badlist->insertItem(QString::number(i));
151 querylist->insertItem(QString::number(i));
154 ref = Threshdate_itemlist;
155 datelist->clear();
156 while (ref->text != 0 )
158 datelist->insertItem (i18n(ref->text));
159 ref++;
162 //compare-functions (the lesson combobox and the five comboboxes on the left)
163 ct = less_complist;
164 lessoncomp->clear();
165 while (*ct != Prefs::EnumCompType::type(-1) )
167 lessoncomp->insertItem (m_queryManager->compStr(*ct));
168 ct++;
171 ct = type_complist;
172 typecomp->clear();
173 while (*ct != Prefs::EnumCompType::type(-1) )
175 typecomp->insertItem (m_queryManager->compStr(*ct));
176 ct++;
179 ct = query_complist;
180 querycomp->clear();
181 while (*ct != Prefs::EnumCompType::type(-1) )
183 querycomp->insertItem (m_queryManager->compStr(*ct));
184 ct++;
187 ct = bad_complist;
188 badcomp->clear();
189 while (*ct != Prefs::EnumCompType::type(-1) ) {
190 badcomp->insertItem (m_queryManager->compStr(*ct));
191 ct++;
194 ct = grade_complist;
195 gradecomp->clear();
196 while (*ct != Prefs::EnumCompType::type(-1) ) {
197 gradecomp->insertItem (m_queryManager->compStr(*ct));
198 ct++;
201 ct = date_complist;
202 datecomp->clear();
203 while (*ct != Prefs::EnumCompType::type(-1) ) {
204 datecomp->insertItem (m_queryManager->compStr(*ct));
205 ct++;
209 void ThresholdOptions::updateWidgets()
211 int index = 0;
212 Prefs::EnumCompType::type *ct;
213 ThreshListRef *ref;
215 vector<int> sel = m_queryManager->lessonItems();
216 if (sel.size() != 0)
218 for (int i = 0; i < (int) sel.size(); i++)
220 if (sel[i] > 0 && sel[i]-1 < (int) lessonlist->count()) // 0 = not assigned lesson
222 lessonlist->setCurrentItem(sel[i]-1); // important with qt1.x!
223 lessonlist->setSelected(sel[i]-1, true);
228 gradelist->setCurrentItem(Prefs::gradeItem());
230 for (int i = 0; i < typelist->count(); i++)
232 if (Prefs::typeItem() == all_maintypes[i].shortStr())
233 index = i;
235 typelist->setCurrentItem(index);
237 badlist->setCurrentItem(Prefs::badItem());
238 querylist->setCurrentItem(Prefs::queryItem());
240 ref = Threshdate_itemlist;
241 while (ref->text != 0 ) {
242 if (Prefs::dateItem() == ref->num)
243 index = ref - Threshdate_itemlist;
244 ref++;
246 datelist->setCurrentItem(index);
248 //compare-functions (the lesson combobox and the five comboboxes on the left)
249 ct = less_complist;
250 while (*ct != Prefs::compType(Prefs::EnumType::Lesson))
251 ct++;
252 lessoncomp->setCurrentItem (ct - less_complist);
253 slotSetLessonComp(ct - less_complist);
255 ct = type_complist;
256 while (*ct != Prefs::compType(Prefs::EnumType::WordType))
257 ct++;
258 typecomp->setCurrentItem(ct - type_complist);
259 typelist->setEnabled(ct - type_complist != 0); // don`t care == 0
261 ct = query_complist;
262 while (*ct != Prefs::compType(Prefs::EnumType::Query))
263 ct++;
264 querycomp->setCurrentItem (ct - query_complist);
265 querylist->setEnabled(ct - query_complist != 0); // don`t care == 0
267 ct = bad_complist;
268 while (*ct != Prefs::compType(Prefs::EnumType::Bad))
269 ct++;
270 badcomp->setCurrentItem(ct - bad_complist);
271 badlist->setEnabled(ct - bad_complist != 0); // don`t care == 0
273 ct = grade_complist;
274 while (*ct != Prefs::compType(Prefs::EnumType::Grade))
275 ct++;
276 gradecomp->setCurrentItem (ct - grade_complist);
277 gradelist->setEnabled(ct - grade_complist != 0); // don`t care == 0
279 ct = date_complist;
280 while (*ct != Prefs::compType(Prefs::EnumType::Date))
281 ct++;
282 datecomp->setCurrentItem (ct - date_complist);
283 if (date_complist[ct - date_complist] == Prefs::EnumCompType::Before ||
284 date_complist[ct - date_complist] == Prefs::EnumCompType::Within)
285 datelist->setEnabled(true);
286 else
287 datelist->setEnabled(false);
290 void ThresholdOptions::slotSelectAll()
292 lessonlist->selectAll(true);
293 emit widgetModified();
296 void ThresholdOptions::slotSelectNone()
298 lessonlist->selectAll(false);
299 emit widgetModified();
303 void ThresholdOptions::slotComboActivated(int)
305 emit widgetModified();
309 void ThresholdOptions::slotSetGradeComp(int i)
311 gradelist->setEnabled(i != 0); // don`t care == 0
312 emit widgetModified();
315 void ThresholdOptions::slotSetBadComp(int i)
317 badlist->setEnabled(i != 0); // don`t care == 0
318 emit widgetModified();
321 void ThresholdOptions::slotSetQueryComp(int i)
323 querylist->setEnabled(i != 0); // don`t care == 0
324 emit widgetModified();
327 void ThresholdOptions::slotSetTypeComp(int i)
329 typelist->setEnabled(i != 0); // don`t care == 0
330 emit widgetModified();
333 void ThresholdOptions::slotSetLessonItems()
335 vector<int> sel;
336 int cnt = 0;
338 for (int i = 0; i < (int) lessonlist->count(); i++)
340 if (lessonlist->isSelected(i))
342 sel.push_back(i+1); // 0 = not assigned lesson
343 cnt++;
347 QString s;
348 s.setNum(cnt);
349 l_count->setText (s);
351 m_queryManager->setLessonItems(sel);
354 void ThresholdOptions::slotSetLessonComp(int i)
356 if (less_complist[i] == Prefs::EnumCompType::OneOf || less_complist[i] == Prefs::EnumCompType::NotOneOf)
358 lessonlist->setEnabled(true);
359 b_all_less->setEnabled(true);
360 b_none_less->setEnabled(true);
361 l_count->setEnabled(true);
362 l_lesson->setEnabled(true);
364 else
366 l_count->setEnabled(false);
367 lessonlist->setEnabled(false);
368 b_all_less->setEnabled(false);
369 b_none_less->setEnabled(false);
370 l_lesson->setEnabled(false);
373 if (i < 0)
374 return;
376 emit widgetModified();
379 void ThresholdOptions::slotSetDateComp(int i)
381 if (date_complist[i] == Prefs::EnumCompType::Before || date_complist[i] == Prefs::EnumCompType::Within)
382 datelist->setEnabled(true);
383 else
384 datelist->setEnabled(false);
385 emit widgetModified();
388 void ThresholdOptions::slotBlockExpire(bool block, bool expire)
390 bool enable = !(block | expire);
392 gradecomp->setEnabled(enable);
393 gradelist->setEnabled(enable && gradecomp->currentItem() != 0);
394 label_grade->setEnabled(enable);
396 datecomp->setEnabled(enable);
397 datelist->setEnabled(enable && datecomp->currentItem() != 0);
398 label_qdate->setEnabled(enable);
400 querycomp->setEnabled(enable);
401 querylist->setEnabled(enable && querycomp->currentItem() != 0);
402 label_qcount->setEnabled(enable);
404 badcomp->setEnabled(enable);
405 badlist->setEnabled(enable && badcomp->currentItem() != 0);
406 label_bcount->setEnabled(enable);
409 bool ThresholdOptions::isDefault()
411 return less_complist[lessoncomp->currentItem()] == Prefs::EnumCompType::Current &&
412 type_complist[typecomp->currentItem()] == Prefs::EnumCompType::DontCare &&
413 grade_complist[gradecomp->currentItem()] == Prefs::EnumCompType::DontCare &&
414 date_complist[datecomp->currentItem()] == Prefs::EnumCompType::DontCare &&
415 query_complist[querycomp->currentItem()] == Prefs::EnumCompType::DontCare &&
416 bad_complist[badcomp->currentItem()] == Prefs::EnumCompType::DontCare;
419 void ThresholdOptions::updateSettings()
421 Prefs::setCompType(Prefs::EnumType::Lesson, less_complist[lessoncomp->currentItem()]);
422 slotSetLessonItems();
423 Prefs::setCompType(Prefs::EnumType::WordType, type_complist[typecomp->currentItem()]);
424 Prefs::setTypeItem(all_maintypes[typelist->currentItem()].shortStr());
425 Prefs::setCompType(Prefs::EnumType::Grade, grade_complist[gradecomp->currentItem()]);
426 Prefs::setGradeItem(gradelist->currentItem() + 1);
427 Prefs::setCompType(Prefs::EnumType::Query, query_complist[querycomp->currentItem()]);
428 Prefs::setQueryItem(querylist->currentItem());
429 Prefs::setCompType(Prefs::EnumType::Bad, bad_complist[badcomp->currentItem()]);
430 Prefs::setBadItem(badlist->currentItem());
431 Prefs::setCompType(Prefs::EnumType::Date, date_complist[datecomp->currentItem()]);
432 Prefs::setDateItem(Threshdate_itemlist[datelist->currentItem()].num);
435 bool ThresholdOptions::hasChanged()
437 return less_complist[lessoncomp->currentItem()] != Prefs::compType(Prefs::EnumType::Lesson) ||
438 type_complist[typecomp->currentItem()] != Prefs::compType(Prefs::EnumType::WordType) ||
439 grade_complist[gradecomp->currentItem()] != Prefs::compType(Prefs::EnumType::Grade) ||
440 query_complist[querycomp->currentItem()] != Prefs::compType(Prefs::EnumType::Query) ||
441 bad_complist[badcomp->currentItem()] != Prefs::compType(Prefs::EnumType::Bad) ||
442 date_complist[datecomp->currentItem()] != Prefs::compType(Prefs::EnumType::Date) ||
443 all_maintypes[typelist->currentItem()].shortStr() != Prefs::typeItem() ||
444 gradelist->currentItem() + 1 != Prefs::gradeItem() ||
445 querylist->currentItem() != Prefs::queryItem() ||
446 badlist->currentItem() != Prefs::badItem() ||
447 Threshdate_itemlist[datelist->currentItem()].num != Prefs::dateItem();
450 #include "thresholdoptions.moc"