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 
112  void updateScene();
113 
114 protected:
115  virtual void mouseMoveEvent(QMouseEvent* event);
116  virtual void mousePressEvent(QMouseEvent* event);
117  virtual void mouseReleaseEvent(QMouseEvent* event);
118  virtual void keyPressEvent(QKeyEvent* event);
119  virtual void keyReleaseEvent(QKeyEvent* event);
120  virtual void wheelEvent(QWheelEvent* wheelEvent);
121  virtual void moveEvent(QMoveEvent* event);
122 
125  virtual void drawBackground(QPainter* painter, const QRectF &rect);
126 
127 signals:
131  void screenshotRequested(void);
132 
133 private slots:
134  // Do the actual screenshot generation in the main thread with this method.
135  void doScreenshot(void);
136 
137  void minFpsChanged();
138 
139 private:
141  void startMainLoop();
142 
143  QString getSupportedOpenGLVersion() const;
144 
146  static StelMainView* singleton;
147 
150  QGraphicsWidget *guiWidget;
151  QDeclarativeItem* skyItem;
152 
154  StelQGLWidget* glWidget;
155  StelGuiBase* gui;
156  class StelApp* stelApp;
157 
158  bool flagInvertScreenShotColors;
159 
160  QString screenShotPrefix;
161  QString screenShotDir;
162 
163  // Number of second before the mouse cursor disappears
164  float cursorTimeout;
165  bool flagCursorTimeout;
166 
169  void thereWasAnEvent();
170 
171  double lastEventTimeSec;
172 
173  QTimer* minFpsTimer;
175  float minfps;
177  float maxfps;
178 };
179 
180 
181 #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.
Definition: StelMainView.hpp:94
void setCursorTimeout(float t)
Set the mouse cursor timeout in seconds.
Definition: StelMainView.hpp:96
void updateScene()
Updates the scene and process all events.
void setMinFps(float m)
Set the minimum frames per second.
Definition: StelMainView.hpp:102
void screenshotRequested(void)
emitted when saveScreenShot is requested with saveScreenShot().
static StelMainView & getInstance()
Get the StelMainView singleton instance.
Definition: StelMainView.hpp:60
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.
Definition: StelMainView.hpp:85
float getCursorTimeout() const
Get the mouse cursor timeout in seconds.
Definition: StelMainView.hpp:92
bool getFlagCursorTimeout()
Get the state of the mouse cursor timeout flag.
Definition: StelMainView.hpp:90
void setMaxFps(float m)
Set the maximum frames per second.
Definition: StelMainView.hpp:107
Reimplement a QGraphicsView for Stellarium.
Definition: StelMainView.hpp:40
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.
Definition: StelMainView.hpp:87
float getMaxFps()
Get the current maximum frames per second.
Definition: StelMainView.hpp:109
QGraphicsWidget * getGuiWidget() const
Return the parent gui widget, this should be used as parent to all the StelDialog instances...
Definition: StelMainView.hpp:68
Singleton main Stellarium application class.
Definition: StelApp.hpp:60
void saveScreenShot(const QString &filePrefix="stellarium-", const QString &saveDir="")
Save a screen shot.
float getMinFps()
Get the current minimum frames per second.
Definition: StelMainView.hpp:104