StelMainGraphicsView.cpp   StelMainGraphicsView.cpp 
skipping to change at line 27 skipping to change at line 27
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#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 "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelScriptMgr.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelGuiBase.hpp" #include "StelGuiBase.hpp"
#include "StelMainScriptAPIProxy.hpp" #include "StelMainWindow.hpp"
#include <QGLFormat> #include <QGLFormat>
#include <QPaintEngine> #include <QPaintEngine>
#include <QGraphicsView> #include <QGraphicsView>
#include <QGLWidget> #include <QGLWidget>
#include <QResizeEvent> #include <QResizeEvent>
#include <QSettings> #include <QSettings>
#include <QCoreApplication>
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
#include <QGraphicsGridLayout> #include <QGraphicsGridLayout>
#include <QGraphicsProxyWidget> #include <QGraphicsProxyWidget>
#include <QPluginLoader>
#include <QtPlugin>
#include <QThread>
#include <QTimer>
#ifndef DISABLE_SCRIPTING
#include "StelScriptMgr.hpp"
#include "StelMainScriptAPIProxy.hpp"
#endif
// The static plugins need to be imported here so that they belong to the
// libStelMain required on win32.
Q_IMPORT_PLUGIN(StelGui)
#ifdef USE_STATIC_PLUGIN_VIRGO
Q_IMPORT_PLUGIN(VirGO)
#endif
#ifdef USE_STATIC_PLUGIN_SVMT
Q_IMPORT_PLUGIN(SVMT)
#endif
#ifdef USE_STATIC_PLUGIN_HELLOSTELMODULE
Q_IMPORT_PLUGIN(HelloStelModule)
#endif
#ifdef USE_STATIC_PLUGIN_ANGLEMEASURE
Q_IMPORT_PLUGIN(AngleMeasure)
#endif
#ifdef USE_STATIC_PLUGIN_COMPASSMARKS
Q_IMPORT_PLUGIN(CompassMarks)
#endif
#ifdef USE_STATIC_PLUGIN_SATELLITES
Q_IMPORT_PLUGIN(Satellites)
#endif
#ifdef USE_STATIC_PLUGIN_TEXTUSERINTERFACE
Q_IMPORT_PLUGIN(TextUserInterface)
#endif
#ifdef USE_STATIC_PLUGIN_LOGBOOK
Q_IMPORT_PLUGIN(LogBook)
#endif
#ifdef USE_STATIC_PLUGIN_OCULARS
Q_IMPORT_PLUGIN(Oculars)
#endif
#ifdef USE_STATIC_PLUGIN_TELESCOPECONTROL
Q_IMPORT_PLUGIN(TelescopeControl)
#endif
// Initialize static variables // Initialize static variables
StelMainGraphicsView* StelMainGraphicsView::singleton = NULL; StelMainGraphicsView* StelMainGraphicsView::singleton = NULL;
class StelQGLWidget : public QGLWidget class StelQGLWidget : public QGLWidget
{ {
public: public:
StelQGLWidget(const QGLFormat& format, QWidget* parent) : QGLWidget( format, parent) StelQGLWidget(QGLContext* ctx, QWidget* parent) : QGLWidget(ctx, par ent)
{ {
setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground); setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_OpaquePaintEvent);
//setAutoFillBackground (false); //setAutoFillBackground(false);
setBackgroundRole(QPalette::Window); setBackgroundRole(QPalette::Window);
} }
protected: protected:
virtual void initializeGL() virtual void initializeGL()
{ {
QGLWidget::initializeGL(); QGLWidget::initializeGL();
if (!format().stencil()) if (!format().stencil())
qWarning("Could not get stencil buffer; results will be suboptimal"); qWarning("Could not get stencil buffer; results will be suboptimal");
skipping to change at line 89 skipping to change at line 140
paintEngineStr = "OpenGL2"; paintEngineStr = "OpenGL2";
break; break;
default: default:
paintEngineStr = "Other"; paintEngineStr = "Other";
} }
qDebug() << "Qt GL paint engine is: " << paintEngineStr; qDebug() << "Qt GL paint engine is: " << paintEngineStr;
} }
}; };
StelMainGraphicsView::StelMainGraphicsView(QWidget* parent) StelMainGraphicsView::StelMainGraphicsView(QWidget* parent)
: QGraphicsView(parent), backItem(NULL), gui(NULL), scriptAPIProxy(N : QGraphicsView(parent), backItem(NULL), gui(NULL),
ULL), scriptMgr(NULL), #ifndef DISABLE_SCRIPTING
scriptAPIProxy(NULL), scriptMgr(NULL),
#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();
// Can't create 2 StelMainGraphicsView instances // Can't create 2 StelMainGraphicsView instances
Q_ASSERT(!singleton); Q_ASSERT(!singleton);
singleton = this; singleton = this;
setObjectName("Mainview"); setObjectName("Mainview");
// Avoid white background at init // Avoid white background at init
setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground); setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_OpaquePaintEvent);
setAutoFillBackground (true); setAutoFillBackground(true);
setBackgroundRole(QPalette::Window); setBackgroundRole(QPalette::Window);
QPalette pal; QPalette pal;
pal.setColor(QPalette::Window, Qt::black); pal.setColor(QPalette::Window, Qt::black);
setPalette(pal); setPalette(pal);
// 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 ()));
qtime = new QTime();
qtime->start();
lastEventTimeSec = 0; lastEventTimeSec = 0;
// Create an openGL viewport // Create an openGL viewport
QGLFormat glFormat(QGL::StencilBuffer | QGL::DepthBuffer | QGL::Doub leBuffer); QGLFormat glFormat(QGL::StencilBuffer | QGL::DepthBuffer | QGL::Doub leBuffer);
glWidget = new StelQGLWidget(glFormat, this); glContext = new QGLContext(glFormat);
glWidget = new StelQGLWidget(glContext, this);
glWidget->updateGL(); glWidget->updateGL();
setViewport(glWidget); setViewport(glWidget);
//setOptimizationFlags(QGraphicsView::DontClipPainter|QGraphicsView: // This line seems to cause font aliasing troubles on win32
:DontSavePainterState|QGraphicsView::DontAdjustForAntialiasing); // setOptimizationFlags(QGraphicsView::DontSavePainterState);
setScene(new QGraphicsScene());
setScene(new QGraphicsScene(this));
scene()->setItemIndexMethod(QGraphicsScene::NoIndex);
backItem = new QGraphicsWidget(); backItem = new QGraphicsWidget();
backItem->setFocusPolicy(Qt::NoFocus); backItem->setFocusPolicy(Qt::NoFocus);
} }
StelMainGraphicsView::~StelMainGraphicsView() StelMainGraphicsView::~StelMainGraphicsView()
{ {
} }
void StelMainGraphicsView::swapBuffer()
{
glWidget->swapBuffers();
}
void StelMainGraphicsView::makeGLContextCurrent()
{
Q_ASSERT(glWidget!=NULL);
Q_ASSERT(glWidget->isValid());
glWidget->makeCurrent();
}
void StelMainGraphicsView::init(QSettings* conf) void StelMainGraphicsView::init(QSettings* conf)
{ {
Q_ASSERT(glWidget->isValid()); Q_ASSERT(glWidget->isValid());
glWidget->makeCurrent(); glWidget->makeCurrent();
// 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();
mainSkyItem->setZValue(-10); mainSkyItem->setZValue(-10);
QGraphicsGridLayout* l = new QGraphicsGridLayout(backItem); QGraphicsGridLayout* l = new QGraphicsGridLayout(backItem);
l->setContentsMargins(0,0,0,0); l->setContentsMargins(0,0,0,0);
skipping to change at line 177 skipping to change at line 220
l->addItem(mainSkyItem, 0, 0); l->addItem(mainSkyItem, 0, 0);
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.).toDoub setCursorTimeout(conf->value("gui/mouse_cursor_timeout", 10.f).toFlo
le()); at());
maxfps = conf->value("video/maximum_fps",10000.).toDouble(); maxfps = conf->value("video/maximum_fps",10000.f).toFloat();
minfps = conf->value("video/minimum_fps",10000.).toDouble(); minfps = conf->value("video/minimum_fps",10000.f).toFloat();
StelPainter::initSystemGLInfo(glContext);
QPainter qPainter(glWidget); QPainter qPainter(glWidget);
StelPainter::setQPainter(&qPainter); 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 // Prevent flickering on mac Leopard/Snow Leopard
glWidget->setAutoFillBackground (false); glWidget->setAutoFillBackground (false);
#ifndef DISABLE_SCRIPTING
scriptAPIProxy = new StelMainScriptAPIProxy(this); scriptAPIProxy = new StelMainScriptAPIProxy(this);
scriptMgr = new StelScriptMgr(this); scriptMgr = new StelScriptMgr(this);
#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);
if (pluginInterface) if (pluginInterface)
{ {
gui = pluginInterface->getStelGuiBase(); gui = pluginInterface->getStelGuiBase();
} }
break; break;
} }
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();
const QString& startupScript = conf->value("scripts/startup_script", #ifndef DISABLE_SCRIPTING
"startup.ssc").toString(); QString startupScript;
if (qApp->property("onetime_startup_script").isValid())
qApp->property("onetime_startup_script").toString();
else
startupScript = conf->value("scripts/startup_script", "start
up.ssc").toString();
scriptMgr->runScript(startupScript); scriptMgr->runScript(startupScript);
#endif
QThread::currentThread()->setPriority(QThread::HighestPriority); QThread::currentThread()->setPriority(QThread::HighestPriority);
StelPainter::setQPainter(NULL); StelPainter::setQPainter(NULL);
startMainLoop(); startMainLoop();
} }
void StelMainGraphicsView::thereWasAnEvent() void StelMainGraphicsView::thereWasAnEvent()
{ {
lastEventTimeSec = StelApp::getTotalRunTime(); lastEventTimeSec = StelApp::getTotalRunTime();
} }
void StelMainGraphicsView::drawBackground(QPainter* painter, const QRectF& rect) void StelMainGraphicsView::drawBackground(QPainter*, const QRectF&)
{ {
if (painter->paintEngine()->type()!=QPaintEngine::OpenGL && painter- const double now = StelApp::getTotalRunTime();
>paintEngine()->type()!=QPaintEngine::OpenGL2)
{
qWarning("StelMainGraphicsView: drawBackground needs a QGLWi
dget to be set as viewport on the graphics view");
return;
}
const double now = ((double)qtime->elapsed())/1000.;
// Determines when the next display will need to be triggered // Determines when the next display will need to be triggered
// The current policy is that after an event, the FPS is maximum for 2.5 seconds // The current policy is that after an event, the FPS is maximum for 2.5 seconds
// after that, it switches back to the default minfps value to save power // after that, it switches back to the default minfps value to save power
if (now-lastEventTimeSec<2.5) if (now-lastEventTimeSec<2.5)
{ {
double duration = 1./getMaxFps(); double duration = 1./getMaxFps();
int dur = (int)(duration*1000); int dur = (int)(duration*1000);
QTimer::singleShot(dur<5 ? 5 : dur, scene(), SLOT(update())) ; QTimer::singleShot(dur<5 ? 5 : dur, this, SLOT(updateScene() ));
} }
// Manage cursor timeout // Manage cursor timeout
if (cursorTimeout>0.f && (now-lastEventTimeSec>cursorTimeout) && fla gCursorTimeout) if (cursorTimeout>0.f && (now-lastEventTimeSec>cursorTimeout) && fla gCursorTimeout)
{ {
if (QApplication::overrideCursor()==0) if (QApplication::overrideCursor()==0)
QApplication::setOverrideCursor(Qt::BlankCursor); QApplication::setOverrideCursor(Qt::BlankCursor);
} }
else else
{ {
if (QApplication::overrideCursor()!=0) if (QApplication::overrideCursor()!=0)
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }
//QGraphicsView::drawBackground(painter, rect);
}
void StelMainGraphicsView::drawForeground(QPainter* painter, const QRectF &
rect)
{
//QGraphicsView::drawForeground(painter, rect);
} }
void StelMainGraphicsView::startMainLoop() void StelMainGraphicsView::startMainLoop()
{ {
// Set a timer refreshing for every minfps frames // Set a timer refreshing for every minfps frames
minFpsChanged(); minFpsChanged();
} }
void StelMainGraphicsView::minFpsChanged() void StelMainGraphicsView::minFpsChanged()
{ {
skipping to change at line 333 skipping to change at line 374
QGraphicsView::keyReleaseEvent(event); QGraphicsView::keyReleaseEvent(event);
} }
//! Delete openGL textures (to call before the GLContext disappears) //! Delete openGL textures (to call before the GLContext disappears)
void StelMainGraphicsView::deinitGL() void StelMainGraphicsView::deinitGL()
{ {
// 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
if (scriptMgr->scriptIsRunning()) if (scriptMgr->scriptIsRunning())
scriptMgr->stopScript(); scriptMgr->stopScript();
#endif
QCoreApplication::processEvents();
StelApp::getInstance().getModuleMgr().unloadAllPlugins(); StelApp::getInstance().getModuleMgr().unloadAllPlugins();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
delete gui;
delete mainSkyItem; delete mainSkyItem;
} }
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());
} }
 End of changes. 27 change blocks. 
52 lines changed or deleted 92 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/