Kstars

xplanetimageviewer.h
1/*
2 SPDX-FileCopyrightText: Thomas Kabelmann
3 SPDX-FileCopyrightText: 2018 Robert Lancaster <rlancaste@gmail.com>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#pragma once
9
10#include "auxiliary/filedownloader.h"
11
12#include <QDialog>
13#include <QLineEdit>
14#include <QSpinBox>
15#include "nonlineardoublespinbox.h"
16#include <QComboBox>
17#include <QFile>
18#include <QFrame>
19#include <QImage>
20#include <QPixmap>
21#include "kstarsdata.h"
22#include <QEvent>
23#include <QGestureEvent>
24#include <QPinchGesture>
25
26#ifndef Q_OS_WIN
27#include<QFutureWatcher>
28#endif
29
30
31class QLabel;
32/**
33 * @class XPlanetImageLabel
34 * @short XPlanet Image viewer QFrame for the KPlanetImageViewer for KStars
35 * @author Thomas Kabelmann
36 * @author Jasem Mutlaq
37 * @author Robert Lancaster
38 * @version 1.1
39 *
40 * This image-viewer QFrame automatically resizes the picture. It also receives input from the mouse to
41 * zoom and pan the XPlanet Image.
42 */
44{
46 public:
48 ~XPlanetImageLabel() override = default;
49 void setImage(const QImage &img);
50 void invertPixels();
51 void refreshImage();
52
53 public slots:
54 void wheelEvent(QWheelEvent *e) override;
55 void mousePressEvent(QMouseEvent *e) override;
56 void mouseReleaseEvent(QMouseEvent *e) override;
57 void mouseMoveEvent(QMouseEvent *e) override;
58
59 signals:
60 void zoomIn();
61 void zoomOut();
62 void changePosition(QPoint);
63 void changeLocation(QPoint);
64
65 protected:
66 void paintEvent(QPaintEvent *e) override;
67 void resizeEvent(QResizeEvent *) override;
68
69 private:
70 //Image related
71 QPixmap m_Pix;
72 QImage m_Image;
73
74 //Mouse related
75 bool m_MouseButtonDown = false;
76 QPoint m_LastMousePoint;
77 bool event(QEvent *event) override;
78 bool gestureEvent(QGestureEvent *event);
79 void pinchTriggered(QPinchGesture *gesture);
80};
81
82/**
83 * @class XPlanetImageViewer
84 * @short XPlanet Image viewer window for KStars
85 * @author Thomas Kabelmann
86 * @author Jasem Mutlaq
87 * @author Robert Lancaster
88 * @version 1.1
89 *
90 * This class is meant to interact with XPlanet and display the results. It has interfaces to control many of the XPlanet Options.
91 * It can change a number of properties using controls. It works with the XPlanetImageLabel to display the results. It also can work
92 * with the XPlanetImageLabel to respond to mouse inputs on the ImageLabel and act on them in the Image Viewer. It has a hover mode where
93 * it hovers over the same planetary body or a remote mode where it views one body from another. It has interfaces for changing the field of
94 * view, the time, the rotation, and other settings. In hover mode, it can change latitude, longitude, and radius with the mouse inputs.
95 * It also can animate events so that you can watch xplanet frames like a movie to see solar system events in action.
96 */
98{
100
101 public:
102 /** Create xplanet image viewer from Object */
103 explicit XPlanetImageViewer(const QString &obj, QWidget *parent = nullptr);
104
105 /** Destructor. If there is a partially downloaded image file, delete it.*/
106 ~XPlanetImageViewer() override;
107
108 /**
109 * @brief loadImage Load image and display it
110 * @return True if opened and displayed, false otherwise
111 */
112 bool loadImage();
113
114 void startXplanet();
115
116 private:
117
118
119 /** prepares the output file**/
120 bool setupOutputFile();
121
122 QImage m_Image;
123
124 /** Save the downloaded image to a local file. */
125 void saveFile(const QString & fileName);
126
127 QFile m_File;
128
129 XPlanetImageLabel *m_View { nullptr };
130 QLabel *m_Caption { nullptr };
131
132 QString m_LastFile;
133
134 QStringList m_ObjectNames;
135 QList<double> m_objectDefaultFOVs;
136
137 typedef enum { YEARS, MONTHS, DAYS, HOURS, MINS, SECS } timeUnits;
138
139 void setXPlanetDate(KStarsDateTime time);
140
141 //XPlanet strings
142 QString m_ObjectName;
143 QString m_OriginName;
144 QString m_Date;
145 QString m_DateText;
146
147 //XPlanet numbers
148 int m_CurrentObjectIndex { 0 };
149 int m_CurrentOriginIndex { 0 };
150 int m_Rotation { 0 };
151 int m_CurrentTimeUnitIndex { 0 };
152 uint32_t m_Radius { 0 };
153 double m_FOV { 0 };
154 double m_lat { 0 };
155 double m_lon { 0 };
156 QPoint center;
157
158#ifndef Q_OS_WIN
159 QFutureWatcher<bool> fifoImageLoadWatcher;
160 QTimer watcherTimeout;
161#endif
162
163 // Time
164 KStarsDateTime m_XPlanetTime {};
165 bool m_XPlanetRunning = false;
166
167 QComboBox *m_OriginSelector {nullptr};
168
169 // Field of view controls
170 QPushButton *m_KStarsFOV {nullptr};
171 QPushButton *m_setFOV {nullptr};
172 QPushButton *m_NoFOV {nullptr};
173 NonLinearDoubleSpinBox *m_FOVEdit {nullptr};
174
175 // Rotation controls
176 QSpinBox *m_RotateEdit {nullptr};
177
178 // Free rotation controls
179 QLabel *m_PositionDisplay {nullptr};
180 QPushButton *m_FreeRotate {nullptr};
181 bool m_ImageLoadSucceeded = false;
182
183 // Time controls
184 QLabel *m_XPlanetTimeDisplay {nullptr};
185 QSlider *m_TimeSlider {nullptr};
186 QSpinBox *m_TimeEdit {nullptr};
187 QComboBox *m_TimeUnitsSelect {nullptr};
188
189 //Animation controls
190 QPushButton *m_RunTime {nullptr};
191 QTimer *m_XPlanetTimer {nullptr};
192
193
194 private slots:
195
196 /**
197 * Display the downloaded image. Resize the window to fit the image, If the image is
198 * larger than the screen, make the image as large as possible while preserving the
199 * original aspect ratio
200 */
201 bool showImage();
202
203 // Saves file to disk.
204 void saveFileToDisk();
205
206 // Inverts colors
207 void invertColors();
208
209 // Rotation slots
210 void updateXPlanetRotationEdit();
211 void resetXPlanetRotation();
212 void invertXPlanetRotation();
213
214 void reCenterXPlanet();
215
216 // Free Rotation slots
217 void changeXPlanetPosition(QPoint delta);
218 void changeXPlanetLocation(QPoint delta);
219 void slotFreeRotate();
220 void updateStates();
221 void updatePositionDisplay();
222 void resetLocation();
223
224 // Field of View slots
225 void zoomInXPlanetFOV();
226 void zoomOutXPlanetFOV();
227 void updateXPlanetFOVEdit();
228 void resetXPlanetFOV();
229 void setKStarsXPlanetFOV();
230 void setFOVfromList();
231
232 // Time slots
233 void updateXPlanetTime(int timeShift);
234 void updateXPlanetObject(int objectIndex);
235 void updateXPlanetOrigin(int originIndex);
236 void updateXPlanetTimeUnits(int units);
237 void updateXPlanetTimeEdit();
238 void setXPlanetTime();
239 void setXPlanetTimetoKStarsTime();
240 void resetXPlanetTime();
241
242 // Animation slots
243 void incrementXPlanetTime();
244 void toggleXPlanetRun();
245 void timeSliderDisplay(int timeShift);
246
247};
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
XPlanet Image viewer QFrame for the KPlanetImageViewer for KStars.
XPlanet Image viewer window for KStars.
XPlanetImageViewer(const QString &obj, QWidget *parent=nullptr)
Create xplanet image viewer from Object.
~XPlanetImageViewer() override
Destructor.
bool loadImage()
loadImage Load image and display it
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:49:21 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.