Stellarium 0.13.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 "config.h"
24 
25 #include <QDeclarativeView>
26 #include <QCoreApplication>
27 #include <QEventLoop>
28 
29 class QDeclarativeItem;
30 class QGLWidget;
31 class QMoveEvent;
32 class QResizeEvent;
33 class StelGuiBase;
34 class StelQGLWidget;
35 class QMoveEvent;
36 
40 class StelMainView : public QDeclarativeView
41 {
42  friend class StelGuiItem;
43  friend class StelSkyItem;
44  Q_OBJECT
45  Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen)
46 
47 public:
48  StelMainView(QWidget* parent = NULL);
49  virtual ~StelMainView();
50 
52  void init(class QSettings* conf);
53  void deinit();
54 
57  void initTitleI18n();
58 
60  static StelMainView& getInstance() {Q_ASSERT(singleton); return *singleton;}
61 
63  void deinitGL();
65  void focusSky();
68  QGraphicsWidget* getGuiWidget() const {return guiWidget;}
69 public slots:
70 
72  void setFullScreen(bool);
73 
75  // Specific methods
82  void saveScreenShot(const QString& filePrefix="stellarium-", const QString& saveDir="");
83 
85  bool getFlagInvertScreenShotColors() const {return flagInvertScreenShotColors;}
87  void setFlagInvertScreenShotColors(bool b) {flagInvertScreenShotColors=b;}
88 
90  bool getFlagCursorTimeout() {return flagCursorTimeout;}
92  float getCursorTimeout() const {return cursorTimeout;}
94  void setFlagCursorTimeout(bool b) {flagCursorTimeout=b;}
96  void setCursorTimeout(float t) {cursorTimeout=t;}
97 
102  void setMinFps(float m) {minfps=m; minFpsChanged();}
104  float getMinFps() {return minfps;}
107  void setMaxFps(float m) {maxfps = m;}
109  float getMaxFps() {return maxfps;}
110 
111  void maxFpsSceneUpdate();
113  void updateScene();
114 
117  void thereWasAnEvent();
118 
119 protected:
120  virtual void mouseMoveEvent(QMouseEvent* event);
121  virtual void mousePressEvent(QMouseEvent* event);
122  virtual void mouseReleaseEvent(QMouseEvent* event);
123  virtual void keyPressEvent(QKeyEvent* event);
124  virtual void keyReleaseEvent(QKeyEvent* event);
125  virtual void wheelEvent(QWheelEvent* wheelEvent);
126  virtual void moveEvent(QMoveEvent* event);
127  virtual void closeEvent(QCloseEvent* event);
128 
131  virtual void drawBackground(QPainter* painter, const QRectF &rect);
132 
133 signals:
137  void screenshotRequested(void);
138 
139 private slots:
140  // Do the actual screenshot generation in the main thread with this method.
141  void doScreenshot(void);
142 
143  void minFpsChanged();
144 
145 private:
147  void startMainLoop();
148 
149  QString getSupportedOpenGLVersion() const;
150 
152  static StelMainView* singleton;
153 
156  QGraphicsWidget *guiWidget;
157  QDeclarativeItem* skyItem;
158 
160  StelQGLWidget* glWidget;
161  StelGuiBase* gui;
162  class StelApp* stelApp;
163 
164  bool flagInvertScreenShotColors;
165 
166  QString screenShotPrefix;
167  QString screenShotDir;
168 
169  // Number of second before the mouse cursor disappears
170  float cursorTimeout;
171  bool flagCursorTimeout;
172 
173  double lastEventTimeSec;
174 
175  QTimer* minFpsTimer;
176  bool flagMaxFpsUpdatePending;
178  float minfps;
180  float maxfps;
181 };
182 
183 
184 #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:60
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.