-rw-r--r-- | korganizer/komonthview.cpp | 3 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 1 |
2 files changed, 2 insertions, 2 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index 425496a..6d6ae8a 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp | |||
@@ -1,1435 +1,1434 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
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 | 19 | ||
20 | #include <qpopupmenu.h> | 20 | #include <qpopupmenu.h> |
21 | #include <qfont.h> | 21 | #include <qfont.h> |
22 | #include <qfontmetrics.h> | 22 | #include <qfontmetrics.h> |
23 | #include <qkeycode.h> | 23 | #include <qkeycode.h> |
24 | #include <qhbox.h> | 24 | #include <qhbox.h> |
25 | #include <qvbox.h> | 25 | #include <qvbox.h> |
26 | #include <qwidgetstack.h> | 26 | #include <qwidgetstack.h> |
27 | #include <qpushbutton.h> | 27 | #include <qpushbutton.h> |
28 | #include <qtooltip.h> | 28 | #include <qtooltip.h> |
29 | #include <qpainter.h> | 29 | #include <qpainter.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | #include <qwhatsthis.h> | 31 | #include <qwhatsthis.h> |
32 | #ifndef DESKTOP_VERSION | 32 | #ifndef DESKTOP_VERSION |
33 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
34 | #else | 34 | #else |
35 | #include <qapplication.h> | 35 | #include <qapplication.h> |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #include <kdebug.h> | 38 | #include <kdebug.h> |
39 | #include <klocale.h> | 39 | #include <klocale.h> |
40 | #include <kglobal.h> | 40 | #include <kglobal.h> |
41 | #include <kconfig.h> | 41 | #include <kconfig.h> |
42 | #include <kiconloader.h> | 42 | #include <kiconloader.h> |
43 | 43 | ||
44 | #include <kcalendarsystem.h> | 44 | #include <kcalendarsystem.h> |
45 | 45 | ||
46 | #ifndef KORG_NOPRINTER | 46 | #ifndef KORG_NOPRINTER |
47 | #include "calprinter.h" | 47 | #include "calprinter.h" |
48 | #endif | 48 | #endif |
49 | #include "koprefs.h" | 49 | #include "koprefs.h" |
50 | #ifndef KORG_NOPLUGINS | 50 | #ifndef KORG_NOPLUGINS |
51 | #include "kocore.h" | 51 | #include "kocore.h" |
52 | #endif | 52 | #endif |
53 | #include "koglobals.h" | 53 | #include "koglobals.h" |
54 | #include <libkcal/kincidenceformatter.h> | 54 | #include <libkcal/kincidenceformatter.h> |
55 | 55 | ||
56 | #include "komonthview.h" | 56 | #include "komonthview.h" |
57 | 57 | ||
58 | #define PIXMAP_SIZE 5 | 58 | #define PIXMAP_SIZE 5 |
59 | #ifdef DESKTOP_VERSION | 59 | #ifdef DESKTOP_VERSION |
60 | QToolTipGroup *MonthViewCell::mToolTipGroup = 0; | 60 | QToolTipGroup *MonthViewCell::mToolTipGroup = 0; |
61 | #endif | 61 | #endif |
62 | class KNOWhatsThis :public QWhatsThis | 62 | class KNOWhatsThis :public QWhatsThis |
63 | { | 63 | { |
64 | public: | 64 | public: |
65 | KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; | 65 | KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; |
66 | //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; | 66 | //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | virtual QString text( const QPoint& p) | 69 | virtual QString text( const QPoint& p) |
70 | { | 70 | { |
71 | return _wid->getWhatsThisText(p) ; | 71 | return _wid->getWhatsThisText(p) ; |
72 | }; | 72 | }; |
73 | private: | 73 | private: |
74 | KNoScrollListBox* _wid; | 74 | KNoScrollListBox* _wid; |
75 | 75 | ||
76 | }; | 76 | }; |
77 | 77 | ||
78 | 78 | ||
79 | KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) | 79 | KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) |
80 | : QListBox(parent, name, WRepaintNoErase) | 80 | : QListBox(parent, name, WRepaintNoErase) |
81 | { | 81 | { |
82 | #ifndef DESKTOP_VERSION | 82 | #ifndef DESKTOP_VERSION |
83 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); | 83 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); |
84 | #endif | 84 | #endif |
85 | mWT = new KNOWhatsThis(this); | 85 | mWT = new KNOWhatsThis(this); |
86 | resetOnFocusIn = true; | 86 | resetOnFocusIn = true; |
87 | setVScrollBarMode(QScrollView::AlwaysOff); | 87 | setVScrollBarMode(QScrollView::AlwaysOff); |
88 | setHScrollBarMode(QScrollView::AlwaysOff); | 88 | setHScrollBarMode(QScrollView::AlwaysOff); |
89 | } | 89 | } |
90 | KNoScrollListBox::~KNoScrollListBox() | 90 | KNoScrollListBox::~KNoScrollListBox() |
91 | { | 91 | { |
92 | 92 | ||
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | void KNoScrollListBox::focusInEvent ( QFocusEvent * e ) | 96 | void KNoScrollListBox::focusInEvent ( QFocusEvent * e ) |
97 | { | 97 | { |
98 | QListBox::focusInEvent ( e ); | 98 | QListBox::focusInEvent ( e ); |
99 | QListBoxItem * i = item ( 0 ); | 99 | QListBoxItem * i = item ( 0 ); |
100 | if ( i && resetOnFocusIn ) { | 100 | if ( i && resetOnFocusIn ) { |
101 | setCurrentItem( i ); | 101 | setCurrentItem( i ); |
102 | setSelected ( 0, true ); | 102 | setSelected ( 0, true ); |
103 | } | 103 | } |
104 | resetOnFocusIn = true; | 104 | resetOnFocusIn = true; |
105 | 105 | ||
106 | if ( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) { | 106 | if ( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) { |
107 | QListBoxItem *fi = firstItem (); | 107 | QListBoxItem *fi = firstItem (); |
108 | if (fi ) { | 108 | if (fi ) { |
109 | int ihei = fi->height( this ); | 109 | int ihei = fi->height( this ); |
110 | int hei = numRows () * ihei; | 110 | int hei = numRows () * ihei; |
111 | if ( hei < height() - horizontalScrollBar()->height () ) { | 111 | if ( hei < height() - horizontalScrollBar()->height () ) { |
112 | setVScrollBarMode(QScrollView::AlwaysOff); | 112 | setVScrollBarMode(QScrollView::AlwaysOff); |
113 | } | 113 | } |
114 | else | 114 | else |
115 | setVScrollBarMode(QScrollView::Auto); | 115 | setVScrollBarMode(QScrollView::Auto); |
116 | if ( ihei *3 > height() ) { | 116 | if ( ihei *3 > height() ) { |
117 | setHScrollBarMode(QScrollView::AlwaysOff); | 117 | setHScrollBarMode(QScrollView::AlwaysOff); |
118 | } | 118 | } |
119 | else { | 119 | else { |
120 | setHScrollBarMode(QScrollView::Auto); | 120 | setHScrollBarMode(QScrollView::Auto); |
121 | } | 121 | } |
122 | } else { | 122 | } else { |
123 | setVScrollBarMode(QScrollView::Auto); | 123 | setVScrollBarMode(QScrollView::Auto); |
124 | setHScrollBarMode(QScrollView::Auto); | 124 | setHScrollBarMode(QScrollView::Auto); |
125 | } | 125 | } |
126 | } | 126 | } |
127 | } | 127 | } |
128 | void KNoScrollListBox::focusOutEvent ( QFocusEvent * e ) | 128 | void KNoScrollListBox::focusOutEvent ( QFocusEvent * e ) |
129 | { | 129 | { |
130 | int i = currentItem (); | 130 | int i = currentItem (); |
131 | if ( i >= 0 ) { | 131 | if ( i >= 0 ) { |
132 | setSelected ( i, false ); | 132 | setSelected ( i, false ); |
133 | } | 133 | } |
134 | QListBox::focusOutEvent ( e ); | 134 | QListBox::focusOutEvent ( e ); |
135 | setVScrollBarMode(QScrollView::AlwaysOff); | 135 | setVScrollBarMode(QScrollView::AlwaysOff); |
136 | setHScrollBarMode(QScrollView::AlwaysOff); | 136 | setHScrollBarMode(QScrollView::AlwaysOff); |
137 | } | 137 | } |
138 | 138 | ||
139 | QString KNoScrollListBox::getWhatsThisText(QPoint p) | 139 | QString KNoScrollListBox::getWhatsThisText(QPoint p) |
140 | { | 140 | { |
141 | QListBoxItem* item = itemAt ( p ); | 141 | QListBoxItem* item = itemAt ( p ); |
142 | if ( ! item ) { | 142 | if ( ! item ) { |
143 | return i18n("Click in the cell\nto add an event!"); | 143 | return i18n("Click in the cell\nto add an event!"); |
144 | } | 144 | } |
145 | return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(), | 145 | return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(), |
146 | KOPrefs::instance()->mWTshowDetails, | 146 | KOPrefs::instance()->mWTshowDetails, |
147 | KOPrefs::instance()->mWTshowCreated, | 147 | KOPrefs::instance()->mWTshowCreated, |
148 | KOPrefs::instance()->mWTshowChanged); | 148 | KOPrefs::instance()->mWTshowChanged); |
149 | } | 149 | } |
150 | void KNoScrollListBox::keyPressEvent(QKeyEvent *e) | 150 | void KNoScrollListBox::keyPressEvent(QKeyEvent *e) |
151 | { | 151 | { |
152 | //qDebug("KNoScrollListBox::keyPressEvent "); | 152 | //qDebug("KNoScrollListBox::keyPressEvent "); |
153 | switch(e->key()) { | 153 | switch(e->key()) { |
154 | case Key_Right: | 154 | case Key_Right: |
155 | if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) | 155 | if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) |
156 | { | 156 | { |
157 | e->ignore(); | 157 | e->ignore(); |
158 | return; | 158 | return; |
159 | } | 159 | } |
160 | scrollBy(10,0); | 160 | scrollBy(10,0); |
161 | break; | 161 | break; |
162 | case Key_Left: | 162 | case Key_Left: |
163 | if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) | 163 | if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) |
164 | { | 164 | { |
165 | e->ignore(); | 165 | e->ignore(); |
166 | return; | 166 | return; |
167 | } | 167 | } |
168 | scrollBy(-10,0); | 168 | scrollBy(-10,0); |
169 | break; | 169 | break; |
170 | case Key_Up: | 170 | case Key_Up: |
171 | if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { | 171 | if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { |
172 | e->ignore(); | 172 | e->ignore(); |
173 | break; | 173 | break; |
174 | } | 174 | } |
175 | if ( count() ) { | 175 | if ( count() ) { |
176 | setCurrentItem((currentItem()+count()-1)%count()); | 176 | setCurrentItem((currentItem()+count()-1)%count()); |
177 | if(!itemVisible(currentItem())) { | 177 | if(!itemVisible(currentItem())) { |
178 | if((unsigned int) currentItem() == (count()-1)) { | 178 | if((unsigned int) currentItem() == (count()-1)) { |
179 | setTopItem(currentItem()-numItemsVisible()+1); | 179 | setTopItem(currentItem()-numItemsVisible()+1); |
180 | } else { | 180 | } else { |
181 | setTopItem(topItem()-1); | 181 | setTopItem(topItem()-1); |
182 | } | 182 | } |
183 | } | 183 | } |
184 | } | 184 | } |
185 | break; | 185 | break; |
186 | case Key_Down: | 186 | case Key_Down: |
187 | if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { | 187 | if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { |
188 | e->ignore(); | 188 | e->ignore(); |
189 | break; | 189 | break; |
190 | } | 190 | } |
191 | if ( count () ) { | 191 | if ( count () ) { |
192 | setCurrentItem((currentItem()+1)%count()); | 192 | setCurrentItem((currentItem()+1)%count()); |
193 | if(!itemVisible(currentItem())) { | 193 | if(!itemVisible(currentItem())) { |
194 | if(currentItem() == 0) { | 194 | if(currentItem() == 0) { |
195 | setTopItem(0); | 195 | setTopItem(0); |
196 | } else { | 196 | } else { |
197 | setTopItem(topItem()+1); | 197 | setTopItem(topItem()+1); |
198 | } | 198 | } |
199 | } | 199 | } |
200 | } | 200 | } |
201 | break; | 201 | break; |
202 | case Key_I: | 202 | case Key_I: |
203 | QTimer::singleShot( 1, this, SLOT ( oneDown() ) ); | 203 | QTimer::singleShot( 1, this, SLOT ( oneDown() ) ); |
204 | e->ignore(); | 204 | e->ignore(); |
205 | break; | 205 | break; |
206 | case Key_Return: | 206 | case Key_Return: |
207 | case Key_Enter: | 207 | case Key_Enter: |
208 | { | 208 | { |
209 | if ( currentItem() >= 0 ) { | 209 | if ( currentItem() >= 0 ) { |
210 | emit doubleClicked( item( currentItem() ) ); | 210 | emit doubleClicked( item( currentItem() ) ); |
211 | e->accept(); | 211 | e->accept(); |
212 | } else { | 212 | } else { |
213 | e->ignore(); | 213 | e->ignore(); |
214 | } | 214 | } |
215 | } | 215 | } |
216 | break; | 216 | break; |
217 | case Key_Shift: | 217 | case Key_Shift: |
218 | emit shiftDown(); | 218 | emit shiftDown(); |
219 | break; | 219 | break; |
220 | default: | 220 | default: |
221 | e->ignore(); | 221 | e->ignore(); |
222 | break; | 222 | break; |
223 | } | 223 | } |
224 | } | 224 | } |
225 | 225 | ||
226 | void KNoScrollListBox::oneDown() | 226 | void KNoScrollListBox::oneDown() |
227 | { | 227 | { |
228 | if ( count () ) { | 228 | if ( count () ) { |
229 | resetOnFocusIn = false; | 229 | resetOnFocusIn = false; |
230 | setCurrentItem((currentItem()+1)%count()); | 230 | setCurrentItem((currentItem()+1)%count()); |
231 | if(!itemVisible(currentItem())) { | 231 | if(!itemVisible(currentItem())) { |
232 | if(currentItem() == 0) { | 232 | if(currentItem() == 0) { |
233 | setTopItem(0); | 233 | setTopItem(0); |
234 | } else { | 234 | } else { |
235 | setTopItem(topItem()+1); | 235 | setTopItem(topItem()+1); |
236 | } | 236 | } |
237 | } | 237 | } |
238 | } | 238 | } |
239 | } | 239 | } |
240 | void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) | 240 | void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) |
241 | { | 241 | { |
242 | switch(e->key()) { | 242 | switch(e->key()) { |
243 | case Key_Shift: | 243 | case Key_Shift: |
244 | emit shiftUp(); | 244 | emit shiftUp(); |
245 | break; | 245 | break; |
246 | default: | 246 | default: |
247 | break; | 247 | break; |
248 | } | 248 | } |
249 | } | 249 | } |
250 | 250 | ||
251 | void KNoScrollListBox::mousePressEvent(QMouseEvent *e) | 251 | void KNoScrollListBox::mousePressEvent(QMouseEvent *e) |
252 | { | 252 | { |
253 | QListBox::mousePressEvent(e); | 253 | QListBox::mousePressEvent(e); |
254 | 254 | ||
255 | if(e->button() == RightButton) { | 255 | if(e->button() == RightButton) { |
256 | emit rightClick(); | 256 | emit rightClick(); |
257 | } | 257 | } |
258 | } | 258 | } |
259 | 259 | ||
260 | MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) | 260 | MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) |
261 | : QListBoxItem() | 261 | : QListBoxItem() |
262 | { | 262 | { |
263 | mblockRepaint = true; | 263 | mblockRepaint = true; |
264 | setText( s ); | 264 | setText( s ); |
265 | mMultiday = 0; | 265 | mMultiday = 0; |
266 | mIncidence = incidence; | 266 | mIncidence = incidence; |
267 | mDate = qd; | 267 | mDate = qd; |
268 | mRecur = false; | 268 | mRecur = false; |
269 | mAlarm = false; | 269 | mAlarm = false; |
270 | mReply = false; | 270 | mReply = false; |
271 | mInfo = false; | 271 | mInfo = false; |
272 | mdayPos = 0; | 272 | mdayPos = 0; |
273 | isWeekItem = KOPrefs::instance()->mMonthViewWeek; | 273 | isWeekItem = KOPrefs::instance()->mMonthViewWeek; |
274 | //qDebug("NEWWWWWWWWWWWWW "); | 274 | //qDebug("NEWWWWWWWWWWWWW "); |
275 | } | 275 | } |
276 | void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s) | 276 | void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s) |
277 | { | 277 | { |
278 | setText( s ); | 278 | setText( s ); |
279 | mMultiday = 0; | 279 | mMultiday = 0; |
280 | mIncidence = incidence; | 280 | mIncidence = incidence; |
281 | mDate = qd; | 281 | mDate = qd; |
282 | mRecur = false; | 282 | mRecur = false; |
283 | mAlarm = false; | 283 | mAlarm = false; |
284 | mReply = false; | 284 | mReply = false; |
285 | mInfo = false; | 285 | mInfo = false; |
286 | mdayPos = 0; | 286 | mdayPos = 0; |
287 | //qDebug("recucleeeeeeeeeeeeeeeee "); | 287 | //qDebug("recucleeeeeeeeeeeeeeeee "); |
288 | } | 288 | } |
289 | 289 | ||
290 | void MonthViewItem::paint(QPainter *p) | 290 | void MonthViewItem::paint(QPainter *p) |
291 | { | 291 | { |
292 | if ( mblockRepaint ) { | 292 | if ( mblockRepaint ) { |
293 | //qDebug("block "); | 293 | //qDebug("block "); |
294 | return; | 294 | return; |
295 | } | 295 | } |
296 | //qDebug("NON block "); | 296 | //qDebug("NON block "); |
297 | #if QT_VERSION >= 0x030000 | 297 | #if QT_VERSION >= 0x030000 |
298 | bool sel = isSelected(); | 298 | bool sel = isSelected(); |
299 | #else | 299 | #else |
300 | bool sel = selected(); | 300 | bool sel = selected(); |
301 | #endif | 301 | #endif |
302 | 302 | ||
303 | 303 | ||
304 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) | 304 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) |
305 | { | 305 | { |
306 | p->setBackgroundColor( palette().color( QPalette::Normal, \ | 306 | p->setBackgroundColor( palette().color( QPalette::Normal, \ |
307 | sel ? QColorGroup::Highlight : QColorGroup::Background ) ); | 307 | sel ? QColorGroup::Highlight : QColorGroup::Background ) ); |
308 | p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); | 308 | p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); |
309 | } | 309 | } |
310 | int x = 1; | 310 | int x = 1; |
311 | //int y = 3;//(height() - mRecurPixmap.height()) /2; | 311 | //int y = 3;//(height() - mRecurPixmap.height()) /2; |
312 | int size = PIXMAP_SIZE; | 312 | int size = PIXMAP_SIZE; |
313 | if ( QApplication::desktop()->width() < 300 ) | 313 | if ( QApplication::desktop()->width() < 300 ) |
314 | size = 3; | 314 | size = 3; |
315 | int heihei = height( listBox () ); | 315 | int heihei = height( listBox () ); |
316 | int y = (heihei - size -1 ) /2; | 316 | int y = (heihei - size -1 ) /2; |
317 | 317 | ||
318 | if ( KOPrefs::instance()->mMonthShowIcons ) { | 318 | if ( KOPrefs::instance()->mMonthShowIcons ) { |
319 | if ( mInfo ) { | 319 | if ( mInfo ) { |
320 | p->fillRect ( x, y,size,size, Qt::darkGreen ); | 320 | p->fillRect ( x, y,size,size, Qt::darkGreen ); |
321 | x += size + 1; | 321 | x += size + 1; |
322 | } | 322 | } |
323 | if ( mRecur ) { | 323 | if ( mRecur ) { |
324 | p->fillRect ( x, y,size,size, Qt::blue ); | 324 | p->fillRect ( x, y,size,size, Qt::blue ); |
325 | x += size + 1; | 325 | x += size + 1; |
326 | } | 326 | } |
327 | if ( mAlarm ) { | 327 | if ( mAlarm ) { |
328 | p->fillRect ( x, y,size,size, Qt::red ); | 328 | p->fillRect ( x, y,size,size, Qt::red ); |
329 | x += size + 1; | 329 | x += size + 1; |
330 | } | 330 | } |
331 | if ( mReply ) { | 331 | if ( mReply ) { |
332 | p->fillRect ( x, y,size,size, Qt::yellow ); | 332 | p->fillRect ( x, y,size,size, Qt::yellow ); |
333 | x += size + 1; | 333 | x += size + 1; |
334 | } | 334 | } |
335 | } | 335 | } |
336 | if ( mMultiday ) { | 336 | if ( mMultiday ) { |
337 | int yyy = y+(size/2); | 337 | int yyy = y+(size/2); |
338 | int sizeM = size+2; | 338 | int sizeM = size+2; |
339 | p->setBrush( QBrush::SolidPattern ); | 339 | p->setBrush( QBrush::SolidPattern ); |
340 | p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ; | 340 | p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ; |
341 | if ( mMultiday == 2 || mMultiday == 3 ) { | 341 | if ( mMultiday == 2 || mMultiday == 3 ) { |
342 | QPointArray pa ( 3 ); | 342 | QPointArray pa ( 3 ); |
343 | pa.setPoint (0, x, yyy ); | 343 | pa.setPoint (0, x, yyy ); |
344 | pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 ); | 344 | pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 ); |
345 | pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 ); | 345 | pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 ); |
346 | p->drawPolygon( pa ); | 346 | p->drawPolygon( pa ); |
347 | } | 347 | } |
348 | if ( mMultiday == 2 || mMultiday == 1 ) { | 348 | if ( mMultiday == 2 || mMultiday == 1 ) { |
349 | QPointArray pa ( 3 ); | 349 | QPointArray pa ( 3 ); |
350 | pa.setPoint (0, x+sizeM +sizeM/2, yyy ); | 350 | pa.setPoint (0, x+sizeM +sizeM/2, yyy ); |
351 | pa.setPoint (1, x+sizeM, yyy+sizeM/2 ); | 351 | pa.setPoint (1, x+sizeM, yyy+sizeM/2 ); |
352 | pa.setPoint (2, x+sizeM, yyy-sizeM/2 ); | 352 | pa.setPoint (2, x+sizeM, yyy-sizeM/2 ); |
353 | p->drawPolygon( pa ); | 353 | p->drawPolygon( pa ); |
354 | } | 354 | } |
355 | if ( mMultiday == 1 ) { | 355 | if ( mMultiday == 1 ) { |
356 | // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); | 356 | // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); |
357 | 357 | ||
358 | p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 ); | 358 | p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 ); |
359 | } | 359 | } |
360 | if ( mMultiday == 3 ) { | 360 | if ( mMultiday == 3 ) { |
361 | // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); | 361 | // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); |
362 | p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 ); | 362 | p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 ); |
363 | 363 | ||
364 | } | 364 | } |
365 | x += sizeM/2 + 1; | 365 | x += sizeM/2 + 1; |
366 | x += sizeM + 1; | 366 | x += sizeM + 1; |
367 | } | 367 | } |
368 | 368 | ||
369 | if ( mIncidence->type() == "Todo" ){ | 369 | if ( mIncidence->type() == "Todo" ){ |
370 | Todo* td = ( Todo* ) mIncidence; | 370 | Todo* td = ( Todo* ) mIncidence; |
371 | if ( td->isCompleted() ) { | 371 | if ( td->isCompleted() ) { |
372 | int half = size/2; | 372 | int half = size/2; |
373 | p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ; | 373 | p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ; |
374 | p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ; | 374 | p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ; |
375 | x += half+half + 4; | 375 | x += half+half + 4; |
376 | 376 | ||
377 | } else { | 377 | } else { |
378 | int val = td->percentComplete()/20; | 378 | int val = td->percentComplete()/20; |
379 | p->fillRect ( x+1, y-2, val ,size+4,Qt::black ); | 379 | p->fillRect ( x+1, y-2, val ,size+4,Qt::black ); |
380 | p->drawRect ( x, y-2,7,size+4); | 380 | p->drawRect ( x, y-2,7,size+4); |
381 | x += size + 3; | 381 | x += size + 3; |
382 | } | 382 | } |
383 | } | 383 | } |
384 | QFontMetrics fm = p->fontMetrics(); | 384 | QFontMetrics fm = p->fontMetrics(); |
385 | int yPos; | 385 | int yPos; |
386 | int pmheight = size; | 386 | int pmheight = size; |
387 | if( pmheight < fm.height() ) | 387 | if( pmheight < fm.height() ) |
388 | yPos = fm.ascent() + fm.leading()/2; | 388 | yPos = fm.ascent() + fm.leading()/2; |
389 | else | 389 | else |
390 | yPos = pmheight/2 - fm.height()/2 + fm.ascent(); | 390 | yPos = pmheight/2 - fm.height()/2 + fm.ascent(); |
391 | p->setPen( palette().color( QPalette::Normal, sel ? \ | 391 | p->setPen( palette().color( QPalette::Normal, sel ? \ |
392 | QColorGroup::HighlightedText : QColorGroup::Foreground ) ); | 392 | QColorGroup::HighlightedText : QColorGroup::Foreground ) ); |
393 | p->drawText( x, yPos, text() ); | 393 | p->drawText( x, yPos, text() ); |
394 | if ( mIncidence->cancelled() ) { | 394 | if ( mIncidence->cancelled() ) { |
395 | int wid = fm.width( text() ); | 395 | int wid = fm.width( text() ); |
396 | p->drawLine( x, heihei/2-1 ,x+wid, heihei/2-1 ); | 396 | p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); |
397 | } | 397 | } |
398 | 398 | ||
399 | } | 399 | } |
400 | 400 | ||
401 | int MonthViewItem::height(const QListBox *lb) const | 401 | int MonthViewItem::height(const QListBox *lb) const |
402 | { | 402 | { |
403 | int ret = 10; | 403 | int ret = 10; |
404 | if ( lb ) | 404 | if ( lb ) |
405 | ret = lb->fontMetrics().lineSpacing()+1; | 405 | ret = lb->fontMetrics().lineSpacing()+1; |
406 | return ret; | 406 | return ret; |
407 | } | 407 | } |
408 | 408 | ||
409 | int MonthViewItem::width(const QListBox *lb) const | 409 | int MonthViewItem::width(const QListBox *lb) const |
410 | { | 410 | { |
411 | |||
412 | if( KOPrefs::instance()->mEnableMonthScroll || isWeekItem ) { | 411 | if( KOPrefs::instance()->mEnableMonthScroll || isWeekItem ) { |
413 | int size = PIXMAP_SIZE; | 412 | int size = PIXMAP_SIZE; |
414 | if ( QApplication::desktop()->width() < 300 ) | 413 | if ( QApplication::desktop()->width() < 300 ) |
415 | size = 3; | 414 | size = 3; |
416 | int x = 1; | 415 | int x = 1; |
417 | if ( KOPrefs::instance()->mMonthShowIcons ) { | 416 | if ( KOPrefs::instance()->mMonthShowIcons ) { |
418 | if ( mInfo ) { | 417 | if ( mInfo ) { |
419 | x += size + 1; | 418 | x += size + 1; |
420 | } | 419 | } |
421 | if( mRecur ) { | 420 | if( mRecur ) { |
422 | x += size+1; | 421 | x += size+1; |
423 | } | 422 | } |
424 | if( mAlarm ) { | 423 | if( mAlarm ) { |
425 | x += size+1; | 424 | x += size+1; |
426 | } | 425 | } |
427 | if( mReply ) { | 426 | if( mReply ) { |
428 | x += size+1; | 427 | x += size+1; |
429 | } | 428 | } |
430 | } | 429 | } |
431 | if( mMultiday ) { | 430 | if( mMultiday ) { |
432 | x += size+1+2+size/2; | 431 | x += size+1+2+size/2; |
433 | } | 432 | } |
434 | return( x + lb->fontMetrics().width( text() ) + 1 ); | 433 | return( x + lb->fontMetrics().width( text() ) + 1 ); |
435 | } | 434 | } |
436 | if ( ! lb ) | 435 | if ( ! lb ) |
437 | return 10; | 436 | return 10; |
438 | //qDebug("ret wid %d ", lb->width()); | 437 | //qDebug("ret wid %d ", lb->width()); |
439 | return lb->width(); | 438 | return lb->width(); |
440 | } | 439 | } |
441 | 440 | ||
442 | 441 | ||
443 | MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) | 442 | MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) |
444 | : KNoScrollListBox( par ), | 443 | : KNoScrollListBox( par ), |
445 | mMonthView( parent ) | 444 | mMonthView( parent ) |
446 | { | 445 | { |
447 | //QVBoxLayout *topLayout = new QVBoxLayout( this ); | 446 | //QVBoxLayout *topLayout = new QVBoxLayout( this ); |
448 | currentPalette = 0; | 447 | currentPalette = 0; |
449 | // mLabel = new QLabel( this );QPushButton | 448 | // mLabel = new QLabel( this );QPushButton |
450 | mLabel = new QPushButton( this ); | 449 | mLabel = new QPushButton( this ); |
451 | //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); | 450 | //mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain ); |
452 | //mLabel->setLineWidth( 1 ); | 451 | //mLabel->setLineWidth( 1 ); |
453 | //mLabel->setAlignment( AlignCenter ); | 452 | //mLabel->setAlignment( AlignCenter ); |
454 | mLabel->setFlat( true ); | 453 | mLabel->setFlat( true ); |
455 | mLabel->setFocusPolicy(NoFocus); | 454 | mLabel->setFocusPolicy(NoFocus); |
456 | //mItemList = new KNoScrollListBox( this ); | 455 | //mItemList = new KNoScrollListBox( this ); |
457 | setMinimumSize( 10, 10 ); | 456 | setMinimumSize( 10, 10 ); |
458 | setFrameStyle( QFrame::Panel | QFrame::Plain ); | 457 | setFrameStyle( QFrame::Panel | QFrame::Plain ); |
459 | setLineWidth( 1 ); | 458 | setLineWidth( 1 ); |
460 | //topLayout->addWidget( mItemList ); | 459 | //topLayout->addWidget( mItemList ); |
461 | mLabel->raise(); | 460 | mLabel->raise(); |
462 | // QColor( 0,0,255 ) QColor( 160,1600,255 ) | 461 | // QColor( 0,0,255 ) QColor( 160,1600,255 ) |
463 | mStandardPalette = palette(); | 462 | mStandardPalette = palette(); |
464 | mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); | 463 | mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); |
465 | 464 | ||
466 | enableScrollBars( false ); | 465 | enableScrollBars( false ); |
467 | updateConfig(); | 466 | updateConfig(); |
468 | //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); | 467 | //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); |
469 | connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); | 468 | connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); |
470 | connect( this , SIGNAL( doubleClicked( QListBoxItem *) ), | 469 | connect( this , SIGNAL( doubleClicked( QListBoxItem *) ), |
471 | SLOT( defaultAction( QListBoxItem * ) ) ); | 470 | SLOT( defaultAction( QListBoxItem * ) ) ); |
472 | connect( this, SIGNAL( rightButtonPressed( QListBoxItem *, | 471 | connect( this, SIGNAL( rightButtonPressed( QListBoxItem *, |
473 | const QPoint &) ), | 472 | const QPoint &) ), |
474 | SLOT( contextMenu( QListBoxItem * ) ) ); | 473 | SLOT( contextMenu( QListBoxItem * ) ) ); |
475 | connect( this, SIGNAL( highlighted( QListBoxItem *) ), | 474 | connect( this, SIGNAL( highlighted( QListBoxItem *) ), |
476 | SLOT( selection( QListBoxItem * ) ) ); | 475 | SLOT( selection( QListBoxItem * ) ) ); |
477 | connect( this, SIGNAL( clicked( QListBoxItem * ) ), | 476 | connect( this, SIGNAL( clicked( QListBoxItem * ) ), |
478 | SLOT( cellClicked( QListBoxItem * ) ) ); | 477 | SLOT( cellClicked( QListBoxItem * ) ) ); |
479 | connect( this, SIGNAL( clicked( QListBoxItem * ) ), | 478 | connect( this, SIGNAL( clicked( QListBoxItem * ) ), |
480 | SLOT( selection( QListBoxItem * ) ) ); | 479 | SLOT( selection( QListBoxItem * ) ) ); |
481 | } | 480 | } |
482 | #ifdef DESKTOP_VERSION | 481 | #ifdef DESKTOP_VERSION |
483 | QToolTipGroup *MonthViewCell::toolTipGroup() | 482 | QToolTipGroup *MonthViewCell::toolTipGroup() |
484 | { | 483 | { |
485 | if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); | 484 | if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); |
486 | return mToolTipGroup; | 485 | return mToolTipGroup; |
487 | } | 486 | } |
488 | #endif | 487 | #endif |
489 | 488 | ||
490 | void MonthViewCell::setDate( const QDate &date ) | 489 | void MonthViewCell::setDate( const QDate &date ) |
491 | { | 490 | { |
492 | // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; | 491 | // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; |
493 | mDate = date; | 492 | mDate = date; |
494 | 493 | ||
495 | 494 | ||
496 | 495 | ||
497 | //resizeEvent( 0 ); | 496 | //resizeEvent( 0 ); |
498 | } | 497 | } |
499 | 498 | ||
500 | QDate MonthViewCell::date() const | 499 | QDate MonthViewCell::date() const |
501 | { | 500 | { |
502 | return mDate; | 501 | return mDate; |
503 | } | 502 | } |
504 | 503 | ||
505 | void MonthViewCell::setPrimary( bool primary ) | 504 | void MonthViewCell::setPrimary( bool primary ) |
506 | { | 505 | { |
507 | mPrimary = primary; | 506 | mPrimary = primary; |
508 | //setMyPalette(); | 507 | //setMyPalette(); |
509 | } | 508 | } |
510 | void MonthViewCell::setMyPalette() | 509 | void MonthViewCell::setMyPalette() |
511 | { | 510 | { |
512 | 511 | ||
513 | if ( mHoliday) { | 512 | if ( mHoliday) { |
514 | if ( currentPalette == 1 ) return; | 513 | if ( currentPalette == 1 ) return; |
515 | mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) )); | 514 | mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) )); |
516 | setPalette( mHolidayPalette ); | 515 | setPalette( mHolidayPalette ); |
517 | //mLabel->setPalette( mHolidayPalette ); | 516 | //mLabel->setPalette( mHolidayPalette ); |
518 | currentPalette = 1; | 517 | currentPalette = 1; |
519 | 518 | ||
520 | } else { | 519 | } else { |
521 | if ( mPrimary ) { | 520 | if ( mPrimary ) { |
522 | if ( currentPalette == 2 ) return; | 521 | if ( currentPalette == 2 ) return; |
523 | mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); | 522 | mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); |
524 | //mLabel->setPalette( mPrimaryPalette ); | 523 | //mLabel->setPalette( mPrimaryPalette ); |
525 | setPalette( mPrimaryPalette ); | 524 | setPalette( mPrimaryPalette ); |
526 | currentPalette = 2; | 525 | currentPalette = 2; |
527 | 526 | ||
528 | } else { | 527 | } else { |
529 | if ( currentPalette == 3 ) return; | 528 | if ( currentPalette == 3 ) return; |
530 | setPalette( mNonPrimaryPalette ); | 529 | setPalette( mNonPrimaryPalette ); |
531 | mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); | 530 | mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) )); |
532 | //mLabel->setPalette( mNonPrimaryPalette );; | 531 | //mLabel->setPalette( mNonPrimaryPalette );; |
533 | currentPalette = 3; | 532 | currentPalette = 3; |
534 | } | 533 | } |
535 | } | 534 | } |
536 | //QPalette pal = palette(); | 535 | //QPalette pal = palette(); |
537 | 536 | ||
538 | //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); | 537 | //mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) )); |
539 | } | 538 | } |
540 | QPalette MonthViewCell::getPalette () | 539 | QPalette MonthViewCell::getPalette () |
541 | { | 540 | { |
542 | if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) | 541 | if ( !KOPrefs::instance()->mMonthViewUsesDayColors ) |
543 | return mStandardPalette; | 542 | return mStandardPalette; |
544 | if ( mHoliday) { | 543 | if ( mHoliday) { |
545 | return mHolidayPalette ; | 544 | return mHolidayPalette ; |
546 | } else { | 545 | } else { |
547 | if ( mPrimary ) { | 546 | if ( mPrimary ) { |
548 | return mPrimaryPalette ; | 547 | return mPrimaryPalette ; |
549 | } | 548 | } |
550 | } | 549 | } |
551 | return mNonPrimaryPalette; | 550 | return mNonPrimaryPalette; |
552 | } | 551 | } |
553 | bool MonthViewCell::isPrimary() const | 552 | bool MonthViewCell::isPrimary() const |
554 | { | 553 | { |
555 | return mPrimary; | 554 | return mPrimary; |
556 | } | 555 | } |
557 | 556 | ||
558 | void MonthViewCell::setHoliday( bool holiday ) | 557 | void MonthViewCell::setHoliday( bool holiday ) |
559 | { | 558 | { |
560 | mHoliday = holiday; | 559 | mHoliday = holiday; |
561 | //setMyPalette(); | 560 | //setMyPalette(); |
562 | } | 561 | } |
563 | 562 | ||
564 | void MonthViewCell::setHoliday( const QString &holiday ) | 563 | void MonthViewCell::setHoliday( const QString &holiday ) |
565 | { | 564 | { |
566 | mHolidayString = holiday; | 565 | mHolidayString = holiday; |
567 | 566 | ||
568 | if ( !holiday.isEmpty() ) { | 567 | if ( !holiday.isEmpty() ) { |
569 | setHoliday( true ); | 568 | setHoliday( true ); |
570 | } | 569 | } |
571 | } | 570 | } |
572 | 571 | ||
573 | void MonthViewCell::startUpdateCell() | 572 | void MonthViewCell::startUpdateCell() |
574 | { | 573 | { |
575 | mdayCount = 0; | 574 | mdayCount = 0; |
576 | setFocusPolicy(NoFocus); | 575 | setFocusPolicy(NoFocus); |
577 | if ( !mMonthView->isUpdatePossible() ) | 576 | if ( !mMonthView->isUpdatePossible() ) |
578 | return; | 577 | return; |
579 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); | 578 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); |
580 | while ( mitem ) { | 579 | while ( mitem ) { |
581 | mitem->setBlockRepaint( true ); | 580 | mitem->setBlockRepaint( true ); |
582 | mitem = (MonthViewItem *)mitem->next(); | 581 | mitem = (MonthViewItem *)mitem->next(); |
583 | } | 582 | } |
584 | if ( mAvailItemList.count() > 20 ) { | 583 | if ( mAvailItemList.count() > 20 ) { |
585 | mAvailItemList.setAutoDelete( true ); | 584 | mAvailItemList.setAutoDelete( true ); |
586 | mAvailItemList.clear(); | 585 | mAvailItemList.clear(); |
587 | mAvailItemList.setAutoDelete( false ); | 586 | mAvailItemList.setAutoDelete( false ); |
588 | } | 587 | } |
589 | /* | 588 | /* |
590 | if ( !isVisible() ){ | 589 | if ( !isVisible() ){ |
591 | return; | 590 | return; |
592 | } | 591 | } |
593 | */ | 592 | */ |
594 | // qDebug("MonthViewCell::updateCell() "); | 593 | // qDebug("MonthViewCell::updateCell() "); |
595 | setPrimary( mDate.month()%2 ); | 594 | setPrimary( mDate.month()%2 ); |
596 | setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); | 595 | setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); |
597 | if ( mDate == QDate::currentDate() ) { | 596 | if ( mDate == QDate::currentDate() ) { |
598 | setLineWidth( 3 ); | 597 | setLineWidth( 3 ); |
599 | } else { | 598 | } else { |
600 | setLineWidth( 1 ); | 599 | setLineWidth( 1 ); |
601 | } | 600 | } |
602 | MonthViewItem* CurrentAvailItem = (MonthViewItem*) firstItem (); | 601 | MonthViewItem* CurrentAvailItem = (MonthViewItem*) firstItem (); |
603 | //clear(); | 602 | //clear(); |
604 | while ( CurrentAvailItem ) { | 603 | while ( CurrentAvailItem ) { |
605 | MonthViewItem *item = CurrentAvailItem; | 604 | MonthViewItem *item = CurrentAvailItem; |
606 | CurrentAvailItem = (MonthViewItem *)item->next(); | 605 | CurrentAvailItem = (MonthViewItem *)item->next(); |
607 | mAvailItemList.append( item ); | 606 | mAvailItemList.append( item ); |
608 | takeItem ( item ); | 607 | takeItem ( item ); |
609 | } | 608 | } |
610 | 609 | ||
611 | #ifdef DESKTOP_VERSION | 610 | #ifdef DESKTOP_VERSION |
612 | QToolTip::remove(this); | 611 | QToolTip::remove(this); |
613 | #endif | 612 | #endif |
614 | mToolTip.clear(); | 613 | mToolTip.clear(); |
615 | //qApp->processEvents(); | 614 | //qApp->processEvents(); |
616 | #if 0 | 615 | #if 0 |
617 | if ( !mHolidayString.isEmpty() ) { | 616 | if ( !mHolidayString.isEmpty() ) { |
618 | MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); | 617 | MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); |
619 | item->setPalette( mHolidayPalette ); | 618 | item->setPalette( mHolidayPalette ); |
620 | insertItem( item ); | 619 | insertItem( item ); |
621 | mToolTip.append ( mHolidayString ); | 620 | mToolTip.append ( mHolidayString ); |
622 | } | 621 | } |
623 | #endif | 622 | #endif |
624 | } | 623 | } |
625 | 624 | ||
626 | int MonthViewCell::insertEvent(Event *event) | 625 | int MonthViewCell::insertEvent(Event *event) |
627 | { | 626 | { |
628 | QString mToolTipText; | 627 | QString mToolTipText; |
629 | setFocusPolicy(WheelFocus); | 628 | setFocusPolicy(WheelFocus); |
630 | if ( !(event->doesRecur() == Recurrence::rNone) ) { | 629 | if ( !(event->doesRecur() == Recurrence::rNone) ) { |
631 | if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) | 630 | if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) |
632 | return mdayCount; | 631 | return mdayCount; |
633 | else | 632 | else |
634 | if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) | 633 | if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) |
635 | return mdayCount; | 634 | return mdayCount; |
636 | } | 635 | } |
637 | 636 | ||
638 | if ( event->isHoliday()) { | 637 | if ( event->isHoliday()) { |
639 | setHoliday( true ); | 638 | setHoliday( true ); |
640 | if ( mDate.dayOfWeek() == 7 ) | 639 | if ( mDate.dayOfWeek() == 7 ) |
641 | setLineWidth( 3 ); | 640 | setLineWidth( 3 ); |
642 | } | 641 | } |
643 | QString text; | 642 | QString text; |
644 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day | 643 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day |
645 | if (event->isMultiDay()) { | 644 | if (event->isMultiDay()) { |
646 | QString prefix = "<->";multiday = 2; | 645 | QString prefix = "<->";multiday = 2; |
647 | QString time; | 646 | QString time; |
648 | if ( event->doesRecur() ) { | 647 | if ( event->doesRecur() ) { |
649 | if ( event->recursOn( mDate) ) { | 648 | if ( event->recursOn( mDate) ) { |
650 | prefix ="->" ;multiday = 1; | 649 | prefix ="->" ;multiday = 1; |
651 | } | 650 | } |
652 | else { | 651 | else { |
653 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 652 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
654 | if ( event->recursOn( mDate.addDays( -days)) ) { | 653 | if ( event->recursOn( mDate.addDays( -days)) ) { |
655 | prefix ="<-" ;multiday = 3; | 654 | prefix ="<-" ;multiday = 3; |
656 | } | 655 | } |
657 | } | 656 | } |
658 | 657 | ||
659 | } else { | 658 | } else { |
660 | if (mDate == event->dtStart().date()) { | 659 | if (mDate == event->dtStart().date()) { |
661 | prefix ="->" ;multiday = 1; | 660 | prefix ="->" ;multiday = 1; |
662 | } else if (mDate == event->dtEnd().date()) { | 661 | } else if (mDate == event->dtEnd().date()) { |
663 | prefix ="<-" ;multiday = 3; | 662 | prefix ="<-" ;multiday = 3; |
664 | } | 663 | } |
665 | } | 664 | } |
666 | if ( !event->doesFloat() ) { | 665 | if ( !event->doesFloat() ) { |
667 | if ( mDate == event->dtStart().date () ) | 666 | if ( mDate == event->dtStart().date () ) |
668 | time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; | 667 | time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; |
669 | else if ( mDate == event->dtEnd().date () ) | 668 | else if ( mDate == event->dtEnd().date () ) |
670 | time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; | 669 | time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; |
671 | 670 | ||
672 | } | 671 | } |
673 | text = time + event->summary(); | 672 | text = time + event->summary(); |
674 | mToolTipText += prefix + text; | 673 | mToolTipText += prefix + text; |
675 | } else { | 674 | } else { |
676 | if (event->doesFloat()) { | 675 | if (event->doesFloat()) { |
677 | text = event->summary(); | 676 | text = event->summary(); |
678 | mToolTipText += text; | 677 | mToolTipText += text; |
679 | } | 678 | } |
680 | else { | 679 | else { |
681 | text = KGlobal::locale()->formatTime(event->dtStart().time()); | 680 | text = KGlobal::locale()->formatTime(event->dtStart().time()); |
682 | text += " " + event->summary(); | 681 | text += " " + event->summary(); |
683 | mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); | 682 | mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); |
684 | } | 683 | } |
685 | } | 684 | } |
686 | MonthViewItem *item ; | 685 | MonthViewItem *item ; |
687 | 686 | ||
688 | if ( mAvailItemList.count() ) { | 687 | if ( mAvailItemList.count() ) { |
689 | item = mAvailItemList.first(); | 688 | item = mAvailItemList.first(); |
690 | mAvailItemList.remove( item ); | 689 | mAvailItemList.remove( item ); |
691 | item->recycle( event, mDate, text ); | 690 | item->recycle( event, mDate, text ); |
692 | } else { | 691 | } else { |
693 | item = new MonthViewItem( event, mDate, text ); | 692 | item = new MonthViewItem( event, mDate, text ); |
694 | } | 693 | } |
695 | 694 | ||
696 | QPalette pal; | 695 | QPalette pal; |
697 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { | 696 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { |
698 | QStringList categories = event->categories(); | 697 | QStringList categories = event->categories(); |
699 | QString cat = categories.first(); | 698 | QString cat = categories.first(); |
700 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { | 699 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { |
701 | pal = getPalette(); | 700 | pal = getPalette(); |
702 | if (cat.isEmpty()) { | 701 | if (cat.isEmpty()) { |
703 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); | 702 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); |
704 | } else { | 703 | } else { |
705 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); | 704 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); |
706 | } | 705 | } |
707 | 706 | ||
708 | } else { | 707 | } else { |
709 | if (cat.isEmpty()) { | 708 | if (cat.isEmpty()) { |
710 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); | 709 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); |
711 | } else { | 710 | } else { |
712 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); | 711 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); |
713 | } | 712 | } |
714 | } | 713 | } |
715 | 714 | ||
716 | } else { | 715 | } else { |
717 | pal = mStandardPalette ; | 716 | pal = mStandardPalette ; |
718 | } | 717 | } |
719 | item->setPalette( pal ); | 718 | item->setPalette( pal ); |
720 | item->setRecur( event->recurrence()->doesRecur() ); | 719 | item->setRecur( event->recurrence()->doesRecur() ); |
721 | item->setAlarm( event->isAlarmEnabled() && multiday < 2 ); | 720 | item->setAlarm( event->isAlarmEnabled() && multiday < 2 ); |
722 | item->setMoreInfo( event->description().length() > 0 ); | 721 | item->setMoreInfo( event->description().length() > 0 ); |
723 | #ifdef DESKTOP_VERSION | 722 | #ifdef DESKTOP_VERSION |
724 | Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, | 723 | Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, |
725 | KOPrefs::instance()->email()); | 724 | KOPrefs::instance()->email()); |
726 | if ( me != 0 ) { | 725 | if ( me != 0 ) { |
727 | if ( me->status() == Attendee::NeedsAction && me->RSVP()) | 726 | if ( me->status() == Attendee::NeedsAction && me->RSVP()) |
728 | item->setReply(true && multiday < 2); | 727 | item->setReply(true && multiday < 2); |
729 | else | 728 | else |
730 | item->setReply(false); | 729 | item->setReply(false); |
731 | } else | 730 | } else |
732 | item->setReply(false); | 731 | item->setReply(false); |
733 | #endif | 732 | #endif |
734 | item->setMultiDay( multiday ); | 733 | item->setMultiDay( multiday ); |
735 | if ( multiday ) { | 734 | if ( multiday ) { |
736 | insertItem( item ,mdayCount); | 735 | insertItem( item ,mdayCount); |
737 | ++mdayCount; | 736 | ++mdayCount; |
738 | } else { | 737 | } else { |
739 | uint i; | 738 | uint i; |
740 | int pos = mdayCount; | 739 | int pos = mdayCount; |
741 | for ( i = mdayCount; i < count();++i ) { | 740 | for ( i = mdayCount; i < count();++i ) { |
742 | QListBoxItem* it = this->item ( i ); | 741 | QListBoxItem* it = this->item ( i ); |
743 | if ( text < it->text() ) { | 742 | if ( text < it->text() ) { |
744 | pos = i; | 743 | pos = i; |
745 | break; | 744 | break; |
746 | } | 745 | } |
747 | ++pos; | 746 | ++pos; |
748 | } | 747 | } |
749 | insertItem( item ,pos); | 748 | insertItem( item ,pos); |
750 | } | 749 | } |
751 | mToolTip.append( mToolTipText ); | 750 | mToolTip.append( mToolTipText ); |
752 | return mdayCount; | 751 | return mdayCount; |
753 | } | 752 | } |
754 | void MonthViewCell::insertTodo(Todo *todo) | 753 | void MonthViewCell::insertTodo(Todo *todo) |
755 | { | 754 | { |
756 | setFocusPolicy(WheelFocus); | 755 | setFocusPolicy(WheelFocus); |
757 | QString text; | 756 | QString text; |
758 | if (todo->hasDueDate()) { | 757 | if (todo->hasDueDate()) { |
759 | if (!todo->doesFloat()) { | 758 | if (!todo->doesFloat()) { |
760 | text += KGlobal::locale()->formatTime(todo->dtDue().time()); | 759 | text += KGlobal::locale()->formatTime(todo->dtDue().time()); |
761 | text += " "; | 760 | text += " "; |
762 | } | 761 | } |
763 | } | 762 | } |
764 | text += todo->summary(); | 763 | text += todo->summary(); |
765 | MonthViewItem *item ; | 764 | MonthViewItem *item ; |
766 | if ( mAvailItemList.count() ) { | 765 | if ( mAvailItemList.count() ) { |
767 | item = mAvailItemList.first(); | 766 | item = mAvailItemList.first(); |
768 | mAvailItemList.remove( item ); | 767 | mAvailItemList.remove( item ); |
769 | item->recycle( todo, mDate, text ); | 768 | item->recycle( todo, mDate, text ); |
770 | } else { | 769 | } else { |
771 | item = new MonthViewItem( todo, mDate, text ); | 770 | item = new MonthViewItem( todo, mDate, text ); |
772 | } | 771 | } |
773 | //MonthViewItem *item = new MonthViewItem( todo, mDate, text ); | 772 | //MonthViewItem *item = new MonthViewItem( todo, mDate, text ); |
774 | //item->setPalette( mStandardPalette ); | 773 | //item->setPalette( mStandardPalette ); |
775 | QPalette pal; | 774 | QPalette pal; |
776 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { | 775 | if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { |
777 | QStringList categories = todo->categories(); | 776 | QStringList categories = todo->categories(); |
778 | QString cat = categories.first(); | 777 | QString cat = categories.first(); |
779 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { | 778 | if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { |
780 | pal = getPalette(); | 779 | pal = getPalette(); |
781 | if (cat.isEmpty()) { | 780 | if (cat.isEmpty()) { |
782 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); | 781 | pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); |
783 | } else { | 782 | } else { |
784 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); | 783 | pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); |
785 | } | 784 | } |
786 | 785 | ||
787 | } else { | 786 | } else { |
788 | if (cat.isEmpty()) { | 787 | if (cat.isEmpty()) { |
789 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); | 788 | pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); |
790 | } else { | 789 | } else { |
791 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); | 790 | pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); |
792 | } | 791 | } |
793 | } | 792 | } |
794 | 793 | ||
795 | } else { | 794 | } else { |
796 | pal = mStandardPalette ; | 795 | pal = mStandardPalette ; |
797 | } | 796 | } |
798 | item->setPalette( pal ); | 797 | item->setPalette( pal ); |
799 | item->setRecur( todo->recurrence()->doesRecur() ); | 798 | item->setRecur( todo->recurrence()->doesRecur() ); |
800 | item->setAlarm( todo->isAlarmEnabled() ); | 799 | item->setAlarm( todo->isAlarmEnabled() ); |
801 | item->setMoreInfo( todo->description().length() > 0 ); | 800 | item->setMoreInfo( todo->description().length() > 0 ); |
802 | insertItem( item , count()); | 801 | insertItem( item , count()); |
803 | mToolTip.append( text ); | 802 | mToolTip.append( text ); |
804 | } | 803 | } |
805 | void MonthViewCell::repaintfinishUpdateCell() | 804 | void MonthViewCell::repaintfinishUpdateCell() |
806 | { | 805 | { |
807 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); | 806 | MonthViewItem *mitem = (MonthViewItem*) firstItem (); |
808 | while ( mitem ) { | 807 | while ( mitem ) { |
809 | mitem->setBlockRepaint( false ); | 808 | mitem->setBlockRepaint( false ); |
810 | updateItem ( mitem ); | 809 | updateItem ( mitem ); |
811 | mitem = (MonthViewItem *)mitem->next(); | 810 | mitem = (MonthViewItem *)mitem->next(); |
812 | } | 811 | } |
813 | } | 812 | } |
814 | void MonthViewCell::finishUpdateCell() | 813 | void MonthViewCell::finishUpdateCell() |
815 | { | 814 | { |
816 | 815 | ||
817 | 816 | ||
818 | 817 | ||
819 | #ifdef DESKTOP_VERSION | 818 | #ifdef DESKTOP_VERSION |
820 | if (mToolTip.count() > 0 ) { | 819 | if (mToolTip.count() > 0 ) { |
821 | mToolTip.sort(); | 820 | mToolTip.sort(); |
822 | QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); | 821 | QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); |
823 | } | 822 | } |
824 | #endif | 823 | #endif |
825 | //sort(); | 824 | //sort(); |
826 | //setMyPalette(); | 825 | //setMyPalette(); |
827 | setMyPalette(); | 826 | setMyPalette(); |
828 | 827 | ||
829 | resizeEvent( 0 ); | 828 | resizeEvent( 0 ); |
830 | 829 | ||
831 | } | 830 | } |
832 | void MonthViewCell::updateCell() | 831 | void MonthViewCell::updateCell() |
833 | { | 832 | { |
834 | //qDebug("MonthViewCell::updateCell() "); | 833 | //qDebug("MonthViewCell::updateCell() "); |
835 | if ( !mMonthView->isUpdatePossible() ) | 834 | if ( !mMonthView->isUpdatePossible() ) |
836 | return; | 835 | return; |
837 | startUpdateCell(); | 836 | startUpdateCell(); |
838 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); | 837 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); |
839 | QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); | 838 | QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); |
840 | Event *event; | 839 | Event *event; |
841 | for( event = events.first(); event; event = events.next() ) { // for event | 840 | for( event = events.first(); event; event = events.next() ) { // for event |
842 | insertEvent(event); | 841 | insertEvent(event); |
843 | } | 842 | } |
844 | // insert due todos | 843 | // insert due todos |
845 | QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); | 844 | QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); |
846 | Todo *todo; | 845 | Todo *todo; |
847 | for(todo = todos.first(); todo; todo = todos.next()) { | 846 | for(todo = todos.first(); todo; todo = todos.next()) { |
848 | insertTodo( todo ); | 847 | insertTodo( todo ); |
849 | } | 848 | } |
850 | finishUpdateCell(); | 849 | finishUpdateCell(); |
851 | // if ( isVisible()) | 850 | // if ( isVisible()) |
852 | //qApp->processEvents(); | 851 | //qApp->processEvents(); |
853 | } | 852 | } |
854 | 853 | ||
855 | void MonthViewCell::updateConfig( bool bigFont ) // = false | 854 | void MonthViewCell::updateConfig( bool bigFont ) // = false |
856 | { | 855 | { |
857 | 856 | ||
858 | if ( bigFont ) { | 857 | if ( bigFont ) { |
859 | QFont fo = KOPrefs::instance()->mMonthViewFont; | 858 | QFont fo = KOPrefs::instance()->mMonthViewFont; |
860 | int ps = fo.pointSize() + 2; | 859 | int ps = fo.pointSize() + 2; |
861 | if ( ps < 18 ) | 860 | if ( ps < 18 ) |
862 | ps += 2; | 861 | ps += 2; |
863 | fo.setPointSize( ps ); | 862 | fo.setPointSize( ps ); |
864 | setFont( fo ); | 863 | setFont( fo ); |
865 | } else | 864 | } else |
866 | setFont( KOPrefs::instance()->mMonthViewFont ); | 865 | setFont( KOPrefs::instance()->mMonthViewFont ); |
867 | 866 | ||
868 | QFontMetrics fm( font() ); | 867 | QFontMetrics fm( font() ); |
869 | mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); | 868 | mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); |
870 | mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); | 869 | mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); |
871 | mHolidayPalette = mStandardPalette; | 870 | mHolidayPalette = mStandardPalette; |
872 | mPrimaryPalette = mStandardPalette; | 871 | mPrimaryPalette = mStandardPalette; |
873 | mNonPrimaryPalette = mStandardPalette; | 872 | mNonPrimaryPalette = mStandardPalette; |
874 | if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { | 873 | if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { |
875 | mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); | 874 | mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); |
876 | mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); | 875 | mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); |
877 | mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); | 876 | mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); |
878 | mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); | 877 | mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); |
879 | mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); | 878 | mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); |
880 | mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); | 879 | mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); |
881 | mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); | 880 | mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); |
882 | mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); | 881 | mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); |
883 | mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); | 882 | mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); |
884 | } | 883 | } |
885 | //updateCell(); | 884 | //updateCell(); |
886 | } | 885 | } |
887 | 886 | ||
888 | void MonthViewCell::enableScrollBars( bool enabled ) | 887 | void MonthViewCell::enableScrollBars( bool enabled ) |
889 | { | 888 | { |
890 | 889 | ||
891 | return; | 890 | return; |
892 | if ( enabled ) { | 891 | if ( enabled ) { |
893 | QListBoxItem *fi = firstItem (); | 892 | QListBoxItem *fi = firstItem (); |
894 | if (fi ) { | 893 | if (fi ) { |
895 | int ihei = fi->height( this ); | 894 | int ihei = fi->height( this ); |
896 | int hei = numRows () * ihei; | 895 | int hei = numRows () * ihei; |
897 | if ( hei < height() - horizontalScrollBar()->height () ) { | 896 | if ( hei < height() - horizontalScrollBar()->height () ) { |
898 | setVScrollBarMode(QScrollView::AlwaysOff); | 897 | setVScrollBarMode(QScrollView::AlwaysOff); |
899 | } | 898 | } |
900 | else | 899 | else |
901 | setVScrollBarMode(QScrollView::Auto); | 900 | setVScrollBarMode(QScrollView::Auto); |
902 | if ( ihei *3 > height() ) { | 901 | if ( ihei *3 > height() ) { |
903 | setHScrollBarMode(QScrollView::AlwaysOff); | 902 | setHScrollBarMode(QScrollView::AlwaysOff); |
904 | } | 903 | } |
905 | else { | 904 | else { |
906 | setHScrollBarMode(QScrollView::Auto); | 905 | setHScrollBarMode(QScrollView::Auto); |
907 | } | 906 | } |
908 | } else { | 907 | } else { |
909 | setVScrollBarMode(QScrollView::Auto); | 908 | setVScrollBarMode(QScrollView::Auto); |
910 | setHScrollBarMode(QScrollView::Auto); | 909 | setHScrollBarMode(QScrollView::Auto); |
911 | } | 910 | } |
912 | } else { | 911 | } else { |
913 | setVScrollBarMode(QScrollView::AlwaysOff); | 912 | setVScrollBarMode(QScrollView::AlwaysOff); |
914 | setHScrollBarMode(QScrollView::AlwaysOff); | 913 | setHScrollBarMode(QScrollView::AlwaysOff); |
915 | } | 914 | } |
916 | } | 915 | } |
917 | 916 | ||
918 | Incidence *MonthViewCell::selectedIncidence() | 917 | Incidence *MonthViewCell::selectedIncidence() |
919 | { | 918 | { |
920 | int index = currentItem(); | 919 | int index = currentItem(); |
921 | if ( index < 0 ) return 0; | 920 | if ( index < 0 ) return 0; |
922 | 921 | ||
923 | MonthViewItem *mitem = | 922 | MonthViewItem *mitem = |
924 | static_cast<MonthViewItem *>( item( index ) ); | 923 | static_cast<MonthViewItem *>( item( index ) ); |
925 | 924 | ||
926 | if ( !mitem ) return 0; | 925 | if ( !mitem ) return 0; |
927 | 926 | ||
928 | return mitem->incidence(); | 927 | return mitem->incidence(); |
929 | } | 928 | } |
930 | 929 | ||
931 | QDate MonthViewCell::selectedIncidenceDate() | 930 | QDate MonthViewCell::selectedIncidenceDate() |
932 | { | 931 | { |
933 | QDate qd; | 932 | QDate qd; |
934 | int index = currentItem(); | 933 | int index = currentItem(); |
935 | if ( index < 0 ) return qd; | 934 | if ( index < 0 ) return qd; |
936 | 935 | ||
937 | MonthViewItem *mitem = | 936 | MonthViewItem *mitem = |
938 | static_cast<MonthViewItem *>( item( index ) ); | 937 | static_cast<MonthViewItem *>( item( index ) ); |
939 | 938 | ||
940 | if ( !mitem ) return qd; | 939 | if ( !mitem ) return qd; |
941 | 940 | ||
942 | return mitem->incidenceDate(); | 941 | return mitem->incidenceDate(); |
943 | } | 942 | } |
944 | 943 | ||
945 | void MonthViewCell::deselect() | 944 | void MonthViewCell::deselect() |
946 | { | 945 | { |
947 | clearSelection(); | 946 | clearSelection(); |
948 | enableScrollBars( false ); | 947 | enableScrollBars( false ); |
949 | // updateCell(); | 948 | // updateCell(); |
950 | } | 949 | } |
951 | void MonthViewCell::select() | 950 | void MonthViewCell::select() |
952 | { | 951 | { |
953 | ;// updateCell(); | 952 | ;// updateCell(); |
954 | } | 953 | } |
955 | 954 | ||
956 | void MonthViewCell::resizeEvent ( QResizeEvent * e ) | 955 | void MonthViewCell::resizeEvent ( QResizeEvent * e ) |
957 | { | 956 | { |
958 | if ( !mMonthView->isUpdatePossible() ) | 957 | if ( !mMonthView->isUpdatePossible() ) |
959 | return; | 958 | return; |
960 | //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height()); | 959 | //qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height()); |
961 | deselect(); | 960 | deselect(); |
962 | mLabel->setMaximumHeight( height() - lineWidth()*2 ); | 961 | mLabel->setMaximumHeight( height() - lineWidth()*2 ); |
963 | 962 | ||
964 | QString text; | 963 | QString text; |
965 | mLabel->setText( text ); | 964 | mLabel->setText( text ); |
966 | bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; | 965 | bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; |
967 | if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { | 966 | if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { |
968 | text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; | 967 | text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; |
969 | mLabel->resize( mLabelBigSize ); | 968 | mLabel->resize( mLabelBigSize ); |
970 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); | 969 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); |
971 | } else { | 970 | } else { |
972 | mLabel->resize( mLabelSize ); | 971 | mLabel->resize( mLabelSize ); |
973 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); | 972 | text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); |
974 | } | 973 | } |
975 | mLabel->setText( text ); | 974 | mLabel->setText( text ); |
976 | 975 | ||
977 | int size = height() - mLabel->height() - lineWidth()-1; | 976 | int size = height() - mLabel->height() - lineWidth()-1; |
978 | //qDebug("LW %d ", lineWidth()); | 977 | //qDebug("LW %d ", lineWidth()); |
979 | if ( size > 0 ) | 978 | if ( size > 0 ) |
980 | verticalScrollBar()->setMaximumHeight( size ); | 979 | verticalScrollBar()->setMaximumHeight( size ); |
981 | size = width() - mLabel->width() -lineWidth()-1; | 980 | size = width() - mLabel->width() -lineWidth()-1; |
982 | if ( size > 0 ) | 981 | if ( size > 0 ) |
983 | horizontalScrollBar()->setMaximumWidth( size ); | 982 | horizontalScrollBar()->setMaximumWidth( size ); |
984 | mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); | 983 | mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); |
985 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); | 984 | //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); |
986 | // mItemList->resize ( width(), height () ); | 985 | // mItemList->resize ( width(), height () ); |
987 | if ( e ) | 986 | if ( e ) |
988 | KNoScrollListBox::resizeEvent ( e ); | 987 | KNoScrollListBox::resizeEvent ( e ); |
989 | } | 988 | } |
990 | 989 | ||
991 | void MonthViewCell::defaultAction( QListBoxItem *item ) | 990 | void MonthViewCell::defaultAction( QListBoxItem *item ) |
992 | { | 991 | { |
993 | if ( !item ) { | 992 | if ( !item ) { |
994 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 993 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
995 | emit newEventSignal( dt ); | 994 | emit newEventSignal( dt ); |
996 | return; | 995 | return; |
997 | } | 996 | } |
998 | 997 | ||
999 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); | 998 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); |
1000 | Incidence *incidence = eventItem->incidence(); | 999 | Incidence *incidence = eventItem->incidence(); |
1001 | if ( incidence ) mMonthView->defaultAction( incidence ); | 1000 | if ( incidence ) mMonthView->defaultAction( incidence ); |
1002 | } | 1001 | } |
1003 | void MonthViewCell::showDay() | 1002 | void MonthViewCell::showDay() |
1004 | { | 1003 | { |
1005 | emit showDaySignal( date() ); | 1004 | emit showDaySignal( date() ); |
1006 | } | 1005 | } |
1007 | void MonthViewCell::newEvent() | 1006 | void MonthViewCell::newEvent() |
1008 | { | 1007 | { |
1009 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 1008 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
1010 | emit newEventSignal( dt ); | 1009 | emit newEventSignal( dt ); |
1011 | } | 1010 | } |
1012 | void MonthViewCell::cellClicked( QListBoxItem *item ) | 1011 | void MonthViewCell::cellClicked( QListBoxItem *item ) |
1013 | { | 1012 | { |
1014 | if ( item == 0 ) { | 1013 | if ( item == 0 ) { |
1015 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 1014 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
1016 | emit newEventSignal( dt ); | 1015 | emit newEventSignal( dt ); |
1017 | return; | 1016 | return; |
1018 | } | 1017 | } |
1019 | /* | 1018 | /* |
1020 | if ( lastClicked ) | 1019 | if ( lastClicked ) |
1021 | if ( ! item ) { | 1020 | if ( ! item ) { |
1022 | if ( lastClicked->listBox() != item->listBox() ) | 1021 | if ( lastClicked->listBox() != item->listBox() ) |
1023 | lastClicked->listBox()->clearSelection(); | 1022 | lastClicked->listBox()->clearSelection(); |
1024 | } | 1023 | } |
1025 | */ | 1024 | */ |
1026 | 1025 | ||
1027 | mMonthView->setSelectedCell( this ); | 1026 | mMonthView->setSelectedCell( this ); |
1028 | if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true ); | 1027 | if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true ); |
1029 | select(); | 1028 | select(); |
1030 | } | 1029 | } |
1031 | 1030 | ||
1032 | void MonthViewCell::contextMenu( QListBoxItem *item ) | 1031 | void MonthViewCell::contextMenu( QListBoxItem *item ) |
1033 | { | 1032 | { |
1034 | if ( !item ) return; | 1033 | if ( !item ) return; |
1035 | 1034 | ||
1036 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); | 1035 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); |
1037 | Incidence *incidence = eventItem->incidence(); | 1036 | Incidence *incidence = eventItem->incidence(); |
1038 | if ( incidence ) mMonthView->showContextMenu( incidence ); | 1037 | if ( incidence ) mMonthView->showContextMenu( incidence ); |
1039 | } | 1038 | } |
1040 | 1039 | ||
1041 | void MonthViewCell::selection( QListBoxItem *item ) | 1040 | void MonthViewCell::selection( QListBoxItem *item ) |
1042 | { | 1041 | { |
1043 | if ( !item ) return; | 1042 | if ( !item ) return; |
1044 | 1043 | ||
1045 | mMonthView->setSelectedCell( this ); | 1044 | mMonthView->setSelectedCell( this ); |
1046 | } | 1045 | } |
1047 | 1046 | ||
1048 | 1047 | ||
1049 | // ******************************************************************************* | 1048 | // ******************************************************************************* |
1050 | // ******************************************************************************* | 1049 | // ******************************************************************************* |
1051 | // ******************************************************************************* | 1050 | // ******************************************************************************* |
1052 | 1051 | ||
1053 | 1052 | ||
1054 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) | 1053 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) |
1055 | : KOEventView( calendar, parent, name ), | 1054 | : KOEventView( calendar, parent, name ), |
1056 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), | 1055 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), |
1057 | mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) | 1056 | mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) |
1058 | { | 1057 | { |
1059 | mFlagKeyPressed = false; | 1058 | mFlagKeyPressed = false; |
1060 | mShortDayLabelsM = false; | 1059 | mShortDayLabelsM = false; |
1061 | mShortDayLabelsW = false; | 1060 | mShortDayLabelsW = false; |
1062 | skipResize = false; | 1061 | skipResize = false; |
1063 | clPending = true; | 1062 | clPending = true; |
1064 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); | 1063 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); |
1065 | mWidStack = new QWidgetStack( this ); | 1064 | mWidStack = new QWidgetStack( this ); |
1066 | QVBoxLayout* hb = new QVBoxLayout( this ); | 1065 | QVBoxLayout* hb = new QVBoxLayout( this ); |
1067 | mMonthView = new QWidget( mWidStack ); | 1066 | mMonthView = new QWidget( mWidStack ); |
1068 | mWeekView = new QWidget( mWidStack ); | 1067 | mWeekView = new QWidget( mWidStack ); |
1069 | #if QT_VERSION >= 0x030000 | 1068 | #if QT_VERSION >= 0x030000 |
1070 | mWidStack->addWidget(mMonthView ); | 1069 | mWidStack->addWidget(mMonthView ); |
1071 | mWidStack->addWidget(mWeekView ); | 1070 | mWidStack->addWidget(mWeekView ); |
1072 | #else | 1071 | #else |
1073 | mWidStack->addWidget( mMonthView, 1 ); | 1072 | mWidStack->addWidget( mMonthView, 1 ); |
1074 | mWidStack->addWidget( mWeekView , 1 ); | 1073 | mWidStack->addWidget( mWeekView , 1 ); |
1075 | #endif | 1074 | #endif |
1076 | hb->addWidget( mNavigatorBar ); | 1075 | hb->addWidget( mNavigatorBar ); |
1077 | hb->addWidget( mWidStack ); | 1076 | hb->addWidget( mWidStack ); |
1078 | mShowWeekView = KOPrefs::instance()->mMonthViewWeek; | 1077 | mShowWeekView = KOPrefs::instance()->mMonthViewWeek; |
1079 | updatePossible = false; | 1078 | updatePossible = false; |
1080 | //updatePossible = true; | 1079 | //updatePossible = true; |
1081 | mCells.setAutoDelete( true ); | 1080 | mCells.setAutoDelete( true ); |
1082 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; | 1081 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; |
1083 | mDayLabels.resize( mDaysPerWeek ); | 1082 | mDayLabels.resize( mDaysPerWeek ); |
1084 | mDayLabelsW.resize( mDaysPerWeek ); | 1083 | mDayLabelsW.resize( mDaysPerWeek ); |
1085 | QFont bfont = font(); | 1084 | QFont bfont = font(); |
1086 | if ( QApplication::desktop()->width() < 650 ) { | 1085 | if ( QApplication::desktop()->width() < 650 ) { |
1087 | bfont.setPointSize( bfont.pointSize() - 2 ); | 1086 | bfont.setPointSize( bfont.pointSize() - 2 ); |
1088 | } | 1087 | } |
1089 | bfont.setBold( true ); | 1088 | bfont.setBold( true ); |
1090 | int i; | 1089 | int i; |
1091 | 1090 | ||
1092 | for( i = 0; i < mDaysPerWeek; i++ ) { | 1091 | for( i = 0; i < mDaysPerWeek; i++ ) { |
1093 | QLabel *label = new QLabel( mMonthView ); | 1092 | QLabel *label = new QLabel( mMonthView ); |
1094 | label->setFont(bfont); | 1093 | label->setFont(bfont); |
1095 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1094 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1096 | label->setLineWidth(1); | 1095 | label->setLineWidth(1); |
1097 | label->setAlignment(AlignCenter); | 1096 | label->setAlignment(AlignCenter); |
1098 | mDayLabels.insert( i, label ); | 1097 | mDayLabels.insert( i, label ); |
1099 | label = new QLabel( mWeekView ); | 1098 | label = new QLabel( mWeekView ); |
1100 | label->setFont(bfont); | 1099 | label->setFont(bfont); |
1101 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1100 | label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1102 | label->setLineWidth(1); | 1101 | label->setLineWidth(1); |
1103 | label->setAlignment(AlignCenter); | 1102 | label->setAlignment(AlignCenter); |
1104 | mDayLabelsW.insert( i, label ); | 1103 | mDayLabelsW.insert( i, label ); |
1105 | } | 1104 | } |
1106 | 1105 | ||
1107 | bfont.setBold( false ); | 1106 | bfont.setBold( false ); |
1108 | mWeekLabels.resize( mNumWeeks+1 ); | 1107 | mWeekLabels.resize( mNumWeeks+1 ); |
1109 | mWeekLabelsW.resize( 2 ); | 1108 | mWeekLabelsW.resize( 2 ); |
1110 | for( i = 0; i < mNumWeeks+1; i++ ) { | 1109 | for( i = 0; i < mNumWeeks+1; i++ ) { |
1111 | KOWeekButton *label = new KOWeekButton( mMonthView ); | 1110 | KOWeekButton *label = new KOWeekButton( mMonthView ); |
1112 | label->setFocusPolicy(NoFocus); | 1111 | label->setFocusPolicy(NoFocus); |
1113 | label->setFont(bfont); | 1112 | label->setFont(bfont); |
1114 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); | 1113 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); |
1115 | label->setFlat(true); | 1114 | label->setFlat(true); |
1116 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); | 1115 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); |
1117 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1116 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1118 | //label->setLineWidth(1); | 1117 | //label->setLineWidth(1); |
1119 | //label->setAlignment(AlignCenter); | 1118 | //label->setAlignment(AlignCenter); |
1120 | mWeekLabels.insert( i, label ); | 1119 | mWeekLabels.insert( i, label ); |
1121 | } | 1120 | } |
1122 | mWeekLabels[mNumWeeks]->setText( i18n("W")); | 1121 | mWeekLabels[mNumWeeks]->setText( i18n("W")); |
1123 | mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus); | 1122 | mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus); |
1124 | QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); | 1123 | QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); |
1125 | 1124 | ||
1126 | for( i = 0; i < 1+1; i++ ) { | 1125 | for( i = 0; i < 1+1; i++ ) { |
1127 | KOWeekButton *label = new KOWeekButton( mWeekView ); | 1126 | KOWeekButton *label = new KOWeekButton( mWeekView ); |
1128 | label->setFocusPolicy(NoFocus); | 1127 | label->setFocusPolicy(NoFocus); |
1129 | label->setFont(bfont); | 1128 | label->setFont(bfont); |
1130 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); | 1129 | connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); |
1131 | label->setFlat(true); | 1130 | label->setFlat(true); |
1132 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); | 1131 | QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); |
1133 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); | 1132 | //label->setFrameStyle(QFrame::Panel|QFrame::Raised); |
1134 | //label->setLineWidth(1); | 1133 | //label->setLineWidth(1); |
1135 | //label->setAlignment(AlignCenter); | 1134 | //label->setAlignment(AlignCenter); |
1136 | mWeekLabelsW.insert( i, label ); | 1135 | mWeekLabelsW.insert( i, label ); |
1137 | } | 1136 | } |
1138 | mWeekLabelsW[1]->setText( i18n("W")); | 1137 | mWeekLabelsW[1]->setText( i18n("W")); |
1139 | mWeekLabelsW[1]->setFocusPolicy(WheelFocus); | 1138 | mWeekLabelsW[1]->setFocusPolicy(WheelFocus); |
1140 | 1139 | ||
1141 | 1140 | ||
1142 | int row, col; | 1141 | int row, col; |
1143 | mCells.resize( mNumCells ); | 1142 | mCells.resize( mNumCells ); |
1144 | for( row = 0; row < mNumWeeks; ++row ) { | 1143 | for( row = 0; row < mNumWeeks; ++row ) { |
1145 | for( col = 0; col < mDaysPerWeek; ++col ) { | 1144 | for( col = 0; col < mDaysPerWeek; ++col ) { |
1146 | MonthViewCell *cell = new MonthViewCell( this, mMonthView ); | 1145 | MonthViewCell *cell = new MonthViewCell( this, mMonthView ); |
1147 | mCells.insert( row * mDaysPerWeek + col, cell ); | 1146 | mCells.insert( row * mDaysPerWeek + col, cell ); |
1148 | 1147 | ||
1149 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), | 1148 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), |
1150 | SLOT( defaultAction( Incidence * ) ) ); | 1149 | SLOT( defaultAction( Incidence * ) ) ); |
1151 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), | 1150 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), |
1152 | SIGNAL( newEventSignal( QDateTime ) ) ); | 1151 | SIGNAL( newEventSignal( QDateTime ) ) ); |
1153 | connect( cell, SIGNAL( showDaySignal( QDate ) ), | 1152 | connect( cell, SIGNAL( showDaySignal( QDate ) ), |
1154 | SIGNAL( showDaySignal( QDate ) ) ); | 1153 | SIGNAL( showDaySignal( QDate ) ) ); |
1155 | } | 1154 | } |
1156 | } | 1155 | } |
1157 | mCellsW.resize( mDaysPerWeek ); | 1156 | mCellsW.resize( mDaysPerWeek ); |
1158 | for( col = 0; col < mDaysPerWeek; ++col ) { | 1157 | for( col = 0; col < mDaysPerWeek; ++col ) { |
1159 | MonthViewCell *cell = new MonthViewCell( this, mWeekView ); | 1158 | MonthViewCell *cell = new MonthViewCell( this, mWeekView ); |
1160 | mCellsW.insert( col, cell ); | 1159 | mCellsW.insert( col, cell ); |
1161 | 1160 | ||
1162 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), | 1161 | connect( cell, SIGNAL( defaultAction( Incidence * ) ), |
1163 | SLOT( defaultAction( Incidence * ) ) ); | 1162 | SLOT( defaultAction( Incidence * ) ) ); |
1164 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), | 1163 | connect( cell, SIGNAL( newEventSignal( QDateTime ) ), |
1165 | SIGNAL( newEventSignal( QDateTime ) ) ); | 1164 | SIGNAL( newEventSignal( QDateTime ) ) ); |
1166 | connect( cell, SIGNAL( showDaySignal( QDate ) ), | 1165 | connect( cell, SIGNAL( showDaySignal( QDate ) ), |
1167 | SIGNAL( showDaySignal( QDate ) ) ); | 1166 | SIGNAL( showDaySignal( QDate ) ) ); |
1168 | cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); | 1167 | cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); |
1169 | } | 1168 | } |
1170 | 1169 | ||
1171 | //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); | 1170 | //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); |
1172 | mContextMenu = eventPopup(); | 1171 | mContextMenu = eventPopup(); |
1173 | // updateConfig(); //useless here... | 1172 | // updateConfig(); //useless here... |
1174 | // ... but we need mWidthLongDayLabel computed | 1173 | // ... but we need mWidthLongDayLabel computed |
1175 | QFontMetrics fontmetric(mDayLabels[0]->font()); | 1174 | QFontMetrics fontmetric(mDayLabels[0]->font()); |
1176 | mWidthLongDayLabel = 0; | 1175 | mWidthLongDayLabel = 0; |
1177 | for (int i = 0; i < 7; i++) { | 1176 | for (int i = 0; i < 7; i++) { |
1178 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); | 1177 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); |
1179 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; | 1178 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; |
1180 | } | 1179 | } |
1181 | 1180 | ||
1182 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); | 1181 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); |
1183 | 1182 | ||
1184 | #if 0 | 1183 | #if 0 |
1185 | if ( mShowWeekView ) | 1184 | if ( mShowWeekView ) |
1186 | mWidStack->raiseWidget( mWeekView ); | 1185 | mWidStack->raiseWidget( mWeekView ); |
1187 | else | 1186 | else |
1188 | mWidStack->raiseWidget( mMonthView ); | 1187 | mWidStack->raiseWidget( mMonthView ); |
1189 | #endif | 1188 | #endif |
1190 | 1189 | ||
1191 | emit incidenceSelected( 0 ); | 1190 | emit incidenceSelected( 0 ); |
1192 | 1191 | ||
1193 | mComputeLayoutTimer = new QTimer( this ); | 1192 | mComputeLayoutTimer = new QTimer( this ); |
1194 | connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); | 1193 | connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); |
1195 | 1194 | ||
1196 | 1195 | ||
1197 | #ifndef DESKTOP_VERSION | 1196 | #ifndef DESKTOP_VERSION |
1198 | resize( QApplication::desktop()->size() ); | 1197 | resize( QApplication::desktop()->size() ); |
1199 | #else | 1198 | #else |
1200 | resize(640, 480 ); | 1199 | resize(640, 480 ); |
1201 | updatePossible = true; | 1200 | updatePossible = true; |
1202 | #endif | 1201 | #endif |
1203 | computeLayout(); | 1202 | computeLayout(); |
1204 | 1203 | ||
1205 | if ( mShowWeekView ) | 1204 | if ( mShowWeekView ) |
1206 | mWidStack->raiseWidget( mWeekView ); | 1205 | mWidStack->raiseWidget( mWeekView ); |
1207 | else | 1206 | else |
1208 | mWidStack->raiseWidget( mMonthView ); | 1207 | mWidStack->raiseWidget( mMonthView ); |
1209 | } | 1208 | } |
1210 | 1209 | ||
1211 | KOMonthView::~KOMonthView() | 1210 | KOMonthView::~KOMonthView() |
1212 | { | 1211 | { |
1213 | delete mContextMenu; | 1212 | delete mContextMenu; |
1214 | } | 1213 | } |
1215 | 1214 | ||
1216 | void KOMonthView::selectInternalWeekNum ( int n ) | 1215 | void KOMonthView::selectInternalWeekNum ( int n ) |
1217 | { | 1216 | { |
1218 | switchView(); | 1217 | switchView(); |
1219 | if ( !KOPrefs::instance()->mMonthViewWeek ) | 1218 | if ( !KOPrefs::instance()->mMonthViewWeek ) |
1220 | emit selectMonth (); | 1219 | emit selectMonth (); |
1221 | else | 1220 | else |
1222 | emit selectWeekNum ( n ); | 1221 | emit selectWeekNum ( n ); |
1223 | } | 1222 | } |
1224 | 1223 | ||
1225 | int KOMonthView::currentWeek() | 1224 | int KOMonthView::currentWeek() |
1226 | { | 1225 | { |
1227 | if ( mShowWeekView ) | 1226 | if ( mShowWeekView ) |
1228 | return mWeekLabelsW[0]->getWeekNum(); | 1227 | return mWeekLabelsW[0]->getWeekNum(); |
1229 | return mWeekLabels[0]->getWeekNum(); | 1228 | return mWeekLabels[0]->getWeekNum(); |
1230 | } | 1229 | } |
1231 | void KOMonthView::switchView() | 1230 | void KOMonthView::switchView() |
1232 | { | 1231 | { |
1233 | if ( selectedCell( ) ) | 1232 | if ( selectedCell( ) ) |
1234 | selectedCell()->deselect(); | 1233 | selectedCell()->deselect(); |
1235 | mShowWeekView = !mShowWeekView; | 1234 | mShowWeekView = !mShowWeekView; |
1236 | KOPrefs::instance()->mMonthViewWeek = mShowWeekView; | 1235 | KOPrefs::instance()->mMonthViewWeek = mShowWeekView; |
1237 | if ( clPending ) { | 1236 | if ( clPending ) { |
1238 | computeLayout(); | 1237 | computeLayout(); |
1239 | updateConfig(); | 1238 | updateConfig(); |
1240 | } | 1239 | } |
1241 | if ( mShowWeekView ) | 1240 | if ( mShowWeekView ) |
1242 | mWidStack->raiseWidget( mWeekView ); | 1241 | mWidStack->raiseWidget( mWeekView ); |
1243 | else | 1242 | else |
1244 | mWidStack->raiseWidget( mMonthView ); | 1243 | mWidStack->raiseWidget( mMonthView ); |
1245 | clPending = false; | 1244 | clPending = false; |
1246 | } | 1245 | } |
1247 | 1246 | ||
1248 | int KOMonthView::maxDatesHint() | 1247 | int KOMonthView::maxDatesHint() |
1249 | { | 1248 | { |
1250 | return mNumCells; | 1249 | return mNumCells; |
1251 | } | 1250 | } |
1252 | 1251 | ||
1253 | int KOMonthView::currentDateCount() | 1252 | int KOMonthView::currentDateCount() |
1254 | { | 1253 | { |
1255 | return mNumCells; | 1254 | return mNumCells; |
1256 | } | 1255 | } |
1257 | 1256 | ||
1258 | QPtrList<Incidence> KOMonthView::selectedIncidences() | 1257 | QPtrList<Incidence> KOMonthView::selectedIncidences() |
1259 | { | 1258 | { |
1260 | QPtrList<Incidence> selected; | 1259 | QPtrList<Incidence> selected; |
1261 | 1260 | ||
1262 | if ( mSelectedCell ) { | 1261 | if ( mSelectedCell ) { |
1263 | Incidence *incidence = mSelectedCell->selectedIncidence(); | 1262 | Incidence *incidence = mSelectedCell->selectedIncidence(); |
1264 | if ( incidence ) selected.append( incidence ); | 1263 | if ( incidence ) selected.append( incidence ); |
1265 | } | 1264 | } |
1266 | 1265 | ||
1267 | return selected; | 1266 | return selected; |
1268 | } | 1267 | } |
1269 | 1268 | ||
1270 | DateList KOMonthView::selectedDates() | 1269 | DateList KOMonthView::selectedDates() |
1271 | { | 1270 | { |
1272 | DateList selected; | 1271 | DateList selected; |
1273 | 1272 | ||
1274 | if ( mSelectedCell ) { | 1273 | if ( mSelectedCell ) { |
1275 | QDate qd = mSelectedCell->selectedIncidenceDate(); | 1274 | QDate qd = mSelectedCell->selectedIncidenceDate(); |
1276 | if ( qd.isValid() ) selected.append( qd ); | 1275 | if ( qd.isValid() ) selected.append( qd ); |
1277 | } | 1276 | } |
1278 | 1277 | ||
1279 | return selected; | 1278 | return selected; |
1280 | } | 1279 | } |
1281 | 1280 | ||
1282 | void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, | 1281 | void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, |
1283 | const QDate &td) | 1282 | const QDate &td) |
1284 | { | 1283 | { |
1285 | #ifndef KORG_NOPRINTER | 1284 | #ifndef KORG_NOPRINTER |
1286 | calPrinter->preview(CalPrinter::Month, fd, td); | 1285 | calPrinter->preview(CalPrinter::Month, fd, td); |
1287 | #endif | 1286 | #endif |
1288 | } | 1287 | } |
1289 | 1288 | ||
1290 | void KOMonthView::updateConfig() | 1289 | void KOMonthView::updateConfig() |
1291 | { | 1290 | { |
1292 | 1291 | ||
1293 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); | 1292 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); |
1294 | 1293 | ||
1295 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { | 1294 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { |
1296 | mWeekStartsMonday = true; | 1295 | mWeekStartsMonday = true; |
1297 | } | 1296 | } |
1298 | QFontMetrics fontmetric(mDayLabels[0]->font()); | 1297 | QFontMetrics fontmetric(mDayLabels[0]->font()); |
1299 | mWidthLongDayLabel = 0; | 1298 | mWidthLongDayLabel = 0; |
1300 | 1299 | ||
1301 | for (int i = 0; i < 7; i++) { | 1300 | for (int i = 0; i < 7; i++) { |
1302 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); | 1301 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); |
1303 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; | 1302 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; |
1304 | } | 1303 | } |
1305 | bool temp = mShowSatSunComp ; | 1304 | bool temp = mShowSatSunComp ; |
1306 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; | 1305 | mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; |
1307 | if ( ! mShowWeekView ) { | 1306 | if ( ! mShowWeekView ) { |
1308 | if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) | 1307 | if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) |
1309 | computeLayout(); | 1308 | computeLayout(); |
1310 | } | 1309 | } |
1311 | updateDayLabels(); | 1310 | updateDayLabels(); |
1312 | //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); | 1311 | //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); |
1313 | //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; | 1312 | //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; |
1314 | //resizeEvent( 0 ); | 1313 | //resizeEvent( 0 ); |
1315 | for (uint i = 0; i < mCells.count(); ++i) { | 1314 | for (uint i = 0; i < mCells.count(); ++i) { |
1316 | mCells[i]->updateConfig(); | 1315 | mCells[i]->updateConfig(); |
1317 | } | 1316 | } |
1318 | 1317 | ||
1319 | for (uint i = 0; i < mCellsW.count(); ++i) { | 1318 | for (uint i = 0; i < mCellsW.count(); ++i) { |
1320 | mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); | 1319 | mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); |
1321 | } | 1320 | } |
1322 | #ifdef DESKTOP_VERSION | 1321 | #ifdef DESKTOP_VERSION |
1323 | MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); | 1322 | MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); |
1324 | #endif | 1323 | #endif |
1325 | updateView(); | 1324 | updateView(); |
1326 | } | 1325 | } |
1327 | 1326 | ||
1328 | void KOMonthView::updateDayLabels() | 1327 | void KOMonthView::updateDayLabels() |
1329 | { | 1328 | { |
1330 | 1329 | ||
1331 | QPtrVector<QLabel> *mDayLabelsT; | 1330 | QPtrVector<QLabel> *mDayLabelsT; |
1332 | 1331 | ||
1333 | mDayLabelsT = &mDayLabelsW; | 1332 | mDayLabelsT = &mDayLabelsW; |
1334 | for (int i = 0; i < 7; i++) { | 1333 | for (int i = 0; i < 7; i++) { |
1335 | { | 1334 | { |
1336 | bool show = mShortDayLabelsW; | 1335 | bool show = mShortDayLabelsW; |
1337 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) | 1336 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) |
1338 | show = true; | 1337 | show = true; |
1339 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); | 1338 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); |
1340 | } | 1339 | } |
1341 | } | 1340 | } |
1342 | mDayLabelsT = &mDayLabels; | 1341 | mDayLabelsT = &mDayLabels; |
1343 | for (int i = 0; i < 7; i++) { | 1342 | for (int i = 0; i < 7; i++) { |
1344 | if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) { | 1343 | if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) { |
1345 | bool show = mShortDayLabelsM; | 1344 | bool show = mShortDayLabelsM; |
1346 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) | 1345 | if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) |
1347 | show = true; | 1346 | show = true; |
1348 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); | 1347 | (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); |
1349 | } else { | 1348 | } else { |
1350 | if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); | 1349 | if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); |
1351 | else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); | 1350 | else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); |
1352 | 1351 | ||
1353 | } | 1352 | } |
1354 | } | 1353 | } |
1355 | 1354 | ||
1356 | } | 1355 | } |
1357 | 1356 | ||
1358 | void KOMonthView::showDates(const QDate &start, const QDate &) | 1357 | void KOMonthView::showDates(const QDate &start, const QDate &) |
1359 | { | 1358 | { |
1360 | // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; | 1359 | // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; |
1361 | 1360 | ||
1362 | QPtrVector<MonthViewCell> *cells; | 1361 | QPtrVector<MonthViewCell> *cells; |
1363 | QPtrVector<QLabel> *dayLabels; | 1362 | QPtrVector<QLabel> *dayLabels; |
1364 | QPtrVector<KOWeekButton> *weekLabels; | 1363 | QPtrVector<KOWeekButton> *weekLabels; |
1365 | int weekNum = 6; | 1364 | int weekNum = 6; |
1366 | mStartDate = start; | 1365 | mStartDate = start; |
1367 | if ( mShowWeekView ) { | 1366 | if ( mShowWeekView ) { |
1368 | weekNum = 1; | 1367 | weekNum = 1; |
1369 | cells = &mCellsW; | 1368 | cells = &mCellsW; |
1370 | dayLabels = &mDayLabelsW; | 1369 | dayLabels = &mDayLabelsW; |
1371 | weekLabels = &mWeekLabelsW; | 1370 | weekLabels = &mWeekLabelsW; |
1372 | if ( !KGlobal::locale()->weekStartsMonday() ) { | 1371 | if ( !KGlobal::locale()->weekStartsMonday() ) { |
1373 | mStartDate = mStartDate.addDays( 1 ); | 1372 | mStartDate = mStartDate.addDays( 1 ); |
1374 | } | 1373 | } |
1375 | } else { | 1374 | } else { |
1376 | cells = &mCells; | 1375 | cells = &mCells; |
1377 | dayLabels = &mDayLabels; | 1376 | dayLabels = &mDayLabels; |
1378 | weekLabels = &mWeekLabels; | 1377 | weekLabels = &mWeekLabels; |
1379 | } | 1378 | } |
1380 | 1379 | ||
1381 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); | 1380 | int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); |
1382 | 1381 | ||
1383 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { | 1382 | if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { |
1384 | mWeekStartsMonday = true; | 1383 | mWeekStartsMonday = true; |
1385 | } | 1384 | } |
1386 | int startWeekDay = mWeekStartsMonday ? 1 : 7; | 1385 | int startWeekDay = mWeekStartsMonday ? 1 : 7; |
1387 | 1386 | ||
1388 | while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { | 1387 | while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { |
1389 | mStartDate = mStartDate.addDays( -1 ); | 1388 | mStartDate = mStartDate.addDays( -1 ); |
1390 | } | 1389 | } |
1391 | bool primary = false; | 1390 | bool primary = false; |
1392 | uint i; | 1391 | uint i; |
1393 | for( i = 0; i < (*cells).size(); ++i ) { | 1392 | for( i = 0; i < (*cells).size(); ++i ) { |
1394 | QDate date = mStartDate.addDays( i ); | 1393 | QDate date = mStartDate.addDays( i ); |
1395 | (*cells)[i]->setDate( date ); | 1394 | (*cells)[i]->setDate( date ); |
1396 | 1395 | ||
1397 | #ifndef KORG_NOPLUGINS | 1396 | #ifndef KORG_NOPLUGINS |
1398 | // add holiday, if present | 1397 | // add holiday, if present |
1399 | QString hstring(KOCore::self()->holiday(date)); | 1398 | QString hstring(KOCore::self()->holiday(date)); |
1400 | (*cells)[i]->setHoliday( hstring ); | 1399 | (*cells)[i]->setHoliday( hstring ); |
1401 | #endif | 1400 | #endif |
1402 | 1401 | ||
1403 | } | 1402 | } |
1404 | QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); | 1403 | QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); |
1405 | for( i = 0; i < weekNum; ++i ) { | 1404 | for( i = 0; i < weekNum; ++i ) { |
1406 | int wno; | 1405 | int wno; |
1407 | // remember, according to ISO 8601, the first week of the year is the | 1406 | // remember, according to ISO 8601, the first week of the year is the |
1408 | // first week that contains a thursday. Thus we must subtract off 4, | 1407 | // first week that contains a thursday. Thus we must subtract off 4, |
1409 | // not just 1. | 1408 | // not just 1. |
1410 | int dayOfYear = date.dayOfYear(); | 1409 | int dayOfYear = date.dayOfYear(); |
1411 | if (dayOfYear % 7 != 0) | 1410 | if (dayOfYear % 7 != 0) |
1412 | wno = dayOfYear / 7 + 1; | 1411 | wno = dayOfYear / 7 + 1; |
1413 | else | 1412 | else |
1414 | wno =dayOfYear / 7; | 1413 | wno =dayOfYear / 7; |
1415 | (*weekLabels)[i]->setWeekNum( wno ); | 1414 | (*weekLabels)[i]->setWeekNum( wno ); |
1416 | date = date.addDays( 7 ); | 1415 | date = date.addDays( 7 ); |
1417 | } | 1416 | } |
1418 | updateView(); | 1417 | updateView(); |
1419 | } | 1418 | } |
1420 | 1419 | ||
1421 | void KOMonthView::showEvents(QPtrList<Event>) | 1420 | void KOMonthView::showEvents(QPtrList<Event>) |
1422 | { | 1421 | { |
1423 | qDebug("KOMonthView::selectEvents is not implemented yet. "); | 1422 | qDebug("KOMonthView::selectEvents is not implemented yet. "); |
1424 | } | 1423 | } |
1425 | 1424 | ||
1426 | void KOMonthView::changeEventDisplay(Event *, int) | 1425 | void KOMonthView::changeEventDisplay(Event *, int) |
1427 | { | 1426 | { |
1428 | // this should be re-written to be much more efficient, but this | 1427 | // this should be re-written to be much more efficient, but this |
1429 | // quick-and-dirty-hack gets the job done for right now. | 1428 | // quick-and-dirty-hack gets the job done for right now. |
1430 | //qDebug("KOMonthView::changeEventDisplay "); | 1429 | //qDebug("KOMonthView::changeEventDisplay "); |
1431 | updateView(); | 1430 | updateView(); |
1432 | } | 1431 | } |
1433 | 1432 | ||
1434 | void KOMonthView::updateView() | 1433 | void KOMonthView::updateView() |
1435 | { | 1434 | { |
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 9a36939..a312ba5 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,696 +1,697 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library 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 GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #include "incidence.h" | 27 | #include "incidence.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | 29 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | 31 | ||
32 | Incidence::Incidence() : | 32 | Incidence::Incidence() : |
33 | IncidenceBase(), | 33 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 35 | { |
36 | mRecurrence = new Recurrence(this); | 36 | mRecurrence = new Recurrence(this); |
37 | mCancelled = false; | 37 | mCancelled = false; |
38 | recreate(); | 38 | recreate(); |
39 | mHasStartDate = true; | 39 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 40 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 41 | mAttachments.setAutoDelete(true); |
42 | mHasRecurrenceID = false; | 42 | mHasRecurrenceID = false; |
43 | mHoliday = false; | 43 | mHoliday = false; |
44 | mBirthday = false; | 44 | mBirthday = false; |
45 | mAnniversary = false; | 45 | mAnniversary = false; |
46 | 46 | ||
47 | } | 47 | } |
48 | 48 | ||
49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
50 | { | 50 | { |
51 | // TODO: reenable attributes currently commented out. | 51 | // TODO: reenable attributes currently commented out. |
52 | mRevision = i.mRevision; | 52 | mRevision = i.mRevision; |
53 | mCreated = i.mCreated; | 53 | mCreated = i.mCreated; |
54 | mDescription = i.mDescription; | 54 | mDescription = i.mDescription; |
55 | mSummary = i.mSummary; | 55 | mSummary = i.mSummary; |
56 | mCategories = i.mCategories; | 56 | mCategories = i.mCategories; |
57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
58 | mRelatedTo = 0; | 58 | mRelatedTo = 0; |
59 | mRelatedToUid = i.mRelatedToUid; | 59 | mRelatedToUid = i.mRelatedToUid; |
60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
61 | mExDates = i.mExDates; | 61 | mExDates = i.mExDates; |
62 | mAttachments = i.mAttachments; | 62 | mAttachments = i.mAttachments; |
63 | mResources = i.mResources; | 63 | mResources = i.mResources; |
64 | mSecrecy = i.mSecrecy; | 64 | mSecrecy = i.mSecrecy; |
65 | mPriority = i.mPriority; | 65 | mPriority = i.mPriority; |
66 | mLocation = i.mLocation; | 66 | mLocation = i.mLocation; |
67 | mCancelled = i.mCancelled; | 67 | mCancelled = i.mCancelled; |
68 | mHasStartDate = i.mHasStartDate; | 68 | mHasStartDate = i.mHasStartDate; |
69 | QPtrListIterator<Alarm> it( i.mAlarms ); | 69 | QPtrListIterator<Alarm> it( i.mAlarms ); |
70 | const Alarm *a; | 70 | const Alarm *a; |
71 | while( (a = it.current()) ) { | 71 | while( (a = it.current()) ) { |
72 | Alarm *b = new Alarm( *a ); | 72 | Alarm *b = new Alarm( *a ); |
73 | b->setParent( this ); | 73 | b->setParent( this ); |
74 | mAlarms.append( b ); | 74 | mAlarms.append( b ); |
75 | 75 | ||
76 | ++it; | 76 | ++it; |
77 | } | 77 | } |
78 | mAlarms.setAutoDelete(true); | 78 | mAlarms.setAutoDelete(true); |
79 | mHasRecurrenceID = i.mHasRecurrenceID; | 79 | mHasRecurrenceID = i.mHasRecurrenceID; |
80 | mRecurrenceID = i.mRecurrenceID; | 80 | mRecurrenceID = i.mRecurrenceID; |
81 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 81 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
82 | mHoliday = i.mHoliday ; | 82 | mHoliday = i.mHoliday ; |
83 | mBirthday = i.mBirthday; | 83 | mBirthday = i.mBirthday; |
84 | mAnniversary = i.mAnniversary; | 84 | mAnniversary = i.mAnniversary; |
85 | } | 85 | } |
86 | 86 | ||
87 | Incidence::~Incidence() | 87 | Incidence::~Incidence() |
88 | { | 88 | { |
89 | 89 | ||
90 | Incidence *ev; | 90 | Incidence *ev; |
91 | QPtrList<Incidence> Relations = relations(); | 91 | QPtrList<Incidence> Relations = relations(); |
92 | for (ev=Relations.first();ev;ev=Relations.next()) { | 92 | for (ev=Relations.first();ev;ev=Relations.next()) { |
93 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 93 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
94 | } | 94 | } |
95 | if (relatedTo()) relatedTo()->removeRelation(this); | 95 | if (relatedTo()) relatedTo()->removeRelation(this); |
96 | delete mRecurrence; | 96 | delete mRecurrence; |
97 | 97 | ||
98 | } | 98 | } |
99 | 99 | ||
100 | bool Incidence::isHoliday() const | 100 | bool Incidence::isHoliday() const |
101 | { | 101 | { |
102 | return mHoliday; | 102 | return mHoliday; |
103 | } | 103 | } |
104 | bool Incidence::isBirthday() const | 104 | bool Incidence::isBirthday() const |
105 | { | 105 | { |
106 | 106 | ||
107 | return mBirthday ; | 107 | return mBirthday ; |
108 | } | 108 | } |
109 | bool Incidence::isAnniversary() const | 109 | bool Incidence::isAnniversary() const |
110 | { | 110 | { |
111 | return mAnniversary ; | 111 | return mAnniversary ; |
112 | 112 | ||
113 | } | 113 | } |
114 | 114 | ||
115 | bool Incidence::hasRecurrenceID() const | 115 | bool Incidence::hasRecurrenceID() const |
116 | { | 116 | { |
117 | return mHasRecurrenceID; | 117 | return mHasRecurrenceID; |
118 | } | 118 | } |
119 | 119 | ||
120 | void Incidence::setHasRecurrenceID( bool b ) | 120 | void Incidence::setHasRecurrenceID( bool b ) |
121 | { | 121 | { |
122 | mHasRecurrenceID = b; | 122 | mHasRecurrenceID = b; |
123 | } | 123 | } |
124 | 124 | ||
125 | void Incidence::setRecurrenceID(QDateTime d) | 125 | void Incidence::setRecurrenceID(QDateTime d) |
126 | { | 126 | { |
127 | mRecurrenceID = d; | 127 | mRecurrenceID = d; |
128 | mHasRecurrenceID = true; | 128 | mHasRecurrenceID = true; |
129 | updated(); | 129 | updated(); |
130 | } | 130 | } |
131 | QDateTime Incidence::recurrenceID () const | 131 | QDateTime Incidence::recurrenceID () const |
132 | { | 132 | { |
133 | return mRecurrenceID; | 133 | return mRecurrenceID; |
134 | } | 134 | } |
135 | 135 | ||
136 | bool Incidence::cancelled() const | 136 | bool Incidence::cancelled() const |
137 | { | 137 | { |
138 | return mCancelled; | 138 | return mCancelled; |
139 | } | 139 | } |
140 | void Incidence::setCancelled( bool b ) | 140 | void Incidence::setCancelled( bool b ) |
141 | { | 141 | { |
142 | mCancelled = b; | 142 | mCancelled = b; |
143 | updated(); | 143 | updated(); |
144 | } | 144 | } |
145 | bool Incidence::hasStartDate() const | 145 | bool Incidence::hasStartDate() const |
146 | { | 146 | { |
147 | return mHasStartDate; | 147 | return mHasStartDate; |
148 | } | 148 | } |
149 | 149 | ||
150 | void Incidence::setHasStartDate(bool f) | 150 | void Incidence::setHasStartDate(bool f) |
151 | { | 151 | { |
152 | if (mReadOnly) return; | 152 | if (mReadOnly) return; |
153 | mHasStartDate = f; | 153 | mHasStartDate = f; |
154 | updated(); | 154 | updated(); |
155 | } | 155 | } |
156 | 156 | ||
157 | // A string comparison that considers that null and empty are the same | 157 | // A string comparison that considers that null and empty are the same |
158 | static bool stringCompare( const QString& s1, const QString& s2 ) | 158 | static bool stringCompare( const QString& s1, const QString& s2 ) |
159 | { | 159 | { |
160 | if ( s1.isEmpty() && s2.isEmpty() ) | 160 | if ( s1.isEmpty() && s2.isEmpty() ) |
161 | return true; | 161 | return true; |
162 | return s1 == s2; | 162 | return s1 == s2; |
163 | } | 163 | } |
164 | 164 | ||
165 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 165 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
166 | { | 166 | { |
167 | 167 | ||
168 | if( i1.alarms().count() != i2.alarms().count() ) { | 168 | if( i1.alarms().count() != i2.alarms().count() ) { |
169 | return false; // no need to check further | 169 | return false; // no need to check further |
170 | } | 170 | } |
171 | if ( i1.alarms().count() > 0 ) { | 171 | if ( i1.alarms().count() > 0 ) { |
172 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 172 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
173 | { | 173 | { |
174 | qDebug("alarm not equal "); | 174 | qDebug("alarm not equal "); |
175 | return false; | 175 | return false; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | #if 0 | 178 | #if 0 |
179 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 179 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
180 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 180 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
181 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 181 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
182 | if( *a1.current() == *a2.current() ) { | 182 | if( *a1.current() == *a2.current() ) { |
183 | continue; | 183 | continue; |
184 | } | 184 | } |
185 | else { | 185 | else { |
186 | return false; | 186 | return false; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | #endif | 189 | #endif |
190 | 190 | ||
191 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { | 191 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { |
192 | if ( i1.hasRecurrenceID() ) { | 192 | if ( i1.hasRecurrenceID() ) { |
193 | if ( i1.recurrenceID() != i2.recurrenceID() ) | 193 | if ( i1.recurrenceID() != i2.recurrenceID() ) |
194 | return false; | 194 | return false; |
195 | } | 195 | } |
196 | 196 | ||
197 | } else { | 197 | } else { |
198 | return false; | 198 | return false; |
199 | } | 199 | } |
200 | 200 | ||
201 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 201 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
202 | return false; | 202 | return false; |
203 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 203 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
204 | if ( i1.hasStartDate() ) { | 204 | if ( i1.hasStartDate() ) { |
205 | if ( i1.dtStart() != i2.dtStart() ) | 205 | if ( i1.dtStart() != i2.dtStart() ) |
206 | return false; | 206 | return false; |
207 | } | 207 | } |
208 | } else { | 208 | } else { |
209 | return false; | 209 | return false; |
210 | } | 210 | } |
211 | if (!( *i1.recurrence() == *i2.recurrence()) ) { | 211 | if (!( *i1.recurrence() == *i2.recurrence()) ) { |
212 | qDebug("recurrence is NOT equal "); | 212 | qDebug("recurrence is NOT equal "); |
213 | return false; | 213 | return false; |
214 | } | 214 | } |
215 | return | 215 | return |
216 | // i1.created() == i2.created() && | 216 | // i1.created() == i2.created() && |
217 | stringCompare( i1.description(), i2.description() ) && | 217 | stringCompare( i1.description(), i2.description() ) && |
218 | stringCompare( i1.summary(), i2.summary() ) && | 218 | stringCompare( i1.summary(), i2.summary() ) && |
219 | i1.categories() == i2.categories() && | 219 | i1.categories() == i2.categories() && |
220 | // no need to compare mRelatedTo | 220 | // no need to compare mRelatedTo |
221 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 221 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
222 | // i1.relations() == i2.relations() && | 222 | // i1.relations() == i2.relations() && |
223 | i1.exDates() == i2.exDates() && | 223 | i1.exDates() == i2.exDates() && |
224 | i1.attachments() == i2.attachments() && | 224 | i1.attachments() == i2.attachments() && |
225 | i1.resources() == i2.resources() && | 225 | i1.resources() == i2.resources() && |
226 | i1.secrecy() == i2.secrecy() && | 226 | i1.secrecy() == i2.secrecy() && |
227 | i1.priority() == i2.priority() && | 227 | i1.priority() == i2.priority() && |
228 | i1.cancelled() == i2.cancelled() && | 228 | i1.cancelled() == i2.cancelled() && |
229 | stringCompare( i1.location(), i2.location() ); | 229 | stringCompare( i1.location(), i2.location() ); |
230 | } | 230 | } |
231 | 231 | ||
232 | Incidence* Incidence::recreateCloneException( QDate d ) | 232 | Incidence* Incidence::recreateCloneException( QDate d ) |
233 | { | 233 | { |
234 | Incidence* newInc = clone(); | 234 | Incidence* newInc = clone(); |
235 | newInc->recreate(); | 235 | newInc->recreate(); |
236 | if ( doesRecur() ) { | 236 | if ( doesRecur() ) { |
237 | addExDate( d ); | 237 | addExDate( d ); |
238 | newInc->recurrence()->unsetRecurs(); | 238 | newInc->recurrence()->unsetRecurs(); |
239 | if ( type() == "Event") { | 239 | if ( type() == "Event") { |
240 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | 240 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); |
241 | QTime tim = dtStart().time(); | 241 | QTime tim = dtStart().time(); |
242 | newInc->setDtStart( QDateTime(d, tim) ); | 242 | newInc->setDtStart( QDateTime(d, tim) ); |
243 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | 243 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); |
244 | } else { | 244 | } else { |
245 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); | 245 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); |
246 | QTime tim = ((Todo*)this)->dtDue().time(); | 246 | QTime tim = ((Todo*)this)->dtDue().time(); |
247 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); | 247 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); |
248 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); | 248 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); |
249 | ((Todo*)this)->setRecurDates(); | 249 | ((Todo*)this)->setRecurDates(); |
250 | } | 250 | } |
251 | newInc->setExDates( DateList () ); | ||
251 | } | 252 | } |
252 | return newInc; | 253 | return newInc; |
253 | } | 254 | } |
254 | 255 | ||
255 | void Incidence::recreate() | 256 | void Incidence::recreate() |
256 | { | 257 | { |
257 | setCreated(QDateTime::currentDateTime()); | 258 | setCreated(QDateTime::currentDateTime()); |
258 | 259 | ||
259 | setUid(CalFormat::createUniqueId()); | 260 | setUid(CalFormat::createUniqueId()); |
260 | 261 | ||
261 | setRevision(0); | 262 | setRevision(0); |
262 | setIDStr( ":" ); | 263 | setIDStr( ":" ); |
263 | setLastModified(QDateTime::currentDateTime()); | 264 | setLastModified(QDateTime::currentDateTime()); |
264 | } | 265 | } |
265 | 266 | ||
266 | void Incidence::setReadOnly( bool readOnly ) | 267 | void Incidence::setReadOnly( bool readOnly ) |
267 | { | 268 | { |
268 | IncidenceBase::setReadOnly( readOnly ); | 269 | IncidenceBase::setReadOnly( readOnly ); |
269 | recurrence()->setRecurReadOnly( readOnly); | 270 | recurrence()->setRecurReadOnly( readOnly); |
270 | } | 271 | } |
271 | 272 | ||
272 | void Incidence::setCreated(QDateTime created) | 273 | void Incidence::setCreated(QDateTime created) |
273 | { | 274 | { |
274 | if (mReadOnly) return; | 275 | if (mReadOnly) return; |
275 | mCreated = getEvenTime(created); | 276 | mCreated = getEvenTime(created); |
276 | } | 277 | } |
277 | 278 | ||
278 | QDateTime Incidence::created() const | 279 | QDateTime Incidence::created() const |
279 | { | 280 | { |
280 | return mCreated; | 281 | return mCreated; |
281 | } | 282 | } |
282 | 283 | ||
283 | void Incidence::setRevision(int rev) | 284 | void Incidence::setRevision(int rev) |
284 | { | 285 | { |
285 | if (mReadOnly) return; | 286 | if (mReadOnly) return; |
286 | mRevision = rev; | 287 | mRevision = rev; |
287 | 288 | ||
288 | updated(); | 289 | updated(); |
289 | } | 290 | } |
290 | 291 | ||
291 | int Incidence::revision() const | 292 | int Incidence::revision() const |
292 | { | 293 | { |
293 | return mRevision; | 294 | return mRevision; |
294 | } | 295 | } |
295 | 296 | ||
296 | void Incidence::setDtStart(const QDateTime &dtStart) | 297 | void Incidence::setDtStart(const QDateTime &dtStart) |
297 | { | 298 | { |
298 | 299 | ||
299 | QDateTime dt = getEvenTime(dtStart); | 300 | QDateTime dt = getEvenTime(dtStart); |
300 | recurrence()->setRecurStart( dt); | 301 | recurrence()->setRecurStart( dt); |
301 | IncidenceBase::setDtStart( dt ); | 302 | IncidenceBase::setDtStart( dt ); |
302 | } | 303 | } |
303 | 304 | ||
304 | void Incidence::setDescription(const QString &description) | 305 | void Incidence::setDescription(const QString &description) |
305 | { | 306 | { |
306 | if (mReadOnly) return; | 307 | if (mReadOnly) return; |
307 | mDescription = description; | 308 | mDescription = description; |
308 | updated(); | 309 | updated(); |
309 | } | 310 | } |
310 | 311 | ||
311 | QString Incidence::description() const | 312 | QString Incidence::description() const |
312 | { | 313 | { |
313 | return mDescription; | 314 | return mDescription; |
314 | } | 315 | } |
315 | 316 | ||
316 | 317 | ||
317 | void Incidence::setSummary(const QString &summary) | 318 | void Incidence::setSummary(const QString &summary) |
318 | { | 319 | { |
319 | if (mReadOnly) return; | 320 | if (mReadOnly) return; |
320 | mSummary = summary; | 321 | mSummary = summary; |
321 | updated(); | 322 | updated(); |
322 | } | 323 | } |
323 | 324 | ||
324 | QString Incidence::summary() const | 325 | QString Incidence::summary() const |
325 | { | 326 | { |
326 | return mSummary; | 327 | return mSummary; |
327 | } | 328 | } |
328 | void Incidence::checkCategories() | 329 | void Incidence::checkCategories() |
329 | { | 330 | { |
330 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); | 331 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); |
331 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); | 332 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); |
332 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); | 333 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); |
333 | } | 334 | } |
334 | 335 | ||
335 | void Incidence::setCategories(const QStringList &categories) | 336 | void Incidence::setCategories(const QStringList &categories) |
336 | { | 337 | { |
337 | if (mReadOnly) return; | 338 | if (mReadOnly) return; |
338 | mCategories = categories; | 339 | mCategories = categories; |
339 | checkCategories(); | 340 | checkCategories(); |
340 | updated(); | 341 | updated(); |
341 | } | 342 | } |
342 | 343 | ||
343 | // TODO: remove setCategories(QString) function | 344 | // TODO: remove setCategories(QString) function |
344 | void Incidence::setCategories(const QString &catStr) | 345 | void Incidence::setCategories(const QString &catStr) |
345 | { | 346 | { |
346 | if (mReadOnly) return; | 347 | if (mReadOnly) return; |
347 | mCategories.clear(); | 348 | mCategories.clear(); |
348 | 349 | ||
349 | if (catStr.isEmpty()) return; | 350 | if (catStr.isEmpty()) return; |
350 | 351 | ||
351 | mCategories = QStringList::split(",",catStr); | 352 | mCategories = QStringList::split(",",catStr); |
352 | 353 | ||
353 | QStringList::Iterator it; | 354 | QStringList::Iterator it; |
354 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 355 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
355 | *it = (*it).stripWhiteSpace(); | 356 | *it = (*it).stripWhiteSpace(); |
356 | } | 357 | } |
357 | checkCategories(); | 358 | checkCategories(); |
358 | updated(); | 359 | updated(); |
359 | } | 360 | } |
360 | 361 | ||
361 | QStringList Incidence::categories() const | 362 | QStringList Incidence::categories() const |
362 | { | 363 | { |
363 | return mCategories; | 364 | return mCategories; |
364 | } | 365 | } |
365 | 366 | ||
366 | QString Incidence::categoriesStr() | 367 | QString Incidence::categoriesStr() |
367 | { | 368 | { |
368 | return mCategories.join(","); | 369 | return mCategories.join(","); |
369 | } | 370 | } |
370 | 371 | ||
371 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 372 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
372 | { | 373 | { |
373 | if (mReadOnly) return; | 374 | if (mReadOnly) return; |
374 | mRelatedToUid = relatedToUid; | 375 | mRelatedToUid = relatedToUid; |
375 | } | 376 | } |
376 | 377 | ||
377 | QString Incidence::relatedToUid() const | 378 | QString Incidence::relatedToUid() const |
378 | { | 379 | { |
379 | return mRelatedToUid; | 380 | return mRelatedToUid; |
380 | } | 381 | } |
381 | 382 | ||
382 | void Incidence::setRelatedTo(Incidence *relatedTo) | 383 | void Incidence::setRelatedTo(Incidence *relatedTo) |
383 | { | 384 | { |
384 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 385 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
385 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 386 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
386 | if (mReadOnly || mRelatedTo == relatedTo) return; | 387 | if (mReadOnly || mRelatedTo == relatedTo) return; |
387 | if(mRelatedTo) { | 388 | if(mRelatedTo) { |
388 | // updated(); | 389 | // updated(); |
389 | mRelatedTo->removeRelation(this); | 390 | mRelatedTo->removeRelation(this); |
390 | } | 391 | } |
391 | mRelatedTo = relatedTo; | 392 | mRelatedTo = relatedTo; |
392 | if (mRelatedTo) mRelatedTo->addRelation(this); | 393 | if (mRelatedTo) mRelatedTo->addRelation(this); |
393 | } | 394 | } |
394 | 395 | ||
395 | Incidence *Incidence::relatedTo() const | 396 | Incidence *Incidence::relatedTo() const |
396 | { | 397 | { |
397 | return mRelatedTo; | 398 | return mRelatedTo; |
398 | } | 399 | } |
399 | 400 | ||
400 | QPtrList<Incidence> Incidence::relations() const | 401 | QPtrList<Incidence> Incidence::relations() const |
401 | { | 402 | { |
402 | return mRelations; | 403 | return mRelations; |
403 | } | 404 | } |
404 | 405 | ||
405 | void Incidence::addRelation(Incidence *event) | 406 | void Incidence::addRelation(Incidence *event) |
406 | { | 407 | { |
407 | if( mRelations.findRef( event ) == -1 ) { | 408 | if( mRelations.findRef( event ) == -1 ) { |
408 | mRelations.append(event); | 409 | mRelations.append(event); |
409 | //updated(); | 410 | //updated(); |
410 | } | 411 | } |
411 | } | 412 | } |
412 | 413 | ||
413 | void Incidence::removeRelation(Incidence *event) | 414 | void Incidence::removeRelation(Incidence *event) |
414 | { | 415 | { |
415 | 416 | ||
416 | mRelations.removeRef(event); | 417 | mRelations.removeRef(event); |
417 | 418 | ||
418 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 419 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
419 | } | 420 | } |
420 | 421 | ||
421 | bool Incidence::recursOn(const QDate &qd) const | 422 | bool Incidence::recursOn(const QDate &qd) const |
422 | { | 423 | { |
423 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; | 424 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; |
424 | else return false; | 425 | else return false; |
425 | } | 426 | } |
426 | 427 | ||
427 | void Incidence::setExDates(const DateList &exDates) | 428 | void Incidence::setExDates(const DateList &exDates) |
428 | { | 429 | { |
429 | if (mReadOnly) return; | 430 | if (mReadOnly) return; |
430 | mExDates = exDates; | 431 | mExDates = exDates; |
431 | 432 | ||
432 | recurrence()->setRecurExDatesCount(mExDates.count()); | 433 | recurrence()->setRecurExDatesCount(mExDates.count()); |
433 | 434 | ||
434 | updated(); | 435 | updated(); |
435 | } | 436 | } |
436 | 437 | ||
437 | void Incidence::addExDate(const QDate &date) | 438 | void Incidence::addExDate(const QDate &date) |
438 | { | 439 | { |
439 | if (mReadOnly) return; | 440 | if (mReadOnly) return; |
440 | mExDates.append(date); | 441 | mExDates.append(date); |
441 | 442 | ||
442 | recurrence()->setRecurExDatesCount(mExDates.count()); | 443 | recurrence()->setRecurExDatesCount(mExDates.count()); |
443 | 444 | ||
444 | updated(); | 445 | updated(); |
445 | } | 446 | } |
446 | 447 | ||
447 | DateList Incidence::exDates() const | 448 | DateList Incidence::exDates() const |
448 | { | 449 | { |
449 | return mExDates; | 450 | return mExDates; |
450 | } | 451 | } |
451 | 452 | ||
452 | bool Incidence::isException(const QDate &date) const | 453 | bool Incidence::isException(const QDate &date) const |
453 | { | 454 | { |
454 | DateList::ConstIterator it; | 455 | DateList::ConstIterator it; |
455 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 456 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
456 | if ( (*it) == date ) { | 457 | if ( (*it) == date ) { |
457 | return true; | 458 | return true; |
458 | } | 459 | } |
459 | } | 460 | } |
460 | 461 | ||
461 | return false; | 462 | return false; |
462 | } | 463 | } |
463 | 464 | ||
464 | void Incidence::addAttachment(Attachment *attachment) | 465 | void Incidence::addAttachment(Attachment *attachment) |
465 | { | 466 | { |
466 | if (mReadOnly || !attachment) return; | 467 | if (mReadOnly || !attachment) return; |
467 | mAttachments.append(attachment); | 468 | mAttachments.append(attachment); |
468 | updated(); | 469 | updated(); |
469 | } | 470 | } |
470 | 471 | ||
471 | void Incidence::deleteAttachment(Attachment *attachment) | 472 | void Incidence::deleteAttachment(Attachment *attachment) |
472 | { | 473 | { |
473 | mAttachments.removeRef(attachment); | 474 | mAttachments.removeRef(attachment); |
474 | } | 475 | } |
475 | 476 | ||
476 | void Incidence::deleteAttachments(const QString& mime) | 477 | void Incidence::deleteAttachments(const QString& mime) |
477 | { | 478 | { |
478 | Attachment *at = mAttachments.first(); | 479 | Attachment *at = mAttachments.first(); |
479 | while (at) { | 480 | while (at) { |
480 | if (at->mimeType() == mime) | 481 | if (at->mimeType() == mime) |
481 | mAttachments.remove(); | 482 | mAttachments.remove(); |
482 | else | 483 | else |
483 | at = mAttachments.next(); | 484 | at = mAttachments.next(); |
484 | } | 485 | } |
485 | } | 486 | } |
486 | 487 | ||
487 | QPtrList<Attachment> Incidence::attachments() const | 488 | QPtrList<Attachment> Incidence::attachments() const |
488 | { | 489 | { |
489 | return mAttachments; | 490 | return mAttachments; |
490 | } | 491 | } |
491 | 492 | ||
492 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 493 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const |
493 | { | 494 | { |
494 | QPtrList<Attachment> attachments; | 495 | QPtrList<Attachment> attachments; |
495 | QPtrListIterator<Attachment> it( mAttachments ); | 496 | QPtrListIterator<Attachment> it( mAttachments ); |
496 | Attachment *at; | 497 | Attachment *at; |
497 | while ( (at = it.current()) ) { | 498 | while ( (at = it.current()) ) { |
498 | if (at->mimeType() == mime) | 499 | if (at->mimeType() == mime) |
499 | attachments.append(at); | 500 | attachments.append(at); |
500 | ++it; | 501 | ++it; |
501 | } | 502 | } |
502 | 503 | ||
503 | return attachments; | 504 | return attachments; |
504 | } | 505 | } |
505 | 506 | ||
506 | void Incidence::setResources(const QStringList &resources) | 507 | void Incidence::setResources(const QStringList &resources) |
507 | { | 508 | { |
508 | if (mReadOnly) return; | 509 | if (mReadOnly) return; |
509 | mResources = resources; | 510 | mResources = resources; |
510 | updated(); | 511 | updated(); |
511 | } | 512 | } |
512 | 513 | ||
513 | QStringList Incidence::resources() const | 514 | QStringList Incidence::resources() const |
514 | { | 515 | { |
515 | return mResources; | 516 | return mResources; |
516 | } | 517 | } |
517 | 518 | ||
518 | 519 | ||
519 | void Incidence::setPriority(int priority) | 520 | void Incidence::setPriority(int priority) |
520 | { | 521 | { |
521 | if (mReadOnly) return; | 522 | if (mReadOnly) return; |
522 | mPriority = priority; | 523 | mPriority = priority; |
523 | updated(); | 524 | updated(); |
524 | } | 525 | } |
525 | 526 | ||
526 | int Incidence::priority() const | 527 | int Incidence::priority() const |
527 | { | 528 | { |
528 | return mPriority; | 529 | return mPriority; |
529 | } | 530 | } |
530 | 531 | ||
531 | void Incidence::setSecrecy(int sec) | 532 | void Incidence::setSecrecy(int sec) |
532 | { | 533 | { |
533 | if (mReadOnly) return; | 534 | if (mReadOnly) return; |
534 | mSecrecy = sec; | 535 | mSecrecy = sec; |
535 | updated(); | 536 | updated(); |
536 | } | 537 | } |
537 | 538 | ||
538 | int Incidence::secrecy() const | 539 | int Incidence::secrecy() const |
539 | { | 540 | { |
540 | return mSecrecy; | 541 | return mSecrecy; |
541 | } | 542 | } |
542 | 543 | ||
543 | QString Incidence::secrecyStr() const | 544 | QString Incidence::secrecyStr() const |
544 | { | 545 | { |
545 | return secrecyName(mSecrecy); | 546 | return secrecyName(mSecrecy); |
546 | } | 547 | } |
547 | 548 | ||
548 | QString Incidence::secrecyName(int secrecy) | 549 | QString Incidence::secrecyName(int secrecy) |
549 | { | 550 | { |
550 | switch (secrecy) { | 551 | switch (secrecy) { |
551 | case SecrecyPublic: | 552 | case SecrecyPublic: |
552 | return i18n("Public"); | 553 | return i18n("Public"); |
553 | break; | 554 | break; |
554 | case SecrecyPrivate: | 555 | case SecrecyPrivate: |
555 | return i18n("Private"); | 556 | return i18n("Private"); |
556 | break; | 557 | break; |
557 | case SecrecyConfidential: | 558 | case SecrecyConfidential: |
558 | return i18n("Confidential"); | 559 | return i18n("Confidential"); |
559 | break; | 560 | break; |
560 | default: | 561 | default: |
561 | return i18n("Undefined"); | 562 | return i18n("Undefined"); |
562 | break; | 563 | break; |
563 | } | 564 | } |
564 | } | 565 | } |
565 | 566 | ||
566 | QStringList Incidence::secrecyList() | 567 | QStringList Incidence::secrecyList() |
567 | { | 568 | { |
568 | QStringList list; | 569 | QStringList list; |
569 | list << secrecyName(SecrecyPublic); | 570 | list << secrecyName(SecrecyPublic); |
570 | list << secrecyName(SecrecyPrivate); | 571 | list << secrecyName(SecrecyPrivate); |
571 | list << secrecyName(SecrecyConfidential); | 572 | list << secrecyName(SecrecyConfidential); |
572 | 573 | ||
573 | return list; | 574 | return list; |
574 | } | 575 | } |
575 | 576 | ||
576 | 577 | ||
577 | QPtrList<Alarm> Incidence::alarms() const | 578 | QPtrList<Alarm> Incidence::alarms() const |
578 | { | 579 | { |
579 | return mAlarms; | 580 | return mAlarms; |
580 | } | 581 | } |
581 | 582 | ||
582 | Alarm* Incidence::newAlarm() | 583 | Alarm* Incidence::newAlarm() |
583 | { | 584 | { |
584 | Alarm* alarm = new Alarm(this); | 585 | Alarm* alarm = new Alarm(this); |
585 | mAlarms.append(alarm); | 586 | mAlarms.append(alarm); |
586 | // updated(); | 587 | // updated(); |
587 | return alarm; | 588 | return alarm; |
588 | } | 589 | } |
589 | 590 | ||
590 | void Incidence::addAlarm(Alarm *alarm) | 591 | void Incidence::addAlarm(Alarm *alarm) |
591 | { | 592 | { |
592 | mAlarms.append(alarm); | 593 | mAlarms.append(alarm); |
593 | updated(); | 594 | updated(); |
594 | } | 595 | } |
595 | 596 | ||
596 | void Incidence::removeAlarm(Alarm *alarm) | 597 | void Incidence::removeAlarm(Alarm *alarm) |
597 | { | 598 | { |
598 | mAlarms.removeRef(alarm); | 599 | mAlarms.removeRef(alarm); |
599 | updated(); | 600 | updated(); |
600 | } | 601 | } |
601 | 602 | ||
602 | void Incidence::clearAlarms() | 603 | void Incidence::clearAlarms() |
603 | { | 604 | { |
604 | mAlarms.clear(); | 605 | mAlarms.clear(); |
605 | updated(); | 606 | updated(); |
606 | } | 607 | } |
607 | 608 | ||
608 | bool Incidence::isAlarmEnabled() const | 609 | bool Incidence::isAlarmEnabled() const |
609 | { | 610 | { |
610 | Alarm* alarm; | 611 | Alarm* alarm; |
611 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 612 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
612 | if (alarm->enabled()) | 613 | if (alarm->enabled()) |
613 | return true; | 614 | return true; |
614 | } | 615 | } |
615 | return false; | 616 | return false; |
616 | } | 617 | } |
617 | 618 | ||
618 | Recurrence *Incidence::recurrence() const | 619 | Recurrence *Incidence::recurrence() const |
619 | { | 620 | { |
620 | return mRecurrence; | 621 | return mRecurrence; |
621 | } | 622 | } |
622 | void Incidence::setRecurrence( Recurrence * r) | 623 | void Incidence::setRecurrence( Recurrence * r) |
623 | { | 624 | { |
624 | delete mRecurrence; | 625 | delete mRecurrence; |
625 | mRecurrence = r; | 626 | mRecurrence = r; |
626 | } | 627 | } |
627 | 628 | ||
628 | void Incidence::setLocation(const QString &location) | 629 | void Incidence::setLocation(const QString &location) |
629 | { | 630 | { |
630 | if (mReadOnly) return; | 631 | if (mReadOnly) return; |
631 | mLocation = location; | 632 | mLocation = location; |
632 | updated(); | 633 | updated(); |
633 | } | 634 | } |
634 | 635 | ||
635 | QString Incidence::location() const | 636 | QString Incidence::location() const |
636 | { | 637 | { |
637 | return mLocation; | 638 | return mLocation; |
638 | } | 639 | } |
639 | 640 | ||
640 | ushort Incidence::doesRecur() const | 641 | ushort Incidence::doesRecur() const |
641 | { | 642 | { |
642 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 643 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
643 | else return Recurrence::rNone; | 644 | else return Recurrence::rNone; |
644 | } | 645 | } |
645 | 646 | ||
646 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 647 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
647 | { | 648 | { |
648 | QDateTime incidenceStart = dt; | 649 | QDateTime incidenceStart = dt; |
649 | *ok = false; | 650 | *ok = false; |
650 | if ( doesRecur() ) { | 651 | if ( doesRecur() ) { |
651 | bool last; | 652 | bool last; |
652 | recurrence()->getPreviousDateTime( incidenceStart , &last ); | 653 | recurrence()->getPreviousDateTime( incidenceStart , &last ); |
653 | int count = 0; | 654 | int count = 0; |
654 | if ( !last ) { | 655 | if ( !last ) { |
655 | while ( !last ) { | 656 | while ( !last ) { |
656 | ++count; | 657 | ++count; |
657 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); | 658 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); |
658 | if ( recursOn( incidenceStart.date() ) ) { | 659 | if ( recursOn( incidenceStart.date() ) ) { |
659 | last = true; // exit while llop | 660 | last = true; // exit while llop |
660 | } else { | 661 | } else { |
661 | if ( last ) { // no alarm on last recurrence | 662 | if ( last ) { // no alarm on last recurrence |
662 | return QDateTime (); | 663 | return QDateTime (); |
663 | } | 664 | } |
664 | int year = incidenceStart.date().year(); | 665 | int year = incidenceStart.date().year(); |
665 | // workaround for bug in recurrence | 666 | // workaround for bug in recurrence |
666 | if ( count == 100 || year < 1000 || year > 5000 ) { | 667 | if ( count == 100 || year < 1000 || year > 5000 ) { |
667 | return QDateTime (); | 668 | return QDateTime (); |
668 | } | 669 | } |
669 | incidenceStart = incidenceStart.addSecs( 1 ); | 670 | incidenceStart = incidenceStart.addSecs( 1 ); |
670 | } | 671 | } |
671 | } | 672 | } |
672 | } else { | 673 | } else { |
673 | return QDateTime (); | 674 | return QDateTime (); |
674 | } | 675 | } |
675 | } else { | 676 | } else { |
676 | if ( hasStartDate () ) { | 677 | if ( hasStartDate () ) { |
677 | incidenceStart = dtStart(); | 678 | incidenceStart = dtStart(); |
678 | } | 679 | } |
679 | if ( type() =="Todo" ) { | 680 | if ( type() =="Todo" ) { |
680 | if ( ((Todo*)this)->hasDueDate() ) | 681 | if ( ((Todo*)this)->hasDueDate() ) |
681 | incidenceStart = ((Todo*)this)->dtDue(); | 682 | incidenceStart = ((Todo*)this)->dtDue(); |
682 | } | 683 | } |
683 | } | 684 | } |
684 | if ( incidenceStart > dt ) | 685 | if ( incidenceStart > dt ) |
685 | *ok = true; | 686 | *ok = true; |
686 | return incidenceStart; | 687 | return incidenceStart; |
687 | } | 688 | } |
688 | QDateTime Incidence::dtStart() const | 689 | QDateTime Incidence::dtStart() const |
689 | { | 690 | { |
690 | if ( doesRecur() ) { | 691 | if ( doesRecur() ) { |
691 | if ( type() == "Todo" ) { | 692 | if ( type() == "Todo" ) { |
692 | ((Todo*)this)->checkSetCompletedFalse(); | 693 | ((Todo*)this)->checkSetCompletedFalse(); |
693 | } | 694 | } |
694 | } | 695 | } |
695 | return mDtStart; | 696 | return mDtStart; |
696 | } | 697 | } |