Stellarium 0.14.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 <QCoreApplication>
24 #include <QGraphicsView>
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 #if STEL_USE_NEW_OPENGL_WIDGETS
34 class QOpenGLWidget;
35 class StelQOpenGLWidget;
36 #else
37 class QGLWidget;
38 class StelQGLWidget;
39 #endif
40 class QMoveEvent;
41 class QResizeEvent;
42 class StelGuiBase;
43 class QMoveEvent;
44 class QSettings;
45 
49 class StelMainView : public QGraphicsView
50 {
51  friend class StelGuiItem;
52  friend class StelSkyItem;
53  Q_OBJECT
54  Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen)
55 
56 public:
57  StelMainView(QWidget* parent = NULL);
58  virtual ~StelMainView();
59 
61  void init(class QSettings* conf);
62  void deinit();
63 
66  void initTitleI18n();
67 
69  static StelMainView& getInstance() {Q_ASSERT(singleton); return *singleton;}
70 
72  void deinitGL();
74  void focusSky();
77  QGraphicsWidget* getGuiWidget() const {return guiItem;}
79  QPoint getMousePos();
80 public slots:
81 
83  void setFullScreen(bool);
84 
86  // Specific methods
94  void saveScreenShot(const QString& filePrefix="stellarium-", const QString& saveDir="", const bool overwrite=false);
95 
97  bool getFlagInvertScreenShotColors() const {return flagInvertScreenShotColors;}
99  void setFlagInvertScreenShotColors(bool b) {flagInvertScreenShotColors=b;}
100 
102  bool getFlagOverwriteScreenShots() const {return flagOverwriteScreenshots;}
104  void setFlagOverwriteScreenShots(bool b) {flagOverwriteScreenshots=b;}
105 
107  bool getFlagCursorTimeout() {return flagCursorTimeout;}
109  float getCursorTimeout() const {return cursorTimeout;}
111  void setFlagCursorTimeout(bool b) {flagCursorTimeout=b;}
113  void setCursorTimeout(float t) {cursorTimeout=t;}
114 
119  void setMinFps(float m) {minfps=m; minFpsChanged();}
121  float getMinFps() {return minfps;}
124  void setMaxFps(float m) {maxfps = m;}
126  float getMaxFps() {return maxfps;}
127 
128  void maxFpsSceneUpdate();
130  void updateScene();
131 
134  void thereWasAnEvent();
135 
136 protected:
137  virtual void mouseMoveEvent(QMouseEvent* event);
138  virtual void mousePressEvent(QMouseEvent* event);
139  virtual void mouseReleaseEvent(QMouseEvent* event);
140  virtual void keyPressEvent(QKeyEvent* event);
141  virtual void keyReleaseEvent(QKeyEvent* event);
142  virtual void wheelEvent(QWheelEvent* wheelEvent);
143  virtual void moveEvent(QMoveEvent* event);
144  virtual void closeEvent(QCloseEvent* event);
145  virtual void resizeEvent(QResizeEvent* event);
146 
149  virtual void drawBackground(QPainter* painter, const QRectF &rect);
150 
151 signals:
155  void screenshotRequested(void);
156 
157 private slots:
158  // Do the actual screenshot generation in the main thread with this method.
159  void doScreenshot(void);
160  void minFpsChanged();
161  void updateNightModeProperty();
162 
163 private:
165  void startMainLoop();
166 
168  void dumpOpenGLdiagnostics() const;
171 #if STEL_USE_NEW_OPENGL_WIDGETS
172  void processOpenGLdiagnosticsAndWarnings(QSettings *conf, StelQOpenGLWidget* glWidget) const;
173 #else
174  void processOpenGLdiagnosticsAndWarnings(QSettings *conf, StelQGLWidget* glWidget) const;
175 #endif
176 
178  static StelMainView* singleton;
179 
180  QGraphicsWidget* rootItem;
181  QGraphicsWidget* skyItem;
182  QGraphicsWidget* guiItem;
183  QGraphicsEffect* nightModeEffect;
184 
186 #if STEL_USE_NEW_OPENGL_WIDGETS
187  StelQOpenGLWidget* glWidget;
188 #else
189  StelQGLWidget* glWidget;
190 #endif
191  StelGuiBase* gui;
192  class StelApp* stelApp;
193 
194  bool flagInvertScreenShotColors;
195  bool flagOverwriteScreenshots;
196 
197  QString screenShotPrefix;
198  QString screenShotDir;
199 
200  // Number of second before the mouse cursor disappears
201  float cursorTimeout;
202  bool flagCursorTimeout;
203 
204  double lastEventTimeSec;
205 
206  QTimer* minFpsTimer;
207  bool flagMaxFpsUpdatePending;
209  float minfps;
211  float maxfps;
212 };
213 
214 
215 #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.
void updateScene()
Updates the scene and process all events.
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
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.
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.
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 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.