-rw-r--r-- | microkde/kdatetbl.cpp | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp index 4271b55..353f78d 100644 --- a/microkde/kdatetbl.cpp +++ b/microkde/kdatetbl.cpp | |||
@@ -211,105 +211,93 @@ KDateTable::keyPressEvent( QKeyEvent *e ) | |||
211 | /* | 211 | /* |
212 | // not working properly | 212 | // not working properly |
213 | if ( e->key() == Qt::Key_Prior ) { | 213 | if ( e->key() == Qt::Key_Prior ) { |
214 | if ( date.month() == 1 ) { | 214 | if ( date.month() == 1 ) { |
215 | KNotifyClient::beep(); | 215 | KNotifyClient::beep(); |
216 | return; | 216 | return; |
217 | } | 217 | } |
218 | int day = date.day(); | 218 | int day = date.day(); |
219 | if ( day > 27 ) | 219 | if ( day > 27 ) |
220 | while ( !QDate::isValid( date.year(), date.month()-1, day ) ) | 220 | while ( !QDate::isValid( date.year(), date.month()-1, day ) ) |
221 | day--; | 221 | day--; |
222 | setDate(QDate(date.year(), date.month()-1, day)); | 222 | setDate(QDate(date.year(), date.month()-1, day)); |
223 | return; | 223 | return; |
224 | } | 224 | } |
225 | if ( e->key() == Qt::Key_Next ) { | 225 | if ( e->key() == Qt::Key_Next ) { |
226 | if ( date.month() == 12 ) { | 226 | if ( date.month() == 12 ) { |
227 | KNotifyClient::beep(); | 227 | KNotifyClient::beep(); |
228 | return; | 228 | return; |
229 | } | 229 | } |
230 | int day = date.day(); | 230 | int day = date.day(); |
231 | if ( day > 27 ) | 231 | if ( day > 27 ) |
232 | while ( !QDate::isValid( date.year(), date.month()+1, day ) ) | 232 | while ( !QDate::isValid( date.year(), date.month()+1, day ) ) |
233 | day--; | 233 | day--; |
234 | setDate(QDate(date.year(), date.month()+1, day)); | 234 | setDate(QDate(date.year(), date.month()+1, day)); |
235 | return; | 235 | return; |
236 | } | 236 | } |
237 | */ | 237 | */ |
238 | int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; | 238 | int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; |
239 | 239 | ||
240 | int temp=firstday+date.day()-dayoff; | 240 | int temp=firstday+date.day()-dayoff; |
241 | int pos = temp; | 241 | int pos = temp; |
242 | bool irgnore = true; | 242 | bool irgnore = true; |
243 | int add = 0; | ||
243 | if ( e->state() != Qt::ControlButton ) { | 244 | if ( e->state() != Qt::ControlButton ) { |
244 | if ( e->key() == Qt::Key_Up ) { | 245 | if ( e->key() == Qt::Key_Up ) { |
245 | pos -= 7; | 246 | add -= 7; |
246 | irgnore = false; | 247 | irgnore = false; |
247 | } | 248 | } |
248 | if ( e->key() == Qt::Key_Down ) { | 249 | if ( e->key() == Qt::Key_Down ) { |
249 | pos += 7; | 250 | add += 7; |
250 | irgnore = false; | 251 | irgnore = false; |
251 | } | 252 | } |
252 | if ( e->key() == Qt::Key_Left ) { | 253 | if ( e->key() == Qt::Key_Left ) { |
253 | pos--; | 254 | --add; |
254 | irgnore = false; | 255 | irgnore = false; |
255 | } | 256 | } |
256 | if ( e->key() == Qt::Key_Right ) { | 257 | if ( e->key() == Qt::Key_Right ) { |
257 | pos++; | 258 | ++add; |
258 | irgnore = false; | 259 | irgnore = false; |
259 | } | 260 | } |
260 | } | 261 | } |
261 | if ( irgnore ) | 262 | if ( irgnore ) { |
262 | e->ignore(); | 263 | e->ignore(); |
263 | |||
264 | if(pos+dayoff<=firstday) | ||
265 | { // this day is in the previous month | ||
266 | KNotifyClient::beep(); | ||
267 | return; | ||
268 | } | ||
269 | if(firstday+numdays<pos+dayoff) | ||
270 | { // this date is in the next month | ||
271 | KNotifyClient::beep(i18n( "Month not long enough" )); | ||
272 | return; | ||
273 | } | ||
274 | |||
275 | if ( pos == temp ) | ||
276 | return; | 264 | return; |
265 | } | ||
277 | 266 | ||
278 | setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); | 267 | pos += add; |
268 | setDate(date.addDays( add )); | ||
279 | updateCell(temp/7+1, temp%7); // Update the previously selected cell | 269 | updateCell(temp/7+1, temp%7); // Update the previously selected cell |
280 | updateCell(pos/7+1, pos%7); // Update the selected cell | 270 | updateCell(pos/7+1, pos%7); // Update the selected cell |
281 | assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); | 271 | |
282 | |||
283 | |||
284 | } | 272 | } |
285 | 273 | ||
286 | void | 274 | void |
287 | KDateTable::viewportResizeEvent(QResizeEvent * e) | 275 | KDateTable::viewportResizeEvent(QResizeEvent * e) |
288 | { | 276 | { |
289 | QGridView::viewportResizeEvent(e); | 277 | QGridView::viewportResizeEvent(e); |
290 | 278 | ||
291 | setCellWidth(viewport()->width()/7); | 279 | setCellWidth(viewport()->width()/7); |
292 | setCellHeight(viewport()->height()/7); | 280 | setCellHeight(viewport()->height()/7); |
293 | } | 281 | } |
294 | 282 | ||
295 | void | 283 | void |
296 | KDateTable::setFontSize(int size) | 284 | KDateTable::setFontSize(int size) |
297 | { | 285 | { |
298 | int count; | 286 | int count; |
299 | QRect rect; | 287 | QRect rect; |
300 | // ----- store rectangles: | 288 | // ----- store rectangles: |
301 | fontsize=size; | 289 | fontsize=size; |
302 | QFont _font = font(); | 290 | QFont _font = font(); |
303 | _font.setPointSize(fontsize); | 291 | _font.setPointSize(fontsize); |
304 | setFont( _font ); | 292 | setFont( _font ); |
305 | _font.setBold( true ); | 293 | _font.setBold( true ); |
306 | QFontMetrics metrics(_font); | 294 | QFontMetrics metrics(_font); |
307 | 295 | ||
308 | // ----- find largest day name: | 296 | // ----- find largest day name: |
309 | maxCell.setWidth(0); | 297 | maxCell.setWidth(0); |
310 | maxCell.setHeight(0); | 298 | maxCell.setHeight(0); |
311 | for(count=0; count<7; ++count) | 299 | for(count=0; count<7; ++count) |
312 | { | 300 | { |
313 | rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); | 301 | rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); |
314 | maxCell.setWidth(QMAX(maxCell.width(), rect.width())); | 302 | maxCell.setWidth(QMAX(maxCell.width(), rect.width())); |
315 | maxCell.setHeight(QMAX(maxCell.height(), rect.height())); | 303 | maxCell.setHeight(QMAX(maxCell.height(), rect.height())); |