-rw-r--r-- | korganizer/kodaymatrix.cpp | 57 | ||||
-rw-r--r-- | korganizer/kodaymatrix.h | 1 |
2 files changed, 46 insertions, 12 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index 53ebdb2..4366265 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -1,987 +1,1020 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> | 3 | Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> |
4 | Parts of the source code have been copied from kdpdatebutton.cpp | 4 | Parts of the source code have been copied from kdpdatebutton.cpp |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or | 8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | 9 | (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, | 11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. | 14 | GNU General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | 17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | 19 | ||
20 | As a special exception, permission is given to link this program | 20 | As a special exception, permission is given to link this program |
21 | with any edition of Qt, and distribute the resulting executable, | 21 | with any edition of Qt, and distribute the resulting executable, |
22 | without including the source ode for Qt in the source distribution. | 22 | without including the source ode for Qt in the source distribution. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <qevent.h> | 25 | #include <qevent.h> |
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qptrlist.h> | 27 | #include <qptrlist.h> |
28 | #include <qtimer.h> | 28 | #include <qtimer.h> |
29 | #include <qwhatsthis.h> | 29 | #include <qwhatsthis.h> |
30 | 30 | ||
31 | #include <kglobal.h> | 31 | #include <kglobal.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | 34 | ||
35 | #include <libkcal/vcaldrag.h> | 35 | #include <libkcal/vcaldrag.h> |
36 | #include <libkcal/icaldrag.h> | 36 | #include <libkcal/icaldrag.h> |
37 | #include <libkcal/dndfactory.h> | 37 | #include <libkcal/dndfactory.h> |
38 | #include <libkcal/calendarresources.h> | 38 | #include <libkcal/calendarresources.h> |
39 | #include <libkcal/resourcecalendar.h> | 39 | #include <libkcal/resourcecalendar.h> |
40 | #include <kresources/resourceselectdialog.h> | 40 | #include <kresources/resourceselectdialog.h> |
41 | 41 | ||
42 | #include <kcalendarsystem.h> | 42 | #include <kcalendarsystem.h> |
43 | 43 | ||
44 | #ifndef KORG_NOPLUGINS | 44 | #ifndef KORG_NOPLUGINS |
45 | #include "kocore.h" | 45 | #include "kocore.h" |
46 | #endif | 46 | #endif |
47 | #include "koprefs.h" | 47 | #include "koprefs.h" |
48 | #include "koglobals.h" | 48 | #include "koglobals.h" |
49 | 49 | ||
50 | #include "kodaymatrix.h" | 50 | #include "kodaymatrix.h" |
51 | 51 | ||
52 | // ============================================================================ | 52 | // ============================================================================ |
53 | // D Y N A M I C T I P | 53 | // D Y N A M I C T I P |
54 | // ============================================================================ | 54 | // ============================================================================ |
55 | 55 | ||
56 | DynamicTip::DynamicTip( QWidget * parent ) | 56 | DynamicTip::DynamicTip( QWidget * parent ) |
57 | : QToolTip( parent ) | 57 | : QToolTip( parent ) |
58 | { | 58 | { |
59 | matrix = (KODayMatrix*)parent; | 59 | matrix = (KODayMatrix*)parent; |
60 | } | 60 | } |
61 | 61 | ||
62 | class KODaymatrixWhatsThis :public QWhatsThis | 62 | class KODaymatrixWhatsThis :public QWhatsThis |
63 | { | 63 | { |
64 | public: | 64 | public: |
65 | KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; | 65 | KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; |
66 | ~KODaymatrixWhatsThis() { ; }; | 66 | ~KODaymatrixWhatsThis() { ; }; |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | virtual QString text( const QPoint& p ) | 69 | virtual QString text( const QPoint& p ) |
70 | { | 70 | { |
71 | return _view->getWhatsThisText( p ) ; | 71 | return _view->getWhatsThisText( p ) ; |
72 | } | 72 | } |
73 | private: | 73 | private: |
74 | KODayMatrix * _view; | 74 | KODayMatrix * _view; |
75 | }; | 75 | }; |
76 | 76 | ||
77 | void DynamicTip::maybeTip( const QPoint &pos ) | 77 | void DynamicTip::maybeTip( const QPoint &pos ) |
78 | { | 78 | { |
79 | //calculate which cell of the matrix the mouse is in | 79 | //calculate which cell of the matrix the mouse is in |
80 | QRect sz = matrix->frameRect(); | 80 | QRect sz = matrix->frameRect(); |
81 | int dheight = sz.height()*7 / 42; | 81 | int dheight = sz.height()*7 / 42; |
82 | int dwidth = sz.width() / 7; | 82 | int dwidth = sz.width() / 7; |
83 | int row = pos.y()/dheight; | 83 | int row = pos.y()/dheight; |
84 | int col = pos.x()/dwidth; | 84 | int col = pos.x()/dwidth; |
85 | 85 | ||
86 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); | 86 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); |
87 | 87 | ||
88 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << | 88 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << |
89 | // col << "][" << row << "] => " <<(col+row*7) << endl; | 89 | // col << "][" << row << "] => " <<(col+row*7) << endl; |
90 | 90 | ||
91 | //show holiday names only | 91 | //show holiday names only |
92 | QString str = matrix->getHolidayLabel(col+row*7); | 92 | QString str = matrix->getHolidayLabel(col+row*7); |
93 | if (str.isEmpty()) return; | 93 | if (str.isEmpty()) return; |
94 | tip(rct, str); | 94 | tip(rct, str); |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | // ============================================================================ | 98 | // ============================================================================ |
99 | // K O D A Y M A T R I X | 99 | // K O D A Y M A T R I X |
100 | // ============================================================================ | 100 | // ============================================================================ |
101 | 101 | ||
102 | const int KODayMatrix::NOSELECTION = -1000; | 102 | const int KODayMatrix::NOSELECTION = -1000; |
103 | const int KODayMatrix::NUMDAYS = 42; | 103 | const int KODayMatrix::NUMDAYS = 42; |
104 | 104 | ||
105 | KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) | 105 | KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) |
106 | : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) | 106 | : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) |
107 | 107 | ||
108 | 108 | ||
109 | { | 109 | { |
110 | mLastView = -1; | 110 | mLastView = -1; |
111 | oldW = 0; | 111 | oldW = 0; |
112 | oldH = 0; | 112 | oldH = 0; |
113 | myPix.resize( 150, 120 ); | 113 | myPix.resize( 150, 120 ); |
114 | mRedrawNeeded = true; | 114 | mRedrawNeeded = true; |
115 | mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); | 115 | mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); |
116 | mPendingUpdateBeforeRepaint = false; | 116 | mPendingUpdateBeforeRepaint = false; |
117 | mouseDown = false; | 117 | mouseDown = false; |
118 | // initialize dynamic arrays | 118 | // initialize dynamic arrays |
119 | bDays.resize ( NUMDAYS ); | 119 | bDays.resize ( NUMDAYS ); |
120 | pDays.resize ( NUMDAYS ); | 120 | pDays.resize ( NUMDAYS ); |
121 | hDays.resize ( NUMDAYS ); | 121 | hDays.resize ( NUMDAYS ); |
122 | eDays.resize ( NUMDAYS ); | 122 | eDays.resize ( NUMDAYS ); |
123 | days = new QDate[NUMDAYS]; | 123 | days = new QDate[NUMDAYS]; |
124 | daylbls = new QString[NUMDAYS]; | 124 | daylbls = new QString[NUMDAYS]; |
125 | //events = new int[NUMDAYS]; | 125 | //events = new int[NUMDAYS]; |
126 | mToolTip = new DynamicTip(this); | 126 | mToolTip = new DynamicTip(this); |
127 | 127 | ||
128 | // set default values used for drawing the matrix | 128 | // set default values used for drawing the matrix |
129 | mDefaultBackColor = palette().active().base(); | 129 | mDefaultBackColor = palette().active().base(); |
130 | mDefaultTextColor = palette().active().foreground(); | 130 | mDefaultTextColor = palette().active().foreground(); |
131 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); | 131 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); |
132 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); | 132 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); |
133 | mSelectedDaysColor = QColor("white"); | 133 | mSelectedDaysColor = QColor("white"); |
134 | mTodayMarginWidth = 2; | 134 | mTodayMarginWidth = 2; |
135 | mSelEnd = mSelStart = NOSELECTION; | 135 | mSelEnd = mSelStart = NOSELECTION; |
136 | 136 | ||
137 | setAcceptDrops(true); | 137 | setAcceptDrops(true); |
138 | //setFont( QFont("Arial", 10) ); | 138 | //setFont( QFont("Arial", 10) ); |
139 | 139 | ||
140 | mUpdateTimer = new QTimer( this ); | 140 | mUpdateTimer = new QTimer( this ); |
141 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); | 141 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); |
142 | mRepaintTimer = new QTimer( this ); | 142 | mRepaintTimer = new QTimer( this ); |
143 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); | 143 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); |
144 | mDayChanged = false; | 144 | mDayChanged = false; |
145 | updateView(); | 145 | updateView(); |
146 | } | 146 | } |
147 | QString KODayMatrix::getWhatsThisText( QPoint p ) | 147 | QString KODayMatrix::getWhatsThisText( QPoint p ) |
148 | { | 148 | { |
149 | 149 | ||
150 | int tmp = getDayIndexFrom(p.x(), p.y()); | 150 | int tmp = getDayIndexFrom(p.x(), p.y()); |
151 | if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) | 151 | if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) |
152 | return QString(); | 152 | return QString(); |
153 | QDate mDate = days[tmp]; | 153 | QDate mDate = days[tmp]; |
154 | QPtrList<Event> eventlist = mCalendar->events(mDate); | 154 | QPtrList<Event> eventlist = mCalendar->events(mDate); |
155 | Event *event; | 155 | Event *event; |
156 | QStringList mToolTip; | 156 | QStringList mToolTip; |
157 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 157 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
158 | QString mToolTipText; | 158 | QString mToolTipText; |
159 | QString text; | 159 | QString text; |
160 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day | 160 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day |
161 | if (event->isMultiDay()) { | 161 | if (event->isMultiDay()) { |
162 | QString prefix = "<->";multiday = 2; | 162 | QString prefix = "<->";multiday = 2; |
163 | QString time; | 163 | QString time; |
164 | if ( event->doesRecur() ) { | 164 | if ( event->doesRecur() ) { |
165 | if ( event->recursOn( mDate) ) { | 165 | if ( event->recursOn( mDate) ) { |
166 | prefix ="->" ;multiday = 1; | 166 | prefix ="->" ;multiday = 1; |
167 | } | 167 | } |
168 | else { | 168 | else { |
169 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 169 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
170 | if ( event->recursOn( mDate.addDays( -days)) ) { | 170 | if ( event->recursOn( mDate.addDays( -days)) ) { |
171 | prefix ="<-" ;multiday = 3; | 171 | prefix ="<-" ;multiday = 3; |
172 | } | 172 | } |
173 | } | 173 | } |
174 | } else { | 174 | } else { |
175 | if (mDate == event->dtStart().date()) { | 175 | if (mDate == event->dtStart().date()) { |
176 | prefix ="->" ;multiday = 1; | 176 | prefix ="->" ;multiday = 1; |
177 | } else if (mDate == event->dtEnd().date()) { | 177 | } else if (mDate == event->dtEnd().date()) { |
178 | prefix ="<-" ;multiday = 3; | 178 | prefix ="<-" ;multiday = 3; |
179 | } | 179 | } |
180 | } | 180 | } |
181 | if ( !event->doesFloat() ) { | 181 | if ( !event->doesFloat() ) { |
182 | if ( mDate == event->dtStart().date () ) | 182 | if ( mDate == event->dtStart().date () ) |
183 | time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; | 183 | time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; |
184 | else if ( mDate == event->dtEnd().date () ) | 184 | else if ( mDate == event->dtEnd().date () ) |
185 | time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; | 185 | time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; |
186 | 186 | ||
187 | } | 187 | } |
188 | text = time + event->summary(); | 188 | text = time + event->summary(); |
189 | mToolTipText += prefix + text; | 189 | mToolTipText += prefix + text; |
190 | } else { | 190 | } else { |
191 | if (event->doesFloat()) { | 191 | if (event->doesFloat()) { |
192 | text = event->summary(); | 192 | text = event->summary(); |
193 | mToolTipText += text; | 193 | mToolTipText += text; |
194 | } | 194 | } |
195 | else { | 195 | else { |
196 | text = KGlobal::locale()->formatTime(event->dtStart().time()); | 196 | text = KGlobal::locale()->formatTime(event->dtStart().time()); |
197 | text += " " + event->summary(); | 197 | text += " " + event->summary(); |
198 | mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); | 198 | mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); |
199 | } | 199 | } |
200 | } | 200 | } |
201 | if ( !event->location().isEmpty() ) | 201 | if ( !event->location().isEmpty() ) |
202 | mToolTipText += " (" + event->location() + ")"; | 202 | mToolTipText += " (" + event->location() + ")"; |
203 | #if QT_VERSION >= 0x030000 | ||
204 | mToolTipText.replace( '<' , "<" ); | ||
205 | mToolTipText.replace( '>' , ">" ); | ||
206 | #else | ||
207 | if ( mToolTipText.find ('<') >= 0 ) { | ||
208 | mToolTipText.replace( QRegExp("<") , "<" ); | ||
209 | } | ||
210 | if ( mToolTipText.find ('>') >= 0 ) { | ||
211 | mToolTipText.replace( QRegExp(">") , ">" ); | ||
212 | } | ||
213 | #endif | ||
214 | //qDebug("TTT: %s ", mToolTipText.latin1()); | 203 | //qDebug("TTT: %s ", mToolTipText.latin1()); |
215 | mToolTip.append( mToolTipText ); | 204 | mToolTip.append( deTag( mToolTipText ) ); |
205 | } | ||
206 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { | ||
207 | QPtrList<Todo> todolist = mCalendar->todos(mDate); | ||
208 | Todo *todo; | ||
209 | for(todo=todolist.first();todo != 0;todo=todolist.next()) { | ||
210 | QString mToolTipText; | ||
211 | if ( !todo->doesFloat() ) | ||
212 | mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" "; | ||
213 | mToolTipText += todo->summary(); | ||
214 | if ( !todo->location().isEmpty() ) | ||
215 | mToolTipText += " (" + todo->location() + ")"; | ||
216 | mToolTipText = deTag( mToolTipText); | ||
217 | mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText; | ||
218 | mToolTip.append( mToolTipText ); | ||
219 | } | ||
216 | } | 220 | } |
217 | mToolTip.sort(); | 221 | mToolTip.sort(); |
222 | if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { | ||
223 | Journal *j = mCalendar->journal( mDate ); | ||
224 | if ( j ) { | ||
225 | QString mToolTipText = j->description().left(100); | ||
226 | if ( j->description().length() > 100 ) | ||
227 | mToolTipText += " ..."; | ||
228 | mToolTipText = deTag( mToolTipText); | ||
229 | mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText; | ||
230 | mToolTip.append( mToolTipText ); | ||
231 | } | ||
232 | } | ||
218 | return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); | 233 | return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); |
219 | } | 234 | } |
235 | |||
236 | |||
237 | QString KODayMatrix::deTag( QString mToolTipText ) | ||
238 | { | ||
239 | |||
240 | #if QT_VERSION >= 0x030000 | ||
241 | mToolTipText.replace( '<' , "<" ); | ||
242 | mToolTipText.replace( '>' , ">" ); | ||
243 | #else | ||
244 | if ( mToolTipText.find ('<') >= 0 ) { | ||
245 | mToolTipText.replace( QRegExp("<") , "<" ); | ||
246 | } | ||
247 | if ( mToolTipText.find ('>') >= 0 ) { | ||
248 | mToolTipText.replace( QRegExp(">") , ">" ); | ||
249 | } | ||
250 | #endif | ||
251 | return mToolTipText; | ||
252 | } | ||
220 | void KODayMatrix::setCalendar( Calendar *cal ) | 253 | void KODayMatrix::setCalendar( Calendar *cal ) |
221 | { | 254 | { |
222 | mCalendar = cal; | 255 | mCalendar = cal; |
223 | 256 | ||
224 | setAcceptDrops( mCalendar ); | 257 | setAcceptDrops( mCalendar ); |
225 | 258 | ||
226 | updateEvents(); | 259 | updateEvents(); |
227 | } | 260 | } |
228 | 261 | ||
229 | QColor KODayMatrix::getShadedColor(QColor color) | 262 | QColor KODayMatrix::getShadedColor(QColor color) |
230 | { | 263 | { |
231 | QColor shaded; | 264 | QColor shaded; |
232 | int h=0; | 265 | int h=0; |
233 | int s=0; | 266 | int s=0; |
234 | int v=0; | 267 | int v=0; |
235 | color.hsv(&h,&s,&v); | 268 | color.hsv(&h,&s,&v); |
236 | s = s/4; | 269 | s = s/4; |
237 | v = 192+v/4; | 270 | v = 192+v/4; |
238 | shaded.setHsv(h,s,v); | 271 | shaded.setHsv(h,s,v); |
239 | 272 | ||
240 | return shaded; | 273 | return shaded; |
241 | } | 274 | } |
242 | 275 | ||
243 | KODayMatrix::~KODayMatrix() | 276 | KODayMatrix::~KODayMatrix() |
244 | { | 277 | { |
245 | #if QT_VERSION >= 0x030000 | 278 | #if QT_VERSION >= 0x030000 |
246 | 279 | ||
247 | #else | 280 | #else |
248 | delete mKODaymatrixWhatsThis; | 281 | delete mKODaymatrixWhatsThis; |
249 | #endif | 282 | #endif |
250 | 283 | ||
251 | // delete mKODaymatrixWhatsThis; | 284 | // delete mKODaymatrixWhatsThis; |
252 | delete [] days; | 285 | delete [] days; |
253 | delete [] daylbls; | 286 | delete [] daylbls; |
254 | //delete [] events; | 287 | //delete [] events; |
255 | delete mToolTip; | 288 | delete mToolTip; |
256 | } | 289 | } |
257 | 290 | ||
258 | /* | 291 | /* |
259 | void KODayMatrix::setStartDate(QDate start) | 292 | void KODayMatrix::setStartDate(QDate start) |
260 | { | 293 | { |
261 | updateView(start); | 294 | updateView(start); |
262 | } | 295 | } |
263 | */ | 296 | */ |
264 | 297 | ||
265 | void KODayMatrix::addSelectedDaysTo(DateList& selDays) | 298 | void KODayMatrix::addSelectedDaysTo(DateList& selDays) |
266 | { | 299 | { |
267 | 300 | ||
268 | if (mSelStart == NOSELECTION) { | 301 | if (mSelStart == NOSELECTION) { |
269 | return; | 302 | return; |
270 | } | 303 | } |
271 | 304 | ||
272 | //cope with selection being out of matrix limits at top (< 0) | 305 | //cope with selection being out of matrix limits at top (< 0) |
273 | int i0 = mSelStart; | 306 | int i0 = mSelStart; |
274 | if (i0 < 0) { | 307 | if (i0 < 0) { |
275 | for (int i = i0; i < 0; i++) { | 308 | for (int i = i0; i < 0; i++) { |
276 | selDays.append(days[0].addDays(i)); | 309 | selDays.append(days[0].addDays(i)); |
277 | } | 310 | } |
278 | i0 = 0; | 311 | i0 = 0; |
279 | } | 312 | } |
280 | 313 | ||
281 | //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) | 314 | //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) |
282 | if (mSelEnd > NUMDAYS-1) { | 315 | if (mSelEnd > NUMDAYS-1) { |
283 | for (int i = i0; i <= NUMDAYS-1; i++) { | 316 | for (int i = i0; i <= NUMDAYS-1; i++) { |
284 | selDays.append(days[i]); | 317 | selDays.append(days[i]); |
285 | } | 318 | } |
286 | for (int i = NUMDAYS; i < mSelEnd; i++) { | 319 | for (int i = NUMDAYS; i < mSelEnd; i++) { |
287 | selDays.append(days[0].addDays(i)); | 320 | selDays.append(days[0].addDays(i)); |
288 | } | 321 | } |
289 | 322 | ||
290 | // apply normal routine to selection being entirely within matrix limits | 323 | // apply normal routine to selection being entirely within matrix limits |
291 | } else { | 324 | } else { |
292 | for (int i = i0; i <= mSelEnd; i++) { | 325 | for (int i = i0; i <= mSelEnd; i++) { |
293 | selDays.append(days[i]); | 326 | selDays.append(days[i]); |
294 | } | 327 | } |
295 | } | 328 | } |
296 | } | 329 | } |
297 | 330 | ||
298 | bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) | 331 | bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) |
299 | { | 332 | { |
300 | mRedrawNeeded = true; | 333 | mRedrawNeeded = true; |
301 | bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); | 334 | bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); |
302 | mSelStart = startdate.daysTo(start); | 335 | mSelStart = startdate.daysTo(start); |
303 | if ( mSelStart < 0 ) | 336 | if ( mSelStart < 0 ) |
304 | mSelStart = 0; | 337 | mSelStart = 0; |
305 | mSelEnd = startdate.daysTo(end); | 338 | mSelEnd = startdate.daysTo(end); |
306 | if ( mSelEnd > NUMDAYS-1 ) | 339 | if ( mSelEnd > NUMDAYS-1 ) |
307 | mSelEnd = NUMDAYS-1; | 340 | mSelEnd = NUMDAYS-1; |
308 | if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { | 341 | if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { |
309 | clearSelection(); | 342 | clearSelection(); |
310 | if ( noSel ) | 343 | if ( noSel ) |
311 | return false; | 344 | return false; |
312 | } | 345 | } |
313 | 346 | ||
314 | return true; | 347 | return true; |
315 | } | 348 | } |
316 | void KODayMatrix::clearSelection() | 349 | void KODayMatrix::clearSelection() |
317 | { | 350 | { |
318 | mSelEnd = mSelStart = NOSELECTION; | 351 | mSelEnd = mSelStart = NOSELECTION; |
319 | } | 352 | } |
320 | 353 | ||
321 | 354 | ||
322 | void KODayMatrix::recalculateToday() | 355 | void KODayMatrix::recalculateToday() |
323 | { | 356 | { |
324 | today = -1; | 357 | today = -1; |
325 | for (int i=0; i<NUMDAYS; i++) { | 358 | for (int i=0; i<NUMDAYS; i++) { |
326 | //events[i] = 0; | 359 | //events[i] = 0; |
327 | days[i] = startdate.addDays(i); | 360 | days[i] = startdate.addDays(i); |
328 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); | 361 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); |
329 | 362 | ||
330 | // if today is in the currently displayed month, hilight today | 363 | // if today is in the currently displayed month, hilight today |
331 | if (days[i].year() == QDate::currentDate().year() && | 364 | if (days[i].year() == QDate::currentDate().year() && |
332 | days[i].month() == QDate::currentDate().month() && | 365 | days[i].month() == QDate::currentDate().month() && |
333 | days[i].day() == QDate::currentDate().day()) { | 366 | days[i].day() == QDate::currentDate().day()) { |
334 | today = i; | 367 | today = i; |
335 | } | 368 | } |
336 | } | 369 | } |
337 | // qDebug(QString("Today is visible at %1.").arg(today)); | 370 | // qDebug(QString("Today is visible at %1.").arg(today)); |
338 | } | 371 | } |
339 | 372 | ||
340 | void KODayMatrix::updateView() | 373 | void KODayMatrix::updateView() |
341 | { | 374 | { |
342 | updateView(startdate); | 375 | updateView(startdate); |
343 | } | 376 | } |
344 | void KODayMatrix::repaintViewTimed() | 377 | void KODayMatrix::repaintViewTimed() |
345 | { | 378 | { |
346 | mRedrawNeeded = true; | 379 | mRedrawNeeded = true; |
347 | // bDays.fill( false); | 380 | // bDays.fill( false); |
348 | //pDays.fill( false); | 381 | //pDays.fill( false); |
349 | //hDays.fill( false); | 382 | //hDays.fill( false); |
350 | //eDays.fill( false); | 383 | //eDays.fill( false); |
351 | mRepaintTimer->stop(); | 384 | mRepaintTimer->stop(); |
352 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday | 385 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday |
353 | int i; | 386 | int i; |
354 | for(i = 0; i < NUMDAYS; i++) { | 387 | for(i = 0; i < NUMDAYS; i++) { |
355 | if ( ( (i+startDay) % 7 == 0 ) ) { | 388 | if ( ( (i+startDay) % 7 == 0 ) ) { |
356 | pDays.setBit(i); | 389 | pDays.setBit(i); |
357 | } | 390 | } |
358 | } | 391 | } |
359 | repaint(false); | 392 | repaint(false); |
360 | } | 393 | } |
361 | void KODayMatrix::computeEvent(Event *event, int i ) | 394 | void KODayMatrix::computeEvent(Event *event, int i ) |
362 | { | 395 | { |
363 | QString holiStr = mHolidays[i]; | 396 | QString holiStr = mHolidays[i]; |
364 | if ( event->isHoliday()) { | 397 | if ( event->isHoliday()) { |
365 | pDays.setBit(i); | 398 | pDays.setBit(i); |
366 | hDays.setBit(i); | 399 | hDays.setBit(i); |
367 | if ( !holiStr.isEmpty() ) | 400 | if ( !holiStr.isEmpty() ) |
368 | holiStr += "\n"; | 401 | holiStr += "\n"; |
369 | holiStr += event->summary(); | 402 | holiStr += event->summary(); |
370 | if ( !event->location().isEmpty() ) | 403 | if ( !event->location().isEmpty() ) |
371 | holiStr += " (" + event->location() + ")"; | 404 | holiStr += " (" + event->location() + ")"; |
372 | mHolidays[i] =holiStr ; | 405 | mHolidays[i] =holiStr ; |
373 | eDays.setBit(i); | 406 | eDays.setBit(i); |
374 | } | 407 | } |
375 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { | 408 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { |
376 | if ( event->isBirthday()) { | 409 | if ( event->isBirthday()) { |
377 | pDays.setBit(i); | 410 | pDays.setBit(i); |
378 | if ( !holiStr.isEmpty() ) | 411 | if ( !holiStr.isEmpty() ) |
379 | holiStr += "\n"; | 412 | holiStr += "\n"; |
380 | holiStr += i18n("Birthday") + ": "+event->summary(); | 413 | holiStr += i18n("Birthday") + ": "+event->summary(); |
381 | if ( !event->location().isEmpty() ) | 414 | if ( !event->location().isEmpty() ) |
382 | holiStr += " (" + event->location() + ")"; | 415 | holiStr += " (" + event->location() + ")"; |
383 | bDays.setBit(i); | 416 | bDays.setBit(i); |
384 | mHolidays[i] =holiStr ; | 417 | mHolidays[i] =holiStr ; |
385 | } | 418 | } |
386 | } | 419 | } |
387 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) | 420 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) |
388 | eDays.setBit(i); | 421 | eDays.setBit(i); |
389 | } | 422 | } |
390 | void KODayMatrix::updateViewTimed() | 423 | void KODayMatrix::updateViewTimed() |
391 | { | 424 | { |
392 | mUpdateTimer->stop(); | 425 | mUpdateTimer->stop(); |
393 | if ( !mCalendar ) { | 426 | if ( !mCalendar ) { |
394 | qDebug("NOT CAL "); | 427 | qDebug("NOT CAL "); |
395 | return; | 428 | return; |
396 | } | 429 | } |
397 | #if 1 | 430 | #if 1 |
398 | 431 | ||
399 | 432 | ||
400 | int i; | 433 | int i; |
401 | int timeSpan = NUMDAYS-1; | 434 | int timeSpan = NUMDAYS-1; |
402 | QPtrList<Event> events = mCalendar->events(); | 435 | QPtrList<Event> events = mCalendar->events(); |
403 | Event *event; | 436 | Event *event; |
404 | QDateTime dt; | 437 | QDateTime dt; |
405 | bool ok; | 438 | bool ok; |
406 | bDays.fill( false); | 439 | bDays.fill( false); |
407 | pDays.fill( false); | 440 | pDays.fill( false); |
408 | hDays.fill( false); | 441 | hDays.fill( false); |
409 | eDays.fill( false); | 442 | eDays.fill( false); |
410 | mHolidays.clear(); | 443 | mHolidays.clear(); |
411 | QDate mStartDate = days[0]; | 444 | QDate mStartDate = days[0]; |
412 | QDate endDate = mStartDate.addDays( timeSpan ); | 445 | QDate endDate = mStartDate.addDays( timeSpan ); |
413 | for( event = events.first(); event; event = events.next() ) { // for event | 446 | for( event = events.first(); event; event = events.next() ) { // for event |
414 | ushort recurType = event->recurrence()->doesRecur(); | 447 | ushort recurType = event->recurrence()->doesRecur(); |
415 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 448 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
416 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 449 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
417 | continue; | 450 | continue; |
418 | } | 451 | } |
419 | if ( event->doesRecur() ) { | 452 | if ( event->doesRecur() ) { |
420 | bool last; | 453 | bool last; |
421 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); | 454 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); |
422 | QDateTime incidenceEnd; | 455 | QDateTime incidenceEnd; |
423 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 456 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
424 | bool invalid = false; | 457 | bool invalid = false; |
425 | while( true ) { | 458 | while( true ) { |
426 | if ( incidenceStart.isValid() ) { | 459 | if ( incidenceStart.isValid() ) { |
427 | incidenceEnd = incidenceStart.addDays( eventlen ); | 460 | incidenceEnd = incidenceStart.addDays( eventlen ); |
428 | int st = incidenceStart.date().daysTo( endDate ); | 461 | int st = incidenceStart.date().daysTo( endDate ); |
429 | if ( st >= 0 ) { // start before timeend | 462 | if ( st >= 0 ) { // start before timeend |
430 | int end = mStartDate.daysTo( incidenceEnd.date() ); | 463 | int end = mStartDate.daysTo( incidenceEnd.date() ); |
431 | if ( end >= 0 ) { // end after timestart --- got one! | 464 | if ( end >= 0 ) { // end after timestart --- got one! |
432 | //normalize | 465 | //normalize |
433 | st = timeSpan - st; | 466 | st = timeSpan - st; |
434 | if ( st < 0 ) st = 0; | 467 | if ( st < 0 ) st = 0; |
435 | if ( end > timeSpan ) end = timeSpan; | 468 | if ( end > timeSpan ) end = timeSpan; |
436 | int iii; | 469 | int iii; |
437 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); | 470 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); |
438 | for ( iii = st;iii<= end;++iii) { | 471 | for ( iii = st;iii<= end;++iii) { |
439 | computeEvent( event, iii ); | 472 | computeEvent( event, iii ); |
440 | } | 473 | } |
441 | } | 474 | } |
442 | } | 475 | } |
443 | } else { | 476 | } else { |
444 | if ( invalid ) | 477 | if ( invalid ) |
445 | break; | 478 | break; |
446 | invalid = true; | 479 | invalid = true; |
447 | //qDebug("invalid %s", event->summary().latin1()); | 480 | //qDebug("invalid %s", event->summary().latin1()); |
448 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; | 481 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; |
449 | } | 482 | } |
450 | if ( last ) | 483 | if ( last ) |
451 | break; | 484 | break; |
452 | bool ok; | 485 | bool ok; |
453 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); | 486 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); |
454 | if ( ! ok ) | 487 | if ( ! ok ) |
455 | break; | 488 | break; |
456 | if ( incidenceStart.date() > endDate ) | 489 | if ( incidenceStart.date() > endDate ) |
457 | break; | 490 | break; |
458 | } | 491 | } |
459 | } else { // no recur | 492 | } else { // no recur |
460 | int st = event->dtStart().date().daysTo( endDate ); | 493 | int st = event->dtStart().date().daysTo( endDate ); |
461 | if ( st >= 0 ) { // start before timeend | 494 | if ( st >= 0 ) { // start before timeend |
462 | int end = mStartDate.daysTo( event->dtEnd().date() ); | 495 | int end = mStartDate.daysTo( event->dtEnd().date() ); |
463 | if ( end >= 0 ) { // end after timestart --- got one! | 496 | if ( end >= 0 ) { // end after timestart --- got one! |
464 | //normalize | 497 | //normalize |
465 | st = timeSpan - st; | 498 | st = timeSpan - st; |
466 | if ( st < 0 ) st = 0; | 499 | if ( st < 0 ) st = 0; |
467 | if ( end > timeSpan ) end = timeSpan; | 500 | if ( end > timeSpan ) end = timeSpan; |
468 | int iii; | 501 | int iii; |
469 | for ( iii = st;iii<= end;++iii) | 502 | for ( iii = st;iii<= end;++iii) |
470 | computeEvent( event, iii ); | 503 | computeEvent( event, iii ); |
471 | } | 504 | } |
472 | } | 505 | } |
473 | } | 506 | } |
474 | } | 507 | } |
475 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday | 508 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday |
476 | for(i = 0; i < NUMDAYS; i++) { | 509 | for(i = 0; i < NUMDAYS; i++) { |
477 | if ( ( (i+startDay) % 7 == 0 ) ) { | 510 | if ( ( (i+startDay) % 7 == 0 ) ) { |
478 | pDays.setBit(i); | 511 | pDays.setBit(i); |
479 | } | 512 | } |
480 | } | 513 | } |
481 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { | 514 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { |
482 | bDays.fill( false); | 515 | bDays.fill( false); |
483 | // insert due todos | 516 | // insert due todos |
484 | QPtrList<Todo> todos = mCalendar->todos( ); | 517 | QPtrList<Todo> todos = mCalendar->todos( ); |
485 | Todo *todo; | 518 | Todo *todo; |
486 | for(todo = todos.first(); todo; todo = todos.next()) { | 519 | for(todo = todos.first(); todo; todo = todos.next()) { |
487 | //insertTodo( todo ); | 520 | //insertTodo( todo ); |
488 | if ( todo->hasDueDate() ) { | 521 | if ( todo->hasDueDate() ) { |
489 | int day = mStartDate.daysTo( todo->dtDue().date() ); | 522 | int day = mStartDate.daysTo( todo->dtDue().date() ); |
490 | if ( day >= 0 && day < timeSpan + 1) { | 523 | if ( day >= 0 && day < timeSpan + 1) { |
491 | int i = day; | 524 | int i = day; |
492 | QString holiStr = mHolidays[i]; | 525 | QString holiStr = mHolidays[i]; |
493 | pDays.setBit(i); | 526 | pDays.setBit(i); |
494 | if ( !holiStr.isEmpty() ) | 527 | if ( !holiStr.isEmpty() ) |
495 | holiStr += "\n"; | 528 | holiStr += "\n"; |
496 | holiStr += i18n("Todo") + ": "+todo->summary(); | 529 | holiStr += i18n("Todo") + ": "+todo->summary(); |
497 | if ( !todo->location().isEmpty() ) | 530 | if ( !todo->location().isEmpty() ) |
498 | holiStr += " (" + todo->location() + ")"; | 531 | holiStr += " (" + todo->location() + ")"; |
499 | bDays.setBit(i); | 532 | bDays.setBit(i); |
500 | mHolidays[i] =holiStr ; | 533 | mHolidays[i] =holiStr ; |
501 | eDays.setBit(i); | 534 | eDays.setBit(i); |
502 | } | 535 | } |
503 | } | 536 | } |
504 | } | 537 | } |
505 | } | 538 | } |
506 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { | 539 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { |
507 | bDays.fill( false); | 540 | bDays.fill( false); |
508 | // insert due todos | 541 | // insert due todos |
509 | QPtrList<Journal> todos = mCalendar->journals( ); | 542 | QPtrList<Journal> todos = mCalendar->journals( ); |
510 | Journal *todo; | 543 | Journal *todo; |
511 | for(todo = todos.first(); todo; todo = todos.next()) { | 544 | for(todo = todos.first(); todo; todo = todos.next()) { |
512 | int day = mStartDate.daysTo( todo->dtStart().date() ); | 545 | int day = mStartDate.daysTo( todo->dtStart().date() ); |
513 | if ( day >= 0 && day < timeSpan + 1) { | 546 | if ( day >= 0 && day < timeSpan + 1) { |
514 | int i = day; | 547 | int i = day; |
515 | QString holiStr = mHolidays[i]; | 548 | QString holiStr = mHolidays[i]; |
516 | pDays.setBit(i); | 549 | pDays.setBit(i); |
517 | if ( !holiStr.isEmpty() ) | 550 | if ( !holiStr.isEmpty() ) |
518 | holiStr += "\n"; | 551 | holiStr += "\n"; |
519 | holiStr += i18n("Journal"); | 552 | holiStr += i18n("Journal"); |
520 | bDays.setBit(i); | 553 | bDays.setBit(i); |
521 | mHolidays[i] =holiStr ; | 554 | mHolidays[i] =holiStr ; |
522 | eDays.setBit(i); | 555 | eDays.setBit(i); |
523 | 556 | ||
524 | } | 557 | } |
525 | } | 558 | } |
526 | } | 559 | } |
527 | #else | 560 | #else |
528 | //qDebug("KODayMatrix::updateViewTimed "); | 561 | //qDebug("KODayMatrix::updateViewTimed "); |
529 | for(int i = 0; i < NUMDAYS; i++) { | 562 | for(int i = 0; i < NUMDAYS; i++) { |
530 | // if events are set for the day then remember to draw it bold | 563 | // if events are set for the day then remember to draw it bold |
531 | QPtrList<Event> eventlist = mCalendar->events(days[i]); | 564 | QPtrList<Event> eventlist = mCalendar->events(days[i]); |
532 | Event *event; | 565 | Event *event; |
533 | int numEvents = eventlist.count(); | 566 | int numEvents = eventlist.count(); |
534 | QString holiStr = ""; | 567 | QString holiStr = ""; |
535 | bDays.clearBit(i); | 568 | bDays.clearBit(i); |
536 | hDays.clearBit(i); | 569 | hDays.clearBit(i); |
537 | eDays.clearBit(i); | 570 | eDays.clearBit(i); |
538 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 571 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
539 | ushort recurType = event->recurrence()->doesRecur(); | 572 | ushort recurType = event->recurrence()->doesRecur(); |
540 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 573 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
541 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 574 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
542 | numEvents--; | 575 | numEvents--; |
543 | } | 576 | } |
544 | if ( event->isHoliday()) { | 577 | if ( event->isHoliday()) { |
545 | hDays.setBit(i); | 578 | hDays.setBit(i); |
546 | if ( !holiStr.isEmpty() ) | 579 | if ( !holiStr.isEmpty() ) |
547 | holiStr += "\n"; | 580 | holiStr += "\n"; |
548 | holiStr += event->summary(); | 581 | holiStr += event->summary(); |
549 | if ( !event->location().isEmpty() ) | 582 | if ( !event->location().isEmpty() ) |
550 | holiStr += " (" + event->location() + ")"; | 583 | holiStr += " (" + event->location() + ")"; |
551 | } | 584 | } |
552 | if ( event->isBirthday()) { | 585 | if ( event->isBirthday()) { |
553 | if ( !holiStr.isEmpty() ) | 586 | if ( !holiStr.isEmpty() ) |
554 | holiStr += "\n"; | 587 | holiStr += "\n"; |
555 | holiStr += i18n("Birthday") + ": "+event->summary(); | 588 | holiStr += i18n("Birthday") + ": "+event->summary(); |
556 | if ( !event->location().isEmpty() ) | 589 | if ( !event->location().isEmpty() ) |
557 | holiStr += " (" + event->location() + ")"; | 590 | holiStr += " (" + event->location() + ")"; |
558 | bDays.setBit(i); | 591 | bDays.setBit(i); |
559 | } | 592 | } |
560 | } | 593 | } |
561 | if ( numEvents ) | 594 | if ( numEvents ) |
562 | eDays.setBit(i); | 595 | eDays.setBit(i); |
563 | //if it is a holy day then draw it red. Sundays are consider holidays, too | 596 | //if it is a holy day then draw it red. Sundays are consider holidays, too |
564 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || | 597 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || |
565 | !holiStr.isEmpty()) { | 598 | !holiStr.isEmpty()) { |
566 | mHolidays[i] = holiStr; | 599 | mHolidays[i] = holiStr; |
567 | } else { | 600 | } else { |
568 | mHolidays[i] = QString::null; | 601 | mHolidays[i] = QString::null; |
569 | } | 602 | } |
570 | } | 603 | } |
571 | #endif | 604 | #endif |
572 | mRedrawNeeded = true; | 605 | mRedrawNeeded = true; |
573 | if ( ! mPendingUpdateBeforeRepaint ) | 606 | if ( ! mPendingUpdateBeforeRepaint ) |
574 | repaint(false); | 607 | repaint(false); |
575 | } | 608 | } |
576 | void KODayMatrix::updateView(QDate actdate) | 609 | void KODayMatrix::updateView(QDate actdate) |
577 | { | 610 | { |
578 | if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) | 611 | if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) |
579 | mRedrawNeeded = true; | 612 | mRedrawNeeded = true; |
580 | mLastView = KOPrefs::instance()->mCurrentDisplayedView; | 613 | mLastView = KOPrefs::instance()->mCurrentDisplayedView; |
581 | if ( ! actdate.isValid() ) { | 614 | if ( ! actdate.isValid() ) { |
582 | //qDebug("date not valid "); | 615 | //qDebug("date not valid "); |
583 | return; | 616 | return; |
584 | } | 617 | } |
585 | mDayChanged = false; | 618 | mDayChanged = false; |
586 | //flag to indicate if the starting day of the matrix has changed by this call | 619 | //flag to indicate if the starting day of the matrix has changed by this call |
587 | //mDayChanged = false; | 620 | //mDayChanged = false; |
588 | // if a new startdate is to be set then apply Cornelius's calculation | 621 | // if a new startdate is to be set then apply Cornelius's calculation |
589 | // of the first day to be shown | 622 | // of the first day to be shown |
590 | if (actdate != startdate) { | 623 | if (actdate != startdate) { |
591 | // reset index of selection according to shift of starting date from startdate to actdate | 624 | // reset index of selection according to shift of starting date from startdate to actdate |
592 | if (mSelStart != NOSELECTION) { | 625 | if (mSelStart != NOSELECTION) { |
593 | int tmp = actdate.daysTo(startdate); | 626 | int tmp = actdate.daysTo(startdate); |
594 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; | 627 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; |
595 | // shift selection if new one would be visible at least partly ! | 628 | // shift selection if new one would be visible at least partly ! |
596 | 629 | ||
597 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { | 630 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { |
598 | // nested if is required for next X display pushed from a different month - correction required | 631 | // nested if is required for next X display pushed from a different month - correction required |
599 | // otherwise, for month forward and backward, it must be avoided | 632 | // otherwise, for month forward and backward, it must be avoided |
600 | if( mSelStart > NUMDAYS || mSelStart < 0 ) | 633 | if( mSelStart > NUMDAYS || mSelStart < 0 ) |
601 | mSelStart = mSelStart + tmp; | 634 | mSelStart = mSelStart + tmp; |
602 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) | 635 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) |
603 | mSelEnd = mSelEnd + tmp; | 636 | mSelEnd = mSelEnd + tmp; |
604 | } | 637 | } |
605 | } | 638 | } |
606 | startdate = actdate; | 639 | startdate = actdate; |
607 | mDayChanged = true; | 640 | mDayChanged = true; |
608 | recalculateToday(); | 641 | recalculateToday(); |
609 | mRedrawNeeded = true; | 642 | mRedrawNeeded = true; |
610 | } | 643 | } |
611 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); | 644 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); |
612 | if ( !isVisible() ) { | 645 | if ( !isVisible() ) { |
613 | mPendingUpdateBeforeRepaint = true; | 646 | mPendingUpdateBeforeRepaint = true; |
614 | } else { | 647 | } else { |
615 | #ifdef DESKTOP_VERSION | 648 | #ifdef DESKTOP_VERSION |
616 | //mRepaintTimer->start( 100 ); | 649 | //mRepaintTimer->start( 100 ); |
617 | //updateViewTimed(); | 650 | //updateViewTimed(); |
618 | mUpdateTimer->start( 50 ); | 651 | mUpdateTimer->start( 50 ); |
619 | #else | 652 | #else |
620 | mRepaintTimer->start( 350 ); | 653 | mRepaintTimer->start( 350 ); |
621 | mUpdateTimer->start( 800 ); | 654 | mUpdateTimer->start( 800 ); |
622 | #endif | 655 | #endif |
623 | } | 656 | } |
624 | } | 657 | } |
625 | void KODayMatrix::updateEvents() | 658 | void KODayMatrix::updateEvents() |
626 | { | 659 | { |
627 | if ( !mCalendar ) return; | 660 | if ( !mCalendar ) return; |
628 | 661 | ||
629 | for( int i = 0; i < NUMDAYS; i++ ) { | 662 | for( int i = 0; i < NUMDAYS; i++ ) { |
630 | // if events are set for the day then remember to draw it bold | 663 | // if events are set for the day then remember to draw it bold |
631 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); | 664 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); |
632 | int numEvents = eventlist.count(); | 665 | int numEvents = eventlist.count(); |
633 | Event *event; | 666 | Event *event; |
634 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { | 667 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { |
635 | ushort recurType = event->doesRecur(); | 668 | ushort recurType = event->doesRecur(); |
636 | 669 | ||
637 | if ( ( recurType == Recurrence::rDaily && | 670 | if ( ( recurType == Recurrence::rDaily && |
638 | !KOPrefs::instance()->mDailyRecur ) || | 671 | !KOPrefs::instance()->mDailyRecur ) || |
639 | ( recurType == Recurrence::rWeekly && | 672 | ( recurType == Recurrence::rWeekly && |
640 | !KOPrefs::instance()->mWeeklyRecur ) ) { | 673 | !KOPrefs::instance()->mWeeklyRecur ) ) { |
641 | numEvents--; | 674 | numEvents--; |
642 | } | 675 | } |
643 | } | 676 | } |
644 | if ( numEvents ) | 677 | if ( numEvents ) |
645 | eDays.setBit(i); | 678 | eDays.setBit(i); |
646 | else | 679 | else |
647 | eDays.clearBit(i); | 680 | eDays.clearBit(i); |
648 | } | 681 | } |
649 | } | 682 | } |
650 | 683 | ||
651 | const QDate& KODayMatrix::getDate(int offset) | 684 | const QDate& KODayMatrix::getDate(int offset) |
652 | { | 685 | { |
653 | if (offset < 0 || offset > NUMDAYS-1) { | 686 | if (offset < 0 || offset > NUMDAYS-1) { |
654 | qDebug("Wrong offset2 %d", offset); | 687 | qDebug("Wrong offset2 %d", offset); |
655 | return days[0]; | 688 | return days[0]; |
656 | } | 689 | } |
657 | return days[offset]; | 690 | return days[offset]; |
658 | } | 691 | } |
659 | 692 | ||
660 | QString KODayMatrix::getHolidayLabel(int offset) | 693 | QString KODayMatrix::getHolidayLabel(int offset) |
661 | { | 694 | { |
662 | if (offset < 0 || offset > NUMDAYS-1) { | 695 | if (offset < 0 || offset > NUMDAYS-1) { |
663 | qDebug("Wrong offset1 %d", offset); | 696 | qDebug("Wrong offset1 %d", offset); |
664 | return QString(); | 697 | return QString(); |
665 | } | 698 | } |
666 | return mHolidays[offset]; | 699 | return mHolidays[offset]; |
667 | } | 700 | } |
668 | 701 | ||
669 | int KODayMatrix::getDayIndexFrom(int x, int y) | 702 | int KODayMatrix::getDayIndexFrom(int x, int y) |
670 | { | 703 | { |
671 | int colModulo = (width()-2) % 7; | 704 | int colModulo = (width()-2) % 7; |
672 | int rowModulo = (height()-2) % 6; | 705 | int rowModulo = (height()-2) % 6; |
673 | #if 0 | 706 | #if 0 |
674 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? | 707 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? |
675 | 6 - x/daysize.width() : x/daysize.width()); | 708 | 6 - x/daysize.width() : x/daysize.width()); |
676 | #endif | 709 | #endif |
677 | int xVal = (x-colModulo/2-2)/daysize.width(); | 710 | int xVal = (x-colModulo/2-2)/daysize.width(); |
678 | int yVal = (y-rowModulo/2-2)/daysize.height(); | 711 | int yVal = (y-rowModulo/2-2)/daysize.height(); |
679 | 712 | ||
680 | 713 | ||
681 | return 7*(yVal) + xVal; | 714 | return 7*(yVal) + xVal; |
682 | 715 | ||
683 | } | 716 | } |
684 | 717 | ||
685 | // ---------------------------------------------------------------------------- | 718 | // ---------------------------------------------------------------------------- |
686 | // M O U S E E V E N T H A N D L I N G | 719 | // M O U S E E V E N T H A N D L I N G |
687 | // ---------------------------------------------------------------------------- | 720 | // ---------------------------------------------------------------------------- |
688 | 721 | ||
689 | void KODayMatrix::mousePressEvent (QMouseEvent* e) | 722 | void KODayMatrix::mousePressEvent (QMouseEvent* e) |
690 | { | 723 | { |
691 | 724 | ||
692 | if ( e->button() == LeftButton ) | 725 | if ( e->button() == LeftButton ) |
693 | mouseDown = true; | 726 | mouseDown = true; |
694 | mSelStart = getDayIndexFrom(e->x(), e->y()); | 727 | mSelStart = getDayIndexFrom(e->x(), e->y()); |
695 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; | 728 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; |
696 | mSelInit = mSelStart; | 729 | mSelInit = mSelStart; |
697 | mSelEnd = mSelStart; | 730 | mSelEnd = mSelStart; |
698 | mRedrawNeeded = true; | 731 | mRedrawNeeded = true; |
699 | repaint(false); | 732 | repaint(false); |
700 | } | 733 | } |
701 | 734 | ||
702 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) | 735 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) |
703 | { | 736 | { |
704 | mRedrawNeeded = true; | 737 | mRedrawNeeded = true; |
705 | if ( e->button() == LeftButton ) | 738 | if ( e->button() == LeftButton ) |
706 | if ( ! mouseDown ) { | 739 | if ( ! mouseDown ) { |
707 | return; | 740 | return; |
708 | } | 741 | } |
709 | else | 742 | else |
710 | mouseDown = false; | 743 | mouseDown = false; |
711 | int tmp = getDayIndexFrom(e->x(), e->y()); | 744 | int tmp = getDayIndexFrom(e->x(), e->y()); |
712 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 745 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
713 | 746 | ||
714 | if (mSelInit > tmp) { | 747 | if (mSelInit > tmp) { |
715 | mSelEnd = mSelInit; | 748 | mSelEnd = mSelInit; |
716 | if (tmp != mSelStart) { | 749 | if (tmp != mSelStart) { |
717 | mSelStart = tmp; | 750 | mSelStart = tmp; |
718 | repaint(false); | 751 | repaint(false); |
719 | } | 752 | } |
720 | } else { | 753 | } else { |
721 | mSelStart = mSelInit; | 754 | mSelStart = mSelInit; |
722 | 755 | ||
723 | //repaint only if selection has changed | 756 | //repaint only if selection has changed |
724 | if (tmp != mSelEnd) { | 757 | if (tmp != mSelEnd) { |
725 | mSelEnd = tmp; | 758 | mSelEnd = tmp; |
726 | repaint(false); | 759 | repaint(false); |
727 | } | 760 | } |
728 | } | 761 | } |
729 | 762 | ||
730 | DateList daylist; | 763 | DateList daylist; |
731 | if ( mSelStart < 0 ) | 764 | if ( mSelStart < 0 ) |
732 | mSelStart = 0; | 765 | mSelStart = 0; |
733 | for (int i = mSelStart; i <= mSelEnd; i++) { | 766 | for (int i = mSelStart; i <= mSelEnd; i++) { |
734 | daylist.append(days[i]); | 767 | daylist.append(days[i]); |
735 | } | 768 | } |
736 | emit selected((const DateList)daylist); | 769 | emit selected((const DateList)daylist); |
737 | 770 | ||
738 | } | 771 | } |
739 | 772 | ||
740 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) | 773 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) |
741 | { | 774 | { |
742 | if ( ! mouseDown ) { | 775 | if ( ! mouseDown ) { |
743 | return; | 776 | return; |
744 | } | 777 | } |
745 | mRedrawNeeded = true; | 778 | mRedrawNeeded = true; |
746 | int tmp = getDayIndexFrom(e->x(), e->y()); | 779 | int tmp = getDayIndexFrom(e->x(), e->y()); |
747 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 780 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
748 | 781 | ||
749 | if (mSelInit > tmp) { | 782 | if (mSelInit > tmp) { |
750 | mSelEnd = mSelInit; | 783 | mSelEnd = mSelInit; |
751 | if (tmp != mSelStart) { | 784 | if (tmp != mSelStart) { |
752 | mSelStart = tmp; | 785 | mSelStart = tmp; |
753 | repaint(false); | 786 | repaint(false); |
754 | } | 787 | } |
755 | } else { | 788 | } else { |
756 | mSelStart = mSelInit; | 789 | mSelStart = mSelInit; |
757 | 790 | ||
758 | //repaint only if selection has changed | 791 | //repaint only if selection has changed |
759 | if (tmp != mSelEnd) { | 792 | if (tmp != mSelEnd) { |
760 | mSelEnd = tmp; | 793 | mSelEnd = tmp; |
761 | repaint(false); | 794 | repaint(false); |
762 | } | 795 | } |
763 | } | 796 | } |
764 | } | 797 | } |
765 | 798 | ||
766 | // ---------------------------------------------------------------------------- | 799 | // ---------------------------------------------------------------------------- |
767 | // D R A G ' N D R O P H A N D L I N G | 800 | // D R A G ' N D R O P H A N D L I N G |
768 | // ---------------------------------------------------------------------------- | 801 | // ---------------------------------------------------------------------------- |
769 | 802 | ||
770 | void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) | 803 | void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) |
771 | { | 804 | { |
772 | #ifndef KORG_NODND | 805 | #ifndef KORG_NODND |
773 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 806 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
774 | e->ignore(); | 807 | e->ignore(); |
775 | return; | 808 | return; |
776 | } | 809 | } |
777 | 810 | ||
778 | // some visual feedback | 811 | // some visual feedback |
779 | // oldPalette = palette(); | 812 | // oldPalette = palette(); |
780 | // setPalette(my_HilitePalette); | 813 | // setPalette(my_HilitePalette); |
781 | // update(); | 814 | // update(); |
782 | #endif | 815 | #endif |
783 | } | 816 | } |
784 | 817 | ||
785 | void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) | 818 | void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) |
786 | { | 819 | { |
787 | #ifndef KORG_NODND | 820 | #ifndef KORG_NODND |
788 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 821 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
789 | e->ignore(); | 822 | e->ignore(); |
790 | return; | 823 | return; |
791 | } | 824 | } |
792 | 825 | ||
793 | e->accept(); | 826 | e->accept(); |
794 | #endif | 827 | #endif |
795 | } | 828 | } |
796 | 829 | ||
797 | void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) | 830 | void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) |
798 | { | 831 | { |
799 | #ifndef KORG_NODND | 832 | #ifndef KORG_NODND |
800 | // setPalette(oldPalette); | 833 | // setPalette(oldPalette); |
801 | // update(); | 834 | // update(); |
802 | #endif | 835 | #endif |
803 | } | 836 | } |
804 | 837 | ||
805 | void KODayMatrix::dropEvent(QDropEvent *e) | 838 | void KODayMatrix::dropEvent(QDropEvent *e) |
806 | { | 839 | { |
807 | #ifndef KORG_NODND | 840 | #ifndef KORG_NODND |
808 | // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; | 841 | // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; |
809 | 842 | ||
810 | if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 843 | if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
811 | e->ignore(); | 844 | e->ignore(); |
812 | return; | 845 | return; |
813 | } | 846 | } |
814 | 847 | ||
815 | DndFactory factory( mCalendar ); | 848 | DndFactory factory( mCalendar ); |
816 | Event *event = factory.createDrop(e); | 849 | Event *event = factory.createDrop(e); |
817 | 850 | ||
818 | if (event) { | 851 | if (event) { |
819 | e->acceptAction(); | 852 | e->acceptAction(); |
820 | 853 | ||
821 | Event *existingEvent = mCalendar->event(event->uid()); | 854 | Event *existingEvent = mCalendar->event(event->uid()); |
822 | 855 | ||
823 | if(existingEvent) { | 856 | if(existingEvent) { |
824 | // uniquify event | 857 | // uniquify event |
825 | event->recreate(); | 858 | event->recreate(); |
826 | /* | 859 | /* |
827 | KMessageBox::sorry(this, | 860 | KMessageBox::sorry(this, |
828 | i18n("Event already exists in this calendar."), | 861 | i18n("Event already exists in this calendar."), |
829 | i18n("Drop Event")); | 862 | i18n("Drop Event")); |
830 | delete event; | 863 | delete event; |
831 | return; | 864 | return; |
832 | */ | 865 | */ |
833 | } | 866 | } |
834 | // kdDebug() << "Drop new Event" << endl; | 867 | // kdDebug() << "Drop new Event" << endl; |
835 | // Adjust date | 868 | // Adjust date |
836 | QDateTime start = event->dtStart(); | 869 | QDateTime start = event->dtStart(); |
837 | QDateTime end = event->dtEnd(); | 870 | QDateTime end = event->dtEnd(); |
838 | int duration = start.daysTo(end); | 871 | int duration = start.daysTo(end); |
839 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); | 872 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); |
840 | 873 | ||
841 | start.setDate(days[idx]); | 874 | start.setDate(days[idx]); |
842 | end.setDate(days[idx].addDays(duration)); | 875 | end.setDate(days[idx].addDays(duration)); |
843 | 876 | ||
844 | event->setDtStart(start); | 877 | event->setDtStart(start); |
845 | event->setDtEnd(end); | 878 | event->setDtEnd(end); |
846 | mCalendar->addEvent(event); | 879 | mCalendar->addEvent(event); |
847 | 880 | ||
848 | emit eventDropped(event); | 881 | emit eventDropped(event); |
849 | } else { | 882 | } else { |
850 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; | 883 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; |
851 | e->ignore(); | 884 | e->ignore(); |
852 | } | 885 | } |
853 | #endif | 886 | #endif |
854 | } | 887 | } |
855 | 888 | ||
856 | // ---------------------------------------------------------------------------- | 889 | // ---------------------------------------------------------------------------- |
857 | // P A I N T E V E N T H A N D L I N G | 890 | // P A I N T E V E N T H A N D L I N G |
858 | // ---------------------------------------------------------------------------- | 891 | // ---------------------------------------------------------------------------- |
859 | 892 | ||
860 | void KODayMatrix::paintEvent(QPaintEvent * pevent) | 893 | void KODayMatrix::paintEvent(QPaintEvent * pevent) |
861 | { | 894 | { |
862 | 895 | ||
863 | if ( width() <= 0 || height() <= 0 ) | 896 | if ( width() <= 0 || height() <= 0 ) |
864 | return; | 897 | return; |
865 | if ( mPendingUpdateBeforeRepaint ) { | 898 | if ( mPendingUpdateBeforeRepaint ) { |
866 | updateViewTimed(); | 899 | updateViewTimed(); |
867 | mPendingUpdateBeforeRepaint = false; | 900 | mPendingUpdateBeforeRepaint = false; |
868 | } | 901 | } |
869 | #if 0 | 902 | #if 0 |
870 | if ( myPix.width() != width() || myPix.height()!=height() ) { | 903 | if ( myPix.width() != width() || myPix.height()!=height() ) { |
871 | myPix.resize(size() ); | 904 | myPix.resize(size() ); |
872 | mRedrawNeeded = true; | 905 | mRedrawNeeded = true; |
873 | } | 906 | } |
874 | #endif | 907 | #endif |
875 | if ( oldW != width() || oldH !=height() ) | 908 | if ( oldW != width() || oldH !=height() ) |
876 | mRedrawNeeded = true; | 909 | mRedrawNeeded = true; |
877 | 910 | ||
878 | oldH = height() ; | 911 | oldH = height() ; |
879 | oldW = width(); | 912 | oldW = width(); |
880 | if ( myPix.width() < width() || myPix.height() < height() ) { | 913 | if ( myPix.width() < width() || myPix.height() < height() ) { |
881 | myPix.resize(size() ); | 914 | myPix.resize(size() ); |
882 | mRedrawNeeded = true; | 915 | mRedrawNeeded = true; |
883 | 916 | ||
884 | } | 917 | } |
885 | 918 | ||
886 | if ( mRedrawNeeded ) { | 919 | if ( mRedrawNeeded ) { |
887 | //qDebug("REDRAW "); | 920 | //qDebug("REDRAW "); |
888 | QPainter p(&myPix); | 921 | QPainter p(&myPix); |
889 | p.setFont(font()); | 922 | p.setFont(font()); |
890 | 923 | ||
891 | 924 | ||
892 | int dheight = daysize.height(); | 925 | int dheight = daysize.height(); |
893 | int dwidth = daysize.width(); | 926 | int dwidth = daysize.width(); |
894 | int row,col; | 927 | int row,col; |
895 | int selw, selh; | 928 | int selw, selh; |
896 | int xyOff = frameWidth(); | 929 | int xyOff = frameWidth(); |
897 | int colModulo = (width()-2) % 7; | 930 | int colModulo = (width()-2) % 7; |
898 | int rowModulo = (height()-2) % 6; | 931 | int rowModulo = (height()-2) % 6; |
899 | //qDebug("col %d row %d ",colModulo,rowModulo ); | 932 | //qDebug("col %d row %d ",colModulo,rowModulo ); |
900 | 933 | ||
901 | bool isRTL = KOGlobals::self()->reverseLayout(); | 934 | bool isRTL = KOGlobals::self()->reverseLayout(); |
902 | 935 | ||
903 | // draw background and topleft frame | 936 | // draw background and topleft frame |
904 | p.fillRect(0,0,width(),height(), mDefaultBackColor); | 937 | p.fillRect(0,0,width(),height(), mDefaultBackColor); |
905 | p.setPen(mDefaultTextColor); | 938 | p.setPen(mDefaultTextColor); |
906 | p.drawRect(0, 0, width(), height()); | 939 | p.drawRect(0, 0, width(), height()); |
907 | int mSelStartT = mSelStart; | 940 | int mSelStartT = mSelStart; |
908 | int mSelEndT = mSelEnd; | 941 | int mSelEndT = mSelEnd; |
909 | if ( mSelEndT >= NUMDAYS ) | 942 | if ( mSelEndT >= NUMDAYS ) |
910 | mSelEndT = NUMDAYS-1; | 943 | mSelEndT = NUMDAYS-1; |
911 | // draw selected days with highlighted background color | 944 | // draw selected days with highlighted background color |
912 | if (mSelStart != NOSELECTION) { | 945 | if (mSelStart != NOSELECTION) { |
913 | bool skip = false; | 946 | bool skip = false; |
914 | if ( ! mouseDown ) { | 947 | if ( ! mouseDown ) { |
915 | int mo = days[20].month(); | 948 | int mo = days[20].month(); |
916 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); | 949 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); |
917 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); | 950 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); |
918 | int startMo = days[mSelStartT].month(); | 951 | int startMo = days[mSelStartT].month(); |
919 | int endMo = days[mSelEndT].month(); | 952 | int endMo = days[mSelEndT].month(); |
920 | if ( startMo == 12 && mo == 1 && endMo <= 2 ) | 953 | if ( startMo == 12 && mo == 1 && endMo <= 2 ) |
921 | startMo = 1; | 954 | startMo = 1; |
922 | if ( endMo == 1 && mo == 12 ) | 955 | if ( endMo == 1 && mo == 12 ) |
923 | endMo = 12; | 956 | endMo = 12; |
924 | if ( mo == 12 && startMo == 1 ) | 957 | if ( mo == 12 && startMo == 1 ) |
925 | startMo = 13; | 958 | startMo = 13; |
926 | if ( (startMo > mo || endMo < mo) ) { | 959 | if ( (startMo > mo || endMo < mo) ) { |
927 | skip = true; | 960 | skip = true; |
928 | } else { | 961 | } else { |
929 | if ( days[mSelStartT].month() != mo ) { | 962 | if ( days[mSelStartT].month() != mo ) { |
930 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); | 963 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); |
931 | mSelStartT += add +1; | 964 | mSelStartT += add +1; |
932 | } | 965 | } |
933 | if ( days[mSelEndT].month() != mo ) { | 966 | if ( days[mSelEndT].month() != mo ) { |
934 | int sub = days[mSelEndT].day(); | 967 | int sub = days[mSelEndT].day(); |
935 | mSelEndT -= sub ; | 968 | mSelEndT -= sub ; |
936 | } | 969 | } |
937 | } | 970 | } |
938 | } | 971 | } |
939 | //qDebug("SKIP %d ", skip); | 972 | //qDebug("SKIP %d ", skip); |
940 | if ( ! skip ) { | 973 | if ( ! skip ) { |
941 | row = mSelStartT/7; | 974 | row = mSelStartT/7; |
942 | col = mSelStartT -row*7; | 975 | col = mSelStartT -row*7; |
943 | QColor selcol = KOPrefs::instance()->mHighlightColor; | 976 | QColor selcol = KOPrefs::instance()->mHighlightColor; |
944 | int addCol = 0; | 977 | int addCol = 0; |
945 | int addRow = 0; | 978 | int addRow = 0; |
946 | int addRow2 = 0; | 979 | int addRow2 = 0; |
947 | int addCol2 = 0; | 980 | int addCol2 = 0; |
948 | if (row == mSelEndT/7) { | 981 | if (row == mSelEndT/7) { |
949 | if ( rowModulo ) { | 982 | if ( rowModulo ) { |
950 | if ( row >= 6 - rowModulo ) | 983 | if ( row >= 6 - rowModulo ) |
951 | addRow = row - 5 + rowModulo; | 984 | addRow = row - 5 + rowModulo; |
952 | } | 985 | } |
953 | if ( colModulo ) { | 986 | if ( colModulo ) { |
954 | int colt1 = mSelEndT%7; | 987 | int colt1 = mSelEndT%7; |
955 | //qDebug("colt1 %d ", colt1 ); | 988 | //qDebug("colt1 %d ", colt1 ); |
956 | if ( colt1 >= 7 - colModulo ) | 989 | if ( colt1 >= 7 - colModulo ) |
957 | addCol = colt1 - 7 + colModulo+1; | 990 | addCol = colt1 - 7 + colModulo+1; |
958 | int colt = mSelStartT%7; | 991 | int colt = mSelStartT%7; |
959 | if ( colt >= 7 - colModulo ) | 992 | if ( colt >= 7 - colModulo ) |
960 | addCol2 = colt - 7 + colModulo; | 993 | addCol2 = colt - 7 + colModulo; |
961 | addCol -= addCol2; | 994 | addCol -= addCol2; |
962 | //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); | 995 | //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); |
963 | } | 996 | } |
964 | // Single row selection | 997 | // Single row selection |
965 | //if ( row == 0) | 998 | //if ( row == 0) |
966 | // addRow = 1; | 999 | // addRow = 1; |
967 | p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, | 1000 | p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, |
968 | row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); | 1001 | row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); |
969 | } else { | 1002 | } else { |
970 | // draw first row to the right | 1003 | // draw first row to the right |
971 | if ( colModulo ) { | 1004 | if ( colModulo ) { |
972 | if ( col >= 7 - colModulo ) | 1005 | if ( col >= 7 - colModulo ) |
973 | addCol2 = col - 7 + colModulo; | 1006 | addCol2 = col - 7 + colModulo; |
974 | } | 1007 | } |
975 | if ( rowModulo ) { | 1008 | if ( rowModulo ) { |
976 | if ( row >= 6 - rowModulo ) | 1009 | if ( row >= 6 - rowModulo ) |
977 | addRow = row - 5 + rowModulo; | 1010 | addRow = row - 5 + rowModulo; |
978 | } | 1011 | } |
979 | //if ( row == 0) | 1012 | //if ( row == 0) |
980 | // addRow = 1; | 1013 | // addRow = 1; |
981 | int drawWid = width()-(col*dwidth+1+addCol2)-1; | 1014 | int drawWid = width()-(col*dwidth+1+addCol2)-1; |
982 | p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid, | 1015 | p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid, |
983 | dheight+1, selcol); | 1016 | dheight+1, selcol); |
984 | // draw full block till last line | 1017 | // draw full block till last line |
985 | selh = mSelEndT/7-row; | 1018 | selh = mSelEndT/7-row; |
986 | addRow = 0; | 1019 | addRow = 0; |
987 | if ( rowModulo ) { | 1020 | if ( rowModulo ) { |
diff --git a/korganizer/kodaymatrix.h b/korganizer/kodaymatrix.h index a3216d6..b96e08f 100644 --- a/korganizer/kodaymatrix.h +++ b/korganizer/kodaymatrix.h | |||
@@ -1,331 +1,332 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> | 3 | Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | #ifndef _KODAYMAT_H | 23 | #ifndef _KODAYMAT_H |
24 | #define _KODAYMAT_H | 24 | #define _KODAYMAT_H |
25 | 25 | ||
26 | #include <libkcal/calendar.h> | 26 | #include <libkcal/calendar.h> |
27 | 27 | ||
28 | #include <qstring.h> | 28 | #include <qstring.h> |
29 | #include <qframe.h> | 29 | #include <qframe.h> |
30 | #include <qcolor.h> | 30 | #include <qcolor.h> |
31 | #include <qpen.h> | 31 | #include <qpen.h> |
32 | #include <qdatetime.h> | 32 | #include <qdatetime.h> |
33 | #include <qtooltip.h> | 33 | #include <qtooltip.h> |
34 | #include <qpixmap.h> | 34 | #include <qpixmap.h> |
35 | #include <qbitarray.h> | 35 | #include <qbitarray.h> |
36 | #include <qmap.h> | 36 | #include <qmap.h> |
37 | 37 | ||
38 | class QDragEnterEvent; | 38 | class QDragEnterEvent; |
39 | class QDragMoveEvent; | 39 | class QDragMoveEvent; |
40 | class QDragLeaveEvent; | 40 | class QDragLeaveEvent; |
41 | class QDropEvent; | 41 | class QDropEvent; |
42 | 42 | ||
43 | class KODayMatrix; | 43 | class KODayMatrix; |
44 | class KODaymatrixWhatsThis; | 44 | class KODaymatrixWhatsThis; |
45 | 45 | ||
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | 48 | ||
49 | /** | 49 | /** |
50 | * small helper class to dynamically show tooltips inside the day matrix. | 50 | * small helper class to dynamically show tooltips inside the day matrix. |
51 | * This class asks the day matrix object for a appropriate label which | 51 | * This class asks the day matrix object for a appropriate label which |
52 | * is in our special case the name of the holiday or null if this day is no holiday. | 52 | * is in our special case the name of the holiday or null if this day is no holiday. |
53 | */ | 53 | */ |
54 | class DynamicTip : public QToolTip | 54 | class DynamicTip : public QToolTip |
55 | { | 55 | { |
56 | public: | 56 | public: |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Constructor that expects a KODayMatrix object as parent. | 59 | * Constructor that expects a KODayMatrix object as parent. |
60 | * | 60 | * |
61 | * @param parent the parent KODayMatrix control. | 61 | * @param parent the parent KODayMatrix control. |
62 | */ | 62 | */ |
63 | DynamicTip(QWidget* parent ); | 63 | DynamicTip(QWidget* parent ); |
64 | 64 | ||
65 | protected: | 65 | protected: |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Qt's callback to ask the object to provide an approrpiate text for the | 68 | * Qt's callback to ask the object to provide an approrpiate text for the |
69 | * tooltip to be shown. | 69 | * tooltip to be shown. |
70 | * | 70 | * |
71 | * @param pos coordinates of the mouse. | 71 | * @param pos coordinates of the mouse. |
72 | */ | 72 | */ |
73 | void maybeTip( const QPoint & pos); | 73 | void maybeTip( const QPoint & pos); |
74 | 74 | ||
75 | private: | 75 | private: |
76 | 76 | ||
77 | /** the parent control this tooltip is designed for. */ | 77 | /** the parent control this tooltip is designed for. */ |
78 | KODayMatrix* matrix; | 78 | KODayMatrix* matrix; |
79 | }; | 79 | }; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * replacement for kdpdatebuton.cpp that used 42 widgets for the day matrix to be displayed. | 82 | * replacement for kdpdatebuton.cpp that used 42 widgets for the day matrix to be displayed. |
83 | * Cornelius thought this was a waste of memory and a lot of overhead. | 83 | * Cornelius thought this was a waste of memory and a lot of overhead. |
84 | * In addition the selection was not very intuitive so I decided to rewrite it using a QFrame | 84 | * In addition the selection was not very intuitive so I decided to rewrite it using a QFrame |
85 | * that draws the labels and allows for dragging selection while maintaining nearly full | 85 | * that draws the labels and allows for dragging selection while maintaining nearly full |
86 | * compatibility in behaviour with its predecessor. | 86 | * compatibility in behaviour with its predecessor. |
87 | * | 87 | * |
88 | * The following functionality has been changed: | 88 | * The following functionality has been changed: |
89 | * | 89 | * |
90 | * o when shifting events in the agenda view from one day to another the day matrix is updated now | 90 | * o when shifting events in the agenda view from one day to another the day matrix is updated now |
91 | * o TODO ET dragging an event to the matrix will MOVE not COPY the event to the new date. | 91 | * o TODO ET dragging an event to the matrix will MOVE not COPY the event to the new date. |
92 | * o no support for Ctrl+click to create groups of dates | 92 | * o no support for Ctrl+click to create groups of dates |
93 | * (This has not really been supported in the predecessor. It was not very intuitive nor was it | 93 | * (This has not really been supported in the predecessor. It was not very intuitive nor was it |
94 | * user friendly.) | 94 | * user friendly.) |
95 | * This feature has been replaced with dragging a selection on the matrix. The matrix will | 95 | * This feature has been replaced with dragging a selection on the matrix. The matrix will |
96 | * automatically choose the appropriate selection (e.g. you are not any longer able to select | 96 | * automatically choose the appropriate selection (e.g. you are not any longer able to select |
97 | * two distinct groups of date selections as in the old class) | 97 | * two distinct groups of date selections as in the old class) |
98 | * o now that you can select more then a week it can happen that not all selected days are | 98 | * o now that you can select more then a week it can happen that not all selected days are |
99 | * displayed in the matrix. However this is preferred to the alternative which would mean to | 99 | * displayed in the matrix. However this is preferred to the alternative which would mean to |
100 | * adjust the selection and leave some days undisplayed while scrolling through the months | 100 | * adjust the selection and leave some days undisplayed while scrolling through the months |
101 | * | 101 | * |
102 | * @short day matrix widget of the KDateNavigator | 102 | * @short day matrix widget of the KDateNavigator |
103 | * | 103 | * |
104 | * @author Eitzenberger Thomas | 104 | * @author Eitzenberger Thomas |
105 | */ | 105 | */ |
106 | class KODayMatrix: public QFrame { | 106 | class KODayMatrix: public QFrame { |
107 | 107 | ||
108 | Q_OBJECT | 108 | Q_OBJECT |
109 | 109 | ||
110 | public: | 110 | public: |
111 | 111 | ||
112 | /** constructor to create a day matrix widget. | 112 | /** constructor to create a day matrix widget. |
113 | * | 113 | * |
114 | * @param parent widget that is the parent of the day matrix. Normally this should | 114 | * @param parent widget that is the parent of the day matrix. Normally this should |
115 | * be a KDateNavigator | 115 | * be a KDateNavigator |
116 | * @param calendar instance of a calendar on which all calculations are based | 116 | * @param calendar instance of a calendar on which all calculations are based |
117 | * @param date start date of the matrix (is expected to be already fixed). It is | 117 | * @param date start date of the matrix (is expected to be already fixed). It is |
118 | * assumed that this date is the first week day to be shown in the matrix. | 118 | * assumed that this date is the first week day to be shown in the matrix. |
119 | * @param name name of the widget | 119 | * @param name name of the widget |
120 | */ | 120 | */ |
121 | KODayMatrix( QWidget *parent, const char *name ); | 121 | KODayMatrix( QWidget *parent, const char *name ); |
122 | //KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name ); | 122 | //KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name ); |
123 | 123 | ||
124 | /** destructor that deallocates all dynamically allocated private members. | 124 | /** destructor that deallocates all dynamically allocated private members. |
125 | */ | 125 | */ |
126 | ~KODayMatrix(); | 126 | ~KODayMatrix(); |
127 | 127 | ||
128 | /** updates the day matrix to start with the given date. Does all the necessary | 128 | /** updates the day matrix to start with the given date. Does all the necessary |
129 | * checks for holidays or events on a day and stores them for display later on. | 129 | * checks for holidays or events on a day and stores them for display later on. |
130 | * Does NOT update the view visually. Call repaint() for this. | 130 | * Does NOT update the view visually. Call repaint() for this. |
131 | * | 131 | * |
132 | * @param actdate recalculates the day matrix to show NUMDAYS starting from this | 132 | * @param actdate recalculates the day matrix to show NUMDAYS starting from this |
133 | * date. | 133 | * date. |
134 | */ | 134 | */ |
135 | void updateView(QDate actdate); | 135 | void updateView(QDate actdate); |
136 | void updateEvents(); | 136 | void updateEvents(); |
137 | 137 | ||
138 | /** returns the QDate object associated with day indexed by the | 138 | /** returns the QDate object associated with day indexed by the |
139 | * supplied offset. | 139 | * supplied offset. |
140 | */ | 140 | */ |
141 | const QDate& getDate(int offset); | 141 | const QDate& getDate(int offset); |
142 | void setCalendar( Calendar * ); | 142 | void setCalendar( Calendar * ); |
143 | /** returns the official name of this holy day or 0 if there is no label | 143 | /** returns the official name of this holy day or 0 if there is no label |
144 | * for this day. | 144 | * for this day. |
145 | */ | 145 | */ |
146 | QString getHolidayLabel(int offset); | 146 | QString getHolidayLabel(int offset); |
147 | 147 | ||
148 | /** adds all actual selected days from mSelStart to mSelEnd to the supplied | 148 | /** adds all actual selected days from mSelStart to mSelEnd to the supplied |
149 | * DateList. | 149 | * DateList. |
150 | */ | 150 | */ |
151 | void addSelectedDaysTo(DateList&); | 151 | void addSelectedDaysTo(DateList&); |
152 | 152 | ||
153 | /** sets the actual to be displayed selection in the day matrix starting from | 153 | /** sets the actual to be displayed selection in the day matrix starting from |
154 | * start and ending with end. Theview must be manually updated by calling | 154 | * start and ending with end. Theview must be manually updated by calling |
155 | * repaint. (?) | 155 | * repaint. (?) |
156 | */ | 156 | */ |
157 | bool setSelectedDaysFrom(const QDate& start, const QDate& end); | 157 | bool setSelectedDaysFrom(const QDate& start, const QDate& end); |
158 | void clearSelection(); | 158 | void clearSelection(); |
159 | 159 | ||
160 | /** Is today visible in the view? Keep this in sync with | 160 | /** Is today visible in the view? Keep this in sync with |
161 | * the values today (below) can take. | 161 | * the values today (below) can take. |
162 | */ | 162 | */ |
163 | bool isTodayVisible() const { return today>=0; } ; | 163 | bool isTodayVisible() const { return today>=0; } ; |
164 | 164 | ||
165 | /** If today is visible, then we can find out if today is | 165 | /** If today is visible, then we can find out if today is |
166 | * near the beginning or the end of the month. | 166 | * near the beginning or the end of the month. |
167 | * This is dependent on today remaining the index | 167 | * This is dependent on today remaining the index |
168 | * in the array of visible dates and going from | 168 | * in the array of visible dates and going from |
169 | * top left (0) to bottom right (41). | 169 | * top left (0) to bottom right (41). |
170 | */ | 170 | */ |
171 | bool isBeginningOfMonth() const { return today<=8; } ; | 171 | bool isBeginningOfMonth() const { return today<=8; } ; |
172 | bool isEndOfMonth() const { return today>=27; } ; | 172 | bool isEndOfMonth() const { return today>=27; } ; |
173 | QString getWhatsThisText( QPoint ) ; | 173 | QString getWhatsThisText( QPoint ) ; |
174 | QSize sizeHint() const; | 174 | QSize sizeHint() const; |
175 | QRect frameRect () const { int wid = frameWidth(); return QRect(0+wid,0+wid,width()-wid-wid,height()-wid-wid);} | 175 | QRect frameRect () const { int wid = frameWidth(); return QRect(0+wid,0+wid,width()-wid-wid,height()-wid-wid);} |
176 | public slots: | 176 | public slots: |
177 | /** Recalculates all the flags of the days in the matrix like holidays or events | 177 | /** Recalculates all the flags of the days in the matrix like holidays or events |
178 | * on a day (Actually calls above method with the actual startdate). | 178 | * on a day (Actually calls above method with the actual startdate). |
179 | */ | 179 | */ |
180 | void updateView(); | 180 | void updateView(); |
181 | void updateViewTimed(); | 181 | void updateViewTimed(); |
182 | void repaintViewTimed(); | 182 | void repaintViewTimed(); |
183 | 183 | ||
184 | /** | 184 | /** |
185 | * Calculate which square in the matrix should be | 185 | * Calculate which square in the matrix should be |
186 | * hilighted to indicate it's today. | 186 | * hilighted to indicate it's today. |
187 | */ | 187 | */ |
188 | void recalculateToday(); | 188 | void recalculateToday(); |
189 | 189 | ||
190 | /* | 190 | /* |
191 | void setStartDate(QDate); | 191 | void setStartDate(QDate); |
192 | */ | 192 | */ |
193 | 193 | ||
194 | signals: | 194 | signals: |
195 | 195 | ||
196 | /** emitted if the user selects a block of days with the mouse by dragging a rectangle | 196 | /** emitted if the user selects a block of days with the mouse by dragging a rectangle |
197 | * inside the matrix | 197 | * inside the matrix |
198 | * | 198 | * |
199 | * @param daylist list of days that have been selected by the user | 199 | * @param daylist list of days that have been selected by the user |
200 | */ | 200 | */ |
201 | void selected( const KCal::DateList &daylist ); | 201 | void selected( const KCal::DateList &daylist ); |
202 | 202 | ||
203 | /** emitted if the user has dropped an event inside the matrix | 203 | /** emitted if the user has dropped an event inside the matrix |
204 | * | 204 | * |
205 | * @param event the dropped calendar event | 205 | * @param event the dropped calendar event |
206 | */ | 206 | */ |
207 | void eventDropped(Event *event); | 207 | void eventDropped(Event *event); |
208 | 208 | ||
209 | protected: | 209 | protected: |
210 | QString deTag( QString mToolTipText ); | ||
210 | 211 | ||
211 | void paintEvent(QPaintEvent *ev); | 212 | void paintEvent(QPaintEvent *ev); |
212 | 213 | ||
213 | void mousePressEvent (QMouseEvent* e); | 214 | void mousePressEvent (QMouseEvent* e); |
214 | 215 | ||
215 | void mouseReleaseEvent (QMouseEvent* e); | 216 | void mouseReleaseEvent (QMouseEvent* e); |
216 | 217 | ||
217 | void mouseMoveEvent (QMouseEvent* e); | 218 | void mouseMoveEvent (QMouseEvent* e); |
218 | 219 | ||
219 | void dragEnterEvent(QDragEnterEvent *); | 220 | void dragEnterEvent(QDragEnterEvent *); |
220 | 221 | ||
221 | void dragMoveEvent(QDragMoveEvent *); | 222 | void dragMoveEvent(QDragMoveEvent *); |
222 | 223 | ||
223 | void dragLeaveEvent(QDragLeaveEvent *); | 224 | void dragLeaveEvent(QDragLeaveEvent *); |
224 | 225 | ||
225 | void dropEvent(QDropEvent *); | 226 | void dropEvent(QDropEvent *); |
226 | 227 | ||
227 | void resizeEvent(QResizeEvent *); | 228 | void resizeEvent(QResizeEvent *); |
228 | 229 | ||
229 | private: | 230 | private: |
230 | int mLastView; | 231 | int mLastView; |
231 | void computeEvent(Event *even, int dayindex ); | 232 | void computeEvent(Event *even, int dayindex ); |
232 | int oldW, oldH; | 233 | int oldW, oldH; |
233 | bool mRedrawNeeded; | 234 | bool mRedrawNeeded; |
234 | KODaymatrixWhatsThis* mKODaymatrixWhatsThis; | 235 | KODaymatrixWhatsThis* mKODaymatrixWhatsThis; |
235 | bool mouseDown; | 236 | bool mouseDown; |
236 | QBitArray bDays; | 237 | QBitArray bDays; |
237 | QBitArray hDays; | 238 | QBitArray hDays; |
238 | QBitArray eDays; | 239 | QBitArray eDays; |
239 | QBitArray pDays; | 240 | QBitArray pDays; |
240 | QPixmap myPix; | 241 | QPixmap myPix; |
241 | QTimer* mUpdateTimer; | 242 | QTimer* mUpdateTimer; |
242 | QTimer* mRepaintTimer; | 243 | QTimer* mRepaintTimer; |
243 | bool mDayChanged; | 244 | bool mDayChanged; |
244 | bool mPendingUpdateBeforeRepaint; | 245 | bool mPendingUpdateBeforeRepaint; |
245 | 246 | ||
246 | /** returns the index of the day located at the matrix's widget (x,y) position. | 247 | /** returns the index of the day located at the matrix's widget (x,y) position. |
247 | * | 248 | * |
248 | * @param x horizontal coordinate | 249 | * @param x horizontal coordinate |
249 | * @param y vertical coordinate | 250 | * @param y vertical coordinate |
250 | */ | 251 | */ |
251 | int getDayIndexFrom(int x, int y); | 252 | int getDayIndexFrom(int x, int y); |
252 | 253 | ||
253 | /** calculates a "shaded" color from the supplied color object. | 254 | /** calculates a "shaded" color from the supplied color object. |
254 | * (Copied from Cornelius's kdpdatebutton.cpp) | 255 | * (Copied from Cornelius's kdpdatebutton.cpp) |
255 | * | 256 | * |
256 | * @param color source based on which a shaded color should be calculated. | 257 | * @param color source based on which a shaded color should be calculated. |
257 | */ | 258 | */ |
258 | QColor getShadedColor(QColor color); | 259 | QColor getShadedColor(QColor color); |
259 | 260 | ||
260 | /** number of days to be displayed. For now there is no support for any other number then 42. | 261 | /** number of days to be displayed. For now there is no support for any other number then 42. |
261 | so change it at your own risk :o) */ | 262 | so change it at your own risk :o) */ |
262 | static const int NUMDAYS; | 263 | static const int NUMDAYS; |
263 | 264 | ||
264 | /** calendar instance to be queried for holidays, events, ... */ | 265 | /** calendar instance to be queried for holidays, events, ... */ |
265 | Calendar *mCalendar; | 266 | Calendar *mCalendar; |
266 | 267 | ||
267 | /** starting date of the matrix */ | 268 | /** starting date of the matrix */ |
268 | QDate startdate; | 269 | QDate startdate; |
269 | 270 | ||
270 | /** array of day labels to optimeize drawing performance. */ | 271 | /** array of day labels to optimeize drawing performance. */ |
271 | QString *daylbls; | 272 | QString *daylbls; |
272 | 273 | ||
273 | /** array of days displayed to reduce memory consumption by | 274 | /** array of days displayed to reduce memory consumption by |
274 | subsequently calling QDate::addDays(). */ | 275 | subsequently calling QDate::addDays(). */ |
275 | QDate *days; | 276 | QDate *days; |
276 | 277 | ||
277 | /** array of storing the number of events on a given day. | 278 | /** array of storing the number of events on a given day. |
278 | * used for drawing a bold font if there is at least one event on that day. | 279 | * used for drawing a bold font if there is at least one event on that day. |
279 | */ | 280 | */ |
280 | //int *events; | 281 | //int *events; |
281 | 282 | ||
282 | /** stores holiday names of the days shown in the matrix. */ | 283 | /** stores holiday names of the days shown in the matrix. */ |
283 | QMap<int,QString> mHolidays; | 284 | QMap<int,QString> mHolidays; |
284 | 285 | ||
285 | /** indey of today or -1 if today is not visible in the matrix. */ | 286 | /** indey of today or -1 if today is not visible in the matrix. */ |
286 | int today; | 287 | int today; |
287 | 288 | ||
288 | /** index of day where dragged selection was initiated. | 289 | /** index of day where dragged selection was initiated. |
289 | used to detect "negative" timely selections */ | 290 | used to detect "negative" timely selections */ |
290 | int mSelInit; | 291 | int mSelInit; |
291 | 292 | ||
292 | /** if mSelStart has this value it indicates that there is no | 293 | /** if mSelStart has this value it indicates that there is no |
293 | actual selection in the matrix. */ | 294 | actual selection in the matrix. */ |
294 | static const int NOSELECTION; | 295 | static const int NOSELECTION; |
295 | 296 | ||
296 | /** index of first selected day. */ | 297 | /** index of first selected day. */ |
297 | int mSelStart; | 298 | int mSelStart; |
298 | 299 | ||
299 | /** index of last selected day. */ | 300 | /** index of last selected day. */ |
300 | int mSelEnd; | 301 | int mSelEnd; |
301 | 302 | ||
302 | /** dynamic tooltip to handle mouse dependent tips for each day in the matrix. */ | 303 | /** dynamic tooltip to handle mouse dependent tips for each day in the matrix. */ |
303 | DynamicTip* mToolTip; | 304 | DynamicTip* mToolTip; |
304 | 305 | ||
305 | 306 | ||
306 | /** default background colour of the matrix. */ | 307 | /** default background colour of the matrix. */ |
307 | QColor mDefaultBackColor; | 308 | QColor mDefaultBackColor; |
308 | 309 | ||
309 | /** default text color of the matrix. */ | 310 | /** default text color of the matrix. */ |
310 | QColor mDefaultTextColor; | 311 | QColor mDefaultTextColor; |
311 | 312 | ||
312 | /** default text color for days not in the actual month. */ | 313 | /** default text color for days not in the actual month. */ |
313 | QColor mDefaultTextColorShaded; | 314 | QColor mDefaultTextColorShaded; |
314 | 315 | ||
315 | /** default text color for holidays not in the actual month. */ | 316 | /** default text color for holidays not in the actual month. */ |
316 | QColor mHolidayColorShaded; | 317 | QColor mHolidayColorShaded; |
317 | 318 | ||
318 | /** text color for selected days. */ | 319 | /** text color for selected days. */ |
319 | QColor mSelectedDaysColor; | 320 | QColor mSelectedDaysColor; |
320 | 321 | ||
321 | /** default width of the frame drawn around today if it is visible in the matrix. */ | 322 | /** default width of the frame drawn around today if it is visible in the matrix. */ |
322 | int mTodayMarginWidth; | 323 | int mTodayMarginWidth; |
323 | 324 | ||
324 | /** stores actual size of each day in the widget so that I dont need to ask this data | 325 | /** stores actual size of each day in the widget so that I dont need to ask this data |
325 | * on every repaint. | 326 | * on every repaint. |
326 | */ | 327 | */ |
327 | QRect daysize; | 328 | QRect daysize; |
328 | 329 | ||
329 | }; | 330 | }; |
330 | 331 | ||
331 | #endif | 332 | #endif |