Merge pull request #5550 from jherico/marge

PLUGINS - Cleaning up HMD tools
This commit is contained in:
Brad Hefta-Gaub 2015-08-11 10:46:59 -07:00
commit 35d6528d08
4 changed files with 87 additions and 102 deletions

View file

@ -4595,18 +4595,22 @@ void Application::updateDisplayMode() {
_offscreenContext->makeCurrent(); _offscreenContext->makeCurrent();
offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize())); offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize()));
_offscreenContext->makeCurrent(); _offscreenContext->makeCurrent();
if (newDisplayPlugin->isHmd()) {
showDisplayPluginsTools();
}
} }
oldDisplayPlugin = _displayPlugin; oldDisplayPlugin = _displayPlugin;
_displayPlugin = newDisplayPlugin; _displayPlugin = newDisplayPlugin;
// Only show the hmd tools after the correct plugin has
// been activated so that it's UI is setup correctly
if (newDisplayPlugin->isHmd()) {
showDisplayPluginsTools();
}
if (oldDisplayPlugin) { if (oldDisplayPlugin) {
oldDisplayPlugin->deactivate(); oldDisplayPlugin->deactivate();
_offscreenContext->makeCurrent(); _offscreenContext->makeCurrent();
} }
emit activeDisplayPluginChanged();
resetSensors(); resetSensors();
} }
Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin");

View file

@ -372,6 +372,7 @@ signals:
void fullAvatarURLChanged(const QString& newValue, const QString& modelName); void fullAvatarURLChanged(const QString& newValue, const QString& modelName);
void beforeAboutToQuit(); void beforeAboutToQuit();
void activeDisplayPluginChanged();
public slots: public slots:
void setSessionUUID(const QUuid& sessionUUID); void setSessionUUID(const QUuid& sessionUUID);

View file

