• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kalarm/lib

dateedit.cpp

Go to the documentation of this file.
00001 /*
00002  *  dateedit.cpp  -  date entry widget
00003  *  Program:  kalarm
00004  *  Copyright © 2002-2008 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include <QMouseEvent>
00022 #include <kglobal.h>
00023 #include <klocale.h>
00024 #include <kmessagebox.h>
00025 #include <kdebug.h>
00026 
00027 #include "dateedit.moc"
00028 
00029 
00030 DateEdit::DateEdit(QWidget* parent)
00031     : KDateEdit(parent)
00032 {
00033     connect(this, SIGNAL(dateEntered(const QDate&)), SLOT(newDateEntered(const QDate&)));
00034 }
00035 
00036 void DateEdit::setMinDate(const QDate& d, const QString& errorDate)
00037 {
00038     mMinDate = d;
00039     if (mMinDate.isValid()  &&  date().isValid()  &&  date() < mMinDate)
00040         setDate(mMinDate);
00041     mMinDateErrString = errorDate;
00042 }
00043 
00044 void DateEdit::setMaxDate(const QDate& d, const QString& errorDate)
00045 {
00046     mMaxDate = d;
00047     if (mMaxDate.isValid()  &&  date().isValid()  &&  date() > mMaxDate)
00048         setDate(mMaxDate);
00049     mMaxDateErrString = errorDate;
00050 }
00051 
00052 void DateEdit::setInvalid()
00053 {
00054     setDate(QDate());
00055 }
00056 
00057 // Check a new date against any minimum or maximum date.
00058 void DateEdit::newDateEntered(const QDate& newDate)
00059 {
00060     if (newDate.isValid())
00061     {
00062         if (mMinDate.isValid()  &&  newDate < mMinDate)
00063         {
00064             pastLimitMessage(mMinDate, mMinDateErrString,
00065                      ki18nc("@info", "Date cannot be earlier than %1"));
00066         }
00067         else if (mMaxDate.isValid()  &&  newDate > mMaxDate)
00068         {
00069             pastLimitMessage(mMaxDate, mMaxDateErrString,
00070                      ki18nc("@info", "Date cannot be later than %1"));
00071         }
00072     }
00073 }
00074 
00075 void DateEdit::pastLimitMessage(const QDate& limit, const QString& error, const KLocalizedString& defaultError)
00076 {
00077     QString errString = error;
00078     if (errString.isNull())
00079     {
00080         if (limit == QDate::currentDate())
00081             errString = i18nc("@info/plain", "today");
00082         else
00083             errString = KGlobal::locale()->formatDate(limit, KLocale::ShortDate);
00084         errString = defaultError.subs(errString).toString();
00085     }
00086     KMessageBox::sorry(this, errString);
00087 }
00088 
00089 void DateEdit::mousePressEvent(QMouseEvent *e)
00090 {
00091     if (isReadOnly())
00092     {
00093         // Swallow up the event if it's the left button
00094         if (e->button() == Qt::LeftButton)
00095             return;
00096     }
00097     KDateEdit::mousePressEvent(e);
00098 }
00099 
00100 void DateEdit::mouseReleaseEvent(QMouseEvent* e)
00101 {
00102     if (!isReadOnly())
00103         KDateEdit::mouseReleaseEvent(e);
00104 }
00105 
00106 void DateEdit::mouseMoveEvent(QMouseEvent* e)
00107 {
00108     if (!isReadOnly())
00109         KDateEdit::mouseMoveEvent(e);
00110 }
00111 
00112 void DateEdit::keyPressEvent(QKeyEvent* e)
00113 {
00114     if (!isReadOnly())
00115         KDateEdit::keyPressEvent(e);
00116 }
00117 
00118 void DateEdit::keyReleaseEvent(QKeyEvent* e)
00119 {
00120     if (!isReadOnly())
00121         KDateEdit::keyReleaseEvent(e);
00122 }

kalarm/lib

Skip menu "kalarm/lib"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal