-rw-r--r-- | core/pim/datebook/datebookday.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index e212807..8232a51 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp | |||
@@ -1,582 +1,582 @@ | |||
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 <qlineedit.h> | 41 | #include <qlineedit.h> |
42 | 42 | ||
43 | #include <qtimer.h> | 43 | #include <qtimer.h> |
44 | 44 | ||
45 | DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name ) | 45 | DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name ) |
46 | : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() ) | 46 | : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() ) |
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 | 66 | ||
67 | initHeader(); | 67 | initHeader(); |
68 | QObject::connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool)) ); | 68 | QObject::connect( qApp, SIGNAL(clockChanged(bool)), 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::slotDateChanged( int y, int m, int d ) | 96 | void DateBookDayView::slotDateChanged( int y, int m, int d ) |
97 | { | 97 | { |
98 | currDate.setYMD(y,m,d); | 98 | currDate.setYMD(y,m,d); |
99 | } | 99 | } |
100 | 100 | ||
101 | void DateBookDayView::slotChangeClock( bool newClock ) | 101 | void DateBookDayView::slotChangeClock( bool newClock ) |
102 | { | 102 | { |
103 | ampm = newClock; | 103 | ampm = newClock; |
104 | initHeader(); | 104 | initHeader(); |
105 | } | 105 | } |
106 | 106 | ||
107 | bool DateBookDayView::whichClock() const | 107 | bool DateBookDayView::whichClock() const |
108 | { | 108 | { |
109 | return ampm; | 109 | return ampm; |
110 | } | 110 | } |
111 | 111 | ||
112 | void DateBookDayView::moveUp() | 112 | void DateBookDayView::moveUp() |
113 | { | 113 | { |
114 | scrollBy(0, -20); | 114 | scrollBy(0, -20); |
115 | } | 115 | } |
116 | 116 | ||
117 | void DateBookDayView::moveDown() | 117 | void DateBookDayView::moveDown() |
118 | { | 118 | { |
119 | scrollBy(0, 20); | 119 | scrollBy(0, 20); |
120 | } | 120 | } |
121 | 121 | ||
122 | void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) | 122 | void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) |
123 | { | 123 | { |
124 | int w = cr.width(); | 124 | int w = cr.width(); |
125 | int h = cr.height(); | 125 | int h = cr.height(); |
126 | p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); | 126 | p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); |
127 | if ( showGrid() ) { | 127 | if ( showGrid() ) { |
128 | // Draw our lines | 128 | // Draw our lines |
129 | int x2 = w - 1; | 129 | int x2 = w - 1; |
130 | int y2 = h - 1; | 130 | int y2 = h - 1; |
131 | QPen pen( p->pen() ); | 131 | QPen pen( p->pen() ); |
132 | p->setPen( colorGroup().dark() ); | 132 | p->setPen( colorGroup().dark() ); |
133 | p->drawLine( x2, 0, x2, y2 ); | 133 | p->drawLine( x2, 0, x2, y2 ); |
134 | p->drawLine( 0, y2, x2, y2 ); | 134 | p->drawLine( 0, y2, x2, y2 ); |
135 | 135 | ||
136 | p->setPen( colorGroup().midlight() ); | 136 | p->setPen( colorGroup().midlight() ); |
137 | p->drawLine( 0, y2 - h/2, x2, y2 - h/2); | 137 | p->drawLine( 0, y2 - h/2, x2, y2 - h/2); |
138 | 138 | ||
139 | p->setPen( pen ); | 139 | p->setPen( pen ); |
140 | } | 140 | } |
141 | } | 141 | } |
142 | 142 | ||
143 | void DateBookDayView::paintFocus( QPainter *, const QRect & ) | 143 | void DateBookDayView::paintFocus( QPainter *, const QRect & ) |
144 | { | 144 | { |
145 | } | 145 | } |
146 | 146 | ||
147 | void DateBookDayView::resizeEvent( QResizeEvent *e ) | 147 | void DateBookDayView::resizeEvent( QResizeEvent *e ) |
148 | { | 148 | { |
149 | QTable::resizeEvent( e ); | 149 | QTable::resizeEvent( e ); |
150 | columnWidthChanged( 0 ); | 150 | columnWidthChanged( 0 ); |
151 | emit sigColWidthChanged(); | 151 | emit sigColWidthChanged(); |
152 | } | 152 | } |
153 | 153 | ||
154 | void DateBookDayView::keyPressEvent( QKeyEvent *e ) | 154 | void DateBookDayView::keyPressEvent( QKeyEvent *e ) |
155 | { | 155 | { |
156 | QString txt = e->text(); | 156 | QString txt = e->text(); |
157 | if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { | 157 | if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { |
158 | // we this is some sort of thing we know about... | 158 | // we this is some sort of thing we know about... |
159 | e->accept(); | 159 | e->accept(); |
160 | emit sigCapturedKey( txt ); | 160 | emit sigCapturedKey( txt ); |
161 | } else { | 161 | } else { |
162 | // I don't know what this key is, do you? | 162 | // I don't know what this key is, do you? |
163 | e->ignore(); | 163 | e->ignore(); |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | void DateBookDayView::setRowStyle( int style ) | 167 | void DateBookDayView::setRowStyle( int style ) |
168 | { | 168 | { |
169 | if (style<0) style = 0; | 169 | if (style<0) style = 0; |
170 | 170 | ||
171 | for (int i=0; i<numRows(); i++) | 171 | for (int i=0; i<numRows(); i++) |
172 | setRowHeight(i, style*10+20); | 172 | setRowHeight(i, style*10+20); |
173 | } | 173 | } |
174 | 174 | ||
175 | void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent *e ) | 175 | void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent *e ) |
176 | { | 176 | { |
177 | int sh=99,eh=-1; | 177 | int sh=99,eh=-1; |
178 | 178 | ||
179 | for(int i=0;i<this->numSelections();i++) { | 179 | for(int i=0;i<this->numSelections();i++) { |
180 | QTableSelection sel = this->selection( i ); | 180 | QTableSelection sel = this->selection( i ); |
181 | sh = QMIN(sh,sel.topRow()); | 181 | sh = QMIN(sh,sel.topRow()); |
182 | eh = QMAX(sh,sel.bottomRow()+1); | 182 | eh = QMAX(sh,sel.bottomRow()+1); |
183 | } | 183 | } |
184 | if (sh > 23 || eh < 1) { | 184 | if (sh > 23 || eh < 1) { |
185 | sh=8; | 185 | sh=8; |
186 | eh=9; | 186 | eh=9; |
187 | } | 187 | } |
188 | 188 | ||
189 | quickLineEdit=new DateBookDayViewQuickLineEdit(QDateTime(currDate,QTime(sh,0,0,0)),QDateTime(currDate,QTime(eh,0,0,0)),this->viewport(),"quickedit"); | 189 | quickLineEdit=new DateBookDayViewQuickLineEdit(QDateTime(currDate,QTime(sh,0,0,0)),QDateTime(currDate,QTime(eh,0,0,0)),this->viewport(),"quickedit"); |
190 | quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0)); | 190 | quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0)); |
191 | this->moveChild(quickLineEdit,0,sh*this->rowHeight(0)); | 191 | this->moveChild(quickLineEdit,0,sh*this->rowHeight(0)); |
192 | quickLineEdit->setFocus(); | 192 | quickLineEdit->setFocus(); |
193 | quickLineEdit->show(); | 193 | quickLineEdit->show(); |
194 | } | 194 | } |
195 | 195 | ||
196 | //=========================================================================== | 196 | //=========================================================================== |
197 | 197 | ||
198 | DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name=0) : QLineEdit(parent,name) | 198 | DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name) : QLineEdit(parent,name) |
199 | { | 199 | { |
200 | active=1; | 200 | active=1; |
201 | quickEvent.setStart(start); | 201 | quickEvent.setStart(start); |
202 | quickEvent.setEnd(end); | 202 | quickEvent.setEnd(end); |
203 | connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed())); | 203 | connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed())); |
204 | } | 204 | } |
205 | 205 | ||
206 | void DateBookDayViewQuickLineEdit::slotReturnPressed() | 206 | void DateBookDayViewQuickLineEdit::slotReturnPressed() |
207 | { | 207 | { |
208 | if(active && (!this->text().isEmpty())) {// Fix to avoid having this event beeing added multiple times. | 208 | if(active && (!this->text().isEmpty())) {// Fix to avoid having this event beeing added multiple times. |
209 | quickEvent.setDescription(this->text()); | 209 | quickEvent.setDescription(this->text()); |
210 | connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &))); | 210 | connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &))); |
211 | emit(insertEvent(quickEvent)); | 211 | emit(insertEvent(quickEvent)); |
212 | active=0; | 212 | active=0; |
213 | } | 213 | } |
214 | this->close(true);// Close and also delete this widget | 214 | this->close(true);// Close and also delete this widget |
215 | } | 215 | } |
216 | 216 | ||
217 | void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent * e ) | 217 | void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent * e ) |
218 | { | 218 | { |
219 | slotReturnPressed(); // Reuse code to add event and close this widget. | 219 | slotReturnPressed(); // Reuse code to add event and close this widget. |
220 | } | 220 | } |
221 | 221 | ||
222 | //=========================================================================== | 222 | //=========================================================================== |
223 | 223 | ||
224 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name ) | 224 | DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name ) |
225 | : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) | 225 | : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) |
226 | { | 226 | { |
227 | widgetList.setAutoDelete( true ); | 227 | widgetList.setAutoDelete( true ); |
228 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); | 228 | header = new DateBookDayHeader( startOnMonday, this, "day header" ); |
229 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); | 229 | header->setDate( currDate.year(), currDate.month(), currDate.day() ); |
230 | view = new DateBookDayView( ampm, this, "day view" ); | 230 | view = new DateBookDayView( ampm, this, "day view" ); |
231 | 231 | ||
232 | connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) ); | 232 | connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) ); |
233 | connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) ); | 233 | connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) ); |
234 | connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); | 234 | connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); |
235 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); | 235 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); |
236 | connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) ); | 236 | connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) ); |
237 | 237 | ||
238 | QTimer *timer = new QTimer( this ); | 238 | QTimer *timer = new QTimer( this ); |
239 | 239 | ||
240 | connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors | 240 | connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) );//connect timer for updating timeMarker & daywidgetcolors |
241 | timer->start( 1000*60*5, FALSE ); //update every 5min | 241 | timer->start( 1000*60*5, FALSE ); //update every 5min |
242 | 242 | ||
243 | selectedWidget = 0; | 243 | selectedWidget = 0; |
244 | 244 | ||
245 | timeMarker = new DateBookDayTimeMarker( this ); | 245 | timeMarker = new DateBookDayTimeMarker( this ); |
246 | timeMarker->setTime( QTime::currentTime() ); | 246 | timeMarker->setTime( QTime::currentTime() ); |
247 | rowStyle = -1; // initialize with bogus values | 247 | rowStyle = -1; // initialize with bogus values |
248 | } | 248 | } |
249 | 249 | ||
250 | void DateBookDay::setJumpToCurTime( bool bJump ) | 250 | void DateBookDay::setJumpToCurTime( bool bJump ) |
251 | { | 251 | { |
252 | jumpToCurTime = bJump; | 252 | jumpToCurTime = bJump; |
253 | } | 253 | } |
254 | 254 | ||
255 | void DateBookDay::setRowStyle( int style ) | 255 | void DateBookDay::setRowStyle( int style ) |
256 | { | 256 | { |
257 | if (rowStyle != style) view->setRowStyle( style ); | 257 | if (rowStyle != style) view->setRowStyle( style ); |
258 | rowStyle = style; | 258 | rowStyle = style; |
259 | } | 259 | } |
260 | 260 | ||
261 | void DateBookDay::updateView( void ) | 261 | void DateBookDay::updateView( void ) |
262 | { | 262 | { |
263 | timeMarker->setTime( QTime::currentTime() ); | 263 | timeMarker->setTime( QTime::currentTime() ); |
264 | //need to find a way to update all DateBookDayWidgets | 264 | //need to find a way to update all DateBookDayWidgets |
265 | } | 265 | } |
266 | 266 | ||
267 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) | 267 | void DateBookDay::setSelectedWidget( DateBookDayWidget *w ) |
268 | { | 268 | { |
269 | selectedWidget = w; | 269 | selectedWidget = w; |
270 | } | 270 | } |
271 | 271 | ||
272 | DateBookDayWidget * DateBookDay::getSelectedWidget( void ) | 272 | DateBookDayWidget * DateBookDay::getSelectedWidget( void ) |
273 | { | 273 | { |
274 | return selectedWidget; | 274 | return selectedWidget; |
275 | } | 275 | } |
276 | 276 | ||
277 | void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) | 277 | void DateBookDay::selectedDates( QDateTime &start, QDateTime &end ) |
278 | { | 278 | { |
279 | start.setDate( currDate ); | 279 | start.setDate( currDate ); |
280 | end.setDate( currDate ); | 280 | end.setDate( currDate ); |
281 | 281 | ||
282 | int sh=99,eh=-1; | 282 | int sh=99,eh=-1; |
283 | 283 | ||
284 | int n = dayView()->numSelections(); | 284 | int n = dayView()->numSelections(); |
285 | 285 | ||
286 | for (int i=0; i<n; i++) { | 286 | for (int i=0; i<n; i++) { |
287 | QTableSelection sel = dayView()->selection( i ); | 287 | QTableSelection sel = dayView()->selection( i ); |
288 | sh = QMIN(sh,sel.topRow()); | 288 | sh = QMIN(sh,sel.topRow()); |
289 | eh = QMAX(sh,sel.bottomRow()+1); | 289 | eh = QMAX(sh,sel.bottomRow()+1); |
290 | } | 290 | } |
291 | 291 | ||
292 | if (sh > 23 || eh < 1) { | 292 | if (sh > 23 || eh < 1) { |
293 | sh=8; | 293 | sh=8; |
294 | eh=9; | 294 | eh=9; |
295 | } | 295 | } |
296 | 296 | ||
297 | start.setTime( QTime( sh, 0, 0 ) ); | 297 | start.setTime( QTime( sh, 0, 0 ) ); |
298 | end.setTime( QTime( eh, 0, 0 ) ); | 298 | end.setTime( QTime( eh, 0, 0 ) ); |
299 | } | 299 | } |
300 | 300 | ||
301 | void DateBookDay::setDate( int y, int m, int d ) | 301 | void DateBookDay::setDate( int y, int m, int d ) |
302 | { | 302 | { |
303 | header->setDate( y, m, d ); | 303 | header->setDate( y, m, d ); |
304 | selectedWidget = 0; | 304 | selectedWidget = 0; |
305 | } | 305 | } |
306 | 306 | ||
307 | void DateBookDay::setDate( QDate d) | 307 | void DateBookDay::setDate( QDate d) |
308 | { | 308 | { |
309 | header->setDate( d.year(), d.month(), d.day() ); | 309 | header->setDate( d.year(), d.month(), d.day() ); |
310 | selectedWidget = 0; | 310 | selectedWidget = 0; |
311 | } | 311 | } |
312 | 312 | ||
313 | void DateBookDay::dateChanged( int y, int m, int d ) | 313 | void DateBookDay::dateChanged( int y, int m, int d ) |
314 | { | 314 | { |
315 | QDate date( y, m, d ); | 315 | QDate date( y, m, d ); |
316 | if ( currDate == date ) | 316 | if ( currDate == date ) |
317 | return; | 317 | return; |
318 | currDate.setYMD( y, m, d ); | 318 | currDate.setYMD( y, m, d ); |
319 | relayoutPage(); | 319 | relayoutPage(); |
320 | dayView()->clearSelection(); | 320 | dayView()->clearSelection(); |
321 | QTableSelection ts; | 321 | QTableSelection ts; |
322 | 322 | ||
323 | if (jumpToCurTime && this->date() == QDate::currentDate()) | 323 | if (jumpToCurTime && this->date() == QDate::currentDate()) |
324 | { | 324 | { |
325 | ts.init( QTime::currentTime().hour(), 0); | 325 | ts.init( QTime::currentTime().hour(), 0); |
326 | ts.expandTo( QTime::currentTime().hour(), 0); | 326 | ts.expandTo( QTime::currentTime().hour(), 0); |
327 | } else { | 327 | } else { |
328 | ts.init( startTime, 0 ); | 328 | ts.init( startTime, 0 ); |
329 | ts.expandTo( startTime, 0 ); | 329 | ts.expandTo( startTime, 0 ); |
330 | } | 330 | } |
331 | 331 | ||
332 | dayView()->addSelection( ts ); | 332 | dayView()->addSelection( ts ); |
333 | selectedWidget = 0; | 333 | selectedWidget = 0; |
334 | } | 334 | } |
335 | 335 | ||
336 | void DateBookDay::redraw() | 336 | void DateBookDay::redraw() |
337 | { | 337 | { |
338 | if ( isUpdatesEnabled() ) | 338 | if ( isUpdatesEnabled() ) |
339 | relayoutPage(); | 339 | relayoutPage(); |
340 | } | 340 | } |
341 | 341 | ||
342 | void DateBookDay::getEvents() | 342 | void DateBookDay::getEvents() |
343 | { | 343 | { |
344 | widgetList.clear(); | 344 | widgetList.clear(); |
345 | 345 | ||
346 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); | 346 | QValueList<EffectiveEvent> eventList = db->getEffectiveEvents( currDate, currDate ); |
347 | QValueListIterator<EffectiveEvent> it; | 347 | QValueListIterator<EffectiveEvent> it; |
348 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { | 348 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { |
349 | EffectiveEvent ev=*it; | 349 | EffectiveEvent ev=*it; |
350 | if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) {// Skip events ending at 00:00 starting at another day. | 350 | if(!((ev.end().hour()==0) && (ev.end().minute()==0) && (ev.startDate()!=ev.date()))) {// Skip events ending at 00:00 starting at another day. |
351 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); | 351 | DateBookDayWidget* w = new DateBookDayWidget( *it, this ); |
352 | connect( w, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) ); | 352 | connect( w, SIGNAL( deleteMe( const Event & ) ), this, SIGNAL( removeEvent( const Event & ) ) ); |
353 | connect( w, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) ); | 353 | connect( w, SIGNAL( duplicateMe( const Event & ) ), this, SIGNAL( duplicateEvent( const Event & ) ) ); |
354 | connect( w, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) ); | 354 | connect( w, SIGNAL( editMe( const Event & ) ), this, SIGNAL( editEvent( const Event & ) ) ); |
355 | connect( w, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) ); | 355 | connect( w, SIGNAL( beamMe( const Event & ) ), this, SIGNAL( beamEvent( const Event & ) ) ); |
356 | widgetList.append( w ); | 356 | widgetList.append( w ); |
357 | } | 357 | } |
358 | } | 358 | } |
359 | } | 359 | } |
360 | 360 | ||
361 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) | 361 | static int place( const DateBookDayWidget *item, bool *used, int maxn ) |
362 | { | 362 | { |
363 | int place = 0; | 363 | int place = 0; |
364 | int start = item->event().start().hour(); | 364 | int start = item->event().start().hour(); |
365 | QTime e = item->event().end(); | 365 | QTime e = item->event().end(); |
366 | int end = e.hour(); | 366 | int end = e.hour(); |
367 | if ( e.minute() < 5 ) | 367 | if ( e.minute() < 5 ) |
368 | end--; | 368 | end--; |
369 | if ( end < start ) | 369 | if ( end < start ) |
370 | end = start; | 370 | end = start; |
371 | while ( place < maxn ) { | 371 | while ( place < maxn ) { |
372 | bool free = TRUE; | 372 | bool free = TRUE; |
373 | int s = start; | 373 | int s = start; |
374 | while( s <= end ) { | 374 | while( s <= end ) { |
375 | if ( used[10*s+place] ) { | 375 | if ( used[10*s+place] ) { |
376 | free = FALSE; | 376 | free = FALSE; |
377 | break; | 377 | break; |
378 | } | 378 | } |
379 | s++; | 379 | s++; |
380 | } | 380 | } |
381 | if ( free ) | 381 | if ( free ) |
382 | break; | 382 | break; |
383 | place++; | 383 | place++; |
384 | } | 384 | } |
385 | if ( place == maxn ) { | 385 | if ( place == maxn ) { |
386 | return -1; | 386 | return -1; |
387 | } | 387 | } |
388 | while( start <= end ) { | 388 | while( start <= end ) { |
389 | used[10*start+place] = TRUE; | 389 | used[10*start+place] = TRUE; |
390 | start++; | 390 | start++; |
391 | } | 391 | } |
392 | return place; | 392 | return place; |
393 | } | 393 | } |
394 | 394 | ||
395 | 395 | ||
396 | void DateBookDay::relayoutPage( bool fromResize ) | 396 | void DateBookDay::relayoutPage( bool fromResize ) |
397 | { | 397 | { |
398 | setUpdatesEnabled( FALSE ); | 398 | setUpdatesEnabled( FALSE ); |
399 | if ( !fromResize ) | 399 | if ( !fromResize ) |
400 | getEvents(); // no need we already have them! | 400 | getEvents(); // no need we already have them! |
401 | 401 | ||
402 | widgetList.sort(); | 402 | widgetList.sort(); |
403 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning | 403 | //sorts the widgetList by the heights of the widget so that the tallest widgets are at the beginning |
404 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view | 404 | //this is needed for the simple algo below to work correctly, otherwise some widgets would be drawn outside the view |
405 | 405 | ||
406 | int wCount = widgetList.count(); | 406 | int wCount = widgetList.count(); |
407 | int wid = view->columnWidth(0)-1; | 407 | int wid = view->columnWidth(0)-1; |
408 | int wd; | 408 | int wd; |
409 | int n = 1; | 409 | int n = 1; |
410 | 410 | ||
411 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget | 411 | QArray<int> anzIntersect(wCount); //this stores the number of maximal intersections of each widget |
412 | 412 | ||
413 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); | 413 | for (int i = 0; i<wCount; anzIntersect[i] = 1, i++); |
414 | 414 | ||
415 | if ( wCount < 20 ) { | 415 | if ( wCount < 20 ) { |
416 | 416 | ||
417 | QArray<QRect> geometries(wCount); | 417 | QArray<QRect> geometries(wCount); |
418 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector | 418 | for (int i = 0; i < wCount; geometries[i] = widgetList.at(i)->geometry(), i++);//stores geometry for each widget in vector |
419 | 419 | ||
420 | for ( int i = 0; i < wCount; i++) { | 420 | for ( int i = 0; i < wCount; i++) { |
421 | QValueList<int> intersectedWidgets; | 421 | QValueList<int> intersectedWidgets; |
422 | 422 | ||
423 | //find all widgets intersecting with widgetList.at(i) | 423 | //find all widgets intersecting with widgetList.at(i) |
424 | for ( int j = 0; j < wCount; j++) { | 424 | for ( int j = 0; j < wCount; j++) { |
425 | if (i != j) | 425 | if (i != j) |
426 | if (geometries[j].intersects(geometries[i])) | 426 | if (geometries[j].intersects(geometries[i])) |
427 | intersectedWidgets.append(j); | 427 | intersectedWidgets.append(j); |
428 | } | 428 | } |
429 | 429 | ||
430 | //for each of these intersecting widgets find out how many widgets are they intersecting with | 430 | //for each of these intersecting widgets find out how many widgets are they intersecting with |
431 | for ( uint j = 0; j < intersectedWidgets.count(); j++) | 431 | for ( uint j = 0; j < intersectedWidgets.count(); j++) |
432 | { | 432 | { |
433 | QArray<int> inter(wCount); | 433 | QArray<int> inter(wCount); |
434 | inter[j]=1; | 434 | inter[j]=1; |
435 | 435 | ||
436 | if (intersectedWidgets[j] != -1) | 436 | if (intersectedWidgets[j] != -1) |
437 | for ( uint k = j; k < intersectedWidgets.count(); k++) { | 437 | for ( uint k = j; k < intersectedWidgets.count(); k++) { |
438 | if (j != k && intersectedWidgets[k] != -1) | 438 | if (j != k && intersectedWidgets[k] != -1) |
439 | if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) { | 439 | if (geometries[intersectedWidgets[k]].intersects(geometries[intersectedWidgets[j]])) { |
440 | inter[j]++; | 440 | inter[j]++; |
441 | intersectedWidgets[k] = -1; | 441 | intersectedWidgets[k] = -1; |
442 | } | 442 | } |
443 | if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; | 443 | if (inter[j] > anzIntersect[i]) anzIntersect[i] = inter[j] + 1; |
444 | } | 444 | } |
445 | } | 445 | } |
446 | if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; | 446 | if (anzIntersect[i] == 1 && intersectedWidgets.count()) anzIntersect[i]++; |
447 | } | 447 | } |
448 | 448 | ||
449 | 449 | ||
450 | for ( int i = 0; i < wCount; i++) { | 450 | for ( int i = 0; i < wCount; i++) { |
451 | DateBookDayWidget *w = widgetList.at(i); | 451 | DateBookDayWidget *w = widgetList.at(i); |
452 | QRect geom = w->geometry(); | 452 | QRect geom = w->geometry(); |
453 | geom.setX( 0 ); | 453 | geom.setX( 0 ); |
454 | wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); | 454 | wd = (view->columnWidth(0)-1) / anzIntersect[i] - (anzIntersect[i]>1?2:0); |
455 | geom.setWidth( wd ); | 455 | geom.setWidth( wd ); |
456 | while ( intersects( w, geom ) ) { | 456 | while ( intersects( w, geom ) ) { |
457 | geom.moveBy( wd + 2 + 1, 0 ); | 457 | geom.moveBy( wd + 2 + 1, 0 ); |
458 | } | 458 | } |
459 | w->setGeometry( geom ); | 459 | w->setGeometry( geom ); |
460 | } | 460 | } |
461 | 461 | ||
462 | if (jumpToCurTime && this->date() == QDate::currentDate()) { | 462 | if (jumpToCurTime && this->date() == QDate::currentDate()) { |
463 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour | 463 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour |
464 | } else { | 464 | } else { |
465 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); | 465 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); |
466 | } | 466 | } |
467 | } else { | 467 | } else { |
468 | int hours[24]; | 468 | int hours[24]; |
469 | memset( hours, 0, 24*sizeof( int ) ); | 469 | memset( hours, 0, 24*sizeof( int ) ); |
470 | bool overFlow = FALSE; | 470 | bool overFlow = FALSE; |
471 | for ( int i = 0; i < wCount; i++ ) { | 471 | for ( int i = 0; i < wCount; i++ ) { |
472 | DateBookDayWidget *w = widgetList.at(i); | 472 | DateBookDayWidget *w = widgetList.at(i); |
473 | int start = w->event().start().hour(); | 473 | int start = w->event().start().hour(); |
474 | QTime e = w->event().end(); | 474 | QTime e = w->event().end(); |
475 | int end = e.hour(); | 475 | int end = e.hour(); |
476 | if ( e.minute() < 5 ) | 476 | if ( e.minute() < 5 ) |
477 | end--; | 477 | end--; |
478 | if ( end < start ) | 478 | if ( end < start ) |
479 | end = start; | 479 | end = start; |
480 | while( start <= end ) { | 480 | while( start <= end ) { |
481 | hours[start]++; | 481 | hours[start]++; |
482 | if ( hours[start] >= 10 ) | 482 | if ( hours[start] >= 10 ) |
483 | overFlow = TRUE; | 483 | overFlow = TRUE; |
484 | ++start; | 484 | ++start; |
485 | } | 485 | } |
486 | if ( overFlow ) | 486 | if ( overFlow ) |
487 | break; | 487 | break; |
488 | } | 488 | } |
489 | for ( int i = 0; i < 24; i++ ) { | 489 | for ( int i = 0; i < 24; i++ ) { |
490 | n = QMAX( n, hours[i] ); | 490 | n = QMAX( n, hours[i] ); |
491 | } | 491 | } |
492 | wid = ( view->columnWidth(0)-1 ) / n; | 492 | wid = ( view->columnWidth(0)-1 ) / n; |
493 | 493 | ||
494 | bool used[24*10]; | 494 | bool used[24*10]; |
495 | memset( used, FALSE, 24*10*sizeof( bool ) ); | 495 | memset( used, FALSE, 24*10*sizeof( bool ) ); |
496 | 496 | ||
497 | for ( int i = 0; i < wCount; i++ ) { | 497 | for ( int i = 0; i < wCount; i++ ) { |
498 | DateBookDayWidget *w = widgetList.at(i); | 498 | DateBookDayWidget *w = widgetList.at(i); |
499 | int xp = place( w, used, n ); | 499 | int xp = place( w, used, n ); |
500 | if ( xp != -1 ) { | 500 | if ( xp != -1 ) { |
501 | QRect geom = w->geometry(); | 501 | QRect geom = w->geometry(); |
502 | geom.setX( xp*(wid+2) ); | 502 | geom.setX( xp*(wid+2) ); |
503 | geom.setWidth( wid ); | 503 | geom.setWidth( wid ); |
504 | w->setGeometry( geom ); | 504 | w->setGeometry( geom ); |
505 | } | 505 | } |
506 | } | 506 | } |
507 | 507 | ||
508 | if (jumpToCurTime && this->date() == QDate::currentDate()) { | 508 | if (jumpToCurTime && this->date() == QDate::currentDate()) { |
509 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour | 509 | view->setContentsPos( 0, QTime::currentTime().hour() * view->rowHeight(0) ); //set listview to current hour |
510 | } else { | 510 | } else { |
511 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); | 511 | view->setContentsPos( 0, startTime * view->rowHeight(0) ); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | 514 | ||
515 | timeMarker->setTime( QTime::currentTime() );//display timeMarker | 515 | timeMarker->setTime( QTime::currentTime() );//display timeMarker |
516 | timeMarker->raise(); //on top of all widgets | 516 | timeMarker->raise(); //on top of all widgets |
517 | if (this->date() == QDate::currentDate()) //only show timeMarker on current day | 517 | if (this->date() == QDate::currentDate()) //only show timeMarker on current day |
518 | timeMarker->show(); else timeMarker->hide(); | 518 | timeMarker->show(); else timeMarker->hide(); |
519 | 519 | ||
520 | setUpdatesEnabled( TRUE ); | 520 | setUpdatesEnabled( TRUE ); |
521 | return; | 521 | return; |
522 | } | 522 | } |
523 | 523 | ||
524 | DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) | 524 | DateBookDayWidget *DateBookDay::intersects( const DateBookDayWidget *item, const QRect &geom ) |
525 | { | 525 | { |
526 | int i = 0; | 526 | int i = 0; |
527 | DateBookDayWidget *w = widgetList.at(i); | 527 | DateBookDayWidget *w = widgetList.at(i); |
528 | int wCount = widgetList.count(); | 528 | int wCount = widgetList.count(); |
529 | while ( i < wCount && w != item ) { | 529 | while ( i < wCount && w != item ) { |
530 | if ( w->geometry().intersects( geom ) ) { | 530 | if ( w->geometry().intersects( geom ) ) { |
531 | return w; | 531 | return w; |
532 | } | 532 | } |
533 | w = widgetList.at(++i); | 533 | w = widgetList.at(++i); |
534 | } | 534 | } |
535 | 535 | ||
536 | return 0; | 536 | return 0; |
537 | } | 537 | } |
538 | 538 | ||
539 | 539 | ||
540 | QDate DateBookDay::date() const | 540 | QDate DateBookDay::date() const |
541 | { | 541 | { |
542 | return currDate; | 542 | return currDate; |
543 | } | 543 | } |
544 | 544 | ||
545 | void DateBookDay::setStartViewTime( int startHere ) | 545 | void DateBookDay::setStartViewTime( int startHere ) |
546 | { | 546 | { |
547 | startTime = startHere; | 547 | startTime = startHere; |
548 | dayView()->clearSelection(); | 548 | dayView()->clearSelection(); |
549 | QTableSelection ts; | 549 | QTableSelection ts; |
550 | 550 | ||
551 | if (jumpToCurTime && this->date() == QDate::currentDate()) {//this should probably be in datebook.cpp where it's called? | 551 | if (jumpToCurTime && this->date() == QDate::currentDate()) {//this should probably be in datebook.cpp where it's called? |
552 | ts.init( QTime::currentTime().hour(), 0); | 552 | ts.init( QTime::currentTime().hour(), 0); |
553 | ts.expandTo( QTime::currentTime().hour(), 0); | 553 | ts.expandTo( QTime::currentTime().hour(), 0); |
554 | } else { | 554 | } else { |
555 | ts.init( startTime, 0 ); | 555 | ts.init( startTime, 0 ); |
556 | ts.expandTo( startTime, 0 ); | 556 | ts.expandTo( startTime, 0 ); |
557 | } | 557 | } |
558 | 558 | ||
559 | dayView()->addSelection( ts ); | 559 | dayView()->addSelection( ts ); |
560 | } | 560 | } |
561 | 561 | ||
562 | int DateBookDay::startViewTime() const | 562 | int DateBookDay::startViewTime() const |
563 | { | 563 | { |
564 | return startTime; | 564 | return startTime; |
565 | } | 565 | } |
566 | 566 | ||
567 | void DateBookDay::slotWeekChanged( bool bStartOnMonday ) | 567 | void DateBookDay::slotWeekChanged( bool bStartOnMonday ) |
568 | { | 568 | { |
569 | header->setStartOfWeek( bStartOnMonday ); | 569 | header->setStartOfWeek( bStartOnMonday ); |
570 | //redraw(); | 570 | //redraw(); |
571 | } | 571 | } |
572 | 572 | ||
573 | void DateBookDay::keyPressEvent(QKeyEvent *e) | 573 | void DateBookDay::keyPressEvent(QKeyEvent *e) |
574 | { | 574 | { |
575 | switch(e->key()) { | 575 | switch(e->key()) { |
576 | case Key_Up: | 576 | case Key_Up: |
577 | view->moveUp(); | 577 | view->moveUp(); |
578 | break; | 578 | break; |
579 | case Key_Down: | 579 | case Key_Down: |
580 | view->moveDown(); | 580 | view->moveDown(); |
581 | break; | 581 | break; |
582 | case Key_Left: | 582 | case Key_Left: |