summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookweek.cpp56
1 files changed, 28 insertions, 28 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp
index e49ed28..2ad7aa9 100644
--- a/core/pim/datebook/datebookweek.cpp
+++ b/core/pim/datebook/datebookweek.cpp
@@ -1,257 +1,257 @@
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("Mo", "Monday" ) );
96 header->addLabel( tr("T", "Tuesday") ); 96 header->addLabel( tr("Tu", "Tuesday") );
97 header->addLabel( tr("W", "Wednesday" ) ); 97 header->addLabel( tr("We", "Wednesday" ) );
98 header->addLabel( tr("T", "Thursday" ) ); 98 header->addLabel( tr("Th", "Thursday" ) );
99 header->addLabel( tr("F", "Friday" ) ); 99 header->addLabel( tr("Fr", "Friday" ) );
100 header->addLabel( tr("S", "Saturday" ) ); 100 header->addLabel( tr("Sa", "Saturday" ) );
101 header->addLabel( tr("S", "Sunday" ) ); 101 header->addLabel( tr("Su", "Sunday" ) );
102 } else { 102 } else {
103 header->addLabel( tr("S", "Sunday" ) ); 103 header->addLabel( tr("Su", "Sunday" ) );
104 header->addLabel( tr("M", "Monday") ); 104 header->addLabel( tr("Mo", "Monday") );
105 header->addLabel( tr("T", "Tuesday") ); 105 header->addLabel( tr("Tu", "Tuesday") );
106 header->addLabel( tr("W", "Wednesday" ) ); 106 header->addLabel( tr("We", "Wednesday" ) );
107 header->addLabel( tr("T", "Thursday" ) ); 107 header->addLabel( tr("Th", "Thursday" ) );
108 header->addLabel( tr("F", "Friday" ) ); 108 header->addLabel( tr("Fr", "Friday" ) );
109 header->addLabel( tr("S", "Saturday" ) ); 109 header->addLabel( tr("Sa", "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("Mo", "Monday") );
116 header->setLabel( 2, tr("T", "Tuesday") ); 116 header->setLabel( 2, tr("Tu", "Tuesday") );
117 header->setLabel( 3, tr("W", "Wednesday" ) ); 117 header->setLabel( 3, tr("We", "Wednesday" ) );
118 header->setLabel( 4, tr("T", "Thursday" ) ); 118 header->setLabel( 4, tr("Th", "Thursday" ) );
119 header->setLabel( 5, tr("F", "Friday" ) ); 119 header->setLabel( 5, tr("Fr", "Friday" ) );
120 header->setLabel( 6, tr("S", "Saturday" ) ); 120 header->setLabel( 6, tr("Sa", "Saturday" ) );
121 header->setLabel( 7, tr("S", "Sunday" ) ); 121 header->setLabel( 7, tr("Su", "Sunday" ) );
122 } else { 122 } else {
123 header->setLabel( 1, tr("S", "Sunday" ) ); 123 header->setLabel( 1, tr("Su", "Sunday" ) );
124 header->setLabel( 2, tr("M", "Monday") ); 124 header->setLabel( 2, tr("Mo", "Monday") );
125 header->setLabel( 3, tr("T", "Tuesday") ); 125 header->setLabel( 3, tr("Tu", "Tuesday") );
126 header->setLabel( 4, tr("W", "Wednesday" ) ); 126 header->setLabel( 4, tr("We", "Wednesday" ) );
127 header->setLabel( 5, tr("T", "Thursday" ) ); 127 header->setLabel( 5, tr("Th", "Thursday" ) );
128 header->setLabel( 6, tr("F", "Friday" ) ); 128 header->setLabel( 6, tr("Fr", "Friday" ) );
129 header->setLabel( 7, tr("S", "Saturday" ) ); 129 header->setLabel( 7, tr("Sa", "Saturday" ) );
130 } 130 }
131 } 131 }
132} 132}
133 133
134 134
135 135
136void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev ) 136void DateBookWeekView::showEvents( QValueList<EffectiveEvent> &ev )
137{ 137{
138 items.clear(); 138 items.clear();
139 QValueListIterator<EffectiveEvent> it; 139 QValueListIterator<EffectiveEvent> it;
140 for ( it = ev.begin(); it != ev.end(); ++it ) { 140 for ( it = ev.begin(); it != ev.end(); ++it ) {
141 DateBookWeekItem *i = new DateBookWeekItem( *it ); 141 DateBookWeekItem *i = new DateBookWeekItem( *it );
142 if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) {// Skip events ending at 00:00 starting at another day. 142 if(!((i->event().end().hour()==0) && (i->event().end().minute()==0) && (i->event().startDate()!=i->event().date()))) {// Skip events ending at 00:00 starting at another day.
143 positionItem( i ); 143 positionItem( i );
144 items.append( i ); 144 items.append( i );
145 } 145 }
146 } 146 }
147 viewport()->update(); 147 viewport()->update();
148} 148}
149 149
150void DateBookWeekView::moveToHour( int h ) 150void DateBookWeekView::moveToHour( int h )
151{ 151{
152 int offset = h*rowHeight; 152 int offset = h*rowHeight;
153 setContentsPos( 0, offset ); 153 setContentsPos( 0, offset );
154} 154}
155 155
156void DateBookWeekView::keyPressEvent( QKeyEvent *e ) 156void DateBookWeekView::keyPressEvent( QKeyEvent *e )
157{ 157{
158 e->ignore(); 158 e->ignore();
159} 159}
160 160
161void DateBookWeekView::slotChangeClock( bool c ) 161void DateBookWeekView::slotChangeClock( bool c )
162{ 162{
163 ampm = c; 163 ampm = c;
164 viewport()->update(); 164 viewport()->update();
165} 165}
166 166
167static inline int db_round30min( int m ) 167static inline int db_round30min( int m )
168{ 168{
169 if ( m < 15 ) 169 if ( m < 15 )
170 m = 0; 170 m = 0;
171 else if ( m < 45 ) 171 else if ( m < 45 )
172 m = 1; 172 m = 1;
173 else 173 else
174 m = 2; 174 m = 2;
175 175
176 return m; 176 return m;
177} 177}
178 178
179void DateBookWeekView::alterDay( int day ) 179void DateBookWeekView::alterDay( int day )
180{ 180{
181 if ( !bOnMonday ) { 181 if ( !bOnMonday ) {
182 day--; 182 day--;
183 } 183 }
184 emit showDay( day ); 184 emit showDay( day );
185} 185}
186 186
187void DateBookWeekView::positionItem( DateBookWeekItem *i ) 187void DateBookWeekView::positionItem( DateBookWeekItem *i )
188{ 188{
189 const int Width = 8; 189 const int Width = 8;
190 const EffectiveEvent ev = i->event(); 190 const EffectiveEvent ev = i->event();
191 191
192 // 30 minute intervals 192 // 30 minute intervals
193 int y = ev.start().hour() * 2; 193 int y = ev.start().hour() * 2;
194 y += db_round30min( ev.start().minute() ); 194 y += db_round30min( ev.start().minute() );
195 int y2 = ev.end().hour() * 2; 195 int y2 = ev.end().hour() * 2;
196 y2 += db_round30min( ev.end().minute() ); 196 y2 += db_round30min( ev.end().minute() );
197 if ( y > 47 ) y = 47; 197 if ( y > 47 ) y = 47;
198 if ( y2 > 48 ) y2 = 48; 198 if ( y2 > 48 ) y2 = 48;
199 y = (y * rowHeight) / 2; 199 y = (y * rowHeight) / 2;
200 y2 = (y2 * rowHeight) / 2; 200 y2 = (y2 * rowHeight) / 2;
201 201
202 int h; 202 int h;
203 if ( ev.event().type() == Event::AllDay ) { 203 if ( ev.event().type() == Event::AllDay ) {
204 h = (48 * rowHeight) / 2; 204 h = (48 * rowHeight) / 2;
205 y = 0; 205 y = 0;
206 } else { 206 } else {
207 h=y2-y; 207 h=y2-y;
208 if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2; 208 if ( h < (1*rowHeight)/2 ) h = (1*rowHeight)/2;
209 } 209 }
210 210
211 int dow = ev.date().dayOfWeek(); 211 int dow = ev.date().dayOfWeek();
212 if ( !bOnMonday ) { 212 if ( !bOnMonday ) {
213 if ( dow == 7 ) 213 if ( dow == 7 )
214 dow = 1; 214 dow = 1;
215 else 215 else
216 dow++; 216 dow++;
217 } 217 }
218 int x = header->sectionPos( dow ) - 1; 218 int x = header->sectionPos( dow ) - 1;
219 int xlim = header->sectionPos( dow ) + header->sectionSize( dow ); 219 int xlim = header->sectionPos( dow ) + header->sectionSize( dow );
220 DateBookWeekItem *isect = 0; 220 DateBookWeekItem *isect = 0;
221 do { 221 do {
222 i->setGeometry( x, y, Width, h ); 222 i->setGeometry( x, y, Width, h );
223 isect = intersects( i ); 223 isect = intersects( i );
224 x += Width - 1; 224 x += Width - 1;
225 } while ( isect && x < xlim ); 225 } while ( isect && x < xlim );
226} 226}
227 227
228DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item ) 228DateBookWeekItem *DateBookWeekView::intersects( const DateBookWeekItem *item )
229{ 229{
230 QRect geom = item->geometry(); 230 QRect geom = item->geometry();
231 231
232 // We allow the edges to overlap 232 // We allow the edges to overlap
233 geom.moveBy( 1, 1 ); 233 geom.moveBy( 1, 1 );
234 geom.setSize( geom.size()-QSize(2,2) ); 234 geom.setSize( geom.size()-QSize(2,2) );
235 235
236 QListIterator<DateBookWeekItem> it(items); 236 QListIterator<DateBookWeekItem> it(items);
237 for ( ; it.current(); ++it ) { 237 for ( ; it.current(); ++it ) {
238 DateBookWeekItem *i = it.current(); 238 DateBookWeekItem *i = it.current();
239 if ( i != item ) { 239 if ( i != item ) {
240 if ( i->geometry().intersects( geom ) ) { 240 if ( i->geometry().intersects( geom ) ) {
241 return i; 241 return i;
242 } 242 }
243 } 243 }
244 } 244 }
245 245
246 return 0; 246 return 0;
247} 247}
248 248
249void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e ) 249void DateBookWeekView::contentsMousePressEvent( QMouseEvent *e )
250{ 250{
251 QListIterator<DateBookWeekItem> it(items); 251 QListIterator<DateBookWeekItem> it(items);
252 for ( ; it.current(); ++it ) { 252 for ( ; it.current(); ++it ) {
253 DateBookWeekItem *i = it.current(); 253 DateBookWeekItem *i = it.current();
254 if ( i->geometry().contains( e->pos() ) ) { 254 if ( i->geometry().contains( e->pos() ) ) {
255 showingEvent = true; 255 showingEvent = true;
256 emit signalShowEvent( i->event() ); 256 emit signalShowEvent( i->event() );
257 break; 257 break;