summaryrefslogtreecommitdiffabout
path: root/microkde/kdatepickernew.cpp
Unidiff
Diffstat (limited to 'microkde/kdatepickernew.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdatepickernew.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/microkde/kdatepickernew.cpp b/microkde/kdatepickernew.cpp
index f60a422..8f8001e 100644
--- a/microkde/kdatepickernew.cpp
+++ b/microkde/kdatepickernew.cpp
@@ -188,257 +188,257 @@ KDatePicker::resizeEvent(QResizeEvent* e)
188 QWidget::resizeEvent(e); 188 QWidget::resizeEvent(e);
189} 189}
190 190
191void 191void
192KDatePicker::dateChangedSlot(QDate date) 192KDatePicker::dateChangedSlot(QDate date)
193{ 193{
194 kdDebug(298) << "KDatePicker::dateChangedSlot: date changed (" << date.year() << "/" << date.month() << "/" << date.day() << ")." << endl; 194 kdDebug(298) << "KDatePicker::dateChangedSlot: date changed (" << date.year() << "/" << date.month() << "/" << date.day() << ")." << endl;
195 195
196 const KCalendarSystem * calendar = KGlobal::locale()->calendar(); 196 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
197 197
198 line->setText(KGlobal::locale()->formatDate(date, true)); 198 line->setText(KGlobal::locale()->formatDate(date, true));
199 selectMonth->setText(calendar->monthName(date, false)); 199 selectMonth->setText(calendar->monthName(date, false));
200 fillWeeksCombo(date); 200 fillWeeksCombo(date);
201 d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1); 201 d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1);
202 selectYear->setText(calendar->yearString(date, false)); 202 selectYear->setText(calendar->yearString(date, false));
203 203
204 emit(dateChanged(date)); 204 emit(dateChanged(date));
205} 205}
206 206
207void 207void
208KDatePicker::tableClickedSlot() 208KDatePicker::tableClickedSlot()
209{ 209{
210 kdDebug(298) << "KDatePicker::tableClickedSlot: table clicked." << endl; 210 kdDebug(298) << "KDatePicker::tableClickedSlot: table clicked." << endl;
211 emit(dateSelected(table->getDate())); 211 emit(dateSelected(table->getDate()));
212 emit(tableClicked()); 212 emit(tableClicked());
213} 213}
214 214
215const QDate& 215const QDate&
216KDatePicker::getDate() const 216KDatePicker::getDate() const
217{ 217{
218 return table->getDate(); 218 return table->getDate();
219} 219}
220 220
221const QDate & 221const QDate &
222KDatePicker::date() const 222KDatePicker::date() const
223{ 223{
224 return table->getDate(); 224 return table->getDate();
225} 225}
226 226
227bool 227bool
228KDatePicker::setDate(const QDate& date) 228KDatePicker::setDate(const QDate& date)
229{ 229{
230 if(date.isValid()) 230 if(date.isValid())
231 { 231 {
232 const KCalendarSystem * calendar = KGlobal::locale()->calendar(); 232 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
233 233
234 table->setDate(date); 234 table->setDate(date);
235 fillWeeksCombo(date); 235 fillWeeksCombo(date);
236 d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1); 236 d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1);
237 selectMonth->setText(calendar->monthName(date, false)); 237 selectMonth->setText(calendar->monthName(date, false));
238 selectYear->setText(calendar->yearString(date, true)); 238 selectYear->setText(calendar->yearString(date, true));
239 line->setText(KGlobal::locale()->formatDate(date, true)); 239 line->setText(KGlobal::locale()->formatDate(date, true));
240 return true; 240 return true;
241 } 241 }
242 else 242 else
243 { 243 {
244 kdDebug(298) << "KDatePicker::setDate: refusing to set invalid date." << endl; 244 kdDebug(298) << "KDatePicker::setDate: refusing to set invalid date." << endl;
245 return false; 245 return false;
246 } 246 }
247} 247}
248 248
249void 249void
250KDatePicker::monthForwardClicked() 250KDatePicker::monthForwardClicked()
251{ 251{
252 QDate temp; 252 QDate temp;
253 temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), 1 ); 253 temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), 1 );
254 254
255 setDate( temp ); 255 setDate( temp );
256} 256}
257 257
258void 258void
259KDatePicker::monthBackwardClicked() 259KDatePicker::monthBackwardClicked()
260{ 260{
261 QDate temp; 261 QDate temp;
262 temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), -1 ); 262 temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), -1 );
263 263
264 setDate( temp ); 264 setDate( temp );
265} 265}
266 266
267void 267void
268KDatePicker::yearForwardClicked() 268KDatePicker::yearForwardClicked()
269{ 269{
270 QDate temp; 270 QDate temp;
271 temp = KGlobal::locale()->calendar()->addYears( table->getDate(), 1 ); 271 temp = KGlobal::locale()->calendar()->addYears( table->getDate(), 1 );
272 272
273 setDate( temp ); 273 setDate( temp );
274} 274}
275 275
276void 276void
277KDatePicker::yearBackwardClicked() 277KDatePicker::yearBackwardClicked()
278{ 278{
279 QDate temp; 279 QDate temp;
280 temp = KGlobal::locale()->calendar()->addYears( table->getDate(), -1 ); 280 temp = KGlobal::locale()->calendar()->addYears( table->getDate(), -1 );
281 281
282 setDate( temp ); 282 setDate( temp );
283} 283}
284 284
285void KDatePicker::selectWeekClicked() {} // ### in 3.2 obsolete; kept for binary compatibility 285void KDatePicker::selectWeekClicked() {} // ### in 3.2 obsolete; kept for binary compatibility
286 286
287void 287void
288KDatePicker::weekSelected(int week) 288KDatePicker::weekSelected(int week)
289{ 289{
290 week++; // week number starts with 1 290 week++; // week number starts with 1
291 291
292 const KCalendarSystem * calendar = KGlobal::locale()->calendar(); 292 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
293 293
294 QDate date = table->getDate(); 294 QDate date = table->getDate();
295 int year = calendar->year(date); 295 int year = calendar->year(date);
296 296
297 calendar->setYMD(date, year, 1, 1); 297 calendar->setYMD(date, year, 1, 1);
298 date = calendar->addDays(date, -7); 298 date = calendar->addDays(date, -7);
299 while (calendar->weekNumber(date) != 1) 299 while (calendar->weekNumber(date) != 1)
300 date = calendar->addDays(date, 1); 300 date = calendar->addDays(date, 1);
301 301
302 // date is now first day in week 1 some day in week 1 302 // date is now first day in week 1 some day in week 1
303 date = calendar->addDays(date, (week - calendar->weekNumber(date)) * 7); 303 date = calendar->addDays(date, (week - calendar->weekNumber(date)) * 7);
304 304
305 setDate(date); 305 setDate(date);
306} 306}
307 307
308void 308void
309KDatePicker::selectMonthClicked() 309KDatePicker::selectMonthClicked()
310{ 310{
311 // every year can have different month names (in some calendar systems) 311 // every year can have different month names (in some calendar systems)
312 const KCalendarSystem * calendar = KGlobal::locale()->calendar(); 312 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
313 QDate date = table->getDate(); 313 QDate date = table->getDate();
314 int i, month, months = calendar->monthsInYear(date); 314 int i, month, months = calendar->monthsInYear(date);
315 315
316 QPopupMenu popup(selectMonth); 316 Q3PopupMenu popup(selectMonth);
317 317
318 for (i = 1; i <= months; i++) 318 for (i = 1; i <= months; i++)
319 popup.insertItem(calendar->monthName(i, calendar->year(date)), i); 319 popup.insertItem(calendar->monthName(i, calendar->year(date)), i);
320 320
321 popup.setActiveItem(calendar->month(date) - 1); 321 popup.setActiveItem(calendar->month(date) - 1);
322 322
323 if ( (month = popup.exec(selectMonth->mapToGlobal(QPoint(0, 0)), calendar->month(date) - 1)) == -1 ) return; // canceled 323 if ( (month = popup.exec(selectMonth->mapToGlobal(QPoint(0, 0)), calendar->month(date) - 1)) == -1 ) return; // canceled
324 324
325 int day = calendar->day(date); 325 int day = calendar->day(date);
326 // ----- construct a valid date in this month: 326 // ----- construct a valid date in this month:
327 //date.setYMD(date.year(), month, 1); 327 //date.setYMD(date.year(), month, 1);
328 //date.setYMD(date.year(), month, QMIN(day, date.daysInMonth())); 328 //date.setYMD(date.year(), month, QMIN(day, date.daysInMonth()));
329 calendar->setYMD(date, calendar->year(date), month, 329 calendar->setYMD(date, calendar->year(date), month,
330 QMIN(day, calendar->daysInMonth(date))); 330 QMIN(day, calendar->daysInMonth(date)));
331 // ----- set this month 331 // ----- set this month
332 setDate(date); 332 setDate(date);
333} 333}
334 334
335void 335void
336KDatePicker::selectYearClicked() 336KDatePicker::selectYearClicked()
337{ 337{
338 const KCalendarSystem * calendar = KGlobal::locale()->calendar(); 338 const KCalendarSystem * calendar = KGlobal::locale()->calendar();
339 339
340 int year; 340 int year;
341 KPopupFrame* popup = new KPopupFrame(this); 341 KPopupFrame* popup = new KPopupFrame(this);
342 KDateInternalYearSelector* picker = new KDateInternalYearSelector(popup); 342 KDateInternalYearSelector* picker = new KDateInternalYearSelector(popup);
343 // ----- 343 // -----
344 picker->resize(picker->sizeHint()); 344 picker->resize(picker->sizeHint());
345 popup->setMainWidget(picker); 345 popup->setMainWidget(picker);
346 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 346 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
347 picker->setFocus(); 347 picker->setFocus();
348 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) 348 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height()))))
349 { 349 {
350 QDate date; 350 QDate date;
351 int day; 351 int day;
352 // ----- 352 // -----
353 year=picker->getYear(); 353 year=picker->getYear();
354 date=table->getDate(); 354 date=table->getDate();
355 day=calendar->day(date); 355 day=calendar->day(date);
356 // ----- construct a valid date in this month: 356 // ----- construct a valid date in this month:
357 //date.setYMD(year, date.month(), 1); 357 //date.setYMD(year, date.month(), 1);
358 //date.setYMD(year, date.month(), QMIN(day, date.daysInMonth())); 358 //date.setYMD(year, date.month(), QMIN(day, date.daysInMonth()));
359 calendar->setYMD(date, year, calendar->month(date), 359 calendar->setYMD(date, year, calendar->month(date),
360 QMIN(day, calendar->daysInMonth(date))); 360 QMIN(day, calendar->daysInMonth(date)));
361 // ----- set this month 361 // ----- set this month
362 setDate(date); 362 setDate(date);
363 } else { 363 } else {
364 KNotifyClient::beep(); 364 KNotifyClient::beep();
365 } 365 }
366 delete popup; 366 delete popup;
367} 367}
368 368
369void 369void
370KDatePicker::setEnabled(bool enable) 370KDatePicker::setEnabled(bool enable)
371{ 371{
372 QWidget *widgets[]= { 372 QWidget *widgets[]= {
373 yearForward, yearBackward, monthForward, monthBackward, 373 yearForward, yearBackward, monthForward, monthBackward,
374 selectMonth, selectYear, 374 selectMonth, selectYear,
375 line, table, d->selectWeek, d->todayButton }; 375 line, table, d->selectWeek, d->todayButton };
376 const int Size=sizeof(widgets)/sizeof(widgets[0]); 376 const int Size=sizeof(widgets)/sizeof(widgets[0]);
377 int count; 377 int count;
378 // ----- 378 // -----
379 for(count=0; count<Size; ++count) 379 for(count=0; count<Size; ++count)
380 { 380 {
381 widgets[count]->setEnabled(enable); 381 widgets[count]->setEnabled(enable);
382 } 382 }
383} 383}
384 384
385void 385void
386KDatePicker::lineEnterPressed() 386KDatePicker::lineEnterPressed()
387{ 387{
388 QDate temp; 388 QDate temp;
389 // ----- 389 // -----
390 if(val->date(line->text(), temp)==QValidator::Acceptable) 390 if(val->date(line->text(), temp)==QValidator::Acceptable)
391 { 391 {
392 kdDebug(298) << "KDatePicker::lineEnterPressed: valid date entered." << endl; 392 kdDebug(298) << "KDatePicker::lineEnterPressed: valid date entered." << endl;
393 emit(dateEntered(temp)); 393 emit(dateEntered(temp));
394 setDate(temp); 394 setDate(temp);
395 } else { 395 } else {
396 KNotifyClient::beep(); 396 KNotifyClient::beep();
397 kdDebug(298) << "KDatePicker::lineEnterPressed: invalid date entered." << endl; 397 kdDebug(298) << "KDatePicker::lineEnterPressed: invalid date entered." << endl;
398 } 398 }
399} 399}
400 400
401void 401void
402KDatePicker::todayButtonClicked() 402KDatePicker::todayButtonClicked()
403{ 403{
404 setDate(QDate::currentDate()); 404 setDate(QDate::currentDate());
405} 405}
406 406
407QSize 407QSize
408KDatePicker::sizeHint() const 408KDatePicker::sizeHint() const
409{ 409{
410 return QWidget::sizeHint(); 410 return QWidget::sizeHint();
411} 411}
412 412
413void 413void
414KDatePicker::setFontSize(int s) 414KDatePicker::setFontSize(int s)
415{ 415{
416 QWidget *buttons[]= { 416 QWidget *buttons[]= {
417 // yearBackward, 417 // yearBackward,
418 // monthBackward, 418 // monthBackward,
419 selectMonth, 419 selectMonth,
420 selectYear, 420 selectYear,
421 // monthForward, 421 // monthForward,
422 // yearForward 422 // yearForward
423 }; 423 };
424 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); 424 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
425 int count; 425 int count;
426 QFont font; 426 QFont font;
427 QRect r; 427 QRect r;
428 // ----- 428 // -----
429 fontsize=s; 429 fontsize=s;
430 for(count=0; count<NoOfButtons; ++count) 430 for(count=0; count<NoOfButtons; ++count)
431 { 431 {
432 font=buttons[count]->font(); 432 font=buttons[count]->font();
433 font.setPointSize(s); 433 font.setPointSize(s);
434 buttons[count]->setFont(font); 434 buttons[count]->setFont(font);
435 } 435 }
436 QFontMetrics metrics(selectMonth->fontMetrics()); 436 QFontMetrics metrics(selectMonth->fontMetrics());
437 437
438 for (int i = 1; ; ++i) 438 for (int i = 1; ; ++i)
439 { 439 {
440 QString str = KGlobal::locale()->calendar()->monthName(i, 440 QString str = KGlobal::locale()->calendar()->monthName(i,
441 KGlobal::locale()->calendar()->year(table->getDate()), false); 441 KGlobal::locale()->calendar()->year(table->getDate()), false);
442 if (str.isNull()) break; 442 if (str.isNull()) break;
443 r=metrics.boundingRect(str); 443 r=metrics.boundingRect(str);
444 maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); 444 maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width()));