author | zautrix <zautrix> | 2005-02-08 16:24:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-08 16:24:18 (UTC) |
commit | 78c70cfbbe79243d8b0ec40f8f6438c99046e12b (patch) (unidiff) | |
tree | 382bc11ad3b56f72b8f84414e1da5e5ea871204b /microkde/kdatetbl.cpp | |
parent | 584ed7893497b2adad5ba6c3e914d90b76973b92 (diff) | |
download | kdepimpi-78c70cfbbe79243d8b0ec40f8f6438c99046e12b.zip kdepimpi-78c70cfbbe79243d8b0ec40f8f6438c99046e12b.tar.gz kdepimpi-78c70cfbbe79243d8b0ec40f8f6438c99046e12b.tar.bz2 |
fix
-rw-r--r-- | microkde/kdatetbl.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp index e827412..990cfb9 100644 --- a/microkde/kdatetbl.cpp +++ b/microkde/kdatetbl.cpp | |||
@@ -60,116 +60,115 @@ KDateValidator::validate(QString& text, int&) const | |||
60 | return date(text, temp); | 60 | return date(text, temp); |
61 | } | 61 | } |
62 | 62 | ||
63 | QValidator::State | 63 | QValidator::State |
64 | KDateValidator::date(const QString& text, QDate& d) const | 64 | KDateValidator::date(const QString& text, QDate& d) const |
65 | { | 65 | { |
66 | QDate tmp = KGlobal::locale()->readDate(text); | 66 | QDate tmp = KGlobal::locale()->readDate(text); |
67 | if (!tmp.isNull()) | 67 | if (!tmp.isNull()) |
68 | { | 68 | { |
69 | d = tmp; | 69 | d = tmp; |
70 | return Acceptable; | 70 | return Acceptable; |
71 | } else | 71 | } else |
72 | return Valid; | 72 | return Valid; |
73 | } | 73 | } |
74 | 74 | ||
75 | void | 75 | void |
76 | KDateValidator::fixup( QString& ) const | 76 | KDateValidator::fixup( QString& ) const |
77 | { | 77 | { |
78 | 78 | ||
79 | } | 79 | } |
80 | 80 | ||
81 | KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f) | 81 | KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f) |
82 | : QGridView(parent, name, f) | 82 | : QGridView(parent, name, f) |
83 | { | 83 | { |
84 | setFontSize(10); | 84 | setFont( KGlobalSettings::generalFont() ); |
85 | if(!date_.isValid()) | 85 | if(!date_.isValid()) |
86 | { | 86 | { |
87 | date_=QDate::currentDate(); | 87 | date_=QDate::currentDate(); |
88 | } | 88 | } |
89 | setFocusPolicy( QWidget::StrongFocus ); | 89 | setFocusPolicy( QWidget::StrongFocus ); |
90 | setNumRows(7); // 6 weeks max + headline | 90 | setNumRows(7); // 6 weeks max + headline |
91 | setNumCols(7); // 7 days a week | 91 | setNumCols(7); // 7 days a week |
92 | setHScrollBarMode(AlwaysOff); | 92 | setHScrollBarMode(AlwaysOff); |
93 | setVScrollBarMode(AlwaysOff); | 93 | setVScrollBarMode(AlwaysOff); |
94 | viewport()->setBackgroundColor(QColor(220,245,255)); | 94 | viewport()->setBackgroundColor(QColor(220,245,255)); |
95 | #if 0 | 95 | #if 0 |
96 | viewport()->setEraseColor(lightGray); | 96 | viewport()->setEraseColor(lightGray); |
97 | #endif | 97 | #endif |
98 | mMarkCurrent = false; | 98 | mMarkCurrent = false; |
99 | setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth | 99 | setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth |
100 | } | 100 | } |
101 | 101 | ||
102 | void | 102 | void |
103 | KDateTable::paintCell(QPainter *painter, int row, int col) | 103 | KDateTable::paintCell(QPainter *painter, int row, int col) |
104 | { | 104 | { |
105 | QRect rect; | 105 | QRect rect; |
106 | QString text; | 106 | QString text; |
107 | QPen pen; | 107 | QPen pen; |
108 | int w=cellWidth(); | 108 | int w=cellWidth(); |
109 | int h=cellHeight(); | 109 | int h=cellHeight(); |
110 | int pos; | 110 | int pos; |
111 | QBrush brushBlue(blue); | 111 | QBrush brushBlue(blue); |
112 | QBrush brushLightblue(QColor(220,245,255)); | 112 | QBrush brushLightblue(QColor(220,245,255)); |
113 | QFont font=KGlobalSettings::generalFont(); | 113 | QFont _font=font(); |
114 | // ----- | 114 | // ----- |
115 | font.setPointSize(fontsize); | ||
116 | if(row==0) | 115 | if(row==0) |
117 | { // we are drawing the headline | 116 | { // we are drawing the headline |
118 | font.setBold(true); | 117 | _font.setBold(true); |
119 | painter->setFont(font); | 118 | painter->setFont(_font); |
120 | bool normalday = true; | 119 | bool normalday = true; |
121 | QString daystr; | 120 | QString daystr; |
122 | if (KGlobal::locale()->weekStartsMonday()) | 121 | if (KGlobal::locale()->weekStartsMonday()) |
123 | { | 122 | { |
124 | daystr = KGlobal::locale()->weekDayName(col+1, true); | 123 | daystr = KGlobal::locale()->weekDayName(col+1, true); |
125 | if (col == 5 || col == 6) | 124 | if (col == 5 || col == 6) |
126 | normalday = false; | 125 | normalday = false; |
127 | } else { | 126 | } else { |
128 | daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true); | 127 | daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true); |
129 | if (col == 0 || col == 6) | 128 | if (col == 0 || col == 6) |
130 | normalday = false; | 129 | normalday = false; |
131 | } | 130 | } |
132 | if (!normalday) | 131 | if (!normalday) |
133 | { | 132 | { |
134 | painter->setPen(QColor(220,245,255)); | 133 | painter->setPen(QColor(220,245,255)); |
135 | painter->setBrush(brushLightblue); | 134 | painter->setBrush(brushLightblue); |
136 | painter->drawRect(0, 0, w, h); | 135 | painter->drawRect(0, 0, w, h); |
137 | painter->setPen(blue); | 136 | painter->setPen(blue); |
138 | } else { | 137 | } else { |
139 | painter->setPen(blue); | 138 | painter->setPen(blue); |
140 | painter->setBrush(brushBlue); | 139 | painter->setBrush(brushBlue); |
141 | painter->drawRect(0, 0, w, h); | 140 | painter->drawRect(0, 0, w, h); |
142 | painter->setPen(white); | 141 | painter->setPen(white); |
143 | } | 142 | } |
144 | painter->drawText(0, 0, w, h-1, AlignCenter, | 143 | painter->drawText(0, 0, w, h-1, AlignCenter, |
145 | daystr, -1, &rect); | 144 | daystr, -1, &rect); |
146 | painter->setPen(black); | 145 | painter->setPen(black); |
147 | painter->moveTo(0, h-1); | 146 | painter->moveTo(0, h-1); |
148 | painter->lineTo(w-1, h-1); | 147 | painter->lineTo(w-1, h-1); |
149 | // ----- draw the weekday: | 148 | // ----- draw the weekday: |
150 | } else { | 149 | } else { |
151 | painter->setFont(font); | 150 | painter->setFont(_font); |
152 | pos=7*(row-1)+col; | 151 | pos=7*(row-1)+col; |
153 | if (KGlobal::locale()->weekStartsMonday()) | 152 | if (KGlobal::locale()->weekStartsMonday()) |
154 | pos++; | 153 | pos++; |
155 | if(pos<firstday || (firstday+numdays<=pos)) | 154 | if(pos<firstday || (firstday+numdays<=pos)) |
156 | { // we are either | 155 | { // we are either |
157 | // ° painting a day of the previous month or | 156 | // ° painting a day of the previous month or |
158 | // ° painting a day of the following month | 157 | // ° painting a day of the following month |
159 | if(pos<firstday) | 158 | if(pos<firstday) |
160 | { // previous month | 159 | { // previous month |
161 | text.setNum(numDaysPrevMonth+pos-firstday+1); | 160 | text.setNum(numDaysPrevMonth+pos-firstday+1); |
162 | } else { // following month | 161 | } else { // following month |
163 | text.setNum(pos-firstday-numdays+1); | 162 | text.setNum(pos-firstday-numdays+1); |
164 | } | 163 | } |
165 | painter->setPen(gray); | 164 | painter->setPen(gray); |
166 | } else { // paint a day of the current month | 165 | } else { // paint a day of the current month |
167 | text.setNum(pos-firstday+1); | 166 | text.setNum(pos-firstday+1); |
168 | painter->setPen(black); | 167 | painter->setPen(black); |
169 | } | 168 | } |
170 | 169 | ||
171 | pen=painter->pen(); | 170 | pen=painter->pen(); |
172 | if(firstday+date.day()-1==pos) | 171 | if(firstday+date.day()-1==pos) |
173 | { | 172 | { |
174 | if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) | 173 | if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) |
175 | painter->setPen(green); | 174 | painter->setPen(green); |
@@ -279,52 +278,53 @@ KDateTable::keyPressEvent( QKeyEvent *e ) | |||
279 | setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); | 278 | setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); |
280 | updateCell(temp/7+1, temp%7); // Update the previously selected cell | 279 | updateCell(temp/7+1, temp%7); // Update the previously selected cell |
281 | updateCell(pos/7+1, pos%7); // Update the selected cell | 280 | updateCell(pos/7+1, pos%7); // Update the selected cell |
282 | assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); | 281 | assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); |
283 | 282 | ||
284 | 283 | ||
285 | } | 284 | } |
286 | 285 | ||
287 | void | 286 | void |
288 | KDateTable::viewportResizeEvent(QResizeEvent * e) | 287 | KDateTable::viewportResizeEvent(QResizeEvent * e) |
289 | { | 288 | { |
290 | QGridView::viewportResizeEvent(e); | 289 | QGridView::viewportResizeEvent(e); |
291 | 290 | ||
292 | setCellWidth(viewport()->width()/7); | 291 | setCellWidth(viewport()->width()/7); |
293 | setCellHeight(viewport()->height()/7); | 292 | setCellHeight(viewport()->height()/7); |
294 | } | 293 | } |
295 | 294 | ||
296 | void | 295 | void |
297 | KDateTable::setFontSize(int size) | 296 | KDateTable::setFontSize(int size) |
298 | { | 297 | { |
299 | int count; | 298 | int count; |
300 | QRect rect; | 299 | QRect rect; |
301 | // ----- store rectangles: | 300 | // ----- store rectangles: |
302 | fontsize=size; | 301 | fontsize=size; |
303 | QFont font = KGlobalSettings::generalFont(); | 302 | QFont _font = font(); |
304 | font.setPointSize(fontsize); | 303 | _font.setPointSize(fontsize); |
305 | font.setBold( true ); | 304 | setFont( _font ); |
306 | QFontMetrics metrics(font); | 305 | _font.setBold( true ); |
306 | QFontMetrics metrics(_font); | ||
307 | 307 | ||
308 | // ----- find largest day name: | 308 | // ----- find largest day name: |
309 | maxCell.setWidth(0); | 309 | maxCell.setWidth(0); |
310 | maxCell.setHeight(0); | 310 | maxCell.setHeight(0); |
311 | for(count=0; count<7; ++count) | 311 | for(count=0; count<7; ++count) |
312 | { | 312 | { |
313 | rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); | 313 | rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); |
314 | maxCell.setWidth(QMAX(maxCell.width(), rect.width())); | 314 | maxCell.setWidth(QMAX(maxCell.width(), rect.width())); |
315 | maxCell.setHeight(QMAX(maxCell.height(), rect.height())); | 315 | maxCell.setHeight(QMAX(maxCell.height(), rect.height())); |
316 | } | 316 | } |
317 | // ----- compare with a real wide number and add some space: | 317 | // ----- compare with a real wide number and add some space: |
318 | rect=metrics.boundingRect(QString::fromLatin1("88")); | 318 | rect=metrics.boundingRect(QString::fromLatin1("88")); |
319 | maxCell.setWidth(QMAX(maxCell.width()+2, rect.width())); | 319 | maxCell.setWidth(QMAX(maxCell.width()+2, rect.width())); |
320 | #ifdef DESKTOP_VERSION | 320 | #ifdef DESKTOP_VERSION |
321 | maxCell.setHeight(QMAX(maxCell.height()+8, rect.height())); | 321 | maxCell.setHeight(QMAX(maxCell.height()+8, rect.height())); |
322 | #else | 322 | #else |
323 | maxCell.setHeight(QMAX(maxCell.height()+4, rect.height())); | 323 | maxCell.setHeight(QMAX(maxCell.height()+4, rect.height())); |
324 | #endif | 324 | #endif |
325 | if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) { | 325 | if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) { |
326 | maxCell.setHeight(maxCell.width() * 1000 / 1900 ); | 326 | maxCell.setHeight(maxCell.width() * 1000 / 1900 ); |
327 | qDebug("setmax "); | 327 | qDebug("setmax "); |
328 | } | 328 | } |
329 | } | 329 | } |
330 | 330 | ||
@@ -422,59 +422,63 @@ 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 | (int fontsize, 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 | //font.setPointSize(fontsize); | 456 | int fontsize = 10; |
457 | int add = 2; | ||
458 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) | ||
459 | add += 6; | ||
460 | font.setPointSize(fontsize+add); | ||
457 | setFont(font); | 461 | setFont(font); |
458 | setHScrollBarMode(AlwaysOff); | 462 | setHScrollBarMode(AlwaysOff); |
459 | setVScrollBarMode(AlwaysOff); | 463 | setVScrollBarMode(AlwaysOff); |
460 | setFrameStyle(QFrame::NoFrame); | 464 | setFrameStyle(QFrame::NoFrame); |
461 | setNumRows(4); | 465 | setNumRows(4); |
462 | setNumCols(3); | 466 | setNumCols(3); |
463 | // enable to find drawing failures: | 467 | // enable to find drawing failures: |
464 | // setTableFlags(Tbl_clipCellPainting); | 468 | // setTableFlags(Tbl_clipCellPainting); |
465 | #if 0 | 469 | #if 0 |
466 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker | 470 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker |
467 | #endif | 471 | #endif |
468 | // ----- find the preferred size | 472 | // ----- find the preferred size |
469 | // (this is slow, possibly, but unfortunatly it is needed here): | 473 | // (this is slow, possibly, but unfortunatly it is needed here): |
470 | QFontMetrics metrics(font); | 474 | QFontMetrics metrics(font); |
471 | for(int i=1; i <= 12; ++i) | 475 | for(int i=1; i <= 12; ++i) |
472 | { | 476 | { |
473 | rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); | 477 | rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); |
474 | if(max.width()<rect.width()) max.setWidth(rect.width()); | 478 | if(max.width()<rect.width()) max.setWidth(rect.width()); |
475 | if(max.height()<rect.height()) max.setHeight(rect.height()); | 479 | if(max.height()<rect.height()) max.setHeight(rect.height()); |
476 | } | 480 | } |
477 | 481 | ||
478 | } | 482 | } |
479 | 483 | ||
480 | QSize | 484 | QSize |
@@ -740,59 +744,63 @@ KPopupFrame::exec(QPoint pos) | |||
740 | { | 744 | { |
741 | popup(pos); | 745 | popup(pos); |
742 | repaint(); | 746 | repaint(); |
743 | qApp->enter_loop(); | 747 | qApp->enter_loop(); |
744 | hide(); | 748 | hide(); |
745 | return result; | 749 | return result; |
746 | } | 750 | } |
747 | 751 | ||
748 | int | 752 | int |
749 | KPopupFrame::exec(int x, int y) | 753 | KPopupFrame::exec(int x, int y) |
750 | { | 754 | { |
751 | return exec(QPoint(x, y)); | 755 | return exec(QPoint(x, y)); |
752 | } | 756 | } |
753 | 757 | ||
754 | void KPopupFrame::virtual_hook( int, void* ) | 758 | void KPopupFrame::virtual_hook( int, void* ) |
755 | { /*BASE::virtual_hook( id, data );*/ } | 759 | { /*BASE::virtual_hook( id, data );*/ } |
756 | 760 | ||
757 | void KDateTable::virtual_hook( int, void* ) | 761 | void KDateTable::virtual_hook( int, void* ) |
758 | { /*BASE::virtual_hook( id, data );*/ } | 762 | { /*BASE::virtual_hook( id, data );*/ } |
759 | 763 | ||
760 | //#include "kdatetbl.moc" | 764 | //#include "kdatetbl.moc" |
761 | 765 | ||
762 | 766 | ||
763 | KDateInternalWeekPicker::KDateInternalWeekPicker | 767 | KDateInternalWeekPicker::KDateInternalWeekPicker |
764 | (int fontsize, QWidget* parent, const char* name) | 768 | (QWidget* parent, const char* name) |
765 | : QGridView(parent, name), | 769 | : QGridView(parent, name), |
766 | result(0) // invalid | 770 | result(0) // invalid |
767 | { | 771 | { |
768 | QRect rect; | 772 | QRect rect; |
769 | QFont font; | 773 | QFont font; |
770 | // ----- | 774 | // ----- |
771 | activeCol = -1; | 775 | activeCol = -1; |
772 | activeRow = -1; | 776 | activeRow = -1; |
773 | font=KGlobalSettings::generalFont(); | 777 | font=KGlobalSettings::generalFont(); |
774 | //font.setPointSize(fontsize); | 778 | int fontsize = 10; |
779 | int add = 2; | ||
780 | if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 ) | ||
781 | add += 4; | ||
782 | font.setPointSize(fontsize+add); | ||
775 | setFont(font); | 783 | setFont(font); |
776 | setHScrollBarMode(AlwaysOff); | 784 | setHScrollBarMode(AlwaysOff); |
777 | setVScrollBarMode(AlwaysOff); | 785 | setVScrollBarMode(AlwaysOff); |
778 | setFrameStyle(QFrame::NoFrame); | 786 | setFrameStyle(QFrame::NoFrame); |
779 | setNumRows(13); | 787 | setNumRows(13); |
780 | setNumCols(4); | 788 | setNumCols(4); |
781 | // enable to find drawing failures: | 789 | // enable to find drawing failures: |
782 | // setTableFlags(Tbl_clipCellPainting); | 790 | // setTableFlags(Tbl_clipCellPainting); |
783 | #if 0 | 791 | #if 0 |
784 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker | 792 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker |
785 | #endif | 793 | #endif |
786 | // ----- find the preferred size | 794 | // ----- find the preferred size |
787 | // (this is slow, possibly, but unfortunatly it is needed here): | 795 | // (this is slow, possibly, but unfortunatly it is needed here): |
788 | QFontMetrics metrics(font); | 796 | QFontMetrics metrics(font); |
789 | for(int i=1; i <= 52; ++i) | 797 | for(int i=1; i <= 52; ++i) |
790 | { | 798 | { |
791 | rect=metrics.boundingRect(QString::number( i )); | 799 | rect=metrics.boundingRect(QString::number( i )); |
792 | if(max.width()<rect.width()) max.setWidth(rect.width()); | 800 | if(max.width()<rect.width()) max.setWidth(rect.width()); |
793 | if(max.height()<rect.height()) max.setHeight(rect.height()); | 801 | if(max.height()<rect.height()) max.setHeight(rect.height()); |
794 | } | 802 | } |
795 | if ( QApplication::desktop()->width() > 640 ) { | 803 | if ( QApplication::desktop()->width() > 640 ) { |
796 | 804 | ||
797 | max.setWidth(max.width()+6); | 805 | max.setWidth(max.width()+6); |
798 | max.setHeight(max.height()+8); | 806 | max.setHeight(max.height()+8); |