add_subdirectory(keduvocdocument)
add_subdirectory(kdeeduui)
-add_subdirectory(extdate)
add_subdirectory(libscience)
+add_subdirectory(widgets)
+++ /dev/null
-
-add_subdirectory( tests )
-
-add_definitions (-DQT3_SUPPORT -DQT3_SUPPORT_WARNINGS)
-
-
-
-########### next target ###############
-
-set(extdate_LIB_SRCS
- extdatetime.cpp
- extcalendarsystem.cpp
- extcalendarsystemgregorian.cpp
- extdatetbl.cpp
- extdatepicker.cpp
- extdatetimeedit.cpp
- extdatewidget.cpp )
-
-
-kde4_add_library(extdate SHARED ${extdate_LIB_SRCS})
-
-target_link_libraries(extdate ${KDE4_KDEUI_LIBS} ${QT_QT3SUPPORT_LIBRARY})
-
-set_target_properties(extdate PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
-install(TARGETS extdate DESTINATION ${LIB_INSTALL_DIR})
-
-
+++ /dev/null
-This libray consists of a group of classes which allow KDE
-applications to access calendar dates outside of the limited range
-of years imposed by QDate.
-
-The QDate class has a limited range of valid dates. It does not
-recognize dates prior to 14 Oct 1752 (when the Gregorian calendar
-was adopted by England), nor dates after 31 Dec 8000. Both of these
-limits are arbitrary.
-
-
-The following classes are included:
-
-ExtDate: Replaces QDate. There is no restriction on what dates
-may be entered. For dates in the valid QDate range, it is
-completely equivalent to QDate.
-
-ExtDateTime: Replaces QDateTime. Consists of a QTime object
-and an ExtDate object.
-
-ExtCalendarSystem: Replaces KCalendarSystem. Uses ExtDate instead
-of QDate. ExtCalendarSystem is a baseclass foundation for several
-different calendar systems. A "calendar system" is just a method for
-hierarchically subdividing the long count of days known as the Julian
-Day Calendar into groups (weeks, months, years).
-
-ExtCalendarSystemGregorian: Replaces KCalendarSystemGregorian.
-The most common calendar system in modern western societies is the
-Gregorian calendar. This class implements the Gregorian calendar
-as a ExtCalendarSystem.
-
-ExtDateTable: Replaces KDateTable.
-ExtDatePicker: Replaces KDatePicker.
-ExtDateTimeEdit: Replaces QDateTimeEdit.
-ExtDateWidget: Replaces KDateWidget.
-
-There are two test programs with the library, to verify the
-functionality of the ExtDate classes:
-
-test_extdate tests the non-GUI functionality, comparing results of
-several operations with the results from QDate.
-
-test_extdatepicker presents a KDatePicker widget and an ExtDatePicker
-widget side-by-side.
+++ /dev/null
-/*
- Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es>
- Copyright (c) 2002 Hans Petter Bieker <bieker@kde.org>
- Copyright (c) 2004 Jason Harris <jharris@30doradus.org>
-
- This class has been derived from ExtCalendarSystem;
- the changesd made just replace QDate objects with ExtDate objects.
- These changes by Jason Harris <jharris@30doradus.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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-// Gregorian calendar system implementation factory for creation of kde calendar
-// systems.
-// Also default gregorian and factory classes
-
-#include "extcalendarsystem.h"
-#include "klocale.h"
-
-#include <kglobal.h>
-
-class ExtCalendarSystemPrivate
-{
-public:
- const KLocale * locale;
-};
-
-ExtCalendarSystem::ExtCalendarSystem(const KLocale * locale)
- : d(new ExtCalendarSystemPrivate)
-{
- d->locale = locale;
-}
-
-ExtCalendarSystem::~ExtCalendarSystem()
-{
- delete d;
-}
-
-const KLocale * ExtCalendarSystem::locale() const
-{
- if ( d->locale )
- return d->locale;
-
- return KGlobal::locale();
-}
-
-QString ExtCalendarSystem::dayString(const ExtDate & pDate, bool bShort) const
-{
- QString sResult;
-
- sResult.setNum(day(pDate));
- if (!bShort && sResult.length() == 1 )
- sResult.prepend('0');
-
- return sResult;
-}
-
-QString ExtCalendarSystem::monthString(const ExtDate & pDate, bool bShort) const
-{
- QString sResult;
-
- sResult.setNum(month(pDate));
- if (!bShort && sResult.length() == 1 )
- sResult.prepend('0');
-
- return sResult;
-}
-
-QString ExtCalendarSystem::yearString(const ExtDate & pDate, bool bShort) const
-{
- QString sResult;
-
- sResult.setNum(year(pDate));
- if (bShort && sResult.length() == 4 )
- sResult = sResult.right(2);
-
- return sResult;
-}
-
-static int stringToInteger(const QString & sNum, int & iLength)
-{
- int iPos = 0;
-
- int result = 0;
- for (; sNum.length() > iPos && sNum.at(iPos).isDigit(); iPos++)
- {
- result *= 10;
- result += sNum.at(iPos).digitValue();
- }
-
- iLength = iPos;
- return result;
-}
-
-
-int ExtCalendarSystem::dayStringToInteger(const QString & sNum, int & iLength) const
-{
- return stringToInteger(sNum, iLength);
-}
-
-int ExtCalendarSystem::monthStringToInteger(const QString & sNum, int & iLength) const
-{
- return stringToInteger(sNum, iLength);
-}
-
-int ExtCalendarSystem::yearStringToInteger(const QString & sNum, int & iLength) const
-{
- return stringToInteger(sNum, iLength);
-}
-
-QString ExtCalendarSystem::weekDayName (int weekDay, bool shortName) const
-{
- if ( shortName )
- switch ( weekDay )
- {
- case 1: return ki18nc("Monday", "Mon").toString(locale());
- case 2: return ki18nc("Tuesday", "Tue").toString(locale());
- case 3: return ki18nc("Wednesday", "Wed").toString(locale());
- case 4: return ki18nc("Thursday", "Thu").toString(locale());
- case 5: return ki18nc("Friday", "Fri").toString(locale());
- case 6: return ki18nc("Saturday", "Sat").toString(locale());
- case 7: return ki18nc("Sunday", "Sun").toString(locale());
- }
- else
- switch ( weekDay )
- {
- case 1: return ki18n("Monday").toString(locale());
- case 2: return ki18n("Tuesday").toString(locale());
- case 3: return ki18n("Wednesday").toString(locale());
- case 4: return ki18n("Thursday").toString(locale());
- case 5: return ki18n("Friday").toString(locale());
- case 6: return ki18n("Saturday").toString(locale());
- case 7: return ki18n("Sunday").toString(locale());
- }
-
- return QString();
-}
-
+++ /dev/null
-/*
- Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es>
- Copyright (c) 2002-2003 Hans Petter Bieker <bieker@kde.org>
- Copyright (c) 2004 Jason Harris <jharris@30doradus.org>
-
- This class has been derived from KCalendarSystem;
- the changesd made just replace QDate objects with ExtDate objects.
- These changes by Jason Harris <jharris@30doradus.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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#ifndef EXTCALENDARSYSTEM_H
-#define EXTCALENDARSYSTEM_H
-
-#include "extdatetime.h"
-
-class KLocale;
-
-class ExtCalendarSystemPrivate;
-
-/**
- * CalendarSystem abstract class, default derived kde gregorian class and
- * factory class. Provides support for different calendar types for kde
- * calendar widget and related stuff.
- *
- * Derived classes must be created through ExtCalendarFactory class
- *
- * @author Carlos Moro <cfmoro@correo.uniovi.es>
- */
-class ExtCalendarSystem
-{
-public:
- /**
- * Constructor of abstract calendar class. This will be called by the derived classes.
- *
- * @param locale It will use this locale for translations, 0 means global.
- */
- ExtCalendarSystem(const KLocale * locale = 0);
-
- /**
- * Descructor.
- */
- virtual ~ExtCalendarSystem();
-
- /**
- * Gets specific calendar type year for a given gregorian date
- *
- * @param date gregorian date
- * @return year
- */
- virtual int year (const ExtDate & date) const = 0;
-
- /**
- * Converts a date into a year literal
- *
- * @param pDate The date to convert
- * @param bShort If the short version of should be used
- * @return The year literal of the date
- */
- virtual QString yearString(const ExtDate & pDate, bool bShort) const;
-
- /**
- * Converts a year literal of a part of a string into a integer starting at the beginning of the string
- *
- * @param sNum The string to parse
- * @param iLength The number of QChars used, and 0 if no valid symbols was found in the string
- * @return An integer corresponding to the year
- */
- virtual int yearStringToInteger(const QString & sNum, int & iLength) const;
-
- /**
- * Gets specific calendar type month for a given gregorian date
- *
- * @param date gregorian date
- * @return month number
- */
- virtual int month (const ExtDate & date) const = 0;
-
- /**
- * Converts a date into a month literal
- *
- * @param pDate The date to convert
- * @param bShort If the short version of should be used
- * @return The month literal of the date
- */
- virtual QString monthString(const ExtDate & pDate, bool bShort) const;
-
- /**
- * Converts a month literal of a part of a string into a integer starting at the beginning of the string
- *
- * @param sNum The string to parse
- * @param iLength The number of QChars used, and 0 if no valid symbols was found in the string
- * @return An integer corresponding to the month
- */
- virtual int monthStringToInteger(const QString & sNum, int & iLength) const;
-
- /**
- * Gets specific calendar type day number of month for a given date
- *
- * @param date gregorian date equivalent to the specific one
- * @return day of the month
- */
- virtual int day (const ExtDate & date) const = 0;
-
- /**
- * Converts a date into a day literal
- *
- * @param pDate The date to convert
- * @param bShort If the short version of should be used
- * @return The day literal of the date
- */
- virtual QString dayString(const ExtDate & pDate, bool bShort) const;
-
- /**
- * Converts a day literal of a part of a string into a integer starting at the beginning of the string
- *
- * @param sNum The string to parse
- * @param iLength The number of QChars used, and 0 if no valid symbols was found in the string
- * @return An integer corresponding to the day
- */
- virtual int dayStringToInteger(const QString & sNum, int & iLength) const;
-
- /**
- * Gets specific calendar type number of day of week number for a given
- * date
- *
- * @param date gregorian date
- * @return day of week
- */
- virtual int dayOfWeek (const ExtDate & date) const = 0;
-
- /**
- * Gets specific calendar type day number of year for a given date
- *
- * @param date gregorian date equivalent to the specific one
- * @return day number
- */
- virtual int dayOfYear (const ExtDate & date) const = 0;
-
- /**
- * Changes the date's year, month and day. The range of the year, month
- * and day depends on which calendar is being used.
- *
- * @param date Date to change
- * @param y Year
- * @param m Month number
- * @param d Day of month
- * @return true if the date is valid; otherwise returns false.
- */
- virtual bool setYMD(ExtDate & date, int y, int m, int d) const = 0;
-
- /**
- * Returns a QDate object containing a date nyears later.
- *
- * @param date The old date
- * @param nyears The number of years to add
- * @return The new date
- */
- virtual ExtDate addYears(const ExtDate & date, int nyears) const = 0;
-
- /**
- * Returns a QDate object containing a date nmonths later.
- *
- * @param date The old date
- * @param nmonths The number of months to add
- * @return The new date
- */
- virtual ExtDate addMonths(const ExtDate & date, int nmonths) const = 0;
-
- /**
- * Returns a QDate object containing a date ndays later.
- *
- * @param date The old date
- * @param ndays The number of days to add
- * @return The new date
- */
- virtual ExtDate addDays(const ExtDate & date, int ndays) const = 0;
-
- /**
- * Gets specific calendar type number of month for a given year
- *
- * @param date The date whose year to use
- * @return The number of months in that year
- */
- virtual int monthsInYear (const ExtDate & date) const = 0;
-
- /**
- * Gets the number of days in date whose years specified.
- *
- * @param date Gregorian date equivalent to the specific one
- * @return The number of days in year
- */
- virtual int daysInYear (const ExtDate & date) const = 0;
-
- /**
- * Gets specific calendar type number of days in month for a given date
- *
- * @param date gregorian date
- * @return number of days for month in date
- */
- virtual int daysInMonth (const ExtDate & date) const = 0;
-
- /**
- * Gets the number of weeks in a specified year
- *
- * @param year the year
- * @return number of weeks in year
- */
- virtual int weeksInYear(int year) const = 0;
-
- /**
- * Gets specific calendar type week number for a given date
- *
- * @param date gregorian date
- * @param yearNum The year the date belongs to
- * @return week number
- */
- virtual int weekNumber(const ExtDate& date, int * yearNum = 0) const = 0;
-
- /**
- * Gets specific calendar type month name for a given month number
- * If an invalid month is specified, QString() is returned.
- *
- * @param month The month number
- * @param year The year the month belongs to
- * @param shortName Specifies if the short month name should be used
- * @return The name of the month
- */
- virtual QString monthName (int month, int year, bool shortName = false) const = 0;
-
- /**
- * Gets specific calendar type month name for a given gregorian date
- *
- * @param date Gregorian date
- * @param shortName Specifies if the short month name should be used
- * @return The name of the month
- */
- virtual QString monthName (const ExtDate & date, bool shortName = false ) const = 0;
-
- /**
- * Returns a string containing the possessive form of the month name.
- * ("of January", "of February", etc.)
- * It's needed in long format dates in some languages.
- * If an invalid month is specified, QString() is returned.
- *
- * @param month The month number
- * @param year The year the month belongs to
- * @param shortName Specifies if the short month name should be used
- *
- * @return The possessive form of the name of the month
- */
- virtual QString monthNamePossessive(int month, int year, bool shortName = false) const = 0;
-
- /**
- * Returns a string containing the possessive form of the month name.
- * ("of January", "of February", etc.)
- * It's needed in long format dates in some languages.
- *
- * @param date Gregorian date
- * @param shortName Specifies if the short month name should be used
- *
- * @return The possessive form of the name of the month
- */
- virtual QString monthNamePossessive(const ExtDate & date, bool shortName = false) const = 0;
-
- /**
- * Gets specific calendar type week day name
- * If an invalid week day is specified, QString() is returned.
- *
- * @param weekDay number of day in week (1 -> Monday)
- * @param shortName short or complete day name
- * @return day name
- */
- virtual QString weekDayName (int weekDay, bool shortName = false) const = 0;
-
- /**
- * Gets specific calendar type week day name
- *
- * @param date the date
- * @param shortName short or complete day name
- * @return day name
- */
- virtual QString weekDayName (const ExtDate & date, bool shortName = false) const = 0;
-
- /**
- * Gets the first year value supported by specific calendar type
- * algorithms.
- *
- * @return first year supported
- */
- virtual int minValidYear () const = 0;
-
- /**
- * Gets the maximum year value supported by specific calendar type
- * algorithms (QDate, 8000)
- *
- * @return maximum year supported
- */
- virtual int maxValidYear () const = 0;
-
- /**
- * Gets the day of the week traditionaly associated with pray
- *
- * @return day number
- */
- virtual int weekDayOfPray () const = 0;
-
- /**
- * Gets the string representing the calendar
- */
- virtual QString calendarName() const = 0;
-
- /**
- * Gets if the calendar is lunar based
- *
- * @return if the calendar is lunar based
- */
- virtual bool isLunar() const = 0;
-
- /**
- * Gets if the calendar is lunisolar based
- *
- * @return if the calendar is lunisolar based
- */
- virtual bool isLunisolar() const = 0;
-
- /**
- * Gets if the calendar is solar based
- *
- * @return if the calendar is solar based
- */
- virtual bool isSolar() const = 0;
-
-protected:
- const KLocale * locale() const;
-
-private:
- ExtCalendarSystemPrivate * d;
-};
-
-#endif
+++ /dev/null
-/*
- Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es>
- Copyright (c) 2002-2003 Hans Petter Bieker <bieker@kde.org>
- Copyright (c) 2004 Jason Harris <jharris@30doradus.org>
-
- This class has been derived from KCalendarSystemGregorian;
- the changesd made just replace QDate objects with ExtDate objects.
- These changes by Jason Harris <jharris@30doradus.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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-// Derived gregorian kde calendar class
-// Just a schema.
-
-
-#include "extcalendarsystemgregorian.h"
-
-#include <klocale.h>
-#include <kdebug.h>
-
-ExtCalendarSystemGregorian::ExtCalendarSystemGregorian(const KLocale * locale)
- : ExtCalendarSystem(locale)
-{
-}
-
-ExtCalendarSystemGregorian::~ExtCalendarSystemGregorian()
-{
-}
-
-int ExtCalendarSystemGregorian::year(const ExtDate& date) const
-{
- return date.year();
-}
-
-int ExtCalendarSystemGregorian::monthsInYear( const ExtDate & date ) const
-{
- Q_UNUSED( date )
-
- return 12;
-}
-
-int ExtCalendarSystemGregorian::weeksInYear(int year) const
-{
- ExtDate temp;
- temp.setYMD(year, 12, 31);
-
- // If the last day of the year is in the first week, we have to check the
- // week before
- if ( temp.weekNumber() == 1 )
- temp = temp.addDays(-7);
-
- return temp.weekNumber();
-}
-
-int ExtCalendarSystemGregorian::weekNumber(const ExtDate& date,
- int * yearNum) const
-{
- return date.weekNumber(yearNum);
-}
-
-QString ExtCalendarSystemGregorian::monthName(const ExtDate& date,
- bool shortName) const
-{
- return monthName(month(date), year(date), shortName);
-}
-
-QString ExtCalendarSystemGregorian::monthNamePossessive(const ExtDate& date, bool shortName) const
-{
- return monthNamePossessive(month(date), year(date), shortName);
-}
-
-QString ExtCalendarSystemGregorian::monthName(int month, int year, bool shortName) const
-{
- Q_UNUSED(year);
-
- if ( shortName )
- switch ( month )
- {
- case 1:
- return ki18nc("January", "Jan").toString(locale());
- case 2:
- return ki18nc("February", "Feb").toString(locale());
- case 3:
- return ki18nc("March", "Mar").toString(locale());
- case 4:
- return ki18nc("April", "Apr").toString(locale());
- case 5:
- return ki18nc("May short", "May").toString(locale());
- case 6:
- return ki18nc("June", "Jun").toString(locale());
- case 7:
- return ki18nc("July", "Jul").toString(locale());
- case 8:
- return ki18nc("August", "Aug").toString(locale());
- case 9:
- return ki18nc("September", "Sep").toString(locale());
- case 10:
- return ki18nc("October", "Oct").toString(locale());
- case 11:
- return ki18nc("November", "Nov").toString(locale());
- case 12:
- return ki18nc("December", "Dec").toString(locale());
- }
- else
- switch ( month )
- {
- case 1:
- return ki18n("January").toString(locale());
- case 2:
- return ki18n("February").toString(locale());
- case 3:
- return ki18n("March").toString(locale());
- case 4:
- return ki18n("April").toString(locale());
- case 5:
- return ki18nc("May long", "May").toString(locale());
- case 6:
- return ki18n("June").toString(locale());
- case 7:
- return ki18n("July").toString(locale());
- case 8:
- return ki18n("August").toString(locale());
- case 9:
- return ki18n("September").toString(locale());
- case 10:
- return ki18n("October").toString(locale());
- case 11:
- return ki18n("November").toString(locale());
- case 12:
- return ki18n("December").toString(locale());
- }
-
- return QString();
-}
-
-QString ExtCalendarSystemGregorian::monthNamePossessive(int month, int year,
- bool shortName) const
-{
- Q_UNUSED(year);
-
- if ( shortName )
- switch ( month )
- {
- case 1:
- return ki18nc("of January", "of Jan").toString(locale());
- case 2:
- return ki18nc("of February", "of Feb").toString(locale());
- case 3:
- return ki18nc("of March", "of Mar").toString(locale());
- case 4:
- return ki18nc("of April", "of Apr").toString(locale());
- case 5:
- return ki18nc("of May short", "of May").toString(locale());
- case 6:
- return ki18nc("of June", "of Jun").toString(locale());
- case 7:
- return ki18nc("of July", "of Jul").toString(locale());
- case 8:
- return ki18nc("of August", "of Aug").toString(locale());
- case 9:
- return ki18nc("of September", "of Sep").toString(locale());
- case 10:
- return ki18nc("of October", "of Oct").toString(locale());
- case 11:
- return ki18nc("of November", "of Nov").toString(locale());
- case 12:
- return ki18nc("of December", "of Dec").toString(locale());
- }
- else
- switch ( month )
- {
- case 1:
- return ki18n("of January").toString(locale());
- case 2:
- return ki18n("of February").toString(locale());
- case 3:
- return ki18n("of March").toString(locale());
- case 4:
- return ki18n("of April").toString(locale());
- case 5:
- return ki18nc("of May long", "of May").toString(locale());
- case 6:
- return ki18n("of June").toString(locale());
- case 7:
- return ki18n("of July").toString(locale());
- case 8:
- return ki18n("of August").toString(locale());
- case 9:
- return ki18n("of September").toString(locale());
- case 10:
- return ki18n("of October").toString(locale());
- case 11:
- return ki18n("of November").toString(locale());
- case 12:
- return ki18n("of December").toString(locale());
- }
-
- return QString();
-}
-
-bool ExtCalendarSystemGregorian::setYMD(ExtDate & date, int y, int m, int d) const
-{
- // ExtDate supports gregorian internally
- return date.setYMD(y, m, d);
-}
-
-ExtDate ExtCalendarSystemGregorian::addYears(const ExtDate & date, int nyears) const
-{
- return date.addYears(nyears);
-}
-
-ExtDate ExtCalendarSystemGregorian::addMonths(const ExtDate & date, int nmonths) const
-{
- return date.addMonths(nmonths);
-}
-
-ExtDate ExtCalendarSystemGregorian::addDays(const ExtDate & date, int ndays) const
-{
- return date.addDays(ndays);
-}
-
-QString ExtCalendarSystemGregorian::weekDayName(int col, bool shortName) const
-{
- // ### Should this really be different to each calendar system? Or are we
- // only going to support weeks with 7 days?
-
- return ExtCalendarSystem::weekDayName(col, shortName);
-}
-
-QString ExtCalendarSystemGregorian::weekDayName(const ExtDate& date, bool shortName) const
-{
- return weekDayName(dayOfWeek(date), shortName);
-}
-
-
-int ExtCalendarSystemGregorian::dayOfWeek(const ExtDate& date) const
-{
- return date.dayOfWeek();
-}
-
-int ExtCalendarSystemGregorian::dayOfYear(const ExtDate & date) const
-{
- return date.dayOfYear();
-}
-
-int ExtCalendarSystemGregorian::daysInMonth(const ExtDate& date) const
-{
- return date.daysInMonth();
-}
-
-int ExtCalendarSystemGregorian::minValidYear() const
-{
- return -50000;
-}
-
-int ExtCalendarSystemGregorian::maxValidYear() const
-{
- return 50000;
-}
-
-int ExtCalendarSystemGregorian::day(const ExtDate& date) const
-{
- return date.day();
-}
-
-int ExtCalendarSystemGregorian::month(const ExtDate& date) const
-{
- return date.month();
-}
-
-int ExtCalendarSystemGregorian::daysInYear(const ExtDate& date) const
-{
- return date.daysInYear();
-}
-
-int ExtCalendarSystemGregorian::weekDayOfPray() const
-{
- return 7; // sunday
-}
-
-QString ExtCalendarSystemGregorian::calendarName() const
-{
- return QString::fromLatin1("gregorian");
-}
-
-bool ExtCalendarSystemGregorian::isLunar() const
-{
- return false;
-}
-
-bool ExtCalendarSystemGregorian::isLunisolar() const
-{
- return false;
-}
-
-bool ExtCalendarSystemGregorian::isSolar() const
-{
- return true;
-}
-
-int ExtCalendarSystemGregorian::yearStringToInteger(const QString & sNum, int & iLength) const
-{
- int iYear;
- iYear = ExtCalendarSystem::yearStringToInteger(sNum, iLength);
-
- // Qt treats a year in the range 0-100 as 1900-1999.
- // It is nicer for the user if we treat 0-68 as 2000-2068
- if (iYear < 69)
- iYear += 2000;
- else if (iYear < 100)
- iYear += 1900;
-
- return iYear;
-}
+++ /dev/null
-/*
- Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es>
- Copyright (c) 2002 Hans Petter Bieker <bieker@kde.org>
- Copyright (c) 2004 Jason Harris <jharris@30doradus.org>
-
- This class has been derived from KCalendarSystemGregorian;
- the changesd made just replace QDate objects with ExtDate objects.
- These changes by Jason Harris <jharris@30doradus.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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#ifndef EXTCALENDARSYSTEMGREGORIAN_H
-#define EXTCALENDARSYSTEMGREGORIAN_H
-
-
-#include "extcalendarsystem.h"
-
-class ExtCalendarSystemGregorianPrivate;
-
-/**
- * @internal
- * This is the Gregorian calendar implementation.
- *
- * The Gregorian calender is the most used calendar today. The first year in
- * the calendar is set to the birth of Christ.
- *
- * @see KLocale,ExtCalendarSystem,ExtCalendarSystemFactory
- *
- * @author Carlos Moro <cfmoro@correo.uniovi.es>
- */
-class ExtCalendarSystemGregorian: public ExtCalendarSystem
-{
-public:
- ExtCalendarSystemGregorian (const KLocale * locale = 0);
- virtual ~ExtCalendarSystemGregorian ();
-
- virtual int year (const ExtDate & date) const;
- virtual int month (const ExtDate & date) const;
- virtual int day (const ExtDate & date) const;
- virtual int dayOfWeek (const ExtDate & date) const;
- virtual int dayOfYear (const ExtDate & date) const;
-
- virtual bool setYMD(ExtDate & date, int y, int m, int d) const;
-
- virtual ExtDate addYears(const ExtDate & date, int nyears) const;
- virtual ExtDate addMonths(const ExtDate & date, int nmonths) const;
- virtual ExtDate addDays(const ExtDate & date, int ndays) const;
-
- virtual int monthsInYear (const ExtDate & date) const;
-
- virtual int daysInYear (const ExtDate & date) const;
- virtual int daysInMonth (const ExtDate & date) const;
- virtual int weeksInYear(int year) const;
- virtual int weekNumber(const ExtDate& date, int * yearNum = 0) const;
-
- virtual int yearStringToInteger(const QString & sNum, int & iLength) const;
-
- virtual QString monthName (int month, int year, bool shortName = false) const;
- virtual QString monthName (const ExtDate & date, bool shortName = false ) const;
- virtual QString monthNamePossessive(int month, int year, bool shortName = false) const;
- virtual QString monthNamePossessive(const ExtDate & date, bool shortName = false ) const;
- virtual QString weekDayName (int weekDay, bool shortName = false) const;
- virtual QString weekDayName (const ExtDate & date, bool shortName = false) const;
-
- virtual int minValidYear () const;
- virtual int maxValidYear () const;
- virtual int weekDayOfPray () const;
-
- virtual QString calendarName() const;
-
- virtual bool isLunar() const;
- virtual bool isLunisolar() const;
- virtual bool isSolar() const;
-
-private:
- ExtCalendarSystemGregorianPrivate * d;
-};
-
-#endif
+++ /dev/null
-/* -*- C++ -*-
- This file is part of the KDE libraries
- Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
- (C) 1998-2001 Mirko Boehm (mirko@kde.org)
- (C) 2004 Jason Harris (jharris@30doradus.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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#include "extdatepicker.h"
-
-#include <QApplication>
-#include <KComboBox>
-#include <QKeyEvent>
-#include <QLayout>
-#include <QStyle>
-#include <QToolButton>
-#include <QMenu>
-
-#include <kdialog.h>
-#include <klocale.h>
-#include <kicon.h>
-#include <kdebug.h>
-#include <knotification.h>
-
-#include "extdatetbl.h"
-#include "extdatepicker.moc"
-
-// Week numbers are defined by ISO 8601
-// See http://www.merlyn.demon.co.uk/weekinfo.htm for details
-
-class ExtDatePicker::ExtDatePickerPrivate
-{
-public:
- ExtDatePickerPrivate(ExtDatePicker *qq) : q(qq), closeButton(0L), selectWeek(0L), todayButton(0),
- navigationLayout(0), calendar(0) {}
-
- void fillWeeksCombo(const ExtDate &date);
-
- ExtDatePicker *q;
-
- QToolButton *closeButton;
- KComboBox *selectWeek;
- QToolButton *todayButton;
- QBoxLayout *navigationLayout;
- ExtCalendarSystem *calendar;
- int fontsize;
-};
-
-void ExtDatePicker::ExtDatePickerPrivate::fillWeeksCombo(const ExtDate &date)
-{
- // every year can have a different number of weeks
-
-//must remain commented unless ExtDate stuff gets added to kdelibs
-// const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();
-
- // it could be that we had 53,1..52 and now 1..53 which is the same number but different
- // so always fill with new values
-
- selectWeek->clear();
-
- // We show all week numbers for all weeks between first day of year to last day of year
- // This of course can be a list like 53,1,2..52
-
- ExtDate day(date.year(), 1, 1);
- int lastMonth = calendar->monthsInYear(day);
- ExtDate lastDay(date.year(), lastMonth, calendar->daysInMonth(ExtDate(date.year(), lastMonth, 1)));
-
- for (; day <= lastDay; day = calendar->addDays(day, 7 /*calendar->daysOfWeek()*/) )
- {
- int year = 0;
- QString week = i18n("Week %1", calendar->weekNumber(day, &year));
- if ( year != date.year() ) week += '*'; // show that this is a week from a different year
- selectWeek->addItem(week);
- }
-}
-
-ExtDatePicker::ExtDatePicker(ExtDate dt, QWidget *parent, Qt::WindowFlags f)
- : QFrame(parent, f), d(new ExtDatePickerPrivate(this))
-{
- init( dt );
-}
-
-ExtDatePicker::ExtDatePicker(QWidget *parent, Qt::WindowFlags f)
- : QFrame(parent, f), d(new ExtDatePickerPrivate(this))
-{
- init( ExtDate::currentDate() );
-}
-
-void ExtDatePicker::init( const ExtDate &dt )
-{
- d->calendar = new ExtCalendarSystemGregorian();
-
- QBoxLayout * topLayout = new QVBoxLayout(this);
-
- d->navigationLayout = new QHBoxLayout();
- topLayout->addLayout(d->navigationLayout);
- d->navigationLayout->addStretch();
- yearBackward = new QToolButton(this);
- yearBackward->setAutoRaise(true);
- d->navigationLayout->addWidget(yearBackward);
- monthBackward = new QToolButton(this);
- monthBackward ->setAutoRaise(true);
- d->navigationLayout->addWidget(monthBackward);
- d->navigationLayout->addSpacing(KDialog::spacingHint());
-
- selectMonth = new QToolButton(this);
- selectMonth ->setAutoRaise(true);
- d->navigationLayout->addWidget(selectMonth);
- selectYear = new QToolButton(this);
- selectYear->setCheckable(true);
- selectYear->setAutoRaise(true);
- d->navigationLayout->addWidget(selectYear);
- d->navigationLayout->addSpacing(KDialog::spacingHint());
-
- monthForward = new QToolButton(this);
- monthForward ->setAutoRaise(true);
- d->navigationLayout->addWidget(monthForward);
- yearForward = new QToolButton(this);
- yearForward ->setAutoRaise(true);
- d->navigationLayout->addWidget(yearForward);
- d->navigationLayout->addStretch();
-
- line = new KLineEdit(this);
- val = new ExtDateValidator(this);
- table = new ExtDateTable(this);
- d->fontsize = KGlobalSettings::generalFont().pointSize();
- if (d->fontsize == -1)
- d->fontsize = QFontInfo(KGlobalSettings::generalFont()).pointSize();
-
- ++d->fontsize; // Make a little bigger
-
- d->selectWeek = new KComboBox(this);
- d->selectWeek->setEditable(false); // read only week selection
- d->todayButton = new QToolButton(this);
- d->todayButton->setIcon(KIcon("go-jump-today"));
-
- yearForward->setToolTip(i18n("Next year"));
- yearBackward->setToolTip(i18n("Previous year"));
- monthForward->setToolTip(i18n("Next month"));
- monthBackward->setToolTip(i18n("Previous month"));
- d->selectWeek->setToolTip(i18n("Select a week"));
- selectMonth->setToolTip(i18n("Select a month"));
- selectYear->setToolTip(i18n("Select a year"));
- d->todayButton->setToolTip(i18n("Select the current day"));
-
- // -----
- setFontSize(d->fontsize);
- line->setValidator(val);
- line->installEventFilter( this );
- if ( QApplication::isRightToLeft() )
- {
- yearForward->setIcon(KIcon(QLatin1String("arrow-left-double")));
- yearBackward->setIcon(KIcon(QLatin1String("arrow-right-double")));
- monthForward->setIcon(KIcon(QLatin1String("arrow-left")));
- monthBackward->setIcon(KIcon(QLatin1String("arrow-right")));
- }
- else
- {
- yearForward->setIcon(KIcon(QLatin1String("arrow-right-double")));
- yearBackward->setIcon(KIcon(QLatin1String("arrow-left-double")));
- monthForward->setIcon(KIcon(QLatin1String("arrow-right")));
- monthBackward->setIcon(KIcon(QLatin1String("arrow-left")));
- }
- connect(table, SIGNAL(dateChanged(const ExtDate&)), SLOT(dateChangedSlot(const ExtDate&)));
- connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()));
- connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()));
- connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
- connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
- connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
- connect(d->selectWeek, SIGNAL(activated(int)), SLOT(weekSelected(int)));
- connect(d->todayButton, SIGNAL(clicked()), SLOT(todayButtonClicked()));
- connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
- connect(selectYear, SIGNAL(toggled(bool)), SLOT(selectYearClicked()));
- connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
- table->setFocus();
-
-
- topLayout->addWidget(table);
-
- QBoxLayout * bottomLayout = new QHBoxLayout();
- topLayout->addLayout(bottomLayout);
- bottomLayout->addWidget(d->todayButton);
- bottomLayout->addWidget(line);
- bottomLayout->addWidget(d->selectWeek);
-
- table->setDate(dt);
- dateChangedSlot(dt); // needed because table emits changed only when newDate != oldDate
-}
-
-ExtDatePicker::~ExtDatePicker()
-{
- delete d;
-}
-
-bool
-ExtDatePicker::eventFilter(QObject *o, QEvent *e )
-{
- if ( e->type() == QEvent::KeyPress ) {
- QKeyEvent *k = (QKeyEvent *)e;
-
- if ( (k->key() == Qt::Key_PageUp) ||
- (k->key() == Qt::Key_PageDown) ||
- (k->key() == Qt::Key_Up) ||
- (k->key() == Qt::Key_Down) )
- {
- QApplication::sendEvent( table, e );
- table->setFocus();
- return true; // eat event
- }
- }
- return QFrame::eventFilter( o, e );
-}
-
-void
-ExtDatePicker::resizeEvent(QResizeEvent* e)
-{
- QWidget::resizeEvent(e);
-}
-
-void
-ExtDatePicker::dateChangedSlot(const ExtDate &date)
-{
- kDebug(298) << "ExtDatePicker::dateChangedSlot: date changed (" << date.year() << "/" << date.month() << "/" << date.day() << ").";
-
-
-//must remain commented unless ExtDate gets added to kdelibs
-// const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();
-
-// line->setText(KGlobal::locale()->formatDate(date, true));
- line->setText( date.toString( KGlobal::locale()->dateFormatShort() ) );
- selectMonth->setText(d->calendar->monthName(date, false));
- d->fillWeeksCombo(date);
-
- // calculate the item num in the week combo box; normalize selected day so as if 1.1. is the first day of the week
- ExtDate firstDay(date.year(), 1, 1);
- d->selectWeek->setCurrentIndex((d->calendar->dayOfYear(date) + d->calendar->dayOfWeek(firstDay) - 2) / 7/*calendar->daysInWeek()*/);
-
- selectYear->setText(d->calendar->yearString(date, false));
-
- emit(dateChanged(date));
-}
-
-void
-ExtDatePicker::tableClickedSlot()
-{
- kDebug(298) << "ExtDatePicker::tableClickedSlot: table clicked.";
- emit(dateSelected(table->getDate()));
- emit(tableClicked());
-}
-
-const ExtDate &
-ExtDatePicker::date() const
-{
- return table->getDate();
-}
-
-bool
-ExtDatePicker::setDate(const ExtDate& date)
-{
- if(date.isValid())
- {
- table->setDate(date); // this also emits dateChanged() which then calls our dateChangedSlot()
- return true;
- }
- else
- {
- kDebug(298) << "ExtDatePicker::setDate: refusing to set invalid date.";
- return false;
- }
-}
-
-void
-ExtDatePicker::monthForwardClicked()
-{
- ExtDate temp;
-// temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), 1 );
- temp = d->calendar->addMonths( table->getDate(), 1 );
- setDate( temp );
-}
-
-void
-ExtDatePicker::monthBackwardClicked()
-{
- ExtDate temp;
-// temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), -1 );
- temp = d->calendar->addMonths( table->getDate(), -1 );
- setDate( temp );
-}
-
-void
-ExtDatePicker::yearForwardClicked()
-{
- ExtDate temp;
-// temp = KGlobal::locale()->calendar()->addYears( table->getDate(), 1 );
- temp = d->calendar->addYears( table->getDate(), 1 );
- setDate( temp );
-}
-
-void
-ExtDatePicker::yearBackwardClicked()
-{
- ExtDate temp;
-// temp = KGlobal::locale()->calendar()->addYears( table->getDate(), -1 );
- temp = d->calendar->addYears( table->getDate(), -1 );
- setDate( temp );
-}
-
-void ExtDatePicker::selectWeekClicked() {} // ### in 3.2 obsolete; kept for binary compatibility
-
-void
-ExtDatePicker::weekSelected(int week)
-{
-// const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();
-
- ExtDate date = table->getDate();
- int year = d->calendar->year(date);
-
- d->calendar->setYMD(date, year, 1, 1); // first day of selected year
-
- // calculate the first day in the selected week (day 1 is first day of week)
- date = d->calendar->addDays(date, week * 7/*calendar->daysOfWeek()*/ -d->calendar->dayOfWeek(date) + 1);
-
- setDate(date);
-}
-
-void
-ExtDatePicker::selectMonthClicked()
-{
- // every year can have different month names (in some calendar systems)
-// const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();
- ExtDate date = table->getDate();
- int i, month, months = d->calendar->monthsInYear(date);
-
- QMenu popup(selectMonth);
-
- QList<QAction*> monthactions;
- for (i = 1; i <= months; i++) {
- // popup.insertItem(d->calendar->monthName(i, d->calendar->year(date)), i);
- QAction *a = popup.addAction( d->calendar->monthName(i, d->calendar->year(date)) );
- monthactions.append(a);
- }
- QAction *active = monthactions.at(d->calendar->month(date) - 1);
- popup.setActiveAction(active);
-
- QAction *act = popup.exec(selectMonth->mapToGlobal(QPoint(0, 0)), active);
- if (!act) return; // canceled
- month = monthactions.indexOf(act)+1;
-
- int day = d->calendar->day(date);
- // ----- construct a valid date in this month:
- //date.setYMD(date.year(), month, 1);
- //date.setYMD(date.year(), month, qMin(day, date.daysInMonth()));
- d->calendar->setYMD(date, d->calendar->year(date), month,
- qMin(day, d->calendar->daysInMonth(date)));
- // ----- set this month
- setDate(date);
-}
-
-void
-ExtDatePicker::selectYearClicked()
-{
-// const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();
-
- if (!selectYear->isChecked())
- {
- return;
- }
-
- int year;
- KPopupFrame* popup = new KPopupFrame(this);
- ExtDateInternalYearSelector* picker = new ExtDateInternalYearSelector(popup);
- picker->setYear(d->calendar->year(table->getDate()));
- // -----
- picker->resize(picker->sizeHint());
- popup->setMainWidget(picker);
- connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
- picker->setFocus();
- if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height()))))
- {
- ExtDate date;
- int day;
- // -----
- year=picker->getYear();
- date=table->getDate();
- day=d->calendar->day(date);
- // ----- construct a valid date in this month:
- //date.setYMD(year, date.month(), 1);
- //date.setYMD(year, date.month(), qMin(day, date.daysInMonth()));
- d->calendar->setYMD(date, year, d->calendar->month(date),
- qMin(day, d->calendar->daysInMonth(date)));
- // ----- set this month
- setDate(date);
- } else {
- KNotification::beep();
- }
- delete popup;
- selectYear->setChecked(false);
-}
-
-void
-ExtDatePicker::setEnabled(bool enable)
-{
- QWidget *widgets[]= {
- yearForward, yearBackward, monthForward, monthBackward,
- selectMonth, selectYear,
- line, table, d->selectWeek, d->todayButton };
- const int Size=sizeof(widgets)/sizeof(widgets[0]);
- int count;
- // -----
- for(count=0; count<Size; ++count)
- {
- widgets[count]->setEnabled(enable);
- }
-}
-
-void
-ExtDatePicker::lineEnterPressed()
-{
- ExtDate temp;
- // -----
- if(val->date(line->text(), temp)==QValidator::Acceptable)
- {
- kDebug(298) << "ExtDatePicker::lineEnterPressed: valid date entered.";
- emit(dateEntered(temp));
- setDate(temp);
- } else {
- KNotification::beep();
- kDebug(298) << "ExtDatePicker::lineEnterPressed: invalid date entered.";
- }
-}
-
-void
-ExtDatePicker::todayButtonClicked()
-{
- setDate(ExtDate::currentDate());
-}
-
-QSize
-ExtDatePicker::sizeHint() const
-{
- return QWidget::sizeHint();
-}
-
-void
-ExtDatePicker::setFontSize(int s)
-{
- QWidget *buttons[]= {
- // yearBackward,
- // monthBackward,
- selectMonth,
- selectYear,
- // monthForward,
- // yearForward
- };
- const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
- int count;
- QFont font;
- QRect r;
- // -----
- d->fontsize=s;
- for(count=0; count<NoOfButtons; ++count)
- {
- font=buttons[count]->font();
- font.setPointSize(s);
- buttons[count]->setFont(font);
- }
- QFontMetrics metrics(selectMonth->fontMetrics());
-
- for (int i = 1; ; ++i)
- {
- QString str = d->calendar->monthName(i,
- d->calendar->year(table->getDate()), false);
- if (str.isNull()) break;
- r=metrics.boundingRect(str);
- maxMonthRect.setWidth(qMax(r.width(), maxMonthRect.width()));
- maxMonthRect.setHeight(qMax(r.height(), maxMonthRect.height()));
- }
-
- QStyleOptionToolButton qsotb;
- QSize metricBound = style()->sizeFromContents(QStyle::CT_ToolButton,
- &qsotb,
- maxMonthRect);
- selectMonth->setMinimumSize(metricBound);
-
- table->setFontSize(s);
-}
-
-int
-ExtDatePicker::fontSize() const
-{
- return d->fontsize;
-}
-
-void
-ExtDatePicker::setCloseButton( bool enable )
-{
- if ( enable == (d->closeButton != 0L) )
- return;
-
- if ( enable ) {
- d->closeButton = new QToolButton( this );
- d->closeButton->setAutoRaise(true);
- d->navigationLayout->addSpacing(KDialog::spacingHint());
- d->navigationLayout->addWidget(d->closeButton);
- d->closeButton->setToolTip(i18n("Close"));
- d->closeButton->setIcon( KIcon("list-remove") );
- connect( d->closeButton, SIGNAL( clicked() ),
- topLevelWidget(), SLOT( close() ) );
- }
- else {
- delete d->closeButton;
- d->closeButton = 0L;
- }
-
- updateGeometry();
-}
-
-bool ExtDatePicker::hasCloseButton() const
-{
- return (d->closeButton != 0L);
-}
+++ /dev/null
-/* -*- C++ -*-
- This file is part of the KDE libraries
- Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
- (C) 1998-2001 Mirko Boehm (mirko@kde.org)
- (C) 2004 Jason Harris (jharris@30doradus.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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-#ifndef EXTDATEPICKER_H
-#define EXTDATEPICKER_H
-
-#include <libkdeedu_extdate_export.h>
-
-#include "extdatetime.h"
-#include <QFrame>
-
-class QLineEdit;
-class QToolButton;
-class ExtDateValidator;
-class ExtDateTable;
-
-/**
- * Provides a widget for calendar date input.
- *
- * Different from the
- * previous versions, it now emits two types of signals, either
- * dateSelected() or dateEntered() (see documentation for both
- * signals).
- *
- * A line edit has been added in the newer versions to allow the user
- * to select a date directly by entering numbers like 19990101
- * or 990101.
- *
- * \image html kdatepicker.png "KDE Date Widget"
- *
- * @version $Id$
- * @author Tim Gilman, Mirko Boehm
- *
- * @short A date selection widget.
- **/
-class EXTDATE_EXPORT ExtDatePicker: public QFrame
-{
- Q_OBJECT
-// Q_PROPERTY( ExtDate date READ date WRITE setDate)
- Q_PROPERTY( bool closeButton READ hasCloseButton WRITE setCloseButton )
- Q_PROPERTY( int fontSize READ fontSize WRITE setFontSize )
-
-public:
- /** The usual constructor. The given date will be displayed
- * initially.
- **/
- explicit ExtDatePicker(ExtDate, QWidget *parent=0, Qt::WindowFlags f=0);
-
- /** The usual constructor. The given date will be displayed
- * initially.
- **/
- explicit ExtDatePicker(QWidget *parent=0, Qt::WindowFlags f=0);
-
- /**
- * The destructor.
- **/
- virtual ~ExtDatePicker();
-
- /** The size hint for date pickers. The size hint recommends the
- * minimum size of the widget so that all elements may be placed
- * without clipping. This sometimes looks ugly, so when using the
- * size hint, try adding 28 to each of the reported numbers of
- * pixels.
- **/
- virtual QSize sizeHint() const;
-
- /**
- * Sets the date.
- *
- * @returns @p false and does not change anything
- * if the date given is invalid.
- **/
- bool setDate(const ExtDate&);
-
- /**
- * @returns the selected date.
- */
- const ExtDate &date() const;
-
- /**
- * Enables or disables the widget.
- **/
- void setEnabled(bool);
-
- /**
- * @returns the ExtDateTable widget child of this ExtDatePicker
- * widget.
- */
- ExtDateTable *dateTable() const { return table; }
-
- /**
- * Sets the font size of the widgets elements.
- **/
- void setFontSize(int);
- /**
- * Returns the font size of the widget elements.
- */
- int fontSize() const;
-
- /**
- * By calling this method with @p enable = true, ExtDatePicker will show
- * a little close-button in the upper button-row. Clicking the
- * close-button will cause the ExtDatePicker's topLevelWidget()'s close()
- * method being called. This is mostly useful for toplevel datepickers
- * without a window manager decoration.
- * @see hasCloseButton
- */
- void setCloseButton( bool enable );
-
- /**
- * @returns true if a ExtDatePicker shows a close-button.
- * @see setCloseButton
- */
- bool hasCloseButton() const;
-
-protected:
- /// to catch move keyEvents when QLineEdit has keyFocus
- virtual bool eventFilter(QObject *o, QEvent *e );
- /// the resize event
- virtual void resizeEvent(QResizeEvent*);
- /// the year forward button
- QToolButton *yearForward;
- /// the year backward button
- QToolButton *yearBackward;
- /// the month forward button
- QToolButton *monthForward;
- /// the month backward button
- QToolButton *monthBackward;
- /// the button for selecting the month directly
- QToolButton *selectMonth;
- /// the button for selecting the year directly
- QToolButton *selectYear;
- /// the line edit to enter the date directly
- QLineEdit *line;
- /// the validator for the line edit:
- ExtDateValidator *val;
- /// the date table
- ExtDateTable *table;
- /// the size calculated during resize events
- // QSize sizehint;
- /// the widest month string in pixels:
- QSize maxMonthRect;
-protected slots:
- void dateChangedSlot(const ExtDate&);
- void tableClickedSlot();
- void monthForwardClicked();
- void monthBackwardClicked();
- void yearForwardClicked();
- void yearBackwardClicked();
- void selectWeekClicked();
- void selectMonthClicked();
- void selectYearClicked();
- void lineEnterPressed();
- void todayButtonClicked();
- void weekSelected(int);
-
-signals:
- /** This signal is emitted each time the selected date is changed.
- * Usually, this does not mean that the date has been entered,
- * since the date also changes, for example, when another month is
- * selected.
- * @see dateSelected
- */
- void dateChanged(const ExtDate&);
- /** This signal is emitted each time a day has been selected by
- * clicking on the table (hitting a day in the current month). It
- * has the same meaning as dateSelected() in older versions of
- * ExtDatePicker.
- */
- void dateSelected(const ExtDate&);
- /** This signal is emitted when enter is pressed and a VALID date
- * has been entered before into the line edit. Connect to both
- * dateEntered() and dateSelected() to receive all events where the
- * user really enters a date.
- */
- void dateEntered(const ExtDate&);
- /** This signal is emitted when the day has been selected by
- * clicking on it in the table.
- */
- void tableClicked();
-
-private:
- void init( const ExtDate &dt );
- class ExtDatePickerPrivate;
- ExtDatePickerPrivate *const d;
-};
-
-#endif // EXTDATEPICKER_H
+++ /dev/null
-/* -*- C++ -*-
- This file is part of the KDE libraries
- Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
- (C) 1998-2001 Mirko Boehm (mirko@kde.org)
- (C) 2004 Jason Harris (jharris@30doradus.org)
-
- These classes has been derived from those in kdatetbl.[h|cpp].
- The only differences are adaptations to use ExtDate instead of QDate,
- to allow for more remote dates. These changes by Jason Harris.
-
- 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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-/////////////////// ExtDateTable widget class //////////////////////
-//
-// Copyright (C) 1997 Tim D. Gilman
-// (C) 1998-2001 Mirko Boehm
-// Written using Qt (http://www.troll.no) for the
-// KDE project (http://www.kde.org)
-//
-// Modified to use ExtDate by Jason Harris, 2004
-//
-// This is a support class for the ExtDatePicker class. It just
-// draws the calender table without titles, but could theoretically
-// be used as a standalone.
-//
-// When a date is selected by the user, it emits a signal:
-// dateSelected(ExtDate)
-
-//#include "extdatepicker.h"
-#include "extdatetbl.h"
-
-#include <kdebug.h>
-#include <kmenu.h>
-#include <knotification.h>
-#include <kcolorscheme.h>
-#include <QApplication>
-#include <QPainter>
-#include <Q3Dict>
-#include <QWheelEvent>
-#include <QFocusEvent>
-#include <QKeyEvent>
-#include <QEvent>
-#include <QFrame>
-#include <QResizeEvent>
-#include <QMouseEvent>
-#include <assert.h>
-
-
-class ExtDateTable::ExtDateTablePrivate
-{
-public:
- ExtDateTablePrivate()
- {
- popupMenuEnabled=false;
- useCustomColors=false;
- calendar = new ExtCalendarSystemGregorian();
-
- }
-
- ~ExtDateTablePrivate()
- {
- delete calendar;
- }
-
- bool popupMenuEnabled;
- bool useCustomColors;
-
- struct DatePaintingMode
- {
- QColor fgColor;
- QColor bgColor;
- BackgroundMode bgMode;
- };
- Q3Dict <DatePaintingMode> customPaintingModes;
- ExtCalendarSystem *calendar;
-};
-
-
-ExtDateValidator::ExtDateValidator(QWidget* parent)
- : QValidator(parent)
-{
-}
-
-QValidator::State
-ExtDateValidator::validate(QString& text, int&) const
-{
- ExtDate temp;
- // ----- everything is tested in date():
- return date(text, temp);
-}
-
-QValidator::State
-ExtDateValidator::date(const QString& text, ExtDate& ed) const
-{
- //FIXME: Can't uncomment unless ExtDate is adopted by KDE
- //ExtDate tmp = KGlobal::locale()->readDate(text);
- ExtDate tmp = ExtDate::fromString( text );
-
- if (!tmp.isNull())
- {
- ed = tmp;
- return Acceptable;
- } else
- return QValidator::Intermediate;
-}
-
-void
-ExtDateValidator::fixup( QString& ) const
-{
-
-}
-
-ExtDateTable::ExtDateTable(QWidget *parent, ExtDate date_, const char* name, Qt::WFlags f)
- : Q3GridView(parent, name, f)
-{
- d = new ExtDateTablePrivate;
- setFontSize(10);
- if(!date_.isValid())
- {
- kDebug() << "ExtDateTable ctor: WARNING: Given date is invalid, using current date.";
- date_=ExtDate::currentDate();
- }
- setFocusPolicy( Qt::StrongFocus );
- setNumRows(7); // 6 weeks max + headline
- setNumCols(7); // 7 days a week
- setHScrollBarMode(AlwaysOff);
- setVScrollBarMode(AlwaysOff);
- QPalette pal = viewport()->palette();
- pal.setColor(viewport()->backgroundRole(), KColorScheme(QPalette::Active, KColorScheme::View).background().color());
- viewport()->setPalette(pal);
- setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth
-}
-
-ExtDateTable::~ExtDateTable()
-{
- delete d;
-}
-
-int ExtDateTable::posFromDate( const ExtDate &dt )
-{
-//FIXME: Can't uncomment unless ExtDate is added to kdelibs
-// const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();
-// const int firstWeekDay = KGlobal::locale()->weekStartDay();
-
- const int firstWeekDay = 7;
-
- int pos = d->calendar->day( dt );
- int offset = (firstday - firstWeekDay + 7) % 7;
- // make sure at least one day of the previous month is visible.
- // adjust this <1 if more days should be forced visible:
- if ( offset < 1 ) offset += 7;
- return pos + offset;
-}
-
-ExtDate ExtDateTable::dateFromPos( int pos )
-{
- ExtDate pCellDate;
-
-//FIXME: Can't uncomment unless ExtDate is added to kdelibs
-// const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();
-// int firstWeekDay = KGlobal::locale()->weekStartDay();
- const int firstWeekDay = 7;
-
- d->calendar->setYMD(pCellDate, d->calendar->year(date), d->calendar->month(date), 1);
-
- int offset = (firstday - firstWeekDay + 7) % 7;
- // make sure at least one day of the previous month is visible.
- // adjust this <1 if more days should be forced visible:
- if ( offset < 1 ) offset += 7;
- pCellDate = d->calendar->addDays( pCellDate, pos - offset );
-
- return pCellDate;
-}
-
-void
-ExtDateTable::paintCell(QPainter *painter, int row, int col)
-{
-//FIXME: Can't uncomment unless ExtDate is added to kdelibs
-// const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();
-// int firstWeekDay = KGlobal::locale()->weekStartDay();
- const int firstWeekDay = 7;
-
- QRect rect;
- QString text;
- QPen pen;
- int w=cellWidth();
- int h=cellHeight();
- QFont font=KGlobalSettings::generalFont();
- // -----
-
- if(row==0)
- { // we are drawing the headline
- font.setBold(true);
- painter->setFont(font);
- bool normalday = true;
- int daynum = ( col+firstWeekDay < 8 ) ? col+firstWeekDay :
- col+firstWeekDay-7;
- if ( daynum == d->calendar->weekDayOfPray() ||
- ( daynum == 6 && d->calendar->calendarName() == "gregorian" ) )
- normalday=false;
-
- QColor titleColor(isEnabled()?( KGlobalSettings::activeTitleColor() ):( KGlobalSettings::inactiveTitleColor() ) );
- QColor textColor(isEnabled()?( KGlobalSettings::activeTextColor() ):( KGlobalSettings::inactiveTextColor() ) );
- if (!normalday)
- {
- painter->setPen(textColor);
- painter->setBrush(textColor);
- painter->drawRect(0, 0, w, h);
- painter->setPen(titleColor);
- } else {
- painter->setPen(titleColor);
- painter->setBrush(titleColor);
- painter->drawRect(0, 0, w, h);
- painter->setPen(textColor);
- }
- painter->drawText(QRect(0, 0, w, h-1), Qt::AlignCenter,
- d->calendar->weekDayName(daynum, true), &rect);
- painter->setPen(palette().color(QPalette::Text));
- // painter->moveTo(0, h-1);
- // painter->lineTo(w-1, h-1);
- painter->drawLine( 0, h-1, w-1, h-1);
- // ----- draw the weekday:
- } else {
- bool paintRect=true;
- painter->setFont(font);
- int pos=7*(row-1)+col;
-
- ExtDate pCellDate = dateFromPos( pos );
- // First day of month
- text = d->calendar->dayString(pCellDate, true);
- if( d->calendar->month(pCellDate) != d->calendar->month(date) )
- { // we are either
- // ° painting a day of the previous month or
- // ° painting a day of the following month
- // TODO: don't hardcode gray here! Use a color with less contrast to the background than normal text.
- painter->setPen( palette().color( QPalette::Mid ) );
-// painter->setPen(gray);
- } else { // paint a day of the current month
- if ( d->useCustomColors )
- {
- ExtDateTablePrivate::DatePaintingMode *mode=d->customPaintingModes[pCellDate.toString()];
- if (mode)
- {
- if (mode->bgMode != NoBgMode)
- {
- QBrush oldbrush=painter->brush();
- painter->setBrush( mode->bgColor );
- switch(mode->bgMode)
- {
- case(CircleMode) : painter->drawEllipse(0,0,w,h);break;
- case(RectangleMode) : painter->drawRect(0,0,w,h);break;
- case(NoBgMode) : // Should never be here, but just to get one
- // less warning when compiling
- default: break;
- }
- painter->setBrush( oldbrush );
- paintRect=false;
- }
- painter->setPen( mode->fgColor );
- } else
- painter->setPen( palette().color( QPalette::Text ) );
- } else //if ( firstWeekDay < 4 ) // <- this doesn' make sense at all!
- painter->setPen( palette().color( QPalette::Text ) );
- }
-
- pen=painter->pen();
- int offset=firstday-firstWeekDay;
- if(offset<1)
- offset+=7;
- int dy = d->calendar->day(date);
- // if( ((offset+dy) == (pos+1)) && hasFocus())
- if( ((offset+dy) == (pos+1)) && hasFocus())
- {
- // draw the currently selected date
- painter->setPen(palette().color(QPalette::Highlight));
- painter->setBrush(palette().color(QPalette::Highlight));
- pen=palette().color(QPalette::HighlightedText);
- } else {
- painter->setBrush(palette().color(backgroundRole()));
- painter->setPen(palette().color(backgroundRole()));
-// painter->setBrush(colorGroup().base());
-// painter->setPen(colorGroup().base());
- }
-
- if ( pCellDate == ExtDate::currentDate() )
- {
- painter->setPen(palette().color( QPalette::Text ) );
- }
-
- if ( paintRect ) painter->drawRect(0, 0, w, h);
- painter->setPen(pen);
- painter->drawText(QRect(0, 0, w, h), Qt::AlignCenter, text, &rect);
- }
- if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
- if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
-}
-
-void
-ExtDateTable::keyPressEvent( QKeyEvent *e )
-{
-//FIXME: Can't uncomment unless ExtDate is added to kdelibs
-// const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();
-
- ExtDate temp = date;
-
- switch( e->key() ) {
- case Qt::Key_PageUp:
- temp = d->calendar->addMonths( date, -1 );
- setDate(temp);
- return;
- case Qt::Key_PageDown:
- temp = d->calendar->addMonths( date, 1 );
- setDate(temp);
- return;
- case Qt::Key_Up:
- if ( d->calendar->day(date) > 7 ) {
- setDate(date.addDays(-7));
- return;
- }
- break;
- case Qt::Key_Down:
- if ( d->calendar->day(date) <= d->calendar->daysInMonth(date)-7 ) {
- setDate(date.addDays(7));
- return;
- }
- break;
- case Qt::Key_Left:
- if ( d->calendar->day(date) > 1 ) {
- setDate(date.addDays(-1));
- return;
- }
- break;
- case Qt::Key_Right:
- if ( d->calendar->day(date) < d->calendar->daysInMonth(date) ) {
- setDate(date.addDays(1));
- return;
- }
- break;
- case Qt::Key_Minus:
- setDate(date.addDays(-1));
- return;
- case Qt::Key_Plus:
- setDate(date.addDays(1));
- return;
- case Qt::Key_N:
- setDate(ExtDate::currentDate());
- return;
- case Qt::Key_Return:
- case Qt::Key_Enter:
- emit tableClicked();
- return;
- default:
- break;
- }
-
- KNotification::beep();
-}
-
-void
-ExtDateTable::viewportResizeEvent(QResizeEvent * e)
-{
- Q3GridView::viewportResizeEvent(e);
-
- setCellWidth(viewport()->width()/7);
- setCellHeight(viewport()->height()/7);
-}
-
-void
-ExtDateTable::setFontSize(int size)
-{
-//FIXME: Can't uncomment unless ExtDate is added to kdelibs
-// const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();
-
- int count;
- QFontMetrics metrics(fontMetrics());
- QRect rect;
- // ----- store rectangles:
- fontsize=size;
- // ----- find largest day name:
- maxCell.setWidth(0);
- maxCell.setHeight(0);
- for(count=0; count<7; ++count)
- {
- rect=metrics.boundingRect(d->calendar->weekDayName(count+1, true));
- maxCell.setWidth(qMax(maxCell.width(), rect.width()));
- maxCell.setHeight(qMax(maxCell.height(), rect.height()));
- }
- // ----- compare with a real wide number and add some space:
- rect=metrics.boundingRect(QString::fromLatin1("88"));
- maxCell.setWidth(qMax(maxCell.width()+2, rect.width()));
- maxCell.setHeight(qMax(maxCell.height()+4, rect.height()));
-}
-
-void
-ExtDateTable::wheelEvent ( QWheelEvent * e )
-{
- setDate(date.addMonths( -(int)(e->delta()/120)) );
- e->accept();
-}
-
-void
-ExtDateTable::contentsMousePressEvent(QMouseEvent *e)
-{
-
- if(e->type()!=QEvent::MouseButtonPress)
- { // the ExtDatePicker only reacts on mouse press events:
- return;
- }
- if(!isEnabled())
- {
- KNotification::beep();
- return;
- }
-
- // -----
- int row, col, pos, temp;
- QPoint mouseCoord;
- // -----
- mouseCoord = e->pos();
- row=rowAt(mouseCoord.y());
- col=columnAt(mouseCoord.x());
- if(row<1 || col<0)
- { // the user clicked on the frame of the table
- return;
- }
-
- // Rows and columns are zero indexed. The (row - 1) below is to avoid counting
- // the row with the days of the week in the calculation.
-
- // old selected date:
- temp = posFromDate( date );
- // new position and date
- pos = (7 * (row - 1)) + col;
- ExtDate clickedDate = dateFromPos( pos );
-
- // set the new date. If it is in the previous or next month, the month will
- // automatically be changed, no need to do that manually...
- setDate( clickedDate );
-
- // call updateCell on the old and new selection. If setDate switched to a different
- // month, these cells will be painted twice, but that's no problem.
- updateCell( temp/7+1, temp%7 );
- updateCell( row, col );
-
- emit tableClicked();
-
- if ( e->button() == Qt::RightButton && d->popupMenuEnabled )
- {
- KMenu *menu = new KMenu();
-
-//FIXME: Uncomment the following line (and remove the one after it)
-// if ExtDate is added to kdelibs
-// menu->addTitle( KGlobal::locale()->formatDate(clickedDate) );
- menu->addTitle( clickedDate.toString() );
-
- emit aboutToShowContextMenu( menu, clickedDate );
- menu->popup(e->globalPos());
- }
-}
-
-bool
-ExtDateTable::setDate(const ExtDate& date_)
-{
- bool changed=false;
- ExtDate temp;
- // -----
- if(!date_.isValid())
- {
- kDebug() << "ExtDateTable::setDate: refusing to set invalid date.";
- return false;
- }
- if(date!=date_)
- {
- emit(dateChanged(date, date_));
- date=date_;
- emit(dateChanged(date));
- changed=true;
- }
-
-//FIXME: Can't uncomment the following unless ExtDate is moved to kdelibs
-// const ExtCalendarSystem * calendar = KGlobal::locale()->calendar();
-
- d->calendar->setYMD(temp, d->calendar->year(date), d->calendar->month(date), 1);
- //temp.setYMD(date.year(), date.month(), 1);
- //kDebug() << "firstDayInWeek: " << temp.toString();
- firstday=temp.dayOfWeek();
- numdays=d->calendar->daysInMonth(date);
-
- temp = d->calendar->addMonths(temp, -1);
- numDaysPrevMonth=d->calendar->daysInMonth(temp);
- if(changed)
- {
- repaintContents(false);
- }
- return true;
-}
-
-const ExtDate&
-ExtDateTable::getDate() const
-{
- return date;
-}
-
-// what are those repaintContents() good for? (pfeiffer)
-void ExtDateTable::focusInEvent( QFocusEvent *e )
-{
-// repaintContents(false);
- Q3GridView::focusInEvent( e );
-}
-
-void ExtDateTable::focusOutEvent( QFocusEvent *e )
-{
-// repaintContents(false);
- Q3GridView::focusOutEvent( e );
-}
-
-QSize
-ExtDateTable::sizeHint() const
-{
- if(maxCell.height()>0 && maxCell.width()>0)
- {
- return QSize(maxCell.width()*numCols()+2*frameWidth(),
- (maxCell.height()+2)*numRows()+2*frameWidth());
- } else {
- kDebug() << "ExtDateTable::sizeHint: obscure failure - ";
- return QSize(-1, -1);
- }
-}
-
-void ExtDateTable::setPopupMenuEnabled( bool enable )
-{
- d->popupMenuEnabled=enable;
-}
-
-bool ExtDateTable::popupMenuEnabled() const
-{
- return d->popupMenuEnabled;
-}
-
-void ExtDateTable::setCustomDatePainting(const ExtDate &date, const QColor &fgColor, BackgroundMode bgMode, const QColor &bgColor)
-{
- if (!fgColor.isValid())
- {
- unsetCustomDatePainting( date );
- return;
- }
-
- ExtDateTablePrivate::DatePaintingMode *mode=new ExtDateTablePrivate::DatePaintingMode;
- mode->bgMode=bgMode;
- mode->fgColor=fgColor;
- mode->bgColor=bgColor;
-
- d->customPaintingModes.replace( date.toString(), mode );
- d->useCustomColors=true;
- update();
-}
-
-void ExtDateTable::unsetCustomDatePainting( const ExtDate &date )
-{
- d->customPaintingModes.remove( date.toString() );
-}
-
-ExtDateInternalWeekSelector::ExtDateInternalWeekSelector
-(QWidget* parent)
- : KLineEdit(parent),
- val(new QIntValidator(this)),
- result(0)
-{
- QFont font;
- // -----
- font=KGlobalSettings::generalFont();
- setFont(font);
- setFrame(false);
- setValidator(val);
- connect(this, SIGNAL(returnPressed()), SLOT(weekEnteredSlot()));
-}
-
-void
-ExtDateInternalWeekSelector::weekEnteredSlot()
-{
- bool ok;
- int week;
- // ----- check if this is a valid week:
- week=text().toInt(&ok);
- if(!ok)
- {
- KNotification::beep();
- return;
- }
- result=week;
- emit(closeMe(1));
-}
-
-int
-ExtDateInternalWeekSelector::getWeek()
-{
- return result;
-}
-
-void
-ExtDateInternalWeekSelector::setWeek(int week)
-{
- QString temp;
- // -----
- temp.setNum(week);
- setText(temp);
-}
-
-void
-ExtDateInternalWeekSelector::setMaxWeek(int max)
-{
- val->setRange(1, max);
-}
-
-// ### CFM To avoid binary incompatibility.
-// In future releases, remove this and replace by a ExtDate
-// private member, needed in ExtDateInternalMonthPicker::paintCell
-class ExtDateInternalMonthPicker::ExtDateInternalMonthPrivate {
-public:
- ExtDateInternalMonthPrivate (int y, int m, int d)
- : year(y), month(m), day(d)
- { calendar = new ExtCalendarSystemGregorian(); }
- ~ExtDateInternalMonthPrivate()
- { delete calendar; }
-
- ExtCalendarSystem *calendar;
- int year;
- int month;
- int day;
-};
-
-ExtDateInternalMonthPicker::~ExtDateInternalMonthPicker() {
- delete d;
-}
-
-ExtDateInternalMonthPicker::ExtDateInternalMonthPicker
-(const ExtDate & date, QWidget* parent)
- : Q3GridView(parent),
- result(0) // invalid
-{
-//FIXME: Can't uncomment the following unless ExtDate is moved to kdelibs
-// ExtCalendarSystem *calendar = KGlobal::locale()->calendar();
-
- QRect rect;
- QFont font;
- // -----
- activeCol = -1;
- activeRow = -1;
- font=KGlobalSettings::generalFont();
- setFont(font);
- setHScrollBarMode(AlwaysOff);
- setVScrollBarMode(AlwaysOff);
- setFrameShape(QFrame::NoFrame);
- setNumCols(3);
- d = new ExtDateInternalMonthPrivate(date.year(), date.month(), date.day());
- // For monthsInYear != 12
- setNumRows( (d->calendar->monthsInYear(date) + 2) / 3);
- // enable to find drawing failures:
- // setTableFlags(Tbl_clipCellPainting);
- QPalette pal = viewport()->palette();
- pal.setColor(viewport()->backgroundRole(), KColorScheme(QPalette::Active, KColorScheme::View).background().color()); // for consistency with the datepicker
- viewport()->setPalette(pal);
- // ----- find the preferred size
- // (this is slow, possibly, but unfortunately it is needed here):
- QFontMetrics metrics(font);
- for(int i = 1; ; ++i)
- {
- QString str = d->calendar->monthName(i,
- d->calendar->year(date), false);
- if (str.isNull()) break;
- rect=metrics.boundingRect(str);
- if(max.width()<rect.width()) max.setWidth(rect.width());
- if(max.height()<rect.height()) max.setHeight(rect.height());
- }
-}
-
-QSize
-ExtDateInternalMonthPicker::sizeHint() const
-{
- return QSize((max.width()+6)*numCols()+2*frameWidth(),
- (max.height()+6)*numRows()+2*frameWidth());
-}
-
-int
-ExtDateInternalMonthPicker::getResult() const
-{
- return result;
-}
-
-void
-ExtDateInternalMonthPicker::setupPainter(QPainter *p)
-{
- p->setPen(KColorScheme(QPalette::Active, KColorScheme::View).foreground().color());
-}
-
-void
-ExtDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*)
-{
- setCellWidth(width() / numCols());
- setCellHeight(height() / numRows());
-}
-
-void
-ExtDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col)
-{
- int index;
- QString text;
- // ----- find the number of the cell:
- index=3*row+col+1;
- text=d->calendar->monthName(index,
- d->calendar->year(ExtDate(d->year, d->month,
- d->day)), false);
- painter->drawText(0, 0, cellWidth(), cellHeight(), Qt::AlignCenter, text);
- if ( activeCol == col && activeRow == row )
- painter->drawRect( 0, 0, cellWidth(), cellHeight() );
-}
-
-void
-ExtDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e)
-{
- if(!isEnabled() || e->button() != Qt::LeftButton)
- {
- KNotification::beep();
- return;
- }
- // -----
- int row, col;
- QPoint mouseCoord;
- // -----
- mouseCoord = e->pos();
- row=rowAt(mouseCoord.y());
- col=columnAt(mouseCoord.x());
-
- if(row<0 || col<0)
- { // the user clicked on the frame of the table
- activeCol = -1;
- activeRow = -1;
- } else {
- activeCol = col;
- activeRow = row;
- updateCell( row, col /*, false */ );
- }
-}
-
-void
-ExtDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e)
-{
- if (e->buttons() & Qt::LeftButton)
- {
- int row, col;
- QPoint mouseCoord;
- // -----
- mouseCoord = e->pos();
- row=rowAt(mouseCoord.y());
- col=columnAt(mouseCoord.x());
- int tmpRow = -1, tmpCol = -1;
- if(row<0 || col<0)
- { // the user clicked on the frame of the table
- if ( activeCol > -1 )
- {
- tmpRow = activeRow;
- tmpCol = activeCol;
- }
- activeCol = -1;
- activeRow = -1;
- } else {
- bool differentCell = (activeRow != row || activeCol != col);
- if ( activeCol > -1 && differentCell)
- {
- tmpRow = activeRow;
- tmpCol = activeCol;
- }
- if ( differentCell)
- {
- activeRow = row;
- activeCol = col;
- updateCell( row, col /*, false */ ); // mark the new active cell
- }
- }
- if ( tmpRow > -1 ) // repaint the former active cell
- updateCell( tmpRow, tmpCol /*, true */ );
- }
-}
-
-void
-ExtDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e)
-{
- if(!isEnabled())
- {
- return;
- }
- // -----
- int row, col, pos;
- QPoint mouseCoord;
- // -----
- mouseCoord = e->pos();
- row=rowAt(mouseCoord.y());
- col=columnAt(mouseCoord.x());
- if(row<0 || col<0)
- { // the user clicked on the frame of the table
- emit(closeMe(0));
- }
-
- pos=3*row+col+1;
- result=pos;
- emit(closeMe(1));
-}
-
-
-
-ExtDateInternalYearSelector::ExtDateInternalYearSelector
-(QWidget* parent)
- : QLineEdit(parent),
- val(new QIntValidator(this)),
- result(0),
- d(new ExtDateInternalYearPrivate())
-{
- QFont font;
- // -----
- font=KGlobalSettings::generalFont();
- setFont(font);
- setFrame(false);
- // set year limits (perhaps we should get rid of limits altogether)
- //there si also a year limit in ExtCalendarSystemGregorian...
- val->setRange(-50000, 50000);
- setValidator(val);
- connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot()));
-}
-
-ExtDateInternalYearSelector::~ExtDateInternalYearSelector() {
- delete val;
- delete d;
-}
-
-void
-ExtDateInternalYearSelector::yearEnteredSlot()
-{
- bool ok;
- int year;
- ExtDate date;
- // ----- check if this is a valid year:
- year=text().toInt(&ok);
- if(!ok)
- {
- KNotification::beep();
- return;
- }
- //date.setYMD(year, 1, 1);
- d->calendar->setYMD(date, year, 1, 1);
- if(!date.isValid())
- {
- KNotification::beep();
- return;
- }
- result=year;
- emit(closeMe(1));
-}
-
-int
-ExtDateInternalYearSelector::getYear()
-{
- return result;
-}
-
-void
-ExtDateInternalYearSelector::setYear(int year)
-{
- QString temp;
- // -----
- temp.setNum(year);
- setText(temp);
-}
-
-KPopupFrame::KPopupFrame(QWidget* parent)
- : QFrame(parent, Qt::Popup),
- result(0), // rejected
- main(0)
-{
- setFrameStyle(QFrame::Box | QFrame::Raised);
- setMidLineWidth(2);
-}
-
-void
-KPopupFrame::keyPressEvent(QKeyEvent* e)
-{
- if(e->key()==Qt::Key_Escape)
- {
- result=0; // rejected
- qApp->exit_loop();
- }
-}
-
-void
-KPopupFrame::close(int r)
-{
- result=r;
- qApp->exit_loop();
-}
-
-void
-KPopupFrame::setMainWidget(QWidget* m)
-{
- main=m;
- if(main!=0)
- {
- resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
- }
-}
-
-void
-KPopupFrame::resizeEvent(QResizeEvent*)
-{
- if(main!=0)
- {
- main->setGeometry(frameWidth(), frameWidth(),
- width()-2*frameWidth(), height()-2*frameWidth());
- }
-}
-
-void
-KPopupFrame::popup(const QPoint &pos)
-{
- // Make sure the whole popup is visible.
- QRect d = KGlobalSettings::desktopGeometry(pos);
-
- int x = pos.x();
- int y = pos.y();
- int w = width();
- int h = height();
- if (x+w > d.x()+d.width())
- x = d.width() - w;
- if (y+h > d.y()+d.height())
- y = d.height() - h;
- if (x < d.x())
- x = 0;
- if (y < d.y())
- y = 0;
-
- if (QLineEdit *edit = qobject_cast<QLineEdit*>(main))
- edit->selectAll();
-
- // Pop the thingy up.
- move(x, y);
- show();
-}
-
-int
-KPopupFrame::exec(const QPoint& pos)
-{
- popup(pos);
- update();
- qApp->enter_loop();
- hide();
- return result;
-}
-
-int
-KPopupFrame::exec(int x, int y)
-{
- return exec(QPoint(x, y));
-}
-
-#include "extdatetbl.moc"
+++ /dev/null
-/* -*- C++ -*-
- This file is part of the KDE libraries
- Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
- (C) 1998-2001 Mirko Boehm (mirko@kde.org)
- (C) 2004 Jason Harris (jharris@30doradus.org)
-
- These classes has been derived from those in kdatetbl.[h|cpp].
- The only differences are adaptations to use ExtDate instead of QDate,
- to allow for more remote dates. These changes by Jason Harris.
-
- 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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-#ifndef EXTDATETBL_H
-#define EXTDATETBL_H
-
-#include <qvalidator.h>
-#include <q3gridview.h>
-#include <klineedit.h>
-#include "extcalendarsystemgregorian.h"
-
-class QMenu;
-class QPainter;
-
-/** Week selection widget.
-* @internal
-* @version $Id$
-* @author Stephan Binner
-*/
-class ExtDateInternalWeekSelector : public KLineEdit
-{
- Q_OBJECT
-protected:
- QIntValidator *val;
- int result;
-public slots:
- void weekEnteredSlot();
- void setMaxWeek(int max);
-signals:
- void closeMe(int);
-public:
- ExtDateInternalWeekSelector( QWidget* parent=0);
- int getWeek();
- void setWeek(int week);
-
-private:
- class ExtDateInternalWeekPrivate;
- ExtDateInternalWeekPrivate *d;
-};
-
-/**
-* A table containing month names. It is used to pick a month directly.
-* @internal
-* @version $Id$
-* @author Tim Gilman, Mirko Boehm
-*/
-class ExtDateInternalMonthPicker : public Q3GridView
-{
- Q_OBJECT
-protected:
- /**
- * Store the month that has been clicked [1..12].
- */
- int result;
- /**
- * the cell under mouse cursor when LBM is pressed
- */
- short int activeCol;
- short int activeRow;
- /**
- * Contains the largest rectangle needed by the month names.
- */
- QRect max;
-signals:
- /**
- * This is send from the mouse click event handler.
- */
- void closeMe(int);
-public:
- /**
- * The constructor.
- */
- ExtDateInternalMonthPicker(const ExtDate& date, QWidget* parent);
- /**
- * The destructor.
- */
- ~ExtDateInternalMonthPicker();
- /**
- * The size hint.
- */
- virtual QSize sizeHint() const;
- /**
- * Return the result. 0 means no selection (reject()), 1..12 are the
- * months.
- */
- int getResult() const;
-protected:
- /**
- * Set up the painter.
- */
- void setupPainter(QPainter *p);
- /**
- * The resize event.
- */
- virtual void viewportResizeEvent(QResizeEvent*);
- /**
- * Paint a cell. This simply draws the month names in it.
- */
- virtual void paintCell(QPainter* painter, int row, int col);
- /**
- * Catch mouse click and move events to paint a rectangle around the item.
- */
- virtual void contentsMousePressEvent(QMouseEvent *e);
- virtual void contentsMouseMoveEvent(QMouseEvent *e);
- /**
- * Emit monthSelected(int) when a cell has been released.
- */
- virtual void contentsMouseReleaseEvent(QMouseEvent *e);
-
-private:
- class ExtDateInternalMonthPrivate;
- ExtDateInternalMonthPrivate *d;
-};
-
-/** Year selection widget.
-* @internal
-* @version $Id$
-* @author Tim Gilman, Mirko Boehm
-*/
-class ExtDateInternalYearSelector : public QLineEdit
-{
- Q_OBJECT
-protected:
- QIntValidator *val;
- int result;
-public slots:
- void yearEnteredSlot();
-signals:
- void closeMe(int);
-public:
- ExtDateInternalYearSelector( QWidget* parent=0 );
- ~ExtDateInternalYearSelector();
- int getYear();
- void setYear(int year);
-
-private:
- class ExtDateInternalYearPrivate {
- public:
- ExtDateInternalYearPrivate() {
- calendar = new ExtCalendarSystemGregorian();
- }
- ~ExtDateInternalYearPrivate() {
- delete calendar;
- }
- ExtCalendarSystem *calendar;
- };
- ExtDateInternalYearPrivate *d;
-
-};
-
-/**
- * Frame with popup menu behavior.
- * @author Tim Gilman, Mirko Boehm
- * @version $Id$
- */
-class KPopupFrame : public QFrame
-{
- Q_OBJECT
-protected:
- /**
- * The result. It is returned from exec() when the popup window closes.
- */
- int result;
- /**
- * Catch key press events.
- */
- virtual void keyPressEvent(QKeyEvent* e);
- /**
- * The only subwidget that uses the whole dialog window.
- */
- QWidget *main;
-public slots:
- /**
- * Close the popup window. This is called from the main widget, usually.
- * @p r is the result returned from exec().
- */
- void close(int r);
-public:
- /**
- * The contructor. Creates a dialog without buttons.
- * @param parent The parent widget for this dialog. If @p parent is 0,
- * the dialog uses the whole desktop.
- */
- KPopupFrame(QWidget* parent=0);
- /**
- * Set the main widget. You cannot set the main widget from the constructor,
- * since it must be a child of the frame itselfes.
- * Be careful: the size is set to the main widgets size. It is up to you to
- * set the main widgets correct size before setting it as the main
- * widget.
- */
- void setMainWidget(QWidget* m);
- /**
- * The resize event. Simply resizes the main widget to the whole
- * widgets client size.
- */
- virtual void resizeEvent(QResizeEvent*);
- /**
- * Open the popup window at position @p pos.
- * @param pos The position (relative to the parent window) where the
- * popup menu should appear.
- */
- void popup(const QPoint &pos);
- /**
- * Execute the popup window.
- * @param p The position where the window should be shown.
- * @return Result code of the popup.
- * @see popup()
- */
- int exec(const QPoint& p);
- /**
- * Execute the popup window.
- * Equivalent to exec(const QPoint &) for the given @p x and @p y.
- */
- int exec(int x, int y);
-
-private:
- class KPopupFramePrivate;
- KPopupFramePrivate *d;
-};
-
-/**
-* Validates user-entered dates.
-*/
-class ExtDateValidator : public QValidator
-{
-public:
- ExtDateValidator(QWidget* parent=0);
- virtual State validate(QString&, int&) const;
- virtual void fixup ( QString & input ) const;
- State date(const QString&, ExtDate&) const;
-};
-
-/**
- * Date selection table.
- * This is a support class for the ExtDatePicker class. It just
- * draws the calender table without titles, but could theoretically
- * be used as a standalone.
- *
- * When a date is selected by the user, it emits a signal:
- * dateSelected(ExtDate)
- *
- * @internal
- * @version $Id$
- * @author Tim Gilman, Mirko Boehm
- */
-class ExtDateTable : public Q3GridView
-{
- Q_OBJECT
- //Q_PROPERTY( ExtDate date READ getDate WRITE setDate )
- Q_PROPERTY( bool popupMenu READ popupMenuEnabled WRITE setPopupMenuEnabled )
-
-public:
- /**
- * The constructor.
- */
- explicit ExtDateTable(QWidget *parent=0,
- ExtDate date=ExtDate::currentDate(),
- const char* name=0, Qt::WFlags f=0);
-
- /**
- * The destructor.
- */
- ~ExtDateTable();
-
- /**
- * Returns a recommended size for the widget.
- * To save some time, the size of the largest used cell content is
- * calculated in each paintCell() call, since all calculations have
- * to be done there anyway. The size is stored in maxCell. The
- * sizeHint() simply returns a multiple of maxCell.
- */
- virtual QSize sizeHint() const;
- /**
- * Set the font size of the date table.
- */
- void setFontSize(int size);
- /**
- * Select and display this date.
- */
- bool setDate(const ExtDate&);
- // ### 4.0 rename to date()
- const ExtDate& getDate() const;
-
- /**
- * Enables a popup menu when right clicking on a date.
- *
- * When it's enabled, this object emits a aboutToShowContextMenu signal
- * where you can fill in the menu items.
- */
- void setPopupMenuEnabled( bool enable );
-
- /**
- * Returns if the popup menu is enabled or not
- */
- bool popupMenuEnabled() const;
-
- enum BackgroundMode { NoBgMode=0, RectangleMode, CircleMode };
-
- /**
- * Makes a given date be painted with a given foregroundColor, and background
- * (a rectangle, or a circle/ellipse) in a given color.
- */
- void setCustomDatePainting( const ExtDate &date, const QColor &fgColor, BackgroundMode bgMode=NoBgMode, const QColor &bgColor=QColor());
-
- /**
- * Unsets the custom painting of a date so that the date is painted as usual.
- */
- void unsetCustomDatePainting( const ExtDate &date );
-
-protected:
- /**
- * calculate the position of the cell in the matrix for the given date. The result is the 0-based index.
- */
- int posFromDate( const ExtDate &date ); // KDE4: make this virtual, so subclasses can reimplement this and use a different default for the start of the matrix
- /**
- * calculate the date that is displayed at a given cell in the matrix. pos is the
- * 0-based index in the matrix. Inverse function to posForDate().
- */
- ExtDate dateFromPos( int pos ); // KDE4: make this virtual
-
- /**
- * Paint a cell.
- */
- virtual void paintCell(QPainter*, int, int);
- /**
- * Handle the resize events.
- */
- virtual void viewportResizeEvent(QResizeEvent *);
- /**
- * React on mouse clicks that select a date.
- */
- virtual void contentsMousePressEvent(QMouseEvent *);
- virtual void wheelEvent( QWheelEvent * e );
- virtual void keyPressEvent( QKeyEvent *e );
- virtual void focusInEvent( QFocusEvent *e );
- virtual void focusOutEvent( QFocusEvent *e );
-
- // ### KDE 4.0 make the following private and mark as members
-
- /**
- * The font size of the displayed text.
- */
- int fontsize;
- /**
- * The currently selected date.
- */
- ExtDate date;
- /**
- * The day of the first day in the month [1..7].
- */
- int firstday;
- /**
- * The number of days in the current month.
- */
- int numdays;
- /**
- * The number of days in the previous month.
- */
- int numDaysPrevMonth;
- /**
- * Save the size of the largest used cell content.
- */
- QRect maxCell;
-signals:
- /**
- * The selected date changed.
- */
- void dateChanged(const ExtDate&);
- /**
- * This function behaves essentially like the one above.
- * The selected date changed.
- * @param cur The current date
- * @param old The date before the date was changed
- */
- void dateChanged(const ExtDate& cur, const ExtDate& old);
- /**
- * A date has been selected by clicking on the table.
- */
- void tableClicked();
-
- /**
- * A popup menu for a given date is about to be shown (as when the user
- * right clicks on that date and the popup menu is enabled). Connect
- * the slot where you fill the menu to this signal.
- */
- void aboutToShowContextMenu( QMenu * menu, const ExtDate &date);
-
-private:
- class ExtDateTablePrivate;
- ExtDateTablePrivate *d;
-};
-
-#endif // EXTDATETBL_H
+++ /dev/null
-/*************************************************************************
-** Definition of extended range date classe
-** (c) 2004 by Michel Guitel <michel.guitel@sap.ap-hop-paris.fr>
-** modifications by Jason Harris <kstars@30doradus.org>
-**
-** This file may be distributed and/or modified under the terms of the
-** GNU General Public License version 2 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-**********************************************************************/
-
-#include "extdatetime.h"
-#include <qregexp.h>
-
-#include <kglobal.h>
-#include <klocale.h>
-#include <kdebug.h>
-#include <qstringlist.h>
-#include <assert.h>
-#include <time.h>
-#include <math.h>
-
-static const uint SECS_PER_DAY = 86400;
-static const uint MSECS_PER_DAY = 86400000;
-static const uint SECS_PER_HOUR = 3600;
-static const uint MSECS_PER_HOUR= 3600000;
-static const uint SECS_PER_MIN = 60;
-static const uint MSECS_PER_MIN = 60000;
-
-/*****************************************************************************
- ExtDate class
- *****************************************************************************/
-
-/*****************************************************************************
- *
- * Concepts :
- * a date is represented internally by its Julian Day number, a simple count
- * of the number of days since a remote, arbitrary date (01 January, 4713 BC).
- * This date has Julian Day number zero.
- *
- * ***************************************************************************/
-
-uint ExtDate::m_monthLength[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-uint ExtDate::m_monthOrigin[] = { 0, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
-
-QString ExtDate::m_shortMonthNames[12] = {
- i18nc("Short month name", "Jan"), i18nc("Short month name", "Feb"),
- i18nc("Short month name", "Mar"), i18nc("Short month name", "Apr"),
- i18nc("Short month name", "May"), i18nc("Short month name", "Jun"),
- i18nc("Short month name", "Jul"), i18nc("Short month name", "Aug"),
- i18nc("Short month name", "Sep"), i18nc("Short month name", "Oct"),
- i18nc("Short month name", "Nov"), i18nc("Short month name", "Dec")
-};
-QString ExtDate::m_shortDayNames[7] = {
- i18nc("Short day name", "Mon"), i18nc("Short day name", "Tue"),
- i18nc("Short day name", "Wed"), i18nc("Short day name", "Thu"),
- i18nc("Short day name", "Fri"), i18nc("Short day name", "Sat"),
- i18nc("Short day name", "Sun")
-};
-QString ExtDate::m_longMonthNames[12] = {
- i18nc("Long month name", "January"), i18nc("Long month name", "February"),
- i18nc("Long month name", "March"), i18nc("Long month name", "April"),
- i18nc("Long month name", "May"), i18nc("Long month name", "June"),
- i18nc("Long month name", "July"), i18nc("Long month name", "August"),
- i18nc("Long month name", "September"), i18nc("Long month name", "October"),
- i18nc("Long month name", "November"), i18nc("Long month name", "December")
-};
-QString ExtDate::m_longDayNames[7] = {
- i18nc("Long day name", "Monday"), i18nc("Long day name", "Tuesday"),
- i18nc("Long day name", "Wednesday"), i18nc("Long day name", "Thursday"),
- i18nc("Long day name", "Friday"), i18nc("Long day name", "Saturday"),
- i18nc("Long day name", "Sunday")
-};
-
-ExtDate::ExtDate() : m_jd(INVALID_DAY), m_year(0), m_month(0), m_day(0)
-{}
-
-ExtDate::ExtDate( int y, int m, int d)
-{
- if ( !isValid(y,m,d) ) {
-#if defined(QT_CHECK_RANGE)
- qWarning( "ExtDate: Invalid date %04d-%02d-%02d", y, m, d );
-#endif
- m_year = 0;
- m_month = 0;
- m_day = 0;
- m_jd = INVALID_DAY;
- } else {
- m_year = y;
- m_month = m;
- m_day = d;
- m_jd = GregorianToJD(y, m, d);
- }
-}
-
-ExtDate::ExtDate( long int jd ) {
- m_jd = jd;
- JDToGregorian( jd, m_year, m_month, m_day );
-}
-
-long int ExtDate::GregorianToJD( int year, int month, int day )
-{
- int m, y, A, B, C, D;
-
- if (month > 2) {
- m = month;
- y = year;
- } else {
- y = year - 1;
- m = month + 12;
- }
-
-/* If the date is after 10/15/1582, then take Pope Gregory's modification
- to the Julian calendar into account */
-
- if ( ( year >1582 ) ||
- ( year ==1582 && month >9 ) ||
- ( year ==1582 && month ==9 && day >15 ))
- {
- A = int(y/100);
- B = 2 - A + int(A/4);
- } else {
- B = 0;
- }
-
- if (y < 0) {
- C = int((365.25*y) - 0.75);
- } else {
- C = int(365.25*y);
- }
-
- D = int(30.6001*(m+1));
-
- long int jd = B + C + D + day + 1720995;
-
- return jd;
-}
-
-//JD to Gregorian code is based on an algorithm by Peter Baum,
-//published here: http://vsg.cape.com/~pbaum/date/injdimp.htm
-void ExtDate::JDToGregorian( long int jd, int &year, int &month, int &day )
-{
- float g;
- int z, a, b, c;
-
- z = int(jd - 1721118.5);
- g = z - 0.25;
-
- a = int(floor( g / 36524.25 ));
- b = a - int(floor(a/4));
-
- year = int(floor((b+g)/365.25));
-
- c = b + z - int(floor(365.25*year));
-
- month = int( ( 5*c + 456) / 153 );
- day = c - int( ( 153*month - 457)/5);
-
- if ( month > 12 ) {
- year++;
- month -= 12;
- }
-}
-
-bool ExtDate::isValid() const
-{
- return ( jd() != INVALID_DAY && isValid( year(), month(), day() ) );
-}
-
-int ExtDate::dayOfWeek() const
-{
- //JD 2451545 (01 Jan 2000) was a Saturday, which is dayOfWeek=6.
- int a_day = (( jd() - 2451545 + 6 ) % 7);
- if ( a_day < 0 ) a_day += 7;
- return (a_day == 0) ? 7 : a_day;
-}
-
-int ExtDate::dayOfYear() const
-{
- return jd() - GregorianToJD( year(), 1, 1) + 1;
-}
-
-int ExtDate::daysInMonth() const
-{
- if ( isValid() ) {
- int m = month();
- int d = m_monthLength[m-1];
- if (m==2 && leapYear(year())) d++;
- return d;
- } else {
- return 31;
- }
-}
-
-int ExtDate::daysInYear() const
-{
- if ( ! isValid() ) return 365;
- return (leapYear(year()) ? 366 : 365);
-}
-
-int ExtDate::weekNumber( int *yearNum ) const
-{
- //ISO 8601:
- //Week 1 is the week containing the first Thursday of the year.
- ExtDate day1( year(), 1, 1 ); //First day of the year
-
- if ( day1.dayOfWeek() > 4 ) {
- //Jan 1 is after Thursday, so it's in the previous year's last week.
- //Set day1 to be the following Monday, which is the start of week 1
- day1 = day1.addDays( 7 - day1.dayOfWeek() + 1 );
- } else {
- //Jan 1 is before Friday, so it is in Week 1.
- //Set day1 to be the preceding Monday
- day1 = day1.addDays( 1 - day1.dayOfWeek() );
- }
-
- //Is the target date prior to day1? If so, the target is in the
- //last week of the previous year.
- if ( day1.daysTo( *this ) < 0 ) {
- if ( yearNum ) *yearNum = year() - 1;
-
- //The last week of the year always contains Dec 28th (ISO 8601)
- ExtDate lastDec28( year()-1, 12, 28 );
- return lastDec28.weekNumber();
- }
-
- //If the target date is after Dec 28th, it's possible that it is in
- //Week 1 of the following year.
- ExtDate dec28( year(), 12, 28 );
- if ( dayOfYear() > dec28.dayOfYear() && dayOfWeek() < 4 ) {
- if ( yearNum ) *yearNum = year() + 1;
- return 1;
- }
-
- //If we reach here, the week number will be in this year.
- int week = 1 + int( day1.daysTo( *this )/7 );
-
- if ( yearNum ) *yearNum = year();
- return week;
-}
-
-#ifndef QT_NO_TEXTDATE
-QString ExtDate::shortMonthName( int month ) {return m_shortMonthNames[month-1];}
-QString ExtDate::shortDayName( int weekday ) {return m_shortDayNames[weekday-1];}
-QString ExtDate::longMonthName( int month ) {return m_longMonthNames[month-1];}
-QString ExtDate::longDayName( int weekday ) {return m_longDayNames[weekday-1];}
-#endif //QT_NO_TEXTDATE
-
-#ifndef QT_NO_TEXTSTRING
-#if !defined(QT_NO_SPRINTF)
-QString ExtDate::toString( Qt::DateFormat f) const
-{
- QString a_format;
-
- if ( ! isValid() ) return QString();
-
- switch (f)
- {
- case Qt::TextDate : // Sat May 20 1995
- a_format = "%a %b %e %Y";
- break;
-
- case Qt::ISODate : // YYYY-MM-DD
- a_format = "%Y-%m-%d";
- break;
-
- case Qt::LocalDate : // local settings
- a_format = KGlobal::locale()->dateFormat();
- break;
-
- default :
- a_format = "toString : unknown format";
- break;
-
- }
- return toString(a_format);
-}
-#endif
-
-QString ExtDate::toString( const QString& format ) const
-{
- if ( ! isValid() ) return QString();
-
- //We use the KDE Date format specs.
- //Replace occurrences of the following tokens with their
- //corresponding values:
- //
- // %Y The year, including centuries prefix (e.g., "1984")
- // %y The year, excluding centuries prefix (e.g., "84")
- // %n Numerical month value (e.g., "3" for March)
- // %m Numerical month value, two digits (e.g., "03" for March)
- // %e Numerical day value (e.g., "3" on March 3rd)
- // %d Numerical day value, two digits (e.g., "03" on March 3rd)
- // %b Month name, short form (e.g., "Mar" for March)
- // %B Month name, long form (e.g., "March")
- // %a Weekday name, short form (e.g., "Wed" for Wednesday)
- // %A Weekday name, long form (e.g., "Wednesday")
-
- //All other characters are left as-is.
-
- QString result( format );
-
- result.replace( "%Y", QString().sprintf( "%d", year() ) );
- result.replace( "%y", QString().sprintf( "%02d", (year() % 100) ) );
- result.replace( "%n", QString().sprintf( "%d", month() ) );
- result.replace( "%m", QString().sprintf( "%02d", month() ) );
- result.replace( "%e", QString().sprintf( "%d", day() ) );
- result.replace( "%d", QString().sprintf( "%02d", day() ) );
- result.replace( "%b", shortMonthName( month() ) );
- result.replace( "%B", longMonthName( month() ) );
- result.replace( "%a", shortDayName( dayOfWeek() ) );
- result.replace( "%A", longDayName( dayOfWeek() ) );
-
- return result;
-}
-#endif
-
-bool ExtDate::setYMD( int y, int m, int d )
-{
- if ( ! isValid(y,m,d) ) {
-#if defined(QT_CHECK_RANGE)
- qWarning( "ExtDate: Invalid date %04d-%02d-%02d", y, m, d );
-#endif
- m_year = 0;
- m_month = 0;
- m_day = 0;
- m_jd = INVALID_DAY;
- return false;
- } else {
- m_year = y;
- m_month = m;
- m_day = d;
- m_jd = GregorianToJD( y, m, d );
- return true;
- }
-}
-
-bool ExtDate::setJD( long int _jd ) {
- if ( _jd == INVALID_DAY ) {
- m_jd = _jd;
- m_year = 0;
- m_month = 0;
- m_day = 0;
- return false;
- } else {
- m_jd = _jd;
- JDToGregorian( _jd, m_year, m_month, m_day );
- return true;
- }
-}
-
-ExtDate ExtDate::addDays( int days ) const
-{
- ExtDate a_date;
- a_date.setJD( jd() + days );
- return a_date;
-}
-
-ExtDate ExtDate::addMonths( int months ) const
-{
- int a_month = month() + months%12;
- int a_year = year() + int(months/12);
-
- while ( a_month < 1 ) {
- a_month += 12;
- a_year--;
- }
-
- while ( a_month > 12 ) {
- a_month -= 12;
- a_year++;
- }
-
- return ExtDate(a_year, a_month, day());
-}
-
-ExtDate ExtDate::addYears( int years ) const
-{
- return ExtDate(year() + years, month(), day());
-}
-
-int ExtDate::daysTo( const ExtDate & a_date) const
-{
- return a_date.jd() - jd();
-}
-
-ExtDate ExtDate::currentDate(Qt::TimeSpec ts)
-{
- time_t a_current_time;
- struct tm a_current_time_tm;
-
- time(&a_current_time);
- switch (ts)
- {
- case Qt::LocalTime :
- localtime_r(&a_current_time, &a_current_time_tm);
- break;
-
- case Qt::UTC :
- gmtime_r(&a_current_time, &a_current_time_tm);
- break;
-
- default :
- assert(0);
- break;
- }
- return ExtDate(a_current_time_tm.tm_year + 1900, a_current_time_tm.tm_mon + 1, a_current_time_tm.tm_mday);
-}
-
-#ifndef QT_NO_DATESTRING
-ExtDate ExtDate::fromString( const QString &sDate, const QString &format ) {
- // %Y The year, including centuries prefix (e.g., "1984")
- // %y The year, excluding centuries prefix (e.g., "84")
- // %n Numerical month value (e.g., "3" for March)
- // %m Numerical month value, two digits (e.g., "03" for March)
- // %e Numerical day value (e.g., "3" on March 3rd)
- // %d Numerical day value, two digits (e.g., "03" on March 3rd)
- // %b Month name, short form (e.g., "Mar" for March)
- // %B Month name, long form (e.g., "March")
- // %a Weekday name, short form (e.g., "Wed" for Wednesday)
- // %A Weekday name, long form (e.g., "Wednesday")
-
- //All other characters are left as-is.
-
- //Parse the format string a piece at a time. Look for the tokens
- //(a "%" followed by a letter). Skip over non-tokens.
- QString s = sDate;
- QString f = format;
-
- int y(0), m(0), d(0);
- int j = 0;
- int jold = j;
- int js = 1; //index marker for date string
- for ( int i=0; i<f.count("%"); i++ ) {
- j = f.indexOf( "%", jold ) + 1;
- js += (j-jold - 2); //-2 accounts for the '%X'
- jold = j;
-
- QChar cf = f[j];
- QChar cend = f[j+1]; //the character following the token
- int jend = s.indexOf( cend, js );
- if (jend==-1) jend = s.length();
- QString chunk = s.mid( js, jend-js );
- js += chunk.length(); //move marker past the data we just read
-
- switch ( cf.toAscii() ) {
- case 'Y':
- y = chunk.toInt();
- break;
- case 'y':
- y = chunk.toInt();
- if ( y<40 ) y += 2000;
- else y += 1900;
- break;
- case 'n': //fall through
- case 'm':
- m = chunk.toInt();
- break;
- case 'e': //fall through
- case 'd':
- d = chunk.toInt();
- break;
- case 'b':
- {
- for ( int imn=1; imn<=12; imn++ )
- if ( chunk == shortMonthName(imn) ) m = imn;
- break;
- }
- case 'B':
- {
- for ( int imn=1; imn<=12; imn++ )
- if ( chunk == longMonthName(imn) ) m = imn;
- break;
- }
- }
- }
-
- if ( y == 0 || m == 0 || d == 0 ) { //date was not assigned.
- return ExtDate(); //invalid date
- } else {
- return ExtDate( y, m, d );
- }
-}
-
-ExtDate ExtDate::fromString( const QString& s )
-{
- ExtDate dResult = ExtDate::fromString( s, Qt::TextDate );
- if ( dResult.isValid() ) return dResult;
-
- dResult = ExtDate::fromString( s, Qt::ISODate );
- if ( dResult.isValid() ) return dResult;
-
- dResult = ExtDate::fromString( s, "%m/%d/%Y" );
- if ( dResult.isValid() ) return dResult;
-
- else return ExtDate(); //invalid
-
-}
-
-ExtDate ExtDate::fromString( const QString& s, Qt::DateFormat f )
-{
- ExtDate dt = ExtDate(); //initialize invalid date
- if ( s.isEmpty() ) { return dt; }
- if ( f == Qt::LocalDate ) { //can't use LocalFormat
-#if defined(QT_CHECK_RANGE)
- qWarning( "QDate::fromString: Parameter out of range" );
-#endif
- return dt;
- }
-
- switch( f ) {
- case Qt::ISODate :
- {
- int year( s.mid( 0, 4 ).toInt() );
- int month( s.mid( 5, 2 ).toInt() );
- int day( s.mid( 8, 2 ).toInt() );
- if ( year && month && day )
- return ExtDate( year, month, day );
- }
- break;
-
- default :
-#ifndef QT_NO_TEXTDATE
- case Qt::TextDate :
- {
- //Three possible date formats:
- //dd mth yyyy; mth dd yyyy; wkd mth dd yyyy
- QStringList ss = s.split( " " );
-
- //Return invalid if we don't have at least 3 fields
- if ( ss.size() < 3 ) return dt;
-
- bool ok = false;
- int month = -1;
- uint imonth = 0;
- uint iyear = 0;
-
- //If neither of the first two words is a number, then we'll assume
- //the first word is a superfluous "weekday" string
- int day = ss[0].toInt( &ok );
- if ( ! ok ) {
- day = ss[1].toInt( &ok );
- if ( ! ok ) {
- day = ss[2].toInt( &ok );
- if ( !ok ) return dt; //could not find a valid day number in first three words
- imonth = 1; //the month must be the second word
- iyear = 3; //the year must be the fourth word
- } else {
- //the month is either the first word, or the third.
- imonth = 0;
- iyear = 2;
- }
- } else {
- //month is the second word
- imonth = 1;
- iyear = 2;
- }
-
- for ( uint i = 0; i < 12; i++ ) {
- if ( ss[imonth] == m_shortMonthNames[i] || ss[imonth] == shortMonthName( i + 1 ) ) {
- month = i + 1;
- break;
- }
- }
-
- if ( month == -1 && imonth == 0 ) { //try the third word
- imonth = 2;
- iyear = 3;
- for ( uint i = 0; i < 12; i++ ) {
- if ( ss[imonth] == m_shortMonthNames[i] || ss[imonth] == shortMonthName( i + 1 ) ) {
- month = i + 1;
- break;
- }
- }
- }
-
- if ( month > -1 ) ok = true;
- if ( ! ok ) return dt; //could not parse month; return invalid
-
- int year = ss[iyear].toInt( &ok );
- if ( ! ok ) return dt; //could not parse year; return invalid
-
- return ExtDate( year, month, day );
-
- break;
- }
-#else
- break;
-#endif //ifndef QT_NO_TEXTDATE
- }
-
- return dt;
-}
-#endif //ifndef QT_NO_DATESTRING
-
-bool ExtDate::isValid( int y, int m, int d )
-{
- if (m < 1 || m > 12) return false;
- if (d < 1) return false;
- if (m != 2 && d > (int) m_monthLength[m-1]) return false;
- if (m == 2 && d > ( (int) m_monthLength[1] + (leapYear(y) ? 1 : 0))) return false;
- return true;
-}
-
-QDate ExtDate::qdate() const {
- QDate q( year(), month(), day() );
-
- if ( q.isValid() )
- return q;
- else
- return QDate();
-}
-
-bool ExtDate::leapYear( int year )
-{
- // year is the year-number where JC birth is 0
- if ((year % 4) != 0) return false;
- // multiple of 4 : can be a leap year
- // centennial years are NOT leap, but quadri-centennial ARE.
- if ((year % 400) == 0) return true;
- if ((year % 100) == 0) return false;
- // year is multiple of 4 but not centennial so leap year !
- return true;
-}
-
-int ExtDate::dayOfYear(int y, int m, int d)
-{
- return m_monthOrigin[m-1] + d + ((m > 1) ? (leapYear(y) ? 1 : 0) : 0);
-}
-
-/*****************************************************************************
- ExtDateTime member functions
- *****************************************************************************/
-
-/*!
- \class ExtDateTime extdatetime.h
- \brief The ExtDateTime class provides date and time functions.
-
- \ingroup time
-
-
- \sa ExtDate QTime ExtDateTimeEdit
-*/
-
-ExtDateTime::ExtDateTime()
- : d( ExtDate() ), t( QTime() )
-{
-}
-
-ExtDateTime::ExtDateTime( const ExtDate &date )
- : d(date), t(QTime(0,0,0))
-{
-}
-
-/*!
- Constructs a datetime with date \a date and time \a time.
-*/
-
-ExtDateTime::ExtDateTime( const ExtDate &date, const QTime &time )
- : d(date), t(time)
-{
-}
-
-
-/*!
- \fn bool ExtDateTime::isNull() const
-
- Returns true if both the date and the time are null; otherwise
- returns false. A null datetime is invalid.
-
- \sa ExtDate::isNull(), QTime::isNull()
-*/
-
-/*!
- \fn bool ExtDateTime::isValid() const
-
- Returns true if both the date and the time are valid; otherwise
- returns false.
-
- \sa ExtDate::isValid(), QTime::isValid()
-*/
-
-/*!
- \fn ExtDate ExtDateTime::date() const
-
- Returns the date part of the datetime.
-
- \sa setDate(), time()
-*/
-
-/*!
- \fn QTime ExtDateTime::time() const
-
- Returns the time part of the datetime.
-
- \sa setTime(), date()
-*/
-
-/*!
- \fn void ExtDateTime::setDate( const ExtDate &date )
-
- Sets the date part of this datetime to \a date.
-
- \sa date(), setTime()
-*/
-
-/*!
- \fn void ExtDateTime::setTime( const QTime &time )
-
- Sets the time part of this datetime to \a time.
-
- \sa time(), setDate()
-*/
-
-
-/*!
- Returns the datetime as the number of seconds that have passed
- since 1970-01-01T00:00:00, Coordinated Universal Time (UTC).
-
- On systems that do not support timezones, this function will
- behave as if local time were UTC.
-
- \sa setTime_t()
-*/
-
-uint ExtDateTime::toTime_t() const
-{
- tm brokenDown;
- brokenDown.tm_sec = t.second();
- brokenDown.tm_min = t.minute();
- brokenDown.tm_hour = t.hour();
- brokenDown.tm_mday = d.day();
- brokenDown.tm_mon = d.month() - 1;
- brokenDown.tm_year = d.year() - 1900;
- brokenDown.tm_isdst = -1;
- int secsSince1Jan1970UTC = (int) mktime( &brokenDown );
- if ( secsSince1Jan1970UTC < -1 )
- secsSince1Jan1970UTC = -1;
- return (uint) secsSince1Jan1970UTC;
-}
-
-/*!
- \overload
-
- Convenience function that sets the date and time to local time
- based on the given UTC time.
-*/
-
-void ExtDateTime::setTime_t( uint secsSince1Jan1970UTC )
-{
- setTime_t( secsSince1Jan1970UTC, Qt::LocalTime );
-}
-
-/*!
- Sets the date and time to \a ts time (\c Qt::LocalTime or \c
- Qt::UTC) given the number of seconds that have passed since
- 1970-01-01T00:00:00, Coordinated Universal Time (UTC). On systems
- that do not support timezones this function will behave as if
- local time were UTC.
-
- On Windows, only a subset of \a secsSince1Jan1970UTC values are
- supported, as Windows starts counting from 1980.
-
- \sa toTime_t()
-*/
-void ExtDateTime::setTime_t( uint secsSince1Jan1970UTC, Qt::TimeSpec ts )
-{
- time_t tmp = (time_t) secsSince1Jan1970UTC;
- tm *brokenDown = 0;
-
-#if defined(Q_OS_UNIX) && defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
- // posix compliant system
- // use the reentrant versions of localtime() and gmtime() where available
- tm res;
- if ( ts == Qt::LocalTime )
- brokenDown = localtime_r( &tmp, &res );
- if ( !brokenDown ) {
- brokenDown = gmtime_r( &tmp, &res );
- if ( !brokenDown ) {
- d.setJD( ExtDate::GregorianToJD( 1970, 1, 1 ) );
- t.setHMS(0,0,0);
- // t.ds = 0;
- return;
- }
- }
-#else
- if ( ts == Qt::LocalTime )
- brokenDown = localtime( &tmp );
- if ( !brokenDown ) {
- brokenDown = gmtime( &tmp );
- if ( !brokenDown ) {
- d.setJD( ExtDate::GregorianToJD( 1970, 1, 1 ) );
-// t.ds = 0;
- t.setHMS(0,0,0);
- return;
- }
- }
-#endif
-
- d.setJD( ExtDate::GregorianToJD( brokenDown->tm_year + 1900,
- brokenDown->tm_mon + 1,
- brokenDown->tm_mday ) );
- t.setHMS( brokenDown->tm_hour, brokenDown->tm_min, brokenDown->tm_sec );
-// t.ds = MSECS_PER_HOUR * brokenDown->tm_hour +
-// MSECS_PER_MIN * brokenDown->tm_min +
-// 1000 * brokenDown->tm_sec;
-}
-#ifndef QT_NO_DATESTRING
-#ifndef QT_NO_SPRINTF
-/*!
- \overload
-
- Returns the datetime as a string. The \a f parameter determines
- the format of the string.
-
- If \a f is \c Qt::TextDate, the string format is "Wed May 20
- 03:40:13 1998" (using ExtDate::shortDayName(), ExtDate::shortMonthName(),
- and QTime::toString() to generate the string, so the day and month
- names will have localized names).
-
- If \a f is \c Qt::ISODate, the string format corresponds to the
- ISO 8601 extended specification for representations of dates and
- times, which is YYYY-MM-DDTHH:MM:SS.
-
- If \a f is \c Qt::LocalDate, the string format depends on the
- locale settings of the system.
-
- If the format \a f is invalid or the datetime is invalid, toString()
- returns a null string.
-
- \sa ExtDate::toString() QTime::toString()
-*/
-
-QString ExtDateTime::toString( Qt::DateFormat f ) const
-{
- if ( !isValid() )
- return QString();
-
- if ( f == Qt::ISODate ) {
- return d.toString( Qt::ISODate ) + 'T' + t.toString( Qt::ISODate );
- }
-#ifndef QT_NO_TEXTDATE
- else if ( f == Qt::TextDate ) {
- return toString( "%a %b %e %Y %H:%M:%S" );
- }
-#endif
- else if ( f == Qt::LocalDate ) {
- return toString( KGlobal::locale()->dateFormat()
- + ' ' + KGlobal::locale()->timeFormat() );
- }
-
- return QString();
-}
-#endif
-
-QString ExtDateTime::toString( const QString& format ) const
-{
- if ( !isValid() )
- return QString();
-
- //Parse the date portion of the format string
- QString result = date().toString( format );
-
- //For the time format, use the following KDE format specs:
- //Replace occurrences of the following tokens with their
- //corresponding values:
- //
- // %H Hour in 24h format, 2 digits
- // %k Hour in 24h format, 1-2 digits
- // %I Hour in 12h format, 2 digits
- // %l Hour in 12h format, 1-2 digits
- // %M Minute, 2 digits
- // %S Seconds, 2 digits
- // %p pm/am
-
- int h = time().hour();
-
- result.replace( "%H", QString().sprintf( "%02d", h ) );
- result.replace( "%k", QString().sprintf( "%d", h ) );
- result.replace( "%I", QString().sprintf( "%02d", ( h > 12 ) ? h-12 : h ) );
- result.replace( "%l", QString().sprintf( "%d", ( h > 12 ) ? h-12 : h ) );
- result.replace( "%M", QString().sprintf( "%02d", time().minute() ) );
- result.replace( "%S", QString().sprintf( "%02d", time().second() ) );
- result.replace( "%p", QString().sprintf( "%s", ( h > 12 ) ? "pm" : "am" ) );
-
- return result;
-}
-#endif //QT_NO_DATESTRING
-
-/*!
- Returns a ExtDateTime object containing a datetime \a ndays days
- later than the datetime of this object (or earlier if \a ndays is
- negative).
-
- \sa daysTo(), addMonths(), addYears(), addSecs()
-*/
-
-ExtDateTime ExtDateTime::addDays( int ndays ) const
-{
- return ExtDateTime( d.addDays(ndays), t );
-}
-
-/*!
- Returns a ExtDateTime object containing a datetime \a nmonths months
- later than the datetime of this object (or earlier if \a nmonths
- is negative).
-
- \sa daysTo(), addDays(), addYears(), addSecs()
-*/
-
-ExtDateTime ExtDateTime::addMonths( int nmonths ) const
-{
- return ExtDateTime( d.addMonths(nmonths), t );
-}
-
-/*!
- Returns a ExtDateTime object containing a datetime \a nyears years
- later than the datetime of this object (or earlier if \a nyears is
- negative).
-
- \sa daysTo(), addDays(), addMonths(), addSecs()
-*/
-
-ExtDateTime ExtDateTime::addYears( int nyears ) const
-{
- return ExtDateTime( d.addYears(nyears), t );
-}
-
-/*!
- Returns a ExtDateTime object containing a datetime \a nsecs seconds
- later than the datetime of this object (or earlier if \a nsecs is
- negative).
-
- \sa secsTo(), addDays(), addMonths(), addYears()
-*/
-
-ExtDateTime ExtDateTime::addSecs( int nsecs ) const
-{
- long int dd = d.jd();
- int tt = MSECS_PER_HOUR*t.hour() + MSECS_PER_MIN*t.minute() + 1000*t.second() + t.msec();
- tt += nsecs*1000;
-
- while ( tt < 0 ) {
- tt += MSECS_PER_DAY;
- --dd;
- }
-
- while ( tt > int(MSECS_PER_DAY) ) {
- tt -= MSECS_PER_DAY;
- ++dd;
- }
-
- ExtDateTime ret;
- ret.setTime( QTime().addMSecs( tt ) );
- ret.setDate( ExtDate( dd ) );
-
- return ret;
-}
-
-/*!
- Returns the number of days from this datetime to \a dt (which is
- negative if \a dt is earlier than this datetime).
-
- \sa addDays(), secsTo()
-*/
-
-int ExtDateTime::daysTo( const ExtDateTime &dt ) const
-{
- return d.daysTo( dt.d );
-}
-
-/*!
- Returns the number of seconds from this datetime to \a dt (which
- is negative if \a dt is earlier than this datetime).
-
- Example:
- \code
- ExtDateTime dt = ExtDateTime::currentDateTime();
- ExtDateTime xmas( ExtDate(dt.date().year(),12,24), QTime(17,00) );
- kDebug( ) << "There are " << dt.secsTo(xmas) << " seconds to Christmas";
- \endcode
-
- \sa addSecs(), daysTo(), QTime::secsTo()
-*/
-
-int ExtDateTime::secsTo( const ExtDateTime &dt ) const
-{
- return t.secsTo(dt.t) + d.daysTo(dt.d)*SECS_PER_DAY;
-}
-
-
-/*!
- Returns true if this datetime is equal to \a dt; otherwise returns false.
-
- \sa operator!=()
-*/
-
-bool ExtDateTime::operator==( const ExtDateTime &dt ) const
-{
- return t == dt.t && d == dt.d;
-}
-
-/*!
- Returns true if this datetime is different from \a dt; otherwise
- returns false.
-
- \sa operator==()
-*/
-
-bool ExtDateTime::operator!=( const ExtDateTime &dt ) const
-{
- return t != dt.t || d != dt.d;
-}
-
-/*!
- Returns true if this datetime is earlier than \a dt; otherwise
- returns false.
-*/
-
-bool ExtDateTime::operator<( const ExtDateTime &dt ) const
-{
- if ( d < dt.d )
- return true;
- return d == dt.d ? t < dt.t : false;
-}
-
-/*!
- Returns true if this datetime is earlier than or equal to \a dt;
- otherwise returns false.
-*/
-
-bool ExtDateTime::operator<=( const ExtDateTime &dt ) const
-{
- if ( d < dt.d )
- return true;
- return d == dt.d ? t <= dt.t : false;
-}
-
-/*!
- Returns true if this datetime is later than \a dt; otherwise
- returns false.
-*/
-
-bool ExtDateTime::operator>( const ExtDateTime &dt ) const
-{
- if ( d > dt.d )
- return true;
- return d == dt.d ? t > dt.t : false;
-}
-
-/*!
- Returns true if this datetime is later than or equal to \a dt;
- otherwise returns false.
-*/
-
-bool ExtDateTime::operator>=( const ExtDateTime &dt ) const
-{
- if ( d > dt.d )
- return true;
- return d == dt.d ? t >= dt.t : false;
-}
-
-/*!
- \overload
-
- Returns the current datetime, as reported by the system clock.
-
- \sa ExtDate::currentDate(), QTime::currentTime()
-*/
-
-ExtDateTime ExtDateTime::currentDateTime()
-{
- return currentDateTime( Qt::LocalTime );
-}
-
-/*!
- Returns the current datetime, as reported by the system clock, for the
- TimeSpec \a ts. The default TimeSpec is LocalTime.
-
- \sa ExtDate::currentDate(), QTime::currentTime(), Qt::TimeSpec
-*/
-
-ExtDateTime ExtDateTime::currentDateTime( Qt::TimeSpec ts )
-{
- ExtDateTime dt;
- dt.setDate( ExtDate::currentDate(ts) );
- QTime t = ts == Qt::LocalTime ? QTime::currentTime() : QDateTime::currentDateTime().toUTC().time();
- if ( t.hour()==0 && t.minute()==0 ) // midnight or right after?
- dt.setDate( ExtDate::currentDate(ts) ); // fetch date again
- dt.setTime( t );
- return dt;
-}
-
-#ifndef QT_NO_DATESTRING
-/*!
- Returns the ExtDateTime represented by the string \a s, using the
- format \a f, or an invalid datetime if this is not possible.
-
- Note for \c Qt::TextDate: It is recommended that you use the
- English short month names (e.g. "Jan"). Although localized month
- names can also be used, they depend on the user's locale settings.
-
- \warning Note that \c Qt::LocalDate cannot be used here.
-*/
-ExtDateTime ExtDateTime::fromString( const QString& s )
-{
- ExtDateTime dtResult = ExtDateTime::fromString( s, Qt::TextDate );
- if ( dtResult.isValid() ) return dtResult;
-
- dtResult = ExtDateTime::fromString( s, Qt::ISODate );
-
- if ( dtResult.isValid() ) return dtResult;
- else return ExtDateTime(); //invalid
-}
-
-ExtDateTime ExtDateTime::fromString( const QString& s, Qt::DateFormat f )
-{
- ExtDateTime dt;
-
- if ( ( s.isEmpty() ) || ( f == Qt::LocalDate ) ) {
-#if defined(QT_CHECK_RANGE)
- qWarning( "ExtDateTime::fromString: Parameter out of range" );
-#endif
- dt.d.setJD( INVALID_DAY );
- return dt;
- }
-
- if ( f == Qt::ISODate ) {
- return ExtDateTime( ExtDate::fromString( s.mid(0,10), Qt::ISODate ),
- QTime::fromString( s.mid(11), Qt::ISODate ) );
- }
-#if !defined(QT_NO_REGEXP) && !defined(QT_NO_TEXTDATE)
- else if ( f == Qt::TextDate ) {
-
- //parse the time, if it exists.
- QTime time;
- QString sd = s;
- int hour, minute, second;
- int pivot = s.indexOf( QRegExp(QString::fromLatin1("[0-9][0-9]:[0-9][0-9]:[0-9][0-9]")) );
- if ( pivot != -1 ) {
- hour = s.mid( pivot, 2 ).toInt();
- minute = s.mid( pivot+3, 2 ).toInt();
- second = s.mid( pivot+6, 2 ).toInt();
- time.setHMS( hour, minute, second );
-
- sd = s.left( pivot - 1 );
- }
-
- //sd is now just the date string.
- ExtDate date = ExtDate::fromString( s, Qt::TextDate );
- return ExtDateTime( date, time );
- }
-
-#endif //QT_NO_REGEXP
- return ExtDateTime();
-}
-#endif //QT_NO_DATESTRING
-
-
-#ifndef QT_NO_DATASTREAM
-KDE_EXPORT QDataStream &operator<<( QDataStream & ostream, const ExtDate & date)
-{
- return ostream << (quint32)(date.jd());
-}
-
-KDE_EXPORT QDataStream &operator>>( QDataStream & ostream, ExtDate & date)
-{
- quint32 julday;
- ostream >> julday;
- date.setJD( julday );
- return ostream;
-}
-
-KDE_EXPORT QDataStream &operator<<( QDataStream & ostream, const ExtDateTime & dt)
-{
- return ostream << dt.d << dt.t;
-}
-
-KDE_EXPORT QDataStream &operator>>( QDataStream & ostream, ExtDateTime & dt)
-{
- ostream >> dt.d >> dt.t;
- return ostream;
-}
-
-#endif // QT_NO_DATASTREAM
+++ /dev/null
-/***************************************************************************
-
- extdatetime.h
- -------------
- Copyright (c) 2004 by Michel Guitel <michel.guitel@sap.ap-hop-paris.fr>
- Copyright (c) 2004-2006 by Jason Harris <kstars@30doradus.org>
-
- Note: This code was adapted from the Qt classes QDate and QDateTime,
- copyright Trolltech, Inc. and licensed under the GNU GPL.
-
- If there is ever a need for an LGPL version of these classes, they
- will need to be reimplemented from scratch to avoid violating
- Trolltech's license.
-
- ***************************************************************************/
-/***************************************************************************
- * *
- * 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. *
- * *
- ***************************************************************************/
-
-#ifndef EXTDATETIME_H
-#define EXTDATETIME_H
-
-#include <libkdeedu_extdate_export.h>
-
-#include <limits.h>
-#include <qstring.h>
-#include <qdatetime.h>
-
-#define INVALID_DAY LONG_MIN
-
-class ExtDateTime;
-
-/**
- *@fn test2_unit
- *@short A function used in the unit tests for this class
- *@note there is no reason to use this function outside the unit tests
- *@param y the year to be tested
- *@param m the month to be tested
- *@param d the day to be tested
- */
-extern void test2_unit(int y, int m, int d);
-
-/**
- *@class ExtDate
- *@short Extended-range date class
- *
- *ExtDate encapsulates the calendar date. It is functionally identical
- *to the Qt class QDate, except that it allows for dates far outside the
- *range of valid QDates (years 1752-8000). In fact, there is no limit
- *to the range of dates possible, but for practical reasons we limit
- *the range of allowable years to -50000 to 50000.
- *
- *The date is represented internally as the Julian Day number (stored
- *as a long int). We also store the year, month and day values as
- *integers.
- *
- *The class provides functions for converting ExtDates to and from
- *QDates, Julian Days, and string expressions. It also provides
- *operators for comparing ExtDate objects. ExtDates can be manipulated
- *by setting the Julian Day, or the year, month or day values. Years,
- *months and days may also be incremented.
- *
- *@author Michael Guitel, Jason Harris
- */
-class EXTDATE_EXPORT ExtDate
-{
- public:
- /**
- *@short Default constructor
- *Create an invalid date
- */
- ExtDate();
- /**
- *@short Constructor
- *Create an ExtDate for the specified calendar date
- *@p y The year of the date to be created
- *@p m The month of the date to be created
- *@p d The day of the date to be created
- *@note The year must be in the range -50000 to 50000.
- */
- ExtDate( int y, int m, int d );
- /**
- *@short Constructor
- *Create an ExtDate from the specified QDate
- *@p q The QDate representing the date to be created
- *@note Of course, this constructor cannot be used if you
- *need a date outside the valid Qt range (years 1752-8000).
- */
- ExtDate( const QDate &q ) { ExtDate( q.year(), q.month(), q.day() ); }
- /**
- *@short Constructor
- *Create an ExtDate for the specified Julian Day.
- *@p jd the Julian Day of the date to be created
- *@note The Julian Day is a simple count of the number
- *of days elapsed since January 1st, in the year -4713.
- */
- ExtDate( long int jd );
-
- /**
- *@return true if the ExtDate is an Null date
- *@note a Null date is one that was created with the default
- *constructor. Null dates are also invalid dates.
- *@sa isValid()
- */
- bool isNull() const { return m_jd == INVALID_DAY; }
-
- /**
- *@return true if the ExtDate is a valid date.
- *@note A date may be invalid if it is a Null date, if
- *its year value exceeds the valid range (-50000 to 50000),
- *or if its month or day values are out of bounds.
- */
- bool isValid() const;
-
- /**
- *@return the ExtDate, converted to a QDate.
- *@note If the ExtDate is invalid or falls outside the range
- *of valid QDates (years 1752 to 8000), the returned QDate
- *will be invalid.
- */
- QDate qdate() const;
-
- /**
- *@return the year of the ExtDate
- */
- int year() const { return m_year; }
- /**
- *@return the month of the ExtDate, as an integer between 1 and 12
- *@sa monthName()
- *@sa longMonthName()
- *@sa shortMonthName()
- */
- int month() const { return m_month; }
- /**
- *@return the day of the ExtDate, as an integer between 1 and 31
- */
- int day() const { return m_day; }
- /**
- *@return the day-of-the week of the ExtDate, as an integer between 1 and 7
- *@sa dayName()
- *@sa longDayName()
- *@sa shortDayName()
- */
- int dayOfWeek() const;
- /**
- *@return the ExtDate's position within the current year, as an integer
- *between 1 and 366.
- */
- int dayOfYear() const;
- /**
- *@return the number of days in the ExtDate's month, as an integer
- *between 28 and 31.
- */
- int daysInMonth() const;
- /**
- *@return the number of days in the ExtDate's year.
- *@note The returned value is either 365, or 366 if it is a leap year.
- */
- int daysInYear() const;
- /**
- *@return the position within the current year of the week containing
- *the ExtDate.
- *@p yearNum pointer integer, which is set to the year to which the week
- *belongs
- *@note It is possible for dates near the end of the year to belong to
- *the first week of the following year.
- */
- int weekNumber( int *yearNum=0 ) const;
- /**
- *@return the Julian Day representation of the ExtDate.
- *@note The Julian Day is a simple count of the number of days
- *elapsed since January 1st, in the year -4713.
- */
- long int jd() const { return m_jd; }
-
-#ifndef QT_NO_TEXTDATE
-#ifndef QT_NO_COMPAT
- /**
- *@return the short name of the ExtDate's month (for example,
- "Aug", short for "August").
- *@note This function is identical to shortMonthName(), and is
- *provided for convenience.
- *@sa shortMonthName()
- */
- static QString monthName( int month ) { return shortMonthName( month ); }
- /**
- *@return the short name of the ExtDate's day-of-week (for example,
- *"Thu", short for "Thursday").
- *@note This function is identical to shortDayName(), and is
- *provided for convenience.
- *@sa shortDayName()
- */
- static QString dayName( int weekday ) { return shortDayName( weekday ); }
-#endif
- /**
- *@return the short name of the ExtDate's month (for example,
- "Aug", short for "August").
- */
- static QString shortMonthName( int month );
- /**
- *@return the short name of the ExtDate's day-of-week (for example,
- *"Thu", short for "Thursday").
- */
- static QString shortDayName( int weekday );
- /**
- *@return the long name of the ExtDate's month (for example, "August").
- */
- static QString longMonthName( int month );
- /**
- *@return the long name of the ExtDate's day-of-week (for example,
- *"Thursday").
- */
- static QString longDayName( int weekday );
-#endif //QT_NO_TEXTDATE
-#ifndef QT_NO_TEXTSTRING
-#if !defined(QT_NO_SPRINTF)
- /**
- *@return a string representation of the ExtDate according to
- *the given date format.
- *@p f the Qt::DateFormat describing the date string
- *@see Qt::DateFormat
- */
- QString toString( Qt::DateFormat f = Qt::TextDate ) const;
-#endif
- /**
- *@return a string representation of the ExtDate according to
- *the given date format.
- *@p format a QString describing the date format according to
- *a subset of the KDE date string specification:
- *
- *Any occurrence of the following tokens in the format string
- *are replaced with the corresponding value:
- *
- *@li %Y The year, including centuries prefix (e.g., "1984")
- *@li %y The year, excluding centuries prefix (e.g., "84")
- *@li %n Numerical month value (e.g., "3" for March)
- *@li %m Numerical month value, two digits (e.g., "03" for March)
- *@li %e Numerical day value (e.g., "3" on March 3rd)
- *@li %d Numerical day value, two digits (e.g., "03" on March 3rd)
- *@li %b Month name, short form (e.g., "Mar" for March)
- *@li %B Month name, long form (e.g., "March")
- *@li %a Weekday name, short form (e.g., "Wed" for Wednesday)
- *@li %A Weekday name, long form (e.g., "Wednesday")
- *
- *All other characters in the format string are left as-is.
- */
- QString toString( const QString& format ) const;
-#endif
- /**
- *@short Set the ExtDate according to the given year, month and day.
- *@p y the year of the date to be set
- *@p m the month of the date to be set
- *@p d the day of the date to be set
- *@return true if the ExtDate is valid
- */
- bool setYMD( int y, int m, int d );
- /**
- *@short Set the ExtDate according to the given Julian Day.
- *@p _jd the Julian Day of the date to be set
- *@return true if the ExtDate is valid
- *@note The Julian Day is a simple count of the number of days
- *elapsed since January 1st, in the year -4713.
- */
- bool setJD( long int _jd );
-
- /**
- *@return an ExtDate created by adding the given number of days
- *to this ExtDate object.
- *@p days the number of days to add to the current ExtDate. The
- *numbers of days may be negative.
- *@note The current ExtDate object is not affected by this function;
- *the modified ExtDate is provided in the return value.
- */
- ExtDate addDays( int days ) const;
- /**
- *@return an ExtDate created by adding the given number of months
- *to this ExtDate object.
- *@p months the number of months to add to the current ExtDate. The
- *numbers of months may be negative.
- *@note The current ExtDate object is not affected by this function;
- *the modified ExtDate is provided in the return value.
- */
- ExtDate addMonths( int months ) const;
- /**
- *@return an ExtDate created by adding the given number of years
- *to this ExtDate object.
- *@p years the number of years to add to the current ExtDate. The
- *numbers of years may be negative.
- *@note The current ExtDate object is not affected by this function;
- *the modified ExtDate is provided in the return value.
- */
- ExtDate addYears( int years ) const;
- /**
- *@return The number of days between the current ExtDate and the
- *ExtDate provided as an argument. For example, if the current
- *ExtDate is March 15, 2006 and the ExtDate given as an argument
- *represents March 18, 2006, then this function wuld return 3.
- *@p d the target date to which the number of days will be counted
- */
- int daysTo( const ExtDate &d ) const;
-
- /**
- *@return true if the two ExtDates are equal
- */
- bool operator==( const ExtDate &d ) const { return m_jd == d.jd(); }
- /**
- *@return true if the two ExtDates are not equal
- */
- bool operator!=( const ExtDate &d ) const { return m_jd != d.jd(); }
- /**
- *@return true if the left-hand ExtDate is earlier than the
- *right-hand ExtDate
- */
- bool operator<( const ExtDate &d ) const { return m_jd < d.jd(); }
- /**
- *@return true if the left-hand ExtDate is earlier than or equal to the
- *right-hand ExtDate
- */
- bool operator<=( const ExtDate &d ) const { return m_jd <= d.jd(); }
- /**
- *@return true if the left-hand ExtDate is later than the
- *right-hand ExtDate
- */
- bool operator>( const ExtDate &d ) const { return m_jd > d.jd(); }
- /**
- *@return true if the left-hand ExtDate is later than or equal to the
- *right-hand ExtDate
- */
- bool operator>=( const ExtDate &d ) const { return m_jd >= d.jd(); }
-
- /**
- *@return an ExtDate representing the current date, according to the
- *computer's clock.
- *@p ts a Qt::TimeSpec value that determines whether the date is
- *computed from the Local Time or the Universal Time.
- *@sa Qt::TimeSpec
- */
- static ExtDate currentDate( Qt::TimeSpec ts = Qt::LocalTime );
-#ifndef QT_NO_DATESTRING
- /**
- *@return an ExtDate constructed from the string representation
- *given as an argument.
- *@p s The string representation of the date
- *@note No sring format is specified, so this function will attempt
- *both Qt::TextDate and Qt::ISODate formats.
- */
- static ExtDate fromString( const QString& s );
- /**
- *@return an ExtDate constructed from the string representation
- *given as an argument.
- *@p s The string representation of the date
- *@p f The Qt::DateFormat with which to interpret the date string
- *@note This function only understands Qt::TextDate and Qt::ISODate
- *formats. It does not handle Qt::LocalDate.
- */
- static ExtDate fromString( const QString& s, Qt::DateFormat f);
- /**
- *@return an ExtDate constructed from the string representation
- *given as an argument.
- *@p s The string representation of the date
- *@p format A string representing the date format, according to
- *the KDE date string specification.
- *@see ExtDate::toString( const QString &format )
- */
- static ExtDate fromString( const QString& s, const QString &format );
-#endif
- /**
- *@return true if the date described by the arguments is valid
- *@p y the year of the date to be tested
- *@p m the month of the date to be tested
- *@p d the day of the date to be tested
- */
- static bool isValid( int y, int m, int d );
- /**
- *@return true if the given year is a leap year.
- *@p year the year to be tested
- */
- static bool leapYear( int year );
-
- /**
- *@return the Julian Day corresponding to the date described by
- *the arguments
- *@p y The year of the date to be converted
- *@p m The month of the date to be converted
- *@p d The day of the date to be converted
- */
- static long int GregorianToJD( int y, int m, int d );
- /**
- *@return the year, month and day corresponding to the given Julian Day
- *@p jd The Julian Day to be converted
- *@p y The date's year is returned as a reference through this argument
- *@p m The date's month is returned as a reference through this argument
- *@p d The date's day is returned as a reference through this argument
- */
- static void JDToGregorian( long int jd, int &y, int &m, int &d );
-
-private:
- /**
- *@return the position within the year of the date described by the arguments
- *@p y the year of the date
- *@p m the month of the date
- *@p d the day of the date
- */
- static int dayOfYear(int y, int m, int d);
-
- long int m_jd;
- int m_year, m_month, m_day;
- static uint m_monthLength[12];
- static uint m_monthOrigin[12];
- static QString m_shortMonthNames[12];
- static QString m_shortDayNames[7];
- static QString m_longMonthNames[12];
- static QString m_longDayNames[7];
-
- friend class ExtDateTime;
-
-#ifndef QT_NO_DATASTREAM
- friend EXTDATE_EXPORT QDataStream &operator<<( QDataStream &, const ExtDate & );
- friend EXTDATE_EXPORT QDataStream &operator>>( QDataStream &, ExtDate & );
- friend EXTDATE_EXPORT QDataStream &operator<<( QDataStream &, const ExtDateTime & );
- friend EXTDATE_EXPORT QDataStream &operator>>( QDataStream &, ExtDateTime & );
-#endif
-};
-
-/**
- *@class ExtDateTime
- *@short Extended-range date class
- *
- *ExtDateTime encapsulates the calendar date and time. It is functionally
- *identical to the Qt class QDateTime, except that it allows for dates
- *far outside the range of valid QDates (years 1752-8000). In fact, there
- *is no limit to the range of dates posiible, but for practical reasons we
- *limit the range of allowable years to -50000 to 50000.
- *
- *Internally, an ExtDateTime is simply an ExtDate paired with a QTime, with
- *very little interaction between these two pieces.
- *
- *@author Michael Guitel, Jason Harris
- */
-class EXTDATE_EXPORT ExtDateTime
-{
-public:
- /**
- *@short Default constructor. Creates a null ExtDateTime object.
- */
- ExtDateTime();
- /**
- *@short Constructor. Sets the date according to the argument;
- *the time is set to midnight.
- *@p d The date to be set
- */
- ExtDateTime( const ExtDate &d );
- /**
- *@short Constructor. Sets date and time according to the arguments
- *@p d The date to be set
- *@p t The time to be set
- */
- ExtDateTime( const ExtDate &d, const QTime &t );
-
- /**
- *@return true if the object specifies a null Date/Time.
- *@note Null Date/Times are also invalid Date/Times
- *@sa isValid()
- */
- bool isNull() const { return d.isNull() && t.isNull(); }
- /**
- *@return true if the both the Date and Time specified in the
- *object are valid
- */
- bool isValid() const { return d.isValid() && t.isValid(); }
-
- /**
- *@return The ExtDate component of the Date/Time
- */
- ExtDate date() const { return d; }
- /**
- *@return The QTime component of the Date/Time
- */
- QTime time() const { return t; }
- /**
- *@return unsigned int corresponding to the UNIX representation
- *of the Date/Time.
- */
- uint toTime_t() const;
- /**
- *@short set the ExtDate component to the given argument, leaving the
- *QTime component at its current value
- *@p date the ExtDate to be set
- */
- void setDate( const ExtDate &date ) { d = date; }
- /**
- *@short set the QTime component to the given argument, leaving the
- *ExtDate component at its current value
- *@p time the QTimee to be set
- */
- void setTime( const QTime &time ) { t = time; }
- /**
- *@short set the Date/Time by converting from the given
- *UNIX time.
- *@p secs the UNIX time to convert
- *@note UNIX time is the number of seconds since 1970 Jan 1 00:00
- */
- void setTime_t( uint secs );
- /**
- *@short set the Date/Time by converting from the given
- *UNIX time.
- *@p secs the UNIX time to convert
- *@p ts Specifies whether Universal Time or Local Time should be set.
- *@note UNIX time is the number of seconds since 1970 Jan 1 00:00
- */
- void setTime_t( uint secs, Qt::TimeSpec ts);
-#ifndef QT_NO_DATESTRING
-#ifndef QT_NO_SPRINTF
- /**
- *@return a string representation of the Date/Time according to
- *the given date format.
- *@p f the Qt::DateFormat describing the date string
- *@sa ExtDate::toString( Qt::DateFormat )
- */
- QString toString( Qt::DateFormat f = Qt::TextDate ) const;
-#endif
- /**
- *@return a string representation of the Date/Time according to
- *the given date format.
- *@p format string representation of the date/time format, using
- *the KDE date/time string specification:
- *
- *Any occurrence of the following tokens in the format string
- *are replaced with the corresponding value:
- *
- *@li %Y The year, including centuries prefix (e.g., "1984")
- *@li %y The year, excluding centuries prefix (e.g., "84")
- *@li %n Numerical month value (e.g., "3" for March)
- *@li %m Numerical month value, two digits (e.g., "03" for March)
- *@li %e Numerical day value (e.g., "3" on March 3rd)
- *@li %d Numerical day value, two digits (e.g., "03" on March 3rd)
- *@li %b Month name, short form (e.g., "Mar" for March)
- *@li %B Month name, long form (e.g., "March")
- *@li %a Weekday name, short form (e.g., "Wed" for Wednesday)
- *@li %A Weekday name, long form (e.g., "Wednesday")
- *@li %H Hour in 24h format, 2 digits
- *@li %k Hour in 24h format, 1-2 digits
- *@li %I Hour in 12h format, 2 digits
- *@li %l Hour in 12h format, 1-2 digits
- *@li %M Minute, 2 digits
- *@li %S Seconds, 2 digits
- *@li %p pm/am
- *
- *All other characters in the format string are left as-is.
- *
- *@sa ExtDate::toString( Qt::DateFormat )
- */
- QString toString( const QString& format ) const;
-#endif
- /**
- *@return an ExtDateTime constructed by adding the given number
- *of days to the current Date/Time.
- *@p days the number of days to add to the current Date/Time.
- *@note the number of days can be negative
- */
- ExtDateTime addDays( int days ) const;
- /**
- *@return an ExtDateTime constructed by adding the given number
- *of months to the current Date/Time.
- *@p months the number of months to add to the current Date/Time.
- *@note the number of months can be negative
- */
- ExtDateTime addMonths( int months ) const;
- /**
- *@return an ExtDateTime constructed by adding the given number
- *of years to the current Date/Time.
- *@p years the number of years to add to the current Date/Time.
- *@note the number of years can be negative
- */
- ExtDateTime addYears( int years ) const;
- /**
- *@return an ExtDateTime constructed by adding the given number
- *of seconds to the current Date/Time.
- *@p seconds the number of days to add to the current Date/Time.
- *@note the number of seconds can be negative
- */
- ExtDateTime addSecs( int secs ) const;
- /**
- *@return the number of days between the current Date/Time and the
- *target Date/Time given as the argument.
- *@p dt the target Date/Time
- */
- int daysTo( const ExtDateTime &dt ) const;
- /**
- *@return the number of seconds between the current Date/Time and the
- *target Date/Time given as the argument.
- *@p dt the target Date/Time
- */
- int secsTo( const ExtDateTime &dt ) const;
-
- /**
- *@return true if the two ExtDateTime objects are equal
- */
- bool operator==( const ExtDateTime &dt ) const;
- /**
- *@return true if the two ExtDateTime objects are not equal
- */
- bool operator!=( const ExtDateTime &dt ) const;
- /**
- *@return true if the left-hand ExtDateTime object is less than
- *the right-hand ExtDateTime object.
- */
- bool operator<( const ExtDateTime &dt ) const;
- /**
- *@return true if the left-hand ExtDateTime object is less than
- *or equal to the right-hand ExtDateTime object.
- */
- bool operator<=( const ExtDateTime &dt ) const;
- /**
- *@return true if the left-hand ExtDateTime object is greater than
- *the right-hand ExtDateTime object.
- */
- bool operator>( const ExtDateTime &dt ) const;
- /**
- *@return true if the left-hand ExtDateTime object is greater than
- *or equal to the right-hand ExtDateTime object.
- */
- bool operator>=( const ExtDateTime &dt ) const;
-
- /**
- *@return Date/Time constructed from the current date and time
- *according to the compter's clock.
- */
- static ExtDateTime currentDateTime();
- /**
- *@return Date/Time constructed from the current date and time
- *according to the compter's clock.
- *@p ts Specifies whether to interpret the computer time as
- *Universal Time or Local Time.
- */
- static ExtDateTime currentDateTime( Qt::TimeSpec ts );
-#ifndef QT_NO_DATESTRING
- /**
- *@return ExtDateTime constructed from the given strng representation
- *@p s String representation of the Date/Time
- */
- static ExtDateTime fromString( const QString& s );
- /**
- *@return ExtDateTime constructed from the given strng representation
- *@p s String representation of the Date/Time
- *@p f Specifies the Date format to use in interpretng the string.
- */
- static ExtDateTime fromString( const QString& s, Qt::DateFormat f );
-#endif
- private:
- ExtDate d;
- QTime t;
-#ifndef QT_NO_DATASTREAM
- friend EXTDATE_EXPORT QDataStream &operator<<( QDataStream &, const ExtDateTime &);
- friend EXTDATE_EXPORT QDataStream &operator>>( QDataStream &, ExtDateTime & );
-#endif
-};
-
-/*****************************************************************************
- Date and time stream functions
- *****************************************************************************/
-
-#ifndef QT_NO_DATASTREAM
-EXTDATE_EXPORT QDataStream &operator<<( QDataStream &, const ExtDate & );
-EXTDATE_EXPORT QDataStream &operator>>( QDataStream &, ExtDate & );
-#endif // QT_NO_DATASTREAM
-
-#endif // EXTDATE_H
-
+++ /dev/null
-/***************************************************************************
- extdatetimeedit.cpp - K Desktop Planetarium
- -------------------
- begin : Tue Aug 30 21:50:00 PST 2005
- copyright : (C) 2005 by Jason Harris
- email : kstars@30doradus.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. *
- * *
- ***************************************************************************/
-
-#include "extdatetimeedit.h"
-#include "extdatetimeedit_p.h"
-
-#include <QDateTimeEdit>
-#include <QTimeEdit>
-#include <QHBoxLayout>
-#include <QMouseEvent>
-#include <QKeyEvent>
-#include <kglobal.h>
-#include <klocale.h>
-#include <kdebug.h>
-
-#include "extdatetime.h"
-
-
-class ExtDateEdit::Private
-{
-public:
- Private(ExtDateEdit* qq)
- : q( qq )
- {
- }
-
- // Initialize the ExtDate edit.
- void init( const ExtDate &d );
-
- // slots
- void slotRefreshHighlight();
- void slotEmitDateChanged();
-
- ExtDateEdit *q;
-
- uchar ActiveField; // 0==day; 1==month; 2==year
- ExtDate m_Date;
- QString m_DateFormat;
-};
-
-ExtDateEdit::ExtDateEdit( const ExtDate &date, QWidget *parent )
-: QSpinBox( parent ), d(new Private(this)) {
- d->init(date);
-}
-
-ExtDateEdit::ExtDateEdit( int jd, QWidget *parent )
- : QSpinBox( parent ), d(new Private(this)) {
- ExtDate ed(jd);
- d->init( ed );
-}
-
-ExtDateEdit::ExtDateEdit( QWidget *p )
- : QSpinBox( p ), d(new Private(this)) {
- d->init( ExtDate::currentDate() );
-}
-
-ExtDateEdit::~ExtDateEdit() {
- delete d;
-}
-
-void ExtDateEdit::Private::init( const ExtDate &d ) {
- ActiveField = 0;
- m_Date = d;
- q->setRange( -20000000, 20000000 ); //range of Julian Days
-
- //Set the date format to be the Locale's short date format, except:
- //always use full years instead of trimming ti two digits
- //and always use two-digit days and months
- m_DateFormat = KGlobal::locale()->dateFormatShort();
- m_DateFormat.replace( "y", "Y" );
- m_DateFormat.replace( "n", "m" );
- m_DateFormat.replace( "e", "d" );
-
- //Make sure highlight is persistent when value is changed
- connect( q, SIGNAL( valueChanged( int ) ), q, SLOT( slotEmitDateChanged() ) );
- connect( q, SIGNAL( dateChanged( const ExtDate & ) ), q, SLOT( slotRefreshHighlight() ) );
-
- edLineEdit *edle = new edLineEdit( q );
- q->setLineEdit(edle);
-
- q->setValue( m_Date.jd() );
- q->highlightActiveField();
-}
-
-void ExtDateEdit::Private::slotEmitDateChanged() {
- emit q->dateChanged( q->date() );
-}
-
-QString ExtDateEdit::simpleDateFormat() const {
- //Convert the KDE date format string (e.g., "%Y-%m-%d") to one
- //that accurately represents the number of digits in each date
- //field (e.g., "YYYY-MM-DD"). Note that while the Months and
- //Days fields will always have two digits, the number of digits
- //in the Years field depends on the displayed year.
- QString result = d->m_DateFormat;
- result.replace( "%Y", "YYYY" );
- result.replace( "%m", "MM" );
- result.replace( "%d", "DD" );
-
- int i=result.indexOf( "Y" );
- int dLength = result.length() - cleanText().length();
- if ( dLength > 0 ) { //the years field must have more than 4 digits
- for ( int j=0; j<dLength; j++ ) result.insert( i, "Y" );
- } else if ( dLength < 0 ) { //the years field has less than 4 digits
- result.remove( i, -1*dLength );
- }
-
- return result;
-}
-
-void ExtDateEdit::highlightActiveField() {
- int iStart(0), iLength(0);
- QString sdf = simpleDateFormat();
-
- //Pick out the position and length of the currently-active field
- if ( d->ActiveField == 0 ) { //Days field
- iStart = sdf.indexOf( "D" );
- iLength = 2; //The Days field should always be two digits
- } else if ( d->ActiveField == 1 ) { //Months field
- iStart = sdf.indexOf( "M" );
- iLength = 2; //The Months field should always be two digits
- } else { //Years field
- iStart = sdf.indexOf( "Y" );
- iLength = sdf.lastIndexOf( "Y" ) - iStart + 1;
- }
-
- lineEdit()->setCursorPosition( iStart + iLength );
- lineEdit()->setSelection( iStart, iLength );
-
-// //DEBUG
-// kDebug() << "selected text: " << lineEdit()->selectedText();
-
-}
-
-void ExtDateEdit::Private::slotRefreshHighlight() {
- q->highlightActiveField();
-}
-
-void ExtDateEdit::stepBy( int steps ) {
- switch ( d->ActiveField ) {
- case 0: //days field
- d->m_Date = d->m_Date.addDays( steps );
- break;
-
- case 1: //months field
- d->m_Date = d->m_Date.addMonths( steps );
- break;
-
- case 2: //years field
- d->m_Date = d->m_Date.addYears( steps );
- break;
- }
-
- int v = d->m_Date.jd();
- if ( v > maximum() ) setValue( maximum() );
- else if ( v < minimum() ) setValue( minimum() );
- else setValue( v );
-}
-
-QValidator::State ExtDateEdit::validate( QString &input, int & ) const {
- if ( ExtDate::fromString( input, d->m_DateFormat ).isValid() )
- return QValidator::Acceptable;
- else
- return QValidator::Invalid;
-}
-
-ExtDate ExtDateEdit::date() const {
- return d->m_Date;
-}
-
-void ExtDateEdit::setDate( const ExtDate &date ) {
- d->m_Date = date;
- setValue( d->m_Date.jd() );
-}
-
-int ExtDateEdit::activeField() const {
- return d->ActiveField;
-}
-
-void ExtDateEdit::setActiveField( int i ) {
- d->ActiveField = i;
-}
-
-QString ExtDateEdit::textFromValue( int v ) const {
- return ExtDate( v ).toString( d->m_DateFormat );
-}
-
-int ExtDateEdit::valueFromText( const QString &text ) const {
- ExtDate date = ExtDate::fromString( text, d->m_DateFormat );
-
- if ( date.isValid() )
- return date.jd();
- else
- return INVALID_DAY;
-}
-
-//Warning: this function assumes that the lineEdit() contains
-//no prefix or suffix. I believe this assumption is always valid,
-//but want to be explicit about this.
-bool ExtDateEdit::focusNextPrevChild( bool next ) {
- if ( !focusWidget() ) return false;
-
- int NewField = d->ActiveField;
- int pos = lineEdit()->cursorPosition(); //assumes no prefix/suffix!
- int step = ( next ? 1 : -1 );
-
- QString sdf = simpleDateFormat();
- while ( NewField == d->ActiveField ) {
- pos += step;
-
- if ( pos >= sdf.length() || pos < 0 )
- return QSpinBox::focusNextPrevChild( next );
-
- QChar c = sdf.at(pos);
-
- if ( c == 'D' ) NewField = 0;
- if ( c == 'M' ) NewField = 1;
- if ( c == 'Y' ) NewField = 2;
-
-// //DEBUG
-// kDebug() << pos << " " << c << " " << NewField;
-
- }
-
- d->ActiveField = NewField;
- highlightActiveField();
- return true;
-}
-
-void ExtDateEdit::invokeKey( Qt::Key k ) {
- QKeyEvent e( QEvent::KeyPress, k, Qt::NoModifier );
- keyPressEvent( &e );
-}
-
-void ExtDateEdit::focusInEvent( QFocusEvent *e ) {
-// //DEBUG
-// kDebug() << "focusInEvent()";
-
- QSpinBox::focusInEvent(e);
- highlightActiveField();
-}
-
-class ExtDateTimeEdit::Private
-{
-public:
- Private(ExtDateTimeEdit *qq, const ExtDateTime& dt);
-
- // slots
- void emitDateTimeChanged();
-
- ExtDateTimeEdit *q;
- QTimeEdit *m_TimeEdit;
- ExtDateEdit *m_DateEdit;
-};
-
-ExtDateTimeEdit::ExtDateTimeEdit( const ExtDateTime &dt, QWidget *parent )
- : QFrame( parent ), d( new Private( this, dt ) )
-{
-}
-
-ExtDateTimeEdit::ExtDateTimeEdit( const ExtDate &date, const QTime &time, QWidget *parent )
- : QFrame( parent ), d( new Private( this, ExtDateTime( date, time ) ) )
-{
-}
-
-ExtDateTimeEdit::ExtDateTimeEdit( QWidget *parent )
- : QFrame( parent ), d( new Private( this, ExtDateTime::currentDateTime() ) )
-{
-}
-
-ExtDateTimeEdit::~ExtDateTimeEdit() {
- delete d;
-}
-
-ExtDateTimeEdit::Private::Private( ExtDateTimeEdit *qq, const ExtDateTime &dt )
- : q( qq )
-{
- QHBoxLayout *hlay = new QHBoxLayout( q );
- hlay->setMargin( 0 );
- m_DateEdit = new ExtDateEdit( dt.date(), q );
- m_TimeEdit = new QTimeEdit( dt.time(), q );
-
- hlay->addWidget( m_DateEdit );
- hlay->addWidget( m_TimeEdit );
-
- connect( m_DateEdit, SIGNAL( dateChanged( const ExtDate & ) ), q, SLOT( emitDateTimeChanged() ) );
- connect( m_TimeEdit, SIGNAL( timeChanged( const QTime & ) ), q, SLOT( emitDateTimeChanged() ) );
-}
-
-ExtDate ExtDateTimeEdit::date() const
-{
- return d->m_DateEdit->date();
-}
-
-void ExtDateTimeEdit::setDate( const ExtDate &date )
-{
- d->m_DateEdit->setDate( date );
-}
-
-QTime ExtDateTimeEdit::time() const
-{
- return d->m_TimeEdit->time();
-}
-
-void ExtDateTimeEdit::setTime( const QTime &t )
-{
- d->m_TimeEdit->setTime( t );
-}
-
-ExtDateTime ExtDateTimeEdit::dateTime() const
-{
- return ExtDateTime( date(), time() );
-}
-
-void ExtDateTimeEdit::setDateTime( const ExtDateTime &dt )
-{
- setDate( dt.date() );
- setTime( dt.time() );
-}
-
-void ExtDateTimeEdit::Private::emitDateTimeChanged()
-{
- emit q->dateTimeChanged( q->dateTime() );
-}
-
-edLineEdit::edLineEdit( ExtDateEdit *parent ) : QLineEdit( parent ) {
- edParent = parent;
-}
-
-void edLineEdit::mouseReleaseEvent( QMouseEvent * ) {
-// //DEBUG
-// kDebug() << "mousePressEvent()";
-
- //assumes no prefix/suffix!
- QString sdf = edParent->simpleDateFormat();
- int p = cursorPosition();
- if ( p >= sdf.length() ) p = sdf.length() - 1;
- QChar c = sdf.at( p );
- while ( c != 0 && c != 'D' && c != 'M' && c != 'Y' )
- c = edParent->simpleDateFormat().at( --p );
-
- if ( c == 'D' ) edParent->setActiveField( 0 );
- else if ( c == 'M' ) edParent->setActiveField( 1 );
- else if ( c == 'Y' ) edParent->setActiveField( 2 );
-
-// //DEBUG
-// kDebug() << "ActiveField = " << edParent->activeField();
-
- edParent->highlightActiveField();
-}
-
-void edLineEdit::keyPressEvent( QKeyEvent *e ) {
-// //DEBUG
-// kDebug() << "keyPressEvent()";
-
- switch ( e->key() ) {
- case Qt::Key_Up:
- edParent->stepBy( 1 );
- break;
- case Qt::Key_Down:
- edParent->stepBy( -1 );
- break;
- case Qt::Key_Left:
- edParent->invokeKey( Qt::Key_Backtab );
- break;
- case Qt::Key_Right:
- edParent->invokeKey( Qt::Key_Tab );
- break;
- default:
- e->ignore();
- break;
- }
-}
-
-#include "extdatetimeedit.moc"
+++ /dev/null
-/***************************************************************************
- extdatetimeedit.h - K Desktop Planetarium
- -------------------
- begin : Tue Aug 30 21:50:00 PST 2005
- copyright : (C) 2005 by Jason Harris
- email : kstars@30doradus.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. *
- * *
- ***************************************************************************/
-
-#ifndef EXTDATETIMEEDIT_H
-#define EXTDATETIMEEDIT_H
-
-#include <libkdeedu_extdate_export.h>
-
-/**
- *@class ExtDateEdit
- *@short provides a spinbox widget for entering an extended date.
- *
- *The date is shown using a slight modification of the user's
- *localized dateFormatShort, in which the day, month and year fields
- *are shown with some kind of delimiter ("/", "-", etc). The
- *modification is that two-digit years are disallowed, so if the
- *user's dateFormatShort uses a two-digit year, this will be changed
- *to show all the year's digits (but only for the purposes of this
- *widget, of course).
- *
- *The user can choose which field will be modified with the up/down
- *buttons or arrow keys by clicking on the desired field. The
- *currently-selected field is highlighted in the widget. The user
- *can also change fields using the left/right arrow keys.
- *
- *The user can also enter date strings directly, and the widget
- *will attempt to guide the user by advancing the cursor between
- *fields and disallowing out-of-range values.
- *
- *Internally, the ExtDate is represented as an integer Julian Day.
- *The range of allowable values is (arbitrarily) set at +/- 2e7,
- *corresponding approximately to years +/- 55,000.
- *
- *@see ExtDateTimeEdit
- *@author Jason Harris
- *@version 1.0
- */
-
-#include <QSpinBox>
-#include <QFrame>
-#include <QTime>
-#include "extdatetime.h"
-
-class EXTDATE_EXPORT ExtDateEdit : public QSpinBox {
- Q_OBJECT
-
- public:
-/**
- *@short Default constructor. Creates an ExtDateEdit displaying the
- *given date.
- *@p d the date to display (default is current system time)
- *@p parent pointer to the parent widget (default: 0)
- */
- explicit ExtDateEdit( const ExtDate &date = ExtDate::currentDate(), QWidget *parent = 0 );
-
-/**
- *@short Constructor. Creates an ExtDateEdit displaying the
- *given date.
- *
- *Differs from the above function only in the data type of its argument.
- *@p jd the date to display (given as an integer representing the Julian Day)
- *@p parent pointer to the parent widget (default: 0)
- */
- explicit ExtDateEdit( int jd, QWidget *parent = 0 );
-
-/**
- *@short Constructor for UI files (contains only a parent widget argument)
- */
- explicit ExtDateEdit( QWidget *parent );
-
-/**
- *@short Default destructor. Empty.
- */
- ~ExtDateEdit();
-
-/**
- *@short Modifies the display date by the given number of steps.
- *
- *Checks to see which date field (Day/Month/Year) is highlighted,
- *and modifies the highlighted value by the given number of steps.
- *@note Overloaded from QAbstractSpinBox.
- *@see activeField()
- *@p steps the number to add to the current day/month/year
- */
- void stepBy( int steps );
-
-/**
- *@short Ensures that the text is a valid ExtDate.
- *
- *@note Overloaded from QAbstractSpinBox; called internally by
- *the baseclass.
- *@p input reference to the text to be validated
- *(typically the text displayed in the spinbox)
- *@p pos the position in the string at which to begin checking
- *@return QValidator::Acceptable if the string is a valid ExtDate;
- *otherwise return QValidator::Invalid
- */
- QValidator::State validate( QString &input, int &pos ) const;
-
-/**
- *@return the internal ExtDate value
- *@see setDate()
- */
- ExtDate date() const;
-/**
- *@short set the internal ExtDate value, and display the new
- *date in the spinbox.
- *
- *@p date reference to the new ExtDate
- *@see date()
- */
- void setDate( const ExtDate &date );
-
-/**
- *@return the currently-active Date field (Day=0; Month=1; Year=2)
- *@see setActiveField()
- */
- int activeField() const;
-/**
- *@short set the currently-active Date field
- *@p i The field to be activated (Day=0; Month=1; Year=2)
- *@note This function does not change highlighting in the GUI;
- *to sync the highlighting with the value of ActiveField, use
- *highlightActiveField().
- *@see highlightActiveField()
- */
- void setActiveField( int i );
-
-/**
- *@short highlight the currently-active Date field in the spinbox
- */
- void highlightActiveField();
-
-/**
- *@short create a keyPressEvent, as if the given key had been pressed.
- *@p k the Qt key value for which a keyPressEvent is to be simulated
- *@see edLineEdit::keyPressEvent()
- *@note (why isn't this in edLineEdit?)
- */
- void invokeKey( Qt::Key k );
-
- Q_SIGNALS:
- void dateChanged( const ExtDate &d );
-
- protected:
-/**
- *@short convert the spinbox internal value (a Julian Day integer)
- *to a date string to be displayed in the spinbox
- *@p v the internal JD value to be converted.
- *@note Overloaded from QSpinBox. Called internally.
- *@see valueFromText()
- */
- QString textFromValue( int v ) const;
-
-/**
- *@short convert the string displayed in the spinbox to its
- *internal representation (a Julian Day integer)
- *@p text reference to the date string to be converted to a JD integer
- *@note Overloaded from QSpinBox. Called internally.
- *@see textFromValue()
- */
- int valueFromText( const QString &text ) const;
-
-/**
- *@short Highlight the active Date field (Day/Month/Year) when the
- *spinbox gains input focus.
- *@p e pointer to the QFocusEvent object
- *@note Overloaded from QSpinBox. Calls QSpinBox::focusInEvent(), and
- *highlights the active date field.
- *@see highlightActiveField()
- */
- void focusInEvent( QFocusEvent *e );
-
-/**
- *@short Advance the active date field forward or backward.
- *
- *Changes the "active date field" to the next or previous date field.
- *If already at the first or last field, then
- *QSpinBox::focusNextPrevChild() is called, which will move input
- *focus to the next/previous widget.
- *@note Overloaded from QWidget. Called internally when Tab/Shift+Tab
- *or Left/Right arrows are pressed.
- *@p next if true, advance to the next field or widget. Otherwise,
- *advance to the previous field or widget.
- */
- bool focusNextPrevChild(bool next);
-
- public:
-/**
- *@short Convert the KDE date format for internal use.
- *
- *The KDE date format string (e.g., "%Y-%m-%d" does not reflect the
- *number of characters in the date string. Specifically, while
- *we use a restricted subset of KDE formats that guarantees two-digit
- *Day and Month fields, the number of digits in the Year field depends
- *on the date being displayed. This function simply converts the date
- *format string to one that reflects the correct number of digits
- *(e.g., "YYYY-MM-DD").
- *
- *This function is used internally to properly highlight the active
- *field, and to process mouse and key events correctly.
- */
- QString simpleDateFormat() const;
-
- private:
- class Private;
- Private *const d;
-
- Q_PRIVATE_SLOT(d, void slotRefreshHighlight())
- Q_PRIVATE_SLOT(d, void slotEmitDateChanged())
-};
-
-/**
- *@class ExtDateTimeEdit
- *@short provides a pair of spinbox widgets, one to set the date,
- *one to set the time.
- *
- *@author Jason Harris
- *@version 1.0
- */
-class EXTDATE_EXPORT ExtDateTimeEdit : public QFrame {
- Q_OBJECT
-
- public:
-/**
- *@short Default Constructor. Displays the given Date and Time.
- *@p dt reference to an ExtDateTime whose date and time values are
- *to be displayed (defaults to the system's current date and time)
- *@p p pointer to the parent widget (default: 0)
- */
- explicit ExtDateTimeEdit( const ExtDateTime &dt = ExtDateTime::currentDateTime(), QWidget *parent = 0 );
-
-/**
- *@short Constructor. Displays the given Date and Time.
- *
- *This is essentially identical to the above function, differing only in
- *the type of its arguments.
- *@p d reference to an ExtDate which is to be displayed in the date box
- *@p t reference to a QTime which is to be displayed in the time box
- *@p p pointer to the parent widget (default: 0)
- */
- ExtDateTimeEdit( const ExtDate &date, const QTime &time, QWidget *p=0 );
-
-/**
- *@short Constructor for UI files (contains only a parent widget argument)
- */
- explicit ExtDateTimeEdit( QWidget *parent );
-
-/**
- *@short Default Destructor. Empty.
- */
- ~ExtDateTimeEdit();
-
-/**
- *@return the internal ExtDate value
- *@see setDate()
- */
- ExtDate date() const;
-/**
- *@short set the internal ExtDate value, and display the new
- *date in the date spinbox.
- *
- *@p d reference to the new ExtDate
- *@see date()
- */
- void setDate( const ExtDate &date );
-
-/**
- *@return the internal QTime value
- *@see setTime()
- */
- QTime time() const;
-/**
- *@short set the internal QTime value, and display the new
- *time in the time spinbox.
- *
- *@p t reference to the new QTime
- *@see time()
- */
- void setTime( const QTime &t );
-
-/**
- *@return the ExtDateTime value displayed in the date and time boxes
- *@see setDateTime()
- */
- ExtDateTime dateTime() const;
-/**
- *@short set the internal ExtDate and QTime values, and display the new
- *values in their respective spinboxes.
- *
- *@p dt reference to the new ExtDateTime
- *@see dateTime()
- */
- void setDateTime( const ExtDateTime &dt );
-
- Q_SIGNALS:
- void dateTimeChanged( const ExtDateTime &dt );
-
- private:
- class Private;
- Private *const d;
-
- Q_DISABLE_COPY( ExtDateTimeEdit )
-
- Q_PRIVATE_SLOT( d, void emitDateTimeChanged() )
-};
-
-#endif //EXTDATETIMEEDIT_H
+++ /dev/null
-/***************************************************************************
- copyright : (C) 2005 by Jason Harris
- email : kstars@30doradus.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. *
- * *
- ***************************************************************************/
-
-#ifndef EXTDATETIMEEDIT_P_H
-#define EXTDATETIMEEDIT_P_H
-
-#include <QLineEdit>
-
-/**
- *@class edLineEdit
- *@short A QLineEdit adapted for use by ExtDateEdit.
- *
- *This class simply provides custom keyboard and mouse event handlers
- *needed for the ExtDateEdit widget.
- *@author Jason Harris
- *@version 1.0
- */
-class edLineEdit : public QLineEdit {
- public:
-/**
- *@short Default constructor.
- *@p parent pointer to the parent widget; defaults to 0
- */
- explicit edLineEdit( ExtDateEdit *parent=0 );
-/**
- *@short Default destructor. Empty.
- */
- ~edLineEdit() {}
-
- protected:
-/**
- *@short Set the active date field based on where in the date
- *string the mouse was clicked.
- */
- void mouseReleaseEvent( QMouseEvent * );
-/**
- *@short Handle arrow-key press events.
- *
- *Up/Down arrows call ExtDateEdit::stepBy();
- *Left/Right arrows invoke a key press of Shift+Tab/Tab,
- *which automatically calls
- *ExtDateEdit::focusNextPrevChild()
- */
- void keyPressEvent( QKeyEvent *e );
-
- private:
- ExtDateEdit *edParent;
-};
-
-#endif //EXTDATETIMEEDIT_H
+++ /dev/null
-/* This file is part of the KDE libraries
- Copyright (C) 2001 Waldo Bastian (bastian@kde.org)
-
- Modified to use ExtDate instead of QDate. Modifications
- Copyright (C) 2004 Jason Harris (jharris@30doradus.org)
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License version 2 as published by the Free Software Foundation.
-
- 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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#include "extdatewidget.h"
-
-#include <KComboBox>
-#include <QHBoxLayout>
-#include <QSpinBox>
-
-#include <kdialog.h>
-
-#include "extcalendarsystemgregorian.h"
-
-class ExtDateWidgetSpinBox : public QSpinBox
-{
-public:
- ExtDateWidgetSpinBox(int min, int max, QWidget *parent)
- : QSpinBox(parent)
- {
- setMinimum(min);
- setMaximum(max);
- setSingleStep(1);
- setAlignment(Qt::AlignRight);
- }
-};
-
-class ExtDateWidget::ExtDateWidgetPrivate
-{
-public:
- ExtDateWidgetPrivate(ExtDateWidget *qq)
- : q( qq ), calendar( new ExtCalendarSystemGregorian() )
- {
- }
-
- ~ExtDateWidgetPrivate()
- {
- delete calendar;
- }
-
- // slots
- void dateChanged();
-
- ExtDateWidget *q;
- ExtDateWidgetSpinBox *m_day;
- KComboBox *m_month;
- ExtDateWidgetSpinBox *m_year;
- ExtDate m_dat;
- ExtCalendarSystemGregorian *calendar;
-};
-
-
-ExtDateWidget::ExtDateWidget( QWidget *parent )
- : QWidget( parent ), d(new ExtDateWidgetPrivate(this))
-{
- init(ExtDate::currentDate());
- setDate(ExtDate());
-}
-
-ExtDateWidget::ExtDateWidget( const ExtDate &date, QWidget *parent )
- : QWidget( parent ), d(new ExtDateWidgetPrivate(this))
-{
- init(date);
- setDate(date);
-}
-
-void ExtDateWidget::init(const ExtDate& date)
-{
- //KLocale *locale = KGlobal::locale();
- QHBoxLayout *layout = new QHBoxLayout(this);
- layout->setMargin(0);
- layout->setSpacing(KDialog::spacingHint());
- d->m_day = new ExtDateWidgetSpinBox(1, 1, this);
- layout->addWidget(d->m_day);
- d->m_month = new KComboBox(this);
- layout->addWidget(d->m_month);
- d->m_month->setEditable(false);
- for (int i = 1; ; ++i)
- {
- QString str = d->calendar->monthName(i,
- d->calendar->year(date));
- if (str.isNull()) break;
- d->m_month->addItem(str);
- }
-
- d->m_year = new ExtDateWidgetSpinBox(d->calendar->minValidYear(),
- d->calendar->maxValidYear(), this);
- layout->addWidget(d->m_year);
-
- connect(d->m_day, SIGNAL(valueChanged(int)), this, SLOT(dateChanged()));
- connect(d->m_month, SIGNAL(activated(int)), this, SLOT(dateChanged()));
- connect(d->m_year, SIGNAL(valueChanged(int)), this, SLOT(dateChanged()));
-}
-
-ExtDateWidget::~ExtDateWidget()
-{
- delete d;
-}
-
-void ExtDateWidget::setDate( const ExtDate &date )
-{
-// const KCalendarSystem * calendar = KGlobal::locale()->calendar();
-
- d->m_day->blockSignals(true);
- d->m_month->blockSignals(true);
- d->m_year->blockSignals(true);
-
- d->m_day->setMaximum(d->calendar->daysInMonth(date));
- d->m_day->setValue(d->calendar->day(date));
- d->m_month->setCurrentIndex(d->calendar->month(date)-1);
- d->m_year->setValue(d->calendar->year(date));
-
- d->m_day->blockSignals(false);
- d->m_month->blockSignals(false);
- d->m_year->blockSignals(false);
-
- d->m_dat = date;
- emit changed(d->m_dat);
-}
-
-ExtDate ExtDateWidget::date() const
-{
- return d->m_dat;
-}
-
-void ExtDateWidget::ExtDateWidgetPrivate::dateChanged()
-{
-// const KCalendarSystem * calendar = KGlobal::locale()->calendar();
-
- ExtDate date;
- int y,m,day;
-
- y = m_year->value();
- y = qMin(qMax(y, calendar->minValidYear()), calendar->maxValidYear());
-
- calendar->setYMD(date, y, 1, 1);
- m = m_month->currentIndex()+1;
- m = qMin(qMax(m,1), calendar->monthsInYear(date));
-
- calendar->setYMD(date, y, m, 1);
- day = m_day->value();
- day = qMin(qMax(day,1), calendar->daysInMonth(date));
-
- calendar->setYMD(date, y, m, day);
- q->setDate(date);
-}
-
-#include "extdatewidget.moc"
+++ /dev/null
-/* This file is part of the KDE libraries
- Copyright (C) 2001 Waldo Bastian (bastian@kde.org)
-
- Modified to use ExtDate instead of QDate. Modifications
- Copyright (C) 2004 Jason Harris (jharris@30doradus.org)
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License version 2 as published by the Free Software Foundation.
-
- 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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#ifndef EXTDATEWIDGET_H
-#define EXTDATEWIDGET_H
-
-#include <libkdeedu_extdate_export.h>
-
-#include <QWidget>
-
-#include "extdatetime.h"
-
-/**
-* This widget can be used to display or allow user selection of a date.
-*
-* @see ExtDatePicker
-*
-* @short A pushbutton to display or allow user selection of a date.
-* @version $Id$
-*/
-class EXTDATE_EXPORT ExtDateWidget : public QWidget
-{
- Q_OBJECT
-// Q_PROPERTY( ExtDate date READ date WRITE setDate )
-
-public:
- /**
- * Constructs a date selection widget, initialized to the current CPU date.
- */
- explicit ExtDateWidget( QWidget *parent=0 );
-
- /**
- * Constructs a date selection widget with the initial date set to @p date.
- */
- explicit ExtDateWidget( const ExtDate &date, QWidget *parent=0 );
-
- /**
- * Destructs the date selection widget.
- */
- virtual ~ExtDateWidget();
-
- /**
- * Returns the currently selected date.
- */
- ExtDate date() const;
-
- /**
- * Changes the selected date to @p date.
- */
- void setDate(const ExtDate &date);
-
-
-Q_SIGNALS:
- /**
- * Emitted whenever the date of the widget
- * is changed, either with setDate() or via user selection.
- */
- void changed(const ExtDate&);
-
-protected:
- void init(const ExtDate&);
-
-private:
- class ExtDateWidgetPrivate;
- ExtDateWidgetPrivate * const d;
-
- Q_PRIVATE_SLOT(d, void dateChanged())
-};
-
-#endif
-
+++ /dev/null
-/* This file is part of the KDE project
- Copyright (C) 2007 David Faure <faure@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., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-#ifndef LIBKDEEDU_EXTDATE_EXPORT_H
-#define LIBKDEEDU_EXTDATE_EXPORT_H
-
-/* needed for KDE_EXPORT and KDE_IMPORT macros */
-#include <kdemacros.h>
-
-#ifndef EXTDATE_EXPORT
-# if defined(MAKE_EXTDATE_LIB)
- /* We are building this library */
-# define EXTDATE_EXPORT KDE_EXPORT
-# else
- /* We are using this library */
-# define EXTDATE_EXPORT KDE_IMPORT
-# endif
-#endif
-
-# ifndef EXTDATE_EXPORT_DEPRECATED
-# define EXTDATE_EXPORT_DEPRECATED KDE_DEPRECATED EXTDATE_EXPORT
-# endif
-
-#endif
+++ /dev/null
-set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
-include_directories( ${CMAKE_SOURCE_DIR}/libkdeedu/extdate )
-
-
-########### next target ###############
-
-set(test_extdate_SRCS test_extdate.cc )
-
-
-kde4_add_executable(test_extdate TEST ${test_extdate_SRCS})
-
-target_link_libraries(test_extdate ${KDE4_KDECORE_LIBS} extdate )
-
-########### next target ###############
-
-set(test_extdatepicker_SRCS edpicker_widget.cpp edpicker_main.cpp )
-
-
-kde4_add_executable(test_extdatepicker TEST ${test_extdatepicker_SRCS})
-
-target_link_libraries(test_extdatepicker ${KDE4_KDECORE_LIBS} extdate )
-
-########### next target ###############
-
-set(test_extdatetimeedit_SRCS edtedit_widget.cpp edtedit_main.cpp )
-
-
-kde4_add_executable(test_extdatetimeedit TEST ${test_extdatetimeedit_SRCS})
-
-target_link_libraries(test_extdatetimeedit ${KDE4_KDECORE_LIBS} extdate )
-
-
+++ /dev/null
-#include "edpicker_widget.h"
-#include <kapplication.h>
-#include <kcmdlineargs.h>
-#include <kaboutdata.h>
-#include <klocale.h>
-
-static const char description[] = I18N_NOOP("ExtDatePicker test program");
-static const char notice[] = I18N_NOOP("Compares KDatePicker and ExtDatePicker");
-
-int main( int argc, char *argv[] )
-{
- KAboutData aboutData( "test_extdatepicker", 0, ki18n("Test ExtDatePicker"),
- "0.1", ki18n(description), KAboutData::License_GPL,
- ki18n("(c) 2004, Jason Harris"), ki18n(notice),
- "http://edu.kde.org/kstars");
- aboutData.addAuthor(ki18n("Jason Harris"), KLocalizedString(),
- "kstars@30doradus.org", "http://edu.kde.org/kstars");
-
- KCmdLineArgs::init( argc, argv, &aboutData );
-
- KApplication a;
- EDPicker *edp = new EDPicker(0);
- edp->show();
- QObject::connect(kapp, SIGNAL(lastWindowClosed()), kapp, SLOT(quit()));
- return a.exec();
-}
+++ /dev/null
-/***************************************************************************
- edpicker_widget.cpp - description
- -------------------
- begin : Sun Apr 11 2004
- copyright : (C) 2004 by Jason Harris
- email : kstars@30doradus.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. *
- * *
- ***************************************************************************/
-
-#include <QLabel>
-#include <QGridLayout>
-
-#include <kdatepicker.h>
-#include <kdatewidget.h>
-#include <klineedit.h>
-
-#include "../extdatepicker.h"
-#include "../extdatewidget.h"
-#include "edpicker_widget.h"
-
-EDPicker::EDPicker( QWidget *p=0 ) : KXmlGuiWindow( p ) {
- QWidget *w = new QWidget(this);
-
- glay = new QGridLayout(w);
-
- QLabel *kdpLabel = new QLabel( QString("KDatePicker"), w );
- QLabel *edpLabel = new QLabel( QString("ExtDatePicker"), w );
- kdp = new KDatePicker(w);
- edp = new ExtDatePicker(w);
- kdpEdit = new KLineEdit(w);
- kdpEdit->setReadOnly( true );
- edpEdit = new KLineEdit(w);
- edpEdit->setReadOnly( true );
-
- kdw = new KDateWidget( QDate::currentDate(), w );
- edw = new ExtDateWidget( ExtDate::currentDate(), w );
-
- glay->addWidget( kdpLabel, 0, 0 );
- glay->addWidget( edpLabel, 0, 1 );
- glay->addWidget( kdp, 1, 0 );
- glay->addWidget( edp, 1, 1 );
- glay->addWidget( kdpEdit, 2, 0 );
- glay->addWidget( edpEdit, 2, 1 );
- glay->addWidget( kdw, 3, 0 );
- glay->addWidget( edw, 3, 1 );
-
- setCentralWidget(w);
-
- connect( kdp, SIGNAL( dateChanged(QDate) ), this, SLOT( slotKDateChanged(QDate) ) );
- connect( edp, SIGNAL( dateChanged(const ExtDate&) ), this, SLOT( slotExtDateChanged(const ExtDate&) ) );
-}
-
-void EDPicker::slotKDateChanged(QDate d) {
- kdpEdit->setText( d.toString() );
-}
-
-void EDPicker::slotExtDateChanged(const ExtDate &d) {
- edpEdit->setText( d.toString() );
-}
-
-#include "edpicker_widget.moc"
+++ /dev/null
-/***************************************************************************
- edpicker_widget.h - description
- -------------------
- begin : Sun Apr 11 2004
- copyright : (C) 2004 by Jason Harris
- email : kstars@30doradus.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. *
- * *
- ***************************************************************************/
-
-#ifndef EDPICKER_WIDGET_H
-#define EDPICKER_WIDGET_H
-
-#include <kxmlguiwindow.h>
-
-class QDate;
-class QGridLayout;
-class KDatePicker;
-class KLineEdit;
-class KDateWidget;
-class ExtDate;
-class ExtDatePicker;
-class ExtDateWidget;
-
-class EDPicker : public KXmlGuiWindow {
- Q_OBJECT
- public:
- EDPicker( QWidget *parent );
- ~EDPicker() {}
-
- public slots:
- void slotKDateChanged(QDate);
- void slotExtDateChanged(const ExtDate&);
-
- private:
- QGridLayout *glay;
- KDatePicker *kdp;
- ExtDatePicker *edp;
- ExtDateWidget *edw;
- KDateWidget *kdw;
- KLineEdit *kdpEdit, *edpEdit;
-};
-
-#endif //ifndef EDPICKER_WIDGET_H
+++ /dev/null
-#include "edtedit_widget.h"
-#include <kapplication.h>
-#include <kcmdlineargs.h>
-#include <kaboutdata.h>
-#include <klocale.h>
-
-static const char description[] = I18N_NOOP("ExtDateTimeEdit test program");
-static const char notice[] = I18N_NOOP("Displays an ExtDateTimeEdit widget to test");
-
-int main( int argc, char *argv[] )
-{
- KAboutData aboutData( "test_extdatetimeedit", 0, ki18n("Test ExtDateTimeEdit"),
- "0.1", ki18n(description), KAboutData::License_GPL,
- ki18n("(c) 2005, Jason Harris"), ki18n(notice),
- "http://edu.kde.org/kstars");
- aboutData.addAuthor(ki18n("Jason Harris"), KLocalizedString(),
- "kstars@30doradus.org", "http://edu.kde.org/kstars");
-
- KCmdLineArgs::init( argc, argv, &aboutData );
-
- KApplication a;
- EDTEdit *edte = new EDTEdit(0);
- edte->show();
- QObject::connect(kapp, SIGNAL(lastWindowClosed()), kapp, SLOT(quit()));
- return a.exec();
-}
+++ /dev/null
-/***************************************************************************
- edtedit_widget.cpp - description
- -------------------
- begin : Sun Sept 4 2005
- copyright : (C) 2005 by Jason Harris
- email : kstars@30doradus.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. *
- * *
- ***************************************************************************/
-
-#include <QWidget>
-#include <QTimeEdit>
-#include <QVBoxLayout>
-#include <kdebug.h>
-
-#include "../extdatetime.h"
-#include "../extdatetimeedit.h"
-#include "edtedit_widget.h"
-
-EDTEdit::EDTEdit( QWidget *p=0 ) : KXmlGuiWindow( p ) {
- QWidget *w = new QWidget(this);
-
- vlay = new QVBoxLayout( w );
-
- ed = new ExtDateEdit( ExtDate::currentDate(), w );
- edt = new ExtDateTimeEdit( ExtDateTime::currentDateTime(), w );
-
- vlay->addWidget( ed );
- vlay->addWidget( edt );
-
- setCentralWidget(w);
-}
-
-EDTEdit::~EDTEdit() {
- //Output current date setting on exit
- kDebug() << "ExDateEdit: " << ed->date().toString();
- kDebug() << "ExDateTimeEdit: " << edt->date().toString();
-}
-
-#include "edtedit_widget.moc"
+++ /dev/null
-/***************************************************************************
- edtedit_widget.cpp - description
- -------------------
- begin : Sun Sept 4 2005
- copyright : (C) 2005 by Jason Harris
- email : kstars@30doradus.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. *
- * *
- ***************************************************************************/
-
-#ifndef EDTEDIT_WIDGET_H
-#define EDTEDIT_WIDGET_H
-
-#include <kxmlguiwindow.h>
-
-class QVBoxLayout;
-class ExtDate;
-class ExtDateEdit;
-class ExtDateTimeEdit;
-
-class EDTEdit : public KXmlGuiWindow {
- Q_OBJECT
- public:
- EDTEdit( QWidget *parent );
- ~EDTEdit();
-
-// public slots:
-
- private:
- QVBoxLayout *vlay;
- ExtDateEdit *ed;
- ExtDateTimeEdit *edt;
-};
-
-#endif //ifndef EDTEDIT_WIDGET_H
+++ /dev/null
-#include <stdlib.h>
-#include <iostream>
-
-#include "../extdatetime.h"
-
-
-void test1_unit(int a_year)
-{
- std::cout << a_year << " (QDate|ExtDate): " << ((QDate::isLeapYear(a_year)) ? "yes" : "no")
- <<"|"<< ((ExtDate::leapYear(a_year)) ? "yes" : "no") << std::endl;
-}
-
-void test1()
-{
- int a_set_of_years[] =
- {
- 1996,
- 1997,
- 1998,
- 2000,
- 1999,
- 2001,
- 1900,
- 1800,
- 1700,
- 1600,
- 2100,
- 2200,
- 2300,
- 0,
- -1,
- -4,
- -100,
- -200,
- -300,
- -400,
- -500
- };
- uint i;
- std::cout << "Checking Leap Years:\n" << std::endl;
- for (i = 0 ; i < sizeof(a_set_of_years)/sizeof(a_set_of_years[0]) ; i++)
- {
- test1_unit(a_set_of_years[i]);
- }
- std::cout << "--------------------" << std::endl;
-}
-
-void test2_unit(int y, int m, int d)
-{
- QDate q(y, m, d);
- ExtDate e(y, m, d);
- int q_week_number = q.dayOfWeek();
- int e_week_number = e.dayOfWeek();
- int q_day_of_year = q.dayOfYear();
- int e_day_of_year = e.dayOfYear();
- std::cout << "(" << y << ", " << m << ", " << d << ") :: "
- << q.toString("dd.MMM.yyyy").toLocal8Bit().data() << " : "
- << q.dayOfWeek() << " : " << q_week_number << " : " << q_day_of_year << " :: "
- << e.toString("%d.%b.%Y").toLocal8Bit().data() << " : "
- << e.dayOfWeek() << " : " << e_week_number << " : " << e_day_of_year << std::endl;
-}
-
-void test2()
-{
- int a_set_of_dates[][3] =
- {
- {0, 1, 1},
- {1, 1, 1},
- {2, 1, 1},
- {3, 1, 1},
- {4, 1, 1},
- {5, 1, 1},
- {99, 1, 1},
- {100, 1, 1},
- {100, 12, 31},
- {101, 1, 1},
- {102, 1, 1},
- {103, 1, 1},
- {104, 1, 1},
- {399, 1, 1},
- {400, 1, 1},
- {401, 1, 1},
- {402, 1, 1},
- {403, 1, 1},
- {404, 1, 1},
- {2003, 1, 1},
- {2003, 1, 2},
- {2003, 1, 3},
- {2003, 1, 4},
- {2003, 1, 5},
- {2003, 1, 6},
- {2003, 1, 7},
- {2003, 1, 8},
- {2003, 1, 9},
- {2003, 1, 10},
- {2003, 1, 11},
- {2003, 1, 12},
- {2003, 1, 13},
- {2003, 1, 14},
- {2003, 1, 15},
- {2003, 1, 16},
- {2003, 1, 17},
- {2003, 1, 18},
- {2003, 12, 19},
- {2003, 12, 20},
- {2003, 12, 21},
- {2003, 12, 22},
- {2003, 12, 23},
- {2003, 12, 24},
- {2003, 12, 25},
- {2003, 12, 26},
- {2003, 12, 27},
- {2003, 12, 28},
- {2003, 12, 29},
- {2003, 12, 30},
- {2003, 12, 31},
- {2004, 1, 1},
- {2003, 11, 2}
- };
- uint i;
- std::cout << "(y, m, d) :: QDate : Q.dayOfWeek() : Q.weekNumber() : Q.dayOfYear() :: ExtDate : E.dayOfWeek() : E.weekNumber() : E.dayOfYear()\n" << std::endl;
-
- for (i = 0 ; i < sizeof(a_set_of_dates)/sizeof(a_set_of_dates[0]) ; i++)
- {
- test2_unit(a_set_of_dates[i][0], a_set_of_dates[i][1], a_set_of_dates[i][2]);
- }
- std::cout << "--------------------" << std::endl;
-}
-
-void test3_unit(int y, int m, int d, int dm)
-{
- QDate q(y, m, d);
- ExtDate e(y, m, d);
- QDate q2 = q.addMonths(dm);
- ExtDate e2 = e.addMonths(dm);
- std::cout << e.toString("%d.%b.%Y").toLocal8Bit().data() << " + " << dm
- << " months :: ExtDate : " << e2.toString("%d.%b.%Y").toLocal8Bit().data()
- << " QDate : " << q2.toString("dd.MMM.yyyy").toLocal8Bit().data() << std::endl;
-}
-
-void test3()
-{
- int a_set_of_dates_delta[][4] =
- {
- {2003, 11, 5, 0},
- {2003, 11, 5, 1},
- {2003, 11, 5, -1},
- {2003, 11, 5, 2},
- {2003, 11, 5, 3}
- };
- uint i;
- std::cout << "Adding Months:\n" << std::endl;
- for (i = 0 ; i < sizeof(a_set_of_dates_delta)/sizeof(a_set_of_dates_delta[0]) ; i++)
- {
- test3_unit(a_set_of_dates_delta[i][0], a_set_of_dates_delta[i][1], a_set_of_dates_delta[i][2], a_set_of_dates_delta[i][3]);
- }
- std::cout << "--------------------" << std::endl;
-}
-void test4_unit(int y, int m, int d, int dy)
-{
- QDate q(y, m, d);
- ExtDate e(y, m, d);
- QDate q2 = q.addYears(dy);
- ExtDate e2 = e.addYears(dy);
- std::cout << e.toString("%d.%m.%Y").toLocal8Bit().data() << " + " << dy << " years :: ExtDate : "
- << e2.toString().toLocal8Bit().data() << " QDate : "
- << q2.toString().toLocal8Bit().data() << std::endl;
-}
-
-void test4()
-{
- int a_set_of_dates_delta[][4] =
- {
- {-1, 11, 5, 0},
- {-1, 11, 5, 1},
- {-1, 11, 5, 2},
- {2003, 11, 5, 1},
- {2003, 11, 5, -1},
- {2003, 11, 5, 2},
- {2003, 11, 5, 3}
- };
- uint i;
- std::cout << "Adding years:\n" << std::endl;
- for (i = 0 ; i < sizeof(a_set_of_dates_delta)/sizeof(a_set_of_dates_delta[0]) ; i++)
- {
- test4_unit(a_set_of_dates_delta[i][0], a_set_of_dates_delta[i][1], a_set_of_dates_delta[i][2], a_set_of_dates_delta[i][3]);
- }
- std::cout << "--------------------" << std::endl;
-}
-
-void test5_unit(int y, int m, int d, const char *qformat, const char *eformat)
-{
- QDate q(y, m, d);
- ExtDate e(y, m, d);
-
- if ( QString(qformat) == "<default>" )
- std::cout << eformat << " : " << e.toString().toLocal8Bit().data() << " :: "
- << qformat << " : " << q.toString().toLocal8Bit().data() << std::endl;
- else
- std::cout << eformat << " : " << e.toString(eformat).toLocal8Bit().data() << " :: "
- << qformat << " : " << q.toString(qformat).toLocal8Bit().data() << std::endl;
-}
-
-void test5()
-{
- const char *q_set_of_formats[7] =
- {
- "d.M.yy",
- "dd.MM.yy",
- "ddd.MMM.yy",
- "ddd dd.MMM.yy",
- "dddd.MMMM.yy",
- ">dd.M.yyyy<",
- "<default>"
- };
- const char *e_set_of_formats[7] =
- {
- "%e.%n.%y",
- "%d.%m.%y",
- "%d.%b.%y",
- "%a %d.%b.%y",
- "%A.%B.%y",
- ">%d.%n.%Y<",
- "<default>"
- };
-
- uint i;
- std::cout << "Date.toString(\"...\")" << std::endl;
- std::cout << "Ext Format : ExtDate :: Q Format : QDate\n" << std::endl;
-
- for (i = 0 ; i < sizeof(q_set_of_formats)/sizeof(q_set_of_formats[0]) ; i++)
- {
- test5_unit(2003, 11, 5, q_set_of_formats[i], e_set_of_formats[i]);
- }
- std::cout << "--------------------" << std::endl;
-}
-
-void test6_unit(int y, int m, int d)
-{
- std::cout << d << "/" << m << "/" << y << " :: "
- << ( ExtDate::isValid(y, m, d) ? "TRUE" : "FALSE" ) << " : "
- << ( QDate::isValid(y, m, d) ? "TRUE" : "FALSE" ) << std::endl;
-}
-
-void test6()
-{
- int a_set_of_dates[][3] =
- {
- {-1, 11, 5},
- {-1, 11, 5},
- {-1, 11, 5},
- {2003, 11, 5},
- {2003, -1, 5},
- {2003, 0, 5},
- {2003, 12, 5},
- {2003, 13, 5},
- {2003, 11, -2},
- {2003, 11, 0},
- {2003, 11, 40},
- {2004, 2, 28},
- {2004, 2, 29},
- {2004, 2, 30},
- {2003, 2, 28},
- {2003, 2, 29},
- {2003, 2, 30}
- };
- uint i;
- std::cout << "Date.isValid()" << std::endl;
- std::cout << "d/m/y :: ExtDate.isValid() : QDate.isValid()\n" << std::endl;
-
- for (i = 0 ; i < sizeof(a_set_of_dates)/sizeof(a_set_of_dates[0]) ; i++)
- {
- test6_unit(a_set_of_dates[i][0], a_set_of_dates[i][1], a_set_of_dates[i][2]);
- }
- std::cout << "--------------------" << std::endl;
-}
-
-void test7()
-{
- std::cout << "Express the current date:\n" << std::endl;
- QDate q = QDate::currentDate();
- ExtDate e = ExtDate::currentDate(Qt::TimeSpec(Qt::LocalTime));
- std::cout << "Qt::LocalTime :: ExtDate : " << e.toString().toLocal8Bit().data() << " QDate : "
- << q.toString().toLocal8Bit().data() << std::endl;
- q = QDateTime::currentDateTime().toUTC().date();
- e = ExtDate::currentDate(Qt::UTC);
- std::cout << "Qt::UTC :: ExtDate : " << e.toString().toLocal8Bit().data() << " QDate : "
- << q.toString().toLocal8Bit().data() << std::endl;
- q = QDate::currentDate();
- e = ExtDate::currentDate();
- std::cout << "<default> :: ExtDate : " << e.toString().toLocal8Bit().data() << " QDate : "
- << q.toString().toLocal8Bit().data() << std::endl;
- std::cout << "--------------------" << std::endl;
-}
-
-void test8() {
- std::cout << "Set dates using days 1-32 for Jan and Feb (some will be invalid): \n" << std::endl;
- std::cout << " QDate : ExtDate" << std::endl;
-
- for ( uint m=1; m<=2; ++m ) {
- for ( uint d=1; d<=32; ++d ) {
-
- QDate test1( 2004, m, d );
- ExtDate test2( 2004, m, d );
- std::cout << test1.toString( "ddd dd.MMM.yy" ).toLocal8Bit().data() << " : "
- << test2.toString( "%a %d.%b.%y" ).toLocal8Bit().data() << std::endl;
- }
- }
-
- std::cout << "--------------------" << std::endl;
-}
-
-void test9() {
- std::cout << "QDateTime : ExtDateTime: \n" << std::endl;
- QDateTime q = QDateTime::currentDateTime();
- ExtDateTime e = ExtDateTime::currentDateTime();
-
- std::cout << q.toString().toLocal8Bit().data() << " : " << e.toString().toLocal8Bit().data() << std::endl;
- std::cout << "--------------------" << std::endl;
-}
-
-void test10() {
- ExtDate d1 = ExtDate::fromString("20050829", Qt::ISODate);
- ExtDate d2 = ExtDate::fromString("30 Aug 2005", Qt::TextDate);
- ExtDate d3 = ExtDate::fromString("Aug 31, 2005", "%b %d, %Y");
- ExtDate d4 = ExtDate::fromString("2005foo09bar01", "%Yfoo%mbar%d");
- std::cout << "ExtDate::fromString(\"20050829\", Qt::ISODate): "
- << d1.toString().toLocal8Bit().data() << std::endl;
- std::cout << "ExtDate::fromString(\"30 Aug 2005\", Qt::TextDate): "
- << d2.toString().toLocal8Bit().data() << std::endl;
- std::cout << "ExtDate::fromString(\"Aug 31, 2005\", \"%b %d, %Y\"): "
- << d3.toString().toLocal8Bit().data() << std::endl;
- std::cout << "ExtDate::fromString(\"2005foo09bar01\", \"%Yfoo%mbar%d\"): "
- << d4.toString().toLocal8Bit().data() << std::endl;
-
- std::cout << "--------------------" << std::endl;
-}
-
-int main(int argc, char *argv[])
-{
- // shut up gcc
- (void)argc;
- (void)argv;
-
- test1();
- test2();
- test3();
- test4();
- test5();
- test6();
- test7();
- test8();
- test9();
- test10();
- exit(0);
-}
-
PluginName=KDEEduWidgets
Includes=kcomponentdata.h
Init=new KComponentData("kdeeduwidgets");
-
-[ExtDateEdit]
-ToolTip=spinbox-based extended date editor (KDE-Edu)
-WhatsThis=Allows the user to specify an extended date
-Group=Date and Time (KDE-Edu)
-ConstructorArgs=(parent)
-IncludeFile=extdatetimeedit.h
-
-[ExtDateTimeEdit]
-ToolTip=spinbox-based extended date/time editor (KDE-Edu)
-WhatsThis=Allows the user to specify an extended date and a time
-Group=Date and Time (KDE-Edu)
-ConstructorArgs=(parent)
-
-[ExtDatePicker]
-ToolTip=calendar-based extended date selector (KDE-Edu)
-WhatsThis=Allows the user to specify an extended date using a calendar
-Group=Date and Time (KDE-Edu)
-ConstructorArgs=(parent)