summaryrefslogtreecommitdiffabout
path: root/libkdepim/kdateedit.cpp
authorMichael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
commita08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff)
tree8ee90d686081c52e7c69b5ce946e9b1a7d690001 /libkdepim/kdateedit.cpp
parent11edc920afe4f274c0964436633aa632c8288a40 (diff)
downloadkdepimpi-p1.zip
kdepimpi-p1.tar.gz
kdepimpi-p1.tar.bz2
initial public commit of qt4 portp1
Diffstat (limited to 'libkdepim/kdateedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kdateedit.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp
index bf38479..28c88d4 100644
--- a/libkdepim/kdateedit.cpp
+++ b/libkdepim/kdateedit.cpp
@@ -22,31 +22,35 @@
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qapplication.h> 25#include <qapplication.h>
26#include <qevent.h> 26#include <qevent.h>
27#include <qlineedit.h> 27#include <qlineedit.h>
28#include <qpixmap.h> 28#include <qpixmap.h>
29#include <qpushbutton.h> 29#include <qpushbutton.h>
30//Added by qt3to4:
31#include <Q3Frame>
32#include <QKeyEvent>
30 33
31#include <kdatepicker.h> 34#include <kdatepicker.h>
32#include <kdebug.h> 35#include <kdebug.h>
33#include <kglobal.h> 36#include <kglobal.h>
34#include <kiconloader.h> 37#include <kiconloader.h>
35#include <klocale.h> 38#include <klocale.h>
36#include <kmessagebox.h> 39#include <kmessagebox.h>
37#include <knotifyclient.h> 40#include <knotifyclient.h>
38#include <qpalette.h> 41#include <qpalette.h>
42#include <QDesktopWidget>
39 43
40#include "kdateedit.h" 44#include "kdateedit.h"
41//#include "kdateedit.moc" 45//#include "kdateedit.moc"
42 46
43KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) 47KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP )
44 : QHBox(parent, name) 48 : Q3HBox(parent, name)
45{ 49{
46 dateFormShort = true; 50 dateFormShort = true;
47 withoutDp = withoutDP; 51 withoutDp = withoutDP;
48 mDateEdit = new QLineEdit(this); 52 mDateEdit = new QLineEdit(this);
49 mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); 53 mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort));
50 setFocusProxy(mDateEdit); 54 setFocusProxy(mDateEdit);
51 mDateEdit->installEventFilter(this); 55 mDateEdit->installEventFilter(this);
52 56
@@ -67,31 +71,31 @@ KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP )
67 } else { 71 } else {
68 QPixmap pixmap = SmallIcon("smallcal"); 72 QPixmap pixmap = SmallIcon("smallcal");
69 mDateButton = new QPushButton(this); 73 mDateButton = new QPushButton(this);
70 mDateButton->setPixmap(pixmap); 74 mDateButton->setPixmap(pixmap);
71 QPixmap pixmap2 = SmallIcon("today_small"); 75 QPixmap pixmap2 = SmallIcon("today_small");
72 QPushButton* nowButton = new QPushButton(this); 76 QPushButton* nowButton = new QPushButton(this);
73 nowButton->setPixmap(pixmap2); 77 nowButton->setPixmap(pixmap2);
74 78
75 mDateFrame = new QVBox(0,0,WType_Popup); 79 mDateFrame = new Q3VBox(0,0,Qt::WType_Popup);
76 // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 80 // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
77 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 81 mDateFrame->setFrameStyle( Q3Frame::WinPanel |Q3Frame::Raised );
78 mDateFrame->setLineWidth(3); 82 mDateFrame->setLineWidth(3);
79 mDateFrame->hide(); 83 mDateFrame->hide();
80 84
81 mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); 85 mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate());
82 connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); 86 connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate)));
83 connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); 87 connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate)));
84 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); 88 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate)));
85 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); 89 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate)));
86 connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); 90 connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide()));
87 connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); 91 connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker()));
88 connect(nowButton,SIGNAL(clicked()),SLOT(goToNow())); 92 connect(nowButton,SIGNAL(clicked()),SLOT(goToNow()));
89 mDateButton->setFocusPolicy( QWidget::NoFocus ); 93 mDateButton->setFocusPolicy( Qt::NoFocus );
90 mDateButton->setAutoDefault( false ); 94 mDateButton->setAutoDefault( false );
91 //mDateFrame->resize( 400, 300 ); 95 //mDateFrame->resize( 400, 300 );
92 96
93 } 97 }
94 connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); 98 connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed()));
95 connect(mDateEdit,SIGNAL(textChanged(const QString &)), 99 connect(mDateEdit,SIGNAL(textChanged(const QString &)),
96 SLOT(textChanged(const QString &))); 100 SLOT(textChanged(const QString &)));
97 101
@@ -220,45 +224,45 @@ void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateForm
220 begin = dateForm.find("%", begin +1); 224 begin = dateForm.find("%", begin +1);
221 } 225 }
222 226
223 // set date 227 // set date
224 switch ( dateForm.at(begin + 1).latin1() ) { 228 switch ( dateForm.at(begin + 1).latin1() ) {
225 case 'd': 229 case 'd':
226 case 'a': 230 case 'a':
227 case 'A': 231 case 'A':
228 if(key == Key_Up) { 232 if(key == Qt::Key_Up) {
229 setDate( date.addDays( 1 ) ); 233 setDate( date.addDays( 1 ) );
230 } 234 }
231 else if(key == Key_Down) { 235 else if(key == Qt::Key_Down) {
232 setDate( date.addDays( -1 ) ); 236 setDate( date.addDays( -1 ) );
233 } 237 }
234 maxDay = readDate().day(); 238 maxDay = readDate().day();
235 break; 239 break;
236 case 'm': 240 case 'm':
237 case 'b': 241 case 'b':
238 case 'B': 242 case 'B':
239 if(key == Key_Up) { 243 if(key == Qt::Key_Up) {
240 int year = ((date.month()+1)>12)?date.year()+1:date.year(); 244 int year = ((date.month()+1)>12)?date.year()+1:date.year();
241 int month = ((date.month()+1)>12)?1:date.month()+1; 245 int month = ((date.month()+1)>12)?1:date.month()+1;
242 int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; 246 int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay;
243 setDate( QDate( year, month, day ) ); 247 setDate( QDate( year, month, day ) );
244 } else if(key == Key_Down) { 248 } else if(key == Qt::Key_Down) {
245 int year = ((date.month()-1)<1)?date.year()-1:date.year(); 249 int year = ((date.month()-1)<1)?date.year()-1:date.year();
246 int month = ((date.month()-1)<1)?12:date.month()-1; 250 int month = ((date.month()-1)<1)?12:date.month()-1;
247 int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; 251 int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay;
248 setDate( QDate( year, month, day ) ); 252 setDate( QDate( year, month, day ) );
249 } 253 }
250 break; 254 break;
251 case 'y': 255 case 'y':
252 case 'Y': 256 case 'Y':
253 if(key == Key_Up) { 257 if(key == Qt::Key_Up) {
254 setDate( QDate( date.year() + 1, date.month() , date.day()) ); 258 setDate( QDate( date.year() + 1, date.month() , date.day()) );
255 } 259 }
256 else if(key == Key_Down) { 260 else if(key == Qt::Key_Down) {
257 setDate( QDate( date.year() - 1, date.month() , date.day()) ); 261 setDate( QDate( date.year() - 1, date.month() , date.day()) );
258 } 262 }
259 break; 263 break;
260/* default: 264/* default:
261 if(key == Key_Up) { 265 if(key == Key_Up) {
262 setDate( date.addDays( 1 ) ); 266 setDate( date.addDays( 1 ) );
263 } else if(key == Key_Down) { 267 } else if(key == Key_Down) {
264 setDate( date.addDays( -1 ) ); 268 setDate( date.addDays( -1 ) );
@@ -339,49 +343,49 @@ QDate KDateEdit::date() const
339 343
340void KDateEdit::keyPressEvent(QKeyEvent *e) 344void KDateEdit::keyPressEvent(QKeyEvent *e)
341{ 345{
342 QDate date = readDate(); 346 QDate date = readDate();
343 int cpos = mDateEdit->cursorPosition(); 347 int cpos = mDateEdit->cursorPosition();
344 348
345 switch(e->key()) 349 switch(e->key())
346 { 350 {
347 case Key_Escape: 351 case Qt::Key_Escape:
348 mDateEdit->deselect(); 352 mDateEdit->deselect();
349 case Key_Tab: 353 case Qt::Key_Tab:
350 QHBox::keyPressEvent(e); 354 Q3HBox::keyPressEvent(e);
351 break; 355 break;
352 case Key_Up: 356 case Qt::Key_Up:
353 // when date invalid then set to currend and return 357 // when date invalid then set to currend and return
354 if(!date.isValid()) { 358 if(!date.isValid()) {
355 date = QDate::currentDate(); 359 date = QDate::currentDate();
356 setDate(date); 360 setDate(date);
357 mDateEdit->setCursorPosition(cpos); 361 mDateEdit->setCursorPosition(cpos);
358 emit(dateChanged(date)); 362 emit(dateChanged(date));
359 QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); 363 QString text = i18n( "You entered an invalid date!\n Date changed to current date." );
360 KMessageBox::information( 0, text ); 364 KMessageBox::information( 0, text );
361 return; 365 return;
362 } 366 }
363 setDate(date, &cpos, Key_Up, dateFormShort); 367 setDate(date, &cpos, Qt::Key_Up, dateFormShort);
364 break; 368 break;
365 case Key_Down: 369 case Qt::Key_Down:
366 // when date invalid then set to current and return 370 // when date invalid then set to current and return
367 if(!date.isValid()) { 371 if(!date.isValid()) {
368 date = QDate::currentDate(); 372 date = QDate::currentDate();
369 setDate(date); 373 setDate(date);
370 mDateEdit->setCursorPosition(cpos); 374 mDateEdit->setCursorPosition(cpos);
371 emit(dateChanged(date)); 375 emit(dateChanged(date));
372 QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); 376 QString text = i18n( "You entered an invalid date!\n Date changed to current date." );
373 KMessageBox::information( 0, text ); 377 KMessageBox::information( 0, text );
374 return; 378 return;
375 } 379 }
376 setDate(date, &cpos, Key_Down, dateFormShort); 380 setDate(date, &cpos, Qt::Key_Down, dateFormShort);
377 break; 381 break;
378 default: 382 default:
379 QHBox::keyPressEvent(e); 383 Q3HBox::keyPressEvent(e);
380 break; 384 break;
381 } // switch 385 } // switch
382 mDateEdit->setCursorPosition(cpos); 386 mDateEdit->setCursorPosition(cpos);
383} 387}
384 388
385void KDateEdit::setSelect( int from, int to ) 389void KDateEdit::setSelect( int from, int to )
386{ 390{
387// return; 391// return;