summaryrefslogtreecommitdiffabout
path: root/microkde/kdatetbl.cpp
Unidiff
Diffstat (limited to 'microkde/kdatetbl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdatetbl.cpp17
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
@@ -693,247 +693,252 @@ KPopupFrame::keyPressEvent(QKeyEvent* e)
693 693
694void 694void
695KPopupFrame::close(int r) 695KPopupFrame::close(int r)
696{ 696{
697 result=r; 697 result=r;
698 qApp->exit_loop(); 698 qApp->exit_loop();
699} 699}
700 700
701void 701void
702KPopupFrame::setMainWidget(QWidget* m) 702KPopupFrame::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
711void 711void
712KPopupFrame::resizeEvent(QResizeEvent*) 712KPopupFrame::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
721void 721void
722KPopupFrame::popup(const QPoint &pos) 722KPopupFrame::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
744int 744int
745KPopupFrame::exec(QPoint pos) 745KPopupFrame::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
754int 754int
755KPopupFrame::exec(int x, int y) 755KPopupFrame::exec(int x, int y)
756{ 756{
757 return exec(QPoint(x, y)); 757 return exec(QPoint(x, y));
758} 758}
759 759
760void KPopupFrame::virtual_hook( int, void* ) 760void KPopupFrame::virtual_hook( int, void* )
761{ /*BASE::virtual_hook( id, data );*/ } 761{ /*BASE::virtual_hook( id, data );*/ }
762 762
763void KDateTable::virtual_hook( int, void* ) 763void 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
769KDateInternalWeekPicker::KDateInternalWeekPicker 769KDateInternalWeekPicker::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
812QSize 817QSize
813KDateInternalWeekPicker::sizeHint() const 818KDateInternalWeekPicker::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
819int 824int
820KDateInternalWeekPicker::getResult() const 825KDateInternalWeekPicker::getResult() const
821{ 826{
822 return result; 827 return result;
823} 828}
824 829
825void 830void
826KDateInternalWeekPicker::setupPainter(QPainter *p) 831KDateInternalWeekPicker::setupPainter(QPainter *p)
827{ 832{
828 p->setPen(black); 833 p->setPen(black);
829} 834}
830 835
831void 836void
832KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*) 837KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*)
833{ 838{
834 setCellWidth(width()/4); 839 setCellWidth(width()/ numCols());
835 setCellHeight(height()/13); 840 setCellHeight(height()/ numRows());
836} 841}
837 842
838void 843void
839KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col) 844KDateInternalWeekPicker::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
851void 856void
852KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e) 857KDateInternalWeekPicker::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
878void 883void
879KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e) 884KDateInternalWeekPicker::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
918void 923void
919KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e) 924KDateInternalWeekPicker::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}