File indexing completed on 2024-11-24 04:50:39

0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <QDateTime>
0007 #include <QObject>
0008 #include <qdatetime.h>
0009 
0010 class DateTimeState : public QObject
0011 {
0012     Q_OBJECT
0013 
0014     /// This property holds the current selected date by the user
0015     Q_PROPERTY(QDateTime selectedDate MEMBER m_selectedDate NOTIFY selectedDateChanged)
0016 
0017     /// This property holds the first day of the month selected by the user
0018     Q_PROPERTY(QDateTime firstDayOfMonth READ firstDayOfMonth NOTIFY selectedDateChanged)
0019 
0020     /// This property holds the first day of the week selected by the user
0021     Q_PROPERTY(QDateTime firstDayOfWeek READ firstDayOfWeek NOTIFY selectedDateChanged)
0022 
0023     Q_PROPERTY(QDateTime currentDate MEMBER m_currentDate NOTIFY currentDateChanged)
0024 
0025 public:
0026     explicit DateTimeState(QObject *parent = nullptr);
0027 
0028     QDateTime firstDayOfMonth() const;
0029     QDateTime firstDayOfWeek() const;
0030 
0031     Q_INVOKABLE void setSelectedYearMonthDay(const int year, const int month, const int day);
0032     Q_INVOKABLE void setSelectedDay(const int day);
0033     Q_INVOKABLE void setSelectedMonth(const int month);
0034     Q_INVOKABLE void setSelectedYear(const int year);
0035 
0036     Q_INVOKABLE void selectPreviousMonth();
0037     Q_INVOKABLE void selectNextMonth();
0038 
0039     Q_INVOKABLE void addDays(const int days);
0040     Q_INVOKABLE bool isToday(const QDate &date) const;
0041 
0042     /// Reset to current time
0043     Q_INVOKABLE void resetTime();
0044 
0045 Q_SIGNALS:
0046     void selectedDateChanged();
0047     void currentDateChanged();
0048 
0049 private:
0050     QDateTime m_selectedDate;
0051     QDateTime m_currentDate;
0052 };