summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/clickablelabel.cpp6
-rw-r--r--core/pim/datebook/datebookday.cpp8
-rw-r--r--core/pim/datebook/datebookweek.cpp2
-rw-r--r--core/pim/datebook/datebookweeklst.cpp12
-rw-r--r--core/pim/datebook/timepicker.cpp4
5 files changed, 16 insertions, 16 deletions
diff --git a/core/pim/datebook/clickablelabel.cpp b/core/pim/datebook/clickablelabel.cpp
index 1dd0d15..128bebb 100644
--- a/core/pim/datebook/clickablelabel.cpp
+++ b/core/pim/datebook/clickablelabel.cpp
@@ -1,88 +1,88 @@
1#include "clickablelabel.h" 1#include "clickablelabel.h"
2#include <stdio.h> 2#include <stdio.h>
3 3
4ClickableLabel::ClickableLabel(QWidget* parent = 0, 4ClickableLabel::ClickableLabel(QWidget* parent,
5 const char* name = 0, 5 const char* name,
6 WFlags fl = 0) : 6 WFlags fl) :
7 QLabel(parent,name,fl) 7 QLabel(parent,name,fl)
8{ 8{
9 textInverted=false; 9 textInverted=false;
10 isToggle=false; 10 isToggle=false;
11 isDown=false; 11 isDown=false;
12 showState(false); 12 showState(false);
13 setFrameShadow(Sunken); 13 setFrameShadow(Sunken);
14} 14}
15 15
16void ClickableLabel::setToggleButton(bool t) { 16void ClickableLabel::setToggleButton(bool t) {
17 isToggle=t; 17 isToggle=t;
18} 18}
19 19
20void ClickableLabel::mousePressEvent( QMouseEvent *e ) { 20void ClickableLabel::mousePressEvent( QMouseEvent *e ) {
21 if (isToggle && isDown) { 21 if (isToggle && isDown) {
22 showState(false); 22 showState(false);
23 } else { 23 } else {
24 showState(true); 24 showState(true);
25 } 25 }
26} 26}
27 27
28void ClickableLabel::mouseReleaseEvent( QMouseEvent *e ) { 28void ClickableLabel::mouseReleaseEvent( QMouseEvent *e ) {
29 if (rect().contains(e->pos()) && isToggle) isDown=!isDown; 29 if (rect().contains(e->pos()) && isToggle) isDown=!isDown;
30 30
31 if (isToggle && isDown) { 31 if (isToggle && isDown) {
32 showState(true); 32 showState(true);
33 } else { 33 } else {
34 showState(false); 34 showState(false);
35 } 35 }
36 36
37 if (rect().contains(e->pos())) { 37 if (rect().contains(e->pos())) {
38 if (isToggle) { 38 if (isToggle) {
39 emit toggled(isDown); 39 emit toggled(isDown);
40 } 40 }
41 emit clicked(); 41 emit clicked();
42 } 42 }
43} 43}
44 44
45void ClickableLabel::mouseMoveEvent( QMouseEvent *e ) { 45void ClickableLabel::mouseMoveEvent( QMouseEvent *e ) {
46 if (rect().contains(e->pos())) { 46 if (rect().contains(e->pos())) {
47 if (isToggle && isDown) { 47 if (isToggle && isDown) {
48 showState(false); 48 showState(false);
49 } else { 49 } else {
50 showState(true); 50 showState(true);
51 } 51 }
52 } else { 52 } else {
53 if (isToggle && isDown) { 53 if (isToggle && isDown) {
54 showState(true); 54 showState(true);
55 } else { 55 } else {
56 showState(false); 56 showState(false);
57 } 57 }
58 } 58 }
59} 59}
60 60
61void ClickableLabel::showState(bool on) { 61void ClickableLabel::showState(bool on) {
62 if (on) { 62 if (on) {
63 //setFrameShape(Panel); 63 //setFrameShape(Panel);
64 setInverted(true); 64 setInverted(true);
65 setBackgroundMode(PaletteHighlight); 65 setBackgroundMode(PaletteHighlight);
66 } else { 66 } else {
67 //setFrameShape(NoFrame); 67 //setFrameShape(NoFrame);
68 setInverted(false); 68 setInverted(false);
69 setBackgroundMode(PaletteBackground); 69 setBackgroundMode(PaletteBackground);
70 } 70 }
71 repaint(); 71 repaint();
72} 72}
73 73
74void ClickableLabel::setInverted(bool on) { 74void ClickableLabel::setInverted(bool on) {
75 if ( (!textInverted && on) || (textInverted && !on) ) { 75 if ( (!textInverted && on) || (textInverted && !on) ) {
76 QPalette pal=palette(); 76 QPalette pal=palette();
77 QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground); 77 QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground);
78 col.setRgb(255-col.red(),255-col.green(),255-col.blue()); 78 col.setRgb(255-col.red(),255-col.green(),255-col.blue());
79 pal.setColor(QPalette::Normal, QColorGroup::Foreground, col); 79 pal.setColor(QPalette::Normal, QColorGroup::Foreground, col);
80 setPalette(pal); 80 setPalette(pal);
81 textInverted=!textInverted; 81 textInverted=!textInverted;
82 } 82 }
83} 83}
84 84
85void ClickableLabel::setOn(bool on) { 85void ClickableLabel::setOn(bool on) {
86 isDown=on; 86 isDown=on;
87 showState(isDown); 87 showState(isDown);
88} 88}
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp
index d5daab2..67a88e9 100644
--- a/core/pim/datebook/datebookday.cpp
+++ b/core/pim/datebook/datebookday.cpp
@@ -1,553 +1,553 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "datebookday.h" 21#include "datebookday.h"
22#include "datebookdayheaderimpl.h" 22#include "datebookdayheaderimpl.h"
23 23
24#include <qpe/datebookdb.h> 24#include <qpe/datebookdb.h>
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/event.h> 26#include <qpe/event.h>
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qpe/timestring.h> 28#include <qpe/timestring.h>
29#include <qpe/qpedebug.h> 29#include <qpe/qpedebug.h>
30 30
31#include <qheader.h> 31#include <qheader.h>
32#include <qdatetime.h> 32#include <qdatetime.h>
33#include <qpainter.h> 33#include <qpainter.h>
34#include <qsimplerichtext.h> 34#include <qsimplerichtext.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36#include <qtextcodec.h> 36#include <qtextcodec.h>
37#include <qpalette.h> 37#include <qpalette.h>
38 38
39DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, 39DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent,
40 const char *name ) 40 const char *name )
41 : QTable( 24, 1, parent, name ), 41 : QTable( 24, 1, parent, name ),
42 ampm( whichClock ) 42 ampm( whichClock )
43{ 43{
44 enableClipper(TRUE); 44 enableClipper(TRUE);
45 setTopMargin( 0 ); 45 setTopMargin( 0 );
46 horizontalHeader()->hide(); 46 horizontalHeader()->hide();
47 setLeftMargin(38); 47 setLeftMargin(38);
48 setColumnStretchable( 0, TRUE ); 48 setColumnStretchable( 0, TRUE );
49 setHScrollBarMode( QScrollView::AlwaysOff ); 49 setHScrollBarMode( QScrollView::AlwaysOff );
50 verticalHeader()->setPalette(white); 50 verticalHeader()->setPalette(white);
51 verticalHeader()->setResizeEnabled(FALSE); 51 verticalHeader()->setResizeEnabled(FALSE);
52 setSelectionMode( Single ); 52 setSelectionMode( Single );
53 53
54 // get rid of being able to edit things... 54 // get rid of being able to edit things...
55 QTableItem *tmp; 55 QTableItem *tmp;
56 int row; 56 int row;
57 for ( row = 0; row < numRows(); row++ ) { 57 for ( row = 0; row < numRows(); row++ ) {
58 tmp = new QTableItem( this, QTableItem::Never, QString::null); 58 tmp = new QTableItem( this, QTableItem::Never, QString::null);
59 setItem( row, 0, tmp ); 59 setItem( row, 0, tmp );
60 } 60 }
61 initHeader(); 61 initHeader();
62 QObject::connect( qApp, SIGNAL(clockChanged(bool)), 62 QObject::connect( qApp, SIGNAL(clockChanged(bool)),
63 this, SLOT(slotChangeClock(bool)) ); 63 this, SLOT(slotChangeClock(bool)) );
64} 64}
65 65
66void DateBookDayView::initHeader() 66void DateBookDayView::initHeader()
67{ 67{
68 QString strTmp; 68 QString strTmp;
69 for ( int i = 0; i < 24; ++i ) { 69 for ( int i = 0; i < 24; ++i ) {
70 if ( ampm ) { 70 if ( ampm ) {
71 if ( i == 0 ) 71 if ( i == 0 )
72 strTmp = QString::number(12) + ":00"; 72 strTmp = QString::number(12) + ":00";
73 else if ( i == 12 ) 73 else if ( i == 12 )
74 strTmp = QString::number(12) + tr(":00p"); 74 strTmp = QString::number(12) + tr(":00p");
75 else if ( i > 12 ) 75 else if ( i > 12 )
76 strTmp = QString::number( i - 12 ) + tr(":00p"); 76 strTmp = QString::number( i - 12 ) + tr(":00p");
77 else 77 else
78 strTmp = QString::number(i) + ":00"; 78 strTmp = QString::number(i) + ":00";
79 } else { 79 } else {
80 if ( i < 10 ) 80 if ( i < 10 )
81 strTmp = "0" + QString::number(i) + ":00"; 81 strTmp = "0" + QString::number(i) + ":00";
82 else 82 else
83 strTmp = QString::number(i) + ":00"; 83 strTmp = QString::number(i) + ":00";
84 } 84 }
85 strTmp = strTmp.rightJustify( 6, ' ' ); 85 strTmp = strTmp.rightJustify( 6, ' ' );
86 verticalHeader()->setLabel( i, strTmp ); 86 verticalHeader()->setLabel( i, strTmp );
87 setRowStretchable( i, FALSE ); 87 setRowStretchable( i, FALSE );
88 } 88 }
89} 89}
90 90
91void DateBookDayView::slotChangeClock( bool newClock ) 91void DateBookDayView::slotChangeClock( bool newClock )
92{ 92{
93 ampm = newClock; 93 ampm = newClock;
94 initHeader(); 94 initHeader();
95} 95}
96 96
97bool DateBookDayView::whichClock() const 97bool DateBookDayView::whichClock() const
98{ 98{
99 return ampm; 99 return ampm;
100} 100}
101 101
102void DateBookDayView::moveUp() 102void DateBookDayView::moveUp()
103{ 103{
104 scrollBy(0, -20); 104 scrollBy(0, -20);
105} 105}
106 106
107void DateBookDayView::moveDown() 107void DateBookDayView::moveDown()
108{ 108{
109 scrollBy(0, 20); 109 scrollBy(0, 20);
110} 110}
111 111
112void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) 112void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool )
113{ 113{
114 int w = cr.width(); 114 int w = cr.width();
115 int h = cr.height(); 115 int h = cr.height();
116 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); 116 p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) );
117 if ( showGrid() ) { 117 if ( showGrid() ) {
118 // Draw our lines 118 // Draw our lines
119 int x2 = w - 1; 119 int x2 = w - 1;
120 int y2 = h - 1; 120 int y2 = h - 1;
121 QPen pen( p->pen() ); 121 QPen pen( p->pen() );
122 p->setPen( colorGroup().mid() ); 122 p->setPen( colorGroup().mid() );
123 p->drawLine( x2, 0, x2, y2 ); 123 p->drawLine( x2, 0, x2, y2 );
124 p->drawLine( 0, y2, x2, y2 ); 124 p->drawLine( 0, y2, x2, y2 );
125 p->setPen( pen ); 125 p->setPen( pen );
126 } 126 }
127} 127}
128 128
129void DateBookDayView::paintFocus( QPainter *, const QRect & ) 129void DateBookDayView::paintFocus( QPainter *, const QRect & )
130{ 130{
131} 131}
132 132
133 133
134void DateBookDayView::resizeEvent( QResizeEvent *e ) 134void DateBookDayView::resizeEvent( QResizeEvent *e )
135{ 135{
136 QTable::resizeEvent( e ); 136 QTable::resizeEvent( e );
137 columnWidthChanged( 0 ); 137 columnWidthChanged( 0 );
138 emit sigColWidthChanged(); 138 emit sigColWidthChanged();
139} 139}
140 140
141void DateBookDayView::keyPressEvent( QKeyEvent *e ) 141void DateBookDayView::keyPressEvent( QKeyEvent *e )
142{ 142{
143 QString txt = e->text(); 143 QString txt = e->text();
144 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { 144 if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) {
145 // we this is some sort of thing we know about... 145 // we this is some sort of thing we know about...
146 e->accept(); 146 e->accept();
147 emit sigCapturedKey( txt ); 147 emit sigCapturedKey( txt );
148 } else { 148 } else {
149 // I don't know what this key is, do you? 149 // I don't know what this key is, do you?
150 e->ignore(); 150 e->ignore();
151 } 151 }
152} 152}
153 153
154 154
155//=========================================================================== 155//===========================================================================
156 156
157DateBookDay::DateBookDay( bool ampm, bool startOnMonday, 157DateBookDay::DateBookDay( bool ampm, bool startOnMonday,
158 DateBookDB *newDb, QWidget *parent, 158 DateBookDB *newDb, QWidget *parent,
159 const char *name ) 159 const char *name )
160 : QVBox( parent, name ), 160 : QVBox( parent, name ),
161 currDate( QDate::currentDate() ), 161 currDate( QDate::currentDate() ),
162 db( newDb ), 162 db( newDb ),
163 startTime( 0 ) 163 startTime( 0 )
164{ 164{
165 widgetList.setAutoDelete( true ); 165 widgetList.setAutoDelete( true );
166 header = new DateBookDayHeader( startOnMonday, this, "day header" ); 166 header = new DateBookDayHeader( startOnMonday, this, "day header" );
167 header->setDate( currDate.year(), currDate.month(), currDate.day() ); 167 header->setDate( currDate.year(), currDate.month(), currDate.day() );
168 view = new DateBookDayView( ampm, this, "day view" ); 168 view = new DateBookDayView( ampm, this, "day view" );
169 connect( header, SIGNAL( dateChanged( int, int, int ) ), 169 connect( header, SIGNAL( dateChanged( int, int, int ) ),
170 this, SLOT( dateChanged( int, int, int ) ) ); 170 this, SLOT( dateChanged( int, int, int ) ) );
171 connect( view, SIGNAL( sigColWidthChanged() ), 171 connect( view, SIGNAL( sigColWidthChanged() ),
172 this, SLOT( slotColWidthChanged() ) ); 172 this, SLOT( slotColWidthChanged() ) );
173 connect( qApp, SIGNAL(weekChanged(bool)), 173 connect( qApp, SIGNAL(weekChanged(bool)),
174 this, SLOT(slotWeekChanged(bool)) ); 174 this, SLOT(slotWeekChanged(bool)) );
175 connect( view, SIGNAL(sigCapturedKey(const QString &)), 175 connect( view, SIGNAL(sigCapturedKey(const QString &)),
176 this, SIGNAL(sigNewEvent(const QString&)) ); 176 this, SIGNAL(sigNewEvent(const QString&)) );
177} 177}
178 178
179void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) 179void DateBookDay::selectedDates( QDateTime &start, QDateTime &end )
180{ 180{
181 start.setDate( currDate ); 181 start.setDate( currDate );
182 end.setDate( currDate ); 182 end.setDate( currDate );
183 183
184 int sh=99,eh=-1; 184 int sh=99,eh=-1;
185 185
186 int n = dayView()->numSelections(); 186 int n = dayView()->numSelections();
187 187
188 for (int i=0; i<n; i++) { 188 for (int i=0; i<n; i++) {
189 QTableSelection sel = dayView()->selection( i ); 189 QTableSelection sel = dayView()->selection( i );
190 sh = QMIN(sh,sel.topRow()); 190 sh = QMIN(sh,sel.topRow());
191 eh = QMAX(sh,sel.bottomRow()+1); 191 eh = QMAX(sh,sel.bottomRow()+1);
192 } 192 }
193 if (sh > 23 || eh < 1) { 193 if (sh > 23 || eh < 1) {
194 sh=8; 194 sh=8;
195 eh=9; 195 eh=9;
196 } 196 }
197 197
198 start.setTime( QTime( sh, 0, 0 ) ); 198 start.setTime( QTime( sh, 0, 0 ) );
199 end.setTime( QTime( eh, 0, 0 ) ); 199 end.setTime( QTime( eh, 0, 0 ) );
200} 200}
201 201
202void DateBookDay::setDate( int y, int m, int d ) 202void DateBookDay::setDate( int y, int m, int d )
203{ 203{
204 header->setDate( y, m, d ); 204 header->setDate( y, m, d );
205} 205}
206 206
207void DateBookDay::setDate( QDate d) 207void DateBookDay::setDate( QDate d)
208{ 208{
209 header->setDate( d.year(), d.month(), d.day() ); 209 header->setDate( d.year(), d.month(), d.day() );
210} 210}
211 211
212void DateBookDay::dateChanged( int y, int m, int d ) 212void DateBookDay::dateChanged( int y, int m, int d )
213{ 213{
214 QDate date( y, m, d ); 214 QDate date( y, m, d );
215 if ( currDate == date ) 215 if ( currDate == date )
216 return; 216 return;
217 currDate.setYMD( y, m, d ); 217 currDate.setYMD( y, m, d );
218 relayoutPage(); 218 relayoutPage();
219 dayView()->clearSelection(); 219 dayView()->clearSelection();
220 QTableSelection ts; 220 QTableSelection ts;
221 ts.init( startTime, 0 ); 221 ts.init( startTime, 0 );
222 ts.expandTo( startTime, 0 ); 222 ts.expandTo( startTime, 0 );
223 dayView()->addSelection( ts ); 223 dayView()->addSelection( ts );
224} 224}
225 225
226void DateBookDay::redraw() 226void DateBookDay::redraw()
227{ 227{
228 if ( isUpdatesEnabled() ) 228 if ( isUpdatesEnabled() )
229 relayoutPage(); 229 relayoutPage();
230} 230}
231 231
232void DateBookDay::getEvents() 232void DateBookDay::getEvents()
233{ 233{
234 widgetList.clear(); 234 widgetList.clear();
235 235
236 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, 236 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate,
237 currDate ); 237 currDate );
238 QValueListIterator<EffectiveEvent> it; 238 QValueListIterator<EffectiveEvent> it;
239 for ( it = eventList.begin(); it != eventList.end(); ++it ) { 239 for ( it = eventList.begin(); it != eventList.end(); ++it ) {
240 DateBookDayWidget* w = new DateBookDayWidget( *it, this ); 240 DateBookDayWidget* w = new DateBookDayWidget( *it, this );
241 connect( w, SIGNAL( deleteMe( const Event & ) ), 241 connect( w, SIGNAL( deleteMe( const Event & ) ),
242 this, SIGNAL( removeEvent( const Event & ) ) ); 242 this, SIGNAL( removeEvent( const Event & ) ) );
243 connect( w, SIGNAL( editMe( const Event & ) ), 243 connect( w, SIGNAL( editMe( const Event & ) ),
244 this, SIGNAL( editEvent( const Event & ) ) ); 244 this, SIGNAL( editEvent( const Event & ) ) );
245 connect( w, SIGNAL( beamMe( const Event & ) ), 245 connect( w, SIGNAL( beamMe( const Event & ) ),
246 this, SIGNAL( beamEvent( const Event & ) ) ); 246 this, SIGNAL( beamEvent( const Event & ) ) );
247 widgetList.append( w ); 247 widgetList.append( w );
248 } 248 }
249} 249}
250 250
251static int place( const DateBookDayWidget *item, bool *used, int maxn ) 251static int place( const DateBookDayWidget *item, bool *used, int maxn )
252{ 252{
253 int place = 0; 253 int place = 0;
254 int start = item->event().start().hour(); 254 int start = item->event().start().hour();
255 QTime e = item->event().end(); 255 QTime e = item->event().end();
256 int end = e.hour(); 256 int end = e.hour();
257 if ( e.minute() < 5 ) 257 if ( e.minute() < 5 )
258 end--; 258 end--;
259 if ( end < start ) 259 if ( end < start )
260 end = start; 260 end = start;
261 while ( place < maxn ) { 261 while ( place < maxn ) {
262 bool free = TRUE; 262 bool free = TRUE;
263 int s = start; 263 int s = start;
264 while( s <= end ) { 264 while( s <= end ) {
265 if ( used[10*s+place] ) { 265 if ( used[10*s+place] ) {
266 free = FALSE; 266 free = FALSE;
267 break; 267 break;
268 } 268 }
269 s++; 269 s++;
270 } 270 }
271 if ( free ) break; 271 if ( free ) break;
272 place++; 272 place++;
273 } 273 }
274 if ( place == maxn ) { 274 if ( place == maxn ) {
275 return -1; 275 return -1;
276 } 276 }
277 while( start <= end ) { 277 while( start <= end ) {
278 used[10*start+place] = TRUE; 278 used[10*start+place] = TRUE;
279 start++; 279 start++;
280 } 280 }
281 return place; 281 return place;
282} 282}
283 283
284 284
285void DateBookDay::relayoutPage( bool fromResize ) 285void DateBookDay::relayoutPage( bool fromResize )
286{ 286{
287 setUpdatesEnabled( FALSE ); 287 setUpdatesEnabled( FALSE );
288 if ( !fromResize ) 288 if ( !fromResize )
289 getEvents(); // no need we already have them! 289 getEvents(); // no need we already have them!
290 290
291 int wCount = widgetList.count(); 291 int wCount = widgetList.count();
292 int wid = view->columnWidth(0)-1; 292 int wid = view->columnWidth(0)-1;
293 int n = 1; 293 int n = 1;
294 294
295 if ( wCount < 20 ) { 295 if ( wCount < 20 ) {
296 for ( int i = 0; i < wCount; ) { 296 for ( int i = 0; i < wCount; ) {
297 DateBookDayWidget *w = widgetList.at(i); 297 DateBookDayWidget *w = widgetList.at(i);
298 int x = 0; 298 int x = 0;
299 int xp = 0; 299 int xp = 0;
300 QRect geom = w->geometry(); 300 QRect geom = w->geometry();
301 geom.setX( x ); 301 geom.setX( x );
302 geom.setWidth( wid ); 302 geom.setWidth( wid );
303 while ( xp < n && intersects( w, geom ) ) { 303 while ( xp < n && intersects( w, geom ) ) {
304 x += wid; 304 x += wid;
305 xp++; 305 xp++;
306 geom.moveBy( wid, 0 ); 306 geom.moveBy( wid, 0 );
307 } 307 }
308 if ( xp >= n ) { 308 if ( xp >= n ) {
309 n++; 309 n++;
310 wid = ( view->columnWidth(0)-1 ) / n; 310 wid = ( view->columnWidth(0)-1 ) / n;
311 i = 0; 311 i = 0;
312 } else { 312 } else {
313 w->setGeometry( geom ); 313 w->setGeometry( geom );
314 i++; 314 i++;
315 } 315 }
316 } 316 }
317 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 317 view->setContentsPos( 0, startTime * view->rowHeight(0) );
318 } else { 318 } else {
319 319
320 320
321 int hours[24]; 321 int hours[24];
322 memset( hours, 0, 24*sizeof( int ) ); 322 memset( hours, 0, 24*sizeof( int ) );
323 bool overFlow = FALSE; 323 bool overFlow = FALSE;
324 for ( int i = 0; i < wCount; i++ ) { 324 for ( int i = 0; i < wCount; i++ ) {
325 DateBookDayWidget *w = widgetList.at(i); 325 DateBookDayWidget *w = widgetList.at(i);
326 int start = w->event().start().hour(); 326 int start = w->event().start().hour();
327 QTime e = w->event().end(); 327 QTime e = w->event().end();
328 int end = e.hour(); 328 int end = e.hour();
329 if ( e.minute() < 5 ) 329 if ( e.minute() < 5 )
330 end--; 330 end--;
331 if ( end < start ) 331 if ( end < start )
332 end = start; 332 end = start;
333 while( start <= end ) { 333 while( start <= end ) {
334 hours[start]++; 334 hours[start]++;
335 if ( hours[start] >= 10 ) 335 if ( hours[start] >= 10 )
336 overFlow = TRUE; 336 overFlow = TRUE;
337 ++start; 337 ++start;
338 } 338 }
339 if ( overFlow ) 339 if ( overFlow )
340 break; 340 break;
341 } 341 }
342 for ( int i = 0; i < 24; i++ ) { 342 for ( int i = 0; i < 24; i++ ) {
343 n = QMAX( n, hours[i] ); 343 n = QMAX( n, hours[i] );
344 } 344 }
345 wid = ( view->columnWidth(0)-1 ) / n; 345 wid = ( view->columnWidth(0)-1 ) / n;
346 346
347 bool used[24*10]; 347 bool used[24*10];
348 memset( used, FALSE, 24*10*sizeof( bool ) ); 348 memset( used, FALSE, 24*10*sizeof( bool ) );
349 349
350 for ( int i = 0; i < wCount; i++ ) { 350 for ( int i = 0; i < wCount; i++ ) {
351 DateBookDayWidget *w = widgetList.at(i); 351 DateBookDayWidget *w = widgetList.at(i);
352 int xp = place( w, used, n ); 352 int xp = place( w, used, n );
353 if ( xp != -1 ) { 353 if ( xp != -1 ) {
354 QRect geom = w->geometry(); 354 QRect geom = w->geometry();
355 geom.setX( xp*wid ); 355 geom.setX( xp*wid );
356 geom.setWidth( wid ); 356 geom.setWidth( wid );
357 w->setGeometry( geom ); 357 w->setGeometry( geom );
358 } 358 }
359 } 359 }
360 view->setContentsPos( 0, startTime * view->rowHeight(0) ); 360 view->setContentsPos( 0, startTime * view->rowHeight(0) );
361 } 361 }
362 setUpdatesEnabled( TRUE ); 362 setUpdatesEnabled( TRUE );
363 return; 363 return;
364} 364}
365 365
366DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) 366DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom )
367{ 367{
368 int i = 0; 368 int i = 0;
369 DateBookDayWidget *w = widgetList.at(i); 369 DateBookDayWidget *w = widgetList.at(i);
370 int wCount = widgetList.count(); 370 int wCount = widgetList.count();
371 while ( i < wCount && w != item ) { 371 while ( i < wCount && w != item ) {
372 if ( w->geometry().intersects( geom ) ) { 372 if ( w->geometry().intersects( geom ) ) {
373 return w; 373 return w;
374 } 374 }
375 w = widgetList.at(++i); 375 w = widgetList.at(++i);
376 } 376 }
377 377
378 return 0; 378 return 0;
379} 379}
380 380
381 381
382QDate DateBookDay::date() const 382QDate DateBookDay::date() const
383{ 383{
384 return currDate; 384 return currDate;
385} 385}
386 386
387void DateBookDay::setStartViewTime( int startHere ) 387void DateBookDay::setStartViewTime( int startHere )
388{ 388{
389 startTime = startHere; 389 startTime = startHere;
390 dayView()->clearSelection(); 390 dayView()->clearSelection();
391 QTableSelection ts; 391 QTableSelection ts;
392 ts.init( startTime, 0 ); 392 ts.init( startTime, 0 );
393 ts.expandTo( startTime, 0 ); 393 ts.expandTo( startTime, 0 );
394 dayView()->addSelection( ts ); 394 dayView()->addSelection( ts );
395} 395}
396 396
397int DateBookDay::startViewTime() const 397int DateBookDay::startViewTime() const
398{ 398{
399 return startTime; 399 return startTime;
400} 400}
401 401
402void DateBookDay::slotWeekChanged( bool bStartOnMonday ) 402void DateBookDay::slotWeekChanged( bool bStartOnMonday )
403{ 403{
404 header->setStartOfWeek( bStartOnMonday ); 404 header->setStartOfWeek( bStartOnMonday );
405 // redraw(); 405 // redraw();
406} 406}
407 407
408void DateBookDay::keyPressEvent(QKeyEvent *e) 408void DateBookDay::keyPressEvent(QKeyEvent *e)
409{ 409{
410 switch(e->key()) { 410 switch(e->key()) {
411 case Key_Up: 411 case Key_Up:
412 view->moveUp(); 412 view->moveUp();
413 break; 413 break;
414 case Key_Down: 414 case Key_Down:
415 view->moveDown(); 415 view->moveDown();
416 break; 416 break;
417 case Key_Left: 417 case Key_Left:
418 setDate(QDate(currDate).addDays(-1)); 418 setDate(QDate(currDate).addDays(-1));
419 break; 419 break;
420 case Key_Right: 420 case Key_Right:
421 setDate(QDate(currDate).addDays(1)); 421 setDate(QDate(currDate).addDays(1));
422 break; 422 break;
423 default: 423 default:
424 e->ignore(); 424 e->ignore();
425 } 425 }
426} 426}
427 427
428//=========================================================================== 428//===========================================================================
429 429
430DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, 430DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e,
431 DateBookDay *db ) 431 DateBookDay *db )
432 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) 432 : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db )
433{ 433{
434 bool whichClock = db->dayView()->whichClock(); 434 bool whichClock = db->dayView()->whichClock();
435 435
436 // why would someone use "<"? Oh well, fix it up... 436 // why would someone use "<"? Oh well, fix it up...
437 // I wonder what other things may be messed up... 437 // I wonder what other things may be messed up...
438 QString strDesc = ev.description(); 438 QString strDesc = ev.description();
439 int where = strDesc.find( "<" ); 439 int where = strDesc.find( "<" );
440 while ( where != -1 ) { 440 while ( where != -1 ) {
441 strDesc.remove( where, 1 ); 441 strDesc.remove( where, 1 );
442 strDesc.insert( where, "&#60;" ); 442 strDesc.insert( where, "&#60;" );
443 where = strDesc.find( "<", where ); 443 where = strDesc.find( "<", where );
444 } 444 }
445 445
446 QString strCat; 446 QString strCat;
447 // ### Fix later... 447 // ### Fix later...
448// QString strCat = ev.category(); 448// QString strCat = ev.category();
449// where = strCat.find( "<" ); 449// where = strCat.find( "<" );
450// while ( where != -1 ) { 450// while ( where != -1 ) {
451 // strCat.remove( where, 1 ); 451 // strCat.remove( where, 1 );
452 // strCat.insert( where, "&#60;" ); 452 // strCat.insert( where, "&#60;" );
453 // where = strCat.find( "<", where ); 453 // where = strCat.find( "<", where );
454// } 454// }
455 455
456 QString strNote = ev.notes(); 456 QString strNote = ev.notes();
457 where = strNote.find( "<" ); 457 where = strNote.find( "<" );
458 while ( where != -1 ) { 458 while ( where != -1 ) {
459 strNote.remove( where, 1 ); 459 strNote.remove( where, 1 );
460 strNote.insert( where, "&#60;" ); 460 strNote.insert( where, "&#60;" );
461 where = strNote.find( "<", where ); 461 where = strNote.find( "<", where );
462 } 462 }
463 463
464 text = "<b>" + strDesc + "</b><br>" + "<i>" 464 text = "<b>" + strDesc + "</b><br>" + "<i>"
465 + strCat + "</i>" 465 + strCat + "</i>"
466 + "<br><b>" + tr("Start") + "</b>: "; 466 + "<br><b>" + tr("Start") + "</b>: ";
467 467
468 468
469 if ( e.startDate() != ev.date() ) { 469 if ( e.startDate() != ev.date() ) {
470 // multi-day event. Show start date 470 // multi-day event. Show start date
471 text += TimeString::longDateString( e.startDate() ); 471 text += TimeString::longDateString( e.startDate() );
472 } else { 472 } else {
473 // Show start time. 473 // Show start time.
474 text += TimeString::timeString( ev.start(), whichClock, FALSE ); 474 text += TimeString::timeString( ev.start(), whichClock, FALSE );
475 } 475 }
476 476
477 text += "<br><b>" + tr("End") + "</b>: "; 477 text += "<br><b>" + tr("End") + "</b>: ";
478 if ( e.endDate() != ev.date() ) { 478 if ( e.endDate() != ev.date() ) {
479 // multi-day event. Show end date 479 // multi-day event. Show end date
480 text += TimeString::longDateString( e.endDate() ); 480 text += TimeString::longDateString( e.endDate() );
481 } else { 481 } else {
482 // Show end time. 482 // Show end time.
483 text += TimeString::timeString( ev.end(), whichClock, FALSE ); 483 text += TimeString::timeString( ev.end(), whichClock, FALSE );
484 } 484 }
485 text += "<br><br>" + strNote; 485 text += "<br><br>" + strNote;
486 setBackgroundMode( PaletteBase ); 486 setBackgroundMode( PaletteBase );
487 487
488 QTime s = ev.start(); 488 QTime start = ev.start();
489 QTime e = ev.end(); 489 QTime end = ev.end();
490 int y = s.hour()*60+s.minute(); 490 int y = start.hour()*60+start.minute();
491 int h = e.hour()*60+e.minute()-y; 491 int h = end.hour()*60+end.minute()-y;
492 int rh = dateBook->dayView()->rowHeight(0); 492 int rh = dateBook->dayView()->rowHeight(0);
493 y = y*rh/60; 493 y = y*rh/60;
494 h = h*rh/60; 494 h = h*rh/60;
495 if ( h < 3 ) 495 if ( h < 3 )
496 h = 3; 496 h = 3;
497 geom.setY( y ); 497 geom.setY( y );
498 geom.setHeight( h ); 498 geom.setHeight( h );
499} 499}
500 500
501DateBookDayWidget::~DateBookDayWidget() 501DateBookDayWidget::~DateBookDayWidget()
502{ 502{
503} 503}
504 504
505void DateBookDayWidget::paintEvent( QPaintEvent *e ) 505void DateBookDayWidget::paintEvent( QPaintEvent *e )
506{ 506{
507 QPainter p( this ); 507 QPainter p( this );
508 p.setPen( QColor(100, 100, 100) ); 508 p.setPen( QColor(100, 100, 100) );
509 p.setBrush( QColor( 255, 240, 230 ) ); // based on priority? 509 p.setBrush( QColor( 255, 240, 230 ) ); // based on priority?
510 p.drawRect(rect()); 510 p.drawRect(rect());
511 511
512 int y = 0; 512 int y = 0;
513 int d = 0; 513 int d = 0;
514 514
515 if ( ev.event().hasAlarm() ) { 515 if ( ev.event().hasAlarm() ) {
516 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); 516 p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) );
517 y = 20; 517 y = 20;
518 d = 20; 518 d = 20;
519 } 519 }
520 520
521 if ( ev.event().hasRepeat() ) { 521 if ( ev.event().hasRepeat() ) {
522 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); 522 p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) );
523 d = 20; 523 d = 20;
524 } 524 }
525 525
526 QSimpleRichText rt( text, font() ); 526 QSimpleRichText rt( text, font() );
527 rt.setWidth( geom.width() - d - 6 ); 527 rt.setWidth( geom.width() - d - 6 );
528 rt.draw( &p, 3, 0, e->region(), colorGroup() ); 528 rt.draw( &p, 3, 0, e->region(), colorGroup() );
529} 529}
530 530
531void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) 531void DateBookDayWidget::mousePressEvent( QMouseEvent *e )
532{ 532{
533 QPopupMenu m; 533 QPopupMenu m;
534 m.insertItem( tr( "Edit" ), 1 ); 534 m.insertItem( tr( "Edit" ), 1 );
535 m.insertItem( tr( "Delete" ), 2 ); 535 m.insertItem( tr( "Delete" ), 2 );
536 m.insertItem( tr( "Beam" ), 3 ); 536 m.insertItem( tr( "Beam" ), 3 );
537 int r = m.exec( e->globalPos() ); 537 int r = m.exec( e->globalPos() );
538 if ( r == 1 ) { 538 if ( r == 1 ) {
539 emit editMe( ev.event() ); 539 emit editMe( ev.event() );
540 } else if ( r == 2 ) { 540 } else if ( r == 2 ) {
541 emit deleteMe( ev.event() ); 541 emit deleteMe( ev.event() );
542 } else if ( r == 3 ) { 542 } else if ( r == 3 ) {
543 emit beamMe( ev.event() ); 543 emit beamMe( ev.event() );
544 } 544 }
545} 545}
546 546
547void DateBookDayWidget::setGeometry( const QRect &r ) 547void DateBookDayWidget::setGeometry( const QRect &r )
548{ 548{
549 geom = r; 549 geom = r;
550 setFixedSize( r.width()+1, r.height()+1 ); 550 setFixedSize( r.width()+1, r.height()+1 );
551 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); 551 dateBook->dayView()->moveChild( this, r.x(), r.y()-1 );
552 show(); 552 show();
553} 553}
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index e9fcc39..6532ba4 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -1,687 +1,687 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "datebookweek.h" 20#include "datebookweek.h"
21#include "datebookweekheaderimpl.h" 21#include "datebookweekheaderimpl.h"
22 22
23#include <qpe/calendar.h> 23#include <qpe/calendar.h>
24#include <qpe/datebookdb.h> 24#include <qpe/datebookdb.h>
25#include <qpe/event.h> 25#include <qpe/event.h>
26#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
27#include <qpe/timestring.h> 27#include <qpe/timestring.h>
28 28
29#include <qdatetime.h> 29#include <qdatetime.h>
30#include <qheader.h> 30#include <qheader.h>
31#include <qlabel.h> 31#include <qlabel.h>
32#include <qlayout.h> 32#include <qlayout.h>
33#include <qpainter.h> 33#include <qpainter.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qtimer.h> 35#include <qtimer.h>
36#include <qspinbox.h> 36#include <qspinbox.h>
37#include <qstyle.h> 37#include <qstyle.h>
38 38
39//----------------------------------------------------------------- 39//-----------------------------------------------------------------
40 40
41 41
42DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e ) 42DateBookWeekItem::DateBookWeekItem( const EffectiveEvent e )
43 : ev( e ) 43 : ev( e )
44{ 44{
45 // with the current implementation change the color for all day events 45 // with the current implementation change the color for all day events
46 if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) { 46 if ( ev.event().type() == Event::AllDay && !ev.event().hasAlarm() ) {
47 c = Qt::green; 47 c = Qt::green;
48 } else { 48 } else {
49 c = ev.event().hasAlarm() ? Qt::red : Qt::blue; 49 c = ev.event().hasAlarm() ? Qt::red : Qt::blue;
50 } 50 }
51} 51}
52 52
53void DateBookWeekItem::setGeometry( int x, int y, int w, int h ) 53void DateBookWeekItem::setGeometry( int x, int y, int w, int h )
54{ 54{
55 r.setRect( x, y, w, h ); 55 r.setRect( x, y, w, h );
56} 56}
57 57
58 58
59//------------------=--------------------------------------------- 59//------------------=---------------------------------------------
60 60
61DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday, 61DateBookWeekView::DateBookWeekView( bool ap, bool startOnMonday,
62 QWidget *parent, const char *name ) 62 QWidget *parent, const char *name )
63 : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ), 63 : QScrollView( parent, name ), ampm( ap ), bOnMonday( startOnMonday ),
64 showingEvent( false ) 64 showingEvent( false )
65{ 65{
66 items.setAutoDelete( true ); 66 items.setAutoDelete( true );
67 67
68 viewport()->setBackgroundMode( PaletteBase ); 68 viewport()->setBackgroundMode( PaletteBase );
69 69
70 header = new QHeader( this ); 70 header = new QHeader( this );
71 header->addLabel( "" ); 71 header->addLabel( "" );
72 72
73 header->setMovingEnabled( false ); 73 header->setMovingEnabled( false );
74 header->setResizeEnabled( false ); 74 header->setResizeEnabled( false );
75 header->setClickEnabled( false, 0 ); 75 header->setClickEnabled( false, 0 );
76 initNames(); 76 initNames();
77 77
78 78
79 connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) ); 79 connect( header, SIGNAL(clicked(int)), this, SIGNAL(showDay(int)) );
80 80
81 QObject::connect(qApp, SIGNAL(clockChanged(bool)), 81 QObject::connect(qApp, SIGNAL(clockChanged(bool)),
82 this, SLOT(slotChangeClock(bool))); 82 this, SLOT(slotChangeClock(bool)));
83 83
84 QFontMetrics fm( font() ); 84 QFontMetrics fm( font() );
85 rowHeight = fm.height()+2; 85 rowHeight = fm.height()+2;
86 86
87 resizeContents( width(), 24*rowHeight ); 87 resizeContents( width(), 24*rowHeight );
88} 88}
89 89
90void DateBookWeekView::initNames() 90void DateBookWeekView::initNames()
91{ 91{
92 static bool bFirst = true; 92 static bool bFirst = true;
93 if ( bFirst ) { 93 if ( bFirst ) {
94 if ( bOnMonday ) { 94 if ( bOnMonday ) {
95 header->addLabel( tr("M", "Monday" ) ); 95 header->addLabel( tr("M", "Monday" ) );
96 header->addLabel( tr("T", "Tuesday") ); 96 header->addLabel( tr("T", "Tuesday") );
97 header->addLabel( tr("W", "Wednesday" ) ); 97 header->addLabel( tr("W", "Wednesday" ) );
98 header->addLabel( tr("T", "Thursday" ) ); 98 header->addLabel( tr("T", "Thursday" ) );
99 header->addLabel( tr("F", "Friday" ) ); 99 header->addLabel( tr("F", "Friday" ) );
100 header->addLabel( tr("S", "Saturday" ) ); 100 header->addLabel( tr("S", "Saturday" ) );
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 positionItem( i ); 142 positionItem( i );
143 items.append( i ); 143 items.append( i );
144 } 144 }
145 viewport()->update(); 145 viewport()->update();
146} 146}
147 147
148void DateBookWeekView::moveToHour( int h ) 148void DateBookWeekView::moveToHour( int h )
149{ 149{
150 int offset = h*rowHeight; 150 int offset = h*rowHeight;
151 setContentsPos( 0, offset ); 151 setContentsPos( 0, offset );
152} 152}
153 153
154void DateBookWeekView::keyPressEvent( QKeyEvent *e ) 154void DateBookWeekView::keyPressEvent( QKeyEvent *e )
155{ 155{
156 e->ignore(); 156 e->ignore();
157} 157}
158 158
159void DateBookWeekView::slotChangeClock( bool c ) 159void DateBookWeekView::slotChangeClock( bool c )
160{ 160{
161 ampm = c; 161 ampm = c;
162 viewport()->update(); 162 viewport()->update();
163} 163}
164 164
165static inline int db_round30min( int m ) 165static inline int db_round30min( int m )
166{ 166{
167 if ( m < 15 ) 167 if ( m < 15 )
168 m = 0; 168 m = 0;
169 else if ( m < 45 ) 169 else if ( m < 45 )
170 m = 1; 170 m = 1;
171 else 171 else
172 m = 2; 172 m = 2;
173 173
174 return m; 174 return m;
175} 175}
176 176
177void DateBookWeekView::alterDay( int day ) 177void DateBookWeekView::alterDay( int day )
178{ 178{
179 if ( !bOnMonday ) { 179 if ( !bOnMonday ) {
180 day--; 180 day--;
181 } 181 }
182 emit showDay( day ); 182 emit showDay( day );
183} 183}
184 184
185void DateBookWeekView::positionItem( DateBookWeekItem *i ) 185void DateBookWeekView::positionItem( DateBookWeekItem *i )
186{ 186{
187 const int Width = 8; 187 const int Width = 8;
188 const EffectiveEvent ev = i->event(); 188 const EffectiveEvent ev = i->event();
189 189
190 // 30 minute intervals 190 // 30 minute intervals
191 int y = ev.start().hour() * 2; 191 int y = ev.start().hour() * 2;
192 y += db_round30min( ev.start().minute() ); 192 y += db_round30min( ev.start().minute() );
193 if ( y > 47 ) 193 if ( y > 47 )
194 y = 47; 194 y = 47;
195 y = y * rowHeight / 2; 195 y = y * rowHeight / 2;
196 196
197 int h; 197 int h;
198 if ( ev.event().type() == Event::AllDay ) { 198 if ( ev.event().type() == Event::AllDay ) {
199 h = 48; 199 h = 48;
200 y = 0; 200 y = 0;
201 } else { 201 } else {
202 h = ( ev.end().hour() - ev.start().hour() ) * 2; 202 h = ( ev.end().hour() - ev.start().hour() ) * 2;
203 h += db_round30min( ev.end().minute() - ev.start().minute() ); 203 h += db_round30min( ev.end().minute() - ev.start().minute() );
204 if ( h < 1 ) h = 1; 204 if ( h < 1 ) h = 1;
205 } 205 }
206 h = h * rowHeight / 2; 206 h = h * rowHeight / 2;
207 207
208 int dow = ev.date().dayOfWeek(); 208 int dow = ev.date().dayOfWeek();
209 if ( !bOnMonday ) { 209 if ( !bOnMonday ) {
210 if ( dow == 7 ) 210 if ( dow == 7 )
211 dow = 1; 211 dow = 1;
212 else 212 else
213 dow++; 213 dow++;
214 } 214 }
215 int x = header->sectionPos( dow ) - 1; 215 int x = header->sectionPos( dow ) - 1;
216 int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); 216 int xlim = header->sectionPos( dow ) + header->sectionSize( dow );
217 DateBookWeekItem *isect = 0; 217 DateBookWeekItem *isect = 0;
218 do { 218 do {
219 i->setGeometry( x, y, Width, h ); 219 i->setGeometry( x, y, Width, h );
220 isect = intersects( i ); 220 isect = intersects( i );
221 x += Width - 1; 221 x += Width - 1;
222 } while ( isect && x < xlim ); 222 } while ( isect && x < xlim );
223} 223}
224 224
225DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) 225DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item )
226{ 226{
227 QRect geom = item->geometry(); 227 QRect geom = item->geometry();
228 228
229 // We allow the edges to overlap 229 // We allow the edges to overlap
230 geom.moveBy( 1, 1 ); 230 geom.moveBy( 1, 1 );
231 geom.setSize( geom.size()-QSize(2,2) ); 231 geom.setSize( geom.size()-QSize(2,2) );
232 232
233 QListIterator<DateBookWeekItem> it(items); 233 QListIterator<DateBookWeekItem> it(items);
234 for ( ; it.current(); ++it ) { 234 for ( ; it.current(); ++it ) {
235 DateBookWeekItem *i = it.current(); 235 DateBookWeekItem *i = it.current();
236 if ( i != item ) { 236 if ( i != item ) {
237 if ( i->geometry().intersects( geom ) ) { 237 if ( i->geometry().intersects( geom ) ) {
238 return i; 238 return i;
239 } 239 }
240 } 240 }
241 } 241 }
242 242
243 return 0; 243 return 0;
244} 244}
245 245
246void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) 246void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e )
247{ 247{
248 QListIterator<DateBookWeekItem> it(items); 248 QListIterator<DateBookWeekItem> it(items);
249 for ( ; it.current(); ++it ) { 249 for ( ; it.current(); ++it ) {
250 DateBookWeekItem *i = it.current(); 250 DateBookWeekItem *i = it.current();
251 if ( i->geometry().contains( e->pos() ) ) { 251 if ( i->geometry().contains( e->pos() ) ) {
252 showingEvent = true; 252 showingEvent = true;
253 emit signalShowEvent( i->event() ); 253 emit signalShowEvent( i->event() );
254 break; 254 break;
255 } 255 }
256 } 256 }
257} 257}
258 258
259void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e ) 259void DateBookWeekView::contentsMouseReleaseEvent( QMouseEvent *e )
260{ 260{
261 if ( showingEvent ) { 261 if ( showingEvent ) {
262 showingEvent = false; 262 showingEvent = false;
263 emit signalHideEvent(); 263 emit signalHideEvent();
264 } else { 264 } else {
265 int d = header->sectionAt( e->pos().x() ); 265 int d = header->sectionAt( e->pos().x() );
266 if ( d > 0 ) { 266 if ( d > 0 ) {
267 // if ( !bOnMonday ) 267 // if ( !bOnMonday )
268 // d--; 268 // d--;
269 emit showDay( d ); 269 emit showDay( d );
270 } 270 }
271 } 271 }
272} 272}
273 273
274void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) 274void DateBookWeekView::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
275{ 275{
276 QRect ur( cx, cy, cw, ch ); 276 QRect ur( cx, cy, cw, ch );
277 p->setPen( lightGray ); 277 p->setPen( lightGray );
278 for ( int i = 1; i <= 7; i++ ) 278 for ( int i = 1; i <= 7; i++ )
279 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch ); 279 p->drawLine( header->sectionPos(i)-2, cy, header->sectionPos(i)-2, cy+ch );
280 280
281 p->setPen( black ); 281 p->setPen( black );
282 for ( int t = 0; t < 24; t++ ) { 282 for ( int t = 0; t < 24; t++ ) {
283 int y = t*rowHeight; 283 int y = t*rowHeight;
284 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) { 284 if ( QRect( 1, y, 20, rowHeight ).intersects( ur ) ) {
285 QString s; 285 QString s;
286 if ( ampm ) { 286 if ( ampm ) {
287 if ( t == 0 ) 287 if ( t == 0 )
288 s = QString::number( 12 ); 288 s = QString::number( 12 );
289 else if ( t == 12 ) 289 else if ( t == 12 )
290 s = QString::number(12) + tr( "p" ); 290 s = QString::number(12) + tr( "p" );
291 else if ( t > 12 ) { 291 else if ( t > 12 ) {
292 if ( t - 12 < 10 ) 292 if ( t - 12 < 10 )
293 s = " "; 293 s = " ";
294 else 294 else
295 s = ""; 295 s = "";
296 s += QString::number( t - 12 ) + tr("p"); 296 s += QString::number( t - 12 ) + tr("p");
297 } else { 297 } else {
298 if ( 12 - t < 3 ) 298 if ( 12 - t < 3 )
299 s = ""; 299 s = "";
300 else 300 else
301 s = " "; 301 s = " ";
302 s += QString::number( t ); 302 s += QString::number( t );
303 } 303 }
304 } else { 304 } else {
305 s = QString::number( t ); 305 s = QString::number( t );
306 if ( s.length() == 1 ) 306 if ( s.length() == 1 )
307 s.prepend( "0" ); 307 s.prepend( "0" );
308 } 308 }
309 p->drawText( 1, y+p->fontMetrics().ascent()+1, s ); 309 p->drawText( 1, y+p->fontMetrics().ascent()+1, s );
310 } 310 }
311 } 311 }
312 312
313 QListIterator<DateBookWeekItem> it(items); 313 QListIterator<DateBookWeekItem> it(items);
314 for ( ; it.current(); ++it ) { 314 for ( ; it.current(); ++it ) {
315 DateBookWeekItem *i = it.current(); 315 DateBookWeekItem *i = it.current();
316 if ( i->geometry().intersects( ur ) ) { 316 if ( i->geometry().intersects( ur ) ) {
317 p->setBrush( i->color() ); 317 p->setBrush( i->color() );
318 p->drawRect( i->geometry() ); 318 p->drawRect( i->geometry() );
319 } 319 }
320 } 320 }
321} 321}
322 322
323void DateBookWeekView::resizeEvent( QResizeEvent *e ) 323void DateBookWeekView::resizeEvent( QResizeEvent *e )
324{ 324{
325 const int hourWidth = 20; 325 const int hourWidth = 20;
326 QScrollView::resizeEvent( e ); 326 QScrollView::resizeEvent( e );
327 int avail = width()-qApp->style().scrollBarExtent().width()-1; 327 int avail = width()-qApp->style().scrollBarExtent().width()-1;
328 header->setGeometry( 0, 0, avail, header->sizeHint().height() ); 328 header->setGeometry( 0, 0, avail, header->sizeHint().height() );
329 setMargins( 0, header->height(), 0, 0 ); 329 setMargins( 0, header->height(), 0, 0 );
330 header->resizeSection( 0, hourWidth ); 330 header->resizeSection( 0, hourWidth );
331 int sw = (avail - hourWidth) / 7; 331 int sw = (avail - hourWidth) / 7;
332 for ( int i = 1; i < 7; i++ ) 332 for ( int i = 1; i < 7; i++ )
333 header->resizeSection( i, sw ); 333 header->resizeSection( i, sw );
334 header->resizeSection( 7, avail - hourWidth - sw*6 ); 334 header->resizeSection( 7, avail - hourWidth - sw*6 );
335} 335}
336 336
337void DateBookWeekView::setStartOfWeek( bool bStartOnMonday ) 337void DateBookWeekView::setStartOfWeek( bool bStartOnMonday )
338{ 338{
339 bOnMonday = bStartOnMonday; 339 bOnMonday = bStartOnMonday;
340 initNames(); 340 initNames();
341} 341}
342 342
343//------------------------------------------------------------------- 343//-------------------------------------------------------------------
344 344
345DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB, 345DateBookWeek::DateBookWeek( bool ap, bool startOnMonday, DateBookDB *newDB,
346 QWidget *parent, const char *name ) 346 QWidget *parent, const char *name )
347 : QWidget( parent, name ), 347 : QWidget( parent, name ),
348 db( newDB ), 348 db( newDB ),
349 startTime( 0 ), 349 startTime( 0 ),
350 ampm( ap ), 350 ampm( ap ),
351 bStartOnMonday( startOnMonday ) 351 bStartOnMonday( startOnMonday )
352{ 352{
353 setFocusPolicy(StrongFocus); 353 setFocusPolicy(StrongFocus);
354 QVBoxLayout *vb = new QVBoxLayout( this ); 354 QVBoxLayout *vb = new QVBoxLayout( this );
355 header = new DateBookWeekHeader( bStartOnMonday, this ); 355 header = new DateBookWeekHeader( bStartOnMonday, this );
356 view = new DateBookWeekView( ampm, startOnMonday, this ); 356 view = new DateBookWeekView( ampm, startOnMonday, this );
357 vb->addWidget( header ); 357 vb->addWidget( header );
358 vb->addWidget( view ); 358 vb->addWidget( view );
359 359
360 lblDesc = new QLabel( this, "event label" ); 360 lblDesc = new QLabel( this, "event label" );
361 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box ); 361 lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box );
362 lblDesc->setBackgroundColor( yellow ); 362 lblDesc->setBackgroundColor( yellow );
363 lblDesc->hide(); 363 lblDesc->hide();
364 364
365 tHide = new QTimer( this ); 365 tHide = new QTimer( this );
366 366
367 connect( view, SIGNAL( showDay( int ) ), 367 connect( view, SIGNAL( showDay( int ) ),
368 this, SLOT( showDay( int ) ) ); 368 this, SLOT( showDay( int ) ) );
369 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)), 369 connect( view, SIGNAL(signalShowEvent(const EffectiveEvent&)),
370 this, SLOT(slotShowEvent(const EffectiveEvent&)) ); 370 this, SLOT(slotShowEvent(const EffectiveEvent&)) );
371 connect( view, SIGNAL(signalHideEvent()), 371 connect( view, SIGNAL(signalHideEvent()),
372 this, SLOT(slotHideEvent()) ); 372 this, SLOT(slotHideEvent()) );
373 connect( header, SIGNAL( dateChanged( int, int ) ), 373 connect( header, SIGNAL( dateChanged( int, int ) ),
374 this, SLOT( dateChanged( int, int ) ) ); 374 this, SLOT( dateChanged( int, int ) ) );
375 connect( tHide, SIGNAL( timeout() ), 375 connect( tHide, SIGNAL( timeout() ),
376 lblDesc, SLOT( hide() ) ); 376 lblDesc, SLOT( hide() ) );
377 connect( header->spinYear, SIGNAL(valueChanged(int)), 377 connect( header->spinYear, SIGNAL(valueChanged(int)),
378 this, SLOT(slotYearChanged(int)) ); 378 this, SLOT(slotYearChanged(int)) );
379 connect( qApp, SIGNAL(weekChanged(bool)), 379 connect( qApp, SIGNAL(weekChanged(bool)),
380 this, SLOT(slotWeekChanged(bool)) ); 380 this, SLOT(slotWeekChanged(bool)) );
381 connect( qApp, SIGNAL(clockChanged(bool)), 381 connect( qApp, SIGNAL(clockChanged(bool)),
382 this, SLOT(slotClockChanged(bool))); 382 this, SLOT(slotClockChanged(bool)));
383 setDate(QDate::currentDate()); 383 setDate(QDate::currentDate());
384 384
385} 385}
386 386
387void DateBookWeek::keyPressEvent(QKeyEvent *e) 387void DateBookWeek::keyPressEvent(QKeyEvent *e)
388{ 388{
389 switch(e->key()) { 389 switch(e->key()) {
390 case Key_Up: 390 case Key_Up:
391 view->scrollBy(0, -20); 391 view->scrollBy(0, -20);
392 break; 392 break;
393 case Key_Down: 393 case Key_Down:
394 view->scrollBy(0, 20); 394 view->scrollBy(0, 20);
395 break; 395 break;
396 case Key_Left: 396 case Key_Left:
397 setDate(date().addDays(-7)); 397 setDate(date().addDays(-7));
398 break; 398 break;
399 case Key_Right: 399 case Key_Right:
400 setDate(date().addDays(7)); 400 setDate(date().addDays(7));
401 break; 401 break;
402 default: 402 default:
403 e->ignore(); 403 e->ignore();
404 } 404 }
405} 405}
406 406
407void DateBookWeek::showDay( int day ) 407void DateBookWeek::showDay( int day )
408{ 408{
409 QDate d; 409 QDate d;
410 d = dateFromWeek( _week, year, bStartOnMonday ); 410 d = dateFromWeek( _week, year, bStartOnMonday );
411 day--; 411 day--;
412 d = d.addDays( day ); 412 d = d.addDays( day );
413 emit showDate( d.year(), d.month(), d.day() ); 413 emit showDate( d.year(), d.month(), d.day() );
414} 414}
415 415
416void DateBookWeek::setDate( int y, int m, int d ) 416void DateBookWeek::setDate( int y, int m, int d )
417{ 417{
418 QDate date; 418 QDate date;
419 date.setYMD( y, m, d ); 419 date.setYMD( y, m, d );
420 setDate(QDate(y, m, d)); 420 setDate(QDate(y, m, d));
421} 421}
422 422
423void DateBookWeek::setDate(QDate date) 423void DateBookWeek::setDate(QDate date)
424{ 424{
425 dow = date.dayOfWeek(); 425 dow = date.dayOfWeek();
426 int w, y; 426 int w, y;
427 calcWeek( date, w, y, bStartOnMonday ); 427 calcWeek( date, w, y, bStartOnMonday );
428 header->setDate( y, w ); 428 header->setDate( y, w );
429} 429}
430 430
431void DateBookWeek::dateChanged( int y, int w ) 431void DateBookWeek::dateChanged( int y, int w )
432{ 432{
433 year = y; 433 year = y;
434 _week = w; 434 _week = w;
435 getEvents(); 435 getEvents();
436} 436}
437 437
438QDate DateBookWeek::date() const 438QDate DateBookWeek::date() const
439{ 439{
440 QDate d; 440 QDate d;
441 d = dateFromWeek( _week - 1, year, bStartOnMonday ); 441 d = dateFromWeek( _week - 1, year, bStartOnMonday );
442 if ( bStartOnMonday ) 442 if ( bStartOnMonday )
443 d = d.addDays( 7 + dow - 1 ); 443 d = d.addDays( 7 + dow - 1 );
444 else { 444 else {
445 if ( dow == 7 ) 445 if ( dow == 7 )
446 d = d.addDays( dow ); 446 d = d.addDays( dow );
447 else 447 else
448 d = d.addDays( 7 + dow ); 448 d = d.addDays( 7 + dow );
449 } 449 }
450 return d; 450 return d;
451} 451}
452 452
453void DateBookWeek::getEvents() 453void DateBookWeek::getEvents()
454{ 454{
455 QDate startWeek = weekDate(); 455 QDate startWeek = weekDate();
456 456
457 QDate endWeek = startWeek.addDays( 6 ); 457 QDate endWeek = startWeek.addDays( 6 );
458 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek, 458 QValueList<EffectiveEvent> eventList = db->getEffectiveEvents(startWeek,
459 endWeek); 459 endWeek);
460 view->showEvents( eventList ); 460 view->showEvents( eventList );
461 view->moveToHour( startTime ); 461 view->moveToHour( startTime );
462} 462}
463 463
464void DateBookWeek::slotShowEvent( const EffectiveEvent &ev ) 464void DateBookWeek::slotShowEvent( const EffectiveEvent &ev )
465{ 465{
466 if ( tHide->isActive() ) 466 if ( tHide->isActive() )
467 tHide->stop(); 467 tHide->stop();
468 468
469 // why would someone use "<"? Oh well, fix it up... 469 // why would someone use "<"? Oh well, fix it up...
470 // I wonder what other things may be messed up... 470 // I wonder what other things may be messed up...
471 QString strDesc = ev.description(); 471 QString strDesc = ev.description();
472 int where = strDesc.find( "<" ); 472 int where = strDesc.find( "<" );
473 while ( where != -1 ) { 473 while ( where != -1 ) {
474 strDesc.remove( where, 1 ); 474 strDesc.remove( where, 1 );
475 strDesc.insert( where, "&#60;" ); 475 strDesc.insert( where, "&#60;" );
476 where = strDesc.find( "<", where ); 476 where = strDesc.find( "<", where );
477 } 477 }
478 478
479 QString strCat; 479 QString strCat;
480 // ### FIX later... 480 // ### FIX later...
481// QString strCat = ev.category(); 481// QString strCat = ev.category();
482// where = strCat.find( "<" ); 482// where = strCat.find( "<" );
483// while ( where != -1 ) { 483// while ( where != -1 ) {
484 // strCat.remove( where, 1 ); 484 // strCat.remove( where, 1 );
485 // strCat.insert( where, "&#60;" ); 485 // strCat.insert( where, "&#60;" );
486 // where = strCat.find( "<", where ); 486 // where = strCat.find( "<", where );
487// } 487// }
488 488
489 QString strNote = ev.notes(); 489 QString strNote = ev.notes();
490 where = strNote.find( "<" ); 490 where = strNote.find( "<" );
491 while ( where != -1 ) { 491 while ( where != -1 ) {
492 strNote.remove( where, 1 ); 492 strNote.remove( where, 1 );
493 strNote.insert( where, "&#60;" ); 493 strNote.insert( where, "&#60;" );
494 where = strNote.find( "<", where ); 494 where = strNote.find( "<", where );
495 } 495 }
496 496
497 QString str = "<b>" + strDesc + "</b><br>" + "<i>" 497 QString str = "<b>" + strDesc + "</b><br>" + "<i>"
498 + strCat + "</i>" 498 + strCat + "</i>"
499 + "<br>" + TimeString::longDateString( ev.date() ) 499 + "<br>" + TimeString::longDateString( ev.date() )
500 + "<br><b>" + QObject::tr("Start") + "</b>: "; 500 + "<br><b>" + QObject::tr("Start") + "</b>: ";
501 501
502 if ( ev.startDate() != ev.date() ) { 502 if ( ev.startDate() != ev.date() ) {
503 // multi-day event. Show start date 503 // multi-day event. Show start date
504 str += TimeString::longDateString( ev.startDate() ); 504 str += TimeString::longDateString( ev.startDate() );
505 } else { 505 } else {
506 // Show start time. 506 // Show start time.
507 str += TimeString::timeString(ev.start(), ampm, FALSE ); 507 str += TimeString::timeString(ev.start(), ampm, FALSE );
508 } 508 }
509 509
510 str += "<br><b>" + QObject::tr("End") + "</b>: "; 510 str += "<br><b>" + QObject::tr("End") + "</b>: ";
511 if ( ev.endDate() != ev.date() ) { 511 if ( ev.endDate() != ev.date() ) {
512 // multi-day event. Show end date 512 // multi-day event. Show end date
513 str += TimeString::longDateString( ev.endDate() ); 513 str += TimeString::longDateString( ev.endDate() );
514 } else { 514 } else {
515 // Show end time. 515 // Show end time.
516 str += TimeString::timeString( ev.end(), ampm, FALSE ); 516 str += TimeString::timeString( ev.end(), ampm, FALSE );
517 } 517 }
518 str += "<br><br>" + strNote; 518 str += "<br><br>" + strNote;
519 519
520 lblDesc->setText( str ); 520 lblDesc->setText( str );
521 lblDesc->resize( lblDesc->sizeHint() ); 521 lblDesc->resize( lblDesc->sizeHint() );
522 // move the label so it is "centerd" horizontally... 522 // move the label so it is "centerd" horizontally...
523 lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 ); 523 lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 );
524 lblDesc->show(); 524 lblDesc->show();
525} 525}
526 526
527void DateBookWeek::slotHideEvent() 527void DateBookWeek::slotHideEvent()
528{ 528{
529 tHide->start( 2000, true ); 529 tHide->start( 2000, true );
530} 530}
531 531
532void DateBookWeek::setStartViewTime( int startHere ) 532void DateBookWeek::setStartViewTime( int startHere )
533{ 533{
534 startTime = startHere; 534 startTime = startHere;
535 view->moveToHour( startTime ); 535 view->moveToHour( startTime );
536} 536}
537 537
538int DateBookWeek::startViewTime() const 538int DateBookWeek::startViewTime() const
539{ 539{
540 return startTime; 540 return startTime;
541} 541}
542 542
543void DateBookWeek::redraw() 543void DateBookWeek::redraw()
544{ 544{
545 getEvents(); 545 getEvents();
546} 546}
547 547
548void DateBookWeek::slotYearChanged( int y ) 548void DateBookWeek::slotYearChanged( int y )
549{ 549{
550 int totWeek; 550 int totWeek;
551 QDate d( y, 12, 31 ); 551 QDate d( y, 12, 31 );
552 int throwAway; 552 int throwAway;
553 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 553 calcWeek( d, totWeek, throwAway, bStartOnMonday );
554 while ( totWeek == 1 ) { 554 while ( totWeek == 1 ) {
555 d = d.addDays( -1 ); 555 d = d.addDays( -1 );
556 calcWeek( d, totWeek, throwAway, bStartOnMonday ); 556 calcWeek( d, totWeek, throwAway, bStartOnMonday );
557 } 557 }
558 if ( totWeek != totalWeeks() ) 558 if ( totWeek != totalWeeks() )
559 setTotalWeeks( totWeek ); 559 setTotalWeeks( totWeek );
560} 560}
561 561
562 562
563void DateBookWeek::setTotalWeeks( int numWeeks ) 563void DateBookWeek::setTotalWeeks( int numWeeks )
564{ 564{
565 header->spinWeek->setMaxValue( numWeeks ); 565 header->spinWeek->setMaxValue( numWeeks );
566} 566}
567 567
568int DateBookWeek::totalWeeks() const 568int DateBookWeek::totalWeeks() const
569{ 569{
570 return header->spinWeek->maxValue(); 570 return header->spinWeek->maxValue();
571} 571}
572 572
573void DateBookWeek::slotWeekChanged( bool onMonday ) 573void DateBookWeek::slotWeekChanged( bool onMonday )
574{ 574{
575 bStartOnMonday = onMonday; 575 bStartOnMonday = onMonday;
576 view->setStartOfWeek( bStartOnMonday ); 576 view->setStartOfWeek( bStartOnMonday );
577 header->setStartOfWeek( bStartOnMonday ); 577 header->setStartOfWeek( bStartOnMonday );
578 redraw(); 578 redraw();
579} 579}
580 580
581void DateBookWeek::slotClockChanged( bool ap ) 581void DateBookWeek::slotClockChanged( bool ap )
582{ 582{
583 ampm = ap; 583 ampm = ap;
584} 584}
585 585
586// return the date at the beginning of the week... 586// return the date at the beginning of the week...
587QDate DateBookWeek::weekDate() const 587QDate DateBookWeek::weekDate() const
588{ 588{
589 return dateFromWeek( _week, year, bStartOnMonday ); 589 return dateFromWeek( _week, year, bStartOnMonday );
590} 590}
591 591
592// this used to only be needed by datebook.cpp, but now we need it inside 592// this used to only be needed by datebook.cpp, but now we need it inside
593// week view since 593// week view since
594// we need to be able to figure out our total number of weeks on the fly... 594// we need to be able to figure out our total number of weeks on the fly...
595// this is probably the best place to put it.. 595// this is probably the best place to put it..
596 596
597// For Weeks that start on Monday... (EASY!) 597// For Weeks that start on Monday... (EASY!)
598// At the moment we will use ISO 8601 method for computing 598// At the moment we will use ISO 8601 method for computing
599// the week. Granted, other countries use other methods, 599// the week. Granted, other countries use other methods,
600// bet we aren't doing any Locale stuff at the moment. So, 600// bet we aren't doing any Locale stuff at the moment. So,
601// this should pass. This Algorithim is public domain and 601// this should pass. This Algorithim is public domain and
602// available at: 602// available at:
603// http://personal.ecu.edu/mccartyr/ISOwdALG.txt 603// http://personal.ecu.edu/mccartyr/ISOwdALG.txt
604// the week number is return, and the year number is returned in year 604// the week number is return, and the year number is returned in year
605// for Instance 2001/12/31 is actually the first week in 2002. 605// for Instance 2001/12/31 is actually the first week in 2002.
606// There is a more mathematical definition, but I will implement it when 606// There is a more mathematical definition, but I will implement it when
607// we are pass our deadline. 607// we are pass our deadline.
608 608
609// For Weeks that start on Sunday... (ahh... home rolled) 609// For Weeks that start on Sunday... (ahh... home rolled)
610// okay, if Jan 1 is on Friday or Saturday, 610// okay, if Jan 1 is on Friday or Saturday,
611// it will go to the pervious 611// it will go to the pervious
612// week... 612// week...
613 613
614bool calcWeek( const QDate &d, int &week, int &year, 614bool calcWeek( const QDate &d, int &week, int &year,
615 bool startOnMonday = false ) 615 bool startOnMonday )
616{ 616{
617 int weekNumber; 617 int weekNumber;
618 int yearNumber; 618 int yearNumber;
619 619
620 // remove a pesky warning, (Optimizations on g++) 620 // remove a pesky warning, (Optimizations on g++)
621 weekNumber = -1; 621 weekNumber = -1;
622 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); 622 int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek();
623 int dayOfWeek = d.dayOfWeek(); 623 int dayOfWeek = d.dayOfWeek();
624 624
625 if ( !d.isValid() ) 625 if ( !d.isValid() )
626 return false; 626 return false;
627 627
628 if ( startOnMonday ) { 628 if ( startOnMonday ) {
629 // find the Jan1Weekday; 629 // find the Jan1Weekday;
630 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) { 630 if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) {
631 yearNumber = d.year() - 1; 631 yearNumber = d.year() - 1;
632 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) 632 if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) )
633 weekNumber = 53; 633 weekNumber = 53;
634 else 634 else
635 weekNumber = 52; 635 weekNumber = 52;
636 } else 636 } else
637 yearNumber = d.year(); 637 yearNumber = d.year();
638 if ( yearNumber == d.year() ) { 638 if ( yearNumber == d.year() ) {
639 int totalDays = 365; 639 int totalDays = 365;
640 if ( QDate::leapYear(yearNumber) ) 640 if ( QDate::leapYear(yearNumber) )
641 totalDays++; 641 totalDays++;
642 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) 642 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) )
643 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { 643 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) {
644 yearNumber++; 644 yearNumber++;
645 weekNumber = 1; 645 weekNumber = 1;
646 } 646 }
647 } 647 }
648 if ( yearNumber == d.year() ) { 648 if ( yearNumber == d.year() ) {
649 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 ); 649 int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 );
650 weekNumber = j / 7; 650 weekNumber = j / 7;
651 if ( jan1WeekDay > 4 ) 651 if ( jan1WeekDay > 4 )
652 weekNumber--; 652 weekNumber--;
653 } 653 }
654 } else { 654 } else {
655 // it's better to keep these cases separate... 655 // it's better to keep these cases separate...
656 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 656 if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4
657 && jan1WeekDay != 7 ) { 657 && jan1WeekDay != 7 ) {
658 yearNumber = d.year() - 1; 658 yearNumber = d.year() - 1;
659 if ( jan1WeekDay == 6 659 if ( jan1WeekDay == 6
660 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { 660 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) {
661 weekNumber = 53; 661 weekNumber = 53;
662 }else 662 }else
663 weekNumber = 52; 663 weekNumber = 52;
664 } else 664 } else
665 yearNumber = d.year(); 665 yearNumber = d.year();
666 if ( yearNumber == d.year() ) { 666 if ( yearNumber == d.year() ) {
667 int totalDays = 365; 667 int totalDays = 365;
668 if ( QDate::leapYear( yearNumber ) ) 668 if ( QDate::leapYear( yearNumber ) )
669 totalDays++; 669 totalDays++;
670 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) { 670 if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) {
671 yearNumber++; 671 yearNumber++;
672 weekNumber = 1; 672 weekNumber = 1;
673 } 673 }
674 } 674 }
675 if ( yearNumber == d.year() ) { 675 if ( yearNumber == d.year() ) {
676 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 ); 676 int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 );
677 weekNumber = j / 7; 677 weekNumber = j / 7;
678 if ( jan1WeekDay > 4 ) { 678 if ( jan1WeekDay > 4 ) {
679 weekNumber--; 679 weekNumber--;
680 } 680 }
681 } 681 }
682 } 682 }
683 year = yearNumber; 683 year = yearNumber;
684 week = weekNumber; 684 week = weekNumber;
685 return true; 685 return true;
686} 686}
687 687
diff --git a/core/pim/datebook/datebookweeklst.cpp b/core/pim/datebook/datebookweeklst.cpp
index 7083bc5..85c745a 100644
--- a/core/pim/datebook/datebookweeklst.cpp
+++ b/core/pim/datebook/datebookweeklst.cpp
@@ -1,373 +1,373 @@
1#include "datebookweeklst.h" 1#include "datebookweeklst.h"
2 2
3#include "datebookweekheaderimpl.h" 3#include "datebookweekheaderimpl.h"
4 4
5#include <qpe/calendar.h> 5#include <qpe/calendar.h>
6#include <qpe/datebookdb.h> 6#include <qpe/datebookdb.h>
7#include <qpe/event.h> 7#include <qpe/event.h>
8#include <qpe/qpeapplication.h> 8#include <qpe/qpeapplication.h>
9#include <qpe/timestring.h> 9#include <qpe/timestring.h>
10#include <qpe/datebookmonth.h> 10#include <qpe/datebookmonth.h>
11#include <qpe/config.h> 11#include <qpe/config.h>
12 12
13#include <qdatetime.h> 13#include <qdatetime.h>
14#include <qheader.h> 14#include <qheader.h>
15#include <qlabel.h> 15#include <qlabel.h>
16#include <qlayout.h> 16#include <qlayout.h>
17#include <qpainter.h> 17#include <qpainter.h>
18#include <qpopupmenu.h> 18#include <qpopupmenu.h>
19#include <qtimer.h> 19#include <qtimer.h>
20#include <qstyle.h> 20#include <qstyle.h>
21#include <qtoolbutton.h> 21#include <qtoolbutton.h>
22#include <qvbox.h> 22#include <qvbox.h>
23#include <qsizepolicy.h> 23#include <qsizepolicy.h>
24#include <qabstractlayout.h> 24#include <qabstractlayout.h>
25#include <qtl.h> 25#include <qtl.h>
26 26
27bool calcWeek(const QDate &d, int &week, int &year, 27bool calcWeek(const QDate &d, int &week, int &year,
28 bool startOnMonday = false); 28 bool startOnMonday = false);
29 29
30DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent, 30DateBookWeekLstHeader::DateBookWeekLstHeader(bool onM, QWidget* parent,
31 const char* name, WFlags fl) 31 const char* name, WFlags fl)
32 : DateBookWeekLstHeaderBase(parent, name, fl) 32 : DateBookWeekLstHeaderBase(parent, name, fl)
33{ 33{
34 setBackgroundMode( PaletteButton ); 34 setBackgroundMode( PaletteButton );
35 labelDate->setBackgroundMode( PaletteButton ); 35 labelDate->setBackgroundMode( PaletteButton );
36 labelWeek->setBackgroundMode( PaletteButton ); 36 labelWeek->setBackgroundMode( PaletteButton );
37 forward->setBackgroundMode( PaletteButton ); 37 forward->setBackgroundMode( PaletteButton );
38 back->setBackgroundMode( PaletteButton ); 38 back->setBackgroundMode( PaletteButton );
39 DateBookWeekLstHeaderBaseLayout->setSpacing(0); 39 DateBookWeekLstHeaderBaseLayout->setSpacing(0);
40 DateBookWeekLstHeaderBaseLayout->setMargin(0); 40 DateBookWeekLstHeaderBaseLayout->setMargin(0);
41 //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding)); 41 //setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding));
42 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 42 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
43 43
44 connect(back, SIGNAL(clicked()), this, SLOT(prevWeek())); 44 connect(back, SIGNAL(clicked()), this, SLOT(prevWeek()));
45 connect(forward, SIGNAL(clicked()), this, SLOT(nextWeek())); 45 connect(forward, SIGNAL(clicked()), this, SLOT(nextWeek()));
46 connect(labelWeek, SIGNAL(clicked()), this, SLOT(pickDate())); 46 connect(labelWeek, SIGNAL(clicked()), this, SLOT(pickDate()));
47 connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool))); 47 connect(dbl, SIGNAL(toggled(bool)), this, SIGNAL(setDbl(bool)));
48 onMonday=onM; 48 onMonday=onM;
49} 49}
50DateBookWeekLstHeader::~DateBookWeekLstHeader(){} 50DateBookWeekLstHeader::~DateBookWeekLstHeader(){}
51void DateBookWeekLstHeader::setDate(const QDate &d) { 51void DateBookWeekLstHeader::setDate(const QDate &d) {
52 date=d; 52 date=d;
53 53
54 int year,week; 54 int year,week;
55 calcWeek(d,week,year,onMonday); 55 calcWeek(d,week,year,onMonday);
56 labelWeek->setText("W: " + QString::number(week)); 56 labelWeek->setText("W: " + QString::number(week));
57 57
58 QDate start=date; 58 QDate start=date;
59 QDate stop=start.addDays(6); 59 QDate stop=start.addDays(6);
60 labelDate->setText( QString::number(start.day()) + " " + 60 labelDate->setText( QString::number(start.day()) + " " +
61 start.monthName(start.month()) + " - " + 61 start.monthName(start.month()) + " - " +
62 QString::number(stop.day()) + " " + 62 QString::number(stop.day()) + " " +
63 start.monthName(stop.month()) ); 63 start.monthName(stop.month()) );
64 emit dateChanged(year,week); 64 emit dateChanged(year,week);
65} 65}
66void DateBookWeekLstHeader::pickDate() { 66void DateBookWeekLstHeader::pickDate() {
67 static QPopupMenu *m1 = 0; 67 static QPopupMenu *m1 = 0;
68 static DateBookMonth *picker = 0; 68 static DateBookMonth *picker = 0;
69 if ( !m1 ) { 69 if ( !m1 ) {
70 m1 = new QPopupMenu( this ); 70 m1 = new QPopupMenu( this );
71 picker = new DateBookMonth( m1, 0, TRUE ); 71 picker = new DateBookMonth( m1, 0, TRUE );
72 m1->insertItem( picker ); 72 m1->insertItem( picker );
73 connect( picker, SIGNAL( dateClicked( int, int, int ) ), 73 connect( picker, SIGNAL( dateClicked( int, int, int ) ),
74 this, SLOT( setDate( int, int, int ) ) ); 74 this, SLOT( setDate( int, int, int ) ) );
75 //connect( m1, SIGNAL( aboutToHide() ), 75 //connect( m1, SIGNAL( aboutToHide() ),
76 //this, SLOT( gotHide() ) ); 76 //this, SLOT( gotHide() ) );
77 } 77 }
78 picker->setDate( date.year(), date.month(), date.day() ); 78 picker->setDate( date.year(), date.month(), date.day() );
79 m1->popup(mapToGlobal(labelWeek->pos()+QPoint(0,labelWeek->height()))); 79 m1->popup(mapToGlobal(labelWeek->pos()+QPoint(0,labelWeek->height())));
80 picker->setFocus(); 80 picker->setFocus();
81} 81}
82void DateBookWeekLstHeader::setDate(int y, int m, int d) { 82void DateBookWeekLstHeader::setDate(int y, int m, int d) {
83 QDate new_date(y,m,d); 83 QDate new_date(y,m,d);
84 setDate(new_date); 84 setDate(new_date);
85} 85}
86 86
87void DateBookWeekLstHeader::nextWeek() { 87void DateBookWeekLstHeader::nextWeek() {
88 setDate(date.addDays(7)); 88 setDate(date.addDays(7));
89} 89}
90void DateBookWeekLstHeader::prevWeek() { 90void DateBookWeekLstHeader::prevWeek() {
91 setDate(date.addDays(-7)); 91 setDate(date.addDays(-7));
92} 92}
93 93
94DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool onM, 94DateBookWeekLstDayHdr::DateBookWeekLstDayHdr(const QDate &d, bool onM,
95 QWidget* parent = 0, 95 QWidget* parent,
96 const char* name = 0, 96 const char* name,
97 WFlags fl = 0 ) 97 WFlags fl )
98 : DateBookWeekLstDayHdrBase(parent, name, fl) { 98 : DateBookWeekLstDayHdrBase(parent, name, fl) {
99 99
100 date=d; 100 date=d;
101 101
102 static const char *wdays="MTWTFSS"; 102 static const char *wdays="MTWTFSS";
103 char day=wdays[d.dayOfWeek()-1]; 103 char day=wdays[d.dayOfWeek()-1];
104 104
105 label->setText( QString(QChar(day)) + " " + 105 label->setText( QString(QChar(day)) + " " +
106 QString::number(d.day()) ); 106 QString::number(d.day()) );
107 add->setText("+"); 107 add->setText("+");
108 108
109 if (d == QDate::currentDate()) { 109 if (d == QDate::currentDate()) {
110 QPalette pal=label->palette(); 110 QPalette pal=label->palette();
111 pal.setColor(QColorGroup::Foreground, QColor(0,0,255)); 111 pal.setColor(QColorGroup::Foreground, QColor(0,0,255));
112 label->setPalette(pal); 112 label->setPalette(pal);
113 113
114 /* 114 /*
115 QFont f=label->font(); 115 QFont f=label->font();
116 f.setItalic(true); 116 f.setItalic(true);
117 label->setFont(f); 117 label->setFont(f);
118 label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor())); 118 label->setPalette(QPalette(QColor(0,0,255),label->backgroundColor()));
119 */ 119 */
120 } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday 120 } else if (d.dayOfWeek() == 7) { // FIXME: Match any holiday
121 QPalette pal=label->palette(); 121 QPalette pal=label->palette();
122 pal.setColor(QColorGroup::Foreground, QColor(255,0,0)); 122 pal.setColor(QColorGroup::Foreground, QColor(255,0,0));
123 label->setPalette(pal); 123 label->setPalette(pal);
124 } 124 }
125 125
126 126
127 connect (label, SIGNAL(clicked()), this, SLOT(showDay())); 127 connect (label, SIGNAL(clicked()), this, SLOT(showDay()));
128 connect (add, SIGNAL(clicked()), this, SLOT(newEvent())); 128 connect (add, SIGNAL(clicked()), this, SLOT(newEvent()));
129} 129}
130 130
131void DateBookWeekLstDayHdr::showDay() { 131void DateBookWeekLstDayHdr::showDay() {
132 emit showDate(date.year(), date.month(), date.day()); 132 emit showDate(date.year(), date.month(), date.day());
133} 133}
134void DateBookWeekLstDayHdr::newEvent() { 134void DateBookWeekLstDayHdr::newEvent() {
135 QDateTime start, stop; 135 QDateTime start, stop;
136 start=stop=date; 136 start=stop=date;
137 start.setTime(QTime(10,0)); 137 start.setTime(QTime(10,0));
138 stop.setTime(QTime(12,0)); 138 stop.setTime(QTime(12,0));
139 139
140 emit addEvent(start,stop,""); 140 emit addEvent(start,stop,"");
141} 141}
142DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev, 142DateBookWeekLstEvent::DateBookWeekLstEvent(const EffectiveEvent &ev,
143 QWidget* parent = 0, 143 QWidget* parent,
144 const char* name = 0, 144 const char* name,
145 WFlags fl = 0) : 145 WFlags fl) :
146 ClickableLabel(parent,name,fl), 146 ClickableLabel(parent,name,fl),
147 event(ev) 147 event(ev)
148{ 148{
149 char s[10]; 149 char s[10];
150 if ( ev.startDate() != ev.date() ) { // multiday event (not first day) 150 if ( ev.startDate() != ev.date() ) { // multiday event (not first day)
151 if ( ev.endDate() == ev.date() ) { // last day 151 if ( ev.endDate() == ev.date() ) { // last day
152 strcpy(s, "__|__"); 152 strcpy(s, "__|__");
153 } else { 153 } else {
154 strcpy(s, " |---"); 154 strcpy(s, " |---");
155 } 155 }
156 } else { 156 } else {
157 sprintf(s,"%.2d:%.2d",ev.start().hour(),ev.start().minute()); 157 sprintf(s,"%.2d:%.2d",ev.start().hour(),ev.start().minute());
158 } 158 }
159 setText(QString(s) + " " + ev.description()); 159 setText(QString(s) + " " + ev.description());
160 connect(this, SIGNAL(clicked()), this, SLOT(editMe())); 160 connect(this, SIGNAL(clicked()), this, SLOT(editMe()));
161 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) ); 161 setAlignment( int( QLabel::WordBreak | QLabel::AlignLeft ) );
162} 162}
163void DateBookWeekLstEvent::editMe() { 163void DateBookWeekLstEvent::editMe() {
164 emit editEvent(event.event()); 164 emit editEvent(event.event());
165} 165}
166 166
167 167
168DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev, 168DateBookWeekLstView::DateBookWeekLstView(QValueList<EffectiveEvent> &ev,
169 const QDate &d, bool onM, 169 const QDate &d, bool onM,
170 QWidget* parent, 170 QWidget* parent,
171 const char* name, WFlags fl) 171 const char* name, WFlags fl)
172 : QWidget( parent, name, fl ) 172 : QWidget( parent, name, fl )
173{ 173{
174 onMonday=onM; 174 onMonday=onM;
175 setPalette(white); 175 setPalette(white);
176 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); 176 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
177 177
178 QVBoxLayout *layout = new QVBoxLayout( this ); 178 QVBoxLayout *layout = new QVBoxLayout( this );
179 179
180 qBubbleSort(ev); 180 qBubbleSort(ev);
181 QValueListIterator<EffectiveEvent> it; 181 QValueListIterator<EffectiveEvent> it;
182 it=ev.begin(); 182 it=ev.begin();
183 183
184 int dayOrder[7]; 184 int dayOrder[7];
185 if (onMonday) 185 if (onMonday)
186 for (int d=0; d<7; d++) dayOrder[d]=d+1; 186 for (int d=0; d<7; d++) dayOrder[d]=d+1;
187 else { 187 else {
188 for (int d=0; d<7; d++) dayOrder[d]=d; 188 for (int d=0; d<7; d++) dayOrder[d]=d;
189 dayOrder[0]=7; 189 dayOrder[0]=7;
190 } 190 }
191 191
192 for (int i=0; i<7; i++) { 192 for (int i=0; i<7; i++) {
193 // Header 193 // Header
194 DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i), 194 DateBookWeekLstDayHdr *hdr=new DateBookWeekLstDayHdr(d.addDays(i),
195 onMonday,this); 195 onMonday,this);
196 connect(hdr, SIGNAL(showDate(int,int,int)), 196 connect(hdr, SIGNAL(showDate(int,int,int)),
197 this, SIGNAL(showDate(int,int,int))); 197 this, SIGNAL(showDate(int,int,int)));
198 connect(hdr, SIGNAL(addEvent(const QDateTime &, 198 connect(hdr, SIGNAL(addEvent(const QDateTime &,
199 const QDateTime &, 199 const QDateTime &,
200 const QString &)), 200 const QString &)),
201 this, SIGNAL(addEvent(const QDateTime &, 201 this, SIGNAL(addEvent(const QDateTime &,
202 const QDateTime &, 202 const QDateTime &,
203 const QString &))); 203 const QString &)));
204 layout->addWidget(hdr); 204 layout->addWidget(hdr);
205 205
206 // Events 206 // Events
207 while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) { 207 while ( (*it).date().dayOfWeek() == dayOrder[i] && it!=ev.end() ) {
208 DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,this); 208 DateBookWeekLstEvent *l=new DateBookWeekLstEvent(*it,this);
209 layout->addWidget(l); 209 layout->addWidget(l);
210 connect (l, SIGNAL(editEvent(const Event &)), 210 connect (l, SIGNAL(editEvent(const Event &)),
211 this, SIGNAL(editEvent(const Event &))); 211 this, SIGNAL(editEvent(const Event &)));
212 it++; 212 it++;
213 } 213 }
214 214
215 layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding)); 215 layout->addItem(new QSpacerItem(1,1, QSizePolicy::Minimum, QSizePolicy::Expanding));
216 } 216 }
217} 217}
218DateBookWeekLstView::~DateBookWeekLstView(){} 218DateBookWeekLstView::~DateBookWeekLstView(){}
219void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();} 219void DateBookWeekLstView::keyPressEvent(QKeyEvent *e) {e->ignore();}
220 220
221DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1, 221DateBookWeekLstDblView::DateBookWeekLstDblView(QValueList<EffectiveEvent> &ev1,
222 QValueList<EffectiveEvent> &ev2, 222 QValueList<EffectiveEvent> &ev2,
223 QDate &d, bool onM, 223 QDate &d, bool onM,
224 QWidget* parent, 224 QWidget* parent,
225 const char* name, WFlags fl) 225 const char* name, WFlags fl)
226 : QWidget( parent, name, fl ) 226 : QWidget( parent, name, fl )
227{ 227{
228 QHBoxLayout *layout = new QHBoxLayout( this ); 228 QHBoxLayout *layout = new QHBoxLayout( this );
229 229
230 DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this); 230 DateBookWeekLstView *w=new DateBookWeekLstView(ev1,d,onM,this);
231 layout->addWidget(w); 231 layout->addWidget(w);
232 connect (w, SIGNAL(editEvent(const Event &)), 232 connect (w, SIGNAL(editEvent(const Event &)),
233 this, SIGNAL(editEvent(const Event &))); 233 this, SIGNAL(editEvent(const Event &)));
234 connect (w, SIGNAL(showDate(int,int,int)), 234 connect (w, SIGNAL(showDate(int,int,int)),
235 this, SIGNAL(showDate(int,int,int))); 235 this, SIGNAL(showDate(int,int,int)));
236 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 236 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
237 const QString &)), 237 const QString &)),
238 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 238 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
239 const QString &))); 239 const QString &)));
240 240
241 241
242 w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this); 242 w=new DateBookWeekLstView(ev2,d.addDays(7),onM,this);
243 layout->addWidget(w); 243 layout->addWidget(w);
244 connect (w, SIGNAL(editEvent(const Event &)), 244 connect (w, SIGNAL(editEvent(const Event &)),
245 this, SIGNAL(editEvent(const Event &))); 245 this, SIGNAL(editEvent(const Event &)));
246 connect (w, SIGNAL(showDate(int,int,int)), 246 connect (w, SIGNAL(showDate(int,int,int)),
247 this, SIGNAL(showDate(int,int,int))); 247 this, SIGNAL(showDate(int,int,int)));
248 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 248 connect (w, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
249 const QString &)), 249 const QString &)),
250 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 250 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
251 const QString &))); 251 const QString &)));
252} 252}
253 253
254DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB, 254DateBookWeekLst::DateBookWeekLst( bool ap, bool onM, DateBookDB *newDB,
255 QWidget *parent, 255 QWidget *parent,
256 const char *name ) 256 const char *name )
257 : QWidget( parent, name ), 257 : QWidget( parent, name ),
258 db( newDB ), 258 db( newDB ),
259 startTime( 0 ), 259 startTime( 0 ),
260 ampm( ap ), 260 ampm( ap ),
261 onMonday(onM) 261 onMonday(onM)
262{ 262{
263 setFocusPolicy(StrongFocus); 263 setFocusPolicy(StrongFocus);
264 layout = new QVBoxLayout( this ); 264 layout = new QVBoxLayout( this );
265 layout->setMargin(0); 265 layout->setMargin(0);
266 266
267 header=new DateBookWeekLstHeader(onM, this); 267 header=new DateBookWeekLstHeader(onM, this);
268 layout->addWidget( header ); 268 layout->addWidget( header );
269 connect(header, SIGNAL(dateChanged(int,int)), 269 connect(header, SIGNAL(dateChanged(int,int)),
270 this, SLOT(dateChanged(int,int))); 270 this, SLOT(dateChanged(int,int)));
271 connect(header, SIGNAL(setDbl(bool)), 271 connect(header, SIGNAL(setDbl(bool)),
272 this, SLOT(setDbl(bool))); 272 this, SLOT(setDbl(bool)));
273 273
274 scroll=new QScrollView(this); 274 scroll=new QScrollView(this);
275 //scroll->setVScrollBarMode(QScrollView::AlwaysOn); 275 //scroll->setVScrollBarMode(QScrollView::AlwaysOn);
276 //scroll->setHScrollBarMode(QScrollView::AlwaysOff); 276 //scroll->setHScrollBarMode(QScrollView::AlwaysOff);
277 scroll->setResizePolicy(QScrollView::AutoOneFit); 277 scroll->setResizePolicy(QScrollView::AutoOneFit);
278 layout->addWidget(scroll); 278 layout->addWidget(scroll);
279 279
280 view=NULL; 280 view=NULL;
281 Config config("DateBook"); 281 Config config("DateBook");
282 config.setGroup("Main"); 282 config.setGroup("Main");
283 dbl=config.readBoolEntry("weeklst_dbl", false); 283 dbl=config.readBoolEntry("weeklst_dbl", false);
284 header->dbl->setOn(dbl); 284 header->dbl->setOn(dbl);
285} 285}
286DateBookWeekLst::~DateBookWeekLst(){ 286DateBookWeekLst::~DateBookWeekLst(){
287 Config config("DateBook"); 287 Config config("DateBook");
288 config.setGroup("Main"); 288 config.setGroup("Main");
289 config.writeEntry("weeklst_dbl", dbl); 289 config.writeEntry("weeklst_dbl", dbl);
290} 290}
291 291
292void DateBookWeekLst::setDate(const QDate &d) { 292void DateBookWeekLst::setDate(const QDate &d) {
293 int w,y; 293 int w,y;
294 calcWeek(d,w,y,onMonday); 294 calcWeek(d,w,y,onMonday);
295 year=y; 295 year=y;
296 _week=w; 296 _week=w;
297 header->setDate(date()); 297 header->setDate(date());
298} 298}
299void DateBookWeekLst::setDbl(bool on) { 299void DateBookWeekLst::setDbl(bool on) {
300 dbl=on; 300 dbl=on;
301 redraw(); 301 redraw();
302} 302}
303void DateBookWeekLst::redraw() {getEvents();} 303void DateBookWeekLst::redraw() {getEvents();}
304 304
305QDate DateBookWeekLst::date() const { 305QDate DateBookWeekLst::date() const {
306 QDate d; 306 QDate d;
307 d.setYMD(year,1,1); 307 d.setYMD(year,1,1);
308 308
309 int dow= d.dayOfWeek(); 309 int dow= d.dayOfWeek();
310 if (!onMonday) 310 if (!onMonday)
311 if (dow==7) dow=1; 311 if (dow==7) dow=1;
312 else dow++; 312 else dow++;
313 313
314 d=d.addDays( (_week-1)*7 - dow + 1 ); 314 d=d.addDays( (_week-1)*7 - dow + 1 );
315 return d; 315 return d;
316} 316}
317 317
318void DateBookWeekLst::getEvents() { 318void DateBookWeekLst::getEvents() {
319 QDate start = date(); 319 QDate start = date();
320 QDate stop = start.addDays(6); 320 QDate stop = start.addDays(6);
321 QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop); 321 QValueList<EffectiveEvent> el = db->getEffectiveEvents(start, stop);
322 322
323 if (view) delete view; 323 if (view) delete view;
324 if (dbl) { 324 if (dbl) {
325 QDate start2=start.addDays(7); 325 QDate start2=start.addDays(7);
326 stop=start2.addDays(6); 326 stop=start2.addDays(6);
327 QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop); 327 QValueList<EffectiveEvent> el2 = db->getEffectiveEvents(start2, stop);
328 328
329 view=new DateBookWeekLstDblView(el,el2,start,onMonday,scroll); 329 view=new DateBookWeekLstDblView(el,el2,start,onMonday,scroll);
330 } else { 330 } else {
331 view=new DateBookWeekLstView(el,start,onMonday,scroll); 331 view=new DateBookWeekLstView(el,start,onMonday,scroll);
332 } 332 }
333 333
334 connect (view, SIGNAL(editEvent(const Event &)), 334 connect (view, SIGNAL(editEvent(const Event &)),
335 this, SIGNAL(editEvent(const Event &))); 335 this, SIGNAL(editEvent(const Event &)));
336 connect (view, SIGNAL(showDate(int,int,int)), 336 connect (view, SIGNAL(showDate(int,int,int)),
337 this, SIGNAL(showDate(int,int,int))); 337 this, SIGNAL(showDate(int,int,int)));
338 connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 338 connect (view, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
339 const QString &)), 339 const QString &)),
340 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &, 340 this, SIGNAL(addEvent(const QDateTime &, const QDateTime &,
341 const QString &))); 341 const QString &)));
342 342
343 scroll->addChild(view); 343 scroll->addChild(view);
344 view->show(); 344 view->show();
345 scroll->updateScrollBars(); 345 scroll->updateScrollBars();
346} 346}
347 347
348void DateBookWeekLst::dateChanged(int y, int w) { 348void DateBookWeekLst::dateChanged(int y, int w) {
349 year=y; 349 year=y;
350 _week=w; 350 _week=w;
351 getEvents(); 351 getEvents();
352} 352}
353 353
354void DateBookWeekLst::keyPressEvent(QKeyEvent *e) 354void DateBookWeekLst::keyPressEvent(QKeyEvent *e)
355{ 355{
356 switch(e->key()) { 356 switch(e->key()) {
357 case Key_Up: 357 case Key_Up:
358 scroll->scrollBy(0, -20); 358 scroll->scrollBy(0, -20);
359 break; 359 break;
360 case Key_Down: 360 case Key_Down:
361 scroll->scrollBy(0, 20); 361 scroll->scrollBy(0, 20);
362 break; 362 break;
363 case Key_Left: 363 case Key_Left:
364 header->prevWeek(); 364 header->prevWeek();
365 break; 365 break;
366 case Key_Right: 366 case Key_Right:
367 header->nextWeek(); 367 header->nextWeek();
368 break; 368 break;
369 default: 369 default:
370 e->ignore(); 370 e->ignore();
371 } 371 }
372} 372}
373 373
diff --git a/core/pim/datebook/timepicker.cpp b/core/pim/datebook/timepicker.cpp
index 9097e1b..43e05ad 100644
--- a/core/pim/datebook/timepicker.cpp
+++ b/core/pim/datebook/timepicker.cpp
@@ -1,120 +1,120 @@
1#include "timepicker.h" 1#include "timepicker.h"
2 2
3#include <qbuttongroup.h> 3#include <qbuttongroup.h>
4#include <qtoolbutton.h> 4#include <qtoolbutton.h>
5#include <qlayout.h> 5#include <qlayout.h>
6#include "clickablelabel.h" 6#include "clickablelabel.h"
7#include <qstring.h> 7#include <qstring.h>
8#include <stdio.h> 8#include <stdio.h>
9 9
10TimePicker::TimePicker(QWidget* parent = 0, const char* name = 0, 10TimePicker::TimePicker(QWidget* parent, const char* name,
11 WFlags fl = 0) : 11 WFlags fl) :
12 QWidget(parent,name,fl) 12 QWidget(parent,name,fl)
13{ 13{
14 QVBoxLayout *vbox=new QVBoxLayout(this); 14 QVBoxLayout *vbox=new QVBoxLayout(this);
15 15
16 ClickableLabel *r; 16 ClickableLabel *r;
17 QString s; 17 QString s;
18 18
19 // Hour Row 19 // Hour Row
20 QWidget *row=new QWidget(this); 20 QWidget *row=new QWidget(this);
21 QHBoxLayout *l=new QHBoxLayout(row); 21 QHBoxLayout *l=new QHBoxLayout(row);
22 vbox->addWidget(row); 22 vbox->addWidget(row);
23 23
24 24
25 for (int i=0; i<24; i++) { 25 for (int i=0; i<24; i++) {
26 r=new ClickableLabel(row); 26 r=new ClickableLabel(row);
27 hourLst.append(r); 27 hourLst.append(r);
28 s.sprintf("%.2d",i); 28 s.sprintf("%.2d",i);
29 r->setText(s); 29 r->setText(s);
30 r->setToggleButton(true); 30 r->setToggleButton(true);
31 r->setAlignment(AlignHCenter | AlignVCenter); 31 r->setAlignment(AlignHCenter | AlignVCenter);
32 l->addWidget(r); 32 l->addWidget(r);
33 connect(r, SIGNAL(toggled(bool)), 33 connect(r, SIGNAL(toggled(bool)),
34 this, SLOT(slotHour(bool))); 34 this, SLOT(slotHour(bool)));
35 35
36 if (i==11) { // Second row 36 if (i==11) { // Second row
37 row=new QWidget(this); 37 row=new QWidget(this);
38 l=new QHBoxLayout(row); 38 l=new QHBoxLayout(row);
39 vbox->addWidget(row); 39 vbox->addWidget(row);
40 } 40 }
41 } 41 }
42 42
43 // Minute Row 43 // Minute Row
44 row=new QWidget(this); 44 row=new QWidget(this);
45 l=new QHBoxLayout(row); 45 l=new QHBoxLayout(row);
46 vbox->addWidget(row); 46 vbox->addWidget(row);
47 47
48 for (int i=0; i<60; i+=5) { 48 for (int i=0; i<60; i+=5) {
49 r=new ClickableLabel(row); 49 r=new ClickableLabel(row);
50 minuteLst.append(r); 50 minuteLst.append(r);
51 s.sprintf("%.2d",i); 51 s.sprintf("%.2d",i);
52 r->setText(s); 52 r->setText(s);
53 r->setToggleButton(true); 53 r->setToggleButton(true);
54 r->setAlignment(AlignHCenter | AlignVCenter); 54 r->setAlignment(AlignHCenter | AlignVCenter);
55 l->addWidget(r); 55 l->addWidget(r);
56 connect(r, SIGNAL(toggled(bool)), 56 connect(r, SIGNAL(toggled(bool)),
57 this, SLOT(slotMinute(bool))); 57 this, SLOT(slotMinute(bool)));
58 } 58 }
59} 59}
60 60
61void TimePicker::slotHour(bool b) { 61void TimePicker::slotHour(bool b) {
62 62
63 ClickableLabel *r = (ClickableLabel *) sender(); 63 ClickableLabel *r = (ClickableLabel *) sender();
64 64
65 if (b) { 65 if (b) {
66 QValueListIterator<ClickableLabel *> it; 66 QValueListIterator<ClickableLabel *> it;
67 for (it=hourLst.begin(); it!=hourLst.end(); it++) { 67 for (it=hourLst.begin(); it!=hourLst.end(); it++) {
68 if (*it != r) (*it)->setOn(false); 68 if (*it != r) (*it)->setOn(false);
69 else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); 69 else tm.setHMS((*it)->text().toInt(), tm.minute(), 0);
70 } 70 }
71 emit timeChanged(tm); 71 emit timeChanged(tm);
72 } else { 72 } else {
73 r->setOn(true); 73 r->setOn(true);
74 } 74 }
75 75
76} 76}
77 77
78void TimePicker::slotMinute(bool b) { 78void TimePicker::slotMinute(bool b) {
79 79
80 ClickableLabel *r = (ClickableLabel *) sender(); 80 ClickableLabel *r = (ClickableLabel *) sender();
81 81
82 if (b) { 82 if (b) {
83 QValueListIterator<ClickableLabel *> it; 83 QValueListIterator<ClickableLabel *> it;
84 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { 84 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) {
85 if (*it != r) (*it)->setOn(false); 85 if (*it != r) (*it)->setOn(false);
86 else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); 86 else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0);
87 } 87 }
88 emit timeChanged(tm); 88 emit timeChanged(tm);
89 } else { 89 } else {
90 r->setOn(true); 90 r->setOn(true);
91 } 91 }
92 92
93} 93}
94 94
95void TimePicker::setMinute(int m) { 95void TimePicker::setMinute(int m) {
96 96
97 QString minute; 97 QString minute;
98 minute.sprintf("%.2d",m); 98 minute.sprintf("%.2d",m);
99 99
100 QValueListIterator<ClickableLabel *> it; 100 QValueListIterator<ClickableLabel *> it;
101 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { 101 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) {
102 if ((*it)->text() == minute) (*it)->setOn(true); 102 if ((*it)->text() == minute) (*it)->setOn(true);
103 else (*it)->setOn(false); 103 else (*it)->setOn(false);
104 } 104 }
105 105
106 tm.setHMS(tm.hour(),m,0); 106 tm.setHMS(tm.hour(),m,0);
107} 107}
108 108
109void TimePicker::setHour(int h) { 109void TimePicker::setHour(int h) {
110 110
111 QString hour; 111 QString hour;
112 hour.sprintf("%.2d",h); 112 hour.sprintf("%.2d",h);
113 113
114 QValueListIterator<ClickableLabel *> it; 114 QValueListIterator<ClickableLabel *> it;
115 for (it=hourLst.begin(); it!=hourLst.end(); it++) { 115 for (it=hourLst.begin(); it!=hourLst.end(); it++) {
116 if ((*it)->text() == hour) (*it)->setOn(true); 116 if ((*it)->text() == hour) (*it)->setOn(true);
117 else (*it)->setOn(false); 117 else (*it)->setOn(false);
118 } 118 }
119 tm.setHMS(h,tm.minute(),0); 119 tm.setHMS(h,tm.minute(),0);
120} 120}