Kstars

moonphasecalendarwidget.h
1 /*
2  SPDX-FileCopyrightText: 2010 Akarsh Simha <[email protected]>
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 
14 class KSMoon;
15 class KSSun;
16 class KStarsDateTime;
17 
18 class MoonPhaseCalendar : public QCalendarWidget
19 {
20  Q_OBJECT
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 };
Q_OBJECTQ_OBJECT
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
virtual void paintEvent(QPaintEvent *event)
Provides necessary information about the Moon. A subclass of SkyObject that provides information need...
Definition: ksmoon.h:25
Provides necessary information about the Sun.
Definition: kssun.h:23
void setGeometry(int x, int y, int w, int h)
virtual QSize sizeHint() const const override
virtual void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 9 2022 04:06:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.