Stellarium 0.15.2
StelMainView.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2007 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 _STELMAINGRAPHICSVIEW_HPP_
21 #define _STELMAINGRAPHICSVIEW_HPP_
22 
23 #include <QCoreApplication>
24 #include <QGraphicsView>
25 #include <QEventLoop>
26 #include <QOpenGLContext>
27 #include <QTimer>
28 #ifdef OPENGL_DEBUG_LOGGING
29 #include <QOpenGLDebugMessage>
30 #endif
31 
32 class StelGLWidget;
33 class StelGraphicsScene;
34 class QMoveEvent;
35 class QResizeEvent;
36 class StelGuiBase;
37 class QMoveEvent;
38 class QSettings;
39 
43 class StelMainView : public QGraphicsView
44 {
45  friend class StelGuiItem;
46  friend class StelRootItem;
47  friend class StelGraphicsScene;
48  friend class NightModeGraphicsEffect;
49  Q_OBJECT
50  Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenChanged)
51 
52 public:
54  struct GLInfo
55  {
56  QString vendor;
57  QString renderer;
58  QOpenGLContext* mainContext;
59  QOpenGLFunctions* functions;
60  };
61 
62  StelMainView(QSettings* settings);
63  virtual ~StelMainView();
64 
66  void init();
67  void deinit();
68 
71  void initTitleI18n();
72 
74  static StelMainView& getInstance() {Q_ASSERT(singleton); return *singleton;}
75 
77  void deinitGL();
78 
81  QGraphicsWidget* getGuiWidget() const {return guiItem;}
83  QPoint getMousePos();
84 
89  QOpenGLContext* glContext() const;
92  void glContextMakeCurrent();
94  void glContextDoneCurrent();
95 
97  GLInfo getGLInformation() const { return glInfo; }
98 public slots:
99 
101  void setFullScreen(bool);
102 
104  void focusSky();
105 
107  // Specific methods
115  void saveScreenShot(const QString& filePrefix="stellarium-", const QString& saveDir="", const bool overwrite=false);
116 
118  bool getFlagInvertScreenShotColors() const {return flagInvertScreenShotColors;}
120  void setFlagInvertScreenShotColors(bool b) {flagInvertScreenShotColors=b;}
121 
123  bool getFlagOverwriteScreenShots() const {return flagOverwriteScreenshots;}
125  void setFlagOverwriteScreenShots(bool b) {flagOverwriteScreenshots=b;}
126 
128  bool getFlagCursorTimeout() {return flagCursorTimeout;}
130  float getCursorTimeout() const {return cursorTimeout;}
132  void setFlagCursorTimeout(bool b) {flagCursorTimeout=b;}
134  void setCursorTimeout(float t) {cursorTimeout=t;}
135 
140  void setMinFps(float m) {minfps=m; minFpsTimer->setInterval(1000/minfps);}
142  float getMinFps() {return minfps;}
146  void setMaxFps(float m) {maxfps = m;}
148  float getMaxFps() {return maxfps;}
149 
152  void thereWasAnEvent();
153 
157  bool needsMaxFPS() const;
158 
159 protected:
162  virtual void moveEvent(QMoveEvent* event) Q_DECL_OVERRIDE;
164  virtual void closeEvent(QCloseEvent* event) Q_DECL_OVERRIDE;
167  virtual void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
168 signals:
174  void screenshotRequested(void);
175  void fullScreenChanged(bool b);
176 private slots:
177  // Do the actual screenshot generation in the main thread with this method.
178  void doScreenshot(void);
179  void minFPSUpdate();
180 #ifdef OPENGL_DEBUG_LOGGING
181  void logGLMessage(const QOpenGLDebugMessage& debugMessage);
182  void contextDestroyed();
183 #endif
184  void updateNightModeProperty(bool b);
185 
186 private:
188  void drawEnded();
192  QSurfaceFormat getDesiredGLFormat() const;
194  void dumpOpenGLdiagnostics() const;
197  void processOpenGLdiagnosticsAndWarnings(QSettings *conf, QOpenGLContext* context) const;
198 
200  static StelMainView* singleton;
201 
202  GLInfo glInfo;
203 
204  QSettings* configuration;
205 
206  class StelRootItem* rootItem;
207  QGraphicsWidget* guiItem;
208  QGraphicsEffect* nightModeEffect;
209 
212  StelGLWidget* glWidget;
214  StelGraphicsScene* stelScene;
215 
216  StelGuiBase* gui;
217  class StelApp* stelApp;
218 
219  bool updateQueued;
220  bool flagInvertScreenShotColors;
221  bool flagOverwriteScreenshots;
222 
223  QString screenShotPrefix;
224  QString screenShotDir;
225 
226  // Number of second before the mouse cursor disappears
227  float cursorTimeout;
228  bool flagCursorTimeout;
229 
230  double lastEventTimeSec;
231 
233  float minfps;
235  float maxfps;
236  QTimer* minFpsTimer;
237 
238 #ifdef OPENGL_DEBUG_LOGGING
239  QOpenGLDebugLogger* glLogger;
240 #endif
241 };
242 
243 
244 #endif // _STELMAINGRAPHICSVIEW_HPP_
void focusSky()
Return focus to the sky item. To be used when we close a dialog.
void setFlagCursorTimeout(bool b)
Get the state of the mouse cursor timeout flag.
bool getFlagOverwriteScreenShots() const
Get whether existing files are overwritten when saving screenshot.
QPoint getMousePos()
Return mouse position coordinates.
void setCursorTimeout(float t)
Set the mouse cursor timeout in seconds.
Contains some basic info about the OpenGL context used.
void setFlagOverwriteScreenShots(bool b)
Set whether existing files are overwritten when saving screenshot.
void setMinFps(float m)
Set the minimum frames per second.
void screenshotRequested(void)
emitted when saveScreenShot is requested with saveScreenShot().
static StelMainView & getInstance()
Get the StelMainView singleton instance.
void initTitleI18n()
Set the application title for the current language.
Abstract class defining the base interface for all GUIs.
Definition: StelGuiBase.hpp:30
void glContextMakeCurrent()
Make the main GL context (the one returned from glContext()) current on the main view surface...
virtual void moveEvent(QMoveEvent *event) Q_DECL_OVERRIDE
Hack to determine current monitor pixel ratio.
bool needsMaxFPS() const
Determines if we should render as fast as possible, or limit the FPS.
bool getFlagInvertScreenShotColors() const
Get whether colors are inverted when saving screenshot.
void saveScreenShot(const QString &filePrefix="stellarium-", const QString &saveDir="", const bool overwrite=false)
Save a screen shot.
float getCursorTimeout() const
Get the mouse cursor timeout in seconds.
bool getFlagCursorTimeout()
Get the state of the mouse cursor timeout flag.
void setMaxFps(float m)
Set the maximum frames per second.
void glContextDoneCurrent()
Releases the main GL context.
Reimplement a QGraphicsView for Stellarium.
void setFullScreen(bool)
Set whether fullscreen is activated or not.
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
Handle window closed event, calling StelApp::quit()
virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE
Handle window resized events, and change the size of the underlying QGraphicsScene to be the same...
GLInfo getGLInformation() const
Returns the information about the GL context, this does not require the context to be active...
void deinitGL()
Delete openGL textures (to call before the GLContext disappears)
void setFlagInvertScreenShotColors(bool b)
Set whether colors should be inverted when saving screenshot.
float getMaxFps()
Get the current maximum frames per second.
QGraphicsWidget * getGuiWidget() const
Return the parent gui widget, this should be used as parent to all the StelDialog instances...
Singleton main Stellarium application class.
Definition: StelApp.hpp:68
void thereWasAnEvent()
Notify that an event was handled by the program and therefore the FPS should be maximized for a coupl...
QOpenGLContext * glContext() const
Returns the main application OpenGL context, which should be used for all drawing Stellarium does...
float getMinFps()
Get the current minimum frames per second.
void init()
Start the main initialization of Stellarium.