-rw-r--r-- | korganizer/calprintbase.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/korganizer/calprintbase.cpp b/korganizer/calprintbase.cpp index f66fddc..7b7d54c 100644 --- a/korganizer/calprintbase.cpp +++ b/korganizer/calprintbase.cpp @@ -559,226 +559,220 @@ void CalPrintBase::drawAgendaDayBox( QPainter &p, Event::List &events, // Calculate horizontal positions and widths of events taking into account // overlapping events QPtrList<KOrg::CellItem> cells; cells.setAutoDelete( true ); Event::List::ConstIterator itEvents; for( itEvents = events.begin(); itEvents != events.end(); ++itEvents ) { cells.append( new PrintCellItem( *itEvents, qd ) ); } QPtrListIterator<KOrg::CellItem> it1( cells ); for( it1.toFirst(); it1.current(); ++it1 ) { KOrg::CellItem *placeItem = it1.current(); KOrg::CellItem::placeItem( cells, placeItem ); } QPen oldPen = p.pen(); QColor oldBgColor = p.backgroundColor(); QBrush oldBrush = p.brush(); p.setFont( QFont( "helvetica", 10 ) ); //p.setBrush( QBrush( Dense7Pattern ) ); for( it1.toFirst(); it1.current(); ++it1 ) { PrintCellItem *placeItem = static_cast<PrintCellItem *>( it1.current() ); drawAgendaItem( placeItem, p, qd, startPrintDate, endPrintDate, minlen, x, y, width ); p.setBrush( oldBrush ); p.setPen( oldPen ); p.setBackgroundColor( oldBgColor ); } p.setBrush( QBrush( NoBrush ) ); } void CalPrintBase::drawAgendaItem( PrintCellItem *item, QPainter &p, const QDate &qd, const QDateTime &startPrintDate, const QDateTime &endPrintDate, float minlen, int x, int y, int width ) { Event *event = item->event(); // set the colors according to the categories if ( mUseColors ) setCategoryColors( p, event ); else p.setBrush( Qt::white ); // start/end of print area for event QDateTime startTime = event->dtStart(); QDateTime endTime = event->dtEnd(); if ( event->doesRecur() ) { startTime.setDate( qd ); endTime.setDate( qd ); } if ( ( startTime < endPrintDate && endTime > startPrintDate ) || ( endTime > startPrintDate && startTime < endPrintDate ) ) { if ( startTime < startPrintDate ) startTime = startPrintDate; if ( endTime > endPrintDate ) endTime = endPrintDate; int eventLength = int( startTime.secsTo( endTime ) / 60. * minlen ); int currentyPos = int( y + startPrintDate.secsTo( startTime ) * minlen / 60. ); int currentWidth = width / item->subCells(); int currentX = x + item->subCell() * currentWidth; QString text = KGlobal::locale()->formatTime(event->dtStart().time())+ "-"+KGlobal::locale()->formatTime(event->dtEnd().time())+ " "+event->summary(); if ( !event->location().isEmpty() ) text += " (" +event->location()+")"; // p.save(); QPen pe = p.pen(); pe.setWidth( 2 ); p.setPen( pe ); p.drawRect( currentX, currentyPos+1, currentWidth+1, eventLength+1 ); p.drawText( currentX+3, currentyPos+2, currentWidth-5, eventLength-3, AlignLeft | AlignTop | AlignJustify | WordBreak, text); // p.restore(); } } void CalPrintBase::drawDayBox(QPainter &p, const QDate &qd, int x, int y, int width, int height, bool fullDate) { QString dayNumStr; QString ampm; const KLocale*local = KGlobal::locale(); // This has to be localized if (fullDate) { - /*int index; - dayNumStr= qd.toString(); - index = dayNumStr.find(' '); - dayNumStr.remove(0, index); - index = dayNumStr.findRev(' '); - dayNumStr.truncate(index);*/ - - const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); - dayNumStr = i18n("weekday month date", "%1 %2 %3") - .arg( calSys->weekDayName( qd ) ) - .arg( calSys->monthName( qd ) ) - .arg( qd.day() ); -// dayNumStr = local->formatDate(qd); + dayNumStr = local->formatDate(qd); } else { dayNumStr = QString::number( qd.day() ); } p.eraseRect( x, y, width, height ); p.drawRect( x, y, width, height ); // p.fillRect( x+1, y+1, width-2,height, QBrush(Dense7Pattern) ); p.drawRect( x, y, width, mSubHeaderHeight ); //p.fillRect( x+1, y+1, width-2, mSubHeaderHeight-2, QBrush(Dense7Pattern) ); QString hstring; #ifndef KORG_NOPLUGINS hstring=KOCore::self()->holiday(qd); #endif if (!hstring.isEmpty()) { p.setFont( QFont( "helvetica", 8, QFont::Bold, true ) ); p.drawText( x+5, y, width-25, mSubHeaderHeight, AlignLeft | AlignVCenter, hstring ); } p.setFont(QFont("helvetica", 10, QFont::Bold)); + if ( fullDate) { + // use short date format, if long date is too long + QFontMetrics fm ( p.font() ); + if ( fm.width( dayNumStr ) > width -10 ) + dayNumStr = local->formatDate(qd, true); + } p.drawText(x+5, y, width-10, mSubHeaderHeight, AlignRight | AlignVCenter, dayNumStr); Event::List eventList; eventList.fill( mCalendar->events( qd, true )); Todo::List todos; todos.fill( mCalendar->todos( qd )); QString outStr; p.setFont( QFont( "helvetica", 8 ) ); int lineSpacing = p.fontMetrics().lineSpacing(); int textY=mSubHeaderHeight+3; // gives the relative y-coord of the next printed entry Event::List::ConstIterator it; int entryCount = eventList.count() +todos.count(); if ( p.fontMetrics().lineSpacing()* entryCount > height-textY ) { if ( (p.fontMetrics().lineSpacing()-1) * entryCount > height-textY ) { p.setFont( QFont( "helvetica", 7 ) ); if ( (p.fontMetrics().lineSpacing()-1) * entryCount > height-textY ) p.setFont( QFont( "helvetica", 6 ) ); } lineSpacing = p.fontMetrics().lineSpacing()-1; } // qDebug("fm %d %d %d ",p.fontMetrics().height(), eventList.count() , height-textY ); for( it = eventList.begin(); it != eventList.end() && textY<height; ++it ) { Event *currEvent = *it; if (currEvent->doesFloat() || currEvent->isMultiDay()) outStr = currEvent->summary(); else { if ( fullDate ) { outStr = KGlobal::locale()->formatTime( currEvent->dtStart().time())+ "-"+KGlobal::locale()->formatTime( currEvent->dtEnd().time())+ " "+ currEvent->summary(); if ( ! currEvent->location().isEmpty() ) outStr += " (" + currEvent->location()+")"; } else { QTime t1 = currEvent->dtStart().time(); outStr = local->formatTime(t1); outStr += " " + currEvent->summary(); } } // doesFloat p.drawText(x+5, y+textY, width-10, lineSpacing, AlignLeft|AlignBottom, outStr); textY+=lineSpacing; } if ( textY<height ) { Todo::List::ConstIterator it2; for( it2 = todos.begin(); it2 != todos.end() && textY<height; ++it2 ) { Todo *todo = *it2; QString text; if (todo->hasDueDate()) { if (!todo->doesFloat()) { text += KGlobal::locale()->formatTime(todo->dtDue().time()); text += " "; } } text += i18n("To-Do: %1").arg(todo->summary()); p.drawText(x+5, y+textY, width-10, lineSpacing, AlignLeft|AlignBottom, text); textY+=lineSpacing; } } } /////////////////////////////////////////////////////////////////////////////// void CalPrintBase::drawWeek(QPainter &p, const QDate &qd, int x, int y, int width, int height) { QDate weekDate = qd; bool portrait = ( mPrinter->orientation() == KPrinter::Portrait ); int cellWidth, cellHeight; int vcells; if (portrait) { cellWidth = width/2; vcells=3; } else { cellWidth = width/6; vcells=1; } cellHeight = height/vcells; // correct begin of week int weekdayCol = weekdayColumn( qd.dayOfWeek() ); weekDate = qd.addDays( -weekdayCol ); for (int i = 0; i < 7; i++, weekDate = weekDate.addDays(1)) { if (i<5) { drawDayBox(p, weekDate, x+cellWidth*(int)(i/vcells), y+cellHeight*(i%vcells), cellWidth, cellHeight, true); |