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 class QDeclarativeItem;
29 class QGLWidget;
30 class QMoveEvent;
31 class QResizeEvent;
32 class StelGuiBase;
33 class StelQGLWidget;
34 class QMoveEvent;
35 
39 class StelMainView : public QDeclarativeView
40 {
41  friend class StelGuiItem;
42  friend class StelSkyItem;
43  Q_OBJECT
44  Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen)
45 
46 public:
47  StelMainView(QWidget* parent = NULL);
48  virtual ~StelMainView();
49 
51  void init(class QSettings* conf);
52  void deinit();
53 
56  void initTitleI18n();
57 
59  static StelMainView& getInstance() {Q_ASSERT(singleton); return *singleton;}
60 
62  void deinitGL();
64  void focusSky();
67  QGraphicsWidget* getGuiWidget() const {return guiWidget;}
68 public slots:
69 
71  void setFullScreen(bool);
72 
74  // Specific methods
81  void saveScreenShot(const QString& filePrefix="stellarium-", const QString& saveDir="");
82 
84  bool getFlagInvertScreenShotColors() const {return flagInvertScreenShotColors;}
86  void setFlagInvertScreenShotColors(bool b) {flagInvertScreenShotColors=b;}
87 
89  bool getFlagCursorTimeout() {return flagCursorTimeout;}
91  float getCursorTimeout() const {return cursorTimeout;}
93  void setFlagCursorTimeout(bool b) {flagCursorTimeout=b;}
95  void setCursorTimeout(float t) {cursorTimeout=t;}
96 
101  void setMinFps(float m) {minfps=m; minFpsChanged();}
103  float getMinFps() {return minfps;}
106  void setMaxFps(float m) {maxfps = m;}
108  float getMaxFps() {return maxfps;}
109 
110  void maxFpsSceneUpdate();
112  void updateScene();
113 
116  void thereWasAnEvent();
117 
118 protected:
119  virtual void mouseMoveEvent(QMouseEvent* event);
120  virtual void mousePressEvent(QMouseEvent* event);
121  virtual void mouseReleaseEvent(QMouseEvent* event);
122  virtual void keyPressEvent(QKeyEvent* event);
123  virtual void keyReleaseEvent(QKeyEvent* event);
124  virtual void wheelEvent(QWheelEvent* wheelEvent);
125  virtual void moveEvent(QMoveEvent* event);
126  virtual void closeEvent(QCloseEvent* event);
127 
130  virtual void drawBackground(QPainter* painter, const QRectF &rect);
131 
132 signals:
136  void screenshotRequested(void);
137 
138 private slots:
139  // Do the actual screenshot generation in the main thread with this method.
140  void doScreenshot(void);
141 
142  void minFpsChanged();
143 
144 private:
146  void startMainLoop();
147 
148  QString getSupportedOpenGLVersion() const;
150  void dumpOpenGLdiagnostics() const;
151 
153  static StelMainView* singleton;
154 
157  QGraphicsWidget *guiWidget;
158  QDeclarativeItem* skyItem;
159 
161  StelQGLWidget* glWidget;
162  StelGuiBase* gui;
163  class StelApp* stelApp;
164 
165  bool flagInvertScreenShotColors;
166 
167  QString screenShotPrefix;
168  QString screenShotDir;
169 
170  // Number of second before the mouse cursor disappears
171  float cursorTimeout;
172  bool flagCursorTimeout;
173 
174  double lastEventTimeSec;
175 
176  QTimer* minFpsTimer;
177  bool flagMaxFpsUpdatePending;
179  float minfps;
181  float maxfps;
182 };
183 
184 
185 #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.