Stellarium 0.12.1
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 
110  #ifdef QT_MAC_USE_COCOA
111  //This call solves the problems with the qt event dispatcher. The stack grew huge and many events were discarded
112  //http://bugreports.qt.nokia.com/browse/QTBUG-7502
113  //The previous bug has been closed an fixed but this line is still needed. The patch didn't solve our problem
114  QCoreApplication::processEvents(QEventLoop::AllEvents);
115  #endif
116  scene()->update();
117  }
118 
119 protected:
120  virtual void resizeEvent(QResizeEvent* event);
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 
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 
149  static StelMainGraphicsView* singleton;
150  QGraphicsWidget* backItem;
151  class StelAppGraphicsWidget* mainSkyItem;
152 
154  class StelRenderer* renderer;
155 
156  StelGuiBase* gui;
157 
158 #ifndef DISABLE_SCRIPTING
159  // The script API proxy object (for bridging threads)
160  StelMainScriptAPIProxy* scriptAPIProxy;
161 
162  // The script manager based on Qt script engine
163  StelScriptMgr* scriptMgr;
164 #endif
165 
166  bool wasDeinit;
167 
168  bool flagInvertScreenShotColors;
169 
170  QString screenShotPrefix;
171  QString screenShotDir;
172 
173  // Number of second before the mouse cursor disappears
174  float cursorTimeout;
175  bool flagCursorTimeout;
176 
179  void thereWasAnEvent();
180 
181  double lastEventTimeSec;
182 
183  QTimer* minFpsTimer;
185  float minfps;
187  float maxfps;
188 };
189 
190 
191 #endif // _STELMAINGRAPHICSVIEW_HPP_