-rw-r--r-- | korganizer/kodaymatrix.cpp | 110 | ||||
-rw-r--r-- | korganizer/kodaymatrix.h | 5 |
2 files changed, 107 insertions, 8 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index 17a8546..1cde616 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp @@ -21,16 +21,17 @@ with any edition of Qt, and distribute the resulting executable, without including the source ode for Qt in the source distribution. */ #include <qevent.h> #include <qpainter.h> #include <qptrlist.h> #include <qtimer.h> +#include <qwhatsthis.h> #include <kglobal.h> #include <kdebug.h> #include <klocale.h> #include <libkcal/vcaldrag.h> #include <libkcal/icaldrag.h> #include <libkcal/dndfactory.h> @@ -53,16 +54,29 @@ // ============================================================================ DynamicTip::DynamicTip( QWidget * parent ) : QToolTip( parent ) { matrix = (KODayMatrix*)parent; } +class KODaymatrixWhatsThis :public QWhatsThis +{ +public: + KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { }; + +protected: + virtual QString text( const QPoint& p ) + { + return _view->getWhatsThisText( p ) ; + } +private: + KODayMatrix * _view; +}; void DynamicTip::maybeTip( const QPoint &pos ) { //calculate which cell of the matrix the mouse is in QRect sz = matrix->frameRect(); int dheight = sz.height()*7 / 42; int dwidth = sz.width() / 7; int row = pos.y()/dheight; @@ -90,20 +104,21 @@ const int KODayMatrix::NUMDAYS = 42; KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) : QFrame( parent, name ), mCalendar( 0 ) #if 0 KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : QFrame(parent, name) #endif { - + new KODaymatrixWhatsThis(this); mPendingUpdateBeforeRepaint = false; - + mouseDown = false; // initialize dynamic arrays + bDays.resize ( NUMDAYS ); days = new QDate[NUMDAYS]; daylbls = new QString[NUMDAYS]; events = new int[NUMDAYS]; mToolTip = new DynamicTip(this); // set default values used for drawing the matrix mDefaultBackColor = palette().active().base(); mDefaultTextColor = palette().active().foreground(); @@ -118,16 +133,75 @@ KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const mUpdateTimer = new QTimer( this ); connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); mRepaintTimer = new QTimer( this ); connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); mDayChanged = false; updateView(); } +QString KODayMatrix::getWhatsThisText( QPoint p ) +{ + + int tmp = getDayIndexFrom(p.x(), p.y()); + if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) + return QString(); + QDate mDate = days[tmp]; + QPtrList<Event> eventlist = mCalendar->events(mDate); + Event *event; + QStringList mToolTip; + for(event=eventlist.first();event != 0;event=eventlist.next()) { + QString mToolTipText; + QString text; + int multiday = 0;// 1 = start, 2 = midddle, 3 = end day + if (event->isMultiDay()) { + QString prefix = "<->";multiday = 2; + QString time; + if ( event->doesRecur() ) { + if ( event->recursOn( mDate) ) { + prefix ="->" ;multiday = 1; + } + else { + int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); + if ( event->recursOn( mDate.addDays( -days)) ) { + prefix ="<-" ;multiday = 3; + } + } + } else { + if (mDate == event->dtStart().date()) { + prefix ="->" ;multiday = 1; + } else if (mDate == event->dtEnd().date()) { + prefix ="<-" ;multiday = 3; + } + } + if ( !event->doesFloat() ) { + if ( mDate == event->dtStart().date () ) + time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; + else if ( mDate == event->dtEnd().date () ) + time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; + + } + text = time + event->summary(); + mToolTipText += prefix + text; + } else { + if (event->doesFloat()) { + text = event->summary(); + mToolTipText += text; + } + else { + text = KGlobal::locale()->formatTime(event->dtStart().time()); + text += " " + event->summary(); + mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); + } + } + mToolTip.append( mToolTipText ); + } + mToolTip.sort(); + return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); +} void KODayMatrix::setCalendar( Calendar *cal ) { mCalendar = cal; setAcceptDrops( mCalendar ); updateEvents(); } @@ -241,27 +315,34 @@ void KODayMatrix::updateViewTimed() } //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->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) { + if ( !holiStr.isEmpty() ) + holiStr += "\n"; + holiStr += event->summary(); + 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; @@ -302,21 +383,21 @@ void KODayMatrix::updateView(QDate actdate) mDayChanged = true; recalculateToday(); } //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); if ( !isVisible() ) { mPendingUpdateBeforeRepaint = true; } else { #ifdef DESKTOP_VERSION - //mRepaintTimer->start( 250 ); - mUpdateTimer->start( 250 ); + //mRepaintTimer->start( 150 ); + mUpdateTimer->start( 150 ); #else mRepaintTimer->start( 350 ); - mUpdateTimer->start( 2000 ); + mUpdateTimer->start( 1200 ); #endif } } void KODayMatrix::updateEvents() { if ( !mCalendar ) return; for( int i = 0; i < NUMDAYS; i++ ) { @@ -363,24 +444,32 @@ int KODayMatrix::getDayIndexFrom(int x, int y) } // ---------------------------------------------------------------------------- // 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; } 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); @@ -402,16 +491,19 @@ void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 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); @@ -625,27 +717,31 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) 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 >= mSelStart && i <= mSelEnd) { - p.setPen(mSelectedDaysColor); + ;//p.setPen(mSelectedDaysColor); } p.drawText(col*dwidth, row*dheight, dwidth, dheight, Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); // reset color to actual color if (!mHolidays[i].isNull()) { p.setPen(actcol); diff --git a/korganizer/kodaymatrix.h b/korganizer/kodaymatrix.h index ba4853f..c049942 100644 --- a/korganizer/kodaymatrix.h +++ b/korganizer/kodaymatrix.h @@ -27,17 +27,17 @@ #include <qstring.h> #include <qframe.h> #include <qcolor.h> #include <qpen.h> #include <qdatetime.h> #include <qtooltip.h> #include <qpixmap.h> - +#include <qbitarray.h> #include <qmap.h> class QDragEnterEvent; class QDragMoveEvent; class QDragLeaveEvent; class QDropEvent; class KODayMatrix; @@ -164,16 +164,17 @@ public: /** If today is visible, then we can find out if today is * near the beginning or the end of the month. * This is dependent on today remaining the index * in the array of visible dates and going from * top left (0) to bottom right (41). */ bool isBeginningOfMonth() const { return today<=8; } ; bool isEndOfMonth() const { return today>=27; } ; + QString getWhatsThisText( QPoint ) ; public slots: /** Recalculates all the flags of the days in the matrix like holidays or events * on a day (Actually calls above method with the actual startdate). */ void updateView(); void updateViewTimed(); void repaintViewTimed(); @@ -219,16 +220,18 @@ protected: void dragLeaveEvent(QDragLeaveEvent *); void dropEvent(QDropEvent *); void resizeEvent(QResizeEvent *); private: + bool mouseDown; + QBitArray bDays; QPixmap myPix; QTimer* mUpdateTimer; QTimer* mRepaintTimer; bool mDayChanged; bool mPendingUpdateBeforeRepaint; /** returns the index of the day located at the matrix's widget (x,y) position. * |