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
@@ -765,104 +765,109 @@ void KDateTable::virtual_hook( int, void* )
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
@@ -912,28 +917,28 @@ KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e)
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}