File indexing completed on 2025-01-05 03:51:07

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 1997-04-21
0007  * Description : Date selection table.
0008  *
0009  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 1997      by Tim D. Gilman <tdgilman at best dot org>
0011  * SPDX-FileCopyrightText: 1998-2001 by Mirko Boehm <mirko at kde dot org>
0012  * SPDX-FileCopyrightText: 2007      by John Layt <john at layt dot net>
0013  *
0014  * SPDX-License-Identifier: GPL-2.0-or-later
0015  *
0016  * ============================================================ */
0017 
0018 #include "ddatetable_p.h"
0019 
0020 // C++ includes
0021 
0022 
0023 // Qt includes
0024 
0025 #include <QAction>
0026 #include <QFontDatabase>
0027 #include <QPainter>
0028 #include <QStyle>
0029 #include <QStyleOptionViewItem>
0030 #include <QActionEvent>
0031 #include <QApplication>
0032 #include <QMenu>
0033 
0034 namespace Digikam
0035 {
0036 
0037 DDateTable::Private::Private(DDateTable* const qq)
0038     : QObject               (qq),
0039       q                     (qq),
0040       weekDayFirstOfMonth   (0),
0041       numDaysThisMonth      (0),
0042       numWeekRows           (0),
0043       numDayColumns         (0),
0044       fontsize              (0),
0045       popupMenuEnabled      (false),
0046       useCustomColors       (false),
0047       hoveredPos            (-1)
0048 {
0049     setDate(QDate::currentDate());
0050 }
0051 
0052 DDateTable::Private::~Private()
0053 {
0054 }
0055 
0056 void DDateTable::Private::nextMonth()
0057 {
0058     // setDate does validity checking for us
0059 
0060     q->setDate(date.addMonths(1));
0061 }
0062 
0063 void DDateTable::Private::previousMonth()
0064 {
0065     // setDate does validity checking for us
0066 
0067     q->setDate(date.addMonths(-1));
0068 }
0069 
0070 void DDateTable::Private::beginningOfMonth()
0071 {
0072     // setDate does validity checking for us
0073 
0074     q->setDate(QDate(date.year(), date.month(), 1));
0075 }
0076 
0077 void DDateTable::Private::endOfMonth()
0078 {
0079     // setDate does validity checking for us
0080 
0081     q->setDate(QDate(date.year(), date.month() + 1, 0));
0082 }
0083 
0084 
0085 void DDateTable::Private::beginningOfWeek()
0086 {
0087     // setDate does validity checking for us
0088 
0089     q->setDate(date.addDays(1 - date.dayOfWeek()));
0090 }
0091 
0092 void DDateTable::Private::endOfWeek()
0093 {
0094     // setDate does validity checking for us
0095 
0096     q->setDate(date.addDays(7 - date.dayOfWeek()));
0097 }
0098 
0099 void DDateTable::Private::setDate(const QDate& dt)
0100 {
0101     date                = dt;
0102     weekDayFirstOfMonth = QDate(date.year(), date.month(), 1).dayOfWeek();
0103     numDaysThisMonth    = date.daysInMonth();
0104     numDayColumns       = 7;
0105 }
0106 
0107 } // namespace Digikam
0108 
0109 #include "moc_ddatetable_p.cpp"