summaryrefslogtreecommitdiffabout
path: root/microkde/kdatetbl.cpp
Unidiff
Diffstat (limited to 'microkde/kdatetbl.cpp') (more/less context) (show whitespace changes)
-rw-r--r--microkde/kdatetbl.cpp165
1 files changed, 165 insertions, 0 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index 508ce31..fce0e5a 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -748,3 +748,168 @@ void KDateTable::virtual_hook( int, void* )
748{ /*BASE::virtual_hook( id, data );*/ } 748{ /*BASE::virtual_hook( id, data );*/ }
749 749
750//#include "kdatetbl.moc" 750//#include "kdatetbl.moc"
751
752
753KDateInternalWeekPicker::KDateInternalWeekPicker
754(int fontsize, QWidget* parent, const char* name)
755 : QGridView(parent, name),
756 result(0) // invalid
757{
758 QRect rect;
759 QFont font;
760 // -----
761 activeCol = -1;
762 activeRow = -1;
763 font=KGlobalSettings::generalFont();
764 font.setPointSize(fontsize);
765 setFont(font);
766 setHScrollBarMode(AlwaysOff);
767 setVScrollBarMode(AlwaysOff);
768 setFrameStyle(QFrame::NoFrame);
769 setNumRows(13);
770 setNumCols(4);
771 // enable to find drawing failures:
772 // setTableFlags(Tbl_clipCellPainting);
773#if 0
774 viewport()->setEraseColor(lightGray); // for consistency with the datepicker
775#endif
776 // ----- find the preferred size
777 // (this is slow, possibly, but unfortunatly it is needed here):
778 QFontMetrics metrics(font);
779 for(int i=1; i <= 52; ++i)
780 {
781 rect=metrics.boundingRect(QString::number( i ));
782 if(max.width()<rect.width()) max.setWidth(rect.width());
783 if(max.height()<rect.height()) max.setHeight(rect.height());
784 }
785
786}
787
788QSize
789KDateInternalWeekPicker::sizeHint() const
790{
791 return QSize((max.width()+6)*numCols()+2*frameWidth(),
792 (max.height()+6)*numRows()+2*frameWidth());
793}
794
795int
796KDateInternalWeekPicker::getResult() const
797{
798 return result;
799}
800
801void
802KDateInternalWeekPicker::setupPainter(QPainter *p)
803{
804 p->setPen(black);
805}
806
807void
808KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*)
809{
810 setCellWidth(width()/4);
811 setCellHeight(height()/13);
812}
813
814void
815KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col)
816{
817 int index;
818 QString text;
819 // ----- find the number of the cell:
820 index=4*row+col+1;
821 text=QString::number( index );
822 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
823 if ( activeCol == col && activeRow == row )
824 painter->drawRect( 0, 0, cellWidth(), cellHeight() );
825}
826
827void
828KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e)
829{
830 if(!isEnabled() || e->button() != LeftButton)
831 {
832 KNotifyClient::beep();
833 return;
834 }
835 // -----
836 int row, col;
837 QPoint mouseCoord;
838 // -----
839 mouseCoord = e->pos();
840 row=rowAt(mouseCoord.y());
841 col=columnAt(mouseCoord.x());
842
843 if(row<0 || col<0)
844 { // the user clicked on the frame of the table
845 activeCol = -1;
846 activeRow = -1;
847 } else {
848 activeCol = col;
849 activeRow = row;
850 updateCell( row, col /*, false */ );
851 }
852}
853
854void
855KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e)
856{
857 if (e->state() & LeftButton)
858 {
859 int row, col;
860 QPoint mouseCoord;
861 // -----
862 mouseCoord = e->pos();
863 row=rowAt(mouseCoord.y());
864 col=columnAt(mouseCoord.x());
865 int tmpRow = -1, tmpCol = -1;
866 if(row<0 || col<0)
867 { // the user clicked on the frame of the table
868 if ( activeCol > -1 )
869 {
870 tmpRow = activeRow;
871 tmpCol = activeCol;
872 }
873 activeCol = -1;
874 activeRow = -1;
875 } else {
876 bool differentCell = (activeRow != row || activeCol != col);
877 if ( activeCol > -1 && differentCell)
878 {
879 tmpRow = activeRow;
880 tmpCol = activeCol;
881 }
882 if ( differentCell)
883 {
884 activeRow = row;
885 activeCol = col;
886 updateCell( row, col /*, false */ ); // mark the new active cell
887 }
888 }
889 if ( tmpRow > -1 ) // repaint the former active cell
890 updateCell( tmpRow, tmpCol /*, true */ );
891 }
892}
893
894void
895KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e)
896{
897 if(!isEnabled())
898 {
899 return;
900 }
901 // -----
902 int row, col, pos;
903 QPoint mouseCoord;
904 // -----
905 mouseCoord = e->pos();
906 row=rowAt(mouseCoord.y());
907 col=columnAt(mouseCoord.x());
908 if(row<0 || col<0)
909 { // the user clicked on the frame of the table
910 emit(closeMe(0));
911 }
912 pos=4*row+col+1;
913 result=pos;
914 emit(closeMe(1));
915}