summaryrefslogtreecommitdiffabout
path: root/libkdepim/kdateedit.cpp
Side-by-side diff
Diffstat (limited to 'libkdepim/kdateedit.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkdepim/kdateedit.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp
index c4c0081..2c78ea3 100644
--- a/libkdepim/kdateedit.cpp
+++ b/libkdepim/kdateedit.cpp
@@ -237,261 +237,262 @@ void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateForm
int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay;
setDate( QDate( year, month, day ) );
}
break;
case 'y':
case 'Y':
if(key == Key_Up) {
setDate( QDate( date.year() + 1, date.month() , date.day()) );
}
else if(key == Key_Down) {
setDate( QDate( date.year() - 1, date.month() , date.day()) );
}
break;
/* default:
if(key == Key_Up) {
setDate( date.addDays( 1 ) );
} else if(key == Key_Down) {
setDate( date.addDays( -1 ) );
}
break;*/
}
date = readDate();
begin = dateForm.find("%");
int allSelectStrLength = 0;
int selectStrLength = 0;
// set selection do new date an set cursor at end of selection
for(int i = 0; i < repeat; i++){
switch ( dateForm.at(begin + 1).latin1() )
{
case 'd':// 16 (month day)
selectStrLength = 2; //Ok
break;
case 'm':// 01 (month)
selectStrLength = 2; //Ok
break;
case 'a':// Mon (Weekday short)
selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length();
break;
case 'A':// Monday (Weekday)
selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length();
break;
case 'b':// Jan (monthName short)
selectStrLength = KGlobal::locale()->monthName(date.month(), true).length();
break;
case 'B':// January (monthName)
selectStrLength = KGlobal::locale()->monthName(date.month(), false).length();
break;
case 'y':// 04 (year short)
selectStrLength = 2; //Ok
break;
case 'Y':// 2004 (year)
selectStrLength = 4; //Ok
break;
default:
break;
}
space = begin - (i * 2);
allSelectStrLength += selectStrLength;
begin = dateForm.find("%", begin +1);
}
// set selection from begin of date
setSelect( space + allSelectStrLength - selectStrLength , selectStrLength);
*cpos = space + allSelectStrLength;
emit(dateChanged(date));
return;
}
void KDateEdit::setHandleInvalid(bool handleInvalid)
{
mHandleInvalid = handleInvalid;
}
void KDateEdit::setEnabled(bool on)
{
mDateEdit->setEnabled(on);
mDateButton->setEnabled(on);
}
QDate KDateEdit::date() const
{
QDate date = readDate();
if (date.isValid() || mHandleInvalid) {
return date;
} else {
KNotifyClient::beep();
return QDate::currentDate();
}
}
void KDateEdit::keyPressEvent(QKeyEvent *e)
{
QDate date = readDate();
int cpos = mDateEdit->cursorPosition();
switch(e->key())
{
case Key_Escape:
mDateEdit->deselect();
case Key_Tab:
QHBox::keyPressEvent(e);
break;
case Key_Up:
// when date invalid then set to currend and return
if(!date.isValid()) {
date = QDate::currentDate();
setDate(date);
mDateEdit->setCursorPosition(cpos);
emit(dateChanged(date));
QString text = i18n( "You entered an invalid date!\n Date changed to current date." );
KMessageBox::information( 0, text );
return;
}
setDate(date, &cpos, Key_Up, dateFormShort);
break;
case Key_Down:
// when date invalid then set to current and return
if(!date.isValid()) {
date = QDate::currentDate();
setDate(date);
mDateEdit->setCursorPosition(cpos);
emit(dateChanged(date));
QString text = i18n( "You entered an invalid date!\n Date changed to current date." );
KMessageBox::information( 0, text );
return;
}
setDate(date, &cpos, Key_Down, dateFormShort);
break;
default:
QHBox::keyPressEvent(e);
break;
} // switch
mDateEdit->setCursorPosition(cpos);
}
void KDateEdit::setSelect( int from, int to )
{
// return;
mDateEdit->setSelection( from , to );
}
void KDateEdit::toggleDatePicker()
{
if( mDateFrame->isVisible() ) {
mDateFrame->hide();
} else {
QPoint tmpPoint = mapToGlobal(mDateButton->geometry().bottomRight());
QSize datepickersize = mDatePicker->sizeHint();
if ( tmpPoint.x() < 7+datepickersize.width() ) tmpPoint.setX( 7+datepickersize.width() );
int h = QApplication::desktop()->height();
if ( tmpPoint.y() + datepickersize.height() > h ) tmpPoint.setY( h - datepickersize.height() );
mDateFrame->setGeometry(tmpPoint.x()-datepickersize.width()-7, tmpPoint.y(),
datepickersize.width()+2*mDateFrame->lineWidth(), datepickersize.height()+2*mDateFrame->lineWidth());
QDate date = readDate();
if(date.isValid()) {
mDatePicker->setDate(date);
} else {
mDatePicker->setDate(QDate::currentDate());
}
mDateFrame->show();
}
}
void KDateEdit::lineEnterPressed()
{
QDate date = readDate();
if(date.isValid())
{
// Update the edit. This is needed if the user has entered a
// word rather than the actual date.
setDate(date);
emit(dateChanged(date));
emit returnPressed();
}
else
{
if ( withoutDp ) {
KNotifyClient::beep();
} else {
if ( !mDateEdit->text().isEmpty() ) {
mTextChanged = false;
QString text = i18n( "You entered an invalid date!\n Will use current date instead." );
+ if ( isVisible() )
if ( KMessageBox::warningContinueCancel( 0, text ) == KMessageBox::Continue ) {
setDate( QDate::currentDate() );
emit dateChanged( QDate::currentDate() );
}
}
}
}
}
bool KDateEdit::inputIsValid()
{
return readDate().isValid();
}
QDate KDateEdit::readDate() const
{
QString text = mDateEdit->text();
QDate date;
if (mKeywordMap.contains(text.lower()))
{
date = QDate::currentDate().addDays(mKeywordMap[text.lower()]);
}
else
{
date = KGlobal::locale()->readDate(text);
}
return date;
}
bool KDateEdit::eventFilter(QObject *, QEvent *e)
{
// We only process the focus out event if the text has changed
// since we got focus
if ((e->type() == QEvent::FocusOut) && mTextChanged)
{
lineEnterPressed();
mTextChanged = false;
}
// switch dateFormShort by double klick with mouse
else if (e->type() == QEvent::MouseButtonDblClick)
{
toggleDateFormat();
}
else if (e->type() == QEvent::FocusIn)
{
maxDay = readDate().day();
}
return false;
}
void KDateEdit::toggleDateFormat()
{
dateFormShort = ! dateFormShort;
mDateEdit->setText(KGlobal::locale()->formatDate(readDate(),dateFormShort));
}
void KDateEdit::textChanged(const QString &)
{
if(mHandleInvalid && mDateEdit->text().stripWhiteSpace().isEmpty()) {
QDate date; //invalid date
emit(dateChanged(date));
} else {
mTextChanged = true;
}
maxDay = readDate().day();
}