mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
more HMD Tools improvements, better support for detecting adding/removing screens
This commit is contained in:
parent
184acaedef
commit
fe010b685a
2 changed files with 40 additions and 13 deletions
|
@ -28,10 +28,11 @@
|
||||||
|
|
||||||
HMDToolsDialog::HMDToolsDialog(QWidget* parent) :
|
HMDToolsDialog::HMDToolsDialog(QWidget* parent) :
|
||||||
QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) ,
|
QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) ,
|
||||||
_switchModeButton(NULL),
|
|
||||||
_debugDetails(NULL),
|
|
||||||
_previousScreen(NULL),
|
_previousScreen(NULL),
|
||||||
_hmdScreen(NULL),
|
_hmdScreen(NULL),
|
||||||
|
_hmdScreenNumber(-1),
|
||||||
|
_switchModeButton(NULL),
|
||||||
|
_debugDetails(NULL),
|
||||||
_previousDialogScreen(NULL),
|
_previousDialogScreen(NULL),
|
||||||
_inHDMMode(false)
|
_inHDMMode(false)
|
||||||
{
|
{
|
||||||
|
@ -75,6 +76,9 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) :
|
||||||
|
|
||||||
// when the application is about to quit, leave HDM mode
|
// when the application is about to quit, leave HDM mode
|
||||||
connect(Application::getInstance(), SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()));
|
connect(Application::getInstance(), SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()));
|
||||||
|
|
||||||
|
// keep track of changes to the number of screens
|
||||||
|
connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &HMDToolsDialog::screenCountChanged);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,11 +103,11 @@ void HMDToolsDialog::dialogWindowScreenChanged(QScreen* screen) {
|
||||||
// if we have more than one screen, and a known hmdScreen then try to
|
// if we have more than one screen, and a known hmdScreen then try to
|
||||||
// keep our dialog off of the hmdScreen
|
// keep our dialog off of the hmdScreen
|
||||||
if (QApplication::desktop()->screenCount() > 1) {
|
if (QApplication::desktop()->screenCount() > 1) {
|
||||||
int hmdScreenNumber = OculusManager::getHMDScreen();
|
|
||||||
|
|
||||||
if (hmdScreenNumber >= 0) {
|
|
||||||
QScreen* hmdScreen = QGuiApplication::screens()[hmdScreenNumber];
|
|
||||||
|
|
||||||
|
// we want to use a local variable here because we are not necesarily in HMD mode
|
||||||
|
int hmdScreenNumber = OculusManager::getHMDScreen();
|
||||||
|
if (_hmdScreenNumber >= 0) {
|
||||||
|
QScreen* hmdScreen = QGuiApplication::screens()[hmdScreenNumber];
|
||||||
if (screen == hmdScreen) {
|
if (screen == hmdScreen) {
|
||||||
qDebug() << "HMD Tools: Whoa! What are you doing? You don't want to move me to the HMD Screen!";
|
qDebug() << "HMD Tools: Whoa! What are you doing? You don't want to move me to the HMD Screen!";
|
||||||
QWindow* dialogWindow = windowHandle();
|
QWindow* dialogWindow = windowHandle();
|
||||||
|
@ -157,6 +161,7 @@ QString HMDToolsDialog::getDebugDetails() const {
|
||||||
results += "Application Primary Screen: " + QGuiApplication::primaryScreen()->name() + "\n";
|
results += "Application Primary Screen: " + QGuiApplication::primaryScreen()->name() + "\n";
|
||||||
QScreen* mainWindowScreen = Application::getInstance()->getWindow()->windowHandle()->screen();
|
QScreen* mainWindowScreen = Application::getInstance()->getWindow()->windowHandle()->screen();
|
||||||
results += "Application Main Window Screen: " + mainWindowScreen->name() + "\n";
|
results += "Application Main Window Screen: " + mainWindowScreen->name() + "\n";
|
||||||
|
results += "Total Screens: " + QString::number(QApplication::desktop()->screenCount()) + "\n";
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@ -174,18 +179,17 @@ void HMDToolsDialog::enterHDMMode() {
|
||||||
_switchModeButton->setText("Leave HMD Mode");
|
_switchModeButton->setText("Leave HMD Mode");
|
||||||
_debugDetails->setText(getDebugDetails());
|
_debugDetails->setText(getDebugDetails());
|
||||||
|
|
||||||
int hmdScreen = OculusManager::getHMDScreen();
|
_hmdScreenNumber = OculusManager::getHMDScreen();
|
||||||
qDebug() << "enterModeClicked().... hmdScreen:" << hmdScreen;
|
|
||||||
|
|
||||||
if (hmdScreen >= 0) {
|
if (_hmdScreenNumber >= 0) {
|
||||||
QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle();
|
QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle();
|
||||||
_hmdScreen = QGuiApplication::screens()[hmdScreen];
|
_hmdScreen = QGuiApplication::screens()[_hmdScreenNumber];
|
||||||
|
|
||||||
_previousRect = Application::getInstance()->getWindow()->rect();
|
_previousRect = Application::getInstance()->getWindow()->rect();
|
||||||
_previousRect = QRect(mainWindow->mapToGlobal(_previousRect.topLeft()),
|
_previousRect = QRect(mainWindow->mapToGlobal(_previousRect.topLeft()),
|
||||||
mainWindow->mapToGlobal(_previousRect.bottomRight()));
|
mainWindow->mapToGlobal(_previousRect.bottomRight()));
|
||||||
_previousScreen = mainWindow->screen();
|
_previousScreen = mainWindow->screen();
|
||||||
QRect rect = QApplication::desktop()->screenGeometry(hmdScreen);
|
QRect rect = QApplication::desktop()->screenGeometry(_hmdScreenNumber);
|
||||||
mainWindow->setScreen(_hmdScreen);
|
mainWindow->setScreen(_hmdScreen);
|
||||||
mainWindow->setGeometry(rect);
|
mainWindow->setGeometry(rect);
|
||||||
|
|
||||||
|
@ -281,4 +285,25 @@ void HMDToolsDialog::aboutToQuit() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HMDToolsDialog::screenCountChanged(int newCount) {
|
||||||
|
if (!OculusManager::isConnected()) {
|
||||||
|
OculusManager::connect();
|
||||||
|
}
|
||||||
|
int hmdScreenNumber = OculusManager::getHMDScreen();
|
||||||
|
|
||||||
|
if (_inHDMMode && _hmdScreenNumber != hmdScreenNumber) {
|
||||||
|
qDebug() << "HMD Display changed WHILE IN HMD MODE";
|
||||||
|
leaveHDMMode();
|
||||||
|
|
||||||
|
// if there is a new best HDM screen then go back into HDM mode after done leaving
|
||||||
|
if (hmdScreenNumber >= 0) {
|
||||||
|
qDebug() << "Trying to go back into HDM Mode";
|
||||||
|
const int SLIGHT_DELAY = 2000;
|
||||||
|
QTimer::singleShot(SLIGHT_DELAY, this, SLOT(enterHDMMode()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_debugDetails->setText(getDebugDetails());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,9 @@ public slots:
|
||||||
void applicationWindowScreenChanged(QScreen* screen);
|
void applicationWindowScreenChanged(QScreen* screen);
|
||||||
void dialogWindowScreenChanged(QScreen* screen);
|
void dialogWindowScreenChanged(QScreen* screen);
|
||||||
void dialogWindowGeometryChanged(int arg);
|
void dialogWindowGeometryChanged(int arg);
|
||||||
void aboutToQuit();
|
void aboutToQuit();
|
||||||
|
void screenCountChanged(int newCount);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void closeEvent(QCloseEvent*); // Emits a 'closed' signal when this dialog is closed.
|
virtual void closeEvent(QCloseEvent*); // Emits a 'closed' signal when this dialog is closed.
|
||||||
virtual void showEvent(QShowEvent* event);
|
virtual void showEvent(QShowEvent* event);
|
||||||
|
@ -50,6 +51,7 @@ private:
|
||||||
QRect _previousRect;
|
QRect _previousRect;
|
||||||
QScreen* _previousScreen;
|
QScreen* _previousScreen;
|
||||||
QScreen* _hmdScreen;
|
QScreen* _hmdScreen;
|
||||||
|
int _hmdScreenNumber;
|
||||||
QPushButton* _switchModeButton;
|
QPushButton* _switchModeButton;
|
||||||
QLabel* _debugDetails;
|
QLabel* _debugDetails;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue