summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookweek.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index 874cf24..8241655 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -101,206 +101,204 @@ void DateBookWeekView::initNames()
101 header->addLabel( tr("S", "Sunday" ) ); 101 header->addLabel( tr("S", "Sunday" ) );
102 } else { 102 } else {
103 header->addLabel( tr("S", "Sunday" ) ); 103 header->addLabel( tr("S", "Sunday" ) );
104 header->addLabel( tr("M", "Monday") ); 104 header->addLabel( tr("M", "Monday") );
105 header->addLabel( tr("T", "Tuesday") ); 105 header->addLabel( tr("T", "Tuesday") );
106 header->addLabel( tr("W", "Wednesday" ) ); 106 header->addLabel( tr("W", "Wednesday" ) );
107 header->addLabel( tr("T", "Thursday" ) ); 107 header->addLabel( tr("T", "Thursday" ) );
108 header->addLabel( tr("F", "Friday" ) ); 108 header->addLabel( tr("F", "Friday" ) );
109 header->addLabel( tr("S", "Saturday" ) ); 109 header->addLabel( tr("S", "Saturday" ) );
110 } 110 }
111 bFirst = false; 111 bFirst = false;
112 } else { 112 } else {
113 // we are change things... 113 // we are change things...
114 if ( bOnMonday ) { 114 if ( bOnMonday ) {
115 header->setLabel( 1, tr("M", "Monday") ); 115 header->setLabel( 1, tr("M", "Monday") );
116 header->setLabel( 2, tr("T", "Tuesday") ); 116 header->setLabel( 2, tr("T", "Tuesday") );
117 header->setLabel( 3, tr("W", "Wednesday" ) ); 117 header->setLabel( 3, tr("W", "Wednesday" ) );
118 header->setLabel( 4, tr("T", "Thursday" ) ); 118 header->setLabel( 4, tr("T", "Thursday" ) );
119 header->setLabel( 5, tr("F", "Friday" ) ); 119 header->setLabel( 5, tr("F", "Friday" ) );
120 header->setLabel( 6, tr("S", "Saturday" ) ); 120 header->setLabel( 6, tr("S", "Saturday" ) );
121 header->setLabel( 7, tr("S", "Sunday" ) ); 121 header->setLabel( 7, tr("S", "Sunday" ) );
122 } else { 122 } else {
123 header->setLabel( 1, tr("S", "Sunday" ) ); 123 header->setLabel( 1, tr("S", "Sunday" ) );
124 header->setLabel( 2, tr("M", "Monday") ); 124 header->setLabel( 2, tr("M", "Monday") );
125 header->setLabel( 3, tr("T", "Tuesday") ); 125 header->setLabel( 3, tr("T", "Tuesday") );
126 header->setLabel( 4, tr("W", "Wednesday" ) ); 126 header->setLabel( 4, tr("W", "Wednesday" ) );
127 header->setLabel( 5, tr("T", "Thursday" ) ); 127 header->setLabel( 5, tr("T", "Thursday" ) );
128 header->setLabel( 6, tr("F", "Friday" ) ); 128 header->setLabel( 6, tr("F", "Friday" ) );
129 header->setLabel( 7, tr("S", "Saturday" ) ); 129 header->setLabel( 7, tr("S", "Saturday" ) );
130 } 130 }
131 } 131 }
132} 132}
133 133
134 134
135 135
136void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) 136void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev )
137{ 137{
138 items.clear(); 138 items.clear();
139 QValueListIterator<EffectiveEvent> it; 139 QValueListIterator<EffectiveEvent> it;
140 for ( it = ev.begin(); it != ev.end(); ++it ) { 140 for ( it = ev.begin(); it != ev.end(); ++it ) {
141 DateBookWeekItem *i = new DateBookWeekItem( *it ); 141 DateBookWeekItem *i = new DateBookWeekItem( *it );
142 if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) {// Skip events ending at 00:00 starting at another day. 142 if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) {// Skip events ending at 00:00 starting at another day.
143 positionItem( i ); 143 positionItem( i );
144 items.append( i ); 144 items.append( i );
145 } 145 }
146 } 146 }
147 viewport()->update(); 147 viewport()->update();
148} 148}
149 149
150void DateBookWeekView::moveToHour( int h ) 150void DateBookWeekView::moveToHour( int h )
151{ 151{
152 int offset = h*rowHeight; 152 int offset = h*rowHeight;
153 setContentsPos( 0, offset ); 153 setContentsPos( 0, offset );
154} 154}
155 155
156void DateBookWeekView::keyPressEvent( QKeyEvent *e ) 156void DateBookWeekView::keyPressEvent( QKeyEvent *e )
157{ 157{
158 e->ignore(); 158 e->ignore();
159} 159}
160 160
161void DateBookWeekView::slotChangeClock( bool c ) 161void DateBookWeekView::slotChangeClock( bool c )
162{ 162{
163 ampm = c; 163 ampm = c;
164 viewport()->update(); 164 viewport()->update();
165} 165}
166 166
167static inline int db_round30min( int m ) 167static inline int db_round30min( int m )
168{ 168{
169 if ( m < 15 ) 169 if ( m < 15 )
170 m = 0; 170 m = 0;
171 else if ( m < 45 ) 171 else if ( m < 45 )
172 m = 1; 172 m = 1;
173 else 173 else
174 m = 2; 174 m = 2;
175 175
176 return m; 176 return m;
177} 177}
178 178
179void DateBookWeekView::alterDay( int day ) 179void DateBookWeekView::alterDay( int day )
180{ 180{
181 if ( !bOnMonday ) { 181 if ( !bOnMonday ) {
182 day--; 182 day--;
183 } 183 }
184 emit showDay( day ); 184 emit showDay( day );
185} 185}
186 186
187void DateBookWeekView::positionItem( DateBookWeekItem *i ) 187void DateBookWeekView::positionItem( DateBookWeekItem *i )
188{ 188{
189 const int Width = 8; 189 const int Width = 8;
190 const EffectiveEvent ev = i->event(); 190 const EffectiveEvent ev = i->event();
191 191
192 // 30 minute intervals 192 // 30 minute intervals
193 int y = ev.start().hour() * 2; 193 int y = ev.start().hour() * 2;
194 y += db_round30min( ev.start().minute() ); 194 y += db_round30min( ev.start().minute() );
195 int y2 = ev.end().hour() * 2; 195 int y2 = ev.end().hour() * 2;
196 y2 += db_round30min( ev.end().minute() ); 196 y2 += db_round30min( ev.end().minute() );
197 if ( y > 47 ) 197 if ( y > 47 ) y = 47;
198 y = 47; 198 if ( y2 > 48 ) y2 = 48;
199 if ( y2 > 48 ) 199 y = (y * rowHeight) / 2;
200 y2 = 48; 200 y2 = (y2 * rowHeight) / 2;
201 y = y * rowHeight / 2;
202 y2 = y2 * rowHeight / 2;
203 201
204 int h; 202 int h;
205 if ( ev.event().type() == Event::AllDay ) { 203 if ( ev.event().type() == Event::AllDay ) {
206 h = 48 * rowHeight / 2; 204 h = (48 * rowHeight) / 2;
207 y = 0; 205 y = 0;
208 } else { 206 } else {
209 h=y2-y; 207 h=y2-y;
210 if ( h < 1 ) h = 1; 208 if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2;
211 } 209 }
212 210
213 int dow = ev.date().dayOfWeek(); 211 int dow = ev.date().dayOfWeek();
214 if ( !bOnMonday ) { 212 if ( !bOnMonday ) {
215 if ( dow == 7 ) 213 if ( dow == 7 )
216 dow = 1; 214 dow = 1;
217 else 215 else
218 dow++; 216 dow++;
219 } 217 }
220 int x = header->sectionPos( dow ) - 1; 218 int x = header->sectionPos( dow ) - 1;
221 int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); 219 int xlim = header->sectionPos( dow ) + header->sectionSize( dow );
222 DateBookWeekItem *isect = 0; 220 DateBookWeekItem *isect = 0;
223 do { 221 do {
224 i->setGeometry( x, y, Width, h ); 222 i->setGeometry( x, y, Width, h );
225 isect = intersects( i ); 223 isect = intersects( i );
226 x += Width - 1; 224 x += Width - 1;
227 } while ( isect && x < xlim ); 225 } while ( isect && x < xlim );
228} 226}
229 227
230DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) 228DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item )
231{ 229{
232 QRect geom = item->geometry(); 230 QRect geom = item->geometry();
233 231
234 // We allow the edges to overlap 232 // We allow the edges to overlap
235 geom.moveBy( 1, 1 ); 233 geom.moveBy( 1, 1 );
236 geom.setSize( geom.size()-QSize(2,2) ); 234 geom.setSize( geom.size()-QSize(2,2) );
237 235
238 QListIterator<DateBookWeekItem> it(items); 236 QListIterator<DateBookWeekItem> it(items);
239 for ( ; it.current(); ++it ) { 237 for ( ; it.current(); ++it ) {
240 DateBookWeekItem *i = it.current(); 238 DateBookWeekItem *i = it.current();
241 if ( i != item ) { 239 if ( i != item ) {
242 if ( i->geometry().intersects( geom ) ) { 240 if ( i->geometry().intersects( geom ) ) {
243 return i; 241 return i;
244 } 242 }
245 } 243 }
246 } 244 }
247 245
248 return 0; 246 return 0;
249} 247}
250 248
251void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) 249void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e )
252{ 250{
253 QListIterator<DateBookWeekItem> it(items); 251 QListIterator<DateBookWeekItem> it(items);
254 for ( ; it.current(); ++it ) { 252 for ( ; it.current(); ++it ) {
255 DateBookWeekItem *i = it.current(); 253 DateBookWeekItem *i = it.current();
256 if ( i->geometry().contains( e->pos() ) ) { 254 if ( i->geometry().contains( e->pos() ) ) {
257 showingEvent = true; 255 showingEvent = true;
258 emit signalShowEvent( i->event() ); 256 emit signalShowEvent( i->event() );
259 break; 257 break;
260 } 258 }
261 } 259 }
262} 260}
263 261
264void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) 262void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e )
265{ 263{
266 if ( showingEvent ) { 264 if ( showingEvent ) {
267 showingEvent = false; 265 showingEvent = false;
268 emit signalHideEvent(); 266 emit signalHideEvent();
269 } else { 267 } else {
270 int d = header->sectionAt( e->pos().x() ); 268 int d = header->sectionAt( e->pos().x() );
271 if ( d > 0 ) { 269 if ( d > 0 ) {
272 // if ( !bOnMonday ) 270 // if ( !bOnMonday )
273 // d--; 271 // d--;
274 emit showDay( d ); 272 emit showDay( d );
275 } 273 }
276 } 274 }
277} 275}
278 276
279void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) 277void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
280{ 278{
281 QRect ur( cx, cy, cw, ch ); 279 QRect ur( cx, cy, cw, ch );
282 p->setPen( lightGray ); 280 p->setPen( lightGray );
283 for ( int i = 1; i <= 7; i++ ) 281 for ( int i = 1; i <= 7; i++ )
284 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); 282 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch );
285 283
286 p->setPen( black ); 284 p->setPen( black );
287 for ( int t = 0; t < 24; t++ ) { 285 for ( int t = 0; t < 24; t++ ) {
288 int y = t*rowHeight; 286 int y = t*rowHeight;
289 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { 287 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) {
290 QString s; 288 QString s;
291 if ( ampm ) { 289 if ( ampm ) {
292 if ( t == 0 ) 290 if ( t == 0 )
293 s = QString::number( 12 ); 291 s = QString::number( 12 );
294 else if ( t == 12 ) 292 else if ( t == 12 )
295 s = QString::number(12) + tr( "p" ); 293 s = QString::number(12) + tr( "p" );
296 else if ( t > 12 ) { 294 else if ( t > 12 ) {
297 if ( t - 12 < 10 ) 295 if ( t - 12 < 10 )
298 s = " "; 296 s = " ";
299 else 297 else
300 s = ""; 298 s = "";
301 s += QString::number( t - 12 ) + tr("p"); 299 s += QString::number( t - 12 ) + tr("p");
302 } else { 300 } else {
303 if ( 12 - t < 3 ) 301 if ( 12 - t < 3 )
304 s = ""; 302 s = "";
305 else 303 else
306 s = " "; 304 s = " ";