author | umopapisdn <umopapisdn> | 2003-03-22 00:35:37 (UTC) |
---|---|---|
committer | umopapisdn <umopapisdn> | 2003-03-22 00:35:37 (UTC) |
commit | 5d488108161a2dfe1377ac38226b5d8a3a438d11 (patch) (unidiff) | |
tree | 1c1931f4e0a03e95ba1d1324135d6bf703c8c4fa | |
parent | ebf65f250904e0619c10b69a0428fcc538ffc167 (diff) | |
download | opie-5d488108161a2dfe1377ac38226b5d8a3a438d11.zip opie-5d488108161a2dfe1377ac38226b5d8a3a438d11.tar.gz opie-5d488108161a2dfe1377ac38226b5d8a3a438d11.tar.bz2 |
More informative dayview text:
An event that begins and ends on the same day is only mentioned by start and
end time.
An event that spans across multiple days, is also mentioned with start and
end date.
-rw-r--r-- | core/pim/datebook/datebookday.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index aaf3e16..a6a1be3 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp | |||
@@ -1,800 +1,795 @@ | |||
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, |
309 | currDate ); | 309 | currDate ); |
310 | QValueListIterator<EffectiveEvent> it; | 310 | QValueListIterator<EffectiveEvent> it; |
311 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { | 311 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { |
312 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); | 312 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); |
313 | connect( w, SIGNAL( deleteMe( const Event & ) ), | 313 | connect( w, SIGNAL( deleteMe( const Event & ) ), |
314 | this, SIGNAL( removeEvent( const Event & ) ) ); | 314 | this, SIGNAL( removeEvent( const Event & ) ) ); |
315 | connect( w, SIGNAL( editMe( const Event & ) ), | 315 | connect( w, SIGNAL( editMe( const Event & ) ), |
316 | this, SIGNAL( editEvent( const Event & ) ) ); | 316 | this, SIGNAL( editEvent( const Event & ) ) ); |
317 | connect( w, SIGNAL( beamMe( const Event & ) ), | 317 | connect( w, SIGNAL( beamMe( const Event & ) ), |
318 | this, SIGNAL( beamEvent( const Event & ) ) ); | 318 | this, SIGNAL( beamEvent( const Event & ) ) ); |
319 | widgetList.append( w ); | 319 | widgetList.append( w ); |
320 | } | 320 | } |
321 | 321 | ||
322 | } | 322 | } |
323 | 323 | ||
324 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) | 324 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) |
325 | { | 325 | { |
326 | int place = 0; | 326 | int place = 0; |
327 | int start = item->event().start().hour(); | 327 | int start = item->event().start().hour(); |
328 | QTime e = item->event().end(); | 328 | QTime e = item->event().end(); |
329 | int end = e.hour(); | 329 | int end = e.hour(); |
330 | if ( e.minute() < 5 ) | 330 | if ( e.minute() < 5 ) |
331 | end--; | 331 | end--; |
332 | if ( end < start ) | 332 | if ( end < start ) |
333 | end = start; | 333 | end = start; |
334 | while ( place < maxn ) { | 334 | while ( place < maxn ) { |
335 | bool free = TRUE; | 335 | bool free = TRUE; |
336 | int s = start; | 336 | int s = start; |
337 | while( s <= end ) { | 337 | while( s <= end ) { |
338 | if ( used[10*s+place] ) { | 338 | if ( used[10*s+place] ) { |
339 | free = FALSE; | 339 | free = FALSE; |
340 | break; | 340 | break; |
341 | } | 341 | } |
342 | s++; | 342 | s++; |
343 | } | 343 | } |
344 | if ( free ) break; | 344 | if ( free ) break; |
345 | place++; | 345 | place++; |
346 | } | 346 | } |
347 | if ( place == maxn ) { | 347 | if ( place == maxn ) { |
348 | return -1; | 348 | return -1; |
349 | } | 349 | } |
350 | while( start <= end ) { | 350 | while( start <= end ) { |
351 | used[10*start+place] = TRUE; | 351 | used[10*start+place] = TRUE; |
352 | start++; | 352 | start++; |
353 | } | 353 | } |
354 | return place; | 354 | return place; |
355 | } | 355 | } |
356 | 356 | ||
357 | 357 | ||
358 | void DateBookDay::relayoutPage( bool fromResize ) | 358 | void DateBookDay::relayoutPage( bool fromResize ) |
359 | { | 359 | { |
360 | setUpdatesEnabled( FALSE ); | 360 | setUpdatesEnabled( FALSE ); |
361 | if ( !fromResize ) | 361 | if ( !fromResize ) |
362 | getEvents(); // no need we already have them! | 362 | getEvents(); // no need we already have them! |
363 | 363 | ||
364 | widgetList.sort(); | 364 | widgetList.sort(); |
365 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning | 365 | //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 | 366 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view |
367 | 367 | ||
368 | int wCount = widgetList.count(); | 368 | int wCount = widgetList.count(); |
369 | int wid = view->columnWidth(0)-1; | 369 | int wid = view->columnWidth(0)-1; |
370 | int wd; | 370 | int wd; |
371 | int n = 1; | 371 | int n = 1; |
372 | 372 | ||
373 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget | 373 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget |
374 | 374 | ||
375 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); | 375 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); |
376 | 376 | ||
377 | if ( wCount < 20 ) { | 377 | if ( wCount < 20 ) { |
378 | 378 | ||
379 | QArray<QRect> geometries(wCount); | 379 | 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 | 380 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector |
381 | 381 | ||
382 | for ( int i = 0; i < wCount; i++) | 382 | for ( int i = 0; i < wCount; i++) |
383 | { | 383 | { |
384 | QValueList<int> intersectedWidgets; | 384 | QValueList<int> intersectedWidgets; |
385 | 385 | ||
386 | //find all widgets intersecting with widgetList.at(i) | 386 | //find all widgets intersecting with widgetList.at(i) |
387 | for ( int j = 0; j < wCount; j++) | 387 | for ( int j = 0; j < wCount; j++) |
388 | if (i != j) | 388 | if (i != j) |
389 | if (geometries[j].intersects(geometries[i])) | 389 | if (geometries[j].intersects(geometries[i])) |
390 | intersectedWidgets.append(j); | 390 | intersectedWidgets.append(j); |
391 | 391 | ||
392 | //for each of these intersecting widgets find out how many widgets are they intersecting with | 392 | //for each of these intersecting widgets find out how many widgets are they intersecting with |
393 | for ( uint j = 0; j < intersectedWidgets.count(); j++) | 393 | for ( uint j = 0; j < intersectedWidgets.count(); j++) |
394 | { | 394 | { |
395 | QArray<int> inter(wCount); | 395 | QArray<int> inter(wCount); |
396 | inter[j]=1; | 396 | inter[j]=1; |
397 | 397 | ||
398 | if (intersectedWidgets[j] != -1) | 398 | if (intersectedWidgets[j] != -1) |
399 | for ( uint k = j; k < intersectedWidgets.count(); k++) | 399 | for ( uint k = j; k < intersectedWidgets.count(); k++) |
400 | if (j != k && intersectedWidgets[k] != -1) | 400 | if (j != k && intersectedWidgets[k] != -1) |
401 | if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) | 401 | if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) |
402 | { | 402 | { |
403 | inter[j]++; | 403 | inter[j]++; |
404 | intersectedWidgets[k] = -1; | 404 | intersectedWidgets[k] = -1; |
405 | } | 405 | } |
406 | if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; | 406 | if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; |
407 | } | 407 | } |
408 | 408 | ||
409 | if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; | 409 | if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; |
410 | } | 410 | } |
411 | 411 | ||
412 | 412 | ||
413 | for ( int i = 0; i < wCount; i++) { | 413 | for ( int i = 0; i < wCount; i++) { |
414 | DateBookDayWidget *w = widgetList.at(i); | 414 | DateBookDayWidget *w = widgetList.at(i); |
415 | QRect geom = w->geometry(); | 415 | QRect geom = w->geometry(); |
416 | 416 | ||
417 | geom.setX( 0 ); | 417 | geom.setX( 0 ); |
418 | 418 | ||
419 | wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); | 419 | wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); |
420 | 420 | ||
421 | geom.setWidth( wd ); | 421 | geom.setWidth( wd ); |
422 | 422 | ||
423 | while ( intersects( w, geom ) ) { | 423 | while ( intersects( w, geom ) ) { |
424 | geom.moveBy( wd + 2 + 1, 0 ); | 424 | geom.moveBy( wd + 2 + 1, 0 ); |
425 | } | 425 | } |
426 | w->setGeometry( geom ); | 426 | w->setGeometry( geom ); |
427 | } | 427 | } |
428 | 428 | ||
429 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 429 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
430 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour | 430 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour |
431 | else | 431 | else |
432 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); | 432 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); |
433 | 433 | ||
434 | 434 | ||
435 | } else { | 435 | } else { |
436 | 436 | ||
437 | 437 | ||
438 | int hours[24]; | 438 | int hours[24]; |
439 | memset( hours, 0, 24*sizeof( int ) ); | 439 | memset( hours, 0, 24*sizeof( int ) ); |
440 | bool overFlow = FALSE; | 440 | bool overFlow = FALSE; |
441 | for ( int i = 0; i < wCount; i++ ) { | 441 | for ( int i = 0; i < wCount; i++ ) { |
442 | DateBookDayWidget *w = widgetList.at(i); | 442 | DateBookDayWidget *w = widgetList.at(i); |
443 | int start = w->event().start().hour(); | 443 | int start = w->event().start().hour(); |
444 | QTime e = w->event().end(); | 444 | QTime e = w->event().end(); |
445 | int end = e.hour(); | 445 | int end = e.hour(); |
446 | if ( e.minute() < 5 ) | 446 | if ( e.minute() < 5 ) |
447 | end--; | 447 | end--; |
448 | if ( end < start ) | 448 | if ( end < start ) |
449 | end = start; | 449 | end = start; |
450 | while( start <= end ) { | 450 | while( start <= end ) { |
451 | hours[start]++; | 451 | hours[start]++; |
452 | if ( hours[start] >= 10 ) | 452 | if ( hours[start] >= 10 ) |
453 | overFlow = TRUE; | 453 | overFlow = TRUE; |
454 | ++start; | 454 | ++start; |
455 | } | 455 | } |
456 | if ( overFlow ) | 456 | if ( overFlow ) |
457 | break; | 457 | break; |
458 | } | 458 | } |
459 | for ( int i = 0; i < 24; i++ ) { | 459 | for ( int i = 0; i < 24; i++ ) { |
460 | n = QMAX( n, hours[i] ); | 460 | n = QMAX( n, hours[i] ); |
461 | } | 461 | } |
462 | wid = ( view->columnWidth(0)-1 ) / n; | 462 | wid = ( view->columnWidth(0)-1 ) / n; |
463 | 463 | ||
464 | bool used[24*10]; | 464 | bool used[24*10]; |
465 | memset( used, FALSE, 24*10*sizeof( bool ) ); | 465 | memset( used, FALSE, 24*10*sizeof( bool ) ); |
466 | 466 | ||
467 | for ( int i = 0; i < wCount; i++ ) { | 467 | for ( int i = 0; i < wCount; i++ ) { |
468 | DateBookDayWidget *w = widgetList.at(i); | 468 | DateBookDayWidget *w = widgetList.at(i); |
469 | int xp = place( w, used, n ); | 469 | int xp = place( w, used, n ); |
470 | if ( xp != -1 ) { | 470 | if ( xp != -1 ) { |
471 | QRect geom = w->geometry(); | 471 | QRect geom = w->geometry(); |
472 | geom.setX( xp*(wid+2) ); | 472 | geom.setX( xp*(wid+2) ); |
473 | geom.setWidth( wid ); | 473 | geom.setWidth( wid ); |
474 | w->setGeometry( geom ); | 474 | w->setGeometry( geom ); |
475 | } | 475 | } |
476 | } | 476 | } |
477 | 477 | ||
478 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 478 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
479 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour | 479 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour |
480 | else | 480 | else |
481 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); | 481 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); |
482 | } | 482 | } |
483 | 483 | ||
484 | timeMarker->setTime( QTime::currentTime() );//display timeMarker | 484 | timeMarker->setTime( QTime::currentTime() );//display timeMarker |
485 | timeMarker->raise(); //on top of all widgets | 485 | timeMarker->raise(); //on top of all widgets |
486 | if (this->date() == QDate::currentDate()) //only show timeMarker on current day | 486 | if (this->date() == QDate::currentDate()) //only show timeMarker on current day |
487 | timeMarker->show(); else timeMarker->hide(); | 487 | timeMarker->show(); else timeMarker->hide(); |
488 | 488 | ||
489 | setUpdatesEnabled( TRUE ); | 489 | setUpdatesEnabled( TRUE ); |
490 | return; | 490 | return; |
491 | } | 491 | } |
492 | 492 | ||
493 | DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) | 493 | DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) |
494 | { | 494 | { |
495 | int i = 0; | 495 | int i = 0; |
496 | DateBookDayWidget *w = widgetList.at(i); | 496 | DateBookDayWidget *w = widgetList.at(i); |
497 | int wCount = widgetList.count(); | 497 | int wCount = widgetList.count(); |
498 | while ( i < wCount && w != item ) { | 498 | while ( i < wCount && w != item ) { |
499 | if ( w->geometry().intersects( geom ) ) { | 499 | if ( w->geometry().intersects( geom ) ) { |
500 | return w; | 500 | return w; |
501 | } | 501 | } |
502 | w = widgetList.at(++i); | 502 | w = widgetList.at(++i); |
503 | } | 503 | } |
504 | 504 | ||
505 | return 0; | 505 | return 0; |
506 | } | 506 | } |
507 | 507 | ||
508 | 508 | ||
509 | QDate DateBookDay::date() const | 509 | QDate DateBookDay::date() const |
510 | { | 510 | { |
511 | return currDate; | 511 | return currDate; |
512 | } | 512 | } |
513 | 513 | ||
514 | void DateBookDay::setStartViewTime( int startHere ) | 514 | void DateBookDay::setStartViewTime( int startHere ) |
515 | { | 515 | { |
516 | startTime = startHere; | 516 | startTime = startHere; |
517 | dayView()->clearSelection(); | 517 | dayView()->clearSelection(); |
518 | QTableSelection ts; | 518 | QTableSelection ts; |
519 | 519 | ||
520 | if (jumpToCurTime && this->date() == QDate::currentDate())//this should probably be in datebook.cpp where it's called? | 520 | if (jumpToCurTime && this->date() == QDate::currentDate())//this should probably be in datebook.cpp where it's called? |
521 | { | 521 | { |
522 | ts.init( QTime::currentTime().hour(), 0); | 522 | ts.init( QTime::currentTime().hour(), 0); |
523 | ts.expandTo( QTime::currentTime().hour(), 0); | 523 | ts.expandTo( QTime::currentTime().hour(), 0); |
524 | } else | 524 | } else |
525 | { | 525 | { |
526 | ts.init( startTime, 0 ); | 526 | ts.init( startTime, 0 ); |
527 | ts.expandTo( startTime, 0 ); | 527 | ts.expandTo( startTime, 0 ); |
528 | } | 528 | } |
529 | 529 | ||
530 | dayView()->addSelection( ts ); | 530 | dayView()->addSelection( ts ); |
531 | } | 531 | } |
532 | 532 | ||
533 | int DateBookDay::startViewTime() const | 533 | int DateBookDay::startViewTime() const |
534 | { | 534 | { |
535 | return startTime; | 535 | return startTime; |
536 | } | 536 | } |
537 | 537 | ||
538 | void DateBookDay::slotWeekChanged( bool bStartOnMonday ) | 538 | void DateBookDay::slotWeekChanged( bool bStartOnMonday ) |
539 | { | 539 | { |
540 | header->setStartOfWeek( bStartOnMonday ); | 540 | header->setStartOfWeek( bStartOnMonday ); |
541 | // redraw(); | 541 | // redraw(); |
542 | } | 542 | } |
543 | 543 | ||
544 | void DateBookDay::keyPressEvent(QKeyEvent *e) | 544 | void DateBookDay::keyPressEvent(QKeyEvent *e) |
545 | { | 545 | { |
546 | switch(e->key()) { | 546 | switch(e->key()) { |
547 | case Key_Up: | 547 | case Key_Up: |
548 | view->moveUp(); | 548 | view->moveUp(); |
549 | break; | 549 | break; |
550 | case Key_Down: | 550 | case Key_Down: |
551 | view->moveDown(); | 551 | view->moveDown(); |
552 | break; | 552 | break; |
553 | case Key_Left: | 553 | case Key_Left: |
554 | setDate(QDate(currDate).addDays(-1)); | 554 | setDate(QDate(currDate).addDays(-1)); |
555 | break; | 555 | break; |
556 | case Key_Right: | 556 | case Key_Right: |
557 | setDate(QDate(currDate).addDays(1)); | 557 | setDate(QDate(currDate).addDays(1)); |
558 | break; | 558 | break; |
559 | default: | 559 | default: |
560 | e->ignore(); | 560 | e->ignore(); |
561 | } | 561 | } |
562 | } | 562 | } |
563 | 563 | ||
564 | //=========================================================================== | 564 | //=========================================================================== |
565 | 565 | ||
566 | DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, | 566 | DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, |
567 | DateBookDay *db ) | 567 | DateBookDay *db ) |
568 | : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) | 568 | : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) |
569 | { | 569 | { |
570 | 570 | ||
571 | 571 | ||
572 | // why would someone use "<"? Oh well, fix it up... | 572 | // why would someone use "<"? Oh well, fix it up... |
573 | // I wonder what other things may be messed up... | 573 | // I wonder what other things may be messed up... |
574 | QString strDesc = ev.description(); | 574 | QString strDesc = ev.description(); |
575 | int where = strDesc.find( "<" ); | 575 | int where = strDesc.find( "<" ); |
576 | while ( where != -1 ) { | 576 | while ( where != -1 ) { |
577 | strDesc.remove( where, 1 ); | 577 | strDesc.remove( where, 1 ); |
578 | strDesc.insert( where, "<" ); | 578 | strDesc.insert( where, "<" ); |
579 | where = strDesc.find( "<", where ); | 579 | where = strDesc.find( "<", where ); |
580 | } | 580 | } |
581 | 581 | ||
582 | QString strCat; | 582 | QString strCat; |
583 | // ### Fix later... | 583 | // ### Fix later... |
584 | // QString strCat = ev.category(); | 584 | // QString strCat = ev.category(); |
585 | // where = strCat.find( "<" ); | 585 | // where = strCat.find( "<" ); |
586 | // while ( where != -1 ) { | 586 | // while ( where != -1 ) { |
587 | // strCat.remove( where, 1 ); | 587 | // strCat.remove( where, 1 ); |
588 | // strCat.insert( where, "<" ); | 588 | // strCat.insert( where, "<" ); |
589 | // where = strCat.find( "<", where ); | 589 | // where = strCat.find( "<", where ); |
590 | // } | 590 | // } |
591 | 591 | ||
592 | QString strNote = ev.notes(); | 592 | QString strNote = ev.notes(); |
593 | where = strNote.find( "<" ); | 593 | where = strNote.find( "<" ); |
594 | while ( where != -1 ) { | 594 | while ( where != -1 ) { |
595 | strNote.remove( where, 1 ); | 595 | strNote.remove( where, 1 ); |
596 | strNote.insert( where, "<" ); | 596 | strNote.insert( where, "<" ); |
597 | where = strNote.find( "<", where ); | 597 | where = strNote.find( "<", where ); |
598 | } | 598 | } |
599 | 599 | ||
600 | text = "<b>" + strDesc + "</b><br>" + "<i>"; | 600 | text = "<b>" + strDesc + "</b><br>" + "<i>"; |
601 | if ( !strCat.isEmpty() ) { | 601 | if ( !strCat.isEmpty() ) { |
602 | text += strCat + "</i><br>"; | 602 | text += strCat + "</i><br>"; |
603 | } | 603 | } |
604 | if (ev.event().type() == Event::Normal ) | 604 | if (ev.event().type() == Event::Normal ) |
605 | setEventText( text ); | 605 | setEventText( text ); |
606 | else | 606 | else |
607 | setAllDayText( text ); | 607 | setAllDayText( text ); |
608 | 608 | ||
609 | text += "<br><br>" + strNote; | 609 | text += "<br><br>" + strNote; |
610 | 610 | ||
611 | setBackgroundMode( PaletteBase ); | 611 | setBackgroundMode( PaletteBase ); |
612 | 612 | ||
613 | QTime start = ev.start(); | 613 | QTime start = ev.start(); |
614 | QTime end = ev.end(); | 614 | QTime end = ev.end(); |
615 | int y = start.hour()*60+start.minute(); | 615 | int y = start.hour()*60+start.minute(); |
616 | int h = end.hour()*60+end.minute()-y; | 616 | int h = end.hour()*60+end.minute()-y; |
617 | int rh = dateBook->dayView()->rowHeight(0); | 617 | int rh = dateBook->dayView()->rowHeight(0); |
618 | y = y*rh/60; | 618 | y = y*rh/60; |
619 | h = h*rh/60; | 619 | h = h*rh/60; |
620 | if ( h < 3 ) { | 620 | if ( h < 3 ) { |
621 | h = 3; | 621 | h = 3; |
622 | } | 622 | } |
623 | geom.setY( y ); | 623 | geom.setY( y ); |
624 | geom.setHeight( h ); | 624 | geom.setHeight( h ); |
625 | geom.setX( 0 ); | 625 | geom.setX( 0 ); |
626 | geom.setWidth(dateBook->dayView()->columnWidth(0)-1); | 626 | geom.setWidth(dateBook->dayView()->columnWidth(0)-1); |
627 | 627 | ||
628 | } | 628 | } |
629 | void DateBookDayWidget::setAllDayText( QString &text ) { | 629 | void DateBookDayWidget::setAllDayText( QString &text ) { |
630 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; | 630 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; |
631 | } | 631 | } |
632 | void DateBookDayWidget::setEventText( QString& text ) { | 632 | void DateBookDayWidget::setEventText( QString& text ) { |
633 | bool whichClock = dateBook->dayView()->whichClock(); | 633 | bool whichClock = dateBook->dayView()->whichClock(); |
634 | text += "<b>" + tr("Time") + "</b>: "; | 634 | if ( ev.startDate() != ev.endDate() ) { |
635 | if ( ev.startDate() != ev.date() ) { | 635 | text += "<b>" + tr("Start") + "</b>: "; |
636 | // multi-day event. Show start date | 636 | text += TimeString::timeString( ev.event().start().time(), whichClock, FALSE ); |
637 | text += TimeString::longDateString( ev.startDate() ); | 637 | text += " - " + TimeString::longDateString( ev.startDate() ) + "<br>"; |
638 | text += "<b>" + tr("End") + "</b>: "; | ||
639 | text += TimeString::timeString( ev.event().end().time(), whichClock, FALSE ); | ||
640 | text += " - " + TimeString::longDateString( ev.endDate() ) + "<br>"; | ||
638 | } else { | 641 | } else { |
639 | // Show start time. | 642 | text += "<b>" + tr("Time") + "</b>: "; |
640 | text += TimeString::timeString( ev.start(), whichClock, FALSE ); | 643 | text += TimeString::timeString( ev.start(), whichClock, FALSE ); |
641 | } | 644 | text += "<b>" + tr(" - ") + "</b>"; |
642 | |||
643 | text += "<b>" + tr(" - ") + "</b>"; | ||
644 | if ( ev.endDate() != ev.date() ) { | ||
645 | // multi-day event. Show end date | ||
646 | text += TimeString::longDateString( ev.endDate() ); | ||
647 | } else { | ||
648 | // Show end time. | ||
649 | text += TimeString::timeString( ev.end(), whichClock, FALSE ); | 645 | text += TimeString::timeString( ev.end(), whichClock, FALSE ); |
650 | } | 646 | } |
651 | |||
652 | } | 647 | } |
653 | 648 | ||
654 | DateBookDayWidget::~DateBookDayWidget() | 649 | DateBookDayWidget::~DateBookDayWidget() |
655 | { | 650 | { |
656 | } | 651 | } |
657 | 652 | ||
658 | void DateBookDayWidget::paintEvent( QPaintEvent *e ) | 653 | void DateBookDayWidget::paintEvent( QPaintEvent *e ) |
659 | { | 654 | { |
660 | QPainter p( this ); | 655 | QPainter p( this ); |
661 | 656 | ||
662 | if (dateBook->getSelectedWidget() == this) | 657 | if (dateBook->getSelectedWidget() == this) |
663 | { | 658 | { |
664 | p.setBrush( QColor( 155, 240, 230 ) ); // selected item | 659 | p.setBrush( QColor( 155, 240, 230 ) ); // selected item |
665 | } else | 660 | } else |
666 | { | 661 | { |
667 | if (dateBook->date() == QDate::currentDate()) | 662 | if (dateBook->date() == QDate::currentDate()) |
668 | { | 663 | { |
669 | QTime curTime = QTime::currentTime(); | 664 | QTime curTime = QTime::currentTime(); |
670 | 665 | ||
671 | if (ev.end() < curTime) | 666 | if (ev.end() < curTime) |
672 | { | 667 | { |
673 | p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive | 668 | p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive |
674 | } else | 669 | } else |
675 | { | 670 | { |
676 | //change color in dependence of the time till the event starts | 671 | //change color in dependence of the time till the event starts |
677 | int duration = curTime.secsTo(ev.start()); | 672 | int duration = curTime.secsTo(ev.start()); |
678 | if (duration < 0) duration = 0; | 673 | if (duration < 0) duration = 0; |
679 | int colChange = duration*160/86400; //86400: secs per day, 160: max color shift | 674 | int colChange = duration*160/86400; //86400: secs per day, 160: max color shift |
680 | 675 | ||
681 | p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue | 676 | p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue |
682 | } | 677 | } |
683 | } else | 678 | } else |
684 | { | 679 | { |
685 | p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) | 680 | p.setBrush( QColor( 220, 220, 220 ) ); //light grey, inactive (not current date) |
686 | //perhaps make a distinction between future/past dates | 681 | //perhaps make a distinction between future/past dates |
687 | } | 682 | } |
688 | } | 683 | } |
689 | 684 | ||
690 | p.setPen( QColor(100, 100, 100) ); | 685 | p.setPen( QColor(100, 100, 100) ); |
691 | p.drawRect(rect()); | 686 | p.drawRect(rect()); |
692 | 687 | ||
693 | // p.drawRect(0,0, 5, height()); | 688 | // p.drawRect(0,0, 5, height()); |
694 | 689 | ||
695 | int y = 0; | 690 | int y = 0; |
696 | int d = 0; | 691 | int d = 0; |
697 | 692 | ||
698 | if ( ev.event().hasAlarm() ) { | 693 | if ( ev.event().hasAlarm() ) { |
699 | p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); | 694 | p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); |
700 | y = 20; | 695 | y = 20; |
701 | d = 20; | 696 | d = 20; |
702 | } | 697 | } |
703 | 698 | ||
704 | if ( ev.event().hasRepeat() ) { | 699 | if ( ev.event().hasRepeat() ) { |
705 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); | 700 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); |
706 | d = 20; | 701 | d = 20; |
707 | y += 20; | 702 | y += 20; |
708 | } | 703 | } |
709 | 704 | ||
710 | QSimpleRichText rt( text, font() ); | 705 | QSimpleRichText rt( text, font() ); |
711 | rt.setWidth( geom.width() - d - 6 ); | 706 | rt.setWidth( geom.width() - d - 6 ); |
712 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); | 707 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); |
713 | } | 708 | } |
714 | 709 | ||
715 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) | 710 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) |
716 | { | 711 | { |
717 | DateBookDayWidget *item; | 712 | DateBookDayWidget *item; |
718 | 713 | ||
719 | item = dateBook->getSelectedWidget(); | 714 | item = dateBook->getSelectedWidget(); |
720 | if (item) item->update(); | 715 | if (item) item->update(); |
721 | 716 | ||
722 | dateBook->setSelectedWidget(this); | 717 | dateBook->setSelectedWidget(this); |
723 | update(); | 718 | update(); |
724 | dateBook->repaint(); | 719 | dateBook->repaint(); |
725 | 720 | ||
726 | QPopupMenu m; | 721 | QPopupMenu m; |
727 | m.insertItem( tr( "Edit" ), 1 ); | 722 | m.insertItem( tr( "Edit" ), 1 ); |
728 | m.insertItem( tr( "Delete" ), 2 ); | 723 | m.insertItem( tr( "Delete" ), 2 ); |
729 | if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); | 724 | if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); |
730 | int r = m.exec( e->globalPos() ); | 725 | int r = m.exec( e->globalPos() ); |
731 | if ( r == 1 ) { | 726 | if ( r == 1 ) { |
732 | emit editMe( ev.event() ); | 727 | emit editMe( ev.event() ); |
733 | } else if ( r == 2 ) { | 728 | } else if ( r == 2 ) { |
734 | emit deleteMe( ev.event() ); | 729 | emit deleteMe( ev.event() ); |
735 | } else if ( r == 3 ) { | 730 | } else if ( r == 3 ) { |
736 | emit beamMe( ev.event() ); | 731 | emit beamMe( ev.event() ); |
737 | } | 732 | } |
738 | } | 733 | } |
739 | 734 | ||
740 | void DateBookDayWidget::setGeometry( const QRect &r ) | 735 | void DateBookDayWidget::setGeometry( const QRect &r ) |
741 | { | 736 | { |
742 | geom = r; | 737 | geom = r; |
743 | setFixedSize( r.width()+1, r.height()+1 ); | 738 | setFixedSize( r.width()+1, r.height()+1 ); |
744 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); | 739 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); |
745 | show(); | 740 | show(); |
746 | } | 741 | } |
747 | 742 | ||
748 | 743 | ||
749 | //--------------------------------------------------------------------------------------------- | 744 | //--------------------------------------------------------------------------------------------- |
750 | //--------------------------------------------------------------------------------------------- | 745 | //--------------------------------------------------------------------------------------------- |
751 | 746 | ||
752 | 747 | ||
753 | DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) | 748 | DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) |
754 | : QWidget( db->dayView()->viewport() ), dateBook( db ) | 749 | : QWidget( db->dayView()->viewport() ), dateBook( db ) |
755 | { | 750 | { |
756 | setBackgroundMode( PaletteBase ); | 751 | setBackgroundMode( PaletteBase ); |
757 | } | 752 | } |
758 | 753 | ||
759 | DateBookDayTimeMarker::~DateBookDayTimeMarker() | 754 | DateBookDayTimeMarker::~DateBookDayTimeMarker() |
760 | { | 755 | { |
761 | } | 756 | } |
762 | 757 | ||
763 | void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) | 758 | void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) |
764 | { | 759 | { |
765 | QPainter p( this ); | 760 | QPainter p( this ); |
766 | p.setBrush( QColor( 255, 0, 0 ) ); | 761 | p.setBrush( QColor( 255, 0, 0 ) ); |
767 | 762 | ||
768 | QPen pen; | 763 | QPen pen; |
769 | pen.setStyle(NoPen); | 764 | pen.setStyle(NoPen); |
770 | 765 | ||
771 | p.setPen( pen ); | 766 | p.setPen( pen ); |
772 | p.drawRect(rect()); | 767 | p.drawRect(rect()); |
773 | } | 768 | } |
774 | 769 | ||
775 | void DateBookDayTimeMarker::setTime( const QTime &t ) | 770 | void DateBookDayTimeMarker::setTime( const QTime &t ) |
776 | { | 771 | { |
777 | int y = t.hour()*60+t.minute(); | 772 | int y = t.hour()*60+t.minute(); |
778 | int rh = dateBook->dayView()->rowHeight(0); | 773 | int rh = dateBook->dayView()->rowHeight(0); |
779 | y = y*rh/60; | 774 | y = y*rh/60; |
780 | 775 | ||
781 | geom.setX( 0 ); | 776 | geom.setX( 0 ); |
782 | 777 | ||
783 | int x = dateBook->dayView()->columnWidth(0)-1; | 778 | int x = dateBook->dayView()->columnWidth(0)-1; |
784 | geom.setWidth( x ); | 779 | geom.setWidth( x ); |
785 | 780 | ||
786 | geom.setY( y ); | 781 | geom.setY( y ); |
787 | geom.setHeight( 1 ); | 782 | geom.setHeight( 1 ); |
788 | 783 | ||
789 | setGeometry( geom ); | 784 | setGeometry( geom ); |
790 | 785 | ||
791 | time = t; | 786 | time = t; |
792 | } | 787 | } |
793 | 788 | ||
794 | void DateBookDayTimeMarker::setGeometry( const QRect &r ) | 789 | void DateBookDayTimeMarker::setGeometry( const QRect &r ) |
795 | { | 790 | { |
796 | geom = r; | 791 | geom = r; |
797 | setFixedSize( r.width()+1, r.height()+1 ); | 792 | setFixedSize( r.width()+1, r.height()+1 ); |
798 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); | 793 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); |
799 | show(); | 794 | show(); |
800 | } | 795 | } |