1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 1997-04-21
7  * Description : Date selection table.
8  *
9  * Copyright (C) 2011-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 1997      by Tim D. Gilman <tdgilman at best dot org>
11  * Copyright (C) 1998-2001 by Mirko Boehm <mirko at kde dot org>
12  * Copyright (C) 2007      by John Layt <john at layt dot net>
13  *
14  * This program is free software; you can redistribute it
15  * and/or modify it under the terms of the GNU General
16  * Public License as published by the Free Software Foundation;
17  * either version 2, or (at your option)
18  * any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * ============================================================ */
26 
27 #include "ddatetable_p.h"
28 
29 // C++ includes
30 
31 #include <cmath>
32 
33 // Qt includes
34 
35 #include <QAction>
36 #include <QFontDatabase>
37 #include <QPainter>
38 #include <QStyle>
39 #include <QStyleOptionViewItem>
40 #include <QActionEvent>
41 #include <QApplication>
42 #include <QMenu>
43 
44 namespace Digikam
45 {
46 
Private(DDateTable * const qq)47 DDateTable::Private::Private(DDateTable* const qq)
48     : QObject               (qq),
49       q                     (qq),
50       weekDayFirstOfMonth   (0),
51       numDaysThisMonth      (0),
52       numWeekRows           (0),
53       numDayColumns         (0),
54       fontsize              (0),
55       popupMenuEnabled      (false),
56       useCustomColors       (false),
57       hoveredPos            (-1)
58 {
59     setDate(QDate::currentDate());
60 }
61 
~Private()62 DDateTable::Private::~Private()
63 {
64 }
65 
nextMonth()66 void DDateTable::Private::nextMonth()
67 {
68     // setDate does validity checking for us
69 
70     q->setDate(date.addMonths(1));
71 }
72 
previousMonth()73 void DDateTable::Private::previousMonth()
74 {
75     // setDate does validity checking for us
76 
77     q->setDate(date.addMonths(-1));
78 }
79 
beginningOfMonth()80 void DDateTable::Private::beginningOfMonth()
81 {
82     // setDate does validity checking for us
83 
84     q->setDate(QDate(date.year(), date.month(), 1));
85 }
86 
endOfMonth()87 void DDateTable::Private::endOfMonth()
88 {
89     // setDate does validity checking for us
90 
91     q->setDate(QDate(date.year(), date.month() + 1, 0));
92 }
93 
94 
beginningOfWeek()95 void DDateTable::Private::beginningOfWeek()
96 {
97     // setDate does validity checking for us
98 
99     q->setDate(date.addDays(1 - date.dayOfWeek()));
100 }
101 
endOfWeek()102 void DDateTable::Private::endOfWeek()
103 {
104     // setDate does validity checking for us
105 
106     q->setDate(date.addDays(7 - date.dayOfWeek()));
107 }
108 
setDate(const QDate & dt)109 void DDateTable::Private::setDate(const QDate& dt)
110 {
111     date                = dt;
112     weekDayFirstOfMonth = QDate(date.year(), date.month(), 1).dayOfWeek();
113     numDaysThisMonth    = date.daysInMonth();
114     numDayColumns       = 7;
115 }
116 
117 } // namespace Digikam
118