-rw-r--r-- | libkdepim/addresseeview.cpp | 10 | ||||
-rw-r--r-- | libkdepim/kdateedit.cpp | 17 | ||||
-rw-r--r-- | libkdepim/kdateedit.h | 3 |
3 files changed, 24 insertions, 6 deletions
diff --git a/libkdepim/addresseeview.cpp b/libkdepim/addresseeview.cpp index d710541..5c69010 100644 --- a/libkdepim/addresseeview.cpp +++ b/libkdepim/addresseeview.cpp @@ -1,319 +1,325 @@ /* This file is part of libkdepim. Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <kabc/address.h> #include <kabc/addressee.h> #include <kabc/phonenumber.h> #include <kglobal.h> //US#include <kglobalsettings.h> #include <kiconloader.h> #include <klocale.h> //US #include <kstringhandler.h> #include <qscrollview.h> #include <qregexp.h> #include <qfile.h> #include <qapplication.h> #include "externalapphandler.h" #include "addresseeview.h" //US #ifndef DESKTOP_VERSION //US #include <qtopia/qcopenvelope_qws.h> //US #include <qpe/qpeapplication.h> //US #endif //US static int kphoneInstalled = 0; using namespace KPIM; AddresseeView::AddresseeView( QWidget *parent, const char *name ) //US : KTextBrowser( parent, name ) : QTextBrowser( parent, name ) { //US setWrapPolicy( QTextEdit::AtWordBoundary ); setLinkUnderline( false ); // setVScrollBarMode( QScrollView::AlwaysOff ); //setHScrollBarMode( QScrollView::AlwaysOff ); //US QStyleSheet *sheet = styleSheet(); //US QStyleSheetItem *link = sheet->item( "a" ); //US link->setColor( KGlobalSettings::linkColor() ); } void AddresseeView::setSource(const QString& n) { - qDebug("********AddresseeView::setSource %s", n.latin1()); + //qDebug("********AddresseeView::setSource %s", n.latin1()); if ( n.left( 6 ) == "mailto" ) ExternalAppHandler::instance()->mailToOneContact( n.mid(7) ); else if ( n.left( 7 ) == "phoneto" ) ExternalAppHandler::instance()->callByPhone( n.mid(8) ); else if ( n.left( 5 ) == "faxto" ) ExternalAppHandler::instance()->callByFax( n.mid(6) ); else if ( n.left( 5 ) == "smsto" ) ExternalAppHandler::instance()->callBySMS( n.mid(6) ); else if ( n.left( 7 ) == "pagerto" ) ExternalAppHandler::instance()->callByPager( n.mid(8) ); } void AddresseeView::setAddressee( const KABC::Addressee& addr ) { ExternalAppHandler* eah = ExternalAppHandler::instance(); bool kemailAvail = eah->isEmailAppAvailable(); bool kphoneAvail = eah->isPhoneAppAvailable(); bool kfaxAvail = eah->isFaxAppAvailable(); bool ksmsAvail = eah->isSMSAppAvailable(); bool kpagerAvail = eah->isPagerAppAvailable(); mAddressee = addr; // clear view setText( QString::null ); if ( mAddressee.isEmpty() ) return; QString name = ( mAddressee.assembledName().isEmpty() ? mAddressee.formattedName() : mAddressee.assembledName() ); QString dynamicPart; QStringList emails = mAddressee.emails(); QStringList::ConstIterator emailIt; QString type = i18n( "Email" ); emailIt = emails.begin(); if ( emailIt != emails.end() ) { if ( kemailAvail ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) .arg( type ) .arg( name ) .arg( *emailIt ) .arg( *emailIt ); ++emailIt; } else { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( type ) .arg( *emailIt ); ++emailIt; } } - + if ( mAddressee.birthday().date().isValid() ) { + dynamicPart += QString( + "<tr><td align=\"right\"><b>%1</b></td>" + "<td align=\"left\">%2</td></tr>" ) + .arg( i18n ("Birthday") ) + .arg( KGlobal::locale()->formatDate( mAddressee.birthday().date() ,true) ); + } KABC::PhoneNumber::List phones = mAddressee.phoneNumbers(); KABC::PhoneNumber::List::ConstIterator phoneIt; QString extension; int phonetype; QString sms; for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { phonetype = (*phoneIt).type(); if (ksmsAvail && ( ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) || ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell) ) ) { sms = QString("<a href=\"smsto:%1 \">(sms)</a>" ) .arg( (*phoneIt).number() ); } else sms = ""; extension = QString::null; if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) { if (kfaxAvail) extension = "faxto:"; } else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) { if (kpagerAvail) extension = "pagerto:"; } else if (kphoneAvail) { extension = "phoneto:"; } else extension = QString::null; if ( !extension.isEmpty() ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\"><a href=\"%2%3 \">%4</a> %5</td></tr>" ) .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) .arg( extension ) .arg( (*phoneIt).number() ) .arg( (*phoneIt).number() ) .arg( sms ); } else { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2 %3</td></tr>" ) .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) .arg( (*phoneIt).number() ) .arg( sms ); } } for ( ; emailIt != emails.end(); ++emailIt ) { if ( kemailAvail ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) .arg( type ) .arg( name ) .arg( *emailIt ) .arg( *emailIt ); } else { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( type ) .arg( *emailIt ); } } if ( !mAddressee.url().url().isEmpty() ) { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( i18n( "Homepage" ) ) //US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) ); .arg( mAddressee.url().url() ); //qDebug("AddresseeView::setAddressee has to be verified."); } KABC::Address::List addresses = mAddressee.addresses(); KABC::Address::List::ConstIterator addrIt; for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { if ( true /*(*addrIt).label().isEmpty()*/ ) { QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace(); //US formattedAddress = formattedAddress.replace( '\n', "<br>" ); //qDebug("adresss %s ",formattedAddress.latin1() ); formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" ); //qDebug("AddresseeView::setAddressee has to be verified."); dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) .arg( formattedAddress ); } else { dynamicPart += QString( "<tr><td align=\"right\"><b>%1</b></td>" "<td align=\"left\">%2</td></tr>" ) .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) //US .arg( (*addrIt).label().replace( '\n', "<br>" ) ); .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ ); } } QString notes; if ( !mAddressee.note().isEmpty() ) { notes = QString( "<tr>" "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label "<td align=\"left\">%2</td>" // note "</tr>" ).arg( i18n( "Notes" ) ) //US .arg( mAddressee.note().replace( '\n', "<br>" ) ); .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) ); //qDebug("AddresseeView::setAddressee has to be verified."); } QString aRole = ""; QString aOrga = ""; if ( true /*!mAddressee.role().isEmpty()*/ ) { aRole = "<tr>" "<td align=\"left\">" + mAddressee.role() + "</td>" "</tr>"; } if ( true /*!mAddressee.organization().isEmpty()*/ ) { aOrga = "<tr>" "<td align=\"left\">" + mAddressee.organization() + "</td>" ; "</tr>"; } mText = ""; QString picString = ""; KABC::Picture picture = mAddressee.photo(); bool picAvailintern = false; bool picAvailUrl = false; if (! picture.undefined() ) { picAvailintern = (picture.isIntern() && !picture.data().isNull()); picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() ); } if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) { if ( picAvailintern ) { QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() ); } else { if ( picAvailUrl ) { QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() )); } else { QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) ); } } picString = "<img src=\"myimage\" width=\"50\" height=\"70\">"; mText = QString::fromLatin1( "<html>" "<body text=\"%1\" bgcolor=\"%2\">" // text and background color "<table>" "<tr>" "<td rowspan=\"3\" align=\"right\" valign=\"top\">" "%3" "</td>" "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name "</tr>" "%5" // role "%6" // organization "<td colspan=\"2\"> </td>" "%7" // dynamic part "%8" // notes "</table>" "</body>" "</html>") //US .arg( /*KGlobalSettings::textColor().name()*/ "black" ) //US .arg( /*KGlobalSettings::baseColor().name()*/ "white" ) .arg( picString ) .arg( name ) .arg( aRole ) .arg( aOrga ) .arg( dynamicPart ) .arg( notes ); } else { // no picture! mText = "<table width=\"100%\">\n"; //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; #ifdef DESKTOP_VERSION mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>"; #else mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>"; #endif diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp index 5fb948a..c4c0081 100644 --- a/libkdepim/kdateedit.cpp +++ b/libkdepim/kdateedit.cpp @@ -1,486 +1,497 @@ /* This file is part of libkdepim. Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qapplication.h> #include <qevent.h> #include <qlineedit.h> #include <qpixmap.h> #include <qpushbutton.h> #include <kdatepicker.h> #include <kdebug.h> #include <kglobal.h> #include <kiconloader.h> #include <klocale.h> #include <kmessagebox.h> #include <knotifyclient.h> #include <qpalette.h> #include "kdateedit.h" //#include "kdateedit.moc" KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) : QHBox(parent, name) { dateFormShort = true; withoutDp = withoutDP; mDateEdit = new QLineEdit(this); mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); setFocusProxy(mDateEdit); mDateEdit->installEventFilter(this); // Highlight Background and Textcolor QPalette palette = QWidget::palette(); unsigned char red, green, blue; red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); mDateEdit->setPalette( palette ); if ( withoutDP ) { mDateFrame = 0; mDateButton = 0; mDatePicker = 0; } else { QPixmap pixmap = SmallIcon("smallcal"); mDateButton = new QPushButton(this); mDateButton->setPixmap(pixmap); mDateFrame = new QVBox(0,0,WType_Popup); // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); mDateFrame->setLineWidth(3); mDateFrame->hide(); mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); //mDateFrame->resize( 400, 300 ); } connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); connect(mDateEdit,SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &))); // Create the keyword list. This will be used to match against when the user // enters information. mKeywordMap[i18n("tomorrow")] = 1; mKeywordMap[i18n("today")] = 0; mKeywordMap[i18n("yesterday")] = -1; /* * This loop uses some math tricks to figure out the offset in days * to the next date the given day of the week occurs. There * are two cases, that the new day is >= the current day, which means * the new day has not occured yet or that the new day < the current day, * which means the new day is already passed (so we need to find the * day in the next week). */ QString dayName; int currentDay = QDate::currentDate().dayOfWeek(); for (int i = 1; i <= 7; ++i) { dayName = KGlobal::locale()->weekDayName(i).lower(); if (i >= currentDay) mKeywordMap[dayName] = i - currentDay; else mKeywordMap[dayName] = 7 - currentDay + i; } mTextChanged = false; mHandleInvalid = false; QWidget::setTabOrder( mDateEdit, mDateButton ); } KDateEdit::~KDateEdit() { delete mDateFrame; } - +void KDateEdit::clear() +{ + bool b = mDateEdit->signalsBlocked(); + mDateEdit->blockSignals(true); + mDateEdit->setText(""); + mDateEdit->blockSignals(b); +} void KDateEdit::setDate(QDate newDate) { if (!newDate.isValid() && !mHandleInvalid) return; if ( readDate() == newDate ) return; QString dateString = ""; if(newDate.isValid()) dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); mTextChanged = false; // We do not want to generate a signal here, since we explicity setting // the date bool b = mDateEdit->signalsBlocked(); mDateEdit->blockSignals(true); mDateEdit->setText(dateString); mDateEdit->blockSignals(b); } void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) { QString dateForm = dateFormShort ? KGlobal::locale()->dateFormatShort() : KGlobal::locale()->dateFormat(); int begin = dateForm.find("%"); int space = 0; int allStrLength = 0; int strLength = 0; int repeat = 0; // witch? Day, Month or Year switch? while(1){ switch ( dateForm.at(begin + 1).latin1() ) { case 'd':// 16 (month day) strLength = 2; //Ok break; case 'm':// 01 (month) strLength = 2; //Ok break; case 'a':// Mon (Weekday) strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); break; case 'A':// Monday (Weekday) strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); break; case 'b':// Jan (monthName) strLength = KGlobal::locale()->monthName(date.month(), true).length(); break; case 'B':// January (monthName) strLength = KGlobal::locale()->monthName(date.month(), false).length(); break; case 'y':// 04 (year short) strLength = 2; //Ok break; case 'Y':// 2004 (year) strLength = 4; //Ok break; default: break; } space = begin - (repeat++ * 2); // all select? then dayswitch if( (mDateEdit->text().length() == mDateEdit->markedText().length() ) && ( (dateForm.at(begin + 1).latin1() == 'd') || (dateForm.at(begin + 1).latin1() == 'a') || (dateForm.at(begin + 1).latin1() == 'A') ) ) { break; } // mDateEdit-StringPos == CursorPosition(cpos) then break and set date if( ( (space + allStrLength) <= *cpos && *cpos <= (space + allStrLength + strLength) ) || *cpos < begin ) { break; } allStrLength += strLength; begin = dateForm.find("%", begin +1); } // set date switch ( dateForm.at(begin + 1).latin1() ) { case 'd': case 'a': case 'A': if(key == Key_Up) { setDate( date.addDays( 1 ) ); } else if(key == Key_Down) { setDate( date.addDays( -1 ) ); } maxDay = readDate().day(); break; case 'm': case 'b': case 'B': if(key == Key_Up) { int year = ((date.month()+1)>12)?date.year()+1:date.year(); int month = ((date.month()+1)>12)?1:date.month()+1; int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; setDate( QDate( year, month, day ) ); } else if(key == Key_Down) { int year = ((date.month()-1)<1)?date.year()-1:date.year(); int month = ((date.month()-1)<1)?12:date.month()-1; 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 ( 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) { - dateFormShort = dateFormShort?false:true; - mDateEdit->setText(KGlobal::locale()->formatDate(readDate(),dateFormShort)); + 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(); } diff --git a/libkdepim/kdateedit.h b/libkdepim/kdateedit.h index 742d843..cf3b90a 100644 --- a/libkdepim/kdateedit.h +++ b/libkdepim/kdateedit.h @@ -1,140 +1,141 @@ /* This file is part of libkdepim. Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef KDATEEDIT_H #define KDATEEDIT_H #include <qhbox.h> #include <qvbox.h> #include <qdatetime.h> #include <qmap.h> class QLineEdit; class QPushButton; class QObject; class QEvent; class KDatePicker; class KDateValidator; /** * A date editing widget that consists of a line edit followed by * a small push button. The line edit contains the date in text form, * and the push button will display a 'popup' style date picker. * * This widget also supports advanced features like allowing the user * to type in the day name to get the date. The following keywords * are supported (in the native language): tomorrow, yesturday, today, * monday, tuesday, wednesday, thursday, friday, saturday, sunday. * * @author Cornelius Schumacher <schumacher@kde.org> * @author Mike Pilone <mpilone@slac.com> */ class KDateEdit : public QHBox { Q_OBJECT public: KDateEdit(QWidget *parent=0, const char *name=0, bool withoutDP = false ); virtual ~KDateEdit(); /** @return True if the date in the text edit is valid, * false otherwise. This will not modify the display of the date, * but only check for validity. */ bool inputIsValid(); /** @return The date entered. This will not * modify the display of the date, but only return it. */ QDate date() const; /** @param handleInvalid If true the date edit accepts invalid dates * and displays them as the empty ("") string. It also returns an invalid date. * If false (default) invalid dates are not accepted and instead the date * of today will be returned. */ void setHandleInvalid(bool handleInvalid); /** Checks for a focus out event. The display of the date is updated * to display the proper date when the focus leaves. */ virtual bool eventFilter(QObject *o, QEvent *e); - + void toggleDateFormat(); + void clear(); signals: /** This signal is emitted whenever the user modifies the date. This * may not get emitted until the user presses enter in the line edit or * focus leaves the widget (ie: the user confirms their selection). */ void dateChanged(QDate); void returnPressed(); public slots: /** Sets the date. * * @param date The new date to display. This date must be valid or * it will not be displayed. */ void setDate(QDate date); // set Date with key_up key_down to relation of cursor Position // and set selection from begin to end of single date void setDate(QDate, int *cpos, const int, const bool); /** Sets the date edit to be enabled or disabled (grayed out) * * @param on Enabled if true, disabled if false */ void setEnabled(bool on); protected slots: void toggleDatePicker(); void lineEnterPressed(); void textChanged(const QString &); private: /** Reads the text from the line edit. If the text is a keyword, the * word will be translated to a date. If the text is not a keyword, the * text will be interpreted as a date. */ QDate readDate() const; /** Maps the text that the user can enter to the offset in days from * today. For example, the text 'tomorrow' is mapped to +1. */ QMap<QString, int> mKeywordMap; bool mTextChanged; bool mHandleInvalid; QPushButton *mDateButton; QLineEdit *mDateEdit; KDatePicker *mDatePicker; QVBox *mDateFrame; int maxDay; bool withoutDp; protected: virtual void keyPressEvent(QKeyEvent *qke); void setSelect ( int, int ); bool dateFormShort; char lengthMonthName; }; #endif |