-rw-r--r-- | libkdepim/kdatepicker.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp index 25b4e81..68ef943 100644 --- a/libkdepim/kdatepicker.cpp +++ b/libkdepim/kdatepicker.cpp | |||
@@ -91,128 +91,132 @@ KDatePicker::~KDatePicker() | |||
91 | 91 | ||
92 | void | 92 | void |
93 | KDatePicker::resizeEvent(QResizeEvent*) | 93 | KDatePicker::resizeEvent(QResizeEvent*) |
94 | { | 94 | { |
95 | QWidget *buttons[] = { | 95 | QWidget *buttons[] = { |
96 | yearBackward, | 96 | yearBackward, |
97 | monthBackward, | 97 | monthBackward, |
98 | selectMonth, | 98 | selectMonth, |
99 | selectYear, | 99 | selectYear, |
100 | monthForward, | 100 | monthForward, |
101 | yearForward }; | 101 | yearForward }; |
102 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); | 102 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); |
103 | QSize sizes[NoOfButtons]; | 103 | QSize sizes[NoOfButtons]; |
104 | int buttonHeight=0; | 104 | int buttonHeight=0; |
105 | int count; | 105 | int count; |
106 | int w; | 106 | int w; |
107 | int x=0; | 107 | int x=0; |
108 | // ----- calculate button row height: | 108 | // ----- calculate button row height: |
109 | for(count=0; count<NoOfButtons; ++count) { | 109 | for(count=0; count<NoOfButtons; ++count) { |
110 | int xS = buttons[count]->sizeHint().width(); | 110 | int xS = buttons[count]->sizeHint().width(); |
111 | int yS = buttons[count]->sizeHint().height(); | 111 | int yS = buttons[count]->sizeHint().height(); |
112 | if ( QApplication::desktop()->width() < 320 ) | 112 | if ( QApplication::desktop()->width() < 320 ) |
113 | sizes[count]=QSize ( xS+4, yS ); | 113 | sizes[count]=QSize ( xS+4, yS ); |
114 | else | 114 | else |
115 | sizes[count]=QSize ( xS+10, yS ); | 115 | sizes[count]=QSize ( xS+10, yS ); |
116 | 116 | ||
117 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); | 117 | buttonHeight=QMAX(buttonHeight, sizes[count].height()); |
118 | } | 118 | } |
119 | buttonHeight += 10; | 119 | buttonHeight += 10; |
120 | // ----- calculate size of the month button: | 120 | // ----- calculate size of the month button: |
121 | w=0; | 121 | w=0; |
122 | for(count=0; count<NoOfButtons; ++count) { | 122 | for(count=0; count<NoOfButtons; ++count) { |
123 | if(buttons[count]!=selectMonth) | 123 | if(buttons[count]!=selectMonth) |
124 | { | 124 | { |
125 | w+=sizes[count].width(); | 125 | w+=sizes[count].width(); |
126 | } else { | 126 | } else { |
127 | x=count; | 127 | x=count; |
128 | } | 128 | } |
129 | } | 129 | } |
130 | sizes[x].setWidth(width()-w); // stretch the month button | 130 | sizes[x].setWidth(width()-w); // stretch the month button |
131 | // ----- place the buttons: | 131 | // ----- place the buttons: |
132 | x=0; | 132 | x=0; |
133 | for(count=0; count<NoOfButtons; ++count) | 133 | for(count=0; count<NoOfButtons; ++count) |
134 | { | 134 | { |
135 | w=sizes[count].width(); | 135 | w=sizes[count].width(); |
136 | buttons[count]->setGeometry(x, 0, w, buttonHeight); | 136 | buttons[count]->setGeometry(x, 0, w, buttonHeight); |
137 | x+=w; | 137 | x+=w; |
138 | } | 138 | } |
139 | // ----- place the line edit for direct input: | 139 | // ----- place the line edit for direct input: |
140 | sizes[0]=lineDate->sizeHint(); | 140 | sizes[0]=lineDate->sizeHint(); |
141 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); | 141 | //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); |
142 | int todaywid = todayBut->sizeHint().width(); | 142 | int todaywid = todayBut->sizeHint().width(); |
143 | todayBut->setGeometry(0, height()-sizes[0].height(),todaywid, sizes[0].height()); | 143 | todayBut->setGeometry(0, height()-sizes[0].height(),todaywid, sizes[0].height()); |
144 | lineDate->setGeometry(0+todaywid, height()-sizes[0].height(), width()-todaywid, sizes[0].height()); | 144 | lineDate->setGeometry(0+todaywid, height()-sizes[0].height(), width()-todaywid, sizes[0].height()); |
145 | // ----- adjust the table: | 145 | // ----- adjust the table: |
146 | table->setGeometry(0, buttonHeight, width(), | 146 | table->setGeometry(0, buttonHeight, width(), |
147 | height()-buttonHeight-sizes[0].height()); | 147 | height()-buttonHeight-sizes[0].height()); |
148 | } | 148 | } |
149 | 149 | ||
150 | void | 150 | void |
151 | KDatePicker::dateChangedSlot(QDate date) | 151 | KDatePicker::dateChangedSlot(QDate date) |
152 | { | 152 | { |
153 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); | 153 | lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); |
154 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 154 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
155 | QString temp; | ||
156 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | ||
157 | temp.setNum(date.year()); | ||
158 | selectYear->setText(temp); | ||
155 | emit(dateChanged(date)); | 159 | emit(dateChanged(date)); |
156 | } | 160 | } |
157 | 161 | ||
158 | void | 162 | void |
159 | KDatePicker::tableClickedSlot() | 163 | KDatePicker::tableClickedSlot() |
160 | { | 164 | { |
161 | 165 | ||
162 | emit(dateSelected(table->getDate())); | 166 | emit(dateSelected(table->getDate())); |
163 | emit(tableClicked()); | 167 | emit(tableClicked()); |
164 | } | 168 | } |
165 | 169 | ||
166 | const QDate& | 170 | const QDate& |
167 | KDatePicker::getDate() const | 171 | KDatePicker::getDate() const |
168 | { | 172 | { |
169 | return table->getDate(); | 173 | return table->getDate(); |
170 | } | 174 | } |
171 | 175 | ||
172 | const QDate & | 176 | const QDate & |
173 | KDatePicker::date() const | 177 | KDatePicker::date() const |
174 | { | 178 | { |
175 | return table->getDate(); | 179 | return table->getDate(); |
176 | } | 180 | } |
177 | 181 | ||
178 | void KDatePicker::goToday() | 182 | void KDatePicker::goToday() |
179 | { | 183 | { |
180 | slotSetDate( QDate::currentDate() ); | 184 | slotSetDate( QDate::currentDate() ); |
181 | 185 | ||
182 | } | 186 | } |
183 | void KDatePicker::slotSetDate( QDate date ) | 187 | void KDatePicker::slotSetDate( QDate date ) |
184 | { | 188 | { |
185 | 189 | ||
186 | if(date.isValid()) { | 190 | if(date.isValid()) { |
187 | QString temp; | 191 | QString temp; |
188 | // ----- | 192 | // ----- |
189 | table->setDate(date); | 193 | table->setDate(date); |
190 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | 194 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); |
191 | temp.setNum(date.year()); | 195 | temp.setNum(date.year()); |
192 | selectYear->setText(temp); | 196 | selectYear->setText(temp); |
193 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 197 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
194 | lineDate->setDate( date ); | 198 | lineDate->setDate( date ); |
195 | } | 199 | } |
196 | 200 | ||
197 | } | 201 | } |
198 | bool | 202 | bool |
199 | KDatePicker::setDate(const QDate& date) | 203 | KDatePicker::setDate(const QDate& date) |
200 | { | 204 | { |
201 | table->setFocus(); | 205 | table->setFocus(); |
202 | if(date.isValid()) { | 206 | if(date.isValid()) { |
203 | QString temp; | 207 | QString temp; |
204 | // ----- | 208 | // ----- |
205 | table->setDate(date); | 209 | table->setDate(date); |
206 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); | 210 | selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); |
207 | temp.setNum(date.year()); | 211 | temp.setNum(date.year()); |
208 | selectYear->setText(temp); | 212 | selectYear->setText(temp); |
209 | //line->setText(KGlobal::locale()->formatDate(date, true)); | 213 | //line->setText(KGlobal::locale()->formatDate(date, true)); |
210 | lineDate->setDate( date ); | 214 | lineDate->setDate( date ); |
211 | return true; | 215 | return true; |
212 | } else { | 216 | } else { |
213 | 217 | ||
214 | return false; | 218 | return false; |
215 | } | 219 | } |
216 | 220 | ||
217 | 221 | ||
218 | } | 222 | } |
@@ -414,77 +418,81 @@ KDatePicker::sizeHint() const | |||
414 | cx=QMAX(cx, tableSize.width()); // line edit ignored | 418 | cx=QMAX(cx, tableSize.width()); // line edit ignored |
415 | if ( cx > QApplication::desktop()->width() -5 ) | 419 | if ( cx > QApplication::desktop()->width() -5 ) |
416 | cx = QApplication::desktop()->width() -5; | 420 | cx = QApplication::desktop()->width() -5; |
417 | // ----- calculate height hint: | 421 | // ----- calculate height hint: |
418 | cy+=tableSize.height()+lineDate->sizeHint().height(); | 422 | cy+=tableSize.height()+lineDate->sizeHint().height(); |
419 | 423 | ||
420 | return QSize(cx, cy); | 424 | return QSize(cx, cy); |
421 | } | 425 | } |
422 | 426 | ||
423 | void | 427 | void |
424 | KDatePicker::setFontSize(int s) | 428 | KDatePicker::setFontSize(int s) |
425 | { | 429 | { |
426 | QWidget *buttons[]= { | 430 | QWidget *buttons[]= { |
427 | // yearBackward, | 431 | // yearBackward, |
428 | // monthBackward, | 432 | // monthBackward, |
429 | selectMonth, | 433 | selectMonth, |
430 | selectYear, | 434 | selectYear, |
431 | // monthForward, | 435 | // monthForward, |
432 | // yearForward | 436 | // yearForward |
433 | }; | 437 | }; |
434 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); | 438 | const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); |
435 | int count; | 439 | int count; |
436 | QFont font; | 440 | QFont font; |
437 | QRect r; | 441 | QRect r; |
438 | // ----- | 442 | // ----- |
439 | fontsize=s; | 443 | fontsize=s; |
440 | for(count=0; count<NoOfButtons; ++count) | 444 | for(count=0; count<NoOfButtons; ++count) |
441 | { | 445 | { |
442 | font=buttons[count]->font(); | 446 | font=buttons[count]->font(); |
443 | font.setPointSize(s); | 447 | font.setPointSize(s); |
444 | buttons[count]->setFont(font); | 448 | buttons[count]->setFont(font); |
445 | } | 449 | } |
446 | QFontMetrics metrics(selectMonth->fontMetrics()); | 450 | QFontMetrics metrics(selectMonth->fontMetrics()); |
447 | for(int i=1; i <= 12; ++i) | 451 | for(int i=1; i <= 12; ++i) |
448 | { // maxMonthRect is used by sizeHint() | 452 | { // maxMonthRect is used by sizeHint() |
449 | r=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); | 453 | r=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); |
450 | maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); | 454 | maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width())); |
451 | maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height())); | 455 | maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height())); |
452 | } | 456 | } |
453 | table->setFontSize(s); | 457 | table->setFontSize(s); |
454 | } | 458 | } |
455 | 459 | ||
456 | void KDatePicker::virtual_hook( int id, void* data ) | 460 | void KDatePicker::virtual_hook( int id, void* data ) |
457 | { /*BASE::virtual_hook( id, data );*/ } | 461 | { /*BASE::virtual_hook( id, data );*/ } |
458 | 462 | ||
459 | void KDatePicker::keyPressEvent ( QKeyEvent * e ) | 463 | void KDatePicker::keyPressEvent ( QKeyEvent * e ) |
460 | { | 464 | { |
461 | switch ( e->key() ) { | 465 | switch ( e->key() ) { |
462 | case Qt::Key_Right: | 466 | case Qt::Key_Right: |
463 | monthForwardClicked(); | 467 | monthForwardClicked(); |
464 | break; | 468 | break; |
465 | case Qt::Key_Left: | 469 | case Qt::Key_Left: |
466 | monthBackwardClicked(); | 470 | monthBackwardClicked(); |
467 | break; | 471 | break; |
468 | 472 | ||
469 | case Qt::Key_Down: | 473 | case Qt::Key_Down: |
470 | yearForwardClicked(); | 474 | yearForwardClicked(); |
471 | 475 | ||
472 | break; | 476 | break; |
473 | 477 | ||
474 | case Qt::Key_Up: | 478 | case Qt::Key_Up: |
475 | yearBackwardClicked(); | 479 | yearBackwardClicked(); |
476 | break; | 480 | break; |
477 | 481 | ||
482 | case Qt::Key_T: | ||
483 | goToday(); | ||
484 | break; | ||
485 | |||
478 | case Qt::Key_Return: | 486 | case Qt::Key_Return: |
479 | case Qt::Key_Enter: | 487 | case Qt::Key_Enter: |
480 | case Qt::Key_Space: | 488 | case Qt::Key_Space: |
481 | tableClickedSlot(); | 489 | tableClickedSlot(); |
482 | break; | 490 | break; |
483 | case Qt::Key_Escape: | 491 | case Qt::Key_Escape: |
484 | e->ignore(); | 492 | e->ignore(); |
485 | break; | 493 | break; |
486 | default: | 494 | default: |
487 | break; | 495 | break; |
488 | } | 496 | } |
489 | 497 | ||
490 | } | 498 | } |