-rw-r--r-- | korganizer/kodaymatrix.cpp | 6 | ||||
-rw-r--r-- | korganizer/kofilterview.cpp | 35 |
2 files changed, 25 insertions, 16 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index 30efbf6..3468657 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -1,1203 +1,1205 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> | 3 | Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> |
4 | Parts of the source code have been copied from kdpdatebutton.cpp | 4 | Parts of the source code have been copied from kdpdatebutton.cpp |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or | 8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | 9 | (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, | 11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. | 14 | GNU General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | 17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | 19 | ||
20 | As a special exception, permission is given to link this program | 20 | As a special exception, permission is given to link this program |
21 | with any edition of Qt, and distribute the resulting executable, | 21 | with any edition of Qt, and distribute the resulting executable, |
22 | without including the source ode for Qt in the source distribution. | 22 | without including the source ode for Qt in the source distribution. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <qevent.h> | 25 | #include <qevent.h> |
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qptrlist.h> | 27 | #include <qptrlist.h> |
28 | #include <qtimer.h> | 28 | #include <qtimer.h> |
29 | #include <qwhatsthis.h> | 29 | #include <qwhatsthis.h> |
30 | 30 | ||
31 | #include <kglobal.h> | 31 | #include <kglobal.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | 34 | ||
35 | #include <libkcal/vcaldrag.h> | 35 | #include <libkcal/vcaldrag.h> |
36 | #include <libkcal/icaldrag.h> | 36 | #include <libkcal/icaldrag.h> |
37 | #include <libkcal/dndfactory.h> | 37 | #include <libkcal/dndfactory.h> |
38 | #include <libkcal/calendarresources.h> | 38 | #include <libkcal/calendarresources.h> |
39 | #include <libkcal/resourcecalendar.h> | 39 | #include <libkcal/resourcecalendar.h> |
40 | #include <kresources/resourceselectdialog.h> | 40 | #include <kresources/resourceselectdialog.h> |
41 | 41 | ||
42 | #include <kcalendarsystem.h> | 42 | #include <kcalendarsystem.h> |
43 | 43 | ||
44 | #ifndef KORG_NOPLUGINS | 44 | #ifndef KORG_NOPLUGINS |
45 | #include "kocore.h" | 45 | #include "kocore.h" |
46 | #endif | 46 | #endif |
47 | #include "koprefs.h" | 47 | #include "koprefs.h" |
48 | #include "koglobals.h" | 48 | #include "koglobals.h" |
49 | 49 | ||
50 | #include "kodaymatrix.h" | 50 | #include "kodaymatrix.h" |
51 | 51 | ||
52 | // ============================================================================ | 52 | // ============================================================================ |
53 | // D Y N A M I C T I P | 53 | // D Y N A M I C T I P |
54 | // ============================================================================ | 54 | // ============================================================================ |
55 | 55 | ||
56 | DynamicTip::DynamicTip( QWidget * parent ) | 56 | DynamicTip::DynamicTip( QWidget * parent ) |
57 | : QToolTip( parent ) | 57 | : QToolTip( parent ) |
58 | { | 58 | { |
59 | matrix = (KODayMatrix*)parent; | 59 | matrix = (KODayMatrix*)parent; |
60 | } | 60 | } |
61 | 61 | ||
62 | class KODaymatrixWhatsThis :public QWhatsThis | 62 | class KODaymatrixWhatsThis :public QWhatsThis |
63 | { | 63 | { |
64 | public: | 64 | public: |
65 | KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; | 65 | KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; |
66 | ~KODaymatrixWhatsThis() { ; }; | 66 | ~KODaymatrixWhatsThis() { ; }; |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | virtual QString text( const QPoint& p ) | 69 | virtual QString text( const QPoint& p ) |
70 | { | 70 | { |
71 | return _view->getWhatsThisText( p ) ; | 71 | return _view->getWhatsThisText( p ) ; |
72 | } | 72 | } |
73 | private: | 73 | private: |
74 | KODayMatrix * _view; | 74 | KODayMatrix * _view; |
75 | }; | 75 | }; |
76 | 76 | ||
77 | void DynamicTip::maybeTip( const QPoint &pos ) | 77 | void DynamicTip::maybeTip( const QPoint &pos ) |
78 | { | 78 | { |
79 | //calculate which cell of the matrix the mouse is in | 79 | //calculate which cell of the matrix the mouse is in |
80 | QRect sz = matrix->frameRect(); | 80 | QRect sz = matrix->frameRect(); |
81 | int dheight = sz.height()*7 / 42; | 81 | int dheight = sz.height()*7 / 42; |
82 | int dwidth = sz.width() / 7; | 82 | int dwidth = sz.width() / 7; |
83 | int row = pos.y()/dheight; | 83 | int row = pos.y()/dheight; |
84 | int col = pos.x()/dwidth; | 84 | int col = pos.x()/dwidth; |
85 | 85 | ||
86 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); | 86 | QRect rct(col*dwidth, row*dheight, dwidth, dheight); |
87 | 87 | ||
88 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << | 88 | // kdDebug() << "DynamicTip::maybeTip matrix cell index [" << |
89 | // col << "][" << row << "] => " <<(col+row*7) << endl; | 89 | // col << "][" << row << "] => " <<(col+row*7) << endl; |
90 | 90 | ||
91 | //show holiday names only | 91 | //show holiday names only |
92 | QString str = matrix->getHolidayLabel(col+row*7); | 92 | QString str = matrix->getHolidayLabel(col+row*7); |
93 | if (str.isEmpty()) return; | 93 | if (str.isEmpty()) return; |
94 | tip(rct, str); | 94 | tip(rct, str); |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | // ============================================================================ | 98 | // ============================================================================ |
99 | // K O D A Y M A T R I X | 99 | // K O D A Y M A T R I X |
100 | // ============================================================================ | 100 | // ============================================================================ |
101 | 101 | ||
102 | const int KODayMatrix::NOSELECTION = -1000; | 102 | const int KODayMatrix::NOSELECTION = -1000; |
103 | const int KODayMatrix::NUMDAYS = 42; | 103 | const int KODayMatrix::NUMDAYS = 42; |
104 | 104 | ||
105 | KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) | 105 | KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) |
106 | : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) | 106 | : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) |
107 | 107 | ||
108 | 108 | ||
109 | { | 109 | { |
110 | mLastView = -1; | 110 | mLastView = -1; |
111 | oldW = 0; | 111 | oldW = 0; |
112 | oldH = 0; | 112 | oldH = 0; |
113 | myPix.resize( 150, 120 ); | 113 | myPix.resize( 150, 120 ); |
114 | mRedrawNeeded = true; | 114 | mRedrawNeeded = true; |
115 | mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); | 115 | mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); |
116 | mPendingUpdateBeforeRepaint = false; | 116 | mPendingUpdateBeforeRepaint = false; |
117 | mouseDown = false; | 117 | mouseDown = false; |
118 | // initialize dynamic arrays | 118 | // initialize dynamic arrays |
119 | bDays.resize ( NUMDAYS ); | 119 | bDays.resize ( NUMDAYS ); |
120 | pDays.resize ( NUMDAYS ); | 120 | pDays.resize ( NUMDAYS ); |
121 | hDays.resize ( NUMDAYS ); | 121 | hDays.resize ( NUMDAYS ); |
122 | eDays.resize ( NUMDAYS ); | 122 | eDays.resize ( NUMDAYS ); |
123 | days = new QDate[NUMDAYS]; | 123 | days = new QDate[NUMDAYS]; |
124 | daylbls = new QString[NUMDAYS]; | 124 | daylbls = new QString[NUMDAYS]; |
125 | //events = new int[NUMDAYS]; | 125 | //events = new int[NUMDAYS]; |
126 | mToolTip = new DynamicTip(this); | 126 | mToolTip = new DynamicTip(this); |
127 | 127 | ||
128 | // set default values used for drawing the matrix | 128 | // set default values used for drawing the matrix |
129 | mDefaultBackColor = palette().active().base(); | 129 | mDefaultBackColor = palette().active().base(); |
130 | mDefaultTextColor = palette().active().foreground(); | 130 | mDefaultTextColor = palette().active().foreground(); |
131 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); | 131 | mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); |
132 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); | 132 | mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); |
133 | mSelectedDaysColor = QColor("white"); | 133 | mSelectedDaysColor = QColor("white"); |
134 | mTodayMarginWidth = 2; | 134 | mTodayMarginWidth = 2; |
135 | mSelEnd = mSelStart = NOSELECTION; | 135 | mSelEnd = mSelStart = NOSELECTION; |
136 | 136 | ||
137 | setAcceptDrops(true); | 137 | setAcceptDrops(true); |
138 | //setFont( QFont("Arial", 10) ); | 138 | //setFont( QFont("Arial", 10) ); |
139 | 139 | ||
140 | mUpdateTimer = new QTimer( this ); | 140 | mUpdateTimer = new QTimer( this ); |
141 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); | 141 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); |
142 | mRepaintTimer = new QTimer( this ); | 142 | mRepaintTimer = new QTimer( this ); |
143 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); | 143 | connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); |
144 | mDayChanged = false; | 144 | mDayChanged = false; |
145 | updateView(); | 145 | updateView(); |
146 | } | 146 | } |
147 | QString KODayMatrix::getWhatsThisText( QPoint p ) | 147 | QString KODayMatrix::getWhatsThisText( QPoint p ) |
148 | { | 148 | { |
149 | 149 | ||
150 | int tmp = getDayIndexFrom(p.x(), p.y()); | 150 | int tmp = getDayIndexFrom(p.x(), p.y()); |
151 | if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) | 151 | if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) |
152 | return QString(); | 152 | return QString(); |
153 | QDate mDate = days[tmp]; | 153 | QDate mDate = days[tmp]; |
154 | QPtrList<Event> eventlist = mCalendar->events(mDate); | 154 | QPtrList<Event> eventlist = mCalendar->events(mDate); |
155 | Event *event; | 155 | Event *event; |
156 | QStringList mToolTip; | 156 | QStringList mToolTip; |
157 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 157 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
158 | QString mToolTipText; | 158 | QString mToolTipText; |
159 | QString text; | 159 | QString text; |
160 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day | 160 | int multiday = 0;// 1 = start, 2 = midddle, 3 = end day |
161 | if (event->isMultiDay()) { | 161 | if (event->isMultiDay()) { |
162 | QString prefix = "<->";multiday = 2; | 162 | QString prefix = "<->";multiday = 2; |
163 | QString time; | 163 | QString time; |
164 | if ( event->doesRecur() ) { | 164 | if ( event->doesRecur() ) { |
165 | if ( event->recursOn( mDate) ) { | 165 | if ( event->recursOn( mDate) ) { |
166 | prefix ="->" ;multiday = 1; | 166 | prefix ="->" ;multiday = 1; |
167 | } | 167 | } |
168 | else { | 168 | else { |
169 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 169 | int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
170 | if ( event->recursOn( mDate.addDays( -days)) ) { | 170 | if ( event->recursOn( mDate.addDays( -days)) ) { |
171 | prefix ="<-" ;multiday = 3; | 171 | prefix ="<-" ;multiday = 3; |
172 | } | 172 | } |
173 | } | 173 | } |
174 | } else { | 174 | } else { |
175 | if (mDate == event->dtStart().date()) { | 175 | if (mDate == event->dtStart().date()) { |
176 | prefix ="->" ;multiday = 1; | 176 | prefix ="->" ;multiday = 1; |
177 | } else if (mDate == event->dtEnd().date()) { | 177 | } else if (mDate == event->dtEnd().date()) { |
178 | prefix ="<-" ;multiday = 3; | 178 | prefix ="<-" ;multiday = 3; |
179 | } | 179 | } |
180 | } | 180 | } |
181 | if ( !event->doesFloat() ) { | 181 | if ( !event->doesFloat() ) { |
182 | if ( mDate == event->dtStart().date () ) | 182 | if ( mDate == event->dtStart().date () ) |
183 | time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; | 183 | time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; |
184 | else if ( mDate == event->dtEnd().date () ) | 184 | else if ( mDate == event->dtEnd().date () ) |
185 | time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; | 185 | time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; |
186 | 186 | ||
187 | } | 187 | } |
188 | text = time + event->summary(); | 188 | text = time + event->summary(); |
189 | mToolTipText += prefix + text; | 189 | mToolTipText += prefix + text; |
190 | } else { | 190 | } else { |
191 | if (event->doesFloat()) { | 191 | if (event->doesFloat()) { |
192 | text = event->summary(); | 192 | text = event->summary(); |
193 | mToolTipText += text; | 193 | mToolTipText += text; |
194 | } | 194 | } |
195 | else { | 195 | else { |
196 | text = KGlobal::locale()->formatTime(event->dtStart().time()); | 196 | text = KGlobal::locale()->formatTime(event->dtStart().time()); |
197 | text += " " + event->summary(); | 197 | text += " " + event->summary(); |
198 | mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); | 198 | mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); |
199 | } | 199 | } |
200 | } | 200 | } |
201 | if ( !event->location().isEmpty() ) | 201 | if ( !event->location().isEmpty() ) |
202 | mToolTipText += " (" + event->location() + ")"; | 202 | mToolTipText += " (" + event->location() + ")"; |
203 | //qDebug("TTT: %s ", mToolTipText.latin1()); | 203 | //qDebug("TTT: %s ", mToolTipText.latin1()); |
204 | mToolTip.append( deTag( mToolTipText ) ); | 204 | mToolTip.append( deTag( mToolTipText ) ); |
205 | } | 205 | } |
206 | mToolTip.sort(); | 206 | mToolTip.sort(); |
207 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { | 207 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { |
208 | QPtrList<Todo> todolist = mCalendar->todos(mDate); | 208 | QPtrList<Todo> todolist = mCalendar->todos(mDate); |
209 | Todo *todo; | 209 | Todo *todo; |
210 | for(todo=todolist.first();todo != 0;todo=todolist.next()) { | 210 | for(todo=todolist.first();todo != 0;todo=todolist.next()) { |
211 | QString mToolTipText; | 211 | QString mToolTipText; |
212 | if ( !todo->doesFloat() ) | 212 | if ( !todo->doesFloat() ) |
213 | mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" "; | 213 | mToolTipText += KGlobal::locale()->formatTime(todo->dtDue().time())+" "; |
214 | mToolTipText += todo->summary(); | 214 | mToolTipText += todo->summary(); |
215 | if ( !todo->location().isEmpty() ) | 215 | if ( !todo->location().isEmpty() ) |
216 | mToolTipText += " (" + todo->location() + ")"; | 216 | mToolTipText += " (" + todo->location() + ")"; |
217 | mToolTipText = deTag( mToolTipText); | 217 | mToolTipText = deTag( mToolTipText); |
218 | mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText; | 218 | mToolTipText = "<b>" + i18n("Todo: ") + "</b>"+ mToolTipText; |
219 | mToolTip.append( mToolTipText ); | 219 | mToolTip.append( mToolTipText ); |
220 | } | 220 | } |
221 | } | 221 | } |
222 | if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { | 222 | if (KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { |
223 | Journal *j = mCalendar->journal( mDate ); | 223 | Journal *j = mCalendar->journal( mDate ); |
224 | if ( j ) { | 224 | if ( j ) { |
225 | QString mToolTipText = j->description().left(100); | 225 | QString mToolTipText = j->description().left(100); |
226 | if ( j->description().length() > 100 ) | 226 | if ( j->description().length() > 100 ) |
227 | mToolTipText += " ..."; | 227 | mToolTipText += " ..."; |
228 | mToolTipText = deTag( mToolTipText); | 228 | mToolTipText = deTag( mToolTipText); |
229 | mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText; | 229 | mToolTipText = "<b>" + i18n("Journal: ") + "</b>"+ mToolTipText; |
230 | mToolTip.append( mToolTipText ); | 230 | mToolTip.append( mToolTipText ); |
231 | } | 231 | } |
232 | } | 232 | } |
233 | return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); | 233 | return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); |
234 | } | 234 | } |
235 | 235 | ||
236 | 236 | ||
237 | QString KODayMatrix::deTag( QString mToolTipText ) | 237 | QString KODayMatrix::deTag( QString mToolTipText ) |
238 | { | 238 | { |
239 | 239 | ||
240 | #if QT_VERSION >= 0x030000 | 240 | #if QT_VERSION >= 0x030000 |
241 | mToolTipText.replace( '<' , "<" ); | 241 | mToolTipText.replace( '<' , "<" ); |
242 | mToolTipText.replace( '>' , ">" ); | 242 | mToolTipText.replace( '>' , ">" ); |
243 | #else | 243 | #else |
244 | if ( mToolTipText.find ('<') >= 0 ) { | 244 | if ( mToolTipText.find ('<') >= 0 ) { |
245 | mToolTipText.replace( QRegExp("<") , "<" ); | 245 | mToolTipText.replace( QRegExp("<") , "<" ); |
246 | } | 246 | } |
247 | if ( mToolTipText.find ('>') >= 0 ) { | 247 | if ( mToolTipText.find ('>') >= 0 ) { |
248 | mToolTipText.replace( QRegExp(">") , ">" ); | 248 | mToolTipText.replace( QRegExp(">") , ">" ); |
249 | } | 249 | } |
250 | #endif | 250 | #endif |
251 | return mToolTipText; | 251 | return mToolTipText; |
252 | } | 252 | } |
253 | void KODayMatrix::setCalendar( Calendar *cal ) | 253 | void KODayMatrix::setCalendar( Calendar *cal ) |
254 | { | 254 | { |
255 | mCalendar = cal; | 255 | mCalendar = cal; |
256 | 256 | ||
257 | setAcceptDrops( mCalendar ); | 257 | setAcceptDrops( mCalendar ); |
258 | 258 | ||
259 | updateEvents(); | 259 | updateEvents(); |
260 | } | 260 | } |
261 | 261 | ||
262 | QColor KODayMatrix::getShadedColor(QColor color) | 262 | QColor KODayMatrix::getShadedColor(QColor color) |
263 | { | 263 | { |
264 | QColor shaded; | 264 | QColor shaded; |
265 | int h=0; | 265 | int h=0; |
266 | int s=0; | 266 | int s=0; |
267 | int v=0; | 267 | int v=0; |
268 | color.hsv(&h,&s,&v); | 268 | color.hsv(&h,&s,&v); |
269 | s = s/4; | 269 | s = s/4; |
270 | v = 192+v/4; | 270 | v = 192+v/4; |
271 | shaded.setHsv(h,s,v); | 271 | shaded.setHsv(h,s,v); |
272 | 272 | ||
273 | return shaded; | 273 | return shaded; |
274 | } | 274 | } |
275 | 275 | ||
276 | KODayMatrix::~KODayMatrix() | 276 | KODayMatrix::~KODayMatrix() |
277 | { | 277 | { |
278 | #if QT_VERSION >= 0x030000 | 278 | #if QT_VERSION >= 0x030000 |
279 | 279 | ||
280 | #else | 280 | #else |
281 | delete mKODaymatrixWhatsThis; | 281 | delete mKODaymatrixWhatsThis; |
282 | #endif | 282 | #endif |
283 | 283 | ||
284 | // delete mKODaymatrixWhatsThis; | 284 | // delete mKODaymatrixWhatsThis; |
285 | delete [] days; | 285 | delete [] days; |
286 | delete [] daylbls; | 286 | delete [] daylbls; |
287 | //delete [] events; | 287 | //delete [] events; |
288 | delete mToolTip; | 288 | delete mToolTip; |
289 | } | 289 | } |
290 | 290 | ||
291 | /* | 291 | /* |
292 | void KODayMatrix::setStartDate(QDate start) | 292 | void KODayMatrix::setStartDate(QDate start) |
293 | { | 293 | { |
294 | updateView(start); | 294 | updateView(start); |
295 | } | 295 | } |
296 | */ | 296 | */ |
297 | 297 | ||
298 | void KODayMatrix::addSelectedDaysTo(DateList& selDays) | 298 | void KODayMatrix::addSelectedDaysTo(DateList& selDays) |
299 | { | 299 | { |
300 | 300 | ||
301 | if (mSelStart == NOSELECTION) { | 301 | if (mSelStart == NOSELECTION) { |
302 | return; | 302 | return; |
303 | } | 303 | } |
304 | 304 | ||
305 | //cope with selection being out of matrix limits at top (< 0) | 305 | //cope with selection being out of matrix limits at top (< 0) |
306 | int i0 = mSelStart; | 306 | int i0 = mSelStart; |
307 | if (i0 < 0) { | 307 | if (i0 < 0) { |
308 | for (int i = i0; i < 0; i++) { | 308 | for (int i = i0; i < 0; i++) { |
309 | selDays.append(days[0].addDays(i)); | 309 | selDays.append(days[0].addDays(i)); |
310 | } | 310 | } |
311 | i0 = 0; | 311 | i0 = 0; |
312 | } | 312 | } |
313 | 313 | ||
314 | //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) | 314 | //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) |
315 | if (mSelEnd > NUMDAYS-1) { | 315 | if (mSelEnd > NUMDAYS-1) { |
316 | for (int i = i0; i <= NUMDAYS-1; i++) { | 316 | for (int i = i0; i <= NUMDAYS-1; i++) { |
317 | selDays.append(days[i]); | 317 | selDays.append(days[i]); |
318 | } | 318 | } |
319 | for (int i = NUMDAYS; i < mSelEnd; i++) { | 319 | for (int i = NUMDAYS; i < mSelEnd; i++) { |
320 | selDays.append(days[0].addDays(i)); | 320 | selDays.append(days[0].addDays(i)); |
321 | } | 321 | } |
322 | 322 | ||
323 | // apply normal routine to selection being entirely within matrix limits | 323 | // apply normal routine to selection being entirely within matrix limits |
324 | } else { | 324 | } else { |
325 | for (int i = i0; i <= mSelEnd; i++) { | 325 | for (int i = i0; i <= mSelEnd; i++) { |
326 | selDays.append(days[i]); | 326 | selDays.append(days[i]); |
327 | } | 327 | } |
328 | } | 328 | } |
329 | } | 329 | } |
330 | 330 | ||
331 | bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) | 331 | bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) |
332 | { | 332 | { |
333 | mRedrawNeeded = true; | 333 | mRedrawNeeded = true; |
334 | bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); | 334 | bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); |
335 | mSelStart = startdate.daysTo(start); | 335 | mSelStart = startdate.daysTo(start); |
336 | if ( mSelStart < 0 ) | 336 | if ( mSelStart < 0 ) |
337 | mSelStart = 0; | 337 | mSelStart = 0; |
338 | mSelEnd = startdate.daysTo(end); | 338 | mSelEnd = startdate.daysTo(end); |
339 | if ( mSelEnd > NUMDAYS-1 ) | 339 | if ( mSelEnd > NUMDAYS-1 ) |
340 | mSelEnd = NUMDAYS-1; | 340 | mSelEnd = NUMDAYS-1; |
341 | if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { | 341 | if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { |
342 | clearSelection(); | 342 | clearSelection(); |
343 | if ( noSel ) | 343 | if ( noSel ) |
344 | return false; | 344 | return false; |
345 | } | 345 | } |
346 | 346 | ||
347 | return true; | 347 | return true; |
348 | } | 348 | } |
349 | void KODayMatrix::clearSelection() | 349 | void KODayMatrix::clearSelection() |
350 | { | 350 | { |
351 | mSelEnd = mSelStart = NOSELECTION; | 351 | mSelEnd = mSelStart = NOSELECTION; |
352 | } | 352 | } |
353 | 353 | ||
354 | 354 | ||
355 | void KODayMatrix::recalculateToday() | 355 | void KODayMatrix::recalculateToday() |
356 | { | 356 | { |
357 | today = -1; | 357 | today = -1; |
358 | for (int i=0; i<NUMDAYS; i++) { | 358 | for (int i=0; i<NUMDAYS; i++) { |
359 | //events[i] = 0; | 359 | //events[i] = 0; |
360 | days[i] = startdate.addDays(i); | 360 | days[i] = startdate.addDays(i); |
361 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); | 361 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); |
362 | 362 | ||
363 | // if today is in the currently displayed month, hilight today | 363 | // if today is in the currently displayed month, hilight today |
364 | if (days[i].year() == QDate::currentDate().year() && | 364 | if (days[i].year() == QDate::currentDate().year() && |
365 | days[i].month() == QDate::currentDate().month() && | 365 | days[i].month() == QDate::currentDate().month() && |
366 | days[i].day() == QDate::currentDate().day()) { | 366 | days[i].day() == QDate::currentDate().day()) { |
367 | today = i; | 367 | today = i; |
368 | } | 368 | } |
369 | } | 369 | } |
370 | // qDebug(QString("Today is visible at %1.").arg(today)); | 370 | // qDebug(QString("Today is visible at %1.").arg(today)); |
371 | } | 371 | } |
372 | 372 | ||
373 | void KODayMatrix::updateView() | 373 | void KODayMatrix::updateView() |
374 | { | 374 | { |
375 | updateView(startdate); | 375 | updateView(startdate); |
376 | } | 376 | } |
377 | void KODayMatrix::repaintViewTimed() | 377 | void KODayMatrix::repaintViewTimed() |
378 | { | 378 | { |
379 | mRedrawNeeded = true; | 379 | mRedrawNeeded = true; |
380 | // bDays.fill( false); | 380 | // bDays.fill( false); |
381 | //pDays.fill( false); | 381 | //pDays.fill( false); |
382 | //hDays.fill( false); | 382 | //hDays.fill( false); |
383 | //eDays.fill( false); | 383 | //eDays.fill( false); |
384 | mRepaintTimer->stop(); | 384 | mRepaintTimer->stop(); |
385 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday | 385 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday |
386 | int i; | 386 | int i; |
387 | for(i = 0; i < NUMDAYS; i++) { | 387 | for(i = 0; i < NUMDAYS; i++) { |
388 | if ( ( (i+startDay) % 7 == 0 ) ) { | 388 | if ( ( (i+startDay) % 7 == 0 ) ) { |
389 | pDays.setBit(i); | 389 | pDays.setBit(i); |
390 | } | 390 | } |
391 | } | 391 | } |
392 | repaint(false); | 392 | repaint(false); |
393 | } | 393 | } |
394 | void KODayMatrix::computeEvent(Event *event, int i ) | 394 | void KODayMatrix::computeEvent(Event *event, int i ) |
395 | { | 395 | { |
396 | QString holiStr = mHolidays[i]; | 396 | QString holiStr = mHolidays[i]; |
397 | if ( event->isHoliday()) { | 397 | if ( event->isHoliday()) { |
398 | pDays.setBit(i); | 398 | pDays.setBit(i); |
399 | hDays.setBit(i); | 399 | hDays.setBit(i); |
400 | if ( !holiStr.isEmpty() ) | 400 | if ( !holiStr.isEmpty() ) |
401 | holiStr += "\n"; | 401 | holiStr += "\n"; |
402 | holiStr += event->summary(); | 402 | holiStr += event->summary(); |
403 | if ( !event->location().isEmpty() ) | 403 | if ( !event->location().isEmpty() ) |
404 | holiStr += " (" + event->location() + ")"; | 404 | holiStr += " (" + event->location() + ")"; |
405 | mHolidays[i] =holiStr ; | 405 | mHolidays[i] =holiStr ; |
406 | eDays.setBit(i); | 406 | eDays.setBit(i); |
407 | } | 407 | } |
408 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { | 408 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_T_VIEW && KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) { |
409 | if ( event->isBirthday()) { | 409 | if ( event->isBirthday()) { |
410 | pDays.setBit(i); | 410 | pDays.setBit(i); |
411 | if ( !holiStr.isEmpty() ) | 411 | if ( !holiStr.isEmpty() ) |
412 | holiStr += "\n"; | 412 | holiStr += "\n"; |
413 | holiStr += i18n("Birthday") + ": "+event->summary(); | 413 | holiStr += i18n("Birthday") + ": "+event->summary(); |
414 | if ( !event->location().isEmpty() ) | 414 | if ( !event->location().isEmpty() ) |
415 | holiStr += " (" + event->location() + ")"; | 415 | holiStr += " (" + event->location() + ")"; |
416 | bDays.setBit(i); | 416 | bDays.setBit(i); |
417 | mHolidays[i] =holiStr ; | 417 | mHolidays[i] =holiStr ; |
418 | } | 418 | } |
419 | } | 419 | } |
420 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) | 420 | if ( KOPrefs::instance()->mCurrentDisplayedView != VIEW_J_VIEW ) |
421 | eDays.setBit(i); | 421 | eDays.setBit(i); |
422 | } | 422 | } |
423 | void KODayMatrix::updateViewTimed() | 423 | void KODayMatrix::updateViewTimed() |
424 | { | 424 | { |
425 | mUpdateTimer->stop(); | 425 | mUpdateTimer->stop(); |
426 | if ( !mCalendar ) { | 426 | if ( !mCalendar ) { |
427 | qDebug("NOT CAL "); | 427 | qDebug("NOT CAL "); |
428 | return; | 428 | return; |
429 | } | 429 | } |
430 | #if 1 | 430 | #if 1 |
431 | 431 | ||
432 | 432 | ||
433 | int i; | 433 | int i; |
434 | int timeSpan = NUMDAYS-1; | 434 | int timeSpan = NUMDAYS-1; |
435 | QPtrList<Event> events = mCalendar->events(); | 435 | QPtrList<Event> events = mCalendar->events(); |
436 | Event *event; | 436 | Event *event; |
437 | QDateTime dt; | 437 | QDateTime dt; |
438 | bool ok; | 438 | bool ok; |
439 | bDays.fill( false); | 439 | bDays.fill( false); |
440 | pDays.fill( false); | 440 | pDays.fill( false); |
441 | hDays.fill( false); | 441 | hDays.fill( false); |
442 | eDays.fill( false); | 442 | eDays.fill( false); |
443 | mHolidays.clear(); | 443 | mHolidays.clear(); |
444 | QDate mStartDate = days[0]; | 444 | QDate mStartDate = days[0]; |
445 | QDate endDate = mStartDate.addDays( timeSpan ); | 445 | QDate endDate = mStartDate.addDays( timeSpan ); |
446 | for( event = events.first(); event; event = events.next() ) { // for event | 446 | for( event = events.first(); event; event = events.next() ) { // for event |
447 | ushort recurType = event->recurrence()->doesRecur(); | 447 | ushort recurType = event->recurrence()->doesRecur(); |
448 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 448 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
449 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 449 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
450 | continue; | 450 | continue; |
451 | } | 451 | } |
452 | if ( event->doesRecur() ) { | 452 | if ( event->doesRecur() ) { |
453 | bool last; | 453 | bool last; |
454 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); | 454 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); |
455 | QDateTime incidenceEnd; | 455 | QDateTime incidenceEnd; |
456 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 456 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
457 | bool invalid = false; | 457 | bool invalid = false; |
458 | while( true ) { | 458 | while( true ) { |
459 | if ( incidenceStart.isValid() ) { | 459 | if ( incidenceStart.isValid() ) { |
460 | incidenceEnd = incidenceStart.addDays( eventlen ); | 460 | incidenceEnd = incidenceStart.addDays( eventlen ); |
461 | int st = incidenceStart.date().daysTo( endDate ); | 461 | int st = incidenceStart.date().daysTo( endDate ); |
462 | if ( st >= 0 ) { // start before timeend | 462 | if ( st >= 0 ) { // start before timeend |
463 | int end = mStartDate.daysTo( incidenceEnd.date() ); | 463 | int end = mStartDate.daysTo( incidenceEnd.date() ); |
464 | if ( end >= 0 ) { // end after timestart --- got one! | 464 | if ( end >= 0 ) { // end after timestart --- got one! |
465 | //normalize | 465 | //normalize |
466 | st = timeSpan - st; | 466 | st = timeSpan - st; |
467 | if ( st < 0 ) st = 0; | 467 | if ( st < 0 ) st = 0; |
468 | if ( end > timeSpan ) end = timeSpan; | 468 | if ( end > timeSpan ) end = timeSpan; |
469 | int iii; | 469 | int iii; |
470 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); | 470 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); |
471 | for ( iii = st;iii<= end;++iii) { | 471 | for ( iii = st;iii<= end;++iii) { |
472 | computeEvent( event, iii ); | 472 | computeEvent( event, iii ); |
473 | } | 473 | } |
474 | } | 474 | } |
475 | } | 475 | } |
476 | } else { | 476 | } else { |
477 | if ( invalid ) | 477 | if ( invalid ) |
478 | break; | 478 | break; |
479 | invalid = true; | 479 | invalid = true; |
480 | //qDebug("invalid %s", event->summary().latin1()); | 480 | //qDebug("invalid %s", event->summary().latin1()); |
481 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; | 481 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; |
482 | } | 482 | } |
483 | if ( last ) | 483 | if ( last ) |
484 | break; | 484 | break; |
485 | bool ok; | 485 | bool ok; |
486 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); | 486 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); |
487 | if ( ! ok ) | 487 | if ( ! ok ) |
488 | break; | 488 | break; |
489 | if ( incidenceStart.date() > endDate ) | 489 | if ( incidenceStart.date() > endDate ) |
490 | break; | 490 | break; |
491 | } | 491 | } |
492 | } else { // no recur | 492 | } else { // no recur |
493 | int st = event->dtStart().date().daysTo( endDate ); | 493 | int st = event->dtStart().date().daysTo( endDate ); |
494 | if ( st >= 0 ) { // start before timeend | 494 | if ( st >= 0 ) { // start before timeend |
495 | int end = mStartDate.daysTo( event->dtEnd().date() ); | 495 | int end = mStartDate.daysTo( event->dtEnd().date() ); |
496 | if ( end >= 0 ) { // end after timestart --- got one! | 496 | if ( end >= 0 ) { // end after timestart --- got one! |
497 | //normalize | 497 | //normalize |
498 | st = timeSpan - st; | 498 | st = timeSpan - st; |
499 | if ( st < 0 ) st = 0; | 499 | if ( st < 0 ) st = 0; |
500 | if ( end > timeSpan ) end = timeSpan; | 500 | if ( end > timeSpan ) end = timeSpan; |
501 | int iii; | 501 | int iii; |
502 | for ( iii = st;iii<= end;++iii) | 502 | for ( iii = st;iii<= end;++iii) |
503 | computeEvent( event, iii ); | 503 | computeEvent( event, iii ); |
504 | } | 504 | } |
505 | } | 505 | } |
506 | } | 506 | } |
507 | } | 507 | } |
508 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday | 508 | int startDay = days[0].dayOfWeek(); // 1...7 7 = sunday |
509 | for(i = 0; i < NUMDAYS; i++) { | 509 | for(i = 0; i < NUMDAYS; i++) { |
510 | if ( ( (i+startDay) % 7 == 0 ) ) { | 510 | if ( ( (i+startDay) % 7 == 0 ) ) { |
511 | pDays.setBit(i); | 511 | pDays.setBit(i); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { | 514 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_T_VIEW ) { |
515 | bDays.fill( false); | 515 | bDays.fill( false); |
516 | // insert due todos | 516 | // insert due todos |
517 | QPtrList<Todo> todos = mCalendar->todos( ); | 517 | QPtrList<Todo> todos = mCalendar->todos( ); |
518 | Todo *todo; | 518 | Todo *todo; |
519 | for(todo = todos.first(); todo; todo = todos.next()) { | 519 | for(todo = todos.first(); todo; todo = todos.next()) { |
520 | //insertTodo( todo ); | 520 | //insertTodo( todo ); |
521 | if ( todo->hasDueDate() ) { | 521 | if ( todo->hasDueDate() ) { |
522 | int day = mStartDate.daysTo( todo->dtDue().date() ); | 522 | int day = mStartDate.daysTo( todo->dtDue().date() ); |
523 | if ( day >= 0 && day < timeSpan + 1) { | 523 | if ( day >= 0 && day < timeSpan + 1) { |
524 | int i = day; | 524 | int i = day; |
525 | QString holiStr = mHolidays[i]; | 525 | QString holiStr = mHolidays[i]; |
526 | pDays.setBit(i); | 526 | pDays.setBit(i); |
527 | if ( !holiStr.isEmpty() ) | 527 | if ( !holiStr.isEmpty() ) |
528 | holiStr += "\n"; | 528 | holiStr += "\n"; |
529 | holiStr += i18n("Todo") + ": "+todo->summary(); | 529 | holiStr += i18n("Todo") + ": "+todo->summary(); |
530 | if ( !todo->location().isEmpty() ) | 530 | if ( !todo->location().isEmpty() ) |
531 | holiStr += " (" + todo->location() + ")"; | 531 | holiStr += " (" + todo->location() + ")"; |
532 | bDays.setBit(i); | 532 | bDays.setBit(i); |
533 | mHolidays[i] =holiStr ; | 533 | mHolidays[i] =holiStr ; |
534 | eDays.setBit(i); | 534 | eDays.setBit(i); |
535 | } | 535 | } |
536 | } | 536 | } |
537 | } | 537 | } |
538 | } | 538 | } |
539 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { | 539 | if ( KOPrefs::instance()->mCurrentDisplayedView == VIEW_J_VIEW ) { |
540 | bDays.fill( false); | 540 | bDays.fill( false); |
541 | // insert due todos | 541 | // insert due todos |
542 | QPtrList<Journal> todos = mCalendar->journals( ); | 542 | QPtrList<Journal> todos = mCalendar->journals( ); |
543 | Journal *todo; | 543 | Journal *todo; |
544 | for(todo = todos.first(); todo; todo = todos.next()) { | 544 | for(todo = todos.first(); todo; todo = todos.next()) { |
545 | int day = mStartDate.daysTo( todo->dtStart().date() ); | 545 | int day = mStartDate.daysTo( todo->dtStart().date() ); |
546 | if ( day >= 0 && day < timeSpan + 1) { | 546 | if ( day >= 0 && day < timeSpan + 1) { |
547 | int i = day; | 547 | int i = day; |
548 | QString holiStr = mHolidays[i]; | 548 | QString holiStr = mHolidays[i]; |
549 | pDays.setBit(i); | 549 | pDays.setBit(i); |
550 | if ( !holiStr.isEmpty() ) | 550 | if ( !holiStr.isEmpty() ) |
551 | holiStr += "\n"; | 551 | holiStr += "\n"; |
552 | holiStr += i18n("Journal"); | 552 | holiStr += i18n("Journal"); |
553 | bDays.setBit(i); | 553 | bDays.setBit(i); |
554 | mHolidays[i] =holiStr ; | 554 | mHolidays[i] =holiStr ; |
555 | eDays.setBit(i); | 555 | eDays.setBit(i); |
556 | 556 | ||
557 | } | 557 | } |
558 | } | 558 | } |
559 | } | 559 | } |
560 | #else | 560 | #else |
561 | //qDebug("KODayMatrix::updateViewTimed "); | 561 | //qDebug("KODayMatrix::updateViewTimed "); |
562 | for(int i = 0; i < NUMDAYS; i++) { | 562 | for(int i = 0; i < NUMDAYS; i++) { |
563 | // if events are set for the day then remember to draw it bold | 563 | // if events are set for the day then remember to draw it bold |
564 | QPtrList<Event> eventlist = mCalendar->events(days[i]); | 564 | QPtrList<Event> eventlist = mCalendar->events(days[i]); |
565 | Event *event; | 565 | Event *event; |
566 | int numEvents = eventlist.count(); | 566 | int numEvents = eventlist.count(); |
567 | QString holiStr = ""; | 567 | QString holiStr = ""; |
568 | bDays.clearBit(i); | 568 | bDays.clearBit(i); |
569 | hDays.clearBit(i); | 569 | hDays.clearBit(i); |
570 | eDays.clearBit(i); | 570 | eDays.clearBit(i); |
571 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 571 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
572 | ushort recurType = event->recurrence()->doesRecur(); | 572 | ushort recurType = event->recurrence()->doesRecur(); |
573 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 573 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
574 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 574 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
575 | numEvents--; | 575 | numEvents--; |
576 | } | 576 | } |
577 | if ( event->isHoliday()) { | 577 | if ( event->isHoliday()) { |
578 | hDays.setBit(i); | 578 | hDays.setBit(i); |
579 | if ( !holiStr.isEmpty() ) | 579 | if ( !holiStr.isEmpty() ) |
580 | holiStr += "\n"; | 580 | holiStr += "\n"; |
581 | holiStr += event->summary(); | 581 | holiStr += event->summary(); |
582 | if ( !event->location().isEmpty() ) | 582 | if ( !event->location().isEmpty() ) |
583 | holiStr += " (" + event->location() + ")"; | 583 | holiStr += " (" + event->location() + ")"; |
584 | } | 584 | } |
585 | if ( event->isBirthday()) { | 585 | if ( event->isBirthday()) { |
586 | if ( !holiStr.isEmpty() ) | 586 | if ( !holiStr.isEmpty() ) |
587 | holiStr += "\n"; | 587 | holiStr += "\n"; |
588 | holiStr += i18n("Birthday") + ": "+event->summary(); | 588 | holiStr += i18n("Birthday") + ": "+event->summary(); |
589 | if ( !event->location().isEmpty() ) | 589 | if ( !event->location().isEmpty() ) |
590 | holiStr += " (" + event->location() + ")"; | 590 | holiStr += " (" + event->location() + ")"; |
591 | bDays.setBit(i); | 591 | bDays.setBit(i); |
592 | } | 592 | } |
593 | } | 593 | } |
594 | if ( numEvents ) | 594 | if ( numEvents ) |
595 | eDays.setBit(i); | 595 | eDays.setBit(i); |
596 | //if it is a holy day then draw it red. Sundays are consider holidays, too | 596 | //if it is a holy day then draw it red. Sundays are consider holidays, too |
597 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || | 597 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || |
598 | !holiStr.isEmpty()) { | 598 | !holiStr.isEmpty()) { |
599 | mHolidays[i] = holiStr; | 599 | mHolidays[i] = holiStr; |
600 | } else { | 600 | } else { |
601 | mHolidays[i] = QString::null; | 601 | mHolidays[i] = QString::null; |
602 | } | 602 | } |
603 | } | 603 | } |
604 | #endif | 604 | #endif |
605 | mRedrawNeeded = true; | 605 | mRedrawNeeded = true; |
606 | if ( ! mPendingUpdateBeforeRepaint ) | 606 | if ( ! mPendingUpdateBeforeRepaint ) |
607 | repaint(false); | 607 | repaint(false); |
608 | } | 608 | } |
609 | void KODayMatrix::updateView(QDate actdate) | 609 | void KODayMatrix::updateView(QDate actdate) |
610 | { | 610 | { |
611 | if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) | 611 | if ( mLastView != KOPrefs::instance()->mCurrentDisplayedView ) |
612 | mRedrawNeeded = true; | 612 | mRedrawNeeded = true; |
613 | mLastView = KOPrefs::instance()->mCurrentDisplayedView; | 613 | mLastView = KOPrefs::instance()->mCurrentDisplayedView; |
614 | if ( ! actdate.isValid() ) { | 614 | if ( ! actdate.isValid() ) { |
615 | //qDebug("date not valid "); | 615 | //qDebug("date not valid "); |
616 | return; | 616 | return; |
617 | } | 617 | } |
618 | mDayChanged = false; | 618 | mDayChanged = false; |
619 | //flag to indicate if the starting day of the matrix has changed by this call | 619 | //flag to indicate if the starting day of the matrix has changed by this call |
620 | //mDayChanged = false; | 620 | //mDayChanged = false; |
621 | // if a new startdate is to be set then apply Cornelius's calculation | 621 | // if a new startdate is to be set then apply Cornelius's calculation |
622 | // of the first day to be shown | 622 | // of the first day to be shown |
623 | if (actdate != startdate) { | 623 | if (actdate != startdate) { |
624 | // reset index of selection according to shift of starting date from startdate to actdate | 624 | // reset index of selection according to shift of starting date from startdate to actdate |
625 | if (mSelStart != NOSELECTION) { | 625 | if (mSelStart != NOSELECTION) { |
626 | int tmp = actdate.daysTo(startdate); | 626 | int tmp = actdate.daysTo(startdate); |
627 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; | 627 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; |
628 | // shift selection if new one would be visible at least partly ! | 628 | // shift selection if new one would be visible at least partly ! |
629 | 629 | ||
630 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { | 630 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { |
631 | // nested if is required for next X display pushed from a different month - correction required | 631 | // nested if is required for next X display pushed from a different month - correction required |
632 | // otherwise, for month forward and backward, it must be avoided | 632 | // otherwise, for month forward and backward, it must be avoided |
633 | if( mSelStart > NUMDAYS || mSelStart < 0 ) | 633 | if( mSelStart > NUMDAYS || mSelStart < 0 ) |
634 | mSelStart = mSelStart + tmp; | 634 | mSelStart = mSelStart + tmp; |
635 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) | 635 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) |
636 | mSelEnd = mSelEnd + tmp; | 636 | mSelEnd = mSelEnd + tmp; |
637 | } | 637 | } |
638 | } | 638 | } |
639 | startdate = actdate; | 639 | startdate = actdate; |
640 | mDayChanged = true; | 640 | mDayChanged = true; |
641 | recalculateToday(); | 641 | recalculateToday(); |
642 | mRedrawNeeded = true; | 642 | mRedrawNeeded = true; |
643 | } | 643 | } |
644 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); | 644 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); |
645 | if ( !isVisible() ) { | 645 | if ( !isVisible() ) { |
646 | mPendingUpdateBeforeRepaint = true; | 646 | mPendingUpdateBeforeRepaint = true; |
647 | } else { | 647 | } else { |
648 | #ifdef DESKTOP_VERSION | 648 | #ifdef DESKTOP_VERSION |
649 | //mRepaintTimer->start( 100 ); | 649 | //mRepaintTimer->start( 100 ); |
650 | //updateViewTimed(); | 650 | //updateViewTimed(); |
651 | mUpdateTimer->start( 50 ); | 651 | mUpdateTimer->start( 50 ); |
652 | #else | 652 | #else |
653 | mRepaintTimer->start( 350 ); | 653 | mRepaintTimer->start( 350 ); |
654 | mUpdateTimer->start( 800 ); | 654 | mUpdateTimer->start( 800 ); |
655 | #endif | 655 | #endif |
656 | } | 656 | } |
657 | } | 657 | } |
658 | void KODayMatrix::updateEvents() | 658 | void KODayMatrix::updateEvents() |
659 | { | 659 | { |
660 | if ( !mCalendar ) return; | 660 | if ( !mCalendar ) return; |
661 | 661 | ||
662 | for( int i = 0; i < NUMDAYS; i++ ) { | 662 | for( int i = 0; i < NUMDAYS; i++ ) { |
663 | // if events are set for the day then remember to draw it bold | 663 | // if events are set for the day then remember to draw it bold |
664 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); | 664 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); |
665 | int numEvents = eventlist.count(); | 665 | int numEvents = eventlist.count(); |
666 | Event *event; | 666 | Event *event; |
667 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { | 667 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { |
668 | ushort recurType = event->doesRecur(); | 668 | ushort recurType = event->doesRecur(); |
669 | 669 | ||
670 | if ( ( recurType == Recurrence::rDaily && | 670 | if ( ( recurType == Recurrence::rDaily && |
671 | !KOPrefs::instance()->mDailyRecur ) || | 671 | !KOPrefs::instance()->mDailyRecur ) || |
672 | ( recurType == Recurrence::rWeekly && | 672 | ( recurType == Recurrence::rWeekly && |
673 | !KOPrefs::instance()->mWeeklyRecur ) ) { | 673 | !KOPrefs::instance()->mWeeklyRecur ) ) { |
674 | numEvents--; | 674 | numEvents--; |
675 | } | 675 | } |
676 | } | 676 | } |
677 | if ( numEvents ) | 677 | if ( numEvents ) |
678 | eDays.setBit(i); | 678 | eDays.setBit(i); |
679 | else | 679 | else |
680 | eDays.clearBit(i); | 680 | eDays.clearBit(i); |
681 | } | 681 | } |
682 | } | 682 | } |
683 | 683 | ||
684 | const QDate& KODayMatrix::getDate(int offset) | 684 | const QDate& KODayMatrix::getDate(int offset) |
685 | { | 685 | { |
686 | if (offset < 0 || offset > NUMDAYS-1) { | 686 | if (offset < 0 || offset > NUMDAYS-1) { |
687 | qDebug("Wrong offset2 %d", offset); | 687 | qDebug("Wrong offset2 %d", offset); |
688 | return days[0]; | 688 | return days[0]; |
689 | } | 689 | } |
690 | return days[offset]; | 690 | return days[offset]; |
691 | } | 691 | } |
692 | 692 | ||
693 | QString KODayMatrix::getHolidayLabel(int offset) | 693 | QString KODayMatrix::getHolidayLabel(int offset) |
694 | { | 694 | { |
695 | if (offset < 0 || offset > NUMDAYS-1) { | 695 | if (offset < 0 || offset > NUMDAYS-1) { |
696 | qDebug("Wrong offset1 %d", offset); | 696 | qDebug("Wrong offset1 %d", offset); |
697 | return QString(); | 697 | return QString(); |
698 | } | 698 | } |
699 | return mHolidays[offset]; | 699 | return mHolidays[offset]; |
700 | } | 700 | } |
701 | 701 | ||
702 | int KODayMatrix::getDayIndexFrom(int x, int y) | 702 | int KODayMatrix::getDayIndexFrom(int x, int y) |
703 | { | 703 | { |
704 | int colModulo = (width()-2) % 7; | 704 | int colModulo = (width()-2) % 7; |
705 | int rowModulo = (height()-2) % 6; | 705 | int rowModulo = (height()-2) % 6; |
706 | #if 0 | 706 | #if 0 |
707 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? | 707 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? |
708 | 6 - x/daysize.width() : x/daysize.width()); | 708 | 6 - x/daysize.width() : x/daysize.width()); |
709 | #endif | 709 | #endif |
710 | int xVal = (x-colModulo/2-2)/daysize.width(); | 710 | int xVal = (x-colModulo/2-2)/daysize.width(); |
711 | int yVal = (y-rowModulo/2-2)/daysize.height(); | 711 | int yVal = (y-rowModulo/2-2)/daysize.height(); |
712 | 712 | ||
713 | 713 | ||
714 | return 7*(yVal) + xVal; | 714 | return 7*(yVal) + xVal; |
715 | 715 | ||
716 | } | 716 | } |
717 | 717 | ||
718 | // ---------------------------------------------------------------------------- | 718 | // ---------------------------------------------------------------------------- |
719 | // M O U S E E V E N T H A N D L I N G | 719 | // M O U S E E V E N T H A N D L I N G |
720 | // ---------------------------------------------------------------------------- | 720 | // ---------------------------------------------------------------------------- |
721 | 721 | ||
722 | void KODayMatrix::mousePressEvent (QMouseEvent* e) | 722 | void KODayMatrix::mousePressEvent (QMouseEvent* e) |
723 | { | 723 | { |
724 | 724 | ||
725 | if ( e->button() == LeftButton ) | 725 | if ( e->button() == LeftButton ) |
726 | mouseDown = true; | 726 | mouseDown = true; |
727 | mSelStart = getDayIndexFrom(e->x(), e->y()); | 727 | mSelStart = getDayIndexFrom(e->x(), e->y()); |
728 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; | 728 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; |
729 | mSelInit = mSelStart; | 729 | mSelInit = mSelStart; |
730 | mSelEnd = mSelStart; | 730 | mSelEnd = mSelStart; |
731 | mRedrawNeeded = true; | 731 | mRedrawNeeded = true; |
732 | repaint(false); | 732 | repaint(false); |
733 | } | 733 | } |
734 | 734 | ||
735 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) | 735 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) |
736 | { | 736 | { |
737 | mRedrawNeeded = true; | 737 | mRedrawNeeded = true; |
738 | if ( e->button() == LeftButton ) | 738 | if ( e->button() == LeftButton ) |
739 | if ( ! mouseDown ) { | 739 | if ( ! mouseDown ) { |
740 | return; | 740 | return; |
741 | } | 741 | } |
742 | else | 742 | else |
743 | mouseDown = false; | 743 | mouseDown = false; |
744 | int tmp = getDayIndexFrom(e->x(), e->y()); | 744 | int tmp = getDayIndexFrom(e->x(), e->y()); |
745 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 745 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
746 | 746 | ||
747 | if (mSelInit > tmp) { | 747 | if (mSelInit > tmp) { |
748 | mSelEnd = mSelInit; | 748 | mSelEnd = mSelInit; |
749 | if (tmp != mSelStart) { | 749 | if (tmp != mSelStart) { |
750 | mSelStart = tmp; | 750 | mSelStart = tmp; |
751 | repaint(false); | 751 | repaint(false); |
752 | } | 752 | } |
753 | } else { | 753 | } else { |
754 | mSelStart = mSelInit; | 754 | mSelStart = mSelInit; |
755 | 755 | ||
756 | //repaint only if selection has changed | 756 | //repaint only if selection has changed |
757 | if (tmp != mSelEnd) { | 757 | if (tmp != mSelEnd) { |
758 | mSelEnd = tmp; | 758 | mSelEnd = tmp; |
759 | repaint(false); | 759 | repaint(false); |
760 | } | 760 | } |
761 | } | 761 | } |
762 | 762 | ||
763 | DateList daylist; | 763 | DateList daylist; |
764 | if ( mSelStart < 0 ) | 764 | if ( mSelStart < 0 ) |
765 | mSelStart = 0; | 765 | mSelStart = 0; |
766 | for (int i = mSelStart; i <= mSelEnd; i++) { | 766 | for (int i = mSelStart; i <= mSelEnd; i++) { |
767 | daylist.append(days[i]); | 767 | daylist.append(days[i]); |
768 | } | 768 | } |
769 | emit selected((const DateList)daylist); | 769 | emit selected((const DateList)daylist); |
770 | 770 | ||
771 | } | 771 | } |
772 | 772 | ||
773 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) | 773 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) |
774 | { | 774 | { |
775 | if ( ! mouseDown ) { | 775 | if ( ! mouseDown ) { |
776 | return; | 776 | return; |
777 | } | 777 | } |
778 | mRedrawNeeded = true; | 778 | mRedrawNeeded = true; |
779 | int tmp = getDayIndexFrom(e->x(), e->y()); | 779 | int tmp = getDayIndexFrom(e->x(), e->y()); |
780 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 780 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
781 | 781 | ||
782 | if (mSelInit > tmp) { | 782 | if (mSelInit > tmp) { |
783 | mSelEnd = mSelInit; | 783 | mSelEnd = mSelInit; |
784 | if (tmp != mSelStart) { | 784 | if (tmp != mSelStart) { |
785 | mSelStart = tmp; | 785 | mSelStart = tmp; |
786 | repaint(false); | 786 | repaint(false); |
787 | } | 787 | } |
788 | } else { | 788 | } else { |
789 | mSelStart = mSelInit; | 789 | mSelStart = mSelInit; |
790 | 790 | ||
791 | //repaint only if selection has changed | 791 | //repaint only if selection has changed |
792 | if (tmp != mSelEnd) { | 792 | if (tmp != mSelEnd) { |
793 | mSelEnd = tmp; | 793 | mSelEnd = tmp; |
794 | repaint(false); | 794 | repaint(false); |
795 | } | 795 | } |
796 | } | 796 | } |
797 | } | 797 | } |
798 | 798 | ||
799 | // ---------------------------------------------------------------------------- | 799 | // ---------------------------------------------------------------------------- |
800 | // D R A G ' N D R O P H A N D L I N G | 800 | // D R A G ' N D R O P H A N D L I N G |
801 | // ---------------------------------------------------------------------------- | 801 | // ---------------------------------------------------------------------------- |
802 | 802 | ||
803 | void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) | 803 | void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) |
804 | { | 804 | { |
805 | #ifndef KORG_NODND | 805 | #ifndef KORG_NODND |
806 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 806 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
807 | e->ignore(); | 807 | e->ignore(); |
808 | return; | 808 | return; |
809 | } | 809 | } |
810 | 810 | ||
811 | // some visual feedback | 811 | // some visual feedback |
812 | // oldPalette = palette(); | 812 | // oldPalette = palette(); |
813 | // setPalette(my_HilitePalette); | 813 | // setPalette(my_HilitePalette); |
814 | // update(); | 814 | // update(); |
815 | #endif | 815 | #endif |
816 | } | 816 | } |
817 | 817 | ||
818 | void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) | 818 | void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) |
819 | { | 819 | { |
820 | #ifndef KORG_NODND | 820 | #ifndef KORG_NODND |
821 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 821 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
822 | e->ignore(); | 822 | e->ignore(); |
823 | return; | 823 | return; |
824 | } | 824 | } |
825 | 825 | ||
826 | e->accept(); | 826 | e->accept(); |
827 | #endif | 827 | #endif |
828 | } | 828 | } |
829 | 829 | ||
830 | void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) | 830 | void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) |
831 | { | 831 | { |
832 | #ifndef KORG_NODND | 832 | #ifndef KORG_NODND |
833 | // setPalette(oldPalette); | 833 | // setPalette(oldPalette); |
834 | // update(); | 834 | // update(); |
835 | #endif | 835 | #endif |
836 | } | 836 | } |
837 | 837 | ||
838 | void KODayMatrix::dropEvent(QDropEvent *e) | 838 | void KODayMatrix::dropEvent(QDropEvent *e) |
839 | { | 839 | { |
840 | #ifndef KORG_NODND | 840 | #ifndef KORG_NODND |
841 | // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; | 841 | // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; |
842 | 842 | ||
843 | if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 843 | if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
844 | e->ignore(); | 844 | e->ignore(); |
845 | return; | 845 | return; |
846 | } | 846 | } |
847 | 847 | ||
848 | DndFactory factory( mCalendar ); | 848 | DndFactory factory( mCalendar ); |
849 | Event *event = factory.createDrop(e); | 849 | Event *event = factory.createDrop(e); |
850 | 850 | ||
851 | if (event) { | 851 | if (event) { |
852 | e->acceptAction(); | 852 | e->acceptAction(); |
853 | 853 | ||
854 | Event *existingEvent = mCalendar->event(event->uid()); | 854 | Event *existingEvent = mCalendar->event(event->uid()); |
855 | 855 | ||
856 | if(existingEvent) { | 856 | if(existingEvent) { |
857 | // uniquify event | 857 | // uniquify event |
858 | event->recreate(); | 858 | event->recreate(); |
859 | /* | 859 | /* |
860 | KMessageBox::sorry(this, | 860 | KMessageBox::sorry(this, |
861 | i18n("Event already exists in this calendar."), | 861 | i18n("Event already exists in this calendar."), |
862 | i18n("Drop Event")); | 862 | i18n("Drop Event")); |
863 | delete event; | 863 | delete event; |
864 | return; | 864 | return; |
865 | */ | 865 | */ |
866 | } | 866 | } |
867 | // kdDebug() << "Drop new Event" << endl; | 867 | // kdDebug() << "Drop new Event" << endl; |
868 | // Adjust date | 868 | // Adjust date |
869 | QDateTime start = event->dtStart(); | 869 | QDateTime start = event->dtStart(); |
870 | QDateTime end = event->dtEnd(); | 870 | QDateTime end = event->dtEnd(); |
871 | int duration = start.daysTo(end); | 871 | int duration = start.daysTo(end); |
872 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); | 872 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); |
873 | 873 | ||
874 | start.setDate(days[idx]); | 874 | start.setDate(days[idx]); |
875 | end.setDate(days[idx].addDays(duration)); | 875 | end.setDate(days[idx].addDays(duration)); |
876 | 876 | ||
877 | event->setDtStart(start); | 877 | event->setDtStart(start); |
878 | event->setDtEnd(end); | 878 | event->setDtEnd(end); |
879 | mCalendar->addEvent(event); | 879 | mCalendar->addEvent(event); |
880 | 880 | ||
881 | emit eventDropped(event); | 881 | emit eventDropped(event); |
882 | } else { | 882 | } else { |
883 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; | 883 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; |
884 | e->ignore(); | 884 | e->ignore(); |
885 | } | 885 | } |
886 | #endif | 886 | #endif |
887 | } | 887 | } |
888 | 888 | ||
889 | // ---------------------------------------------------------------------------- | 889 | // ---------------------------------------------------------------------------- |
890 | // P A I N T E V E N T H A N D L I N G | 890 | // P A I N T E V E N T H A N D L I N G |
891 | // ---------------------------------------------------------------------------- | 891 | // ---------------------------------------------------------------------------- |
892 | 892 | ||
893 | void KODayMatrix::paintEvent(QPaintEvent * pevent) | 893 | void KODayMatrix::paintEvent(QPaintEvent * pevent) |
894 | { | 894 | { |
895 | 895 | ||
896 | if ( width() <= 0 || height() <= 0 ) | 896 | if ( width() <= 0 || height() <= 0 ) |
897 | return; | 897 | return; |
898 | if ( mPendingUpdateBeforeRepaint ) { | 898 | if ( mPendingUpdateBeforeRepaint ) { |
899 | updateViewTimed(); | 899 | updateViewTimed(); |
900 | mPendingUpdateBeforeRepaint = false; | 900 | mPendingUpdateBeforeRepaint = false; |
901 | } | 901 | } |
902 | #if 0 | 902 | #if 0 |
903 | if ( myPix.width() != width() || myPix.height()!=height() ) { | 903 | if ( myPix.width() != width() || myPix.height()!=height() ) { |
904 | myPix.resize(size() ); | 904 | myPix.resize(size() ); |
905 | mRedrawNeeded = true; | 905 | mRedrawNeeded = true; |
906 | } | 906 | } |
907 | #endif | 907 | #endif |
908 | if ( oldW != width() || oldH !=height() ) | 908 | if ( oldW != width() || oldH !=height() ) |
909 | mRedrawNeeded = true; | 909 | mRedrawNeeded = true; |
910 | 910 | ||
911 | oldH = height() ; | 911 | oldH = height() ; |
912 | oldW = width(); | 912 | oldW = width(); |
913 | if ( myPix.width() < width() || myPix.height() < height() ) { | 913 | if ( myPix.width() < width() || myPix.height() < height() ) { |
914 | myPix.resize(size() ); | 914 | myPix.resize(size() ); |
915 | mRedrawNeeded = true; | 915 | mRedrawNeeded = true; |
916 | 916 | ||
917 | } | 917 | } |
918 | 918 | ||
919 | if ( mRedrawNeeded ) { | 919 | if ( mRedrawNeeded ) { |
920 | //qDebug("REDRAW "); | 920 | //qDebug("REDRAW "); |
921 | QPainter p(&myPix); | 921 | QPainter p(&myPix); |
922 | p.setFont(font()); | 922 | p.setFont(font()); |
923 | 923 | ||
924 | 924 | ||
925 | int dheight = daysize.height(); | 925 | int dheight = daysize.height(); |
926 | int dwidth = daysize.width(); | 926 | int dwidth = daysize.width(); |
927 | int row,col; | 927 | int row,col; |
928 | int selw, selh; | 928 | int selw, selh; |
929 | int xyOff = frameWidth(); | 929 | int xyOff = frameWidth(); |
930 | int colModulo = (width()-2) % 7; | 930 | int colModulo = (width()-2) % 7; |
931 | int rowModulo = (height()-2) % 6; | 931 | int rowModulo = (height()-2) % 6; |
932 | //qDebug("col %d row %d ",colModulo,rowModulo ); | 932 | //qDebug("col %d row %d ",colModulo,rowModulo ); |
933 | 933 | ||
934 | bool isRTL = KOGlobals::self()->reverseLayout(); | 934 | bool isRTL = KOGlobals::self()->reverseLayout(); |
935 | 935 | ||
936 | // draw background and topleft frame | 936 | // draw background and topleft frame |
937 | p.fillRect(0,0,width(),height(), mDefaultBackColor); | 937 | p.fillRect(0,0,width(),height(), mDefaultBackColor); |
938 | p.setPen(mDefaultTextColor); | 938 | //p.setPen(mDefaultTextColor); |
939 | p.drawRect(0, 0, width(), height()); | 939 | //p.drawRect(0, 0, width(), height()); |
940 | int mSelStartT = mSelStart; | 940 | int mSelStartT = mSelStart; |
941 | int mSelEndT = mSelEnd; | 941 | int mSelEndT = mSelEnd; |
942 | if ( mSelEndT >= NUMDAYS ) | 942 | if ( mSelEndT >= NUMDAYS ) |
943 | mSelEndT = NUMDAYS-1; | 943 | mSelEndT = NUMDAYS-1; |
944 | // draw selected days with highlighted background color | 944 | // draw selected days with highlighted background color |
945 | if (mSelStart != NOSELECTION) { | 945 | if (mSelStart != NOSELECTION) { |
946 | bool skip = false; | 946 | bool skip = false; |
947 | if ( ! mouseDown ) { | 947 | if ( ! mouseDown ) { |
948 | int mo = days[20].month(); | 948 | int mo = days[20].month(); |
949 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); | 949 | //qDebug("-- %d %d ", mSelStartT, mSelEndT); |
950 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); | 950 | //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); |
951 | int startMo = days[mSelStartT].month(); | 951 | int startMo = days[mSelStartT].month(); |
952 | int endMo = days[mSelEndT].month(); | 952 | int endMo = days[mSelEndT].month(); |
953 | if ( startMo == 12 && mo == 1 && endMo <= 2 ) | 953 | if ( startMo == 12 && mo == 1 && endMo <= 2 ) |
954 | startMo = 1; | 954 | startMo = 1; |
955 | if ( endMo == 1 && mo == 12 ) | 955 | if ( endMo == 1 && mo == 12 ) |
956 | endMo = 12; | 956 | endMo = 12; |
957 | if ( mo == 12 && startMo == 1 ) | 957 | if ( mo == 12 && startMo == 1 ) |
958 | startMo = 13; | 958 | startMo = 13; |
959 | if ( (startMo > mo || endMo < mo) ) { | 959 | if ( (startMo > mo || endMo < mo) ) { |
960 | skip = true; | 960 | skip = true; |
961 | } else { | 961 | } else { |
962 | if ( days[mSelStartT].month() != mo ) { | 962 | if ( days[mSelStartT].month() != mo ) { |
963 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); | 963 | int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); |
964 | mSelStartT += add +1; | 964 | mSelStartT += add +1; |
965 | } | 965 | } |
966 | if ( days[mSelEndT].month() != mo ) { | 966 | if ( days[mSelEndT].month() != mo ) { |
967 | int sub = days[mSelEndT].day(); | 967 | int sub = days[mSelEndT].day(); |
968 | mSelEndT -= sub ; | 968 | mSelEndT -= sub ; |
969 | } | 969 | } |
970 | } | 970 | } |
971 | } | 971 | } |
972 | //qDebug("SKIP %d ", skip); | 972 | //qDebug("SKIP %d ", skip); |
973 | if ( ! skip ) { | 973 | if ( ! skip ) { |
974 | row = mSelStartT/7; | 974 | row = mSelStartT/7; |
975 | col = mSelStartT -row*7; | 975 | col = mSelStartT -row*7; |
976 | QColor selcol = KOPrefs::instance()->mHighlightColor; | 976 | QColor selcol = KOPrefs::instance()->mHighlightColor; |
977 | int addCol = 0; | 977 | int addCol = 0; |
978 | int addRow = 0; | 978 | int addRow = 0; |
979 | int addRow2 = 0; | 979 | int addRow2 = 0; |
980 | int addCol2 = 0; | 980 | int addCol2 = 0; |
981 | if (row == mSelEndT/7) { | 981 | if (row == mSelEndT/7) { |
982 | if ( rowModulo ) { | 982 | if ( rowModulo ) { |
983 | if ( row >= 6 - rowModulo ) | 983 | if ( row >= 6 - rowModulo ) |
984 | addRow = row - 5 + rowModulo; | 984 | addRow = row - 5 + rowModulo; |
985 | } | 985 | } |
986 | if ( colModulo ) { | 986 | if ( colModulo ) { |
987 | int colt1 = mSelEndT%7; | 987 | int colt1 = mSelEndT%7; |
988 | //qDebug("colt1 %d ", colt1 ); | 988 | //qDebug("colt1 %d ", colt1 ); |
989 | if ( colt1 >= 7 - colModulo ) | 989 | if ( colt1 >= 7 - colModulo ) |
990 | addCol = colt1 - 7 + colModulo+1; | 990 | addCol = colt1 - 7 + colModulo+1; |
991 | int colt = mSelStartT%7; | 991 | int colt = mSelStartT%7; |
992 | if ( colt >= 7 - colModulo ) | 992 | if ( colt >= 7 - colModulo ) |
993 | addCol2 = colt - 7 + colModulo; | 993 | addCol2 = colt - 7 + colModulo; |
994 | addCol -= addCol2; | 994 | addCol -= addCol2; |
995 | //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); | 995 | //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); |
996 | } | 996 | } |
997 | // Single row selection | 997 | // Single row selection |
998 | //if ( row == 0) | 998 | //if ( row == 0) |
999 | // addRow = 1; | 999 | // addRow = 1; |
1000 | p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, | 1000 | p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, |
1001 | row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); | 1001 | row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); |
1002 | } else { | 1002 | } else { |
1003 | // draw first row to the right | 1003 | // draw first row to the right |
1004 | if ( colModulo ) { | 1004 | if ( colModulo ) { |
1005 | if ( col >= 7 - colModulo ) | 1005 | if ( col >= 7 - colModulo ) |
1006 | addCol2 = col - 7 + colModulo; | 1006 | addCol2 = col - 7 + colModulo; |
1007 | } | 1007 | } |
1008 | if ( rowModulo ) { | 1008 | if ( rowModulo ) { |
1009 | if ( row >= 6 - rowModulo ) | 1009 | if ( row >= 6 - rowModulo ) |
1010 | addRow = row - 5 + rowModulo; | 1010 | addRow = row - 5 + rowModulo; |
1011 | } | 1011 | } |
1012 | //if ( row == 0) | 1012 | //if ( row == 0) |
1013 | // addRow = 1; | 1013 | // addRow = 1; |
1014 | int drawWid = width()-(col*dwidth+1+addCol2)-1; | 1014 | int drawWid = width()-(col*dwidth+1+addCol2)-1; |
1015 | p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid, | 1015 | p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid, |
1016 | dheight+1, selcol); | 1016 | dheight+1, selcol); |
1017 | // draw full block till last line | 1017 | // draw full block till last line |
1018 | selh = mSelEndT/7-row; | 1018 | selh = mSelEndT/7-row; |
1019 | addRow = 0; | 1019 | addRow = 0; |
1020 | if ( rowModulo ) { | 1020 | if ( rowModulo ) { |
1021 | if ( mSelEndT/7 >= 6 - rowModulo ) | 1021 | if ( mSelEndT/7 >= 6 - rowModulo ) |
1022 | addRow = mSelEndT/7 - 5 + rowModulo; | 1022 | addRow = mSelEndT/7 - 5 + rowModulo; |
1023 | } | 1023 | } |
1024 | //qDebug("%d %d %d ",selh, row, addRow ); | 1024 | //qDebug("%d %d %d ",selh, row, addRow ); |
1025 | int addrow2 = addRow-selh+1; | 1025 | int addrow2 = addRow-selh+1; |
1026 | if ( addrow2 < 0 ) | 1026 | if ( addrow2 < 0 ) |
1027 | addrow2 = 0; | 1027 | addrow2 = 0; |
1028 | if (selh > 1) { | 1028 | if (selh > 1) { |
1029 | p.fillRect(1, (row+1)*dheight+addrow2, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); | 1029 | p.fillRect(1, (row+1)*dheight+addrow2, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); |
1030 | } | 1030 | } |
1031 | // draw last block from left to mSelEndT | 1031 | // draw last block from left to mSelEndT |
1032 | selw = mSelEndT-7*(mSelEndT/7)+1; | 1032 | selw = mSelEndT-7*(mSelEndT/7)+1; |
1033 | //qDebug("esl %d ",selw ); | 1033 | //qDebug("esl %d ",selw ); |
1034 | int add = 0; | 1034 | int add = 0; |
1035 | if ( colModulo ) { | 1035 | if ( colModulo ) { |
1036 | add = 7 - colModulo; | 1036 | add = 7 - colModulo; |
1037 | if ( selw > add ) | 1037 | if ( selw > add ) |
1038 | add = selw - add; | 1038 | add = selw - add; |
1039 | else | 1039 | else |
1040 | add = 0; | 1040 | add = 0; |
1041 | } | 1041 | } |
1042 | //qDebug("add %d ", add); | 1042 | //qDebug("add %d ", add); |
1043 | p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, | 1043 | p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, |
1044 | selw*dwidth+add, dheight+1, selcol); | 1044 | selw*dwidth+add, dheight+1, selcol); |
1045 | } | 1045 | } |
1046 | } | 1046 | } |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | // iterate over all days in the matrix and draw the day label in appropriate colors | 1049 | // iterate over all days in the matrix and draw the day label in appropriate colors |
1050 | QColor actcol = mDefaultTextColorShaded; | 1050 | QColor actcol = mDefaultTextColorShaded; |
1051 | p.setPen(actcol); | 1051 | p.setPen(actcol); |
1052 | QPen tmppen; | 1052 | QPen tmppen; |
1053 | for(int i = 0; i < NUMDAYS; i++) { | 1053 | for(int i = 0; i < NUMDAYS; i++) { |
1054 | row = i/7; | 1054 | row = i/7; |
1055 | col = isRTL ? 6-(i-row*7) : i-row*7; | 1055 | col = isRTL ? 6-(i-row*7) : i-row*7; |
1056 | 1056 | ||
1057 | // if it is the first day of a month switch color from normal to shaded and vice versa | 1057 | // if it is the first day of a month switch color from normal to shaded and vice versa |
1058 | if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { | 1058 | if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { |
1059 | if (actcol == mDefaultTextColorShaded) { | 1059 | if (actcol == mDefaultTextColorShaded) { |
1060 | actcol = mDefaultTextColor; | 1060 | actcol = mDefaultTextColor; |
1061 | } else { | 1061 | } else { |
1062 | actcol = mDefaultTextColorShaded; | 1062 | actcol = mDefaultTextColorShaded; |
1063 | } | 1063 | } |
1064 | p.setPen(actcol); | 1064 | p.setPen(actcol); |
1065 | } | 1065 | } |
1066 | if (actcol == mDefaultTextColorShaded) { | 1066 | if (actcol == mDefaultTextColorShaded) { |
1067 | if ( ! mouseDown ) { | 1067 | if ( ! mouseDown ) { |
1068 | continue; | 1068 | continue; |
1069 | } | 1069 | } |
1070 | } | 1070 | } |
1071 | //Reset pen color after selected days block | 1071 | //Reset pen color after selected days block |
1072 | if (i == mSelEndT+1) { | 1072 | if (i == mSelEndT+1) { |
1073 | p.setPen(actcol); | 1073 | p.setPen(actcol); |
1074 | } | 1074 | } |
1075 | 1075 | ||
1076 | // if today then draw rectangle around day | 1076 | // if today then draw rectangle around day |
1077 | if (today == i) { | 1077 | if (today == i) { |
1078 | tmppen = p.pen(); | 1078 | tmppen = p.pen(); |
1079 | QPen mTodayPen(p.pen()); | 1079 | QPen mTodayPen(p.pen()); |
1080 | if ( daysize.width() < 20 ) | 1080 | if ( daysize.width() < 20 ) |
1081 | mTodayPen.setWidth(1); | 1081 | mTodayPen.setWidth(1); |
1082 | else | 1082 | else |
1083 | mTodayPen.setWidth(mTodayMarginWidth); | 1083 | mTodayPen.setWidth(mTodayMarginWidth); |
1084 | //draw red rectangle for holidays | 1084 | //draw red rectangle for holidays |
1085 | if (pDays.testBit(i)) { | 1085 | if (pDays.testBit(i)) { |
1086 | if (actcol == mDefaultTextColor) { | 1086 | if (actcol == mDefaultTextColor) { |
1087 | mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); | 1087 | mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); |
1088 | } else { | 1088 | } else { |
1089 | mTodayPen.setColor(mHolidayColorShaded); | 1089 | mTodayPen.setColor(mHolidayColorShaded); |
1090 | } | 1090 | } |
1091 | } | 1091 | } |
1092 | //draw gray rectangle for today if in selection | 1092 | //draw gray rectangle for today if in selection |
1093 | if (i >= mSelStartT && i <= mSelEndT) { | 1093 | if (i >= mSelStartT && i <= mSelEndT) { |
1094 | QColor grey("grey"); | 1094 | QColor grey("grey"); |
1095 | mTodayPen.setColor(grey); | 1095 | mTodayPen.setColor(grey); |
1096 | } | 1096 | } |
1097 | p.setPen(mTodayPen); | 1097 | p.setPen(mTodayPen); |
1098 | 1098 | ||
1099 | 1099 | ||
1100 | int addCol = 0; | 1100 | int addCol = 0; |
1101 | int addRow = 0; | 1101 | int addRow = 0; |
1102 | if (rowModulo) { | 1102 | if (rowModulo) { |
1103 | if ( row >= 6 - rowModulo ) | 1103 | if ( row >= 6 - rowModulo ) |
1104 | addRow = row - 5 + rowModulo; | 1104 | addRow = row - 5 + rowModulo; |
1105 | } | 1105 | } |
1106 | if ( colModulo ) { | 1106 | if ( colModulo ) { |
1107 | if ( col >= 7 - colModulo ) | 1107 | if ( col >= 7 - colModulo ) |
1108 | addCol = col - 6 + colModulo-1; | 1108 | addCol = col - 6 + colModulo-1; |
1109 | } | 1109 | } |
1110 | 1110 | ||
1111 | addCol += 1; | 1111 | addCol += 1; |
1112 | if ( row == 0 ) | 1112 | if ( row == 0 ) |
1113 | addRow = 1; | 1113 | addRow = 1; |
1114 | p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1); | 1114 | p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1); |
1115 | p.setPen(tmppen); | 1115 | p.setPen(tmppen); |
1116 | } | 1116 | } |
1117 | 1117 | ||
1118 | // if any events are on that day then draw it using a bold font | 1118 | // if any events are on that day then draw it using a bold font |
1119 | if ( eDays.testBit(i) ) { | 1119 | if ( eDays.testBit(i) ) { |
1120 | QFont myFont = font(); | 1120 | QFont myFont = font(); |
1121 | myFont.setBold(true); | 1121 | myFont.setBold(true); |
1122 | p.setFont(myFont); | 1122 | p.setFont(myFont); |
1123 | } | 1123 | } |
1124 | 1124 | ||
1125 | // if it is a holiday then use the default holiday color | 1125 | // if it is a holiday then use the default holiday color |
1126 | if ( pDays.testBit(i)) { | 1126 | if ( pDays.testBit(i)) { |
1127 | if ( bDays.testBit(i) ) { | 1127 | if ( bDays.testBit(i) ) { |
1128 | if ( hDays.testBit(i) ) | 1128 | if ( hDays.testBit(i) ) |
1129 | p.setPen(QColor(0,200,0)); | 1129 | p.setPen(QColor(0,200,0)); |
1130 | else | 1130 | else |
1131 | p.setPen(QColor(Qt::blue)); | 1131 | p.setPen(QColor(Qt::blue)); |
1132 | } else { | 1132 | } else { |
1133 | if (actcol == mDefaultTextColor ) { | 1133 | if (actcol == mDefaultTextColor ) { |
1134 | p.setPen(KOPrefs::instance()->mHolidayColor); | 1134 | p.setPen(KOPrefs::instance()->mHolidayColor); |
1135 | } else { | 1135 | } else { |
1136 | p.setPen(mHolidayColorShaded); | 1136 | p.setPen(mHolidayColorShaded); |
1137 | } | 1137 | } |
1138 | } | 1138 | } |
1139 | } | 1139 | } |
1140 | 1140 | ||
1141 | // draw selected days with special color | 1141 | // draw selected days with special color |
1142 | // DO NOT specially highlight holidays in selection ! | 1142 | // DO NOT specially highlight holidays in selection ! |
1143 | if (i >= mSelStartT && i <= mSelEndT) { | 1143 | if (i >= mSelStartT && i <= mSelEndT) { |
1144 | ;//p.setPen(mSelectedDaysColor); | 1144 | ;//p.setPen(mSelectedDaysColor); |
1145 | } | 1145 | } |
1146 | 1146 | ||
1147 | int addCol = 0; | 1147 | int addCol = 0; |
1148 | int addRow = 0; | 1148 | int addRow = 0; |
1149 | if ( colModulo ) { | 1149 | if ( colModulo ) { |
1150 | if ( col >= 7 - colModulo ) | 1150 | if ( col >= 7 - colModulo ) |
1151 | addCol = col - 7 + colModulo; | 1151 | addCol = col - 7 + colModulo; |
1152 | } | 1152 | } |
1153 | if ( rowModulo ) { | 1153 | if ( rowModulo ) { |
1154 | if ( row >= 6 - rowModulo ) | 1154 | if ( row >= 6 - rowModulo ) |
1155 | addRow = row - 5 + rowModulo; | 1155 | addRow = row - 5 + rowModulo; |
1156 | } | 1156 | } |
1157 | //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); | 1157 | //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); |
1158 | ++addCol;//++addCol; | 1158 | ++addCol;//++addCol; |
1159 | if ( row == 0) | 1159 | if ( row == 0) |
1160 | addRow = 1; | 1160 | addRow = 1; |
1161 | p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, | 1161 | p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, |
1162 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); | 1162 | Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); |
1163 | 1163 | ||
1164 | // reset color to actual color | 1164 | // reset color to actual color |
1165 | if (pDays.testBit(i)) { | 1165 | if (pDays.testBit(i)) { |
1166 | p.setPen(actcol); | 1166 | p.setPen(actcol); |
1167 | } | 1167 | } |
1168 | // reset bold font to plain font | 1168 | // reset bold font to plain font |
1169 | if ( eDays.testBit(i)) { | 1169 | if ( eDays.testBit(i)) { |
1170 | QFont myFont = font(); | 1170 | QFont myFont = font(); |
1171 | myFont.setBold(false); | 1171 | myFont.setBold(false); |
1172 | p.setFont(myFont); | 1172 | p.setFont(myFont); |
1173 | } | 1173 | } |
1174 | } | 1174 | } |
1175 | p.setPen(mDefaultTextColor); | ||
1176 | p.drawRect(0, 0, width(), height()); | ||
1175 | } else { | 1177 | } else { |
1176 | //qDebug("NO redraw "); | 1178 | //qDebug("NO redraw "); |
1177 | } | 1179 | } |
1178 | 1180 | ||
1179 | bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,CopyROP); | 1181 | bitBlt (this, pevent->rect().topLeft(), &myPix , pevent->rect() ,CopyROP); |
1180 | mRedrawNeeded = false; | 1182 | mRedrawNeeded = false; |
1181 | } | 1183 | } |
1182 | 1184 | ||
1183 | // ---------------------------------------------------------------------------- | 1185 | // ---------------------------------------------------------------------------- |
1184 | // R E SI Z E E V E N T H A N D L I N G | 1186 | // R E SI Z E E V E N T H A N D L I N G |
1185 | // ---------------------------------------------------------------------------- | 1187 | // ---------------------------------------------------------------------------- |
1186 | 1188 | ||
1187 | void KODayMatrix::resizeEvent(QResizeEvent *) | 1189 | void KODayMatrix::resizeEvent(QResizeEvent *) |
1188 | { | 1190 | { |
1189 | QRect sz = frameRect(); | 1191 | QRect sz = frameRect(); |
1190 | daysize.setHeight(sz.height()*7 / NUMDAYS); | 1192 | daysize.setHeight(sz.height()*7 / NUMDAYS); |
1191 | daysize.setWidth(sz.width() / 7); | 1193 | daysize.setWidth(sz.width() / 7); |
1192 | } | 1194 | } |
1193 | 1195 | ||
1194 | QSize KODayMatrix::sizeHint() const | 1196 | QSize KODayMatrix::sizeHint() const |
1195 | { | 1197 | { |
1196 | 1198 | ||
1197 | QFontMetrics fm ( font() ); | 1199 | QFontMetrics fm ( font() ); |
1198 | int wid = fm.width( "30") *7+3; | 1200 | int wid = fm.width( "30") *7+3; |
1199 | int hei = fm.height() * 6+3; | 1201 | int hei = fm.height() * 6+3; |
1200 | //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); | 1202 | //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); |
1201 | return QSize ( wid, hei ); | 1203 | return QSize ( wid, hei ); |
1202 | 1204 | ||
1203 | } | 1205 | } |
diff --git a/korganizer/kofilterview.cpp b/korganizer/kofilterview.cpp index bb88386..ea53043 100644 --- a/korganizer/kofilterview.cpp +++ b/korganizer/kofilterview.cpp | |||
@@ -1,424 +1,431 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 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 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qcheckbox.h> | 24 | #include <qcheckbox.h> |
25 | #include <qcombobox.h> | 25 | #include <qcombobox.h> |
26 | #include <qpushbutton.h> | 26 | #include <qpushbutton.h> |
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | #include <qlabel.h> | 28 | #include <qlabel.h> |
29 | #include <qdialog.h> | 29 | #include <qdialog.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qtextcodec.h> | 31 | #include <qtextcodec.h> |
32 | 32 | ||
33 | 33 | ||
34 | #include <libkcal/calfilter.h> | 34 | #include <libkcal/calfilter.h> |
35 | 35 | ||
36 | #include "kofilterview.h" | 36 | #include "kofilterview.h" |
37 | #include "koprefs.h" | 37 | #include "koprefs.h" |
38 | #include <kiconloader.h> | 38 | #include <kiconloader.h> |
39 | #include <kglobal.h> | 39 | #include <kglobal.h> |
40 | #include <kcolorbutton.h> | 40 | #include <kcolorbutton.h> |
41 | #include <kmessagebox.h> | 41 | #include <kmessagebox.h> |
42 | 42 | ||
43 | 43 | ||
44 | 44 | ||
45 | 45 | ||
46 | 46 | ||
47 | KOFilterView::KOFilterView(QPtrList<CalFilter> *filterList,QWidget* parent, | 47 | KOFilterView::KOFilterView(QPtrList<CalFilter> *filterList,QWidget* parent, |
48 | const char* name,WFlags fl ) | 48 | const char* name,WFlags fl ) |
49 | : KOFilterView_base(parent,name,fl) | 49 | : KOFilterView_base(parent,name,fl) |
50 | { | 50 | { |
51 | mFilters = filterList; | 51 | mFilters = filterList; |
52 | 52 | ||
53 | connect(mSelectionCombo,SIGNAL(activated(int)),SIGNAL(filterChanged())); | 53 | connect(mSelectionCombo,SIGNAL(activated(int)),SIGNAL(filterChanged())); |
54 | connect(mEnabledCheck,SIGNAL(clicked()),SIGNAL(filterChanged())); | 54 | connect(mEnabledCheck,SIGNAL(clicked()),SIGNAL(filterChanged())); |
55 | connect(mEditButton,SIGNAL(clicked()),SIGNAL(editFilters())); | 55 | connect(mEditButton,SIGNAL(clicked()),SIGNAL(editFilters())); |
56 | } | 56 | } |
57 | 57 | ||
58 | KOFilterView::~KOFilterView() | 58 | KOFilterView::~KOFilterView() |
59 | { | 59 | { |
60 | // no need to delete child widgets, Qt does it all for us | 60 | // no need to delete child widgets, Qt does it all for us |
61 | } | 61 | } |
62 | 62 | ||
63 | bool KOFilterView::filtersEnabled() | 63 | bool KOFilterView::filtersEnabled() |
64 | { | 64 | { |
65 | return mEnabledCheck->isChecked(); | 65 | return mEnabledCheck->isChecked(); |
66 | } | 66 | } |
67 | 67 | ||
68 | void KOFilterView::setFiltersEnabled(bool set) | 68 | void KOFilterView::setFiltersEnabled(bool set) |
69 | { | 69 | { |
70 | mEnabledCheck->setChecked(set); | 70 | mEnabledCheck->setChecked(set); |
71 | emit filterChanged(); | 71 | emit filterChanged(); |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
75 | void KOFilterView::updateFilters() | 75 | void KOFilterView::updateFilters() |
76 | { | 76 | { |
77 | mSelectionCombo->clear(); | 77 | mSelectionCombo->clear(); |
78 | 78 | ||
79 | CalFilter *filter = mFilters->first(); | 79 | CalFilter *filter = mFilters->first(); |
80 | while(filter) { | 80 | while(filter) { |
81 | mSelectionCombo->insertItem(filter->name()); | 81 | mSelectionCombo->insertItem(filter->name()); |
82 | filter = mFilters->next(); | 82 | filter = mFilters->next(); |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | CalFilter *KOFilterView::selectedFilter() | 86 | CalFilter *KOFilterView::selectedFilter() |
87 | { | 87 | { |
88 | CalFilter *f = mFilters->at(mSelectionCombo->currentItem()); | 88 | CalFilter *f = mFilters->at(mSelectionCombo->currentItem()); |
89 | return f; | 89 | return f; |
90 | } | 90 | } |
91 | 91 | ||
92 | void KOFilterView::setSelectedFilter(QString filterName) | 92 | void KOFilterView::setSelectedFilter(QString filterName) |
93 | { | 93 | { |
94 | int filter_num = mSelectionCombo->count(); | 94 | int filter_num = mSelectionCombo->count(); |
95 | int i; | 95 | int i; |
96 | for (i=0;i<filter_num;i++) { | 96 | for (i=0;i<filter_num;i++) { |
97 | if (mSelectionCombo->text(i)==filterName) | 97 | if (mSelectionCombo->text(i)==filterName) |
98 | mSelectionCombo->setCurrentItem(i); | 98 | mSelectionCombo->setCurrentItem(i); |
99 | } | 99 | } |
100 | emit filterChanged(); | 100 | emit filterChanged(); |
101 | } | 101 | } |
102 | void KOFilterView::setSelectedFilter( int fil ) | 102 | void KOFilterView::setSelectedFilter( int fil ) |
103 | { | 103 | { |
104 | if ( fil >= mSelectionCombo->count() ) | 104 | if ( fil >= mSelectionCombo->count() ) |
105 | return; | 105 | return; |
106 | mSelectionCombo->setCurrentItem( fil ); | 106 | mSelectionCombo->setCurrentItem( fil ); |
107 | emit filterChanged(); | 107 | emit filterChanged(); |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | 111 | ||
112 | KOCalEditView::KOCalEditView(QWidget* parent, | 112 | KOCalEditView::KOCalEditView(QWidget* parent, |
113 | const char* name ) | 113 | const char* name ) |
114 | : QScrollView(parent,name) | 114 | : QScrollView(parent,name) |
115 | { | 115 | { |
116 | mw = 0; | 116 | mw = 0; |
117 | setResizePolicy( AutoOneFit ); | 117 | setResizePolicy( AutoOneFit ); |
118 | setFrameStyle ( QFrame::Panel | QFrame::Plain ); | 118 | setFrameStyle ( QFrame::Panel | QFrame::Plain ); |
119 | setLineWidth ( 1 ); | 119 | setLineWidth ( 1 ); |
120 | setMidLineWidth ( 1 ); | 120 | setMidLineWidth ( 1 ); |
121 | setFocusPolicy(NoFocus); | 121 | setFocusPolicy(NoFocus); |
122 | } | 122 | } |
123 | 123 | ||
124 | KOCalEditView::~KOCalEditView() | 124 | KOCalEditView::~KOCalEditView() |
125 | { | 125 | { |
126 | // no need to delete child widgets, Qt does it all for us | 126 | // no need to delete child widgets, Qt does it all for us |
127 | } | 127 | } |
128 | void KOCalEditView::selectCal(int id ,bool b) | 128 | void KOCalEditView::selectCal(int id ,bool b) |
129 | { | 129 | { |
130 | KOPrefs::instance()->getCalendar( id )->isEnabled = b; | 130 | KOPrefs::instance()->getCalendar( id )->isEnabled = b; |
131 | emit calendarEnabled ( id, b ); | 131 | emit calendarEnabled ( id, b ); |
132 | emit needsUpdate(); | 132 | emit needsUpdate(); |
133 | 133 | ||
134 | } | 134 | } |
135 | void KOCalEditView::selectStdCal( int id, bool b ) | 135 | void KOCalEditView::selectStdCal( int id, bool b ) |
136 | { | 136 | { |
137 | 137 | ||
138 | if ( !b ) { | 138 | if ( !b ) { |
139 | KOCalCheckButton* it = (KOCalCheckButton*) sender(); | 139 | KOCalCheckButton* it = (KOCalCheckButton*) sender(); |
140 | if ( it ) { | 140 | if ( it ) { |
141 | it->blockSignals( true ); | 141 | it->blockSignals( true ); |
142 | it->setChecked( true ); | 142 | it->setChecked( true ); |
143 | it->blockSignals( false ); | 143 | it->blockSignals( false ); |
144 | return; | 144 | return; |
145 | } | 145 | } |
146 | return; | 146 | return; |
147 | } | 147 | } |
148 | KOCalCheckButton* sen = (KOCalCheckButton*) sender(); | 148 | KOCalCheckButton* sen = (KOCalCheckButton*) sender(); |
149 | KOCalCheckButton* it = mStdandardB.first(); | 149 | KOCalCheckButton* it = mStdandardB.first(); |
150 | while ( it ) { | 150 | while ( it ) { |
151 | if ( it->isChecked() ) { | 151 | if ( it->isChecked() ) { |
152 | if ( it != sen ) { | 152 | if ( it != sen ) { |
153 | it->blockSignals( true ); | 153 | it->blockSignals( true ); |
154 | it->setChecked( false ); | 154 | it->setChecked( false ); |
155 | it->blockSignals( false ); | 155 | it->blockSignals( false ); |
156 | break; | 156 | break; |
157 | } | 157 | } |
158 | } | 158 | } |
159 | it = mStdandardB.next(); | 159 | it = mStdandardB.next(); |
160 | } | 160 | } |
161 | KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); | 161 | KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); |
162 | while ( kkf ) { | 162 | while ( kkf ) { |
163 | kkf->isStandard = false; | 163 | kkf->isStandard = false; |
164 | kkf = KOPrefs::instance()->mCalendars.next(); | 164 | kkf = KOPrefs::instance()->mCalendars.next(); |
165 | } | 165 | } |
166 | KOPrefs::instance()->getCalendar( id )->isStandard = true; | 166 | KOPrefs::instance()->getCalendar( id )->isStandard = true; |
167 | emit setCalendarDefault ( id ); | 167 | emit setCalendarDefault ( id ); |
168 | } | 168 | } |
169 | 169 | ||
170 | void KOCalEditView::selectCalAlarm(int id ,bool b ) | 170 | void KOCalEditView::selectCalAlarm(int id ,bool b ) |
171 | { | 171 | { |
172 | KOPrefs::instance()->getCalendar( id )->isAlarmEnabled = b; | 172 | KOPrefs::instance()->getCalendar( id )->isAlarmEnabled = b; |
173 | emit alarmEnabled ( id , b ); | 173 | emit alarmEnabled ( id , b ); |
174 | emit needsUpdate(); | 174 | emit needsUpdate(); |
175 | } | 175 | } |
176 | void KOCalEditView::selectReadOnly(int id ,bool b ) | 176 | void KOCalEditView::selectReadOnly(int id ,bool b ) |
177 | { | 177 | { |
178 | KOPrefs::instance()->getCalendar( id )->isReadOnly = b; | 178 | KOPrefs::instance()->getCalendar( id )->isReadOnly = b; |
179 | emit calendarReadonly ( id , b ); | 179 | emit calendarReadonly ( id , b ); |
180 | if ( KOPrefs::instance()->getCalendar( id )->isStandard && b && id > 1 ) { | 180 | if ( KOPrefs::instance()->getCalendar( id )->isStandard && b && id > 1 ) { |
181 | KOPrefs::instance()->getCalendar( id )->isStandard = false; | 181 | KOPrefs::instance()->getCalendar( id )->isStandard = false; |
182 | KOPrefs::instance()->getCalendar( 1 )->isStandard = true; | 182 | KOPrefs::instance()->getCalendar( 1 )->isStandard = true; |
183 | emit setCalendarDefault ( 1 ); | 183 | emit setCalendarDefault ( 1 ); |
184 | } | 184 | } |
185 | emit needsUpdate(); | 185 | emit needsUpdate(); |
186 | QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); | 186 | QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); |
187 | 187 | ||
188 | } | 188 | } |
189 | void KOCalEditView::setColor( const QColor& c, int id ) | 189 | void KOCalEditView::setColor( const QColor& c, int id ) |
190 | { | 190 | { |
191 | KOPrefs::instance()->getCalendar( id )->mDefaultColor = c; | 191 | KOPrefs::instance()->getCalendar( id )->mDefaultColor = c; |
192 | emit needsUpdate(); | 192 | emit needsUpdate(); |
193 | } | 193 | } |
194 | void KOCalEditView::deleteCal( int id ) | 194 | void KOCalEditView::deleteCal( int id ) |
195 | { | 195 | { |
196 | KopiCalendarFile * kkf = KOPrefs::instance()->getCalendar( id ); | 196 | KopiCalendarFile * kkf = KOPrefs::instance()->getCalendar( id ); |
197 | QString name = kkf->mName; | 197 | QString name = kkf->mName; |
198 | QString file = KGlobal::formatMessage ( kkf->mFileName ,0 ); | 198 | QString file = KGlobal::formatMessage ( kkf->mFileName ,0 ); |
199 | if ( KMessageBox::warningContinueCancel( this, i18n("The calendar <b>%1</b> is displaying file <b>%2</b>. Do you want to remove this calendar from KO/Pi? (The file is not removed!)").arg(name).arg(file) ) != KMessageBox::Continue ) return; | 199 | if ( KMessageBox::warningContinueCancel( this, i18n("The calendar <b>%1</b> is displaying file <b>%2</b>. Do you want to remove this calendar from KO/Pi? (The file is not removed!)").arg(name).arg(file) ) != KMessageBox::Continue ) return; |
200 | if ( kkf->isStandard ) | 200 | if ( kkf->isStandard ) |
201 | selectStdCal( 1, true ); | 201 | selectStdCal( 1, true ); |
202 | emit removeCalendar ( id ); | 202 | emit removeCalendar ( id ); |
203 | KOPrefs::instance()->mCalendars.remove ( kkf ); | 203 | KOPrefs::instance()->mCalendars.remove ( kkf ); |
204 | emit needsUpdate(); | 204 | emit needsUpdate(); |
205 | QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); | 205 | QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); |
206 | } | 206 | } |
207 | void KOCalEditView::infoCal( int id ) | 207 | void KOCalEditView::infoCal( int id ) |
208 | { | 208 | { |
209 | QString name = KOPrefs::instance()->getCalendar( id )->mName; | 209 | QString name = KOPrefs::instance()->getCalendar( id )->mName; |
210 | QString file = KGlobal::formatMessage ( KOPrefs::instance()->getCalendar( id )->mFileName, 0 ); | 210 | QString file = KGlobal::formatMessage ( KOPrefs::instance()->getCalendar( id )->mFileName, 0 ); |
211 | if ( KOPrefs::instance()->getCalendar( id )->mErrorOnLoad ) { | 211 | if ( KOPrefs::instance()->getCalendar( id )->mErrorOnLoad ) { |
212 | if ( KMessageBox::Yes == KMessageBox::questionYesNo( this, i18n("The calendar <b>%1</b> is not loaded! Loading of file <b>%2</b> failed! <b>Try again to load the calendar?</b>").arg(name).arg(file) ) ) { | 212 | if ( KMessageBox::Yes == KMessageBox::questionYesNo( this, i18n("The calendar <b>%1</b> is not loaded! Loading of file <b>%2</b> failed! <b>Try again to load the calendar?</b>").arg(name).arg(file) ) ) { |
213 | emit calendarAdded( id ); | 213 | emit calendarAdded( id ); |
214 | emit needsUpdate(); | 214 | emit needsUpdate(); |
215 | QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); | 215 | QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); |
216 | } | 216 | } |
217 | } | 217 | } |
218 | else | 218 | else |
219 | KMessageBox::information( this, i18n("The calendar <b>%1</b> is displaying file <b>%2</b>").arg(name).arg(file) ); | 219 | KMessageBox::information( this, i18n("The calendar <b>%1</b> is displaying file <b>%2</b>").arg(name).arg(file) ); |
220 | } | 220 | } |
221 | void KOCalEditView::readConfig() | 221 | void KOCalEditView::readConfig() |
222 | { | 222 | { |
223 | 223 | ||
224 | mStdandardB.clear(); | 224 | mStdandardB.clear(); |
225 | mEnabledB.clear(); | 225 | mEnabledB.clear(); |
226 | mAlarmB.clear(); | 226 | mAlarmB.clear(); |
227 | mROB.clear(); | 227 | mROB.clear(); |
228 | 228 | ||
229 | if ( mw ) delete mw; | 229 | if ( mw ) delete mw; |
230 | mw = new QWidget ( viewport() ); | 230 | mw = new QWidget ( viewport() ); |
231 | addChild(mw); | 231 | addChild(mw); |
232 | 232 | int ii = 0; | |
233 | mainLayout = new QGridLayout ( mw , 2, 8 ); | 233 | mainLayout = new QGridLayout ( mw , 2, 8 ); |
234 | mainLayout->setMargin( 3); | 234 | mainLayout->setMargin( 2 ); |
235 | mainLayout->setSpacing( 2); | 235 | mainLayout->setSpacing( 2 ); |
236 | QPushButton * addBut = new QPushButton ( mw ); | 236 | QPushButton * addBut = new QPushButton ( mw ); |
237 | addBut->setFocusPolicy(NoFocus); | 237 | addBut->setFocusPolicy(NoFocus); |
238 | mainLayout->addWidget( addBut,0,0 ); | 238 | mainLayout->addWidget( addBut,0,0 ); |
239 | addBut->setPixmap ( SmallIcon("plus")); | 239 | addBut->setPixmap ( SmallIcon("plus")); |
240 | connect(addBut,SIGNAL(clicked()),SLOT(addCal())); | 240 | connect(addBut,SIGNAL(clicked()),SLOT(addCal())); |
241 | addBut->setMaximumWidth( addBut->sizeHint().height() ); | 241 | addBut->setMaximumWidth( addBut->sizeHint().height() ); |
242 | 242 | int max = addBut->sizeHint().height(); | |
243 | addBut = new QPushButton ( mw ); | 243 | addBut = new QPushButton ( mw ); |
244 | addBut->setFocusPolicy(NoFocus); | 244 | addBut->setFocusPolicy(NoFocus); |
245 | mainLayout->addWidget( addBut,0,1 ); | 245 | mainLayout->addWidget( addBut,0,++ii ); |
246 | addBut->setPixmap ( SmallIcon("eye")); | 246 | addBut->setPixmap ( SmallIcon("eye")); |
247 | connect(addBut,SIGNAL(clicked()),SLOT(enableAll())); | 247 | connect(addBut,SIGNAL(clicked()),SLOT(enableAll())); |
248 | addBut->setMaximumWidth( addBut->sizeHint().height() ); | 248 | addBut->setMaximumWidth( addBut->sizeHint().height() ); |
249 | 249 | ||
250 | QLabel* lab = new QLabel (i18n(" Calendar \n Resource "), mw ); | 250 | QLabel* lab = new QLabel (i18n(" Calendar \n Resource "), mw ); |
251 | mainLayout->addWidget( lab,0,2 ); | 251 | mainLayout->addWidget( lab,0,++ii ); |
252 | lab = new QLabel ( i18n(" "), mw ); | 252 | //lab = new QLabel ( i18n(" "), mw ); |
253 | mainLayout->addWidget( lab,0,3 ); | 253 | //mainLayout->addWidget( lab,0,++ii ); |
254 | lab->setFixedWidth( 6 ); | 254 | //lab->setFixedWidth( 1 ); |
255 | addBut = new QPushButton ( mw ); | 255 | addBut = new QPushButton ( mw ); |
256 | addBut->setFocusPolicy(NoFocus); | 256 | addBut->setFocusPolicy(NoFocus); |
257 | mainLayout->addWidget( addBut,0,4 ); | 257 | mainLayout->addWidget( addBut,0,++ii ); |
258 | addBut->setPixmap ( SmallIcon("bell")); | 258 | addBut->setPixmap ( SmallIcon("bell")); |
259 | connect(addBut,SIGNAL(clicked()),SLOT(enableAlarm())); | 259 | connect(addBut,SIGNAL(clicked()),SLOT(enableAlarm())); |
260 | addBut->setMaximumWidth( addBut->sizeHint().height() ); | 260 | addBut->setMaximumWidth( addBut->sizeHint().height() ); |
261 | 261 | ||
262 | addBut = new QPushButton ( mw ); | 262 | addBut = new QPushButton ( mw ); |
263 | addBut->setFocusPolicy(NoFocus); | 263 | addBut->setFocusPolicy(NoFocus); |
264 | mainLayout->addWidget( addBut,0,5 ); | 264 | mainLayout->addWidget( addBut,0,++ii ); |
265 | addBut->setPixmap ( SmallIcon("pencil")); | 265 | addBut->setPixmap ( SmallIcon("pencil")); |
266 | connect(addBut,SIGNAL(clicked()),SLOT(disableRO())); | 266 | connect(addBut,SIGNAL(clicked()),SLOT(disableRO())); |
267 | addBut->setMaximumWidth( addBut->sizeHint().height() ); | 267 | addBut->setMaximumWidth( addBut->sizeHint().height() ); |
268 | 268 | ||
269 | lab = new QLabel ( i18n(" Color "), mw ); | 269 | lab = new QLabel ( i18n(" Color "), mw ); |
270 | mainLayout->addWidget( lab,0,6 ); | 270 | mainLayout->addWidget( lab,0,++ii ); |
271 | lab = new QLabel ( "", mw ); | ||
272 | mainLayout->addWidget( lab,0,++ii ); | ||
273 | lab->setMaximumWidth( max+4 ); | ||
274 | lab = new QLabel ( "", mw ); | ||
275 | mainLayout->addWidget( lab,0,++ii ); | ||
276 | |||
277 | |||
271 | #if 0 | 278 | #if 0 |
272 | addBut = new QPushButton ( mw ); | 279 | addBut = new QPushButton ( mw ); |
273 | mainLayout->addWidget( addBut,0,6 ); | 280 | mainLayout->addWidget( addBut,0,6 ); |
274 | addBut->setPixmap ( SmallIcon("minus")); | 281 | addBut->setPixmap ( SmallIcon("minus")); |
275 | connect(addBut,SIGNAL(clicked()),SLOT(deleteAll())); | 282 | connect(addBut,SIGNAL(clicked()),SLOT(deleteAll())); |
276 | addBut->setMaximumWidth( addBut->sizeHint().height() ); | 283 | addBut->setMaximumWidth( addBut->sizeHint().height() ); |
277 | #endif | 284 | #endif |
278 | 285 | ||
279 | 286 | ||
280 | KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); | 287 | KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); |
281 | int row = 1; | 288 | int row = 1; |
282 | while ( kkf ) { | 289 | while ( kkf ) { |
283 | int iii = 0; | 290 | int iii = 0; |
284 | KOCalCheckButton* cb = new KOCalCheckButton( mw ); | 291 | KOCalCheckButton* cb = new KOCalCheckButton( mw ); |
285 | mainLayout->addWidget( cb,row,0 );mStdandardB.append( cb ); | 292 | mainLayout->addWidget( cb,row,0 );mStdandardB.append( cb ); |
286 | cb->setChecked( kkf->isStandard ); | 293 | cb->setChecked( kkf->isStandard ); |
287 | cb->setNum( kkf->mCalNumber ); | 294 | cb->setNum( kkf->mCalNumber ); |
288 | connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectStdCal(int,bool) ) ); | 295 | connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectStdCal(int,bool) ) ); |
289 | if ( kkf->mErrorOnLoad || kkf->isReadOnly ) | 296 | if ( kkf->mErrorOnLoad || kkf->isReadOnly ) |
290 | cb->setEnabled( false ); | 297 | cb->setEnabled( false ); |
291 | cb = new KOCalCheckButton( mw ); | 298 | cb = new KOCalCheckButton( mw ); |
292 | mainLayout->addWidget( cb,row,++iii );mEnabledB.append( cb ); | 299 | mainLayout->addWidget( cb,row,++iii );mEnabledB.append( cb ); |
293 | cb->setChecked( kkf->isEnabled ); | 300 | cb->setChecked( kkf->isEnabled ); |
294 | cb->setNum( kkf->mCalNumber ); | 301 | cb->setNum( kkf->mCalNumber ); |
295 | if ( kkf->mErrorOnLoad ) | 302 | if ( kkf->mErrorOnLoad ) |
296 | cb->setEnabled( false ); | 303 | cb->setEnabled( false ); |
297 | connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCal(int,bool) ) ); | 304 | connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCal(int,bool) ) ); |
298 | KOCalButton* name = new KOCalButton( mw ); | 305 | KOCalButton* name = new KOCalButton( mw ); |
299 | name->setNum( kkf->mCalNumber ); | 306 | name->setNum( kkf->mCalNumber ); |
300 | name->setText( kkf->mName ); | 307 | name->setText( kkf->mName ); |
301 | mainLayout->addWidget( name,row,++iii ); | 308 | mainLayout->addWidget( name,row,++iii ); |
302 | connect (name, SIGNAL (selectNum(int)), SLOT ( infoCal(int) ) ); | 309 | connect (name, SIGNAL (selectNum(int)), SLOT ( infoCal(int) ) ); |
303 | lab = new QLabel ( i18n(" "), mw ); | 310 | //lab = new QLabel (" ", mw ); |
304 | mainLayout->addWidget( lab,row,++iii ); | 311 | //mainLayout->addWidget( lab,row,++iii ); |
305 | cb = new KOCalCheckButton( mw ); | 312 | cb = new KOCalCheckButton( mw ); |
306 | mainLayout->addWidget( cb,row,++iii );mAlarmB.append( cb ); | 313 | mainLayout->addWidget( cb,row,++iii );mAlarmB.append( cb ); |
307 | cb->setChecked( kkf->isAlarmEnabled ); | 314 | cb->setChecked( kkf->isAlarmEnabled ); |
308 | cb->setNum( kkf->mCalNumber ); | 315 | cb->setNum( kkf->mCalNumber ); |
309 | connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCalAlarm(int,bool) ) ); | 316 | connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectCalAlarm(int,bool) ) ); |
310 | if ( kkf->mErrorOnLoad ) | 317 | if ( kkf->mErrorOnLoad ) |
311 | cb->setEnabled( false ); | 318 | cb->setEnabled( false ); |
312 | cb = new KOCalCheckButton( mw ); | 319 | cb = new KOCalCheckButton( mw ); |
313 | mainLayout->addWidget( cb,row,++iii );mROB.append( cb ); | 320 | mainLayout->addWidget( cb,row,++iii );mROB.append( cb ); |
314 | cb->setChecked( kkf->isReadOnly ); | 321 | cb->setChecked( kkf->isReadOnly ); |
315 | cb->setNum( kkf->mCalNumber ); | 322 | cb->setNum( kkf->mCalNumber ); |
316 | connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectReadOnly(int,bool) ) ); | 323 | connect (cb, SIGNAL (selectNum(int,bool)), SLOT ( selectReadOnly(int,bool) ) ); |
317 | if ( kkf->mErrorOnLoad ) | 324 | if ( kkf->mErrorOnLoad ) |
318 | cb->setEnabled( false ); | 325 | cb->setEnabled( false ); |
319 | if ( row > 1) { | 326 | if ( row > 1) { |
320 | KColorButton *colb = new KColorButton( mw ); | 327 | KColorButton *colb = new KColorButton( mw ); |
321 | mainLayout->addWidget( colb,row,++iii ); | 328 | mainLayout->addWidget( colb,row,++iii ); |
322 | colb->setID( kkf->mCalNumber ); | 329 | colb->setID( kkf->mCalNumber ); |
323 | colb->setColor( kkf->mDefaultColor ); | 330 | colb->setColor( kkf->mDefaultColor ); |
324 | connect (colb, SIGNAL (changedID(const QColor&, int )), SLOT ( setColor(const QColor&,int) ) ); | 331 | connect (colb, SIGNAL (changedID(const QColor&, int )), SLOT ( setColor(const QColor&,int) ) ); |
325 | KOCalButton* calb = new KOCalButton( mw ); | 332 | KOCalButton* calb = new KOCalButton( mw ); |
326 | mainLayout->addWidget( calb,row,++iii ); | 333 | mainLayout->addWidget( calb,row,++iii ); |
327 | calb->setNum( kkf->mCalNumber ); | 334 | calb->setNum( kkf->mCalNumber ); |
328 | calb->setPixmap ( SmallIcon("minus")); | 335 | calb->setPixmap ( SmallIcon("minus")); |
329 | connect (calb, SIGNAL (selectNum(int)), SLOT ( deleteCal(int) ) ); | 336 | connect (calb, SIGNAL (selectNum(int)), SLOT ( deleteCal(int) ) ); |
330 | int hei = calb->sizeHint().height(); | 337 | int hei = calb->sizeHint().height(); |
331 | //calb->setMaximumSize( hei*9/10, hei*9/10 ); | 338 | //calb->setMaximumSize( hei*9/10, hei*9/10 ); |
332 | } | 339 | } |
333 | ++row; | 340 | ++row; |
334 | kkf = KOPrefs::instance()->mCalendars.next(); | 341 | kkf = KOPrefs::instance()->mCalendars.next(); |
335 | } | 342 | } |
336 | lab = new QLabel ( "", mw ); | 343 | lab = new QLabel ( "", mw ); |
337 | mainLayout->addWidget( lab,row,0 ); | 344 | mainLayout->addWidget( lab,row,0 ); |
338 | mw->show(); | 345 | mw->show(); |
339 | 346 | ||
340 | } | 347 | } |
341 | void KOCalEditView::addCal() | 348 | void KOCalEditView::addCal() |
342 | { | 349 | { |
343 | bool tryagain = true; | 350 | bool tryagain = true; |
344 | QString name, file; | 351 | QString name, file; |
345 | while ( tryagain ) { | 352 | while ( tryagain ) { |
346 | KONewCalPrefs prefs ( this ); | 353 | KONewCalPrefs prefs ( this ); |
347 | prefs.nameE->setText( name ); | 354 | prefs.nameE->setText( name ); |
348 | prefs.url->setURL( file ); | 355 | prefs.url->setURL( file ); |
349 | if ( ! prefs.exec() ) | 356 | if ( ! prefs.exec() ) |
350 | return; | 357 | return; |
351 | name = prefs.calName(); | 358 | name = prefs.calName(); |
352 | file = prefs.calFileName(); | 359 | file = prefs.calFileName(); |
353 | tryagain = false; | 360 | tryagain = false; |
354 | KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); | 361 | KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); |
355 | while ( kkf ) { | 362 | while ( kkf ) { |
356 | if ( kkf->mName == name ) { | 363 | if ( kkf->mName == name ) { |
357 | KMessageBox::information( this, i18n("Sorry, the calendar name \n%1\nalready exists!\nPlease choose another name!").arg( name ) ); | 364 | KMessageBox::information( this, i18n("Sorry, the calendar name \n%1\nalready exists!\nPlease choose another name!").arg( name ) ); |
358 | name = ""; | 365 | name = ""; |
359 | tryagain = true; | 366 | tryagain = true; |
360 | break; | 367 | break; |
361 | } | 368 | } |
362 | if ( kkf->mFileName == file ) { | 369 | if ( kkf->mFileName == file ) { |
363 | KMessageBox::information( this, i18n("Sorry, the file \n%1\nis already loaded!\nPlease choose another file!").arg( KGlobal::formatMessage (file, 0 )) ); | 370 | KMessageBox::information( this, i18n("Sorry, the file \n%1\nis already loaded!\nPlease choose another file!").arg( KGlobal::formatMessage (file, 0 )) ); |
364 | tryagain = true; | 371 | tryagain = true; |
365 | file = ""; | 372 | file = ""; |
366 | break; | 373 | break; |
367 | } | 374 | } |
368 | kkf = KOPrefs::instance()->mCalendars.next(); | 375 | kkf = KOPrefs::instance()->mCalendars.next(); |
369 | } | 376 | } |
370 | } | 377 | } |
371 | QFileInfo fi ( file ); | 378 | QFileInfo fi ( file ); |
372 | if (!fi.exists() ) { | 379 | if (!fi.exists() ) { |
373 | if ( KMessageBox::questionYesNo(this, i18n("The file\n%1\ndoes not exist!\nShall I create it for you?").arg( file ) )== KMessageBox::No ) | 380 | if ( KMessageBox::questionYesNo(this, i18n("The file\n%1\ndoes not exist!\nShall I create it for you?").arg( file ) )== KMessageBox::No ) |
374 | return; | 381 | return; |
375 | QFile fileIn( file ); | 382 | QFile fileIn( file ); |
376 | if (!fileIn.open( IO_WriteOnly ) ) { | 383 | if (!fileIn.open( IO_WriteOnly ) ) { |
377 | KMessageBox::sorry( this, i18n("Sorry, cannot create the file\n%1!\nNo calendar added!").arg( file ) ); | 384 | KMessageBox::sorry( this, i18n("Sorry, cannot create the file\n%1!\nNo calendar added!").arg( file ) ); |
378 | return; | 385 | return; |
379 | } | 386 | } |
380 | QTextStream tsIn( &fileIn ); | 387 | QTextStream tsIn( &fileIn ); |
381 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 388 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
382 | tsIn << "BEGIN:VCALENDAR\nPRODID:-//KDE-Pim//Platform-independent 2.1.0\nVERSION:2.0\nEND:VCALENDAR\n"; | 389 | tsIn << "BEGIN:VCALENDAR\nPRODID:-//KDE-Pim//Platform-independent 2.1.0\nVERSION:2.0\nEND:VCALENDAR\n"; |
383 | fileIn.close(); | 390 | fileIn.close(); |
384 | } | 391 | } |
385 | KopiCalendarFile * kkf = KOPrefs::instance()->getNewCalendar(); | 392 | KopiCalendarFile * kkf = KOPrefs::instance()->getNewCalendar(); |
386 | kkf->mName = name; | 393 | kkf->mName = name; |
387 | kkf->mFileName = file; | 394 | kkf->mFileName = file; |
388 | emit calendarAdded( kkf->mCalNumber ); | 395 | emit calendarAdded( kkf->mCalNumber ); |
389 | emit needsUpdate(); | 396 | emit needsUpdate(); |
390 | QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); | 397 | QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); |
391 | } | 398 | } |
392 | void KOCalEditView::enableAll() | 399 | void KOCalEditView::enableAll() |
393 | { | 400 | { |
394 | toggleList( mEnabledB ); | 401 | toggleList( mEnabledB ); |
395 | } | 402 | } |
396 | void KOCalEditView::enableAlarm() | 403 | void KOCalEditView::enableAlarm() |
397 | { | 404 | { |
398 | toggleList( mAlarmB ); | 405 | toggleList( mAlarmB ); |
399 | } | 406 | } |
400 | void KOCalEditView::disableRO() | 407 | void KOCalEditView::disableRO() |
401 | { | 408 | { |
402 | toggleList( mROB ); | 409 | toggleList( mROB ); |
403 | } | 410 | } |
404 | void KOCalEditView::toggleList ( QPtrList<KOCalCheckButton> list ) | 411 | void KOCalEditView::toggleList ( QPtrList<KOCalCheckButton> list ) |
405 | { | 412 | { |
406 | bool dis = false; | 413 | bool dis = false; |
407 | KOCalCheckButton* it = list.first(); | 414 | KOCalCheckButton* it = list.first(); |
408 | while ( it ) { | 415 | while ( it ) { |
409 | if ( !it->isChecked() ) { | 416 | if ( !it->isChecked() ) { |
410 | dis = true; | 417 | dis = true; |
411 | break; | 418 | break; |
412 | } | 419 | } |
413 | it = list.next(); | 420 | it = list.next(); |
414 | } | 421 | } |
415 | it = list.first(); | 422 | it = list.first(); |
416 | while ( it ) { | 423 | while ( it ) { |
417 | it->setChecked(dis); | 424 | it->setChecked(dis); |
418 | it = list.next(); | 425 | it = list.next(); |
419 | } | 426 | } |
420 | } | 427 | } |
421 | void KOCalEditView::deleteAll() | 428 | void KOCalEditView::deleteAll() |
422 | { | 429 | { |
423 | qDebug("delteAll"); | 430 | qDebug("delteAll"); |
424 | } | 431 | } |