1/***************************************************************************
2 moonphasecalendarwidget.h - K Desktop Planetarium
3 -------------------
4 begin : Sat Jun 26 2010
5 copyright : (C) 2010 by Akarsh Simha
6 email : akarshsimha@gmail.com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef _MOONPHASECALENDARWIDGET_H_
19#define _MOONPHASECALENDARWIDGET_H_
20
21#include <QWidget>
22#include <KDateTable>
23
24class KSMoon;
25class KSSun;
26class KStarsDateTime;
27
28class MoonPhaseCalendar : public KDateTable {
29
30 Q_OBJECT
31
32 public:
33
34 /**
35 * Constructor
36 * @param moon A reference to a (non-const) KSMoon object, that will be updated
37 * @param sun A reference to a (non-const) KSSun object, that will be updated
38 */
39 explicit MoonPhaseCalendar( KSMoon &moon, KSSun &sun, QWidget *parent = 0 );
40
41 ~MoonPhaseCalendar();
42
43 /**
44 * @return a suggested size for the widget
45 */
46 virtual QSize sizeHint() const;
47
48 public slots:
49
50 /**
51 * Set the geometry of the moon phase calendar (overloaded from QWidget).
52 * Resizes the cells so as to fill the space of the calendar.
53 * @note This is called automatically by resize events.
54 * @p x the x-position of the widget
55 * @p y the y-position of the widget
56 * @p w the width of the widget
57 * @p h the height of the widget
58 */
59
60 virtual void setGeometry( int x, int y, int w, int h );
61
62 virtual void setGeometry( const QRect &r );
63
64 protected:
65
66 /**
67 * Overrides KDateTable::paintEvent() to draw moon phases on the
68 * calendar cells by calling this->paintCell()
69 * @note Most of this code is copied from KDateTable::paintEvent()
70 */
71 virtual void paintEvent( QPaintEvent *e );
72
73 /**
74 * Replaces KDateTable::paintCell() to draw moon phases on the calendar cells
75 * @note Most of this code is copied from KDateTable::paintCell()
76 */
77 void paintCell( QPainter *painter, int row, int col, const KColorScheme &colorScheme );
78
79 /**
80 * @short Loads the moon images, appropriately resized depending
81 * on the current cell size.
82 *
83 * @note This method is very slow and one must avoid calling it more than once.
84 */
85 void loadImages();
86
87 /**
88 * @short Computes the optimum moon image size
89 */
90 void computeMoonImageSize();
91
92 private:
93
94 /**
95 * @short Computes the moon phase for the given date.
96 * @param date Date / Time of the computation
97 * @return the _integer_ phase for the given date
98 */
99 unsigned short computeMoonPhase( const KStarsDateTime &date );
100
101 QPixmap m_Images[36]; // Array storing moon images against integer phase
102
103 double cellWidth, cellHeight;
104 int numWeekRows;
105 int numDayColumns;
106 int MoonImageSize;
107 bool imagesLoaded;
108
109 KSMoon &m_Moon;
110 KSSun &m_Sun;
111};
112
113#endif
114