-rw-r--r-- | microkde/kdatetbl.cpp | 165 | ||||
-rw-r--r-- | microkde/kdatetbl.h | 63 |
2 files changed, 228 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 | |||
753 | KDateInternalWeekPicker::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 | |||
788 | QSize | ||
789 | KDateInternalWeekPicker::sizeHint() const | ||
790 | { | ||
791 | return QSize((max.width()+6)*numCols()+2*frameWidth(), | ||
792 | (max.height()+6)*numRows()+2*frameWidth()); | ||
793 | } | ||
794 | |||
795 | int | ||
796 | KDateInternalWeekPicker::getResult() const | ||
797 | { | ||
798 | return result; | ||
799 | } | ||
800 | |||
801 | void | ||
802 | KDateInternalWeekPicker::setupPainter(QPainter *p) | ||
803 | { | ||
804 | p->setPen(black); | ||
805 | } | ||
806 | |||
807 | void | ||
808 | KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*) | ||
809 | { | ||
810 | setCellWidth(width()/4); | ||
811 | setCellHeight(height()/13); | ||
812 | } | ||
813 | |||
814 | void | ||
815 | KDateInternalWeekPicker::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 | |||
827 | void | ||
828 | KDateInternalWeekPicker::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 | |||
854 | void | ||
855 | KDateInternalWeekPicker::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 | |||
894 | void | ||
895 | KDateInternalWeekPicker::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 | } | ||
diff --git a/microkde/kdatetbl.h b/microkde/kdatetbl.h index b4d3e16..2efa532 100644 --- a/microkde/kdatetbl.h +++ b/microkde/kdatetbl.h | |||
@@ -307,3 +307,66 @@ private: | |||
307 | }; | 307 | }; |
308 | 308 | ||
309 | #endif // KDATETBL_H | 309 | #endif // KDATETBL_H |
310 | class KDateInternalWeekPicker : public QGridView | ||
311 | { | ||
312 | Q_OBJECT | ||
313 | protected: | ||
314 | /** | ||
315 | * Store the month that has been clicked [1..12]. | ||
316 | */ | ||
317 | int result; | ||
318 | /** | ||
319 | * the cell under mouse cursor when LBM is pressed | ||
320 | */ | ||
321 | short int activeCol; | ||
322 | short int activeRow; | ||
323 | /** | ||
324 | * Contains the largest rectangle needed by the month names. | ||
325 | */ | ||
326 | QRect max; | ||
327 | signals: | ||
328 | /** | ||
329 | * This is send from the mouse click event handler. | ||
330 | */ | ||
331 | void closeMe(int); | ||
332 | public: | ||
333 | /** | ||
334 | * The constructor. | ||
335 | */ | ||
336 | KDateInternalWeekPicker(int fontsize, QWidget* parent, const char* name=0); | ||
337 | /** | ||
338 | * The size hint. | ||
339 | */ | ||
340 | QSize sizeHint() const; | ||
341 | /** | ||
342 | * Return the result. 0 means no selection (reject()), 1..12 are the | ||
343 | * months. | ||
344 | */ | ||
345 | int getResult() const; | ||
346 | protected: | ||
347 | /** | ||
348 | * Set up the painter. | ||
349 | */ | ||
350 | void setupPainter(QPainter *p); | ||
351 | /** | ||
352 | * The resize event. | ||
353 | */ | ||
354 | void viewportResizeEvent(QResizeEvent*); | ||
355 | /** | ||
356 | * Paint a cell. This simply draws the month names in it. | ||
357 | */ | ||
358 | virtual void paintCell(QPainter* painter, int row, int col); | ||
359 | /** | ||
360 | * Catch mouse click and move events to paint a rectangle around the item. | ||
361 | */ | ||
362 | void contentsMousePressEvent(QMouseEvent *e); | ||
363 | void contentsMouseMoveEvent(QMouseEvent *e); | ||
364 | /** | ||
365 | * Emit monthSelected(int) when a cell has been released. | ||
366 | */ | ||
367 | void contentsMouseReleaseEvent(QMouseEvent *e); | ||
368 | |||
369 | private: | ||
370 | class KDateInternalMonthPrivate; | ||
371 | KDateInternalMonthPrivate *d; | ||
372 | }; | ||