summaryrefslogtreecommitdiffabout
path: root/korganizer/calprintbase.cpp
Unidiff
Diffstat (limited to 'korganizer/calprintbase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calprintbase.cpp1304
1 files changed, 1304 insertions, 0 deletions
diff --git a/korganizer/calprintbase.cpp b/korganizer/calprintbase.cpp
new file mode 100644
index 0000000..af32ebc
--- a/dev/null
+++ b/korganizer/calprintbase.cpp
@@ -0,0 +1,1304 @@
1/*
2 This file is part of KOrganizer.
3
4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2003 Reinhold Kainhofer <reinhold@kainhofer.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution.
24*/
25
26#include <qpainter.h>
27#include <qlayout.h>
28#include <qframe.h>
29#include <qlabel.h>
30#include <qptrlist.h>
31#include <qintdict.h>
32#include <qfontmetrics.h>
33
34#include <kglobal.h>
35#include <klocale.h>
36#include <kdebug.h>
37#include <kconfig.h>
38#include <kcalendarsystem.h>
39#include <kprinter.h>
40
41#include <libkcal/todo.h>
42#include <libkcal/event.h>
43#include <libkcal/calendar.h>
44
45#include "koprefs.h"
46#include "koglobals.h"
47#ifndef KORG_NOPLUGINS
48#include "kocore.h"
49#endif
50#include "cellitem.h"
51
52#include "calprintbase.h"
53
54#ifndef KORG_NOPRINTER
55//#include "calprintbase.moc"
56
57int CalPrintBase::mHeaderHeight=90;
58int CalPrintBase::mSubHeaderHeight=20;
59int CalPrintBase::mMargin=36;
60
61
62
63class CalPrintBase::TodoParentStart
64{
65 public:
66 TodoParentStart( QRect pt = QRect(), bool page = true )
67 : mRect( pt ), mSamePage( page ) {}
68
69 QRect mRect;
70 bool mSamePage;
71};
72
73class PrintCellItem : public KOrg::CellItem
74{
75 public:
76 PrintCellItem( Event *event, const QDate &day )
77 : mEvent( event ), mDay( day )
78 {
79 }
80
81 Event *event() const { return mEvent; }
82
83 QString label() const { return mEvent->summary(); }
84
85 bool overlaps( KOrg::CellItem *o ) const
86 {
87 PrintCellItem *other = static_cast<PrintCellItem *>( o );
88
89 QDateTime start = event()->dtStart();
90 QDateTime end = event()->dtEnd();
91 if ( event()->doesRecur() ) {
92 start.setDate( mDay );
93 end.setDate( mDay );
94 }
95 QDateTime otherStart = other->event()->dtStart();
96 QDateTime otherEnd = other->event()->dtEnd();
97 if ( other->event()->doesRecur() ) {
98 otherStart.setDate( mDay );
99 otherEnd.setDate( mDay );
100 }
101
102#if 0
103 kdDebug() << "PrintCellItem::overlaps() " << event()->summary()
104 << " <-> " << other->event()->summary() << endl;
105 kdDebug() << " start : " << start.toString() << endl;
106 kdDebug() << " end : " << end.toString() << endl;
107 kdDebug() << " otherStart: " << otherStart.toString() << endl;
108 kdDebug() << " otherEnd : " << otherEnd.toString() << endl;
109#endif
110
111 return !( otherStart >= end || otherEnd <= start );
112 }
113
114 private:
115 Event *mEvent;
116 QDate mDay;
117};
118
119void setCategoryColors( QPainter &p, Incidence *incidence)
120{
121 QColor bgColor;
122 QStringList categories = incidence->categories();
123 QString cat = categories.first();
124 if (cat.isEmpty())
125 bgColor = KOPrefs::instance()->mEventColor;
126 else
127 bgColor = *(KOPrefs::instance()->categoryColor(cat));
128 QColor textColor = Qt::black;//getTextColor(bgColor);
129 p.setPen( textColor );
130 p.setBrush( bgColor );
131}
132
133
134
135CalPrintBase::CalPrintBase( KPrinter *printer, Calendar *cal, KConfig *cfg )
136 : QObject(), mPrinter( printer ), mCalendar( cal ), mConfig( cfg )
137{
138}
139
140CalPrintBase::~CalPrintBase()
141{
142}
143
144
145
146QWidget *CalPrintBase::configWidget( QWidget *w )
147{
148 QFrame *wdg = new QFrame( w );
149 QVBoxLayout *layout = new QVBoxLayout( wdg );
150
151 QLabel *title = new QLabel( description(), wdg );
152 QFont titleFont( title->font() );
153 titleFont.setPointSize( 20 );
154 titleFont.setBold( true );
155 title->setFont( titleFont );
156
157 layout->addWidget( title );
158 layout->addWidget( new QLabel( longDescription(), wdg ) );
159 layout->addSpacing( 20 );
160 layout->addWidget( new QLabel( i18n("This printing style does not "
161 "have any configuration options."),
162 wdg ) );
163 layout->addStretch();
164 return wdg;
165}
166#include <qapplication.h>
167void CalPrintBase::doPrint()
168{
169 QPainter p;
170
171 mPrinter->setColorMode( (mUseColors)?(KPrinter::Color):(KPrinter::GrayScale));
172 //#define DUMMY_PRINTER
173#ifdef DUMMY_PRINTER
174
175 static QWidget* dummy = 0;
176 if ( ! dummy )
177 dummy = new QWidget( );
178 else {
179 delete dummy;
180 dummy = new QWidget( );
181
182 }
183 dummy->resize( 1024, 1024 );
184 dummy->repaint();
185 dummy->show();
186 dummy->raise();
187 dummy->setBackgroundColor( Qt::white);
188 qApp->processEvents();
189 p.begin(dummy);
190#else
191 p.begin(mPrinter);
192#endif
193 // the painter initially begins at 72 dpi per the Qt docs.
194 // we want half-inch margins.
195 p.setViewport(mMargin, mMargin,
196 p.viewport().width()-mMargin,
197 p.viewport().height()-mMargin);
198 int pageWidth = p.viewport().width();
199 int pageHeight = p.viewport().height();
200
201 print(p, pageWidth, pageHeight);
202
203 p.end();
204}
205
206void CalPrintBase::doLoadConfig()
207{
208 if ( mConfig ) {
209 mConfig->setGroup(description());
210 //KConfigGroupSaver saver( mConfig, description() );
211 mConfig->sync();
212 QDateTime currDate( QDate::currentDate() );
213 mFromDate = mConfig->readDateTimeEntry( "FromDate", &currDate ).date();
214 mToDate = mConfig->readDateTimeEntry( "ToDate" ).date();
215 mUseColors = mConfig->readBoolEntry( "UseColors", false );
216 loadConfig();
217 } else {
218 qDebug("no config in CalPrintBase::doLoadConfig ");
219 }
220}
221
222void CalPrintBase::doSaveConfig()
223{
224 if ( mConfig ) {
225 mConfig->setGroup(description());
226 // KConfigGroupSaver saver( mConfig, description() );
227 saveConfig();
228 mConfig->writeEntry( "FromDate", QDateTime( mFromDate ) );
229 mConfig->writeEntry( "ToDate", QDateTime( mToDate ) );
230 mConfig->writeEntry( "UseColors", mUseColors );
231 mConfig->sync();
232 } else {
233 qDebug("no config in CalPrintBase::doSveConfig ");
234 }
235}
236
237///////////////////////////////////////////////////////////////////////////////
238
239void CalPrintBase::drawHeader( QPainter &p, QString title,
240 const QDate &month1, const QDate &month2,
241 int x, int y, int width, int height )
242{
243 p.drawRect(x, y, width, height);
244 // p.fillRect( x+1, y+1,
245// width-2,height-2,
246// QBrush(Dense7Pattern) );
247
248 QString myOwner(mCalendar->getOwner());
249
250 int right=x+width;
251
252 // print previous month for month view, print current for todo, day and week
253 int smallMonthWidth=width/4-10;
254 if (smallMonthWidth>100) smallMonthWidth=100;
255 if (month2.isValid()) {
256 right -= (10+smallMonthWidth);
257 drawSmallMonth(p, QDate(month2.year(), month2.month(), 1),
258 right, y+2, smallMonthWidth, height-4);
259 right-=10;
260 }
261 if (month1.isValid()) {
262 right -= (10+smallMonthWidth);
263 drawSmallMonth(p, QDate(month1.year(), month1.month(), 1),
264 right, y+2, smallMonthWidth, height-4);
265 right-=10;
266 }
267
268 // Print the titles...
269 QFont font("helvetica", 18, QFont::Bold);
270 p.setFont(font);
271 QRect textRect( x+5, y+5, right-10-x, height-10 );
272 p.drawText( textRect, Qt::AlignLeft | Qt::AlignTop | Qt::WordBreak, title );
273}
274
275
276void CalPrintBase::drawSmallMonth(QPainter &p, const QDate &qd,
277 int x, int y, int width, int height)
278{
279 bool firstCol = true;
280 QDate monthDate(QDate(qd.year(), qd.month(), 1));
281 QDate monthDate2;
282 int month = monthDate.month();
283
284 // draw the title
285 p.setFont(QFont("helvetica", 7, QFont::Bold));
286 // int lineSpacing = p.fontMetrics().lineSpacing();
287 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
288 p.drawText(x, y, width, height/4, AlignCenter, calSys->monthName( qd ) );
289
290 int cellWidth = width/7;
291 int cellHeight = height/8;
292 QString tmpStr;
293
294 // correct begin of week
295 int weekdayCol = weekdayColumn( qd.dayOfWeek() );
296 monthDate2 = monthDate.addDays(-weekdayCol);
297
298 // draw days of week
299 p.setFont(QFont("helvetica", 7, QFont::Bold));
300 for (int col = 0; col < 7; col++) {
301 // tmpStr.sprintf("%c",(const char*)monthDate2.dayName(monthDate2.dayOfWeek()));
302 tmpStr=calSys->weekDayName( monthDate2 )[0].upper();
303 p.drawText(x+col*cellWidth, y+height/4, cellWidth, cellHeight,
304 AlignCenter, tmpStr);
305 monthDate2 = monthDate2.addDays(1);
306 }
307
308 // draw separator line
309 p.drawLine(x, y+height/4+cellHeight, x+width, y+height/4+cellHeight);
310
311 for (int row = 0; row < 5; row++) {
312 for (int col = 0; col < 7; col++) {
313 if (monthDate.month() != month)
314 break;
315 if (firstCol) {
316 firstCol = true;
317 col = weekdayColumn( monthDate.dayOfWeek() );
318 }
319 p.drawText( x+col*cellWidth,
320 y+height/4+cellHeight+(row*cellHeight),
321 cellWidth, cellHeight, AlignCenter,
322 tmpStr.setNum(monthDate.day()) );
323 monthDate = monthDate.addDays(1);
324 }
325 }
326}
327
328
329///////////////////////////////////////////////////////////////////////////////
330
331/*
332 * This routine draws a header box over the main part of the calendar
333 * containing the days of the week.
334 */
335void CalPrintBase::drawDaysOfWeek(QPainter &p,
336 const QDate &fromDate, const QDate &toDate,
337 int x, int y, int width, int height)
338{
339 int cellWidth = width/(fromDate.daysTo( toDate )+1);
340 int currx=x;
341 QDate cellDate(fromDate);
342
343 while (cellDate<=toDate) {
344 drawDaysOfWeekBox(p, cellDate, currx, y, cellWidth, height);
345 currx+=cellWidth;
346 cellDate = cellDate.addDays(1);
347 }
348}
349
350
351void CalPrintBase::drawDaysOfWeekBox(QPainter &p, const QDate &qd,
352 int x, int y, int width, int height)
353{
354 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
355
356 p.setFont( QFont( "helvetica", 10, QFont::Bold ) );
357 p.drawRect( x, y, width, height );
358// p.fillRect( x+1, y+1,
359// width-2, height-2,
360// QBrush( Dense7Pattern ) );
361 p.drawText( x+5, y, width-10, height, AlignCenter | AlignVCenter,
362 calSys->weekDayName( qd ) );
363}
364
365
366void CalPrintBase::drawTimeLine(QPainter &p,
367 const QTime &fromTime, const QTime &toTime,
368 int x, int y, int width, int height)
369{
370 p.drawRect(x, y, width, height);
371
372 int totalsecs=fromTime.secsTo(toTime);
373 float minlen=(float)height*60./(float)totalsecs;
374 float cellHeight=(60.*(float)minlen);
375 float currY=y;
376
377 QTime curTime( fromTime );
378 QTime endTime( toTime );
379 if ( fromTime.minute() > 30 )
380 curTime = QTime( fromTime.hour()+1, 0, 0 );
381 else if ( fromTime.minute() > 0 ) {
382 curTime = QTime( fromTime.hour(), 30, 0 );
383 float yy = currY + minlen*(float)fromTime.secsTo( curTime )/60.;
384 p.drawLine( x+width/2, (int)yy, x+width, (int)yy );
385 curTime = QTime( fromTime.hour()+1, 0, 0 );
386 }
387 currY += ( fromTime.secsTo(curTime)*minlen/60 );
388
389 while ( curTime < endTime ) {
390 p.drawLine( x, (int)currY, x+width, (int)currY );
391 int newY=(int)(currY+cellHeight/2.);
392 QString numStr;
393 if (newY < y+height) {
394 p.drawLine(x+width/2, (int)newY, x+width, (int)newY);
395 // draw the time:
396 if ( !KGlobal::locale()->use12Clock() ) {
397 numStr.setNum(curTime.hour());
398 if (cellHeight > 30) {
399 p.setFont(QFont("helvetica", 16, QFont::Bold));
400 } else {
401 p.setFont(QFont("helvetica", 12, QFont::Bold));
402 }
403 p.drawText(x+2, (int)currY+2, width/2-2, (int)cellHeight,
404 AlignTop|AlignRight, numStr);
405 p.setFont(QFont("helvetica", 10, QFont::Normal));
406 p.drawText(x+width/2, (int)currY+2, width/2+2, (int)(cellHeight/2)-3,
407 AlignTop | AlignLeft, "00");
408 } else {
409 QTime time( curTime.hour(), 0 );
410 numStr = KGlobal::locale()->formatTime( time );
411 p.setFont(QFont("helvetica", 14, QFont::Bold));
412 p.drawText(x+2, (int)currY+2, width-4, (int)cellHeight/2-3,
413 AlignTop|AlignLeft, numStr);
414 }
415 currY+=cellHeight;
416 } // enough space for half-hour line and time
417 if (curTime.secsTo(endTime)>3600)
418 curTime=curTime.addSecs(3600);
419 else curTime=endTime;
420 } // currTime<endTime
421}
422
423
424///////////////////////////////////////////////////////////////////////////////
425
426/** prints the all-day box for the agenda print view. if expandable is set,
427 height is the cell height of a single cell, and the returned height will
428 be the total height used for the all-day events. If !expandable, only one
429 cell will be used, and multiple events are concatenated using ", ".
430*/
431void CalPrintBase::drawAllDayBox(QPainter &p, Event::List &eventList,
432 const QDate &qd, bool expandable,
433 int x, int y, int width, int &height)
434{
435 Event::List::Iterator it, itold;
436
437 int offset=y;
438
439 //p.setBrush(QBrush(Dense7Pattern));
440 QPen oldPen(p.pen());
441 QColor oldBgColor(p.backgroundColor());
442 QBrush oldBrush(p.brush());
443 QString multiDayStr;
444
445 it = eventList.begin();
446#ifndef KORG_NOPLUGINS
447 QString hstring(KOCore::self()->holiday(qd));
448 if (!hstring.isEmpty()) {
449 Event*holiday=new Event();
450 holiday->setDtStart(qd);
451 holiday->setDtEnd(qd);
452 holiday->setFloats(true);
453 holiday->setCategories(i18n("Holiday"));
454 eventList.prepend(holiday);
455 }
456#endif
457 Event *currEvent = 0;
458 // First, print all floating events
459 while( it!=eventList.end() ) {
460 currEvent=*it;
461 itold=it;
462 ++it;
463 if ( currEvent->doesFloat() ) {
464 // set the colors according to the categories
465 QString text = currEvent->summary() ;
466 if ( ! currEvent->location().isEmpty() )
467 text += " ("+currEvent->location()+")";
468 if (expandable) {
469 if (mUseColors)
470 setCategoryColors(p, currEvent);
471
472 p.drawRect( x, offset, width, height );
473
474 p.drawText( x+5, offset+5, width-10, height-10,
475 AlignCenter | AlignVCenter | AlignJustify | WordBreak,
476 text );
477 // reset the colors
478 p.setBrush( oldBrush );
479 p.setPen( oldPen );
480 p.setBackgroundColor(oldBgColor);
481
482 offset += height;
483 } else {
484 //if (!multiDayStr.isEmpty()) multiDayStr+=", ";
485 multiDayStr += text+"\n";
486 }
487 eventList.remove( itold );
488 }
489 }
490
491 if (!expandable) {
492 p.drawRect(x, offset, width, height);
493 if (!multiDayStr.isEmpty()) {
494 // p.fillRect(x+1, offset+1, width-2, height-2, QBrush(Dense5Pattern) );
495 p.drawText( x+5, offset+5, width-10, height-10,
496 AlignLeft | AlignTop | AlignJustify ,
497 multiDayStr);
498 }
499 } else {
500 height=offset-y;
501 }
502}
503
504
505void CalPrintBase::drawAgendaDayBox( QPainter &p, Event::List &events,
506 const QDate &qd, bool expandable,
507 QTime &fromTime, QTime &toTime,
508 int x, int y, int width, int height )
509{
510 p.drawRect( x, y, width, height );
511
512 Event *event;
513
514 if ( expandable ) {
515 // Adapt start/end times to include complete events
516 Event::List::ConstIterator it;
517 for ( it = events.begin(); it != events.end(); ++it ) {
518 event = *it;
519 if ( event->dtStart().time() < fromTime )
520 fromTime = event->dtStart().time();
521 if ( event->dtEnd().time() > toTime )
522 toTime = event->dtEnd().time();
523 }
524 }
525
526 // Show at least one hour
527 if ( fromTime.secsTo( toTime ) < 3600 ) {
528 fromTime = QTime( fromTime.hour(), 0, 0 );
529 toTime = fromTime.addSecs( 3600 );
530 }
531
532 // calculate the height of a cell and of a minute
533 int totalsecs = fromTime.secsTo( toTime );
534 float minlen = height * 60. / totalsecs;
535 float cellHeight = 60. * minlen;
536 float currY = y;
537
538 // print grid:
539 QTime curTime( QTime( fromTime.hour(), 0, 0 ) );
540 currY += fromTime.secsTo( curTime ) * minlen / 60;
541
542 while ( curTime < toTime && curTime.isValid() ) {
543 if ( currY > y ) p.drawLine( x, int( currY ), x + width, int( currY ) );
544 currY += cellHeight / 2;
545 if ( ( currY > y ) && ( currY < y + height ) ) {
546 QPen oldPen( p.pen() );
547 p.setPen( QColor( 192, 192, 192 ) );
548 p.drawLine( x, int( currY ), x + width, int( currY ) );
549 p.setPen( oldPen );
550 } // enough space for half-hour line
551 if ( curTime.secsTo( toTime ) > 3600 )
552 curTime = curTime.addSecs( 3600 );
553 else curTime = toTime;
554 currY += cellHeight / 2;
555 }
556
557 QDateTime startPrintDate = QDateTime( qd, fromTime );
558 QDateTime endPrintDate = QDateTime( qd, toTime );
559
560 // Calculate horizontal positions and widths of events taking into account
561 // overlapping events
562
563 QPtrList<KOrg::CellItem> cells;
564 cells.setAutoDelete( true );
565
566 Event::List::ConstIterator itEvents;
567 for( itEvents = events.begin(); itEvents != events.end(); ++itEvents ) {
568 cells.append( new PrintCellItem( *itEvents, qd ) );
569 }
570
571 QPtrListIterator<KOrg::CellItem> it1( cells );
572 for( it1.toFirst(); it1.current(); ++it1 ) {
573 KOrg::CellItem *placeItem = it1.current();
574
575 KOrg::CellItem::placeItem( cells, placeItem );
576 }
577
578 QPen oldPen = p.pen();
579 QColor oldBgColor = p.backgroundColor();
580 QBrush oldBrush = p.brush();
581
582 p.setFont( QFont( "helvetica", 10 ) );
583 //p.setBrush( QBrush( Dense7Pattern ) );
584
585 for( it1.toFirst(); it1.current(); ++it1 ) {
586 PrintCellItem *placeItem = static_cast<PrintCellItem *>( it1.current() );
587
588 drawAgendaItem( placeItem, p, qd, startPrintDate, endPrintDate, minlen, x,
589 y, width );
590
591 p.setBrush( oldBrush );
592 p.setPen( oldPen );
593 p.setBackgroundColor( oldBgColor );
594 }
595
596 p.setBrush( QBrush( NoBrush ) );
597}
598
599
600void CalPrintBase::drawAgendaItem( PrintCellItem *item, QPainter &p,
601 const QDate &qd,
602 const QDateTime &startPrintDate,
603 const QDateTime &endPrintDate,
604 float minlen, int x, int y, int width )
605{
606 Event *event = item->event();
607
608 // set the colors according to the categories
609 if ( mUseColors ) setCategoryColors( p, event );
610 else p.setBrush( Qt::white );
611 // start/end of print area for event
612 QDateTime startTime = event->dtStart();
613 QDateTime endTime = event->dtEnd();
614 if ( event->doesRecur() ) {
615 startTime.setDate( qd );
616 endTime.setDate( qd );
617 }
618 if ( ( startTime < endPrintDate && endTime > startPrintDate ) ||
619 ( endTime > startPrintDate && startTime < endPrintDate ) ) {
620 if ( startTime < startPrintDate ) startTime = startPrintDate;
621 if ( endTime > endPrintDate ) endTime = endPrintDate;
622 int eventLength = int( startTime.secsTo( endTime ) / 60. * minlen );
623 int currentyPos = int( y + startPrintDate.secsTo( startTime ) *
624 minlen / 60. );
625 int currentWidth = width / item->subCells();
626 int currentX = x + item->subCell() * currentWidth;
627 QString text = KGlobal::locale()->formatTime(event->dtStart().time())+
628 "-"+KGlobal::locale()->formatTime(event->dtEnd().time())+
629 " "+event->summary();
630 if ( !event->location().isEmpty() )
631 text += " (" +event->location()+")";
632 // p.save();
633 QPen pe = p.pen();
634 pe.setWidth( 2 );
635 p.setPen( pe );
636 p.drawRect( currentX, currentyPos+1, currentWidth+1, eventLength+1 );
637 p.drawText( currentX+3, currentyPos+2, currentWidth-5, eventLength-3,
638 AlignLeft | AlignTop | AlignJustify | WordBreak,
639 text);
640 // p.restore();
641 }
642}
643
644void CalPrintBase::drawDayBox(QPainter &p, const QDate &qd,
645 int x, int y, int width, int height,
646 bool fullDate)
647{
648 QString dayNumStr;
649 QString ampm;
650 const KLocale*local = KGlobal::locale();
651
652
653 // This has to be localized
654 if (fullDate) {
655 /*int index;
656 dayNumStr= qd.toString();
657 index = dayNumStr.find(' ');
658 dayNumStr.remove(0, index);
659 index = dayNumStr.findRev(' ');
660 dayNumStr.truncate(index);*/
661
662 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
663 dayNumStr = i18n("weekday month date", "%1 %2 %3")
664 .arg( calSys->weekDayName( qd ) )
665 .arg( calSys->monthName( qd ) )
666 .arg( qd.day() );
667// dayNumStr = local->formatDate(qd);
668 } else {
669 dayNumStr = QString::number( qd.day() );
670 }
671
672 p.eraseRect( x, y, width, height );
673 p.drawRect( x, y, width, height );
674 // p.fillRect( x+1, y+1, width-2,height, QBrush(Dense7Pattern) );
675 p.drawRect( x, y, width, mSubHeaderHeight );
676 //p.fillRect( x+1, y+1, width-2, mSubHeaderHeight-2, QBrush(Dense7Pattern) );
677 QString hstring;
678#ifndef KORG_NOPLUGINS
679 hstring=KOCore::self()->holiday(qd);
680#endif
681
682 if (!hstring.isEmpty()) {
683 p.setFont( QFont( "helvetica", 8, QFont::Bold, true ) );
684
685 p.drawText( x+5, y, width-25, mSubHeaderHeight, AlignLeft | AlignVCenter,
686 hstring );
687 }
688 p.setFont(QFont("helvetica", 10, QFont::Bold));
689 p.drawText(x+5, y, width-10, mSubHeaderHeight, AlignRight | AlignVCenter,
690 dayNumStr);
691 Event::List eventList;
692 eventList.fill( mCalendar->events( qd, true ));
693 Todo::List todos;
694 todos.fill( mCalendar->todos( qd ));
695 QString outStr;
696 p.setFont( QFont( "helvetica", 8 ) );
697 int lineSpacing = p.fontMetrics().lineSpacing();
698
699 int textY=mSubHeaderHeight+3; // gives the relative y-coord of the next printed entry
700 Event::List::ConstIterator it;
701 int entryCount = eventList.count() +todos.count();
702 if ( p.fontMetrics().lineSpacing()* entryCount > height-textY ) {
703 if ( (p.fontMetrics().lineSpacing()-1) * entryCount > height-textY ) {
704 p.setFont( QFont( "helvetica", 7 ) );
705 if ( (p.fontMetrics().lineSpacing()-1) * entryCount > height-textY )
706 p.setFont( QFont( "helvetica", 6 ) );
707 }
708 lineSpacing = p.fontMetrics().lineSpacing()-1;
709 }
710 // qDebug("fm %d %d %d ",p.fontMetrics().height(), eventList.count() , height-textY );
711 for( it = eventList.begin(); it != eventList.end() && textY<height; ++it ) {
712 Event *currEvent = *it;
713 if (currEvent->doesFloat() || currEvent->isMultiDay())
714 outStr = currEvent->summary();
715
716 else {
717 if ( fullDate ) {
718 outStr = KGlobal::locale()->formatTime( currEvent->dtStart().time())+
719 "-"+KGlobal::locale()->formatTime( currEvent->dtEnd().time())+
720 " "+ currEvent->summary();
721 if ( ! currEvent->location().isEmpty() )
722 outStr += " (" + currEvent->location()+")";
723 } else {
724 QTime t1 = currEvent->dtStart().time();
725
726 outStr = local->formatTime(t1);
727 outStr += " " + currEvent->summary();
728 }
729
730 } // doesFloat
731
732 p.drawText(x+5, y+textY, width-10, lineSpacing,
733 AlignLeft|AlignBottom, outStr);
734 textY+=lineSpacing;
735 }
736
737 if ( textY<height ) {
738
739 Todo::List::ConstIterator it2;
740 for( it2 = todos.begin(); it2 != todos.end() && textY<height; ++it2 ) {
741 Todo *todo = *it2;
742 QString text;
743 if (todo->hasDueDate()) {
744 if (!todo->doesFloat()) {
745 text += KGlobal::locale()->formatTime(todo->dtDue().time());
746 text += " ";
747 }
748 }
749 text += i18n("To-Do: %1").arg(todo->summary());
750
751 p.drawText(x+5, y+textY, width-10, lineSpacing,
752 AlignLeft|AlignBottom, text);
753 textY+=lineSpacing;
754 }
755 }
756}
757
758
759///////////////////////////////////////////////////////////////////////////////
760
761void CalPrintBase::drawWeek(QPainter &p, const QDate &qd,
762 int x, int y, int width, int height)
763{
764 QDate weekDate = qd;
765 bool portrait = ( mPrinter->orientation() == KPrinter::Portrait );
766 int cellWidth, cellHeight;
767 int vcells;
768 if (portrait) {
769 cellWidth = width/2;
770 vcells=3;
771 } else {
772 cellWidth = width/6;
773 vcells=1;
774 }
775 cellHeight = height/vcells;
776
777 // correct begin of week
778 int weekdayCol = weekdayColumn( qd.dayOfWeek() );
779 weekDate = qd.addDays( -weekdayCol );
780
781 for (int i = 0; i < 7; i++, weekDate = weekDate.addDays(1)) {
782 if (i<5) {
783 drawDayBox(p, weekDate, x+cellWidth*(int)(i/vcells), y+cellHeight*(i%vcells),
784 cellWidth, cellHeight, true);
785 } else if (i==5) {
786 drawDayBox(p, weekDate, x+cellWidth*(int)(i/vcells), y+cellHeight*(i%vcells),
787 cellWidth, cellHeight/2, true);
788 } else if (i==6) {
789 drawDayBox(p, weekDate, x+cellWidth*(int)((i-1)/vcells),
790 y+cellHeight*((i-1)%vcells)+cellHeight/2, cellWidth, cellHeight/2, true);
791 }
792 } // for i through all weekdays
793}
794
795
796void CalPrintBase::drawTimeTable(QPainter &p,
797 const QDate &fromDate, const QDate &toDate,
798 QTime &fromTime, QTime &toTime,
799 int x, int y, int width, int height)
800{
801 // timeline is 1.5 hours:
802 int alldayHeight = (int)( 3600.*height/(fromTime.secsTo(toTime)+3600.) );
803 int timelineWidth = 60;
804 int cellWidth = (int)( (width-timelineWidth)/(fromDate.daysTo(toDate)+1) );
805 int currY=y;
806 int currX=x;
807
808 drawDaysOfWeek( p, fromDate, toDate, x+timelineWidth, currY, width-timelineWidth, mSubHeaderHeight);
809 currY+=mSubHeaderHeight;
810 drawTimeLine( p, fromTime, toTime, x, currY+alldayHeight,
811 timelineWidth, height-mSubHeaderHeight-alldayHeight );
812
813 currX=x+timelineWidth;
814 // draw each day
815 QDate curDate(fromDate);
816 while (curDate<=toDate) {Event::List eventList;
817 eventList.fill( mCalendar->events(curDate, true));
818 drawAllDayBox( p, eventList, curDate, false, currX, currY, cellWidth, alldayHeight);
819 drawAgendaDayBox( p, eventList, curDate, false, fromTime, toTime, currX,
820 currY+alldayHeight, cellWidth, height-mSubHeaderHeight-alldayHeight );
821 currX+=cellWidth;
822 curDate=curDate.addDays(1);
823 }
824
825}
826
827
828///////////////////////////////////////////////////////////////////////////////
829
830void CalPrintBase::drawMonth(QPainter &p, const QDate &qd, bool weeknumbers,
831 int x, int y, int width, int height)
832{
833
834 int yoffset = mSubHeaderHeight;
835 int xoffset = 0;
836
837 QDate monthDate(QDate(qd.year(), qd.month(), 1));
838 QDate monthFirst(monthDate);
839 QDate monthLast(monthDate.addMonths(1).addDays(-1));
840
841
842 int weekdayCol = weekdayColumn( monthDate.dayOfWeek() );
843 monthDate = monthDate.addDays(-weekdayCol);
844
845 int rows=(weekdayCol + qd.daysInMonth() - 1)/7 +1;
846 int cellHeight = (height-yoffset) / rows;
847
848 if (weeknumbers) {
849 QFont oldFont(p.font());
850 QFont newFont(p.font());
851 newFont.setPointSize(7);
852 p.setFont(newFont);
853 xoffset += 18;
854 QDate weekDate(monthDate);
855 for (int row = 0; row<rows; row++) {
856 int calWeek = weekDate.weekNumber();
857 QRect rc(x, y+yoffset+cellHeight*row, xoffset-1, cellHeight);
858 p.drawText( rc, AlignRight|AlignVCenter, QString::number(calWeek) );
859 weekDate = weekDate.addDays(7);
860 }
861 p.setFont(oldFont);
862 }
863
864 drawDaysOfWeek( p, monthDate, monthDate.addDays(6), x+xoffset, y, width-xoffset, mSubHeaderHeight );
865 int cellWidth = (width-xoffset) / 7;
866
867 QColor back = p.backgroundColor();
868 bool darkbg = false;
869 for (int row = 0; row < rows; row++) {
870 for (int col = 0; col < 7; col++) {
871 // show days from previous/next month with a grayed background
872 if ( (monthDate < monthFirst) || (monthDate > monthLast) ) {
873 p.setBackgroundColor( QColor( 240, 240, 240) );
874 darkbg = true;
875 }
876 drawDayBox(p, monthDate, x+xoffset+col*cellWidth, y+yoffset+row*cellHeight, cellWidth, cellHeight);
877 if ( darkbg ) {
878 p.setBackgroundColor( back );
879 darkbg = false;
880 }
881 monthDate = monthDate.addDays(1);
882 }
883 }
884}
885
886
887///////////////////////////////////////////////////////////////////////////////
888
889void CalPrintBase::drawTodo( bool completed, int &count, Todo * item, QPainter &p, bool connectSubTodos,
890 bool desc, int pospriority, int possummary, int posDueDt, int level,
891 int x, int &y, int width, int &height, int pageHeight,
892 TodoParentStart *r )
893{
894 if ( !completed && item->isCompleted() )
895 return;
896 QString outStr;
897// int fontHeight = 10;
898 const KLocale *local = KGlobal::locale();
899 int priority=item->priority();
900 int posdue=posDueDt;
901 if (posdue<0) posdue=x+width;
902 QRect rect;
903 TodoParentStart startpt;
904 // This list keeps all starting points of the parent todos so the connection
905 // lines of the tree can easily be drawn (needed if a new page is started)
906 static QPtrList<TodoParentStart> startPoints;
907 if (level<1) {
908 startPoints.clear();
909 }
910
911 // size of item
912 outStr=item->summary();
913 if ( ! item->location().isEmpty() )
914 outStr += " ("+item->location()+")";
915 if ( item->hasDueDate() && posDueDt>=0 ) {
916 outStr += " [" +local->formatDate(item->dtDue().date(),true)+"]";
917 }
918 int left = possummary+(level*10);
919 rect = p.boundingRect(left, y, (posdue-left-5),-1, WordBreak, outStr);
920 if ( !item->description().isEmpty() && !desc ) {
921 outStr = item->description();
922 rect = p.boundingRect( left+20, rect.bottom()+5, width-(left+10-x), -1,
923 WordBreak, outStr );
924 }
925 // if too big make new page
926 if ( rect.bottom() > y+height) {
927 // first draw the connection lines from parent todos:
928 if (level > 0 && connectSubTodos) {
929 TodoParentStart *rct;
930 for ( rct = startPoints.first(); rct; rct = startPoints.next() ) {
931 int start;
932 int center = rct->mRect.left() + (rct->mRect.width()/2);
933 int to = p.viewport().bottom();
934
935 // draw either from start point of parent or from top of the page
936 if (rct->mSamePage)
937 start = rct->mRect.bottom() + 1;
938 else
939 start = p.viewport().top();
940 p.moveTo( center, start );
941 p.lineTo( center, to );
942 rct->mSamePage=false;
943 }
944 }
945 y=0;
946 height=pageHeight-y;
947 mPrinter->newPage();
948 }
949
950 // If this is a sub-item, r will not be 0, and we want the LH side of the priority line up
951 //to the RH side of the parent item's priority
952 if (r && pospriority >= 0 ) {
953 pospriority = r->mRect.right() + 1;
954 }
955
956 // Priority
957 outStr.setNum(priority);
958 rect = p.boundingRect(pospriority, y + 10, 5, -1, AlignCenter, outStr);
959 // Make it a more reasonable size
960 rect.setWidth(19);
961 rect.setHeight(19);
962 if ( priority > 0 && pospriority>=0 ) {
963 p.drawText(rect, AlignCenter, outStr);
964 p.drawRect(rect);
965 // cross out the rectangle for completed items
966 if ( item->isCompleted() ) {
967 p.drawLine( rect.topLeft(), rect.bottomRight() );
968 p.drawLine( rect.topRight(), rect.bottomLeft() );
969 }
970 }
971 startpt.mRect = rect; //save for later
972
973 // Connect the dots
974 if (level > 0 && connectSubTodos) {
975 int bottom;
976 int center( r->mRect.left() + (r->mRect.width()/2)+1 );
977 if (r->mSamePage )
978 bottom = r->mRect.bottom();//lutz + 1;
979 else
980 bottom = 0;
981 int to( rect.top() + (rect.height()/2)+1 );
982 int endx( rect.left() );
983 p.moveTo(center, bottom);
984 p.lineTo(center, to);
985 p.lineTo(endx, to);
986 }
987
988 // if completed, use strike out font
989 QFont ft=p.font();
990 ft.setStrikeOut( item->isCompleted() );
991 p.setFont( ft );
992 // summary
993 outStr=item->summary();
994 if ( ! item->location().isEmpty() )
995 outStr += " ("+item->location()+")";
996 if ( item->hasDueDate() && posDueDt>=0 ) {
997 outStr += " [" +local->formatDate(item->dtDue().date(),true)+"]";
998 }
999 rect = p.boundingRect( left, rect.top(), (posdue-(left + rect.width() + 5)),
1000 -1, WordBreak, outStr);
1001 QRect newrect;
1002 p.drawText( rect, WordBreak, outStr, -1, &newrect );
1003 ft.setStrikeOut(false);
1004 p.setFont(ft);
1005
1006 // due
1007 // if ( item->hasDueDate() && posDueDt>=0 ) {
1008// outStr = local->formatDate(item->dtDue().date(),true);
1009// rect = p.boundingRect(posdue, y, x+width, -1, AlignTop|AlignLeft, outStr);
1010// p.drawText(rect, AlignTop|AlignLeft, outStr);
1011// }
1012
1013 if ( !item->description().isEmpty() && desc ) {
1014 y=newrect.bottom() + 5;
1015 outStr = item->description();
1016 rect = p.boundingRect( left+20, y, x+width-(left+10), -1,
1017 WordBreak, outStr );
1018 p.drawText( rect, WordBreak, outStr, -1, &newrect );
1019 }
1020
1021 // Set the new line position
1022 y=newrect.bottom() + 10; //set the line position
1023
1024 // If the item has subitems, we need to call ourselves recursively
1025 Incidence::List l;l.fill( item->relations());
1026 Incidence::List::ConstIterator it;
1027 startPoints.append( &startpt );
1028 for( it = l.begin(); it != l.end(); ++it ) {
1029 count++;
1030 drawTodo( completed, count, static_cast<Todo *>( *it ), p, connectSubTodos,
1031 desc, pospriority, possummary, posDueDt, level+1,
1032 x, y, width, height, pageHeight, &startpt);
1033 }
1034 startPoints.remove(&startpt);
1035}
1036
1037int CalPrintBase::weekdayColumn( int weekday )
1038{
1039 return ( weekday + 7 - KGlobal::locale()->weekStartDay() ) % 7;
1040}
1041
1042void CalPrintBase::drawSplitWeek( QPainter &p, const QDate &fd,
1043 const QDate &td )
1044{
1045 QDate curDay, fromDay, toDay, curWeek, fromWeek, toWeek;
1046
1047 mPrinter->setOrientation(KPrinter::Portrait);
1048
1049 int minus = 0;
1050 if (KGlobal::locale()->weekStartsMonday()) {
1051 // correct to monday
1052 fromWeek = fd.addDays(-(fd.dayOfWeek()-1));
1053 // correct to sunday
1054 toWeek = td.addDays(7-fd.dayOfWeek());
1055 minus = 1;
1056 } else {
1057 // correct to sunday
1058 fromWeek = fd.addDays(-(fd.dayOfWeek()%7));
1059 // correct to saturday
1060 toWeek = td.addDays(6-td.dayOfWeek());
1061 }
1062
1063 fromDay = fd;
1064 curDay = fd;
1065 toDay = td;
1066 p.setFont( QFont("Helvetica") );
1067 // the painter initially begins at 72 dpi per the Qt docs.
1068 int pageWidth = p.viewport().width();
1069 int pageHeight = p.viewport().height();
1070 int margin=0;
1071 mHeaderHeight = 110;
1072 mSubHeaderHeight = 20;
1073
1074 p.setViewport(margin, margin,
1075 p.viewport().width()-margin,
1076 p.viewport().height()-margin);
1077
1078 curWeek = fromWeek.addDays(6);
1079
1080 int columnWidth = int( pageWidth / 4.5 );
1081
1082 do {
1083
1084 // if ( (curDay.dayOfWeek()-1)%7 < 3 )
1085 switch((curDay.dayOfWeek()-minus)%7){
1086 case 0:
1087 drawSplitTimes( p, pageWidth, columnWidth, pageHeight );
1088 drawSplitDay( p, curDay, columnWidth, pageHeight,
1089 int( columnWidth * 0.5 ) );
1090 break;
1091 case 1:
1092 drawSplitDay( p, curDay, columnWidth, pageHeight,
1093 int( columnWidth * 1.5 ) );
1094 break;
1095 case 2:
1096 drawSplitDay( p, curDay, columnWidth, pageHeight,
1097 int( columnWidth * 2.5 ) );
1098 break;
1099 case 3:
1100 drawSplitDay( p, curDay, columnWidth, pageHeight,
1101 int( columnWidth * 3.5 ) );
1102 mPrinter->newPage();
1103 break;
1104 case 4:
1105 drawSplitTimes( p, int( pageWidth * ( 3.5/ 4.5 ) ), columnWidth,
1106 pageHeight );
1107 drawSplitDay( p, curDay, columnWidth, pageHeight,
1108 int( columnWidth * 0.5 ) );
1109 drawSplitHeaderRight( p, curWeek.addDays( -6 ), curWeek,
1110 curWeek, pageWidth, mHeaderHeight );
1111 break;
1112 case 5:
1113 drawSplitDay( p, curDay, columnWidth, pageHeight,
1114 int( columnWidth * 1.5 ) );
1115 break;
1116 case 6:
1117 drawSplitDay( p, curDay, columnWidth, pageHeight,
1118 int( columnWidth * 2.5 ) );
1119 if ( curDay < toDay )
1120 mPrinter->newPage();
1121 curWeek = curWeek.addDays( 7 );
1122 break;
1123 }
1124 curDay = curDay.addDays(1);
1125
1126 } while (curDay <= toDay);
1127
1128}
1129
1130void CalPrintBase::drawSplitHeaderRight( QPainter &p, const QDate &fd,
1131 const QDate &td,
1132 const QDate &,
1133 int width, int )
1134{
1135 int tempStore = mSubHeaderHeight;
1136 mSubHeaderHeight+= mSubHeaderHeight;
1137 KLocale *local = KGlobal::locale();
1138 QFont font("helvetica", 18, QFont::Bold);
1139 QPen penA( black,0);
1140 QPen penB( black,3);
1141 p.setFont(font);
1142 int lineSpacing = p.fontMetrics().lineSpacing();
1143 QString title;
1144 QString myOwner(mCalendar->getOwner());
1145 if ( fd.month() == td.month() ) {
1146 title = local->monthName(fd.month(), false) + ' ' + QString::number(fd.day()) + ' '
1147 + '-' + ' ' + QString::number(td.day());
1148 } else {
1149 title = local->monthName(fd.month(), false) + ' ' + QString::number(fd.day()) + ' '
1150 + '-' + ' ' + local->monthName(td.month(), false) + ' ' + QString::number(td.day());
1151 }
1152
1153// Grrrrrrr! why can't I set the font to a serif font?!?!?
1154 QFont serifFont("Helvetica", 30);
1155// serifFont.setFamily("Serif");
1156// serifFont.setWeight(87);
1157// serifFont.setItalic(true);
1158 p.setFont(serifFont);
1159 QFontInfo info(p.font());
1160
1161 lineSpacing = p.fontMetrics().lineSpacing();
1162 p.drawText(0, lineSpacing * 0, width, lineSpacing, AlignRight |AlignTop, title );
1163
1164 title.truncate(0);
1165
1166 p.setPen(penB );
1167 p.drawLine(200, lineSpacing * 1, width, lineSpacing * 1);
1168 p.setPen(penA );
1169
1170 p.setFont(QFont("Helvetica", 20, QFont::Bold, TRUE));
1171 title += QString::number(fd.year());
1172 p.drawText(0, lineSpacing * 1, width, lineSpacing, AlignRight |AlignTop, title );
1173 mSubHeaderHeight = tempStore ;
1174}
1175
1176void CalPrintBase::drawSplitDay( QPainter &p, const QDate &qd, int width,
1177 int height, int offsetLeft )
1178{
1179 int tempStore = mSubHeaderHeight;
1180 mSubHeaderHeight+= mSubHeaderHeight;
1181 int startHour = KOPrefs::instance()->mDayBegins;
1182 int endHour = 20;
1183 int offset = mHeaderHeight + mSubHeaderHeight + 10;
1184 Event::List eventList; eventList.fill( mCalendar->events( qd, true ));
1185 Event::List::Iterator it;
1186 Event *currEvent;
1187 KLocale *local = KGlobal::locale();
1188 QString dayName;
1189
1190 dayName = local->weekDayName(qd.dayOfWeek()) + ' ' + ' ' + QString::number(qd.day());
1191 //p.setBrush(QBrush(black));
1192// width+1 to make sure there's a continuous, black bar across the top.
1193 p.setPen( QPen(Qt::black,2));
1194 p.drawRect(offsetLeft, mHeaderHeight + 5, width +1, mSubHeaderHeight);
1195 p.setPen( Qt::black);
1196 p.setFont(QFont("helvetica", 12, QFont::Bold, true));
1197 p.drawText(offsetLeft, mHeaderHeight + 5,
1198 width, mSubHeaderHeight, AlignHCenter | AlignVCenter,
1199 dayName);
1200
1201 p.setPen( QPen(Qt::black,2));
1202 p.setFont(QFont("helvetica", 12));
1203 p.setBrush(Qt::white);
1204 it = eventList.begin();
1205 int allDays = 0;
1206 /*
1207 while( it != eventList.end() ) {
1208 Event *currEvent = *it;
1209 if ( currEvent->doesFloat() ) {
1210 p.drawRect( offsetLeft, offset, width, 35 );
1211 p.drawText( offsetLeft + 5, offset + 10, width - 10, 30,
1212 AlignLeft | AlignTop, currEvent->summary() );
1213 offset += 40;
1214 allDays++;
1215 it = eventList.remove( it );
1216 } else {
1217 ++it;
1218 }
1219 }
1220 */
1221 //p.setBrush(QBrush());
1222 int tmpEnd;
1223 for ( it = eventList.begin(); it != eventList.end(); ++it ) {
1224 Event *currEvent = *it;
1225 tmpEnd = currEvent->dtEnd().time().hour();
1226 if (currEvent->dtEnd().time().minute() > 0)
1227 tmpEnd++;
1228 if (tmpEnd > endHour)
1229 endHour = tmpEnd;
1230 }
1231 int hours = endHour - startHour;
1232 int cellHeight = (height-offset) / hours; // hour increments.
1233
1234 p.setFont(QFont("helvetica", 12));
1235 //p.setBrush(QBrush(Dense7Pattern));
1236 p.setBrush(Qt::white);
1237 for ( it = eventList.begin(); it != eventList.end(); ++it ) {
1238 Event *currEvent = *it;
1239 int startTime = currEvent->dtStart().time().hour();
1240 int endTime = currEvent->dtEnd().time().hour();
1241 float minuteInc = cellHeight / 60.0;
1242 if ((startTime >= startHour) && (endTime <= (startHour + hours))) {
1243 startTime -= startHour;
1244 int startMinuteOff = (int) (minuteInc *
1245 currEvent->dtStart().time().minute());
1246 QString text = currEvent->summary() ;
1247 if ( ! currEvent->location().isEmpty() )
1248 text += "\n("+currEvent->location()+")";
1249 int endMinuteOff = (int) (minuteInc * currEvent->dtEnd().time().minute());
1250 int cheight = (int) (minuteInc *
1251 currEvent->dtStart().secsTo(currEvent->dtEnd()) / 60 );
1252 p.drawRect(offsetLeft+2, 1+offset+startMinuteOff+startTime*cellHeight,
1253 width-4, cheight);
1254 p.drawText(offsetLeft+12, offset+startMinuteOff+startTime*cellHeight+5, width-24,
1255 cheight-10, AlignHCenter | AlignTop, text);
1256 }
1257 }
1258 p.setBrush(QBrush(NoBrush));
1259 mSubHeaderHeight = tempStore ;
1260}
1261
1262void CalPrintBase::drawSplitTimes( QPainter &p, int width, int timeWidth,
1263 int height )
1264{
1265 int tempStore = mSubHeaderHeight;
1266 mSubHeaderHeight+= mSubHeaderHeight;
1267 int startHour = KOPrefs::instance()->mDayBegins;
1268 int endHour = 20;
1269 int offset = mHeaderHeight + mSubHeaderHeight + 10;
1270 int hours = endHour - startHour;
1271 int cellHeight = (height-offset) / hours; // hour increments.
1272
1273 QString numStr;
1274 for (int i = 0; i < hours; i++) {
1275 p.setPen(QPen(black,1));
1276 p.drawLine(0, offset+i*cellHeight, width, offset+i*cellHeight);
1277 p.setPen(QPen(gray,0));
1278 p.drawLine(37, offset+i*cellHeight+(cellHeight/2),
1279 width, offset+i*cellHeight+(cellHeight/2));
1280 p.setPen(QPen(black,0));
1281
1282 if ( !KGlobal::locale()->use12Clock() ) {
1283 numStr.setNum(i+startHour);
1284 if (cellHeight > 40) {
1285 p.setFont(QFont("helvetica", 16, QFont::Bold));
1286 } else {
1287 p.setFont(QFont("helvetica", 14, QFont::Bold));
1288 }
1289 p.drawText(0, offset+i*cellHeight, 33, cellHeight/2,
1290 AlignTop|AlignRight, numStr);
1291 p.setFont(QFont("helvetica", 12, QFont::Bold));
1292 p.drawText(37, offset+i*cellHeight, 45, cellHeight/2,
1293 AlignTop | AlignLeft, "00");
1294 } else {
1295 QTime time( i + startHour, 0 );
1296 numStr = KGlobal::locale()->formatTime( time );
1297 p.setFont(QFont("helvetica", 12, QFont::Bold));
1298 p.drawText(4, offset+i*cellHeight, 70, cellHeight/2,
1299 AlignTop|AlignLeft, numStr);
1300 }
1301 } mSubHeaderHeight = tempStore ;
1302}
1303
1304#endif