void StelDialog::setVisible(bool v) { if (v) { QSize screenSize = StelMainGraphicsView::getInstance().size(); if (dialog) { dialog->show(); StelMainGraphicsView::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; } dialog = new QDialog(NULL); //dialog->setAttribute(Qt::WA_OpaquePaintEvent, true); connect(dialog, SIGNAL(rejected()), this, SLOT(close())); createDialogContent(); proxy = new CustomProxy(NULL, 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); StelMainGraphicsView::getInstance().scene()->addItem(proxy); 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); StelMainGraphicsView::getInstance().scene()->setActiveWindow(proxy); proxy->setFocus(); } else { dialog->hide(); emit visibleChanged(false); //proxy->clearFocus(); StelMainGraphicsView::getInstance().scene()->setActiveWindow(0); } }
void StelDialogLogBook::setVisible(bool v) { if (v) { QSize screenSize = StelMainWindow::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; } dialog = new QDialog(NULL); connect(dialog, SIGNAL(rejected()), this, SLOT(close())); createDialogContent(); proxy = new CustomProxy(NULL, Qt::Tool); proxy->setWidget(dialog); QRectF bound = proxy->boundingRect(); // centre with dialog according to current window size. proxy->setPos((int)((screenSize.width()-bound.width())/2), (int)((screenSize.height()-bound.height())/2)); StelMainView::getInstance().scene()->addItem(proxy); proxy->setWindowFrameMargins(2,0,2,2); // The caching is buggy on all plateforms with Qt 4.5.2 #if QT_VERSION==0x040502 proxy->setCacheMode(QGraphicsItem::NoCache); #else proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache); #endif proxy->setZValue(100); StelMainView::getInstance().scene()->setActiveWindow(proxy); proxy->setFocus(); } else { dialog->hide(); emit visibleChanged(false); //proxy->clearFocus(); StelMainView::getInstance().scene()->setActiveWindow(0); } }
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 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 {