StelMainWindow::StelMainWindow() : QMainWindow(NULL) { // Can't create 2 StelMainWindow instances Q_ASSERT(!singleton); singleton = this; setAttribute(Qt::WA_NoSystemBackground); setWindowIcon(QIcon(":/mainWindow/icon.bmp")); initTitleI18n(); mainGraphicsView = new StelMainGraphicsView(this); setCentralWidget(mainGraphicsView); #ifdef BUILD_FOR_MAEMO if (!winId()) { qWarning("Can't grab keys unless we have a window id"); return; } unsigned long val = 1; Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False); if (!atom) { qWarning("Unable to obtain _HILDON_ZOOM_KEY_ATOM. This only works on a Maemo 5 device!"); } else { XChangeProperty (QX11Info::display(), winId(), atom, XA_INTEGER, 32, PropModeReplace, reinterpret_cast<unsigned char *>(&val), 1); } #endif }
StelMainView::StelMainView(QWidget* parent) : QGraphicsView(parent), guiItem(NULL), gui(NULL), flagInvertScreenShotColors(false), flagOverwriteScreenshots(false), screenShotPrefix("stellarium-"), screenShotDir(""), cursorTimeout(-1.f), flagCursorTimeout(false), minFpsTimer(NULL), maxfps(10000.f) { StelApp::initStatic(); // Can't create 2 StelMainView instances Q_ASSERT(!singleton); singleton = this; setWindowIcon(QIcon(":/mainWindow/icon.bmp")); initTitleI18n(); setObjectName("Mainview"); // Allows for precise FPS control setViewportUpdateMode(QGraphicsView::NoViewportUpdate); setFrameShape(QFrame::NoFrame); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setFocusPolicy(Qt::StrongFocus); connect(this, SIGNAL(screenshotRequested()), this, SLOT(doScreenshot())); lastEventTimeSec = 0; #if STEL_USE_NEW_OPENGL_WIDGETS // Primary test for OpenGL existence if (QSurfaceFormat::defaultFormat().majorVersion() < 2) { qWarning() << "No OpenGL 2 support on this system. Aborting."; QMessageBox::critical(0, "Stellarium", q_("No OpenGL 2 found on this system. Please upgrade hardware or use MESA or an older version."), QMessageBox::Abort, QMessageBox::Abort); exit(0); } //QSurfaceFormat format(); //// TBD: What options shall be default? //QSurfaceFormat::setDefaultFormat(format); ////QOpenGLContext* context=new QOpenGLContext::create(); glWidget = new StelQOpenGLWidget(this); //glWidget->setFormat(format); #else // Primary test for OpenGL existence if (QGLFormat::openGLVersionFlags() < QGLFormat::OpenGL_Version_2_1) { qWarning() << "No OpenGL 2.1 support on this system. Aborting."; QMessageBox::critical(0, "Stellarium", q_("No OpenGL 2 found on this system. Please upgrade hardware or use MESA or an older version."), QMessageBox::Abort, QMessageBox::Abort); exit(1); } // Create an openGL viewport QGLFormat glFormat(QGL::StencilBuffer | QGL::DepthBuffer | QGL::DoubleBuffer); // Even if setting a version here, it is ignored in StelQGLWidget()! // TBD: Maybe this must make a differentiation between OpenGL and OpenGL ES! // glFormat.setVersion(2, 1); QGLContext* context=new QGLContext(glFormat); if (context->format() != glFormat) { qWarning() << "Cannot provide OpenGL context. Apparently insufficient OpenGL resources on this system."; QMessageBox::critical(0, "Stellarium", q_("Cannot acquire necessary OpenGL resources."), QMessageBox::Abort, QMessageBox::Abort); exit(1); } glWidget = new StelQGLWidget(context, this); // This does not return the version number set previously! // qDebug() << "glWidget.context.format.version, result:" << glWidget->context()->format().majorVersion() << "." << glWidget->context()->format().minorVersion(); #endif setViewport(glWidget); setScene(new QGraphicsScene(this)); scene()->setItemIndexMethod(QGraphicsScene::NoIndex); rootItem = new QGraphicsWidget(); rootItem->setFocusPolicy(Qt::NoFocus); // 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 where // it will silently reset LC_NUMERIC to the value of LC_ALL during OpenGL // initialization. This has been observed on Ubuntu 11.10 under certain // circumstances, so here we set it again just to be on the safe side. setlocale(LC_NUMERIC, "C"); // End workaround }