Stellarium 0.13.3
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 <QDeclarativeView>
24 #include <QCoreApplication>
25 #include <QEventLoop>
26 #include <QOpenGLContext>
27 
28 // This define (only used here and in StelMainView.cpp) is temporarily used
29 // to allow uncompromised compiling while the migration to the new QOpenGL... classes
30 // has not been done. As soon as Qt5.4 is out, we should finish this migration process!
31 #define STEL_USE_NEW_OPENGL_WIDGETS 0
32 
33 class QDeclarativeItem;
34 #if STEL_USE_NEW_OPENGL_WIDGETS
35 class QOpenGLWidget;
36 class StelQOpenGLWidget;
37 #else
38 class QGLWidget;
39 class StelQGLWidget;
40 #endif
41 class QMoveEvent;
42 class QResizeEvent;
43 class StelGuiBase;
44 class QMoveEvent;
45 class QSettings;
46 
50 class StelMainView : public QDeclarativeView
51 {
52  friend class StelGuiItem;
53  friend class StelSkyItem;
54  Q_OBJECT
55  Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen)
56 
57 public:
58  StelMainView(QWidget* parent = NULL);
59  virtual ~StelMainView();
60 
62  void init(class QSettings* conf);
63  void deinit();
64 
67  void initTitleI18n();
68 
70  static StelMainView& getInstance() {Q_ASSERT(singleton); return *singleton;}
71 
73  void deinitGL();
75  void focusSky();
78  QGraphicsWidget* getGuiWidget() const {return guiWidget;}
80  QPoint getMousePos();
81 public slots:
82 
84  void setFullScreen(bool);
85 
87  // Specific methods
94  void saveScreenShot(const QString& filePrefix="stellarium-", const QString& saveDir="");
95 
97  bool getFlagInvertScreenShotColors() const {return flagInvertScreenShotColors;}
99  void setFlagInvertScreenShotColors(bool b) {flagInvertScreenShotColors=b;}
100 
102  bool getFlagCursorTimeout() {return flagCursorTimeout;}
104  float getCursorTimeout() const {return cursorTimeout;}
106  void setFlagCursorTimeout(bool b) {flagCursorTimeout=b;}
108  void setCursorTimeout(float t) {cursorTimeout=t;}
109 
114  void setMinFps(float m) {minfps=m; minFpsChanged();}
116  float getMinFps() {return minfps;}
119  void setMaxFps(float m) {maxfps = m;}
121  float getMaxFps() {return maxfps;}
122 
123  void maxFpsSceneUpdate();
125  void updateScene();
126 
129  void thereWasAnEvent();
130 
131 protected:
132  virtual void mouseMoveEvent(QMouseEvent* event);
133  virtual void mousePressEvent(QMouseEvent* event);
134  virtual void mouseReleaseEvent(QMouseEvent* event);
135  virtual void keyPressEvent(QKeyEvent* event);
136  virtual void keyReleaseEvent(QKeyEvent* event);
137  virtual void wheelEvent(QWheelEvent* wheelEvent);
138  virtual void moveEvent(QMoveEvent* event);
139  virtual void closeEvent(QCloseEvent* event);
140 
143  virtual void drawBackground(QPainter* painter, const QRectF &rect);
144 
145 signals:
149  void screenshotRequested(void);
150 
151 private slots:
152  // Do the actual screenshot generation in the main thread with this method.
153  void doScreenshot(void);
154 
155  void minFpsChanged();
156 
157 private:
159  void startMainLoop();
160 
162  void dumpOpenGLdiagnostics() const;
165 #if STEL_USE_NEW_OPENGL_WIDGETS
166  void processOpenGLdiagnosticsAndWarnings(QSettings *conf, StelQOpenGLWidget* glWidget) const;
167 #else
168  void processOpenGLdiagnosticsAndWarnings(QSettings *conf, StelQGLWidget* glWidget) const;
169 #endif
170 
172  static StelMainView* singleton;
173 
176  QGraphicsWidget *guiWidget;
177  QDeclarativeItem* skyItem;
178 
180 #if STEL_USE_NEW_OPENGL_WIDGETS
181  StelQOpenGLWidget* glWidget;
182 #else
183  StelQGLWidget* glWidget;
184 #endif
185  StelGuiBase* gui;
186  class StelApp* stelApp;
187 
188  bool flagInvertScreenShotColors;
189 
190  QString screenShotPrefix;
191  QString screenShotDir;
192 
193  // Number of second before the mouse cursor disappears
194  float cursorTimeout;
195  bool flagCursorTimeout;
196 
197  double lastEventTimeSec;
198 
199  QTimer* minFpsTimer;
200  bool flagMaxFpsUpdatePending;
202  float minfps;
204  float maxfps;
205 };
206 
207 
208 #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.
QPoint getMousePos()
Return mouse position coordinates.
void setCursorTimeout(float t)
Set the mouse cursor timeout in seconds.
void updateScene()
Updates the scene and process all events.
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
virtual void drawBackground(QPainter *painter, const QRectF &rect)
Update the mouse pointer state and schedule next redraw.
bool getFlagInvertScreenShotColors() const
Get whether colors are inverted when saving screenshot.
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.
Reimplement a QGraphicsView for Stellarium.
void setFullScreen(bool)
Set whether fullscreen is activated or not.
void init(class QSettings *conf)
Start the main initialization of Stellarium.
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:60
void saveScreenShot(const QString &filePrefix="stellarium-", const QString &saveDir="")
Save a screen shot.
void thereWasAnEvent()
Notify that an event was handled by the program and therefore the FPS should be maximized for a coupl...
float getMinFps()
Get the current minimum frames per second.