mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 19:04:29 +02:00
Merge pull request #3871 from ZappoMan/HMDMode
Various HMD Tools improvements
This commit is contained in:
commit
56b27a2595
3 changed files with 114 additions and 56 deletions
|
@ -438,6 +438,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
|
|
||||||
void Application::aboutToQuit() {
|
void Application::aboutToQuit() {
|
||||||
_aboutToQuit = true;
|
_aboutToQuit = true;
|
||||||
|
setFullscreen(false); // if you exit while in full screen, you'll get bad behavior when you restart.
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application() {
|
Application::~Application() {
|
||||||
|
|
|
@ -30,27 +30,27 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) :
|
||||||
QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) ,
|
QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) ,
|
||||||
_previousScreen(NULL),
|
_previousScreen(NULL),
|
||||||
_hmdScreen(NULL),
|
_hmdScreen(NULL),
|
||||||
_previousDialogScreen(NULL)
|
_hmdScreenNumber(-1),
|
||||||
|
_switchModeButton(NULL),
|
||||||
|
_debugDetails(NULL),
|
||||||
|
_previousDialogScreen(NULL),
|
||||||
|
_inHDMMode(false)
|
||||||
{
|
{
|
||||||
this->setWindowTitle("HMD Tools");
|
this->setWindowTitle("HMD Tools");
|
||||||
|
|
||||||
// Create layouter
|
// Create layouter
|
||||||
QFormLayout* form = new QFormLayout();
|
QFormLayout* form = new QFormLayout();
|
||||||
|
const int WIDTH = 350;
|
||||||
|
|
||||||
// Add a button to enter
|
// Add a button to enter
|
||||||
QPushButton* enterModeButton = new QPushButton("Enter HMD Mode");
|
_switchModeButton = new QPushButton("Enter HMD Mode");
|
||||||
form->addRow("", enterModeButton);
|
_switchModeButton->setFixedWidth(WIDTH);
|
||||||
connect(enterModeButton,SIGNAL(clicked(bool)),this,SLOT(enterModeClicked(bool)));
|
form->addRow("", _switchModeButton);
|
||||||
|
connect(_switchModeButton,SIGNAL(clicked(bool)),this,SLOT(switchModeClicked(bool)));
|
||||||
// Add a button to leave
|
|
||||||
QPushButton* leaveModeButton = new QPushButton("Leave HMD Mode");
|
|
||||||
form->addRow("", leaveModeButton);
|
|
||||||
connect(leaveModeButton,SIGNAL(clicked(bool)),this,SLOT(leaveModeClicked(bool)));
|
|
||||||
|
|
||||||
// Create a label with debug details...
|
// Create a label with debug details...
|
||||||
_debugDetails = new QLabel();
|
_debugDetails = new QLabel();
|
||||||
_debugDetails->setText(getDebugDetails());
|
_debugDetails->setText(getDebugDetails());
|
||||||
const int WIDTH = 350;
|
|
||||||
const int HEIGHT = 100;
|
const int HEIGHT = 100;
|
||||||
_debugDetails->setFixedSize(WIDTH, HEIGHT);
|
_debugDetails->setFixedSize(WIDTH, HEIGHT);
|
||||||
form->addRow("", _debugDetails);
|
form->addRow("", _debugDetails);
|
||||||
|
@ -65,14 +65,21 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) :
|
||||||
QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle();
|
QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle();
|
||||||
connect(mainWindow, &QWindow::screenChanged, this, &HMDToolsDialog::applicationWindowScreenChanged);
|
connect(mainWindow, &QWindow::screenChanged, this, &HMDToolsDialog::applicationWindowScreenChanged);
|
||||||
|
|
||||||
// watch for our dialog window moving screens. If it does we want to enforce our rules about what screens we're
|
// watch for our dialog window moving screens. If it does we want to enforce our rules about
|
||||||
// allowed on
|
// what screens we're allowed on
|
||||||
QWindow* dialogWindow = windowHandle();
|
QWindow* dialogWindow = windowHandle();
|
||||||
connect(dialogWindow, &QWindow::screenChanged, this, &HMDToolsDialog::dialogWindowScreenChanged);
|
connect(dialogWindow, &QWindow::screenChanged, this, &HMDToolsDialog::dialogWindowScreenChanged);
|
||||||
connect(dialogWindow, &QWindow::xChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged);
|
connect(dialogWindow, &QWindow::xChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged);
|
||||||
connect(dialogWindow, &QWindow::yChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged);
|
connect(dialogWindow, &QWindow::yChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged);
|
||||||
connect(dialogWindow, &QWindow::widthChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged);
|
connect(dialogWindow, &QWindow::widthChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged);
|
||||||
connect(dialogWindow, &QWindow::heightChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged);
|
connect(dialogWindow, &QWindow::heightChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged);
|
||||||
|
|
||||||
|
// when the application is about to quit, leave HDM mode
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HMDToolsDialog::~HMDToolsDialog() {
|
HMDToolsDialog::~HMDToolsDialog() {
|
||||||
|
@ -96,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) {
|
||||||
|
|
||||||
|
// we want to use a local variable here because we are not necesarily in HMD mode
|
||||||
int hmdScreenNumber = OculusManager::getHMDScreen();
|
int hmdScreenNumber = OculusManager::getHMDScreen();
|
||||||
|
if (_hmdScreenNumber >= 0) {
|
||||||
if (hmdScreenNumber >= 0) {
|
|
||||||
QScreen* hmdScreen = QGuiApplication::screens()[hmdScreenNumber];
|
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();
|
||||||
|
@ -154,25 +161,35 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HMDToolsDialog::enterModeClicked(bool checked) {
|
void HMDToolsDialog::switchModeClicked(bool checked) {
|
||||||
|
if (!_inHDMMode) {
|
||||||
|
enterHDMMode();
|
||||||
|
} else {
|
||||||
|
leaveHDMMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HMDToolsDialog::enterHDMMode() {
|
||||||
|
if (!_inHDMMode) {
|
||||||
|
_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);
|
||||||
|
|
||||||
|
@ -190,6 +207,9 @@ void HMDToolsDialog::enterModeClicked(bool checked) {
|
||||||
|
|
||||||
const int SLIGHT_DELAY = 500;
|
const int SLIGHT_DELAY = 500;
|
||||||
QTimer::singleShot(SLIGHT_DELAY, this, SLOT(activateWindowAfterEnterMode()));
|
QTimer::singleShot(SLIGHT_DELAY, this, SLOT(activateWindowAfterEnterMode()));
|
||||||
|
|
||||||
|
_inHDMMode = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HMDToolsDialog::activateWindowAfterEnterMode() {
|
void HMDToolsDialog::activateWindowAfterEnterMode() {
|
||||||
|
@ -199,8 +219,9 @@ void HMDToolsDialog::activateWindowAfterEnterMode() {
|
||||||
centerCursorOnWidget(Application::getInstance()->getWindow());
|
centerCursorOnWidget(Application::getInstance()->getWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HMDToolsDialog::leaveHDMMode() {
|
||||||
void HMDToolsDialog::leaveModeClicked(bool checked) {
|
if (_inHDMMode) {
|
||||||
|
_switchModeButton->setText("Enter HMD Mode");
|
||||||
_debugDetails->setText(getDebugDetails());
|
_debugDetails->setText(getDebugDetails());
|
||||||
|
|
||||||
Application::getInstance()->setFullscreen(false);
|
Application::getInstance()->setFullscreen(false);
|
||||||
|
@ -216,6 +237,8 @@ void HMDToolsDialog::leaveModeClicked(bool checked) {
|
||||||
QTimer::singleShot(SLIGHT_DELAY, this, SLOT(moveWindowAfterLeaveMode()));
|
QTimer::singleShot(SLIGHT_DELAY, this, SLOT(moveWindowAfterLeaveMode()));
|
||||||
}
|
}
|
||||||
_wasMoved = false;
|
_wasMoved = false;
|
||||||
|
_inHDMMode = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HMDToolsDialog::moveWindowAfterLeaveMode() {
|
void HMDToolsDialog::moveWindowAfterLeaveMode() {
|
||||||
|
@ -256,3 +279,31 @@ void HMDToolsDialog::hideEvent(QHideEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HMDToolsDialog::aboutToQuit() {
|
||||||
|
if (_inHDMMode) {
|
||||||
|
leaveHDMMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,13 +28,14 @@ signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void reject();
|
void reject();
|
||||||
void enterModeClicked(bool checked);
|
void switchModeClicked(bool checked);
|
||||||
void leaveModeClicked(bool checked);
|
|
||||||
void activateWindowAfterEnterMode();
|
void activateWindowAfterEnterMode();
|
||||||
void moveWindowAfterLeaveMode();
|
void moveWindowAfterLeaveMode();
|
||||||
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 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.
|
||||||
|
@ -43,15 +44,20 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void centerCursorOnWidget(QWidget* widget);
|
void centerCursorOnWidget(QWidget* widget);
|
||||||
|
void enterHDMMode();
|
||||||
|
void leaveHDMMode();
|
||||||
|
|
||||||
bool _wasMoved;
|
bool _wasMoved;
|
||||||
QRect _previousRect;
|
QRect _previousRect;
|
||||||
QScreen* _previousScreen;
|
QScreen* _previousScreen;
|
||||||
QScreen* _hmdScreen;
|
QScreen* _hmdScreen;
|
||||||
|
int _hmdScreenNumber;
|
||||||
|
QPushButton* _switchModeButton;
|
||||||
QLabel* _debugDetails;
|
QLabel* _debugDetails;
|
||||||
|
|
||||||
QRect _previousDialogRect;
|
QRect _previousDialogRect;
|
||||||
QScreen* _previousDialogScreen;
|
QScreen* _previousDialogScreen;
|
||||||
|
bool _inHDMMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_HMDToolsDialog_h
|
#endif // hifi_HMDToolsDialog_h
|
||||||
|
|
Loading…
Reference in a new issue