summaryrefslogtreecommitdiffabout
path: root/microkde/kdatetbl.cpp
Unidiff
Diffstat (limited to 'microkde/kdatetbl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdatetbl.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index fce0e5a..e827412 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -137,374 +137,384 @@ KDateTable::paintCell(QPainter *painter, int row, int col)
137 painter->setPen(blue); 137 painter->setPen(blue);
138 } else { 138 } else {
139 painter->setPen(blue); 139 painter->setPen(blue);
140 painter->setBrush(brushBlue); 140 painter->setBrush(brushBlue);
141 painter->drawRect(0, 0, w, h); 141 painter->drawRect(0, 0, w, h);
142 painter->setPen(white); 142 painter->setPen(white);
143 } 143 }
144 painter->drawText(0, 0, w, h-1, AlignCenter, 144 painter->drawText(0, 0, w, h-1, AlignCenter,
145 daystr, -1, &rect); 145 daystr, -1, &rect);
146 painter->setPen(black); 146 painter->setPen(black);
147 painter->moveTo(0, h-1); 147 painter->moveTo(0, h-1);
148 painter->lineTo(w-1, h-1); 148 painter->lineTo(w-1, h-1);
149 // ----- draw the weekday: 149 // ----- draw the weekday:
150 } else { 150 } else {
151 painter->setFont(font); 151 painter->setFont(font);
152 pos=7*(row-1)+col; 152 pos=7*(row-1)+col;
153 if (KGlobal::locale()->weekStartsMonday()) 153 if (KGlobal::locale()->weekStartsMonday())
154 pos++; 154 pos++;
155 if(pos<firstday || (firstday+numdays<=pos)) 155 if(pos<firstday || (firstday+numdays<=pos))
156 { // we are either 156 { // we are either
157 // ° painting a day of the previous month or 157 // ° painting a day of the previous month or
158 // ° painting a day of the following month 158 // ° painting a day of the following month
159 if(pos<firstday) 159 if(pos<firstday)
160 { // previous month 160 { // previous month
161 text.setNum(numDaysPrevMonth+pos-firstday+1); 161 text.setNum(numDaysPrevMonth+pos-firstday+1);
162 } else { // following month 162 } else { // following month
163 text.setNum(pos-firstday-numdays+1); 163 text.setNum(pos-firstday-numdays+1);
164 } 164 }
165 painter->setPen(gray); 165 painter->setPen(gray);
166 } else { // paint a day of the current month 166 } else { // paint a day of the current month
167 text.setNum(pos-firstday+1); 167 text.setNum(pos-firstday+1);
168 painter->setPen(black); 168 painter->setPen(black);
169 } 169 }
170 170
171 pen=painter->pen(); 171 pen=painter->pen();
172 if(firstday+date.day()-1==pos) 172 if(firstday+date.day()-1==pos)
173 { 173 {
174 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) 174 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
175 painter->setPen(green); 175 painter->setPen(green);
176 else 176 else
177 painter->setPen(red); 177 painter->setPen(red);
178 if(hasFocus()) 178 if(hasFocus())
179 { 179 {
180 painter->setBrush(darkRed); 180 painter->setBrush(darkRed);
181 pen=white; 181 pen=white;
182 } else { 182 } else {
183 painter->setBrush(darkGray); 183 painter->setBrush(darkGray);
184 pen=white; 184 pen=white;
185 } 185 }
186 } else { 186 } else {
187 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) 187 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
188 { 188 {
189 painter->setPen(green); 189 painter->setPen(green);
190 painter->setBrush(darkGreen); 190 painter->setBrush(darkGreen);
191 pen=white; 191 pen=white;
192 } else { 192 } else {
193 painter->setBrush(QColor(220,245,255)); 193 painter->setBrush(QColor(220,245,255));
194 painter->setPen(QColor(220,245,255)); 194 painter->setPen(QColor(220,245,255));
195 } 195 }
196 } 196 }
197 painter->drawRect(0, 0, w, h); 197 painter->drawRect(0, 0, w, h);
198 painter->setPen(pen); 198 painter->setPen(pen);
199 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect); 199 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
200 } 200 }
201 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); 201 /*
202 if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height()); 202 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
203 if(rect.height()>maxCell.height()) {
204 maxCell.setHeight(rect.height());
205 }
206 */
203} 207}
204 208
205void 209void
206KDateTable::keyPressEvent( QKeyEvent *e ) 210KDateTable::keyPressEvent( QKeyEvent *e )
207{ 211{
208 /* 212 /*
209 // not working properly 213 // not working properly
210 if ( e->key() == Qt::Key_Prior ) { 214 if ( e->key() == Qt::Key_Prior ) {
211 if ( date.month() == 1 ) { 215 if ( date.month() == 1 ) {
212 KNotifyClient::beep(); 216 KNotifyClient::beep();
213 return; 217 return;
214 } 218 }
215 int day = date.day(); 219 int day = date.day();
216 if ( day > 27 ) 220 if ( day > 27 )
217 while ( !QDate::isValid( date.year(), date.month()-1, day ) ) 221 while ( !QDate::isValid( date.year(), date.month()-1, day ) )
218 day--; 222 day--;
219 setDate(QDate(date.year(), date.month()-1, day)); 223 setDate(QDate(date.year(), date.month()-1, day));
220 return; 224 return;
221 } 225 }
222 if ( e->key() == Qt::Key_Next ) { 226 if ( e->key() == Qt::Key_Next ) {
223 if ( date.month() == 12 ) { 227 if ( date.month() == 12 ) {
224 KNotifyClient::beep(); 228 KNotifyClient::beep();
225 return; 229 return;
226 } 230 }
227 int day = date.day(); 231 int day = date.day();
228 if ( day > 27 ) 232 if ( day > 27 )
229 while ( !QDate::isValid( date.year(), date.month()+1, day ) ) 233 while ( !QDate::isValid( date.year(), date.month()+1, day ) )
230 day--; 234 day--;
231 setDate(QDate(date.year(), date.month()+1, day)); 235 setDate(QDate(date.year(), date.month()+1, day));
232 return; 236 return;
233 } 237 }
234 */ 238 */
235 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; 239 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
236 240
237 int temp=firstday+date.day()-dayoff; 241 int temp=firstday+date.day()-dayoff;
238 int pos = temp; 242 int pos = temp;
239 bool irgnore = true; 243 bool irgnore = true;
240 if ( e->state() != Qt::ControlButton ) { 244 if ( e->state() != Qt::ControlButton ) {
241 if ( e->key() == Qt::Key_Up ) { 245 if ( e->key() == Qt::Key_Up ) {
242 pos -= 7; 246 pos -= 7;
243 irgnore = false; 247 irgnore = false;
244 } 248 }
245 if ( e->key() == Qt::Key_Down ) { 249 if ( e->key() == Qt::Key_Down ) {
246 pos += 7; 250 pos += 7;
247 irgnore = false; 251 irgnore = false;
248 } 252 }
249 if ( e->key() == Qt::Key_Left ) { 253 if ( e->key() == Qt::Key_Left ) {
250 pos--; 254 pos--;
251 irgnore = false; 255 irgnore = false;
252 } 256 }
253 if ( e->key() == Qt::Key_Right ) { 257 if ( e->key() == Qt::Key_Right ) {
254 pos++; 258 pos++;
255 irgnore = false; 259 irgnore = false;
256 } 260 }
257 } 261 }
258 if ( irgnore ) 262 if ( irgnore )
259 e->ignore(); 263 e->ignore();
260 264
261 if(pos+dayoff<=firstday) 265 if(pos+dayoff<=firstday)
262 { // this day is in the previous month 266 { // this day is in the previous month
263 KNotifyClient::beep(); 267 KNotifyClient::beep();
264 return; 268 return;
265 } 269 }
266 if(firstday+numdays<pos+dayoff) 270 if(firstday+numdays<pos+dayoff)
267 { // this date is in the next month 271 { // this date is in the next month
268 KNotifyClient::beep(i18n( "Month not long enough" )); 272 KNotifyClient::beep(i18n( "Month not long enough" ));
269 return; 273 return;
270 } 274 }
271 275
272 if ( pos == temp ) 276 if ( pos == temp )
273 return; 277 return;
274 278
275 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); 279 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff));
276 updateCell(temp/7+1, temp%7); // Update the previously selected cell 280 updateCell(temp/7+1, temp%7); // Update the previously selected cell
277 updateCell(pos/7+1, pos%7); // Update the selected cell 281 updateCell(pos/7+1, pos%7); // Update the selected cell
278 assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 282 assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
279 283
280 284
281} 285}
282 286
283void 287void
284KDateTable::viewportResizeEvent(QResizeEvent * e) 288KDateTable::viewportResizeEvent(QResizeEvent * e)
285{ 289{
286 QGridView::viewportResizeEvent(e); 290 QGridView::viewportResizeEvent(e);
287 291
288 setCellWidth(viewport()->width()/7); 292 setCellWidth(viewport()->width()/7);
289 setCellHeight(viewport()->height()/7); 293 setCellHeight(viewport()->height()/7);
290} 294}
291 295
292void 296void
293KDateTable::setFontSize(int size) 297KDateTable::setFontSize(int size)
294{ 298{
295 int count; 299 int count;
296 QRect rect; 300 QRect rect;
297 // ----- store rectangles: 301 // ----- store rectangles:
298 fontsize=size; 302 fontsize=size;
299 QFont font = KGlobalSettings::generalFont(); 303 QFont font = KGlobalSettings::generalFont();
300 font.setPointSize(fontsize); 304 font.setPointSize(fontsize);
301 font.setBold( true ); 305 font.setBold( true );
302 QFontMetrics metrics(font); 306 QFontMetrics metrics(font);
303 307
304 // ----- find largest day name: 308 // ----- find largest day name:
305 maxCell.setWidth(0); 309 maxCell.setWidth(0);
306 maxCell.setHeight(0); 310 maxCell.setHeight(0);
307 for(count=0; count<7; ++count) 311 for(count=0; count<7; ++count)
308 { 312 {
309 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); 313 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true));
310 maxCell.setWidth(QMAX(maxCell.width(), rect.width())); 314 maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
311 maxCell.setHeight(QMAX(maxCell.height(), rect.height())); 315 maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
312 } 316 }
313 // ----- compare with a real wide number and add some space: 317 // ----- compare with a real wide number and add some space:
314 rect=metrics.boundingRect(QString::fromLatin1("88")); 318 rect=metrics.boundingRect(QString::fromLatin1("88"));
315 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width())); 319 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
320#ifdef DESKTOP_VERSION
321 maxCell.setHeight(QMAX(maxCell.height()+8, rect.height()));
322#else
316 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height())); 323 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
317 if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) 324#endif
325 if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) {
318 maxCell.setHeight(maxCell.width() * 1000 / 1900 ); 326 maxCell.setHeight(maxCell.width() * 1000 / 1900 );
327 qDebug("setmax ");
328 }
319} 329}
320 330
321void 331void
322KDateTable::contentsMousePressEvent(QMouseEvent *e) 332KDateTable::contentsMousePressEvent(QMouseEvent *e)
323{ 333{
324 if(e->type()!=QEvent::MouseButtonPress) 334 if(e->type()!=QEvent::MouseButtonPress)
325 { // the KDatePicker only reacts on mouse press events: 335 { // the KDatePicker only reacts on mouse press events:
326 return; 336 return;
327 } 337 }
328 if(!isEnabled()) 338 if(!isEnabled())
329 { 339 {
330 KNotifyClient::beep(); 340 KNotifyClient::beep();
331 return; 341 return;
332 } 342 }
333 343
334 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; 344 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
335 // ----- 345 // -----
336 int row, col, pos, temp; 346 int row, col, pos, temp;
337 QPoint mouseCoord; 347 QPoint mouseCoord;
338 // ----- 348 // -----
339 mouseCoord = e->pos(); 349 mouseCoord = e->pos();
340 row=rowAt(mouseCoord.y()); 350 row=rowAt(mouseCoord.y());
341 col=columnAt(mouseCoord.x()); 351 col=columnAt(mouseCoord.x());
342 if(row<0 || col<0) 352 if(row<0 || col<0)
343 { // the user clicked on the frame of the table 353 { // the user clicked on the frame of the table
344 return; 354 return;
345 } 355 }
346 pos=7*(row-1)+col+1; 356 pos=7*(row-1)+col+1;
347#if 0 357#if 0
348 if(pos+dayoff<=firstday) 358 if(pos+dayoff<=firstday)
349 { // this day is in the previous month 359 { // this day is in the previous month
350 KNotifyClient::beep(); 360 KNotifyClient::beep();
351 return; 361 return;
352 } 362 }
353 if(firstday+numdays<pos+dayoff) 363 if(firstday+numdays<pos+dayoff)
354 { // this date is in the next month 364 { // this date is in the next month
355 KNotifyClient::beep(); 365 KNotifyClient::beep();
356 return; 366 return;
357 } 367 }
358#endif 368#endif
359 temp=firstday+date.day()-dayoff-1; 369 temp=firstday+date.day()-dayoff-1;
360 QDate da = QDate(date.year(), date.month(),1); 370 QDate da = QDate(date.year(), date.month(),1);
361 setDate(da.addDays( pos-firstday+dayoff-1)); 371 setDate(da.addDays( pos-firstday+dayoff-1));
362 updateCell(temp/7+1, temp%7); // Update the previously selected cell 372 updateCell(temp/7+1, temp%7); // Update the previously selected cell
363 updateCell(row, col); // Update the selected cell 373 updateCell(row, col); // Update the selected cell
364 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 374 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
365 emit(tableClicked()); 375 emit(tableClicked());
366} 376}
367 377
368bool 378bool
369KDateTable::setDate(const QDate& date_) 379KDateTable::setDate(const QDate& date_)
370{ 380{
371 bool changed=false; 381 bool changed=false;
372 QDate temp; 382 QDate temp;
373 mMarkCurrent = false; 383 mMarkCurrent = false;
374 // ----- 384 // -----
375 if(!date_.isValid()) 385 if(!date_.isValid())
376 { 386 {
377 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; 387 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
378 return false; 388 return false;
379 } 389 }
380 if(date!=date_) 390 if(date!=date_)
381 { 391 {
382 date=date_; 392 date=date_;
383 changed=true; 393 changed=true;
384 } 394 }
385 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() ); 395 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() );
386 temp.setYMD(date.year(), date.month(), 1); 396 temp.setYMD(date.year(), date.month(), 1);
387 firstday=temp.dayOfWeek(); 397 firstday=temp.dayOfWeek();
388 if(firstday==1) firstday=8; 398 if(firstday==1) firstday=8;
389 numdays=date.daysInMonth(); 399 numdays=date.daysInMonth();
390 if(date.month()==1) 400 if(date.month()==1)
391 { // set to december of previous year 401 { // set to december of previous year
392 temp.setYMD(date.year()-1, 12, 1); 402 temp.setYMD(date.year()-1, 12, 1);
393 } else { // set to previous month 403 } else { // set to previous month
394 temp.setYMD(date.year(), date.month()-1, 1); 404 temp.setYMD(date.year(), date.month()-1, 1);
395 } 405 }
396 numDaysPrevMonth=temp.daysInMonth(); 406 numDaysPrevMonth=temp.daysInMonth();
397 if(changed) 407 if(changed)
398 { 408 {
399 repaintContents(false); 409 repaintContents(false);
400 } 410 }
401 emit(dateChanged(date)); 411 emit(dateChanged(date));
402 return true; 412 return true;
403} 413}
404 414
405const QDate& 415const QDate&
406KDateTable::getDate() const 416KDateTable::getDate() const
407{ 417{
408 return date; 418 return date;
409} 419}
410 420
411void KDateTable::focusInEvent( QFocusEvent *e ) 421void KDateTable::focusInEvent( QFocusEvent *e )
412{ 422{
413 repaintContents(false); 423 repaintContents(false);
414 QGridView::focusInEvent( e ); 424 QGridView::focusInEvent( e );
415} 425}
416 426
417void KDateTable::focusOutEvent( QFocusEvent *e ) 427void KDateTable::focusOutEvent( QFocusEvent *e )
418{ 428{
419 repaintContents(false); 429 repaintContents(false);
420 QGridView::focusOutEvent( e ); 430 QGridView::focusOutEvent( e );
421} 431}
422 432
423QSize 433QSize
424KDateTable::sizeHint() const 434KDateTable::sizeHint() const
425{ 435{
426 if(maxCell.height()>0 && maxCell.width()>0) 436 if(maxCell.height()>0 && maxCell.width()>0)
427 { 437 {
428 return QSize((maxCell.width()+2)*numCols()+2*frameWidth(), 438 return QSize((maxCell.width()+2)*numCols()+2*frameWidth(),
429 (maxCell.height()+4)*numRows()+2*frameWidth()); 439 (maxCell.height()+4)*numRows()+2*frameWidth());
430 } else { 440 } else {
431 return QSize(-1, -1); 441 return QSize(-1, -1);
432 } 442 }
433} 443}
434 444
435KDateInternalMonthPicker::KDateInternalMonthPicker 445KDateInternalMonthPicker::KDateInternalMonthPicker
436(int fontsize, QWidget* parent, const char* name) 446(int fontsize, QWidget* parent, const char* name)
437 : QGridView(parent, name), 447 : QGridView(parent, name),
438 result(0) // invalid 448 result(0) // invalid
439{ 449{
440 QRect rect; 450 QRect rect;
441 QFont font; 451 QFont font;
442 // ----- 452 // -----
443 activeCol = -1; 453 activeCol = -1;
444 activeRow = -1; 454 activeRow = -1;
445 font=KGlobalSettings::generalFont(); 455 font=KGlobalSettings::generalFont();
446 font.setPointSize(fontsize); 456 //font.setPointSize(fontsize);
447 setFont(font); 457 setFont(font);
448 setHScrollBarMode(AlwaysOff); 458 setHScrollBarMode(AlwaysOff);
449 setVScrollBarMode(AlwaysOff); 459 setVScrollBarMode(AlwaysOff);
450 setFrameStyle(QFrame::NoFrame); 460 setFrameStyle(QFrame::NoFrame);
451 setNumRows(4); 461 setNumRows(4);
452 setNumCols(3); 462 setNumCols(3);
453 // enable to find drawing failures: 463 // enable to find drawing failures:
454 // setTableFlags(Tbl_clipCellPainting); 464 // setTableFlags(Tbl_clipCellPainting);
455#if 0 465#if 0
456 viewport()->setEraseColor(lightGray); // for consistency with the datepicker 466 viewport()->setEraseColor(lightGray); // for consistency with the datepicker
457#endif 467#endif
458 // ----- find the preferred size 468 // ----- find the preferred size
459 // (this is slow, possibly, but unfortunatly it is needed here): 469 // (this is slow, possibly, but unfortunatly it is needed here):
460 QFontMetrics metrics(font); 470 QFontMetrics metrics(font);
461 for(int i=1; i <= 12; ++i) 471 for(int i=1; i <= 12; ++i)
462 { 472 {
463 rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); 473 rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false));
464 if(max.width()<rect.width()) max.setWidth(rect.width()); 474 if(max.width()<rect.width()) max.setWidth(rect.width());
465 if(max.height()<rect.height()) max.setHeight(rect.height()); 475 if(max.height()<rect.height()) max.setHeight(rect.height());
466 } 476 }
467 477
468} 478}
469 479
470QSize 480QSize
471KDateInternalMonthPicker::sizeHint() const 481KDateInternalMonthPicker::sizeHint() const
472{ 482{
473 return QSize((max.width()+6)*numCols()+2*frameWidth(), 483 return QSize((max.width()+6)*numCols()+2*frameWidth(),
474 (max.height()+6)*numRows()+2*frameWidth()); 484 (max.height()+6)*numRows()+2*frameWidth());
475} 485}
476 486
477int 487int
478KDateInternalMonthPicker::getResult() const 488KDateInternalMonthPicker::getResult() const
479{ 489{
480 return result; 490 return result;
481} 491}
482 492
483void 493void
484KDateInternalMonthPicker::setupPainter(QPainter *p) 494KDateInternalMonthPicker::setupPainter(QPainter *p)
485{ 495{
486 p->setPen(black); 496 p->setPen(black);
487} 497}
488 498
489void 499void
490KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*) 500KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*)
491{ 501{
492 setCellWidth(width()/3); 502 setCellWidth(width()/3);
493 setCellHeight(height()/4); 503 setCellHeight(height()/4);
494} 504}
495 505
496void 506void
497KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col) 507KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col)
498{ 508{
499 int index; 509 int index;
500 QString text; 510 QString text;
501 // ----- find the number of the cell: 511 // ----- find the number of the cell:
502 index=3*row+col+1; 512 index=3*row+col+1;
503 text=KGlobal::locale()->monthName(index, false); 513 text=KGlobal::locale()->monthName(index, false);
504 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); 514 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
505 if ( activeCol == col && activeRow == row ) 515 if ( activeCol == col && activeRow == row )
506 painter->drawRect( 0, 0, cellWidth(), cellHeight() ); 516 painter->drawRect( 0, 0, cellWidth(), cellHeight() );
507} 517}
508 518
509void 519void
510KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e) 520KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e)
@@ -700,150 +710,154 @@ KPopupFrame::resizeEvent(QResizeEvent*)
700 main->setGeometry(frameWidth(), frameWidth(), 710 main->setGeometry(frameWidth(), frameWidth(),
701 width()-2*frameWidth(), height()-2*frameWidth()); 711 width()-2*frameWidth(), height()-2*frameWidth());
702 } 712 }
703} 713}
704 714
705void 715void
706KPopupFrame::popup(const QPoint &pos) 716KPopupFrame::popup(const QPoint &pos)
707{ 717{
708 // Make sure the whole popup is visible. 718 // Make sure the whole popup is visible.
709 QRect d = QApplication::desktop()->frameGeometry(); 719 QRect d = QApplication::desktop()->frameGeometry();
710 int x = pos.x(); 720 int x = pos.x();
711 int y = pos.y(); 721 int y = pos.y();
712 int w = width(); 722 int w = width();
713 int h = height(); 723 int h = height();
714 if (x+w > d.x()+d.width()) 724 if (x+w > d.x()+d.width())
715 x = d.width() - w; 725 x = d.width() - w;
716 if (y+h > d.y()+d.height()) 726 if (y+h > d.y()+d.height())
717 y = d.height() - h; 727 y = d.height() - h;
718 if (x < d.x()) 728 if (x < d.x())
719 x = 0; 729 x = 0;
720 if (y < d.y()) 730 if (y < d.y())
721 y = 0; 731 y = 0;
722 732
723 // Pop the thingy up. 733 // Pop the thingy up.
724 move(x, y); 734 move(x, y);
725 show(); 735 show();
726} 736}
727 737
728int 738int
729KPopupFrame::exec(QPoint pos) 739KPopupFrame::exec(QPoint pos)
730{ 740{
731 popup(pos); 741 popup(pos);
732 repaint(); 742 repaint();
733 qApp->enter_loop(); 743 qApp->enter_loop();
734 hide(); 744 hide();
735 return result; 745 return result;
736} 746}
737 747
738int 748int
739KPopupFrame::exec(int x, int y) 749KPopupFrame::exec(int x, int y)
740{ 750{
741 return exec(QPoint(x, y)); 751 return exec(QPoint(x, y));
742} 752}
743 753
744void KPopupFrame::virtual_hook( int, void* ) 754void KPopupFrame::virtual_hook( int, void* )
745{ /*BASE::virtual_hook( id, data );*/ } 755{ /*BASE::virtual_hook( id, data );*/ }
746 756
747void KDateTable::virtual_hook( int, void* ) 757void KDateTable::virtual_hook( int, void* )
748{ /*BASE::virtual_hook( id, data );*/ } 758{ /*BASE::virtual_hook( id, data );*/ }
749 759
750//#include "kdatetbl.moc" 760//#include "kdatetbl.moc"
751 761
752 762
753KDateInternalWeekPicker::KDateInternalWeekPicker 763KDateInternalWeekPicker::KDateInternalWeekPicker
754(int fontsize, QWidget* parent, const char* name) 764(int fontsize, QWidget* parent, const char* name)
755 : QGridView(parent, name), 765 : QGridView(parent, name),
756 result(0) // invalid 766 result(0) // invalid
757{ 767{
758 QRect rect; 768 QRect rect;
759 QFont font; 769 QFont font;
760 // ----- 770 // -----
761 activeCol = -1; 771 activeCol = -1;
762 activeRow = -1; 772 activeRow = -1;
763 font=KGlobalSettings::generalFont(); 773 font=KGlobalSettings::generalFont();
764 font.setPointSize(fontsize); 774 //font.setPointSize(fontsize);
765 setFont(font); 775 setFont(font);
766 setHScrollBarMode(AlwaysOff); 776 setHScrollBarMode(AlwaysOff);
767 setVScrollBarMode(AlwaysOff); 777 setVScrollBarMode(AlwaysOff);
768 setFrameStyle(QFrame::NoFrame); 778 setFrameStyle(QFrame::NoFrame);
769 setNumRows(13); 779 setNumRows(13);
770 setNumCols(4); 780 setNumCols(4);
771 // enable to find drawing failures: 781 // enable to find drawing failures:
772 // setTableFlags(Tbl_clipCellPainting); 782 // setTableFlags(Tbl_clipCellPainting);
773#if 0 783#if 0
774 viewport()->setEraseColor(lightGray); // for consistency with the datepicker 784 viewport()->setEraseColor(lightGray); // for consistency with the datepicker
775#endif 785#endif
776 // ----- find the preferred size 786 // ----- find the preferred size
777 // (this is slow, possibly, but unfortunatly it is needed here): 787 // (this is slow, possibly, but unfortunatly it is needed here):
778 QFontMetrics metrics(font); 788 QFontMetrics metrics(font);
779 for(int i=1; i <= 52; ++i) 789 for(int i=1; i <= 52; ++i)
780 { 790 {
781 rect=metrics.boundingRect(QString::number( i )); 791 rect=metrics.boundingRect(QString::number( i ));
782 if(max.width()<rect.width()) max.setWidth(rect.width()); 792 if(max.width()<rect.width()) max.setWidth(rect.width());
783 if(max.height()<rect.height()) max.setHeight(rect.height()); 793 if(max.height()<rect.height()) max.setHeight(rect.height());
784 } 794 }
785 795 if ( QApplication::desktop()->width() > 640 ) {
796
797 max.setWidth(max.width()+6);
798 max.setHeight(max.height()+8);
799 }
786} 800}
787 801
788QSize 802QSize
789KDateInternalWeekPicker::sizeHint() const 803KDateInternalWeekPicker::sizeHint() const
790{ 804{
791 return QSize((max.width()+6)*numCols()+2*frameWidth(), 805 return QSize((max.width()+6)*numCols()+2*frameWidth(),
792 (max.height()+6)*numRows()+2*frameWidth()); 806 (max.height()+6)*numRows()+2*frameWidth());
793} 807}
794 808
795int 809int
796KDateInternalWeekPicker::getResult() const 810KDateInternalWeekPicker::getResult() const
797{ 811{
798 return result; 812 return result;
799} 813}
800 814
801void 815void
802KDateInternalWeekPicker::setupPainter(QPainter *p) 816KDateInternalWeekPicker::setupPainter(QPainter *p)
803{ 817{
804 p->setPen(black); 818 p->setPen(black);
805} 819}
806 820
807void 821void
808KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*) 822KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*)
809{ 823{
810 setCellWidth(width()/4); 824 setCellWidth(width()/4);
811 setCellHeight(height()/13); 825 setCellHeight(height()/13);
812} 826}
813 827
814void 828void
815KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col) 829KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col)
816{ 830{
817 int index; 831 int index;
818 QString text; 832 QString text;
819 // ----- find the number of the cell: 833 // ----- find the number of the cell:
820 index=4*row+col+1; 834 index=4*row+col+1;
821 text=QString::number( index ); 835 text=QString::number( index );
822 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); 836 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
823 if ( activeCol == col && activeRow == row ) 837 if ( activeCol == col && activeRow == row )
824 painter->drawRect( 0, 0, cellWidth(), cellHeight() ); 838 painter->drawRect( 0, 0, cellWidth(), cellHeight() );
825} 839}
826 840
827void 841void
828KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e) 842KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e)
829{ 843{
830 if(!isEnabled() || e->button() != LeftButton) 844 if(!isEnabled() || e->button() != LeftButton)
831 { 845 {
832 KNotifyClient::beep(); 846 KNotifyClient::beep();
833 return; 847 return;
834 } 848 }
835 // ----- 849 // -----
836 int row, col; 850 int row, col;
837 QPoint mouseCoord; 851 QPoint mouseCoord;
838 // ----- 852 // -----
839 mouseCoord = e->pos(); 853 mouseCoord = e->pos();
840 row=rowAt(mouseCoord.y()); 854 row=rowAt(mouseCoord.y());
841 col=columnAt(mouseCoord.x()); 855 col=columnAt(mouseCoord.x());
842 856
843 if(row<0 || col<0) 857 if(row<0 || col<0)
844 { // the user clicked on the frame of the table 858 { // the user clicked on the frame of the table
845 activeCol = -1; 859 activeCol = -1;
846 activeRow = -1; 860 activeRow = -1;
847 } else { 861 } else {
848 activeCol = col; 862 activeCol = col;
849 activeRow = row; 863 activeRow = row;