author | zautrix <zautrix> | 2005-03-18 10:44:44 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-18 10:44:44 (UTC) |
commit | 414cb038cbe353f2fdb90969bc2531b687acc85f (patch) (side-by-side diff) | |
tree | 178c9da0d3a711a90beef435d32dcce50c53bdae | |
parent | e972244f2a0581496301c7aa12e0498b34b48479 (diff) | |
download | kdepimpi-414cb038cbe353f2fdb90969bc2531b687acc85f.zip kdepimpi-414cb038cbe353f2fdb90969bc2531b687acc85f.tar.gz kdepimpi-414cb038cbe353f2fdb90969bc2531b687acc85f.tar.bz2 |
print fix
-rw-r--r-- | korganizer/calprintbase.cpp | 20 | ||||
-rw-r--r-- | korganizer/koagenda.cpp | 2 | ||||
-rw-r--r-- | libkdepim/kpimglobalprefs.cpp | 2 |
3 files changed, 9 insertions, 15 deletions
diff --git a/korganizer/calprintbase.cpp b/korganizer/calprintbase.cpp index f66fddc..7b7d54c 100644 --- a/korganizer/calprintbase.cpp +++ b/korganizer/calprintbase.cpp @@ -1,1312 +1,1306 @@ /* This file is part of KOrganizer. Copyright (c) 1998 Preston Brown Copyright (c) 2003 Reinhold Kainhofer <reinhold@kainhofer.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qpainter.h> #include <qlayout.h> #include <qframe.h> #include <qlabel.h> #include <qptrlist.h> #include <qintdict.h> #include <qfontmetrics.h> #include <kglobal.h> #include <klocale.h> #include <kdebug.h> #include <kconfig.h> #include <kcalendarsystem.h> #include <kprinter.h> #include <libkcal/todo.h> #include <libkcal/event.h> #include <libkcal/calendar.h> #include "koprefs.h" #include "koglobals.h" #ifndef KORG_NOPLUGINS #include "kocore.h" #endif #include "cellitem.h" #include "calprintbase.h" #ifndef KORG_NOPRINTER //#include "calprintbase.moc" int CalPrintBase::mHeaderHeight=90; int CalPrintBase::mSubHeaderHeight=20; int CalPrintBase::mMargin=36; class CalPrintBase::TodoParentStart { public: TodoParentStart( QRect pt = QRect(), bool page = true ) : mRect( pt ), mSamePage( page ) {} QRect mRect; bool mSamePage; }; class PrintCellItem : public KOrg::CellItem { public: PrintCellItem( Event *event, const QDate &day ) : mEvent( event ), mDay( day ) { } Event *event() const { return mEvent; } QString label() const { return mEvent->summary(); } bool overlaps( KOrg::CellItem *o ) const { PrintCellItem *other = static_cast<PrintCellItem *>( o ); QDateTime start = event()->dtStart(); QDateTime end = event()->dtEnd(); if ( event()->doesRecur() ) { start.setDate( mDay ); end.setDate( mDay ); } QDateTime otherStart = other->event()->dtStart(); QDateTime otherEnd = other->event()->dtEnd(); if ( other->event()->doesRecur() ) { otherStart.setDate( mDay ); otherEnd.setDate( mDay ); } #if 0 kdDebug() << "PrintCellItem::overlaps() " << event()->summary() << " <-> " << other->event()->summary() << endl; kdDebug() << " start : " << start.toString() << endl; kdDebug() << " end : " << end.toString() << endl; kdDebug() << " otherStart: " << otherStart.toString() << endl; kdDebug() << " otherEnd : " << otherEnd.toString() << endl; #endif return !( otherStart >= end || otherEnd <= start ); } private: Event *mEvent; QDate mDay; }; void setCategoryColors( QPainter &p, Incidence *incidence) { QColor bgColor; QStringList categories = incidence->categories(); QString cat = categories.first(); if (cat.isEmpty()) bgColor = KOPrefs::instance()->mEventColor; else bgColor = *(KOPrefs::instance()->categoryColor(cat)); QColor textColor = Qt::black;//getTextColor(bgColor); p.setPen( textColor ); p.setBrush( bgColor ); } CalPrintBase::CalPrintBase( KPrinter *printer, Calendar *cal, KConfig *cfg ) : QObject(), mPrinter( printer ), mCalendar( cal ), mConfig( cfg ) { } CalPrintBase::~CalPrintBase() { } QWidget *CalPrintBase::configWidget( QWidget *w ) { QFrame *wdg = new QFrame( w ); QVBoxLayout *layout = new QVBoxLayout( wdg ); QLabel *title = new QLabel( description(), wdg ); QFont titleFont( title->font() ); titleFont.setPointSize( 20 ); titleFont.setBold( true ); title->setFont( titleFont ); layout->addWidget( title ); layout->addWidget( new QLabel( longDescription(), wdg ) ); layout->addSpacing( 20 ); layout->addWidget( new QLabel( i18n("This printing style does not " "have any configuration options."), wdg ) ); layout->addStretch(); return wdg; } #include <qapplication.h> void CalPrintBase::doPrint() { QPainter p; mPrinter->setColorMode( (mUseColors)?(KPrinter::Color):(KPrinter::GrayScale)); //#define DUMMY_PRINTER #ifdef DUMMY_PRINTER static QWidget* dummy = 0; if ( ! dummy ) dummy = new QWidget( ); else { delete dummy; dummy = new QWidget( ); } dummy->resize( 1024, 1024 ); dummy->repaint(); dummy->show(); dummy->raise(); dummy->setBackgroundColor( Qt::white); qApp->processEvents(); p.begin(dummy); #else p.begin(mPrinter); #endif // the painter initially begins at 72 dpi per the Qt docs. // we want half-inch margins. p.setViewport(mMargin, mMargin, p.viewport().width()-mMargin, p.viewport().height()-mMargin); int pageWidth = p.viewport().width(); int pageHeight = p.viewport().height(); print(p, pageWidth, pageHeight); p.end(); } void CalPrintBase::doLoadConfig() { if ( mConfig ) { mConfig->setGroup(description()); //KConfigGroupSaver saver( mConfig, description() ); mConfig->sync(); QDateTime currDate( QDate::currentDate() ); mFromDate = mConfig->readDateTimeEntry( "FromDate", &currDate ).date(); mToDate = mConfig->readDateTimeEntry( "ToDate" ).date(); mUseColors = mConfig->readBoolEntry( "UseColors", false ); loadConfig(); } else { qDebug("no config in CalPrintBase::doLoadConfig "); } } void CalPrintBase::doSaveConfig() { if ( mConfig ) { mConfig->setGroup(description()); // KConfigGroupSaver saver( mConfig, description() ); saveConfig(); mConfig->writeEntry( "FromDate", QDateTime( mFromDate ) ); mConfig->writeEntry( "ToDate", QDateTime( mToDate ) ); mConfig->writeEntry( "UseColors", mUseColors ); mConfig->sync(); } else { qDebug("no config in CalPrintBase::doSveConfig "); } } /////////////////////////////////////////////////////////////////////////////// void CalPrintBase::drawHeader( QPainter &p, QString title, const QDate &month1, const QDate &month2, int x, int y, int width, int height ) { p.drawRect(x, y, width, height); // p.fillRect( x+1, y+1, // width-2,height-2, // QBrush(Dense7Pattern) ); QString myOwner(mCalendar->getOwner()); int right=x+width; // print previous month for month view, print current for todo, day and week int smallMonthWidth=width/4-10; if (smallMonthWidth>100) smallMonthWidth=100; if (month2.isValid()) { right -= (10+smallMonthWidth); drawSmallMonth(p, QDate(month2.year(), month2.month(), 1), right, y+2, smallMonthWidth, height-4); right-=10; } if (month1.isValid()) { right -= (10+smallMonthWidth); drawSmallMonth(p, QDate(month1.year(), month1.month(), 1), right, y+2, smallMonthWidth, height-4); right-=10; } // Print the titles... QFont font("helvetica", 18, QFont::Bold); p.setFont(font); QRect textRect( x+5, y+5, right-10-x, height-10 ); p.drawText( textRect, Qt::AlignLeft | Qt::AlignTop | Qt::WordBreak, title ); } void CalPrintBase::drawSmallMonth(QPainter &p, const QDate &qd, int x, int y, int width, int height) { bool firstCol = true; QDate monthDate(QDate(qd.year(), qd.month(), 1)); QDate monthDate2; int month = monthDate.month(); // draw the title p.setFont(QFont("helvetica", 7, QFont::Bold)); // int lineSpacing = p.fontMetrics().lineSpacing(); const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); p.drawText(x, y, width, height/4, AlignCenter, calSys->monthName( qd ) ); int cellWidth = width/7; int cellHeight = height/8; QString tmpStr; // correct begin of week int weekdayCol = weekdayColumn( qd.dayOfWeek() ); monthDate2 = monthDate.addDays(-weekdayCol); // draw days of week p.setFont(QFont("helvetica", 7, QFont::Bold)); for (int col = 0; col < 7; col++) { // tmpStr.sprintf("%c",(const char*)monthDate2.dayName(monthDate2.dayOfWeek())); tmpStr=calSys->weekDayName( monthDate2 )[0].upper(); p.drawText(x+col*cellWidth, y+height/4, cellWidth, cellHeight, AlignCenter, tmpStr); monthDate2 = monthDate2.addDays(1); } // draw separator line p.drawLine(x, y+height/4+cellHeight, x+width, y+height/4+cellHeight); for (int row = 0; row < 5; row++) { for (int col = 0; col < 7; col++) { if (monthDate.month() != month) break; if (firstCol) { firstCol = true; col = weekdayColumn( monthDate.dayOfWeek() ); } p.drawText( x+col*cellWidth, y+height/4+cellHeight+(row*cellHeight), cellWidth, cellHeight, AlignCenter, tmpStr.setNum(monthDate.day()) ); monthDate = monthDate.addDays(1); } } } /////////////////////////////////////////////////////////////////////////////// /* * This routine draws a header box over the main part of the calendar * containing the days of the week. */ void CalPrintBase::drawDaysOfWeek(QPainter &p, const QDate &fromDate, const QDate &toDate, int x, int y, int width, int height) { int cellWidth = width/(fromDate.daysTo( toDate )+1); int currx=x; QDate cellDate(fromDate); while (cellDate<=toDate) { drawDaysOfWeekBox(p, cellDate, currx, y, cellWidth, height); currx+=cellWidth; cellDate = cellDate.addDays(1); } } void CalPrintBase::drawDaysOfWeekBox(QPainter &p, const QDate &qd, int x, int y, int width, int height) { const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); p.setFont( QFont( "helvetica", 10, QFont::Bold ) ); p.drawRect( x, y, width, height ); // p.fillRect( x+1, y+1, // width-2, height-2, // QBrush( Dense7Pattern ) ); p.drawText( x+5, y, width-10, height, AlignCenter | AlignVCenter, calSys->weekDayName( qd ) ); } void CalPrintBase::drawTimeLine(QPainter &p, const QTime &fromTime, const QTime &toTime, int x, int y, int width, int height) { p.drawRect(x, y, width, height); int totalsecs=fromTime.secsTo(toTime); float minlen=(float)height*60./(float)totalsecs; float cellHeight=(60.*(float)minlen); float currY=y; QTime curTime( fromTime ); QTime endTime( toTime ); if ( fromTime.minute() > 30 ) curTime = QTime( fromTime.hour()+1, 0, 0 ); else if ( fromTime.minute() > 0 ) { curTime = QTime( fromTime.hour(), 30, 0 ); float yy = currY + minlen*(float)fromTime.secsTo( curTime )/60.; p.drawLine( x+width/2, (int)yy, x+width, (int)yy ); curTime = QTime( fromTime.hour()+1, 0, 0 ); } currY += ( fromTime.secsTo(curTime)*minlen/60 ); while ( curTime < endTime ) { p.drawLine( x, (int)currY, x+width, (int)currY ); int newY=(int)(currY+cellHeight/2.); QString numStr; if (newY < y+height) { p.drawLine(x+width/2, (int)newY, x+width, (int)newY); // draw the time: if ( !KGlobal::locale()->use12Clock() ) { numStr.setNum(curTime.hour()); if (cellHeight > 30) { 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; } } y=0; height=pageHeight-y; mPrinter->newPage(); } // If this is a sub-item, r will not be 0, and we want the LH side of the priority line up //to the RH side of the parent item's priority if (r && pospriority >= 0 ) { pospriority = r->mRect.right() + 1; } // Priority outStr.setNum(priority); rect = p.boundingRect(pospriority, y + 10, 5, -1, AlignCenter, outStr); // Make it a more reasonable size rect.setWidth(19); rect.setHeight(19); if ( priority > 0 && pospriority>=0 ) { p.drawText(rect, AlignCenter, outStr); p.drawRect(rect); // cross out the rectangle for completed items if ( item->isCompleted() ) { p.drawLine( rect.topLeft(), rect.bottomRight() ); p.drawLine( rect.topRight(), rect.bottomLeft() ); } else if (item->cancelled() ) { QPen pen = p.pen(); p.setPen ( QPen ( black, 2) ); p.drawLine( rect.left()+2,rect.top()+rect.height()/2, rect.right()-2, +rect.top()+rect.height()/2 ); p.setPen( pen ); } } startpt.mRect = rect; //save for later // Connect the dots if (level > 0 && connectSubTodos) { int bottom; int center( r->mRect.left() + (r->mRect.width()/2)+1 ); if (r->mSamePage ) bottom = r->mRect.bottom();//lutz + 1; else bottom = 0; int to( rect.top() + (rect.height()/2)+1 ); int endx( rect.left() ); p.moveTo(center, bottom); p.lineTo(center, to); p.lineTo(endx, to); } // if completed, use strike out font // LR does not work - font is underlined, not striked out //QFont ft=p.font(); //ft.setStrikeOut( item->isCompleted() ); //p.setFont( ft ); // summary outStr=item->summary(); if ( ! item->location().isEmpty() ) outStr += " ("+item->location()+")"; if ( item->hasDueDate() && posDueDt>=0 ) { outStr += " [" +item->dtDueStr(true)+"]"; } rect = p.boundingRect( left, rect.top(), (posdue-(left + rect.width() + 5)), -1, WordBreak, outStr); QRect newrect; p.drawText( rect, WordBreak, outStr, -1, &newrect ); //ft.setStrikeOut(false); // p.setFont(ft); // due // if ( item->hasDueDate() && posDueDt>=0 ) { // outStr = local->formatDate(item->dtDue().date(),true); // rect = p.boundingRect(posdue, y, x+width, -1, AlignTop|AlignLeft, outStr); // p.drawText(rect, AlignTop|AlignLeft, outStr); // } if ( !item->description().isEmpty() && desc ) { y=newrect.bottom() + 5; outStr = item->description(); rect = p.boundingRect( left+20, y, x+width-(left+10), -1, WordBreak, outStr ); p.drawText( rect, WordBreak, outStr, -1, &newrect ); } // Set the new line position y=newrect.bottom() + 10; //set the line position // If the item has subitems, we need to call ourselves recursively Incidence::List l;l.fill( item->relations()); Incidence::List::ConstIterator it; startPoints.append( &startpt ); for( it = l.begin(); it != l.end(); ++it ) { count++; drawTodo( completed, count, static_cast<Todo *>( *it ), p, connectSubTodos, desc, pospriority, possummary, posDueDt, level+1, x, y, width, height, pageHeight, &startpt); } startPoints.remove(&startpt); } int CalPrintBase::weekdayColumn( int weekday ) { return ( weekday + 7 - KGlobal::locale()->weekStartDay() ) % 7; } void CalPrintBase::drawSplitWeek( QPainter &p, const QDate &fd, const QDate &td ) { QDate curDay, fromDay, toDay, curWeek, fromWeek, toWeek; mPrinter->setOrientation(KPrinter::Portrait); int minus = 0; if (KGlobal::locale()->weekStartsMonday()) { // correct to monday fromWeek = fd.addDays(-(fd.dayOfWeek()-1)); // correct to sunday toWeek = td.addDays(7-fd.dayOfWeek()); minus = 1; } else { // correct to sunday fromWeek = fd.addDays(-(fd.dayOfWeek()%7)); // correct to saturday toWeek = td.addDays(6-td.dayOfWeek()); } fromDay = fd; curDay = fd; toDay = td; p.setFont( QFont("Helvetica") ); // the painter initially begins at 72 dpi per the Qt docs. int pageWidth = p.viewport().width(); int pageHeight = p.viewport().height(); int margin=0; mHeaderHeight = 110; mSubHeaderHeight = 20; p.setViewport(margin, margin, p.viewport().width()-margin, p.viewport().height()-margin); curWeek = fromWeek.addDays(6); int columnWidth = int( pageWidth / 4.5 ); do { // if ( (curDay.dayOfWeek()-1)%7 < 3 ) switch((curDay.dayOfWeek()-minus)%7){ case 0: drawSplitTimes( p, pageWidth, columnWidth, pageHeight ); drawSplitDay( p, curDay, columnWidth, pageHeight, int( columnWidth * 0.5 ) ); break; case 1: drawSplitDay( p, curDay, columnWidth, pageHeight, int( columnWidth * 1.5 ) ); break; case 2: drawSplitDay( p, curDay, columnWidth, pageHeight, int( columnWidth * 2.5 ) ); break; case 3: drawSplitDay( p, curDay, columnWidth, pageHeight, int( columnWidth * 3.5 ) ); mPrinter->newPage(); break; case 4: drawSplitTimes( p, int( pageWidth * ( 3.5/ 4.5 ) ), columnWidth, pageHeight ); drawSplitDay( p, curDay, columnWidth, pageHeight, int( columnWidth * 0.5 ) ); drawSplitHeaderRight( p, curWeek.addDays( -6 ), curWeek, curWeek, pageWidth, mHeaderHeight ); break; case 5: drawSplitDay( p, curDay, columnWidth, pageHeight, int( columnWidth * 1.5 ) ); break; case 6: drawSplitDay( p, curDay, columnWidth, pageHeight, int( columnWidth * 2.5 ) ); if ( curDay < toDay ) mPrinter->newPage(); curWeek = curWeek.addDays( 7 ); break; } curDay = curDay.addDays(1); } while (curDay <= toDay); } void CalPrintBase::drawSplitHeaderRight( QPainter &p, const QDate &fd, const QDate &td, const QDate &, int width, int ) { int tempStore = mSubHeaderHeight; mSubHeaderHeight+= mSubHeaderHeight; KLocale *local = KGlobal::locale(); QFont font("helvetica", 18, QFont::Bold); QPen penA( black,0); QPen penB( black,3); p.setFont(font); int lineSpacing = p.fontMetrics().lineSpacing(); QString title; QString myOwner(mCalendar->getOwner()); if ( fd.month() == td.month() ) { title = local->monthName(fd.month(), false) + ' ' + QString::number(fd.day()) + ' ' + '-' + ' ' + QString::number(td.day()); } else { title = local->monthName(fd.month(), false) + ' ' + QString::number(fd.day()) + ' ' + '-' + ' ' + local->monthName(td.month(), false) + ' ' + QString::number(td.day()); } // Grrrrrrr! why can't I set the font to a serif font?!?!? QFont serifFont("Helvetica", 30); // serifFont.setFamily("Serif"); // serifFont.setWeight(87); // serifFont.setItalic(true); p.setFont(serifFont); QFontInfo info(p.font()); lineSpacing = p.fontMetrics().lineSpacing(); p.drawText(0, lineSpacing * 0, width, lineSpacing, AlignRight |AlignTop, title ); title.truncate(0); p.setPen(penB ); p.drawLine(200, lineSpacing * 1, width, lineSpacing * 1); p.setPen(penA ); p.setFont(QFont("Helvetica", 20, QFont::Bold, TRUE)); title += QString::number(fd.year()); p.drawText(0, lineSpacing * 1, width, lineSpacing, AlignRight |AlignTop, title ); mSubHeaderHeight = tempStore ; } void CalPrintBase::drawSplitDay( QPainter &p, const QDate &qd, int width, int height, int offsetLeft ) { int tempStore = mSubHeaderHeight; mSubHeaderHeight+= mSubHeaderHeight; int startHour = KOPrefs::instance()->mDayBegins; int endHour = 20; int offset = mHeaderHeight + mSubHeaderHeight + 10; Event::List eventList; eventList.fill( mCalendar->events( qd, true )); Event::List::Iterator it; Event *currEvent; KLocale *local = KGlobal::locale(); QString dayName; dayName = local->weekDayName(qd.dayOfWeek()) + ' ' + ' ' + QString::number(qd.day()); //p.setBrush(QBrush(black)); // width+1 to make sure there's a continuous, black bar across the top. p.setPen( QPen(Qt::black,2)); p.drawRect(offsetLeft, mHeaderHeight + 5, width +1, mSubHeaderHeight); p.setPen( Qt::black); p.setFont(QFont("helvetica", 12, QFont::Bold, true)); p.drawText(offsetLeft, mHeaderHeight + 5, width, mSubHeaderHeight, AlignHCenter | AlignVCenter, dayName); p.setPen( QPen(Qt::black,2)); p.setFont(QFont("helvetica", 12)); p.setBrush(Qt::white); it = eventList.begin(); int allDays = 0; /* while( it != eventList.end() ) { Event *currEvent = *it; if ( currEvent->doesFloat() ) { p.drawRect( offsetLeft, offset, width, 35 ); p.drawText( offsetLeft + 5, offset + 10, width - 10, 30, AlignLeft | AlignTop, currEvent->summary() ); offset += 40; allDays++; it = eventList.remove( it ); } else { ++it; } } */ //p.setBrush(QBrush()); int tmpEnd; for ( it = eventList.begin(); it != eventList.end(); ++it ) { Event *currEvent = *it; tmpEnd = currEvent->dtEnd().time().hour(); if (currEvent->dtEnd().time().minute() > 0) tmpEnd++; if (tmpEnd > endHour) endHour = tmpEnd; } int hours = endHour - startHour; int cellHeight = (height-offset) / hours; // hour increments. p.setFont(QFont("helvetica", 12)); //p.setBrush(QBrush(Dense7Pattern)); p.setBrush(Qt::white); for ( it = eventList.begin(); it != eventList.end(); ++it ) { Event *currEvent = *it; int startTime = currEvent->dtStart().time().hour(); int endTime = currEvent->dtEnd().time().hour(); float minuteInc = cellHeight / 60.0; if ((startTime >= startHour) && (endTime <= (startHour + hours))) { startTime -= startHour; int startMinuteOff = (int) (minuteInc * currEvent->dtStart().time().minute()); QString text = currEvent->summary() ; if ( ! currEvent->location().isEmpty() ) text += "\n("+currEvent->location()+")"; int endMinuteOff = (int) (minuteInc * currEvent->dtEnd().time().minute()); int cheight = (int) (minuteInc * currEvent->dtStart().secsTo(currEvent->dtEnd()) / 60 ); p.drawRect(offsetLeft+2, 1+offset+startMinuteOff+startTime*cellHeight, width-4, cheight); p.drawText(offsetLeft+12, offset+startMinuteOff+startTime*cellHeight+5, width-24, cheight-10, AlignHCenter | AlignTop, text); } } p.setBrush(QBrush(NoBrush)); mSubHeaderHeight = tempStore ; } void CalPrintBase::drawSplitTimes( QPainter &p, int width, int timeWidth, int height ) { int tempStore = mSubHeaderHeight; mSubHeaderHeight+= mSubHeaderHeight; int startHour = KOPrefs::instance()->mDayBegins; int endHour = 20; int offset = mHeaderHeight + mSubHeaderHeight + 10; int hours = endHour - startHour; int cellHeight = (height-offset) / hours; // hour increments. QString numStr; for (int i = 0; i < hours; i++) { p.setPen(QPen(black,1)); p.drawLine(0, offset+i*cellHeight, width, offset+i*cellHeight); p.setPen(QPen(gray,0)); p.drawLine(37, offset+i*cellHeight+(cellHeight/2), width, offset+i*cellHeight+(cellHeight/2)); p.setPen(QPen(black,0)); if ( !KGlobal::locale()->use12Clock() ) { numStr.setNum(i+startHour); if (cellHeight > 40) { p.setFont(QFont("helvetica", 16, QFont::Bold)); } else { p.setFont(QFont("helvetica", 14, QFont::Bold)); } p.drawText(0, offset+i*cellHeight, 33, cellHeight/2, AlignTop|AlignRight, numStr); p.setFont(QFont("helvetica", 12, QFont::Bold)); p.drawText(37, offset+i*cellHeight, 45, cellHeight/2, AlignTop | AlignLeft, "00"); } else { QTime time( i + startHour, 0 ); numStr = KGlobal::locale()->formatTime( time ); p.setFont(QFont("helvetica", 12, QFont::Bold)); p.drawText(4, offset+i*cellHeight, 70, cellHeight/2, AlignTop|AlignLeft, numStr); } } mSubHeaderHeight = tempStore ; } #endif diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index e8b7c94..8c2996b 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp @@ -471,1586 +471,1586 @@ bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) // emit startDragSignal( mActionItem->incidence() ); setCursor( arrowCursor ); mActionItem = 0; mActionType = NOP; mItemMoved = 0; return true; } endItemAction(); } } } else { // ---------- viewport() if (me->button() == RightButton) { //right click if ( blockMoving ) { // we did mot moved the mouse much - popup menu if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action endSelectAction( false ); // do not emit new event signal leftMouseDown = false; // no more leftMouse computation } int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); int gx,gy; contentsToGrid(x,y,gx,gy); mCurrentCellX = gx; mCurrentCellY = gy; mStartCellX = gx; mStartCellY = gy; mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); } } else if (me->button() == LeftButton && leftMouseDown ) { //left click endSelectAction( true ); // emit new event signal } } if (me->button() == LeftButton) leftMouseDown = false; else if (me->button() == RightButton) rightMouseDown = false; break; case QEvent::MouseMove: if ( !rightMouseDown && !leftMouseDown ) return true; if ( blockMoving ) { int dX, dY; dX = startX - viewportPos.x(); if ( dX < 0 ) dX = -dX; dY = viewportPos.y() - startY; if ( dY < 0 ) dY = -dY; //qDebug("%d %d %d ", dX, dY , blockmoveDist ); if ( dX > blockmoveDist || dY > blockmoveDist ) { blockMoving = false; } } if (object != viewport()) { KOAgendaItem *moveItem = (KOAgendaItem *)object; if (!moveItem->incidence()->isReadOnly() ) { if (!mActionItem) setNoActionCursor(moveItem,viewportPos); else { if ( !blockMoving ) performItemAction(viewportPos); } } } else { // ---------- viewport() if ( mActionType == SELECT ) { performSelectAction( viewportPos ); } } break; case QEvent::MouseButtonDblClick: if (object == viewport()) { selectItem(0); int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); int gx,gy; contentsToGrid(x,y,gx,gy); emit newEventSignal(gx,gy); } else { KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; selectItem(doubleClickedItem); if ( KOPrefs::instance()->mEditOnDoubleClick ) emit editIncidenceSignal(doubleClickedItem->incidence()); else emit showIncidenceSignal(doubleClickedItem->incidence()); } break; default: break; } return true; } void KOAgenda::newItem( int item ) { if ( item == 1 ) { //new event newEventSignal(mStartCellX ,mStartCellY ); } else if ( item == 2 ) { //new event newTodoSignal(mStartCellX ,mStartCellY ); } else { QDate day = mSelectedDates[mStartCellX]; emit showDateView( item, day ); // 3Day view // 4Week view // 5Month view // 6Journal view } } void KOAgenda::startSelectAction(QPoint viewportPos) { //emit newStartSelectSignal(); mActionType = SELECT; int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); int gx,gy; contentsToGrid(x,y,gx,gy); mStartCellX = gx; mStartCellY = gy; mCurrentCellX = gx; mCurrentCellY = gy; // Store coordinates of old selection int selectionX = mSelectionCellX * mGridSpacingX; int selectionYTop = mSelectionYTop; int selectionHeight = mSelectionHeight; // Store new selection mSelectionCellX = gx; mSelectionYTop = gy * mGridSpacingY; mSelectionHeight = mGridSpacingY; // Clear old selection repaintContents( selectionX, selectionYTop, mGridSpacingX, selectionHeight,false ); // Paint new selection // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, // mGridSpacingX, mSelectionHeight ); } void KOAgenda::performSelectAction(QPoint viewportPos) { int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); int gx,gy; contentsToGrid(x,y,gx,gy); QPoint clipperPos = clipper()-> mapFromGlobal(viewport()->mapToGlobal(viewportPos)); // Scroll if cursor was moved to upper or lower end of agenda. if (clipperPos.y() < mScrollBorderWidth) { mScrollUpTimer.start(mScrollDelay); } else if (visibleHeight() - clipperPos.y() < mScrollBorderWidth) { mScrollDownTimer.start(mScrollDelay); } else { mScrollUpTimer.stop(); mScrollDownTimer.stop(); } if ( gy > mCurrentCellY ) { mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; #if 0 // FIXME: Repaint only the newly selected region repaintContents( mSelectionCellX * mGridSpacingX, mCurrentCellY + mGridSpacingY, mGridSpacingX, mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); #else repaintContents( (KOGlobals::self()->reverseLayout() ? mColumns - 1 - mSelectionCellX : mSelectionCellX) * mGridSpacingX, mSelectionYTop, mGridSpacingX, mSelectionHeight , false); #endif mCurrentCellY = gy; } else if ( gy < mCurrentCellY ) { if ( gy >= mStartCellY ) { int selectionHeight = mSelectionHeight; mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; repaintContents( (KOGlobals::self()->reverseLayout() ? mColumns - 1 - mSelectionCellX : mSelectionCellX) * mGridSpacingX, mSelectionYTop, mGridSpacingX, selectionHeight,false ); mCurrentCellY = gy; } else { } } } void KOAgenda::endSelectAction( bool emitNewEvent ) { mActionType = NOP; mScrollUpTimer.stop(); mScrollDownTimer.stop(); emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); if ( emitNewEvent && mStartCellY < mCurrentCellY ) { qDebug("ew event signal "); emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); } } void KOAgenda::startItemAction(QPoint viewportPos) { int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); int gx,gy; contentsToGrid(x,y,gx,gy); mStartCellX = gx; mStartCellY = gy; mCurrentCellX = gx; mCurrentCellY = gy; if (mAllDayMode) { int gridDistanceX = (x - gx * mGridSpacingX); if (gridDistanceX < mResizeBorderWidth && mActionItem->cellX() == mCurrentCellX) { mActionType = RESIZELEFT; setCursor(sizeHorCursor); } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && mActionItem->cellXWidth() == mCurrentCellX) { mActionType = RESIZERIGHT; setCursor(sizeHorCursor); } else { mActionType = MOVE; mActionItem->startMove(); setCursor(sizeAllCursor); } } else { int gridDistanceY = (y - gy * mGridSpacingY); bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); if (allowResize && gridDistanceY < mResizeBorderWidth && mActionItem->cellYTop() == mCurrentCellY && !mActionItem->firstMultiItem()) { mActionType = RESIZETOP; setCursor(sizeVerCursor); } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && mActionItem->cellYBottom() == mCurrentCellY && !mActionItem->lastMultiItem()) { mActionType = RESIZEBOTTOM; setCursor(sizeVerCursor); } else { mActionType = MOVE; mActionItem->startMove(); setCursor(sizeAllCursor); } } } void KOAgenda::performItemAction(QPoint viewportPos) { // kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; // QPoint point = viewport()->mapToGlobal(viewportPos); // kdDebug() << "Global: " << point.x() << "," << point.y() << endl; // point = clipper()->mapFromGlobal(point); // kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; // kdDebug() << "visible height: " << visibleHeight() << endl; int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); // kdDebug() << "contents: " << x << "," << y << "\n" << endl; int gx,gy; contentsToGrid(x,y,gx,gy); QPoint clipperPos = clipper()-> mapFromGlobal(viewport()->mapToGlobal(viewportPos)); // Cursor left active agenda area. // This starts a drag. if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { if ( mActionType == MOVE ) { mScrollUpTimer.stop(); mScrollDownTimer.stop(); mActionItem->resetMove(); placeSubCells( mActionItem ); // emit startDragSignal( mActionItem->incidence() ); setCursor( arrowCursor ); mActionItem = 0; mActionType = NOP; mItemMoved = 0; return; } } else { switch ( mActionType ) { case MOVE: setCursor( sizeAllCursor ); break; case RESIZETOP: case RESIZEBOTTOM: setCursor( sizeVerCursor ); break; case RESIZELEFT: case RESIZERIGHT: setCursor( sizeHorCursor ); break; default: setCursor( arrowCursor ); } } // Scroll if item was moved to upper or lower end of agenda. if (clipperPos.y() < mScrollBorderWidth) { mScrollUpTimer.start(mScrollDelay); } else if (visibleHeight() - clipperPos.y() < mScrollBorderWidth) { mScrollDownTimer.start(mScrollDelay); } else { mScrollUpTimer.stop(); mScrollDownTimer.stop(); } // Move or resize item if necessary if (mCurrentCellX != gx || mCurrentCellY != gy) { mItemMoved = true; mActionItem->raise(); if (mActionType == MOVE) { // Move all items belonging to a multi item KOAgendaItem *moveItem = mActionItem->firstMultiItem(); bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); if (!moveItem) moveItem = mActionItem; while (moveItem) { int dy; if (isMultiItem) dy = 0; else dy = gy - mCurrentCellY; moveItem->moveRelative(gx - mCurrentCellX,dy); int x,y; gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); moveItem->resize(mGridSpacingX * moveItem->cellWidth(), mGridSpacingY * moveItem->cellHeight()); moveChild(moveItem,x,y); moveItem = moveItem->nextMultiItem(); } } else if (mActionType == RESIZETOP) { if (mCurrentCellY <= mActionItem->cellYBottom()) { mActionItem->expandTop(gy - mCurrentCellY); mActionItem->resize(mActionItem->width(), mGridSpacingY * mActionItem->cellHeight()); int x,y; gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); //moveChild(mActionItem,childX(mActionItem),y); QScrollView::moveChild( mActionItem,childX(mActionItem),y ); } } else if (mActionType == RESIZEBOTTOM) { if (mCurrentCellY >= mActionItem->cellYTop()) { mActionItem->expandBottom(gy - mCurrentCellY); mActionItem->resize(mActionItem->width(), mGridSpacingY * mActionItem->cellHeight()); } } else if (mActionType == RESIZELEFT) { if (mCurrentCellX <= mActionItem->cellXWidth()) { mActionItem->expandLeft(gx - mCurrentCellX); mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), mActionItem->height()); int x,y; gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); moveChild(mActionItem,x,childY(mActionItem)); } } else if (mActionType == RESIZERIGHT) { if (mCurrentCellX >= mActionItem->cellX()) { mActionItem->expandRight(gx - mCurrentCellX); mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), mActionItem->height()); } } mCurrentCellX = gx; mCurrentCellY = gy; } } void KOAgenda::endItemAction() { if ( mItemMoved ) { KOAgendaItem *placeItem = mActionItem->firstMultiItem(); if ( !placeItem ) { placeItem = mActionItem; } if ( placeItem->incidence()->recurrence()->doesRecur() ) { Incidence* oldInc = placeItem->incidence(); placeItem->recreateIncidence(); emit addToCalSignal(placeItem->incidence(), oldInc ); } int type = mActionType; if ( mAllDayMode ) type = -1; KOAgendaItem *modifiedItem = placeItem; //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); KOAgendaItem *item; if ( placeItem->incidence()->type() == "Todo" ) { mSelectedItem = 0; //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); modifiedItem->mLastMoveXPos = mCurrentCellX; emit itemModified( modifiedItem, mActionType ); } else { #if 0 for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { placeSubCells(item); } while ( placeItem ) { //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); placeSubCells( placeItem ); placeItem = placeItem->nextMultiItem(); } #endif globalFlagBlockAgendaItemPaint = 1; for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { placeSubCells(item); } while ( placeItem ) { //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); oldconflictItems = placeItem->conflictItems(); for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { placeSubCells(item); } placeSubCells( placeItem ); placeItem = placeItem->nextMultiItem(); } globalFlagBlockAgendaItemPaint = 0; for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { globalFlagBlockAgendaItemUpdate = 0; item->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; item->repaint( false ); } placeItem = modifiedItem; while ( placeItem ) { //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); globalFlagBlockAgendaItemUpdate = 0; placeItem->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; placeItem->repaint(false); placeItem = placeItem->nextMultiItem(); } emit itemModified( modifiedItem, mActionType ); placeItem = modifiedItem; while ( placeItem ) { oldconflictItems = placeItem->conflictItems(); for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { placeSubCells(item); } placeSubCells( placeItem ); placeItem = placeItem->nextMultiItem(); } placeItem = modifiedItem; while ( placeItem ) { oldconflictItems = placeItem->conflictItems(); for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { globalFlagBlockAgendaItemUpdate = 0; item->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; item->repaint(false); } placeItem = placeItem->nextMultiItem(); } /* oldconflictItems = modifiedItem->conflictItems(); for ( item=oldconflictItems.first(); item != 0; item=oldconflictItems.next() ) { globalFlagBlockAgendaItemUpdate = 0; item->paintMe(false); globalFlagBlockAgendaItemUpdate = 1; item->repaint(false); } */ } } mScrollUpTimer.stop(); mScrollDownTimer.stop(); setCursor( arrowCursor ); mActionItem = 0; mActionType = NOP; mItemMoved = 0; } void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) { // kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; // QPoint point = viewport()->mapToGlobal(viewportPos); // kdDebug() << "Global: " << point.x() << "," << point.y() << endl; // point = clipper()->mapFromGlobal(point); // kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; int x,y; viewportToContents(viewportPos.x(),viewportPos.y(),x,y); // kdDebug() << "contents: " << x << "," << y << "\n" << endl; int gx,gy; contentsToGrid(x,y,gx,gy); // Change cursor to resize cursor if appropriate if (mAllDayMode) { int gridDistanceX = (x - gx * mGridSpacingX); if (gridDistanceX < mResizeBorderWidth && moveItem->cellX() == gx) { setCursor(sizeHorCursor); } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && moveItem->cellXWidth() == gx) { setCursor(sizeHorCursor); } else { setCursor(arrowCursor); } } else { int gridDistanceY = (y - gy * mGridSpacingY); if (gridDistanceY < mResizeBorderWidth && moveItem->cellYTop() == gy && !moveItem->firstMultiItem()) { setCursor(sizeVerCursor); } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && moveItem->cellYBottom() == gy && !moveItem->lastMultiItem()) { setCursor(sizeVerCursor); } else { setCursor(arrowCursor); } } } /* Place item in cell and take care that multiple items using the same cell do not overlap. This method is not yet optimal. It doesnīt use the maximum space it can get in all cases. At the moment the method has a bug: When an item is placed only the sub cell widths of the items are changed, which are within the Y region the item to place spans. When the sub cell width change of one of this items affects a cell, where other items are, which do not overlap in Y with the item to place, the display gets corrupted, although the corruption looks quite nice. */ void KOAgenda::placeSubCells(KOAgendaItem *placeItem) { QPtrList<KOAgendaItem> conflictItems; int maxSubCells = 0; QIntDict<KOAgendaItem> subCellDict(5); KOAgendaItem *item; for ( item=mItems.first(); item != 0; item=mItems.next() ) { if (item != placeItem) { if (placeItem->cellX() <= item->cellXWidth() && placeItem->cellXWidth() >= item->cellX()) { if ((placeItem->cellYTop() <= item->cellYBottom()) && (placeItem->cellYBottom() >= item->cellYTop())) { conflictItems.append(item); if (item->subCells() > maxSubCells) maxSubCells = item->subCells(); subCellDict.insert(item->subCell(),item); } } } } if (conflictItems.count() > 0) { // Look for unused sub cell and insert item int i; for(i=0;i<maxSubCells;++i) { if (!subCellDict.find(i)) { placeItem->setSubCell(i); break; } } if (i == maxSubCells) { placeItem->setSubCell(maxSubCells); maxSubCells++; // add new item to number of sub cells } // Prepare for sub cell geometry adjustment int newSubCellWidth; if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; else newSubCellWidth = mGridSpacingX / maxSubCells; conflictItems.append(placeItem); // Adjust sub cell geometry of all direct conflict items for ( item=conflictItems.first(); item != 0; item=conflictItems.next() ) { item->setSubCells(maxSubCells); if (mAllDayMode) { item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); } else { item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); } int x,y; gridToContents(item->cellX(),item->cellYTop(),x,y); if (mAllDayMode) { y += item->subCell() * newSubCellWidth; } else { x += item->subCell() * newSubCellWidth; } moveChild(item,x,y); // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); //item->updateItem(); } // Adjust sub cell geometry of all conflict items of all conflict items for ( item=conflictItems.first(); item != 0; item=conflictItems.next() ) { if ( placeItem != item ) { KOAgendaItem *item2; QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); for ( item2=conflictItems2.first(); item2 != 0; item2=conflictItems2.next() ) { if ( item2->subCells() != maxSubCells) { item2->setSubCells(maxSubCells); if (mAllDayMode) { item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); } else { item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); } int x,y; gridToContents(item2->cellX(),item2->cellYTop(),x,y); if (mAllDayMode) { y += item2->subCell() * newSubCellWidth; } else { x += item2->subCell() * newSubCellWidth; } moveChild(item2,x,y); //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); } } } } } else { placeItem->setSubCell(0); placeItem->setSubCells(1); if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); else placeItem->resize(mGridSpacingX,placeItem->height()); int x,y; gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); moveChild(placeItem,x,y); } placeItem->setConflictItems(conflictItems); // for ( item=conflictItems.first(); item != 0; // item=conflictItems.next() ) { // //item->updateItem(); // //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); // } // placeItem->updateItem(); } void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) { if ( globalFlagBlockAgenda ) return; //qDebug("KOAgenda::drawContents "); if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) ;//drawContentsToPainter(); QPaintDevice* pd = p->device(); p->end(); int vx, vy; int selectionX = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - mSelectionCellX) * mGridSpacingX : mSelectionCellX * mGridSpacingX; contentsToViewport ( cx, cy, vx,vy); // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); if ( mSelectionHeight > 0 ) { //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { contentsToViewport ( selectionX, mSelectionYTop, vx,vy); bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); } } //qDebug("btbl "); p->begin( pd ); //qDebug("end "); } void KOAgenda::finishUpdate() { KOAgendaItem *item; globalFlagBlockAgendaItemPaint = 1; // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems for ( item=mItems.first(); item != 0; item=mItems.next() ) { if ( !item->checkLayout() ) { //qDebug(" conflictitem found "); int newSubCellWidth; if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); else newSubCellWidth = mGridSpacingX / item->subCells(); if (mAllDayMode) { item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); } else { item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); } int x,y; gridToContents(item->cellX(),item->cellYTop(),x,y); if (mAllDayMode) { y += item->subCell() * newSubCellWidth; } else { x += item->subCell() * newSubCellWidth; } moveChild(item,x,y); } } for ( item=mItems.first(); item != 0; item=mItems.next() ) { if ( !item->isVisible() ) item->show(); } globalFlagBlockAgendaItemUpdate = 0; for ( item=mItems.first(); item != 0; item=mItems.next() ) { item->repaintMe( ); } globalFlagBlockAgendaItemUpdate = 1; qApp->processEvents(); globalFlagBlockAgendaItemPaint = 0; for ( item=mItems.first(); item != 0; item=mItems.next() ) { item->repaint( false ); } } /* Draw grid in the background of the agenda. */ void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) { if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) return; if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) return; int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); if ( ch < 1 ) ch = 1; if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { mPaintPixmap.resize( contentsWidth()+42, ch ); } mCurPixWid = contentsWidth(); mCurPixHei = ch; if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) { mHighlightPixmap.resize( mGridSpacingX-1, ch ); mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); } mPixPainter.begin( &mPaintPixmap) ; //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); QPainter * p ; if (paint == 0) { mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); p = &mPixPainter; } else p = paint ; // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); //--cx;++cw; int lGridSpacingY = mGridSpacingY*2; int selDay; if ( !backgroundOnly ) for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) { if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) { int x1 = cx; int y1 = 0; if (y1 < cy) y1 = cy; int x2 = cx+cw-1; int y2 = contentsHeight(); if (y2 > cy+ch-1) y2=cy+ch-1; if (x2 >= x1 && y2 >= y1) { int gxStart = selDay; int gxEnd = gxStart ; int xStart = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gxStart)*mGridSpacingX : gxStart*mGridSpacingX; if (xStart < x1) xStart = x1; int xEnd = KOGlobals::self()->reverseLayout() ? (mColumns - gxStart)*mGridSpacingX-1 : (gxStart+1)*mGridSpacingX-1; if (xEnd > x2) xEnd = x2; if ( KOPrefs::instance()->mUseHighlightLightColor ) p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, KOPrefs::instance()->mAgendaBgColor.light()); else p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, KOPrefs::instance()->mAgendaBgColor.dark()); } } } // Highlight working hours if ( !backgroundOnly ) if (mWorkingHoursEnable) { int x1 = cx; int y1 = mWorkingHoursYTop; if (y1 < cy) y1 = cy; int x2 = cx+cw-1; // int x2 = mGridSpacingX * 5 - 1; // if (x2 > cx+cw-1) x2 = cx + cw - 1; int y2 = mWorkingHoursYBottom; if (y2 > cy+ch-1) y2=cy+ch-1; if (x2 >= x1 && y2 >= y1) { // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); int gxStart = x1/mGridSpacingX; int gxEnd = x2/mGridSpacingX; while(gxStart <= gxEnd) { if (gxStart < int(mHolidayMask->count()) && !mHolidayMask->at(gxStart)) { int xStart = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gxStart)*mGridSpacingX : gxStart*mGridSpacingX; if (xStart < x1) xStart = x1; int xEnd = KOGlobals::self()->reverseLayout() ? (mColumns - gxStart)*mGridSpacingX-1 : (gxStart+1)*mGridSpacingX-1; if (xEnd > x2) xEnd = x2; if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) { if ( KOPrefs::instance()->mUseHighlightLightColor ) p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, KOPrefs::instance()->mWorkingHoursColor.light()); else p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, KOPrefs::instance()->mWorkingHoursColor.dark()); } else { p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, KOPrefs::instance()->mWorkingHoursColor); } } ++gxStart; } } } /* int selectionX = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - mSelectionCellX) * mGridSpacingX : mSelectionCellX * mGridSpacingX; // Draw selection if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { // TODO: paint only part within cx,cy,cw,ch p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight, KOPrefs::instance()->mHighlightColor ); } */ // Draw vertical lines of grid int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; if ( mGridSpacingX > 0 ) { while (x < cx + cw) { p->drawLine(x,cy,x,cy+ch); x+=mGridSpacingX; } } // Draw horizontal lines of grid int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; if ( lGridSpacingY > 0 ) { while (y < cy + ch) { p->setPen( SolidLine ); p->drawLine(cx,y,cx+cw,y); y+=lGridSpacingY; p->setPen( DotLine ); p->drawLine(cx,y,cx+cw,y); y+=lGridSpacingY; } p->setPen( SolidLine ); } mPixPainter.end() ; } /* Convert srcollview contents coordinates to agenda grid coordinates. */ void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) { gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : x/mGridSpacingX; gy = y/mGridSpacingY; } /* Convert agenda grid coordinates to scrollview contents coordinates. */ void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) { x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: gx*mGridSpacingX; y = gy*mGridSpacingY; } /* Return Y coordinate corresponding to time. Coordinates are rounded to fit into the grid. */ int KOAgenda::timeToY(const QTime &time) { int minutesPerCell = 24 * 60 / mRows; int timeMinutes = time.hour() * 60 + time.minute(); int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; return Y; } /* Return time corresponding to cell y coordinate. Coordinates are rounded to fit into the grid. */ QTime KOAgenda::gyToTime(int gy) { int secondsPerCell = 24 * 60 * 60/ mRows; int timeSeconds = secondsPerCell * gy; QTime time( 0, 0, 0 ); if ( timeSeconds < 24 * 60 * 60 ) { time = time.addSecs(timeSeconds); } else { time.setHMS( 23, 59, 59 ); } return time; } void KOAgenda::setStartHour(int startHour) { int startCell = startHour * mRows / 24; setContentsPos(0,startCell * gridSpacingY()); } void KOAgenda::hideUnused() { // experimental only // return; KOAgendaItem *item; for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { item->hide(); } } KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) { KOAgendaItem *fi; for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { if ( fi->incidence() == event ) { mUnusedItems.remove(); fi->init( event, qd ); return fi; } } fi=mUnusedItems.first(); if ( fi ) { mUnusedItems.remove(); fi->init( event, qd ); return fi; } // qDebug("new KOAgendaItem "); KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); agendaItem->installEventFilter(this); addChild(agendaItem,0,0); return agendaItem; } KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) { KOAgendaItem *item; for ( item=mItems.first(); item != 0; item=mItems.next() ) { if ( item->incidence() == todo ) { mItems.remove(); return item; } } return 0; } void KOAgenda::updateTodo( Todo * todo, int days, bool remove) { // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )|| KOAgendaItem *item; item = getItemForTodo ( todo ); //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); if ( item ) { blockSignals( true ); //qDebug("item found "); item->hide(); item->setCellX(-2, -1 ); item->select(false); mUnusedItems.append( item ); mItems.remove( item ); QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); KOAgendaItem *itemit; //globalFlagBlockAgendaItemPaint = 1; for ( itemit=oldconflictItems.first(); itemit != 0; itemit=oldconflictItems.next() ) { if ( itemit != item ) placeSubCells(itemit); } qApp->processEvents(); //globalFlagBlockAgendaItemPaint = 0; for ( itemit=oldconflictItems.first(); itemit != 0; itemit=oldconflictItems.next() ) { globalFlagBlockAgendaItemUpdate = 0; if ( itemit != item ) itemit->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; itemit->repaint(); } blockSignals( false ); } if ( remove ) { //qDebug("remove****************************************** "); return; } //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda ); QDate currentDate; QDateTime dt; if ( todo->hasCompletedDate() ) dt = todo->completed(); else dt = todo->dtDue(); if ( overdue ) { currentDate = QDate::currentDate(); days += todo->dtDue().date().daysTo( currentDate ); } else currentDate = dt.date(); if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) { if ( ! mAllDayMode ) return; // aldayagenda globalFlagBlockAgendaItemPaint = 1; item = insertAllDayItem(todo, currentDate,days, days); item->show(); } else { if ( mAllDayMode ) return; // mAgenda globalFlagBlockAgendaItemPaint = 1; int endY = timeToY(dt.time()) - 1; int hi = 12/KOPrefs::instance()->mHourSize; int startY = endY - 1-hi; item = insertItem(todo,currentDate,days,startY,endY); item->show(); } qApp->processEvents(); globalFlagBlockAgendaItemPaint = 0; QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); KOAgendaItem *itemit; for ( itemit=oldconflictItems.first(); itemit != 0; itemit=oldconflictItems.next() ) { globalFlagBlockAgendaItemUpdate = 0; itemit->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; itemit->repaint(); } globalFlagBlockAgendaItemUpdate = 0; item->repaintMe(); globalFlagBlockAgendaItemUpdate = 1; item->repaint(); } /* Insert KOAgendaItem into agenda. */ KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) { //kdDebug() << "KOAgenda::insertItem:" << event->summary() << "-" << qd.toString() << " ;top, bottom:" << YTop << "," << YBottom << endl; if (mAllDayMode) { kdDebug() << "KOAgenda: calling insertItem in all-day mode is illegal." << endl; return 0; } KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); //agendaItem->setFrameStyle(WinPanel|Raised); int YSize = YBottom - YTop + 1; if (YSize < 0) { kdDebug() << "KOAgenda::insertItem(): Text: " << agendaItem->text() << " YSize<0" << endl; YSize = 1; } int iheight = mGridSpacingY * YSize; agendaItem->resize(mGridSpacingX,iheight ); agendaItem->setCellXY(X,YTop,YBottom); agendaItem->setCellXWidth(X); //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); mItems.append(agendaItem); placeSubCells(agendaItem); //agendaItem->show(); marcus_bains(); return agendaItem; } /* Insert all-day KOAgendaItem into agenda. */ KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) { if (!mAllDayMode) { return 0; } KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); agendaItem->setCellXY(XBegin,0,0); agendaItem->setCellXWidth(XEnd); agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); //addChild(agendaItem,XBegin*mGridSpacingX,0); mItems.append(agendaItem); placeSubCells(agendaItem); //agendaItem->show(); return agendaItem; } void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, int YTop,int YBottom) { if (mAllDayMode) { ; return; } int cellX,cellYTop,cellYBottom; QString newtext; int width = XEnd - XBegin + 1; int count = 0; KOAgendaItem *current = 0; QPtrList<KOAgendaItem> multiItems; for (cellX = XBegin;cellX <= XEnd;++cellX) { if (cellX == XBegin) cellYTop = YTop; else cellYTop = 0; if (cellX == XEnd) cellYBottom = YBottom; else cellYBottom = rows() - 1; newtext = QString("(%1/%2): ").arg(++count).arg(width); newtext.append(event->summary()); current = insertItem(event,qd,cellX,cellYTop,cellYBottom); current->setText(newtext); multiItems.append(current); } KOAgendaItem *next = 0; KOAgendaItem *last = multiItems.last(); KOAgendaItem *first = multiItems.first(); KOAgendaItem *setFirst,*setLast; current = first; while (current) { next = multiItems.next(); if (current == first) setFirst = 0; else setFirst = first; if (current == last) setLast = 0; else setLast = last; current->setMultiItem(setFirst,next,setLast); current = next; } marcus_bains(); } //QSizePolicy KOAgenda::sizePolicy() const //{ // Thought this would make the all-day event agenda minimum size and the // normal agenda take the remaining space. But it doesnīt work. The QSplitter // donīt seem to think that an Expanding widget needs more space than a // Preferred one. // But it doesnīt hurt, so it stays. // if (mAllDayMode) { // return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); // } else { // return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); // } //} void KOAgenda::finishResize ( ) { //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); if ( globalFlagBlockAgenda == 0 ) { finishUpdate(); //qDebug("finishUpdate() called "); } } /* Overridden from QScrollView to provide proper resizing of KOAgendaItems. */ void KOAgenda::resizeEvent ( QResizeEvent *ev ) { mResizeTimer.start( 150 , true ); computeSizes(); return; } void KOAgenda::computeSizes() { if ( globalFlagBlockStartup ) return; if (mAllDayMode) { mGridSpacingX = (width()-3) / mColumns; mGridSpacingY = height() - 2 * frameWidth() - 1; resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); // mGridSpacingY = height(); // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); KOAgendaItem *item; int subCellWidth; for ( item=mItems.first(); item != 0; item=mItems.next() ) { subCellWidth = mGridSpacingY / item->subCells(); item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); moveChild(item,KOGlobals::self()->reverseLayout() ? (mColumns - 1 - item->cellX()) * mGridSpacingX : item->cellX() * mGridSpacingX, item->subCell() * subCellWidth); } KOPrefs::instance()->mAllDaySize = mGridSpacingY; } else { mGridSpacingX = (width() - verticalScrollBar()->width()-3)/mColumns; if (height() > mGridSpacingY * mRows + 1 ) { KOPrefs::instance()->mHourSize = ((height())/mRows)+1; mGridSpacingY = KOPrefs::instance()->mHourSize ; resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); emit resizedSignal(); } else resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); KOAgendaItem *item; int subCellWidth; for ( item=mItems.first(); item != 0; item=mItems.next() ) { subCellWidth = mGridSpacingX / item->subCells(); item->resize(subCellWidth,item->height()); moveChild(item,(KOGlobals::self()->reverseLayout() ? (mColumns - 1 - item->cellX()) * mGridSpacingX : item->cellX() * mGridSpacingX) + item->subCell() * subCellWidth,childY(item)); } } 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 } diff --git a/libkdepim/kpimglobalprefs.cpp b/libkdepim/kpimglobalprefs.cpp index ac7d205..a09b278 100644 --- a/libkdepim/kpimglobalprefs.cpp +++ b/libkdepim/kpimglobalprefs.cpp @@ -1,211 +1,211 @@ /* This file is part of libkdepim. Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <kglobal.h> #include <kconfig.h> #include <klocale.h> #include <kdebug.h> #include <kglobalsettings.h> #include <kstaticdeleter.h> #include <qregexp.h> #include <qfile.h> #include <stdlib.h> #include <qtextstream.h> #include <qapplication.h> #include "kpimglobalprefs.h" KPimGlobalPrefs *KPimGlobalPrefs::sInstance = 0; static KStaticDeleter<KPimGlobalPrefs> staticDeleterGP; KPimGlobalPrefs::KPimGlobalPrefs( const QString &name ) : KPrefs("microkdeglobalrc") { mLocaleDict = 0; KPrefs::setCurrentGroup("Fonts"); addItemFont("ApplicationFont",&mApplicationFont,KGlobalSettings::generalFont() ); KPrefs::setCurrentGroup("Locale"); addItemInt("PreferredLanguage",&mPreferredLanguage,0); addItemInt("PreferredTime",&mPreferredTime,0); addItemInt("PreferredDate",&mPreferredDate,0); addItemBool("WeekStartsOnSunday",&mWeekStartsOnSunday,false); - addItemString("UserDateFormatLong", &mUserDateFormatLong, "%A %d %b %y"); + addItemString("UserDateFormatLong", &mUserDateFormatLong, "%AK %d. %b %y"); addItemString("UserDateFormatShort", &mUserDateFormatShort, "%aK %d.%m.%y"); KPrefs::setCurrentGroup("Time & Date"); addItemString("TimeZoneName",&mTimeZoneId, ("+01:00 Europe/Oslo(CET)") ); addItemBool("UseDaylightsaving",&mUseDaylightsaving,true); addItemBool("TimeZoneAdd30min",&mTimeZoneAdd30min,false); addItemInt("DaylightsavingStart",&mDaylightsavingStart,90); addItemInt("DaylightsavingEnd",&mDaylightsavingEnd,304); KPrefs::setCurrentGroup( "ExternalApplications" ); addItemInt( "EmailChannelType", &mEmailClient, OMPI_EMC ); addItemString( "EmailChannel", &mEmailOtherChannel, "" ); addItemString( "EmailChannelMessage", &mEmailOtherMessage, "" ); addItemString( "EmailChannelParameters", &mEmailOtherMessageParameters, "" ); addItemString( "EmailChannelMessage2", &mEmailOtherMessage2, "" ); addItemString( "EmailChannelParameters2", &mEmailOtherMessageParameters2, "" ); addItemInt( "PhoneChannelType", &mPhoneClient, KPPI_PHC ); addItemString( "PhoneChannel", &mPhoneOtherChannel, "" ); addItemString( "PhoneChannelMessage", &mPhoneOtherMessage, "" ); addItemString( "PhoneChannelParameters", &mPhoneOtherMessageParameters, "" ); addItemInt( "FaxChannelType", &mFaxClient, NONE_FAC ); addItemString( "FaxChannel", &mFaxOtherChannel, "" ); addItemString( "FaxChannelMessage", &mFaxOtherMessage, "" ); addItemString( "FaxChannelParameters", &mFaxOtherMessageParameters, "" ); addItemInt( "SMSChannelType", &mSMSClient, NONE_SMC ); addItemString( "SMSChannel", &mSMSOtherChannel, "" ); addItemString( "SMSChannelMessage", &mSMSOtherMessage, "" ); addItemString( "SMSChannelParameters", &mSMSOtherMessageParameters, "" ); addItemInt( "PagerChannelType", &mPagerClient, NONE_PAC ); addItemString( "PagerChannel", &mPagerOtherChannel, "" ); addItemString( "PagerChannelMessage", &mPagerOtherMessage, "" ); addItemString( "PagerChannelParameters", &mPagerOtherMessageParameters, "" ); addItemInt( "SIPChannelType", &mSipClient, KPPI_SIC ); addItemString( "SIPChannel", &mSipOtherChannel, "" ); addItemString( "SIPChannelMessage", &mSipOtherMessage, "" ); addItemString( "SIPChannelParameters", &mSipOtherMessageParameters, "" ); KPrefs::setCurrentGroup( "PhoneAccess" ); addItemString("Ex2PhoneDevice",&mEx2PhoneDevice,"/dev/ircomm"); addItemString("Ex2PhoneConnection",&mEx2PhoneConnection,"irda"); addItemString("Ex2PhoneModel",&mEx2PhoneModel,"6310i"); } void KPimGlobalPrefs::setGlobalConfig() { if ( mLocaleDict == 0 ) { QString fileName ; QString name = KGlobal::getAppName() +"/"; #ifndef DESKTOP_VERSION fileName= QString(getenv("QPEDIR"))+"/pics/kdepim/"+name; #else fileName = qApp->applicationDirPath () + "/kdepim/"+ name; #endif mLocaleDict = 0; if ( mPreferredLanguage > 0 && mPreferredLanguage < 5 ) { if ( mPreferredLanguage == 1 ) fileName = fileName+"germantranslation.txt"; else if ( mPreferredLanguage == 4 ) fileName = fileName+"usertranslation.txt"; else if ( mPreferredLanguage == 2 ) fileName = fileName+"frenchtranslation.txt"; else if ( mPreferredLanguage == 3 ) fileName = fileName+"italiantranslation.txt"; QFile file( fileName ); if (file.open( IO_ReadOnly ) ) { QTextStream ts( &file ); ts.setEncoding( QTextStream::Latin1 ); //ts.setCodec( QTextCodec::latin1 ); QString text = ts.read(); file.close(); text.replace( QRegExp("\\\\n"), "\n" ); QString line; QString we; QString wt; int br = 0; int nbr; nbr = text.find ( "},", br ); line = text.mid( br, nbr - br ); br = nbr+1; int se, ee, st, et; mLocaleDict = new QDict<QString>; mLocaleDict->setAutoDelete( true ); QString end = "{ \"\",\"\" }"; while ( (line != end) && (br > 1) ) { //qDebug("%d *%s* ", br, line.latin1()); se = line.find("\"")+1; et = line.findRev("\"",-1); ee = line.find("\",\""); st = ee+3; we = line.mid( se, ee-se ); if ( mPreferredLanguage == 4 ) wt = QString::fromUtf8(line.mid( st, et-st ).latin1()); else wt = line.mid( st, et-st ); //qDebug("*%s* *%s* ", we.latin1(), wt.latin1()); mLocaleDict->insert( we, new QString (wt) ); nbr = text.find ( "}", br ); line = text.mid( br, nbr - br ); br = nbr+1; } //qDebug("end *%s* ", end.latin1()); setLocaleDict( mLocaleDict ); } else { qDebug("KO: Cannot find translation file %s",fileName.latin1() ); } } } KGlobal::locale()->setHore24Format( !mPreferredTime ); KGlobal::locale()->setWeekStartMonday( !mWeekStartsOnSunday ); KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)mPreferredDate ); KGlobal::locale()->setLanguage( mPreferredLanguage ); QString dummy = mUserDateFormatLong; KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); dummy = mUserDateFormatShort; KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); KGlobal::locale()->setDaylightSaving( mUseDaylightsaving, mDaylightsavingStart, mDaylightsavingEnd ); KGlobal::locale()->setTimezone( mTimeZoneId, mTimeZoneAdd30min ); } KPimGlobalPrefs::~KPimGlobalPrefs() { if (sInstance == this) sInstance = staticDeleterGP.setObject(0); else qDebug("Whats this? Error in KPimGlobalPrefs::~KPimGlobalPrefs() ?"); if ( mLocaleDict ) delete mLocaleDict; } KPimGlobalPrefs *KPimGlobalPrefs::instance() { if ( !sInstance ) { sInstance = staticDeleterGP.setObject( new KPimGlobalPrefs() ); sInstance->readConfig(); } return sInstance; } |