-rw-r--r-- | korganizer/kodaymatrix.cpp | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index 52fd1e8..4f681b3 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -1,271 +1,280 @@ | |||
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 <q3ptrlist.h> |
28 | #include <qtimer.h> | 28 | #include <qtimer.h> |
29 | #include <qwhatsthis.h> | 29 | #include <q3whatsthis.h> |
30 | //Added by qt3to4: | ||
31 | #include <QDragLeaveEvent> | ||
32 | #include <Q3Frame> | ||
33 | #include <QDragEnterEvent> | ||
34 | #include <QDragMoveEvent> | ||
35 | #include <QDropEvent> | ||
36 | #include <QResizeEvent> | ||
37 | #include <QMouseEvent> | ||
38 | #include <QPaintEvent> | ||
30 | 39 | ||
31 | #include <kglobal.h> | 40 | #include <kglobal.h> |
32 | #include <kdebug.h> | 41 | #include <kdebug.h> |
33 | #include <klocale.h> | 42 | #include <klocale.h> |
34 | 43 | ||
35 | #include <libkcal/vcaldrag.h> | 44 | #include <libkcal/vcaldrag.h> |
36 | #include <libkcal/icaldrag.h> | 45 | #include <libkcal/icaldrag.h> |
37 | #include <libkcal/dndfactory.h> | 46 | #include <libkcal/dndfactory.h> |
38 | #include <libkcal/calendarresources.h> | 47 | #include <libkcal/calendarresources.h> |
39 | #include <libkcal/resourcecalendar.h> | 48 | #include <libkcal/resourcecalendar.h> |
40 | #include <kresources/resourceselectdialog.h> | 49 | #include <kresources/resourceselectdialog.h> |
41 | 50 | ||
42 | #include <kcalendarsystem.h> | 51 | #include <kcalendarsystem.h> |
43 | 52 | ||
44 | #ifndef KORG_NOPLUGINS | 53 | #ifndef KORG_NOPLUGINS |
45 | #include "kocore.h" | 54 | #include "kocore.h" |
46 | #endif | 55 | #endif |
47 | #include "koprefs.h" | 56 | #include "koprefs.h" |
48 | #include "koglobals.h" | 57 | #include "koglobals.h" |
49 | 58 | ||
50 | #include "kodaymatrix.h" | 59 | #include "kodaymatrix.h" |
51 | 60 | ||
52 | // ============================================================================ | 61 | // ============================================================================ |
53 | // D Y N A M I C T I P | 62 | // D Y N A M I C T I P |
54 | // ============================================================================ | 63 | // ============================================================================ |
55 | 64 | ||
56 | DynamicTip::DynamicTip( QWidget * parent ) | 65 | DynamicTip::DynamicTip( QWidget * parent ) |
57 | : QToolTip( parent ) | 66 | /* TODO:hacker: : QToolTip( parent ) */ |
58 | { | 67 | { |
59 | matrix = (KODayMatrix*)parent; | 68 | matrix = (KODayMatrix*)parent; |
60 | } | 69 | } |
61 | 70 | ||
62 | class KODaymatrixWhatsThis :public QWhatsThis | 71 | class KODaymatrixWhatsThis :public Q3WhatsThis |
63 | { | 72 | { |
64 | public: | 73 | public: |
65 | KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; | 74 | KODaymatrixWhatsThis( KODayMatrix* view ) : Q3WhatsThis( view ),_view (view) { ;}; |
66 | ~KODaymatrixWhatsThis() { ; }; | 75 | ~KODaymatrixWhatsThis() { ; }; |
67 | 76 | ||
68 | protected: | 77 | protected: |
69 | virtual QString text( const QPoint& p ) | 78 | virtual QString text( const QPoint& p ) |
70 | { | 79 | { |
71 | return _view->getWhatsThisText( p ) ; | 80 | return _view->getWhatsThisText( p ) ; |
72 | } | 81 | } |
73 | private: | 82 | private: |
74 | KODayMatrix * _view; | 83 | KODayMatrix * _view; |
75 | }; | 84 | }; |
76 | 85 | ||
77 | void DynamicTip::maybeTip( const QPoint &pos ) | 86 | void DynamicTip::maybeTip( const QPoint &pos ) |
78 | { | 87 | { |
79 | //calculate which cell of the matrix the mouse is in | 88 | //calculate which cell of the matrix the mouse is in |
80 | QRect sz = matrix->frameRect(); | 89 | QRect sz = matrix->frameRect(); |
81 | int dheight = sz.height()*7 / 42; | 90 | int dheight = sz.height()*7 / 42; |
82 | int dwidth = sz.width() / 7; | 91 | int dwidth = sz.width() / 7; |
83 | int row = pos.y()/dheight; | 92 | int row = pos.y()/dheight; |
84 | int col = pos.x()/dwidth; | 93 | int col = pos.x()/dwidth; |
85 | 94 | ||
86 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); | 95 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); |
87 | 96 | ||
88 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << | 97 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << |
89 | // col << "][" << row << "] => " <<(col+row*7) << endl; | 98 | // col << "][" << row << "] => " <<(col+row*7) << endl; |
90 | 99 | ||
91 | //show holiday names only | 100 | //show holiday names only |
92 | QString str = matrix->getHolidayLabel(col+row*7); | 101 | QString str = matrix->getHolidayLabel(col+row*7); |
93 | if (str.isEmpty()) return; | 102 | if (str.isEmpty()) return; |
94 | tip(rct, str); | 103 | /* TODO:hacker: tip(rct, str);*/ |
95 | } | 104 | } |
96 | 105 | ||
97 | 106 | ||
98 | // ============================================================================ | 107 | // ============================================================================ |
99 | // K O D A Y M A T R I X | 108 | // K O D A Y M A T R I X |
100 | // ============================================================================ | 109 | // ============================================================================ |
101 | 110 | ||
102 | const int KODayMatrix::NOSELECTION = -1000; | 111 | const int KODayMatrix::NOSELECTION = -1000; |
103 | const int KODayMatrix::NUMDAYS = 42; | 112 | const int KODayMatrix::NUMDAYS = 42; |
104 | 113 | ||
105 | KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) | 114 | KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) |
106 | : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) | 115 | : Q3Frame( parent, name , Qt::WNoAutoErase ), mCalendar( 0 ) |
107 | 116 | ||
108 | 117 | ||
109 | { | 118 | { |
110 | mLastView = -1; | 119 | mLastView = -1; |
111 | oldW = 0; | 120 | oldW = 0; |
112 | oldH = 0; | 121 | oldH = 0; |
113 | myPix.resize( 150, 120 ); | 122 | myPix.resize( 150, 120 ); |
114 | mRedrawNeeded = true; | 123 | mRedrawNeeded = true; |
115 | mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); | 124 | mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); |
116 | mPendingUpdateBeforeRepaint = false; | 125 | mPendingUpdateBeforeRepaint = false; |
117 | mouseDown = false; | 126 | mouseDown = false; |
118 | // initialize dynamic arrays | 127 | // initialize dynamic arrays |
119 | bDays.resize ( NUMDAYS ); | 128 | bDays.resize ( NUMDAYS ); |
120 | pDays.resize ( NUMDAYS ); | 129 | pDays.resize ( NUMDAYS ); |
121 | hDays.resize ( NUMDAYS ); | 130 | hDays.resize ( NUMDAYS ); |
122 | eDays.resize ( NUMDAYS ); | 131 | eDays.resize ( NUMDAYS ); |
123 | days = new QDate[NUMDAYS]; | 132 | days = new QDate[NUMDAYS]; |
124 | daylbls = new QString[NUMDAYS]; | 133 | daylbls = new QString[NUMDAYS]; |
125 | //events = new int[NUMDAYS]; | 134 | //events = new int[NUMDAYS]; |
126 | mToolTip = new DynamicTip(this); | 135 | mToolTip = new DynamicTip(this); |
127 | 136 | ||
128 | // set default values used for drawing the matrix | 137 | // set default values used for drawing the matrix |
129 | mDefaultBackColor = palette().active().base(); | 138 | mDefaultBackColor = palette().active().base(); |
130 | mDefaultTextColor = palette().active().foreground(); | 139 | mDefaultTextColor = palette().active().foreground(); |
131 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); | 140 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); |
132 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); | 141 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); |
133 | mSelectedDaysColor = QColor("white"); | 142 | mSelectedDaysColor = QColor("white"); |
134 | mTodayMarginWidth = 2; | 143 | mTodayMarginWidth = 2; |
135 | mSelEnd = mSelStart = NOSELECTION; | 144 | mSelEnd = mSelStart = NOSELECTION; |
136 | 145 | ||
137 | setAcceptDrops(true); | 146 | setAcceptDrops(true); |
138 | //setFont( QFont("Arial", 10) ); | 147 | //setFont( QFont("Arial", 10) ); |
139 | 148 | ||
140 | mUpdateTimer = new QTimer( this ); | 149 | mUpdateTimer = new QTimer( this ); |
141 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); | 150 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); |
142 | mRepaintTimer = new QTimer( this ); | 151 | mRepaintTimer = new QTimer( this ); |
143 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); | 152 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); |
144 | mDayChanged = false; | 153 | mDayChanged = false; |
145 | updateView(); | 154 | updateView(); |
146 | } | 155 | } |
147 | QString KODayMatrix::getWhatsThisText( QPoint p ) | 156 | QString KODayMatrix::getWhatsThisText( QPoint p ) |
148 | { | 157 | { |
149 | 158 | ||
150 | int tmp = getDayIndexFrom(p.x(), p.y()); | 159 | int tmp = getDayIndexFrom(p.x(), p.y()); |
151 | if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) | 160 | if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) |
152 | return QString(); | 161 | return QString(); |
153 | QDate mDate = days[tmp]; | 162 | QDate mDate = days[tmp]; |
154 | QPtrList<Event> eventlist = mCalendar->events(mDate); | 163 | Q3PtrList<Event> eventlist = mCalendar->events(mDate); |
155 | Event *event; | 164 | Event *event; |
156 | QStringList mToolTip; | 165 | QStringList mToolTip; |
157 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 166 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
158 | QString mToolTipText; | 167 | QString mToolTipText; |
159 | QString text; | 168 | QString text; |
160 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day | 169 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day |
161 | if (event->isMultiDay()) { | 170 | if (event->isMultiDay()) { |
162 | QString prefix = "<->";multiday = 2; | 171 | QString prefix = "<->";multiday = 2; |
163 | QString time; | 172 | QString time; |
164 | if ( event->doesRecur() ) { | 173 | if ( event->doesRecur() ) { |
165 | if ( event->recursOn( mDate) ) { | 174 | if ( event->recursOn( mDate) ) { |
166 | prefix ="->" ;multiday = 1; | 175 | prefix ="->" ;multiday = 1; |
167 | } | 176 | } |
168 | else { | 177 | else { |
169 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 178 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
170 | if ( event->recursOn( mDate.addDays( -days)) ) { | 179 | if ( event->recursOn( mDate.addDays( -days)) ) { |
171 | prefix ="<-" ;multiday = 3; | 180 | prefix ="<-" ;multiday = 3; |
172 | } | 181 | } |
173 | } | 182 | } |
174 | } else { | 183 | } else { |
175 | if (mDate == event->dtStart().date()) { | 184 | if (mDate == event->dtStart().date()) { |
176 | prefix ="->" ;multiday = 1; | 185 | prefix ="->" ;multiday = 1; |
177 | } else if (mDate == event->dtEnd().date()) { | 186 | } else if (mDate == event->dtEnd().date()) { |
178 | prefix ="<-" ;multiday = 3; | 187 | prefix ="<-" ;multiday = 3; |
179 | } | 188 | } |
180 | } | 189 | } |
181 | if ( !event->doesFloat() ) { | 190 | if ( !event->doesFloat() ) { |
182 | if ( mDate == event->dtStart().date () ) | 191 | if ( mDate == event->dtStart().date () ) |
183 | time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; | 192 | time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; |
184 | else if ( mDate == event->dtEnd().date () ) | 193 | else if ( mDate == event->dtEnd().date () ) |
185 | time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; | 194 | time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; |
186 | 195 | ||
187 | } | 196 | } |
188 | text = time + event->summary(); | 197 | text = time + event->summary(); |
189 | mToolTipText += prefix + text; | 198 | mToolTipText += prefix + text; |
190 | } else { | 199 | } else { |
191 | if (event->doesFloat()) { | 200 | if (event->doesFloat()) { |
192 | text = event->summary(); | 201 | text = event->summary(); |
193 | mToolTipText += text; | 202 | mToolTipText += text; |
194 | } | 203 | } |
195 | else { | 204 | else { |
196 | text = KGlobal::locale()->formatTime(event->dtStart().time()); | 205 | text = KGlobal::locale()->formatTime(event->dtStart().time()); |
197 | text += " " + event->summary(); | 206 | text += " " + event->summary(); |
198 | mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); | 207 | mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); |
199 | } | 208 | } |
200 | } | 209 | } |
201 | if ( !event->location().isEmpty() ) | 210 | if ( !event->location().isEmpty() ) |
202 | mToolTipText += " (" + event->location() + ")"; | 211 | mToolTipText += " (" + event->location() + ")"; |
203 | //qDebug("TTT: %s ", mToolTipText.latin1()); | 212 | //qDebug("TTT: %s ", mToolTipText.latin1()); |
204 | mToolTip.append( deTag( mToolTipText ) ); | 213 | mToolTip.append( deTag( mToolTipText ) ); |
205 | } | 214 | } |
206 | mToolTip.sort(); | 215 | mToolTip.sort(); |
207 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { | 216 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { |
208 | QPtrList<Todo> todolist = mCalendar->todos(mDate); | 217 | Q3PtrList<Todo> todolist = mCalendar->todos(mDate); |
209 | Todo *todo; | 218 | Todo *todo; |
210 | for(todo=todolist.first();todo != 0;todo=todolist.next()) { | 219 | for(todo=todolist.first();todo != 0;todo=todolist.next()) { |
211 | QString mToolTipText; | 220 | QString mToolTipText; |
212 | if ( !todo->doesFloat() ) | 221 | if ( !todo->doesFloat() ) |
213 | mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" "; | 222 | mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" "; |
214 | mToolTipText += todo->summary(); | 223 | mToolTipText += todo->summary(); |
215 | if ( !todo->location().isEmpty() ) | 224 | if ( !todo->location().isEmpty() ) |
216 | mToolTipText += " (" + todo->location() + ")"; | 225 | mToolTipText += " (" + todo->location() + ")"; |
217 | mToolTipText = deTag( mToolTipText); | 226 | mToolTipText = deTag( mToolTipText); |
218 | mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText; | 227 | mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText; |
219 | mToolTip.append( mToolTipText ); | 228 | mToolTip.append( mToolTipText ); |
220 | } | 229 | } |
221 | } | 230 | } |
222 | if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { | 231 | if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { |
223 | QPtrList<Journal> j_list = mCalendar->journals4Date( mDate ); | 232 | Q3PtrList<Journal> j_list = mCalendar->journals4Date( mDate ); |
224 | Journal *j = j_list.first(); | 233 | Journal *j = j_list.first(); |
225 | while ( j ) { | 234 | while ( j ) { |
226 | QString mToolTipText; | 235 | QString mToolTipText; |
227 | if ( !j->summary().isEmpty() ) { | 236 | if ( !j->summary().isEmpty() ) { |
228 | mToolTipText = j->summary().left(30); | 237 | mToolTipText = j->summary().left(30); |
229 | if ( j->summary().length() > 30 ) | 238 | if ( j->summary().length() > 30 ) |
230 | mToolTipText += " ..."; | 239 | mToolTipText += " ..."; |
231 | } else { | 240 | } else { |
232 | mToolTipText = j->description().left(25); | 241 | mToolTipText = j->description().left(25); |
233 | if ( j->description().length() > 25 ) | 242 | if ( j->description().length() > 25 ) |
234 | mToolTipText += " ..."; | 243 | mToolTipText += " ..."; |
235 | mToolTipText = deTag( mToolTipText); | 244 | mToolTipText = deTag( mToolTipText); |
236 | } | 245 | } |
237 | mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText; | 246 | mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText; |
238 | mToolTip.append( mToolTipText ); | 247 | mToolTip.append( mToolTipText ); |
239 | j = j_list.next(); | 248 | j = j_list.next(); |
240 | } | 249 | } |
241 | } | 250 | } |
242 | return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); | 251 | return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); |
243 | } | 252 | } |
244 | 253 | ||
245 | 254 | ||
246 | QString KODayMatrix::deTag( QString mToolTipText ) | 255 | QString KODayMatrix::deTag( QString mToolTipText ) |
247 | { | 256 | { |
248 | 257 | ||
249 | #if QT_VERSION >= 0x030000 | 258 | #if QT_VERSION >= 0x030000 |
250 | mToolTipText.replace( '<' , "<" ); | 259 | mToolTipText.replace( '<' , "<" ); |
251 | mToolTipText.replace( '>' , ">" ); | 260 | mToolTipText.replace( '>' , ">" ); |
252 | #else | 261 | #else |
253 | if ( mToolTipText.find ('<') >= 0 ) { | 262 | if ( mToolTipText.find ('<') >= 0 ) { |
254 | mToolTipText.replace( QRegExp("<") , "<" ); | 263 | mToolTipText.replace( QRegExp("<") , "<" ); |
255 | } | 264 | } |
256 | if ( mToolTipText.find ('>') >= 0 ) { | 265 | if ( mToolTipText.find ('>') >= 0 ) { |
257 | mToolTipText.replace( QRegExp(">") , ">" ); | 266 | mToolTipText.replace( QRegExp(">") , ">" ); |
258 | } | 267 | } |
259 | #endif | 268 | #endif |
260 | return mToolTipText; | 269 | return mToolTipText; |
261 | } | 270 | } |
262 | void KODayMatrix::setCalendar( Calendar *cal ) | 271 | void KODayMatrix::setCalendar( Calendar *cal ) |
263 | { | 272 | { |
264 | mCalendar = cal; | 273 | mCalendar = cal; |
265 | 274 | ||
266 | setAcceptDrops( mCalendar ); | 275 | setAcceptDrops( mCalendar ); |
267 | 276 | ||
268 | updateEvents(); | 277 | updateEvents(); |
269 | } | 278 | } |
270 | 279 | ||
271 | QColor KODayMatrix::getShadedColor(QColor color) | 280 | QColor KODayMatrix::getShadedColor(QColor color) |
@@ -396,231 +405,231 @@ void KODayMatrix::repaintViewTimed() | |||
396 | for(i = 0; i < NUMDAYS; i++) { | 405 | for(i = 0; i < NUMDAYS; i++) { |
397 | if ( ( (i+startDay) % 7 == 0 ) ) { | 406 | if ( ( (i+startDay) % 7 == 0 ) ) { |
398 | pDays.setBit(i); | 407 | pDays.setBit(i); |
399 | } | 408 | } |
400 | } | 409 | } |
401 | repaint(false); | 410 | repaint(false); |
402 | } | 411 | } |
403 | void KODayMatrix::computeEvent(Event *event, int i ) | 412 | void KODayMatrix::computeEvent(Event *event, int i ) |
404 | { | 413 | { |
405 | QString holiStr = mHolidays[i]; | 414 | QString holiStr = mHolidays[i]; |
406 | if ( event->isHoliday()) { | 415 | if ( event->isHoliday()) { |
407 | pDays.setBit(i); | 416 | pDays.setBit(i); |
408 | hDays.setBit(i); | 417 | hDays.setBit(i); |
409 | if ( !holiStr.isEmpty() ) | 418 | if ( !holiStr.isEmpty() ) |
410 | holiStr += "\n"; | 419 | holiStr += "\n"; |
411 | holiStr += event->summary(); | 420 | holiStr += event->summary(); |
412 | if ( !event->location().isEmpty() ) | 421 | if ( !event->location().isEmpty() ) |
413 | holiStr += " (" + event->location() + ")"; | 422 | holiStr += " (" + event->location() + ")"; |
414 | mHolidays[i] =holiStr ; | 423 | mHolidays[i] =holiStr ; |
415 | eDays.setBit(i); | 424 | eDays.setBit(i); |
416 | } | 425 | } |
417 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { | 426 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { |
418 | if ( event->isBirthday()) { | 427 | if ( event->isBirthday()) { |
419 | pDays.setBit(i); | 428 | pDays.setBit(i); |
420 | if ( !holiStr.isEmpty() ) | 429 | if ( !holiStr.isEmpty() ) |
421 | holiStr += "\n"; | 430 | holiStr += "\n"; |
422 | holiStr += i18n("Birthday") + ": "+event->summary(); | 431 | holiStr += i18n("Birthday") + ": "+event->summary(); |
423 | if ( !event->location().isEmpty() ) | 432 | if ( !event->location().isEmpty() ) |
424 | holiStr += " (" + event->location() + ")"; | 433 | holiStr += " (" + event->location() + ")"; |
425 | bDays.setBit(i); | 434 | bDays.setBit(i); |
426 | mHolidays[i] =holiStr ; | 435 | mHolidays[i] =holiStr ; |
427 | } | 436 | } |
428 | } | 437 | } |
429 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) | 438 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) |
430 | eDays.setBit(i); | 439 | eDays.setBit(i); |
431 | } | 440 | } |
432 | void KODayMatrix::updateViewTimed() | 441 | void KODayMatrix::updateViewTimed() |
433 | { | 442 | { |
434 | mUpdateTimer->stop(); | 443 | mUpdateTimer->stop(); |
435 | if ( !mCalendar ) { | 444 | if ( !mCalendar ) { |
436 | qDebug("NOT CAL "); | 445 | qDebug("NOT CAL "); |
437 | return; | 446 | return; |
438 | } | 447 | } |
439 | #if 1 | 448 | #if 1 |
440 | 449 | ||
441 | 450 | ||
442 | int i; | 451 | int i; |
443 | int timeSpan = NUMDAYS-1; | 452 | int timeSpan = NUMDAYS-1; |
444 | QPtrList<Event> events = mCalendar->events(); | 453 | Q3PtrList<Event> events = mCalendar->events(); |
445 | Event *event; | 454 | Event *event; |
446 | QDateTime dt; | 455 | QDateTime dt; |
447 | bool ok; | 456 | bool ok; |
448 | bDays.fill( false); | 457 | bDays.fill( false); |
449 | pDays.fill( false); | 458 | pDays.fill( false); |
450 | hDays.fill( false); | 459 | hDays.fill( false); |
451 | eDays.fill( false); | 460 | eDays.fill( false); |
452 | mHolidays.clear(); | 461 | mHolidays.clear(); |
453 | QDate mStartDate = days[0]; | 462 | QDate mStartDate = days[0]; |
454 | QDate endDate = mStartDate.addDays( timeSpan ); | 463 | QDate endDate = mStartDate.addDays( timeSpan ); |
455 | for( event = events.first(); event; event = events.next() ) { // for event | 464 | for( event = events.first(); event; event = events.next() ) { // for event |
456 | ushort recurType = event->doesRecur(); | 465 | ushort recurType = event->doesRecur(); |
457 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 466 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
458 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 467 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
459 | continue; | 468 | continue; |
460 | } | 469 | } |
461 | if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) { | 470 | if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) { |
462 | continue; | 471 | continue; |
463 | } | 472 | } |
464 | if ( event->doesRecur() ) { | 473 | if ( event->doesRecur() ) { |
465 | bool last; | 474 | bool last; |
466 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); | 475 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); |
467 | QDateTime incidenceEnd; | 476 | QDateTime incidenceEnd; |
468 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 477 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
469 | bool invalid = false; | 478 | bool invalid = false; |
470 | while( true ) { | 479 | while( true ) { |
471 | if ( incidenceStart.isValid() ) { | 480 | if ( incidenceStart.isValid() ) { |
472 | incidenceEnd = incidenceStart.addDays( eventlen ); | 481 | incidenceEnd = incidenceStart.addDays( eventlen ); |
473 | int st = incidenceStart.date().daysTo( endDate ); | 482 | int st = incidenceStart.date().daysTo( endDate ); |
474 | if ( st >= 0 ) { // start before timeend | 483 | if ( st >= 0 ) { // start before timeend |
475 | int end = mStartDate.daysTo( incidenceEnd.date() ); | 484 | int end = mStartDate.daysTo( incidenceEnd.date() ); |
476 | if ( end >= 0 ) { // end after timestart --- got one! | 485 | if ( end >= 0 ) { // end after timestart --- got one! |
477 | //normalize | 486 | //normalize |
478 | st = timeSpan - st; | 487 | st = timeSpan - st; |
479 | if ( st < 0 ) st = 0; | 488 | if ( st < 0 ) st = 0; |
480 | if ( end > timeSpan ) end = timeSpan; | 489 | if ( end > timeSpan ) end = timeSpan; |
481 | int iii; | 490 | int iii; |
482 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); | 491 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); |
483 | for ( iii = st;iii<= end;++iii) { | 492 | for ( iii = st;iii<= end;++iii) { |
484 | computeEvent( event, iii ); | 493 | computeEvent( event, iii ); |
485 | } | 494 | } |
486 | } | 495 | } |
487 | } | 496 | } |
488 | } else { | 497 | } else { |
489 | if ( invalid ) | 498 | if ( invalid ) |
490 | break; | 499 | break; |
491 | invalid = true; | 500 | invalid = true; |
492 | //qDebug("invalid %s", event->summary().latin1()); | 501 | //qDebug("invalid %s", event->summary().latin1()); |
493 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; | 502 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; |
494 | } | 503 | } |
495 | if ( last ) | 504 | if ( last ) |
496 | break; | 505 | break; |
497 | bool ok; | 506 | bool ok; |
498 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); | 507 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); |
499 | if ( ! ok ) | 508 | if ( ! ok ) |
500 | break; | 509 | break; |
501 | if ( incidenceStart.date() > endDate ) | 510 | if ( incidenceStart.date() > endDate ) |
502 | break; | 511 | break; |
503 | } | 512 | } |
504 | } else { // no recur | 513 | } else { // no recur |
505 | int st = event->dtStart().date().daysTo( endDate ); | 514 | int st = event->dtStart().date().daysTo( endDate ); |
506 | if ( st >= 0 ) { // start before timeend | 515 | if ( st >= 0 ) { // start before timeend |
507 | int end = mStartDate.daysTo( event->dtEnd().date() ); | 516 | int end = mStartDate.daysTo( event->dtEnd().date() ); |
508 | if ( end >= 0 ) { // end after timestart --- got one! | 517 | if ( end >= 0 ) { // end after timestart --- got one! |
509 | //normalize | 518 | //normalize |
510 | st = timeSpan - st; | 519 | st = timeSpan - st; |
511 | if ( st < 0 ) st = 0; | 520 | if ( st < 0 ) st = 0; |
512 | if ( end > timeSpan ) end = timeSpan; | 521 | if ( end > timeSpan ) end = timeSpan; |
513 | int iii; | 522 | int iii; |
514 | for ( iii = st;iii<= end;++iii) | 523 | for ( iii = st;iii<= end;++iii) |
515 | computeEvent( event, iii ); | 524 | computeEvent( event, iii ); |
516 | } | 525 | } |
517 | } | 526 | } |
518 | } | 527 | } |
519 | } | 528 | } |
520 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday | 529 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday |
521 | for(i = 0; i < NUMDAYS; i++) { | 530 | for(i = 0; i < NUMDAYS; i++) { |
522 | if ( ( (i+startDay) % 7 == 0 ) ) { | 531 | if ( ( (i+startDay) % 7 == 0 ) ) { |
523 | pDays.setBit(i); | 532 | pDays.setBit(i); |
524 | } | 533 | } |
525 | } | 534 | } |
526 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { | 535 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { |
527 | bDays.fill( false); | 536 | bDays.fill( false); |
528 | // insert due todos | 537 | // insert due todos |
529 | QPtrList<Todo> todos = mCalendar->todos( ); | 538 | Q3PtrList<Todo> todos = mCalendar->todos( ); |
530 | Todo *todo; | 539 | Todo *todo; |
531 | for(todo = todos.first(); todo; todo = todos.next()) { | 540 | for(todo = todos.first(); todo; todo = todos.next()) { |
532 | //insertTodo( todo ); | 541 | //insertTodo( todo ); |
533 | if ( todo->hasDueDate() ) { | 542 | if ( todo->hasDueDate() ) { |
534 | int day = mStartDate.daysTo( todo->dtDue().date() ); | 543 | int day = mStartDate.daysTo( todo->dtDue().date() ); |
535 | if ( day >= 0 && day < timeSpan + 1) { | 544 | if ( day >= 0 && day < timeSpan + 1) { |
536 | int i = day; | 545 | int i = day; |
537 | QString holiStr = mHolidays[i]; | 546 | QString holiStr = mHolidays[i]; |
538 | pDays.setBit(i); | 547 | pDays.setBit(i); |
539 | if ( !holiStr.isEmpty() ) | 548 | if ( !holiStr.isEmpty() ) |
540 | holiStr += "\n"; | 549 | holiStr += "\n"; |
541 | holiStr += i18n("Todo") + ": "+todo->summary(); | 550 | holiStr += i18n("Todo") + ": "+todo->summary(); |
542 | if ( !todo->location().isEmpty() ) | 551 | if ( !todo->location().isEmpty() ) |
543 | holiStr += " (" + todo->location() + ")"; | 552 | holiStr += " (" + todo->location() + ")"; |
544 | bDays.setBit(i); | 553 | bDays.setBit(i); |
545 | mHolidays[i] =holiStr ; | 554 | mHolidays[i] =holiStr ; |
546 | eDays.setBit(i); | 555 | eDays.setBit(i); |
547 | } | 556 | } |
548 | } | 557 | } |
549 | } | 558 | } |
550 | } | 559 | } |
551 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { | 560 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { |
552 | bDays.fill( false); | 561 | bDays.fill( false); |
553 | // insert due todos | 562 | // insert due todos |
554 | QPtrList<Journal> todos = mCalendar->journals( ); | 563 | Q3PtrList<Journal> todos = mCalendar->journals( ); |
555 | Journal *todo; | 564 | Journal *todo; |
556 | for(todo = todos.first(); todo; todo = todos.next()) { | 565 | for(todo = todos.first(); todo; todo = todos.next()) { |
557 | int day = mStartDate.daysTo( todo->dtStart().date() ); | 566 | int day = mStartDate.daysTo( todo->dtStart().date() ); |
558 | if ( day >= 0 && day < timeSpan + 1) { | 567 | if ( day >= 0 && day < timeSpan + 1) { |
559 | int i = day; | 568 | int i = day; |
560 | QString holiStr = mHolidays[i]; | 569 | QString holiStr = mHolidays[i]; |
561 | pDays.setBit(i); | 570 | pDays.setBit(i); |
562 | if ( !holiStr.isEmpty() ) | 571 | if ( !holiStr.isEmpty() ) |
563 | holiStr += "\n"; | 572 | holiStr += "\n"; |
564 | holiStr += i18n("Journal: ")+todo->summary().left(25); | 573 | holiStr += i18n("Journal: ")+todo->summary().left(25); |
565 | if ( todo->summary().length() > 25 ) | 574 | if ( todo->summary().length() > 25 ) |
566 | holiStr +="..."; | 575 | holiStr +="..."; |
567 | bDays.setBit(i); | 576 | bDays.setBit(i); |
568 | mHolidays[i] =holiStr ; | 577 | mHolidays[i] =holiStr ; |
569 | eDays.setBit(i); | 578 | eDays.setBit(i); |
570 | 579 | ||
571 | } | 580 | } |
572 | } | 581 | } |
573 | } | 582 | } |
574 | #else | 583 | #else |
575 | //qDebug("KODayMatrix::updateViewTimed "); | 584 | //qDebug("KODayMatrix::updateViewTimed "); |
576 | for(int i = 0; i < NUMDAYS; i++) { | 585 | for(int i = 0; i < NUMDAYS; i++) { |
577 | // if events are set for the day then remember to draw it bold | 586 | // if events are set for the day then remember to draw it bold |
578 | QPtrList<Event> eventlist = mCalendar->events(days[i]); | 587 | Q3PtrList<Event> eventlist = mCalendar->events(days[i]); |
579 | Event *event; | 588 | Event *event; |
580 | int numEvents = eventlist.count(); | 589 | int numEvents = eventlist.count(); |
581 | QString holiStr = ""; | 590 | QString holiStr = ""; |
582 | bDays.clearBit(i); | 591 | bDays.clearBit(i); |
583 | hDays.clearBit(i); | 592 | hDays.clearBit(i); |
584 | eDays.clearBit(i); | 593 | eDays.clearBit(i); |
585 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 594 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
586 | ushort recurType = event->recurrence()->doesRecur(); | 595 | ushort recurType = event->recurrence()->doesRecur(); |
587 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 596 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
588 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 597 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
589 | numEvents--; | 598 | numEvents--; |
590 | } | 599 | } |
591 | if ( event->isHoliday()) { | 600 | if ( event->isHoliday()) { |
592 | hDays.setBit(i); | 601 | hDays.setBit(i); |
593 | if ( !holiStr.isEmpty() ) | 602 | if ( !holiStr.isEmpty() ) |
594 | holiStr += "\n"; | 603 | holiStr += "\n"; |
595 | holiStr += event->summary(); | 604 | holiStr += event->summary(); |
596 | if ( !event->location().isEmpty() ) | 605 | if ( !event->location().isEmpty() ) |
597 | holiStr += " (" + event->location() + ")"; | 606 | holiStr += " (" + event->location() + ")"; |
598 | } | 607 | } |
599 | if ( event->isBirthday()) { | 608 | if ( event->isBirthday()) { |
600 | if ( !holiStr.isEmpty() ) | 609 | if ( !holiStr.isEmpty() ) |
601 | holiStr += "\n"; | 610 | holiStr += "\n"; |
602 | holiStr += i18n("Birthday") + ": "+event->summary(); | 611 | holiStr += i18n("Birthday") + ": "+event->summary(); |
603 | if ( !event->location().isEmpty() ) | 612 | if ( !event->location().isEmpty() ) |
604 | holiStr += " (" + event->location() + ")"; | 613 | holiStr += " (" + event->location() + ")"; |
605 | bDays.setBit(i); | 614 | bDays.setBit(i); |
606 | } | 615 | } |
607 | } | 616 | } |
608 | if ( numEvents ) | 617 | if ( numEvents ) |
609 | eDays.setBit(i); | 618 | eDays.setBit(i); |
610 | //if it is a holy day then draw it red. Sundays are consider holidays, too | 619 | //if it is a holy day then draw it red. Sundays are consider holidays, too |
611 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || | 620 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || |
612 | !holiStr.isEmpty()) { | 621 | !holiStr.isEmpty()) { |
613 | mHolidays[i] = holiStr; | 622 | mHolidays[i] = holiStr; |
614 | } else { | 623 | } else { |
615 | mHolidays[i] = QString::null; | 624 | mHolidays[i] = QString::null; |
616 | } | 625 | } |
617 | } | 626 | } |
618 | #endif | 627 | #endif |
619 | mRedrawNeeded = true; | 628 | mRedrawNeeded = true; |
620 | if ( ! mPendingUpdateBeforeRepaint ) | 629 | if ( ! mPendingUpdateBeforeRepaint ) |
621 | repaint(false); | 630 | repaint(false); |
622 | } | 631 | } |
623 | void KODayMatrix::updateView(QDate actdate) | 632 | void KODayMatrix::updateView(QDate actdate) |
624 | { | 633 | { |
625 | if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) | 634 | if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) |
626 | mRedrawNeeded = true; | 635 | mRedrawNeeded = true; |
@@ -630,174 +639,174 @@ void KODayMatrix::updateView(QDate actdate) | |||
630 | return; | 639 | return; |
631 | } | 640 | } |
632 | mDayChanged = false; | 641 | mDayChanged = false; |
633 | //flag to indicate if the starting day of the matrix has changed by this call | 642 | //flag to indicate if the starting day of the matrix has changed by this call |
634 | //mDayChanged = false; | 643 | //mDayChanged = false; |
635 | // if a new startdate is to be set then apply Cornelius's calculation | 644 | // if a new startdate is to be set then apply Cornelius's calculation |
636 | // of the first day to be shown | 645 | // of the first day to be shown |
637 | if (actdate != startdate) { | 646 | if (actdate != startdate) { |
638 | // reset index of selection according to shift of starting date from startdate to actdate | 647 | // reset index of selection according to shift of starting date from startdate to actdate |
639 | if (mSelStart != NOSELECTION) { | 648 | if (mSelStart != NOSELECTION) { |
640 | int tmp = actdate.daysTo(startdate); | 649 | int tmp = actdate.daysTo(startdate); |
641 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; | 650 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; |
642 | // shift selection if new one would be visible at least partly ! | 651 | // shift selection if new one would be visible at least partly ! |
643 | 652 | ||
644 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { | 653 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { |
645 | // nested if is required for next X display pushed from a different month - correction required | 654 | // nested if is required for next X display pushed from a different month - correction required |
646 | // otherwise, for month forward and backward, it must be avoided | 655 | // otherwise, for month forward and backward, it must be avoided |
647 | if( mSelStart > NUMDAYS || mSelStart < 0 ) | 656 | if( mSelStart > NUMDAYS || mSelStart < 0 ) |
648 | mSelStart = mSelStart + tmp; | 657 | mSelStart = mSelStart + tmp; |
649 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) | 658 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) |
650 | mSelEnd = mSelEnd + tmp; | 659 | mSelEnd = mSelEnd + tmp; |
651 | } | 660 | } |
652 | } | 661 | } |
653 | startdate = actdate; | 662 | startdate = actdate; |
654 | mDayChanged = true; | 663 | mDayChanged = true; |
655 | recalculateToday(); | 664 | recalculateToday(); |
656 | mRedrawNeeded = true; | 665 | mRedrawNeeded = true; |
657 | } | 666 | } |
658 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); | 667 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); |
659 | if ( !isVisible() ) { | 668 | if ( !isVisible() ) { |
660 | mPendingUpdateBeforeRepaint = true; | 669 | mPendingUpdateBeforeRepaint = true; |
661 | } else { | 670 | } else { |
662 | #ifdef DESKTOP_VERSION | 671 | #ifdef DESKTOP_VERSION |
663 | //mRepaintTimer->start( 100 ); | 672 | //mRepaintTimer->start( 100 ); |
664 | //updateViewTimed(); | 673 | //updateViewTimed(); |
665 | mUpdateTimer->start( 50 ); | 674 | mUpdateTimer->start( 50 ); |
666 | #else | 675 | #else |
667 | mRepaintTimer->start( 250 ); | 676 | mRepaintTimer->start( 250 ); |
668 | mUpdateTimer->start( 500 ); | 677 | mUpdateTimer->start( 500 ); |
669 | #endif | 678 | #endif |
670 | } | 679 | } |
671 | } | 680 | } |
672 | void KODayMatrix::updateEvents() | 681 | void KODayMatrix::updateEvents() |
673 | { | 682 | { |
674 | if ( !mCalendar ) return; | 683 | if ( !mCalendar ) return; |
675 | 684 | ||
676 | for( int i = 0; i < NUMDAYS; i++ ) { | 685 | for( int i = 0; i < NUMDAYS; i++ ) { |
677 | // if events are set for the day then remember to draw it bold | 686 | // if events are set for the day then remember to draw it bold |
678 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); | 687 | Q3PtrList<Event> eventlist = mCalendar->events( days[ i ] ); |
679 | int numEvents = eventlist.count(); | 688 | int numEvents = eventlist.count(); |
680 | Event *event; | 689 | Event *event; |
681 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { | 690 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { |
682 | ushort recurType = event->doesRecur(); | 691 | ushort recurType = event->doesRecur(); |
683 | 692 | ||
684 | if ( ( recurType == Recurrence::rDaily && | 693 | if ( ( recurType == Recurrence::rDaily && |
685 | !KOPrefs::instance()->mDailyRecur ) || | 694 | !KOPrefs::instance()->mDailyRecur ) || |
686 | ( recurType == Recurrence::rWeekly && | 695 | ( recurType == Recurrence::rWeekly && |
687 | !KOPrefs::instance()->mWeeklyRecur ) ) { | 696 | !KOPrefs::instance()->mWeeklyRecur ) ) { |
688 | numEvents--; | 697 | numEvents--; |
689 | } | 698 | } |
690 | if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) { | 699 | if ( !KOPrefs::instance()->mLongAllday && event->doesFloat()&& event->isMultiDay() ) { |
691 | numEvents--; | 700 | numEvents--; |
692 | } | 701 | } |
693 | } | 702 | } |
694 | if ( numEvents ) | 703 | if ( numEvents ) |
695 | eDays.setBit(i); | 704 | eDays.setBit(i); |
696 | else | 705 | else |
697 | eDays.clearBit(i); | 706 | eDays.clearBit(i); |
698 | } | 707 | } |
699 | } | 708 | } |
700 | 709 | ||
701 | const QDate& KODayMatrix::getDate(int offset) | 710 | const QDate& KODayMatrix::getDate(int offset) |
702 | { | 711 | { |
703 | if (offset < 0 || offset > NUMDAYS-1) { | 712 | if (offset < 0 || offset > NUMDAYS-1) { |
704 | qDebug("Wrong offset2 %d", offset); | 713 | qDebug("Wrong offset2 %d", offset); |
705 | return days[0]; | 714 | return days[0]; |
706 | } | 715 | } |
707 | return days[offset]; | 716 | return days[offset]; |
708 | } | 717 | } |
709 | 718 | ||
710 | QString KODayMatrix::getHolidayLabel(int offset) | 719 | QString KODayMatrix::getHolidayLabel(int offset) |
711 | { | 720 | { |
712 | if (offset < 0 || offset > NUMDAYS-1) { | 721 | if (offset < 0 || offset > NUMDAYS-1) { |
713 | qDebug("Wrong offset1 %d", offset); | 722 | qDebug("Wrong offset1 %d", offset); |
714 | return QString(); | 723 | return QString(); |
715 | } | 724 | } |
716 | return mHolidays[offset]; | 725 | return mHolidays[offset]; |
717 | } | 726 | } |
718 | 727 | ||
719 | int KODayMatrix::getDayIndexFrom(int x, int y) | 728 | int KODayMatrix::getDayIndexFrom(int x, int y) |
720 | { | 729 | { |
721 | int colModulo = (width()-2) % 7; | 730 | int colModulo = (width()-2) % 7; |
722 | int rowModulo = (height()-2) % 6; | 731 | int rowModulo = (height()-2) % 6; |
723 | #if 0 | 732 | #if 0 |
724 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? | 733 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? |
725 | 6 - x/daysize.width() : x/daysize.width()); | 734 | 6 - x/daysize.width() : x/daysize.width()); |
726 | #endif | 735 | #endif |
727 | int xVal = (x-colModulo/2-2)/daysize.width(); | 736 | int xVal = (x-colModulo/2-2)/daysize.width(); |
728 | int yVal = (y-rowModulo/2-2)/daysize.height(); | 737 | int yVal = (y-rowModulo/2-2)/daysize.height(); |
729 | 738 | ||
730 | 739 | ||
731 | return 7*(yVal) + xVal; | 740 | return 7*(yVal) + xVal; |
732 | 741 | ||
733 | } | 742 | } |
734 | 743 | ||
735 | // ---------------------------------------------------------------------------- | 744 | // ---------------------------------------------------------------------------- |
736 | // M O U S E E V E N T H A N D L I N G | 745 | // M O U S E E V E N T H A N D L I N G |
737 | // ---------------------------------------------------------------------------- | 746 | // ---------------------------------------------------------------------------- |
738 | 747 | ||
739 | void KODayMatrix::mousePressEvent (QMouseEvent* e) | 748 | void KODayMatrix::mousePressEvent (QMouseEvent* e) |
740 | { | 749 | { |
741 | 750 | ||
742 | if ( e->button() == LeftButton ) | 751 | if ( e->button() == Qt::LeftButton ) |
743 | mouseDown = true; | 752 | mouseDown = true; |
744 | mSelStart = getDayIndexFrom(e->x(), e->y()); | 753 | mSelStart = getDayIndexFrom(e->x(), e->y()); |
745 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; | 754 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; |
746 | mSelInit = mSelStart; | 755 | mSelInit = mSelStart; |
747 | mSelEnd = mSelStart; | 756 | mSelEnd = mSelStart; |
748 | mRedrawNeeded = true; | 757 | mRedrawNeeded = true; |
749 | repaint(false); | 758 | repaint(false); |
750 | } | 759 | } |
751 | 760 | ||
752 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) | 761 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) |
753 | { | 762 | { |
754 | mRedrawNeeded = true; | 763 | mRedrawNeeded = true; |
755 | if ( e->button() == LeftButton ) | 764 | if ( e->button() == Qt::LeftButton ) |
756 | if ( ! mouseDown ) { | 765 | if ( ! mouseDown ) { |
757 | return; | 766 | return; |
758 | } | 767 | } |
759 | else | 768 | else |
760 | mouseDown = false; | 769 | mouseDown = false; |
761 | int tmp = getDayIndexFrom(e->x(), e->y()); | 770 | int tmp = getDayIndexFrom(e->x(), e->y()); |
762 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 771 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
763 | 772 | ||
764 | if (mSelInit > tmp) { | 773 | if (mSelInit > tmp) { |
765 | mSelEnd = mSelInit; | 774 | mSelEnd = mSelInit; |
766 | if (tmp != mSelStart) { | 775 | if (tmp != mSelStart) { |
767 | mSelStart = tmp; | 776 | mSelStart = tmp; |
768 | repaint(false); | 777 | repaint(false); |
769 | } | 778 | } |
770 | } else { | 779 | } else { |
771 | mSelStart = mSelInit; | 780 | mSelStart = mSelInit; |
772 | 781 | ||
773 | //repaint only if selection has changed | 782 | //repaint only if selection has changed |
774 | if (tmp != mSelEnd) { | 783 | if (tmp != mSelEnd) { |
775 | mSelEnd = tmp; | 784 | mSelEnd = tmp; |
776 | repaint(false); | 785 | repaint(false); |
777 | } | 786 | } |
778 | } | 787 | } |
779 | 788 | ||
780 | DateList daylist; | 789 | DateList daylist; |
781 | if ( mSelStart < 0 ) | 790 | if ( mSelStart < 0 ) |
782 | mSelStart = 0; | 791 | mSelStart = 0; |
783 | for (int i = mSelStart; i <= mSelEnd; i++) { | 792 | for (int i = mSelStart; i <= mSelEnd; i++) { |
784 | daylist.append(days[i]); | 793 | daylist.append(days[i]); |
785 | } | 794 | } |
786 | emit selected((const DateList)daylist); | 795 | emit selected((const DateList)daylist); |
787 | 796 | ||
788 | } | 797 | } |
789 | 798 | ||
790 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) | 799 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) |
791 | { | 800 | { |
792 | if ( ! mouseDown ) { | 801 | if ( ! mouseDown ) { |
793 | return; | 802 | return; |
794 | } | 803 | } |
795 | mRedrawNeeded = true; | 804 | mRedrawNeeded = true; |
796 | int tmp = getDayIndexFrom(e->x(), e->y()); | 805 | int tmp = getDayIndexFrom(e->x(), e->y()); |
797 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 806 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
798 | 807 | ||
799 | if (mSelInit > tmp) { | 808 | if (mSelInit > tmp) { |
800 | mSelEnd = mSelInit; | 809 | mSelEnd = mSelInit; |
801 | if (tmp != mSelStart) { | 810 | if (tmp != mSelStart) { |
802 | mSelStart = tmp; | 811 | mSelStart = tmp; |
803 | repaint(false); | 812 | repaint(false); |
@@ -1150,74 +1159,74 @@ void KODayMatrix::paintEvent(QPaintEvent * pevent) | |||
1150 | if (actcol == mDefaultTextColor ) { | 1159 | if (actcol == mDefaultTextColor ) { |
1151 | p.setPen(KOPrefs::instance()->mHolidayColor); | 1160 | p.setPen(KOPrefs::instance()->mHolidayColor); |
1152 | } else { | 1161 | } else { |
1153 | p.setPen(mHolidayColorShaded); | 1162 | p.setPen(mHolidayColorShaded); |
1154 | } | 1163 | } |
1155 | } | 1164 | } |
1156 | } | 1165 | } |
1157 | 1166 | ||
1158 | // draw selected days with special color | 1167 | // draw selected days with special color |
1159 | // DO NOT specially highlight holidays in selection ! | 1168 | // DO NOT specially highlight holidays in selection ! |
1160 | if (i >= mSelStartT && i <= mSelEndT) { | 1169 | if (i >= mSelStartT && i <= mSelEndT) { |
1161 | ;//p.setPen(mSelectedDaysColor); | 1170 | ;//p.setPen(mSelectedDaysColor); |
1162 | } | 1171 | } |
1163 | 1172 | ||
1164 | int addCol = 0; | 1173 | int addCol = 0; |
1165 | int addRow = 0; | 1174 | int addRow = 0; |
1166 | if ( colModulo ) { | 1175 | if ( colModulo ) { |
1167 | if ( col >= 7 - colModulo ) | 1176 | if ( col >= 7 - colModulo ) |
1168 | addCol = col - 7 + colModulo; | 1177 | addCol = col - 7 + colModulo; |
1169 | } | 1178 | } |
1170 | if ( rowModulo ) { | 1179 | if ( rowModulo ) { |
1171 | if ( row >= 6 - rowModulo ) | 1180 | if ( row >= 6 - rowModulo ) |
1172 | addRow = row - 5 + rowModulo; | 1181 | addRow = row - 5 + rowModulo; |
1173 | } | 1182 | } |
1174 | //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); | 1183 | //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); |
1175 | ++addCol;//++addCol; | 1184 | ++addCol;//++addCol; |
1176 | if ( row == 0) | 1185 | if ( row == 0) |
1177 | addRow = 1; | 1186 | addRow = 1; |
1178 | p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, | 1187 | p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, |
1179 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); | 1188 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); |
1180 | 1189 | ||
1181 | // reset color to actual color | 1190 | // reset color to actual color |
1182 | if (pDays.testBit(i)) { | 1191 | if (pDays.testBit(i)) { |
1183 | p.setPen(actcol); | 1192 | p.setPen(actcol); |
1184 | } | 1193 | } |
1185 | // reset bold font to plain font | 1194 | // reset bold font to plain font |
1186 | if ( eDays.testBit(i)) { | 1195 | if ( eDays.testBit(i)) { |
1187 | QFont myFont = font(); | 1196 | QFont myFont = font(); |
1188 | myFont.setBold(false); | 1197 | myFont.setBold(false); |
1189 | p.setFont(myFont); | 1198 | p.setFont(myFont); |
1190 | } | 1199 | } |
1191 | } | 1200 | } |
1192 | p.setPen(mDefaultTextColor); | 1201 | p.setPen(mDefaultTextColor); |
1193 | p.drawRect(0, 0, width(), height()); | 1202 | p.drawRect(0, 0, width(), height()); |
1194 | } else { | 1203 | } else { |
1195 | //qDebug("NO redraw "); | 1204 | //qDebug("NO redraw "); |
1196 | } | 1205 | } |
1197 | 1206 | ||
1198 | bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,CopyROP); | 1207 | bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,QPainter::CompositionMode_Source); |
1199 | mRedrawNeeded = false; | 1208 | mRedrawNeeded = false; |
1200 | } | 1209 | } |
1201 | 1210 | ||
1202 | // ---------------------------------------------------------------------------- | 1211 | // ---------------------------------------------------------------------------- |
1203 | // R E SI Z E E V E N T H A N D L I N G | 1212 | // R E SI Z E E V E N T H A N D L I N G |
1204 | // ---------------------------------------------------------------------------- | 1213 | // ---------------------------------------------------------------------------- |
1205 | 1214 | ||
1206 | void KODayMatrix::resizeEvent(QResizeEvent * e) | 1215 | void KODayMatrix::resizeEvent(QResizeEvent * e) |
1207 | { | 1216 | { |
1208 | QRect sz = frameRect(); | 1217 | QRect sz = frameRect(); |
1209 | daysize.setHeight(sz.height()*7 / NUMDAYS); | 1218 | daysize.setHeight(sz.height()*7 / NUMDAYS); |
1210 | daysize.setWidth(sz.width() / 7); | 1219 | daysize.setWidth(sz.width() / 7); |
1211 | QFrame::resizeEvent( e ); | 1220 | Q3Frame::resizeEvent( e ); |
1212 | } | 1221 | } |
1213 | 1222 | ||
1214 | QSize KODayMatrix::sizeHint() const | 1223 | QSize KODayMatrix::sizeHint() const |
1215 | { | 1224 | { |
1216 | 1225 | ||
1217 | QFontMetrics fm ( font() ); | 1226 | QFontMetrics fm ( font() ); |
1218 | int wid = fm.width( "30") *7+3; | 1227 | int wid = fm.width( "30") *7+3; |
1219 | int hei = fm.height() * 6+3; | 1228 | int hei = fm.height() * 6+3; |
1220 | //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); | 1229 | //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); |
1221 | return QSize ( wid, hei ); | 1230 | return QSize ( wid, hei ); |
1222 | 1231 | ||
1223 | } | 1232 | } |