Stellarium 0.13.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 <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;}
79 public slots:
80 
82  void setFullScreen(bool);
83 
85  // Specific methods
92  void saveScreenShot(const QString& filePrefix="stellarium-", const QString& saveDir="");
93 
95  bool getFlagInvertScreenShotColors() const {return flagInvertScreenShotColors;}
97  void setFlagInvertScreenShotColors(bool b) {flagInvertScreenShotColors=b;}
98 
100  bool getFlagCursorTimeout() {return flagCursorTimeout;}
102  float getCursorTimeout() const {return cursorTimeout;}
104  void setFlagCursorTimeout(bool b) {flagCursorTimeout=b;}
106  void setCursorTimeout(float t) {cursorTimeout=t;}
107 
112  void setMinFps(float m) {minfps=m; minFpsChanged();}
114  float getMinFps() {return minfps;}
117  void setMaxFps(float m) {maxfps = m;}
119  float getMaxFps() {return maxfps;}
120 
121  void maxFpsSceneUpdate();
123  void updateScene();
124 
127  void thereWasAnEvent();
128 
129 protected:
130  virtual void mouseMoveEvent(QMouseEvent* event);
131  virtual void mousePressEvent(QMouseEvent* event);
132  virtual void mouseReleaseEvent(QMouseEvent* event);
133  virtual void keyPressEvent(QKeyEvent* event);
134  virtual void keyReleaseEvent(QKeyEvent* event);
135  virtual void wheelEvent(QWheelEvent* wheelEvent);
136  virtual void moveEvent(QMoveEvent* event);
137  virtual void closeEvent(QCloseEvent* event);
138 
141  virtual void drawBackground(QPainter* painter, const QRectF &rect);
142 
143 signals:
147  void screenshotRequested(void);
148 
149 private slots:
150  // Do the actual screenshot generation in the main thread with this method.
151  void doScreenshot(void);
152 
153  void minFpsChanged();
154 
155 private:
157  void startMainLoop();
158 
160  void dumpOpenGLdiagnostics() const;
163  void processOpenGLdiagnosticsAndWarnings(QSettings *conf) const;
164 
166  static StelMainView* singleton;
167 
170  QGraphicsWidget *guiWidget;
171  QDeclarativeItem* skyItem;
172 
174 #if STEL_USE_NEW_OPENGL_WIDGETS
175  StelQOpenGLWidget* glWidget;
176 #else
177  StelQGLWidget* glWidget;
178 #endif
179  StelGuiBase* gui;
180  class StelApp* stelApp;
181 
182  bool flagInvertScreenShotColors;
183 
184  QString screenShotPrefix;
185  QString screenShotDir;
186 
187  // Number of second before the mouse cursor disappears
188  float cursorTimeout;
189  bool flagCursorTimeout;
190 
191  double lastEventTimeSec;
192 
193  QTimer* minFpsTimer;
194  bool flagMaxFpsUpdatePending;
196  float minfps;
198  float maxfps;
199 };
200 
201 
202 #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.
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:32
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:61
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.