summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-03-18 10:44:44 (UTC)
committer zautrix <zautrix>2005-03-18 10:44:44 (UTC)
commit414cb038cbe353f2fdb90969bc2531b687acc85f (patch) (side-by-side diff)
tree178c9da0d3a711a90beef435d32dcce50c53bdae /korganizer
parente972244f2a0581496301c7aa12e0498b34b48479 (diff)
downloadkdepimpi-414cb038cbe353f2fdb90969bc2531b687acc85f.zip
kdepimpi-414cb038cbe353f2fdb90969bc2531b687acc85f.tar.gz
kdepimpi-414cb038cbe353f2fdb90969bc2531b687acc85f.tar.bz2
print fix
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calprintbase.cpp20
-rw-r--r--korganizer/koagenda.cpp2
2 files changed, 8 insertions, 14 deletions
diff --git a/korganizer/calprintbase.cpp b/korganizer/calprintbase.cpp
index f66fddc..7b7d54c 100644
--- a/korganizer/calprintbase.cpp
+++ b/korganizer/calprintbase.cpp
@@ -399,546 +399,540 @@ void CalPrintBase::drawTimeLine(QPainter &p,
p.setFont(QFont("helvetica", 16, QFont::Bold));
} else {
p.setFont(QFont("helvetica", 12, QFont::Bold));
}
p.drawText(x+2, (int)currY+2, width/2-2, (int)cellHeight,
AlignTop|AlignRight, numStr);
p.setFont(QFont("helvetica", 10, QFont::Normal));
p.drawText(x+width/2, (int)currY+2, width/2+2, (int)(cellHeight/2)-3,
AlignTop | AlignLeft, "00");
} else {
QTime time( curTime.hour(), 0 );
numStr = KGlobal::locale()->formatTime( time );
p.setFont(QFont("helvetica", 14, QFont::Bold));
p.drawText(x+2, (int)currY+2, width-4, (int)cellHeight/2-3,
AlignTop|AlignLeft, numStr);
}
currY+=cellHeight;
} // enough space for half-hour line and time
if (curTime.secsTo(endTime)>3600)
curTime=curTime.addSecs(3600);
else curTime=endTime;
} // currTime<endTime
}
///////////////////////////////////////////////////////////////////////////////
/** prints the all-day box for the agenda print view. if expandable is set,
height is the cell height of a single cell, and the returned height will
be the total height used for the all-day events. If !expandable, only one
cell will be used, and multiple events are concatenated using ", ".
*/
void CalPrintBase::drawAllDayBox(QPainter &p, Event::List &eventList,
const QDate &qd, bool expandable,
int x, int y, int width, int &height)
{
Event::List::Iterator it, itold;
int offset=y;
//p.setBrush(QBrush(Dense7Pattern));
QPen oldPen(p.pen());
QColor oldBgColor(p.backgroundColor());
QBrush oldBrush(p.brush());
QString multiDayStr;
it = eventList.begin();
#ifndef KORG_NOPLUGINS
QString hstring(KOCore::self()->holiday(qd));
if (!hstring.isEmpty()) {
Event*holiday=new Event();
holiday->setDtStart(qd);
holiday->setDtEnd(qd);
holiday->setFloats(true);
holiday->setCategories(i18n("Holiday"));
eventList.prepend(holiday);
}
#endif
Event *currEvent = 0;
// First, print all floating events
while( it!=eventList.end() ) {
currEvent=*it;
itold=it;
++it;
if ( currEvent->doesFloat() ) {
// set the colors according to the categories
QString text = currEvent->summary() ;
if ( ! currEvent->location().isEmpty() )
text += " ("+currEvent->location()+")";
if (expandable) {
if (mUseColors)
setCategoryColors(p, currEvent);
p.drawRect( x, offset, width, height );
p.drawText( x+5, offset+5, width-10, height-10,
AlignCenter | AlignVCenter | AlignJustify | WordBreak,
text );
// reset the colors
p.setBrush( oldBrush );
p.setPen( oldPen );
p.setBackgroundColor(oldBgColor);
offset += height;
} else {
//if (!multiDayStr.isEmpty()) multiDayStr+=", ";
multiDayStr += text+"\n";
}
eventList.remove( itold );
}
}
if (!expandable) {
p.drawRect(x, offset, width, height);
if (!multiDayStr.isEmpty()) {
// p.fillRect(x+1, offset+1, width-2, height-2, QBrush(Dense5Pattern) );
p.drawText( x+5, offset+5, width-10, height-10,
AlignLeft | AlignTop | AlignJustify ,
multiDayStr);
}
} else {
height=offset-y;
}
}
void CalPrintBase::drawAgendaDayBox( QPainter &p, Event::List &events,
const QDate &qd, bool expandable,
QTime &fromTime, QTime &toTime,
int x, int y, int width, int height )
{
p.drawRect( x, y, width, height );
Event *event;
if ( expandable ) {
// Adapt start/end times to include complete events
Event::List::ConstIterator it;
for ( it = events.begin(); it != events.end(); ++it ) {
event = *it;
if ( event->dtStart().time() < fromTime )
fromTime = event->dtStart().time();
if ( event->dtEnd().time() > toTime )
toTime = event->dtEnd().time();
}
}
// Show at least one hour
if ( fromTime.secsTo( toTime ) < 3600 ) {
fromTime = QTime( fromTime.hour(), 0, 0 );
toTime = fromTime.addSecs( 3600 );
}
// calculate the height of a cell and of a minute
int totalsecs = fromTime.secsTo( toTime );
float minlen = height * 60. / totalsecs;
float cellHeight = 60. * minlen;
float currY = y;
// print grid:
QTime curTime( QTime( fromTime.hour(), 0, 0 ) );
currY += fromTime.secsTo( curTime ) * minlen / 60;
while ( curTime < toTime && curTime.isValid() ) {
if ( currY > y ) p.drawLine( x, int( currY ), x + width, int( currY ) );
currY += cellHeight / 2;
if ( ( currY > y ) && ( currY < y + height ) ) {
QPen oldPen( p.pen() );
p.setPen( QColor( 192, 192, 192 ) );
p.drawLine( x, int( currY ), x + width, int( currY ) );
p.setPen( oldPen );
} // enough space for half-hour line
if ( curTime.secsTo( toTime ) > 3600 )
curTime = curTime.addSecs( 3600 );
else curTime = toTime;
currY += cellHeight / 2;
}
QDateTime startPrintDate = QDateTime( qd, fromTime );
QDateTime endPrintDate = QDateTime( qd, toTime );
// 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);
} else if (i==5) {
drawDayBox(p, weekDate, x+cellWidth*(int)(i/vcells), y+cellHeight*(i%vcells),
cellWidth, cellHeight/2, true);
} else if (i==6) {
drawDayBox(p, weekDate, x+cellWidth*(int)((i-1)/vcells),
y+cellHeight*((i-1)%vcells)+cellHeight/2, cellWidth, cellHeight/2, true);
}
} // for i through all weekdays
}
void CalPrintBase::drawTimeTable(QPainter &p,
const QDate &fromDate, const QDate &toDate,
QTime &fromTime, QTime &toTime,
int x, int y, int width, int height)
{
// timeline is 1.5 hours:
int alldayHeight = (int)( 3600.*height/(fromTime.secsTo(toTime)+3600.) );
int timelineWidth = 60;
int cellWidth = (int)( (width-timelineWidth)/(fromDate.daysTo(toDate)+1) );
int currY=y;
int currX=x;
drawDaysOfWeek( p, fromDate, toDate, x+timelineWidth, currY, width-timelineWidth, mSubHeaderHeight);
currY+=mSubHeaderHeight;
drawTimeLine( p, fromTime, toTime, x, currY+alldayHeight,
timelineWidth, height-mSubHeaderHeight-alldayHeight );
currX=x+timelineWidth;
// draw each day
QDate curDate(fromDate);
while (curDate<=toDate) {Event::List eventList;
eventList.fill( mCalendar->events(curDate, true));
drawAllDayBox( p, eventList, curDate, false, currX, currY, cellWidth, alldayHeight);
drawAgendaDayBox( p, eventList, curDate, false, fromTime, toTime, currX,
currY+alldayHeight, cellWidth, height-mSubHeaderHeight-alldayHeight );
currX+=cellWidth;
curDate=curDate.addDays(1);
}
}
///////////////////////////////////////////////////////////////////////////////
void CalPrintBase::drawMonth(QPainter &p, const QDate &qd, bool weeknumbers,
int x, int y, int width, int height)
{
int yoffset = mSubHeaderHeight;
int xoffset = 0;
QDate monthDate(QDate(qd.year(), qd.month(), 1));
QDate monthFirst(monthDate);
QDate monthLast(monthDate.addMonths(1).addDays(-1));
int weekdayCol = weekdayColumn( monthDate.dayOfWeek() );
monthDate = monthDate.addDays(-weekdayCol);
int rows=(weekdayCol + qd.daysInMonth() - 1)/7 +1;
int cellHeight = (height-yoffset) / rows;
if (weeknumbers) {
QFont oldFont(p.font());
QFont newFont(p.font());
newFont.setPointSize(7);
p.setFont(newFont);
xoffset += 18;
QDate weekDate(monthDate);
for (int row = 0; row<rows; row++) {
int calWeek = weekDate.weekNumber();
QRect rc(x, y+yoffset+cellHeight*row, xoffset-1, cellHeight);
p.drawText( rc, AlignRight|AlignVCenter, QString::number(calWeek) );
weekDate = weekDate.addDays(7);
}
p.setFont(oldFont);
}
drawDaysOfWeek( p, monthDate, monthDate.addDays(6), x+xoffset, y, width-xoffset, mSubHeaderHeight );
int cellWidth = (width-xoffset) / 7;
QColor back = p.backgroundColor();
bool darkbg = false;
for (int row = 0; row < rows; row++) {
for (int col = 0; col < 7; col++) {
// show days from previous/next month with a grayed background
if ( (monthDate < monthFirst) || (monthDate > monthLast) ) {
p.setBackgroundColor( QColor( 240, 240, 240) );
darkbg = true;
}
drawDayBox(p, monthDate, x+xoffset+col*cellWidth, y+yoffset+row*cellHeight, cellWidth, cellHeight);
if ( darkbg ) {
p.setBackgroundColor( back );
darkbg = false;
}
monthDate = monthDate.addDays(1);
}
}
}
///////////////////////////////////////////////////////////////////////////////
void CalPrintBase::drawTodo( bool completed, int &count, Todo * item, QPainter &p, bool connectSubTodos,
bool desc, int pospriority, int possummary, int posDueDt, int level,
int x, int &y, int width, int &height, int pageHeight,
TodoParentStart *r )
{
if ( !completed && item->isCompleted() )
return;
QString outStr;
// int fontHeight = 10;
const KLocale *local = KGlobal::locale();
int priority=item->priority();
int posdue=posDueDt;
if (posdue<0) posdue=x+width;
QRect rect;
TodoParentStart startpt;
// This list keeps all starting points of the parent todos so the connection
// lines of the tree can easily be drawn (needed if a new page is started)
static QPtrList<TodoParentStart> startPoints;
if (level<1) {
startPoints.clear();
}
// size of item
outStr=item->summary();
if ( ! item->location().isEmpty() )
outStr += " ("+item->location()+")";
if ( item->hasDueDate() && posDueDt>=0 ) {
outStr += " [" +local->formatDate(item->dtDue().date(),true)+"]";
}
int left = possummary+(level*10);
rect = p.boundingRect(left, y, (posdue-left-5),-1, WordBreak, outStr);
//qDebug("bottom1 %d ", rect.bottom() );
if ( !item->description().isEmpty() && desc ) {
outStr = item->description();
rect = p.boundingRect( left+20, rect.bottom()+5, width-(left+10-x), -1,
WordBreak, outStr );
}
//qDebug("bottom2 %d y+h %d y %d ph %d", rect.bottom(), y+height, y , pageHeight );
// if too big make new page
if ( rect.bottom() > y+height) {
// first draw the connection lines from parent todos:
if (level > 0 && connectSubTodos) {
TodoParentStart *rct;
for ( rct = startPoints.first(); rct; rct = startPoints.next() ) {
int start;
int center = rct->mRect.left() + (rct->mRect.width()/2);
int to = p.viewport().bottom();
// draw either from start point of parent or from top of the page
if (rct->mSamePage)
start = rct->mRect.bottom() + 1;
else
start = p.viewport().top();
p.moveTo( center, start );
p.lineTo( center, to );
rct->mSamePage=false;
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index e8b7c94..8c2996b 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -1751,306 +1751,306 @@ void KOAgenda::computeSizes()
int cw = contentsWidth();
int ch = contentsHeight();
if ( mAllDayMode ) {
QPixmap* paintPixAll = KOAgendaItem::paintPixAllday();
if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 )
paintPixAll->resize( cw, ch );
} else {
QPixmap* paintPix = KOAgendaItem::paintPix();
if ( paintPix->width() < cw || paintPix->height() < ch )
KOAgendaItem::resizePixmap( cw , ch );
}
checkScrollBoundaries();
marcus_bains();
drawContentsToPainter();
viewport()->repaint(false);
}
void KOAgenda::scrollUp()
{
scrollBy(0,-mScrollOffset);
}
void KOAgenda::scrollDown()
{
scrollBy(0,mScrollOffset);
}
void KOAgenda::popupAlarm()
{
if (!mClickedItem) {
qDebug("KOAgenda::popupAlarm() called without having a clicked item ");
return;
}
// TODO: deal correctly with multiple alarms
Alarm* alarm;
QPtrList<Alarm> list(mClickedItem->incidence()->alarms());
for(alarm=list.first();alarm;alarm=list.next()) {
alarm->toggleAlarm();
}
emit itemModified( mClickedItem , KOGlobals::EVENTEDITED );
mClickedItem->paintMe( true );
mClickedItem->repaint( false );
}
/*
Calculates the minimum width
*/
int KOAgenda::minimumWidth() const
{
// TODO:: develop a way to dynamically determine the minimum width
int min = 100;
return min;
}
void KOAgenda::updateConfig()
{
if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor)
viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
if ( mAllDayMode ) {
mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize;
//mGridSpacingY = KOPrefs::instance()->mAllDaySize;
resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 );
// setMaximumHeight( mGridSpacingY+1 );
viewport()->repaint( false );
//setFixedHeight( mGridSpacingY+1 );
//qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize);
}
else {
mGridSpacingY = KOPrefs::instance()->mHourSize;
calculateWorkingHours();
marcus_bains();
}
}
void KOAgenda::checkScrollBoundaries()
{
// Invalidate old values to force update
mOldLowerScrollValue = -1;
mOldUpperScrollValue = -1;
checkScrollBoundaries(verticalScrollBar()->value());
}
void KOAgenda::checkScrollBoundaries(int v)
{
if ( mGridSpacingY == 0 )
return;
int yMin = v/mGridSpacingY;
int yMax = (v+visibleHeight())/mGridSpacingY;
// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl;
if (yMin != mOldLowerScrollValue) {
mOldLowerScrollValue = yMin;
emit lowerYChanged(yMin);
}
if (yMax != mOldUpperScrollValue) {
mOldUpperScrollValue = yMax;
emit upperYChanged(yMax);
}
}
void KOAgenda::deselectItem()
{
if (mSelectedItem.isNull()) return;
mSelectedItem->select(false);
mSelectedItem = 0;
}
void KOAgenda::selectItem(KOAgendaItem *item)
{
if ((KOAgendaItem *)mSelectedItem == item) return;
deselectItem();
if (item == 0) {
emit incidenceSelected( 0 );
return;
}
mSelectedItem = item;
mSelectedItem->select();
emit incidenceSelected( mSelectedItem->incidence() );
}
// This function seems never be called.
void KOAgenda::keyPressEvent( QKeyEvent *kev )
{
switch(kev->key()) {
case Key_PageDown:
verticalScrollBar()->addPage();
break;
case Key_PageUp:
verticalScrollBar()->subtractPage();
break;
case Key_Down:
verticalScrollBar()->addLine();
break;
case Key_Up:
verticalScrollBar()->subtractLine();
break;
default:
;
}
}
void KOAgenda::calculateWorkingHours()
{
// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours;
mWorkingHoursEnable = !mAllDayMode;
mWorkingHoursYTop = mGridSpacingY *
KOPrefs::instance()->mWorkingHoursStart * 4;
mWorkingHoursYBottom = mGridSpacingY *
KOPrefs::instance()->mWorkingHoursEnd * 4 - 1;
}
DateList KOAgenda::dateList() const
{
return mSelectedDates;
}
void KOAgenda::setDateList(const DateList &selectedDates)
{
mSelectedDates = selectedDates;
marcus_bains();
}
void KOAgenda::setHolidayMask(QMemArray<bool> *mask)
{
mHolidayMask = mask;
/*
kdDebug() << "HolidayMask: ";
for(uint i=0;i<mask->count();++i) {
kdDebug() << (mask->at(i) ? "*" : "o");
}
kdDebug() << endl;
*/
}
void KOAgenda::contentsMousePressEvent ( QMouseEvent *event )
{
QScrollView::contentsMousePressEvent(event);
}
void KOAgenda::storePosition()
{
//mContentPosition
int max = mGridSpacingY*4*24;
if ( contentsY() < 5 && max > viewport()->height()*3/2 )
mContentPosition = 0;
else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2)
mContentPosition = -1.0;
else
mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2)));
//qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height());
}
void KOAgenda::restorePosition()
{
int posY;
int max = mGridSpacingY*4*24;
if ( mContentPosition < 0 )
posY = max-viewport()->height();
else
if ( mContentPosition == 0 )
posY = 0;
else
posY = (max/mContentPosition)-(viewport()->height()/2);
setContentsPos (0, posY );
//qDebug("posY %d hei %d", posY, max);
}
void KOAgenda::moveChild( QWidget *w, int x , int y )
{
++x;
QScrollView::moveChild( w, x , y );
}
#include <qmessagebox.h>
#ifdef DESKTOP_VERSION
#include <qprinter.h>
#include <qpainter.h>
#include <qpaintdevicemetrics.h>
#endif
void KOAgenda::printSelection()
{
#ifdef DESKTOP_VERSION
if ( mStartCellY == mCurrentCellY ) {
int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
i18n("Nothing selected!\n\nThis prints the full width of the Agenda view as you see it!\n\nTo determine the vertical range of the printing, please select\na vertical range (with the left mouse button down) in one column. "),
i18n("OK"), 0, 0,
0, 1 );
return;
}
float dx, dy;
int x,y,w,h;
x= 0;
w= contentsWidth()+2;
// h= contentsHeight();
y = mGridSpacingY*mStartCellY;
h = mGridSpacingY*(mCurrentCellY+1)-y+2;
//return;
QPrinter* printer = new QPrinter();
if ( !printer->setup()) {
delete printer;
return;
}
QPainter p( printer );
QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer );
QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() );
- date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true );
+ //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true );
int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height();
// p.drawText( 0, 0, date );
int offset = m.width()/8;
// compute the scale
dx = ((float) m.width()-offset) / (float)w;
dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h;
float scale;
// scale to fit the width or height of the paper
if ( dx < dy )
scale = dx;
else
scale = dy;
// set the scale
p.drawText( offset* scale, offset* scale*3/4, date );
int selDay;
float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count()));
float startX = 1;
for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
{
QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true );
p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) );
p.drawText( offset* scale+startX, (offset+hei)* scale, text );
startX += widOffset;
}
p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale));
p.scale( scale, scale );
p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale );
// now printing with y offset: 2 hei
// p.translate( 0, -y*scale);
drawContentsToPainter(&p, true );
globalFlagBlockAgendaItemUpdate = false;
KOAgendaItem *item;
for ( item=mItems.first(); item != 0; item=mItems.next() ) {
item->select(false);
item->paintMe( false, &p );
}
globalFlagBlockAgendaItemUpdate = true;
p.end();
delete printer;
#else
int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
i18n("Not supported \non PDA!\n"),
i18n("OK"), 0, 0,
0, 1 );
#endif
}