Stellarium 0.12.4
StelMainGraphicsView.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 <QGraphicsView>
24 #include <QCoreApplication>
25 #include <QEventLoop>
26 
27 class QGLWidget;
28 class QResizeEvent;
29 class StelGuiBase;
31 class StelScriptMgr;
32 class StelQGLWidget;
33 
37 class StelMainGraphicsView : public QGraphicsView
38 {
39 Q_OBJECT
40 public:
41  StelMainGraphicsView(QWidget* parent);
42  virtual ~StelMainGraphicsView();
43 
45  void init(class QSettings* conf);
46 
48  static StelMainGraphicsView& getInstance() {Q_ASSERT(singleton); return *singleton;}
49 
51  void deinit();
52 
55  class StelAppGraphicsWidget* getStelAppGraphicsWidget() {return mainSkyItem;}
56 
59  QGraphicsWidget* getTopLevelGraphicsWidget() {return backItem;}
60 
61 #ifndef DISABLE_SCRIPTING
62 
63  StelMainScriptAPIProxy* getMainScriptAPIProxy() {return scriptAPIProxy;}
65  StelScriptMgr& getScriptMgr() {return *scriptMgr;}
66 #endif
67 
68 public slots:
69 
71  // Specific methods
78  void saveScreenShot(const QString& filePrefix="stellarium-", const QString& saveDir="");
79 
81  bool getFlagInvertScreenShotColors() const {return flagInvertScreenShotColors;}
83  void setFlagInvertScreenShotColors(bool b) {flagInvertScreenShotColors=b;}
84 
86  bool getFlagCursorTimeout() {return flagCursorTimeout;}
88  float getCursorTimeout() const {return cursorTimeout;}
90  void setFlagCursorTimeout(bool b) {flagCursorTimeout=b;}
92  void setCursorTimeout(float t) {cursorTimeout=t;}
93 
98  void setMinFps(float m) {minfps=m; minFpsChanged();}
100  float getMinFps() {return minfps;}
103  void setMaxFps(float m) {maxfps = m;}
105  float getMaxFps() {return maxfps;}
106 
108  void updateScene() {
109  scene()->update();
110  }
111 
112 protected:
113  virtual void resizeEvent(QResizeEvent* event);
114  virtual void mouseMoveEvent(QMouseEvent* event);
115  virtual void mousePressEvent(QMouseEvent* event);
116  virtual void mouseReleaseEvent(QMouseEvent* event);
117  virtual void keyPressEvent(QKeyEvent* event);
118  virtual void keyReleaseEvent(QKeyEvent* event);
119  virtual void wheelEvent(QWheelEvent* wheelEvent);
120 
123  virtual void drawBackground(QPainter* painter, const QRectF &rect);
124 
125 signals:
129  void screenshotRequested(void);
130 
131 private slots:
132  // Do the actual screenshot generation in the main thread with this method.
133  void doScreenshot(void);
134 
135  void minFpsChanged();
136 
137 private:
139  void startMainLoop();
140 
142  static StelMainGraphicsView* singleton;
143  QGraphicsWidget* backItem;
144  class StelAppGraphicsWidget* mainSkyItem;
145 
147  class StelRenderer* renderer;
148 
149  StelGuiBase* gui;
150 
151 #ifndef DISABLE_SCRIPTING
152  // The script API proxy object (for bridging threads)
153  StelMainScriptAPIProxy* scriptAPIProxy;
154 
155  // The script manager based on Qt script engine
156  StelScriptMgr* scriptMgr;
157 #endif
158 
159  bool wasDeinit;
160 
161  bool flagInvertScreenShotColors;
162 
163  QString screenShotPrefix;
164  QString screenShotDir;
165 
166  // Number of second before the mouse cursor disappears
167  float cursorTimeout;
168  bool flagCursorTimeout;
169 
172  void thereWasAnEvent();
173 
174  double lastEventTimeSec;
175 
176  QTimer* minFpsTimer;
178  float minfps;
180  float maxfps;
181 };
182 
183 
184 #endif // _STELMAINGRAPHICSVIEW_HPP_