From 2cbcca0db1343e1c40e52af729a5eb34ca8a7e37 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Thu, 27 Jun 2024 21:53:17 +0900 Subject: Rename date and time nt* related files to equivalent tq* Signed-off-by: Michele Calgaro --- src/canvas/tqcanvas.cpp | 2 +- src/dialogs/qfiledialog.cpp | 2 +- src/dialogs/qprogressdialog.cpp | 4 +- src/kernel/ntqasyncio.h | 2 +- src/kernel/ntqnamespace.h | 4 +- src/kernel/ntqt.h | 6 +- src/kernel/ntqtimer.h | 91 - src/kernel/ntqurlinfo.h | 2 +- src/kernel/qapplication_x11.cpp | 2 +- src/kernel/qclipboard_x11.cpp | 2 +- src/kernel/qdnd_x11.cpp | 2 +- src/kernel/qeventloop.cpp | 2 +- src/kernel/qfontdatabase_x11.cpp | 2 +- src/kernel/qmngio.cpp | 2 +- src/kernel/qmovie.cpp | 2 +- src/kernel/qnetworkprotocol.cpp | 2 +- src/kernel/qprocess_unix.cpp | 2 +- src/kernel/qpsprinter.cpp | 4 +- src/kernel/qt_kernel.pri | 4 +- src/kernel/qt_pch.h | 4 +- src/kernel/qtimer.cpp | 338 ---- src/kernel/qvariant.cpp | 2 +- src/kernel/tqtimer.cpp | 338 ++++ src/kernel/tqtimer.h | 91 + src/kernel/tqwidget_x11.cpp | 2 +- src/moc/moc.pro | 2 +- src/moc/moc.y | 2 +- src/moc/moc_yacc.cpp | 2 +- src/network/qdns.cpp | 4 +- src/network/qftp.cpp | 2 +- src/network/qhttp.cpp | 2 +- src/network/qsocket.cpp | 2 +- src/sql/drivers/cache/tqsqlcachedresult.cpp | 2 +- src/sql/drivers/ibase/tqsql_ibase.cpp | 2 +- src/sql/drivers/mysql/tqsql_mysql.cpp | 2 +- src/sql/drivers/odbc/tqsql_odbc.cpp | 2 +- src/sql/drivers/psql/tqsql_psql.cpp | 2 +- src/sql/drivers/sqlite/tqsql_sqlite.cpp | 2 +- src/sql/drivers/sqlite3/tqsql_sqlite3.cpp | 2 +- src/sql/tqdatatable.cpp | 4 +- src/sql/tqeditorfactory.cpp | 2 +- src/sql/tqsqlcursor.cpp | 2 +- src/sql/tqsqldriver.cpp | 2 +- src/sql/tqsqleditorfactory.cpp | 2 +- src/table/qtable.cpp | 2 +- src/tools/ntqdatetime.h | 254 --- src/tools/ntqfileinfo.h | 2 +- src/tools/ntqsettings.h | 2 +- src/tools/qcomlibrary.cpp | 2 +- src/tools/qdatetime.cpp | 2600 ------------------------ src/tools/qfeatures.txt | 4 +- src/tools/qfileinfo.cpp | 2 +- src/tools/qfileinfo_unix.cpp | 2 +- src/tools/qglobal.cpp | 2 +- src/tools/qt_tools.pri | 4 +- src/tools/quuid.cpp | 2 +- src/tools/tqdatetime.cpp | 2600 ++++++++++++++++++++++++ src/tools/tqdatetime.h | 254 +++ src/widgets/ntqdatetimeedit.h | 293 --- src/widgets/qbutton.cpp | 2 +- src/widgets/qcombobox.cpp | 2 +- src/widgets/qdatetimeedit.cpp | 2842 --------------------------- src/widgets/qdockwindow.cpp | 2 +- src/widgets/qeffects.cpp | 4 +- src/widgets/qlineedit.cpp | 2 +- src/widgets/qlistbox.cpp | 2 +- src/widgets/qlistview.cpp | 4 +- src/widgets/qmainwindow.cpp | 4 +- src/widgets/qmenubar.cpp | 2 +- src/widgets/qmultilineedit.cpp | 2 +- src/widgets/qpopupmenu.cpp | 6 +- src/widgets/qscrollbar.cpp | 2 +- src/widgets/qscrollview.cpp | 2 +- src/widgets/qslider.cpp | 2 +- src/widgets/qspinwidget.cpp | 2 +- src/widgets/qstatusbar.cpp | 2 +- src/widgets/qsyntaxhighlighter.cpp | 2 +- src/widgets/qt_widgets.pri | 4 +- src/widgets/qtitlebar.cpp | 4 +- src/widgets/qtoolbar.cpp | 2 +- src/widgets/qtoolbox.cpp | 2 +- src/widgets/qtoolbutton.cpp | 2 +- src/widgets/qtooltip.cpp | 2 +- src/widgets/qwhatsthis.cpp | 2 +- src/widgets/tqdatetimeedit.cpp | 2842 +++++++++++++++++++++++++++ src/widgets/tqdatetimeedit.h | 293 +++ src/widgets/tqiconview.cpp | 2 +- src/widgets/tqtextbrowser.cpp | 2 +- src/widgets/tqtextedit.cpp | 2 +- src/workspace/qworkspace.cpp | 4 +- 90 files changed, 6515 insertions(+), 6515 deletions(-) delete mode 100644 src/kernel/ntqtimer.h delete mode 100644 src/kernel/qtimer.cpp create mode 100644 src/kernel/tqtimer.cpp create mode 100644 src/kernel/tqtimer.h delete mode 100644 src/tools/ntqdatetime.h delete mode 100644 src/tools/qdatetime.cpp create mode 100644 src/tools/tqdatetime.cpp create mode 100644 src/tools/tqdatetime.h delete mode 100644 src/widgets/ntqdatetimeedit.h delete mode 100644 src/widgets/qdatetimeedit.cpp create mode 100644 src/widgets/tqdatetimeedit.cpp create mode 100644 src/widgets/tqdatetimeedit.h (limited to 'src') diff --git a/src/canvas/tqcanvas.cpp b/src/canvas/tqcanvas.cpp index aa38c2055..8249f454a 100644 --- a/src/canvas/tqcanvas.cpp +++ b/src/canvas/tqcanvas.cpp @@ -46,7 +46,7 @@ #include "tqptrdict.h" #include "ntqpainter.h" #include "ntqpolygonscanner.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqtl.h" #include diff --git a/src/dialogs/qfiledialog.cpp b/src/dialogs/qfiledialog.cpp index 79fe33346..7dfc1fb2a 100644 --- a/src/dialogs/qfiledialog.cpp +++ b/src/dialogs/qfiledialog.cpp @@ -88,7 +88,7 @@ #include "ntqsplitter.h" #include "tqstrlist.h" #include "tqstyle.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqtoolbutton.h" #include "ntqtooltip.h" #include "ntqvbox.h" diff --git a/src/dialogs/qprogressdialog.cpp b/src/dialogs/qprogressdialog.cpp index 0424a9ec6..1202d4b76 100644 --- a/src/dialogs/qprogressdialog.cpp +++ b/src/dialogs/qprogressdialog.cpp @@ -45,12 +45,12 @@ #include "ntqaccel.h" #include "ntqpainter.h" #include "ntqdrawutil.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqapplication.h" #include "tqstyle.h" #include "ntqpushbutton.h" #include "ntqcursor.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include // If the operation is expected to take this long (as predicted by diff --git a/src/kernel/ntqasyncio.h b/src/kernel/ntqasyncio.h index 19fe284b0..b2c88ce4d 100644 --- a/src/kernel/ntqasyncio.h +++ b/src/kernel/ntqasyncio.h @@ -44,7 +44,7 @@ #ifndef QT_H #include "tqobject.h" #include "ntqsignal.h" -#include "ntqtimer.h" +#include "tqtimer.h" #endif // QT_H #ifndef TQT_NO_ASYNC_IO diff --git a/src/kernel/ntqnamespace.h b/src/kernel/ntqnamespace.h index c0c34533a..587b8720a 100644 --- a/src/kernel/ntqnamespace.h +++ b/src/kernel/ntqnamespace.h @@ -948,14 +948,14 @@ public: // compatibility typedef Dock ToolBarDock; - // documented in qdatetime.cpp + // documented in tqdatetime.cpp enum DateFormat { TextDate, // default TQt ISODate, // ISO 8601 LocalDate // locale dependent }; - // documented in qdatetime.cpp + // documented in tqdatetime.cpp enum TimeSpec { LocalTime, UTC diff --git a/src/kernel/ntqt.h b/src/kernel/ntqt.h index 5afa96e1d..4dee12662 100644 --- a/src/kernel/ntqt.h +++ b/src/kernel/ntqt.h @@ -48,7 +48,7 @@ #include "tqstrlist.h" #include "tqvaluelist.h" #include "tqmap.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqmime.h" #include "ntqasciidict.h" #include "ntqpaintdevice.h" @@ -95,7 +95,7 @@ #include #include "ntqrangecontrol.h" #include "ntqbuttongroup.h" -#include +#include #include "ntqgvector.h" #include "ntqhbox.h" #include @@ -185,7 +185,7 @@ #include #include #include -#include "ntqtimer.h" +#include "tqtimer.h" #include #include #include diff --git a/src/kernel/ntqtimer.h b/src/kernel/ntqtimer.h deleted file mode 100644 index 40aae8724..000000000 --- a/src/kernel/ntqtimer.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Definition of TQTimer class -** -** Created : 931111 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQTIMER_H -#define TQTIMER_H - -#ifndef QT_H -#include "tqobject.h" -#endif // QT_H - - -class TQ_EXPORT TQTimer : public TQObject -{ - TQ_OBJECT -public: - TQTimer( TQObject *parent=0, const char *name=0 ); - ~TQTimer(); - - bool isActive() const; - - int start( int msec, bool sshot = FALSE ); - void changeInterval( int msec ); - void stop(); - - static void singleShot( int msec, TQObject *receiver, const char *member ); - - int timerId() const { return id; } - -signals: - void timeout(); - -protected: - bool event( TQEvent * ); - -private: - int id; - uint single : 1; - uint nulltimer : 1; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQTimer( const TQTimer & ); - TQTimer &operator=( const TQTimer & ); -#endif -}; - - -inline bool TQTimer::isActive() const -{ - return id >= 0; -} - - -#endif // TQTIMER_H diff --git a/src/kernel/ntqurlinfo.h b/src/kernel/ntqurlinfo.h index b9fa36eae..8c0269f84 100644 --- a/src/kernel/ntqurlinfo.h +++ b/src/kernel/ntqurlinfo.h @@ -42,7 +42,7 @@ #define TQURLINFO_H #ifndef QT_H -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "tqstring.h" #endif // QT_H diff --git a/src/kernel/qapplication_x11.cpp b/src/kernel/qapplication_x11.cpp index 0a1d62cf8..33fa0ceca 100644 --- a/src/kernel/qapplication_x11.cpp +++ b/src/kernel/qapplication_x11.cpp @@ -73,7 +73,7 @@ #include "ntqbitarray.h" #include "ntqpainter.h" #include "ntqpixmapcache.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "tqtextcodec.h" #include "ntqdatastream.h" #include "ntqbuffer.h" diff --git a/src/kernel/qclipboard_x11.cpp b/src/kernel/qclipboard_x11.cpp index 7776cf606..dbe3a7f78 100644 --- a/src/kernel/qclipboard_x11.cpp +++ b/src/kernel/qclipboard_x11.cpp @@ -67,7 +67,7 @@ #include "ntqapplication.h" #include "ntqeventloop.h" #include "ntqbitmap.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqdragobject.h" #include "ntqbuffer.h" #include "tqtextcodec.h" diff --git a/src/kernel/qdnd_x11.cpp b/src/kernel/qdnd_x11.cpp index 859a3c1a6..7e2a1fd04 100644 --- a/src/kernel/qdnd_x11.cpp +++ b/src/kernel/qdnd_x11.cpp @@ -46,7 +46,7 @@ #include "tqwidget.h" #include "ntqintdict.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqdict.h" #include "ntqguardedptr.h" #include "ntqdragobject.h" diff --git a/src/kernel/qeventloop.cpp b/src/kernel/qeventloop.cpp index 402894f2a..e08a1ee1c 100644 --- a/src/kernel/qeventloop.cpp +++ b/src/kernel/qeventloop.cpp @@ -39,7 +39,7 @@ #include "qeventloop_p.h" // includes qplatformdefs.h #include "ntqeventloop.h" #include "ntqapplication.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #ifdef TQT_THREAD_SUPPORT # include "ntqthread.h" diff --git a/src/kernel/qfontdatabase_x11.cpp b/src/kernel/qfontdatabase_x11.cpp index c449b8961..d1045740d 100644 --- a/src/kernel/qfontdatabase_x11.cpp +++ b/src/kernel/qfontdatabase_x11.cpp @@ -40,7 +40,7 @@ #include -#include +#include #include #include "qt_x11_p.h" diff --git a/src/kernel/qmngio.cpp b/src/kernel/qmngio.cpp index deb0225c3..5c46cbd74 100644 --- a/src/kernel/qmngio.cpp +++ b/src/kernel/qmngio.cpp @@ -38,7 +38,7 @@ ** **********************************************************************/ -#include "ntqdatetime.h" +#include "tqdatetime.h" #ifndef TQT_NO_IMAGEIO_MNG diff --git a/src/kernel/qmovie.cpp b/src/kernel/qmovie.cpp index d52f662a7..7be719725 100644 --- a/src/kernel/qmovie.cpp +++ b/src/kernel/qmovie.cpp @@ -40,7 +40,7 @@ // #define QT_SAVE_MOVIE_HACK -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqpainter.h" #include "tqptrlist.h" #include "ntqbitmap.h" diff --git a/src/kernel/qnetworkprotocol.cpp b/src/kernel/qnetworkprotocol.cpp index 8d7ff8f1a..718a7ac11 100644 --- a/src/kernel/qnetworkprotocol.cpp +++ b/src/kernel/qnetworkprotocol.cpp @@ -44,7 +44,7 @@ #include "ntqlocalfs.h" #include "ntqurloperator.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "tqmap.h" #include "tqptrqueue.h" diff --git a/src/kernel/qprocess_unix.cpp b/src/kernel/qprocess_unix.cpp index 87f76848d..0e5a2299a 100644 --- a/src/kernel/qprocess_unix.cpp +++ b/src/kernel/qprocess_unix.cpp @@ -53,7 +53,7 @@ #include "tqptrqueue.h" #include "tqptrlist.h" #include "ntqsocketnotifier.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqcleanuphandler.h" #include "ntqregexp.h" #include "private/qinternal_p.h" diff --git a/src/kernel/qpsprinter.cpp b/src/kernel/qpsprinter.cpp index 943cefff4..c9ce2ea7d 100644 --- a/src/kernel/qpsprinter.cpp +++ b/src/kernel/qpsprinter.cpp @@ -60,7 +60,7 @@ #include "ntqapplication.h" #include "ntqpaintdevicemetrics.h" #include "tqimage.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "tqstring.h" #include "ntqdict.h" #include "ntqmemarray.h" @@ -5351,7 +5351,7 @@ static void emitBits( char *out, int & byte, int & bit, //#define DEBUG_COMPRESS #ifdef DEBUG_COMPRESS -#include +#include #endif static TQByteArray compress( const TQImage & image, bool gray ) { diff --git a/src/kernel/qt_kernel.pri b/src/kernel/qt_kernel.pri index c812e5843..446019b6e 100644 --- a/src/kernel/qt_kernel.pri +++ b/src/kernel/qt_kernel.pri @@ -78,7 +78,7 @@ kernel { $$KERNEL_H/tqstyle.h \ $$KERNEL_H/tqstylesheet.h \ $$KERNEL_H/ntqthread.h \ - $$KERNEL_H/ntqtimer.h \ + $$KERNEL_H/tqtimer.h \ $$KERNEL_H/ntqurl.h \ $$KERNEL_H/ntqlocalfs.h \ $$KERNEL_H/ntqurloperator.h \ @@ -249,7 +249,7 @@ kernel { $$KERNEL_CPP/qsound.cpp \ $$KERNEL_CPP/tqstylesheet.cpp \ $$KERNEL_CPP/qthread.cpp \ - $$KERNEL_CPP/qtimer.cpp \ + $$KERNEL_CPP/tqtimer.cpp \ $$KERNEL_CPP/qurl.cpp \ $$KERNEL_CPP/qlocalfs.cpp \ $$KERNEL_CPP/qurloperator.cpp \ diff --git a/src/kernel/qt_pch.h b/src/kernel/qt_pch.h index a4655ff25..aff826dc0 100644 --- a/src/kernel/qt_pch.h +++ b/src/kernel/qt_pch.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include // All moc genereated code has this include @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/kernel/qtimer.cpp b/src/kernel/qtimer.cpp deleted file mode 100644 index ca2dddb9e..000000000 --- a/src/kernel/qtimer.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQTimer class -** -** Created : 931111 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqtimer.h" -#include "ntqsignal.h" -#include "tqobjectlist.h" - -/*! - \class TQTimer ntqtimer.h - \brief The TQTimer class provides timer signals and single-shot timers. - - \ingroup time - \ingroup events - \mainclass - - It uses \link TQTimerEvent timer events\endlink internally to - provide a more versatile timer. TQTimer is very easy to use: - create a TQTimer, call start() to start it and connect its - timeout() to the appropriate slots. When the time is up it will - emit the timeout() signal. - - Note that a TQTimer object is destroyed automatically when its - parent object is destroyed. - - Example: - \code - TQTimer *timer = new TQTimer( myObject ); - connect( timer, TQ_SIGNAL(timeout()), myObject, TQ_SLOT(timerDone()) ); - timer->start( 2000, TRUE ); // 2 seconds single-shot timer - \endcode - - You can also use the static singleShot() function to create a - single shot timer. - - As a special case, a TQTimer with timeout 0 times out as soon as - all the events in the window system's event queue have been - processed. - - This can be used to do heavy work while providing a snappy - user interface: - \code - TQTimer *t = new TQTimer( myObject ); - connect( t, TQ_SIGNAL(timeout()), TQ_SLOT(processOneThing()) ); - t->start( 0, FALSE ); - \endcode - - myObject->processOneThing() will be called repeatedly and should - return quickly (typically after processing one data item) so that - TQt can deliver events to widgets and stop the timer as soon as it - has done all its work. This is the traditional way of - implementing heavy work in GUI applications; multi-threading is - now becoming available on more and more platforms, and we expect - that null events will eventually be replaced by threading. - - Note that TQTimer's accuracy depends on the underlying operating - system and hardware. Most platforms support an accuracy of 20ms; - some provide more. If TQt is unable to deliver the requested - number of timer clicks, it will silently discard some. - - An alternative to using TQTimer is to call TQObject::startTimer() - for your object and reimplement the TQObject::timerEvent() event - handler in your class (which must, of course, inherit TQObject). - The disadvantage is that timerEvent() does not support such - high-level features as single-shot timers or signals. - - Some operating systems limit the number of timers that may be - used; TQt tries to work around these limitations. -*/ - - -static const int INV_TIMER = -1; // invalid timer id - - -/*! - Constructs a timer called \a name, with the parent \a parent. - - Note that the parent object's destructor will destroy this timer - object. -*/ - -TQTimer::TQTimer( TQObject *parent, const char *name ) - : TQObject( parent, name ), id(INV_TIMER), single(0), nulltimer(0) -{ -} - -/*! - Destroys the timer. -*/ - -TQTimer::~TQTimer() -{ - if ( id != INV_TIMER ) // stop running timer - stop(); -} - - -/*! - \fn void TQTimer::timeout() - - This signal is emitted when the timer is activated. -*/ - -/*! - \fn bool TQTimer::isActive() const - - Returns TRUE if the timer is running (pending); otherwise returns - FALSE. -*/ - -/*! - \fn int TQTimer::timerId() const - - Returns the ID of the timer if the timer is running; otherwise returns - -1. -*/ - - -/*! - Starts the timer with a \a msec milliseconds timeout, and returns - the ID of the timer, or zero when starting the timer failed. - - If \a sshot is TRUE, the timer will be activated only once; - otherwise it will continue until it is stopped. - - Any pending timer will be stopped. - - \sa singleShot() stop(), changeInterval(), isActive() -*/ - -int TQTimer::start( int msec, bool sshot ) -{ - if ( id >=0 && nulltimer && !msec && sshot ) - return id; - if ( id != INV_TIMER ) // stop running timer - stop(); - single = sshot; - nulltimer = ( !msec && sshot ); - return id = startTimer( msec ); -} - - -/*! - Changes the timeout interval to \a msec milliseconds. - - If the timer signal is pending, it will be stopped and restarted; - otherwise it will be started. - - \sa start(), isActive() -*/ - -void TQTimer::changeInterval( int msec ) -{ - if ( id == INV_TIMER ) { // create new timer - start( msec ); - } else { - killTimer( id ); // restart timer - id = startTimer( msec ); - } -} - -/*! - Stops the timer. - - \sa start() -*/ - -void TQTimer::stop() -{ - if ( id != INV_TIMER ) { - killTimer( id ); - id = INV_TIMER; - } -} - - -/*! - \reimp -*/ -bool TQTimer::event( TQEvent *e ) -{ - if ( e->type() != TQEvent::Timer ) // ignore all other events - return FALSE; - if ( single ) // stop single shot timer - stop(); - emit timeout(); // emit timeout signal - return TRUE; -} - - -/* - The TQSingleShotTimer class is an internal class for implementing - TQTimer::singleShot(). It starts a timer and emits the signal - and kills itself when it gets the timeout. -*/ - -static TQObjectList *sst_list = 0; // list of single shot timers - -static void sst_cleanup() -{ - if ( sst_list ) { - sst_list->setAutoDelete( TRUE ); - delete sst_list; - sst_list = 0; - } -} - -static void sst_init() -{ - if ( !sst_list ) { - sst_list = new TQObjectList; - TQ_CHECK_PTR( sst_list ); - tqAddPostRoutine( sst_cleanup ); - } -} - - -class TQSingleShotTimer : public TQObject -{ -public: - ~TQSingleShotTimer(); - bool start( int msec, TQObject *r, const char * m ); - bool isActive() const { return timerId > 0; } -protected: - bool event( TQEvent * ); -private: - TQSignal signal; - int timerId; -}; - -extern int qStartTimer( int interval, TQObject *obj ); // implemented in qapp_xxx.cpp -extern bool qKillTimer( int id ); - -TQSingleShotTimer::~TQSingleShotTimer() -{ - if (timerId != 0) { - qKillTimer(timerId); - timerId = 0; - } -} - -bool TQSingleShotTimer::start( int msec, TQObject *r, const char *m ) -{ - timerId = 0; - if ( signal.connect(r, m) ) - timerId = qStartTimer( msec, (TQObject *)this ); - return timerId != 0; -} - -bool TQSingleShotTimer::event( TQEvent * ) -{ - qKillTimer( timerId ); // no more timeouts - signal.activate(); // emit the signal - signal.disconnect( 0, 0 ); - timerId = 0; // mark as inactive - return TRUE; -} - - -/*! - This static function calls a slot after a given time interval. - - It is very convenient to use this function because you do not need - to bother with a \link TQObject::timerEvent() timerEvent\endlink or - to create a local TQTimer object. - - Example: - \code - #include - #include - - int main( int argc, char **argv ) - { - TQApplication a( argc, argv ); - TQTimer::singleShot( 10*60*1000, &a, TQ_SLOT(quit()) ); - ... // create and show your widgets - return a.exec(); - } - \endcode - - This sample program automatically terminates after 10 minutes (i.e. - 600000 milliseconds). - - The \a receiver is the receiving object and the \a member is the - slot. The time interval is \a msec. -*/ - -void TQTimer::singleShot( int msec, TQObject *receiver, const char *member ) -{ - if ( !sst_list ) - sst_init(); - // search the list for a free ss timer we could reuse - TQSingleShotTimer *sst = (TQSingleShotTimer*)sst_list->first(); - while ( sst && sst->isActive() ) - sst = (TQSingleShotTimer*)sst_list->next(); - // create a new one if not successful - if ( !sst ) { - sst = new TQSingleShotTimer; - sst_list->append( sst ); - } - sst->start(msec, receiver, member); -} diff --git a/src/kernel/qvariant.cpp b/src/kernel/qvariant.cpp index d3782f483..7e9b659ac 100644 --- a/src/kernel/qvariant.cpp +++ b/src/kernel/qvariant.cpp @@ -59,7 +59,7 @@ #include "ntqpointarray.h" #include "ntqbitmap.h" #include "ntqcursor.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqsizepolicy.h" #include "ntqshared.h" #include "ntqbitarray.h" diff --git a/src/kernel/tqtimer.cpp b/src/kernel/tqtimer.cpp new file mode 100644 index 000000000..11fecf81f --- /dev/null +++ b/src/kernel/tqtimer.cpp @@ -0,0 +1,338 @@ +/**************************************************************************** +** +** Implementation of TQTimer class +** +** Created : 931111 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqtimer.h" +#include "ntqsignal.h" +#include "tqobjectlist.h" + +/*! + \class TQTimer tqtimer.h + \brief The TQTimer class provides timer signals and single-shot timers. + + \ingroup time + \ingroup events + \mainclass + + It uses \link TQTimerEvent timer events\endlink internally to + provide a more versatile timer. TQTimer is very easy to use: + create a TQTimer, call start() to start it and connect its + timeout() to the appropriate slots. When the time is up it will + emit the timeout() signal. + + Note that a TQTimer object is destroyed automatically when its + parent object is destroyed. + + Example: + \code + TQTimer *timer = new TQTimer( myObject ); + connect( timer, TQ_SIGNAL(timeout()), myObject, TQ_SLOT(timerDone()) ); + timer->start( 2000, TRUE ); // 2 seconds single-shot timer + \endcode + + You can also use the static singleShot() function to create a + single shot timer. + + As a special case, a TQTimer with timeout 0 times out as soon as + all the events in the window system's event queue have been + processed. + + This can be used to do heavy work while providing a snappy + user interface: + \code + TQTimer *t = new TQTimer( myObject ); + connect( t, TQ_SIGNAL(timeout()), TQ_SLOT(processOneThing()) ); + t->start( 0, FALSE ); + \endcode + + myObject->processOneThing() will be called repeatedly and should + return quickly (typically after processing one data item) so that + TQt can deliver events to widgets and stop the timer as soon as it + has done all its work. This is the traditional way of + implementing heavy work in GUI applications; multi-threading is + now becoming available on more and more platforms, and we expect + that null events will eventually be replaced by threading. + + Note that TQTimer's accuracy depends on the underlying operating + system and hardware. Most platforms support an accuracy of 20ms; + some provide more. If TQt is unable to deliver the requested + number of timer clicks, it will silently discard some. + + An alternative to using TQTimer is to call TQObject::startTimer() + for your object and reimplement the TQObject::timerEvent() event + handler in your class (which must, of course, inherit TQObject). + The disadvantage is that timerEvent() does not support such + high-level features as single-shot timers or signals. + + Some operating systems limit the number of timers that may be + used; TQt tries to work around these limitations. +*/ + + +static const int INV_TIMER = -1; // invalid timer id + + +/*! + Constructs a timer called \a name, with the parent \a parent. + + Note that the parent object's destructor will destroy this timer + object. +*/ + +TQTimer::TQTimer( TQObject *parent, const char *name ) + : TQObject( parent, name ), id(INV_TIMER), single(0), nulltimer(0) +{ +} + +/*! + Destroys the timer. +*/ + +TQTimer::~TQTimer() +{ + if ( id != INV_TIMER ) // stop running timer + stop(); +} + + +/*! + \fn void TQTimer::timeout() + + This signal is emitted when the timer is activated. +*/ + +/*! + \fn bool TQTimer::isActive() const + + Returns TRUE if the timer is running (pending); otherwise returns + FALSE. +*/ + +/*! + \fn int TQTimer::timerId() const + + Returns the ID of the timer if the timer is running; otherwise returns + -1. +*/ + + +/*! + Starts the timer with a \a msec milliseconds timeout, and returns + the ID of the timer, or zero when starting the timer failed. + + If \a sshot is TRUE, the timer will be activated only once; + otherwise it will continue until it is stopped. + + Any pending timer will be stopped. + + \sa singleShot() stop(), changeInterval(), isActive() +*/ + +int TQTimer::start( int msec, bool sshot ) +{ + if ( id >=0 && nulltimer && !msec && sshot ) + return id; + if ( id != INV_TIMER ) // stop running timer + stop(); + single = sshot; + nulltimer = ( !msec && sshot ); + return id = startTimer( msec ); +} + + +/*! + Changes the timeout interval to \a msec milliseconds. + + If the timer signal is pending, it will be stopped and restarted; + otherwise it will be started. + + \sa start(), isActive() +*/ + +void TQTimer::changeInterval( int msec ) +{ + if ( id == INV_TIMER ) { // create new timer + start( msec ); + } else { + killTimer( id ); // restart timer + id = startTimer( msec ); + } +} + +/*! + Stops the timer. + + \sa start() +*/ + +void TQTimer::stop() +{ + if ( id != INV_TIMER ) { + killTimer( id ); + id = INV_TIMER; + } +} + + +/*! + \reimp +*/ +bool TQTimer::event( TQEvent *e ) +{ + if ( e->type() != TQEvent::Timer ) // ignore all other events + return FALSE; + if ( single ) // stop single shot timer + stop(); + emit timeout(); // emit timeout signal + return TRUE; +} + + +/* + The TQSingleShotTimer class is an internal class for implementing + TQTimer::singleShot(). It starts a timer and emits the signal + and kills itself when it gets the timeout. +*/ + +static TQObjectList *sst_list = 0; // list of single shot timers + +static void sst_cleanup() +{ + if ( sst_list ) { + sst_list->setAutoDelete( TRUE ); + delete sst_list; + sst_list = 0; + } +} + +static void sst_init() +{ + if ( !sst_list ) { + sst_list = new TQObjectList; + TQ_CHECK_PTR( sst_list ); + tqAddPostRoutine( sst_cleanup ); + } +} + + +class TQSingleShotTimer : public TQObject +{ +public: + ~TQSingleShotTimer(); + bool start( int msec, TQObject *r, const char * m ); + bool isActive() const { return timerId > 0; } +protected: + bool event( TQEvent * ); +private: + TQSignal signal; + int timerId; +}; + +extern int qStartTimer( int interval, TQObject *obj ); // implemented in qapp_xxx.cpp +extern bool qKillTimer( int id ); + +TQSingleShotTimer::~TQSingleShotTimer() +{ + if (timerId != 0) { + qKillTimer(timerId); + timerId = 0; + } +} + +bool TQSingleShotTimer::start( int msec, TQObject *r, const char *m ) +{ + timerId = 0; + if ( signal.connect(r, m) ) + timerId = qStartTimer( msec, (TQObject *)this ); + return timerId != 0; +} + +bool TQSingleShotTimer::event( TQEvent * ) +{ + qKillTimer( timerId ); // no more timeouts + signal.activate(); // emit the signal + signal.disconnect( 0, 0 ); + timerId = 0; // mark as inactive + return TRUE; +} + + +/*! + This static function calls a slot after a given time interval. + + It is very convenient to use this function because you do not need + to bother with a \link TQObject::timerEvent() timerEvent\endlink or + to create a local TQTimer object. + + Example: + \code + #include + #include + + int main( int argc, char **argv ) + { + TQApplication a( argc, argv ); + TQTimer::singleShot( 10*60*1000, &a, TQ_SLOT(quit()) ); + ... // create and show your widgets + return a.exec(); + } + \endcode + + This sample program automatically terminates after 10 minutes (i.e. + 600000 milliseconds). + + The \a receiver is the receiving object and the \a member is the + slot. The time interval is \a msec. +*/ + +void TQTimer::singleShot( int msec, TQObject *receiver, const char *member ) +{ + if ( !sst_list ) + sst_init(); + // search the list for a free ss timer we could reuse + TQSingleShotTimer *sst = (TQSingleShotTimer*)sst_list->first(); + while ( sst && sst->isActive() ) + sst = (TQSingleShotTimer*)sst_list->next(); + // create a new one if not successful + if ( !sst ) { + sst = new TQSingleShotTimer; + sst_list->append( sst ); + } + sst->start(msec, receiver, member); +} diff --git a/src/kernel/tqtimer.h b/src/kernel/tqtimer.h new file mode 100644 index 000000000..40aae8724 --- /dev/null +++ b/src/kernel/tqtimer.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Definition of TQTimer class +** +** Created : 931111 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQTIMER_H +#define TQTIMER_H + +#ifndef QT_H +#include "tqobject.h" +#endif // QT_H + + +class TQ_EXPORT TQTimer : public TQObject +{ + TQ_OBJECT +public: + TQTimer( TQObject *parent=0, const char *name=0 ); + ~TQTimer(); + + bool isActive() const; + + int start( int msec, bool sshot = FALSE ); + void changeInterval( int msec ); + void stop(); + + static void singleShot( int msec, TQObject *receiver, const char *member ); + + int timerId() const { return id; } + +signals: + void timeout(); + +protected: + bool event( TQEvent * ); + +private: + int id; + uint single : 1; + uint nulltimer : 1; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQTimer( const TQTimer & ); + TQTimer &operator=( const TQTimer & ); +#endif +}; + + +inline bool TQTimer::isActive() const +{ + return id >= 0; +} + + +#endif // TQTIMER_H diff --git a/src/kernel/tqwidget_x11.cpp b/src/kernel/tqwidget_x11.cpp index 78d1e850e..bc31e7e75 100644 --- a/src/kernel/tqwidget_x11.cpp +++ b/src/kernel/tqwidget_x11.cpp @@ -48,7 +48,7 @@ #include "tqobjectlist.h" #include "ntqlayout.h" #include "tqtextcodec.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqcursor.h" #include "qt_x11_p.h" #include diff --git a/src/moc/moc.pro b/src/moc/moc.pro index 566a8589f..32f30dc06 100644 --- a/src/moc/moc.pro +++ b/src/moc/moc.pro @@ -16,7 +16,7 @@ SOURCES = ../tools/qbuffer.cpp \ ../tools/tqptrcollection.cpp \ ../tools/qcstring.cpp \ ../tools/qdatastream.cpp \ - ../tools/qdatetime.cpp \ + ../tools/tqdatetime.cpp \ ../tools/qfile.cpp \ ../tools/qdir.cpp \ ../tools/qfileinfo.cpp \ diff --git a/src/moc/moc.y b/src/moc/moc.y index 0d675fbc7..eb5cb1320 100644 --- a/src/moc/moc.y +++ b/src/moc/moc.y @@ -60,7 +60,7 @@ void yyerror( const char *msg ); #include "qplatformdefs.h" #include "ntqasciidict.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqdict.h" #include "ntqfile.h" #include "ntqdir.h" diff --git a/src/moc/moc_yacc.cpp b/src/moc/moc_yacc.cpp index d070c4230..bde5c9f53 100644 --- a/src/moc/moc_yacc.cpp +++ b/src/moc/moc_yacc.cpp @@ -73,7 +73,7 @@ void yyerror( const char *msg ); #include "qplatformdefs.h" #include "ntqasciidict.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqdict.h" #include "ntqfile.h" #include "ntqdir.h" diff --git a/src/network/qdns.cpp b/src/network/qdns.cpp index dc641569a..69fb60f52 100644 --- a/src/network/qdns.cpp +++ b/src/network/qdns.cpp @@ -64,11 +64,11 @@ #ifndef TQT_NO_DNS -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqdict.h" #include "tqptrlist.h" #include "tqstring.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqapplication.h" #include "tqptrvector.h" #include "tqstrlist.h" diff --git a/src/network/qftp.cpp b/src/network/qftp.cpp index 756f3ec09..9e9135113 100644 --- a/src/network/qftp.cpp +++ b/src/network/qftp.cpp @@ -48,7 +48,7 @@ #include "ntqurloperator.h" #include "tqstringlist.h" #include "ntqregexp.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqfileinfo.h" #include "tqptrdict.h" // binary compatibility diff --git a/src/network/qhttp.cpp b/src/network/qhttp.cpp index b37d4789d..0d8b83fb1 100644 --- a/src/network/qhttp.cpp +++ b/src/network/qhttp.cpp @@ -50,7 +50,7 @@ #include "ntqcstring.h" #include "ntqbuffer.h" #include "ntqurloperator.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "private/qinternal_p.h" //#define TQHTTP_DEBUG diff --git a/src/network/qsocket.cpp b/src/network/qsocket.cpp index 687c13f90..17050c9c1 100644 --- a/src/network/qsocket.cpp +++ b/src/network/qsocket.cpp @@ -41,7 +41,7 @@ #include "ntqsocket.h" #ifndef TQT_NO_NETWORK #include "tqptrlist.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqsocketdevice.h" #include "ntqdns.h" #include "private/qinternal_p.h" diff --git a/src/sql/drivers/cache/tqsqlcachedresult.cpp b/src/sql/drivers/cache/tqsqlcachedresult.cpp index 6b0b77e35..709e61944 100644 --- a/src/sql/drivers/cache/tqsqlcachedresult.cpp +++ b/src/sql/drivers/cache/tqsqlcachedresult.cpp @@ -38,7 +38,7 @@ **********************************************************************/ #include "tqsqlcachedresult.h" -#include +#include #ifndef TQT_NO_SQL static const uint initial_cache_size = 128; diff --git a/src/sql/drivers/ibase/tqsql_ibase.cpp b/src/sql/drivers/ibase/tqsql_ibase.cpp index e96d15b6a..425d0e311 100644 --- a/src/sql/drivers/ibase/tqsql_ibase.cpp +++ b/src/sql/drivers/ibase/tqsql_ibase.cpp @@ -14,7 +14,7 @@ #include "tqsql_ibase.h" -#include +#include #include #include diff --git a/src/sql/drivers/mysql/tqsql_mysql.cpp b/src/sql/drivers/mysql/tqsql_mysql.cpp index d91720e80..603a5b960 100644 --- a/src/sql/drivers/mysql/tqsql_mysql.cpp +++ b/src/sql/drivers/mysql/tqsql_mysql.cpp @@ -41,7 +41,7 @@ #include "tqsql_mysql.h" #include -#include +#include #include #include diff --git a/src/sql/drivers/odbc/tqsql_odbc.cpp b/src/sql/drivers/odbc/tqsql_odbc.cpp index 605948ca1..a9a3aa468 100644 --- a/src/sql/drivers/odbc/tqsql_odbc.cpp +++ b/src/sql/drivers/odbc/tqsql_odbc.cpp @@ -45,7 +45,7 @@ #include #include #endif -#include +#include #include #include #include diff --git a/src/sql/drivers/psql/tqsql_psql.cpp b/src/sql/drivers/psql/tqsql_psql.cpp index 1ea64fb75..ecc63a635 100644 --- a/src/sql/drivers/psql/tqsql_psql.cpp +++ b/src/sql/drivers/psql/tqsql_psql.cpp @@ -46,7 +46,7 @@ #include #include #include -#include +#include // PostgreSQL header included by redefines DEBUG. #if defined(DEBUG) # undef DEBUG diff --git a/src/sql/drivers/sqlite/tqsql_sqlite.cpp b/src/sql/drivers/sqlite/tqsql_sqlite.cpp index 4b7191bb4..8ec7425cd 100644 --- a/src/sql/drivers/sqlite/tqsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/tqsql_sqlite.cpp @@ -14,7 +14,7 @@ #include "tqsql_sqlite.h" -#include +#include #include #include #include diff --git a/src/sql/drivers/sqlite3/tqsql_sqlite3.cpp b/src/sql/drivers/sqlite3/tqsql_sqlite3.cpp index ec577c873..8eef4a3ac 100644 --- a/src/sql/drivers/sqlite3/tqsql_sqlite3.cpp +++ b/src/sql/drivers/sqlite3/tqsql_sqlite3.cpp @@ -14,7 +14,7 @@ #include "tqsql_sqlite3.h" -#include +#include #include #include #include diff --git a/src/sql/tqdatatable.cpp b/src/sql/tqdatatable.cpp index bb81ff6c1..c62b607f8 100644 --- a/src/sql/tqdatatable.cpp +++ b/src/sql/tqdatatable.cpp @@ -51,9 +51,9 @@ #include "ntqpopupmenu.h" #include "tqvaluelist.h" #include "tqsqlmanager_p.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqcursor.h" -#include "ntqtimer.h" +#include "tqtimer.h" //#define QT_DEBUG_DATATABLE diff --git a/src/sql/tqeditorfactory.cpp b/src/sql/tqeditorfactory.cpp index 918f5f32f..7893a1355 100644 --- a/src/sql/tqeditorfactory.cpp +++ b/src/sql/tqeditorfactory.cpp @@ -45,7 +45,7 @@ #include "ntqcombobox.h" #include "tqeditorfactory.h" -#include "ntqdatetimeedit.h" +#include "tqdatetimeedit.h" #ifndef TQT_NO_SQL_EDIT_WIDGETS diff --git a/src/sql/tqsqlcursor.cpp b/src/sql/tqsqlcursor.cpp index 858a3668a..55f9c9a38 100644 --- a/src/sql/tqsqlcursor.cpp +++ b/src/sql/tqsqlcursor.cpp @@ -44,7 +44,7 @@ #include "tqsqldriver.h" #include "tqsqlresult.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "tqsqldatabase.h" #include "tqsql.h" diff --git a/src/sql/tqsqldriver.cpp b/src/sql/tqsqldriver.cpp index f24fedf47..d688b9a46 100644 --- a/src/sql/tqsqldriver.cpp +++ b/src/sql/tqsqldriver.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_SQL -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "tqsqlextension_p.h" // database states diff --git a/src/sql/tqsqleditorfactory.cpp b/src/sql/tqsqleditorfactory.cpp index f7ac2d9e8..6be4a2d36 100644 --- a/src/sql/tqsqleditorfactory.cpp +++ b/src/sql/tqsqleditorfactory.cpp @@ -48,7 +48,7 @@ #include "ntqlineedit.h" #include "ntqspinbox.h" #include "ntqcombobox.h" -#include "ntqdatetimeedit.h" +#include "tqdatetimeedit.h" /*! \class TQSqlEditorFactory tqsqleditorfactory.h diff --git a/src/table/qtable.cpp b/src/table/qtable.cpp index 31f6dd0bd..c696dbaf2 100644 --- a/src/table/qtable.cpp +++ b/src/table/qtable.cpp @@ -52,7 +52,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/tools/ntqdatetime.h b/src/tools/ntqdatetime.h deleted file mode 100644 index 545f1f56b..000000000 --- a/src/tools/ntqdatetime.h +++ /dev/null @@ -1,254 +0,0 @@ -/************************************************************************* -** -** Definition of date and time classes -** -** Created : 940124 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQDATETIME_H -#define TQDATETIME_H - -#ifndef QT_H -#include "tqstring.h" -#include "ntqnamespace.h" -#endif // QT_H - -#include - -/***************************************************************************** - TQDate class - *****************************************************************************/ - -class TQ_EXPORT TQDate -{ -public: - TQDate() { jd = 0; } - TQDate( int y, int m, int d ); - - bool isNull() const { return jd == 0; } - bool isValid() const; - - int year() const; - int month() const; - int day() const; - int dayOfWeek() const; - int dayOfYear() const; - int daysInMonth() const; - int daysInYear() const; - int weekNumber( int *yearNum = 0 ) const; - -#ifndef TQT_NO_TEXTDATE -#ifndef TQT_NO_COMPAT - static TQString monthName( int month ) { return shortMonthName( month ); } - static TQString dayName( int weekday ) { return shortDayName( weekday ); } -#endif - static TQString shortMonthName( int month ); - static TQString shortDayName( int weekday ); - static TQString longMonthName( int month ); - static TQString longDayName( int weekday ); -#endif //TQT_NO_TEXTDATE -#ifndef TQT_NO_TEXTSTRING -#if !defined(TQT_NO_SPRINTF) - TQString toString( TQt::DateFormat f = TQt::TextDate ) const; -#endif - TQString toString( const TQString& format ) const; -#endif - bool setYMD( int y, int m, int d ); - - TQDate addDays( int days ) const; - TQDate addMonths( int months ) const; - TQDate addYears( int years ) const; - int daysTo( const TQDate & ) const; - - bool operator==( const TQDate &d ) const { return jd == d.jd; } - bool operator!=( const TQDate &d ) const { return jd != d.jd; } - bool operator<( const TQDate &d ) const { return jd < d.jd; } - bool operator<=( const TQDate &d ) const { return jd <= d.jd; } - bool operator>( const TQDate &d ) const { return jd > d.jd; } - bool operator>=( const TQDate &d ) const { return jd >= d.jd; } - - static TQDate currentDate(); - static TQDate currentDate( TQt::TimeSpec ); -#ifndef TQT_NO_DATESTRING - static TQDate fromString( const TQString& s, TQt::DateFormat f = TQt::TextDate ); -#endif - static bool isValid( int y, int m, int d ); - static bool leapYear( int year ); - - static uint gregorianToJulian( int y, int m, int d ); - static void julianToGregorian( uint jd, int &y, int &m, int &d ); -private: - uint jd; - friend class TQDateTime; -#ifndef TQT_NO_DATASTREAM - friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQDate & ); - friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQDate & ); -#endif -}; - - -/***************************************************************************** - TQTime class - *****************************************************************************/ - -class TQ_EXPORT TQTime -{ -public: - TQTime() { ds=0; } // set null time - TQTime( int h, int m, int s=0, int ms=0 ); // set time - - bool isNull() const { return ds == 0; } - bool isValid() const; // valid time - - int hour() const; // 0..23 - int minute() const; // 0..59 - int second() const; // 0..59 - int msec() const; // 0..999 -#ifndef TQT_NO_DATESTRING -#ifndef TQT_NO_SPRINTF - TQString toString( TQt::DateFormat f = TQt::TextDate ) const; -#endif - TQString toString( const TQString& format ) const; -#endif - bool setHMS( int h, int m, int s, int ms=0 ); - - TQTime addSecs( int secs ) const; - int secsTo( const TQTime & ) const; - TQTime addMSecs( int ms ) const; - int msecsTo( const TQTime & ) const; - - bool operator==( const TQTime &d ) const { return ds == d.ds; } - bool operator!=( const TQTime &d ) const { return ds != d.ds; } - bool operator<( const TQTime &d ) const { return ds < d.ds; } - bool operator<=( const TQTime &d ) const { return ds <= d.ds; } - bool operator>( const TQTime &d ) const { return ds > d.ds; } - bool operator>=( const TQTime &d ) const { return ds >= d.ds; } - - static TQTime currentTime(); - static TQTime currentTime( TQt::TimeSpec ); -#ifndef TQT_NO_DATESTRING - static TQTime fromString( const TQString& s, TQt::DateFormat f = TQt::TextDate ); -#endif - static bool isValid( int h, int m, int s, int ms=0 ); - - void start(); - int restart(); - int elapsed() const; - -private: - static bool currentTime( TQTime * ); - static bool currentTime( TQTime *, TQt::TimeSpec ); - - uint ds; - friend class TQDateTime; -#ifndef TQT_NO_DATASTREAM - friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQTime & ); - friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQTime & ); -#endif -}; - - -/***************************************************************************** - TQDateTime class - *****************************************************************************/ - -class TQ_EXPORT TQDateTime -{ -public: - TQDateTime() {} // set null date and null time - TQDateTime( const TQDate & ); - TQDateTime( const TQDate &, const TQTime & ); - - bool isNull() const { return d.isNull() && t.isNull(); } - bool isValid() const { return d.isValid() && t.isValid(); } - - TQDate date() const { return d; } - TQTime time() const { return t; } - time_t toTime_t() const; - void setDate( const TQDate &date ) { d = date; } - void setTime( const TQTime &time ) { t = time; } - void setTime_t( time_t secsSince1Jan1970UTC ); - void setTime_t( time_t secsSince1Jan1970UTC, TQt::TimeSpec ); -#ifndef TQT_NO_DATESTRING -#ifndef TQT_NO_SPRINTF - TQString toString( TQt::DateFormat f = TQt::TextDate ) const; -#endif - TQString toString( const TQString& format ) const; -#endif - TQDateTime addDays( int days ) const; - TQDateTime addMonths( int months ) const; - TQDateTime addYears( int years ) const; - TQDateTime addSecs( int secs ) const; - int daysTo( const TQDateTime & ) const; - int secsTo( const TQDateTime & ) const; - - bool operator==( const TQDateTime &dt ) const; - bool operator!=( const TQDateTime &dt ) const; - bool operator<( const TQDateTime &dt ) const; - bool operator<=( const TQDateTime &dt ) const; - bool operator>( const TQDateTime &dt ) const; - bool operator>=( const TQDateTime &dt ) const; - - static TQDateTime currentDateTime(); - static TQDateTime currentDateTime( TQt::TimeSpec ); -#ifndef TQT_NO_DATESTRING - static TQDateTime fromString( const TQString& s, TQt::DateFormat f = TQt::TextDate ); -#endif -private: - TQDate d; - TQTime t; -#ifndef TQT_NO_DATASTREAM - friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQDateTime &); - friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQDateTime & ); -#endif -}; - - -/***************************************************************************** - Date and time stream functions - *****************************************************************************/ - -#ifndef TQT_NO_DATASTREAM -TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQDate & ); -TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQDate & ); -TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQTime & ); -TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQTime & ); -TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQDateTime & ); -TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQDateTime & ); -#endif // TQT_NO_DATASTREAM - -#endif // TQDATETIME_H - diff --git a/src/tools/ntqfileinfo.h b/src/tools/ntqfileinfo.h index eab7f63d1..3c4e3b3a3 100644 --- a/src/tools/ntqfileinfo.h +++ b/src/tools/ntqfileinfo.h @@ -43,7 +43,7 @@ #ifndef QT_H #include "ntqfile.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #endif // QT_H diff --git a/src/tools/ntqsettings.h b/src/tools/ntqsettings.h index f5804e89f..ee8e8e3b2 100644 --- a/src/tools/ntqsettings.h +++ b/src/tools/ntqsettings.h @@ -42,7 +42,7 @@ #define TQSETTINGS_H #ifndef QT_H -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "tqstringlist.h" #endif // QT_H diff --git a/src/tools/qcomlibrary.cpp b/src/tools/qcomlibrary.cpp index 20366db9a..27ffbb8ce 100644 --- a/src/tools/qcomlibrary.cpp +++ b/src/tools/qcomlibrary.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #ifndef NO_ERRNO_H #include diff --git a/src/tools/qdatetime.cpp b/src/tools/qdatetime.cpp deleted file mode 100644 index 51f0e51de..000000000 --- a/src/tools/qdatetime.cpp +++ /dev/null @@ -1,2600 +0,0 @@ -/**************************************************************************** -** -** Implementation of date and time classes -** -** Created : 940124 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "qplatformdefs.h" - -#include "ntqdatetime.h" -#include "ntqdatastream.h" -#include "ntqregexp.h" - -#include -#ifndef Q_OS_TEMP -#include -#endif - -#if defined(Q_OS_WIN32) -#include -#endif - -static const uint FIRST_DAY = 2361222; // Julian day for 1752-09-14 -static const int FIRST_YEAR = 1752; // ### wrong for many countries -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; - -static const short monthDays[] = { - 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - -static const char * const qt_shortMonthNames[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - -#ifndef TQT_NO_DATESTRING -/***************************************************************************** - Some static function used by TQDate, TQTime and TQDateTime - *****************************************************************************/ - -// Replaces tokens by their value. See TQDateTime::toString() for a list of valid tokens -static TQString getFmtString( const TQString& f, const TQTime* dt = 0, const TQDate* dd = 0, bool am_pm = FALSE ) -{ - if ( f.isEmpty() ) - return TQString::null; - - TQString buf = f; - - if ( dt ) { - if ( f == "h" ) { - if ( ( am_pm ) && ( dt->hour() > 12 ) ) - buf = TQString::number( dt->hour() - 12 ); - else if ( ( am_pm ) && ( dt->hour() == 0 ) ) - buf = "12"; - else - buf = TQString::number( dt->hour() ); - } else if ( f == "hh" ) { - if ( ( am_pm ) && ( dt->hour() > 12 ) ) - buf = TQString::number( dt->hour() - 12 ).rightJustify( 2, '0', TRUE ); - else if ( ( am_pm ) && ( dt->hour() == 0 ) ) - buf = "12"; - else - buf = TQString::number( dt->hour() ).rightJustify( 2, '0', TRUE ); - } else if ( f == "m" ) { - buf = TQString::number( dt->minute() ); - } else if ( f == "mm" ) { - buf = TQString::number( dt->minute() ).rightJustify( 2, '0', TRUE ); - } else if ( f == "s" ) { - buf = TQString::number( dt->second() ); - } else if ( f == "ss" ) { - buf = TQString::number( dt->second() ).rightJustify( 2, '0', TRUE ); - } else if ( f == "z" ) { - buf = TQString::number( dt->msec() ); - } else if ( f == "zzz" ) { - buf = TQString::number( dt->msec() ).rightJustify( 3, '0', TRUE ); - } else if ( f == "ap" ) { - buf = dt->hour() < 12 ? "am" : "pm"; - } else if ( f == "AP" ) { - buf = dt->hour() < 12 ? "AM" : "PM"; - } - } - - if ( dd ) { - if ( f == "d" ) { - buf = TQString::number( dd->day() ); - } else if ( f == "dd" ) { - buf = TQString::number( dd->day() ).rightJustify( 2, '0', TRUE ); - } else if ( f == "M" ) { - buf = TQString::number( dd->month() ); - } else if ( f == "MM" ) { - buf = TQString::number( dd->month() ).rightJustify( 2, '0', TRUE ); -#ifndef TQT_NO_TEXTDATE - } else if ( f == "ddd" ) { - buf = dd->shortDayName( dd->dayOfWeek() ); - } else if ( f == "dddd" ) { - buf = dd->longDayName( dd->dayOfWeek() ); - } else if ( f == "MMM" ) { - buf = dd->shortMonthName( dd->month() ); - } else if ( f == "MMMM" ) { - buf = dd->longMonthName( dd->month() ); -#endif - } else if ( f == "yy" ) { - buf = TQString::number( dd->year() ).right( 2 ); - } else if ( f == "yyyy" ) { - buf = TQString::number( dd->year() ); - } - } - - return buf; -} - -// Parses the format string and uses getFmtString to get the values for the tokens. Ret -static TQString fmtDateTime( const TQString& f, const TQTime* dt = 0, const TQDate* dd = 0 ) -{ - if ( f.isEmpty() ) { - return TQString::null; - } - - if ( dt && !dt->isValid() ) - return TQString::null; - if ( dd && !dd->isValid() ) - return TQString::null; - - bool ap = ( f.contains( "AP" ) || f.contains( "ap" ) ); - - TQString buf; - TQString frm; - TQChar status = '0'; - - for ( int i = 0; i < (int)f.length(); ++i ) { - - if ( f[ i ] == status ) { - if ( ( ap ) && ( ( f[ i ] == 'P' ) || ( f[ i ] == 'p' ) ) ) - status = '0'; - frm += f[ i ]; - } else { - buf += getFmtString( frm, dt, dd, ap ); - frm = TQString::null; - if ( ( f[ i ] == 'h' ) || ( f[ i ] == 'm' ) || ( f[ i ] == 's' ) || ( f[ i ] == 'z' ) ) { - status = f[ i ]; - frm += f[ i ]; - } else if ( ( f[ i ] == 'd' ) || ( f[ i ] == 'M' ) || ( f[ i ] == 'y' ) ) { - status = f[ i ]; - frm += f[ i ]; - } else if ( ( ap ) && ( f[ i ] == 'A' ) ) { - status = 'P'; - frm += f[ i ]; - } else if( ( ap ) && ( f[ i ] == 'a' ) ) { - status = 'p'; - frm += f[ i ]; - } else { - buf += f[ i ]; - status = '0'; - } - } - } - - buf += getFmtString( frm, dt, dd, ap ); - - return buf; -} -#endif // TQT_NO_DATESTRING - -/***************************************************************************** - TQDate member functions - *****************************************************************************/ - -/*! - \class TQDate ntqdatetime.h - \reentrant - \brief The TQDate class provides date functions. - - \ingroup time - \mainclass - - A TQDate object contains a calendar date, i.e. year, month, and day - numbers, in the modern Western (Gregorian) calendar. It can read - the current date from the system clock. It provides functions for - comparing dates and for manipulating dates, e.g. by adding a - number of days or months or years. - - A TQDate object is typically created either by giving the year, - month and day numbers explicitly, or by using the static function - currentDate(), which creates a TQDate object containing the system - clock's date. An explicit date can also be set using setYMD(). The - fromString() function returns a TQDate given a string and a date - format which is used to interpret the date within the string. - - The year(), month(), and day() functions provide access to the - year, month, and day numbers. Also, dayOfWeek() and dayOfYear() - functions are provided. The same information is provided in - textual format by the toString(), shortDayName(), longDayName(), - shortMonthName() and longMonthName() functions. - - TQDate provides a full set of operators to compare two TQDate - objects where smaller means earlier and larger means later. - - You can increment (or decrement) a date by a given number of days - using addDays(). Similarly you can use addMonths() and addYears(). - The daysTo() function returns the number of days between two - dates. - - The daysInMonth() and daysInYear() functions return how many days - there are in this date's month and year, respectively. The - leapYear() function indicates whether this date is in a leap year. - - Note that TQDate should not be used for date calculations for dates - prior to the introduction of the Gregorian calendar. This calendar - was adopted by England from the 14th - September 1752 (hence this is the earliest valid TQDate), and - subsequently by most other Western countries, until 1923. - - The end of time is reached around the year 8000, by which time we - expect TQt to be obsolete. - - \sa TQTime TQDateTime TQDateEdit TQDateTimeEdit -*/ - -/*! - \enum TQt::DateFormat - - \value TextDate (default) TQt format - \value ISODate ISO 8601 extended format (YYYY-MM-DD, or with time, - YYYY-MM-DDTHH:MM:SS) - \value LocalDate locale dependent format -*/ - - -/*! - \enum TQt::TimeSpec - - \value LocalTime Locale dependent time (Timezones and Daylight Savings Time) - \value UTC Coordinated Universal Time, replaces Greenwich Time -*/ - -/*! - \fn TQDate::TQDate() - - Constructs a null date. Null dates are invalid. - - \sa isNull(), isValid() -*/ - - -/*! - Constructs a date with year \a y, month \a m and day \a d. - - \a y must be in the range 1752..8000, \a m must be in the range - 1..12, and \a d must be in the range 1..31. - - \warning If \a y is in the range 0..99, it is interpreted as - 1900..1999. - - \sa isValid() -*/ - -TQDate::TQDate( int y, int m, int d ) -{ - jd = 0; - setYMD( y, m, d ); -} - - -/*! - \fn bool TQDate::isNull() const - - Returns TRUE if the date is null; otherwise returns FALSE. A null - date is invalid. - - \sa isValid() -*/ - - -/*! - Returns TRUE if this date is valid; otherwise returns FALSE. - - \sa isNull() -*/ - -bool TQDate::isValid() const -{ - return jd >= FIRST_DAY; -} - - -/*! - Returns the year (1752..8000) of this date. - - \sa month(), day() -*/ - -int TQDate::year() const -{ - int y, m, d; - julianToGregorian( jd, y, m, d ); - return y; -} - -/*! - Returns the month (January=1..December=12) of this date. - - \sa year(), day() -*/ - -int TQDate::month() const -{ - int y, m, d; - julianToGregorian( jd, y, m, d ); - return m; -} - -/*! - Returns the day of the month (1..31) of this date. - - \sa year(), month(), dayOfWeek() -*/ - -int TQDate::day() const -{ - int y, m, d; - julianToGregorian( jd, y, m, d ); - return d; -} - -/*! - Returns the weekday (Monday=1..Sunday=7) for this date. - - \sa day(), dayOfYear() -*/ - -int TQDate::dayOfWeek() const -{ - return ( jd % 7 ) + 1; -} - -/*! - Returns the day of the year (1..365) for this date. - - \sa day(), dayOfWeek() -*/ - -int TQDate::dayOfYear() const -{ - return jd - gregorianToJulian(year(), 1, 1) + 1; -} - -/*! - Returns the number of days in the month (28..31) for this date. - - \sa day(), daysInYear() -*/ - -int TQDate::daysInMonth() const -{ - int y, m, d; - julianToGregorian( jd, y, m, d ); - if ( m == 2 && leapYear(y) ) - return 29; - else - return monthDays[m]; -} - -/*! - Returns the number of days in the year (365 or 366) for this date. - - \sa day(), daysInMonth() -*/ - -int TQDate::daysInYear() const -{ - int y, m, d; - julianToGregorian( jd, y, m, d ); - return leapYear( y ) ? 366 : 365; -} - -/*! - Returns the week number (1 to 53), and stores the year in \a - *yearNumber unless \a yearNumber is null (the default). - - Returns 0 if the date is invalid. - - In accordance with ISO 8601, weeks start on Monday and the first - Thursday of a year is always in week 1 of that year. Most years - have 52 weeks, but some have 53. - - \a *yearNumber is not always the same as year(). For example, 1 - January 2000 has week number 52 in the year 1999, and 31 December - 2002 has week number 1 in the year 2003. - - \legalese - - Copyright (c) 1989 The Regents of the University of California. - All rights reserved. - - Redistribution and use in source and binary forms are permitted - provided that the above copyright notice and this paragraph are - duplicated in all such forms and that any documentation, - advertising materials, and other materials related to such - distribution and use acknowledge that the software was developed - by the University of California, Berkeley. The name of the - University may not be used to endorse or promote products derived - from this software without specific prior written permission. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - - \sa isValid() -*/ - -int TQDate::weekNumber( int *yearNumber ) const -{ - if ( !isValid() ) - return 0; - - int year = TQDate::year(); - int yday = dayOfYear() - 1; - int wday = dayOfWeek(); - if (wday == 7) - wday = 0; - int w; - - for (;;) { - int len; - int bot; - int top; - - len = leapYear(year) ? 366 : 365; - /* - ** What yday (-3 ... 3) does - ** the ISO year begin on? - */ - bot = ((yday + 11 - wday) % 7) - 3; - /* - ** What yday does the NEXT - ** ISO year begin on? - */ - top = bot - (len % 7); - if (top < -3) - top += 7; - top += len; - if (yday >= top) { - ++year; - w = 1; - break; - } - if (yday >= bot) { - w = 1 + ((yday - bot) / 7); - break; - } - --year; - yday += leapYear(year) ? 366 : 365; - } - if (yearNumber != 0) - *yearNumber = year; - return w; -} - -/*! - \fn TQString TQDate::monthName( int month ) - \obsolete - - Use shortMonthName() instead. -*/ -#ifndef TQT_NO_TEXTDATE -/*! - Returns the name of the \a month. - - 1 = "Jan", 2 = "Feb", ... 12 = "Dec" - - The month names will be localized according to the system's locale - settings. - - \sa toString(), longMonthName(), shortDayName(), longDayName() -*/ - -TQString TQDate::shortMonthName( int month ) -{ -#if defined(QT_CHECK_RANGE) - if ( month < 1 || month > 12 ) { - tqWarning( "TQDate::shortMonthName: Parameter out ouf range" ); - month = 1; - } -#endif -#ifndef TQ_WS_WIN - char buffer[255]; - tm tt; - memset( &tt, 0, sizeof( tm ) ); - tt.tm_mon = month - 1; - if ( strftime( buffer, sizeof( buffer ), "%b", &tt ) ) - return TQString::fromLocal8Bit( buffer ); -#else - SYSTEMTIME st; - memset( &st, 0, sizeof(SYSTEMTIME) ); - st.wYear = 2000; - st.wMonth = month; - st.wDay = 1; - const wchar_t mmm_t[] = L"MMM"; // workaround for Borland - QT_WA( { - TCHAR buf[255]; - if ( GetDateFormat( LOCALE_USER_DEFAULT, 0, &st, mmm_t, buf, 255 ) ) - return TQString::fromUcs2( (ushort*)buf ); - } , { - char buf[255]; - if ( GetDateFormatA( LOCALE_USER_DEFAULT, 0, &st, "MMM", (char*)&buf, 255 ) ) - return TQString::fromLocal8Bit( buf ); - } ); -#endif - return TQString::null; -} - -/*! - Returns the long name of the \a month. - - 1 = "January", 2 = "February", ... 12 = "December" - - The month names will be localized according to the system's locale - settings. - - \sa toString(), shortMonthName(), shortDayName(), longDayName() -*/ - -TQString TQDate::longMonthName( int month ) -{ -#if defined(QT_CHECK_RANGE) - if ( month < 1 || month > 12 ) { - tqWarning( "TQDate::longMonthName: Parameter out ouf range" ); - month = 1; - } -#endif -#ifndef TQ_WS_WIN - char buffer[255]; - tm tt; - memset( &tt, 0, sizeof( tm ) ); - tt.tm_mon = month - 1; - if ( strftime( buffer, sizeof( buffer ), "%B", &tt ) ) - return TQString::fromLocal8Bit( buffer ); -#else - SYSTEMTIME st; - memset( &st, 0, sizeof(SYSTEMTIME) ); - st.wYear = 2000; - st.wMonth = month; - st.wDay = 1 ; - const wchar_t mmmm_t[] = L"MMMM"; // workaround for Borland - QT_WA( { - TCHAR buf[255]; - if ( GetDateFormat( LOCALE_USER_DEFAULT, 0, &st, mmmm_t, buf, 255 ) ) - return TQString::fromUcs2( (ushort*)buf ); - } , { - char buf[255]; - if ( GetDateFormatA( LOCALE_USER_DEFAULT, 0, &st, "MMMM", (char*)&buf, 255 ) ) - return TQString::fromLocal8Bit( buf ); - } ) -#endif - - return TQString::null; -} - -/*! - \fn TQString TQDate::dayName( int weekday ) - \obsolete - - Use shortDayName() instead. -*/ - -/*! - Returns the name of the \a weekday. - - 1 = "Mon", 2 = "Tue", ... 7 = "Sun" - - The day names will be localized according to the system's locale - settings. - - \sa toString(), shortMonthName(), longMonthName(), longDayName() -*/ - -TQString TQDate::shortDayName( int weekday ) -{ -#if defined(QT_CHECK_RANGE) - if ( weekday < 1 || weekday > 7 ) { - tqWarning( "TQDate::shortDayName: Parameter out of range" ); - weekday = 1; - } -#endif -#ifndef TQ_WS_WIN - char buffer[255]; - tm tt; - memset( &tt, 0, sizeof( tm ) ); - tt.tm_wday = ( weekday == 7 ) ? 0 : weekday; - if ( strftime( buffer, sizeof( buffer ), "%a", &tt ) ) - return TQString::fromLocal8Bit( buffer ); -#else - SYSTEMTIME st; - memset( &st, 0, sizeof(SYSTEMTIME) ); - st.wYear = 2001; - st.wMonth = 10; - st.wDayOfWeek = ( weekday == 7 ) ? 0 : weekday; - st.wDay = 21 + st.wDayOfWeek; - const wchar_t ddd_t[] = L"ddd"; // workaround for Borland - QT_WA( { - TCHAR buf[255]; - if ( GetDateFormat( LOCALE_USER_DEFAULT, 0, &st, ddd_t, buf, 255 ) ) - return TQString::fromUcs2( (ushort*)buf ); - } , { - char buf[255]; - if ( GetDateFormatA( LOCALE_USER_DEFAULT, 0, &st, "ddd", (char*)&buf, 255 ) ) - return TQString::fromLocal8Bit( buf ); - } ); -#endif - - return TQString::null; -} - -/*! - Returns the long name of the \a weekday. - - 1 = "Monday", 2 = "Tuesday", ... 7 = "Sunday" - - The day names will be localized according to the system's locale - settings. - - \sa toString(), shortDayName(), shortMonthName(), longMonthName() -*/ - -TQString TQDate::longDayName( int weekday ) -{ -#if defined(QT_CHECK_RANGE) - if ( weekday < 1 || weekday > 7 ) { - tqWarning( "TQDate::longDayName: Parameter out of range" ); - weekday = 1; - } -#endif -#ifndef TQ_WS_WIN - char buffer[255]; - tm tt; - memset( &tt, 0, sizeof( tm ) ); - tt.tm_wday = ( weekday == 7 ) ? 0 : weekday; - if ( strftime( buffer, sizeof( buffer ), "%A", &tt ) ) - return TQString::fromLocal8Bit( buffer ); -#else - SYSTEMTIME st; - memset( &st, 0, sizeof(SYSTEMTIME) ); - st.wYear = 2001; - st.wMonth = 10; - st.wDayOfWeek = ( weekday == 7 ) ? 0 : weekday; - st.wDay = 21 + st.wDayOfWeek; - const wchar_t dddd_t[] = L"dddd"; // workaround for Borland - QT_WA( { - TCHAR buf[255]; - if ( GetDateFormat( LOCALE_USER_DEFAULT, 0, &st, dddd_t, buf, 255 ) ) - return TQString::fromUcs2( (ushort*)buf ); - } , { - char buf[255]; - if ( GetDateFormatA( LOCALE_USER_DEFAULT, 0, &st, "dddd", (char*)&buf, 255 ) ) - return TQString::fromLocal8Bit( buf ); - } ); -#endif - - return TQString::null; -} -#endif //TQT_NO_TEXTDATE - -#ifndef TQT_NO_DATESTRING - -#if !defined(TQT_NO_SPRINTF) -/*! - \overload - - Returns the date as a string. The \a f parameter determines the - format of the string. - - If \a f is \c TQt::TextDate, the string format is "Sat May 20 1995" - (using the shortDayName() and shortMonthName() functions to - generate the string, so the day and month names are locale - specific). - - If \a f is \c TQt::ISODate, the string format corresponds to the - ISO 8601 specification for representations of dates, which is - YYYY-MM-DD where YYYY is the year, MM is the month of the year - (between 01 and 12), and DD is the day of the month between 01 and - 31. - - If \a f is \c TQt::LocalDate, the string format depends on the - locale settings of the system. - - If the date is an invalid date, then TQString::null will be returned. - - \sa shortDayName(), shortMonthName() -*/ -TQString TQDate::toString( TQt::DateFormat f ) const -{ - if ( !isValid() ) - return TQString::null; - int y, m, d; - julianToGregorian( jd, y, m, d ); - switch ( f ) { - case TQt::LocalDate: - { -#ifndef TQ_WS_WIN - tm tt; - memset( &tt, 0, sizeof( tm ) ); - char buf[255]; - tt.tm_mday = day(); - tt.tm_mon = month() - 1; - tt.tm_year = year() - 1900; - - static const char * avoidEgcsWarning = "%x"; - if ( strftime( buf, sizeof(buf), avoidEgcsWarning, &tt ) ) - return TQString::fromLocal8Bit( buf ); -#else - SYSTEMTIME st; - memset( &st, 0, sizeof(SYSTEMTIME) ); - st.wYear = year(); - st.wMonth = month(); - st.wDay = day(); - QT_WA( { - TCHAR buf[255]; - if ( GetDateFormat( LOCALE_USER_DEFAULT, 0, &st, 0, buf, 255 ) ) - return TQString::fromUcs2( (ushort*)buf ); - } , { - char buf[255]; - if ( GetDateFormatA( LOCALE_USER_DEFAULT, 0, &st, 0, (char*)&buf, 255 ) ) - return TQString::fromLocal8Bit( buf ); - } ); -#endif - return TQString::null; - } - default: -#ifndef TQT_NO_TEXTDATE - case TQt::TextDate: - { - TQString buf = shortDayName( dayOfWeek() ); - buf += ' '; - buf += shortMonthName( m ); - TQString t; - t.sprintf( " %d %d", d, y ); - buf += t; - return buf; - } -#endif - case TQt::ISODate: - { - TQString month( TQString::number( m ).rightJustify( 2, '0' ) ); - TQString day( TQString::number( d ).rightJustify( 2, '0' ) ); - return TQString::number( y ) + "-" + month + "-" + day; - } - } -} -#endif //TQT_NO_SPRINTF - -/*! - Returns the date as a string. The \a format parameter determines - the format of the result string. - - These expressions may be used: - - \table - \header \i Expression \i Output - \row \i d \i the day as number without a leading zero (1-31) - \row \i dd \i the day as number with a leading zero (01-31) - \row \i ddd - \i the abbreviated localized day name (e.g. 'Mon'..'Sun'). - Uses TQDate::shortDayName(). - \row \i dddd - \i the long localized day name (e.g. 'Monday'..'Sunday'). - Uses TQDate::longDayName(). - \row \i M \i the month as number without a leading zero (1-12) - \row \i MM \i the month as number with a leading zero (01-12) - \row \i MMM - \i the abbreviated localized month name (e.g. 'Jan'..'Dec'). - Uses TQDate::shortMonthName(). - \row \i MMMM - \i the long localized month name (e.g. 'January'..'December'). - Uses TQDate::longMonthName(). - \row \i yy \i the year as two digit number (00-99) - \row \i yyyy \i the year as four digit number (1752-8000) - \endtable - - All other input characters will be ignored. - - Example format strings (assuming that the TQDate is the - 20th July 1969): - \table - \header \i Format \i Result - \row \i dd.MM.yyyy \i11 20.07.1969 - \row \i ddd MMMM d yy \i11 Sun July 20 69 - \endtable - - If the date is an invalid date, then TQString::null will be returned. - - \sa TQDateTime::toString() TQTime::toString() - -*/ -TQString TQDate::toString( const TQString& format ) const -{ - return fmtDateTime( format, 0, this ); -} -#endif //TQT_NO_DATESTRING - -/*! - Sets the date's year \a y, month \a m and day \a d. - - \a y must be in the range 1752..8000, \a m must be in the range - 1..12, and \a d must be in the range 1..31. - - \warning If \a y is in the range 0..99, it is interpreted as - 1900..1999. - - Returns TRUE if the date is valid; otherwise returns FALSE. -*/ - -bool TQDate::setYMD( int y, int m, int d ) -{ - if ( year() == y && month() == m && day() == d ) - return isValid(); - if ( !isValid(y,m,d) ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQDate::setYMD: Invalid date %04d-%02d-%02d", y, m, d ); -#endif - return FALSE; - } - jd = gregorianToJulian( y, m, d ); - return TRUE; -} - -/*! - Returns a TQDate object containing a date \a ndays later than the - date of this object (or earlier if \a ndays is negative). - - \sa addMonths() addYears() daysTo() -*/ - -TQDate TQDate::addDays( int ndays ) const -{ - TQDate d; - d.jd = jd + ndays; - return d; -} - -/*! - Returns a TQDate object containing a date \a nmonths later than the - date of this object (or earlier if \a nmonths is negative). - - \sa addDays() addYears() -*/ - -TQDate TQDate::addMonths( int nmonths ) const -{ - int y, m, d; - julianToGregorian( jd, y, m, d ); - - while ( nmonths != 0 ) { - if ( nmonths < 0 && nmonths + 12 <= 0 ) { - y--; - nmonths+=12; - } else if ( nmonths < 0 ) { - m+= nmonths; - nmonths = 0; - if ( m <= 0 ) { - --y; - m+=12; - } - } else if ( nmonths - 12 >= 0 ) { - y++; - nmonths-=12; - } else if ( m == 12 ) { - y++; - m = 0; - } else { - m+= nmonths; - nmonths = 0; - if ( m > 12 ) { - ++y; - m -= 12; - } - } - } - - TQDate tmp(y,m,1); - - if( d > tmp.daysInMonth() ) - d = tmp.daysInMonth(); - - TQDate date(y, m, d); - return date; - -} - -/*! - Returns a TQDate object containing a date \a nyears later than the - date of this object (or earlier if \a nyears is negative). - - \sa addDays(), addMonths() -*/ - -TQDate TQDate::addYears( int nyears ) const -{ - int y, m, d; - julianToGregorian( jd, y, m, d ); - y += nyears; - - TQDate tmp(y,m,1); - - if( d > tmp.daysInMonth() ) - d = tmp.daysInMonth(); - - TQDate date(y, m, d); - return date; -} - - - -/*! - Returns the number of days from this date to \a d (which is - negative if \a d is earlier than this date). - - Example: - \code - TQDate d1( 1995, 5, 17 ); // May 17th 1995 - TQDate d2( 1995, 5, 20 ); // May 20th 1995 - d1.daysTo( d2 ); // returns 3 - d2.daysTo( d1 ); // returns -3 - \endcode - - \sa addDays() -*/ - -int TQDate::daysTo( const TQDate &d ) const -{ - return d.jd - jd; -} - - -/*! - \fn bool TQDate::operator==( const TQDate &d ) const - - Returns TRUE if this date is equal to \a d; otherwise returns FALSE. -*/ - -/*! - \fn bool TQDate::operator!=( const TQDate &d ) const - - Returns TRUE if this date is different from \a d; otherwise returns FALSE. -*/ - -/*! - \fn bool TQDate::operator<( const TQDate &d ) const - - Returns TRUE if this date is earlier than \a d, otherwise returns FALSE. -*/ - -/*! - \fn bool TQDate::operator<=( const TQDate &d ) const - - Returns TRUE if this date is earlier than or equal to \a d, - otherwise returns FALSE. -*/ - -/*! - \fn bool TQDate::operator>( const TQDate &d ) const - - Returns TRUE if this date is later than \a d, otherwise returns FALSE. -*/ - -/*! - \fn bool TQDate::operator>=( const TQDate &d ) const - - Returns TRUE if this date is later than or equal to \a d, - otherwise returns FALSE. -*/ - -/*! - \overload - Returns the current date, as reported by the system clock. - - \sa TQTime::currentTime(), TQDateTime::currentDateTime() -*/ - -TQDate TQDate::currentDate() -{ - return currentDate( TQt::LocalTime ); -} - -/*! - Returns the current date, as reported by the system clock, for the - TimeSpec \a ts. The default TimeSpec is LocalTime. - - \sa TQTime::currentTime(), TQDateTime::currentDateTime(), TQt::TimeSpec -*/ -TQDate TQDate::currentDate( TQt::TimeSpec ts ) -{ - TQDate d; -#if defined(Q_OS_WIN32) - SYSTEMTIME t; - memset( &t, 0, sizeof(SYSTEMTIME) ); - if ( ts == TQt::LocalTime ) - GetLocalTime( &t ); - else - GetSystemTime( &t ); - d.jd = gregorianToJulian( t.wYear, t.wMonth, t.wDay ); -#else - // posix compliant system - time_t ltime; - time( <ime ); - tm *t; - -# if defined(TQT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) - // use the reentrant versions of localtime() and gmtime() where available - tm res; - if ( ts == TQt::LocalTime ) - t = localtime_r( <ime, &res ); - else - t = gmtime_r( <ime, &res ); -# else - if ( ts == TQt::LocalTime ) - t = localtime( <ime ); - else - t = gmtime( <ime ); -# endif // TQT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS - - d.jd = gregorianToJulian( t->tm_year + 1900, t->tm_mon + 1, t->tm_mday ); -#endif - return d; -} - -#ifndef TQT_NO_DATESTRING -/*! - Returns the TQDate represented by the string \a s, using the format - \a f, or an invalid date if the string cannot be parsed. - - Note for \c TQt::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 \c TQt::LocalDate cannot be used here. -*/ -TQDate TQDate::fromString( const TQString& s, TQt::DateFormat f ) -{ - if ( ( s.isEmpty() ) || ( f == TQt::LocalDate ) ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQDate::fromString: Parameter out of range" ); -#endif - TQDate d; - d.jd = 0; - return d; - } - switch ( f ) { - case TQt::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 TQDate( year, month, day ); - } - break; - default: -#ifndef TQT_NO_TEXTDATE - case TQt::TextDate: - { - /* - This will fail gracefully if the input string doesn't - contain any space. - */ - int monthPos = s.find( ' ' ) + 1; - int dayPos = s.find( ' ', monthPos ) + 1; - - TQString monthName( s.mid(monthPos, dayPos - monthPos - 1) ); - int month = -1; - - // try English names first - for ( int i = 0; i < 12; i++ ) { - if ( monthName == qt_shortMonthNames[i] ) { - month = i + 1; - break; - } - } - - // try the localized names - if ( month == -1 ) { - for ( int i = 0; i < 12; i++ ) { - if ( monthName == shortMonthName( i + 1 ) ) { - month = i + 1; - break; - } - } - } -#if defined(QT_CHECK_RANGE) - if ( month < 1 || month > 12 ) { - tqWarning( "TQDate::fromString: Parameter out of range" ); - TQDate d; - d.jd = 0; - return d; - } -#endif - int day = s.mid( dayPos, 2 ).stripWhiteSpace().toInt(); - int year = s.right( 4 ).toInt(); - return TQDate( year, month, day ); - } -#else - break; -#endif - } - return TQDate(); -} -#endif //TQT_NO_DATESTRING - -/*! - \overload - - Returns TRUE if the specified date (year \a y, month \a m and day - \a d) is valid; otherwise returns FALSE. - - Example: - \code - TQDate::isValid( 2002, 5, 17 ); // TRUE May 17th 2002 is valid - TQDate::isValid( 2002, 2, 30 ); // FALSE Feb 30th does not exist - TQDate::isValid( 2004, 2, 29 ); // TRUE 2004 is a leap year - TQDate::isValid( 1202, 6, 6 ); // FALSE 1202 is pre-Gregorian - \endcode - - \warning A \a y value in the range 00..99 is interpreted as - 1900..1999. - - \sa isNull(), setYMD() -*/ - -bool TQDate::isValid( int y, int m, int d ) -{ - if ( y >= 0 && y <= 99 ) - y += 1900; - else if ( y < FIRST_YEAR || (y == FIRST_YEAR && (m < 9 || - (m == 9 && d < 14))) ) - return FALSE; - return (d > 0 && m > 0 && m <= 12) && - (d <= monthDays[m] || (d == 29 && m == 2 && leapYear(y))); -} - -/*! - Returns TRUE if the specified year \a y is a leap year; otherwise - returns FALSE. -*/ - -bool TQDate::leapYear( int y ) -{ - return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0; -} - -/*! - \internal - Converts a Gregorian date to a Julian day. - This algorithm is taken from Communications of the ACM, Vol 6, No 8. - \sa julianToGregorian() -*/ - -uint TQDate::gregorianToJulian( int y, int m, int d ) -{ - uint c, ya; - if ( y <= 99 ) - y += 1900; - if ( m > 2 ) { - m -= 3; - } else { - m += 9; - y--; - } - c = y; // NOTE: Sym C++ 6.0 bug - c /= 100; - ya = y - 100*c; - return 1721119 + d + (146097*c)/4 + (1461*ya)/4 + (153*m+2)/5; -} - -/*! - \internal - Converts a Julian day to a Gregorian date. - This algorithm is taken from Communications of the ACM, Vol 6, No 8. - \sa gregorianToJulian() -*/ - -void TQDate::julianToGregorian( uint jd, int &y, int &m, int &d ) -{ - uint x; - uint j = jd - 1721119; - y = (j*4 - 1)/146097; - j = j*4 - 146097*y - 1; - x = j/4; - j = (x*4 + 3) / 1461; - y = 100*y + j; - x = (x*4) + 3 - 1461*j; - x = (x + 4)/4; - m = (5*x - 3)/153; - x = 5*x - 3 - 153*m; - d = (x + 5)/5; - if ( m < 10 ) { - m += 3; - } else { - m -= 9; - y++; - } -} - - -/***************************************************************************** - TQTime member functions - *****************************************************************************/ - -/*! - \class TQTime ntqdatetime.h - \reentrant - - \brief The TQTime class provides clock time functions. - - \ingroup time - \mainclass - - A TQTime object contains a clock time, i.e. the number of hours, - minutes, seconds, and milliseconds since midnight. It can read the - current time from the system clock and measure a span of elapsed - time. It provides functions for comparing times and for - manipulating a time by adding a number of (milli)seconds. - - TQTime uses the 24-hour clock format; it has no concept of AM/PM. - It operates in local time; it knows nothing about time zones or - daylight savings time. - - A TQTime object is typically created either by giving the number of - hours, minutes, seconds, and milliseconds explicitly, or by using - the static function currentTime(), which creates a TQTime object - that contains the system's clock time. Note that the accuracy - depends on the accuracy of the underlying operating system; not - all systems provide 1-millisecond accuracy. - - The hour(), minute(), second(), and msec() functions provide - access to the number of hours, minutes, seconds, and milliseconds - of the time. The same information is provided in textual format by - the toString() function. - - TQTime provides a full set of operators to compare two TQTime - objects. One time is considered smaller than another if it is - earlier than the other. - - The time a given number of seconds or milliseconds later than a - given time can be found using the addSecs() or addMSecs() - functions. Correspondingly, the number of (milli)seconds between - two times can be found using the secsTo() or msecsTo() functions. - - TQTime can be used to measure a span of elapsed time using the - start(), restart(), and elapsed() functions. - - \sa TQDate, TQDateTime -*/ - -/*! - \fn TQTime::TQTime() - - Constructs the time 0 hours, minutes, seconds and milliseconds, - i.e. 00:00:00.000 (midnight). This is a valid time. - - \sa isValid() -*/ - -/*! - Constructs a time with hour \a h, minute \a m, seconds \a s and - milliseconds \a ms. - - \a h must be in the range 0..23, \a m and \a s must be in the - range 0..59, and \a ms must be in the range 0..999. - - \sa isValid() -*/ - -TQTime::TQTime( int h, int m, int s, int ms ) -{ - setHMS( h, m, s, ms ); -} - - -/*! - \fn bool TQTime::isNull() const - - Returns TRUE if the time is equal to 00:00:00.000; otherwise - returns FALSE. A null time is valid. - - \sa isValid() -*/ - -/*! - Returns TRUE if the time is valid; otherwise returns FALSE. The - time 23:30:55.746 is valid, whereas 24:12:30 is invalid. - - \sa isNull() -*/ - -bool TQTime::isValid() const -{ - return ds < MSECS_PER_DAY; -} - - -/*! - Returns the hour part (0..23) of the time. -*/ - -int TQTime::hour() const -{ - return ds / MSECS_PER_HOUR; -} - -/*! - Returns the minute part (0..59) of the time. -*/ - -int TQTime::minute() const -{ - return (ds % MSECS_PER_HOUR)/MSECS_PER_MIN; -} - -/*! - Returns the second part (0..59) of the time. -*/ - -int TQTime::second() const -{ - return (ds / 1000)%SECS_PER_MIN; -} - -/*! - Returns the millisecond part (0..999) of the time. -*/ - -int TQTime::msec() const -{ - return ds % 1000; -} - -#ifndef TQT_NO_DATESTRING -#ifndef TQT_NO_SPRINTF -/*! - \overload - - Returns the time as a string. Milliseconds are not included. The - \a f parameter determines the format of the string. - - If \a f is \c TQt::TextDate, the string format is HH:MM:SS; e.g. 1 - second before midnight would be "23:59:59". - - If \a f is \c TQt::ISODate, the string format corresponds to the - ISO 8601 extended specification for representations of dates, - which is also HH:MM:SS. - - If \a f is TQt::LocalDate, the string format depends on the locale - settings of the system. - - If the time is an invalid time, then TQString::null will be returned. -*/ - -TQString TQTime::toString( TQt::DateFormat f ) const -{ - if ( !isValid() ) - return TQString::null; - - switch ( f ) { - case TQt::LocalDate: - { -#ifndef TQ_WS_WIN - tm tt; - memset( &tt, 0, sizeof( tm ) ); - char buf[255]; - tt.tm_sec = second(); - tt.tm_min = minute(); - tt.tm_hour = hour(); - if ( strftime( buf, sizeof(buf), "%X", &tt ) ) - return TQString::fromLocal8Bit( buf ); -#else - SYSTEMTIME st; - memset( &st, 0, sizeof(SYSTEMTIME) ); - st.wHour = hour(); - st.wMinute = minute(); - st.wSecond = second(); - st.wMilliseconds = 0; - QT_WA( { - TCHAR buf[255]; - if ( GetTimeFormat( LOCALE_USER_DEFAULT, 0, &st, 0, buf, 255 ) ) - return TQString::fromUcs2( (ushort*)buf ); - } , { - char buf[255]; - if ( GetTimeFormatA( LOCALE_USER_DEFAULT, 0, &st, 0, (char*)&buf, 255 ) ) - return TQString::fromLocal8Bit( buf ); - } ); -#endif - return TQString::null; - } - default: - case TQt::ISODate: - case TQt::TextDate: - TQString buf; - buf.sprintf( "%.2d:%.2d:%.2d", hour(), minute(), second() ); - return buf; - } -} -#endif - -/*! - Returns the time as a string. The \a format parameter determines - the format of the result string. - - These expressions may be used: - - \table - \header \i Expression \i Output - \row \i h - \i the hour without a leading zero (0..23 or 1..12 if AM/PM display) - \row \i hh - \i the hour with a leading zero (00..23 or 01..12 if AM/PM display) - \row \i m \i the minute without a leading zero (0..59) - \row \i mm \i the minute with a leading zero (00..59) - \row \i s \i the second whithout a leading zero (0..59) - \row \i ss \i the second whith a leading zero (00..59) - \row \i z \i the milliseconds without leading zeroes (0..999) - \row \i zzz \i the milliseconds with leading zeroes (000..999) - \row \i AP - \i use AM/PM display. \e AP will be replaced by either "AM" or "PM". - \row \i ap - \i use am/pm display. \e ap will be replaced by either "am" or "pm". - \endtable - - All other input characters will be ignored. - - Example format strings (assuming that the TQTime is 14:13:09.042) - - \table - \header \i Format \i Result - \row \i hh:mm:ss.zzz \i11 14:13:09.042 - \row \i h:m:s ap \i11 2:13:9 pm - \endtable - - If the time is an invalid time, then TQString::null will be returned. - - \sa TQDate::toString() TQDateTime::toString() -*/ -TQString TQTime::toString( const TQString& format ) const -{ - return fmtDateTime( format, this, 0 ); -} -#endif //TQT_NO_DATESTRING -/*! - Sets the time to hour \a h, minute \a m, seconds \a s and - milliseconds \a ms. - - \a h must be in the range 0..23, \a m and \a s must be in the - range 0..59, and \a ms must be in the range 0..999. Returns TRUE - if the set time is valid; otherwise returns FALSE. - - \sa isValid() -*/ - -bool TQTime::setHMS( int h, int m, int s, int ms ) -{ - if ( !isValid(h,m,s,ms) ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQTime::setHMS Invalid time %02d:%02d:%02d.%03d", h, m, s, - ms ); -#endif - ds = MSECS_PER_DAY; // make this invalid - return FALSE; - } - ds = (h*SECS_PER_HOUR + m*SECS_PER_MIN + s)*1000 + ms; - return TRUE; -} - -/*! - Returns a TQTime object containing a time \a nsecs seconds later - than the time of this object (or earlier if \a nsecs is negative). - - Note that the time will wrap if it passes midnight. - - Example: - \code - TQTime n( 14, 0, 0 ); // n == 14:00:00 - TQTime t; - t = n.addSecs( 70 ); // t == 14:01:10 - t = n.addSecs( -70 ); // t == 13:58:50 - t = n.addSecs( 10*60*60 + 5 ); // t == 00:00:05 - t = n.addSecs( -15*60*60 ); // t == 23:00:00 - \endcode - - \sa addMSecs(), secsTo(), TQDateTime::addSecs() -*/ - -TQTime TQTime::addSecs( int nsecs ) const -{ - return addMSecs( nsecs * 1000 ); -} - -/*! - Returns the number of seconds from this time to \a t (which is - negative if \a t is earlier than this time). - - Because TQTime measures time within a day and there are 86400 - seconds in a day, the result is always between -86400 and 86400. - - \sa addSecs() TQDateTime::secsTo() -*/ - -int TQTime::secsTo( const TQTime &t ) const -{ - return ((int)t.ds - (int)ds)/1000; -} - -/*! - Returns a TQTime object containing a time \a ms milliseconds later - than the time of this object (or earlier if \a ms is negative). - - Note that the time will wrap if it passes midnight. See addSecs() - for an example. - - \sa addSecs(), msecsTo() -*/ - -TQTime TQTime::addMSecs( int ms ) const -{ - TQTime t; - if ( ms < 0 ) { - // % not well-defined for -ve, but / is. - int negdays = (MSECS_PER_DAY-ms) / MSECS_PER_DAY; - t.ds = ((int)ds + ms + negdays*MSECS_PER_DAY) - % MSECS_PER_DAY; - } else { - t.ds = ((int)ds + ms) % MSECS_PER_DAY; - } - return t; -} - -/*! - Returns the number of milliseconds from this time to \a t (which - is negative if \a t is earlier than this time). - - Because TQTime measures time within a day and there are 86400 - seconds in a day, the result is always between -86400000 and - 86400000 msec. - - \sa secsTo() -*/ - -int TQTime::msecsTo( const TQTime &t ) const -{ - return (int)t.ds - (int)ds; -} - - -/*! - \fn bool TQTime::operator==( const TQTime &t ) const - - Returns TRUE if this time is equal to \a t; otherwise returns FALSE. -*/ - -/*! - \fn bool TQTime::operator!=( const TQTime &t ) const - - Returns TRUE if this time is different from \a t; otherwise returns FALSE. -*/ - -/*! - \fn bool TQTime::operator<( const TQTime &t ) const - - Returns TRUE if this time is earlier than \a t; otherwise returns FALSE. -*/ - -/*! - \fn bool TQTime::operator<=( const TQTime &t ) const - - Returns TRUE if this time is earlier than or equal to \a t; - otherwise returns FALSE. -*/ - -/*! - \fn bool TQTime::operator>( const TQTime &t ) const - - Returns TRUE if this time is later than \a t; otherwise returns FALSE. -*/ - -/*! - \fn bool TQTime::operator>=( const TQTime &t ) const - - Returns TRUE if this time is later than or equal to \a t; - otherwise returns FALSE. -*/ - - - -/*! - \overload - - Returns the current time as reported by the system clock. - - Note that the accuracy depends on the accuracy of the underlying - operating system; not all systems provide 1-millisecond accuracy. -*/ - -TQTime TQTime::currentTime() -{ - return currentTime( TQt::LocalTime ); -} - -/*! - Returns the current time as reported by the system clock, for the - TimeSpec \a ts. The default TimeSpec is LocalTime. - - Note that the accuracy depends on the accuracy of the underlying - operating system; not all systems provide 1-millisecond accuracy. - - \sa TQt::TimeSpec -*/ -TQTime TQTime::currentTime( TQt::TimeSpec ts ) -{ - TQTime t; - currentTime( &t, ts ); - return t; -} - -#ifndef TQT_NO_DATESTRING -/*! - Returns the representation \a s as a TQTime using the format \a f, - or an invalid time if this is not possible. - - \warning Note that \c TQt::LocalDate cannot be used here. -*/ -TQTime TQTime::fromString( const TQString& s, TQt::DateFormat f ) -{ - if ( ( s.isEmpty() ) || ( f == TQt::LocalDate ) ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQTime::fromString: Parameter out of range" ); -#endif - TQTime t; - t.ds = MSECS_PER_DAY; - return t; - } - - int hour( s.mid( 0, 2 ).toInt() ); - int minute( s.mid( 3, 2 ).toInt() ); - int second( s.mid( 6, 2 ).toInt() ); - int msec( s.mid( 9, 3 ).toInt() ); - return TQTime( hour, minute, second, msec ); -} -#endif - -/*! - \internal - \obsolete - - Fetches the current time and returns TRUE if the time is within one - minute after midnight, otherwise FALSE. The return value is used by - TQDateTime::currentDateTime() to ensure that the date there is correct. -*/ - -bool TQTime::currentTime( TQTime *ct ) -{ - return currentTime( ct, TQt::LocalTime ); -} - - -/*! - \internal - - Fetches the current time, for the TimeSpec \a ts, and returns TRUE - if the time is within one minute after midnight, otherwise FALSE. The - return value is used by TQDateTime::currentDateTime() to ensure that - the date there is correct. The default TimeSpec is LocalTime. - - \sa TQt::TimeSpec -*/ -bool TQTime::currentTime( TQTime *ct, TQt::TimeSpec ts ) -{ - if ( !ct ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQTime::currentTime(TQTime *): Null pointer not allowed" ); -#endif - return FALSE; - } - -#if defined(Q_OS_WIN32) - SYSTEMTIME t; - if ( ts == TQt::LocalTime ) { - GetLocalTime( &t ); - } else { - GetSystemTime( &t ); - } - ct->ds = (uint)( MSECS_PER_HOUR*t.wHour + MSECS_PER_MIN*t.wMinute + - 1000*t.wSecond + t.wMilliseconds ); -#elif defined(Q_OS_UNIX) - // posix compliant system - struct timeval tv; - gettimeofday( &tv, 0 ); - time_t ltime = tv.tv_sec; - tm *t; - -# if defined(TQT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) - // use the reentrant versions of localtime() and gmtime() where available - tm res; - if ( ts == TQt::LocalTime ) - t = localtime_r( <ime, &res ); - else - t = gmtime_r( <ime, &res ); -# else - if ( ts == TQt::LocalTime ) - t = localtime( <ime ); - else - t = gmtime( <ime ); -# endif // TQT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS - - ct->ds = (uint)( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + - 1000 * t->tm_sec + tv.tv_usec / 1000 ); -#else - time_t ltime; // no millisecond resolution - ::time( <ime ); - tm *t; - if ( ts == TQt::LocalTime ) - localtime( <ime ); - else - gmtime( <ime ); - ct->ds = (uint) ( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + - 1000 * t->tm_sec ); -#endif - // 00:00.00 to 00:00.59.999 is considered as "midnight or right after" - return ct->ds < (uint) MSECS_PER_MIN; -} - -/*! - \overload - - Returns TRUE if the specified time is valid; otherwise returns - FALSE. - - The time is valid if \a h is in the range 0..23, \a m and \a s are - in the range 0..59, and \a ms is in the range 0..999. - - Example: - \code - TQTime::isValid(21, 10, 30); // returns TRUE - TQTime::isValid(22, 5, 62); // returns FALSE - \endcode -*/ - -bool TQTime::isValid( int h, int m, int s, int ms ) -{ - return (uint)h < 24 && (uint)m < 60 && (uint)s < 60 && (uint)ms < 1000; -} - - -/*! - Sets this time to the current time. This is practical for timing: - - \code - TQTime t; - t.start(); - some_lengthy_task(); - tqDebug( "Time elapsed: %d ms", t.elapsed() ); - \endcode - - \sa restart(), elapsed(), currentTime() -*/ - -void TQTime::start() -{ - *this = currentTime(); -} - -/*! - Sets this time to the current time and returns the number of - milliseconds that have elapsed since the last time start() or - restart() was called. - - This function is guaranteed to be atomic and is thus very handy - for repeated measurements. Call start() to start the first - measurement and then restart() for each later measurement. - - Note that the counter wraps to zero 24 hours after the last call - to start() or restart(). - - \warning If the system's clock setting has been changed since the - last time start() or restart() was called, the result is - undefined. This can happen when daylight savings time is turned on - or off. - - \sa start(), elapsed(), currentTime() -*/ - -int TQTime::restart() -{ - TQTime t = currentTime(); - int n = msecsTo( t ); - if ( n < 0 ) // passed midnight - n += 86400*1000; - *this = t; - return n; -} - -/*! - Returns the number of milliseconds that have elapsed since the - last time start() or restart() was called. - - Note that the counter wraps to zero 24 hours after the last call - to start() or restart. - - Note that the accuracy depends on the accuracy of the underlying - operating system; not all systems provide 1-millisecond accuracy. - - \warning If the system's clock setting has been changed since the - last time start() or restart() was called, the result is - undefined. This can happen when daylight savings time is turned on - or off. - - \sa start(), restart() -*/ - -int TQTime::elapsed() const -{ - int n = msecsTo( currentTime() ); - if ( n < 0 ) // passed midnight - n += 86400*1000; - return n; -} - - -/***************************************************************************** - TQDateTime member functions - *****************************************************************************/ - -/*! - \class TQDateTime ntqdatetime.h - \reentrant - \brief The TQDateTime class provides date and time functions. - - \ingroup time - \mainclass - - A TQDateTime object contains a calendar date and a clock time (a - "datetime"). It is a combination of the TQDate and TQTime classes. - It can read the current datetime from the system clock. It - provides functions for comparing datetimes and for manipulating a - datetime by adding a number of seconds, days, months or years. - - A TQDateTime object is typically created either by giving a date - and time explicitly in the constructor, or by using the static - function currentDateTime(), which returns a TQDateTime object set - to the system clock's time. The date and time can be changed with - setDate() and setTime(). A datetime can also be set using the - setTime_t() function, which takes a POSIX-standard "number of - seconds since 00:00:00 on January 1, 1970" value. The fromString() - function returns a TQDateTime given a string and a date format - which is used to interpret the date within the string. - - The date() and time() functions provide access to the date and - time parts of the datetime. The same information is provided in - textual format by the toString() function. - - TQDateTime provides a full set of operators to compare two - TQDateTime objects where smaller means earlier and larger means - later. - - You can increment (or decrement) a datetime by a given number of - seconds using addSecs() or days using addDays(). Similarly you can - use addMonths() and addYears(). The daysTo() function returns the - number of days between two datetimes, and secsTo() returns the - number of seconds between two datetimes. - - The range of a datetime object is constrained to the ranges of the - TQDate and TQTime objects which it embodies. - - \sa TQDate TQTime TQDateTimeEdit -*/ - - -/*! - \fn TQDateTime::TQDateTime() - - Constructs a null datetime (i.e. null date and null time). A null - datetime is invalid, since the date is invalid. - - \sa isValid() -*/ - - -/*! - Constructs a datetime with date \a date and null (but valid) time - (00:00:00.000). -*/ - -TQDateTime::TQDateTime( const TQDate &date ) - : d(date) -{ -} - -/*! - Constructs a datetime with date \a date and time \a time. -*/ - -TQDateTime::TQDateTime( const TQDate &date, const TQTime &time ) - : d(date), t(time) -{ -} - - -/*! - \fn bool TQDateTime::isNull() const - - Returns TRUE if both the date and the time are null; otherwise - returns FALSE. A null datetime is invalid. - - \sa TQDate::isNull(), TQTime::isNull() -*/ - -/*! - \fn bool TQDateTime::isValid() const - - Returns TRUE if both the date and the time are valid; otherwise - returns FALSE. - - \sa TQDate::isValid(), TQTime::isValid() -*/ - -/*! - \fn TQDate TQDateTime::date() const - - Returns the date part of the datetime. - - \sa setDate(), time() -*/ - -/*! - \fn TQTime TQDateTime::time() const - - Returns the time part of the datetime. - - \sa setTime(), date() -*/ - -/*! - \fn void TQDateTime::setDate( const TQDate &date ) - - Sets the date part of this datetime to \a date. - - \sa date(), setTime() -*/ - -/*! - \fn void TQDateTime::setTime( const TQTime &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() -*/ - -time_t TQDateTime::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; - time_t secsSince1Jan1970UTC = mktime( &brokenDown ); - if ( secsSince1Jan1970UTC < -1 ) - secsSince1Jan1970UTC = -1; - return secsSince1Jan1970UTC; -} - -/*! - \overload - - Convenience function that sets the date and time to local time - based on the given UTC time. -*/ - -void TQDateTime::setTime_t( time_t secsSince1Jan1970UTC ) -{ - setTime_t( secsSince1Jan1970UTC, TQt::LocalTime ); -} - -/*! - Sets the date and time to \a ts time (\c TQt::LocalTime or \c - TQt::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 TQDateTime::setTime_t( time_t secsSince1Jan1970UTC, TQt::TimeSpec ts ) -{ - time_t tmp = secsSince1Jan1970UTC; - tm *brokenDown = 0; - -#if defined(Q_OS_UNIX) && defined(TQT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) - // posix compliant system - // use the reentrant versions of localtime() and gmtime() where available - tm res; - if ( ts == TQt::LocalTime ) - brokenDown = localtime_r( &tmp, &res ); - if ( !brokenDown ) { - brokenDown = gmtime_r( &tmp, &res ); - if ( !brokenDown ) { - d.jd = TQDate::gregorianToJulian( 1970, 1, 1 ); - t.ds = 0; - return; - } - } -#else - if ( ts == TQt::LocalTime ) - brokenDown = localtime( &tmp ); - if ( !brokenDown ) { - brokenDown = gmtime( &tmp ); - if ( !brokenDown ) { - d.jd = TQDate::gregorianToJulian( 1970, 1, 1 ); - t.ds = 0; - return; - } - } -#endif - - d.jd = TQDate::gregorianToJulian( brokenDown->tm_year + 1900, - brokenDown->tm_mon + 1, - brokenDown->tm_mday ); - t.ds = MSECS_PER_HOUR * brokenDown->tm_hour + - MSECS_PER_MIN * brokenDown->tm_min + - 1000 * brokenDown->tm_sec; -} -#ifndef TQT_NO_DATESTRING -#ifndef TQT_NO_SPRINTF -/*! - \overload - - Returns the datetime as a string. The \a f parameter determines - the format of the string. - - If \a f is \c TQt::TextDate, the string format is "Wed May 20 - 03:40:13 1998" (using TQDate::shortDayName(), TQDate::shortMonthName(), - and TQTime::toString() to generate the string, so the day and month - names will have localized names). - - If \a f is \c TQt::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 TQt::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 TQDate::toString() TQTime::toString() -*/ - -TQString TQDateTime::toString( TQt::DateFormat f ) const -{ - if ( !isValid() ) - return TQString::null; - - if ( f == TQt::ISODate ) { - return d.toString( TQt::ISODate ) + "T" + t.toString( TQt::ISODate ); - } -#ifndef TQT_NO_TEXTDATE - else if ( f == TQt::TextDate ) { -#ifndef TQ_WS_WIN - TQString buf = d.shortDayName( d.dayOfWeek() ); - buf += ' '; - buf += d.shortMonthName( d.month() ); - buf += ' '; - buf += TQString().setNum( d.day() ); - buf += ' '; -#else - TQString buf; - TQString winstr; - QT_WA( { - TCHAR out[255]; - GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_ILDATE, out, 255 ); - winstr = TQString::fromUcs2( (ushort*)out ); - } , { - char out[255]; - GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_ILDATE, (char*)&out, 255 ); - winstr = TQString::fromLocal8Bit( out ); - } ); - switch ( winstr.toInt() ) { - case 1: - buf = d.shortDayName( d.dayOfWeek() ) + " " + TQString().setNum( d.day() ) + ". " + d.shortMonthName( d.month() ) + " "; - break; - default: - buf = d.shortDayName( d.dayOfWeek() ) + " " + d.shortMonthName( d.month() ) + " " + TQString().setNum( d.day() ) + " "; - break; - } -#endif - buf += t.toString(); - buf += ' '; - buf += TQString().setNum( d.year() ); - return buf; - } -#endif - else if ( f == TQt::LocalDate ) { - return d.toString( TQt::LocalDate ) + " " + t.toString( TQt::LocalDate ); - } - return TQString::null; -} -#endif - -/*! - Returns the datetime as a string. The \a format parameter - determines the format of the result string. - - These expressions may be used for the date: - - \table - \header \i Expression \i Output - \row \i d \i the day as number without a leading zero (1-31) - \row \i dd \i the day as number with a leading zero (01-31) - \row \i ddd - \i the abbreviated localized day name (e.g. 'Mon'..'Sun'). - Uses TQDate::shortDayName(). - \row \i dddd - \i the long localized day name (e.g. 'Monday'..'Sunday'). - Uses TQDate::longDayName(). - \row \i M \i the month as number without a leading zero (1-12) - \row \i MM \i the month as number with a leading zero (01-12) - \row \i MMM - \i the abbreviated localized month name (e.g. 'Jan'..'Dec'). - Uses TQDate::shortMonthName(). - \row \i MMMM - \i the long localized month name (e.g. 'January'..'December'). - Uses TQDate::longMonthName(). - \row \i yy \i the year as two digit number (00-99) - \row \i yyyy \i the year as four digit number (1752-8000) - \endtable - - These expressions may be used for the time: - - \table - \header \i Expression \i Output - \row \i h - \i the hour without a leading zero (0..23 or 1..12 if AM/PM display) - \row \i hh - \i the hour with a leading zero (00..23 or 01..12 if AM/PM display) - \row \i m \i the minute without a leading zero (0..59) - \row \i mm \i the minute with a leading zero (00..59) - \row \i s \i the second whithout a leading zero (0..59) - \row \i ss \i the second whith a leading zero (00..59) - \row \i z \i the milliseconds without leading zeroes (0..999) - \row \i zzz \i the milliseconds with leading zeroes (000..999) - \row \i AP - \i use AM/PM display. \e AP will be replaced by either "AM" or "PM". - \row \i ap - \i use am/pm display. \e ap will be replaced by either "am" or "pm". - \endtable - - All other input characters will be ignored. - - Example format strings (assumed that the TQDateTime is - 21st May 2001 14:13:09) - - \table - \header \i Format \i Result - \row \i dd.MM.yyyy \i11 21.05.2001 - \row \i ddd MMMM d yy \i11 Tue May 21 01 - \row \i hh:mm:ss.zzz \i11 14:13:09.042 - \row \i h:m:s ap \i11 2:13:9 pm - \endtable - - If the datetime is an invalid datetime, then TQString::null will be returned. - - \sa TQDate::toString() TQTime::toString() -*/ -TQString TQDateTime::toString( const TQString& format ) const -{ - return fmtDateTime( format, &t, &d ); -} -#endif //TQT_NO_DATESTRING - -/*! - Returns a TQDateTime 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() -*/ - -TQDateTime TQDateTime::addDays( int ndays ) const -{ - return TQDateTime( d.addDays(ndays), t ); -} - -/*! - Returns a TQDateTime 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() -*/ - -TQDateTime TQDateTime::addMonths( int nmonths ) const -{ - return TQDateTime( d.addMonths(nmonths), t ); -} - -/*! - Returns a TQDateTime 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() -*/ - -TQDateTime TQDateTime::addYears( int nyears ) const -{ - return TQDateTime( d.addYears(nyears), t ); -} - -/*! - Returns a TQDateTime 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() -*/ - -TQDateTime TQDateTime::addSecs( int nsecs ) const -{ - uint dd = d.jd; - int tt = t.ds; - int sign = 1; - if ( nsecs < 0 ) { - nsecs = -nsecs; - sign = -1; - } - if ( nsecs >= (int)SECS_PER_DAY ) { - dd += sign*(nsecs/SECS_PER_DAY); - nsecs %= SECS_PER_DAY; - } - tt += sign*nsecs*1000; - if ( tt < 0 ) { - tt = MSECS_PER_DAY - tt - 1; - dd -= tt / MSECS_PER_DAY; - tt = tt % MSECS_PER_DAY; - tt = MSECS_PER_DAY - tt - 1; - } else if ( tt >= (int)MSECS_PER_DAY ) { - dd += ( tt / MSECS_PER_DAY ); - tt = tt % MSECS_PER_DAY; - } - TQDateTime ret; - ret.t.ds = tt; - ret.d.jd = 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 TQDateTime::daysTo( const TQDateTime &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 - TQDateTime dt = TQDateTime::currentDateTime(); - TQDateTime xmas( TQDate(dt.date().year(),12,24), TQTime(17,00) ); - tqDebug( "There are %d seconds to Christmas", dt.secsTo(xmas) ); - \endcode - - \sa addSecs(), daysTo(), TQTime::secsTo() -*/ - -int TQDateTime::secsTo( const TQDateTime &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 TQDateTime::operator==( const TQDateTime &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 TQDateTime::operator!=( const TQDateTime &dt ) const -{ - return t != dt.t || d != dt.d; -} - -/*! - Returns TRUE if this datetime is earlier than \a dt; otherwise - returns FALSE. -*/ - -bool TQDateTime::operator<( const TQDateTime &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 TQDateTime::operator<=( const TQDateTime &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 TQDateTime::operator>( const TQDateTime &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 TQDateTime::operator>=( const TQDateTime &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 TQDate::currentDate(), TQTime::currentTime() -*/ - -TQDateTime TQDateTime::currentDateTime() -{ - return currentDateTime( TQt::LocalTime ); -} - -/*! - Returns the current datetime, as reported by the system clock, for the - TimeSpec \a ts. The default TimeSpec is LocalTime. - - \sa TQDate::currentDate(), TQTime::currentTime(), TQt::TimeSpec -*/ - -TQDateTime TQDateTime::currentDateTime( TQt::TimeSpec ts ) -{ - TQDateTime dt; - TQTime t; - dt.setDate( TQDate::currentDate(ts) ); - if ( TQTime::currentTime(&t, ts) ) // midnight or right after? - dt.setDate( TQDate::currentDate(ts) ); // fetch date again - dt.setTime( t ); - return dt; -} - -#ifndef TQT_NO_DATESTRING -/*! - Returns the TQDateTime represented by the string \a s, using the - format \a f, or an invalid datetime if this is not possible. - - Note for \c TQt::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 TQt::LocalDate cannot be used here. -*/ -TQDateTime TQDateTime::fromString( const TQString& s, TQt::DateFormat f ) -{ - if ( ( s.isEmpty() ) || ( f == TQt::LocalDate ) ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQDateTime::fromString: Parameter out of range" ); -#endif - TQDateTime dt; - dt.d.jd = 0; - return dt; - } - if ( f == TQt::ISODate ) { - return TQDateTime( TQDate::fromString( s.mid(0,10), TQt::ISODate ), - TQTime::fromString( s.mid(11), TQt::ISODate ) ); - } -#if !defined(TQT_NO_REGEXP) && !defined(TQT_NO_TEXTDATE) - else if ( f == TQt::TextDate ) { - const int firstSpace = s.find(' '); - TQString monthName( s.mid( firstSpace + 1, 3 ) ); - int month = -1; - // Assume that English monthnames are the default - for ( int i = 0; i < 12; ++i ) { - if ( monthName == qt_shortMonthNames[i] ) { - month = i + 1; - break; - } - } - // If English names can't be found, search the localized ones - if ( month == -1 ) { - for ( int i = 1; i <= 12; ++i ) { - if ( monthName == TQDate::shortMonthName( i ) ) { - month = i; - break; - } - } - } -#if defined(QT_CHECK_RANGE) - if ( month < 1 || month > 12 ) { - tqWarning( "TQDateTime::fromString: Parameter out of range" ); - TQDateTime dt; - dt.d.jd = 0; - return dt; - } -#endif - int day = s.mid( firstSpace + 5, 2 ).simplifyWhiteSpace().toInt(); - int year = s.right( 4 ).toInt(); - TQDate date( year, month, day ); - TQTime time; - int hour, minute, second; - int pivot = s.find( TQRegExp(TQString::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 ); - } - return TQDateTime( date, time ); - } -#endif //TQT_NO_REGEXP - return TQDateTime(); -} -#endif //TQT_NO_DATESTRING - - -/***************************************************************************** - Date/time stream functions - *****************************************************************************/ - -#ifndef TQT_NO_DATASTREAM -/*! - \relates TQDate - - Writes the date, \a d, to the data stream, \a s. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator<<( TQDataStream &s, const TQDate &d ) -{ - return s << (TQ_UINT32)(d.jd); -} - -/*! - \relates TQDate - - Reads a date from the stream \a s into \a d. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator>>( TQDataStream &s, TQDate &d ) -{ - TQ_UINT32 jd; - s >> jd; - d.jd = jd; - return s; -} - -/*! - \relates TQTime - - Writes time \a t to the stream \a s. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator<<( TQDataStream &s, const TQTime &t ) -{ - return s << (TQ_UINT32)(t.ds); -} - -/*! - \relates TQTime - - Reads a time from the stream \a s into \a t. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator>>( TQDataStream &s, TQTime &t ) -{ - TQ_UINT32 ds; - s >> ds; - t.ds = ds; - return s; -} - -/*! - \relates TQDateTime - - Writes the datetime \a dt to the stream \a s. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator<<( TQDataStream &s, const TQDateTime &dt ) -{ - return s << dt.d << dt.t; -} - -/*! - \relates TQDateTime - - Reads a datetime from the stream \a s into \a dt. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator>>( TQDataStream &s, TQDateTime &dt ) -{ - s >> dt.d >> dt.t; - return s; -} -#endif //TQT_NO_DATASTREAM diff --git a/src/tools/qfeatures.txt b/src/tools/qfeatures.txt index 6751ce41d..765061ff2 100644 --- a/src/tools/qfeatures.txt +++ b/src/tools/qfeatures.txt @@ -170,7 +170,7 @@ SeeAlso: ??? Feature: DATESTRING Section: Data structures Requires: -Name: QDate/QTime/QDateTime toString() and fromString() +Name: TQDate/TQTime/TQDateTime toString() and fromString() SeeAlso: ??? Feature: ICONSET @@ -1048,7 +1048,7 @@ SeeAlso: ??? Feature: DATETIMEEDIT Section: Widgets Requires: RICHTEXT SPINWIDGET DATESTRING -Name: QDateTimeEdit +Name: TQDateTimeEdit SeeAlso: ??? Feature: TEXTCODECPLUGIN diff --git a/src/tools/qfileinfo.cpp b/src/tools/qfileinfo.cpp index 9ef1462cd..f5e85119b 100644 --- a/src/tools/qfileinfo.cpp +++ b/src/tools/qfileinfo.cpp @@ -41,7 +41,7 @@ #include "qplatformdefs.h" #include "ntqfileinfo.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqdir.h" #include "qfiledefs_p.h" #include "ntqdeepcopy.h" diff --git a/src/tools/qfileinfo_unix.cpp b/src/tools/qfileinfo_unix.cpp index 0a2036053..159b43ae2 100644 --- a/src/tools/qfileinfo_unix.cpp +++ b/src/tools/qfileinfo_unix.cpp @@ -41,7 +41,7 @@ #include "qplatformdefs.h" #include "ntqfileinfo.h" #include "qfiledefs_p.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqdir.h" #include diff --git a/src/tools/qglobal.cpp b/src/tools/qglobal.cpp index 21d433d71..910580f7a 100644 --- a/src/tools/qglobal.cpp +++ b/src/tools/qglobal.cpp @@ -41,7 +41,7 @@ #include "qplatformdefs.h" #include "ntqasciidict.h" -#include +#include #include #include #include diff --git a/src/tools/qt_tools.pri b/src/tools/qt_tools.pri index 54cfd4414..b57e00435 100644 --- a/src/tools/qt_tools.pri +++ b/src/tools/qt_tools.pri @@ -13,7 +13,7 @@ tools { $$TOOLS_P/qcomlibrary_p.h \ $$TOOLS_H/ntqcstring.h \ $$TOOLS_H/ntqdatastream.h \ - $$TOOLS_H/ntqdatetime.h \ + $$TOOLS_H/tqdatetime.h \ $$TOOLS_H/ntqdeepcopy.h \ $$TOOLS_H/ntqdict.h \ $$TOOLS_H/ntqdir.h \ @@ -112,7 +112,7 @@ tools { $$TOOLS_CPP/qcomlibrary.cpp \ $$TOOLS_CPP/qcstring.cpp \ $$TOOLS_CPP/qdatastream.cpp \ - $$TOOLS_CPP/qdatetime.cpp \ + $$TOOLS_CPP/tqdatetime.cpp \ $$TOOLS_CPP/qdeepcopy.cpp \ $$TOOLS_CPP/qdir.cpp \ $$TOOLS_CPP/qfile.cpp \ diff --git a/src/tools/quuid.cpp b/src/tools/quuid.cpp index 15e3b3c6e..34b6e3db7 100644 --- a/src/tools/quuid.cpp +++ b/src/tools/quuid.cpp @@ -401,7 +401,7 @@ TQUuid TQUuid::createUuid() return TQUuid(uuid_string); } #else // !Q_OS_LINUX -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "stdlib.h" // For srand/rand TQUuid TQUuid::createUuid() { diff --git a/src/tools/tqdatetime.cpp b/src/tools/tqdatetime.cpp new file mode 100644 index 000000000..d6f212a12 --- /dev/null +++ b/src/tools/tqdatetime.cpp @@ -0,0 +1,2600 @@ +/**************************************************************************** +** +** Implementation of date and time classes +** +** Created : 940124 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "qplatformdefs.h" + +#include "tqdatetime.h" +#include "ntqdatastream.h" +#include "ntqregexp.h" + +#include +#ifndef Q_OS_TEMP +#include +#endif + +#if defined(Q_OS_WIN32) +#include +#endif + +static const uint FIRST_DAY = 2361222; // Julian day for 1752-09-14 +static const int FIRST_YEAR = 1752; // ### wrong for many countries +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; + +static const short monthDays[] = { + 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + +static const char * const qt_shortMonthNames[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + +#ifndef TQT_NO_DATESTRING +/***************************************************************************** + Some static function used by TQDate, TQTime and TQDateTime + *****************************************************************************/ + +// Replaces tokens by their value. See TQDateTime::toString() for a list of valid tokens +static TQString getFmtString( const TQString& f, const TQTime* dt = 0, const TQDate* dd = 0, bool am_pm = FALSE ) +{ + if ( f.isEmpty() ) + return TQString::null; + + TQString buf = f; + + if ( dt ) { + if ( f == "h" ) { + if ( ( am_pm ) && ( dt->hour() > 12 ) ) + buf = TQString::number( dt->hour() - 12 ); + else if ( ( am_pm ) && ( dt->hour() == 0 ) ) + buf = "12"; + else + buf = TQString::number( dt->hour() ); + } else if ( f == "hh" ) { + if ( ( am_pm ) && ( dt->hour() > 12 ) ) + buf = TQString::number( dt->hour() - 12 ).rightJustify( 2, '0', TRUE ); + else if ( ( am_pm ) && ( dt->hour() == 0 ) ) + buf = "12"; + else + buf = TQString::number( dt->hour() ).rightJustify( 2, '0', TRUE ); + } else if ( f == "m" ) { + buf = TQString::number( dt->minute() ); + } else if ( f == "mm" ) { + buf = TQString::number( dt->minute() ).rightJustify( 2, '0', TRUE ); + } else if ( f == "s" ) { + buf = TQString::number( dt->second() ); + } else if ( f == "ss" ) { + buf = TQString::number( dt->second() ).rightJustify( 2, '0', TRUE ); + } else if ( f == "z" ) { + buf = TQString::number( dt->msec() ); + } else if ( f == "zzz" ) { + buf = TQString::number( dt->msec() ).rightJustify( 3, '0', TRUE ); + } else if ( f == "ap" ) { + buf = dt->hour() < 12 ? "am" : "pm"; + } else if ( f == "AP" ) { + buf = dt->hour() < 12 ? "AM" : "PM"; + } + } + + if ( dd ) { + if ( f == "d" ) { + buf = TQString::number( dd->day() ); + } else if ( f == "dd" ) { + buf = TQString::number( dd->day() ).rightJustify( 2, '0', TRUE ); + } else if ( f == "M" ) { + buf = TQString::number( dd->month() ); + } else if ( f == "MM" ) { + buf = TQString::number( dd->month() ).rightJustify( 2, '0', TRUE ); +#ifndef TQT_NO_TEXTDATE + } else if ( f == "ddd" ) { + buf = dd->shortDayName( dd->dayOfWeek() ); + } else if ( f == "dddd" ) { + buf = dd->longDayName( dd->dayOfWeek() ); + } else if ( f == "MMM" ) { + buf = dd->shortMonthName( dd->month() ); + } else if ( f == "MMMM" ) { + buf = dd->longMonthName( dd->month() ); +#endif + } else if ( f == "yy" ) { + buf = TQString::number( dd->year() ).right( 2 ); + } else if ( f == "yyyy" ) { + buf = TQString::number( dd->year() ); + } + } + + return buf; +} + +// Parses the format string and uses getFmtString to get the values for the tokens. Ret +static TQString fmtDateTime( const TQString& f, const TQTime* dt = 0, const TQDate* dd = 0 ) +{ + if ( f.isEmpty() ) { + return TQString::null; + } + + if ( dt && !dt->isValid() ) + return TQString::null; + if ( dd && !dd->isValid() ) + return TQString::null; + + bool ap = ( f.contains( "AP" ) || f.contains( "ap" ) ); + + TQString buf; + TQString frm; + TQChar status = '0'; + + for ( int i = 0; i < (int)f.length(); ++i ) { + + if ( f[ i ] == status ) { + if ( ( ap ) && ( ( f[ i ] == 'P' ) || ( f[ i ] == 'p' ) ) ) + status = '0'; + frm += f[ i ]; + } else { + buf += getFmtString( frm, dt, dd, ap ); + frm = TQString::null; + if ( ( f[ i ] == 'h' ) || ( f[ i ] == 'm' ) || ( f[ i ] == 's' ) || ( f[ i ] == 'z' ) ) { + status = f[ i ]; + frm += f[ i ]; + } else if ( ( f[ i ] == 'd' ) || ( f[ i ] == 'M' ) || ( f[ i ] == 'y' ) ) { + status = f[ i ]; + frm += f[ i ]; + } else if ( ( ap ) && ( f[ i ] == 'A' ) ) { + status = 'P'; + frm += f[ i ]; + } else if( ( ap ) && ( f[ i ] == 'a' ) ) { + status = 'p'; + frm += f[ i ]; + } else { + buf += f[ i ]; + status = '0'; + } + } + } + + buf += getFmtString( frm, dt, dd, ap ); + + return buf; +} +#endif // TQT_NO_DATESTRING + +/***************************************************************************** + TQDate member functions + *****************************************************************************/ + +/*! + \class TQDate tqdatetime.h + \reentrant + \brief The TQDate class provides date functions. + + \ingroup time + \mainclass + + A TQDate object contains a calendar date, i.e. year, month, and day + numbers, in the modern Western (Gregorian) calendar. It can read + the current date from the system clock. It provides functions for + comparing dates and for manipulating dates, e.g. by adding a + number of days or months or years. + + A TQDate object is typically created either by giving the year, + month and day numbers explicitly, or by using the static function + currentDate(), which creates a TQDate object containing the system + clock's date. An explicit date can also be set using setYMD(). The + fromString() function returns a TQDate given a string and a date + format which is used to interpret the date within the string. + + The year(), month(), and day() functions provide access to the + year, month, and day numbers. Also, dayOfWeek() and dayOfYear() + functions are provided. The same information is provided in + textual format by the toString(), shortDayName(), longDayName(), + shortMonthName() and longMonthName() functions. + + TQDate provides a full set of operators to compare two TQDate + objects where smaller means earlier and larger means later. + + You can increment (or decrement) a date by a given number of days + using addDays(). Similarly you can use addMonths() and addYears(). + The daysTo() function returns the number of days between two + dates. + + The daysInMonth() and daysInYear() functions return how many days + there are in this date's month and year, respectively. The + leapYear() function indicates whether this date is in a leap year. + + Note that TQDate should not be used for date calculations for dates + prior to the introduction of the Gregorian calendar. This calendar + was adopted by England from the 14th + September 1752 (hence this is the earliest valid TQDate), and + subsequently by most other Western countries, until 1923. + + The end of time is reached around the year 8000, by which time we + expect TQt to be obsolete. + + \sa TQTime TQDateTime TQDateEdit TQDateTimeEdit +*/ + +/*! + \enum TQt::DateFormat + + \value TextDate (default) TQt format + \value ISODate ISO 8601 extended format (YYYY-MM-DD, or with time, + YYYY-MM-DDTHH:MM:SS) + \value LocalDate locale dependent format +*/ + + +/*! + \enum TQt::TimeSpec + + \value LocalTime Locale dependent time (Timezones and Daylight Savings Time) + \value UTC Coordinated Universal Time, replaces Greenwich Time +*/ + +/*! + \fn TQDate::TQDate() + + Constructs a null date. Null dates are invalid. + + \sa isNull(), isValid() +*/ + + +/*! + Constructs a date with year \a y, month \a m and day \a d. + + \a y must be in the range 1752..8000, \a m must be in the range + 1..12, and \a d must be in the range 1..31. + + \warning If \a y is in the range 0..99, it is interpreted as + 1900..1999. + + \sa isValid() +*/ + +TQDate::TQDate( int y, int m, int d ) +{ + jd = 0; + setYMD( y, m, d ); +} + + +/*! + \fn bool TQDate::isNull() const + + Returns TRUE if the date is null; otherwise returns FALSE. A null + date is invalid. + + \sa isValid() +*/ + + +/*! + Returns TRUE if this date is valid; otherwise returns FALSE. + + \sa isNull() +*/ + +bool TQDate::isValid() const +{ + return jd >= FIRST_DAY; +} + + +/*! + Returns the year (1752..8000) of this date. + + \sa month(), day() +*/ + +int TQDate::year() const +{ + int y, m, d; + julianToGregorian( jd, y, m, d ); + return y; +} + +/*! + Returns the month (January=1..December=12) of this date. + + \sa year(), day() +*/ + +int TQDate::month() const +{ + int y, m, d; + julianToGregorian( jd, y, m, d ); + return m; +} + +/*! + Returns the day of the month (1..31) of this date. + + \sa year(), month(), dayOfWeek() +*/ + +int TQDate::day() const +{ + int y, m, d; + julianToGregorian( jd, y, m, d ); + return d; +} + +/*! + Returns the weekday (Monday=1..Sunday=7) for this date. + + \sa day(), dayOfYear() +*/ + +int TQDate::dayOfWeek() const +{ + return ( jd % 7 ) + 1; +} + +/*! + Returns the day of the year (1..365) for this date. + + \sa day(), dayOfWeek() +*/ + +int TQDate::dayOfYear() const +{ + return jd - gregorianToJulian(year(), 1, 1) + 1; +} + +/*! + Returns the number of days in the month (28..31) for this date. + + \sa day(), daysInYear() +*/ + +int TQDate::daysInMonth() const +{ + int y, m, d; + julianToGregorian( jd, y, m, d ); + if ( m == 2 && leapYear(y) ) + return 29; + else + return monthDays[m]; +} + +/*! + Returns the number of days in the year (365 or 366) for this date. + + \sa day(), daysInMonth() +*/ + +int TQDate::daysInYear() const +{ + int y, m, d; + julianToGregorian( jd, y, m, d ); + return leapYear( y ) ? 366 : 365; +} + +/*! + Returns the week number (1 to 53), and stores the year in \a + *yearNumber unless \a yearNumber is null (the default). + + Returns 0 if the date is invalid. + + In accordance with ISO 8601, weeks start on Monday and the first + Thursday of a year is always in week 1 of that year. Most years + have 52 weeks, but some have 53. + + \a *yearNumber is not always the same as year(). For example, 1 + January 2000 has week number 52 in the year 1999, and 31 December + 2002 has week number 1 in the year 2003. + + \legalese + + Copyright (c) 1989 The Regents of the University of California. + All rights reserved. + + Redistribution and use in source and binary forms are permitted + provided that the above copyright notice and this paragraph are + duplicated in all such forms and that any documentation, + advertising materials, and other materials related to such + distribution and use acknowledge that the software was developed + by the University of California, Berkeley. The name of the + University may not be used to endorse or promote products derived + from this software without specific prior written permission. + THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + + \sa isValid() +*/ + +int TQDate::weekNumber( int *yearNumber ) const +{ + if ( !isValid() ) + return 0; + + int year = TQDate::year(); + int yday = dayOfYear() - 1; + int wday = dayOfWeek(); + if (wday == 7) + wday = 0; + int w; + + for (;;) { + int len; + int bot; + int top; + + len = leapYear(year) ? 366 : 365; + /* + ** What yday (-3 ... 3) does + ** the ISO year begin on? + */ + bot = ((yday + 11 - wday) % 7) - 3; + /* + ** What yday does the NEXT + ** ISO year begin on? + */ + top = bot - (len % 7); + if (top < -3) + top += 7; + top += len; + if (yday >= top) { + ++year; + w = 1; + break; + } + if (yday >= bot) { + w = 1 + ((yday - bot) / 7); + break; + } + --year; + yday += leapYear(year) ? 366 : 365; + } + if (yearNumber != 0) + *yearNumber = year; + return w; +} + +/*! + \fn TQString TQDate::monthName( int month ) + \obsolete + + Use shortMonthName() instead. +*/ +#ifndef TQT_NO_TEXTDATE +/*! + Returns the name of the \a month. + + 1 = "Jan", 2 = "Feb", ... 12 = "Dec" + + The month names will be localized according to the system's locale + settings. + + \sa toString(), longMonthName(), shortDayName(), longDayName() +*/ + +TQString TQDate::shortMonthName( int month ) +{ +#if defined(QT_CHECK_RANGE) + if ( month < 1 || month > 12 ) { + tqWarning( "TQDate::shortMonthName: Parameter out ouf range" ); + month = 1; + } +#endif +#ifndef TQ_WS_WIN + char buffer[255]; + tm tt; + memset( &tt, 0, sizeof( tm ) ); + tt.tm_mon = month - 1; + if ( strftime( buffer, sizeof( buffer ), "%b", &tt ) ) + return TQString::fromLocal8Bit( buffer ); +#else + SYSTEMTIME st; + memset( &st, 0, sizeof(SYSTEMTIME) ); + st.wYear = 2000; + st.wMonth = month; + st.wDay = 1; + const wchar_t mmm_t[] = L"MMM"; // workaround for Borland + QT_WA( { + TCHAR buf[255]; + if ( GetDateFormat( LOCALE_USER_DEFAULT, 0, &st, mmm_t, buf, 255 ) ) + return TQString::fromUcs2( (ushort*)buf ); + } , { + char buf[255]; + if ( GetDateFormatA( LOCALE_USER_DEFAULT, 0, &st, "MMM", (char*)&buf, 255 ) ) + return TQString::fromLocal8Bit( buf ); + } ); +#endif + return TQString::null; +} + +/*! + Returns the long name of the \a month. + + 1 = "January", 2 = "February", ... 12 = "December" + + The month names will be localized according to the system's locale + settings. + + \sa toString(), shortMonthName(), shortDayName(), longDayName() +*/ + +TQString TQDate::longMonthName( int month ) +{ +#if defined(QT_CHECK_RANGE) + if ( month < 1 || month > 12 ) { + tqWarning( "TQDate::longMonthName: Parameter out ouf range" ); + month = 1; + } +#endif +#ifndef TQ_WS_WIN + char buffer[255]; + tm tt; + memset( &tt, 0, sizeof( tm ) ); + tt.tm_mon = month - 1; + if ( strftime( buffer, sizeof( buffer ), "%B", &tt ) ) + return TQString::fromLocal8Bit( buffer ); +#else + SYSTEMTIME st; + memset( &st, 0, sizeof(SYSTEMTIME) ); + st.wYear = 2000; + st.wMonth = month; + st.wDay = 1 ; + const wchar_t mmmm_t[] = L"MMMM"; // workaround for Borland + QT_WA( { + TCHAR buf[255]; + if ( GetDateFormat( LOCALE_USER_DEFAULT, 0, &st, mmmm_t, buf, 255 ) ) + return TQString::fromUcs2( (ushort*)buf ); + } , { + char buf[255]; + if ( GetDateFormatA( LOCALE_USER_DEFAULT, 0, &st, "MMMM", (char*)&buf, 255 ) ) + return TQString::fromLocal8Bit( buf ); + } ) +#endif + + return TQString::null; +} + +/*! + \fn TQString TQDate::dayName( int weekday ) + \obsolete + + Use shortDayName() instead. +*/ + +/*! + Returns the name of the \a weekday. + + 1 = "Mon", 2 = "Tue", ... 7 = "Sun" + + The day names will be localized according to the system's locale + settings. + + \sa toString(), shortMonthName(), longMonthName(), longDayName() +*/ + +TQString TQDate::shortDayName( int weekday ) +{ +#if defined(QT_CHECK_RANGE) + if ( weekday < 1 || weekday > 7 ) { + tqWarning( "TQDate::shortDayName: Parameter out of range" ); + weekday = 1; + } +#endif +#ifndef TQ_WS_WIN + char buffer[255]; + tm tt; + memset( &tt, 0, sizeof( tm ) ); + tt.tm_wday = ( weekday == 7 ) ? 0 : weekday; + if ( strftime( buffer, sizeof( buffer ), "%a", &tt ) ) + return TQString::fromLocal8Bit( buffer ); +#else + SYSTEMTIME st; + memset( &st, 0, sizeof(SYSTEMTIME) ); + st.wYear = 2001; + st.wMonth = 10; + st.wDayOfWeek = ( weekday == 7 ) ? 0 : weekday; + st.wDay = 21 + st.wDayOfWeek; + const wchar_t ddd_t[] = L"ddd"; // workaround for Borland + QT_WA( { + TCHAR buf[255]; + if ( GetDateFormat( LOCALE_USER_DEFAULT, 0, &st, ddd_t, buf, 255 ) ) + return TQString::fromUcs2( (ushort*)buf ); + } , { + char buf[255]; + if ( GetDateFormatA( LOCALE_USER_DEFAULT, 0, &st, "ddd", (char*)&buf, 255 ) ) + return TQString::fromLocal8Bit( buf ); + } ); +#endif + + return TQString::null; +} + +/*! + Returns the long name of the \a weekday. + + 1 = "Monday", 2 = "Tuesday", ... 7 = "Sunday" + + The day names will be localized according to the system's locale + settings. + + \sa toString(), shortDayName(), shortMonthName(), longMonthName() +*/ + +TQString TQDate::longDayName( int weekday ) +{ +#if defined(QT_CHECK_RANGE) + if ( weekday < 1 || weekday > 7 ) { + tqWarning( "TQDate::longDayName: Parameter out of range" ); + weekday = 1; + } +#endif +#ifndef TQ_WS_WIN + char buffer[255]; + tm tt; + memset( &tt, 0, sizeof( tm ) ); + tt.tm_wday = ( weekday == 7 ) ? 0 : weekday; + if ( strftime( buffer, sizeof( buffer ), "%A", &tt ) ) + return TQString::fromLocal8Bit( buffer ); +#else + SYSTEMTIME st; + memset( &st, 0, sizeof(SYSTEMTIME) ); + st.wYear = 2001; + st.wMonth = 10; + st.wDayOfWeek = ( weekday == 7 ) ? 0 : weekday; + st.wDay = 21 + st.wDayOfWeek; + const wchar_t dddd_t[] = L"dddd"; // workaround for Borland + QT_WA( { + TCHAR buf[255]; + if ( GetDateFormat( LOCALE_USER_DEFAULT, 0, &st, dddd_t, buf, 255 ) ) + return TQString::fromUcs2( (ushort*)buf ); + } , { + char buf[255]; + if ( GetDateFormatA( LOCALE_USER_DEFAULT, 0, &st, "dddd", (char*)&buf, 255 ) ) + return TQString::fromLocal8Bit( buf ); + } ); +#endif + + return TQString::null; +} +#endif //TQT_NO_TEXTDATE + +#ifndef TQT_NO_DATESTRING + +#if !defined(TQT_NO_SPRINTF) +/*! + \overload + + Returns the date as a string. The \a f parameter determines the + format of the string. + + If \a f is \c TQt::TextDate, the string format is "Sat May 20 1995" + (using the shortDayName() and shortMonthName() functions to + generate the string, so the day and month names are locale + specific). + + If \a f is \c TQt::ISODate, the string format corresponds to the + ISO 8601 specification for representations of dates, which is + YYYY-MM-DD where YYYY is the year, MM is the month of the year + (between 01 and 12), and DD is the day of the month between 01 and + 31. + + If \a f is \c TQt::LocalDate, the string format depends on the + locale settings of the system. + + If the date is an invalid date, then TQString::null will be returned. + + \sa shortDayName(), shortMonthName() +*/ +TQString TQDate::toString( TQt::DateFormat f ) const +{ + if ( !isValid() ) + return TQString::null; + int y, m, d; + julianToGregorian( jd, y, m, d ); + switch ( f ) { + case TQt::LocalDate: + { +#ifndef TQ_WS_WIN + tm tt; + memset( &tt, 0, sizeof( tm ) ); + char buf[255]; + tt.tm_mday = day(); + tt.tm_mon = month() - 1; + tt.tm_year = year() - 1900; + + static const char * avoidEgcsWarning = "%x"; + if ( strftime( buf, sizeof(buf), avoidEgcsWarning, &tt ) ) + return TQString::fromLocal8Bit( buf ); +#else + SYSTEMTIME st; + memset( &st, 0, sizeof(SYSTEMTIME) ); + st.wYear = year(); + st.wMonth = month(); + st.wDay = day(); + QT_WA( { + TCHAR buf[255]; + if ( GetDateFormat( LOCALE_USER_DEFAULT, 0, &st, 0, buf, 255 ) ) + return TQString::fromUcs2( (ushort*)buf ); + } , { + char buf[255]; + if ( GetDateFormatA( LOCALE_USER_DEFAULT, 0, &st, 0, (char*)&buf, 255 ) ) + return TQString::fromLocal8Bit( buf ); + } ); +#endif + return TQString::null; + } + default: +#ifndef TQT_NO_TEXTDATE + case TQt::TextDate: + { + TQString buf = shortDayName( dayOfWeek() ); + buf += ' '; + buf += shortMonthName( m ); + TQString t; + t.sprintf( " %d %d", d, y ); + buf += t; + return buf; + } +#endif + case TQt::ISODate: + { + TQString month( TQString::number( m ).rightJustify( 2, '0' ) ); + TQString day( TQString::number( d ).rightJustify( 2, '0' ) ); + return TQString::number( y ) + "-" + month + "-" + day; + } + } +} +#endif //TQT_NO_SPRINTF + +/*! + Returns the date as a string. The \a format parameter determines + the format of the result string. + + These expressions may be used: + + \table + \header \i Expression \i Output + \row \i d \i the day as number without a leading zero (1-31) + \row \i dd \i the day as number with a leading zero (01-31) + \row \i ddd + \i the abbreviated localized day name (e.g. 'Mon'..'Sun'). + Uses TQDate::shortDayName(). + \row \i dddd + \i the long localized day name (e.g. 'Monday'..'Sunday'). + Uses TQDate::longDayName(). + \row \i M \i the month as number without a leading zero (1-12) + \row \i MM \i the month as number with a leading zero (01-12) + \row \i MMM + \i the abbreviated localized month name (e.g. 'Jan'..'Dec'). + Uses TQDate::shortMonthName(). + \row \i MMMM + \i the long localized month name (e.g. 'January'..'December'). + Uses TQDate::longMonthName(). + \row \i yy \i the year as two digit number (00-99) + \row \i yyyy \i the year as four digit number (1752-8000) + \endtable + + All other input characters will be ignored. + + Example format strings (assuming that the TQDate is the + 20th July 1969): + \table + \header \i Format \i Result + \row \i dd.MM.yyyy \i11 20.07.1969 + \row \i ddd MMMM d yy \i11 Sun July 20 69 + \endtable + + If the date is an invalid date, then TQString::null will be returned. + + \sa TQDateTime::toString() TQTime::toString() + +*/ +TQString TQDate::toString( const TQString& format ) const +{ + return fmtDateTime( format, 0, this ); +} +#endif //TQT_NO_DATESTRING + +/*! + Sets the date's year \a y, month \a m and day \a d. + + \a y must be in the range 1752..8000, \a m must be in the range + 1..12, and \a d must be in the range 1..31. + + \warning If \a y is in the range 0..99, it is interpreted as + 1900..1999. + + Returns TRUE if the date is valid; otherwise returns FALSE. +*/ + +bool TQDate::setYMD( int y, int m, int d ) +{ + if ( year() == y && month() == m && day() == d ) + return isValid(); + if ( !isValid(y,m,d) ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQDate::setYMD: Invalid date %04d-%02d-%02d", y, m, d ); +#endif + return FALSE; + } + jd = gregorianToJulian( y, m, d ); + return TRUE; +} + +/*! + Returns a TQDate object containing a date \a ndays later than the + date of this object (or earlier if \a ndays is negative). + + \sa addMonths() addYears() daysTo() +*/ + +TQDate TQDate::addDays( int ndays ) const +{ + TQDate d; + d.jd = jd + ndays; + return d; +} + +/*! + Returns a TQDate object containing a date \a nmonths later than the + date of this object (or earlier if \a nmonths is negative). + + \sa addDays() addYears() +*/ + +TQDate TQDate::addMonths( int nmonths ) const +{ + int y, m, d; + julianToGregorian( jd, y, m, d ); + + while ( nmonths != 0 ) { + if ( nmonths < 0 && nmonths + 12 <= 0 ) { + y--; + nmonths+=12; + } else if ( nmonths < 0 ) { + m+= nmonths; + nmonths = 0; + if ( m <= 0 ) { + --y; + m+=12; + } + } else if ( nmonths - 12 >= 0 ) { + y++; + nmonths-=12; + } else if ( m == 12 ) { + y++; + m = 0; + } else { + m+= nmonths; + nmonths = 0; + if ( m > 12 ) { + ++y; + m -= 12; + } + } + } + + TQDate tmp(y,m,1); + + if( d > tmp.daysInMonth() ) + d = tmp.daysInMonth(); + + TQDate date(y, m, d); + return date; + +} + +/*! + Returns a TQDate object containing a date \a nyears later than the + date of this object (or earlier if \a nyears is negative). + + \sa addDays(), addMonths() +*/ + +TQDate TQDate::addYears( int nyears ) const +{ + int y, m, d; + julianToGregorian( jd, y, m, d ); + y += nyears; + + TQDate tmp(y,m,1); + + if( d > tmp.daysInMonth() ) + d = tmp.daysInMonth(); + + TQDate date(y, m, d); + return date; +} + + + +/*! + Returns the number of days from this date to \a d (which is + negative if \a d is earlier than this date). + + Example: + \code + TQDate d1( 1995, 5, 17 ); // May 17th 1995 + TQDate d2( 1995, 5, 20 ); // May 20th 1995 + d1.daysTo( d2 ); // returns 3 + d2.daysTo( d1 ); // returns -3 + \endcode + + \sa addDays() +*/ + +int TQDate::daysTo( const TQDate &d ) const +{ + return d.jd - jd; +} + + +/*! + \fn bool TQDate::operator==( const TQDate &d ) const + + Returns TRUE if this date is equal to \a d; otherwise returns FALSE. +*/ + +/*! + \fn bool TQDate::operator!=( const TQDate &d ) const + + Returns TRUE if this date is different from \a d; otherwise returns FALSE. +*/ + +/*! + \fn bool TQDate::operator<( const TQDate &d ) const + + Returns TRUE if this date is earlier than \a d, otherwise returns FALSE. +*/ + +/*! + \fn bool TQDate::operator<=( const TQDate &d ) const + + Returns TRUE if this date is earlier than or equal to \a d, + otherwise returns FALSE. +*/ + +/*! + \fn bool TQDate::operator>( const TQDate &d ) const + + Returns TRUE if this date is later than \a d, otherwise returns FALSE. +*/ + +/*! + \fn bool TQDate::operator>=( const TQDate &d ) const + + Returns TRUE if this date is later than or equal to \a d, + otherwise returns FALSE. +*/ + +/*! + \overload + Returns the current date, as reported by the system clock. + + \sa TQTime::currentTime(), TQDateTime::currentDateTime() +*/ + +TQDate TQDate::currentDate() +{ + return currentDate( TQt::LocalTime ); +} + +/*! + Returns the current date, as reported by the system clock, for the + TimeSpec \a ts. The default TimeSpec is LocalTime. + + \sa TQTime::currentTime(), TQDateTime::currentDateTime(), TQt::TimeSpec +*/ +TQDate TQDate::currentDate( TQt::TimeSpec ts ) +{ + TQDate d; +#if defined(Q_OS_WIN32) + SYSTEMTIME t; + memset( &t, 0, sizeof(SYSTEMTIME) ); + if ( ts == TQt::LocalTime ) + GetLocalTime( &t ); + else + GetSystemTime( &t ); + d.jd = gregorianToJulian( t.wYear, t.wMonth, t.wDay ); +#else + // posix compliant system + time_t ltime; + time( <ime ); + tm *t; + +# if defined(TQT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) + // use the reentrant versions of localtime() and gmtime() where available + tm res; + if ( ts == TQt::LocalTime ) + t = localtime_r( <ime, &res ); + else + t = gmtime_r( <ime, &res ); +# else + if ( ts == TQt::LocalTime ) + t = localtime( <ime ); + else + t = gmtime( <ime ); +# endif // TQT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS + + d.jd = gregorianToJulian( t->tm_year + 1900, t->tm_mon + 1, t->tm_mday ); +#endif + return d; +} + +#ifndef TQT_NO_DATESTRING +/*! + Returns the TQDate represented by the string \a s, using the format + \a f, or an invalid date if the string cannot be parsed. + + Note for \c TQt::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 \c TQt::LocalDate cannot be used here. +*/ +TQDate TQDate::fromString( const TQString& s, TQt::DateFormat f ) +{ + if ( ( s.isEmpty() ) || ( f == TQt::LocalDate ) ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQDate::fromString: Parameter out of range" ); +#endif + TQDate d; + d.jd = 0; + return d; + } + switch ( f ) { + case TQt::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 TQDate( year, month, day ); + } + break; + default: +#ifndef TQT_NO_TEXTDATE + case TQt::TextDate: + { + /* + This will fail gracefully if the input string doesn't + contain any space. + */ + int monthPos = s.find( ' ' ) + 1; + int dayPos = s.find( ' ', monthPos ) + 1; + + TQString monthName( s.mid(monthPos, dayPos - monthPos - 1) ); + int month = -1; + + // try English names first + for ( int i = 0; i < 12; i++ ) { + if ( monthName == qt_shortMonthNames[i] ) { + month = i + 1; + break; + } + } + + // try the localized names + if ( month == -1 ) { + for ( int i = 0; i < 12; i++ ) { + if ( monthName == shortMonthName( i + 1 ) ) { + month = i + 1; + break; + } + } + } +#if defined(QT_CHECK_RANGE) + if ( month < 1 || month > 12 ) { + tqWarning( "TQDate::fromString: Parameter out of range" ); + TQDate d; + d.jd = 0; + return d; + } +#endif + int day = s.mid( dayPos, 2 ).stripWhiteSpace().toInt(); + int year = s.right( 4 ).toInt(); + return TQDate( year, month, day ); + } +#else + break; +#endif + } + return TQDate(); +} +#endif //TQT_NO_DATESTRING + +/*! + \overload + + Returns TRUE if the specified date (year \a y, month \a m and day + \a d) is valid; otherwise returns FALSE. + + Example: + \code + TQDate::isValid( 2002, 5, 17 ); // TRUE May 17th 2002 is valid + TQDate::isValid( 2002, 2, 30 ); // FALSE Feb 30th does not exist + TQDate::isValid( 2004, 2, 29 ); // TRUE 2004 is a leap year + TQDate::isValid( 1202, 6, 6 ); // FALSE 1202 is pre-Gregorian + \endcode + + \warning A \a y value in the range 00..99 is interpreted as + 1900..1999. + + \sa isNull(), setYMD() +*/ + +bool TQDate::isValid( int y, int m, int d ) +{ + if ( y >= 0 && y <= 99 ) + y += 1900; + else if ( y < FIRST_YEAR || (y == FIRST_YEAR && (m < 9 || + (m == 9 && d < 14))) ) + return FALSE; + return (d > 0 && m > 0 && m <= 12) && + (d <= monthDays[m] || (d == 29 && m == 2 && leapYear(y))); +} + +/*! + Returns TRUE if the specified year \a y is a leap year; otherwise + returns FALSE. +*/ + +bool TQDate::leapYear( int y ) +{ + return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0; +} + +/*! + \internal + Converts a Gregorian date to a Julian day. + This algorithm is taken from Communications of the ACM, Vol 6, No 8. + \sa julianToGregorian() +*/ + +uint TQDate::gregorianToJulian( int y, int m, int d ) +{ + uint c, ya; + if ( y <= 99 ) + y += 1900; + if ( m > 2 ) { + m -= 3; + } else { + m += 9; + y--; + } + c = y; // NOTE: Sym C++ 6.0 bug + c /= 100; + ya = y - 100*c; + return 1721119 + d + (146097*c)/4 + (1461*ya)/4 + (153*m+2)/5; +} + +/*! + \internal + Converts a Julian day to a Gregorian date. + This algorithm is taken from Communications of the ACM, Vol 6, No 8. + \sa gregorianToJulian() +*/ + +void TQDate::julianToGregorian( uint jd, int &y, int &m, int &d ) +{ + uint x; + uint j = jd - 1721119; + y = (j*4 - 1)/146097; + j = j*4 - 146097*y - 1; + x = j/4; + j = (x*4 + 3) / 1461; + y = 100*y + j; + x = (x*4) + 3 - 1461*j; + x = (x + 4)/4; + m = (5*x - 3)/153; + x = 5*x - 3 - 153*m; + d = (x + 5)/5; + if ( m < 10 ) { + m += 3; + } else { + m -= 9; + y++; + } +} + + +/***************************************************************************** + TQTime member functions + *****************************************************************************/ + +/*! + \class TQTime tqdatetime.h + \reentrant + + \brief The TQTime class provides clock time functions. + + \ingroup time + \mainclass + + A TQTime object contains a clock time, i.e. the number of hours, + minutes, seconds, and milliseconds since midnight. It can read the + current time from the system clock and measure a span of elapsed + time. It provides functions for comparing times and for + manipulating a time by adding a number of (milli)seconds. + + TQTime uses the 24-hour clock format; it has no concept of AM/PM. + It operates in local time; it knows nothing about time zones or + daylight savings time. + + A TQTime object is typically created either by giving the number of + hours, minutes, seconds, and milliseconds explicitly, or by using + the static function currentTime(), which creates a TQTime object + that contains the system's clock time. Note that the accuracy + depends on the accuracy of the underlying operating system; not + all systems provide 1-millisecond accuracy. + + The hour(), minute(), second(), and msec() functions provide + access to the number of hours, minutes, seconds, and milliseconds + of the time. The same information is provided in textual format by + the toString() function. + + TQTime provides a full set of operators to compare two TQTime + objects. One time is considered smaller than another if it is + earlier than the other. + + The time a given number of seconds or milliseconds later than a + given time can be found using the addSecs() or addMSecs() + functions. Correspondingly, the number of (milli)seconds between + two times can be found using the secsTo() or msecsTo() functions. + + TQTime can be used to measure a span of elapsed time using the + start(), restart(), and elapsed() functions. + + \sa TQDate, TQDateTime +*/ + +/*! + \fn TQTime::TQTime() + + Constructs the time 0 hours, minutes, seconds and milliseconds, + i.e. 00:00:00.000 (midnight). This is a valid time. + + \sa isValid() +*/ + +/*! + Constructs a time with hour \a h, minute \a m, seconds \a s and + milliseconds \a ms. + + \a h must be in the range 0..23, \a m and \a s must be in the + range 0..59, and \a ms must be in the range 0..999. + + \sa isValid() +*/ + +TQTime::TQTime( int h, int m, int s, int ms ) +{ + setHMS( h, m, s, ms ); +} + + +/*! + \fn bool TQTime::isNull() const + + Returns TRUE if the time is equal to 00:00:00.000; otherwise + returns FALSE. A null time is valid. + + \sa isValid() +*/ + +/*! + Returns TRUE if the time is valid; otherwise returns FALSE. The + time 23:30:55.746 is valid, whereas 24:12:30 is invalid. + + \sa isNull() +*/ + +bool TQTime::isValid() const +{ + return ds < MSECS_PER_DAY; +} + + +/*! + Returns the hour part (0..23) of the time. +*/ + +int TQTime::hour() const +{ + return ds / MSECS_PER_HOUR; +} + +/*! + Returns the minute part (0..59) of the time. +*/ + +int TQTime::minute() const +{ + return (ds % MSECS_PER_HOUR)/MSECS_PER_MIN; +} + +/*! + Returns the second part (0..59) of the time. +*/ + +int TQTime::second() const +{ + return (ds / 1000)%SECS_PER_MIN; +} + +/*! + Returns the millisecond part (0..999) of the time. +*/ + +int TQTime::msec() const +{ + return ds % 1000; +} + +#ifndef TQT_NO_DATESTRING +#ifndef TQT_NO_SPRINTF +/*! + \overload + + Returns the time as a string. Milliseconds are not included. The + \a f parameter determines the format of the string. + + If \a f is \c TQt::TextDate, the string format is HH:MM:SS; e.g. 1 + second before midnight would be "23:59:59". + + If \a f is \c TQt::ISODate, the string format corresponds to the + ISO 8601 extended specification for representations of dates, + which is also HH:MM:SS. + + If \a f is TQt::LocalDate, the string format depends on the locale + settings of the system. + + If the time is an invalid time, then TQString::null will be returned. +*/ + +TQString TQTime::toString( TQt::DateFormat f ) const +{ + if ( !isValid() ) + return TQString::null; + + switch ( f ) { + case TQt::LocalDate: + { +#ifndef TQ_WS_WIN + tm tt; + memset( &tt, 0, sizeof( tm ) ); + char buf[255]; + tt.tm_sec = second(); + tt.tm_min = minute(); + tt.tm_hour = hour(); + if ( strftime( buf, sizeof(buf), "%X", &tt ) ) + return TQString::fromLocal8Bit( buf ); +#else + SYSTEMTIME st; + memset( &st, 0, sizeof(SYSTEMTIME) ); + st.wHour = hour(); + st.wMinute = minute(); + st.wSecond = second(); + st.wMilliseconds = 0; + QT_WA( { + TCHAR buf[255]; + if ( GetTimeFormat( LOCALE_USER_DEFAULT, 0, &st, 0, buf, 255 ) ) + return TQString::fromUcs2( (ushort*)buf ); + } , { + char buf[255]; + if ( GetTimeFormatA( LOCALE_USER_DEFAULT, 0, &st, 0, (char*)&buf, 255 ) ) + return TQString::fromLocal8Bit( buf ); + } ); +#endif + return TQString::null; + } + default: + case TQt::ISODate: + case TQt::TextDate: + TQString buf; + buf.sprintf( "%.2d:%.2d:%.2d", hour(), minute(), second() ); + return buf; + } +} +#endif + +/*! + Returns the time as a string. The \a format parameter determines + the format of the result string. + + These expressions may be used: + + \table + \header \i Expression \i Output + \row \i h + \i the hour without a leading zero (0..23 or 1..12 if AM/PM display) + \row \i hh + \i the hour with a leading zero (00..23 or 01..12 if AM/PM display) + \row \i m \i the minute without a leading zero (0..59) + \row \i mm \i the minute with a leading zero (00..59) + \row \i s \i the second whithout a leading zero (0..59) + \row \i ss \i the second whith a leading zero (00..59) + \row \i z \i the milliseconds without leading zeroes (0..999) + \row \i zzz \i the milliseconds with leading zeroes (000..999) + \row \i AP + \i use AM/PM display. \e AP will be replaced by either "AM" or "PM". + \row \i ap + \i use am/pm display. \e ap will be replaced by either "am" or "pm". + \endtable + + All other input characters will be ignored. + + Example format strings (assuming that the TQTime is 14:13:09.042) + + \table + \header \i Format \i Result + \row \i hh:mm:ss.zzz \i11 14:13:09.042 + \row \i h:m:s ap \i11 2:13:9 pm + \endtable + + If the time is an invalid time, then TQString::null will be returned. + + \sa TQDate::toString() TQDateTime::toString() +*/ +TQString TQTime::toString( const TQString& format ) const +{ + return fmtDateTime( format, this, 0 ); +} +#endif //TQT_NO_DATESTRING +/*! + Sets the time to hour \a h, minute \a m, seconds \a s and + milliseconds \a ms. + + \a h must be in the range 0..23, \a m and \a s must be in the + range 0..59, and \a ms must be in the range 0..999. Returns TRUE + if the set time is valid; otherwise returns FALSE. + + \sa isValid() +*/ + +bool TQTime::setHMS( int h, int m, int s, int ms ) +{ + if ( !isValid(h,m,s,ms) ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQTime::setHMS Invalid time %02d:%02d:%02d.%03d", h, m, s, + ms ); +#endif + ds = MSECS_PER_DAY; // make this invalid + return FALSE; + } + ds = (h*SECS_PER_HOUR + m*SECS_PER_MIN + s)*1000 + ms; + return TRUE; +} + +/*! + Returns a TQTime object containing a time \a nsecs seconds later + than the time of this object (or earlier if \a nsecs is negative). + + Note that the time will wrap if it passes midnight. + + Example: + \code + TQTime n( 14, 0, 0 ); // n == 14:00:00 + TQTime t; + t = n.addSecs( 70 ); // t == 14:01:10 + t = n.addSecs( -70 ); // t == 13:58:50 + t = n.addSecs( 10*60*60 + 5 ); // t == 00:00:05 + t = n.addSecs( -15*60*60 ); // t == 23:00:00 + \endcode + + \sa addMSecs(), secsTo(), TQDateTime::addSecs() +*/ + +TQTime TQTime::addSecs( int nsecs ) const +{ + return addMSecs( nsecs * 1000 ); +} + +/*! + Returns the number of seconds from this time to \a t (which is + negative if \a t is earlier than this time). + + Because TQTime measures time within a day and there are 86400 + seconds in a day, the result is always between -86400 and 86400. + + \sa addSecs() TQDateTime::secsTo() +*/ + +int TQTime::secsTo( const TQTime &t ) const +{ + return ((int)t.ds - (int)ds)/1000; +} + +/*! + Returns a TQTime object containing a time \a ms milliseconds later + than the time of this object (or earlier if \a ms is negative). + + Note that the time will wrap if it passes midnight. See addSecs() + for an example. + + \sa addSecs(), msecsTo() +*/ + +TQTime TQTime::addMSecs( int ms ) const +{ + TQTime t; + if ( ms < 0 ) { + // % not well-defined for -ve, but / is. + int negdays = (MSECS_PER_DAY-ms) / MSECS_PER_DAY; + t.ds = ((int)ds + ms + negdays*MSECS_PER_DAY) + % MSECS_PER_DAY; + } else { + t.ds = ((int)ds + ms) % MSECS_PER_DAY; + } + return t; +} + +/*! + Returns the number of milliseconds from this time to \a t (which + is negative if \a t is earlier than this time). + + Because TQTime measures time within a day and there are 86400 + seconds in a day, the result is always between -86400000 and + 86400000 msec. + + \sa secsTo() +*/ + +int TQTime::msecsTo( const TQTime &t ) const +{ + return (int)t.ds - (int)ds; +} + + +/*! + \fn bool TQTime::operator==( const TQTime &t ) const + + Returns TRUE if this time is equal to \a t; otherwise returns FALSE. +*/ + +/*! + \fn bool TQTime::operator!=( const TQTime &t ) const + + Returns TRUE if this time is different from \a t; otherwise returns FALSE. +*/ + +/*! + \fn bool TQTime::operator<( const TQTime &t ) const + + Returns TRUE if this time is earlier than \a t; otherwise returns FALSE. +*/ + +/*! + \fn bool TQTime::operator<=( const TQTime &t ) const + + Returns TRUE if this time is earlier than or equal to \a t; + otherwise returns FALSE. +*/ + +/*! + \fn bool TQTime::operator>( const TQTime &t ) const + + Returns TRUE if this time is later than \a t; otherwise returns FALSE. +*/ + +/*! + \fn bool TQTime::operator>=( const TQTime &t ) const + + Returns TRUE if this time is later than or equal to \a t; + otherwise returns FALSE. +*/ + + + +/*! + \overload + + Returns the current time as reported by the system clock. + + Note that the accuracy depends on the accuracy of the underlying + operating system; not all systems provide 1-millisecond accuracy. +*/ + +TQTime TQTime::currentTime() +{ + return currentTime( TQt::LocalTime ); +} + +/*! + Returns the current time as reported by the system clock, for the + TimeSpec \a ts. The default TimeSpec is LocalTime. + + Note that the accuracy depends on the accuracy of the underlying + operating system; not all systems provide 1-millisecond accuracy. + + \sa TQt::TimeSpec +*/ +TQTime TQTime::currentTime( TQt::TimeSpec ts ) +{ + TQTime t; + currentTime( &t, ts ); + return t; +} + +#ifndef TQT_NO_DATESTRING +/*! + Returns the representation \a s as a TQTime using the format \a f, + or an invalid time if this is not possible. + + \warning Note that \c TQt::LocalDate cannot be used here. +*/ +TQTime TQTime::fromString( const TQString& s, TQt::DateFormat f ) +{ + if ( ( s.isEmpty() ) || ( f == TQt::LocalDate ) ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQTime::fromString: Parameter out of range" ); +#endif + TQTime t; + t.ds = MSECS_PER_DAY; + return t; + } + + int hour( s.mid( 0, 2 ).toInt() ); + int minute( s.mid( 3, 2 ).toInt() ); + int second( s.mid( 6, 2 ).toInt() ); + int msec( s.mid( 9, 3 ).toInt() ); + return TQTime( hour, minute, second, msec ); +} +#endif + +/*! + \internal + \obsolete + + Fetches the current time and returns TRUE if the time is within one + minute after midnight, otherwise FALSE. The return value is used by + TQDateTime::currentDateTime() to ensure that the date there is correct. +*/ + +bool TQTime::currentTime( TQTime *ct ) +{ + return currentTime( ct, TQt::LocalTime ); +} + + +/*! + \internal + + Fetches the current time, for the TimeSpec \a ts, and returns TRUE + if the time is within one minute after midnight, otherwise FALSE. The + return value is used by TQDateTime::currentDateTime() to ensure that + the date there is correct. The default TimeSpec is LocalTime. + + \sa TQt::TimeSpec +*/ +bool TQTime::currentTime( TQTime *ct, TQt::TimeSpec ts ) +{ + if ( !ct ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQTime::currentTime(TQTime *): Null pointer not allowed" ); +#endif + return FALSE; + } + +#if defined(Q_OS_WIN32) + SYSTEMTIME t; + if ( ts == TQt::LocalTime ) { + GetLocalTime( &t ); + } else { + GetSystemTime( &t ); + } + ct->ds = (uint)( MSECS_PER_HOUR*t.wHour + MSECS_PER_MIN*t.wMinute + + 1000*t.wSecond + t.wMilliseconds ); +#elif defined(Q_OS_UNIX) + // posix compliant system + struct timeval tv; + gettimeofday( &tv, 0 ); + time_t ltime = tv.tv_sec; + tm *t; + +# if defined(TQT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) + // use the reentrant versions of localtime() and gmtime() where available + tm res; + if ( ts == TQt::LocalTime ) + t = localtime_r( <ime, &res ); + else + t = gmtime_r( <ime, &res ); +# else + if ( ts == TQt::LocalTime ) + t = localtime( <ime ); + else + t = gmtime( <ime ); +# endif // TQT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS + + ct->ds = (uint)( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + + 1000 * t->tm_sec + tv.tv_usec / 1000 ); +#else + time_t ltime; // no millisecond resolution + ::time( <ime ); + tm *t; + if ( ts == TQt::LocalTime ) + localtime( <ime ); + else + gmtime( <ime ); + ct->ds = (uint) ( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + + 1000 * t->tm_sec ); +#endif + // 00:00.00 to 00:00.59.999 is considered as "midnight or right after" + return ct->ds < (uint) MSECS_PER_MIN; +} + +/*! + \overload + + Returns TRUE if the specified time is valid; otherwise returns + FALSE. + + The time is valid if \a h is in the range 0..23, \a m and \a s are + in the range 0..59, and \a ms is in the range 0..999. + + Example: + \code + TQTime::isValid(21, 10, 30); // returns TRUE + TQTime::isValid(22, 5, 62); // returns FALSE + \endcode +*/ + +bool TQTime::isValid( int h, int m, int s, int ms ) +{ + return (uint)h < 24 && (uint)m < 60 && (uint)s < 60 && (uint)ms < 1000; +} + + +/*! + Sets this time to the current time. This is practical for timing: + + \code + TQTime t; + t.start(); + some_lengthy_task(); + tqDebug( "Time elapsed: %d ms", t.elapsed() ); + \endcode + + \sa restart(), elapsed(), currentTime() +*/ + +void TQTime::start() +{ + *this = currentTime(); +} + +/*! + Sets this time to the current time and returns the number of + milliseconds that have elapsed since the last time start() or + restart() was called. + + This function is guaranteed to be atomic and is thus very handy + for repeated measurements. Call start() to start the first + measurement and then restart() for each later measurement. + + Note that the counter wraps to zero 24 hours after the last call + to start() or restart(). + + \warning If the system's clock setting has been changed since the + last time start() or restart() was called, the result is + undefined. This can happen when daylight savings time is turned on + or off. + + \sa start(), elapsed(), currentTime() +*/ + +int TQTime::restart() +{ + TQTime t = currentTime(); + int n = msecsTo( t ); + if ( n < 0 ) // passed midnight + n += 86400*1000; + *this = t; + return n; +} + +/*! + Returns the number of milliseconds that have elapsed since the + last time start() or restart() was called. + + Note that the counter wraps to zero 24 hours after the last call + to start() or restart. + + Note that the accuracy depends on the accuracy of the underlying + operating system; not all systems provide 1-millisecond accuracy. + + \warning If the system's clock setting has been changed since the + last time start() or restart() was called, the result is + undefined. This can happen when daylight savings time is turned on + or off. + + \sa start(), restart() +*/ + +int TQTime::elapsed() const +{ + int n = msecsTo( currentTime() ); + if ( n < 0 ) // passed midnight + n += 86400*1000; + return n; +} + + +/***************************************************************************** + TQDateTime member functions + *****************************************************************************/ + +/*! + \class TQDateTime tqdatetime.h + \reentrant + \brief The TQDateTime class provides date and time functions. + + \ingroup time + \mainclass + + A TQDateTime object contains a calendar date and a clock time (a + "datetime"). It is a combination of the TQDate and TQTime classes. + It can read the current datetime from the system clock. It + provides functions for comparing datetimes and for manipulating a + datetime by adding a number of seconds, days, months or years. + + A TQDateTime object is typically created either by giving a date + and time explicitly in the constructor, or by using the static + function currentDateTime(), which returns a TQDateTime object set + to the system clock's time. The date and time can be changed with + setDate() and setTime(). A datetime can also be set using the + setTime_t() function, which takes a POSIX-standard "number of + seconds since 00:00:00 on January 1, 1970" value. The fromString() + function returns a TQDateTime given a string and a date format + which is used to interpret the date within the string. + + The date() and time() functions provide access to the date and + time parts of the datetime. The same information is provided in + textual format by the toString() function. + + TQDateTime provides a full set of operators to compare two + TQDateTime objects where smaller means earlier and larger means + later. + + You can increment (or decrement) a datetime by a given number of + seconds using addSecs() or days using addDays(). Similarly you can + use addMonths() and addYears(). The daysTo() function returns the + number of days between two datetimes, and secsTo() returns the + number of seconds between two datetimes. + + The range of a datetime object is constrained to the ranges of the + TQDate and TQTime objects which it embodies. + + \sa TQDate TQTime TQDateTimeEdit +*/ + + +/*! + \fn TQDateTime::TQDateTime() + + Constructs a null datetime (i.e. null date and null time). A null + datetime is invalid, since the date is invalid. + + \sa isValid() +*/ + + +/*! + Constructs a datetime with date \a date and null (but valid) time + (00:00:00.000). +*/ + +TQDateTime::TQDateTime( const TQDate &date ) + : d(date) +{ +} + +/*! + Constructs a datetime with date \a date and time \a time. +*/ + +TQDateTime::TQDateTime( const TQDate &date, const TQTime &time ) + : d(date), t(time) +{ +} + + +/*! + \fn bool TQDateTime::isNull() const + + Returns TRUE if both the date and the time are null; otherwise + returns FALSE. A null datetime is invalid. + + \sa TQDate::isNull(), TQTime::isNull() +*/ + +/*! + \fn bool TQDateTime::isValid() const + + Returns TRUE if both the date and the time are valid; otherwise + returns FALSE. + + \sa TQDate::isValid(), TQTime::isValid() +*/ + +/*! + \fn TQDate TQDateTime::date() const + + Returns the date part of the datetime. + + \sa setDate(), time() +*/ + +/*! + \fn TQTime TQDateTime::time() const + + Returns the time part of the datetime. + + \sa setTime(), date() +*/ + +/*! + \fn void TQDateTime::setDate( const TQDate &date ) + + Sets the date part of this datetime to \a date. + + \sa date(), setTime() +*/ + +/*! + \fn void TQDateTime::setTime( const TQTime &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() +*/ + +time_t TQDateTime::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; + time_t secsSince1Jan1970UTC = mktime( &brokenDown ); + if ( secsSince1Jan1970UTC < -1 ) + secsSince1Jan1970UTC = -1; + return secsSince1Jan1970UTC; +} + +/*! + \overload + + Convenience function that sets the date and time to local time + based on the given UTC time. +*/ + +void TQDateTime::setTime_t( time_t secsSince1Jan1970UTC ) +{ + setTime_t( secsSince1Jan1970UTC, TQt::LocalTime ); +} + +/*! + Sets the date and time to \a ts time (\c TQt::LocalTime or \c + TQt::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 TQDateTime::setTime_t( time_t secsSince1Jan1970UTC, TQt::TimeSpec ts ) +{ + time_t tmp = secsSince1Jan1970UTC; + tm *brokenDown = 0; + +#if defined(Q_OS_UNIX) && defined(TQT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) + // posix compliant system + // use the reentrant versions of localtime() and gmtime() where available + tm res; + if ( ts == TQt::LocalTime ) + brokenDown = localtime_r( &tmp, &res ); + if ( !brokenDown ) { + brokenDown = gmtime_r( &tmp, &res ); + if ( !brokenDown ) { + d.jd = TQDate::gregorianToJulian( 1970, 1, 1 ); + t.ds = 0; + return; + } + } +#else + if ( ts == TQt::LocalTime ) + brokenDown = localtime( &tmp ); + if ( !brokenDown ) { + brokenDown = gmtime( &tmp ); + if ( !brokenDown ) { + d.jd = TQDate::gregorianToJulian( 1970, 1, 1 ); + t.ds = 0; + return; + } + } +#endif + + d.jd = TQDate::gregorianToJulian( brokenDown->tm_year + 1900, + brokenDown->tm_mon + 1, + brokenDown->tm_mday ); + t.ds = MSECS_PER_HOUR * brokenDown->tm_hour + + MSECS_PER_MIN * brokenDown->tm_min + + 1000 * brokenDown->tm_sec; +} +#ifndef TQT_NO_DATESTRING +#ifndef TQT_NO_SPRINTF +/*! + \overload + + Returns the datetime as a string. The \a f parameter determines + the format of the string. + + If \a f is \c TQt::TextDate, the string format is "Wed May 20 + 03:40:13 1998" (using TQDate::shortDayName(), TQDate::shortMonthName(), + and TQTime::toString() to generate the string, so the day and month + names will have localized names). + + If \a f is \c TQt::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 TQt::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 TQDate::toString() TQTime::toString() +*/ + +TQString TQDateTime::toString( TQt::DateFormat f ) const +{ + if ( !isValid() ) + return TQString::null; + + if ( f == TQt::ISODate ) { + return d.toString( TQt::ISODate ) + "T" + t.toString( TQt::ISODate ); + } +#ifndef TQT_NO_TEXTDATE + else if ( f == TQt::TextDate ) { +#ifndef TQ_WS_WIN + TQString buf = d.shortDayName( d.dayOfWeek() ); + buf += ' '; + buf += d.shortMonthName( d.month() ); + buf += ' '; + buf += TQString().setNum( d.day() ); + buf += ' '; +#else + TQString buf; + TQString winstr; + QT_WA( { + TCHAR out[255]; + GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_ILDATE, out, 255 ); + winstr = TQString::fromUcs2( (ushort*)out ); + } , { + char out[255]; + GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_ILDATE, (char*)&out, 255 ); + winstr = TQString::fromLocal8Bit( out ); + } ); + switch ( winstr.toInt() ) { + case 1: + buf = d.shortDayName( d.dayOfWeek() ) + " " + TQString().setNum( d.day() ) + ". " + d.shortMonthName( d.month() ) + " "; + break; + default: + buf = d.shortDayName( d.dayOfWeek() ) + " " + d.shortMonthName( d.month() ) + " " + TQString().setNum( d.day() ) + " "; + break; + } +#endif + buf += t.toString(); + buf += ' '; + buf += TQString().setNum( d.year() ); + return buf; + } +#endif + else if ( f == TQt::LocalDate ) { + return d.toString( TQt::LocalDate ) + " " + t.toString( TQt::LocalDate ); + } + return TQString::null; +} +#endif + +/*! + Returns the datetime as a string. The \a format parameter + determines the format of the result string. + + These expressions may be used for the date: + + \table + \header \i Expression \i Output + \row \i d \i the day as number without a leading zero (1-31) + \row \i dd \i the day as number with a leading zero (01-31) + \row \i ddd + \i the abbreviated localized day name (e.g. 'Mon'..'Sun'). + Uses TQDate::shortDayName(). + \row \i dddd + \i the long localized day name (e.g. 'Monday'..'Sunday'). + Uses TQDate::longDayName(). + \row \i M \i the month as number without a leading zero (1-12) + \row \i MM \i the month as number with a leading zero (01-12) + \row \i MMM + \i the abbreviated localized month name (e.g. 'Jan'..'Dec'). + Uses TQDate::shortMonthName(). + \row \i MMMM + \i the long localized month name (e.g. 'January'..'December'). + Uses TQDate::longMonthName(). + \row \i yy \i the year as two digit number (00-99) + \row \i yyyy \i the year as four digit number (1752-8000) + \endtable + + These expressions may be used for the time: + + \table + \header \i Expression \i Output + \row \i h + \i the hour without a leading zero (0..23 or 1..12 if AM/PM display) + \row \i hh + \i the hour with a leading zero (00..23 or 01..12 if AM/PM display) + \row \i m \i the minute without a leading zero (0..59) + \row \i mm \i the minute with a leading zero (00..59) + \row \i s \i the second whithout a leading zero (0..59) + \row \i ss \i the second whith a leading zero (00..59) + \row \i z \i the milliseconds without leading zeroes (0..999) + \row \i zzz \i the milliseconds with leading zeroes (000..999) + \row \i AP + \i use AM/PM display. \e AP will be replaced by either "AM" or "PM". + \row \i ap + \i use am/pm display. \e ap will be replaced by either "am" or "pm". + \endtable + + All other input characters will be ignored. + + Example format strings (assumed that the TQDateTime is + 21st May 2001 14:13:09) + + \table + \header \i Format \i Result + \row \i dd.MM.yyyy \i11 21.05.2001 + \row \i ddd MMMM d yy \i11 Tue May 21 01 + \row \i hh:mm:ss.zzz \i11 14:13:09.042 + \row \i h:m:s ap \i11 2:13:9 pm + \endtable + + If the datetime is an invalid datetime, then TQString::null will be returned. + + \sa TQDate::toString() TQTime::toString() +*/ +TQString TQDateTime::toString( const TQString& format ) const +{ + return fmtDateTime( format, &t, &d ); +} +#endif //TQT_NO_DATESTRING + +/*! + Returns a TQDateTime 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() +*/ + +TQDateTime TQDateTime::addDays( int ndays ) const +{ + return TQDateTime( d.addDays(ndays), t ); +} + +/*! + Returns a TQDateTime 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() +*/ + +TQDateTime TQDateTime::addMonths( int nmonths ) const +{ + return TQDateTime( d.addMonths(nmonths), t ); +} + +/*! + Returns a TQDateTime 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() +*/ + +TQDateTime TQDateTime::addYears( int nyears ) const +{ + return TQDateTime( d.addYears(nyears), t ); +} + +/*! + Returns a TQDateTime 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() +*/ + +TQDateTime TQDateTime::addSecs( int nsecs ) const +{ + uint dd = d.jd; + int tt = t.ds; + int sign = 1; + if ( nsecs < 0 ) { + nsecs = -nsecs; + sign = -1; + } + if ( nsecs >= (int)SECS_PER_DAY ) { + dd += sign*(nsecs/SECS_PER_DAY); + nsecs %= SECS_PER_DAY; + } + tt += sign*nsecs*1000; + if ( tt < 0 ) { + tt = MSECS_PER_DAY - tt - 1; + dd -= tt / MSECS_PER_DAY; + tt = tt % MSECS_PER_DAY; + tt = MSECS_PER_DAY - tt - 1; + } else if ( tt >= (int)MSECS_PER_DAY ) { + dd += ( tt / MSECS_PER_DAY ); + tt = tt % MSECS_PER_DAY; + } + TQDateTime ret; + ret.t.ds = tt; + ret.d.jd = 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 TQDateTime::daysTo( const TQDateTime &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 + TQDateTime dt = TQDateTime::currentDateTime(); + TQDateTime xmas( TQDate(dt.date().year(),12,24), TQTime(17,00) ); + tqDebug( "There are %d seconds to Christmas", dt.secsTo(xmas) ); + \endcode + + \sa addSecs(), daysTo(), TQTime::secsTo() +*/ + +int TQDateTime::secsTo( const TQDateTime &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 TQDateTime::operator==( const TQDateTime &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 TQDateTime::operator!=( const TQDateTime &dt ) const +{ + return t != dt.t || d != dt.d; +} + +/*! + Returns TRUE if this datetime is earlier than \a dt; otherwise + returns FALSE. +*/ + +bool TQDateTime::operator<( const TQDateTime &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 TQDateTime::operator<=( const TQDateTime &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 TQDateTime::operator>( const TQDateTime &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 TQDateTime::operator>=( const TQDateTime &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 TQDate::currentDate(), TQTime::currentTime() +*/ + +TQDateTime TQDateTime::currentDateTime() +{ + return currentDateTime( TQt::LocalTime ); +} + +/*! + Returns the current datetime, as reported by the system clock, for the + TimeSpec \a ts. The default TimeSpec is LocalTime. + + \sa TQDate::currentDate(), TQTime::currentTime(), TQt::TimeSpec +*/ + +TQDateTime TQDateTime::currentDateTime( TQt::TimeSpec ts ) +{ + TQDateTime dt; + TQTime t; + dt.setDate( TQDate::currentDate(ts) ); + if ( TQTime::currentTime(&t, ts) ) // midnight or right after? + dt.setDate( TQDate::currentDate(ts) ); // fetch date again + dt.setTime( t ); + return dt; +} + +#ifndef TQT_NO_DATESTRING +/*! + Returns the TQDateTime represented by the string \a s, using the + format \a f, or an invalid datetime if this is not possible. + + Note for \c TQt::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 TQt::LocalDate cannot be used here. +*/ +TQDateTime TQDateTime::fromString( const TQString& s, TQt::DateFormat f ) +{ + if ( ( s.isEmpty() ) || ( f == TQt::LocalDate ) ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQDateTime::fromString: Parameter out of range" ); +#endif + TQDateTime dt; + dt.d.jd = 0; + return dt; + } + if ( f == TQt::ISODate ) { + return TQDateTime( TQDate::fromString( s.mid(0,10), TQt::ISODate ), + TQTime::fromString( s.mid(11), TQt::ISODate ) ); + } +#if !defined(TQT_NO_REGEXP) && !defined(TQT_NO_TEXTDATE) + else if ( f == TQt::TextDate ) { + const int firstSpace = s.find(' '); + TQString monthName( s.mid( firstSpace + 1, 3 ) ); + int month = -1; + // Assume that English monthnames are the default + for ( int i = 0; i < 12; ++i ) { + if ( monthName == qt_shortMonthNames[i] ) { + month = i + 1; + break; + } + } + // If English names can't be found, search the localized ones + if ( month == -1 ) { + for ( int i = 1; i <= 12; ++i ) { + if ( monthName == TQDate::shortMonthName( i ) ) { + month = i; + break; + } + } + } +#if defined(QT_CHECK_RANGE) + if ( month < 1 || month > 12 ) { + tqWarning( "TQDateTime::fromString: Parameter out of range" ); + TQDateTime dt; + dt.d.jd = 0; + return dt; + } +#endif + int day = s.mid( firstSpace + 5, 2 ).simplifyWhiteSpace().toInt(); + int year = s.right( 4 ).toInt(); + TQDate date( year, month, day ); + TQTime time; + int hour, minute, second; + int pivot = s.find( TQRegExp(TQString::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 ); + } + return TQDateTime( date, time ); + } +#endif //TQT_NO_REGEXP + return TQDateTime(); +} +#endif //TQT_NO_DATESTRING + + +/***************************************************************************** + Date/time stream functions + *****************************************************************************/ + +#ifndef TQT_NO_DATASTREAM +/*! + \relates TQDate + + Writes the date, \a d, to the data stream, \a s. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator<<( TQDataStream &s, const TQDate &d ) +{ + return s << (TQ_UINT32)(d.jd); +} + +/*! + \relates TQDate + + Reads a date from the stream \a s into \a d. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator>>( TQDataStream &s, TQDate &d ) +{ + TQ_UINT32 jd; + s >> jd; + d.jd = jd; + return s; +} + +/*! + \relates TQTime + + Writes time \a t to the stream \a s. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator<<( TQDataStream &s, const TQTime &t ) +{ + return s << (TQ_UINT32)(t.ds); +} + +/*! + \relates TQTime + + Reads a time from the stream \a s into \a t. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator>>( TQDataStream &s, TQTime &t ) +{ + TQ_UINT32 ds; + s >> ds; + t.ds = ds; + return s; +} + +/*! + \relates TQDateTime + + Writes the datetime \a dt to the stream \a s. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator<<( TQDataStream &s, const TQDateTime &dt ) +{ + return s << dt.d << dt.t; +} + +/*! + \relates TQDateTime + + Reads a datetime from the stream \a s into \a dt. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator>>( TQDataStream &s, TQDateTime &dt ) +{ + s >> dt.d >> dt.t; + return s; +} +#endif //TQT_NO_DATASTREAM diff --git a/src/tools/tqdatetime.h b/src/tools/tqdatetime.h new file mode 100644 index 000000000..545f1f56b --- /dev/null +++ b/src/tools/tqdatetime.h @@ -0,0 +1,254 @@ +/************************************************************************* +** +** Definition of date and time classes +** +** Created : 940124 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQDATETIME_H +#define TQDATETIME_H + +#ifndef QT_H +#include "tqstring.h" +#include "ntqnamespace.h" +#endif // QT_H + +#include + +/***************************************************************************** + TQDate class + *****************************************************************************/ + +class TQ_EXPORT TQDate +{ +public: + TQDate() { jd = 0; } + TQDate( int y, int m, int d ); + + bool isNull() const { return jd == 0; } + bool isValid() const; + + int year() const; + int month() const; + int day() const; + int dayOfWeek() const; + int dayOfYear() const; + int daysInMonth() const; + int daysInYear() const; + int weekNumber( int *yearNum = 0 ) const; + +#ifndef TQT_NO_TEXTDATE +#ifndef TQT_NO_COMPAT + static TQString monthName( int month ) { return shortMonthName( month ); } + static TQString dayName( int weekday ) { return shortDayName( weekday ); } +#endif + static TQString shortMonthName( int month ); + static TQString shortDayName( int weekday ); + static TQString longMonthName( int month ); + static TQString longDayName( int weekday ); +#endif //TQT_NO_TEXTDATE +#ifndef TQT_NO_TEXTSTRING +#if !defined(TQT_NO_SPRINTF) + TQString toString( TQt::DateFormat f = TQt::TextDate ) const; +#endif + TQString toString( const TQString& format ) const; +#endif + bool setYMD( int y, int m, int d ); + + TQDate addDays( int days ) const; + TQDate addMonths( int months ) const; + TQDate addYears( int years ) const; + int daysTo( const TQDate & ) const; + + bool operator==( const TQDate &d ) const { return jd == d.jd; } + bool operator!=( const TQDate &d ) const { return jd != d.jd; } + bool operator<( const TQDate &d ) const { return jd < d.jd; } + bool operator<=( const TQDate &d ) const { return jd <= d.jd; } + bool operator>( const TQDate &d ) const { return jd > d.jd; } + bool operator>=( const TQDate &d ) const { return jd >= d.jd; } + + static TQDate currentDate(); + static TQDate currentDate( TQt::TimeSpec ); +#ifndef TQT_NO_DATESTRING + static TQDate fromString( const TQString& s, TQt::DateFormat f = TQt::TextDate ); +#endif + static bool isValid( int y, int m, int d ); + static bool leapYear( int year ); + + static uint gregorianToJulian( int y, int m, int d ); + static void julianToGregorian( uint jd, int &y, int &m, int &d ); +private: + uint jd; + friend class TQDateTime; +#ifndef TQT_NO_DATASTREAM + friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQDate & ); + friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQDate & ); +#endif +}; + + +/***************************************************************************** + TQTime class + *****************************************************************************/ + +class TQ_EXPORT TQTime +{ +public: + TQTime() { ds=0; } // set null time + TQTime( int h, int m, int s=0, int ms=0 ); // set time + + bool isNull() const { return ds == 0; } + bool isValid() const; // valid time + + int hour() const; // 0..23 + int minute() const; // 0..59 + int second() const; // 0..59 + int msec() const; // 0..999 +#ifndef TQT_NO_DATESTRING +#ifndef TQT_NO_SPRINTF + TQString toString( TQt::DateFormat f = TQt::TextDate ) const; +#endif + TQString toString( const TQString& format ) const; +#endif + bool setHMS( int h, int m, int s, int ms=0 ); + + TQTime addSecs( int secs ) const; + int secsTo( const TQTime & ) const; + TQTime addMSecs( int ms ) const; + int msecsTo( const TQTime & ) const; + + bool operator==( const TQTime &d ) const { return ds == d.ds; } + bool operator!=( const TQTime &d ) const { return ds != d.ds; } + bool operator<( const TQTime &d ) const { return ds < d.ds; } + bool operator<=( const TQTime &d ) const { return ds <= d.ds; } + bool operator>( const TQTime &d ) const { return ds > d.ds; } + bool operator>=( const TQTime &d ) const { return ds >= d.ds; } + + static TQTime currentTime(); + static TQTime currentTime( TQt::TimeSpec ); +#ifndef TQT_NO_DATESTRING + static TQTime fromString( const TQString& s, TQt::DateFormat f = TQt::TextDate ); +#endif + static bool isValid( int h, int m, int s, int ms=0 ); + + void start(); + int restart(); + int elapsed() const; + +private: + static bool currentTime( TQTime * ); + static bool currentTime( TQTime *, TQt::TimeSpec ); + + uint ds; + friend class TQDateTime; +#ifndef TQT_NO_DATASTREAM + friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQTime & ); + friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQTime & ); +#endif +}; + + +/***************************************************************************** + TQDateTime class + *****************************************************************************/ + +class TQ_EXPORT TQDateTime +{ +public: + TQDateTime() {} // set null date and null time + TQDateTime( const TQDate & ); + TQDateTime( const TQDate &, const TQTime & ); + + bool isNull() const { return d.isNull() && t.isNull(); } + bool isValid() const { return d.isValid() && t.isValid(); } + + TQDate date() const { return d; } + TQTime time() const { return t; } + time_t toTime_t() const; + void setDate( const TQDate &date ) { d = date; } + void setTime( const TQTime &time ) { t = time; } + void setTime_t( time_t secsSince1Jan1970UTC ); + void setTime_t( time_t secsSince1Jan1970UTC, TQt::TimeSpec ); +#ifndef TQT_NO_DATESTRING +#ifndef TQT_NO_SPRINTF + TQString toString( TQt::DateFormat f = TQt::TextDate ) const; +#endif + TQString toString( const TQString& format ) const; +#endif + TQDateTime addDays( int days ) const; + TQDateTime addMonths( int months ) const; + TQDateTime addYears( int years ) const; + TQDateTime addSecs( int secs ) const; + int daysTo( const TQDateTime & ) const; + int secsTo( const TQDateTime & ) const; + + bool operator==( const TQDateTime &dt ) const; + bool operator!=( const TQDateTime &dt ) const; + bool operator<( const TQDateTime &dt ) const; + bool operator<=( const TQDateTime &dt ) const; + bool operator>( const TQDateTime &dt ) const; + bool operator>=( const TQDateTime &dt ) const; + + static TQDateTime currentDateTime(); + static TQDateTime currentDateTime( TQt::TimeSpec ); +#ifndef TQT_NO_DATESTRING + static TQDateTime fromString( const TQString& s, TQt::DateFormat f = TQt::TextDate ); +#endif +private: + TQDate d; + TQTime t; +#ifndef TQT_NO_DATASTREAM + friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQDateTime &); + friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQDateTime & ); +#endif +}; + + +/***************************************************************************** + Date and time stream functions + *****************************************************************************/ + +#ifndef TQT_NO_DATASTREAM +TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQDate & ); +TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQDate & ); +TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQTime & ); +TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQTime & ); +TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQDateTime & ); +TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQDateTime & ); +#endif // TQT_NO_DATASTREAM + +#endif // TQDATETIME_H + diff --git a/src/widgets/ntqdatetimeedit.h b/src/widgets/ntqdatetimeedit.h deleted file mode 100644 index f125c673a..000000000 --- a/src/widgets/ntqdatetimeedit.h +++ /dev/null @@ -1,293 +0,0 @@ -/**************************************************************************** -** -** Definition of date and time edit classes -** -** Created : 001103 -** -** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQDATETIMEEDIT_H -#define TQDATETIMEEDIT_H - -#ifndef QT_H -#include "tqwidget.h" -#include "tqstring.h" -#include "ntqdatetime.h" -#endif // QT_H - -#ifndef TQT_NO_DATETIMEEDIT - -class TQ_EXPORT TQDateTimeEditBase : public TQWidget -{ - TQ_OBJECT -public: - TQDateTimeEditBase( TQWidget* parent=0, const char* name=0 ) - : TQWidget( parent, name ) {} - - virtual bool setFocusSection( int sec ) = 0; - virtual TQString sectionFormattedText( int sec ) = 0; - virtual void addNumber( int sec, int num ) = 0; - virtual void removeLastNumber( int sec ) = 0; - -public slots: - virtual void stepUp() = 0; - virtual void stepDown() = 0; - -private: -#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= - TQDateTimeEditBase( const TQDateTimeEditBase & ); - TQDateTimeEditBase &operator=( const TQDateTimeEditBase & ); -#endif -}; - -class TQDateEditPrivate; - -class TQ_EXPORT TQDateEdit : public TQDateTimeEditBase -{ - TQ_OBJECT - TQ_ENUMS( Order ) - TQ_PROPERTY( Order order READ order WRITE setOrder ) - TQ_PROPERTY( TQDate date READ date WRITE setDate ) - TQ_PROPERTY( bool autoAdvance READ autoAdvance WRITE setAutoAdvance ) - TQ_PROPERTY( TQDate maxValue READ maxValue WRITE setMaxValue ) - TQ_PROPERTY( TQDate minValue READ minValue WRITE setMinValue ) - -public: - TQDateEdit( TQWidget* parent=0, const char* name=0 ); - TQDateEdit( const TQDate& date, TQWidget* parent=0, const char* name=0 ); - ~TQDateEdit(); - - enum Order { DMY, MDY, YMD, YDM }; - - TQSize sizeHint() const; - TQSize minimumSizeHint() const; - -public slots: - virtual void setDate( const TQDate& date ); - -public: - TQDate date() const; - virtual void setOrder( Order order ); - Order order() const; - virtual void setAutoAdvance( bool advance ); - bool autoAdvance() const; - - virtual void setMinValue( const TQDate& d ) { setRange( d, maxValue() ); } - TQDate minValue() const; - virtual void setMaxValue( const TQDate& d ) { setRange( minValue(), d ); } - TQDate maxValue() const; - virtual void setRange( const TQDate& min, const TQDate& max ); - TQString separator() const; - virtual void setSeparator( const TQString& s ); - - // Make removeFirstNumber() virtual in TQDateTimeEditBase in 4.0 - void removeFirstNumber( int sec ); - -signals: - void valueChanged( const TQDate& date ); - -protected: - bool event( TQEvent *e ); - void timerEvent( TQTimerEvent * ); - void resizeEvent( TQResizeEvent * ); - void stepUp(); - void stepDown(); - TQString sectionFormattedText( int sec ); - void addNumber( int sec, int num ); - - void removeLastNumber( int sec ); - bool setFocusSection( int s ); - - virtual void setYear( int year ); - virtual void setMonth( int month ); - virtual void setDay( int day ); - virtual void fix(); - virtual bool outOfRange( int y, int m, int d ) const; - -protected slots: - void updateButtons(); - -private: - void init(); - int sectionOffsetEnd( int sec ) const; - int sectionLength( int sec ) const; - TQString sectionText( int sec ) const; - TQDateEditPrivate* d; - -#if defined(TQ_DISABLE_COPY) - TQDateEdit( const TQDateEdit & ); - TQDateEdit &operator=( const TQDateEdit & ); -#endif -}; - -class TQTimeEditPrivate; - -class TQ_EXPORT TQTimeEdit : public TQDateTimeEditBase -{ - TQ_OBJECT - TQ_SETS( Display ) - TQ_PROPERTY( TQTime time READ time WRITE setTime ) - TQ_PROPERTY( bool autoAdvance READ autoAdvance WRITE setAutoAdvance ) - TQ_PROPERTY( TQTime maxValue READ maxValue WRITE setMaxValue ) - TQ_PROPERTY( TQTime minValue READ minValue WRITE setMinValue ) - TQ_PROPERTY( Display display READ display WRITE setDisplay ) - -public: - enum Display { - Hours = 0x01, - Minutes = 0x02, - Seconds = 0x04, - /*Reserved = 0x08,*/ - AMPM = 0x10 - }; - - TQTimeEdit( TQWidget* parent=0, const char* name=0 ); - TQTimeEdit( const TQTime& time, TQWidget* parent=0, const char* name=0 ); - ~TQTimeEdit(); - - TQSize sizeHint() const; - TQSize minimumSizeHint() const; - -public slots: - virtual void setTime( const TQTime& time ); - -public: - TQTime time() const; - virtual void setAutoAdvance( bool advance ); - bool autoAdvance() const; - - virtual void setMinValue( const TQTime& d ) { setRange( d, maxValue() ); } - TQTime minValue() const; - virtual void setMaxValue( const TQTime& d ) { setRange( minValue(), d ); } - TQTime maxValue() const; - virtual void setRange( const TQTime& min, const TQTime& max ); - TQString separator() const; - virtual void setSeparator( const TQString& s ); - - uint display() const; - void setDisplay( uint disp ); - - // Make removeFirstNumber() virtual in TQDateTimeEditBase in 4.0 - void removeFirstNumber( int sec ); - -signals: - void valueChanged( const TQTime& time ); - -protected: - bool event( TQEvent *e ); - void timerEvent( TQTimerEvent *e ); - void resizeEvent( TQResizeEvent * ); - void stepUp(); - void stepDown(); - TQString sectionFormattedText( int sec ); - void addNumber( int sec, int num ); - void removeLastNumber( int sec ); - bool setFocusSection( int s ); - - virtual bool outOfRange( int h, int m, int s ) const; - virtual void setHour( int h ); - virtual void setMinute( int m ); - virtual void setSecond( int s ); - -protected slots: - void updateButtons(); - -private: - void init(); - TQString sectionText( int sec ); - TQTimeEditPrivate* d; - -#if defined(TQ_DISABLE_COPY) - TQTimeEdit( const TQTimeEdit & ); - TQTimeEdit &operator=( const TQTimeEdit & ); -#endif -}; - - -class TQDateTimeEditPrivate; - -class TQ_EXPORT TQDateTimeEdit : public TQWidget -{ - TQ_OBJECT - TQ_PROPERTY( TQDateTime dateTime READ dateTime WRITE setDateTime ) - -public: - TQDateTimeEdit( TQWidget* parent=0, const char* name=0 ); - TQDateTimeEdit( const TQDateTime& datetime, TQWidget* parent=0, - const char* name=0 ); - ~TQDateTimeEdit(); - - TQSize sizeHint() const; - TQSize minimumSizeHint() const; - -public slots: - virtual void setDateTime( const TQDateTime & dt ); - -public: - TQDateTime dateTime() const; - - TQDateEdit* dateEdit() { return de; } - TQTimeEdit* timeEdit() { return te; } - - virtual void setAutoAdvance( bool advance ); - bool autoAdvance() const; - -signals: - void valueChanged( const TQDateTime& datetime ); - -protected: - // ### make init() private in TQt 4.0 - void init(); - void resizeEvent( TQResizeEvent * ); - -protected slots: - // ### make these two functions private in TQt 4.0, - // and merge them into one with no parameter - void newValue( const TQDate& d ); - void newValue( const TQTime& t ); - -private: - TQDateEdit* de; - TQTimeEdit* te; - TQDateTimeEditPrivate* d; - -#if defined(TQ_DISABLE_COPY) - TQDateTimeEdit( const TQDateTimeEdit & ); - TQDateTimeEdit &operator=( const TQDateTimeEdit & ); -#endif -}; - -#endif -#endif diff --git a/src/widgets/qbutton.cpp b/src/widgets/qbutton.cpp index 3b91b18fb..6eeb59f05 100644 --- a/src/widgets/qbutton.cpp +++ b/src/widgets/qbutton.cpp @@ -43,7 +43,7 @@ #include "ntqbuttongroup.h" #include "ntqbitmap.h" #include "ntqpainter.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqaccel.h" #include "ntqpixmapcache.h" #include "ntqapplication.h" diff --git a/src/widgets/qcombobox.cpp b/src/widgets/qcombobox.cpp index e8c1e28e0..47dfb959f 100644 --- a/src/widgets/qcombobox.cpp +++ b/src/widgets/qcombobox.cpp @@ -46,7 +46,7 @@ #include "ntqdrawutil.h" #include "tqstrlist.h" #include "ntqpixmap.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqapplication.h" #include "ntqlineedit.h" #include "ntqbitmap.h" diff --git a/src/widgets/qdatetimeedit.cpp b/src/widgets/qdatetimeedit.cpp deleted file mode 100644 index ce74b33a1..000000000 --- a/src/widgets/qdatetimeedit.cpp +++ /dev/null @@ -1,2842 +0,0 @@ -/**************************************************************************** -** -** Implementation of date and time edit classes -** -** Created : 001103 -** -** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqdatetimeedit.h" - -#ifndef TQT_NO_DATETIMEEDIT - -#include "../kernel/qinternal_p.h" -#include "../kernel/qrichtext_p.h" -#include "ntqrangecontrol.h" -#include "ntqapplication.h" -#include "ntqpixmap.h" -#include "ntqapplication.h" -#include "tqvaluelist.h" -#include "tqstring.h" -#include "tqstyle.h" - -#if defined(TQ_WS_WIN) -#include "qt_windows.h" -#endif - -#define TQDATETIMEEDIT_HIDDEN_CHAR '0' - -class TQ_EXPORT TQNumberSection -{ -public: - TQNumberSection( int selStart = 0, int selEnd = 0, bool separat = TRUE, int actual = -1 ) - : selstart( selStart ), selend( selEnd ), act( actual ), sep( separat ) - {} - int selectionStart() const { return selstart; } - void setSelectionStart( int s ) { selstart = s; } - int selectionEnd() const { return selend; } - void setSelectionEnd( int s ) { selend = s; } - int width() const { return selend - selstart; } - int index() const { return act; } - bool separator() const { return sep; } - TQ_DUMMY_COMPARISON_OPERATOR( TQNumberSection ) -private: - int selstart :12; - int selend :12; - int act :7; - bool sep :1; -}; - -static TQString *lDateSep = 0; -static TQString *lTimeSep = 0; -static bool lAMPM = FALSE; -static TQString *lAM = 0; -static TQString *lPM = 0; -static TQDateEdit::Order lOrder = TQDateEdit::YMD; -static int refcount = 0; - -static void cleanup() -{ - delete lDateSep; - lDateSep = 0; - delete lTimeSep; - lTimeSep = 0; - delete lAM; - lAM = 0; - delete lPM; - lPM = 0; -} - -/*! -\internal -try to get the order of DMY and the date/time separator from the locale settings -*/ -static void readLocaleSettings() -{ - int dpos, mpos, ypos; - cleanup(); - - lDateSep = new TQString(); - lTimeSep = new TQString(); - -#if defined(TQ_WS_WIN) - QT_WA( { - TCHAR data[10]; - GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SDATE, data, 10 ); - *lDateSep = TQString::fromUcs2( (ushort*)data ); - GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_STIME, data, 10 ); - *lTimeSep = TQString::fromUcs2( (ushort*)data ); - GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_ITIME, data, 10 ); - lAMPM = TQString::fromUcs2( (ushort*)data ).toInt()==0; - GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_S1159, data, 10 ); - TQString am = TQString::fromUcs2( (ushort*)data ); - if ( !am.isEmpty() ) - lAM = new TQString( am ); - GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_S2359, data, 10 ); - TQString pm = TQString::fromUcs2( (ushort*)data ); - if ( !pm.isEmpty() ) - lPM = new TQString( pm ); - } , { - char data[10]; - GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_SDATE, (char*)&data, 10 ); - *lDateSep = TQString::fromLocal8Bit( data ); - GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_STIME, (char*)&data, 10 ); - *lTimeSep = TQString::fromLocal8Bit( data ); - GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_ITIME, (char*)&data, 10 ); - lAMPM = TQString::fromLocal8Bit( data ).toInt()==0; - GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_S1159, (char*)&data, 10 ); - TQString am = TQString::fromLocal8Bit( data ); - if ( !am.isEmpty() ) - lAM = new TQString( am ); - GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_S2359, (char*)&data, 10 ); - TQString pm = TQString::fromLocal8Bit( data ); - if ( !pm.isEmpty() ) - lPM = new TQString( pm ); - } ); -#else - *lDateSep = "-"; - *lTimeSep = ":"; -#endif - TQString d = TQDate( 1999, 11, 22 ).toString( TQt::LocalDate ); - dpos = d.find( "22" ); - mpos = d.find( "11" ); - ypos = d.find( "99" ); - if ( dpos > -1 && mpos > -1 && ypos > -1 ) { - // test for DMY, MDY, YMD, YDM - if ( dpos < mpos && mpos < ypos ) { - lOrder = TQDateEdit::DMY; - } else if ( mpos < dpos && dpos < ypos ) { - lOrder = TQDateEdit::MDY; - } else if ( ypos < mpos && mpos < dpos ) { - lOrder = TQDateEdit::YMD; - } else if ( ypos < dpos && dpos < mpos ) { - lOrder = TQDateEdit::YDM; - } else { - // cannot determine the dateformat - use the default - return; - } - - // this code needs to change if new formats are added - -#ifndef TQ_WS_WIN - TQString sep = d.mid( TQMIN( dpos, mpos ) + 2, TQABS( dpos - mpos ) - 2 ); - if ( d.contains( sep ) == 2 ) { - *lDateSep = sep; - } -#endif - } - -#ifndef TQ_WS_WIN - TQString t = TQTime( 11, 22, 33 ).toString( TQt::LocalDate ); - dpos = t.find( "11" ); - mpos = t.find( "22" ); - ypos = t.find( "33" ); - // We only allow hhmmss - if ( dpos > -1 && dpos < mpos && mpos < ypos ) { - TQString sep = t.mid( dpos + 2, mpos - dpos - 2 ); - if ( sep == t.mid( mpos + 2, ypos - mpos - 2 ) ) { - *lTimeSep = sep; - } - } -#endif -} - -static TQDateEdit::Order localOrder() { - if ( !lDateSep ) { - readLocaleSettings(); - } - return lOrder; -} - -static TQString localDateSep() { - if ( !lDateSep ) { - readLocaleSettings(); - } - return *lDateSep; -} - -static TQString localTimeSep() { - if ( !lTimeSep ) { - readLocaleSettings(); - } - return *lTimeSep; -} - -class TQDateTimeEditorPrivate -{ -public: - TQDateTimeEditorPrivate() - : frm( TRUE ), - parag( new TQTextParagraph( 0, 0, 0, FALSE ) ), - focusSec(0) - { - parag->formatter()->setWrapEnabled( FALSE ); - cursor = new TQTextCursor( 0 ); - cursor->setParagraph( parag ); - offset = 0; - sep = localDateSep(); - refcount++; - } - ~TQDateTimeEditorPrivate() - { - delete parag; - delete cursor; - if ( !--refcount ) - cleanup(); - } - - void appendSection( const TQNumberSection& sec ) - { - sections.append( sec ); - - } - void clearSections() - { - sections.clear(); - } - void setSectionSelection( int sec, int selstart, int selend ) - { - if ( sec < 0 || sec > (int)sections.count() ) - return; - sections[sec].setSelectionStart( selstart ); - sections[sec].setSelectionEnd( selend ); - } - uint sectionCount() const { return (uint)sections.count(); } - void setSeparator( const TQString& s ) { sep = s; } - TQString separator() const { return sep; } - - void setFrame( bool f ) { frm = f; } - bool frame() const { return frm; } - - int focusSection() const { return focusSec; } - int section( const TQPoint& p ) - { - cursor->place( p + TQPoint( offset, 0 ), parag ); - int idx = cursor->index(); - for ( uint i = 0; i < sections.count(); ++i ) { - if ( idx >= sections[i].selectionStart() && - idx <= sections[i].selectionEnd() ) - return i; - } - return -1; - } - TQNumberSection section( int idx ) const - { - return sections[idx]; - } - bool setFocusSection( int idx ) - { - if ( idx > (int)sections.count()-1 || idx < 0 ) - return FALSE; - if ( idx != focusSec ) { - focusSec = idx; - applyFocusSelection(); - return TRUE; - } - return FALSE; - } - - bool inSectionSelection( int idx ) - { - for ( uint i = 0; i < sections.count(); ++i ) { - if ( idx >= sections[i].selectionStart() && - idx <= sections[i].selectionEnd() ) - return TRUE; - } - return FALSE; - } - - void paint( const TQString& txt, bool focus, TQPainter& p, - const TQColorGroup& cg, const TQRect& rect, TQStyle& style ) - { - int fw = 0; - if ( frm ) - fw = style.pixelMetric(TQStyle::PM_DefaultFrameWidth); - - parag->truncate( 0 ); - parag->append( txt ); - if ( !focus ) - parag->removeSelection( TQTextDocument::Standard ); - else { - applyFocusSelection(); - } - - /* color all TQDATETIMEEDIT_HIDDEN_CHAR chars to background color */ - TQTextFormat *fb = parag->formatCollection()->format( p.font(), - cg.base() ); - TQTextFormat *nf = parag->formatCollection()->format( p.font(), - cg.text() ); - for ( uint i = 0; i < txt.length(); ++i ) { - parag->setFormat( i, 1, nf ); - if ( inSectionSelection( i ) ) - continue; - if ( txt.at(i) == TQDATETIMEEDIT_HIDDEN_CHAR ) - parag->setFormat( i, 1, fb ); - else - parag->setFormat( i, 1, nf ); - } - fb->removeRef(); - nf->removeRef(); - - TQRect r( rect.x(), rect.y(), rect.width() - 2 * ( 2 + fw ), rect.height() ); - parag->pseudoDocument()->docRect = r; - parag->invalidate(0); - parag->format(); - - int xoff = 2 + fw - offset; - int yoff = ( rect.height() - parag->rect().height() + 1 ) / 2; - if ( yoff < 0 ) - yoff = 0; - - p.translate( xoff, yoff ); - parag->paint( p, cg, 0, TRUE ); - if ( frm ) - p.translate( -xoff, -yoff ); - } - - void resize( const TQSize& size ) { sz = size; } - - int mapSection( int sec ) - { - return sections[sec].index(); - } - -protected: - void applyFocusSelection() - { - if ( focusSec > -1 ) { - int selstart = sections[ focusSec ].selectionStart(); - int selend = sections[ focusSec ].selectionEnd(); - parag->setSelection( TQTextDocument::Standard, selstart, selend ); - parag->format(); - if ( parag->at( selstart )->x < offset || - parag->at( selend )->x + parag->string()->width( selend ) > offset + sz.width() ) { - offset = parag->at( selstart )->x; - } - } - } -private: - bool frm; - TQTextParagraph *parag; - TQTextCursor *cursor; - TQSize sz; - int focusSec; - TQValueList< TQNumberSection > sections; - TQString sep; - int offset; -}; - -class TQDateTimeEditor : public TQWidget -{ - TQ_OBJECT -public: - TQDateTimeEditor( TQDateTimeEditBase * widget, TQWidget *parent, - const char * name=0 ); - ~TQDateTimeEditor(); - - void setControlWidget( TQDateTimeEditBase * widget ); - TQDateTimeEditBase * controlWidget() const; - - void setSeparator( const TQString& s ); - TQString separator() const; - - int focusSection() const; - bool setFocusSection( int s ); - void appendSection( const TQNumberSection& sec ); - void clearSections(); - void setSectionSelection( int sec, int selstart, int selend ); - bool eventFilter( TQObject *o, TQEvent *e ); - int sectionAt( const TQPoint &p ); - int mapSection( int sec ); - -protected: - void init(); - bool event( TQEvent *e ); - void resizeEvent( TQResizeEvent * ); - void paintEvent( TQPaintEvent * ); - void mousePressEvent( TQMouseEvent *e ); - -private: - TQDateTimeEditBase* cw; - TQDateTimeEditorPrivate* d; -}; - -class TQDateTimeSpinWidget : public TQSpinWidget -{ -public: - TQDateTimeSpinWidget( TQWidget *parent, const char *name ) - : TQSpinWidget( parent, name ) - { - } - - void enabledChange(bool notenabled) - { - TQDateEdit *de = ::tqt_cast(parentWidget()); - if (de && !notenabled) { - setUpEnabled(de->date() < de->maxValue()); - setDownEnabled(de->date() > de->minValue()); - } else { - setUpEnabled(!notenabled); - setDownEnabled(!notenabled); - } - } - -protected: -#ifndef TQT_NO_WHEELEVENT - void wheelEvent( TQWheelEvent *e ) - { - TQDateTimeEditor *editor = (TQDateTimeEditor*)editWidget()->tqt_cast( "TQDateTimeEditor" ); - Q_ASSERT( editor ); - if ( !editor ) - return; - - int section = editor->sectionAt( e->pos() ); - editor->setFocusSection( section ); - - if ( section == -1 ) - return; - TQSpinWidget::wheelEvent( e ); - } -#endif -}; - -/*! - Constructs an empty datetime editor with parent \a parent and - called \a name. -*/ -TQDateTimeEditor::TQDateTimeEditor( TQDateTimeEditBase * widget, TQWidget *parent, - const char * name ) - : TQWidget( parent, name, WNoAutoErase ) -{ - d = new TQDateTimeEditorPrivate(); - cw = widget; - init(); -} - -/*! - Destroys the object and frees any allocated resources. -*/ - -TQDateTimeEditor::~TQDateTimeEditor() -{ - delete d; -} - -/*! \internal - -*/ - -void TQDateTimeEditor::init() -{ - setBackgroundMode( PaletteBase ); - setFocusSection( -1 ); - installEventFilter( this ); - setFocusPolicy( WheelFocus ); -} - - -/*! \reimp - -*/ - -bool TQDateTimeEditor::event( TQEvent *e ) -{ - if ( e->type() == TQEvent::FocusIn || e->type() == TQEvent::FocusOut ) { - if ( e->type() == TQEvent::FocusOut ) - tqApp->sendEvent( cw, e ); - update( rect() ); - } else if ( e->type() == TQEvent::AccelOverride ) { - TQKeyEvent* ke = (TQKeyEvent*) e; - switch ( ke->key() ) { - case Key_Delete: - case Key_Backspace: - case Key_Up: - case Key_Down: - case Key_Left: - case Key_Right: - ke->accept(); - default: - break; - } - } - return TQWidget::event( e ); -} - -/*! \reimp - -*/ - -void TQDateTimeEditor::resizeEvent( TQResizeEvent *e ) -{ - d->resize( e->size() ); - TQWidget::resizeEvent( e ); -} - - -/*! \reimp - -*/ - -void TQDateTimeEditor::paintEvent( TQPaintEvent * ) -{ - TQString txt; - for ( uint i = 0; i < d->sectionCount(); ++i ) { - txt += cw->sectionFormattedText( i ); - if ( i < d->sectionCount()-1 ) { - if ( d->section( i+1 ).separator() ) - txt += d->separator(); - else - txt += " "; - } - } - - TQSharedDoubleBuffer buffer( this ); - const TQBrush &bg = - colorGroup().brush( isEnabled() ? TQColorGroup::Base : TQColorGroup::Background ); - buffer.painter()->fillRect( 0, 0, width(), height(), bg ); - d->paint( txt, hasFocus(), *buffer.painter(), colorGroup(), rect(), - style() ); - buffer.end(); -} - - -/*! - Returns the section index at point \a p. -*/ -int TQDateTimeEditor::sectionAt( const TQPoint &p ) -{ - return d->section( p ); -} - -int TQDateTimeEditor::mapSection( int sec ) -{ - return d->mapSection( sec ); -} - - -/*! \reimp - -*/ - -void TQDateTimeEditor::mousePressEvent( TQMouseEvent *e ) -{ - TQPoint p( e->pos().x(), 0 ); - int sec = sectionAt( p ); - if ( sec != -1 ) { - cw->setFocusSection( sec ); - repaint( rect(), FALSE ); - } -} - -/*! \reimp - -*/ -bool TQDateTimeEditor::eventFilter( TQObject *o, TQEvent *e ) -{ - if ( o == this ) { - if ( e->type() == TQEvent::KeyPress ) { - TQKeyEvent *ke = (TQKeyEvent*)e; - switch ( ke->key() ) { - case Key_Right: - if ( d->focusSection() < (int)d->sectionCount()-1 ) { - if ( cw->setFocusSection( focusSection()+1 ) ) - repaint( rect(), FALSE ); - } - return TRUE; - case Key_Left: - if ( d->focusSection() > 0 ) { - if ( cw->setFocusSection( focusSection()-1 ) ) - repaint( rect(), FALSE ); - } - return TRUE; - case Key_Up: - cw->stepUp(); - return TRUE; - case Key_Down: - cw->stepDown(); - return TRUE; - case Key_Backspace: - if ( ::tqt_cast(cw) ) - ((TQDateEdit*)cw)->removeFirstNumber( d->focusSection() ); - else if ( ::tqt_cast(cw) ) - ((TQTimeEdit*)cw)->removeFirstNumber( d->focusSection() ); - return TRUE; - case Key_Delete: - cw->removeLastNumber( d->focusSection() ); - return TRUE; - case Key_Tab: - case Key_BackTab: { - if ( ke->state() == TQt::ControlButton ) - return FALSE; - - TQWidget *w = this; - bool hadDateEdit = FALSE; - while ( w ) { - if ( ( ::tqt_cast(w) && qstrcmp( w->name(), "qt_spin_widget" ) != 0 ) || - ::tqt_cast(w) ) - break; - hadDateEdit = hadDateEdit || ::tqt_cast(w); - w = w->parentWidget(); - } - - if ( w ) { - if ( !::tqt_cast(w) ) { - w = w->parentWidget(); - } else { - TQDateTimeEdit *ed = (TQDateTimeEdit*)w; - if ( hadDateEdit && ke->key() == Key_Tab ) { - ed->timeEdit()->setFocus(); - return TRUE; - } else if ( !hadDateEdit && ke->key() == Key_BackTab ) { - ed->dateEdit()->setFocus(); - return TRUE; - } else { - while ( w && !::tqt_cast(w) ) - w = w->parentWidget(); - } - } - - tqApp->sendEvent( w, e ); - return TRUE; - } - } break; - default: - TQString txt = ke->text().lower(); - if ( !txt.isEmpty() && !separator().isEmpty() && txt[0] == separator()[0] ) { - // do the same thing as KEY_RIGHT when the user presses the separator key - if ( d->focusSection() < 2 ) { - if ( cw->setFocusSection( focusSection()+1 ) ) - repaint( rect(), FALSE ); - } - return TRUE; - } else if ( !txt.isEmpty() && ::tqt_cast(cw) && focusSection() == (int) d->sectionCount()-1 ) { - // the first character of the AM/PM indicator toggles if the section has focus - TQTimeEdit *te = (TQTimeEdit*)cw; - TQTime time = te->time(); - if ( lAMPM && lAM && lPM && (te->display()&TQTimeEdit::AMPM) ) { - if ( txt[0] == (*lAM).lower()[0] && time.hour() >= 12 ) { - time.setHMS( time.hour()-12, time.minute(), time.second(), time.msec() ); - te->setTime( time ); - } else if ( txt[0] == (*lPM).lower()[0] && time.hour() < 12 ) { - time.setHMS( time.hour()+12, time.minute(), time.second(), time.msec() ); - te->setTime( time ); - } - } - } - - int num = txt[0].digitValue(); - if ( num != -1 ) { - cw->addNumber( d->focusSection(), num ); - return TRUE; - } - } - } - } - return FALSE; -} - - -/*! - Appends the number section \a sec to the editor. -*/ - -void TQDateTimeEditor::appendSection( const TQNumberSection& sec ) -{ - d->appendSection( sec ); -} - -/*! - Removes all sections from the editor. -*/ - -void TQDateTimeEditor::clearSections() -{ - d->clearSections(); -} - -/*! - Sets the selection of \a sec to start at \a selstart and end at \a - selend. -*/ - -void TQDateTimeEditor::setSectionSelection( int sec, int selstart, int selend ) -{ - d->setSectionSelection( sec, selstart, selend ); -} - -/*! - Sets the separator for all numbered sections to \a s. Note that - currently, only the first character of \a s is used. -*/ - -void TQDateTimeEditor::setSeparator( const TQString& s ) -{ - d->setSeparator( s ); - update(); -} - - -/*! - Returns the editor's separator. -*/ - -TQString TQDateTimeEditor::separator() const -{ - return d->separator(); -} - -/*! - Returns the number of the section that has focus. -*/ - -int TQDateTimeEditor::focusSection() const -{ - return d->focusSection(); -} - - -/*! - Sets the focus to section \a sec. If \a sec does not exist, - nothing happens. -*/ - -bool TQDateTimeEditor::setFocusSection( int sec ) -{ - return d->setFocusSection( sec ); -} - -/*! \class TQDateTimeEditBase - \brief The TQDateTimeEditBase class provides an abstraction for date and edit editors. - - Small abstract class that provides some functions that are common - for both TQDateEdit and TQTimeEdit. It is used internally by - TQDateTimeEditor. -*/ - -/*! - \fn TQDateTimeEditBase::TQDateTimeEditBase(TQWidget *, const char*) - \internal -*/ - -/*! - \fn TQDateTimeEditBase::setFocusSection(int) - \internal -*/ - -/*! \fn TQString TQDateTimeEditBase::sectionFormattedText( int sec ) - \internal - - Pure virtual function which returns the formatted text of section \a - sec. - -*/ - -/*! \fn void TQDateTimeEditBase::stepUp() - \internal - - Pure virtual slot which is called whenever the user increases the - number in a section by pressing the widget's arrow buttons or the - keyboard's arrow keys. -*/ - -/*! \fn void TQDateTimeEditBase::stepDown() - \internal - - Pure virtual slot which is called whenever the user decreases the - number in a section by pressing the widget's arrow buttons or the - keyboard's arrow keys. - -*/ - -/*! \fn void TQDateTimeEditBase::addNumber( int sec, int num ) - \internal - - Pure virtual function which is called whenever the user types a number. - \a sec indicates the section where the number should be added. \a - num is the number that was pressed. -*/ - -/*! \fn void TQDateTimeEditBase::removeLastNumber( int sec ) - \internal - - Pure virtual function which is called whenever the user tries to - remove the last number from \a sec by pressing the delete key. -*/ - -//////////////// - -class TQDateEditPrivate -{ -public: - int y; - int m; - int d; - // remebers the last entry for the day. - // if the day is 31 and you cycle through the months, - // the day will be 31 again if you reach a month with 31 days - // otherwise it will be the highest day in the month - int dayCache; - int yearSection; - int monthSection; - int daySection; - TQDateEdit::Order ord; - bool overwrite; - bool adv; - int timerId; - bool typing; - TQDate min; - TQDate max; - bool changed; - TQDateTimeEditor *ed; - TQSpinWidget *controls; -}; - - -/*! - \class TQDateEdit ntqdatetimeedit.h - \brief The TQDateEdit class provides a date editor. - - \ingroup advanced - \ingroup time - \mainclass - - TQDateEdit allows the user to edit dates by using the keyboard or - the arrow keys to increase/decrease date values. The arrow keys - can be used to move from section to section within the TQDateEdit - box. Dates appear in accordance with the local date/time settings - or in year, month, day order if the system doesn't provide this - information. It is recommended that the TQDateEdit be initialised - with a date, e.g. - - \code - TQDateEdit *dateEdit = new TQDateEdit( TQDate::currentDate(), this ); - dateEdit->setRange( TQDate::currentDate().addDays( -365 ), - TQDate::currentDate().addDays( 365 ) ); - dateEdit->setOrder( TQDateEdit::MDY ); - dateEdit->setAutoAdvance( TRUE ); - \endcode - - Here we've created a new TQDateEdit object initialised with today's - date and restricted the valid date range to today plus or minus - 365 days. We've set the order to month, day, year. If the auto - advance property is TRUE (as we've set it here) when the user - completes a section of the date, e.g. enters two digits for the - month, they are automatically taken to the next section. - - The maximum and minimum values for a date value in the date editor - default to the maximum and minimum values for a TQDate. You can - change this by calling setMinValue(), setMaxValue() or setRange(). - - Terminology: A TQDateEdit widget comprises three 'sections', one - each for the year, month and day. You can change the separator - character using TQDateTimeEditor::setSeparator(), by default the - separator will be taken from the systems settings. If that is - not possible, it defaults to "-". - - \img datetimewidgets.png Date Time Widgets - - \sa TQDate TQTimeEdit TQDateTimeEdit -*/ - -/*! - \enum TQDateEdit::Order - - This enum defines the order in which the sections that comprise a - date appear. - \value MDY month-day-year - \value DMY day-month-year - \value YMD year-month-day (the default) - \value YDM year-day-month (included for completeness; but should - not be used) -*/ - -/*! - \enum TQTimeEdit::Display - - This enum defines the sections that comprise a time - - \value Hours The hours section - \value Minutes The minutes section - \value Seconds The seconds section - \value AMPM The AM/PM section - - The values can be or'ed together to show any combination. -*/ - -/*! - Constructs an empty date editor which is a child of \a parent and - called name \a name. -*/ - -TQDateEdit::TQDateEdit( TQWidget * parent, const char * name ) - : TQDateTimeEditBase( parent, name ) -{ - init(); - updateButtons(); -} - -/*! - \overload - - Constructs a date editor with the initial value \a date, parent \a - parent and called \a name. - - The date editor is initialized with \a date. -*/ - -TQDateEdit::TQDateEdit( const TQDate& date, TQWidget * parent, const char * name ) - : TQDateTimeEditBase( parent, name ) -{ - init(); - setDate( date ); -} - -/*! \internal -*/ -void TQDateEdit::init() -{ - d = new TQDateEditPrivate(); - d->controls = new TQDateTimeSpinWidget( this, qstrcmp( name(), "qt_datetime_dateedit" ) == 0 ? "qt_spin_widget" : "date edit controls" ); - d->ed = new TQDateTimeEditor( this, d->controls, "date editor" ); - d->controls->setEditWidget( d->ed ); - setFocusProxy( d->ed ); - connect( d->controls, TQ_SIGNAL( stepUpPressed() ), TQ_SLOT( stepUp() ) ); - connect( d->controls, TQ_SIGNAL( stepDownPressed() ), TQ_SLOT( stepDown() ) ); - connect( this, TQ_SIGNAL( valueChanged(const TQDate&) ), - TQ_SLOT( updateButtons() ) ); - d->ed->appendSection( TQNumberSection( 0,4 ) ); - d->ed->appendSection( TQNumberSection( 5,7 ) ); - d->ed->appendSection( TQNumberSection( 8,10 ) ); - - d->yearSection = -1; - d->monthSection = -1; - d->daySection = -1; - - d->y = 0; - d->m = 0; - d->d = 0; - d->dayCache = 0; - setOrder( localOrder() ); - setFocusSection( 0 ); - d->overwrite = TRUE; - d->adv = FALSE; - d->timerId = 0; - d->typing = FALSE; - d->min = TQDate( 1752, 9, 14 ); - d->max = TQDate( 8000, 12, 31 ); - d->changed = FALSE; - - setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ); - - refcount++; -} - -/*! - Destroys the object and frees any allocated resources. -*/ - -TQDateEdit::~TQDateEdit() -{ - delete d; - if ( !--refcount ) - cleanup(); -} - -/*! - \property TQDateEdit::minValue - - \brief the editor's minimum value - - Setting the minimum date value is equivalent to calling - TQDateEdit::setRange( \e d, maxValue() ), where \e d is the minimum - date. The default minimum date is 1752-09-14. - - \sa maxValue setRange() -*/ - -TQDate TQDateEdit::minValue() const -{ - return d->min; -} - -/*! - \property TQDateEdit::maxValue - - \brief the editor's maximum value - - Setting the maximum date value for the editor is equivalent to - calling TQDateEdit::setRange( minValue(), \e d ), where \e d is the - maximum date. The default maximum date is 8000-12-31. - - \sa minValue setRange() -*/ - -TQDate TQDateEdit::maxValue() const -{ - return d->max; -} - - -/*! - Sets the valid input range for the editor to be from \a min to \a - max inclusive. If \a min is invalid no minimum date will be set. - Similarly, if \a max is invalid no maximum date will be set. -*/ - -void TQDateEdit::setRange( const TQDate& min, const TQDate& max ) -{ - if ( min.isValid() ) - d->min = min; - if ( max.isValid() ) - d->max = max; -} - -/*! - Sets the separator to \a s. Note that currently only the first - character of \a s is used. -*/ - -void TQDateEdit::setSeparator( const TQString& s ) -{ - d->ed->setSeparator( s ); -} - -/*! - Returns the editor's separator. -*/ - -TQString TQDateEdit::separator() const -{ - return d->ed->separator(); -} - - -/*! - Enables/disables the push buttons according to the min/max date - for this widget. -*/ - -void TQDateEdit::updateButtons() -{ - if ( !isEnabled() ) - return; - - bool upEnabled = date() < maxValue(); - bool downEnabled = date() > minValue(); - - d->controls->setUpEnabled( upEnabled ); - d->controls->setDownEnabled( downEnabled ); -} - -/*! \reimp - */ -void TQDateEdit::resizeEvent( TQResizeEvent * ) -{ - d->controls->resize( width(), height() ); -} - -/*! \reimp - -*/ -TQSize TQDateEdit::sizeHint() const -{ - constPolish(); - TQFontMetrics fm( font() ); - int fw = style().pixelMetric( TQStyle::PM_DefaultFrameWidth, this ); - int h = TQMAX( fm.lineSpacing(), 14 ) + 2; - int w = 2 + fm.width( '9' ) * 8 + fm.width( d->ed->separator() ) * 2 + d->controls->upRect().width() + fw * 4; - - return TQSize( w, TQMAX(h + fw * 2,20) ).expandedTo( TQApplication::globalStrut() ); -} - -/*! \reimp - -*/ -TQSize TQDateEdit::minimumSizeHint() const -{ - return sizeHint(); -} - - -/*! - Returns the formatted number for section \a sec. This will - correspond to either the year, month or day section, depending on - the current display order. - - \sa setOrder() -*/ - -TQString TQDateEdit::sectionFormattedText( int sec ) -{ - TQString txt; - txt = sectionText( sec ); - if ( d->typing && sec == d->ed->focusSection() ) - d->ed->setSectionSelection( sec, sectionOffsetEnd( sec ) - txt.length(), - sectionOffsetEnd( sec ) ); - else - d->ed->setSectionSelection( sec, sectionOffsetEnd( sec ) - sectionLength( sec ), - sectionOffsetEnd( sec ) ); - txt = txt.rightJustify( sectionLength( sec ), TQDATETIMEEDIT_HIDDEN_CHAR ); - return txt; -} - - -/*! - Returns the desired length (number of digits) of section \a sec. - This will correspond to either the year, month or day section, - depending on the current display order. - - \sa setOrder() -*/ - -int TQDateEdit::sectionLength( int sec ) const -{ - int val = 0; - if ( sec == d->yearSection ) { - val = 4; - } else if ( sec == d->monthSection ) { - val = 2; - } else if ( sec == d->daySection ) { - val = 2; - } - return val; -} - -/*! - Returns the text of section \a sec. This will correspond to either - the year, month or day section, depending on the current display - order. - - \sa setOrder() -*/ - -TQString TQDateEdit::sectionText( int sec ) const -{ - int val = 0; - if ( sec == d->yearSection ) { - val = d->y; - } else if ( sec == d->monthSection ) { - val = d->m; - } else if ( sec == d->daySection ) { - val = d->d; - } - return TQString::number( val ); -} - -/*! \internal - - Returns the end of the section offset \a sec. - -*/ - -int TQDateEdit::sectionOffsetEnd( int sec ) const -{ - if ( sec == d->yearSection ) { - switch( d->ord ) { - case DMY: - case MDY: - return sectionOffsetEnd( sec-1) + separator().length() + sectionLength( sec ); - case YMD: - case YDM: - return sectionLength( sec ); - } - } else if ( sec == d->monthSection ) { - switch( d->ord ) { - case DMY: - case YDM: - case YMD: - return sectionOffsetEnd( sec-1) + separator().length() + sectionLength( sec ); - case MDY: - return sectionLength( sec ); - } - } else if ( sec == d->daySection ) { - switch( d->ord ) { - case DMY: - return sectionLength( sec ); - case YMD: - case MDY: - case YDM: - return sectionOffsetEnd( sec-1 ) + separator().length() + sectionLength( sec ); - } - } - return 0; -} - - -/*! - \property TQDateEdit::order - \brief the order in which the year, month and day appear - - The default order is locale dependent. - - \sa Order -*/ - -void TQDateEdit::setOrder( TQDateEdit::Order order ) -{ - d->ord = order; - switch( d->ord ) { - case DMY: - d->yearSection = 2; - d->monthSection = 1; - d->daySection = 0; - break; - case MDY: - d->yearSection = 2; - d->monthSection = 0; - d->daySection = 1; - break; - case YMD: - d->yearSection = 0; - d->monthSection = 1; - d->daySection = 2; - break; - case YDM: - d->yearSection = 0; - d->monthSection = 2; - d->daySection = 1; - break; - } - if ( isVisible() ) - d->ed->repaint( d->ed->rect(), FALSE ); -} - - -TQDateEdit::Order TQDateEdit::order() const -{ - return d->ord; -} - - -/*! \reimp - -*/ -void TQDateEdit::stepUp() -{ - int sec = d->ed->focusSection(); - bool accepted = FALSE; - if ( sec == d->yearSection ) { - if ( !outOfRange( d->y+1, d->m, d->d ) ) { - accepted = TRUE; - setYear( d->y+1 ); - } - } else if ( sec == d->monthSection ) { - if ( !outOfRange( d->y, d->m+1, d->d ) ) { - accepted = TRUE; - setMonth( d->m+1 ); - } - } else if ( sec == d->daySection ) { - if ( !outOfRange( d->y, d->m, d->d+1 ) ) { - accepted = TRUE; - setDay( d->d+1 ); - } - } - if ( accepted ) { - d->changed = FALSE; - emit valueChanged( date() ); - } - d->ed->repaint( d->ed->rect(), FALSE ); -} - - - -/*! \reimp - -*/ - -void TQDateEdit::stepDown() -{ - int sec = d->ed->focusSection(); - bool accepted = FALSE; - if ( sec == d->yearSection ) { - if ( !outOfRange( d->y-1, d->m, d->d ) ) { - accepted = TRUE; - setYear( d->y-1 ); - } - } else if ( sec == d->monthSection ) { - if ( !outOfRange( d->y, d->m-1, d->d ) ) { - accepted = TRUE; - setMonth( d->m-1 ); - } - } else if ( sec == d->daySection ) { - if ( !outOfRange( d->y, d->m, d->d-1 ) ) { - accepted = TRUE; - setDay( d->d-1 ); - } - } - if ( accepted ) { - d->changed = FALSE; - emit valueChanged( date() ); - } - d->ed->repaint( d->ed->rect(), FALSE ); -} - -/*! - Sets the year to \a year, which must be a valid year. The range - currently supported is from 1752 to 8000. - - \sa TQDate -*/ - -void TQDateEdit::setYear( int year ) -{ - if ( year < 1752 ) - year = 1752; - if ( year > 8000 ) - year = 8000; - if ( !outOfRange( year, d->m, d->d ) ) { - d->y = year; - setMonth( d->m ); - int tmp = d->dayCache; - setDay( d->dayCache ); - d->dayCache = tmp; - } -} - - -/*! - Sets the month to \a month, which must be a valid month, i.e. - between 1 and 12. -*/ - -void TQDateEdit::setMonth( int month ) -{ - if ( month < 1 ) - month = 1; - if ( month > 12 ) - month = 12; - if ( !outOfRange( d->y, month, d->d ) ) { - d->m = month; - int tmp = d->dayCache; - setDay( d->dayCache ); - d->dayCache = tmp; - } -} - - -/*! - Sets the day to \a day, which must be a valid day. The function - will ensure that the \a day set is valid for the month and year. -*/ - -void TQDateEdit::setDay( int day ) -{ - if ( day < 1 ) - day = 1; - if ( day > 31 ) - day = 31; - if ( d->m > 0 && d->y > 1752 ) { - while ( !TQDate::isValid( d->y, d->m, day ) ) - --day; - if ( !outOfRange( d->y, d->m, day ) ) - d->d = day; - } else if ( d->m > 0 ) { - if ( day > 0 && day < 32 ) { - if ( !outOfRange( d->y, d->m, day ) ) - d->d = day; - } - } - d->dayCache = d->d; -} - - -/*! - \property TQDateEdit::date - \brief the editor's date value. - - If the date property is not valid, the editor displays all zeroes - and TQDateEdit::date() will return an invalid date. It is strongly - recommended that the editor is given a default date value (e.g. - currentDate()). That way, attempts to set the date property to an - invalid date will fail. - - When changing the date property, if the date is less than - minValue(), or is greater than maxValue(), nothing happens. -*/ - -void TQDateEdit::setDate( const TQDate& date ) -{ - if ( !date.isValid() ) { - d->y = 0; - d->m = 0; - d->d = 0; - d->dayCache = 0; - } else { - if ( date > maxValue() || date < minValue() ) - return; - d->y = date.year(); - d->m = date.month(); - d->d = date.day(); - d->dayCache = d->d; - emit valueChanged( date ); - } - d->changed = FALSE; - d->ed->repaint( d->ed->rect(), FALSE ); -} - -TQDate TQDateEdit::date() const -{ - if ( TQDate::isValid( d->y, d->m, d->d ) ) - return TQDate( d->y, d->m, d->d ); - return TQDate(); -} - -/*! \internal - - Returns TRUE if \a y, \a m, \a d is out of range, otherwise returns - FALSE. - - \sa setRange() - -*/ - -bool TQDateEdit::outOfRange( int y, int m, int d ) const -{ - if ( TQDate::isValid( y, m, d ) ) { - TQDate currentDate( y, m, d ); - if ( currentDate > maxValue() || - currentDate < minValue() ) { - //## outOfRange should set overwrite? - return TRUE; - } - return FALSE; - } - return FALSE; /* assume ok */ -} - -/*! \reimp - -*/ - -void TQDateEdit::addNumber( int sec, int num ) -{ - if ( sec == -1 ) - return; - killTimer( d->timerId ); - bool overwrite = FALSE; - bool accepted = FALSE; - d->typing = TRUE; - TQString txt; - if ( sec == d->yearSection ) { - txt = TQString::number( d->y ); - if ( d->overwrite || txt.length() == 4 ) { - accepted = TRUE; - d->y = num; - } else { - txt += TQString::number( num ); - if ( txt.length() == 4 ) { - int val = txt.toInt(); - if ( val < 1792 ) - d->y = 1792; - else if ( val > 8000 ) - d->y = 8000; - else if ( outOfRange( val, d->m, d->d ) ) - txt = TQString::number( d->y ); - else { - accepted = TRUE; - d->y = val; - } - } else { - accepted = TRUE; - d->y = txt.toInt(); - } - if ( d->adv && txt.length() == 4 ) { - d->ed->setFocusSection( d->ed->focusSection()+1 ); - overwrite = TRUE; - } - } - } else if ( sec == d->monthSection ) { - txt = TQString::number( d->m ); - if ( d->overwrite || txt.length() == 2 ) { - accepted = TRUE; - d->m = num; - } else { - txt += TQString::number( num ); - int temp = txt.toInt(); - if ( temp > 12 ) - temp = num; - if ( outOfRange( d->y, temp, d->d ) ) - txt = TQString::number( d->m ); - else { - accepted = TRUE; - d->m = temp; - } - if ( d->adv && txt.length() == 2 ) { - d->ed->setFocusSection( d->ed->focusSection()+1 ); - overwrite = TRUE; - } - } - } else if ( sec == d->daySection ) { - txt = TQString::number( d->d ); - if ( d->overwrite || txt.length() == 2 ) { - accepted = TRUE; - d->d = num; - d->dayCache = d->d; - } else { - txt += TQString::number( num ); - int temp = txt.toInt(); - if ( temp > 31 ) - temp = num; - if ( outOfRange( d->y, d->m, temp ) ) - txt = TQString::number( d->d ); - else { - accepted = TRUE; - d->d = temp; - d->dayCache = d->d; - } - if ( d->adv && txt.length() == 2 ) { - d->ed->setFocusSection( d->ed->focusSection()+1 ); - overwrite = TRUE; - } - } - } - if ( accepted ) { - d->changed = FALSE; - emit valueChanged( date() ); - } - d->overwrite = overwrite; - d->timerId = startTimer( tqApp->doubleClickInterval()*4 ); - d->ed->repaint( d->ed->rect(), FALSE ); -} - - -/*! \reimp - -*/ - -bool TQDateEdit::setFocusSection( int s ) -{ - if ( s != d->ed->focusSection() ) { - killTimer( d->timerId ); - d->overwrite = TRUE; - d->typing = FALSE; - fix(); // will emit valueChanged if necessary - } - return d->ed->setFocusSection( s ); -} - - -/*! - Attempts to fix any invalid date entries. - - The rules applied are as follows: - - \list - \i If the year has four digits it is left unchanged. - \i If the year has two digits, the year will be changed to four - digits in the range current year - 70 to current year + 29. - \i If the year has three digits in the range 100..999, the - current millennium, i.e. 2000, will be added giving a year - in the range 2100..2999. - \i If the day or month is 0 then it will be set to 1 or the - minimum valid day\month in the range. - \endlist - -*/ - -void TQDateEdit::fix() -{ - bool changed = FALSE; - int currentYear = TQDate::currentDate().year(); - int year = d->y; - if ( year < 100 ) { - int currentCentury = currentYear / 100; - year += currentCentury * 100; - if ( currentYear > year ) { - if ( currentYear > year + 70 ) - year += 100; - } else { - if ( year >= currentYear + 30 ) - year -= 100; - } - changed = TRUE; - } else if ( year < 1000 ) { - int currentMillennium = currentYear / 10; - year += currentMillennium * 10; - changed = TRUE; - } else if (d->d == 0) { - d->d = 1; - changed = TRUE; - } else if (d->m == 0) { - d->m = 1; - changed = TRUE; - } - if ( outOfRange( year, d->m, d->d ) ) { - if ( minValue().isValid() && date() < minValue() ) { - d->d = minValue().day(); - d->dayCache = d->d; - d->m = minValue().month(); - d->y = minValue().year(); - } - if ( date() > maxValue() ) { - d->d = maxValue().day(); - d->dayCache = d->d; - d->m = maxValue().month(); - d->y = maxValue().year(); - } - changed = TRUE; - } else if ( changed ) - setYear( year ); - if ( changed ) { - emit valueChanged( date() ); - d->changed = FALSE; - } -} - - -/*! \reimp - -*/ - -bool TQDateEdit::event( TQEvent *e ) -{ - if( e->type() == TQEvent::FocusOut ) { - d->typing = FALSE; - fix(); - // the following can't be done in fix() because fix() called - // from all over the place and it will break the old behaviour - if ( !TQDate::isValid( d->y, d->m, d->d ) ) { - d->dayCache = d->d; - int i = d->d; - for ( ; i > 0; i-- ) { - d->d = i; - if ( TQDate::isValid( d->y, d->m, d->d ) ) - break; - } - d->changed = TRUE; - } - if ( d->changed ) { - emit valueChanged( date() ); - d->changed = FALSE; - } - } else if ( e->type() == TQEvent::LocaleChange ) { - readLocaleSettings(); - d->ed->setSeparator( localDateSep() ); - setOrder( localOrder() ); - } - return TQDateTimeEditBase::event( e ); -} - -/*! - \internal - - Function which is called whenever the user tries to - remove the first number from \a sec by pressing the backspace key. -*/ - -void TQDateEdit::removeFirstNumber( int sec ) -{ - if ( sec == -1 ) - return; - TQString txt; - if ( sec == d->yearSection ) { - txt = TQString::number( d->y ); - txt = txt.mid( 1, txt.length() ) + "0"; - d->y = txt.toInt(); - } else if ( sec == d->monthSection ) { - txt = TQString::number( d->m ); - txt = txt.mid( 1, txt.length() ) + "0"; - d->m = txt.toInt(); - } else if ( sec == d->daySection ) { - txt = TQString::number( d->d ); - txt = txt.mid( 1, txt.length() ) + "0"; - d->d = txt.toInt(); - d->dayCache = d->d; - } - d->ed->repaint( d->ed->rect(), FALSE ); -} - -/*! \reimp - -*/ - -void TQDateEdit::removeLastNumber( int sec ) -{ - if ( sec == -1 ) - return; - TQString txt; - if ( sec == d->yearSection ) { - txt = TQString::number( d->y ); - txt = txt.mid( 0, txt.length()-1 ); - d->y = txt.toInt(); - } else if ( sec == d->monthSection ) { - txt = TQString::number( d->m ); - txt = txt.mid( 0, txt.length()-1 ); - d->m = txt.toInt(); - } else if ( sec == d->daySection ) { - txt = TQString::number( d->d ); - txt = txt.mid( 0, txt.length()-1 ); - d->d = txt.toInt(); - d->dayCache = d->d; - } - d->ed->repaint( d->ed->rect(), FALSE ); -} - -/*! - \property TQDateEdit::autoAdvance - \brief whether the editor automatically advances to the next - section - - If autoAdvance is TRUE, the editor will automatically advance - focus to the next date section if a user has completed a section. - The default is FALSE. -*/ - -void TQDateEdit::setAutoAdvance( bool advance ) -{ - d->adv = advance; -} - - -bool TQDateEdit::autoAdvance() const -{ - return d->adv; -} - -/*! \reimp -*/ - -void TQDateEdit::timerEvent( TQTimerEvent * ) -{ - d->overwrite = TRUE; -} - -/*! - \fn void TQDateEdit::valueChanged( const TQDate& date ) - - This signal is emitted whenever the editor's value changes. The \a - date parameter is the new value. -*/ - -/////////// - -class TQTimeEditPrivate -{ -public: - int h; - int m; - int s; - uint display; - bool adv; - bool overwrite; - int timerId; - bool typing; - TQTime min; - TQTime max; - bool changed; - TQDateTimeEditor *ed; - TQSpinWidget *controls; -}; - -/*! - \class TQTimeEdit ntqdatetimeedit.h - \brief The TQTimeEdit class provides a time editor. - - \ingroup advanced - \ingroup time - \mainclass - - TQTimeEdit allows the user to edit times by using the keyboard or - the arrow keys to increase/decrease time values. The arrow keys - can be used to move from section to section within the TQTimeEdit - box. The user can automatically be moved to the next section once - they complete a section using setAutoAdvance(). Times appear in - hour, minute, second order. It is recommended that the TQTimeEdit - is initialised with a time, e.g. - \code - TQTime timeNow = TQTime::currentTime(); - TQTimeEdit *timeEdit = new TQTimeEdit( timeNow, this ); - timeEdit->setRange( timeNow, timeNow.addSecs( 60 * 60 ) ); - \endcode - Here we've created a TQTimeEdit widget set to the current time. - We've also set the minimum value to the current time and the - maximum time to one hour from now. - - The maximum and minimum values for a time value in the time editor - default to the maximum and minimum values for a TQTime. You can - change this by calling setMinValue(), setMaxValue() or setRange(). - - Terminology: A TQTimeWidget consists of three sections, one each - for the hour, minute and second. You can change the separator - character using setSeparator(), by default the separator is read - from the system's settings. - - \img datetimewidgets.png Date Time Widgets - - \sa TQTime TQDateEdit TQDateTimeEdit -*/ - - -/*! - Constructs an empty time edit with parent \a parent and called \a - name. -*/ - -TQTimeEdit::TQTimeEdit( TQWidget * parent, const char * name ) - : TQDateTimeEditBase( parent, name ) -{ - init(); -} - -/*! - \overload - - Constructs a time edit with the initial time value, \a time, - parent \a parent and called \a name. -*/ - -TQTimeEdit::TQTimeEdit( const TQTime& time, TQWidget * parent, const char * name ) - : TQDateTimeEditBase( parent, name ) -{ - init(); - setTime( time ); -} - -/*! \internal - */ - -void TQTimeEdit::init() -{ - d = new TQTimeEditPrivate(); - d->controls = new TQDateTimeSpinWidget( this, qstrcmp( name(), "qt_datetime_timeedit" ) == 0 ? "qt_spin_widget" : "time edit controls" ); - d->ed = new TQDateTimeEditor( this, d->controls, "time edit base" ); - d->controls->setEditWidget( d->ed ); - setFocusProxy( d->ed ); - connect( d->controls, TQ_SIGNAL( stepUpPressed() ), TQ_SLOT( stepUp() ) ); - connect( d->controls, TQ_SIGNAL( stepDownPressed() ), TQ_SLOT( stepDown() ) ); - - d->ed->appendSection( TQNumberSection( 0,0, TRUE, 0 ) ); - d->ed->appendSection( TQNumberSection( 0,0, TRUE, 1 ) ); - d->ed->appendSection( TQNumberSection( 0,0, TRUE, 2 ) ); - d->ed->setSeparator( localTimeSep() ); - - d->h = 0; - d->m = 0; - d->s = 0; - d->display = Hours | Minutes | Seconds; - if ( lAMPM ) { - d->display |= AMPM; - d->ed->appendSection( TQNumberSection( 0,0, FALSE, 3 ) ); - } - d->adv = FALSE; - d->overwrite = TRUE; - d->timerId = 0; - d->typing = FALSE; - d->min = TQTime( 0, 0, 0 ); - d->max = TQTime( 23, 59, 59 ); - d->changed = FALSE; - - setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ); - - refcount++; -} - -/*! - Destroys the object and frees any allocated resources. -*/ - -TQTimeEdit::~TQTimeEdit() -{ - delete d; - if ( !--refcount ) - cleanup(); -} - -/*! - \property TQTimeEdit::minValue - \brief the minimum time value - - Setting the minimum time value is equivalent to calling - TQTimeEdit::setRange( \e t, maxValue() ), where \e t is the minimum - time. The default minimum time is 00:00:00. - - \sa maxValue setRange() -*/ - -TQTime TQTimeEdit::minValue() const -{ - return d->min; -} - -/*! - \property TQTimeEdit::maxValue - \brief the maximum time value - - Setting the maximum time value is equivalent to calling - TQTimeEdit::setRange( minValue(), \e t ), where \e t is the maximum - time. The default maximum time is 23:59:59. - - \sa minValue setRange() -*/ - -TQTime TQTimeEdit::maxValue() const -{ - return d->max; -} - - -/*! - Sets the valid input range for the editor to be from \a min to \a - max inclusive. If \a min is invalid no minimum time is set. - Similarly, if \a max is invalid no maximum time is set. -*/ - -void TQTimeEdit::setRange( const TQTime& min, const TQTime& max ) -{ - if ( min.isValid() ) - d->min = min; - if ( max.isValid() ) - d->max = max; -} - -/*! - \property TQTimeEdit::display - \brief the sections that are displayed in the time edit - - The value can be any combination of the values in the Display enum. - By default, the widget displays hours, minutes and seconds. -*/ -void TQTimeEdit::setDisplay( uint display ) -{ - if ( d->display == display ) - return; - - d->ed->clearSections(); - d->display = display; - if ( d->display & Hours ) - d->ed->appendSection( TQNumberSection( 0,0, TRUE, 0 ) ); - if ( d->display & Minutes ) - d->ed->appendSection( TQNumberSection( 0,0, TRUE, 1 ) ); - if ( d->display & Seconds ) - d->ed->appendSection( TQNumberSection( 0,0, TRUE, 2 ) ); - if ( d->display & AMPM ) - d->ed->appendSection( TQNumberSection( 0,0, FALSE, 3 ) ); - - d->ed->setFocusSection( 0 ); - d->ed->update(); -} - -uint TQTimeEdit::display() const -{ - return d->display; -} - -/*! - \property TQTimeEdit::time - \brief the editor's time value. - - When changing the time property, if the time is less than - minValue(), or is greater than maxValue(), nothing happens. -*/ - -void TQTimeEdit::setTime( const TQTime& time ) -{ - if ( !time.isValid() ) { - d->h = 0; - d->m = 0; - d->s = 0; - } else { - if ( time > maxValue() || time < minValue() ) - return; - d->h = time.hour(); - d->m = time.minute(); - d->s = time.second(); - emit valueChanged( time ); - } - d->changed = FALSE; - d->ed->repaint( d->ed->rect(), FALSE ); -} - -TQTime TQTimeEdit::time() const -{ - if ( TQTime::isValid( d->h, d->m, d->s ) ) - return TQTime( d->h, d->m, d->s ); - return TQTime(); -} - -/*! - \property TQTimeEdit::autoAdvance - \brief whether the editor automatically advances to the next - section - - If autoAdvance is TRUE, the editor will automatically advance - focus to the next time section if a user has completed a section. - The default is FALSE. -*/ - -void TQTimeEdit::setAutoAdvance( bool advance ) -{ - d->adv = advance; -} - -bool TQTimeEdit::autoAdvance() const -{ - return d->adv; -} - -/*! - Sets the separator to \a s. Note that currently only the first - character of \a s is used. -*/ - -void TQTimeEdit::setSeparator( const TQString& s ) -{ - d->ed->setSeparator( s ); -} - -/*! - Returns the editor's separator. -*/ - -TQString TQTimeEdit::separator() const -{ - return d->ed->separator(); -} - - -/*! - \fn void TQTimeEdit::valueChanged( const TQTime& time ) - - This signal is emitted whenever the editor's value changes. The \a - time parameter is the new value. -*/ - -/*! \reimp - -*/ - -bool TQTimeEdit::event( TQEvent *e ) -{ - if ( e->type() == TQEvent::FocusOut ) { - d->typing = FALSE; - if ( d->changed ) { - emit valueChanged( time() ); - d->changed = FALSE; - } - } else if ( e->type() == TQEvent::LocaleChange ) { - readLocaleSettings(); - d->ed->setSeparator( localTimeSep() ); - } - return TQDateTimeEditBase::event( e ); -} - -/*! \reimp - -*/ - -void TQTimeEdit::timerEvent( TQTimerEvent * ) -{ - d->overwrite = TRUE; -} - - -/*! \reimp - -*/ - -void TQTimeEdit::stepUp() -{ - if (minValue() > maxValue()) { - return; - } - int sec = d->ed->mapSection( d->ed->focusSection() ); - bool accepted = TRUE; - switch( sec ) { - case 0: - do { - d->h = (d->h + 1) % 24; - } while (outOfRange(d->h, d->m, d->s)); - break; - case 1: - do { - d->m = (d->m + 1) % 60; - } while (outOfRange(d->h, d->m, d->s)); - break; - case 2: - do { - d->s = (d->s + 1) % 60; - } while (outOfRange(d->h, d->m, d->s)); - break; - case 3: - if ( d->h < 12 ) - setHour( d->h+12 ); - else - setHour( d->h-12 ); - break; - default: - accepted = FALSE; -#ifdef QT_CHECK_RANGE - tqWarning( "TQTimeEdit::stepUp: Focus section out of range!" ); -#endif - break; - } - if ( accepted ) { - d->changed = FALSE; - emit valueChanged( time() ); - } - d->ed->repaint( d->ed->rect(), FALSE ); -} - - -/*! \reimp - -*/ - -void TQTimeEdit::stepDown() -{ - if (minValue() > maxValue()) { - return; - } - - int sec = d->ed->mapSection( d->ed->focusSection() ); - bool accepted = TRUE; - switch( sec ) { - case 0: - do { - if (--d->h < 0) - d->h = 23; - } while (outOfRange(d->h, d->m, d->s)); - break; - case 1: - do { - if (--d->m < 0) - d->m = 59; - } while (outOfRange(d->h, d->m, d->s)); - break; - case 2: - do { - if (--d->s < 0) - d->s = 59; - } while (outOfRange(d->h, d->m, d->s)); - break; - case 3: - if ( d->h > 11 ) - setHour( d->h-12 ); - else - setHour( d->h+12 ); - break; - default: - accepted = FALSE; -#ifdef QT_CHECK_RANGE - tqWarning( "TQTimeEdit::stepDown: Focus section out of range!" ); -#endif - break; - } - if ( accepted ) { - d->changed = FALSE; - emit valueChanged( time() ); - } - d->ed->repaint( d->ed->rect(), FALSE ); -} - - -/*! - Returns the formatted number for section \a sec. This will - correspond to either the hour, minute or second section, depending - on \a sec. -*/ - -TQString TQTimeEdit::sectionFormattedText( int sec ) -{ - TQString txt; - txt = sectionText( sec ); - txt = txt.rightJustify( 2, TQDATETIMEEDIT_HIDDEN_CHAR ); - int offset = sec*2+sec*separator().length() + txt.length(); - if ( d->typing && sec == d->ed->focusSection() ) - d->ed->setSectionSelection( sec, offset - txt.length(), offset ); - else - d->ed->setSectionSelection( sec, offset - txt.length(), offset ); - - return txt; -} - - -/*! \reimp - -*/ - -bool TQTimeEdit::setFocusSection( int sec ) -{ - if ( sec != d->ed->focusSection() ) { - killTimer( d->timerId ); - d->overwrite = TRUE; - d->typing = FALSE; - TQString txt = sectionText( sec ); - txt = txt.rightJustify( 2, TQDATETIMEEDIT_HIDDEN_CHAR ); - int offset = sec*2+sec*separator().length() + txt.length(); - d->ed->setSectionSelection( sec, offset - txt.length(), offset ); - if ( d->changed ) { - emit valueChanged( time() ); - d->changed = FALSE; - } - } - return d->ed->setFocusSection( sec ); -} - - -/*! - Sets the hour to \a h, which must be a valid hour, i.e. in the - range 0..24. -*/ - -void TQTimeEdit::setHour( int h ) -{ - if ( h < 0 ) - h = 0; - if ( h > 23 ) - h = 23; - d->h = h; -} - - -/*! - Sets the minute to \a m, which must be a valid minute, i.e. in the - range 0..59. -*/ - -void TQTimeEdit::setMinute( int m ) -{ - if ( m < 0 ) - m = 0; - if ( m > 59 ) - m = 59; - d->m = m; -} - - -/*! - Sets the second to \a s, which must be a valid second, i.e. in the - range 0..59. -*/ - -void TQTimeEdit::setSecond( int s ) -{ - if ( s < 0 ) - s = 0; - if ( s > 59 ) - s = 59; - d->s = s; -} - - -/*! \internal - - Returns the text of section \a sec. - -*/ - -TQString TQTimeEdit::sectionText( int sec ) -{ - sec = d->ed->mapSection( sec ); - - TQString txt; - switch( sec ) { - case 0: - if ( !(d->display & AMPM) || ( d->h < 13 && d->h ) ) { // I wished the day stared at 0:00 for everybody - txt = TQString::number( d->h ); - } else { - if ( d->h ) - txt = TQString::number( d->h - 12 ); - else - txt = "12"; - } - break; - case 1: - txt = TQString::number( d->m ); - break; - case 2: - txt = TQString::number( d->s ); - break; - case 3: - if ( d->h < 12 ) { - if ( lAM ) - txt = *lAM; - else - txt = TQString::fromLatin1( "AM" ); - } else { - if ( lPM ) - txt = *lPM; - else - txt = TQString::fromLatin1( "PM" ); - } - break; - default: - break; - } - return txt; -} - - -/*! \internal - Returns TRUE if \a h, \a m, and \a s are out of range. - */ - -bool TQTimeEdit::outOfRange( int h, int m, int s ) const -{ - if ( TQTime::isValid( h, m, s ) ) { - TQTime currentTime( h, m, s ); - if ( currentTime > maxValue() || - currentTime < minValue() ) - return TRUE; - else - return FALSE; - } - return TRUE; -} - -/*! \reimp - -*/ - -void TQTimeEdit::addNumber( int sec, int num ) -{ - if ( sec == -1 ) - return; - sec = d->ed->mapSection( sec ); - killTimer( d->timerId ); - bool overwrite = FALSE; - bool accepted = FALSE; - d->typing = TRUE; - TQString txt; - - switch( sec ) { - case 0: - txt = ( d->display & AMPM && d->h > 12 ) ? - TQString::number( d->h - 12 ) : TQString::number( d->h ); - - if ( d->overwrite || txt.length() == 2 ) { - if ( d->display & AMPM && num == 0 ) - break; // Don't process 0 in 12 hour clock mode - if ( d->display & AMPM && d->h > 11 ) - num += 12; - if ( !outOfRange( num, d->m, d->s ) ) { - accepted = TRUE; - d->h = num; - } - } else { - txt += TQString::number( num ); - int temp = txt.toInt(); - - if ( d->display & AMPM ) { - if ( temp == 12 ) { - if ( d->h < 12 ) { - temp = 0; - } - accepted = TRUE; - } else if ( outOfRange( temp + 12, d->m, d->s ) ) { - txt = TQString::number( d->h ); - } else { - if ( d->h > 11 ) { - temp += 12; - } - accepted = TRUE; - } - } else if ( !(d->display & AMPM) && outOfRange( temp, d->m, d->s ) ) { - txt = TQString::number( d->h ); - } else { - accepted = TRUE; - } - - if ( accepted ) - d->h = temp; - - if ( d->adv && txt.length() == 2 ) { - setFocusSection( d->ed->focusSection()+1 ); - overwrite = TRUE; - } - } - break; - - case 1: - txt = TQString::number( d->m ); - if ( d->overwrite || txt.length() == 2 ) { - if ( !outOfRange( d->h, num, d->s ) ) { - accepted = TRUE; - d->m = num; - } - } else { - txt += TQString::number( num ); - int temp = txt.toInt(); - if ( temp > 59 ) - temp = num; - if ( outOfRange( d->h, temp, d->s ) ) - txt = TQString::number( d->m ); - else { - accepted = TRUE; - d->m = temp; - } - if ( d->adv && txt.length() == 2 ) { - setFocusSection( d->ed->focusSection()+1 ); - overwrite = TRUE; - } - } - break; - - case 2: - txt = TQString::number( d->s ); - if ( d->overwrite || txt.length() == 2 ) { - if ( !outOfRange( d->h, d->m, num ) ) { - accepted = TRUE; - d->s = num; - } - } else { - txt += TQString::number( num ); - int temp = txt.toInt(); - if ( temp > 59 ) - temp = num; - if ( outOfRange( d->h, d->m, temp ) ) - txt = TQString::number( d->s ); - else { - accepted = TRUE; - d->s = temp; - } - if ( d->adv && txt.length() == 2 ) { - setFocusSection( d->ed->focusSection()+1 ); - overwrite = TRUE; - } - } - break; - - case 3: - break; - - default: - break; - } - d->changed = !accepted; - if ( accepted ) - emit valueChanged( time() ); - d->overwrite = overwrite; - d->timerId = startTimer( tqApp->doubleClickInterval()*4 ); - d->ed->repaint( d->ed->rect(), FALSE ); -} - - -/*! - \internal - - Function which is called whenever the user tries to - remove the first number from \a sec by pressing the backspace key. -*/ - -void TQTimeEdit::removeFirstNumber( int sec ) -{ - if ( sec == -1 ) - return; - sec = d->ed->mapSection( sec ); - TQString txt; - switch( sec ) { - case 0: - txt = TQString::number( d->h ); - break; - case 1: - txt = TQString::number( d->m ); - break; - case 2: - txt = TQString::number( d->s ); - break; - } - txt = txt.mid( 1, txt.length() ) + "0"; - switch( sec ) { - case 0: - d->h = txt.toInt(); - break; - case 1: - d->m = txt.toInt(); - break; - case 2: - d->s = txt.toInt(); - break; - } - d->ed->repaint( d->ed->rect(), FALSE ); -} - -/*! \reimp - -*/ -void TQTimeEdit::removeLastNumber( int sec ) -{ - if ( sec == -1 ) - return; - sec = d->ed->mapSection( sec ); - TQString txt; - switch( sec ) { - case 0: - txt = TQString::number( d->h ); - break; - case 1: - txt = TQString::number( d->m ); - break; - case 2: - txt = TQString::number( d->s ); - break; - } - txt = txt.mid( 0, txt.length()-1 ); - switch( sec ) { - case 0: - d->h = txt.toInt(); - break; - case 1: - d->m = txt.toInt(); - break; - case 2: - d->s = txt.toInt(); - break; - } - d->ed->repaint( d->ed->rect(), FALSE ); -} - -/*! \reimp - */ -void TQTimeEdit::resizeEvent( TQResizeEvent * ) -{ - d->controls->resize( width(), height() ); -} - -/*! \reimp -*/ -TQSize TQTimeEdit::sizeHint() const -{ - constPolish(); - TQFontMetrics fm( font() ); - int fw = style().pixelMetric( TQStyle::PM_DefaultFrameWidth, this ); - int h = fm.lineSpacing() + 2; - int w = 2 + fm.width( '9' ) * 6 + fm.width( d->ed->separator() ) * 2 + - d->controls->upRect().width() + fw * 4; - if ( d->display & AMPM ) { - if ( lAM ) - w += fm.width( *lAM ) + 4; - else - w += fm.width( TQString::fromLatin1( "AM" ) ) + 4; - } - - return TQSize( w, TQMAX(h + fw * 2,20) ).expandedTo( TQApplication::globalStrut() ); -} - -/*! \reimp -*/ -TQSize TQTimeEdit::minimumSizeHint() const -{ - return sizeHint(); -} - -/*! - \internal - Enables/disables the push buttons according to the min/max time - for this widget. -*/ - -// ### Remove in 4.0? - -void TQTimeEdit::updateButtons() -{ - if ( !isEnabled() ) - return; - - bool upEnabled = time() < maxValue(); - bool downEnabled = time() > minValue(); - - d->controls->setUpEnabled( upEnabled ); - d->controls->setDownEnabled( downEnabled ); -} - - -class TQDateTimeEditPrivate -{ -public: - bool adv; -}; - -/*! - \class TQDateTimeEdit ntqdatetimeedit.h - \brief The TQDateTimeEdit class combines a TQDateEdit and TQTimeEdit - widget into a single widget for editing datetimes. - - \ingroup advanced - \ingroup time - \mainclass - - TQDateTimeEdit consists of a TQDateEdit and TQTimeEdit widget placed - side by side and offers the functionality of both. The user can - edit the date and time by using the keyboard or the arrow keys to - increase/decrease date or time values. The Tab key can be used to - move from section to section within the TQDateTimeEdit widget, and - the user can be moved automatically when they complete a section - using setAutoAdvance(). The datetime can be set with - setDateTime(). - - The date format is read from the system's locale settings. It is - set to year, month, day order if that is not possible. See - TQDateEdit::setOrder() to change this. Times appear in the order - hours, minutes, seconds using the 24 hour clock. - - It is recommended that the TQDateTimeEdit is initialised with a - datetime, e.g. - \code - TQDateTimeEdit *dateTimeEdit = new TQDateTimeEdit( TQDateTime::currentDateTime(), this ); - dateTimeEdit->dateEdit()->setRange( TQDateTime::currentDate(), - TQDateTime::currentDate().addDays( 7 ) ); - \endcode - Here we've created a new TQDateTimeEdit set to the current date and - time, and set the date to have a minimum date of now and a maximum - date of a week from now. - - Terminology: A TQDateEdit widget consists of three 'sections', one - each for the year, month and day. Similarly a TQTimeEdit consists - of three sections, one each for the hour, minute and second. The - character that separates each date section is specified with - setDateSeparator(); similarly setTimeSeparator() is used for the - time sections. - - \img datetimewidgets.png Date Time Widgets - - \sa TQDateEdit TQTimeEdit -*/ - -/*! - Constructs an empty datetime edit with parent \a parent and called - \a name. -*/ -TQDateTimeEdit::TQDateTimeEdit( TQWidget * parent, const char * name ) - : TQWidget( parent, name ) -{ - init(); -} - - -/*! - \overload - - Constructs a datetime edit with the initial value \a datetime, - parent \a parent and called \a name. -*/ -TQDateTimeEdit::TQDateTimeEdit( const TQDateTime& datetime, - TQWidget * parent, const char * name ) - : TQWidget( parent, name ) -{ - init(); - setDateTime( datetime ); -} - - - -/*! - Destroys the object and frees any allocated resources. -*/ - -TQDateTimeEdit::~TQDateTimeEdit() -{ - delete d; -} - - -/*! - \reimp - - Intercepts and handles resize events which have special meaning - for the TQDateTimeEdit. -*/ - -void TQDateTimeEdit::resizeEvent( TQResizeEvent * ) -{ - int dw = de->sizeHint().width(); - int tw = te->sizeHint().width(); - int w = width(); - int h = height(); - int extra = w - ( dw + tw ); - - if ( tw + extra < 0 ) { - dw = w; - } else { - dw += 9 * extra / 16; - } - tw = w - dw; - - de->setGeometry( 0, 0, dw, h ); - te->setGeometry( dw, 0, tw, h ); -} - -/*! \reimp -*/ - -TQSize TQDateTimeEdit::minimumSizeHint() const -{ - TQSize dsh = de->minimumSizeHint(); - TQSize tsh = te->minimumSizeHint(); - return TQSize( dsh.width() + tsh.width(), - TQMAX( dsh.height(), tsh.height() ) ); -} - -/*! \internal - */ - -void TQDateTimeEdit::init() -{ - d = new TQDateTimeEditPrivate(); - de = new TQDateEdit( this, "qt_datetime_dateedit" ); - te = new TQTimeEdit( this, "qt_datetime_timeedit" ); - d->adv = FALSE; - connect( de, TQ_SIGNAL( valueChanged(const TQDate&) ), - this, TQ_SLOT( newValue(const TQDate&) ) ); - connect( te, TQ_SIGNAL( valueChanged(const TQTime&) ), - this, TQ_SLOT( newValue(const TQTime&) ) ); - setFocusProxy( de ); - setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ); -} - -/*! \reimp - */ - -TQSize TQDateTimeEdit::sizeHint() const -{ - constPolish(); - TQSize dsh = de->sizeHint(); - TQSize tsh = te->sizeHint(); - return TQSize( dsh.width() + tsh.width(), - TQMAX( dsh.height(), tsh.height() ) ); -} - -/*! - \property TQDateTimeEdit::dateTime - \brief the editor's datetime value - - The datetime edit's datetime which may be an invalid datetime. -*/ - -void TQDateTimeEdit::setDateTime( const TQDateTime & dt ) -{ - if ( dt.isValid() ) { - de->setDate( dt.date() ); - te->setTime( dt.time() ); - emit valueChanged( dt ); - } -} - -TQDateTime TQDateTimeEdit::dateTime() const -{ - return TQDateTime( de->date(), te->time() ); -} - -/*! - \fn void TQDateTimeEdit::valueChanged( const TQDateTime& datetime ) - - This signal is emitted every time the date or time changes. The \a - datetime argument is the new datetime. -*/ - - -/*! \internal - - Re-emits the value \a d. - */ - -void TQDateTimeEdit::newValue( const TQDate& ) -{ - TQDateTime dt = dateTime(); - emit valueChanged( dt ); -} - -/*! \internal - \overload - Re-emits the value \a t. - */ - -void TQDateTimeEdit::newValue( const TQTime& ) -{ - TQDateTime dt = dateTime(); - emit valueChanged( dt ); -} - - -/*! - Sets the auto advance property of the editor to \a advance. If set - to TRUE, the editor will automatically advance focus to the next - date or time section if the user has completed a section. -*/ - -void TQDateTimeEdit::setAutoAdvance( bool advance ) -{ - de->setAutoAdvance( advance ); - te->setAutoAdvance( advance ); -} - -/*! - Returns TRUE if auto-advance is enabled, otherwise returns FALSE. - - \sa setAutoAdvance() -*/ - -bool TQDateTimeEdit::autoAdvance() const -{ - return de->autoAdvance(); -} - -/*! - \fn TQDateEdit* TQDateTimeEdit::dateEdit() - - Returns the internal widget used for editing the date part of the - datetime. -*/ - -/*! - \fn TQTimeEdit* TQDateTimeEdit::timeEdit() - - Returns the internal widget used for editing the time part of the - datetime. -*/ - -#include "qdatetimeedit.moc" - -#endif diff --git a/src/widgets/qdockwindow.cpp b/src/widgets/qdockwindow.cpp index bfcd8dba7..77155540e 100644 --- a/src/widgets/qdockwindow.cpp +++ b/src/widgets/qdockwindow.cpp @@ -51,7 +51,7 @@ #include "ntqtoolbar.h" #include "ntqlayout.h" #include "ntqmainwindow.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqtooltip.h" #include "ntqguardedptr.h" #include "ntqcursor.h" diff --git a/src/widgets/qeffects.cpp b/src/widgets/qeffects.cpp index 07dee3f56..e81144261 100644 --- a/src/widgets/qeffects.cpp +++ b/src/widgets/qeffects.cpp @@ -44,8 +44,8 @@ #include "qeffects_p.h" #include "ntqpixmap.h" #include "tqimage.h" -#include "ntqtimer.h" -#include "ntqdatetime.h" +#include "tqtimer.h" +#include "tqdatetime.h" #include "ntqguardedptr.h" #include "ntqscrollview.h" diff --git a/src/widgets/qlineedit.cpp b/src/widgets/qlineedit.cpp index f03b57cb9..87a63e7fc 100644 --- a/src/widgets/qlineedit.cpp +++ b/src/widgets/qlineedit.cpp @@ -54,7 +54,7 @@ #include "ntqapplication.h" #include "ntqvalidator.h" #include "ntqdragobject.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqpopupmenu.h" #include "tqstringlist.h" #include "ntqguardedptr.h" diff --git a/src/widgets/qlistbox.cpp b/src/widgets/qlistbox.cpp index 48ee6dc19..d18381f8e 100644 --- a/src/widgets/qlistbox.cpp +++ b/src/widgets/qlistbox.cpp @@ -53,7 +53,7 @@ #include "ntqpixmap.h" #include "ntqapplication.h" #include "tqptrdict.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "tqstringlist.h" #include "tqstyle.h" #include "ntqpopupmenu.h" diff --git a/src/widgets/qlistview.cpp b/src/widgets/qlistview.cpp index ac2369637..14fcb6735 100644 --- a/src/widgets/qlistview.cpp +++ b/src/widgets/qlistview.cpp @@ -40,7 +40,7 @@ #include "ntqlistview.h" #ifndef TQT_NO_LISTVIEW -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqheader.h" #include "ntqpainter.h" #include "ntqcursor.h" @@ -49,7 +49,7 @@ #include "tqstrlist.h" #include "ntqapplication.h" #include "ntqbitmap.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "tqptrdict.h" #include "tqptrvector.h" #include "tqiconset.h" diff --git a/src/widgets/qmainwindow.cpp b/src/widgets/qmainwindow.cpp index 0048f566b..1f33829f7 100644 --- a/src/widgets/qmainwindow.cpp +++ b/src/widgets/qmainwindow.cpp @@ -41,7 +41,7 @@ #include "ntqmainwindow.h" #ifndef TQT_NO_MAINWINDOW -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqlayout.h" #include "tqobjectlist.h" #include "ntqintdict.h" @@ -56,7 +56,7 @@ #include "ntqstatusbar.h" #include "ntqscrollview.h" #include "ntqtooltip.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqwhatsthis.h" #include "ntqbitmap.h" #include "ntqdockarea.h" diff --git a/src/widgets/qmenubar.cpp b/src/widgets/qmenubar.cpp index fa25ebbac..2a99c223d 100644 --- a/src/widgets/qmenubar.cpp +++ b/src/widgets/qmenubar.cpp @@ -54,7 +54,7 @@ #include "ntqcleanuphandler.h" #include "../kernel/qinternal_p.h" #include "tqstyle.h" -#include "ntqtimer.h" +#include "tqtimer.h" #if defined(QT_ACCESSIBILITY_SUPPORT) #include "ntqaccessible.h" #endif diff --git a/src/widgets/qmultilineedit.cpp b/src/widgets/qmultilineedit.cpp index 09fe86a66..6ce84317b 100644 --- a/src/widgets/qmultilineedit.cpp +++ b/src/widgets/qmultilineedit.cpp @@ -49,7 +49,7 @@ #include "ntqapplication.h" #include "ntqdragobject.h" #include "ntqpopupmenu.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqdict.h" #include "../kernel/qrichtext_p.h" diff --git a/src/widgets/qpopupmenu.cpp b/src/widgets/qpopupmenu.cpp index d2926d42a..6827f1b4d 100644 --- a/src/widgets/qpopupmenu.cpp +++ b/src/widgets/qpopupmenu.cpp @@ -47,15 +47,15 @@ #include "ntqapplication.h" #include "ntqpixmap.h" #include "ntqpixmapcache.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqwhatsthis.h" #include "tqobjectlist.h" #include "ntqguardedptr.h" #include "qeffects_p.h" #include "ntqcursor.h" #include "tqstyle.h" -#include "ntqtimer.h" -#include "ntqdatetime.h" +#include "tqtimer.h" +#include "tqdatetime.h" #if defined(QT_ACCESSIBILITY_SUPPORT) #include "ntqaccessible.h" #endif diff --git a/src/widgets/qscrollbar.cpp b/src/widgets/qscrollbar.cpp index d38607085..2ac1e377b 100644 --- a/src/widgets/qscrollbar.cpp +++ b/src/widgets/qscrollbar.cpp @@ -43,7 +43,7 @@ #include "ntqpainter.h" #include "ntqbitmap.h" #include "ntqapplication.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "tqstyle.h" #ifndef TQT_NO_CURSOR #include diff --git a/src/widgets/qscrollview.cpp b/src/widgets/qscrollview.cpp index e6f459cbd..a07a3cce5 100644 --- a/src/widgets/qscrollview.cpp +++ b/src/widgets/qscrollview.cpp @@ -49,7 +49,7 @@ #include "ntqscrollview.h" #include "tqptrdict.h" #include "ntqapplication.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "tqstyle.h" #include "ntqlistview.h" #ifdef TQ_WS_MAC diff --git a/src/widgets/qslider.cpp b/src/widgets/qslider.cpp index f77fc4d42..4600ff826 100644 --- a/src/widgets/qslider.cpp +++ b/src/widgets/qslider.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_SLIDER #include "ntqpainter.h" #include "ntqdrawutil.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqbitmap.h" #include "ntqapplication.h" #include "tqstyle.h" diff --git a/src/widgets/qspinwidget.cpp b/src/widgets/qspinwidget.cpp index 6086ce11a..e2d67796d 100644 --- a/src/widgets/qspinwidget.cpp +++ b/src/widgets/qspinwidget.cpp @@ -41,7 +41,7 @@ #ifndef TQT_NO_SPINWIDGET #include "ntqrect.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "tqstyle.h" #include "ntqpainter.h" diff --git a/src/widgets/qstatusbar.cpp b/src/widgets/qstatusbar.cpp index b5c8b9cab..c7f357e3b 100644 --- a/src/widgets/qstatusbar.cpp +++ b/src/widgets/qstatusbar.cpp @@ -44,7 +44,7 @@ #include "tqptrlist.h" #include "ntqlayout.h" #include "ntqpainter.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqdrawutil.h" #include "tqstyle.h" #include "ntqsizegrip.h" diff --git a/src/widgets/qsyntaxhighlighter.cpp b/src/widgets/qsyntaxhighlighter.cpp index 8cd8ba2a8..d9fececf1 100644 --- a/src/widgets/qsyntaxhighlighter.cpp +++ b/src/widgets/qsyntaxhighlighter.cpp @@ -44,7 +44,7 @@ #ifndef TQT_NO_SYNTAXHIGHLIGHTER #include "../kernel/qrichtext_p.h" #include "tqtextedit.h" -#include "ntqtimer.h" +#include "tqtimer.h" /*! \class TQSyntaxHighlighter ntqsyntaxhighlighter.h diff --git a/src/widgets/qt_widgets.pri b/src/widgets/qt_widgets.pri index 08b852de5..a74eb7483 100644 --- a/src/widgets/qt_widgets.pri +++ b/src/widgets/qt_widgets.pri @@ -58,7 +58,7 @@ widgets { $$WIDGETS_H/ntqwhatsthis.h \ $$WIDGETS_H/tqwidgetstack.h \ $$WIDGETS_H/ntqaction.h \ - $$WIDGETS_H/ntqdatetimeedit.h \ + $$WIDGETS_H/tqdatetimeedit.h \ $$WIDGETS_H/tqtextview.h \ $$WIDGETS_H/tqtextbrowser.h \ $$WIDGETS_H/tqtextedit.h \ @@ -120,7 +120,7 @@ widgets { $$WIDGETS_CPP/qwhatsthis.cpp \ $$WIDGETS_CPP/tqwidgetstack.cpp \ $$WIDGETS_CPP/qaction.cpp \ - $$WIDGETS_CPP/qdatetimeedit.cpp \ + $$WIDGETS_CPP/tqdatetimeedit.cpp \ $$WIDGETS_CPP/qeffects.cpp \ $$WIDGETS_CPP/tqtextview.cpp \ $$WIDGETS_CPP/tqtextbrowser.cpp \ diff --git a/src/widgets/qtitlebar.cpp b/src/widgets/qtitlebar.cpp index c14e2a82a..553811d27 100644 --- a/src/widgets/qtitlebar.cpp +++ b/src/widgets/qtitlebar.cpp @@ -47,11 +47,11 @@ #include #include "ntqapplication.h" #include "tqstyle.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "private/qapplication_p.h" #include "ntqtooltip.h" #include "tqimage.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqpainter.h" #include "tqstyle.h" #include "private/qinternal_p.h" diff --git a/src/widgets/qtoolbar.cpp b/src/widgets/qtoolbar.cpp index 08c57b58d..20eba04d4 100644 --- a/src/widgets/qtoolbar.cpp +++ b/src/widgets/qtoolbar.cpp @@ -52,7 +52,7 @@ #include "ntqtoolbutton.h" #include "ntqpopupmenu.h" #include "ntqcombobox.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "tqwidgetlist.h" #include "tqstyle.h" diff --git a/src/widgets/qtoolbox.cpp b/src/widgets/qtoolbox.cpp index c426a5d68..c366dfbcb 100644 --- a/src/widgets/qtoolbox.cpp +++ b/src/widgets/qtoolbox.cpp @@ -54,7 +54,7 @@ #include #include #include -#include +#include class TQToolBoxButton : public TQButton { diff --git a/src/widgets/qtoolbutton.cpp b/src/widgets/qtoolbutton.cpp index 4b9145d4f..bfaaf47fa 100644 --- a/src/widgets/qtoolbutton.cpp +++ b/src/widgets/qtoolbutton.cpp @@ -52,7 +52,7 @@ #include "ntqtoolbar.h" #include "tqimage.h" #include "tqiconset.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqpopupmenu.h" #include "ntqguardedptr.h" diff --git a/src/widgets/qtooltip.cpp b/src/widgets/qtooltip.cpp index a9f9624f5..c897c4a58 100644 --- a/src/widgets/qtooltip.cpp +++ b/src/widgets/qtooltip.cpp @@ -42,7 +42,7 @@ #include "tqptrdict.h" #include "ntqapplication.h" #include "ntqguardedptr.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "qeffects_p.h" static bool globally_enabled = TRUE; diff --git a/src/widgets/qwhatsthis.cpp b/src/widgets/qwhatsthis.cpp index b7bc0b15b..64de3654c 100644 --- a/src/widgets/qwhatsthis.cpp +++ b/src/widgets/qwhatsthis.cpp @@ -42,7 +42,7 @@ #include "ntqpaintdevicemetrics.h" #include "ntqpixmap.h" #include "ntqpainter.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "tqptrdict.h" #include "ntqtoolbutton.h" #include "ntqshared.h" diff --git a/src/widgets/tqdatetimeedit.cpp b/src/widgets/tqdatetimeedit.cpp new file mode 100644 index 000000000..0d21eee75 --- /dev/null +++ b/src/widgets/tqdatetimeedit.cpp @@ -0,0 +1,2842 @@ +/**************************************************************************** +** +** Implementation of date and time edit classes +** +** Created : 001103 +** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqdatetimeedit.h" + +#ifndef TQT_NO_DATETIMEEDIT + +#include "../kernel/qinternal_p.h" +#include "../kernel/qrichtext_p.h" +#include "ntqrangecontrol.h" +#include "ntqapplication.h" +#include "ntqpixmap.h" +#include "ntqapplication.h" +#include "tqvaluelist.h" +#include "tqstring.h" +#include "tqstyle.h" + +#if defined(TQ_WS_WIN) +#include "qt_windows.h" +#endif + +#define TQDATETIMEEDIT_HIDDEN_CHAR '0' + +class TQ_EXPORT TQNumberSection +{ +public: + TQNumberSection( int selStart = 0, int selEnd = 0, bool separat = TRUE, int actual = -1 ) + : selstart( selStart ), selend( selEnd ), act( actual ), sep( separat ) + {} + int selectionStart() const { return selstart; } + void setSelectionStart( int s ) { selstart = s; } + int selectionEnd() const { return selend; } + void setSelectionEnd( int s ) { selend = s; } + int width() const { return selend - selstart; } + int index() const { return act; } + bool separator() const { return sep; } + TQ_DUMMY_COMPARISON_OPERATOR( TQNumberSection ) +private: + int selstart :12; + int selend :12; + int act :7; + bool sep :1; +}; + +static TQString *lDateSep = 0; +static TQString *lTimeSep = 0; +static bool lAMPM = FALSE; +static TQString *lAM = 0; +static TQString *lPM = 0; +static TQDateEdit::Order lOrder = TQDateEdit::YMD; +static int refcount = 0; + +static void cleanup() +{ + delete lDateSep; + lDateSep = 0; + delete lTimeSep; + lTimeSep = 0; + delete lAM; + lAM = 0; + delete lPM; + lPM = 0; +} + +/*! +\internal +try to get the order of DMY and the date/time separator from the locale settings +*/ +static void readLocaleSettings() +{ + int dpos, mpos, ypos; + cleanup(); + + lDateSep = new TQString(); + lTimeSep = new TQString(); + +#if defined(TQ_WS_WIN) + QT_WA( { + TCHAR data[10]; + GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_SDATE, data, 10 ); + *lDateSep = TQString::fromUcs2( (ushort*)data ); + GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_STIME, data, 10 ); + *lTimeSep = TQString::fromUcs2( (ushort*)data ); + GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_ITIME, data, 10 ); + lAMPM = TQString::fromUcs2( (ushort*)data ).toInt()==0; + GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_S1159, data, 10 ); + TQString am = TQString::fromUcs2( (ushort*)data ); + if ( !am.isEmpty() ) + lAM = new TQString( am ); + GetLocaleInfo( LOCALE_USER_DEFAULT, LOCALE_S2359, data, 10 ); + TQString pm = TQString::fromUcs2( (ushort*)data ); + if ( !pm.isEmpty() ) + lPM = new TQString( pm ); + } , { + char data[10]; + GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_SDATE, (char*)&data, 10 ); + *lDateSep = TQString::fromLocal8Bit( data ); + GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_STIME, (char*)&data, 10 ); + *lTimeSep = TQString::fromLocal8Bit( data ); + GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_ITIME, (char*)&data, 10 ); + lAMPM = TQString::fromLocal8Bit( data ).toInt()==0; + GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_S1159, (char*)&data, 10 ); + TQString am = TQString::fromLocal8Bit( data ); + if ( !am.isEmpty() ) + lAM = new TQString( am ); + GetLocaleInfoA( LOCALE_USER_DEFAULT, LOCALE_S2359, (char*)&data, 10 ); + TQString pm = TQString::fromLocal8Bit( data ); + if ( !pm.isEmpty() ) + lPM = new TQString( pm ); + } ); +#else + *lDateSep = "-"; + *lTimeSep = ":"; +#endif + TQString d = TQDate( 1999, 11, 22 ).toString( TQt::LocalDate ); + dpos = d.find( "22" ); + mpos = d.find( "11" ); + ypos = d.find( "99" ); + if ( dpos > -1 && mpos > -1 && ypos > -1 ) { + // test for DMY, MDY, YMD, YDM + if ( dpos < mpos && mpos < ypos ) { + lOrder = TQDateEdit::DMY; + } else if ( mpos < dpos && dpos < ypos ) { + lOrder = TQDateEdit::MDY; + } else if ( ypos < mpos && mpos < dpos ) { + lOrder = TQDateEdit::YMD; + } else if ( ypos < dpos && dpos < mpos ) { + lOrder = TQDateEdit::YDM; + } else { + // cannot determine the dateformat - use the default + return; + } + + // this code needs to change if new formats are added + +#ifndef TQ_WS_WIN + TQString sep = d.mid( TQMIN( dpos, mpos ) + 2, TQABS( dpos - mpos ) - 2 ); + if ( d.contains( sep ) == 2 ) { + *lDateSep = sep; + } +#endif + } + +#ifndef TQ_WS_WIN + TQString t = TQTime( 11, 22, 33 ).toString( TQt::LocalDate ); + dpos = t.find( "11" ); + mpos = t.find( "22" ); + ypos = t.find( "33" ); + // We only allow hhmmss + if ( dpos > -1 && dpos < mpos && mpos < ypos ) { + TQString sep = t.mid( dpos + 2, mpos - dpos - 2 ); + if ( sep == t.mid( mpos + 2, ypos - mpos - 2 ) ) { + *lTimeSep = sep; + } + } +#endif +} + +static TQDateEdit::Order localOrder() { + if ( !lDateSep ) { + readLocaleSettings(); + } + return lOrder; +} + +static TQString localDateSep() { + if ( !lDateSep ) { + readLocaleSettings(); + } + return *lDateSep; +} + +static TQString localTimeSep() { + if ( !lTimeSep ) { + readLocaleSettings(); + } + return *lTimeSep; +} + +class TQDateTimeEditorPrivate +{ +public: + TQDateTimeEditorPrivate() + : frm( TRUE ), + parag( new TQTextParagraph( 0, 0, 0, FALSE ) ), + focusSec(0) + { + parag->formatter()->setWrapEnabled( FALSE ); + cursor = new TQTextCursor( 0 ); + cursor->setParagraph( parag ); + offset = 0; + sep = localDateSep(); + refcount++; + } + ~TQDateTimeEditorPrivate() + { + delete parag; + delete cursor; + if ( !--refcount ) + cleanup(); + } + + void appendSection( const TQNumberSection& sec ) + { + sections.append( sec ); + + } + void clearSections() + { + sections.clear(); + } + void setSectionSelection( int sec, int selstart, int selend ) + { + if ( sec < 0 || sec > (int)sections.count() ) + return; + sections[sec].setSelectionStart( selstart ); + sections[sec].setSelectionEnd( selend ); + } + uint sectionCount() const { return (uint)sections.count(); } + void setSeparator( const TQString& s ) { sep = s; } + TQString separator() const { return sep; } + + void setFrame( bool f ) { frm = f; } + bool frame() const { return frm; } + + int focusSection() const { return focusSec; } + int section( const TQPoint& p ) + { + cursor->place( p + TQPoint( offset, 0 ), parag ); + int idx = cursor->index(); + for ( uint i = 0; i < sections.count(); ++i ) { + if ( idx >= sections[i].selectionStart() && + idx <= sections[i].selectionEnd() ) + return i; + } + return -1; + } + TQNumberSection section( int idx ) const + { + return sections[idx]; + } + bool setFocusSection( int idx ) + { + if ( idx > (int)sections.count()-1 || idx < 0 ) + return FALSE; + if ( idx != focusSec ) { + focusSec = idx; + applyFocusSelection(); + return TRUE; + } + return FALSE; + } + + bool inSectionSelection( int idx ) + { + for ( uint i = 0; i < sections.count(); ++i ) { + if ( idx >= sections[i].selectionStart() && + idx <= sections[i].selectionEnd() ) + return TRUE; + } + return FALSE; + } + + void paint( const TQString& txt, bool focus, TQPainter& p, + const TQColorGroup& cg, const TQRect& rect, TQStyle& style ) + { + int fw = 0; + if ( frm ) + fw = style.pixelMetric(TQStyle::PM_DefaultFrameWidth); + + parag->truncate( 0 ); + parag->append( txt ); + if ( !focus ) + parag->removeSelection( TQTextDocument::Standard ); + else { + applyFocusSelection(); + } + + /* color all TQDATETIMEEDIT_HIDDEN_CHAR chars to background color */ + TQTextFormat *fb = parag->formatCollection()->format( p.font(), + cg.base() ); + TQTextFormat *nf = parag->formatCollection()->format( p.font(), + cg.text() ); + for ( uint i = 0; i < txt.length(); ++i ) { + parag->setFormat( i, 1, nf ); + if ( inSectionSelection( i ) ) + continue; + if ( txt.at(i) == TQDATETIMEEDIT_HIDDEN_CHAR ) + parag->setFormat( i, 1, fb ); + else + parag->setFormat( i, 1, nf ); + } + fb->removeRef(); + nf->removeRef(); + + TQRect r( rect.x(), rect.y(), rect.width() - 2 * ( 2 + fw ), rect.height() ); + parag->pseudoDocument()->docRect = r; + parag->invalidate(0); + parag->format(); + + int xoff = 2 + fw - offset; + int yoff = ( rect.height() - parag->rect().height() + 1 ) / 2; + if ( yoff < 0 ) + yoff = 0; + + p.translate( xoff, yoff ); + parag->paint( p, cg, 0, TRUE ); + if ( frm ) + p.translate( -xoff, -yoff ); + } + + void resize( const TQSize& size ) { sz = size; } + + int mapSection( int sec ) + { + return sections[sec].index(); + } + +protected: + void applyFocusSelection() + { + if ( focusSec > -1 ) { + int selstart = sections[ focusSec ].selectionStart(); + int selend = sections[ focusSec ].selectionEnd(); + parag->setSelection( TQTextDocument::Standard, selstart, selend ); + parag->format(); + if ( parag->at( selstart )->x < offset || + parag->at( selend )->x + parag->string()->width( selend ) > offset + sz.width() ) { + offset = parag->at( selstart )->x; + } + } + } +private: + bool frm; + TQTextParagraph *parag; + TQTextCursor *cursor; + TQSize sz; + int focusSec; + TQValueList< TQNumberSection > sections; + TQString sep; + int offset; +}; + +class TQDateTimeEditor : public TQWidget +{ + TQ_OBJECT +public: + TQDateTimeEditor( TQDateTimeEditBase * widget, TQWidget *parent, + const char * name=0 ); + ~TQDateTimeEditor(); + + void setControlWidget( TQDateTimeEditBase * widget ); + TQDateTimeEditBase * controlWidget() const; + + void setSeparator( const TQString& s ); + TQString separator() const; + + int focusSection() const; + bool setFocusSection( int s ); + void appendSection( const TQNumberSection& sec ); + void clearSections(); + void setSectionSelection( int sec, int selstart, int selend ); + bool eventFilter( TQObject *o, TQEvent *e ); + int sectionAt( const TQPoint &p ); + int mapSection( int sec ); + +protected: + void init(); + bool event( TQEvent *e ); + void resizeEvent( TQResizeEvent * ); + void paintEvent( TQPaintEvent * ); + void mousePressEvent( TQMouseEvent *e ); + +private: + TQDateTimeEditBase* cw; + TQDateTimeEditorPrivate* d; +}; + +class TQDateTimeSpinWidget : public TQSpinWidget +{ +public: + TQDateTimeSpinWidget( TQWidget *parent, const char *name ) + : TQSpinWidget( parent, name ) + { + } + + void enabledChange(bool notenabled) + { + TQDateEdit *de = ::tqt_cast(parentWidget()); + if (de && !notenabled) { + setUpEnabled(de->date() < de->maxValue()); + setDownEnabled(de->date() > de->minValue()); + } else { + setUpEnabled(!notenabled); + setDownEnabled(!notenabled); + } + } + +protected: +#ifndef TQT_NO_WHEELEVENT + void wheelEvent( TQWheelEvent *e ) + { + TQDateTimeEditor *editor = (TQDateTimeEditor*)editWidget()->tqt_cast( "TQDateTimeEditor" ); + Q_ASSERT( editor ); + if ( !editor ) + return; + + int section = editor->sectionAt( e->pos() ); + editor->setFocusSection( section ); + + if ( section == -1 ) + return; + TQSpinWidget::wheelEvent( e ); + } +#endif +}; + +/*! + Constructs an empty datetime editor with parent \a parent and + called \a name. +*/ +TQDateTimeEditor::TQDateTimeEditor( TQDateTimeEditBase * widget, TQWidget *parent, + const char * name ) + : TQWidget( parent, name, WNoAutoErase ) +{ + d = new TQDateTimeEditorPrivate(); + cw = widget; + init(); +} + +/*! + Destroys the object and frees any allocated resources. +*/ + +TQDateTimeEditor::~TQDateTimeEditor() +{ + delete d; +} + +/*! \internal + +*/ + +void TQDateTimeEditor::init() +{ + setBackgroundMode( PaletteBase ); + setFocusSection( -1 ); + installEventFilter( this ); + setFocusPolicy( WheelFocus ); +} + + +/*! \reimp + +*/ + +bool TQDateTimeEditor::event( TQEvent *e ) +{ + if ( e->type() == TQEvent::FocusIn || e->type() == TQEvent::FocusOut ) { + if ( e->type() == TQEvent::FocusOut ) + tqApp->sendEvent( cw, e ); + update( rect() ); + } else if ( e->type() == TQEvent::AccelOverride ) { + TQKeyEvent* ke = (TQKeyEvent*) e; + switch ( ke->key() ) { + case Key_Delete: + case Key_Backspace: + case Key_Up: + case Key_Down: + case Key_Left: + case Key_Right: + ke->accept(); + default: + break; + } + } + return TQWidget::event( e ); +} + +/*! \reimp + +*/ + +void TQDateTimeEditor::resizeEvent( TQResizeEvent *e ) +{ + d->resize( e->size() ); + TQWidget::resizeEvent( e ); +} + + +/*! \reimp + +*/ + +void TQDateTimeEditor::paintEvent( TQPaintEvent * ) +{ + TQString txt; + for ( uint i = 0; i < d->sectionCount(); ++i ) { + txt += cw->sectionFormattedText( i ); + if ( i < d->sectionCount()-1 ) { + if ( d->section( i+1 ).separator() ) + txt += d->separator(); + else + txt += " "; + } + } + + TQSharedDoubleBuffer buffer( this ); + const TQBrush &bg = + colorGroup().brush( isEnabled() ? TQColorGroup::Base : TQColorGroup::Background ); + buffer.painter()->fillRect( 0, 0, width(), height(), bg ); + d->paint( txt, hasFocus(), *buffer.painter(), colorGroup(), rect(), + style() ); + buffer.end(); +} + + +/*! + Returns the section index at point \a p. +*/ +int TQDateTimeEditor::sectionAt( const TQPoint &p ) +{ + return d->section( p ); +} + +int TQDateTimeEditor::mapSection( int sec ) +{ + return d->mapSection( sec ); +} + + +/*! \reimp + +*/ + +void TQDateTimeEditor::mousePressEvent( TQMouseEvent *e ) +{ + TQPoint p( e->pos().x(), 0 ); + int sec = sectionAt( p ); + if ( sec != -1 ) { + cw->setFocusSection( sec ); + repaint( rect(), FALSE ); + } +} + +/*! \reimp + +*/ +bool TQDateTimeEditor::eventFilter( TQObject *o, TQEvent *e ) +{ + if ( o == this ) { + if ( e->type() == TQEvent::KeyPress ) { + TQKeyEvent *ke = (TQKeyEvent*)e; + switch ( ke->key() ) { + case Key_Right: + if ( d->focusSection() < (int)d->sectionCount()-1 ) { + if ( cw->setFocusSection( focusSection()+1 ) ) + repaint( rect(), FALSE ); + } + return TRUE; + case Key_Left: + if ( d->focusSection() > 0 ) { + if ( cw->setFocusSection( focusSection()-1 ) ) + repaint( rect(), FALSE ); + } + return TRUE; + case Key_Up: + cw->stepUp(); + return TRUE; + case Key_Down: + cw->stepDown(); + return TRUE; + case Key_Backspace: + if ( ::tqt_cast(cw) ) + ((TQDateEdit*)cw)->removeFirstNumber( d->focusSection() ); + else if ( ::tqt_cast(cw) ) + ((TQTimeEdit*)cw)->removeFirstNumber( d->focusSection() ); + return TRUE; + case Key_Delete: + cw->removeLastNumber( d->focusSection() ); + return TRUE; + case Key_Tab: + case Key_BackTab: { + if ( ke->state() == TQt::ControlButton ) + return FALSE; + + TQWidget *w = this; + bool hadDateEdit = FALSE; + while ( w ) { + if ( ( ::tqt_cast(w) && qstrcmp( w->name(), "qt_spin_widget" ) != 0 ) || + ::tqt_cast(w) ) + break; + hadDateEdit = hadDateEdit || ::tqt_cast(w); + w = w->parentWidget(); + } + + if ( w ) { + if ( !::tqt_cast(w) ) { + w = w->parentWidget(); + } else { + TQDateTimeEdit *ed = (TQDateTimeEdit*)w; + if ( hadDateEdit && ke->key() == Key_Tab ) { + ed->timeEdit()->setFocus(); + return TRUE; + } else if ( !hadDateEdit && ke->key() == Key_BackTab ) { + ed->dateEdit()->setFocus(); + return TRUE; + } else { + while ( w && !::tqt_cast(w) ) + w = w->parentWidget(); + } + } + + tqApp->sendEvent( w, e ); + return TRUE; + } + } break; + default: + TQString txt = ke->text().lower(); + if ( !txt.isEmpty() && !separator().isEmpty() && txt[0] == separator()[0] ) { + // do the same thing as KEY_RIGHT when the user presses the separator key + if ( d->focusSection() < 2 ) { + if ( cw->setFocusSection( focusSection()+1 ) ) + repaint( rect(), FALSE ); + } + return TRUE; + } else if ( !txt.isEmpty() && ::tqt_cast(cw) && focusSection() == (int) d->sectionCount()-1 ) { + // the first character of the AM/PM indicator toggles if the section has focus + TQTimeEdit *te = (TQTimeEdit*)cw; + TQTime time = te->time(); + if ( lAMPM && lAM && lPM && (te->display()&TQTimeEdit::AMPM) ) { + if ( txt[0] == (*lAM).lower()[0] && time.hour() >= 12 ) { + time.setHMS( time.hour()-12, time.minute(), time.second(), time.msec() ); + te->setTime( time ); + } else if ( txt[0] == (*lPM).lower()[0] && time.hour() < 12 ) { + time.setHMS( time.hour()+12, time.minute(), time.second(), time.msec() ); + te->setTime( time ); + } + } + } + + int num = txt[0].digitValue(); + if ( num != -1 ) { + cw->addNumber( d->focusSection(), num ); + return TRUE; + } + } + } + } + return FALSE; +} + + +/*! + Appends the number section \a sec to the editor. +*/ + +void TQDateTimeEditor::appendSection( const TQNumberSection& sec ) +{ + d->appendSection( sec ); +} + +/*! + Removes all sections from the editor. +*/ + +void TQDateTimeEditor::clearSections() +{ + d->clearSections(); +} + +/*! + Sets the selection of \a sec to start at \a selstart and end at \a + selend. +*/ + +void TQDateTimeEditor::setSectionSelection( int sec, int selstart, int selend ) +{ + d->setSectionSelection( sec, selstart, selend ); +} + +/*! + Sets the separator for all numbered sections to \a s. Note that + currently, only the first character of \a s is used. +*/ + +void TQDateTimeEditor::setSeparator( const TQString& s ) +{ + d->setSeparator( s ); + update(); +} + + +/*! + Returns the editor's separator. +*/ + +TQString TQDateTimeEditor::separator() const +{ + return d->separator(); +} + +/*! + Returns the number of the section that has focus. +*/ + +int TQDateTimeEditor::focusSection() const +{ + return d->focusSection(); +} + + +/*! + Sets the focus to section \a sec. If \a sec does not exist, + nothing happens. +*/ + +bool TQDateTimeEditor::setFocusSection( int sec ) +{ + return d->setFocusSection( sec ); +} + +/*! \class TQDateTimeEditBase + \brief The TQDateTimeEditBase class provides an abstraction for date and edit editors. + + Small abstract class that provides some functions that are common + for both TQDateEdit and TQTimeEdit. It is used internally by + TQDateTimeEditor. +*/ + +/*! + \fn TQDateTimeEditBase::TQDateTimeEditBase(TQWidget *, const char*) + \internal +*/ + +/*! + \fn TQDateTimeEditBase::setFocusSection(int) + \internal +*/ + +/*! \fn TQString TQDateTimeEditBase::sectionFormattedText( int sec ) + \internal + + Pure virtual function which returns the formatted text of section \a + sec. + +*/ + +/*! \fn void TQDateTimeEditBase::stepUp() + \internal + + Pure virtual slot which is called whenever the user increases the + number in a section by pressing the widget's arrow buttons or the + keyboard's arrow keys. +*/ + +/*! \fn void TQDateTimeEditBase::stepDown() + \internal + + Pure virtual slot which is called whenever the user decreases the + number in a section by pressing the widget's arrow buttons or the + keyboard's arrow keys. + +*/ + +/*! \fn void TQDateTimeEditBase::addNumber( int sec, int num ) + \internal + + Pure virtual function which is called whenever the user types a number. + \a sec indicates the section where the number should be added. \a + num is the number that was pressed. +*/ + +/*! \fn void TQDateTimeEditBase::removeLastNumber( int sec ) + \internal + + Pure virtual function which is called whenever the user tries to + remove the last number from \a sec by pressing the delete key. +*/ + +//////////////// + +class TQDateEditPrivate +{ +public: + int y; + int m; + int d; + // remebers the last entry for the day. + // if the day is 31 and you cycle through the months, + // the day will be 31 again if you reach a month with 31 days + // otherwise it will be the highest day in the month + int dayCache; + int yearSection; + int monthSection; + int daySection; + TQDateEdit::Order ord; + bool overwrite; + bool adv; + int timerId; + bool typing; + TQDate min; + TQDate max; + bool changed; + TQDateTimeEditor *ed; + TQSpinWidget *controls; +}; + + +/*! + \class TQDateEdit tqdatetimeedit.h + \brief The TQDateEdit class provides a date editor. + + \ingroup advanced + \ingroup time + \mainclass + + TQDateEdit allows the user to edit dates by using the keyboard or + the arrow keys to increase/decrease date values. The arrow keys + can be used to move from section to section within the TQDateEdit + box. Dates appear in accordance with the local date/time settings + or in year, month, day order if the system doesn't provide this + information. It is recommended that the TQDateEdit be initialised + with a date, e.g. + + \code + TQDateEdit *dateEdit = new TQDateEdit( TQDate::currentDate(), this ); + dateEdit->setRange( TQDate::currentDate().addDays( -365 ), + TQDate::currentDate().addDays( 365 ) ); + dateEdit->setOrder( TQDateEdit::MDY ); + dateEdit->setAutoAdvance( TRUE ); + \endcode + + Here we've created a new TQDateEdit object initialised with today's + date and restricted the valid date range to today plus or minus + 365 days. We've set the order to month, day, year. If the auto + advance property is TRUE (as we've set it here) when the user + completes a section of the date, e.g. enters two digits for the + month, they are automatically taken to the next section. + + The maximum and minimum values for a date value in the date editor + default to the maximum and minimum values for a TQDate. You can + change this by calling setMinValue(), setMaxValue() or setRange(). + + Terminology: A TQDateEdit widget comprises three 'sections', one + each for the year, month and day. You can change the separator + character using TQDateTimeEditor::setSeparator(), by default the + separator will be taken from the systems settings. If that is + not possible, it defaults to "-". + + \img datetimewidgets.png Date Time Widgets + + \sa TQDate TQTimeEdit TQDateTimeEdit +*/ + +/*! + \enum TQDateEdit::Order + + This enum defines the order in which the sections that comprise a + date appear. + \value MDY month-day-year + \value DMY day-month-year + \value YMD year-month-day (the default) + \value YDM year-day-month (included for completeness; but should + not be used) +*/ + +/*! + \enum TQTimeEdit::Display + + This enum defines the sections that comprise a time + + \value Hours The hours section + \value Minutes The minutes section + \value Seconds The seconds section + \value AMPM The AM/PM section + + The values can be or'ed together to show any combination. +*/ + +/*! + Constructs an empty date editor which is a child of \a parent and + called name \a name. +*/ + +TQDateEdit::TQDateEdit( TQWidget * parent, const char * name ) + : TQDateTimeEditBase( parent, name ) +{ + init(); + updateButtons(); +} + +/*! + \overload + + Constructs a date editor with the initial value \a date, parent \a + parent and called \a name. + + The date editor is initialized with \a date. +*/ + +TQDateEdit::TQDateEdit( const TQDate& date, TQWidget * parent, const char * name ) + : TQDateTimeEditBase( parent, name ) +{ + init(); + setDate( date ); +} + +/*! \internal +*/ +void TQDateEdit::init() +{ + d = new TQDateEditPrivate(); + d->controls = new TQDateTimeSpinWidget( this, qstrcmp( name(), "qt_datetime_dateedit" ) == 0 ? "qt_spin_widget" : "date edit controls" ); + d->ed = new TQDateTimeEditor( this, d->controls, "date editor" ); + d->controls->setEditWidget( d->ed ); + setFocusProxy( d->ed ); + connect( d->controls, TQ_SIGNAL( stepUpPressed() ), TQ_SLOT( stepUp() ) ); + connect( d->controls, TQ_SIGNAL( stepDownPressed() ), TQ_SLOT( stepDown() ) ); + connect( this, TQ_SIGNAL( valueChanged(const TQDate&) ), + TQ_SLOT( updateButtons() ) ); + d->ed->appendSection( TQNumberSection( 0,4 ) ); + d->ed->appendSection( TQNumberSection( 5,7 ) ); + d->ed->appendSection( TQNumberSection( 8,10 ) ); + + d->yearSection = -1; + d->monthSection = -1; + d->daySection = -1; + + d->y = 0; + d->m = 0; + d->d = 0; + d->dayCache = 0; + setOrder( localOrder() ); + setFocusSection( 0 ); + d->overwrite = TRUE; + d->adv = FALSE; + d->timerId = 0; + d->typing = FALSE; + d->min = TQDate( 1752, 9, 14 ); + d->max = TQDate( 8000, 12, 31 ); + d->changed = FALSE; + + setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ); + + refcount++; +} + +/*! + Destroys the object and frees any allocated resources. +*/ + +TQDateEdit::~TQDateEdit() +{ + delete d; + if ( !--refcount ) + cleanup(); +} + +/*! + \property TQDateEdit::minValue + + \brief the editor's minimum value + + Setting the minimum date value is equivalent to calling + TQDateEdit::setRange( \e d, maxValue() ), where \e d is the minimum + date. The default minimum date is 1752-09-14. + + \sa maxValue setRange() +*/ + +TQDate TQDateEdit::minValue() const +{ + return d->min; +} + +/*! + \property TQDateEdit::maxValue + + \brief the editor's maximum value + + Setting the maximum date value for the editor is equivalent to + calling TQDateEdit::setRange( minValue(), \e d ), where \e d is the + maximum date. The default maximum date is 8000-12-31. + + \sa minValue setRange() +*/ + +TQDate TQDateEdit::maxValue() const +{ + return d->max; +} + + +/*! + Sets the valid input range for the editor to be from \a min to \a + max inclusive. If \a min is invalid no minimum date will be set. + Similarly, if \a max is invalid no maximum date will be set. +*/ + +void TQDateEdit::setRange( const TQDate& min, const TQDate& max ) +{ + if ( min.isValid() ) + d->min = min; + if ( max.isValid() ) + d->max = max; +} + +/*! + Sets the separator to \a s. Note that currently only the first + character of \a s is used. +*/ + +void TQDateEdit::setSeparator( const TQString& s ) +{ + d->ed->setSeparator( s ); +} + +/*! + Returns the editor's separator. +*/ + +TQString TQDateEdit::separator() const +{ + return d->ed->separator(); +} + + +/*! + Enables/disables the push buttons according to the min/max date + for this widget. +*/ + +void TQDateEdit::updateButtons() +{ + if ( !isEnabled() ) + return; + + bool upEnabled = date() < maxValue(); + bool downEnabled = date() > minValue(); + + d->controls->setUpEnabled( upEnabled ); + d->controls->setDownEnabled( downEnabled ); +} + +/*! \reimp + */ +void TQDateEdit::resizeEvent( TQResizeEvent * ) +{ + d->controls->resize( width(), height() ); +} + +/*! \reimp + +*/ +TQSize TQDateEdit::sizeHint() const +{ + constPolish(); + TQFontMetrics fm( font() ); + int fw = style().pixelMetric( TQStyle::PM_DefaultFrameWidth, this ); + int h = TQMAX( fm.lineSpacing(), 14 ) + 2; + int w = 2 + fm.width( '9' ) * 8 + fm.width( d->ed->separator() ) * 2 + d->controls->upRect().width() + fw * 4; + + return TQSize( w, TQMAX(h + fw * 2,20) ).expandedTo( TQApplication::globalStrut() ); +} + +/*! \reimp + +*/ +TQSize TQDateEdit::minimumSizeHint() const +{ + return sizeHint(); +} + + +/*! + Returns the formatted number for section \a sec. This will + correspond to either the year, month or day section, depending on + the current display order. + + \sa setOrder() +*/ + +TQString TQDateEdit::sectionFormattedText( int sec ) +{ + TQString txt; + txt = sectionText( sec ); + if ( d->typing && sec == d->ed->focusSection() ) + d->ed->setSectionSelection( sec, sectionOffsetEnd( sec ) - txt.length(), + sectionOffsetEnd( sec ) ); + else + d->ed->setSectionSelection( sec, sectionOffsetEnd( sec ) - sectionLength( sec ), + sectionOffsetEnd( sec ) ); + txt = txt.rightJustify( sectionLength( sec ), TQDATETIMEEDIT_HIDDEN_CHAR ); + return txt; +} + + +/*! + Returns the desired length (number of digits) of section \a sec. + This will correspond to either the year, month or day section, + depending on the current display order. + + \sa setOrder() +*/ + +int TQDateEdit::sectionLength( int sec ) const +{ + int val = 0; + if ( sec == d->yearSection ) { + val = 4; + } else if ( sec == d->monthSection ) { + val = 2; + } else if ( sec == d->daySection ) { + val = 2; + } + return val; +} + +/*! + Returns the text of section \a sec. This will correspond to either + the year, month or day section, depending on the current display + order. + + \sa setOrder() +*/ + +TQString TQDateEdit::sectionText( int sec ) const +{ + int val = 0; + if ( sec == d->yearSection ) { + val = d->y; + } else if ( sec == d->monthSection ) { + val = d->m; + } else if ( sec == d->daySection ) { + val = d->d; + } + return TQString::number( val ); +} + +/*! \internal + + Returns the end of the section offset \a sec. + +*/ + +int TQDateEdit::sectionOffsetEnd( int sec ) const +{ + if ( sec == d->yearSection ) { + switch( d->ord ) { + case DMY: + case MDY: + return sectionOffsetEnd( sec-1) + separator().length() + sectionLength( sec ); + case YMD: + case YDM: + return sectionLength( sec ); + } + } else if ( sec == d->monthSection ) { + switch( d->ord ) { + case DMY: + case YDM: + case YMD: + return sectionOffsetEnd( sec-1) + separator().length() + sectionLength( sec ); + case MDY: + return sectionLength( sec ); + } + } else if ( sec == d->daySection ) { + switch( d->ord ) { + case DMY: + return sectionLength( sec ); + case YMD: + case MDY: + case YDM: + return sectionOffsetEnd( sec-1 ) + separator().length() + sectionLength( sec ); + } + } + return 0; +} + + +/*! + \property TQDateEdit::order + \brief the order in which the year, month and day appear + + The default order is locale dependent. + + \sa Order +*/ + +void TQDateEdit::setOrder( TQDateEdit::Order order ) +{ + d->ord = order; + switch( d->ord ) { + case DMY: + d->yearSection = 2; + d->monthSection = 1; + d->daySection = 0; + break; + case MDY: + d->yearSection = 2; + d->monthSection = 0; + d->daySection = 1; + break; + case YMD: + d->yearSection = 0; + d->monthSection = 1; + d->daySection = 2; + break; + case YDM: + d->yearSection = 0; + d->monthSection = 2; + d->daySection = 1; + break; + } + if ( isVisible() ) + d->ed->repaint( d->ed->rect(), FALSE ); +} + + +TQDateEdit::Order TQDateEdit::order() const +{ + return d->ord; +} + + +/*! \reimp + +*/ +void TQDateEdit::stepUp() +{ + int sec = d->ed->focusSection(); + bool accepted = FALSE; + if ( sec == d->yearSection ) { + if ( !outOfRange( d->y+1, d->m, d->d ) ) { + accepted = TRUE; + setYear( d->y+1 ); + } + } else if ( sec == d->monthSection ) { + if ( !outOfRange( d->y, d->m+1, d->d ) ) { + accepted = TRUE; + setMonth( d->m+1 ); + } + } else if ( sec == d->daySection ) { + if ( !outOfRange( d->y, d->m, d->d+1 ) ) { + accepted = TRUE; + setDay( d->d+1 ); + } + } + if ( accepted ) { + d->changed = FALSE; + emit valueChanged( date() ); + } + d->ed->repaint( d->ed->rect(), FALSE ); +} + + + +/*! \reimp + +*/ + +void TQDateEdit::stepDown() +{ + int sec = d->ed->focusSection(); + bool accepted = FALSE; + if ( sec == d->yearSection ) { + if ( !outOfRange( d->y-1, d->m, d->d ) ) { + accepted = TRUE; + setYear( d->y-1 ); + } + } else if ( sec == d->monthSection ) { + if ( !outOfRange( d->y, d->m-1, d->d ) ) { + accepted = TRUE; + setMonth( d->m-1 ); + } + } else if ( sec == d->daySection ) { + if ( !outOfRange( d->y, d->m, d->d-1 ) ) { + accepted = TRUE; + setDay( d->d-1 ); + } + } + if ( accepted ) { + d->changed = FALSE; + emit valueChanged( date() ); + } + d->ed->repaint( d->ed->rect(), FALSE ); +} + +/*! + Sets the year to \a year, which must be a valid year. The range + currently supported is from 1752 to 8000. + + \sa TQDate +*/ + +void TQDateEdit::setYear( int year ) +{ + if ( year < 1752 ) + year = 1752; + if ( year > 8000 ) + year = 8000; + if ( !outOfRange( year, d->m, d->d ) ) { + d->y = year; + setMonth( d->m ); + int tmp = d->dayCache; + setDay( d->dayCache ); + d->dayCache = tmp; + } +} + + +/*! + Sets the month to \a month, which must be a valid month, i.e. + between 1 and 12. +*/ + +void TQDateEdit::setMonth( int month ) +{ + if ( month < 1 ) + month = 1; + if ( month > 12 ) + month = 12; + if ( !outOfRange( d->y, month, d->d ) ) { + d->m = month; + int tmp = d->dayCache; + setDay( d->dayCache ); + d->dayCache = tmp; + } +} + + +/*! + Sets the day to \a day, which must be a valid day. The function + will ensure that the \a day set is valid for the month and year. +*/ + +void TQDateEdit::setDay( int day ) +{ + if ( day < 1 ) + day = 1; + if ( day > 31 ) + day = 31; + if ( d->m > 0 && d->y > 1752 ) { + while ( !TQDate::isValid( d->y, d->m, day ) ) + --day; + if ( !outOfRange( d->y, d->m, day ) ) + d->d = day; + } else if ( d->m > 0 ) { + if ( day > 0 && day < 32 ) { + if ( !outOfRange( d->y, d->m, day ) ) + d->d = day; + } + } + d->dayCache = d->d; +} + + +/*! + \property TQDateEdit::date + \brief the editor's date value. + + If the date property is not valid, the editor displays all zeroes + and TQDateEdit::date() will return an invalid date. It is strongly + recommended that the editor is given a default date value (e.g. + currentDate()). That way, attempts to set the date property to an + invalid date will fail. + + When changing the date property, if the date is less than + minValue(), or is greater than maxValue(), nothing happens. +*/ + +void TQDateEdit::setDate( const TQDate& date ) +{ + if ( !date.isValid() ) { + d->y = 0; + d->m = 0; + d->d = 0; + d->dayCache = 0; + } else { + if ( date > maxValue() || date < minValue() ) + return; + d->y = date.year(); + d->m = date.month(); + d->d = date.day(); + d->dayCache = d->d; + emit valueChanged( date ); + } + d->changed = FALSE; + d->ed->repaint( d->ed->rect(), FALSE ); +} + +TQDate TQDateEdit::date() const +{ + if ( TQDate::isValid( d->y, d->m, d->d ) ) + return TQDate( d->y, d->m, d->d ); + return TQDate(); +} + +/*! \internal + + Returns TRUE if \a y, \a m, \a d is out of range, otherwise returns + FALSE. + + \sa setRange() + +*/ + +bool TQDateEdit::outOfRange( int y, int m, int d ) const +{ + if ( TQDate::isValid( y, m, d ) ) { + TQDate currentDate( y, m, d ); + if ( currentDate > maxValue() || + currentDate < minValue() ) { + //## outOfRange should set overwrite? + return TRUE; + } + return FALSE; + } + return FALSE; /* assume ok */ +} + +/*! \reimp + +*/ + +void TQDateEdit::addNumber( int sec, int num ) +{ + if ( sec == -1 ) + return; + killTimer( d->timerId ); + bool overwrite = FALSE; + bool accepted = FALSE; + d->typing = TRUE; + TQString txt; + if ( sec == d->yearSection ) { + txt = TQString::number( d->y ); + if ( d->overwrite || txt.length() == 4 ) { + accepted = TRUE; + d->y = num; + } else { + txt += TQString::number( num ); + if ( txt.length() == 4 ) { + int val = txt.toInt(); + if ( val < 1792 ) + d->y = 1792; + else if ( val > 8000 ) + d->y = 8000; + else if ( outOfRange( val, d->m, d->d ) ) + txt = TQString::number( d->y ); + else { + accepted = TRUE; + d->y = val; + } + } else { + accepted = TRUE; + d->y = txt.toInt(); + } + if ( d->adv && txt.length() == 4 ) { + d->ed->setFocusSection( d->ed->focusSection()+1 ); + overwrite = TRUE; + } + } + } else if ( sec == d->monthSection ) { + txt = TQString::number( d->m ); + if ( d->overwrite || txt.length() == 2 ) { + accepted = TRUE; + d->m = num; + } else { + txt += TQString::number( num ); + int temp = txt.toInt(); + if ( temp > 12 ) + temp = num; + if ( outOfRange( d->y, temp, d->d ) ) + txt = TQString::number( d->m ); + else { + accepted = TRUE; + d->m = temp; + } + if ( d->adv && txt.length() == 2 ) { + d->ed->setFocusSection( d->ed->focusSection()+1 ); + overwrite = TRUE; + } + } + } else if ( sec == d->daySection ) { + txt = TQString::number( d->d ); + if ( d->overwrite || txt.length() == 2 ) { + accepted = TRUE; + d->d = num; + d->dayCache = d->d; + } else { + txt += TQString::number( num ); + int temp = txt.toInt(); + if ( temp > 31 ) + temp = num; + if ( outOfRange( d->y, d->m, temp ) ) + txt = TQString::number( d->d ); + else { + accepted = TRUE; + d->d = temp; + d->dayCache = d->d; + } + if ( d->adv && txt.length() == 2 ) { + d->ed->setFocusSection( d->ed->focusSection()+1 ); + overwrite = TRUE; + } + } + } + if ( accepted ) { + d->changed = FALSE; + emit valueChanged( date() ); + } + d->overwrite = overwrite; + d->timerId = startTimer( tqApp->doubleClickInterval()*4 ); + d->ed->repaint( d->ed->rect(), FALSE ); +} + + +/*! \reimp + +*/ + +bool TQDateEdit::setFocusSection( int s ) +{ + if ( s != d->ed->focusSection() ) { + killTimer( d->timerId ); + d->overwrite = TRUE; + d->typing = FALSE; + fix(); // will emit valueChanged if necessary + } + return d->ed->setFocusSection( s ); +} + + +/*! + Attempts to fix any invalid date entries. + + The rules applied are as follows: + + \list + \i If the year has four digits it is left unchanged. + \i If the year has two digits, the year will be changed to four + digits in the range current year - 70 to current year + 29. + \i If the year has three digits in the range 100..999, the + current millennium, i.e. 2000, will be added giving a year + in the range 2100..2999. + \i If the day or month is 0 then it will be set to 1 or the + minimum valid day\month in the range. + \endlist + +*/ + +void TQDateEdit::fix() +{ + bool changed = FALSE; + int currentYear = TQDate::currentDate().year(); + int year = d->y; + if ( year < 100 ) { + int currentCentury = currentYear / 100; + year += currentCentury * 100; + if ( currentYear > year ) { + if ( currentYear > year + 70 ) + year += 100; + } else { + if ( year >= currentYear + 30 ) + year -= 100; + } + changed = TRUE; + } else if ( year < 1000 ) { + int currentMillennium = currentYear / 10; + year += currentMillennium * 10; + changed = TRUE; + } else if (d->d == 0) { + d->d = 1; + changed = TRUE; + } else if (d->m == 0) { + d->m = 1; + changed = TRUE; + } + if ( outOfRange( year, d->m, d->d ) ) { + if ( minValue().isValid() && date() < minValue() ) { + d->d = minValue().day(); + d->dayCache = d->d; + d->m = minValue().month(); + d->y = minValue().year(); + } + if ( date() > maxValue() ) { + d->d = maxValue().day(); + d->dayCache = d->d; + d->m = maxValue().month(); + d->y = maxValue().year(); + } + changed = TRUE; + } else if ( changed ) + setYear( year ); + if ( changed ) { + emit valueChanged( date() ); + d->changed = FALSE; + } +} + + +/*! \reimp + +*/ + +bool TQDateEdit::event( TQEvent *e ) +{ + if( e->type() == TQEvent::FocusOut ) { + d->typing = FALSE; + fix(); + // the following can't be done in fix() because fix() called + // from all over the place and it will break the old behaviour + if ( !TQDate::isValid( d->y, d->m, d->d ) ) { + d->dayCache = d->d; + int i = d->d; + for ( ; i > 0; i-- ) { + d->d = i; + if ( TQDate::isValid( d->y, d->m, d->d ) ) + break; + } + d->changed = TRUE; + } + if ( d->changed ) { + emit valueChanged( date() ); + d->changed = FALSE; + } + } else if ( e->type() == TQEvent::LocaleChange ) { + readLocaleSettings(); + d->ed->setSeparator( localDateSep() ); + setOrder( localOrder() ); + } + return TQDateTimeEditBase::event( e ); +} + +/*! + \internal + + Function which is called whenever the user tries to + remove the first number from \a sec by pressing the backspace key. +*/ + +void TQDateEdit::removeFirstNumber( int sec ) +{ + if ( sec == -1 ) + return; + TQString txt; + if ( sec == d->yearSection ) { + txt = TQString::number( d->y ); + txt = txt.mid( 1, txt.length() ) + "0"; + d->y = txt.toInt(); + } else if ( sec == d->monthSection ) { + txt = TQString::number( d->m ); + txt = txt.mid( 1, txt.length() ) + "0"; + d->m = txt.toInt(); + } else if ( sec == d->daySection ) { + txt = TQString::number( d->d ); + txt = txt.mid( 1, txt.length() ) + "0"; + d->d = txt.toInt(); + d->dayCache = d->d; + } + d->ed->repaint( d->ed->rect(), FALSE ); +} + +/*! \reimp + +*/ + +void TQDateEdit::removeLastNumber( int sec ) +{ + if ( sec == -1 ) + return; + TQString txt; + if ( sec == d->yearSection ) { + txt = TQString::number( d->y ); + txt = txt.mid( 0, txt.length()-1 ); + d->y = txt.toInt(); + } else if ( sec == d->monthSection ) { + txt = TQString::number( d->m ); + txt = txt.mid( 0, txt.length()-1 ); + d->m = txt.toInt(); + } else if ( sec == d->daySection ) { + txt = TQString::number( d->d ); + txt = txt.mid( 0, txt.length()-1 ); + d->d = txt.toInt(); + d->dayCache = d->d; + } + d->ed->repaint( d->ed->rect(), FALSE ); +} + +/*! + \property TQDateEdit::autoAdvance + \brief whether the editor automatically advances to the next + section + + If autoAdvance is TRUE, the editor will automatically advance + focus to the next date section if a user has completed a section. + The default is FALSE. +*/ + +void TQDateEdit::setAutoAdvance( bool advance ) +{ + d->adv = advance; +} + + +bool TQDateEdit::autoAdvance() const +{ + return d->adv; +} + +/*! \reimp +*/ + +void TQDateEdit::timerEvent( TQTimerEvent * ) +{ + d->overwrite = TRUE; +} + +/*! + \fn void TQDateEdit::valueChanged( const TQDate& date ) + + This signal is emitted whenever the editor's value changes. The \a + date parameter is the new value. +*/ + +/////////// + +class TQTimeEditPrivate +{ +public: + int h; + int m; + int s; + uint display; + bool adv; + bool overwrite; + int timerId; + bool typing; + TQTime min; + TQTime max; + bool changed; + TQDateTimeEditor *ed; + TQSpinWidget *controls; +}; + +/*! + \class TQTimeEdit tqdatetimeedit.h + \brief The TQTimeEdit class provides a time editor. + + \ingroup advanced + \ingroup time + \mainclass + + TQTimeEdit allows the user to edit times by using the keyboard or + the arrow keys to increase/decrease time values. The arrow keys + can be used to move from section to section within the TQTimeEdit + box. The user can automatically be moved to the next section once + they complete a section using setAutoAdvance(). Times appear in + hour, minute, second order. It is recommended that the TQTimeEdit + is initialised with a time, e.g. + \code + TQTime timeNow = TQTime::currentTime(); + TQTimeEdit *timeEdit = new TQTimeEdit( timeNow, this ); + timeEdit->setRange( timeNow, timeNow.addSecs( 60 * 60 ) ); + \endcode + Here we've created a TQTimeEdit widget set to the current time. + We've also set the minimum value to the current time and the + maximum time to one hour from now. + + The maximum and minimum values for a time value in the time editor + default to the maximum and minimum values for a TQTime. You can + change this by calling setMinValue(), setMaxValue() or setRange(). + + Terminology: A TQTimeWidget consists of three sections, one each + for the hour, minute and second. You can change the separator + character using setSeparator(), by default the separator is read + from the system's settings. + + \img datetimewidgets.png Date Time Widgets + + \sa TQTime TQDateEdit TQDateTimeEdit +*/ + + +/*! + Constructs an empty time edit with parent \a parent and called \a + name. +*/ + +TQTimeEdit::TQTimeEdit( TQWidget * parent, const char * name ) + : TQDateTimeEditBase( parent, name ) +{ + init(); +} + +/*! + \overload + + Constructs a time edit with the initial time value, \a time, + parent \a parent and called \a name. +*/ + +TQTimeEdit::TQTimeEdit( const TQTime& time, TQWidget * parent, const char * name ) + : TQDateTimeEditBase( parent, name ) +{ + init(); + setTime( time ); +} + +/*! \internal + */ + +void TQTimeEdit::init() +{ + d = new TQTimeEditPrivate(); + d->controls = new TQDateTimeSpinWidget( this, qstrcmp( name(), "qt_datetime_timeedit" ) == 0 ? "qt_spin_widget" : "time edit controls" ); + d->ed = new TQDateTimeEditor( this, d->controls, "time edit base" ); + d->controls->setEditWidget( d->ed ); + setFocusProxy( d->ed ); + connect( d->controls, TQ_SIGNAL( stepUpPressed() ), TQ_SLOT( stepUp() ) ); + connect( d->controls, TQ_SIGNAL( stepDownPressed() ), TQ_SLOT( stepDown() ) ); + + d->ed->appendSection( TQNumberSection( 0,0, TRUE, 0 ) ); + d->ed->appendSection( TQNumberSection( 0,0, TRUE, 1 ) ); + d->ed->appendSection( TQNumberSection( 0,0, TRUE, 2 ) ); + d->ed->setSeparator( localTimeSep() ); + + d->h = 0; + d->m = 0; + d->s = 0; + d->display = Hours | Minutes | Seconds; + if ( lAMPM ) { + d->display |= AMPM; + d->ed->appendSection( TQNumberSection( 0,0, FALSE, 3 ) ); + } + d->adv = FALSE; + d->overwrite = TRUE; + d->timerId = 0; + d->typing = FALSE; + d->min = TQTime( 0, 0, 0 ); + d->max = TQTime( 23, 59, 59 ); + d->changed = FALSE; + + setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ); + + refcount++; +} + +/*! + Destroys the object and frees any allocated resources. +*/ + +TQTimeEdit::~TQTimeEdit() +{ + delete d; + if ( !--refcount ) + cleanup(); +} + +/*! + \property TQTimeEdit::minValue + \brief the minimum time value + + Setting the minimum time value is equivalent to calling + TQTimeEdit::setRange( \e t, maxValue() ), where \e t is the minimum + time. The default minimum time is 00:00:00. + + \sa maxValue setRange() +*/ + +TQTime TQTimeEdit::minValue() const +{ + return d->min; +} + +/*! + \property TQTimeEdit::maxValue + \brief the maximum time value + + Setting the maximum time value is equivalent to calling + TQTimeEdit::setRange( minValue(), \e t ), where \e t is the maximum + time. The default maximum time is 23:59:59. + + \sa minValue setRange() +*/ + +TQTime TQTimeEdit::maxValue() const +{ + return d->max; +} + + +/*! + Sets the valid input range for the editor to be from \a min to \a + max inclusive. If \a min is invalid no minimum time is set. + Similarly, if \a max is invalid no maximum time is set. +*/ + +void TQTimeEdit::setRange( const TQTime& min, const TQTime& max ) +{ + if ( min.isValid() ) + d->min = min; + if ( max.isValid() ) + d->max = max; +} + +/*! + \property TQTimeEdit::display + \brief the sections that are displayed in the time edit + + The value can be any combination of the values in the Display enum. + By default, the widget displays hours, minutes and seconds. +*/ +void TQTimeEdit::setDisplay( uint display ) +{ + if ( d->display == display ) + return; + + d->ed->clearSections(); + d->display = display; + if ( d->display & Hours ) + d->ed->appendSection( TQNumberSection( 0,0, TRUE, 0 ) ); + if ( d->display & Minutes ) + d->ed->appendSection( TQNumberSection( 0,0, TRUE, 1 ) ); + if ( d->display & Seconds ) + d->ed->appendSection( TQNumberSection( 0,0, TRUE, 2 ) ); + if ( d->display & AMPM ) + d->ed->appendSection( TQNumberSection( 0,0, FALSE, 3 ) ); + + d->ed->setFocusSection( 0 ); + d->ed->update(); +} + +uint TQTimeEdit::display() const +{ + return d->display; +} + +/*! + \property TQTimeEdit::time + \brief the editor's time value. + + When changing the time property, if the time is less than + minValue(), or is greater than maxValue(), nothing happens. +*/ + +void TQTimeEdit::setTime( const TQTime& time ) +{ + if ( !time.isValid() ) { + d->h = 0; + d->m = 0; + d->s = 0; + } else { + if ( time > maxValue() || time < minValue() ) + return; + d->h = time.hour(); + d->m = time.minute(); + d->s = time.second(); + emit valueChanged( time ); + } + d->changed = FALSE; + d->ed->repaint( d->ed->rect(), FALSE ); +} + +TQTime TQTimeEdit::time() const +{ + if ( TQTime::isValid( d->h, d->m, d->s ) ) + return TQTime( d->h, d->m, d->s ); + return TQTime(); +} + +/*! + \property TQTimeEdit::autoAdvance + \brief whether the editor automatically advances to the next + section + + If autoAdvance is TRUE, the editor will automatically advance + focus to the next time section if a user has completed a section. + The default is FALSE. +*/ + +void TQTimeEdit::setAutoAdvance( bool advance ) +{ + d->adv = advance; +} + +bool TQTimeEdit::autoAdvance() const +{ + return d->adv; +} + +/*! + Sets the separator to \a s. Note that currently only the first + character of \a s is used. +*/ + +void TQTimeEdit::setSeparator( const TQString& s ) +{ + d->ed->setSeparator( s ); +} + +/*! + Returns the editor's separator. +*/ + +TQString TQTimeEdit::separator() const +{ + return d->ed->separator(); +} + + +/*! + \fn void TQTimeEdit::valueChanged( const TQTime& time ) + + This signal is emitted whenever the editor's value changes. The \a + time parameter is the new value. +*/ + +/*! \reimp + +*/ + +bool TQTimeEdit::event( TQEvent *e ) +{ + if ( e->type() == TQEvent::FocusOut ) { + d->typing = FALSE; + if ( d->changed ) { + emit valueChanged( time() ); + d->changed = FALSE; + } + } else if ( e->type() == TQEvent::LocaleChange ) { + readLocaleSettings(); + d->ed->setSeparator( localTimeSep() ); + } + return TQDateTimeEditBase::event( e ); +} + +/*! \reimp + +*/ + +void TQTimeEdit::timerEvent( TQTimerEvent * ) +{ + d->overwrite = TRUE; +} + + +/*! \reimp + +*/ + +void TQTimeEdit::stepUp() +{ + if (minValue() > maxValue()) { + return; + } + int sec = d->ed->mapSection( d->ed->focusSection() ); + bool accepted = TRUE; + switch( sec ) { + case 0: + do { + d->h = (d->h + 1) % 24; + } while (outOfRange(d->h, d->m, d->s)); + break; + case 1: + do { + d->m = (d->m + 1) % 60; + } while (outOfRange(d->h, d->m, d->s)); + break; + case 2: + do { + d->s = (d->s + 1) % 60; + } while (outOfRange(d->h, d->m, d->s)); + break; + case 3: + if ( d->h < 12 ) + setHour( d->h+12 ); + else + setHour( d->h-12 ); + break; + default: + accepted = FALSE; +#ifdef QT_CHECK_RANGE + tqWarning( "TQTimeEdit::stepUp: Focus section out of range!" ); +#endif + break; + } + if ( accepted ) { + d->changed = FALSE; + emit valueChanged( time() ); + } + d->ed->repaint( d->ed->rect(), FALSE ); +} + + +/*! \reimp + +*/ + +void TQTimeEdit::stepDown() +{ + if (minValue() > maxValue()) { + return; + } + + int sec = d->ed->mapSection( d->ed->focusSection() ); + bool accepted = TRUE; + switch( sec ) { + case 0: + do { + if (--d->h < 0) + d->h = 23; + } while (outOfRange(d->h, d->m, d->s)); + break; + case 1: + do { + if (--d->m < 0) + d->m = 59; + } while (outOfRange(d->h, d->m, d->s)); + break; + case 2: + do { + if (--d->s < 0) + d->s = 59; + } while (outOfRange(d->h, d->m, d->s)); + break; + case 3: + if ( d->h > 11 ) + setHour( d->h-12 ); + else + setHour( d->h+12 ); + break; + default: + accepted = FALSE; +#ifdef QT_CHECK_RANGE + tqWarning( "TQTimeEdit::stepDown: Focus section out of range!" ); +#endif + break; + } + if ( accepted ) { + d->changed = FALSE; + emit valueChanged( time() ); + } + d->ed->repaint( d->ed->rect(), FALSE ); +} + + +/*! + Returns the formatted number for section \a sec. This will + correspond to either the hour, minute or second section, depending + on \a sec. +*/ + +TQString TQTimeEdit::sectionFormattedText( int sec ) +{ + TQString txt; + txt = sectionText( sec ); + txt = txt.rightJustify( 2, TQDATETIMEEDIT_HIDDEN_CHAR ); + int offset = sec*2+sec*separator().length() + txt.length(); + if ( d->typing && sec == d->ed->focusSection() ) + d->ed->setSectionSelection( sec, offset - txt.length(), offset ); + else + d->ed->setSectionSelection( sec, offset - txt.length(), offset ); + + return txt; +} + + +/*! \reimp + +*/ + +bool TQTimeEdit::setFocusSection( int sec ) +{ + if ( sec != d->ed->focusSection() ) { + killTimer( d->timerId ); + d->overwrite = TRUE; + d->typing = FALSE; + TQString txt = sectionText( sec ); + txt = txt.rightJustify( 2, TQDATETIMEEDIT_HIDDEN_CHAR ); + int offset = sec*2+sec*separator().length() + txt.length(); + d->ed->setSectionSelection( sec, offset - txt.length(), offset ); + if ( d->changed ) { + emit valueChanged( time() ); + d->changed = FALSE; + } + } + return d->ed->setFocusSection( sec ); +} + + +/*! + Sets the hour to \a h, which must be a valid hour, i.e. in the + range 0..24. +*/ + +void TQTimeEdit::setHour( int h ) +{ + if ( h < 0 ) + h = 0; + if ( h > 23 ) + h = 23; + d->h = h; +} + + +/*! + Sets the minute to \a m, which must be a valid minute, i.e. in the + range 0..59. +*/ + +void TQTimeEdit::setMinute( int m ) +{ + if ( m < 0 ) + m = 0; + if ( m > 59 ) + m = 59; + d->m = m; +} + + +/*! + Sets the second to \a s, which must be a valid second, i.e. in the + range 0..59. +*/ + +void TQTimeEdit::setSecond( int s ) +{ + if ( s < 0 ) + s = 0; + if ( s > 59 ) + s = 59; + d->s = s; +} + + +/*! \internal + + Returns the text of section \a sec. + +*/ + +TQString TQTimeEdit::sectionText( int sec ) +{ + sec = d->ed->mapSection( sec ); + + TQString txt; + switch( sec ) { + case 0: + if ( !(d->display & AMPM) || ( d->h < 13 && d->h ) ) { // I wished the day stared at 0:00 for everybody + txt = TQString::number( d->h ); + } else { + if ( d->h ) + txt = TQString::number( d->h - 12 ); + else + txt = "12"; + } + break; + case 1: + txt = TQString::number( d->m ); + break; + case 2: + txt = TQString::number( d->s ); + break; + case 3: + if ( d->h < 12 ) { + if ( lAM ) + txt = *lAM; + else + txt = TQString::fromLatin1( "AM" ); + } else { + if ( lPM ) + txt = *lPM; + else + txt = TQString::fromLatin1( "PM" ); + } + break; + default: + break; + } + return txt; +} + + +/*! \internal + Returns TRUE if \a h, \a m, and \a s are out of range. + */ + +bool TQTimeEdit::outOfRange( int h, int m, int s ) const +{ + if ( TQTime::isValid( h, m, s ) ) { + TQTime currentTime( h, m, s ); + if ( currentTime > maxValue() || + currentTime < minValue() ) + return TRUE; + else + return FALSE; + } + return TRUE; +} + +/*! \reimp + +*/ + +void TQTimeEdit::addNumber( int sec, int num ) +{ + if ( sec == -1 ) + return; + sec = d->ed->mapSection( sec ); + killTimer( d->timerId ); + bool overwrite = FALSE; + bool accepted = FALSE; + d->typing = TRUE; + TQString txt; + + switch( sec ) { + case 0: + txt = ( d->display & AMPM && d->h > 12 ) ? + TQString::number( d->h - 12 ) : TQString::number( d->h ); + + if ( d->overwrite || txt.length() == 2 ) { + if ( d->display & AMPM && num == 0 ) + break; // Don't process 0 in 12 hour clock mode + if ( d->display & AMPM && d->h > 11 ) + num += 12; + if ( !outOfRange( num, d->m, d->s ) ) { + accepted = TRUE; + d->h = num; + } + } else { + txt += TQString::number( num ); + int temp = txt.toInt(); + + if ( d->display & AMPM ) { + if ( temp == 12 ) { + if ( d->h < 12 ) { + temp = 0; + } + accepted = TRUE; + } else if ( outOfRange( temp + 12, d->m, d->s ) ) { + txt = TQString::number( d->h ); + } else { + if ( d->h > 11 ) { + temp += 12; + } + accepted = TRUE; + } + } else if ( !(d->display & AMPM) && outOfRange( temp, d->m, d->s ) ) { + txt = TQString::number( d->h ); + } else { + accepted = TRUE; + } + + if ( accepted ) + d->h = temp; + + if ( d->adv && txt.length() == 2 ) { + setFocusSection( d->ed->focusSection()+1 ); + overwrite = TRUE; + } + } + break; + + case 1: + txt = TQString::number( d->m ); + if ( d->overwrite || txt.length() == 2 ) { + if ( !outOfRange( d->h, num, d->s ) ) { + accepted = TRUE; + d->m = num; + } + } else { + txt += TQString::number( num ); + int temp = txt.toInt(); + if ( temp > 59 ) + temp = num; + if ( outOfRange( d->h, temp, d->s ) ) + txt = TQString::number( d->m ); + else { + accepted = TRUE; + d->m = temp; + } + if ( d->adv && txt.length() == 2 ) { + setFocusSection( d->ed->focusSection()+1 ); + overwrite = TRUE; + } + } + break; + + case 2: + txt = TQString::number( d->s ); + if ( d->overwrite || txt.length() == 2 ) { + if ( !outOfRange( d->h, d->m, num ) ) { + accepted = TRUE; + d->s = num; + } + } else { + txt += TQString::number( num ); + int temp = txt.toInt(); + if ( temp > 59 ) + temp = num; + if ( outOfRange( d->h, d->m, temp ) ) + txt = TQString::number( d->s ); + else { + accepted = TRUE; + d->s = temp; + } + if ( d->adv && txt.length() == 2 ) { + setFocusSection( d->ed->focusSection()+1 ); + overwrite = TRUE; + } + } + break; + + case 3: + break; + + default: + break; + } + d->changed = !accepted; + if ( accepted ) + emit valueChanged( time() ); + d->overwrite = overwrite; + d->timerId = startTimer( tqApp->doubleClickInterval()*4 ); + d->ed->repaint( d->ed->rect(), FALSE ); +} + + +/*! + \internal + + Function which is called whenever the user tries to + remove the first number from \a sec by pressing the backspace key. +*/ + +void TQTimeEdit::removeFirstNumber( int sec ) +{ + if ( sec == -1 ) + return; + sec = d->ed->mapSection( sec ); + TQString txt; + switch( sec ) { + case 0: + txt = TQString::number( d->h ); + break; + case 1: + txt = TQString::number( d->m ); + break; + case 2: + txt = TQString::number( d->s ); + break; + } + txt = txt.mid( 1, txt.length() ) + "0"; + switch( sec ) { + case 0: + d->h = txt.toInt(); + break; + case 1: + d->m = txt.toInt(); + break; + case 2: + d->s = txt.toInt(); + break; + } + d->ed->repaint( d->ed->rect(), FALSE ); +} + +/*! \reimp + +*/ +void TQTimeEdit::removeLastNumber( int sec ) +{ + if ( sec == -1 ) + return; + sec = d->ed->mapSection( sec ); + TQString txt; + switch( sec ) { + case 0: + txt = TQString::number( d->h ); + break; + case 1: + txt = TQString::number( d->m ); + break; + case 2: + txt = TQString::number( d->s ); + break; + } + txt = txt.mid( 0, txt.length()-1 ); + switch( sec ) { + case 0: + d->h = txt.toInt(); + break; + case 1: + d->m = txt.toInt(); + break; + case 2: + d->s = txt.toInt(); + break; + } + d->ed->repaint( d->ed->rect(), FALSE ); +} + +/*! \reimp + */ +void TQTimeEdit::resizeEvent( TQResizeEvent * ) +{ + d->controls->resize( width(), height() ); +} + +/*! \reimp +*/ +TQSize TQTimeEdit::sizeHint() const +{ + constPolish(); + TQFontMetrics fm( font() ); + int fw = style().pixelMetric( TQStyle::PM_DefaultFrameWidth, this ); + int h = fm.lineSpacing() + 2; + int w = 2 + fm.width( '9' ) * 6 + fm.width( d->ed->separator() ) * 2 + + d->controls->upRect().width() + fw * 4; + if ( d->display & AMPM ) { + if ( lAM ) + w += fm.width( *lAM ) + 4; + else + w += fm.width( TQString::fromLatin1( "AM" ) ) + 4; + } + + return TQSize( w, TQMAX(h + fw * 2,20) ).expandedTo( TQApplication::globalStrut() ); +} + +/*! \reimp +*/ +TQSize TQTimeEdit::minimumSizeHint() const +{ + return sizeHint(); +} + +/*! + \internal + Enables/disables the push buttons according to the min/max time + for this widget. +*/ + +// ### Remove in 4.0? + +void TQTimeEdit::updateButtons() +{ + if ( !isEnabled() ) + return; + + bool upEnabled = time() < maxValue(); + bool downEnabled = time() > minValue(); + + d->controls->setUpEnabled( upEnabled ); + d->controls->setDownEnabled( downEnabled ); +} + + +class TQDateTimeEditPrivate +{ +public: + bool adv; +}; + +/*! + \class TQDateTimeEdit tqdatetimeedit.h + \brief The TQDateTimeEdit class combines a TQDateEdit and TQTimeEdit + widget into a single widget for editing datetimes. + + \ingroup advanced + \ingroup time + \mainclass + + TQDateTimeEdit consists of a TQDateEdit and TQTimeEdit widget placed + side by side and offers the functionality of both. The user can + edit the date and time by using the keyboard or the arrow keys to + increase/decrease date or time values. The Tab key can be used to + move from section to section within the TQDateTimeEdit widget, and + the user can be moved automatically when they complete a section + using setAutoAdvance(). The datetime can be set with + setDateTime(). + + The date format is read from the system's locale settings. It is + set to year, month, day order if that is not possible. See + TQDateEdit::setOrder() to change this. Times appear in the order + hours, minutes, seconds using the 24 hour clock. + + It is recommended that the TQDateTimeEdit is initialised with a + datetime, e.g. + \code + TQDateTimeEdit *dateTimeEdit = new TQDateTimeEdit( TQDateTime::currentDateTime(), this ); + dateTimeEdit->dateEdit()->setRange( TQDateTime::currentDate(), + TQDateTime::currentDate().addDays( 7 ) ); + \endcode + Here we've created a new TQDateTimeEdit set to the current date and + time, and set the date to have a minimum date of now and a maximum + date of a week from now. + + Terminology: A TQDateEdit widget consists of three 'sections', one + each for the year, month and day. Similarly a TQTimeEdit consists + of three sections, one each for the hour, minute and second. The + character that separates each date section is specified with + setDateSeparator(); similarly setTimeSeparator() is used for the + time sections. + + \img datetimewidgets.png Date Time Widgets + + \sa TQDateEdit TQTimeEdit +*/ + +/*! + Constructs an empty datetime edit with parent \a parent and called + \a name. +*/ +TQDateTimeEdit::TQDateTimeEdit( TQWidget * parent, const char * name ) + : TQWidget( parent, name ) +{ + init(); +} + + +/*! + \overload + + Constructs a datetime edit with the initial value \a datetime, + parent \a parent and called \a name. +*/ +TQDateTimeEdit::TQDateTimeEdit( const TQDateTime& datetime, + TQWidget * parent, const char * name ) + : TQWidget( parent, name ) +{ + init(); + setDateTime( datetime ); +} + + + +/*! + Destroys the object and frees any allocated resources. +*/ + +TQDateTimeEdit::~TQDateTimeEdit() +{ + delete d; +} + + +/*! + \reimp + + Intercepts and handles resize events which have special meaning + for the TQDateTimeEdit. +*/ + +void TQDateTimeEdit::resizeEvent( TQResizeEvent * ) +{ + int dw = de->sizeHint().width(); + int tw = te->sizeHint().width(); + int w = width(); + int h = height(); + int extra = w - ( dw + tw ); + + if ( tw + extra < 0 ) { + dw = w; + } else { + dw += 9 * extra / 16; + } + tw = w - dw; + + de->setGeometry( 0, 0, dw, h ); + te->setGeometry( dw, 0, tw, h ); +} + +/*! \reimp +*/ + +TQSize TQDateTimeEdit::minimumSizeHint() const +{ + TQSize dsh = de->minimumSizeHint(); + TQSize tsh = te->minimumSizeHint(); + return TQSize( dsh.width() + tsh.width(), + TQMAX( dsh.height(), tsh.height() ) ); +} + +/*! \internal + */ + +void TQDateTimeEdit::init() +{ + d = new TQDateTimeEditPrivate(); + de = new TQDateEdit( this, "qt_datetime_dateedit" ); + te = new TQTimeEdit( this, "qt_datetime_timeedit" ); + d->adv = FALSE; + connect( de, TQ_SIGNAL( valueChanged(const TQDate&) ), + this, TQ_SLOT( newValue(const TQDate&) ) ); + connect( te, TQ_SIGNAL( valueChanged(const TQTime&) ), + this, TQ_SLOT( newValue(const TQTime&) ) ); + setFocusProxy( de ); + setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ); +} + +/*! \reimp + */ + +TQSize TQDateTimeEdit::sizeHint() const +{ + constPolish(); + TQSize dsh = de->sizeHint(); + TQSize tsh = te->sizeHint(); + return TQSize( dsh.width() + tsh.width(), + TQMAX( dsh.height(), tsh.height() ) ); +} + +/*! + \property TQDateTimeEdit::dateTime + \brief the editor's datetime value + + The datetime edit's datetime which may be an invalid datetime. +*/ + +void TQDateTimeEdit::setDateTime( const TQDateTime & dt ) +{ + if ( dt.isValid() ) { + de->setDate( dt.date() ); + te->setTime( dt.time() ); + emit valueChanged( dt ); + } +} + +TQDateTime TQDateTimeEdit::dateTime() const +{ + return TQDateTime( de->date(), te->time() ); +} + +/*! + \fn void TQDateTimeEdit::valueChanged( const TQDateTime& datetime ) + + This signal is emitted every time the date or time changes. The \a + datetime argument is the new datetime. +*/ + + +/*! \internal + + Re-emits the value \a d. + */ + +void TQDateTimeEdit::newValue( const TQDate& ) +{ + TQDateTime dt = dateTime(); + emit valueChanged( dt ); +} + +/*! \internal + \overload + Re-emits the value \a t. + */ + +void TQDateTimeEdit::newValue( const TQTime& ) +{ + TQDateTime dt = dateTime(); + emit valueChanged( dt ); +} + + +/*! + Sets the auto advance property of the editor to \a advance. If set + to TRUE, the editor will automatically advance focus to the next + date or time section if the user has completed a section. +*/ + +void TQDateTimeEdit::setAutoAdvance( bool advance ) +{ + de->setAutoAdvance( advance ); + te->setAutoAdvance( advance ); +} + +/*! + Returns TRUE if auto-advance is enabled, otherwise returns FALSE. + + \sa setAutoAdvance() +*/ + +bool TQDateTimeEdit::autoAdvance() const +{ + return de->autoAdvance(); +} + +/*! + \fn TQDateEdit* TQDateTimeEdit::dateEdit() + + Returns the internal widget used for editing the date part of the + datetime. +*/ + +/*! + \fn TQTimeEdit* TQDateTimeEdit::timeEdit() + + Returns the internal widget used for editing the time part of the + datetime. +*/ + +#include "tqdatetimeedit.moc" + +#endif diff --git a/src/widgets/tqdatetimeedit.h b/src/widgets/tqdatetimeedit.h new file mode 100644 index 000000000..334e24d56 --- /dev/null +++ b/src/widgets/tqdatetimeedit.h @@ -0,0 +1,293 @@ +/**************************************************************************** +** +** Definition of date and time edit classes +** +** Created : 001103 +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQDATETIMEEDIT_H +#define TQDATETIMEEDIT_H + +#ifndef QT_H +#include "tqwidget.h" +#include "tqstring.h" +#include "tqdatetime.h" +#endif // QT_H + +#ifndef TQT_NO_DATETIMEEDIT + +class TQ_EXPORT TQDateTimeEditBase : public TQWidget +{ + TQ_OBJECT +public: + TQDateTimeEditBase( TQWidget* parent=0, const char* name=0 ) + : TQWidget( parent, name ) {} + + virtual bool setFocusSection( int sec ) = 0; + virtual TQString sectionFormattedText( int sec ) = 0; + virtual void addNumber( int sec, int num ) = 0; + virtual void removeLastNumber( int sec ) = 0; + +public slots: + virtual void stepUp() = 0; + virtual void stepDown() = 0; + +private: +#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= + TQDateTimeEditBase( const TQDateTimeEditBase & ); + TQDateTimeEditBase &operator=( const TQDateTimeEditBase & ); +#endif +}; + +class TQDateEditPrivate; + +class TQ_EXPORT TQDateEdit : public TQDateTimeEditBase +{ + TQ_OBJECT + TQ_ENUMS( Order ) + TQ_PROPERTY( Order order READ order WRITE setOrder ) + TQ_PROPERTY( TQDate date READ date WRITE setDate ) + TQ_PROPERTY( bool autoAdvance READ autoAdvance WRITE setAutoAdvance ) + TQ_PROPERTY( TQDate maxValue READ maxValue WRITE setMaxValue ) + TQ_PROPERTY( TQDate minValue READ minValue WRITE setMinValue ) + +public: + TQDateEdit( TQWidget* parent=0, const char* name=0 ); + TQDateEdit( const TQDate& date, TQWidget* parent=0, const char* name=0 ); + ~TQDateEdit(); + + enum Order { DMY, MDY, YMD, YDM }; + + TQSize sizeHint() const; + TQSize minimumSizeHint() const; + +public slots: + virtual void setDate( const TQDate& date ); + +public: + TQDate date() const; + virtual void setOrder( Order order ); + Order order() const; + virtual void setAutoAdvance( bool advance ); + bool autoAdvance() const; + + virtual void setMinValue( const TQDate& d ) { setRange( d, maxValue() ); } + TQDate minValue() const; + virtual void setMaxValue( const TQDate& d ) { setRange( minValue(), d ); } + TQDate maxValue() const; + virtual void setRange( const TQDate& min, const TQDate& max ); + TQString separator() const; + virtual void setSeparator( const TQString& s ); + + // Make removeFirstNumber() virtual in TQDateTimeEditBase in 4.0 + void removeFirstNumber( int sec ); + +signals: + void valueChanged( const TQDate& date ); + +protected: + bool event( TQEvent *e ); + void timerEvent( TQTimerEvent * ); + void resizeEvent( TQResizeEvent * ); + void stepUp(); + void stepDown(); + TQString sectionFormattedText( int sec ); + void addNumber( int sec, int num ); + + void removeLastNumber( int sec ); + bool setFocusSection( int s ); + + virtual void setYear( int year ); + virtual void setMonth( int month ); + virtual void setDay( int day ); + virtual void fix(); + virtual bool outOfRange( int y, int m, int d ) const; + +protected slots: + void updateButtons(); + +private: + void init(); + int sectionOffsetEnd( int sec ) const; + int sectionLength( int sec ) const; + TQString sectionText( int sec ) const; + TQDateEditPrivate* d; + +#if defined(TQ_DISABLE_COPY) + TQDateEdit( const TQDateEdit & ); + TQDateEdit &operator=( const TQDateEdit & ); +#endif +}; + +class TQTimeEditPrivate; + +class TQ_EXPORT TQTimeEdit : public TQDateTimeEditBase +{ + TQ_OBJECT + TQ_SETS( Display ) + TQ_PROPERTY( TQTime time READ time WRITE setTime ) + TQ_PROPERTY( bool autoAdvance READ autoAdvance WRITE setAutoAdvance ) + TQ_PROPERTY( TQTime maxValue READ maxValue WRITE setMaxValue ) + TQ_PROPERTY( TQTime minValue READ minValue WRITE setMinValue ) + TQ_PROPERTY( Display display READ display WRITE setDisplay ) + +public: + enum Display { + Hours = 0x01, + Minutes = 0x02, + Seconds = 0x04, + /*Reserved = 0x08,*/ + AMPM = 0x10 + }; + + TQTimeEdit( TQWidget* parent=0, const char* name=0 ); + TQTimeEdit( const TQTime& time, TQWidget* parent=0, const char* name=0 ); + ~TQTimeEdit(); + + TQSize sizeHint() const; + TQSize minimumSizeHint() const; + +public slots: + virtual void setTime( const TQTime& time ); + +public: + TQTime time() const; + virtual void setAutoAdvance( bool advance ); + bool autoAdvance() const; + + virtual void setMinValue( const TQTime& d ) { setRange( d, maxValue() ); } + TQTime minValue() const; + virtual void setMaxValue( const TQTime& d ) { setRange( minValue(), d ); } + TQTime maxValue() const; + virtual void setRange( const TQTime& min, const TQTime& max ); + TQString separator() const; + virtual void setSeparator( const TQString& s ); + + uint display() const; + void setDisplay( uint disp ); + + // Make removeFirstNumber() virtual in TQDateTimeEditBase in 4.0 + void removeFirstNumber( int sec ); + +signals: + void valueChanged( const TQTime& time ); + +protected: + bool event( TQEvent *e ); + void timerEvent( TQTimerEvent *e ); + void resizeEvent( TQResizeEvent * ); + void stepUp(); + void stepDown(); + TQString sectionFormattedText( int sec ); + void addNumber( int sec, int num ); + void removeLastNumber( int sec ); + bool setFocusSection( int s ); + + virtual bool outOfRange( int h, int m, int s ) const; + virtual void setHour( int h ); + virtual void setMinute( int m ); + virtual void setSecond( int s ); + +protected slots: + void updateButtons(); + +private: + void init(); + TQString sectionText( int sec ); + TQTimeEditPrivate* d; + +#if defined(TQ_DISABLE_COPY) + TQTimeEdit( const TQTimeEdit & ); + TQTimeEdit &operator=( const TQTimeEdit & ); +#endif +}; + + +class TQDateTimeEditPrivate; + +class TQ_EXPORT TQDateTimeEdit : public TQWidget +{ + TQ_OBJECT + TQ_PROPERTY( TQDateTime dateTime READ dateTime WRITE setDateTime ) + +public: + TQDateTimeEdit( TQWidget* parent=0, const char* name=0 ); + TQDateTimeEdit( const TQDateTime& datetime, TQWidget* parent=0, + const char* name=0 ); + ~TQDateTimeEdit(); + + TQSize sizeHint() const; + TQSize minimumSizeHint() const; + +public slots: + virtual void setDateTime( const TQDateTime & dt ); + +public: + TQDateTime dateTime() const; + + TQDateEdit* dateEdit() { return de; } + TQTimeEdit* timeEdit() { return te; } + + virtual void setAutoAdvance( bool advance ); + bool autoAdvance() const; + +signals: + void valueChanged( const TQDateTime& datetime ); + +protected: + // ### make init() private in TQt 4.0 + void init(); + void resizeEvent( TQResizeEvent * ); + +protected slots: + // ### make these two functions private in TQt 4.0, + // and merge them into one with no parameter + void newValue( const TQDate& d ); + void newValue( const TQTime& t ); + +private: + TQDateEdit* de; + TQTimeEdit* te; + TQDateTimeEditPrivate* d; + +#if defined(TQ_DISABLE_COPY) + TQDateTimeEdit( const TQDateTimeEdit & ); + TQDateTimeEdit &operator=( const TQDateTimeEdit & ); +#endif +}; + +#endif +#endif diff --git a/src/widgets/tqiconview.cpp b/src/widgets/tqiconview.cpp index 292086428..2a76b53d6 100644 --- a/src/widgets/tqiconview.cpp +++ b/src/widgets/tqiconview.cpp @@ -56,7 +56,7 @@ #include "tqimage.h" #include "ntqpen.h" #include "ntqbrush.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqcursor.h" #include "ntqapplication.h" #include "tqtextedit.h" diff --git a/src/widgets/tqtextbrowser.cpp b/src/widgets/tqtextbrowser.cpp index dfafb32c8..d28543409 100644 --- a/src/widgets/tqtextbrowser.cpp +++ b/src/widgets/tqtextbrowser.cpp @@ -52,7 +52,7 @@ #include "tqtextstream.h" #include "ntqlayout.h" #include "ntqbitmap.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "tqimage.h" #include "ntqsimplerichtext.h" #include "ntqdragobject.h" diff --git a/src/widgets/tqtextedit.cpp b/src/widgets/tqtextedit.cpp index 33307e4b8..6d48be52b 100644 --- a/src/widgets/tqtextedit.cpp +++ b/src/widgets/tqtextedit.cpp @@ -57,7 +57,7 @@ #include "tqstyle.h" #include "ntqsize.h" #include "ntqevent.h" -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqapplication.h" #include "ntqlistbox.h" #include "ntqvbox.h" diff --git a/src/workspace/qworkspace.cpp b/src/workspace/qworkspace.cpp index e7f8381d1..d267177c8 100644 --- a/src/workspace/qworkspace.cpp +++ b/src/workspace/qworkspace.cpp @@ -55,7 +55,7 @@ #include "tqiconset.h" #include "../widgets/tqwidgetresizehandler_p.h" #include "ntqfocusdata.h" -#include "ntqdatetime.h" +#include "tqdatetime.h" #include "ntqtooltip.h" #include "ntqwmatrix.h" #include "tqimage.h" @@ -64,7 +64,7 @@ #include "ntqbitmap.h" // magic non-mdi things -#include "ntqtimer.h" +#include "tqtimer.h" #include "ntqdockarea.h" #include "ntqstatusbar.h" #include "ntqmainwindow.h" -- cgit v1.2.3