Stellarium 0.11.2
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure
StelMainGraphicsView.hpp
00001 /*
00002  * Stellarium
00003  * Copyright (C) 2007 Fabien Chereau
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
00018  */
00019 
00020 #ifndef _STELMAINGRAPHICSVIEW_HPP_
00021 #define _STELMAINGRAPHICSVIEW_HPP_
00022 
00023 #include <QGraphicsView>
00024 #include <QCoreApplication>
00025 #include <QEventLoop>
00026 
00027 class QGLWidget;
00028 class QResizeEvent;
00029 class StelGuiBase;
00030 class StelMainScriptAPIProxy;
00031 class StelScriptMgr;
00032 class StelQGLWidget;
00033 
00037 class StelMainGraphicsView : public QGraphicsView
00038 {
00039 Q_OBJECT
00040 public:
00041     StelMainGraphicsView(QWidget* parent);
00042     virtual ~StelMainGraphicsView();
00043 
00045     void init(class QSettings* conf);
00046 
00048     static StelMainGraphicsView& getInstance() {Q_ASSERT(singleton); return *singleton;}
00049 
00051     void deinitGL();
00052 
00055     class StelAppGraphicsWidget* getStelAppGraphicsWidget() {return mainSkyItem;}
00056 
00059     QGraphicsWidget* getTopLevelGraphicsWidget() {return backItem;}
00060 
00061 #ifndef DISABLE_SCRIPTING
00062 
00063     StelMainScriptAPIProxy* getMainScriptAPIProxy() {return scriptAPIProxy;}
00065     StelScriptMgr& getScriptMgr() {return *scriptMgr;}
00066 #endif
00067 
00068 public slots:
00069 
00071     // Specific methods
00078     void saveScreenShot(const QString& filePrefix="stellarium-", const QString& saveDir="");
00079 
00081     bool getFlagInvertScreenShotColors() const {return flagInvertScreenShotColors;}
00083     void setFlagInvertScreenShotColors(bool b) {flagInvertScreenShotColors=b;}
00084 
00086     bool getFlagCursorTimeout() {return flagCursorTimeout;}
00088     float getCursorTimeout() const {return cursorTimeout;}
00090     void setFlagCursorTimeout(bool b) {flagCursorTimeout=b;}
00092     void setCursorTimeout(float t) {cursorTimeout=t;}
00093 
00098     void setMinFps(float m) {minfps=m; minFpsChanged();}
00100     float getMinFps() {return minfps;}
00103     void setMaxFps(float m) {maxfps = m;}
00105     float getMaxFps() {return maxfps;}
00106 
00108     void updateScene() {
00109 
00110         #ifdef QT_MAC_USE_COCOA
00111              //This call solves the problems with the qt event dispatcher. The stack grew huge and many events were discarded
00112              //http://bugreports.qt.nokia.com/browse/QTBUG-7502
00113              //The previous bug has been closed an fixed but this line is still needed. The patch didn't solve our problem
00114             QCoreApplication::processEvents(QEventLoop::AllEvents);
00115         #endif
00116         scene()->update();
00117     }
00118 
00119 protected:
00120     virtual void resizeEvent(QResizeEvent* event);
00121     virtual void mouseMoveEvent(QMouseEvent* event);
00122     virtual void mousePressEvent(QMouseEvent* event);
00123     virtual void mouseReleaseEvent(QMouseEvent* event);
00124     virtual void keyPressEvent(QKeyEvent* event);
00125     virtual void keyReleaseEvent(QKeyEvent* event);
00126     virtual void wheelEvent(QWheelEvent* wheelEvent);
00127 
00130     virtual void drawBackground(QPainter* painter, const QRectF &rect);
00131 
00132 signals:
00136     void screenshotRequested(void);
00137 
00138 private slots:
00139     // Do the actual screenshot generation in the main thread with this method.
00140     void doScreenshot(void);
00141 
00142     void minFpsChanged();
00143 
00144 private:
00146     void startMainLoop();
00147 
00149     static StelMainGraphicsView* singleton;
00150     QGraphicsWidget* backItem;
00151     class StelAppGraphicsWidget* mainSkyItem;
00152 
00154     StelQGLWidget* glWidget;
00155     class QGLContext* glContext;
00156 
00157     StelGuiBase* gui;
00158 
00159 #ifndef DISABLE_SCRIPTING
00160     // The script API proxy object (for bridging threads)
00161     StelMainScriptAPIProxy* scriptAPIProxy;
00162 
00163     // The script manager based on Qt script engine
00164     StelScriptMgr* scriptMgr;
00165 #endif
00166 
00167     bool wasDeinit;
00168 
00169     bool flagInvertScreenShotColors;
00170 
00171     QString screenShotPrefix;
00172     QString screenShotDir;
00173 
00174     // Number of second before the mouse cursor disappears
00175     float cursorTimeout;
00176     bool flagCursorTimeout;
00177 
00180     void thereWasAnEvent();
00181 
00182     double lastEventTimeSec;
00183 
00184     QTimer* minFpsTimer;
00186     float minfps;
00188     float maxfps;
00189 };
00190 
00191 
00192 #endif // _STELMAINGRAPHICSVIEW_HPP_