-rw-r--r-- | core/pim/datebook/datebookday.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index a6a1be3..42f026a 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp | |||
@@ -1,795 +1,797 @@ | |||
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 <qmessagebox.h> | 20 | #include <qmessagebox.h> |
21 | 21 | ||
22 | #include "datebookday.h" | 22 | #include "datebookday.h" |
23 | #include "datebookdayheaderimpl.h" | 23 | #include "datebookdayheaderimpl.h" |
24 | 24 | ||
25 | #include <qpe/datebookdb.h> | 25 | #include <qpe/datebookdb.h> |
26 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | #include <qpe/event.h> | 27 | #include <qpe/event.h> |
28 | #include <qpe/qpeapplication.h> | 28 | #include <qpe/qpeapplication.h> |
29 | #include <qpe/timestring.h> | 29 | #include <qpe/timestring.h> |
30 | #include <qpe/qpedebug.h> | 30 | #include <qpe/qpedebug.h> |
31 | #include <qpe/ir.h> | 31 | #include <qpe/ir.h> |
32 | 32 | ||
33 | #include <qheader.h> | 33 | #include <qheader.h> |
34 | #include <qdatetime.h> | 34 | #include <qdatetime.h> |
35 | #include <qpainter.h> | 35 | #include <qpainter.h> |
36 | #include <qsimplerichtext.h> | 36 | #include <qsimplerichtext.h> |
37 | #include <qpopupmenu.h> | 37 | #include <qpopupmenu.h> |
38 | #include <qtextcodec.h> | 38 | #include <qtextcodec.h> |
39 | #include <qpalette.h> | 39 | #include <qpalette.h> |
40 | 40 | ||
41 | #include <qtimer.h> | 41 | #include <qtimer.h> |
42 | 42 | ||
43 | DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, | 43 | DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, |
44 | const char *name ) | 44 | const char *name ) |
45 | : QTable( 24, 1, parent, name ), | 45 | : QTable( 24, 1, parent, name ), |
46 | ampm( whichClock ) | 46 | ampm( whichClock ) |
47 | { | 47 | { |
48 | enableClipper(TRUE); | 48 | enableClipper(TRUE); |
49 | setTopMargin( 0 ); | 49 | setTopMargin( 0 ); |
50 | horizontalHeader()->hide(); | 50 | horizontalHeader()->hide(); |
51 | setLeftMargin(38); | 51 | setLeftMargin(38); |
52 | setColumnStretchable( 0, TRUE ); | 52 | setColumnStretchable( 0, TRUE ); |
53 | setHScrollBarMode( QScrollView::AlwaysOff ); | 53 | setHScrollBarMode( QScrollView::AlwaysOff ); |
54 | verticalHeader()->setPalette(white); | 54 | verticalHeader()->setPalette(white); |
55 | verticalHeader()->setResizeEnabled(FALSE); | 55 | verticalHeader()->setResizeEnabled(FALSE); |
56 | setSelectionMode( Single ); | 56 | setSelectionMode( Single ); |
57 | 57 | ||
58 | // get rid of being able to edit things... | 58 | // get rid of being able to edit things... |
59 | QTableItem *tmp; | 59 | QTableItem *tmp; |
60 | int row; | 60 | int row; |
61 | for ( row = 0; row < numRows(); row++ ) { | 61 | for ( row = 0; row < numRows(); row++ ) { |
62 | tmp = new QTableItem( this, QTableItem::Never, QString::null); | 62 | tmp = new QTableItem( this, QTableItem::Never, QString::null); |
63 | setItem( row, 0, tmp ); | 63 | setItem( row, 0, tmp ); |
64 | //setRowHeight( row, 40); | 64 | //setRowHeight( row, 40); |
65 | } | 65 | } |
66 | initHeader(); | 66 | initHeader(); |
67 | QObject::connect( qApp, SIGNAL(clockChanged(bool)), | 67 | QObject::connect( qApp, SIGNAL(clockChanged(bool)), |
68 | this, SLOT(slotChangeClock(bool)) ); | 68 | this, SLOT(slotChangeClock(bool)) ); |
69 | } | 69 | } |
70 | 70 | ||
71 | void DateBookDayView::initHeader() | 71 | void DateBookDayView::initHeader() |
72 | { | 72 | { |
73 | QString strTmp; | 73 | QString strTmp; |
74 | for ( int i = 0; i < 24; ++i ) { | 74 | for ( int i = 0; i < 24; ++i ) { |
75 | if ( ampm ) { | 75 | if ( ampm ) { |
76 | if ( i == 0 ) | 76 | if ( i == 0 ) |
77 | strTmp = QString::number(12) + ":00"; | 77 | strTmp = QString::number(12) + ":00"; |
78 | else if ( i == 12 ) | 78 | else if ( i == 12 ) |
79 | strTmp = QString::number(12) + tr(":00p"); | 79 | strTmp = QString::number(12) + tr(":00p"); |
80 | else if ( i > 12 ) | 80 | else if ( i > 12 ) |
81 | strTmp = QString::number( i - 12 ) + tr(":00p"); | 81 | strTmp = QString::number( i - 12 ) + tr(":00p"); |
82 | else | 82 | else |
83 | strTmp = QString::number(i) + ":00"; | 83 | strTmp = QString::number(i) + ":00"; |
84 | } else { | 84 | } else { |
85 | if ( i < 10 ) | 85 | if ( i < 10 ) |
86 | strTmp = "0" + QString::number(i) + ":00"; | 86 | strTmp = "0" + QString::number(i) + ":00"; |
87 | else | 87 | else |
88 | strTmp = QString::number(i) + ":00"; | 88 | strTmp = QString::number(i) + ":00"; |
89 | } | 89 | } |
90 | strTmp = strTmp.rightJustify( 6, ' ' ); | 90 | strTmp = strTmp.rightJustify( 6, ' ' ); |
91 | verticalHeader()->setLabel( i, strTmp ); | 91 | verticalHeader()->setLabel( i, strTmp ); |
92 | setRowStretchable( i, FALSE ); | 92 | setRowStretchable( i, FALSE ); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | void DateBookDayView::slotChangeClock( bool newClock ) | 96 | void DateBookDayView::slotChangeClock( bool newClock ) |
97 | { | 97 | { |
98 | ampm = newClock; | 98 | ampm = newClock; |
99 | initHeader(); | 99 | initHeader(); |
100 | } | 100 | } |
101 | 101 | ||
102 | bool DateBookDayView::whichClock() const | 102 | bool DateBookDayView::whichClock() const |
103 | { | 103 | { |
104 | return ampm; | 104 | return ampm; |
105 | } | 105 | } |
106 | 106 | ||
107 | void DateBookDayView::moveUp() | 107 | void DateBookDayView::moveUp() |
108 | { | 108 | { |
109 | scrollBy(0, -20); | 109 | scrollBy(0, -20); |
110 | } | 110 | } |
111 | 111 | ||
112 | void DateBookDayView::moveDown() | 112 | void DateBookDayView::moveDown() |
113 | { | 113 | { |
114 | scrollBy(0, 20); | 114 | scrollBy(0, 20); |
115 | } | 115 | } |
116 | 116 | ||
117 | void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) | 117 | void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) |
118 | { | 118 | { |
119 | int w = cr.width(); | 119 | int w = cr.width(); |
120 | int h = cr.height(); | 120 | int h = cr.height(); |
121 | p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); | 121 | p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); |
122 | if ( showGrid() ) { | 122 | if ( showGrid() ) { |
123 | // Draw our lines | 123 | // Draw our lines |
124 | int x2 = w - 1; | 124 | int x2 = w - 1; |
125 | int y2 = h - 1; | 125 | int y2 = h - 1; |
126 | QPen pen( p->pen() ); | 126 | QPen pen( p->pen() ); |
127 | p->setPen( colorGroup().dark() ); | 127 | p->setPen( colorGroup().dark() ); |
128 | p->drawLine( x2, 0, x2, y2 ); | 128 | p->drawLine( x2, 0, x2, y2 ); |
129 | p->drawLine( 0, y2, x2, y2 ); | 129 | p->drawLine( 0, y2, x2, y2 ); |
130 | 130 | ||
131 | p->setPen( colorGroup().midlight() ); | 131 | p->setPen( colorGroup().midlight() ); |
132 | p->drawLine( 0, y2 - h/2, x2, y2 - h/2); | 132 | p->drawLine( 0, y2 - h/2, x2, y2 - h/2); |
133 | 133 | ||
134 | p->setPen( pen ); | 134 | p->setPen( pen ); |
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | void DateBookDayView::paintFocus( QPainter *, const QRect & ) | 138 | void DateBookDayView::paintFocus( QPainter *, const QRect & ) |
139 | { | 139 | { |
140 | } | 140 | } |
141 | 141 | ||
142 | 142 | ||
143 | void DateBookDayView::resizeEvent( QResizeEvent *e ) | 143 | void DateBookDayView::resizeEvent( QResizeEvent *e ) |
144 | { | 144 | { |
145 | QTable::resizeEvent( e ); | 145 | QTable::resizeEvent( e ); |
146 | columnWidthChanged( 0 ); | 146 | columnWidthChanged( 0 ); |
147 | emit sigColWidthChanged(); | 147 | emit sigColWidthChanged(); |
148 | } | 148 | } |
149 | 149 | ||
150 | void DateBookDayView::keyPressEvent( QKeyEvent *e ) | 150 | void DateBookDayView::keyPressEvent( QKeyEvent *e ) |
151 | { | 151 | { |
152 | QString txt = e->text(); | 152 | QString txt = e->text(); |
153 | if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { | 153 | if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { |
154 | // we this is some sort of thing we know about... | 154 | // we this is some sort of thing we know about... |
155 | e->accept(); | 155 | e->accept(); |
156 | emit sigCapturedKey( txt ); | 156 | emit sigCapturedKey( txt ); |
157 | } else { | 157 | } else { |
158 | // I don't know what this key is, do you? | 158 | // I don't know what this key is, do you? |
159 | e->ignore(); | 159 | e->ignore(); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | 162 | ||
163 | void DateBookDayView::setRowStyle( int style ) | 163 | void DateBookDayView::setRowStyle( int style ) |
164 | { | 164 | { |
165 | if (style<0) style = 0; | 165 | if (style<0) style = 0; |
166 | 166 | ||
167 | for (int i=0; i<numRows(); i++) | 167 | for (int i=0; i<numRows(); i++) |
168 | setRowHeight(i, style*10+20); | 168 | setRowHeight(i, style*10+20); |
169 | } | 169 | } |
170 | 170 | ||
171 | //=========================================================================== | 171 | //=========================================================================== |
172 | 172 | ||
173 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, | 173 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, |
174 | DateBookDB *newDb, QWidget *parent, | 174 | DateBookDB *newDb, QWidget *parent, |
175 | const char *name ) | 175 | const char *name ) |
176 | : QVBox( parent, name ), | 176 | : QVBox( parent, name ), |
177 | currDate( QDate::currentDate() ), | 177 | currDate( QDate::currentDate() ), |
178 | db( newDb ), | 178 | db( newDb ), |
179 | startTime( 0 ) | 179 | startTime( 0 ) |
180 | { | 180 | { |
181 | widgetList.setAutoDelete( true ); | 181 | widgetList.setAutoDelete( true ); |
182 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); | 182 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); |
183 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); | 183 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); |
184 | view = new DateBookDayView( ampm, this, "day view" ); | 184 | view = new DateBookDayView( ampm, this, "day view" ); |
185 | 185 | ||
186 | connect( header, SIGNAL( dateChanged( int, int, int ) ), | 186 | connect( header, SIGNAL( dateChanged( int, int, int ) ), |
187 | this, SLOT( dateChanged( int, int, int ) ) ); | 187 | this, SLOT( dateChanged( int, int, int ) ) ); |
188 | connect( view, SIGNAL( sigColWidthChanged() ), | 188 | connect( view, SIGNAL( sigColWidthChanged() ), |
189 | this, SLOT( slotColWidthChanged() ) ); | 189 | this, SLOT( slotColWidthChanged() ) ); |
190 | connect( qApp, SIGNAL(weekChanged(bool)), | 190 | connect( qApp, SIGNAL(weekChanged(bool)), |
191 | this, SLOT(slotWeekChanged(bool)) ); | 191 | this, SLOT(slotWeekChanged(bool)) ); |
192 | connect( view, SIGNAL(sigCapturedKey(const QString &)), | 192 | connect( view, SIGNAL(sigCapturedKey(const QString &)), |
193 | this, SIGNAL(sigNewEvent(const QString&)) ); | 193 | this, SIGNAL(sigNewEvent(const QString&)) ); |
194 | 194 | ||
195 | QTimer *timer = new QTimer( this ); | 195 | QTimer *timer = new QTimer( this ); |
196 | 196 | ||
197 | connect( timer, SIGNAL(timeout()), | 197 | connect( timer, SIGNAL(timeout()), |
198 | this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors | 198 | this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors |
199 | timer->start( 1000*60*5, FALSE ); //update every 5min | 199 | timer->start( 1000*60*5, FALSE ); //update every 5min |
200 | 200 | ||
201 | selectedWidget = 0; | 201 | selectedWidget = 0; |
202 | 202 | ||
203 | timeMarker = new DateBookDayTimeMarker( this ); | 203 | timeMarker = new DateBookDayTimeMarker( this ); |
204 | timeMarker->setTime( QTime::currentTime() ); | 204 | timeMarker->setTime( QTime::currentTime() ); |
205 | rowStyle = -1; // initialize with bogus values | 205 | rowStyle = -1; // initialize with bogus values |
206 | } | 206 | } |
207 | 207 | ||
208 | void DateBookDay::setJumpToCurTime( bool bJump ) | 208 | void DateBookDay::setJumpToCurTime( bool bJump ) |
209 | { | 209 | { |
210 | jumpToCurTime = bJump; | 210 | jumpToCurTime = bJump; |
211 | } | 211 | } |
212 | 212 | ||
213 | void DateBookDay::setRowStyle( int style ) | 213 | void DateBookDay::setRowStyle( int style ) |
214 | { | 214 | { |
215 | if (rowStyle != style) view->setRowStyle( style ); | 215 | if (rowStyle != style) view->setRowStyle( style ); |
216 | rowStyle = style; | 216 | rowStyle = style; |
217 | } | 217 | } |
218 | 218 | ||
219 | void DateBookDay::updateView( void ) | 219 | void DateBookDay::updateView( void ) |
220 | { | 220 | { |
221 | timeMarker->setTime( QTime::currentTime() ); | 221 | timeMarker->setTime( QTime::currentTime() ); |
222 | //need to find a way to update all DateBookDayWidgets | 222 | //need to find a way to update all DateBookDayWidgets |
223 | } | 223 | } |
224 | 224 | ||
225 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) | 225 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) |
226 | { | 226 | { |
227 | selectedWidget = w; | 227 | selectedWidget = w; |
228 | } | 228 | } |
229 | 229 | ||
230 | DateBookDayWidget * DateBookDay::getSelectedWidget( void ) | 230 | DateBookDayWidget * DateBookDay::getSelectedWidget( void ) |
231 | { | 231 | { |
232 | return selectedWidget; | 232 | return selectedWidget; |
233 | } | 233 | } |
234 | 234 | ||
235 | void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) | 235 | void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) |
236 | { | 236 | { |
237 | start.setDate( currDate ); | 237 | start.setDate( currDate ); |
238 | end.setDate( currDate ); | 238 | end.setDate( currDate ); |
239 | 239 | ||
240 | int sh=99,eh=-1; | 240 | int sh=99,eh=-1; |
241 | 241 | ||
242 | int n = dayView()->numSelections(); | 242 | int n = dayView()->numSelections(); |
243 | 243 | ||
244 | for (int i=0; i<n; i++) { | 244 | for (int i=0; i<n; i++) { |
245 | QTableSelection sel = dayView()->selection( i ); | 245 | QTableSelection sel = dayView()->selection( i ); |
246 | sh = QMIN(sh,sel.topRow()); | 246 | sh = QMIN(sh,sel.topRow()); |
247 | eh = QMAX(sh,sel.bottomRow()+1); | 247 | eh = QMAX(sh,sel.bottomRow()+1); |
248 | } | 248 | } |
249 | if (sh > 23 || eh < 1) { | 249 | if (sh > 23 || eh < 1) { |
250 | sh=8; | 250 | sh=8; |
251 | eh=9; | 251 | eh=9; |
252 | } | 252 | } |
253 | 253 | ||
254 | start.setTime( QTime( sh, 0, 0 ) ); | 254 | start.setTime( QTime( sh, 0, 0 ) ); |
255 | end.setTime( QTime( eh, 0, 0 ) ); | 255 | end.setTime( QTime( eh, 0, 0 ) ); |
256 | } | 256 | } |
257 | 257 | ||
258 | void DateBookDay::setDate( int y, int m, int d ) | 258 | void DateBookDay::setDate( int y, int m, int d ) |
259 | { | 259 | { |
260 | header->setDate( y, m, d ); | 260 | header->setDate( y, m, d ); |
261 | 261 | ||
262 | selectedWidget = 0; | 262 | selectedWidget = 0; |
263 | } | 263 | } |
264 | 264 | ||
265 | void DateBookDay::setDate( QDate d) | 265 | void DateBookDay::setDate( QDate d) |
266 | { | 266 | { |
267 | header->setDate( d.year(), d.month(), d.day() ); | 267 | header->setDate( d.year(), d.month(), d.day() ); |
268 | 268 | ||
269 | selectedWidget = 0; | 269 | selectedWidget = 0; |
270 | } | 270 | } |
271 | 271 | ||
272 | void DateBookDay::dateChanged( int y, int m, int d ) | 272 | void DateBookDay::dateChanged( int y, int m, int d ) |
273 | { | 273 | { |
274 | QDate date( y, m, d ); | 274 | QDate date( y, m, d ); |
275 | if ( currDate == date ) | 275 | if ( currDate == date ) |
276 | return; | 276 | return; |
277 | currDate.setYMD( y, m, d ); | 277 | currDate.setYMD( y, m, d ); |
278 | relayoutPage(); | 278 | relayoutPage(); |
279 | dayView()->clearSelection(); | 279 | dayView()->clearSelection(); |
280 | QTableSelection ts; | 280 | QTableSelection ts; |
281 | 281 | ||
282 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 282 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
283 | { | 283 | { |
284 | ts.init( QTime::currentTime().hour(), 0); | 284 | ts.init( QTime::currentTime().hour(), 0); |
285 | ts.expandTo( QTime::currentTime().hour(), 0); | 285 | ts.expandTo( QTime::currentTime().hour(), 0); |
286 | } else | 286 | } else |
287 | { | 287 | { |
288 | ts.init( startTime, 0 ); | 288 | ts.init( startTime, 0 ); |
289 | ts.expandTo( startTime, 0 ); | 289 | ts.expandTo( startTime, 0 ); |
290 | } | 290 | } |
291 | 291 | ||
292 | dayView()->addSelection( ts ); | 292 | dayView()->addSelection( ts ); |
293 | 293 | ||
294 | selectedWidget = 0; | 294 | selectedWidget = 0; |
295 | 295 | ||
296 | } | 296 | } |
297 | 297 | ||
298 | void DateBookDay::redraw() | 298 | void DateBookDay::redraw() |
299 | { | 299 | { |
300 | if ( isUpdatesEnabled() ) | 300 | if ( isUpdatesEnabled() ) |
301 | relayoutPage(); | 301 | relayoutPage(); |
302 | } | 302 | } |
303 | 303 | ||
304 | void DateBookDay::getEvents() | 304 | void DateBookDay::getEvents() |
305 | { | 305 | { |
306 | widgetList.clear(); | 306 | widgetList.clear(); |
307 | 307 | ||
308 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, | 308 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); |
309 | currDate ); | 309 | QValueListIterator<EffectiveEvent> it; |
310 | QValueListIterator<EffectiveEvent> it; | 310 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { |
311 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { | 311 | EffectiveEvent ev=*it; |
312 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); | 312 | if(!(ev.end().hour()==ev.start().hour() && ev.end().minute()==ev.start().minute())) {// Skip effective events with no duration. (i.e ending at 00:00) |
313 | connect( w, SIGNAL( deleteMe( const Event & ) ), | 313 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); |
314 | this, SIGNAL( removeEvent( const Event & ) ) ); | 314 | connect( w, SIGNAL( deleteMe( const Event & ) ), |
315 | connect( w, SIGNAL( editMe( const Event & ) ), | 315 | this, SIGNAL( removeEvent( const Event & ) ) ); |
316 | this, SIGNAL( editEvent( const Event & ) ) ); | 316 | connect( w, SIGNAL( editMe( const Event & ) ), |
317 | connect( w, SIGNAL( beamMe( const Event & ) ), | 317 | this, SIGNAL( editEvent( const Event & ) ) ); |
318 | this, SIGNAL( beamEvent( const Event & ) ) ); | 318 | connect( w, SIGNAL( beamMe( const Event & ) ), |
319 | widgetList.append( w ); | 319 | this, SIGNAL( beamEvent( const Event & ) ) ); |
320 | widgetList.append( w ); | ||
321 | } | ||
320 | } | 322 | } |
321 | 323 | ||
322 | } | 324 | } |
323 | 325 | ||
324 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) | 326 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) |
325 | { | 327 | { |
326 | int place = 0; | 328 | int place = 0; |
327 | int start = item->event().start().hour(); | 329 | int start = item->event().start().hour(); |
328 | QTime e = item->event().end(); | 330 | QTime e = item->event().end(); |
329 | int end = e.hour(); | 331 | int end = e.hour(); |
330 | if ( e.minute() < 5 ) | 332 | if ( e.minute() < 5 ) |
331 | end--; | 333 | end--; |
332 | if ( end < start ) | 334 | if ( end < start ) |
333 | end = start; | 335 | end = start; |
334 | while ( place < maxn ) { | 336 | while ( place < maxn ) { |
335 | bool free = TRUE; | 337 | bool free = TRUE; |
336 | int s = start; | 338 | int s = start; |
337 | while( s <= end ) { | 339 | while( s <= end ) { |
338 | if ( used[10*s+place] ) { | 340 | if ( used[10*s+place] ) { |
339 | free = FALSE; | 341 | free = FALSE; |
340 | break; | 342 | break; |
341 | } | 343 | } |
342 | s++; | 344 | s++; |
343 | } | 345 | } |
344 | if ( free ) break; | 346 | if ( free ) break; |
345 | place++; | 347 | place++; |
346 | } | 348 | } |
347 | if ( place == maxn ) { | 349 | if ( place == maxn ) { |
348 | return -1; | 350 | return -1; |
349 | } | 351 | } |
350 | while( start <= end ) { | 352 | while( start <= end ) { |
351 | used[10*start+place] = TRUE; | 353 | used[10*start+place] = TRUE; |
352 | start++; | 354 | start++; |
353 | } | 355 | } |
354 | return place; | 356 | return place; |
355 | } | 357 | } |
356 | 358 | ||
357 | 359 | ||
358 | void DateBookDay::relayoutPage( bool fromResize ) | 360 | void DateBookDay::relayoutPage( bool fromResize ) |
359 | { | 361 | { |
360 | setUpdatesEnabled( FALSE ); | 362 | setUpdatesEnabled( FALSE ); |
361 | if ( !fromResize ) | 363 | if ( !fromResize ) |
362 | getEvents(); // no need we already have them! | 364 | getEvents(); // no need we already have them! |
363 | 365 | ||
364 | widgetList.sort(); | 366 | widgetList.sort(); |
365 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning | 367 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning |
366 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view | 368 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view |
367 | 369 | ||
368 | int wCount = widgetList.count(); | 370 | int wCount = widgetList.count(); |
369 | int wid = view->columnWidth(0)-1; | 371 | int wid = view->columnWidth(0)-1; |
370 | int wd; | 372 | int wd; |
371 | int n = 1; | 373 | int n = 1; |
372 | 374 | ||
373 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget | 375 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget |
374 | 376 | ||
375 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); | 377 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); |
376 | 378 | ||
377 | if ( wCount < 20 ) { | 379 | if ( wCount < 20 ) { |
378 | 380 | ||
379 | QArray<QRect> geometries(wCount); | 381 | QArray<QRect> geometries(wCount); |
380 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector | 382 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector |
381 | 383 | ||
382 | for ( int i = 0; i < wCount; i++) | 384 | for ( int i = 0; i < wCount; i++) |
383 | { | 385 | { |
384 | QValueList<int> intersectedWidgets; | 386 | QValueList<int> intersectedWidgets; |
385 | 387 | ||
386 | //find all widgets intersecting with widgetList.at(i) | 388 | //find all widgets intersecting with widgetList.at(i) |
387 | for ( int j = 0; j < wCount; j++) | 389 | for ( int j = 0; j < wCount; j++) |
388 | if (i != j) | 390 | if (i != j) |
389 | if (geometries[j].intersects(geometries[i])) | 391 | if (geometries[j].intersects(geometries[i])) |
390 | intersectedWidgets.append(j); | 392 | intersectedWidgets.append(j); |
391 | 393 | ||
392 | //for each of these intersecting widgets find out how many widgets are they intersecting with | 394 | //for each of these intersecting widgets find out how many widgets are they intersecting with |
393 | for ( uint j = 0; j < intersectedWidgets.count(); j++) | 395 | for ( uint j = 0; j < intersectedWidgets.count(); j++) |
394 | { | 396 | { |
395 | QArray<int> inter(wCount); | 397 | QArray<int> inter(wCount); |
396 | inter[j]=1; | 398 | inter[j]=1; |
397 | 399 | ||
398 | if (intersectedWidgets[j] != -1) | 400 | if (intersectedWidgets[j] != -1) |
399 | for ( uint k = j; k < intersectedWidgets.count(); k++) | 401 | for ( uint k = j; k < intersectedWidgets.count(); k++) |
400 | if (j != k && intersectedWidgets[k] != -1) | 402 | if (j != k && intersectedWidgets[k] != -1) |
401 | if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) | 403 | if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) |
402 | { | 404 | { |
403 | inter[j]++; | 405 | inter[j]++; |
404 | intersectedWidgets[k] = -1; | 406 | intersectedWidgets[k] = -1; |
405 | } | 407 | } |
406 | if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; | 408 | if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; |
407 | } | 409 | } |
408 | 410 | ||
409 | if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; | 411 | if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; |
410 | } | 412 | } |
411 | 413 | ||
412 | 414 | ||
413 | for ( int i = 0; i < wCount; i++) { | 415 | for ( int i = 0; i < wCount; i++) { |
414 | DateBookDayWidget *w = widgetList.at(i); | 416 | DateBookDayWidget *w = widgetList.at(i); |
415 | QRect geom = w->geometry(); | 417 | QRect geom = w->geometry(); |
416 | 418 | ||
417 | geom.setX( 0 ); | 419 | geom.setX( 0 ); |
418 | 420 | ||
419 | wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); | 421 | wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); |
420 | 422 | ||
421 | geom.setWidth( wd ); | 423 | geom.setWidth( wd ); |
422 | 424 | ||
423 | while ( intersects( w, geom ) ) { | 425 | while ( intersects( w, geom ) ) { |
424 | geom.moveBy( wd + 2 + 1, 0 ); | 426 | geom.moveBy( wd + 2 + 1, 0 ); |
425 | } | 427 | } |
426 | w->setGeometry( geom ); | 428 | w->setGeometry( geom ); |
427 | } | 429 | } |
428 | 430 | ||
429 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 431 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
430 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour | 432 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour |
431 | else | 433 | else |
432 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); | 434 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); |
433 | 435 | ||
434 | 436 | ||
435 | } else { | 437 | } else { |
436 | 438 | ||
437 | 439 | ||
438 | int hours[24]; | 440 | int hours[24]; |
439 | memset( hours, 0, 24*sizeof( int ) ); | 441 | memset( hours, 0, 24*sizeof( int ) ); |
440 | bool overFlow = FALSE; | 442 | bool overFlow = FALSE; |
441 | for ( int i = 0; i < wCount; i++ ) { | 443 | for ( int i = 0; i < wCount; i++ ) { |
442 | DateBookDayWidget *w = widgetList.at(i); | 444 | DateBookDayWidget *w = widgetList.at(i); |
443 | int start = w->event().start().hour(); | 445 | int start = w->event().start().hour(); |
444 | QTime e = w->event().end(); | 446 | QTime e = w->event().end(); |
445 | int end = e.hour(); | 447 | int end = e.hour(); |
446 | if ( e.minute() < 5 ) | 448 | if ( e.minute() < 5 ) |
447 | end--; | 449 | end--; |
448 | if ( end < start ) | 450 | if ( end < start ) |
449 | end = start; | 451 | end = start; |
450 | while( start <= end ) { | 452 | while( start <= end ) { |
451 | hours[start]++; | 453 | hours[start]++; |
452 | if ( hours[start] >= 10 ) | 454 | if ( hours[start] >= 10 ) |
453 | overFlow = TRUE; | 455 | overFlow = TRUE; |
454 | ++start; | 456 | ++start; |
455 | } | 457 | } |
456 | if ( overFlow ) | 458 | if ( overFlow ) |
457 | break; | 459 | break; |
458 | } | 460 | } |
459 | for ( int i = 0; i < 24; i++ ) { | 461 | for ( int i = 0; i < 24; i++ ) { |
460 | n = QMAX( n, hours[i] ); | 462 | n = QMAX( n, hours[i] ); |
461 | } | 463 | } |
462 | wid = ( view->columnWidth(0)-1 ) / n; | 464 | wid = ( view->columnWidth(0)-1 ) / n; |
463 | 465 | ||
464 | bool used[24*10]; | 466 | bool used[24*10]; |
465 | memset( used, FALSE, 24*10*sizeof( bool ) ); | 467 | memset( used, FALSE, 24*10*sizeof( bool ) ); |
466 | 468 | ||
467 | for ( int i = 0; i < wCount; i++ ) { | 469 | for ( int i = 0; i < wCount; i++ ) { |
468 | DateBookDayWidget *w = widgetList.at(i); | 470 | DateBookDayWidget *w = widgetList.at(i); |
469 | int xp = place( w, used, n ); | 471 | int xp = place( w, used, n ); |
470 | if ( xp != -1 ) { | 472 | if ( xp != -1 ) { |
471 | QRect geom = w->geometry(); | 473 | QRect geom = w->geometry(); |
472 | geom.setX( xp*(wid+2) ); | 474 | geom.setX( xp*(wid+2) ); |
473 | geom.setWidth( wid ); | 475 | geom.setWidth( wid ); |
474 | w->setGeometry( geom ); | 476 | w->setGeometry( geom ); |
475 | } | 477 | } |
476 | } | 478 | } |
477 | 479 | ||
478 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 480 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
479 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour | 481 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour |
480 | else | 482 | else |
481 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); | 483 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); |
482 | } | 484 | } |
483 | 485 | ||
484 | timeMarker->setTime( QTime::currentTime() );//display timeMarker | 486 | timeMarker->setTime( QTime::currentTime() );//display timeMarker |
485 | timeMarker->raise(); //on top of all widgets | 487 | timeMarker->raise(); //on top of all widgets |
486 | if (this->date() == QDate::currentDate()) //only show timeMarker on current day | 488 | if (this->date() == QDate::currentDate()) //only show timeMarker on current day |
487 | timeMarker->show(); else timeMarker->hide(); | 489 | timeMarker->show(); else timeMarker->hide(); |
488 | 490 | ||
489 | setUpdatesEnabled( TRUE ); | 491 | setUpdatesEnabled( TRUE ); |
490 | return; | 492 | return; |
491 | } | 493 | } |
492 | 494 | ||
493 | DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) | 495 | DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) |
494 | { | 496 | { |
495 | int i = 0; | 497 | int i = 0; |
496 | DateBookDayWidget *w = widgetList.at(i); | 498 | DateBookDayWidget *w = widgetList.at(i); |
497 | int wCount = widgetList.count(); | 499 | int wCount = widgetList.count(); |
498 | while ( i < wCount && w != item ) { | 500 | while ( i < wCount && w != item ) { |
499 | if ( w->geometry().intersects( geom ) ) { | 501 | if ( w->geometry().intersects( geom ) ) { |
500 | return w; | 502 | return w; |
501 | } | 503 | } |
502 | w = widgetList.at(++i); | 504 | w = widgetList.at(++i); |
503 | } | 505 | } |
504 | 506 | ||
505 | return 0; | 507 | return 0; |
506 | } | 508 | } |
507 | 509 | ||
508 | 510 | ||
509 | QDate DateBookDay::date() const | 511 | QDate DateBookDay::date() const |
510 | { | 512 | { |
511 | return currDate; | 513 | return currDate; |
512 | } | 514 | } |
513 | 515 | ||
514 | void DateBookDay::setStartViewTime( int startHere ) | 516 | void DateBookDay::setStartViewTime( int startHere ) |
515 | { | 517 | { |
516 | startTime = startHere; | 518 | startTime = startHere; |
517 | dayView()->clearSelection(); | 519 | dayView()->clearSelection(); |
518 | QTableSelection ts; | 520 | QTableSelection ts; |
519 | 521 | ||
520 | if (jumpToCurTime && this->date() == QDate::currentDate())//this should probably be in datebook.cpp where it's called? | 522 | if (jumpToCurTime && this->date() == QDate::currentDate())//this should probably be in datebook.cpp where it's called? |
521 | { | 523 | { |
522 | ts.init( QTime::currentTime().hour(), 0); | 524 | ts.init( QTime::currentTime().hour(), 0); |
523 | ts.expandTo( QTime::currentTime().hour(), 0); | 525 | ts.expandTo( QTime::currentTime().hour(), 0); |
524 | } else | 526 | } else |
525 | { | 527 | { |
526 | ts.init( startTime, 0 ); | 528 | ts.init( startTime, 0 ); |
527 | ts.expandTo( startTime, 0 ); | 529 | ts.expandTo( startTime, 0 ); |
528 | } | 530 | } |
529 | 531 | ||
530 | dayView()->addSelection( ts ); | 532 | dayView()->addSelection( ts ); |
531 | } | 533 | } |
532 | 534 | ||
533 | int DateBookDay::startViewTime() const | 535 | int DateBookDay::startViewTime() const |
534 | { | 536 | { |
535 | return startTime; | 537 | return startTime; |
536 | } | 538 | } |
537 | 539 | ||
538 | void DateBookDay::slotWeekChanged( bool bStartOnMonday ) | 540 | void DateBookDay::slotWeekChanged( bool bStartOnMonday ) |
539 | { | 541 | { |
540 | header->setStartOfWeek( bStartOnMonday ); | 542 | header->setStartOfWeek( bStartOnMonday ); |
541 | // redraw(); | 543 | // redraw(); |
542 | } | 544 | } |
543 | 545 | ||
544 | void DateBookDay::keyPressEvent(QKeyEvent *e) | 546 | void DateBookDay::keyPressEvent(QKeyEvent *e) |
545 | { | 547 | { |
546 | switch(e->key()) { | 548 | switch(e->key()) { |
547 | case Key_Up: | 549 | case Key_Up: |
548 | view->moveUp(); | 550 | view->moveUp(); |
549 | break; | 551 | break; |
550 | case Key_Down: | 552 | case Key_Down: |
551 | view->moveDown(); | 553 | view->moveDown(); |
552 | break; | 554 | break; |
553 | case Key_Left: | 555 | case Key_Left: |
554 | setDate(QDate(currDate).addDays(-1)); | 556 | setDate(QDate(currDate).addDays(-1)); |
555 | break; | 557 | break; |
556 | case Key_Right: | 558 | case Key_Right: |
557 | setDate(QDate(currDate).addDays(1)); | 559 | setDate(QDate(currDate).addDays(1)); |
558 | break; | 560 | break; |
559 | default: | 561 | default: |
560 | e->ignore(); | 562 | e->ignore(); |
561 | } | 563 | } |
562 | } | 564 | } |
563 | 565 | ||
564 | //=========================================================================== | 566 | //=========================================================================== |
565 | 567 | ||
566 | DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, | 568 | DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, |
567 | DateBookDay *db ) | 569 | DateBookDay *db ) |
568 | : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) | 570 | : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) |
569 | { | 571 | { |
570 | 572 | ||
571 | 573 | ||
572 | // why would someone use "<"? Oh well, fix it up... | 574 | // why would someone use "<"? Oh well, fix it up... |
573 | // I wonder what other things may be messed up... | 575 | // I wonder what other things may be messed up... |
574 | QString strDesc = ev.description(); | 576 | QString strDesc = ev.description(); |
575 | int where = strDesc.find( "<" ); | 577 | int where = strDesc.find( "<" ); |
576 | while ( where != -1 ) { | 578 | while ( where != -1 ) { |
577 | strDesc.remove( where, 1 ); | 579 | strDesc.remove( where, 1 ); |
578 | strDesc.insert( where, "<" ); | 580 | strDesc.insert( where, "<" ); |
579 | where = strDesc.find( "<", where ); | 581 | where = strDesc.find( "<", where ); |
580 | } | 582 | } |
581 | 583 | ||
582 | QString strCat; | 584 | QString strCat; |
583 | // ### Fix later... | 585 | // ### Fix later... |
584 | // QString strCat = ev.category(); | 586 | // QString strCat = ev.category(); |
585 | // where = strCat.find( "<" ); | 587 | // where = strCat.find( "<" ); |
586 | // while ( where != -1 ) { | 588 | // while ( where != -1 ) { |
587 | // strCat.remove( where, 1 ); | 589 | // strCat.remove( where, 1 ); |
588 | // strCat.insert( where, "<" ); | 590 | // strCat.insert( where, "<" ); |
589 | // where = strCat.find( "<", where ); | 591 | // where = strCat.find( "<", where ); |
590 | // } | 592 | // } |
591 | 593 | ||
592 | QString strNote = ev.notes(); | 594 | QString strNote = ev.notes(); |
593 | where = strNote.find( "<" ); | 595 | where = strNote.find( "<" ); |
594 | while ( where != -1 ) { | 596 | while ( where != -1 ) { |
595 | strNote.remove( where, 1 ); | 597 | strNote.remove( where, 1 ); |
596 | strNote.insert( where, "<" ); | 598 | strNote.insert( where, "<" ); |
597 | where = strNote.find( "<", where ); | 599 | where = strNote.find( "<", where ); |
598 | } | 600 | } |
599 | 601 | ||
600 | text = "<b>" + strDesc + "</b><br>" + "<i>"; | 602 | text = "<b>" + strDesc + "</b><br>" + "<i>"; |
601 | if ( !strCat.isEmpty() ) { | 603 | if ( !strCat.isEmpty() ) { |
602 | text += strCat + "</i><br>"; | 604 | text += strCat + "</i><br>"; |
603 | } | 605 | } |
604 | if (ev.event().type() == Event::Normal ) | 606 | if (ev.event().type() == Event::Normal ) |
605 | setEventText( text ); | 607 | setEventText( text ); |
606 | else | 608 | else |
607 | setAllDayText( text ); | 609 | setAllDayText( text ); |
608 | 610 | ||
609 | text += "<br><br>" + strNote; | 611 | text += "<br><br>" + strNote; |
610 | 612 | ||
611 | setBackgroundMode( PaletteBase ); | 613 | setBackgroundMode( PaletteBase ); |
612 | 614 | ||
613 | QTime start = ev.start(); | 615 | QTime start = ev.start(); |
614 | QTime end = ev.end(); | 616 | QTime end = ev.end(); |
615 | int y = start.hour()*60+start.minute(); | 617 | int y = start.hour()*60+start.minute(); |
616 | int h = end.hour()*60+end.minute()-y; | 618 | int h = end.hour()*60+end.minute()-y; |
617 | int rh = dateBook->dayView()->rowHeight(0); | 619 | int rh = dateBook->dayView()->rowHeight(0); |
618 | y = y*rh/60; | 620 | y = y*rh/60; |
619 | h = h*rh/60; | 621 | h = h*rh/60; |
620 | if ( h < 3 ) { | 622 | if ( h < 3 ) { |
621 | h = 3; | 623 | h = 3; |
622 | } | 624 | } |
623 | geom.setY( y ); | 625 | geom.setY( y ); |
624 | geom.setHeight( h ); | 626 | geom.setHeight( h ); |
625 | geom.setX( 0 ); | 627 | geom.setX( 0 ); |
626 | geom.setWidth(dateBook->dayView()->columnWidth(0)-1); | 628 | geom.setWidth(dateBook->dayView()->columnWidth(0)-1); |
627 | 629 | ||
628 | } | 630 | } |
629 | void DateBookDayWidget::setAllDayText( QString &text ) { | 631 | void DateBookDayWidget::setAllDayText( QString &text ) { |
630 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; | 632 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; |
631 | } | 633 | } |
632 | void DateBookDayWidget::setEventText( QString& text ) { | 634 | void DateBookDayWidget::setEventText( QString& text ) { |
633 | bool whichClock = dateBook->dayView()->whichClock(); | 635 | bool whichClock = dateBook->dayView()->whichClock(); |
634 | if ( ev.startDate() != ev.endDate() ) { | 636 | if ( ev.startDate() != ev.endDate() ) { |
635 | text += "<b>" + tr("Start") + "</b>: "; | 637 | text += "<b>" + tr("Start") + "</b>: "; |
636 | text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE ); | 638 | text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE ); |
637 | text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>"; | 639 | text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>"; |
638 | text += "<b>" + tr("End") + "</b>: "; | 640 | text += "<b>" + tr("End") + "</b>: "; |
639 | text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE ); | 641 | text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE ); |
640 | text += " - " + TimeString::longDateString( ev.endDate() ) + "<br>"; | 642 | text += " - " + TimeString::longDateString( ev.endDate() ) + "<br>"; |
641 | } else { | 643 | } else { |
642 | text += "<b>" + tr("Time") + "</b>: "; | 644 | text += "<b>" + tr("Time") + "</b>: "; |
643 | text += TimeString::timeString( ev.start(), whichClock, FALSE ); | 645 | text += TimeString::timeString( ev.start(), whichClock, FALSE ); |
644 | text += "<b>" + tr(" - ") + "</b>"; | 646 | text += "<b>" + tr(" - ") + "</b>"; |
645 | text += TimeString::timeString( ev.end(), whichClock, FALSE ); | 647 | text += TimeString::timeString( ev.end(), whichClock, FALSE ); |
646 | } | 648 | } |
647 | } | 649 | } |
648 | 650 | ||
649 | DateBookDayWidget::~DateBookDayWidget() | 651 | DateBookDayWidget::~DateBookDayWidget() |
650 | { | 652 | { |
651 | } | 653 | } |
652 | 654 | ||
653 | void DateBookDayWidget::paintEvent( QPaintEvent *e ) | 655 | void DateBookDayWidget::paintEvent( QPaintEvent *e ) |
654 | { | 656 | { |
655 | QPainter p( this ); | 657 | QPainter p( this ); |
656 | 658 | ||
657 | if (dateBook->getSelectedWidget() == this) | 659 | if (dateBook->getSelectedWidget() == this) |
658 | { | 660 | { |
659 | p.setBrush( QColor( 155, 240, 230 ) ); // selected item | 661 | p.setBrush( QColor( 155, 240, 230 ) ); // selected item |
660 | } else | 662 | } else |
661 | { | 663 | { |
662 | if (dateBook->date() == QDate::currentDate()) | 664 | if (dateBook->date() == QDate::currentDate()) |
663 | { | 665 | { |
664 | QTime curTime = QTime::currentTime(); | 666 | QTime curTime = QTime::currentTime(); |
665 | 667 | ||
666 | if (ev.end() < curTime) | 668 | if (ev.end() < curTime) |
667 | { | 669 | { |
668 | p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive | 670 | p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive |
669 | } else | 671 | } else |
670 | { | 672 | { |
671 | //change color in dependence of the time till the event starts | 673 | //change color in dependence of the time till the event starts |
672 | int duration = curTime.secsTo(ev.start()); | 674 | int duration = curTime.secsTo(ev.start()); |
673 | if (duration < 0) duration = 0; | 675 | if (duration < 0) duration = 0; |
674 | int colChange = duration*160/86400; //86400: secs per day, 160: max color shift | 676 | int colChange = duration*160/86400; //86400: secs per day, 160: max color shift |
675 | 677 | ||
676 | p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue | 678 | p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue |
677 | } | 679 | } |
678 | } else | 680 | } else |
679 | { | 681 | { |
680 | p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) | 682 | p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) |
681 | //perhaps make a distinction between future/past dates | 683 | //perhaps make a distinction between future/past dates |
682 | } | 684 | } |
683 | } | 685 | } |
684 | 686 | ||
685 | p.setPen( QColor(100, 100, 100) ); | 687 | p.setPen( QColor(100, 100, 100) ); |
686 | p.drawRect(rect()); | 688 | p.drawRect(rect()); |
687 | 689 | ||
688 | // p.drawRect(0,0, 5, height()); | 690 | // p.drawRect(0,0, 5, height()); |
689 | 691 | ||
690 | int y = 0; | 692 | int y = 0; |
691 | int d = 0; | 693 | int d = 0; |
692 | 694 | ||
693 | if ( ev.event().hasAlarm() ) { | 695 | if ( ev.event().hasAlarm() ) { |
694 | p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); | 696 | p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); |
695 | y = 20; | 697 | y = 20; |
696 | d = 20; | 698 | d = 20; |
697 | } | 699 | } |
698 | 700 | ||
699 | if ( ev.event().hasRepeat() ) { | 701 | if ( ev.event().hasRepeat() ) { |
700 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); | 702 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); |
701 | d = 20; | 703 | d = 20; |
702 | y += 20; | 704 | y += 20; |
703 | } | 705 | } |
704 | 706 | ||
705 | QSimpleRichText rt( text, font() ); | 707 | QSimpleRichText rt( text, font() ); |
706 | rt.setWidth( geom.width() - d - 6 ); | 708 | rt.setWidth( geom.width() - d - 6 ); |
707 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); | 709 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); |
708 | } | 710 | } |
709 | 711 | ||
710 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) | 712 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) |
711 | { | 713 | { |
712 | DateBookDayWidget *item; | 714 | DateBookDayWidget *item; |
713 | 715 | ||
714 | item = dateBook->getSelectedWidget(); | 716 | item = dateBook->getSelectedWidget(); |
715 | if (item) item->update(); | 717 | if (item) item->update(); |
716 | 718 | ||
717 | dateBook->setSelectedWidget(this); | 719 | dateBook->setSelectedWidget(this); |
718 | update(); | 720 | update(); |
719 | dateBook->repaint(); | 721 | dateBook->repaint(); |
720 | 722 | ||
721 | QPopupMenu m; | 723 | QPopupMenu m; |
722 | m.insertItem( tr( "Edit" ), 1 ); | 724 | m.insertItem( tr( "Edit" ), 1 ); |
723 | m.insertItem( tr( "Delete" ), 2 ); | 725 | m.insertItem( tr( "Delete" ), 2 ); |
724 | if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); | 726 | if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); |
725 | int r = m.exec( e->globalPos() ); | 727 | int r = m.exec( e->globalPos() ); |
726 | if ( r == 1 ) { | 728 | if ( r == 1 ) { |
727 | emit editMe( ev.event() ); | 729 | emit editMe( ev.event() ); |
728 | } else if ( r == 2 ) { | 730 | } else if ( r == 2 ) { |
729 | emit deleteMe( ev.event() ); | 731 | emit deleteMe( ev.event() ); |
730 | } else if ( r == 3 ) { | 732 | } else if ( r == 3 ) { |
731 | emit beamMe( ev.event() ); | 733 | emit beamMe( ev.event() ); |
732 | } | 734 | } |
733 | } | 735 | } |
734 | 736 | ||
735 | void DateBookDayWidget::setGeometry( const QRect &r ) | 737 | void DateBookDayWidget::setGeometry( const QRect &r ) |
736 | { | 738 | { |
737 | geom = r; | 739 | geom = r; |
738 | setFixedSize( r.width()+1, r.height()+1 ); | 740 | setFixedSize( r.width()+1, r.height()+1 ); |
739 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); | 741 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); |
740 | show(); | 742 | show(); |
741 | } | 743 | } |
742 | 744 | ||
743 | 745 | ||
744 | //--------------------------------------------------------------------------------------------- | 746 | //--------------------------------------------------------------------------------------------- |
745 | //--------------------------------------------------------------------------------------------- | 747 | //--------------------------------------------------------------------------------------------- |
746 | 748 | ||
747 | 749 | ||
748 | DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) | 750 | DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) |
749 | : QWidget( db->dayView()->viewport() ), dateBook( db ) | 751 | : QWidget( db->dayView()->viewport() ), dateBook( db ) |
750 | { | 752 | { |
751 | setBackgroundMode( PaletteBase ); | 753 | setBackgroundMode( PaletteBase ); |
752 | } | 754 | } |
753 | 755 | ||
754 | DateBookDayTimeMarker::~DateBookDayTimeMarker() | 756 | DateBookDayTimeMarker::~DateBookDayTimeMarker() |
755 | { | 757 | { |
756 | } | 758 | } |
757 | 759 | ||
758 | void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) | 760 | void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) |
759 | { | 761 | { |
760 | QPainter p( this ); | 762 | QPainter p( this ); |
761 | p.setBrush( QColor( 255, 0, 0 ) ); | 763 | p.setBrush( QColor( 255, 0, 0 ) ); |
762 | 764 | ||
763 | QPen pen; | 765 | QPen pen; |
764 | pen.setStyle(NoPen); | 766 | pen.setStyle(NoPen); |
765 | 767 | ||
766 | p.setPen( pen ); | 768 | p.setPen( pen ); |
767 | p.drawRect(rect()); | 769 | p.drawRect(rect()); |
768 | } | 770 | } |
769 | 771 | ||
770 | void DateBookDayTimeMarker::setTime( const QTime &t ) | 772 | void DateBookDayTimeMarker::setTime( const QTime &t ) |
771 | { | 773 | { |
772 | int y = t.hour()*60+t.minute(); | 774 | int y = t.hour()*60+t.minute(); |
773 | int rh = dateBook->dayView()->rowHeight(0); | 775 | int rh = dateBook->dayView()->rowHeight(0); |
774 | y = y*rh/60; | 776 | y = y*rh/60; |
775 | 777 | ||
776 | geom.setX( 0 ); | 778 | geom.setX( 0 ); |
777 | 779 | ||
778 | int x = dateBook->dayView()->columnWidth(0)-1; | 780 | int x = dateBook->dayView()->columnWidth(0)-1; |
779 | geom.setWidth( x ); | 781 | geom.setWidth( x ); |
780 | 782 | ||
781 | geom.setY( y ); | 783 | geom.setY( y ); |
782 | geom.setHeight( 1 ); | 784 | geom.setHeight( 1 ); |
783 | 785 | ||
784 | setGeometry( geom ); | 786 | setGeometry( geom ); |
785 | 787 | ||
786 | time = t; | 788 | time = t; |
787 | } | 789 | } |
788 | 790 | ||
789 | void DateBookDayTimeMarker::setGeometry( const QRect &r ) | 791 | void DateBookDayTimeMarker::setGeometry( const QRect &r ) |
790 | { | 792 | { |
791 | geom = r; | 793 | geom = r; |
792 | setFixedSize( r.width()+1, r.height()+1 ); | 794 | setFixedSize( r.width()+1, r.height()+1 ); |
793 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); | 795 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); |
794 | show(); | 796 | show(); |
795 | } | 797 | } |