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 */
30class AVTPlotWidget : public KPlotWidget
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, const QVector<double> &times,
96 const QVector<double> &alts, int lineWidth = 2, Qt::GlobalColor color = Qt::white);
97
98 void plotOverlay(const QVector<double> &times, const QVector<double> &alts,
99 int lineWidth = 5, Qt::GlobalColor color = Qt::green);
100
101 /**
102 * Sets the plot index which whose altitude is displayed when clicking on the graph.
103 * @param lineIndex the plot index whose altitude should be displayed when the plot is clicked.
104 */
105 void setCurrentLine(int lineIndex);
106
107 void disableAxis(KPlotWidget::Axis axisToDisable);
108
109
110 protected:
111 /**
112 * Handle mouse move events. If the mouse button is down, draw crosshair lines
113 * centered at the cursor position. This allows the user to pinpoint specific
114 * position sin the plot.
115 */
116 void mouseMoveEvent(QMouseEvent *e) override;
117
118 /** Simply calls mouseMoveEvent(). */
119 void mousePressEvent(QMouseEvent *e) override;
120
121 /** Reset the MousePoint to a null value, to erase the crosshairs */
122 void mouseDoubleClickEvent(QMouseEvent *e) override;
123
124 /** Redraw the plot. */
125 void paintEvent(QPaintEvent *e) override;
126
127 private:
128 int convertCoords(double xCoord);
129
130 // The times below (SunRise, SunSet, Dawn, Dusk, MoonRise, MoonSet) are all in fractional
131 // parts of the day (e.g. 0.5 is 12 noon).
132 double SunRise { 0.25 };
133 double SunSet { 0.75 };
134 double Dawn { 0 };
135 double Dusk { 0 };
136 double SunMinAlt { 0 };
137 double SunMaxAlt { 0 };
138 double MoonRise { 0 };
139 double MoonSet { 0 };
140 double MoonIllum { 0 };
141 double noonOffset { 0.0}; // Default start plotting at noon plus this offset
142 double plotDuration { 24.0 }; // Default plot length is 24 hours
143 double altitudeAxisMin { -90.0 };
144 double altitudeAxisMax { 90.0 };
145 QPoint MousePoint;
146 const GeoLocation *geo { nullptr };
147
148 int currentLine { 0 };
149};
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 plot(const GeoLocation *geo, KSAlmanac *ksal, const QVector< double > &times, const QVector< double > &alts, int lineWidth=2, Qt::GlobalColor color=Qt::white)
Higher level method to plot.
void setCurrentLine(int lineIndex)
Sets the plot index which whose altitude is displayed when clicking on the graph.
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
KPlotWidget(QWidget *parent=nullptr)
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
GlobalColor
QWidget(QWidget *parent, Qt::WindowFlags f)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 7 2025 11:55:45 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.