-rw-r--r-- | core/pim/datebook/datebookday.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index 5474cfc..325b902 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp | |||
@@ -1,286 +1,287 @@ | |||
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 | 32 | ||
32 | #include <qheader.h> | 33 | #include <qheader.h> |
33 | #include <qdatetime.h> | 34 | #include <qdatetime.h> |
34 | #include <qpainter.h> | 35 | #include <qpainter.h> |
35 | #include <qsimplerichtext.h> | 36 | #include <qsimplerichtext.h> |
36 | #include <qpopupmenu.h> | 37 | #include <qpopupmenu.h> |
37 | #include <qtextcodec.h> | 38 | #include <qtextcodec.h> |
38 | #include <qpalette.h> | 39 | #include <qpalette.h> |
39 | 40 | ||
40 | #include <qtimer.h> | 41 | #include <qtimer.h> |
41 | 42 | ||
42 | DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, | 43 | DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, |
43 | const char *name ) | 44 | const char *name ) |
44 | : QTable( 24, 1, parent, name ), | 45 | : QTable( 24, 1, parent, name ), |
45 | ampm( whichClock ) | 46 | ampm( whichClock ) |
46 | { | 47 | { |
47 | enableClipper(TRUE); | 48 | enableClipper(TRUE); |
48 | setTopMargin( 0 ); | 49 | setTopMargin( 0 ); |
49 | horizontalHeader()->hide(); | 50 | horizontalHeader()->hide(); |
50 | setLeftMargin(38); | 51 | setLeftMargin(38); |
51 | setColumnStretchable( 0, TRUE ); | 52 | setColumnStretchable( 0, TRUE ); |
52 | setHScrollBarMode( QScrollView::AlwaysOff ); | 53 | setHScrollBarMode( QScrollView::AlwaysOff ); |
53 | verticalHeader()->setPalette(white); | 54 | verticalHeader()->setPalette(white); |
54 | verticalHeader()->setResizeEnabled(FALSE); | 55 | verticalHeader()->setResizeEnabled(FALSE); |
55 | setSelectionMode( Single ); | 56 | setSelectionMode( Single ); |
56 | 57 | ||
57 | // get rid of being able to edit things... | 58 | // get rid of being able to edit things... |
58 | QTableItem *tmp; | 59 | QTableItem *tmp; |
59 | int row; | 60 | int row; |
60 | for ( row = 0; row < numRows(); row++ ) { | 61 | for ( row = 0; row < numRows(); row++ ) { |
61 | tmp = new QTableItem( this, QTableItem::Never, QString::null); | 62 | tmp = new QTableItem( this, QTableItem::Never, QString::null); |
62 | setItem( row, 0, tmp ); | 63 | setItem( row, 0, tmp ); |
63 | //setRowHeight( row, 40); | 64 | //setRowHeight( row, 40); |
64 | } | 65 | } |
65 | initHeader(); | 66 | initHeader(); |
66 | QObject::connect( qApp, SIGNAL(clockChanged(bool)), | 67 | QObject::connect( qApp, SIGNAL(clockChanged(bool)), |
67 | this, SLOT(slotChangeClock(bool)) ); | 68 | this, SLOT(slotChangeClock(bool)) ); |
68 | } | 69 | } |
69 | 70 | ||
70 | void DateBookDayView::initHeader() | 71 | void DateBookDayView::initHeader() |
71 | { | 72 | { |
72 | QString strTmp; | 73 | QString strTmp; |
73 | for ( int i = 0; i < 24; ++i ) { | 74 | for ( int i = 0; i < 24; ++i ) { |
74 | if ( ampm ) { | 75 | if ( ampm ) { |
75 | if ( i == 0 ) | 76 | if ( i == 0 ) |
76 | strTmp = QString::number(12) + ":00"; | 77 | strTmp = QString::number(12) + ":00"; |
77 | else if ( i == 12 ) | 78 | else if ( i == 12 ) |
78 | strTmp = QString::number(12) + tr(":00p"); | 79 | strTmp = QString::number(12) + tr(":00p"); |
79 | else if ( i > 12 ) | 80 | else if ( i > 12 ) |
80 | strTmp = QString::number( i - 12 ) + tr(":00p"); | 81 | strTmp = QString::number( i - 12 ) + tr(":00p"); |
81 | else | 82 | else |
82 | strTmp = QString::number(i) + ":00"; | 83 | strTmp = QString::number(i) + ":00"; |
83 | } else { | 84 | } else { |
84 | if ( i < 10 ) | 85 | if ( i < 10 ) |
85 | strTmp = "0" + QString::number(i) + ":00"; | 86 | strTmp = "0" + QString::number(i) + ":00"; |
86 | else | 87 | else |
87 | strTmp = QString::number(i) + ":00"; | 88 | strTmp = QString::number(i) + ":00"; |
88 | } | 89 | } |
89 | strTmp = strTmp.rightJustify( 6, ' ' ); | 90 | strTmp = strTmp.rightJustify( 6, ' ' ); |
90 | verticalHeader()->setLabel( i, strTmp ); | 91 | verticalHeader()->setLabel( i, strTmp ); |
91 | setRowStretchable( i, FALSE ); | 92 | setRowStretchable( i, FALSE ); |
92 | } | 93 | } |
93 | } | 94 | } |
94 | 95 | ||
95 | void DateBookDayView::slotChangeClock( bool newClock ) | 96 | void DateBookDayView::slotChangeClock( bool newClock ) |
96 | { | 97 | { |
97 | ampm = newClock; | 98 | ampm = newClock; |
98 | initHeader(); | 99 | initHeader(); |
99 | } | 100 | } |
100 | 101 | ||
101 | bool DateBookDayView::whichClock() const | 102 | bool DateBookDayView::whichClock() const |
102 | { | 103 | { |
103 | return ampm; | 104 | return ampm; |
104 | } | 105 | } |
105 | 106 | ||
106 | void DateBookDayView::moveUp() | 107 | void DateBookDayView::moveUp() |
107 | { | 108 | { |
108 | scrollBy(0, -20); | 109 | scrollBy(0, -20); |
109 | } | 110 | } |
110 | 111 | ||
111 | void DateBookDayView::moveDown() | 112 | void DateBookDayView::moveDown() |
112 | { | 113 | { |
113 | scrollBy(0, 20); | 114 | scrollBy(0, 20); |
114 | } | 115 | } |
115 | 116 | ||
116 | void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) | 117 | void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) |
117 | { | 118 | { |
118 | int w = cr.width(); | 119 | int w = cr.width(); |
119 | int h = cr.height(); | 120 | int h = cr.height(); |
120 | p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); | 121 | p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); |
121 | if ( showGrid() ) { | 122 | if ( showGrid() ) { |
122 | // Draw our lines | 123 | // Draw our lines |
123 | int x2 = w - 1; | 124 | int x2 = w - 1; |
124 | int y2 = h - 1; | 125 | int y2 = h - 1; |
125 | QPen pen( p->pen() ); | 126 | QPen pen( p->pen() ); |
126 | p->setPen( colorGroup().dark() ); | 127 | p->setPen( colorGroup().dark() ); |
127 | p->drawLine( x2, 0, x2, y2 ); | 128 | p->drawLine( x2, 0, x2, y2 ); |
128 | p->drawLine( 0, y2, x2, y2 ); | 129 | p->drawLine( 0, y2, x2, y2 ); |
129 | 130 | ||
130 | p->setPen( colorGroup().midlight() ); | 131 | p->setPen( colorGroup().midlight() ); |
131 | p->drawLine( 0, y2 - h/2, x2, y2 - h/2); | 132 | p->drawLine( 0, y2 - h/2, x2, y2 - h/2); |
132 | 133 | ||
133 | p->setPen( pen ); | 134 | p->setPen( pen ); |
134 | } | 135 | } |
135 | } | 136 | } |
136 | 137 | ||
137 | void DateBookDayView::paintFocus( QPainter *, const QRect & ) | 138 | void DateBookDayView::paintFocus( QPainter *, const QRect & ) |
138 | { | 139 | { |
139 | } | 140 | } |
140 | 141 | ||
141 | 142 | ||
142 | void DateBookDayView::resizeEvent( QResizeEvent *e ) | 143 | void DateBookDayView::resizeEvent( QResizeEvent *e ) |
143 | { | 144 | { |
144 | QTable::resizeEvent( e ); | 145 | QTable::resizeEvent( e ); |
145 | columnWidthChanged( 0 ); | 146 | columnWidthChanged( 0 ); |
146 | emit sigColWidthChanged(); | 147 | emit sigColWidthChanged(); |
147 | } | 148 | } |
148 | 149 | ||
149 | void DateBookDayView::keyPressEvent( QKeyEvent *e ) | 150 | void DateBookDayView::keyPressEvent( QKeyEvent *e ) |
150 | { | 151 | { |
151 | QString txt = e->text(); | 152 | QString txt = e->text(); |
152 | if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { | 153 | if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { |
153 | // we this is some sort of thing we know about... | 154 | // we this is some sort of thing we know about... |
154 | e->accept(); | 155 | e->accept(); |
155 | emit sigCapturedKey( txt ); | 156 | emit sigCapturedKey( txt ); |
156 | } else { | 157 | } else { |
157 | // I don't know what this key is, do you? | 158 | // I don't know what this key is, do you? |
158 | e->ignore(); | 159 | e->ignore(); |
159 | } | 160 | } |
160 | } | 161 | } |
161 | 162 | ||
162 | void DateBookDayView::setRowStyle( int style ) | 163 | void DateBookDayView::setRowStyle( int style ) |
163 | { | 164 | { |
164 | if (style<0) style = 0; | 165 | if (style<0) style = 0; |
165 | 166 | ||
166 | for (int i=0; i<numRows(); i++) | 167 | for (int i=0; i<numRows(); i++) |
167 | setRowHeight(i, style*10+20); | 168 | setRowHeight(i, style*10+20); |
168 | } | 169 | } |
169 | 170 | ||
170 | //=========================================================================== | 171 | //=========================================================================== |
171 | 172 | ||
172 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, | 173 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, |
173 | DateBookDB *newDb, QWidget *parent, | 174 | DateBookDB *newDb, QWidget *parent, |
174 | const char *name ) | 175 | const char *name ) |
175 | : QVBox( parent, name ), | 176 | : QVBox( parent, name ), |
176 | currDate( QDate::currentDate() ), | 177 | currDate( QDate::currentDate() ), |
177 | db( newDb ), | 178 | db( newDb ), |
178 | startTime( 0 ) | 179 | startTime( 0 ) |
179 | { | 180 | { |
180 | widgetList.setAutoDelete( true ); | 181 | widgetList.setAutoDelete( true ); |
181 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); | 182 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); |
182 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); | 183 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); |
183 | view = new DateBookDayView( ampm, this, "day view" ); | 184 | view = new DateBookDayView( ampm, this, "day view" ); |
184 | 185 | ||
185 | connect( header, SIGNAL( dateChanged( int, int, int ) ), | 186 | connect( header, SIGNAL( dateChanged( int, int, int ) ), |
186 | this, SLOT( dateChanged( int, int, int ) ) ); | 187 | this, SLOT( dateChanged( int, int, int ) ) ); |
187 | connect( view, SIGNAL( sigColWidthChanged() ), | 188 | connect( view, SIGNAL( sigColWidthChanged() ), |
188 | this, SLOT( slotColWidthChanged() ) ); | 189 | this, SLOT( slotColWidthChanged() ) ); |
189 | connect( qApp, SIGNAL(weekChanged(bool)), | 190 | connect( qApp, SIGNAL(weekChanged(bool)), |
190 | this, SLOT(slotWeekChanged(bool)) ); | 191 | this, SLOT(slotWeekChanged(bool)) ); |
191 | connect( view, SIGNAL(sigCapturedKey(const QString &)), | 192 | connect( view, SIGNAL(sigCapturedKey(const QString &)), |
192 | this, SIGNAL(sigNewEvent(const QString&)) ); | 193 | this, SIGNAL(sigNewEvent(const QString&)) ); |
193 | 194 | ||
194 | QTimer *timer = new QTimer( this ); | 195 | QTimer *timer = new QTimer( this ); |
195 | 196 | ||
196 | connect( timer, SIGNAL(timeout()), | 197 | connect( timer, SIGNAL(timeout()), |
197 | this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors | 198 | this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors |
198 | timer->start( 1000*60*5, FALSE ); //update every 5min | 199 | timer->start( 1000*60*5, FALSE ); //update every 5min |
199 | 200 | ||
200 | selectedWidget = 0; | 201 | selectedWidget = 0; |
201 | 202 | ||
202 | timeMarker = new DateBookDayTimeMarker( this ); | 203 | timeMarker = new DateBookDayTimeMarker( this ); |
203 | timeMarker->setTime( QTime::currentTime() ); | 204 | timeMarker->setTime( QTime::currentTime() ); |
204 | rowStyle = -1; // initialize with bogus values | 205 | rowStyle = -1; // initialize with bogus values |
205 | } | 206 | } |
206 | 207 | ||
207 | void DateBookDay::setJumpToCurTime( bool bJump ) | 208 | void DateBookDay::setJumpToCurTime( bool bJump ) |
208 | { | 209 | { |
209 | jumpToCurTime = bJump; | 210 | jumpToCurTime = bJump; |
210 | } | 211 | } |
211 | 212 | ||
212 | void DateBookDay::setRowStyle( int style ) | 213 | void DateBookDay::setRowStyle( int style ) |
213 | { | 214 | { |
214 | if (rowStyle != style) view->setRowStyle( style ); | 215 | if (rowStyle != style) view->setRowStyle( style ); |
215 | rowStyle = style; | 216 | rowStyle = style; |
216 | } | 217 | } |
217 | 218 | ||
218 | void DateBookDay::updateView( void ) | 219 | void DateBookDay::updateView( void ) |
219 | { | 220 | { |
220 | timeMarker->setTime( QTime::currentTime() ); | 221 | timeMarker->setTime( QTime::currentTime() ); |
221 | //need to find a way to update all DateBookDayWidgets | 222 | //need to find a way to update all DateBookDayWidgets |
222 | } | 223 | } |
223 | 224 | ||
224 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) | 225 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) |
225 | { | 226 | { |
226 | selectedWidget = w; | 227 | selectedWidget = w; |
227 | } | 228 | } |
228 | 229 | ||
229 | DateBookDayWidget * DateBookDay::getSelectedWidget( void ) | 230 | DateBookDayWidget * DateBookDay::getSelectedWidget( void ) |
230 | { | 231 | { |
231 | return selectedWidget; | 232 | return selectedWidget; |
232 | } | 233 | } |
233 | 234 | ||
234 | void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) | 235 | void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) |
235 | { | 236 | { |
236 | start.setDate( currDate ); | 237 | start.setDate( currDate ); |
237 | end.setDate( currDate ); | 238 | end.setDate( currDate ); |
238 | 239 | ||
239 | int sh=99,eh=-1; | 240 | int sh=99,eh=-1; |
240 | 241 | ||
241 | int n = dayView()->numSelections(); | 242 | int n = dayView()->numSelections(); |
242 | 243 | ||
243 | for (int i=0; i<n; i++) { | 244 | for (int i=0; i<n; i++) { |
244 | QTableSelection sel = dayView()->selection( i ); | 245 | QTableSelection sel = dayView()->selection( i ); |
245 | sh = QMIN(sh,sel.topRow()); | 246 | sh = QMIN(sh,sel.topRow()); |
246 | eh = QMAX(sh,sel.bottomRow()+1); | 247 | eh = QMAX(sh,sel.bottomRow()+1); |
247 | } | 248 | } |
248 | if (sh > 23 || eh < 1) { | 249 | if (sh > 23 || eh < 1) { |
249 | sh=8; | 250 | sh=8; |
250 | eh=9; | 251 | eh=9; |
251 | } | 252 | } |
252 | 253 | ||
253 | start.setTime( QTime( sh, 0, 0 ) ); | 254 | start.setTime( QTime( sh, 0, 0 ) ); |
254 | end.setTime( QTime( eh, 0, 0 ) ); | 255 | end.setTime( QTime( eh, 0, 0 ) ); |
255 | } | 256 | } |
256 | 257 | ||
257 | void DateBookDay::setDate( int y, int m, int d ) | 258 | void DateBookDay::setDate( int y, int m, int d ) |
258 | { | 259 | { |
259 | header->setDate( y, m, d ); | 260 | header->setDate( y, m, d ); |
260 | 261 | ||
261 | selectedWidget = 0; | 262 | selectedWidget = 0; |
262 | } | 263 | } |
263 | 264 | ||
264 | void DateBookDay::setDate( QDate d) | 265 | void DateBookDay::setDate( QDate d) |
265 | { | 266 | { |
266 | header->setDate( d.year(), d.month(), d.day() ); | 267 | header->setDate( d.year(), d.month(), d.day() ); |
267 | 268 | ||
268 | selectedWidget = 0; | 269 | selectedWidget = 0; |
269 | } | 270 | } |
270 | 271 | ||
271 | void DateBookDay::dateChanged( int y, int m, int d ) | 272 | void DateBookDay::dateChanged( int y, int m, int d ) |
272 | { | 273 | { |
273 | QDate date( y, m, d ); | 274 | QDate date( y, m, d ); |
274 | if ( currDate == date ) | 275 | if ( currDate == date ) |
275 | return; | 276 | return; |
276 | currDate.setYMD( y, m, d ); | 277 | currDate.setYMD( y, m, d ); |
277 | relayoutPage(); | 278 | relayoutPage(); |
278 | dayView()->clearSelection(); | 279 | dayView()->clearSelection(); |
279 | QTableSelection ts; | 280 | QTableSelection ts; |
280 | 281 | ||
281 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 282 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
282 | { | 283 | { |
283 | ts.init( QTime::currentTime().hour(), 0); | 284 | ts.init( QTime::currentTime().hour(), 0); |
284 | ts.expandTo( QTime::currentTime().hour(), 0); | 285 | ts.expandTo( QTime::currentTime().hour(), 0); |
285 | } else | 286 | } else |
286 | { | 287 | { |
@@ -469,328 +470,328 @@ void DateBookDay::relayoutPage( bool fromResize ) | |||
469 | if ( xp != -1 ) { | 470 | if ( xp != -1 ) { |
470 | QRect geom = w->geometry(); | 471 | QRect geom = w->geometry(); |
471 | geom.setX( xp*(wid+2) ); | 472 | geom.setX( xp*(wid+2) ); |
472 | geom.setWidth( wid ); | 473 | geom.setWidth( wid ); |
473 | w->setGeometry( geom ); | 474 | w->setGeometry( geom ); |
474 | } | 475 | } |
475 | } | 476 | } |
476 | 477 | ||
477 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 478 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
478 | 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 |
479 | else | 480 | else |
480 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); | 481 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); |
481 | } | 482 | } |
482 | 483 | ||
483 | timeMarker->setTime( QTime::currentTime() );//display timeMarker | 484 | timeMarker->setTime( QTime::currentTime() );//display timeMarker |
484 | timeMarker->raise(); //on top of all widgets | 485 | timeMarker->raise(); //on top of all widgets |
485 | if (this->date() == QDate::currentDate()) //only show timeMarker on current day | 486 | if (this->date() == QDate::currentDate()) //only show timeMarker on current day |
486 | timeMarker->show(); else timeMarker->hide(); | 487 | timeMarker->show(); else timeMarker->hide(); |
487 | 488 | ||
488 | setUpdatesEnabled( TRUE ); | 489 | setUpdatesEnabled( TRUE ); |
489 | return; | 490 | return; |
490 | } | 491 | } |
491 | 492 | ||
492 | DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) | 493 | DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) |
493 | { | 494 | { |
494 | int i = 0; | 495 | int i = 0; |
495 | DateBookDayWidget *w = widgetList.at(i); | 496 | DateBookDayWidget *w = widgetList.at(i); |
496 | int wCount = widgetList.count(); | 497 | int wCount = widgetList.count(); |
497 | while ( i < wCount && w != item ) { | 498 | while ( i < wCount && w != item ) { |
498 | if ( w->geometry().intersects( geom ) ) { | 499 | if ( w->geometry().intersects( geom ) ) { |
499 | return w; | 500 | return w; |
500 | } | 501 | } |
501 | w = widgetList.at(++i); | 502 | w = widgetList.at(++i); |
502 | } | 503 | } |
503 | 504 | ||
504 | return 0; | 505 | return 0; |
505 | } | 506 | } |
506 | 507 | ||
507 | 508 | ||
508 | QDate DateBookDay::date() const | 509 | QDate DateBookDay::date() const |
509 | { | 510 | { |
510 | return currDate; | 511 | return currDate; |
511 | } | 512 | } |
512 | 513 | ||
513 | void DateBookDay::setStartViewTime( int startHere ) | 514 | void DateBookDay::setStartViewTime( int startHere ) |
514 | { | 515 | { |
515 | startTime = startHere; | 516 | startTime = startHere; |
516 | dayView()->clearSelection(); | 517 | dayView()->clearSelection(); |
517 | QTableSelection ts; | 518 | QTableSelection ts; |
518 | 519 | ||
519 | 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? |
520 | { | 521 | { |
521 | ts.init( QTime::currentTime().hour(), 0); | 522 | ts.init( QTime::currentTime().hour(), 0); |
522 | ts.expandTo( QTime::currentTime().hour(), 0); | 523 | ts.expandTo( QTime::currentTime().hour(), 0); |
523 | } else | 524 | } else |
524 | { | 525 | { |
525 | ts.init( startTime, 0 ); | 526 | ts.init( startTime, 0 ); |
526 | ts.expandTo( startTime, 0 ); | 527 | ts.expandTo( startTime, 0 ); |
527 | } | 528 | } |
528 | 529 | ||
529 | dayView()->addSelection( ts ); | 530 | dayView()->addSelection( ts ); |
530 | } | 531 | } |
531 | 532 | ||
532 | int DateBookDay::startViewTime() const | 533 | int DateBookDay::startViewTime() const |
533 | { | 534 | { |
534 | return startTime; | 535 | return startTime; |
535 | } | 536 | } |
536 | 537 | ||
537 | void DateBookDay::slotWeekChanged( bool bStartOnMonday ) | 538 | void DateBookDay::slotWeekChanged( bool bStartOnMonday ) |
538 | { | 539 | { |
539 | header->setStartOfWeek( bStartOnMonday ); | 540 | header->setStartOfWeek( bStartOnMonday ); |
540 | // redraw(); | 541 | // redraw(); |
541 | } | 542 | } |
542 | 543 | ||
543 | void DateBookDay::keyPressEvent(QKeyEvent *e) | 544 | void DateBookDay::keyPressEvent(QKeyEvent *e) |
544 | { | 545 | { |
545 | switch(e->key()) { | 546 | switch(e->key()) { |
546 | case Key_Up: | 547 | case Key_Up: |
547 | view->moveUp(); | 548 | view->moveUp(); |
548 | break; | 549 | break; |
549 | case Key_Down: | 550 | case Key_Down: |
550 | view->moveDown(); | 551 | view->moveDown(); |
551 | break; | 552 | break; |
552 | case Key_Left: | 553 | case Key_Left: |
553 | setDate(QDate(currDate).addDays(-1)); | 554 | setDate(QDate(currDate).addDays(-1)); |
554 | break; | 555 | break; |
555 | case Key_Right: | 556 | case Key_Right: |
556 | setDate(QDate(currDate).addDays(1)); | 557 | setDate(QDate(currDate).addDays(1)); |
557 | break; | 558 | break; |
558 | default: | 559 | default: |
559 | e->ignore(); | 560 | e->ignore(); |
560 | } | 561 | } |
561 | } | 562 | } |
562 | 563 | ||
563 | //=========================================================================== | 564 | //=========================================================================== |
564 | 565 | ||
565 | DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, | 566 | DateBookDayWidget::DateBookDayWidget( const EffectiveEvent &e, |
566 | DateBookDay *db ) | 567 | DateBookDay *db ) |
567 | : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) | 568 | : QWidget( db->dayView()->viewport() ), ev( e ), dateBook( db ) |
568 | { | 569 | { |
569 | 570 | ||
570 | 571 | ||
571 | // why would someone use "<"? Oh well, fix it up... | 572 | // why would someone use "<"? Oh well, fix it up... |
572 | // I wonder what other things may be messed up... | 573 | // I wonder what other things may be messed up... |
573 | QString strDesc = ev.description(); | 574 | QString strDesc = ev.description(); |
574 | int where = strDesc.find( "<" ); | 575 | int where = strDesc.find( "<" ); |
575 | while ( where != -1 ) { | 576 | while ( where != -1 ) { |
576 | strDesc.remove( where, 1 ); | 577 | strDesc.remove( where, 1 ); |
577 | strDesc.insert( where, "<" ); | 578 | strDesc.insert( where, "<" ); |
578 | where = strDesc.find( "<", where ); | 579 | where = strDesc.find( "<", where ); |
579 | } | 580 | } |
580 | 581 | ||
581 | QString strCat; | 582 | QString strCat; |
582 | // ### Fix later... | 583 | // ### Fix later... |
583 | // QString strCat = ev.category(); | 584 | // QString strCat = ev.category(); |
584 | // where = strCat.find( "<" ); | 585 | // where = strCat.find( "<" ); |
585 | // while ( where != -1 ) { | 586 | // while ( where != -1 ) { |
586 | // strCat.remove( where, 1 ); | 587 | // strCat.remove( where, 1 ); |
587 | // strCat.insert( where, "<" ); | 588 | // strCat.insert( where, "<" ); |
588 | // where = strCat.find( "<", where ); | 589 | // where = strCat.find( "<", where ); |
589 | // } | 590 | // } |
590 | 591 | ||
591 | QString strNote = ev.notes(); | 592 | QString strNote = ev.notes(); |
592 | where = strNote.find( "<" ); | 593 | where = strNote.find( "<" ); |
593 | while ( where != -1 ) { | 594 | while ( where != -1 ) { |
594 | strNote.remove( where, 1 ); | 595 | strNote.remove( where, 1 ); |
595 | strNote.insert( where, "<" ); | 596 | strNote.insert( where, "<" ); |
596 | where = strNote.find( "<", where ); | 597 | where = strNote.find( "<", where ); |
597 | } | 598 | } |
598 | 599 | ||
599 | text = "<b>" + strDesc + "</b><br>" + "<i>" | 600 | text = "<b>" + strDesc + "</b><br>" + "<i>" |
600 | + strCat + "</i><br>"; | 601 | + strCat + "</i><br>"; |
601 | if (ev.event().type() == Event::Normal ) | 602 | if (ev.event().type() == Event::Normal ) |
602 | setEventText( text ); | 603 | setEventText( text ); |
603 | else | 604 | else |
604 | setAllDayText( text ); | 605 | setAllDayText( text ); |
605 | 606 | ||
606 | text += "<br><br>" + strNote; | 607 | text += "<br><br>" + strNote; |
607 | 608 | ||
608 | setBackgroundMode( PaletteBase ); | 609 | setBackgroundMode( PaletteBase ); |
609 | 610 | ||
610 | QTime start = ev.start(); | 611 | QTime start = ev.start(); |
611 | QTime end = ev.end(); | 612 | QTime end = ev.end(); |
612 | int y = start.hour()*60+start.minute(); | 613 | int y = start.hour()*60+start.minute(); |
613 | int h = end.hour()*60+end.minute()-y; | 614 | int h = end.hour()*60+end.minute()-y; |
614 | int rh = dateBook->dayView()->rowHeight(0); | 615 | int rh = dateBook->dayView()->rowHeight(0); |
615 | y = y*rh/60; | 616 | y = y*rh/60; |
616 | h = h*rh/60; | 617 | h = h*rh/60; |
617 | if ( h < 3 ) | 618 | if ( h < 3 ) |
618 | h = 3; | 619 | h = 3; |
619 | geom.setY( y ); | 620 | geom.setY( y ); |
620 | geom.setHeight( h ); | 621 | geom.setHeight( h ); |
621 | geom.setX( 0 ); | 622 | geom.setX( 0 ); |
622 | geom.setWidth(dateBook->dayView()->columnWidth(0)-1); | 623 | geom.setWidth(dateBook->dayView()->columnWidth(0)-1); |
623 | 624 | ||
624 | } | 625 | } |
625 | void DateBookDayWidget::setAllDayText( QString &text ) { | 626 | void DateBookDayWidget::setAllDayText( QString &text ) { |
626 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; | 627 | text += "<b>" + tr("This is an all day event.") + "</b><br>"; |
627 | } | 628 | } |
628 | void DateBookDayWidget::setEventText( QString& text ) { | 629 | void DateBookDayWidget::setEventText( QString& text ) { |
629 | bool whichClock = dateBook->dayView()->whichClock(); | 630 | bool whichClock = dateBook->dayView()->whichClock(); |
630 | text += "<b>" + tr("Start") + "</b>: "; | 631 | text += "<b>" + tr("Start") + "</b>: "; |
631 | if ( ev.startDate() != ev.date() ) { | 632 | if ( ev.startDate() != ev.date() ) { |
632 | // multi-day event. Show start date | 633 | // multi-day event. Show start date |
633 | text += TimeString::longDateString( ev.startDate() ); | 634 | text += TimeString::longDateString( ev.startDate() ); |
634 | } else { | 635 | } else { |
635 | // Show start time. | 636 | // Show start time. |
636 | text += TimeString::timeString( ev.start(), whichClock, FALSE ); | 637 | text += TimeString::timeString( ev.start(), whichClock, FALSE ); |
637 | } | 638 | } |
638 | 639 | ||
639 | text += "<br><b>" + tr("End") + "</b>: "; | 640 | text += "<br><b>" + tr("End") + "</b>: "; |
640 | if ( ev.endDate() != ev.date() ) { | 641 | if ( ev.endDate() != ev.date() ) { |
641 | // multi-day event. Show end date | 642 | // multi-day event. Show end date |
642 | text += TimeString::longDateString( ev.endDate() ); | 643 | text += TimeString::longDateString( ev.endDate() ); |
643 | } else { | 644 | } else { |
644 | // Show end time. | 645 | // Show end time. |
645 | text += TimeString::timeString( ev.end(), whichClock, FALSE ); | 646 | text += TimeString::timeString( ev.end(), whichClock, FALSE ); |
646 | } | 647 | } |
647 | 648 | ||
648 | } | 649 | } |
649 | 650 | ||
650 | DateBookDayWidget::~DateBookDayWidget() | 651 | DateBookDayWidget::~DateBookDayWidget() |
651 | { | 652 | { |
652 | } | 653 | } |
653 | 654 | ||
654 | void DateBookDayWidget::paintEvent( QPaintEvent *e ) | 655 | void DateBookDayWidget::paintEvent( QPaintEvent *e ) |
655 | { | 656 | { |
656 | QPainter p( this ); | 657 | QPainter p( this ); |
657 | 658 | ||
658 | if (dateBook->getSelectedWidget() == this) | 659 | if (dateBook->getSelectedWidget() == this) |
659 | { | 660 | { |
660 | p.setBrush( QColor( 155, 240, 230 ) ); // selected item | 661 | p.setBrush( QColor( 155, 240, 230 ) ); // selected item |
661 | } else | 662 | } else |
662 | { | 663 | { |
663 | if (dateBook->date() == QDate::currentDate()) | 664 | if (dateBook->date() == QDate::currentDate()) |
664 | { | 665 | { |
665 | QTime curTime = QTime::currentTime(); | 666 | QTime curTime = QTime::currentTime(); |
666 | 667 | ||
667 | if (ev.end() < curTime) | 668 | if (ev.end() < curTime) |
668 | { | 669 | { |
669 | p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive | 670 | p.setBrush( QColor( 180, 180, 180 ) ); // grey, inactive |
670 | } else | 671 | } else |
671 | { | 672 | { |
672 | //change color in dependence of the time till the event starts | 673 | //change color in dependence of the time till the event starts |
673 | int duration = curTime.secsTo(ev.start()); | 674 | int duration = curTime.secsTo(ev.start()); |
674 | if (duration < 0) duration = 0; | 675 | if (duration < 0) duration = 0; |
675 | 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 |
676 | 677 | ||
677 | p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue | 678 | p.setBrush( QColor( 200-colChange, 200-colChange, 255 ) ); //blue |
678 | } | 679 | } |
679 | } else | 680 | } else |
680 | { | 681 | { |
681 | 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) |
682 | //perhaps make a distinction between future/past dates | 683 | //perhaps make a distinction between future/past dates |
683 | } | 684 | } |
684 | } | 685 | } |
685 | 686 | ||
686 | p.setPen( QColor(100, 100, 100) ); | 687 | p.setPen( QColor(100, 100, 100) ); |
687 | p.drawRect(rect()); | 688 | p.drawRect(rect()); |
688 | 689 | ||
689 | // p.drawRect(0,0, 5, height()); | 690 | // p.drawRect(0,0, 5, height()); |
690 | 691 | ||
691 | int y = 0; | 692 | int y = 0; |
692 | int d = 0; | 693 | int d = 0; |
693 | 694 | ||
694 | if ( ev.event().hasAlarm() ) { | 695 | if ( ev.event().hasAlarm() ) { |
695 | p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); | 696 | p.drawPixmap( width() - 16, 0, Resource::loadPixmap( "bell" ) ); |
696 | y = 20; | 697 | y = 20; |
697 | d = 20; | 698 | d = 20; |
698 | } | 699 | } |
699 | 700 | ||
700 | if ( ev.event().hasRepeat() ) { | 701 | if ( ev.event().hasRepeat() ) { |
701 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); | 702 | p.drawPixmap( width() - 16, y, Resource::loadPixmap( "repeat" ) ); |
702 | d = 20; | 703 | d = 20; |
703 | y += 20; | 704 | y += 20; |
704 | } | 705 | } |
705 | 706 | ||
706 | QSimpleRichText rt( text, font() ); | 707 | QSimpleRichText rt( text, font() ); |
707 | rt.setWidth( geom.width() - d - 6 ); | 708 | rt.setWidth( geom.width() - d - 6 ); |
708 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); | 709 | rt.draw( &p, 7, 0, e->region(), colorGroup() ); |
709 | } | 710 | } |
710 | 711 | ||
711 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) | 712 | void DateBookDayWidget::mousePressEvent( QMouseEvent *e ) |
712 | { | 713 | { |
713 | DateBookDayWidget *item; | 714 | DateBookDayWidget *item; |
714 | 715 | ||
715 | item = dateBook->getSelectedWidget(); | 716 | item = dateBook->getSelectedWidget(); |
716 | if (item) item->update(); | 717 | if (item) item->update(); |
717 | 718 | ||
718 | dateBook->setSelectedWidget(this); | 719 | dateBook->setSelectedWidget(this); |
719 | update(); | 720 | update(); |
720 | dateBook->repaint(); | 721 | dateBook->repaint(); |
721 | 722 | ||
722 | QPopupMenu m; | 723 | QPopupMenu m; |
723 | m.insertItem( tr( "Edit" ), 1 ); | 724 | m.insertItem( tr( "Edit" ), 1 ); |
724 | m.insertItem( tr( "Delete" ), 2 ); | 725 | m.insertItem( tr( "Delete" ), 2 ); |
725 | m.insertItem( tr( "Beam" ), 3 ); | 726 | if(Ir::supported()) m.insertItem( tr( "Beam" ), 3 ); |
726 | int r = m.exec( e->globalPos() ); | 727 | int r = m.exec( e->globalPos() ); |
727 | if ( r == 1 ) { | 728 | if ( r == 1 ) { |
728 | emit editMe( ev.event() ); | 729 | emit editMe( ev.event() ); |
729 | } else if ( r == 2 ) { | 730 | } else if ( r == 2 ) { |
730 | emit deleteMe( ev.event() ); | 731 | emit deleteMe( ev.event() ); |
731 | } else if ( r == 3 ) { | 732 | } else if ( r == 3 ) { |
732 | emit beamMe( ev.event() ); | 733 | emit beamMe( ev.event() ); |
733 | } | 734 | } |
734 | } | 735 | } |
735 | 736 | ||
736 | void DateBookDayWidget::setGeometry( const QRect &r ) | 737 | void DateBookDayWidget::setGeometry( const QRect &r ) |
737 | { | 738 | { |
738 | geom = r; | 739 | geom = r; |
739 | setFixedSize( r.width()+1, r.height()+1 ); | 740 | setFixedSize( r.width()+1, r.height()+1 ); |
740 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); | 741 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); |
741 | show(); | 742 | show(); |
742 | } | 743 | } |
743 | 744 | ||
744 | 745 | ||
745 | //--------------------------------------------------------------------------------------------- | 746 | //--------------------------------------------------------------------------------------------- |
746 | //--------------------------------------------------------------------------------------------- | 747 | //--------------------------------------------------------------------------------------------- |
747 | 748 | ||
748 | 749 | ||
749 | DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) | 750 | DateBookDayTimeMarker::DateBookDayTimeMarker( DateBookDay *db ) |
750 | : QWidget( db->dayView()->viewport() ), dateBook( db ) | 751 | : QWidget( db->dayView()->viewport() ), dateBook( db ) |
751 | { | 752 | { |
752 | setBackgroundMode( PaletteBase ); | 753 | setBackgroundMode( PaletteBase ); |
753 | } | 754 | } |
754 | 755 | ||
755 | DateBookDayTimeMarker::~DateBookDayTimeMarker() | 756 | DateBookDayTimeMarker::~DateBookDayTimeMarker() |
756 | { | 757 | { |
757 | } | 758 | } |
758 | 759 | ||
759 | void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) | 760 | void DateBookDayTimeMarker::paintEvent( QPaintEvent */*e*/ ) |
760 | { | 761 | { |
761 | QPainter p( this ); | 762 | QPainter p( this ); |
762 | p.setBrush( QColor( 255, 0, 0 ) ); | 763 | p.setBrush( QColor( 255, 0, 0 ) ); |
763 | 764 | ||
764 | QPen pen; | 765 | QPen pen; |
765 | pen.setStyle(NoPen); | 766 | pen.setStyle(NoPen); |
766 | 767 | ||
767 | p.setPen( pen ); | 768 | p.setPen( pen ); |
768 | p.drawRect(rect()); | 769 | p.drawRect(rect()); |
769 | } | 770 | } |
770 | 771 | ||
771 | void DateBookDayTimeMarker::setTime( const QTime &t ) | 772 | void DateBookDayTimeMarker::setTime( const QTime &t ) |
772 | { | 773 | { |
773 | int y = t.hour()*60+t.minute(); | 774 | int y = t.hour()*60+t.minute(); |
774 | int rh = dateBook->dayView()->rowHeight(0); | 775 | int rh = dateBook->dayView()->rowHeight(0); |
775 | y = y*rh/60; | 776 | y = y*rh/60; |
776 | 777 | ||
777 | geom.setX( 0 ); | 778 | geom.setX( 0 ); |
778 | 779 | ||
779 | int x = dateBook->dayView()->columnWidth(0)-1; | 780 | int x = dateBook->dayView()->columnWidth(0)-1; |
780 | geom.setWidth( x ); | 781 | geom.setWidth( x ); |
781 | 782 | ||
782 | geom.setY( y ); | 783 | geom.setY( y ); |
783 | geom.setHeight( 1 ); | 784 | geom.setHeight( 1 ); |
784 | 785 | ||
785 | setGeometry( geom ); | 786 | setGeometry( geom ); |
786 | 787 | ||
787 | time = t; | 788 | time = t; |
788 | } | 789 | } |
789 | 790 | ||
790 | void DateBookDayTimeMarker::setGeometry( const QRect &r ) | 791 | void DateBookDayTimeMarker::setGeometry( const QRect &r ) |
791 | { | 792 | { |
792 | geom = r; | 793 | geom = r; |
793 | setFixedSize( r.width()+1, r.height()+1 ); | 794 | setFixedSize( r.width()+1, r.height()+1 ); |
794 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); | 795 | dateBook->dayView()->moveChild( this, r.x(), r.y()-1 ); |
795 | show(); | 796 | show(); |
796 | } | 797 | } |