summaryrefslogtreecommitdiffabout
path: root/microkde/kdatetbl.cpp
authorzautrix <zautrix>2005-01-22 10:18:16 (UTC)
committer zautrix <zautrix>2005-01-22 10:18:16 (UTC)
commit6946f6ab0ee6eeafee0c8ff5d33fffc0826c7452 (patch) (unidiff)
tree006248579ca44ad2e0c1a67db55b1a8013180ed7 /microkde/kdatetbl.cpp
parentb715b109b70b8cd24a2d9da1d4863c44d79fb2a4 (diff)
downloadkdepimpi-6946f6ab0ee6eeafee0c8ff5d33fffc0826c7452.zip
kdepimpi-6946f6ab0ee6eeafee0c8ff5d33fffc0826c7452.tar.gz
kdepimpi-6946f6ab0ee6eeafee0c8ff5d33fffc0826c7452.tar.bz2
some small fixes
Diffstat (limited to 'microkde/kdatetbl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdatetbl.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index 146291b..508ce31 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -283,140 +283,143 @@ KDateTable::keyPressEvent( QKeyEvent *e )
283void 283void
284KDateTable::viewportResizeEvent(QResizeEvent * e) 284KDateTable::viewportResizeEvent(QResizeEvent * e)
285{ 285{
286 QGridView::viewportResizeEvent(e); 286 QGridView::viewportResizeEvent(e);
287 287
288 setCellWidth(viewport()->width()/7); 288 setCellWidth(viewport()->width()/7);
289 setCellHeight(viewport()->height()/7); 289 setCellHeight(viewport()->height()/7);
290} 290}
291 291
292void 292void
293KDateTable::setFontSize(int size) 293KDateTable::setFontSize(int size)
294{ 294{
295 int count; 295 int count;
296 QRect rect; 296 QRect rect;
297 // ----- store rectangles: 297 // ----- store rectangles:
298 fontsize=size; 298 fontsize=size;
299 QFont font = KGlobalSettings::generalFont(); 299 QFont font = KGlobalSettings::generalFont();
300 font.setPointSize(fontsize); 300 font.setPointSize(fontsize);
301 font.setBold( true ); 301 font.setBold( true );
302 QFontMetrics metrics(font); 302 QFontMetrics metrics(font);
303 303
304 // ----- find largest day name: 304 // ----- find largest day name:
305 maxCell.setWidth(0); 305 maxCell.setWidth(0);
306 maxCell.setHeight(0); 306 maxCell.setHeight(0);
307 for(count=0; count<7; ++count) 307 for(count=0; count<7; ++count)
308 { 308 {
309 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); 309 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true));
310 maxCell.setWidth(QMAX(maxCell.width(), rect.width())); 310 maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
311 maxCell.setHeight(QMAX(maxCell.height(), rect.height())); 311 maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
312 } 312 }
313 // ----- compare with a real wide number and add some space: 313 // ----- compare with a real wide number and add some space:
314 rect=metrics.boundingRect(QString::fromLatin1("88")); 314 rect=metrics.boundingRect(QString::fromLatin1("88"));
315 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width())); 315 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
316 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height())); 316 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
317 if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) 317 if ( maxCell.width() * 1000 / maxCell.height() > 1900 )
318 maxCell.setHeight(maxCell.width() * 1000 / 1900 ); 318 maxCell.setHeight(maxCell.width() * 1000 / 1900 );
319} 319}
320 320
321void 321void
322KDateTable::contentsMousePressEvent(QMouseEvent *e) 322KDateTable::contentsMousePressEvent(QMouseEvent *e)
323{ 323{
324 if(e->type()!=QEvent::MouseButtonPress) 324 if(e->type()!=QEvent::MouseButtonPress)
325 { // the KDatePicker only reacts on mouse press events: 325 { // the KDatePicker only reacts on mouse press events:
326 return; 326 return;
327 } 327 }
328 if(!isEnabled()) 328 if(!isEnabled())
329 { 329 {
330 KNotifyClient::beep(); 330 KNotifyClient::beep();
331 return; 331 return;
332 } 332 }
333 333
334 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; 334 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
335 // ----- 335 // -----
336 int row, col, pos, temp; 336 int row, col, pos, temp;
337 QPoint mouseCoord; 337 QPoint mouseCoord;
338 // ----- 338 // -----
339 mouseCoord = e->pos(); 339 mouseCoord = e->pos();
340 row=rowAt(mouseCoord.y()); 340 row=rowAt(mouseCoord.y());
341 col=columnAt(mouseCoord.x()); 341 col=columnAt(mouseCoord.x());
342 if(row<0 || col<0) 342 if(row<0 || col<0)
343 { // the user clicked on the frame of the table 343 { // the user clicked on the frame of the table
344 return; 344 return;
345 } 345 }
346 pos=7*(row-1)+col+1; 346 pos=7*(row-1)+col+1;
347#if 0
347 if(pos+dayoff<=firstday) 348 if(pos+dayoff<=firstday)
348 { // this day is in the previous month 349 { // this day is in the previous month
349 KNotifyClient::beep(); 350 KNotifyClient::beep();
350 return; 351 return;
351 } 352 }
352 if(firstday+numdays<pos+dayoff) 353 if(firstday+numdays<pos+dayoff)
353 { // this date is in the next month 354 { // this date is in the next month
354 KNotifyClient::beep(); 355 KNotifyClient::beep();
355 return; 356 return;
356 } 357 }
358#endif
357 temp=firstday+date.day()-dayoff-1; 359 temp=firstday+date.day()-dayoff-1;
358 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); 360 QDate da = QDate(date.year(), date.month(),1);
361 setDate(da.addDays( pos-firstday+dayoff-1));
359 updateCell(temp/7+1, temp%7); // Update the previously selected cell 362 updateCell(temp/7+1, temp%7); // Update the previously selected cell
360 updateCell(row, col); // Update the selected cell 363 updateCell(row, col); // Update the selected cell
361 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 364 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
362 emit(tableClicked()); 365 emit(tableClicked());
363} 366}
364 367
365bool 368bool
366KDateTable::setDate(const QDate& date_) 369KDateTable::setDate(const QDate& date_)
367{ 370{
368 bool changed=false; 371 bool changed=false;
369 QDate temp; 372 QDate temp;
370 mMarkCurrent = false; 373 mMarkCurrent = false;
371 // ----- 374 // -----
372 if(!date_.isValid()) 375 if(!date_.isValid())
373 { 376 {
374 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; 377 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
375 return false; 378 return false;
376 } 379 }
377 if(date!=date_) 380 if(date!=date_)
378 { 381 {
379 date=date_; 382 date=date_;
380 changed=true; 383 changed=true;
381 } 384 }
382 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() ); 385 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() );
383 temp.setYMD(date.year(), date.month(), 1); 386 temp.setYMD(date.year(), date.month(), 1);
384 firstday=temp.dayOfWeek(); 387 firstday=temp.dayOfWeek();
385 if(firstday==1) firstday=8; 388 if(firstday==1) firstday=8;
386 numdays=date.daysInMonth(); 389 numdays=date.daysInMonth();
387 if(date.month()==1) 390 if(date.month()==1)
388 { // set to december of previous year 391 { // set to december of previous year
389 temp.setYMD(date.year()-1, 12, 1); 392 temp.setYMD(date.year()-1, 12, 1);
390 } else { // set to previous month 393 } else { // set to previous month
391 temp.setYMD(date.year(), date.month()-1, 1); 394 temp.setYMD(date.year(), date.month()-1, 1);
392 } 395 }
393 numDaysPrevMonth=temp.daysInMonth(); 396 numDaysPrevMonth=temp.daysInMonth();
394 if(changed) 397 if(changed)
395 { 398 {
396 repaintContents(false); 399 repaintContents(false);
397 } 400 }
398 emit(dateChanged(date)); 401 emit(dateChanged(date));
399 return true; 402 return true;
400} 403}
401 404
402const QDate& 405const QDate&
403KDateTable::getDate() const 406KDateTable::getDate() const
404{ 407{
405 return date; 408 return date;
406} 409}
407 410
408void KDateTable::focusInEvent( QFocusEvent *e ) 411void KDateTable::focusInEvent( QFocusEvent *e )
409{ 412{
410 repaintContents(false); 413 repaintContents(false);
411 QGridView::focusInEvent( e ); 414 QGridView::focusInEvent( e );
412} 415}
413 416
414void KDateTable::focusOutEvent( QFocusEvent *e ) 417void KDateTable::focusOutEvent( QFocusEvent *e )
415{ 418{
416 repaintContents(false); 419 repaintContents(false);
417 QGridView::focusOutEvent( e ); 420 QGridView::focusOutEvent( e );
418} 421}
419 422
420QSize 423QSize
421KDateTable::sizeHint() const 424KDateTable::sizeHint() const
422{ 425{