Stellarium 0.15.0
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 NOTIFY fullScreenChanged)
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  void setFocusOnSky();
87 
89  // Specific methods
97  void saveScreenShot(const QString& filePrefix="stellarium-", const QString& saveDir="", const bool overwrite=false);
98 
100  bool getFlagInvertScreenShotColors() const {return flagInvertScreenShotColors;}
102  void setFlagInvertScreenShotColors(bool b) {flagInvertScreenShotColors=b;}
103 
105  bool getFlagOverwriteScreenShots() const {return flagOverwriteScreenshots;}
107  void setFlagOverwriteScreenShots(bool b) {flagOverwriteScreenshots=b;}
108 
110  bool getFlagCursorTimeout() {return flagCursorTimeout;}
112  float getCursorTimeout() const {return cursorTimeout;}
114  void setFlagCursorTimeout(bool b) {flagCursorTimeout=b;}
116  void setCursorTimeout(float t) {cursorTimeout=t;}
117 
122  void setMinFps(float m) {minfps=m; minFpsChanged();}
124  float getMinFps() {return minfps;}
127  void setMaxFps(float m) {maxfps = m;}
129  float getMaxFps() {return maxfps;}
130 
131  void maxFpsSceneUpdate();
133  void updateScene();
134 
137  void thereWasAnEvent();
138 
139 protected:
140  virtual void mouseMoveEvent(QMouseEvent* event);
141  virtual void mousePressEvent(QMouseEvent* event);
142  virtual void mouseReleaseEvent(QMouseEvent* event);
143  virtual void keyPressEvent(QKeyEvent* event);
144  virtual void keyReleaseEvent(QKeyEvent* event);
145  virtual void wheelEvent(QWheelEvent* wheelEvent);
146  virtual void moveEvent(QMoveEvent* event);
147  virtual void closeEvent(QCloseEvent* event);
148  virtual void resizeEvent(QResizeEvent* event);
149 
152  virtual void drawBackground(QPainter* painter, const QRectF &rect);
153 
154 signals:
158  void screenshotRequested(void);
159  void fullScreenChanged(bool b);
160 
161 private slots:
162  // Do the actual screenshot generation in the main thread with this method.
163  void doScreenshot(void);
164  void minFpsChanged();
165  void updateNightModeProperty();
166 
167 private:
169  void startMainLoop();
170 
172  void dumpOpenGLdiagnostics() const;
175 #if STEL_USE_NEW_OPENGL_WIDGETS
176  void processOpenGLdiagnosticsAndWarnings(QSettings *conf, StelQOpenGLWidget* glWidget) const;
177 #else
178  void processOpenGLdiagnosticsAndWarnings(QSettings *conf, StelQGLWidget* glWidget) const;
179 #endif
180 
182  static StelMainView* singleton;
183 
184  QGraphicsWidget* rootItem;
185  QGraphicsWidget* skyItem;
186  QGraphicsWidget* guiItem;
187  QGraphicsEffect* nightModeEffect;
188 
190 #if STEL_USE_NEW_OPENGL_WIDGETS
191  StelQOpenGLWidget* glWidget;
192 #else
193  StelQGLWidget* glWidget;
194 #endif
195  StelGuiBase* gui;
196  class StelApp* stelApp;
197 
198  bool flagInvertScreenShotColors;
199  bool flagOverwriteScreenshots;
200 
201  QString screenShotPrefix;
202  QString screenShotDir;
203 
204  // Number of second before the mouse cursor disappears
205  float cursorTimeout;
206  bool flagCursorTimeout;
207 
208  double lastEventTimeSec;
209 
210  QTimer* minFpsTimer;
211  bool flagMaxFpsUpdatePending;
213  float minfps;
215  float maxfps;
216 };
217 
218 
219 #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 setFocusOnSky()
Set focus on the sky.
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:61
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.