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 "config.h"
24 
25 #include <QDeclarativeView>
26 #include <QCoreApplication>
27 #include <QEventLoop>
28 #include <QOpenGLContext>
29 
30 class QDeclarativeItem;
31 class QGLWidget;
32 class QMoveEvent;
33 class QResizeEvent;
34 class StelGuiBase;
35 class StelQGLWidget;
36 class QMoveEvent;
37 
41 class StelMainView : public QDeclarativeView
42 {
43  friend class StelGuiItem;
44  friend class StelSkyItem;
45  Q_OBJECT
46  Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen)
47 
48 public:
49  StelMainView(QWidget* parent = NULL);
50  virtual ~StelMainView();
51 
53  void init(class QSettings* conf);
54  void deinit();
55 
58  void initTitleI18n();
59 
61  static StelMainView& getInstance() {Q_ASSERT(singleton); return *singleton;}
62 
64  void deinitGL();
66  void focusSky();
69  QGraphicsWidget* getGuiWidget() const {return guiWidget;}
70 public slots:
71 
73  void setFullScreen(bool);
74 
76  // Specific methods
83  void saveScreenShot(const QString& filePrefix="stellarium-", const QString& saveDir="");
84 
86  bool getFlagInvertScreenShotColors() const {return flagInvertScreenShotColors;}
88  void setFlagInvertScreenShotColors(bool b) {flagInvertScreenShotColors=b;}
89 
91  bool getFlagCursorTimeout() {return flagCursorTimeout;}
93  float getCursorTimeout() const {return cursorTimeout;}
95  void setFlagCursorTimeout(bool b) {flagCursorTimeout=b;}
97  void setCursorTimeout(float t) {cursorTimeout=t;}
98 
103  void setMinFps(float m) {minfps=m; minFpsChanged();}
105  float getMinFps() {return minfps;}
108  void setMaxFps(float m) {maxfps = m;}
110  float getMaxFps() {return maxfps;}
111 
112  void maxFpsSceneUpdate();
114  void updateScene();
115 
118  void thereWasAnEvent();
119 
120 protected:
121  virtual void mouseMoveEvent(QMouseEvent* event);
122  virtual void mousePressEvent(QMouseEvent* event);
123  virtual void mouseReleaseEvent(QMouseEvent* event);
124  virtual void keyPressEvent(QKeyEvent* event);
125  virtual void keyReleaseEvent(QKeyEvent* event);
126  virtual void wheelEvent(QWheelEvent* wheelEvent);
127  virtual void moveEvent(QMoveEvent* event);
128  virtual void closeEvent(QCloseEvent* event);
129 
132  virtual void drawBackground(QPainter* painter, const QRectF &rect);
133 
134 signals:
138  void screenshotRequested(void);
139 
140 private slots:
141  // Do the actual screenshot generation in the main thread with this method.
142  void doScreenshot(void);
143 
144  void minFpsChanged();
145 
146 private:
148  void startMainLoop();
149 
150  QString getSupportedOpenGLVersion() const;
152  void dumpOpenGLdiagnostics() const;
153 
155  static StelMainView* singleton;
156 
159  QGraphicsWidget *guiWidget;
160  QDeclarativeItem* skyItem;
161 
163  StelQGLWidget* glWidget;
164  StelGuiBase* gui;
165  class StelApp* stelApp;
166 
167  bool flagInvertScreenShotColors;
168 
169  QString screenShotPrefix;
170  QString screenShotDir;
171 
172  // Number of second before the mouse cursor disappears
173  float cursorTimeout;
174  bool flagCursorTimeout;
175 
176  double lastEventTimeSec;
177 
178  QTimer* minFpsTimer;
179  bool flagMaxFpsUpdatePending;
181  float minfps;
183  float maxfps;
184 };
185 
186 
187 #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:62
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.