refs #76 CForeignWindows

Provides static methods to get QWindow pointers to known simulators
This commit is contained in:
Roland Winklmeier
2014-08-26 22:51:07 +02:00
parent 53a42e3dd8
commit adc25f5f3d
2 changed files with 116 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
/* Copyright (C) 2014
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "foreignwindows.h"
#include <QWidget>
#include <QWindow>
#include <QApplication>
namespace BlackGui
{
QScopedPointer<IWindowFinder> CForeignWindows::m_windowFinder(IWindowFinder::create());
QWindow *CForeignWindows::getFS9Window()
{
QWindow *simulatorWindow = nullptr;
simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN");
return simulatorWindow;
}
QWindow *CForeignWindows::getFSXWindow()
{
QWindow *simulatorWindow = nullptr;
simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN");
return simulatorWindow;
}
QWindow *CForeignWindows::getXPlaneWindow()
{
QWindow *simulatorWindow = nullptr;
// FIXME:
// Use datarefs Sim/operation/windows/system window via xbus to grab the OS's native window handle
// http://www.xsquawkbox.net/xpsdk/mediawiki/sim%252Foperation%252Fwindows%252Fsystem_window
// For the time being, use IWindowFinder.
// The if condition is to prevent a crash on Linux/OSX.
if (!m_windowFinder.isNull()) simulatorWindow = m_windowFinder->findForeignWindow("X-System", "");
return simulatorWindow;
}
void CForeignWindows::setSimulatorAsParent(QWindow *simulatorWindow, QWidget *child)
{
if (!simulatorWindow) return;
if (!child) return;
bool isVisible = child->isVisible();
// If visible, hide it during the reparent. Otherwise setting the parent will have no effect.
if (isVisible) child->hide();
QWindow *childWindow = child->windowHandle();
Q_ASSERT_X(childWindow, "CForeignWindows::setSimulatorAsParent", "Native resources for child widget have not yet been allocated. Did you call QWidget::show() before?");
childWindow->setTransientParent(simulatorWindow);
// If it was visible before, make it visible again
if (isVisible) child->show();
}
}

View File

@@ -0,0 +1,50 @@
/* Copyright (C) 2014
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_FOREIGNWINDOWS_H
#define BLACKGUI_FOREIGNWINDOWS_H
#include "blacksim/simulatorinfo.h"
#include "windowfinder.h"
#include <QWindow>
#include <QWidget>
#include <QScopedPointer>
namespace BlackGui
{
//! Foreign windows
class CForeignWindows
{
public:
//! FS9 window
static QWindow *getFS9Window();
//! FSX window
static QWindow *getFSXWindow();
//! X-Plane window
static QWindow *getXPlaneWindow();
//! Set simulator as transient parent for child widget
static void setSimulatorAsParent(QWindow *simulatorWindow, QWidget *child);
private:
//! Constructor, use static methods only
CForeignWindows() {}
static QScopedPointer<IWindowFinder> m_windowFinder;
};
}
#endif // guard