Stellarium 0.13.3
StelApp.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2006 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELAPP_HPP_
21 #define _STELAPP_HPP_
22 
23 #include <QString>
24 #include <QObject>
25 
26 // Predeclaration of some classes
27 class StelCore;
28 class StelTextureMgr;
29 class StelObjectMgr;
30 class StelLocaleMgr;
31 class StelModuleMgr;
32 class StelSkyCultureMgr;
33 class StelViewportEffect;
34 class QOpenGLFramebufferObject;
35 class QSettings;
36 class QNetworkAccessManager;
37 class QNetworkReply;
38 class QTime;
39 class QTimer;
40 class StelLocationMgr;
41 class StelSkyLayerMgr;
42 class StelAudioMgr;
43 class StelVideoMgr;
44 class StelGuiBase;
46 class StelScriptMgr;
47 class StelActionMgr;
49 
61 class StelApp : public QObject
62 {
63  Q_OBJECT
64  Q_PROPERTY(bool nightMode READ getVisionModeNight WRITE setVisionModeNight NOTIFY visionNightModeChanged)
65 
66 public:
67  friend class StelAppGraphicsWidget;
68  friend class StelSkyItem;
69 
75  StelApp(QObject* parent=NULL);
76 
78  virtual ~StelApp();
79 
81  void init(QSettings* conf);
83  void deinit();
84 
86  void initPlugIns();
87 
90  static StelApp& getInstance() {Q_ASSERT(singleton); return *singleton;}
91 
94  StelModuleMgr& getModuleMgr() {return *moduleMgr;}
95 
98  StelLocaleMgr& getLocaleMgr() {return *localeMgr;}
99 
102  StelSkyCultureMgr& getSkyCultureMgr() {return *skyCultureMgr;}
103 
106  StelTextureMgr& getTextureManager() {return *textureMgr;}
107 
110  StelLocationMgr& getLocationMgr() {return *planetLocationMgr;}
111 
114  StelObjectMgr& getStelObjectMgr() {return *stelObjectMgr;}
115 
116  StelSkyLayerMgr& getSkyImageMgr() {return *skyImageMgr;}
117 
119  StelAudioMgr* getStelAudioMgr() {return audioMgr;}
120 
122  StelActionMgr* getStelActionManager() {return actionMgr;}
123 
125  StelVideoMgr* getStelVideoMgr() {return videoMgr;}
126 
130  StelCore* getCore() {return core;}
131 
133  QNetworkAccessManager* getNetworkAccessManager() {return networkAccessManager;}
134 
136  void updateI18n();
137 
139  void updateSkyCulture();
140 
142  QSettings* getSettings() {return confSettings;}
143 
145  QString getCurrentStelStyle() {return "color";}
146 
148  void update(double deltaTime);
149 
151  // 2014-11: OLD COMMENT? What does a void return?
152  // @return the max squared distance in pixels that any object has travelled since the last update.
153  void draw();
154 
156  void glWindowHasBeenResized(float x, float y, float w, float h);
157 
160  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
161  void setDevicePixelsPerPixel(float dppp);
162 
166  float getGlobalScalingRatio() const {return globalScalingRatio;}
167  void setGlobalScalingRatio(float r) {globalScalingRatio=r;}
168 
170  int getBaseFontSize() const { return baseFontSize; }
171  void setBaseFontSize(int s) { baseFontSize=s; }
172 
174  StelGuiBase* getGui() const {return stelGui;}
177  void setGui(StelGuiBase* b) {stelGui=b;}
178 
179 #ifndef DISABLE_SCRIPTING
180  StelMainScriptAPIProxy* getMainScriptAPIProxy() {return scriptAPIProxy;}
183  StelScriptMgr& getScriptMgr() {return *scriptMgr;}
184 #endif
185 
186  static void initStatic();
187  static void deinitStatic();
188 
193  void removeProgressBar(StelProgressController* p);
194 
197  void setViewportEffect(const QString& effectName);
199  QString getViewportEffect() const;
200 
202  // Scriptable methods
203 public slots:
204 
206  void setVisionModeNight(bool);
208  bool getVisionModeNight() const {return flagNightVision;}
209 
211  void setFlagShowDecimalDegrees(bool b);
213  bool getFlagShowDecimalDegrees() const {return flagShowDecimalDegrees;}
214 
217  float getFps() const {return fps;}
218 
220  static double getTotalRunTime();
221 
224  void reportFileDownloadFinished(QNetworkReply* reply);
225 
227  void quit();
228 signals:
229  void visionNightModeChanged(bool);
230  void colorSchemeChanged(const QString&);
231  void languageChanged();
232  void skyCultureChanged(const QString&);
233 
239  void aboutToQuit();
240 
241 private:
242 
244  void handleClick(class QMouseEvent* event);
246  void handleWheel(class QWheelEvent* event);
248  void handleMove(float x, float y, Qt::MouseButtons b);
250  void handleKeys(class QKeyEvent* event);
252  void handlePinch(qreal scale, bool started);
253 
254  void initScriptMgr(QSettings* conf);
255 
256  void prepareRenderBuffer();
257  void applyRenderBuffer();
258 
259  // The StelApp singleton
260  static StelApp* singleton;
261 
262  // The associated StelCore instance
263  StelCore* core;
264 
265  // Module manager for the application
266  StelModuleMgr* moduleMgr;
267 
268  // Locale manager for the application
269  StelLocaleMgr* localeMgr;
270 
271  // Sky cultures manager for the application
272  StelSkyCultureMgr* skyCultureMgr;
273 
274  //Actions manager fot the application. Will replace shortcutMgr.
275  StelActionMgr* actionMgr;
276 
277  // Textures manager for the application
278  StelTextureMgr* textureMgr;
279 
280  // Manager for all the StelObjects of the program
281  StelObjectMgr* stelObjectMgr;
282 
283  // Manager for the list of observer locations on planets
284  StelLocationMgr* planetLocationMgr;
285 
286  // Main network manager used for the program
287  QNetworkAccessManager* networkAccessManager;
288 
290  void setupHttpProxy();
291 
292  // The audio manager. Must execute in the main thread.
293  StelAudioMgr* audioMgr;
294 
295  // The video manager. Must execute in the main thread.
296  StelVideoMgr* videoMgr;
297 
298  StelSkyLayerMgr* skyImageMgr;
299 
300 #ifndef DISABLE_SCRIPTING
301  // The script API proxy object (for bridging threads)
302  StelMainScriptAPIProxy* scriptAPIProxy;
303 
304  // The script manager based on Qt script engine
305  StelScriptMgr* scriptMgr;
306 #endif
307 
308 
309 
310  StelGuiBase* stelGui;
311 
312  // Store the ratio between real device pixel in "Device Independent Pixel"
313  // Usually this value is 1, but for a mac with retina screen this will be value 2.
314  float devicePixelsPerPixel;
315 
316  // The scaling ratio to apply on all display elements, like GUI, text etc..
317  float globalScalingRatio;
318 
319  // Used to collect wheel events
320  QTimer * wheelEventTimer;
321 
322  // Accumulated horizontal and vertical wheel event deltas
323  int wheelEventDelta[2];
324 
325  float fps;
326  int frame;
327  double timefr, timeBase; // Used for fps counter
328 
330  bool flagNightVision;
331 
332  QSettings* confSettings;
333 
334  // Define whether the StelApp instance has completed initialization
335  bool initialized;
336 
337  static QTime* qtime;
338 
339  // Temporary variables used to store the last gl window resize
340  // if the core was not yet initialized
341  int saveProjW;
342  int saveProjH;
343 
345  int nbDownloadedFiles;
347  qint64 totalDownloadedSize;
348 
350  int nbUsedCache;
352  qint64 totalUsedCacheSize;
353 
354  QList<StelProgressController*> progressControllers;
355 
356  int baseFontSize;
357 
358  // Framebuffer object used for viewport effects.
359  QOpenGLFramebufferObject* renderBuffer;
360 
361  StelViewportEffect* viewportEffect;
362 
363  bool flagShowDecimalDegrees;
364 };
365 
366 #endif // _STELAPP_HPP_
Manage the sky background images, including DSS and deep sky objects images.
StelScriptMgr & getScriptMgr()
Get the script manager.
Definition: StelApp.hpp:183
StelLocationMgr & getLocationMgr()
Get the Location manager to use for managing stored locations.
Definition: StelApp.hpp:110
StelVideoMgr * getStelVideoMgr()
Get the video manager.
Definition: StelApp.hpp:125
bool getFlagShowDecimalDegrees() const
Get flag for showing decimal degree in various places.
Definition: StelApp.hpp:213
void reportFileDownloadFinished(QNetworkReply *reply)
Report that a download occured.
int getBaseFontSize() const
Get the size of font.
Definition: StelApp.hpp:170
float getFps() const
Get the current number of frame per second.
Definition: StelApp.hpp:217
void progressBarRemoved(const StelProgressController *)
Called just before a progress bar is removed.
void updateSkyCulture()
Update and reload sky culture informations everywhere in the program.
StelObjectMgr & getStelObjectMgr()
Get the StelObject manager to use for querying from all stellarium objects.
Definition: StelApp.hpp:114
Manage i18n operations such as message translation and date/time localization.
Main class for Stellarium core processing.
Definition: StelCore.hpp:46
Because the core API runs in a different thread to the main program, direct function calls to some cl...
StelModuleMgr & getModuleMgr()
Get the module manager to use for accessing any module loaded in the application. ...
Definition: StelApp.hpp:94
StelTextureMgr & getTextureManager()
Get the texture manager to use for loading textures.
Definition: StelApp.hpp:106
void deinit()
Deinitialize core and all the modules.
Manage the list of available location.
QNetworkAccessManager * getNetworkAccessManager()
Get the common instance of QNetworkAccessManager used in stellarium.
Definition: StelApp.hpp:133
QString getCurrentStelStyle()
Return the currently used style.
Definition: StelApp.hpp:145
void progressBarAdded(const StelProgressController *)
Called just after a progress bar is added.
Abstract class defining the base interface for all GUIs.
Definition: StelGuiBase.hpp:30
StelMainScriptAPIProxy * getMainScriptAPIProxy()
Get the script API proxy (for signal handling)
Definition: StelApp.hpp:181
void setGui(StelGuiBase *b)
Tell the StelApp instance which GUI si currently being used.
Definition: StelApp.hpp:177
void initPlugIns()
Load and initialize external modules (plugins)
StelActionMgr * getStelActionManager()
Get the actions manager to use for managing and editing actions.
Definition: StelApp.hpp:122
void draw()
Draw all registered StelModule in the order defined by the order lists.
void update(double deltaTime)
Update all object according to the deltaTime in seconds.
Allow to apply visual effects on the whole Stellarium viewport.
Manage a collection of StelModules including both core and plugin modules.
QString getViewportEffect() const
Get the type of viewport effect currently used.
void updateI18n()
Update translations, font for GUI and sky everywhere in the program.
float getGlobalScalingRatio() const
Get the scaling ratio to apply on all display elements, like GUI, text etc.
Definition: StelApp.hpp:166
StelApp(QObject *parent=NULL)
Create and initialize the main Stellarium application.
void quit()
do some cleanup and call QCoreApplication::exit(0)
StelAudioMgr * getStelAudioMgr()
Get the audio manager.
Definition: StelApp.hpp:119
Manage the selection and queries on one or more StelObjects.
Manage scripting in Stellarium.
float getDevicePixelsPerPixel() const
Get the ratio between real device pixel and "Device Independent Pixel".
Definition: StelApp.hpp:160
Manage textures loading.
Maintain the state of a progress bar.
Manage sky cultures for stellarium.
void setVisionModeNight(bool)
Set flag for activating night vision mode.
void glWindowHasBeenResized(float x, float y, float w, float h)
Call this when the size of the GL window has changed.
static double getTotalRunTime()
Return the time since when stellarium is running in second.
void setViewportEffect(const QString &effectName)
Define the type of viewport effect to use.
static StelApp & getInstance()
Get the StelApp singleton instance.
Definition: StelApp.hpp:90
virtual ~StelApp()
Deinitialize and destroy the main Stellarium application.
StelSkyCultureMgr & getSkyCultureMgr()
Get the sky cultures manager.
Definition: StelApp.hpp:102
QSettings * getSettings()
Return the main configuration options.
Definition: StelApp.hpp:142
StelGuiBase * getGui() const
Get the GUI instance implementing the abstract GUI interface.
Definition: StelApp.hpp:174
void setFlagShowDecimalDegrees(bool b)
Set flag for showing decimal degree in various places.
Singleton main Stellarium application class.
Definition: StelApp.hpp:61
StelProgressController * addProgressBar()
Add a progression indicator to the GUI (if applicable).
void aboutToQuit()
Called just before we exit Qt mainloop.
StelCore * getCore()
Get the core of the program.
Definition: StelApp.hpp:130
StelLocaleMgr & getLocaleMgr()
Get the locale manager to use for i18n & date/time localization.
Definition: StelApp.hpp:98
void init(QSettings *conf)
Initialize core and all the modules.
bool getVisionModeNight() const
Get flag for activating night vision mode.
Definition: StelApp.hpp:208