diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-10-03 19:04:44 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-10-04 10:56:45 +0000 |
commit | 6eab7d10aa34b6a76cbd46a6af703d6c6fa77ca5 (patch) | |
tree | 004aa0cfa9163ed974bac982b1b879304be2446a /src/imports | |
parent | abacbbe4d2b92ebe9e488e61906ba1d36abb3ef8 (diff) |
Add Calendar singleton
Not yet super useful, as it only contains a Month enum to help with
JavaScript's zero-based months. Later on, we can add various calendar
related utility methods, such as calculating the next/prev month and
so on.
Change-Id: I7685eb931833fc0c30e2d5d4fe874d0618d054b4
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/calendar/calendar.pri | 2 | ||||
-rw-r--r-- | src/imports/calendar/qquickcalendar.cpp | 58 | ||||
-rw-r--r-- | src/imports/calendar/qquickcalendar_p.h | 84 | ||||
-rw-r--r-- | src/imports/calendar/qquickmonthgrid.cpp | 19 | ||||
-rw-r--r-- | src/imports/calendar/qquickweeknumbercolumn.cpp | 19 | ||||
-rw-r--r-- | src/imports/calendar/qtlabscalendarplugin.cpp | 9 |
6 files changed, 187 insertions, 4 deletions
diff --git a/src/imports/calendar/calendar.pri b/src/imports/calendar/calendar.pri index 78c2f1e3..00ed1209 100644 --- a/src/imports/calendar/calendar.pri +++ b/src/imports/calendar/calendar.pri @@ -4,6 +4,7 @@ QML_FILES = \ WeekNumberColumn.qml HEADERS += \ + $$PWD/qquickcalendar_p.h \ $$PWD/qquickcalendarmodel_p.h \ $$PWD/qquickdayofweekmodel_p.h \ $$PWD/qquickdayofweekrow_p.h \ @@ -13,6 +14,7 @@ HEADERS += \ $$PWD/qquickweeknumbermodel_p.h SOURCES += \ + $$PWD/qquickcalendar.cpp \ $$PWD/qquickcalendarmodel.cpp \ $$PWD/qquickdayofweekmodel.cpp \ $$PWD/qquickdayofweekrow.cpp \ diff --git a/src/imports/calendar/qquickcalendar.cpp b/src/imports/calendar/qquickcalendar.cpp new file mode 100644 index 00000000..198c4527 --- /dev/null +++ b/src/imports/calendar/qquickcalendar.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Calendar module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickcalendar_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Calendar + \inherits QObject + \instantiates QQuickCalendar + \inqmlmodule Qt.labs.calendar + \brief A calendar namespace. + + The Calendar singleton provides miscellaneous calendar related + utilities. + + \sa MonthGrid, DayOfWeekRow, WeekNumberColumn +*/ + +QQuickCalendar::QQuickCalendar(QObject *parent) : QObject(parent) +{ +} + +QT_END_NAMESPACE diff --git a/src/imports/calendar/qquickcalendar_p.h b/src/imports/calendar/qquickcalendar_p.h new file mode 100644 index 00000000..569be1d6 --- /dev/null +++ b/src/imports/calendar/qquickcalendar_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Labs Calendar module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKCALENDAR_P_H +#define QQUICKCALENDAR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qobject.h> +#include <QtCore/qdatetime.h> + +QT_BEGIN_NAMESPACE + +class QQuickCalendar : public QObject +{ + Q_OBJECT + +public: + explicit QQuickCalendar(QObject *parent = Q_NULLPTR); + + enum Month { + January, + February, + March, + April, + May, + June, + July, + August, + September, + October, + November, + December + }; + Q_ENUM(Month) +}; + +Q_DECLARE_TYPEINFO(QQuickCalendar, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKCALENDAR_P_H diff --git a/src/imports/calendar/qquickmonthgrid.cpp b/src/imports/calendar/qquickmonthgrid.cpp index 1803c1d0..d1b9d966 100644 --- a/src/imports/calendar/qquickmonthgrid.cpp +++ b/src/imports/calendar/qquickmonthgrid.cpp @@ -182,8 +182,23 @@ QQuickMonthGrid::QQuickMonthGrid(QQuickItem *parent) : This property holds the number of the month. - The value must be in the range from \c 0 (January) to \c 11 (December). The default - value is the current month. + Supported values: + \list + \li \c Calendar.January (0) + \li \c Calendar.February (1) + \li \c Calendar.March (2) + \li \c Calendar.April (3) + \li \c Calendar.May (4) + \li \c Calendar.June (5) + \li \c Calendar.July (6) + \li \c Calendar.August (7) + \li \c Calendar.September (8) + \li \c Calendar.October (9) + \li \c Calendar.November (10) + \li \c Calendar.December (11) + \endlist + + The default value is the current month. */ int QQuickMonthGrid::month() const { diff --git a/src/imports/calendar/qquickweeknumbercolumn.cpp b/src/imports/calendar/qquickweeknumbercolumn.cpp index cec8c792..a902bdae 100644 --- a/src/imports/calendar/qquickweeknumbercolumn.cpp +++ b/src/imports/calendar/qquickweeknumbercolumn.cpp @@ -110,8 +110,23 @@ QQuickWeekNumberColumn::QQuickWeekNumberColumn(QQuickItem *parent) : This property holds the number of the month that the week numbers are calculated for. - The value must be in the range from \c 0 (January) to \c 11 (December). The default - value is the current month. + Supported values: + \list + \li \c Calendar.January (0) + \li \c Calendar.February (1) + \li \c Calendar.March (2) + \li \c Calendar.April (3) + \li \c Calendar.May (4) + \li \c Calendar.June (5) + \li \c Calendar.July (6) + \li \c Calendar.August (7) + \li \c Calendar.September (8) + \li \c Calendar.October (9) + \li \c Calendar.November (10) + \li \c Calendar.December (11) + \endlist + + The default value is the current month. */ int QQuickWeekNumberColumn::month() const { diff --git a/src/imports/calendar/qtlabscalendarplugin.cpp b/src/imports/calendar/qtlabscalendarplugin.cpp index 53acf800..8d7d563d 100644 --- a/src/imports/calendar/qtlabscalendarplugin.cpp +++ b/src/imports/calendar/qtlabscalendarplugin.cpp @@ -40,6 +40,7 @@ #include "qquickmonthgrid_p.h" #include "qquickweeknumbercolumn_p.h" #include "qquickcalendarmodel_p.h" +#include "qquickcalendar_p.h" QT_BEGIN_NAMESPACE @@ -52,12 +53,20 @@ public: void registerTypes(const char *uri); }; +static QObject *calendarSingleton(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine); + Q_UNUSED(scriptEngine); + return new QQuickCalendar; +} + void QtLabsCalendarPlugin::registerTypes(const char *uri) { qmlRegisterType<QQuickDayOfWeekRow>(uri, 1, 0, "AbstractDayOfWeekRow"); qmlRegisterType<QQuickMonthGrid>(uri, 1, 0, "AbstractMonthGrid"); qmlRegisterType<QQuickWeekNumberColumn>(uri, 1, 0, "AbstractWeekNumberColumn"); qmlRegisterType<QQuickCalendarModel>(uri, 1, 0, "CalendarModel"); + qmlRegisterSingletonType<QQuickCalendar>(uri, 1, 0, "Calendar", calendarSingleton); } QT_END_NAMESPACE |