File indexing completed on 2024-04-21 14:46:51
0001 /* 0002 SPDX-FileCopyrightText: 2007 Jason Harris <kstars@30doradus.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <kplotwidget.h> 0010 0011 #include <QPoint> 0012 0013 class GeoLocation; 0014 0015 /** 0016 * @class AVTPlotWidget 0017 * @short An extension of the KPlotWidget for the AltVsTime tool. 0018 * The biggest difference is that in addition to the plot objects, it draws the "ground" below 0019 * Alt=0 and draws the sky light blue for day times, and black for night times. The transition 0020 * between day and night is drawn with a gradient, and the position follows the actual 0021 * sunrise/sunset times of the given date/location. Also, this plot widget provides two 0022 * time axes (local time along the bottom, and local sideral time along the top). Finally, it 0023 * provides user interaction: on mouse click, it draws crosshairs at the mouse position with 0024 * labels for the time and altitude. 0025 * 0026 * @version 1.0 0027 * @author Jason Harris 0028 */ 0029 class AVTPlotWidget : public KPlotWidget 0030 { 0031 Q_OBJECT 0032 public: 0033 explicit AVTPlotWidget(QWidget *parent = nullptr); 0034 0035 /** 0036 * Set the fractional positions of the Sunrise and Sunset positions, in units where last 0037 * midnight was 0.0, and next midnight is 1.0. i.e., if Sunrise is at 06:00, then we set 0038 * it as 0.25 in this function. Likewise, if Sunset is at 18:00, then we set it as 0039 * 0.75 in this function. 0040 * @param sr the fractional position of Sunrise 0041 * @param ss the fractional position of Sunset 0042 */ 0043 void setSunRiseSetTimes(double sr, double ss); 0044 0045 void setDawnDuskTimes(double da, double du); 0046 0047 void setMinMaxSunAlt(double min, double max); 0048 0049 /** 0050 * Set the fractional positions of moonrise and moon set in units 0051 * where last midnight was 0.0 and next midnight is 1.0 0052 */ 0053 void setMoonRiseSetTimes(double mr, double ms); 0054 0055 /** 0056 * @short Set the moon illumination 0057 * @param mi Moon illuminated fraction (0.0 to 1.0) 0058 * @note Used to determine the brightness of the gradient representing lunar skyglow 0059 */ 0060 void setMoonIllum(double mi); 0061 0062 /** 0063 * @short Set the GeoLocation 0064 * @param geo_ Used to convert and format the current time correctly 0065 * @warning Might be better to skip the entire shebang and include the KSAlmanac calls within AVTPlotWidget 0066 */ 0067 inline void setGeoLocation(const GeoLocation *geo_) { geo = geo_; } 0068 0069 protected: 0070 /** 0071 * Handle mouse move events. If the mouse button is down, draw crosshair lines 0072 * centered at the cursor position. This allows the user to pinpoint specific 0073 * position sin the plot. 0074 */ 0075 void mouseMoveEvent(QMouseEvent *e) override; 0076 0077 /** Simply calls mouseMoveEvent(). */ 0078 void mousePressEvent(QMouseEvent *e) override; 0079 0080 /** Reset the MousePoint to a null value, to erase the crosshairs */ 0081 void mouseDoubleClickEvent(QMouseEvent *e) override; 0082 0083 /** Redraw the plot. */ 0084 void paintEvent(QPaintEvent *e) override; 0085 0086 private: 0087 double SunRise { 0.25 }; 0088 double SunSet { 0.75 }; 0089 double Dawn { 0 }; 0090 double Dusk { 0 }; 0091 double SunMinAlt { 0 }; 0092 double SunMaxAlt { 0 }; 0093 double MoonRise { 0 }; 0094 double MoonSet { 0 }; 0095 double MoonIllum { 0 }; 0096 QPoint MousePoint; 0097 const GeoLocation *geo { nullptr }; 0098 };