StelMainGraphicsView.cpp   StelMainGraphicsView.cpp 
skipping to change at line 25 skipping to change at line 25
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#include "StelMainGraphicsView.hpp" #include "StelMainGraphicsView.hpp"
#include "StelAppGraphicsWidget.hpp" #include "StelAppGraphicsWidget.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelQGL1Renderer.hpp"
#include "StelQGL2Renderer.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelPainter.hpp"
#include "StelGuiBase.hpp" #include "StelGuiBase.hpp"
#include "StelMainWindow.hpp" #include "StelMainWindow.hpp"
#include <QGLFormat>
#include <QPaintEngine>
#include <QGraphicsView> #include <QGraphicsView>
#include <QGLWidget>
#include <QResizeEvent> #include <QResizeEvent>
#include <QSettings> #include <QSettings>
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
#include <QGraphicsGridLayout> #include <QGraphicsGridLayout>
#include <QGraphicsProxyWidget> #include <QGraphicsProxyWidget>
#include <QPluginLoader> #include <QPluginLoader>
#include <QtPlugin> #include <QtPlugin>
#include <QThread> #include <QThread>
skipping to change at line 68 skipping to change at line 66
#endif #endif
#ifdef USE_STATIC_PLUGIN_SVMT #ifdef USE_STATIC_PLUGIN_SVMT
Q_IMPORT_PLUGIN(SVMT) Q_IMPORT_PLUGIN(SVMT)
#endif #endif
#ifdef USE_STATIC_PLUGIN_HELLOSTELMODULE #ifdef USE_STATIC_PLUGIN_HELLOSTELMODULE
Q_IMPORT_PLUGIN(HelloStelModule) Q_IMPORT_PLUGIN(HelloStelModule)
#endif #endif
#ifdef USE_STATIC_PLUGIN_SIMPLEDRAWLINE
Q_IMPORT_PLUGIN(SimpleDrawLine)
#endif
#ifdef USE_STATIC_PLUGIN_ANGLEMEASURE #ifdef USE_STATIC_PLUGIN_ANGLEMEASURE
Q_IMPORT_PLUGIN(AngleMeasure) Q_IMPORT_PLUGIN(AngleMeasure)
#endif #endif
#ifdef USE_STATIC_PLUGIN_COMPASSMARKS #ifdef USE_STATIC_PLUGIN_COMPASSMARKS
Q_IMPORT_PLUGIN(CompassMarks) Q_IMPORT_PLUGIN(CompassMarks)
#endif #endif
#ifdef USE_STATIC_PLUGIN_RENDERERSTATISTICS
Q_IMPORT_PLUGIN(RendererStatistics)
#endif
#ifdef USE_STATIC_PLUGIN_SATELLITES #ifdef USE_STATIC_PLUGIN_SATELLITES
Q_IMPORT_PLUGIN(Satellites) Q_IMPORT_PLUGIN(Satellites)
#endif #endif
#ifdef USE_STATIC_PLUGIN_TEXTUSERINTERFACE #ifdef USE_STATIC_PLUGIN_TEXTUSERINTERFACE
Q_IMPORT_PLUGIN(TextUserInterface) Q_IMPORT_PLUGIN(TextUserInterface)
#endif #endif
#ifdef USE_STATIC_PLUGIN_LOGBOOK #ifdef USE_STATIC_PLUGIN_LOGBOOK
Q_IMPORT_PLUGIN(LogBook) Q_IMPORT_PLUGIN(LogBook)
skipping to change at line 127 skipping to change at line 133
Q_IMPORT_PLUGIN(Exoplanets) Q_IMPORT_PLUGIN(Exoplanets)
#endif #endif
#ifdef USE_STATIC_PLUGIN_OBSERVABILITY #ifdef USE_STATIC_PLUGIN_OBSERVABILITY
Q_IMPORT_PLUGIN(Observability) Q_IMPORT_PLUGIN(Observability)
#endif #endif
// Initialize static variables // Initialize static variables
StelMainGraphicsView* StelMainGraphicsView::singleton = NULL; StelMainGraphicsView* StelMainGraphicsView::singleton = NULL;
class StelQGLWidget : public QGLWidget
{
public:
StelQGLWidget(QGLContext* ctx, QWidget* parent) : QGLWidget(ctx, par
ent)
{
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);
//setAutoFillBackground(false);
setBackgroundRole(QPalette::Window);
}
protected:
virtual void initializeGL()
{
qDebug() << "OpenGL supported version: " << QString((char*)g
lGetString(GL_VERSION));
QGLWidget::initializeGL();
if (!format().stencil())
qWarning("Could not get stencil buffer; results will
be suboptimal");
if (!format().depth())
qWarning("Could not get depth buffer; results will b
e suboptimal");
if (!format().doubleBuffer())
qWarning("Could not get double buffer; results will
be suboptimal");
QString paintEngineStr;
switch (paintEngine()->type())
{
case QPaintEngine::OpenGL:
paintEngineStr = "OpenGL";
break;
case QPaintEngine::OpenGL2:
paintEngineStr = "OpenGL2";
break;
default:
paintEngineStr = "Other";
}
qDebug() << "Qt GL paint engine is: " << paintEngineStr;
}
};
StelMainGraphicsView::StelMainGraphicsView(QWidget* parent) StelMainGraphicsView::StelMainGraphicsView(QWidget* parent)
: QGraphicsView(parent), backItem(NULL), gui(NULL), : QGraphicsView(parent), backItem(NULL), renderer(NULL), gui(NULL),
#ifndef DISABLE_SCRIPTING #ifndef DISABLE_SCRIPTING
scriptAPIProxy(NULL), scriptMgr(NULL), scriptAPIProxy(NULL), scriptMgr(NULL),
#endif #endif
wasDeinit(false), wasDeinit(false),
flagInvertScreenShotColors(false), flagInvertScreenShotColors(false),
screenShotPrefix("stellarium-"), screenShotPrefix("stellarium-"),
screenShotDir(""), screenShotDir(""),
cursorTimeout(-1.f), flagCursorTimeout(false), minFpsTimer(NULL), maxfps(10000.f) cursorTimeout(-1.f), flagCursorTimeout(false), minFpsTimer(NULL), maxfps(10000.f)
{ {
StelApp::initStatic(); StelApp::initStatic();
skipping to change at line 208 skipping to change at line 172
// Allows for precise FPS control // Allows for precise FPS control
setViewportUpdateMode(QGraphicsView::NoViewportUpdate); setViewportUpdateMode(QGraphicsView::NoViewportUpdate);
setFrameShape(QFrame::NoFrame); setFrameShape(QFrame::NoFrame);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
connect(this, SIGNAL(screenshotRequested()), this, SLOT(doScreenshot ())); connect(this, SIGNAL(screenshotRequested()), this, SLOT(doScreenshot ()));
lastEventTimeSec = 0; lastEventTimeSec = 0;
// Create an openGL viewport
QGLFormat glFormat(QGL::StencilBuffer | QGL::DepthBuffer | QGL::Doub
leBuffer);
glContext = new QGLContext(glFormat);
glWidget = new StelQGLWidget(glContext, this);
glWidget->updateGL();
setViewport(glWidget);
// This line seems to cause font aliasing troubles on win32 // This line seems to cause font aliasing troubles on win32
// setOptimizationFlags(QGraphicsView::DontSavePainterState); // setOptimizationFlags(QGraphicsView::DontSavePainterState);
setScene(new QGraphicsScene(this)); setScene(new QGraphicsScene(this));
scene()->setItemIndexMethod(QGraphicsScene::NoIndex); scene()->setItemIndexMethod(QGraphicsScene::NoIndex);
backItem = new QGraphicsWidget(); backItem = new QGraphicsWidget();
backItem->setFocusPolicy(Qt::NoFocus); backItem->setFocusPolicy(Qt::NoFocus);
// Workaround (see Bug #940638) Although we have already explicitly set // Workaround (see Bug #940638) Although we have already explicitly set
// LC_NUMERIC to "C" in main.cpp there seems to be a bug in OpenGL w here // LC_NUMERIC to "C" in main.cpp there seems to be a bug in OpenGL w here
// it will silently reset LC_NUMERIC to the value of LC_ALL during O penGL // it will silently reset LC_NUMERIC to the value of LC_ALL during O penGL
// initialization. This has been observed on Ubuntu 11.10 under cert ain // initialization. This has been observed on Ubuntu 11.10 under cert ain
// circumstances, so here we set it again just to be on the safe sid e. // circumstances, so here we set it again just to be on the safe sid e.
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
// End workaround // End workaround
} }
StelMainGraphicsView::~StelMainGraphicsView() StelMainGraphicsView::~StelMainGraphicsView()
{ {
if(NULL != renderer)
{
delete renderer;
}
} }
void StelMainGraphicsView::init(QSettings* conf) void StelMainGraphicsView::init(QSettings* conf)
{ {
Q_ASSERT(glWidget->isValid()); // TODO: On hardware with .pvr texture support, the second argument
glWidget->makeCurrent(); should be true
qDebug() << "Going to initialize the OpenGL 2 renderer";
renderer = new StelQGL2Renderer(this, false);
if(!renderer->init())
{
qWarning() << "Failed to initialize the OpenGL 2 renderer, "
"falling back to the OpenGL 1 renderer";
delete renderer;
renderer = new StelQGL1Renderer(this);
if(!renderer->init())
{
Q_ASSERT_X(false, Q_FUNC_INFO, "Failed to initialize
fallback renderer");
}
}
// Create the main widget for stellarium, which in turn creates the main StelApp instance. // Create the main widget for stellarium, which in turn creates the main StelApp instance.
mainSkyItem = new StelAppGraphicsWidget(); mainSkyItem = new StelAppGraphicsWidget(renderer);
mainSkyItem->setZValue(-10); mainSkyItem->setZValue(-10);
mainSkyItem->setContentsMargins(0,0,0,0); mainSkyItem->setContentsMargins(0,0,0,0);
QGraphicsGridLayout* l = new QGraphicsGridLayout(backItem); QGraphicsGridLayout* l = new QGraphicsGridLayout(backItem);
l->setSpacing(0); l->setSpacing(0);
l->setContentsMargins(0,0,0,0); l->setContentsMargins(0,0,0,0);
l->addItem(mainSkyItem, 0, 0); l->addItem(mainSkyItem, 0, 0);
backItem->setLayout(l); backItem->setLayout(l);
scene()->addItem(backItem); scene()->addItem(backItem);
// Activate the resizing caused by the layout // Activate the resizing caused by the layout
QCoreApplication::processEvents(); QCoreApplication::processEvents();
mainSkyItem->setFocus(); mainSkyItem->setFocus();
flagInvertScreenShotColors = conf->value("main/invert_screenshots_co lors", false).toBool(); flagInvertScreenShotColors = conf->value("main/invert_screenshots_co lors", false).toBool();
setFlagCursorTimeout(conf->value("gui/flag_mouse_cursor_timeout", fa lse).toBool()); setFlagCursorTimeout(conf->value("gui/flag_mouse_cursor_timeout", fa lse).toBool());
setCursorTimeout(conf->value("gui/mouse_cursor_timeout", 10.f).toFlo at()); setCursorTimeout(conf->value("gui/mouse_cursor_timeout", 10.f).toFlo at());
maxfps = conf->value("video/maximum_fps",10000.f).toFloat(); maxfps = conf->value("video/maximum_fps",10000.f).toFloat();
minfps = conf->value("video/minimum_fps",10000.f).toFloat(); minfps = conf->value("video/minimum_fps",10000.f).toFloat();
StelPainter::initSystemGLInfo(glContext);
QPainter qPainter(glWidget);
StelPainter::setQPainter(&qPainter);
// Initialize the core, including the StelApp instance. // Initialize the core, including the StelApp instance.
mainSkyItem->init(conf); mainSkyItem->init(conf);
// Prevent flickering on mac Leopard/Snow Leopard
glWidget->setAutoFillBackground (false);
#ifndef DISABLE_SCRIPTING #ifndef DISABLE_SCRIPTING
scriptAPIProxy = new StelMainScriptAPIProxy(this); scriptAPIProxy = new StelMainScriptAPIProxy(this);
scriptMgr = new StelScriptMgr(this); scriptMgr = new StelScriptMgr(this);
#endif #endif
// Look for a static GUI plugins. // Look for a static GUI plugins.
foreach (QObject *plugin, QPluginLoader::staticInstances()) foreach (QObject *plugin, QPluginLoader::staticInstances())
{ {
StelGuiPluginInterface* pluginInterface = qobject_cast<StelG uiPluginInterface*>(plugin); StelGuiPluginInterface* pluginInterface = qobject_cast<StelG uiPluginInterface*>(plugin);
skipping to change at line 299 skipping to change at line 265
Q_ASSERT(gui); // There was no GUI plugin found Q_ASSERT(gui); // There was no GUI plugin found
StelApp::getInstance().setGui(gui); StelApp::getInstance().setGui(gui);
gui->init(backItem, mainSkyItem); gui->init(backItem, mainSkyItem);
StelApp::getInstance().initPlugIns(); StelApp::getInstance().initPlugIns();
// Force refreshing of button bars if plugins modified the GUI, e.g. added buttons. // Force refreshing of button bars if plugins modified the GUI, e.g. added buttons.
gui->forceRefreshGui(); gui->forceRefreshGui();
#ifndef DISABLE_SCRIPTING #ifndef DISABLE_SCRIPTING
// Defer adding the StelModules into the script engine until the plu
gins are loaded.
scriptMgr->addModules();
QString startupScript; QString startupScript;
if (qApp->property("onetime_startup_script").isValid()) if (qApp->property("onetime_startup_script").isValid())
startupScript = qApp->property("onetime_startup_script").toS tring(); startupScript = qApp->property("onetime_startup_script").toS tring();
else else
startupScript = conf->value("scripts/startup_script", "start up.ssc").toString(); startupScript = conf->value("scripts/startup_script", "start up.ssc").toString();
// Use a queued slot call to start the script only once the main qAp p event loop is running... // Use a queued slot call to start the script only once the main qAp p event loop is running...
QMetaObject::invokeMethod(scriptMgr, QMetaObject::invokeMethod(scriptMgr,
"runScript", "runScript",
Qt::QueuedConnection, Qt::QueuedConnection,
Q_ARG(QString, startupScript)); Q_ARG(QString, startupScript));
#endif #endif
QThread::currentThread()->setPriority(QThread::HighestPriority); QThread::currentThread()->setPriority(QThread::HighestPriority);
StelPainter::setQPainter(NULL);
startMainLoop(); startMainLoop();
} }
void StelMainGraphicsView::thereWasAnEvent() void StelMainGraphicsView::thereWasAnEvent()
{ {
lastEventTimeSec = StelApp::getTotalRunTime(); lastEventTimeSec = StelApp::getTotalRunTime();
} }
void StelMainGraphicsView::drawBackground(QPainter*, const QRectF&) void StelMainGraphicsView::drawBackground(QPainter*, const QRectF&)
{ {
skipping to change at line 414 skipping to change at line 383
thereWasAnEvent(); // Refresh screen ASAP thereWasAnEvent(); // Refresh screen ASAP
QGraphicsView::keyPressEvent(event); QGraphicsView::keyPressEvent(event);
} }
void StelMainGraphicsView::keyReleaseEvent(QKeyEvent* event) void StelMainGraphicsView::keyReleaseEvent(QKeyEvent* event)
{ {
thereWasAnEvent(); // Refresh screen ASAP thereWasAnEvent(); // Refresh screen ASAP
QGraphicsView::keyReleaseEvent(event); QGraphicsView::keyReleaseEvent(event);
} }
//! Delete openGL textures (to call before the GLContext disappears) //! Delete textures (to call before the renderer disappears)
void StelMainGraphicsView::deinitGL() void StelMainGraphicsView::deinit()
{ {
// Can be called only once // Can be called only once
if (wasDeinit==true) if (wasDeinit==true)
return; return;
wasDeinit = true; wasDeinit = true;
#ifndef DISABLE_SCRIPTING #ifndef DISABLE_SCRIPTING
if (scriptMgr->scriptIsRunning()) if (scriptMgr->scriptIsRunning())
scriptMgr->stopScript(); scriptMgr->stopScript();
#endif #endif
QCoreApplication::processEvents(); QCoreApplication::processEvents();
skipping to change at line 442 skipping to change at line 411
void StelMainGraphicsView::saveScreenShot(const QString& filePrefix, const QString& saveDir) void StelMainGraphicsView::saveScreenShot(const QString& filePrefix, const QString& saveDir)
{ {
screenShotPrefix = filePrefix; screenShotPrefix = filePrefix;
screenShotDir = saveDir; screenShotDir = saveDir;
emit(screenshotRequested()); emit(screenshotRequested());
} }
void StelMainGraphicsView::doScreenshot(void) void StelMainGraphicsView::doScreenshot(void)
{ {
QFileInfo shotDir; QFileInfo shotDir;
QImage im = glWidget->grabFrameBuffer(); QImage im = renderer->screenshot();
if (flagInvertScreenShotColors) if (flagInvertScreenShotColors)
im.invertPixels(); im.invertPixels();
if (screenShotDir == "") if (screenShotDir == "")
shotDir = QFileInfo(StelFileMgr::getScreenshotDir()); shotDir = QFileInfo(StelFileMgr::getScreenshotDir());
else else
shotDir = QFileInfo(screenShotDir); shotDir = QFileInfo(screenShotDir);
if (!shotDir.isDir()) if (!shotDir.isDir())
{ {
 End of changes. 18 change blocks. 
74 lines changed or deleted 40 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/