void StelDialog::setVisible(bool v) { if (v) { QSize screenSize = StelMainView::getInstance().size(); if (dialog) { dialog->show(); StelMainView::getInstance().scene()->setActiveWindow(proxy); // If the main window has been resized, it is possible the dialog // will be off screen. Check for this and move it to a visible // position if necessary QPointF newPos = proxy->pos(); if (newPos.x()>=screenSize.width()) newPos.setX(screenSize.width() - dialog->size().width()); if (newPos.y()>=screenSize.height()) newPos.setY(screenSize.height() - dialog->size().height()); if (newPos != dialog->pos()) proxy->setPos(newPos); proxy->setFocus(); return; } QGraphicsWidget* parent = qobject_cast<QGraphicsWidget*>(this->parent()); dialog = new QDialog(NULL); // dialog->setParent(parent); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui()); Q_ASSERT(gui); //dialog->setAttribute(Qt::WA_OpaquePaintEvent, true); connect(dialog, SIGNAL(rejected()), this, SLOT(close())); createDialogContent(); dialog->setStyleSheet(gui->getStelStyle().qtStyleSheet); // Ensure that tooltip get rendered in red in night mode. connect(&StelApp::getInstance(), SIGNAL(visionNightModeChanged(bool)), this, SLOT(updateNightModeProperty())); updateNightModeProperty(); proxy = new CustomProxy(parent, Qt::Tool); proxy->setWidget(dialog); QSizeF size = proxy->size(); // centre with dialog according to current window size. int newX = (int)((screenSize.width() - size.width())/2); int newY = (int)((screenSize.height() - size.height())/2); // Make sure that the window's title bar is accessible if (newY <-0) newY = 0; proxy->setPos(newX, newY); proxy->setWindowFrameMargins(2,0,2,2); // (this also changes the bounding rectangle size) // The caching is buggy on all plateforms with Qt 4.5.2 proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache); proxy->setZValue(100); StelMainView::getInstance().scene()->setActiveWindow(proxy); proxy->setFocus(); } else {
void StelMainView::init(QSettings* conf) { gui = new StelGui(); #if STEL_USE_NEW_OPENGL_WIDGETS //glWidget->initializeGL(); // protected... //Q_ASSERT(glWidget->isValid()); #else Q_ASSERT(glWidget->isValid()); glWidget->makeCurrent(); #endif // Should be check of requirements disabled? if (conf->value("main/check_requirements", true).toBool()) { // Find out lots of debug info about supported version of OpenGL and vendor/renderer. processOpenGLdiagnosticsAndWarnings(conf, glWidget); } stelApp= new StelApp(); stelApp->setGui(gui); stelApp->init(conf); StelActionMgr *actionMgr = stelApp->getStelActionManager(); actionMgr->addAction("actionSave_Screenshot_Global", N_("Miscellaneous"), N_("Save screenshot"), this, "saveScreenShot()", "Ctrl+S"); actionMgr->addAction("actionSet_Full_Screen_Global", N_("Display Options"), N_("Full-screen mode"), this, "fullScreen", "F11"); StelPainter::initGLShaders(); skyItem = new StelSkyItem(); guiItem = new StelGuiItem(); QGraphicsAnchorLayout* l = new QGraphicsAnchorLayout(rootItem); l->setSpacing(0); l->setContentsMargins(0,0,0,0); l->addCornerAnchors(skyItem, Qt::TopLeftCorner, l, Qt::TopLeftCorner); l->addCornerAnchors(skyItem, Qt::BottomRightCorner, l, Qt::BottomRightCorner); l->addCornerAnchors(guiItem, Qt::BottomLeftCorner, l, Qt::BottomLeftCorner); l->addCornerAnchors(guiItem, Qt::TopRightCorner, l, Qt::TopRightCorner); rootItem->setLayout(l); scene()->addItem(rootItem); nightModeEffect = new NightModeGraphicsEffect(this); updateNightModeProperty(); rootItem->setGraphicsEffect(nightModeEffect); QSize size = glWidget->windowHandle()->screen()->size(); size = QSize(conf->value("video/screen_w", size.width()).toInt(), conf->value("video/screen_h", size.height()).toInt()); bool fullscreen = conf->value("video/fullscreen", true).toBool(); // Without this, the screen is not shown on a Mac + we should use resize() for correct work of fullscreen/windowed mode switch. --AW WTF??? resize(size); QDesktopWidget *desktop = QApplication::desktop(); int screen = conf->value("video/screen_number", 0).toInt(); if (screen < 0 || screen >= desktop->screenCount()) { qWarning() << "WARNING: screen" << screen << "not found"; screen = 0; } QRect screenGeom = desktop->screenGeometry(screen); if (fullscreen) { // The "+1" below is to work around Linux/Gnome problem with mouse focus. move(screenGeom.x()+1, screenGeom.y()+1); // The fullscreen window appears on screen where is the majority of // the normal window. Therefore we crop the normal window to the // screen area to ensure that the majority is not on another screen. setGeometry(geometry() & screenGeom); setFullScreen(true); } else { setFullScreen(false); int x = conf->value("video/screen_x", 0).toInt(); int y = conf->value("video/screen_y", 0).toInt(); move(x + screenGeom.x(), y + screenGeom.y()); } flagInvertScreenShotColors = conf->value("main/invert_screenshots_colors", false).toBool(); setFlagCursorTimeout(conf->value("gui/flag_mouse_cursor_timeout", false).toBool()); setCursorTimeout(conf->value("gui/mouse_cursor_timeout", 10.f).toFloat()); maxfps = conf->value("video/maximum_fps",10000.f).toFloat(); minfps = conf->value("video/minimum_fps",10000.f).toFloat(); flagMaxFpsUpdatePending = false; // XXX: This should be done in StelApp::init(), unfortunately for the moment we need init the gui before the // plugins, because the gui create the QActions needed by some plugins. StelApp::getInstance().initPlugIns(); // activate DE430/431 StelApp::getInstance().getCore()->initEphemeridesFunctions(); // The script manager can only be fully initialized after the plugins have loaded. StelApp::getInstance().initScriptMgr(); // Set the global stylesheet, this is only useful for the tooltips. StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui()); if (gui!=NULL) setStyleSheet(gui->getStelStyle().qtStyleSheet); connect(&StelApp::getInstance(), SIGNAL(visionNightModeChanged(bool)), this, SLOT(updateNightModeProperty())); QThread::currentThread()->setPriority(QThread::HighestPriority); startMainLoop(); }
void StelDialog::setVisible(bool v) { if (v) { StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui()); Q_ASSERT(gui); QSize screenSize = StelMainView::getInstance().size(); QSize maxSize = 0.8*screenSize; if (dialog) { // reload stylesheet, in case size changed! dialog->setStyleSheet(gui->getStelStyle().qtStyleSheet); dialog->show(); StelMainView::getInstance().scene()->setActiveWindow(proxy); // If the main window has been resized, it is possible the dialog // will be off screen. Check for this and move it to a visible // position if necessary QPointF newPos = proxy->pos(); if (newPos.x()>=screenSize.width()) newPos.setX(screenSize.width() - dialog->size().width()); if (newPos.y()>=screenSize.height()) newPos.setY(screenSize.height() - dialog->size().height()); if (newPos != dialog->pos()) proxy->setPos(newPos); QSizeF newSize = proxy->size(); if (newSize.width() >= maxSize.width()) newSize.setWidth(maxSize.width()); if (newSize.height() >= maxSize.height()) newSize.setHeight(maxSize.height()); if(newSize != dialog->size()) proxy->resize(newSize); } else { QGraphicsWidget* parent = qobject_cast<QGraphicsWidget*>(this->parent()); dialog = new QDialog(Q_NULLPTR); // dialog->setParent(parent); //dialog->setAttribute(Qt::WA_OpaquePaintEvent, true); connect(dialog, SIGNAL(rejected()), this, SLOT(close())); createDialogContent(); dialog->setStyleSheet(gui->getStelStyle().qtStyleSheet); // Ensure that tooltip get rendered in red in night mode. connect(&StelApp::getInstance(), SIGNAL(visionNightModeChanged(bool)), this, SLOT(updateNightModeProperty())); updateNightModeProperty(); proxy = new CustomProxy(parent, Qt::Tool); proxy->setWidget(dialog); QSizeF size = proxy->size(); connect(proxy, SIGNAL(sizeChanged(QSizeF)), this, SLOT(handleDialogSizeChanged(QSizeF))); int newX, newY; // Retrieve panel locations from config.ini, but shift if required to a visible position. // else centre dialog according to current window size. QSettings *conf=StelApp::getInstance().getSettings(); Q_ASSERT(conf); QString confNamePt="DialogPositions/" + dialogName; QString storedPosString=conf->value(confNamePt, QString("%1,%2") .arg((int)((screenSize.width() - size.width() )/2)) .arg((int)((screenSize.height() - size.height())/2))) .toString(); QStringList posList=storedPosString.split(","); if (posList.length()==2) { newX=posList.at(0).toInt(); newY=posList.at(1).toInt(); } else // in case there is an invalid string? { newX=(int)((screenSize.width() - size.width() )/2); newY=(int)((screenSize.height() - size.height())/2); } if (newX>=screenSize.width()) newX= (screenSize.width() - dialog->size().width()); if (newY>=screenSize.height()) newY= (screenSize.height() - dialog->size().height()); // Make sure that the window's title bar is accessible if (newY <-0) newY = 0; proxy->setPos(newX, newY); proxy->setWindowFrameMargins(2,0,2,2); // (this also changes the bounding rectangle size) // Retrieve stored panel sizes, scale panel up if it was stored larger than default. QString confNameSize="DialogSizes/" + dialogName; QString storedSizeString=conf->value(confNameSize, QString("0,0")).toString(); QStringList sizeList=storedSizeString.split(","); if (sizeList.length()==2) { newX=sizeList.at(0).toInt(); newY=sizeList.at(1).toInt(); } else // in case there is an invalid string? { newX=0; newY=0; } // resize only if number was valid and larger than default loaded size. if ( (newX>=proxy->size().width()) || (newY>=proxy->size().height()) ) { //qDebug() << confNameSize << ": resize to " << storedSizeString; proxy->resize(qMax((qreal)newX, proxy->size().width()), qMax((qreal)newY, proxy->size().height())); } if(proxy->size().width() > maxSize.width() || proxy->size().height() > maxSize.height()) { proxy->resize(maxSize); } handleDialogSizeChanged(proxy->size()); // This may trigger internal updates in subclasses. E.g. LocationPanel location arrow. // The caching is buggy on all platforms with Qt 4.5.2 // Disabled on mac for the moment (https://github.com/Stellarium/stellarium/issues/393) #ifndef Q_OS_MAC proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache); #endif proxy->setZValue(100); StelMainView::getInstance().scene()->setActiveWindow(proxy); } proxy->setFocus(); } else {