From ec54b609df13d20a01fe0ecbb18e6550ba2ba5e1 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 10 Dec 2014 17:23:39 -0800 Subject: [PATCH] dry up code and make chat window avoid the hmd screen --- interface/src/Application.cpp | 24 +++++++++++++++++++++++ interface/src/Application.h | 2 ++ interface/src/ui/ChatWindow.cpp | 2 +- interface/src/ui/FramelessDialog.cpp | 24 ++--------------------- interface/src/ui/RunningScriptsWidget.cpp | 22 +-------------------- 5 files changed, 30 insertions(+), 44 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index dc4b66ad93..cb3acc88f1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -2714,6 +2715,29 @@ bool Application::isHMDMode() const { } } +QRect Application::getDesirableApplicationGeometry() { + QRect applicationGeometry = getWindow()->geometry(); + + // If our parent window is on the HMD, then don't use it's geometry, instead use + // the "main screen" geometry. + HMDToolsDialog* hmdTools = Menu::getInstance()->getHMDToolsDialog(); + if (hmdTools && hmdTools->hasHMDScreen()) { + QScreen* hmdScreen = hmdTools->getHMDScreen(); + QWindow* appWindow = getWindow()->windowHandle(); + QScreen* appScreen = appWindow->screen(); + + // if our app's screen is the hmd screen, we don't want to place the + // running scripts widget on it. So we need to pick a better screen. + // we will use the screen for the HMDTools since it's a guarenteed + // better screen. + if (appScreen == hmdScreen) { + QScreen* betterScreen = hmdTools->windowHandle()->screen(); + applicationGeometry = betterScreen->geometry(); + } + } + return applicationGeometry; +} + ///////////////////////////////////////////////////////////////////////////////////// // loadViewFrustum() // diff --git a/interface/src/Application.h b/interface/src/Application.h index 0f0bd91210..217d547c89 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -327,6 +327,8 @@ public: // rendering of several elements depend on that // TODO: carry that information on the Camera as a setting bool isHMDMode() const; + + QRect getDesirableApplicationGeometry(); signals: diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 7869926ebe..747b4ae68d 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -124,7 +124,7 @@ void ChatWindow::showEvent(QShowEvent* event) { if (!event->spontaneous()) { _ui->messagePlainTextEdit->setFocus(); } - const QRect parentGeometry = parentWidget()->geometry(); + QRect parentGeometry = Application::getInstance()->getDesirableApplicationGeometry(); int titleBarHeight = UIUtil::getWindowTitleBarHeight(this); int menuBarHeight = Menu::getInstance()->geometry().height(); int topMargin = titleBarHeight + menuBarHeight; diff --git a/interface/src/ui/FramelessDialog.cpp b/interface/src/ui/FramelessDialog.cpp index 8a170ab78d..280354d974 100644 --- a/interface/src/ui/FramelessDialog.cpp +++ b/interface/src/ui/FramelessDialog.cpp @@ -94,29 +94,9 @@ void FramelessDialog::showEvent(QShowEvent* event) { } void FramelessDialog::resizeAndPosition(bool resizeParent) { - QSize parentSize = parentWidget()->size(); - QRect parentGeometry = parentWidget()->geometry(); + QRect parentGeometry = Application::getInstance()->getDesirableApplicationGeometry(); + QSize parentSize = parentGeometry.size(); - // If our parent window is on the HMD, then don't use it's geometry, instead use - // the "main screen" geometry. - HMDToolsDialog* hmdTools = Menu::getInstance()->getHMDToolsDialog(); - if (hmdTools && hmdTools->hasHMDScreen()) { - QScreen* hmdScreen = hmdTools->getHMDScreen(); - QWindow* appWindow = parentWidget()->windowHandle(); - QScreen* appScreen = appWindow->screen(); - - // if our app's screen is the hmd screen, we don't want to place the - // running scripts widget on it. So we need to pick a better screen. - // we will use the screen for the HMDTools since it's a guarenteed - // better screen. - if (appScreen == hmdScreen) { - QScreen* betterScreen = hmdTools->windowHandle()->screen(); - parentGeometry = betterScreen->geometry(); - parentSize = betterScreen->size(); - } - - } - // keep full app height or width depending on position if (_position == POSITION_LEFT || _position == POSITION_RIGHT) { setFixedHeight(parentSize.height()); diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 4fd19d4588..cfd7428482 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -151,27 +151,7 @@ void RunningScriptsWidget::showEvent(QShowEvent* event) { ui->filterLineEdit->setFocus(); } - QRect parentGeometry = parentWidget()->geometry(); - - // If our parent window is on the HMD, then don't use it's geometry, instead use - // the "main screen" geometry. - HMDToolsDialog* hmdTools = Menu::getInstance()->getHMDToolsDialog(); - if (hmdTools && hmdTools->hasHMDScreen()) { - QScreen* hmdScreen = hmdTools->getHMDScreen(); - QWindow* appWindow = parentWidget()->windowHandle(); - QScreen* appScreen = appWindow->screen(); - - // if our app's screen is the hmd screen, we don't want to place the - // running scripts widget on it. So we need to pick a better screen. - // we will use the screen for the HMDTools since it's a guarenteed - // better screen. - if (appScreen == hmdScreen) { - QScreen* betterScreen = hmdTools->windowHandle()->screen(); - parentGeometry = betterScreen->geometry(); - } - - } - + QRect parentGeometry = Application::getInstance()->getDesirableApplicationGeometry(); int titleBarHeight = UIUtil::getWindowTitleBarHeight(this); int menuBarHeight = Menu::getInstance()->geometry().height(); int topMargin = titleBarHeight + menuBarHeight;