Kstars

moonphasecalendarwidget.h
1/*
2 SPDX-FileCopyrightText: 2010 Akarsh Simha <akarshsimha@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <KColorScheme>
10
11#include <QWidget>
12#include <QCalendarWidget>
13
14class KSMoon;
15class KSSun;
16class KStarsDateTime;
17
18class MoonPhaseCalendar : public QCalendarWidget
19{
21
22 public:
23 /**
24 * Constructor
25 * @param moon A reference to a (non-const) KSMoon object, that will be updated
26 * @param sun A reference to a (non-const) KSSun object, that will be updated
27 * @param parent Parent widget
28 */
29 explicit MoonPhaseCalendar(KSMoon &moon, KSSun &sun, QWidget *parent = nullptr);
30
31 ~MoonPhaseCalendar();
32
33 /** @return a suggested size for the widget */
34 virtual QSize sizeHint() const;
35
36 public slots:
37
38 /**
39 * Set the geometry of the moon phase calendar (overloaded from QWidget).
40 * Resizes the cells so as to fill the space of the calendar.
41 * @note This is called automatically by resize events.
42 * @p x the x-position of the widget
43 * @p y the y-position of the widget
44 * @p w the width of the widget
45 * @p h the height of the widget
46 */
47 virtual void setGeometry(int x, int y, int w, int h);
48
49 virtual void setGeometry(const QRect &r);
50
51 protected:
52 /**
53 * Overrides KDateTable::paintEvent() to draw moon phases on the
54 * calendar cells by calling this->paintCell()
55 * @note Most of this code is copied from KDateTable::paintEvent()
56 */
57 virtual void paintEvent(QPaintEvent *e);
58
59 /**
60 * Replaces KDateTable::paintCell() to draw moon phases on the calendar cells
61 * @note Most of this code is copied from KDateTable::paintCell()
62 */
63 void paintCell(QPainter *painter, int row, int col, const KColorScheme &colorScheme);
64
65 /**
66 * @short Loads the moon images, appropriately resized depending
67 * on the current cell size.
68 *
69 * @note This method is very slow and one must avoid calling it more than once.
70 */
71 void loadImages();
72
73 /** @short Computes the optimum moon image size */
74 void computeMoonImageSize();
75
76 private:
77 /**
78 * @short Computes the moon phase for the given date.
79 * @param date Date / Time of the computation
80 * @return the _integer_ phase for the given date
81 */
82 unsigned short computeMoonPhase(const KStarsDateTime &date);
83
84 QPixmap m_Images[36]; // Array storing moon images against integer phase
85
86 double cellWidth { 0 };
87 double cellHeight { 0 };
88 int numWeekRows { 0 };
89 int numDayColumns { 0 };
90 int MoonImageSize { 0 };
91 bool imagesLoaded { false };
92
93 KSMoon &m_Moon;
94 KSSun &m_Sun;
95};
Provides necessary information about the Moon.
Definition ksmoon.h:26
Child class of KSPlanetBase; encapsulates information about the Sun.
Definition kssun.h:24
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.