Stellarium  0.16.1
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 
160  void setFlagUseButtonsBackground(bool b) { flagUseButtonsBackground=b; }
162  bool getFlagUseButtonsBackground() { return flagUseButtonsBackground; }
163 
164 protected:
167  virtual void moveEvent(QMoveEvent* event) Q_DECL_OVERRIDE;
169  virtual void closeEvent(QCloseEvent* event) Q_DECL_OVERRIDE;
172  virtual void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
173 signals:
179  void screenshotRequested(void);
180  void fullScreenChanged(bool b);
184  void reloadShadersRequested();
185 
186  void updateIconsRequested();
187 
188 private slots:
189  // Do the actual screenshot generation in the main thread with this method.
190  void doScreenshot(void);
191  void minFPSUpdate();
192 #ifdef OPENGL_DEBUG_LOGGING
193  void logGLMessage(const QOpenGLDebugMessage& debugMessage);
194  void contextDestroyed();
195 #endif
196  void updateNightModeProperty(bool b);
197 
198  void reloadShaders();
199 
200 private:
202  void drawEnded();
206  QSurfaceFormat getDesiredGLFormat() const;
208  void dumpOpenGLdiagnostics() const;
211  void processOpenGLdiagnosticsAndWarnings(QSettings *conf, QOpenGLContext* context) const;
212 
214  static StelMainView* singleton;
215 
216  GLInfo glInfo;
217 
218  QSettings* configuration;
219 
220  class StelRootItem* rootItem;
221  QGraphicsWidget* guiItem;
222  QGraphicsEffect* nightModeEffect;
223 
226  StelGLWidget* glWidget;
228  StelGraphicsScene* stelScene;
229 
230  StelGuiBase* gui;
231  class StelApp* stelApp;
232 
233  bool updateQueued;
234  bool flagInvertScreenShotColors;
235  bool flagOverwriteScreenshots;
236 
237  QString screenShotPrefix;
238  QString screenShotDir;
239 
240  // Number of second before the mouse cursor disappears
241  float cursorTimeout;
242  bool flagCursorTimeout;
243 
244  bool flagUseButtonsBackground;
245 
246  double lastEventTimeSec;
247 
249  float minfps;
251  float maxfps;
252  QTimer* minFpsTimer;
253 
254 #ifdef OPENGL_DEBUG_LOGGING
255  QOpenGLDebugLogger* glLogger;
256 #endif
257 };
258 
259 
260 #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.
void reloadShadersRequested()
Emitted when the "Reload shaders" action is perfomed Interested objects should subscribe to this sign...
QPoint getMousePos()
Return mouse position coordinates.
void setFlagUseButtonsBackground(bool b)
Set the state of the flag of usage background for GUI buttons.
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
bool getFlagUseButtonsBackground()
Get the state of the flag of usage background for GUI buttons.
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.