author | zautrix <zautrix> | 2005-03-30 11:55:53 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-30 11:55:53 (UTC) |
commit | b5222dd7a607f78235b1ea39fea0f95a9c08ccd3 (patch) (unidiff) | |
tree | 4e4d334ae9d8805b7718c1610bd84af128fd8151 /microkde/kdatetbl.cpp | |
parent | 597cad3a63e6c22855704bf8435db70e3c2b184f (diff) | |
download | kdepimpi-b5222dd7a607f78235b1ea39fea0f95a9c08ccd3.zip kdepimpi-b5222dd7a607f78235b1ea39fea0f95a9c08ccd3.tar.gz kdepimpi-b5222dd7a607f78235b1ea39fea0f95a9c08ccd3.tar.bz2 |
fixes
-rw-r--r-- | microkde/kdatetbl.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp index d182279..2d97c8c 100644 --- a/microkde/kdatetbl.cpp +++ b/microkde/kdatetbl.cpp | |||
@@ -199,257 +199,257 @@ KDateTable::paintCell(QPainter *painter, int row, int col) | |||
199 | } | 199 | } |
200 | /* | 200 | /* |
201 | if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); | 201 | if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); |
202 | if(rect.height()>maxCell.height()) { | 202 | if(rect.height()>maxCell.height()) { |
203 | maxCell.setHeight(rect.height()); | 203 | maxCell.setHeight(rect.height()); |
204 | } | 204 | } |
205 | */ | 205 | */ |
206 | } | 206 | } |
207 | 207 | ||
208 | void | 208 | void |
209 | KDateTable::keyPressEvent( QKeyEvent *e ) | 209 | KDateTable::keyPressEvent( QKeyEvent *e ) |
210 | { | 210 | { |
211 | /* | 211 | /* |
212 | // not working properly | 212 | // not working properly |
213 | if ( e->key() == Qt::Key_Prior ) { | 213 | if ( e->key() == Qt::Key_Prior ) { |
214 | if ( date.month() == 1 ) { | 214 | if ( date.month() == 1 ) { |
215 | KNotifyClient::beep(); | 215 | KNotifyClient::beep(); |
216 | return; | 216 | return; |
217 | } | 217 | } |
218 | int day = date.day(); | 218 | int day = date.day(); |
219 | if ( day > 27 ) | 219 | if ( day > 27 ) |
220 | while ( !QDate::isValid( date.year(), date.month()-1, day ) ) | 220 | while ( !QDate::isValid( date.year(), date.month()-1, day ) ) |
221 | day--; | 221 | day--; |
222 | setDate(QDate(date.year(), date.month()-1, day)); | 222 | setDate(QDate(date.year(), date.month()-1, day)); |
223 | return; | 223 | return; |
224 | } | 224 | } |
225 | if ( e->key() == Qt::Key_Next ) { | 225 | if ( e->key() == Qt::Key_Next ) { |
226 | if ( date.month() == 12 ) { | 226 | if ( date.month() == 12 ) { |
227 | KNotifyClient::beep(); | 227 | KNotifyClient::beep(); |
228 | return; | 228 | return; |
229 | } | 229 | } |
230 | int day = date.day(); | 230 | int day = date.day(); |
231 | if ( day > 27 ) | 231 | if ( day > 27 ) |
232 | while ( !QDate::isValid( date.year(), date.month()+1, day ) ) | 232 | while ( !QDate::isValid( date.year(), date.month()+1, day ) ) |
233 | day--; | 233 | day--; |
234 | setDate(QDate(date.year(), date.month()+1, day)); | 234 | setDate(QDate(date.year(), date.month()+1, day)); |
235 | return; | 235 | return; |
236 | } | 236 | } |
237 | */ | 237 | */ |
238 | int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; | 238 | int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; |
239 | 239 | ||
240 | int temp=firstday+date.day()-dayoff; | 240 | int temp=firstday+date.day()-dayoff; |
241 | int pos = temp; | 241 | int pos = temp; |
242 | bool irgnore = true; | 242 | bool irgnore = true; |
243 | if ( e->state() != Qt::ControlButton ) { | 243 | if ( e->state() != Qt::ControlButton ) { |
244 | if ( e->key() == Qt::Key_Up ) { | 244 | if ( e->key() == Qt::Key_Up ) { |
245 | pos -= 7; | 245 | pos -= 7; |
246 | irgnore = false; | 246 | irgnore = false; |
247 | } | 247 | } |
248 | if ( e->key() == Qt::Key_Down ) { | 248 | if ( e->key() == Qt::Key_Down ) { |
249 | pos += 7; | 249 | pos += 7; |
250 | irgnore = false; | 250 | irgnore = false; |
251 | } | 251 | } |
252 | if ( e->key() == Qt::Key_Left ) { | 252 | if ( e->key() == Qt::Key_Left ) { |
253 | pos--; | 253 | pos--; |
254 | irgnore = false; | 254 | irgnore = false; |
255 | } | 255 | } |
256 | if ( e->key() == Qt::Key_Right ) { | 256 | if ( e->key() == Qt::Key_Right ) { |
257 | pos++; | 257 | pos++; |
258 | irgnore = false; | 258 | irgnore = false; |
259 | } | 259 | } |
260 | } | 260 | } |
261 | if ( irgnore ) | 261 | if ( irgnore ) |
262 | e->ignore(); | 262 | e->ignore(); |
263 | 263 | ||
264 | if(pos+dayoff<=firstday) | 264 | if(pos+dayoff<=firstday) |
265 | { // this day is in the previous month | 265 | { // this day is in the previous month |
266 | KNotifyClient::beep(); | 266 | KNotifyClient::beep(); |
267 | return; | 267 | return; |
268 | } | 268 | } |
269 | if(firstday+numdays<pos+dayoff) | 269 | if(firstday+numdays<pos+dayoff) |
270 | { // this date is in the next month | 270 | { // this date is in the next month |
271 | KNotifyClient::beep(i18n( "Month not long enough" )); | 271 | KNotifyClient::beep(i18n( "Month not long enough" )); |
272 | return; | 272 | return; |
273 | } | 273 | } |
274 | 274 | ||
275 | if ( pos == temp ) | 275 | if ( pos == temp ) |
276 | return; | 276 | return; |
277 | 277 | ||
278 | setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); | 278 | setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); |
279 | updateCell(temp/7+1, temp%7); // Update the previously selected cell | 279 | updateCell(temp/7+1, temp%7); // Update the previously selected cell |
280 | updateCell(pos/7+1, pos%7); // Update the selected cell | 280 | updateCell(pos/7+1, pos%7); // Update the selected cell |
281 | assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); | 281 | assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); |
282 | 282 | ||
283 | 283 | ||
284 | } | 284 | } |
285 | 285 | ||
286 | void | 286 | void |
287 | KDateTable::viewportResizeEvent(QResizeEvent * e) | 287 | KDateTable::viewportResizeEvent(QResizeEvent * e) |
288 | { | 288 | { |
289 | QGridView::viewportResizeEvent(e); | 289 | QGridView::viewportResizeEvent(e); |
290 | 290 | ||
291 | setCellWidth(viewport()->width()/7); | 291 | setCellWidth(viewport()->width()/7); |
292 | setCellHeight(viewport()->height()/7); | 292 | setCellHeight(viewport()->height()/7); |
293 | } | 293 | } |
294 | 294 | ||
295 | void | 295 | void |
296 | KDateTable::setFontSize(int size) | 296 | KDateTable::setFontSize(int size) |
297 | { | 297 | { |
298 | int count; | 298 | int count; |
299 | QRect rect; | 299 | QRect rect; |
300 | // ----- store rectangles: | 300 | // ----- store rectangles: |
301 | fontsize=size; | 301 | fontsize=size; |
302 | QFont _font = font(); | 302 | QFont _font = font(); |
303 | _font.setPointSize(fontsize); | 303 | _font.setPointSize(fontsize); |
304 | setFont( _font ); | 304 | setFont( _font ); |
305 | _font.setBold( true ); | 305 | _font.setBold( true ); |
306 | QFontMetrics metrics(_font); | 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 | ||
331 | void | 331 | void |
332 | KDateTable::contentsMousePressEvent(QMouseEvent *e) | 332 | KDateTable::contentsMousePressEvent(QMouseEvent *e) |
333 | { | 333 | { |
334 | if(e->type()!=QEvent::MouseButtonPress) | 334 | if(e->type()!=QEvent::MouseButtonPress) |
335 | { // the KDatePicker only reacts on mouse press events: | 335 | { // the KDatePicker only reacts on mouse press events: |
336 | return; | 336 | return; |
337 | } | 337 | } |
338 | if(!isEnabled()) | 338 | if(!isEnabled()) |
339 | { | 339 | { |
340 | KNotifyClient::beep(); | 340 | KNotifyClient::beep(); |
341 | return; | 341 | return; |
342 | } | 342 | } |
343 | 343 | ||
344 | int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; | 344 | int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; |
345 | // ----- | 345 | // ----- |
346 | int row, col, pos, temp; | 346 | int row, col, pos, temp; |
347 | QPoint mouseCoord; | 347 | QPoint mouseCoord; |
348 | // ----- | 348 | // ----- |
349 | mouseCoord = e->pos(); | 349 | mouseCoord = e->pos(); |
350 | row=rowAt(mouseCoord.y()); | 350 | row=rowAt(mouseCoord.y()); |
351 | col=columnAt(mouseCoord.x()); | 351 | col=columnAt(mouseCoord.x()); |
352 | if(row<0 || col<0) | 352 | if(row<0 || col<0) |
353 | { // the user clicked on the frame of the table | 353 | { // the user clicked on the frame of the table |
354 | return; | 354 | return; |
355 | } | 355 | } |
356 | pos=7*(row-1)+col+1; | 356 | pos=7*(row-1)+col+1; |
357 | #if 0 | 357 | #if 0 |
358 | if(pos+dayoff<=firstday) | 358 | if(pos+dayoff<=firstday) |
359 | { // this day is in the previous month | 359 | { // this day is in the previous month |
360 | KNotifyClient::beep(); | 360 | KNotifyClient::beep(); |
361 | return; | 361 | return; |
362 | } | 362 | } |
363 | if(firstday+numdays<pos+dayoff) | 363 | if(firstday+numdays<pos+dayoff) |
364 | { // this date is in the next month | 364 | { // this date is in the next month |
365 | KNotifyClient::beep(); | 365 | KNotifyClient::beep(); |
366 | return; | 366 | return; |
367 | } | 367 | } |
368 | #endif | 368 | #endif |
369 | temp=firstday+date.day()-dayoff-1; | 369 | temp=firstday+date.day()-dayoff-1; |
370 | QDate da = QDate(date.year(), date.month(),1); | 370 | QDate da = QDate(date.year(), date.month(),1); |
371 | setDate(da.addDays( pos-firstday+dayoff-1)); | 371 | setDate(da.addDays( pos-firstday+dayoff-1)); |
372 | updateCell(temp/7+1, temp%7); // Update the previously selected cell | 372 | updateCell(temp/7+1, temp%7); // Update the previously selected cell |
373 | updateCell(row, col); // Update the selected cell | 373 | updateCell(row, col); // Update the selected cell |
374 | // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); | 374 | // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); |
375 | emit(tableClicked()); | 375 | emit(tableClicked()); |
376 | } | 376 | } |
377 | 377 | ||
378 | bool | 378 | bool |
379 | KDateTable::setDate(const QDate& date_) | 379 | KDateTable::setDate(const QDate& date_) |
380 | { | 380 | { |
381 | bool changed=false; | 381 | bool changed=false; |
382 | QDate temp; | 382 | QDate temp; |
383 | mMarkCurrent = false; | 383 | mMarkCurrent = false; |
384 | // ----- | 384 | // ----- |
385 | if(!date_.isValid()) | 385 | if(!date_.isValid()) |
386 | { | 386 | { |
387 | kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; | 387 | kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; |
388 | return false; | 388 | return false; |
389 | } | 389 | } |
390 | if(date!=date_) | 390 | if(date!=date_) |
391 | { | 391 | { |
392 | date=date_; | 392 | date=date_; |
393 | changed=true; | 393 | changed=true; |
394 | } | 394 | } |
395 | mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() ); | 395 | mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() ); |
396 | temp.setYMD(date.year(), date.month(), 1); | 396 | temp.setYMD(date.year(), date.month(), 1); |
397 | firstday=temp.dayOfWeek(); | 397 | firstday=temp.dayOfWeek(); |
398 | if(firstday==1) firstday=8; | 398 | if(firstday==1) firstday=8; |
399 | numdays=date.daysInMonth(); | 399 | numdays=date.daysInMonth(); |
400 | if(date.month()==1) | 400 | if(date.month()==1) |
401 | { // set to december of previous year | 401 | { // set to december of previous year |
402 | temp.setYMD(date.year()-1, 12, 1); | 402 | temp.setYMD(date.year()-1, 12, 1); |
403 | } else { // set to previous month | 403 | } else { // set to previous month |
404 | temp.setYMD(date.year(), date.month()-1, 1); | 404 | temp.setYMD(date.year(), date.month()-1, 1); |
405 | } | 405 | } |
406 | numDaysPrevMonth=temp.daysInMonth(); | 406 | numDaysPrevMonth=temp.daysInMonth(); |
407 | if(changed) | 407 | if(changed) |
408 | { | 408 | { |
409 | repaintContents(false); | 409 | repaintContents(false); |
410 | } | 410 | } |
411 | emit(dateChanged(date)); | 411 | emit(dateChanged(date)); |
412 | return true; | 412 | return true; |
413 | } | 413 | } |
414 | 414 | ||
415 | const QDate& | 415 | const QDate& |
416 | KDateTable::getDate() const | 416 | KDateTable::getDate() const |
417 | { | 417 | { |
418 | return date; | 418 | return date; |
419 | } | 419 | } |
420 | 420 | ||
421 | void KDateTable::focusInEvent( QFocusEvent *e ) | 421 | 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 | (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(); |