mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
refs #76 CForeignWindows
Provides static methods to get QWindow pointers to known simulators
This commit is contained in:
66
src/blackgui/foreignwindows.cpp
Normal file
66
src/blackgui/foreignwindows.cpp
Normal 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();
|
||||
}
|
||||
}
|
||||
50
src/blackgui/foreignwindows.h
Normal file
50
src/blackgui/foreignwindows.h
Normal 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
|
||||
Reference in New Issue
Block a user