moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kvoctrain / kvoctrain / entry-dialogs / FromToEntryPage.cpp
blob460c3d0bb7157ff1e588d7486cd1c0b2e017b058
1 /***************************************************************************
3 edit properties from/to original
5 -----------------------------------------------------------------------
7 begin : Mon Jun 28 21:02:16 1999
9 copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
10 (C) 2001 The KDE-EDU team
11 (C) 2005 Peter Hedlund <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 ***************************************************************************/
27 #include "FromToEntryPage.h"
28 #include "EntryDlg.h"
30 #include <qlineedit.h>
31 #include <qcombobox.h>
32 #include <qpushbutton.h>
33 #include <qgroupbox.h>
35 #include <klocale.h>
37 #include <QueryManager.h>
38 #include <langset.h>
40 #include "blockall.h"
41 #include "MySpinBox.h"
43 static QStringList monthnames;
45 FromToEntryPage::FromToEntryPage
47 EntryDlg *_dlgbook,
48 bool multi_sel,
49 grade_t _grade,
50 time_t _time,
51 count_t _qcount,
52 count_t _bcount,
53 QString faux,
54 QString label,
55 QWidget *parent,
56 const char *name
59 FromToEntryPageForm( parent, name ), fauxami(faux), dlgbook(_dlgbook)
61 monthnames.clear();
62 monthnames.append ("");
63 monthnames.append (i18n("January"));
64 monthnames.append (i18n("February"));
65 monthnames.append (i18n("March"));
66 monthnames.append (i18n("April"));
67 monthnames.append (i18n("May"));
68 monthnames.append (i18n("June"));
69 monthnames.append (i18n("July"));
70 monthnames.append (i18n("August"));
71 monthnames.append (i18n("September"));
72 monthnames.append (i18n("October"));
73 monthnames.append (i18n("November"));
74 monthnames.append (i18n("December"));
76 connect( bcount_line, SIGNAL(textChanged(const QString&)), SLOT(slotBCount(const QString&)) );
77 connect( qcount_line, SIGNAL(textChanged(const QString&)), SLOT(slotQCount(const QString&)) );
78 connect( fauxami_line, SIGNAL(textChanged(const QString&)), SLOT(slotFauxAmiSelected(const QString&)) );
80 connect( never, SIGNAL(clicked()), SLOT(slotNever()) );
81 connect( today, SIGNAL(clicked()), SLOT(slotToday()) );
82 connect( gradebox, SIGNAL(activated(int)), SLOT(slotGradeSelected(int)) );
84 connect( year_spin, SIGNAL(valueChanged(int)), SLOT(slotYearChanged(int)) );
85 connect( month_spin, SIGNAL(valueChanged(int)), SLOT(slotMonthChanged(int)) );
86 connect( day_spin, SIGNAL(valueChanged(int)), SLOT(slotDayChanged(int)) );
88 year_spin->setData ((QStringList *) 0, 1980, 2100);
89 month_spin->setData (&monthnames, 1, 12);
90 day_spin->setData ((QStringList *) 0, 1, 31);
92 QString s;
93 for (int i = 0; i <= KV_MAX_GRADE; i++) {
94 s.setNum (i);
95 gradebox->insertItem( QueryManager::gradeStr(i) );
97 gradebox->setValidator (new BlockAllValidator() );
99 setTabOrder(fauxami_line, year_spin);
100 setTabOrder(year_spin, month_spin);
101 setTabOrder(month_spin, day_spin);
102 setTabOrder(day_spin, today);
104 setData(multi_sel, _grade, _time, _qcount, _bcount, faux, label);
108 void FromToEntryPage::setData(
109 bool multi_sel,
110 grade_t _grade,
111 time_t _time,
112 count_t _qcount,
113 count_t _bcount,
114 QString faux,
115 QString label)
117 grade = _grade;
118 qcount = _qcount;
119 bcount = _bcount;
120 fauxami = faux;
121 fauxami_line->setText(fauxami);
123 valid_date = false;
124 QDateTime dt;
125 QDate date;
126 if (_time != 0 && !multi_sel) {
127 dt.setTime_t (_time);
128 valid_date = true;
130 date = dt.date();
131 year = date.year();
132 month = date.month();
133 day = date.day();
135 day_spin->setValue(day);
136 month_spin->setValue(month);
137 year_spin->setValue(year);
138 year_spin->setSpecial(QString::null);
139 month_spin->setSpecial(QString::null);
140 day_spin->setSpecial(QString::null);
142 else {
143 dt.setTime_t (time(0L));
144 date = dt.date();
145 year = date.year();
146 month = date.month();
147 day = date.day();
148 year_spin->setSpecial("----");
149 month_spin->setSpecial("----");
150 day_spin->setSpecial("--");
153 direc_label->setTitle (label);
155 gradebox->setCurrentItem (grade);
157 QString s;
158 s.setNum (qcount);
159 qcount_line->setText (s);
161 s.setNum (bcount);
162 bcount_line->setText (s);
164 if (multi_sel) {
165 fauxami_line->setEnabled(false);
166 valid_date = false;
167 bcount_line->setText ("");
168 qcount_line->setText ("");
169 month_spin->setSpecial(" ");
170 day_spin->setSpecial(" ");
171 // FIXME: possibly derive new combobox type
172 // which filters ALL charcters to prevent new input
173 // in edit field
174 gradebox->clearEdit();
177 bcount_dirty = false;
178 qcount_dirty = false;
179 date_dirty = false;
180 grade_dirty = false;
182 setModified(false);
186 void FromToEntryPage::slotFauxAmiSelected(const QString& s)
188 setModified(true);
189 fauxami = s;
193 void FromToEntryPage::slotGradeSelected (int g)
195 setModified(true);
196 grade_dirty = true;
197 grade = g;
201 void FromToEntryPage::slotQCount(const QString& s)
203 setModified(true);
204 qcount_dirty = true;
205 qcount = atoi (s.local8Bit());
209 void FromToEntryPage::slotBCount(const QString& s)
211 setModified(true);
212 bcount_dirty = true;
213 bcount = atoi (s.local8Bit());
217 time_t FromToEntryPage::getDate () const
219 // FIXME: warning dialog/don`t quit dialog when date invalid
220 if (valid_date) {
221 QDate act_date (year, month, day);
222 QDateTime time_null (QDate (1970, 1, 1), QTime (0,0,0));
223 return -QDateTime(act_date).secsTo (time_null);
225 else
226 return 0;
230 void FromToEntryPage::validate()
232 if (!valid_date) {
233 valid_date = true;
234 day_spin->setValue(day);
235 month_spin->setValue(month);
236 year_spin->setValue(year);
241 void FromToEntryPage::slotYearChanged(int new_year)
243 setModified(true);
244 date_dirty = true;
245 if (!valid_date) {
246 slotToday();
247 new_year = year;
250 year_spin->setSpecial(QString::null);
252 year = new_year;
253 validate();
257 void FromToEntryPage::slotDecYear()
259 setModified(true);
263 // FIXME: dec month when day decrease below 1
264 void FromToEntryPage::slotIncYear()
266 setModified(true);
270 void FromToEntryPage::slotMonthChanged(int new_month)
272 setModified(true);
273 date_dirty = true;
274 if (!valid_date) {
275 slotToday();
276 new_month = month;
279 month_spin->setSpecial(QString::null);
281 month = new_month;
282 validate();
286 void FromToEntryPage::slotDecMonth()
288 setModified(true);
292 void FromToEntryPage::slotIncMonth()
294 setModified(true);
298 void FromToEntryPage::slotDayChanged(int new_day)
300 setModified(true);
301 date_dirty = true;
302 if (!valid_date) {
303 slotToday();
304 new_day = day;
307 day_spin->setSpecial(QString::null);
309 day = new_day;
310 validate();
314 void FromToEntryPage::slotDecDay()
316 setModified(true);
320 void FromToEntryPage::slotIncDay()
322 setModified(true);
326 void FromToEntryPage::slotToday()
328 setModified(true);
329 date_dirty = true;
330 QDateTime dt;
331 dt.setTime_t (time(0L));
333 year = dt.date().year();
334 month = dt.date().month();
335 day = dt.date().day();
337 day_spin->setValue(day);
338 month_spin->setValue(month);
339 year_spin->setValue(year);
340 year_spin->setSpecial(QString::null);
341 month_spin->setSpecial(QString::null);
342 day_spin->setSpecial(QString::null);
343 validate();
347 void FromToEntryPage::slotNever()
349 setModified(true);
350 date_dirty = true;
351 year = 0;
352 month = 0;
353 day = 0;
354 year_spin->setSpecial("----");
355 month_spin->setSpecial("----");
356 day_spin->setSpecial("--");
357 valid_date = false;
361 bool FromToEntryPage::isModified()
363 return modified;
367 void FromToEntryPage::setEnabled(int enable)
369 bool ena = enable == EntryDlg::EnableAll;
371 bcount_line->setEnabled(ena);
372 qcount_line->setEnabled(ena);
373 fauxami_line->setEnabled(ena);
375 never->setEnabled(ena);
376 today->setEnabled(ena);
377 gradebox->setEnabled(ena);
379 year_spin->setEnabled(ena);
380 month_spin->setEnabled(ena);
381 day_spin->setEnabled(ena);
385 void FromToEntryPage::setModified(bool mod)
387 modified = mod;
388 if (mod)
389 emit sigModified();
392 #include "FromToEntryPage.moc"