@ -27,62 +27,51 @@
#include "ui/DialogsManager.h" #include "ui/DialogsManager.h"
#include "ui/HMDToolsDialog.h" #include "ui/HMDToolsDialog.h"
static const int WIDTH = 350;
static const int HEIGHT = 100;
HMDToolsDialog::HMDToolsDialog(QWidget* parent) : HMDToolsDialog::HMDToolsDialog(QWidget* parent) :
QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) , QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint)
_previousScreen(NULL),
_hmdScreen(NULL),
_hmdScreenNumber(-1),
_switchModeButton(NULL),
_debugDetails(NULL),
_previousDialogScreen(NULL),
_inHDMMode(false)
{ {
// FIXME do we want to support more than one connected HMD? It seems like a pretty corner case // FIXME do we want to support more than one connected HMD? It seems like a pretty corner case
foreach(auto dp, PluginManager::getInstance()->getDisplayPlugins()) { foreach(auto displayPlugin, PluginManager::getInstance()->getDisplayPlugins()) {
// The first plugin is always the standard 2D display, by convention // The first plugin is always the standard 2D display, by convention
if (_defaultPluginName.isEmpty()) { if (_defaultPluginName.isEmpty()) {
_defaultPluginName = dp->getName(); _defaultPluginName = displayPlugin->getName();
continue; continue;
} }
if (dp->isHmd()) { if (displayPlugin->isHmd()) {
// Not all HMD's have corresponding screens // Not all HMD's have corresponding screens
if (dp->getHmdScreen() >= 0) { if (displayPlugin->getHmdScreen() >= 0) {
_hmdScreenNumber = dp->getHmdScreen(); _hmdScreenNumber = displayPlugin->getHmdScreen();
} }
_hmdPluginName = dp->getName(); _hmdPluginName = displayPlugin->getName();
break; break;
} }
} }
this->setWindowTitle("HMD Tools"); setWindowTitle("HMD Tools");
// Create layouter // Create layouter
QFormLayout* form = new QFormLayout(); {
const int WIDTH = 350; QFormLayout* form = new QFormLayout();
// Add a button to enter
_switchModeButton = new QPushButton("Toggle HMD Mode");
if (_hmdPluginName.isEmpty()) {
_switchModeButton->setEnabled(false);
}
// Add a button to enter
_switchModeButton->setFixedWidth(WIDTH);
form->addRow("", _switchModeButton);
// Create a label with debug details...
_debugDetails = new QLabel();
_debugDetails->setFixedSize(WIDTH, HEIGHT);
form->addRow("", _debugDetails);
setLayout(form);
}
// Add a button to enter qApp->getWindow()->activateWindow();
_switchModeButton = new QPushButton("Enter HMD Mode");
_switchModeButton->setFixedWidth(WIDTH);
form->addRow("", _switchModeButton);
connect(_switchModeButton,SIGNAL(clicked(bool)),this,SLOT(switchModeClicked(bool)));
// Create a label with debug details...
_debugDetails = new QLabel();
_debugDetails->setText(getDebugDetails());
const int HEIGHT = 100;
_debugDetails->setFixedSize(WIDTH, HEIGHT);
form->addRow("", _debugDetails);
this->QDialog::setLayout(form);
Application::getInstance()->getWindow()->activateWindow();
// watch for our application window moving screens. If it does we want to update our screen details
QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle();
connect(mainWindow, &QWindow::screenChanged, this, &HMDToolsDialog::applicationWindowScreenChanged);
// watch for our dialog window moving screens. If it does we want to enforce our rules about // watch for our dialog window moving screens. If it does we want to enforce our rules about
// what screens we're allowed on // what screens we're allowed on
@ -104,11 +93,31 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) :
watchWindow(dialogsManager->getLodToolsDialog()->windowHandle()); watchWindow(dialogsManager->getLodToolsDialog()->windowHandle());
} }
connect(_switchModeButton, &QPushButton::clicked, [this]{
toggleHMDMode();
});
// when the application is about to quit, leave HDM mode // when the application is about to quit, leave HDM mode
connect(Application::getInstance(), SIGNAL(beforeAboutToQuit()), this, SLOT(aboutToQuit())); connect(qApp, &Application::beforeAboutToQuit, [this]{
// FIXME this is ineffective because it doesn't trigger the menu to
// save the fact that VR Mode is not checked.
leaveHMDMode();
});
connect(qApp, &Application::activeDisplayPluginChanged, [this]{
updateUi();
});
// watch for our application window moving screens. If it does we want to update our screen details
QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle();
connect(mainWindow, &QWindow::screenChanged, [this]{
updateUi();
});
// keep track of changes to the number of screens // keep track of changes to the number of screens
connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &HMDToolsDialog::screenCountChanged); connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &HMDToolsDialog::screenCountChanged);
updateUi();
} }
HMDToolsDialog::~HMDToolsDialog() { HMDToolsDialog::~HMDToolsDialog() {
@ -118,10 +127,6 @@ HMDToolsDialog::~HMDToolsDialog() {
_windowWatchers.clear(); _windowWatchers.clear();
} }
void HMDToolsDialog::applicationWindowScreenChanged(QScreen* screen) {
_debugDetails->setText(getDebugDetails());
}
QString HMDToolsDialog::getDebugDetails() const { QString HMDToolsDialog::getDebugDetails() const {
QString results; QString results;
@ -143,38 +148,25 @@ QString HMDToolsDialog::getDebugDetails() const {
return results; return results;
} }
void HMDToolsDialog::switchModeClicked(bool checked) { void HMDToolsDialog::toggleHMDMode() {
if (!_inHDMMode) { if (!qApp->isHMDMode()) {
enterHDMMode(); enterHMDMode();
} else { } else {
leaveHDMMode(); leaveHMDMode();
} }
} }
void HMDToolsDialog::enterHDMMode() { void HMDToolsDialog::enterHMDMode() {
if (!_inHDMMode) { if (!qApp->isHMDMode()) {
_switchModeButton->setText("Leave HMD Mode");
_debugDetails->setText(getDebugDetails());
// if we're on a single screen setup, then hide our tools window when entering HMD mode
if (QApplication::desktop()->screenCount() == 1) {
close();
}
Application::getInstance()->setActiveDisplayPlugin(_hmdPluginName); Application::getInstance()->setActiveDisplayPlugin(_hmdPluginName);
_inHDMMode = true;
Application::getInstance()->getWindow()->activateWindow(); Application::getInstance()->getWindow()->activateWindow();
} }
} }
void HMDToolsDialog::leaveHDMMode() { void HMDToolsDialog::leaveHMDMode() {
if (_inHDMMode) { if (qApp->isHMDMode()) {
_switchModeButton->setText("Enter HMD Mode");
_debugDetails->setText(getDebugDetails());
Application::getInstance()->setActiveDisplayPlugin(_defaultPluginName); Application::getInstance()->setActiveDisplayPlugin(_defaultPluginName);
Application::getInstance()->getWindow()->activateWindow(); Application::getInstance()->getWindow()->activateWindow();
_inHDMMode = false;
} }
} }
@ -185,7 +177,7 @@ void HMDToolsDialog::reject() {
void HMDToolsDialog::closeEvent(QCloseEvent* event) { void HMDToolsDialog::closeEvent(QCloseEvent* event) {
// TODO: consider if we want to prevent closing of this window with event->ignore(); // TODO: consider if we want to prevent closing of this window with event->ignore();
this->QDialog::closeEvent(event); QDialog::closeEvent(event);
emit closed(); emit closed();
} }
@ -196,16 +188,15 @@ void HMDToolsDialog::centerCursorOnWidget(QWidget* widget) {
QCursor::setPos(screen, windowCenter); QCursor::setPos(screen, windowCenter);
} }
void HMDToolsDialog::updateUi() {
_switchModeButton->setText(qApp->isHMDMode() ? "Leave HMD Mode" : "Enter HMD Mode");
_debugDetails->setText(getDebugDetails());
}
void HMDToolsDialog::showEvent(QShowEvent* event) { void HMDToolsDialog::showEvent(QShowEvent* event) {
// center the cursor on the hmd tools dialog // center the cursor on the hmd tools dialog
centerCursorOnWidget(this); centerCursorOnWidget(this);
if (qApp->isHMDMode()) { updateUi();
_inHDMMode = true;
_switchModeButton->setText("Leave HMD Mode");
} else {
_inHDMMode = false;
_switchModeButton->setText("Enter HMD Mode");
}
} }
void HMDToolsDialog::hideEvent(QHideEvent* event) { void HMDToolsDialog::hideEvent(QHideEvent* event) {
@ -213,15 +204,6 @@ void HMDToolsDialog::hideEvent(QHideEvent* event) {
centerCursorOnWidget(Application::getInstance()->getWindow()); centerCursorOnWidget(Application::getInstance()->getWindow());
} }
void HMDToolsDialog::aboutToQuit() {
if (_inHDMMode) {
// FIXME this is ineffective because it doesn't trigger the menu to
// save the fact that VR Mode is not checked.
leaveHDMMode();
}
}
void HMDToolsDialog::screenCountChanged(int newCount) { void HMDToolsDialog::screenCountChanged(int newCount) {
int hmdScreenNumber = -1; int hmdScreenNumber = -1;
auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins(); auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins();
@ -234,19 +216,19 @@ void HMDToolsDialog::screenCountChanged(int newCount) {
} }
} }
if (qApp->isHMDMode() && _hmdScreenNumber != hmdScreenNumber) {
if (_inHDMMode && _hmdScreenNumber != hmdScreenNumber) {
qDebug() << "HMD Display changed WHILE IN HMD MODE"; qDebug() << "HMD Display changed WHILE IN HMD MODE";
leaveHDMMode(); leaveHMDMode();
// if there is a new best HDM screen then go back into HDM mode after done leaving // if there is a new best HDM screen then go back into HDM mode after done leaving
if (hmdScreenNumber >= 0) { if (hmdScreenNumber >= 0) {
qDebug() << "Trying to go back into HDM Mode"; qDebug() << "Trying to go back into HMD Mode";
const int SLIGHT_DELAY = 2000; const int SLIGHT_DELAY = 2000;
QTimer::singleShot(SLIGHT_DELAY, this, SLOT(enterHDMMode())); QTimer::singleShot(SLIGHT_DELAY, [this]{
enterHMDMode();
});
} }
} }
_debugDetails->setText(getDebugDetails());
} }
void HMDToolsDialog::watchWindow(QWindow* window) { void HMDToolsDialog::watchWindow(QWindow* window) {

View file

@ -34,9 +34,6 @@ signals:
public slots: public slots:
void reject(); void reject();
void switchModeClicked(bool checked);
void applicationWindowScreenChanged(QScreen* screen);
void aboutToQuit();
void screenCountChanged(int newCount); void screenCountChanged(int newCount);
protected: protected:
@ -46,18 +43,19 @@ protected:
private: private:
void centerCursorOnWidget(QWidget* widget); void centerCursorOnWidget(QWidget* widget);
void enterHDMMode(); void enterHMDMode();
void leaveHDMMode(); void leaveHMDMode();
void toggleHMDMode();
void updateUi();
QScreen* _previousScreen; QScreen* _previousScreen{ nullptr };
QScreen* _hmdScreen; QScreen* _hmdScreen{ nullptr };
int _hmdScreenNumber; int _hmdScreenNumber{ -1 };
QPushButton* _switchModeButton; QPushButton* _switchModeButton{ nullptr };
QLabel* _debugDetails; QLabel* _debugDetails{ nullptr };
QRect _previousDialogRect; QRect _previousDialogRect;
QScreen* _previousDialogScreen; QScreen* _previousDialogScreen{ nullptr };
bool _inHDMMode;
QString _hmdPluginName; QString _hmdPluginName;
QString _defaultPluginName; QString _defaultPluginName;