File indexing completed on 2024-04-21 03:45:05
0001 /* 0002 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "config-kstars.h" 0010 0011 //Needed for Projection enum 0012 #include "projections/projector.h" 0013 0014 #include <QQuickWindow> 0015 #include <QPalette> 0016 #include <QString> 0017 #include <QtQml/QQmlApplicationEngine> 0018 0019 #include <memory> 0020 0021 // forward declaration is enough. We only need pointers 0022 class KStarsData; 0023 class SkyMapLite; 0024 class SkyPoint; 0025 class GeoLocation; 0026 class ImageProvider; 0027 0028 class FindDialogLite; 0029 class DetailDialogLite; 0030 class LocationDialogLite; 0031 0032 class ClientManagerLite; 0033 0034 class QQuickItem; 0035 0036 /** 0037 * @class KStarsLite 0038 * @short This class loads QML files and connects SkyMapLite and KStarsData 0039 * Unlike KStars class it is not a main window (see KStarsLite::m_Engine) but a root object that contains the program clock and 0040 * holds pointers to SkyMapLite and KStarsData objects. 0041 * KStarsLite is a singleton, use KStarsLite::createInstance() to create an instance and KStarsLite::Instance() to get a pointer to the instance 0042 * 0043 * @author Artem Fedoskin 0044 * @version 1.0 0045 */ 0046 class KStarsLite : public QObject 0047 { 0048 Q_OBJECT 0049 //runTutorial is a wrapper for Options::RunStartupWizard() 0050 Q_PROPERTY(bool runTutorial WRITE setRunTutorial READ getRunTutorial NOTIFY runTutorialChanged) 0051 private: 0052 0053 /** 0054 * @short Constructor. 0055 * @param doSplash should the splash panel be displayed during initialization. 0056 * @param startClockRunning should the clock be running on startup? 0057 * @param startDateString date (in string representation) to start running from. 0058 */ 0059 explicit KStarsLite(bool doSplash, bool startClockRunning = true, const QString &startDateString = QString()); 0060 virtual ~KStarsLite(); 0061 0062 static KStarsLite *pinstance; // Pointer to an instance of KStarsLite 0063 0064 public: 0065 /** 0066 * @short Create an instance of this class. Destroy any previous instance 0067 * @param doSplash 0068 * @param clockrunning 0069 * @param startDateString 0070 * @note See KStarsLite::KStarsLite for details on parameters 0071 * @return a pointer to the instance 0072 */ 0073 static KStarsLite *createInstance(bool doSplash, bool clockrunning = true, 0074 const QString &startDateString = QString()); 0075 0076 /** @return a pointer to the instance of this class */ 0077 inline static KStarsLite *Instance() { return pinstance; } 0078 0079 /** @return pointer to SkyMapLite object which draws SkyMap. */ 0080 inline SkyMapLite *map() const { return m_SkyMapLite; } 0081 0082 /** @return pointer to the main window. */ 0083 QQuickWindow *getMainWindow(); 0084 0085 /** @return pointer to KStarsData object which contains application data. */ 0086 inline KStarsData *data() const { return m_KStarsData; } 0087 0088 /** @return pointer to ImageProvider that is used in QML to display image fetched from CCD **/ 0089 inline ImageProvider *imageProvider() const { return m_imgProvider.get(); } 0090 0091 /** @return pointer to QQmlApplicationEngine that runs QML **/ 0092 inline QQmlApplicationEngine *qmlEngine() { return &m_Engine; } 0093 0094 /** @short used from QML to update positions of sky objects and update SkyMapLite */ 0095 Q_INVOKABLE void fullUpdate(); 0096 0097 /** @short currently sets color scheme from config **/ 0098 Q_INVOKABLE void applyConfig(bool doApplyFocus = true); 0099 0100 /** @short set whether tutorial should be shown on next startup **/ 0101 void setRunTutorial(bool runTutorial); 0102 0103 /** @return true if tutorial should be shown **/ 0104 bool getRunTutorial(); 0105 0106 /** @return pointer to KStarsData object which handles connection to INDI server. */ 0107 inline ClientManagerLite *clientManagerLite() const { return m_clientManager; } 0108 0109 /** 0110 * @defgroup kconfigwrappers QML wrappers around KConfig 0111 * @{ 0112 */ 0113 enum class ObjectsToToggle 0114 { 0115 Stars, 0116 DeepSky, 0117 Planets, 0118 CLines, 0119 CBounds, 0120 ConstellationArt, 0121 MilkyWay, 0122 CNames, 0123 EquatorialGrid, 0124 HorizontalGrid, 0125 Ground, 0126 Flags, 0127 Satellites, 0128 Supernovae 0129 }; 0130 0131 Q_ENUMS(ObjectsToToggle) 0132 0133 /** setProjection calls Options::setProjection(proj) and updates SkyMapLite */ 0134 // Having projection as uint is not good but it will go away once KConfig is fixed 0135 // The reason for this is that you can't use Enums of another in class in Q_INVOKABLE function 0136 Q_INVOKABLE void setProjection(uint proj); 0137 0138 // These functions are just convenient getters to access internals of KStars from QML 0139 0140 /** 0141 * @short returns color with key name from current color scheme 0142 * @param name the key name of the color to be retrieved from current color scheme 0143 * @return color from name 0144 */ 0145 Q_INVOKABLE QColor getColor(QString name); 0146 0147 Q_INVOKABLE QString getConfigCScheme(); 0148 0149 /** 0150 * @short toggles on/off objects of group toToggle 0151 * @see ObjectsToToggle 0152 */ 0153 Q_INVOKABLE void toggleObjects(ObjectsToToggle toToggle, bool toggle); 0154 0155 /** @return true if objects from group toToggle are currently toggled on **/ 0156 Q_INVOKABLE bool isToggled(ObjectsToToggle toToggle); 0157 0158 /** @} */ // end of kconfigwrappers group 0159 0160 signals: 0161 /** Sent when KStarsData finishes loading data */ 0162 void dataLoadFinished(); 0163 0164 /** Makes splash (Splash.qml) visible on startup */ 0165 void showSplash(); 0166 0167 /** Emitted whenever TimeSpinBox in QML changes the scale **/ 0168 void scaleChanged(float); 0169 0170 void runTutorialChanged(); 0171 0172 /** 0173 * Once this signal is emitted, notification with text msg will appear on the screen. 0174 * Use this signal to output messages to user (warnings, info etc.) 0175 */ 0176 void notificationMessage(QString msg); 0177 0178 public Q_SLOTS: 0179 /** 0180 * Update time-dependent data and (possibly) repaint the sky map. 0181 * @param automaticDSTchange change DST status automatically? 0182 */ 0183 void updateTime(const bool automaticDSTchange = true); 0184 0185 /** Write current settings to config file. Used to save config file upon exit */ 0186 bool writeConfig(); 0187 0188 /** 0189 * Load a color scheme. 0190 * @param name the name of the color scheme to load (e.g., "Moonless Night") 0191 */ 0192 void loadColorScheme(const QString &name); 0193 0194 /** sets time and date according to parameter time*/ 0195 void slotSetTime(QDateTime time); 0196 0197 /** action slot: toggle whether kstars clock is running or not */ 0198 void slotToggleTimer(); 0199 0200 /** action slot: advance one step forward in time */ 0201 void slotStepForward(); 0202 0203 /** action slot: advance one step backward in time */ 0204 void slotStepBackward(); 0205 0206 /** start tracking clickedPoint or stop tracking if we are already tracking some object **/ 0207 void slotTrack(); 0208 0209 private slots: 0210 /** finish setting up after the KStarsData has finished */ 0211 void datainitFinished(); 0212 0213 /** Save data to config file before exiting.*/ 0214 void handleStateChange(Qt::ApplicationState state); 0215 0216 private: 0217 /** Initialize focus position */ 0218 void initFocus(); 0219 0220 QQmlApplicationEngine m_Engine; 0221 SkyMapLite *m_SkyMapLite { nullptr }; 0222 QPalette OriginalPalette, DarkPalette; 0223 0224 QObject *m_RootObject { nullptr }; 0225 bool StartClockRunning { false }; 0226 0227 KStarsData *m_KStarsData { nullptr }; 0228 std::unique_ptr<ImageProvider> m_imgProvider; 0229 0230 //Dialogs 0231 FindDialogLite *m_findDialogLite { nullptr }; 0232 DetailDialogLite *m_detailDialogLite { nullptr }; 0233 LocationDialogLite *m_locationDialogLite { nullptr }; 0234 0235 ClientManagerLite *m_clientManager { nullptr }; 0236 };