author | zautrix <zautrix> | 2005-04-30 07:32:03 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-30 07:32:03 (UTC) |
commit | 7c31102a00920834ab8e3778f0f459b96b2fb309 (patch) (unidiff) | |
tree | 9f238caaaab4ba150e4f14708d85162af0ea5092 /microkde/kdatetbl.cpp | |
parent | bdaded2da25b0ccef80d6e638fa12f92a4f8744d (diff) | |
download | kdepimpi-7c31102a00920834ab8e3778f0f459b96b2fb309.zip kdepimpi-7c31102a00920834ab8e3778f0f459b96b2fb309.tar.gz kdepimpi-7c31102a00920834ab8e3778f0f459b96b2fb309.tar.bz2 |
fixes
-rw-r--r-- | microkde/kdatetbl.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp index 2d97c8c..4271b55 100644 --- a/microkde/kdatetbl.cpp +++ b/microkde/kdatetbl.cpp | |||
@@ -405,535 +405,540 @@ KDateTable::setDate(const QDate& date_) | |||
405 | } | 405 | } |
406 | numDaysPrevMonth=temp.daysInMonth(); | 406 | numDaysPrevMonth=temp.daysInMonth(); |
407 | if(changed) | 407 | if(changed) |
408 | { | 408 | { |
409 | repaintContents(false); | 409 | repaintContents(false); |
410 | } | 410 | } |
411 | emit(dateChanged(date)); | 411 | emit(dateChanged(date)); |
412 | return true; | 412 | return true; |
413 | } | 413 | } |
414 | 414 | ||
415 | const QDate& | 415 | const QDate& |
416 | KDateTable::getDate() const | 416 | KDateTable::getDate() const |
417 | { | 417 | { |
418 | return date; | 418 | return date; |
419 | } | 419 | } |
420 | 420 | ||
421 | void KDateTable::focusInEvent( QFocusEvent *e ) | 421 | void KDateTable::focusInEvent( QFocusEvent *e ) |
422 | { | 422 | { |
423 | repaintContents(false); | 423 | repaintContents(false); |
424 | QGridView::focusInEvent( e ); | 424 | QGridView::focusInEvent( e ); |
425 | } | 425 | } |
426 | 426 | ||
427 | void KDateTable::focusOutEvent( QFocusEvent *e ) | 427 | void KDateTable::focusOutEvent( QFocusEvent *e ) |
428 | { | 428 | { |
429 | repaintContents(false); | 429 | repaintContents(false); |
430 | QGridView::focusOutEvent( e ); | 430 | QGridView::focusOutEvent( e ); |
431 | } | 431 | } |
432 | 432 | ||
433 | QSize | 433 | QSize |
434 | KDateTable::sizeHint() const | 434 | KDateTable::sizeHint() const |
435 | { | 435 | { |
436 | if(maxCell.height()>0 && maxCell.width()>0) | 436 | if(maxCell.height()>0 && maxCell.width()>0) |
437 | { | 437 | { |
438 | return QSize((maxCell.width()+2)*numCols()+2*frameWidth(), | 438 | return QSize((maxCell.width()+2)*numCols()+2*frameWidth(), |
439 | (maxCell.height()+4)*numRows()+2*frameWidth()); | 439 | (maxCell.height()+4)*numRows()+2*frameWidth()); |
440 | } else { | 440 | } else { |
441 | return QSize(-1, -1); | 441 | return QSize(-1, -1); |
442 | } | 442 | } |
443 | } | 443 | } |
444 | 444 | ||
445 | KDateInternalMonthPicker::KDateInternalMonthPicker | 445 | KDateInternalMonthPicker::KDateInternalMonthPicker |
446 | (QWidget* parent, const char* name) | 446 | (QWidget* parent, const char* name) |
447 | : QGridView(parent, name), | 447 | : QGridView(parent, name), |
448 | result(0) // invalid | 448 | result(0) // invalid |
449 | { | 449 | { |
450 | QRect rect; | 450 | QRect rect; |
451 | QFont font; | 451 | QFont font; |
452 | // ----- | 452 | // ----- |
453 | activeCol = -1; | 453 | activeCol = -1; |
454 | activeRow = -1; | 454 | activeRow = -1; |
455 | font=KGlobalSettings::generalFont(); | 455 | font=KGlobalSettings::generalFont(); |
456 | int fontsize = 10; | 456 | int fontsize = 10; |
457 | int add = 2; | 457 | int add = 2; |
458 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) | 458 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) |
459 | add += 8; | 459 | add += 8; |
460 | if ( QApplication::desktop()->width() > 640 ) | 460 | if ( QApplication::desktop()->width() > 640 ) |
461 | add += 6; | 461 | add += 6; |
462 | font.setPointSize(fontsize+add); | 462 | font.setPointSize(fontsize+add); |
463 | setFont(font); | 463 | setFont(font); |
464 | setHScrollBarMode(AlwaysOff); | 464 | setHScrollBarMode(AlwaysOff); |
465 | setVScrollBarMode(AlwaysOff); | 465 | setVScrollBarMode(AlwaysOff); |
466 | setFrameStyle(QFrame::NoFrame); | 466 | setFrameStyle(QFrame::NoFrame); |
467 | setNumRows(4); | 467 | setNumRows(4); |
468 | setNumCols(3); | 468 | setNumCols(3); |
469 | // enable to find drawing failures: | 469 | // enable to find drawing failures: |
470 | // setTableFlags(Tbl_clipCellPainting); | 470 | // setTableFlags(Tbl_clipCellPainting); |
471 | #if 0 | 471 | #if 0 |
472 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker | 472 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker |
473 | #endif | 473 | #endif |
474 | // ----- find the preferred size | 474 | // ----- find the preferred size |
475 | // (this is slow, possibly, but unfortunatly it is needed here): | 475 | // (this is slow, possibly, but unfortunatly it is needed here): |
476 | QFontMetrics metrics(font); | 476 | QFontMetrics metrics(font); |
477 | for(int i=1; i <= 12; ++i) | 477 | for(int i=1; i <= 12; ++i) |
478 | { | 478 | { |
479 | rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); | 479 | rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); |
480 | if(max.width()<rect.width()) max.setWidth(rect.width()); | 480 | if(max.width()<rect.width()) max.setWidth(rect.width()); |
481 | if(max.height()<rect.height()) max.setHeight(rect.height()); | 481 | if(max.height()<rect.height()) max.setHeight(rect.height()); |
482 | } | 482 | } |
483 | 483 | ||
484 | } | 484 | } |
485 | 485 | ||
486 | QSize | 486 | QSize |
487 | KDateInternalMonthPicker::sizeHint() const | 487 | KDateInternalMonthPicker::sizeHint() const |
488 | { | 488 | { |
489 | return QSize((max.width()+6)*numCols()+2*frameWidth(), | 489 | return QSize((max.width()+6)*numCols()+2*frameWidth(), |
490 | (max.height()+6)*numRows()+2*frameWidth()); | 490 | (max.height()+6)*numRows()+2*frameWidth()); |
491 | } | 491 | } |
492 | 492 | ||
493 | int | 493 | int |
494 | KDateInternalMonthPicker::getResult() const | 494 | KDateInternalMonthPicker::getResult() const |
495 | { | 495 | { |
496 | return result; | 496 | return result; |
497 | } | 497 | } |
498 | 498 | ||
499 | void | 499 | void |
500 | KDateInternalMonthPicker::setupPainter(QPainter *p) | 500 | KDateInternalMonthPicker::setupPainter(QPainter *p) |
501 | { | 501 | { |
502 | p->setPen(black); | 502 | p->setPen(black); |
503 | } | 503 | } |
504 | 504 | ||
505 | void | 505 | void |
506 | KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*) | 506 | KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*) |
507 | { | 507 | { |
508 | setCellWidth(width()/3); | 508 | setCellWidth(width()/3); |
509 | setCellHeight(height()/4); | 509 | setCellHeight(height()/4); |
510 | } | 510 | } |
511 | 511 | ||
512 | void | 512 | void |
513 | KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col) | 513 | KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col) |
514 | { | 514 | { |
515 | int index; | 515 | int index; |
516 | QString text; | 516 | QString text; |
517 | // ----- find the number of the cell: | 517 | // ----- find the number of the cell: |
518 | index=3*row+col+1; | 518 | index=3*row+col+1; |
519 | text=KGlobal::locale()->monthName(index, false); | 519 | text=KGlobal::locale()->monthName(index, false); |
520 | painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); | 520 | painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); |
521 | if ( activeCol == col && activeRow == row ) | 521 | if ( activeCol == col && activeRow == row ) |
522 | painter->drawRect( 0, 0, cellWidth(), cellHeight() ); | 522 | painter->drawRect( 0, 0, cellWidth(), cellHeight() ); |
523 | } | 523 | } |
524 | 524 | ||
525 | void | 525 | void |
526 | KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e) | 526 | KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e) |
527 | { | 527 | { |
528 | if(!isEnabled() || e->button() != LeftButton) | 528 | if(!isEnabled() || e->button() != LeftButton) |
529 | { | 529 | { |
530 | KNotifyClient::beep(); | 530 | KNotifyClient::beep(); |
531 | return; | 531 | return; |
532 | } | 532 | } |
533 | // ----- | 533 | // ----- |
534 | int row, col; | 534 | int row, col; |
535 | QPoint mouseCoord; | 535 | QPoint mouseCoord; |
536 | // ----- | 536 | // ----- |
537 | mouseCoord = e->pos(); | 537 | mouseCoord = e->pos(); |
538 | row=rowAt(mouseCoord.y()); | 538 | row=rowAt(mouseCoord.y()); |
539 | col=columnAt(mouseCoord.x()); | 539 | col=columnAt(mouseCoord.x()); |
540 | 540 | ||
541 | if(row<0 || col<0) | 541 | if(row<0 || col<0) |
542 | { // the user clicked on the frame of the table | 542 | { // the user clicked on the frame of the table |
543 | activeCol = -1; | 543 | activeCol = -1; |
544 | activeRow = -1; | 544 | activeRow = -1; |
545 | } else { | 545 | } else { |
546 | activeCol = col; | 546 | activeCol = col; |
547 | activeRow = row; | 547 | activeRow = row; |
548 | updateCell( row, col /*, false */ ); | 548 | updateCell( row, col /*, false */ ); |
549 | } | 549 | } |
550 | } | 550 | } |
551 | 551 | ||
552 | void | 552 | void |
553 | KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e) | 553 | KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e) |
554 | { | 554 | { |
555 | if (e->state() & LeftButton) | 555 | if (e->state() & LeftButton) |
556 | { | 556 | { |
557 | int row, col; | 557 | int row, col; |
558 | QPoint mouseCoord; | 558 | QPoint mouseCoord; |
559 | // ----- | 559 | // ----- |
560 | mouseCoord = e->pos(); | 560 | mouseCoord = e->pos(); |
561 | row=rowAt(mouseCoord.y()); | 561 | row=rowAt(mouseCoord.y()); |
562 | col=columnAt(mouseCoord.x()); | 562 | col=columnAt(mouseCoord.x()); |
563 | int tmpRow = -1, tmpCol = -1; | 563 | int tmpRow = -1, tmpCol = -1; |
564 | if(row<0 || col<0) | 564 | if(row<0 || col<0) |
565 | { // the user clicked on the frame of the table | 565 | { // the user clicked on the frame of the table |
566 | if ( activeCol > -1 ) | 566 | if ( activeCol > -1 ) |
567 | { | 567 | { |
568 | tmpRow = activeRow; | 568 | tmpRow = activeRow; |
569 | tmpCol = activeCol; | 569 | tmpCol = activeCol; |
570 | } | 570 | } |
571 | activeCol = -1; | 571 | activeCol = -1; |
572 | activeRow = -1; | 572 | activeRow = -1; |
573 | } else { | 573 | } else { |
574 | bool differentCell = (activeRow != row || activeCol != col); | 574 | bool differentCell = (activeRow != row || activeCol != col); |
575 | if ( activeCol > -1 && differentCell) | 575 | if ( activeCol > -1 && differentCell) |
576 | { | 576 | { |
577 | tmpRow = activeRow; | 577 | tmpRow = activeRow; |
578 | tmpCol = activeCol; | 578 | tmpCol = activeCol; |
579 | } | 579 | } |
580 | if ( differentCell) | 580 | if ( differentCell) |
581 | { | 581 | { |
582 | activeRow = row; | 582 | activeRow = row; |
583 | activeCol = col; | 583 | activeCol = col; |
584 | updateCell( row, col /*, false */ ); // mark the new active cell | 584 | updateCell( row, col /*, false */ ); // mark the new active cell |
585 | } | 585 | } |
586 | } | 586 | } |
587 | if ( tmpRow > -1 ) // repaint the former active cell | 587 | if ( tmpRow > -1 ) // repaint the former active cell |
588 | updateCell( tmpRow, tmpCol /*, true */ ); | 588 | updateCell( tmpRow, tmpCol /*, true */ ); |
589 | } | 589 | } |
590 | } | 590 | } |
591 | 591 | ||
592 | void | 592 | void |
593 | KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e) | 593 | KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e) |
594 | { | 594 | { |
595 | if(!isEnabled()) | 595 | if(!isEnabled()) |
596 | { | 596 | { |
597 | return; | 597 | return; |
598 | } | 598 | } |
599 | // ----- | 599 | // ----- |
600 | int row, col, pos; | 600 | int row, col, pos; |
601 | QPoint mouseCoord; | 601 | QPoint mouseCoord; |
602 | // ----- | 602 | // ----- |
603 | mouseCoord = e->pos(); | 603 | mouseCoord = e->pos(); |
604 | row=rowAt(mouseCoord.y()); | 604 | row=rowAt(mouseCoord.y()); |
605 | col=columnAt(mouseCoord.x()); | 605 | col=columnAt(mouseCoord.x()); |
606 | if(row<0 || col<0) | 606 | if(row<0 || col<0) |
607 | { // the user clicked on the frame of the table | 607 | { // the user clicked on the frame of the table |
608 | emit(closeMe(0)); | 608 | emit(closeMe(0)); |
609 | } | 609 | } |
610 | pos=3*row+col+1; | 610 | pos=3*row+col+1; |
611 | result=pos; | 611 | result=pos; |
612 | emit(closeMe(1)); | 612 | emit(closeMe(1)); |
613 | } | 613 | } |
614 | 614 | ||
615 | 615 | ||
616 | 616 | ||
617 | KDateInternalYearSelector::KDateInternalYearSelector | 617 | KDateInternalYearSelector::KDateInternalYearSelector |
618 | (int fontsize, QWidget* parent, const char* name) | 618 | (int fontsize, QWidget* parent, const char* name) |
619 | : QLineEdit(parent, name), | 619 | : QLineEdit(parent, name), |
620 | val(new QIntValidator(this)), | 620 | val(new QIntValidator(this)), |
621 | result(0) | 621 | result(0) |
622 | { | 622 | { |
623 | QFont font; | 623 | QFont font; |
624 | // ----- | 624 | // ----- |
625 | font=KGlobalSettings::generalFont(); | 625 | font=KGlobalSettings::generalFont(); |
626 | font.setPointSize(fontsize); | 626 | font.setPointSize(fontsize); |
627 | setFont(font); | 627 | setFont(font); |
628 | #if 0 | 628 | #if 0 |
629 | setFrameStyle(QFrame::NoFrame); | 629 | setFrameStyle(QFrame::NoFrame); |
630 | #endif | 630 | #endif |
631 | // we have to respect the limits of QDate here, I fear: | 631 | // we have to respect the limits of QDate here, I fear: |
632 | val->setRange(0, 8000); | 632 | val->setRange(0, 8000); |
633 | setValidator(val); | 633 | setValidator(val); |
634 | connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot())); | 634 | connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot())); |
635 | } | 635 | } |
636 | 636 | ||
637 | void | 637 | void |
638 | KDateInternalYearSelector::yearEnteredSlot() | 638 | KDateInternalYearSelector::yearEnteredSlot() |
639 | { | 639 | { |
640 | bool ok; | 640 | bool ok; |
641 | int year; | 641 | int year; |
642 | QDate date; | 642 | QDate date; |
643 | // ----- check if this is a valid year: | 643 | // ----- check if this is a valid year: |
644 | year=text().toInt(&ok); | 644 | year=text().toInt(&ok); |
645 | if(!ok) | 645 | if(!ok) |
646 | { | 646 | { |
647 | KNotifyClient::beep(); | 647 | KNotifyClient::beep(); |
648 | return; | 648 | return; |
649 | } | 649 | } |
650 | date.setYMD(year, 1, 1); | 650 | date.setYMD(year, 1, 1); |
651 | if(!date.isValid()) | 651 | if(!date.isValid()) |
652 | { | 652 | { |
653 | KNotifyClient::beep(); | 653 | KNotifyClient::beep(); |
654 | return; | 654 | return; |
655 | } | 655 | } |
656 | result=year; | 656 | result=year; |
657 | emit(closeMe(1)); | 657 | emit(closeMe(1)); |
658 | } | 658 | } |
659 | 659 | ||
660 | int | 660 | int |
661 | KDateInternalYearSelector::getYear() | 661 | KDateInternalYearSelector::getYear() |
662 | { | 662 | { |
663 | return result; | 663 | return result; |
664 | } | 664 | } |
665 | 665 | ||
666 | void | 666 | void |
667 | KDateInternalYearSelector::setYear(int year) | 667 | KDateInternalYearSelector::setYear(int year) |
668 | { | 668 | { |
669 | QString temp; | 669 | QString temp; |
670 | // ----- | 670 | // ----- |
671 | temp.setNum(year); | 671 | temp.setNum(year); |
672 | setText(temp); | 672 | setText(temp); |
673 | } | 673 | } |
674 | 674 | ||
675 | KPopupFrame::KPopupFrame(QWidget* parent, const char* name) | 675 | KPopupFrame::KPopupFrame(QWidget* parent, const char* name) |
676 | : QFrame(parent, name, WType_Popup), | 676 | : QFrame(parent, name, WType_Popup), |
677 | result(0), // rejected | 677 | result(0), // rejected |
678 | main(0) | 678 | main(0) |
679 | { | 679 | { |
680 | setFrameStyle(QFrame::Box|QFrame::Raised); | 680 | setFrameStyle(QFrame::Box|QFrame::Raised); |
681 | setMidLineWidth(2); | 681 | setMidLineWidth(2); |
682 | } | 682 | } |
683 | 683 | ||
684 | void | 684 | void |
685 | KPopupFrame::keyPressEvent(QKeyEvent* e) | 685 | KPopupFrame::keyPressEvent(QKeyEvent* e) |
686 | { | 686 | { |
687 | if(e->key()==Key_Escape) | 687 | if(e->key()==Key_Escape) |
688 | { | 688 | { |
689 | result=0; // rejected | 689 | result=0; // rejected |
690 | qApp->exit_loop(); | 690 | qApp->exit_loop(); |
691 | } | 691 | } |
692 | } | 692 | } |
693 | 693 | ||
694 | void | 694 | void |
695 | KPopupFrame::close(int r) | 695 | KPopupFrame::close(int r) |
696 | { | 696 | { |
697 | result=r; | 697 | result=r; |
698 | qApp->exit_loop(); | 698 | qApp->exit_loop(); |
699 | } | 699 | } |
700 | 700 | ||
701 | void | 701 | void |
702 | KPopupFrame::setMainWidget(QWidget* m) | 702 | KPopupFrame::setMainWidget(QWidget* m) |
703 | { | 703 | { |
704 | main=m; | 704 | main=m; |
705 | if(main!=0) | 705 | if(main!=0) |
706 | { | 706 | { |
707 | resize(main->width()+2*frameWidth(), main->height()+2*frameWidth()); | 707 | resize(main->width()+2*frameWidth(), main->height()+2*frameWidth()); |
708 | } | 708 | } |
709 | } | 709 | } |
710 | 710 | ||
711 | void | 711 | void |
712 | KPopupFrame::resizeEvent(QResizeEvent*) | 712 | KPopupFrame::resizeEvent(QResizeEvent*) |
713 | { | 713 | { |
714 | if(main!=0) | 714 | if(main!=0) |
715 | { | 715 | { |
716 | main->setGeometry(frameWidth(), frameWidth(), | 716 | main->setGeometry(frameWidth(), frameWidth(), |
717 | width()-2*frameWidth(), height()-2*frameWidth()); | 717 | width()-2*frameWidth(), height()-2*frameWidth()); |
718 | } | 718 | } |
719 | } | 719 | } |
720 | 720 | ||
721 | void | 721 | void |
722 | KPopupFrame::popup(const QPoint &pos) | 722 | KPopupFrame::popup(const QPoint &pos) |
723 | { | 723 | { |
724 | // Make sure the whole popup is visible. | 724 | // Make sure the whole popup is visible. |
725 | QRect d = QApplication::desktop()->frameGeometry(); | 725 | QRect d = QApplication::desktop()->frameGeometry(); |
726 | int x = pos.x(); | 726 | int x = pos.x(); |
727 | int y = pos.y(); | 727 | int y = pos.y(); |
728 | int w = width(); | 728 | int w = width(); |
729 | int h = height(); | 729 | int h = height(); |
730 | if (x+w > d.x()+d.width()) | 730 | if (x+w > d.x()+d.width()) |
731 | x = d.width() - w; | 731 | x = d.width() - w; |
732 | if (y+h > d.y()+d.height()) | 732 | if (y+h > d.y()+d.height()) |
733 | y = d.height() - h; | 733 | y = d.height() - h; |
734 | if (x < d.x()) | 734 | if (x < d.x()) |
735 | x = 0; | 735 | x = 0; |
736 | if (y < d.y()) | 736 | if (y < d.y()) |
737 | y = 0; | 737 | y = 0; |
738 | 738 | ||
739 | // Pop the thingy up. | 739 | // Pop the thingy up. |
740 | move(x, y); | 740 | move(x, y); |
741 | show(); | 741 | show(); |
742 | } | 742 | } |
743 | 743 | ||
744 | int | 744 | int |
745 | KPopupFrame::exec(QPoint pos) | 745 | KPopupFrame::exec(QPoint pos) |
746 | { | 746 | { |
747 | popup(pos); | 747 | popup(pos); |
748 | repaint(); | 748 | repaint(); |
749 | qApp->enter_loop(); | 749 | qApp->enter_loop(); |
750 | hide(); | 750 | hide(); |
751 | return result; | 751 | return result; |
752 | } | 752 | } |
753 | 753 | ||
754 | int | 754 | int |
755 | KPopupFrame::exec(int x, int y) | 755 | KPopupFrame::exec(int x, int y) |
756 | { | 756 | { |
757 | return exec(QPoint(x, y)); | 757 | return exec(QPoint(x, y)); |
758 | } | 758 | } |
759 | 759 | ||
760 | void KPopupFrame::virtual_hook( int, void* ) | 760 | void KPopupFrame::virtual_hook( int, void* ) |
761 | { /*BASE::virtual_hook( id, data );*/ } | 761 | { /*BASE::virtual_hook( id, data );*/ } |
762 | 762 | ||
763 | void KDateTable::virtual_hook( int, void* ) | 763 | void KDateTable::virtual_hook( int, void* ) |
764 | { /*BASE::virtual_hook( id, data );*/ } | 764 | { /*BASE::virtual_hook( id, data );*/ } |
765 | 765 | ||
766 | //#include "kdatetbl.moc" | 766 | //#include "kdatetbl.moc" |
767 | 767 | ||
768 | 768 | ||
769 | KDateInternalWeekPicker::KDateInternalWeekPicker | 769 | KDateInternalWeekPicker::KDateInternalWeekPicker |
770 | (QWidget* parent, const char* name) | 770 | (QWidget* parent, const char* name) |
771 | : QGridView(parent, name), | 771 | : QGridView(parent, name), |
772 | result(0) // invalid | 772 | result(0) // invalid |
773 | { | 773 | { |
774 | QRect rect; | 774 | QRect rect; |
775 | QFont font; | 775 | QFont font; |
776 | // ----- | 776 | // ----- |
777 | activeCol = -1; | 777 | activeCol = -1; |
778 | activeRow = -1; | 778 | activeRow = -1; |
779 | font=KGlobalSettings::generalFont(); | 779 | font=KGlobalSettings::generalFont(); |
780 | int fontsize = 10; | 780 | int fontsize = 10; |
781 | int add = 2; | 781 | int add = 2; |
782 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) | 782 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) |
783 | add += 6; | 783 | add += 6; |
784 | font.setPointSize(fontsize+add); | 784 | font.setPointSize(fontsize+add); |
785 | setFont(font); | 785 | setFont(font); |
786 | setHScrollBarMode(AlwaysOff); | 786 | setHScrollBarMode(AlwaysOff); |
787 | setVScrollBarMode(AlwaysOff); | 787 | setVScrollBarMode(AlwaysOff); |
788 | setFrameStyle(QFrame::NoFrame); | 788 | setFrameStyle(QFrame::NoFrame); |
789 | setNumRows(13); | 789 | if ( QApplication::desktop()->height() > 240 ) { |
790 | setNumCols(4); | 790 | setNumRows(13); |
791 | setNumCols(4); | ||
792 | } else { | ||
793 | setNumRows(4); | ||
794 | setNumCols(13); | ||
795 | } | ||
791 | // enable to find drawing failures: | 796 | // enable to find drawing failures: |
792 | // setTableFlags(Tbl_clipCellPainting); | 797 | // setTableFlags(Tbl_clipCellPainting); |
793 | #if 0 | 798 | #if 0 |
794 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker | 799 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker |
795 | #endif | 800 | #endif |
796 | // ----- find the preferred size | 801 | // ----- find the preferred size |
797 | // (this is slow, possibly, but unfortunatly it is needed here): | 802 | // (this is slow, possibly, but unfortunatly it is needed here): |
798 | QFontMetrics metrics(font); | 803 | QFontMetrics metrics(font); |
799 | for(int i=1; i <= 52; ++i) | 804 | for(int i=1; i <= 52; ++i) |
800 | { | 805 | { |
801 | rect=metrics.boundingRect(QString::number( i )); | 806 | rect=metrics.boundingRect(QString::number( i )); |
802 | if(max.width()<rect.width()) max.setWidth(rect.width()); | 807 | if(max.width()<rect.width()) max.setWidth(rect.width()); |
803 | if(max.height()<rect.height()) max.setHeight(rect.height()); | 808 | if(max.height()<rect.height()) max.setHeight(rect.height()); |
804 | } | 809 | } |
805 | if ( QApplication::desktop()->width() > 640 ) { | 810 | if ( QApplication::desktop()->width() > 640 ) { |
806 | 811 | ||
807 | max.setWidth(max.width()+6); | 812 | max.setWidth(max.width()+6); |
808 | max.setHeight(max.height()+8); | 813 | max.setHeight(max.height()+8); |
809 | } | 814 | } |
810 | } | 815 | } |
811 | 816 | ||
812 | QSize | 817 | QSize |
813 | KDateInternalWeekPicker::sizeHint() const | 818 | KDateInternalWeekPicker::sizeHint() const |
814 | { | 819 | { |
815 | return QSize((max.width()+6)*numCols()+2*frameWidth(), | 820 | return QSize((max.width()+6)*numCols()+2*frameWidth(), |
816 | (max.height()+6)*numRows()+2*frameWidth()); | 821 | (max.height()+6)*numRows()+2*frameWidth()); |
817 | } | 822 | } |
818 | 823 | ||
819 | int | 824 | int |
820 | KDateInternalWeekPicker::getResult() const | 825 | KDateInternalWeekPicker::getResult() const |
821 | { | 826 | { |
822 | return result; | 827 | return result; |
823 | } | 828 | } |
824 | 829 | ||
825 | void | 830 | void |
826 | KDateInternalWeekPicker::setupPainter(QPainter *p) | 831 | KDateInternalWeekPicker::setupPainter(QPainter *p) |
827 | { | 832 | { |
828 | p->setPen(black); | 833 | p->setPen(black); |
829 | } | 834 | } |
830 | 835 | ||
831 | void | 836 | void |
832 | KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*) | 837 | KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*) |
833 | { | 838 | { |
834 | setCellWidth(width()/4); | 839 | setCellWidth(width()/ numCols()); |
835 | setCellHeight(height()/13); | 840 | setCellHeight(height()/ numRows()); |
836 | } | 841 | } |
837 | 842 | ||
838 | void | 843 | void |
839 | KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col) | 844 | KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col) |
840 | { | 845 | { |
841 | int index; | 846 | int index; |
842 | QString text; | 847 | QString text; |
843 | // ----- find the number of the cell: | 848 | // ----- find the number of the cell: |
844 | index=4*row+col+1; | 849 | index=numCols()*row+col+1; |
845 | text=QString::number( index ); | 850 | text=QString::number( index ); |
846 | painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); | 851 | painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); |
847 | if ( activeCol == col && activeRow == row ) | 852 | if ( activeCol == col && activeRow == row ) |
848 | painter->drawRect( 0, 0, cellWidth(), cellHeight() ); | 853 | painter->drawRect( 0, 0, cellWidth(), cellHeight() ); |
849 | } | 854 | } |
850 | 855 | ||
851 | void | 856 | void |
852 | KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e) | 857 | KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e) |
853 | { | 858 | { |
854 | if(!isEnabled() || e->button() != LeftButton) | 859 | if(!isEnabled() || e->button() != LeftButton) |
855 | { | 860 | { |
856 | KNotifyClient::beep(); | 861 | KNotifyClient::beep(); |
857 | return; | 862 | return; |
858 | } | 863 | } |
859 | // ----- | 864 | // ----- |
860 | int row, col; | 865 | int row, col; |
861 | QPoint mouseCoord; | 866 | QPoint mouseCoord; |
862 | // ----- | 867 | // ----- |
863 | mouseCoord = e->pos(); | 868 | mouseCoord = e->pos(); |
864 | row=rowAt(mouseCoord.y()); | 869 | row=rowAt(mouseCoord.y()); |
865 | col=columnAt(mouseCoord.x()); | 870 | col=columnAt(mouseCoord.x()); |
866 | 871 | ||
867 | if(row<0 || col<0) | 872 | if(row<0 || col<0) |
868 | { // the user clicked on the frame of the table | 873 | { // the user clicked on the frame of the table |
869 | activeCol = -1; | 874 | activeCol = -1; |
870 | activeRow = -1; | 875 | activeRow = -1; |
871 | } else { | 876 | } else { |
872 | activeCol = col; | 877 | activeCol = col; |
873 | activeRow = row; | 878 | activeRow = row; |
874 | updateCell( row, col /*, false */ ); | 879 | updateCell( row, col /*, false */ ); |
875 | } | 880 | } |
876 | } | 881 | } |
877 | 882 | ||
878 | void | 883 | void |
879 | KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e) | 884 | KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e) |
880 | { | 885 | { |
881 | if (e->state() & LeftButton) | 886 | if (e->state() & LeftButton) |
882 | { | 887 | { |
883 | int row, col; | 888 | int row, col; |
884 | QPoint mouseCoord; | 889 | QPoint mouseCoord; |
885 | // ----- | 890 | // ----- |
886 | mouseCoord = e->pos(); | 891 | mouseCoord = e->pos(); |
887 | row=rowAt(mouseCoord.y()); | 892 | row=rowAt(mouseCoord.y()); |
888 | col=columnAt(mouseCoord.x()); | 893 | col=columnAt(mouseCoord.x()); |
889 | int tmpRow = -1, tmpCol = -1; | 894 | int tmpRow = -1, tmpCol = -1; |
890 | if(row<0 || col<0) | 895 | if(row<0 || col<0) |
891 | { // the user clicked on the frame of the table | 896 | { // the user clicked on the frame of the table |
892 | if ( activeCol > -1 ) | 897 | if ( activeCol > -1 ) |
893 | { | 898 | { |
894 | tmpRow = activeRow; | 899 | tmpRow = activeRow; |
895 | tmpCol = activeCol; | 900 | tmpCol = activeCol; |
896 | } | 901 | } |
897 | activeCol = -1; | 902 | activeCol = -1; |
898 | activeRow = -1; | 903 | activeRow = -1; |
899 | } else { | 904 | } else { |
900 | bool differentCell = (activeRow != row || activeCol != col); | 905 | bool differentCell = (activeRow != row || activeCol != col); |
901 | if ( activeCol > -1 && differentCell) | 906 | if ( activeCol > -1 && differentCell) |
902 | { | 907 | { |
903 | tmpRow = activeRow; | 908 | tmpRow = activeRow; |
904 | tmpCol = activeCol; | 909 | tmpCol = activeCol; |
905 | } | 910 | } |
906 | if ( differentCell) | 911 | if ( differentCell) |
907 | { | 912 | { |
908 | activeRow = row; | 913 | activeRow = row; |
909 | activeCol = col; | 914 | activeCol = col; |
910 | updateCell( row, col /*, false */ ); // mark the new active cell | 915 | updateCell( row, col /*, false */ ); // mark the new active cell |
911 | } | 916 | } |
912 | } | 917 | } |
913 | if ( tmpRow > -1 ) // repaint the former active cell | 918 | if ( tmpRow > -1 ) // repaint the former active cell |
914 | updateCell( tmpRow, tmpCol /*, true */ ); | 919 | updateCell( tmpRow, tmpCol /*, true */ ); |
915 | } | 920 | } |
916 | } | 921 | } |
917 | 922 | ||
918 | void | 923 | void |
919 | KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e) | 924 | KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e) |
920 | { | 925 | { |
921 | if(!isEnabled()) | 926 | if(!isEnabled()) |
922 | { | 927 | { |
923 | return; | 928 | return; |
924 | } | 929 | } |
925 | // ----- | 930 | // ----- |
926 | int row, col, pos; | 931 | int row, col, pos; |
927 | QPoint mouseCoord; | 932 | QPoint mouseCoord; |
928 | // ----- | 933 | // ----- |
929 | mouseCoord = e->pos(); | 934 | mouseCoord = e->pos(); |
930 | row=rowAt(mouseCoord.y()); | 935 | row=rowAt(mouseCoord.y()); |
931 | col=columnAt(mouseCoord.x()); | 936 | col=columnAt(mouseCoord.x()); |
932 | if(row<0 || col<0) | 937 | if(row<0 || col<0) |
933 | { // the user clicked on the frame of the table | 938 | { // the user clicked on the frame of the table |
934 | emit(closeMe(0)); | 939 | emit(closeMe(0)); |
935 | } | 940 | } |
936 | pos=4*row+col+1; | 941 | pos=numCols()*row+col+1; |
937 | result=pos; | 942 | result=pos; |
938 | emit(closeMe(1)); | 943 | emit(closeMe(1)); |
939 | } | 944 | } |