Kstars

avtplotwidget.h
1/*
2 SPDX-FileCopyrightText: 2007 Jason Harris <kstars@30doradus.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <kplotwidget.h>
10
11#include <QPoint>
12
13class GeoLocation;
14class KSAlmanac;
15
16/**
17 * @class AVTPlotWidget
18 * @short An extension of the KPlotWidget for the AltVsTime tool.
19 * The biggest difference is that in addition to the plot objects, it draws the "ground" below
20 * Alt=0 and draws the sky light blue for day times, and black for night times. The transition
21 * between day and night is drawn with a gradient, and the position follows the actual
22 * sunrise/sunset times of the given date/location. Also, this plot widget provides two
23 * time axes (local time along the bottom, and local sideral time along the top). Finally, it
24 * provides user interaction: on mouse click, it draws crosshairs at the mouse position with
25 * labels for the time and altitude.
26 *
27 * @version 1.0
28 * @author Jason Harris
29 */
31{
33 public:
34 explicit AVTPlotWidget(QWidget *parent = nullptr);
35
36 /**
37 * Set the fractional positions of the Sunrise and Sunset positions, in units where last
38 * midnight was 0.0, and next midnight is 1.0. i.e., if Sunrise is at 06:00, then we set
39 * it as 0.25 in this function. Likewise, if Sunset is at 18:00, then we set it as
40 * 0.75 in this function.
41 * @param sr the fractional position of Sunrise
42 * @param ss the fractional position of Sunset
43 */
44 void setSunRiseSetTimes(double sr, double ss);
45
46 void setDawnDuskTimes(double da, double du);
47
48 void setMinMaxSunAlt(double min, double max);
49
50 /**
51 * Set the fractional positions of moonrise and moon set in units
52 * where last midnight was 0.0 and next midnight is 1.0
53 */
54 void setMoonRiseSetTimes(double mr, double ms);
55
56 /**
57 * @short Set the moon illumination
58 * @param mi Moon illuminated fraction (0.0 to 1.0)
59 * @note Used to determine the brightness of the gradient representing lunar skyglow
60 */
61 void setMoonIllum(double mi);
62
63 /**
64 * @short Set the GeoLocation
65 * @param geo_ Used to convert and format the current time correctly
66 * @warning Might be better to skip the entire shebang and include the KSAlmanac calls within AVTPlotWidget
67 */
68 inline void setGeoLocation(const GeoLocation *geo_) { geo = geo_; }
69
70 /**
71 * This is needed when not plotting from noon to noon.
72 * Set the offset from noon to start the plot (e.g. 6pm would be 6)
73 * and set the plot length in hours.
74 * @param noonOffset hours after noon when the plot should start
75 * @param plotDuration Number of hours that the plot represents.
76 * @warning This only affects moon and sub and mouse clicks. You must coordinate the points with this
77 */
78 void setPlotExtent(double noonOffset, double plotDuration);
79
80 /**
81 * Sets the Y-axis min and max values
82 * @param min the y-value at the bottom of the plot
83 * @param max the y-value at the top of the plot.
84 */
85 void setAltitudeAxis(double min, double max);
86
87 /**
88 * Higher level method to plot.
89 * @param geo geographic location
90 * @param ksal almanac to lookup sun and moon positions
91 * @param times the times (x-axis) for plotting the object's altitudes. Note 0 is midnight.
92 * @param alts the altitudes (y-axis) of the plot
93 * @param overlay Should be false on first plot. If overlaying a 2nd plot, set to true then.
94 */
95 void plot(const GeoLocation *geo, KSAlmanac *ksal,
96 const QVector<double> &times, const QVector<double> &alts, bool overlay);
97
98 protected:
99 /**
100 * Handle mouse move events. If the mouse button is down, draw crosshair lines
101 * centered at the cursor position. This allows the user to pinpoint specific
102 * position sin the plot.
103 */
104 void mouseMoveEvent(QMouseEvent *e) override;
105
106 /** Simply calls mouseMoveEvent(). */
107 void mousePressEvent(QMouseEvent *e) override;
108
109 /** Reset the MousePoint to a null value, to erase the crosshairs */
110 void mouseDoubleClickEvent(QMouseEvent *e) override;
111
112 /** Redraw the plot. */
113 void paintEvent(QPaintEvent *e) override;
114
115 private:
116 int convertCoords(double xCoord);
117
118 // The times below (SunRise, SunSet, Dawn, Dusk, MoonRise, MoonSet) are all in fractional
119 // parts of the day (e.g. 0.5 is 12 noon).
120 double SunRise { 0.25 };
121 double SunSet { 0.75 };
122 double Dawn { 0 };
123 double Dusk { 0 };
124 double SunMinAlt { 0 };
125 double SunMaxAlt { 0 };
126 double MoonRise { 0 };
127 double MoonSet { 0 };
128 double MoonIllum { 0 };
129 double noonOffset { 0.0}; // Default start plotting at noon plus this offset
130 double plotDuration { 24.0 }; // Default plot length is 24 hours
131 double altitudeAxisMin { -90.0 };
132 double altitudeAxisMax { 90.0 };
133 QPoint MousePoint;
134 const GeoLocation *geo { nullptr };
135};
An extension of the KPlotWidget for the AltVsTime tool.
void plot(const GeoLocation *geo, KSAlmanac *ksal, const QVector< double > &times, const QVector< double > &alts, bool overlay)
Higher level method to plot.
void setGeoLocation(const GeoLocation *geo_)
Set the GeoLocation.
void setSunRiseSetTimes(double sr, double ss)
Set the fractional positions of the Sunrise and Sunset positions, in units where last midnight was 0....
void setMoonRiseSetTimes(double mr, double ms)
Set the fractional positions of moonrise and moon set in units where last midnight was 0....
void paintEvent(QPaintEvent *e) override
Redraw the plot.
void setPlotExtent(double noonOffset, double plotDuration)
This is needed when not plotting from noon to noon.
void mouseDoubleClickEvent(QMouseEvent *e) override
Reset the MousePoint to a null value, to erase the crosshairs.
void setMoonIllum(double mi)
Set the moon illumination.
void mousePressEvent(QMouseEvent *e) override
Simply calls mouseMoveEvent().
void mouseMoveEvent(QMouseEvent *e) override
Handle mouse move events.
void setAltitudeAxis(double min, double max)
Sets the Y-axis min and max values.
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
Definition geolocation.h:28
A class that implements methods to find sun rise, sun set, twilight begin / end times,...
Definition ksalmanac.h:27
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.