author | zautrix <zautrix> | 2005-03-21 13:56:46 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-21 13:56:46 (UTC) |
commit | 41f264fea6caaf9ca0f8b34509a07157c210f851 (patch) (side-by-side diff) | |
tree | f49b5d10db838821f79d5ae3d28b492f76663b62 /korganizer | |
parent | 098a3c6dd844a880beb2851be53314613c3a038d (diff) | |
download | kdepimpi-41f264fea6caaf9ca0f8b34509a07157c210f851.zip kdepimpi-41f264fea6caaf9ca0f8b34509a07157c210f851.tar.gz kdepimpi-41f264fea6caaf9ca0f8b34509a07157c210f851.tar.bz2 |
fixes
-rw-r--r-- | korganizer/kdatenavigator.cpp | 2 | ||||
-rw-r--r-- | korganizer/kdatenavigator.h | 2 | ||||
-rw-r--r-- | korganizer/kodaymatrix.cpp | 8 |
3 files changed, 8 insertions, 4 deletions
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp index 4b50b5a..2321acb 100644 --- a/korganizer/kdatenavigator.cpp +++ b/korganizer/kdatenavigator.cpp @@ -1,368 +1,368 @@ /* This file is part of KOrganizer. Copyright (c) 2001,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. */ #include <qstring.h> #include <qkeycode.h> #include <qlayout.h> #include <qtimer.h> #include <qframe.h> #include <qlabel.h> #include <qapplication.h> #include <kdebug.h> #include <klocale.h> #include <kglobal.h> #include "koglobals.h" #include "koprefs.h" #ifndef KORG_NOPLUGINS #include "kocore.h" #endif #include <kcalendarsystem.h> #include "navigatorbar.h" #include "kdatenavigator.h" KDateNavigator::KDateNavigator( QWidget *parent, const char *name ) : QFrame(parent, name), updateTimer(0L) { setFrameStyle(QFrame::NoFrame); QDate startDate = QDate::currentDate(); QGridLayout *topLayout = new QGridLayout(this,8,8); if (! startDate.isValid()) { qDebug("KDateNavigator::invalid startdate "); startDate = QDate::currentDate(); } mMonthSignalOffset = 0; mSelectedDates.append(startDate); m_MthYr = startDate; m_bShowWeekNums = true; setFont( KOPrefs::instance()->mDateNavigatorFont ); mNavigatorBar = new NavigatorBar( startDate, this ); topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 ); //mNavigatorBar->resize( 1,1); connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); // get the day of the week on the first day QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); m_fstDayOfWk = dayone.dayOfWeek(); int i; // Set up the heading fields. for( i = 0; i < 7; i++ ) { headings[i] = new QLabel("",this); //headings[i]->setFont(QFont("Arial", 10, QFont::Bold)); headings[i]->setAlignment(AlignCenter); topLayout->addWidget(headings[i],1,i+1); } // Create the weeknumber labels for( i = 0; i < 6; i++ ) { weeknos[i] = new QLabel(this); weeknos[i]->setAlignment(AlignCenter); //weeknos[i]->setFont(QFont("Arial", 10)); if(!m_bShowWeekNums) { weeknos[i]->hide(); } weeknos[i]->installEventFilter(this); topLayout->addWidget(weeknos[i],i+2,0); } daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix"); daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken); daymatrix->setLineWidth(1); connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ), SIGNAL( datesSelected( const KCal::DateList & ) ) ); connect( daymatrix, SIGNAL( eventDropped( Event * ) ), SIGNAL( eventDropped( Event * ) ) ); topLayout->addMultiCellWidget(daymatrix,2,7,1,7); // read settings from configuration file. updateConfig(); enableRollover(FollowMonth); mySizeHint = sizeHintTwoButtons(); mFontChanged = false; } void KDateNavigator::changeFont ( QFont fo ) { setFont( fo ); mNavigatorBar->resetFont( fo ); } QFont KDateNavigator::yourFontHint( QSize si , bool *b) { QFont fo = KOPrefs::instance()->mDateNavigatorFont; *b = false; int fontPoint = fo.pointSize(); while ( fontPoint > 5 ) { --fontPoint; fo.setPointSize( fontPoint ); setFont( fo ); mFontChanged = true; mNavigatorBar->resetFont( fo ); QSize sh = sizeHintTwoButtons(); //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() ); if ( si.width() > sh.width() && si.height() > sh.height()) { *b = true; //qDebug("fooooooooooooooooooooooouuuuund "); break; } } //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() ); return fo; } QSize KDateNavigator::sizeHint() const { QFontMetrics fm ( font() ); QSize day = daymatrix->sizeHint(); QSize nav = mNavigatorBar->sizeHint(); int wid = fm.width( "30") + day.width()+3; int hei = fm.height() +day.height()+nav.height()+2; if ( wid < nav.width() ) wid = nav.width() ; //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); return QSize ( wid, hei ); } QSize KDateNavigator::sizeHintTwoButtons() const { QFontMetrics fm ( font() ); QSize day = daymatrix->sizeHint(); QSize nav = mNavigatorBar->sizeHintTwoButtons(); int wid = fm.width( "30") + day.width()+3; int hei = fm.height() +day.height()+nav.height()+2; if ( wid < nav.width() ) wid = nav.width() ; //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); return QSize ( wid, hei ); } void KDateNavigator::slotMonthSelected( int m ) { if ( m_MthYr.month() <= mMonthSignalOffset) m += 12; - int mo = m - mMonthSignalOffset; + //qDebug("%d mMonthSignalOffset %d emit %d", m, mMonthSignalOffset, m - mMonthSignalOffset); emit monthSelected( m - mMonthSignalOffset ); } void KDateNavigator::setCalendar( Calendar *cal ) { daymatrix->setCalendar( cal ); } void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true { m_MthYr = date; updateDates(); updateView(); KCal::DateList dates; dates.append( date ); mNavigatorBar->selectDates( dates ); daymatrix->clearSelection(); if ( doRepaint ) daymatrix->repaint(); } void KDateNavigator::enableRollover(RolloverType r) { switch(r) { case None : if (updateTimer) { updateTimer->stop(); delete updateTimer; updateTimer=0L; } break; case FollowDay : case FollowMonth : if (!updateTimer) { updateTimer = new QTimer(this); QObject::connect(updateTimer,SIGNAL(timeout()), this,SLOT(possiblyPastMidnight())); } updateTimer->start(0,true); lastDayChecked = QDate::currentDate(); } updateRollover=r; } KDateNavigator::~KDateNavigator() { } void KDateNavigator::passedMidnight() { QDate today = QDate::currentDate(); bool emitMonth = false; if (today.month() != lastDayChecked.month()) { if (updateRollover==FollowMonth && daymatrix->isEndOfMonth()) { goNextMonth(); emitMonth=true; } } daymatrix->recalculateToday(); daymatrix->repaint(); emit dayPassed(today); if (emitMonth) { emit monthPassed(today); } } /* slot */ void KDateNavigator::possiblyPastMidnight() { if (lastDayChecked!=QDate::currentDate()) { passedMidnight(); lastDayChecked=QDate::currentDate(); } // Set the timer to go off 1 second after midnight // or after 8 minutes, whichever comes first. if (updateTimer) { QTime now = QTime::currentTime(); QTime midnight = QTime(23,59,59); int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait)) // .arg(now.toString()).arg(midnight.toString())); updateTimer->stop(); updateTimer->start(msecsWait,true); } } void KDateNavigator::updateDates() { // Find the first day of the week of the current month. //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr ); QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() ); int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); //int di = d1 - d2 + 1; dayone = dayone.addDays( -d2 + 1 ); int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone ); // If month begins on Monday and Monday is first day of week, // month should begin on second line. Sunday doesn't have this problem. int nextLine = ( ( m_fstDayOfWkCalsys == 1) && ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0; // update the matrix dates int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine; daymatrix->updateView(dayone.addDays(index)); //each updateDates is followed by an updateView -> repaint is issued there ! // daymatrix->repaint(); } void KDateNavigator::updateDayMatrix() { daymatrix->updateView(); //daymatrix->repaint(); } void KDateNavigator::updateView() { setUpdatesEnabled( false ); int i; // kdDebug() << "updateView() -> daymatrix->updateView()" << endl; daymatrix->updateView(); // set the week numbers. for(i = 0; i < 6; i++) { QString weeknum; // remember, according to ISO 8601, the first week of the year is the // first week that contains a thursday. Thus we must subtract off 4, // not just 1. //ET int dayOfYear = buttons[(i + 1) * 7 - 4]->date().dayOfYear(); int dayOfYear = KOGlobals::self()->calendarSystem()->dayOfYear((daymatrix->getDate((i+1)*7-4))); int add = 0; if ( ! KGlobal::locale()->weekStartsMonday() ) ++add; if (dayOfYear % 7 != 0) weeknum.setNum(dayOfYear / 7 + 1+add); else weeknum.setNum(dayOfYear / 7 +add); weeknos[i]->setText(weeknum); } setUpdatesEnabled( true ); // kdDebug() << "updateView() -> repaint()" << endl; repaint(); // daymatrix->repaint(); } void KDateNavigator::updateConfig() { int day; for(int i=0; i<7; i++) { // take the first letter of the day name to be the abbreviation if (KGlobal::locale()->weekStartsMonday()) { day = i+1; } else { if (i==0) day = 7; else day = i; } QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day, true ); if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 ); headings[i]->setText( dayName ); } updateDates(); updateView(); } void KDateNavigator::setShowWeekNums(bool enabled) { m_bShowWeekNums = enabled; for(int i=0; i<6; i++) { if(enabled) weeknos[i]->show(); diff --git a/korganizer/kdatenavigator.h b/korganizer/kdatenavigator.h index d1f32b6..77b9b7c 100644 --- a/korganizer/kdatenavigator.h +++ b/korganizer/kdatenavigator.h @@ -1,161 +1,161 @@ /* This file is part of KOrganizer. Copyright (c) 2001 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. */ #ifndef KDATENAVIGATOR_H #define KDATENAVIGATOR_H #include <qframe.h> #include <qdatetime.h> #include <qlabel.h> #include <libkcal/calendar.h> #include "kodaymatrix.h" class QPushButton; class QTimer; class KCalendarSystem; class NavigatorBar; class KDateNavigator: public QFrame { Q_OBJECT public: KDateNavigator( QWidget *parent = 0,const char *name = 0 ); ~KDateNavigator(); /** The DateNavigator automatically checks for * the passage of midnight. If rollover type is * set to None, no signals are emitted and no * processing is done. With rollover set to * FollowDay, the day highlighter changes at * midnight and dayPassed() is emitted. * With FollowMonth, it has the same effect * as FollowDay but also adjusts the month that is * visible and emits monthPassed() when the month changes. */ enum RolloverType { None, FollowDay, FollowMonth } ; void enableRollover( RolloverType ); void setShowWeekNums( bool enabled ); void setCalendar( Calendar * ); void setBaseDate( const QDate & , bool doRepaint = true ); KCal::DateList selectedDates() const { return mSelectedDates; } NavigatorBar *navigatorBar() const { return mNavigatorBar; } - void setMonthSignalOffset ( int off ) { mMonthSignalOffset = off;} + void setMonthSignalOffset ( int off ) { mMonthSignalOffset = off%12;} QSize yourSizeHint() { return mySizeHint; } QFont yourFontHint( QSize , bool * b); bool fontChanged() {return mFontChanged; } void unsetFontChanged() { mFontChanged = false; } KODayMatrix *dayMatrix() { return daymatrix ;} QSize sizeHint() const; QSize sizeHintTwoButtons() const; void changeFont ( QFont fo ); public slots: void selectDates( const KCal::DateList & ); void updateView(); void updateConfig(); void updateDayMatrix(); signals: void datesSelected( const KCal::DateList & ); void eventDropped( Event * ); void weekClicked( const QDate &); void goPrevious(); void goNext(); void goNextMonth(); void goPrevMonth(); void goNextYear(); void goPrevYear(); void monthSelected( int ); // Signals emitted at midnight carrying the new date. void dayPassed( QDate ); void monthPassed( QDate ); protected slots: /** * Called regularly to see if we need to update the view * wrt. the today box and the month box. Only important * if you leave KOrganizer idle for long periods of time. * * Until we have a reliable way of setting QTimers to go * off at a particular wall-clock time, we need this, * which calls passedMidnight() at the right moments. */ void possiblyPastMidnight(); /** handles updating the view when midnight has come by due to idle time. * */ void passedMidnight(); void slotMonthSelected( int m ); protected: void updateDates(); void wheelEvent (QWheelEvent *); bool eventFilter (QObject *,QEvent *); private: QSize mySizeHint; bool mFontChanged; int mMonthSignalOffset; NavigatorBar *mNavigatorBar; QFrame *headingSep; QFrame *weeknumSep; QLabel *headings[7]; QLabel *weeknos[7]; KODayMatrix *daymatrix; KCal::DateList mSelectedDates; QDate m_MthYr; int m_fstDayOfWk; bool m_bShowWeekNums; int dayNum(int row, int col); int dayToIndex(int dayNum); Calendar *mCalendar; KCalendarSystem *mCalendarSystem; const QString *curHeaders; /** used to update the day view periodically, in particular every * midnight to move the "today" rectangle. */ QTimer *updateTimer; QDate lastDayChecked; RolloverType updateRollover; // Disabling copy constructor and assignment operator KDateNavigator(const KDateNavigator & ); KDateNavigator &operator=(const KDateNavigator &); }; #endif diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index 9baff20..493382d 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp @@ -222,386 +222,386 @@ void KODayMatrix::setCalendar( Calendar *cal ) QColor KODayMatrix::getShadedColor(QColor color) { QColor shaded; int h=0; int s=0; int v=0; color.hsv(&h,&s,&v); s = s/4; v = 192+v/4; shaded.setHsv(h,s,v); return shaded; } KODayMatrix::~KODayMatrix() { // delete mKODaymatrixWhatsThis; delete [] days; delete [] daylbls; delete [] events; delete mToolTip; } /* void KODayMatrix::setStartDate(QDate start) { updateView(start); } */ void KODayMatrix::addSelectedDaysTo(DateList& selDays) { if (mSelStart == NOSELECTION) { return; } //cope with selection being out of matrix limits at top (< 0) int i0 = mSelStart; if (i0 < 0) { for (int i = i0; i < 0; i++) { selDays.append(days[0].addDays(i)); } i0 = 0; } //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) if (mSelEnd > NUMDAYS-1) { for (int i = i0; i <= NUMDAYS-1; i++) { selDays.append(days[i]); } for (int i = NUMDAYS; i < mSelEnd; i++) { selDays.append(days[0].addDays(i)); } // apply normal routine to selection being entirely within matrix limits } else { for (int i = i0; i <= mSelEnd; i++) { selDays.append(days[i]); } } } void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) { mSelStart = startdate.daysTo(start); if ( mSelStart < 0 ) mSelStart = 0; mSelEnd = startdate.daysTo(end); if ( mSelEnd < 0 ) clearSelection(); } void KODayMatrix::clearSelection() { mSelEnd = mSelStart = NOSELECTION; } void KODayMatrix::recalculateToday() { today = -1; for (int i=0; i<NUMDAYS; i++) { events[i] = 0; days[i] = startdate.addDays(i); daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); // if today is in the currently displayed month, hilight today if (days[i].year() == QDate::currentDate().year() && days[i].month() == QDate::currentDate().month() && days[i].day() == QDate::currentDate().day()) { today = i; } } // qDebug(QString("Today is visible at %1.").arg(today)); } void KODayMatrix::updateView() { updateView(startdate); } void KODayMatrix::repaintViewTimed() { mRepaintTimer->stop(); repaint(false); } void KODayMatrix::updateViewTimed() { mUpdateTimer->stop(); if ( !mCalendar ) { qDebug("NOT CAL "); return; } //qDebug("KODayMatrix::updateViewTimed "); for(int i = 0; i < NUMDAYS; i++) { // if events are set for the day then remember to draw it bold QPtrList<Event> eventlist = mCalendar->events(days[i]); Event *event; int numEvents = eventlist.count(); QString holiStr = ""; bDays.clearBit(i); for(event=eventlist.first();event != 0;event=eventlist.next()) { ushort recurType = event->recurrence()->doesRecur(); if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { numEvents--; } if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) { if ( !holiStr.isEmpty() ) holiStr += "\n"; holiStr += event->summary(); if ( !event->location().isEmpty() ) holiStr += " (" + event->location() + ")"; } if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) { if ( !holiStr.isEmpty() ) holiStr += "\n"; holiStr += i18n("Birthday") + ": "+event->summary(); if ( !event->location().isEmpty() ) holiStr += " (" + event->location() + ")"; bDays.setBit(i); } } events[i] = numEvents; //if it is a holy day then draw it red. Sundays are consider holidays, too if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || !holiStr.isEmpty()) { mHolidays[i] = holiStr; } else { mHolidays[i] = QString::null; } } if ( ! mPendingUpdateBeforeRepaint ) repaint(false); } void KODayMatrix::updateView(QDate actdate) { if ( ! actdate.isValid() ) { //qDebug("date not valid "); return; } mDayChanged = false; //flag to indicate if the starting day of the matrix has changed by this call //mDayChanged = false; // if a new startdate is to be set then apply Cornelius's calculation // of the first day to be shown if (actdate != startdate) { // reset index of selection according to shift of starting date from startdate to actdate if (mSelStart != NOSELECTION) { int tmp = actdate.daysTo(startdate); //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; // shift selection if new one would be visible at least partly ! if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { // nested if is required for next X display pushed from a different month - correction required // otherwise, for month forward and backward, it must be avoided if( mSelStart > NUMDAYS || mSelStart < 0 ) mSelStart = mSelStart + tmp; if( mSelEnd > NUMDAYS || mSelEnd < 0 ) mSelEnd = mSelEnd + tmp; } } startdate = actdate; mDayChanged = true; recalculateToday(); } //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); if ( !isVisible() ) { mPendingUpdateBeforeRepaint = true; } else { #ifdef DESKTOP_VERSION - //mRepaintTimer->start( 150 ); - mUpdateTimer->start( 150 ); + //mRepaintTimer->start( 100 ); + mUpdateTimer->start( 100 ); #else mRepaintTimer->start( 350 ); mUpdateTimer->start( 1200 ); #endif } } void KODayMatrix::updateEvents() { if ( !mCalendar ) return; for( int i = 0; i < NUMDAYS; i++ ) { // if events are set for the day then remember to draw it bold QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); int numEvents = eventlist.count(); Event *event; for( event = eventlist.first(); event != 0;event=eventlist.next()) { ushort recurType = event->doesRecur(); if ( ( recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur ) || ( recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur ) ) { numEvents--; } } events[ i ] = numEvents; } } const QDate& KODayMatrix::getDate(int offset) { if (offset < 0 || offset > NUMDAYS-1) { qDebug("Wrong offset2 %d", offset); return days[0]; } return days[offset]; } QString KODayMatrix::getHolidayLabel(int offset) { if (offset < 0 || offset > NUMDAYS-1) { qDebug("Wrong offset1 %d", offset); return QString(); } return mHolidays[offset]; } int KODayMatrix::getDayIndexFrom(int x, int y) { int colModulo = (width()-2) % 7; int rowModulo = (height()-2) % 6; #if 0 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 6 - x/daysize.width() : x/daysize.width()); #endif int xVal = (x-colModulo/2-2)/daysize.width(); int yVal = (y-rowModulo/2-2)/daysize.height(); return 7*(yVal) + xVal; } // ---------------------------------------------------------------------------- // M O U S E E V E N T H A N D L I N G // ---------------------------------------------------------------------------- void KODayMatrix::mousePressEvent (QMouseEvent* e) { if ( e->button() == LeftButton ) mouseDown = true; mSelStart = getDayIndexFrom(e->x(), e->y()); if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; mSelInit = mSelStart; mSelEnd = mSelStart; repaint(false); } void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) { if ( e->button() == LeftButton ) if ( ! mouseDown ) { return; } else mouseDown = false; int tmp = getDayIndexFrom(e->x(), e->y()); if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; if (mSelInit > tmp) { mSelEnd = mSelInit; if (tmp != mSelStart) { mSelStart = tmp; repaint(false); } } else { mSelStart = mSelInit; //repaint only if selection has changed if (tmp != mSelEnd) { mSelEnd = tmp; repaint(false); } } DateList daylist; if ( mSelStart < 0 ) mSelStart = 0; for (int i = mSelStart; i <= mSelEnd; i++) { daylist.append(days[i]); } emit selected((const DateList)daylist); } void KODayMatrix::mouseMoveEvent (QMouseEvent* e) { if ( ! mouseDown ) { return; } int tmp = getDayIndexFrom(e->x(), e->y()); if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; if (mSelInit > tmp) { mSelEnd = mSelInit; if (tmp != mSelStart) { mSelStart = tmp; repaint(false); } } else { mSelStart = mSelInit; //repaint only if selection has changed if (tmp != mSelEnd) { mSelEnd = tmp; repaint(false); } } } // ---------------------------------------------------------------------------- // D R A G ' N D R O P H A N D L I N G // ---------------------------------------------------------------------------- void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) { #ifndef KORG_NODND if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { e->ignore(); return; } // some visual feedback // oldPalette = palette(); // setPalette(my_HilitePalette); // update(); #endif } void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) { #ifndef KORG_NODND if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { e->ignore(); return; } e->accept(); #endif } void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) { #ifndef KORG_NODND // setPalette(oldPalette); // update(); #endif } void KODayMatrix::dropEvent(QDropEvent *e) { #ifndef KORG_NODND // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { e->ignore(); return; } DndFactory factory( mCalendar ); Event *event = factory.createDrop(e); @@ -646,274 +646,278 @@ void KODayMatrix::dropEvent(QDropEvent *e) // ---------------------------------------------------------------------------- // P A I N T E V E N T H A N D L I N G // ---------------------------------------------------------------------------- void KODayMatrix::paintEvent(QPaintEvent * pevent) { QRect sz = frameRect(); if ( sz.width() <= 0 || sz.height() <= 0 ) return; if ( mPendingUpdateBeforeRepaint ) { updateViewTimed(); mPendingUpdateBeforeRepaint = false; } if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { myPix.resize(sz.size() ); } QPainter p(&myPix); p.setFont(font()); int dheight = daysize.height(); int dwidth = daysize.width(); int row,col; int selw, selh; int xyOff = frameWidth(); int colModulo = sz.width() % 7; int rowModulo = sz.height() % 6; //qDebug("col %d row %d ",colModulo,rowModulo ); bool isRTL = KOGlobals::self()->reverseLayout(); // draw background and topleft frame p.fillRect(pevent->rect(), mDefaultBackColor); p.setPen(mDefaultTextColor); p.drawRect(0, 0, sz.width()+1, sz.height()+1); int mSelStartT = mSelStart; int mSelEndT = mSelEnd; if ( mSelEndT >= NUMDAYS ) mSelEndT = NUMDAYS-1; // draw selected days with highlighted background color if (mSelStart != NOSELECTION) { bool skip = false; if ( ! mouseDown ) { int mo = days[20].month(); //qDebug("-- %d %d ", mSelStartT, mSelEndT); //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { skip = true; } else { if ( days[mSelStartT].month() != mo ) { int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); mSelStartT += add +1; } if ( days[mSelEndT].month() != mo ) { int sub = days[mSelEndT].day(); mSelEndT -= sub ; } } } if ( ! skip ) { row = mSelStartT/7; col = mSelStartT -row*7; QColor selcol = KOPrefs::instance()->mHighlightColor; int addCol = 0; int addRow = 0; int addRow2 = 0; int addCol2 = 0; if (row == mSelEndT/7) { if ( rowModulo ) { if ( row >= 6 - rowModulo ) addRow = row - 5 + rowModulo; } if ( colModulo ) { int colt1 = mSelEndT%7; //qDebug("colt1 %d ", colt1 ); if ( colt1 >= 7 - colModulo ) addCol = colt1 - 7 + colModulo+1; int colt = mSelStartT%7; if ( colt >= 7 - colModulo ) addCol2 = colt - 7 + colModulo; addCol -= addCol2; //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); } // Single row selection if ( row == 0) addRow = 1; p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); } else { // draw first row to the right if ( colModulo ) { if ( col >= 7 - colModulo ) addCol2 = col - 7 + colModulo; } if ( rowModulo ) { if ( row >= 6 - rowModulo ) addRow = row - 5 + rowModulo; } if ( row == 0) addRow = 1; p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo, dheight+1, selcol); // draw full block till last line selh = mSelEndT/7-row; addRow = 0; if ( rowModulo ) { if ( mSelEndT/7 >= 6 - rowModulo ) addRow = mSelEndT/7 - 5 + rowModulo; } if (selh > 1) { p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); } // draw last block from left to mSelEndT selw = mSelEndT-7*(mSelEndT/7)+1; //qDebug("esl %d ",selw ); int add = 0; if ( colModulo ) { add = 7 - colModulo; if ( selw > add ) add = selw - add; else add = 0; } //qDebug("add %d ", add); p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, selw*dwidth+add, dheight+1, selcol); } } } // iterate over all days in the matrix and draw the day label in appropriate colors QColor actcol = mDefaultTextColorShaded; p.setPen(actcol); QPen tmppen; for(int i = 0; i < NUMDAYS; i++) { row = i/7; col = isRTL ? 6-(i-row*7) : i-row*7; // if it is the first day of a month switch color from normal to shaded and vice versa if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { if (actcol == mDefaultTextColorShaded) { actcol = mDefaultTextColor; } else { actcol = mDefaultTextColorShaded; } p.setPen(actcol); } if (actcol == mDefaultTextColorShaded) { if ( ! mouseDown ) { continue; } } //Reset pen color after selected days block if (i == mSelEndT+1) { p.setPen(actcol); } // if today then draw rectangle around day if (today == i) { tmppen = p.pen(); QPen mTodayPen(p.pen()); if ( daysize.width() < 20 ) mTodayPen.setWidth(1); else mTodayPen.setWidth(mTodayMarginWidth); //draw red rectangle for holidays if (!mHolidays[i].isNull()) { if (actcol == mDefaultTextColor) { mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); } else { mTodayPen.setColor(mHolidayColorShaded); } } //draw gray rectangle for today if in selection if (i >= mSelStartT && i <= mSelEndT) { QColor grey("grey"); mTodayPen.setColor(grey); } p.setPen(mTodayPen); int addCol = 0; int addRow = 0; if (rowModulo) { if ( row >= 6 - rowModulo ) addRow = row - 5 + rowModulo; } if ( colModulo ) { if ( col >= 7 - colModulo ) addCol = col - 6 + colModulo-1; } + if ( col == 0 ) + addCol = 1; p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1); p.setPen(tmppen); } // if any events are on that day then draw it using a bold font if (events[i] > 0) { QFont myFont = font(); myFont.setBold(true); p.setFont(myFont); } // if it is a holiday then use the default holiday color if (!mHolidays[i].isNull()) { if ( bDays.testBit(i) ) { p.setPen(Qt::green); } else { if (actcol == mDefaultTextColor) { p.setPen(KOPrefs::instance()->mHolidayColor); } else { p.setPen(mHolidayColorShaded); } } } // draw selected days with special color // DO NOT specially highlight holidays in selection ! if (i >= mSelStartT && i <= mSelEndT) { ;//p.setPen(mSelectedDaysColor); } int addCol = 0; int addRow = 0; if ( colModulo ) { if ( col >= 7 - colModulo ) addCol = col - 7 + colModulo; } if ( rowModulo ) { if ( row >= 6 - rowModulo ) addRow = row - 5 + rowModulo; } //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); ++addCol;//++addCol; + if ( row == 0) + addRow = 1; p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); // reset color to actual color if (!mHolidays[i].isNull()) { p.setPen(actcol); } // reset bold font to plain font if (events[i] > 0) { QFont myFont = font(); myFont.setBold(false); p.setFont(myFont); } } int off = xyOff; bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); //qDebug("ffffffffff %d ", off); } // ---------------------------------------------------------------------------- // R E SI Z E E V E N T H A N D L I N G // ---------------------------------------------------------------------------- void KODayMatrix::resizeEvent(QResizeEvent *) { QRect sz = frameRect(); daysize.setHeight(sz.height()*7 / NUMDAYS); daysize.setWidth(sz.width() / 7); } QSize KODayMatrix::sizeHint() const { QFontMetrics fm ( font() ); int wid = fm.width( "30") *7+3; int hei = fm.height() * 6+3; //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); return QSize ( wid, hei ); } |