mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
Ref T256, added foreign window utility functions
This commit is contained in:
@@ -14,55 +14,93 @@
|
|||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
using namespace BlackMisc::Simulation;
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
QScopedPointer<IWindowFinder> CForeignWindows::m_windowFinder(IWindowFinder::create());
|
QScopedPointer<IWindowFinder> CForeignWindows::m_windowFinder(IWindowFinder::create());
|
||||||
|
|
||||||
QWindow *CForeignWindows::getFS9Window()
|
QWindow *CForeignWindows::getFS9Window()
|
||||||
{
|
{
|
||||||
QWindow *simulatorWindow = nullptr;
|
if (!m_windowFinder) { return nullptr; }
|
||||||
simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN");
|
QWindow *simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN");
|
||||||
|
|
||||||
return simulatorWindow;
|
return simulatorWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWindow *CForeignWindows::getFSXWindow()
|
QWindow *CForeignWindows::getFSXWindow()
|
||||||
{
|
{
|
||||||
QWindow *simulatorWindow = nullptr;
|
if (!m_windowFinder) { return nullptr; }
|
||||||
simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN");
|
QWindow *simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN");
|
||||||
|
return simulatorWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWindow *CForeignWindows::getP3DWindow()
|
||||||
|
{
|
||||||
|
if (!m_windowFinder) { return nullptr; }
|
||||||
|
QWindow *simulatorWindow = m_windowFinder->findForeignWindow("", "FS98MAIN");
|
||||||
return simulatorWindow;
|
return simulatorWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWindow *CForeignWindows::getXPlaneWindow()
|
QWindow *CForeignWindows::getXPlaneWindow()
|
||||||
{
|
{
|
||||||
QWindow *simulatorWindow = nullptr;
|
QWindow *simulatorWindow = nullptr;
|
||||||
|
|
||||||
// FIXME:
|
// FIXME:
|
||||||
// Use datarefs Sim/operation/windows/system window via xswiftbus to grab the OS's native window handle
|
// Use datarefs Sim/operation/windows/system window via xswiftbus to grab the OS's native window handle
|
||||||
// http://www.xsquawkbox.net/xpsdk/mediawiki/sim%252Foperation%252Fwindows%252Fsystem_window
|
// http://www.xsquawkbox.net/xpsdk/mediawiki/sim%252Foperation%252Fwindows%252Fsystem_window
|
||||||
// For the time being, use IWindowFinder.
|
// For the time being, use IWindowFinder.
|
||||||
// The if condition is to prevent a crash on Linux/MacOS.
|
// The if condition is to prevent a crash on Linux/MacOS.
|
||||||
if (!m_windowFinder.isNull()) simulatorWindow = m_windowFinder->findForeignWindow("X-System", "");
|
if (!m_windowFinder.isNull()) simulatorWindow = m_windowFinder->findForeignWindow("X-System", "");
|
||||||
|
|
||||||
return simulatorWindow;
|
return simulatorWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CForeignWindows::setSimulatorAsParent(QWindow *simulatorWindow, QWidget *child)
|
QWindow *CForeignWindows::getFirstFoundSimulatorWindow()
|
||||||
{
|
{
|
||||||
if (!simulatorWindow) return;
|
QWindow *w = CForeignWindows::getP3DWindow(); if (w) { return w; }
|
||||||
if (!child) return;
|
w = CForeignWindows::getXPlaneWindow(); if (w) { return w; }
|
||||||
|
w = CForeignWindows::getFSXWindow(); if (w) { return w; }
|
||||||
|
w = CForeignWindows::getFS9Window();
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
bool isVisible = child->isVisible();
|
QWindow *CForeignWindows::getSimulatorWindow(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
switch (simulator.getSimulator())
|
||||||
|
{
|
||||||
|
case CSimulatorInfo::FS9: return CForeignWindows::getFS9Window();
|
||||||
|
case CSimulatorInfo::FSX: return CForeignWindows::getFSXWindow();
|
||||||
|
case CSimulatorInfo::P3D: return CForeignWindows::getP3DWindow();
|
||||||
|
case CSimulatorInfo::XPLANE: return CForeignWindows::getXPlaneWindow();
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CForeignWindows::setSimulatorAsParent(QWindow *simulatorWindow, QWidget *child)
|
||||||
|
{
|
||||||
|
if (!simulatorWindow) { return false; }
|
||||||
|
if (!child) {return false; }
|
||||||
|
|
||||||
// If visible, hide it during the reparent. Otherwise setting the parent will have no effect.
|
// If visible, hide it during the reparent. Otherwise setting the parent will have no effect.
|
||||||
if (isVisible) child->hide();
|
const bool isVisible = child->isVisible();
|
||||||
|
if (isVisible) {child->hide(); }
|
||||||
|
|
||||||
QWindow *childWindow = child->windowHandle();
|
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?");
|
Q_ASSERT_X(childWindow, Q_FUNC_INFO, "Native resources for child widget have not yet been allocated. Did you call QWidget::show() before?");
|
||||||
|
|
||||||
childWindow->setTransientParent(simulatorWindow);
|
childWindow->setTransientParent(simulatorWindow);
|
||||||
|
|
||||||
// If it was visible before, make it visible again
|
// If it was visible before, make it visible again
|
||||||
if (isVisible) child->show();
|
if (isVisible) { child->show(); }
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CForeignWindows::unsetSimulatorAsParent(QWidget *child)
|
||||||
|
{
|
||||||
|
if (!child) { return false; }
|
||||||
|
if (!child->windowHandle()) { return false; }
|
||||||
|
if (!child->windowHandle()->transientParent()) { return false; }
|
||||||
|
child->windowHandle()->setTransientParent(nullptr);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#define BLACKGUI_FOREIGNWINDOWS_H
|
#define BLACKGUI_FOREIGNWINDOWS_H
|
||||||
|
|
||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
|
#include "blackmisc/simulation/simulatorinfo.h"
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
|
||||||
class QWidget;
|
class QWidget;
|
||||||
@@ -26,23 +26,32 @@ namespace BlackGui
|
|||||||
//! Foreign windows
|
//! Foreign windows
|
||||||
class BLACKGUI_EXPORT CForeignWindows
|
class BLACKGUI_EXPORT CForeignWindows
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! FS9 window
|
//! FS9 window
|
||||||
static QWindow *getFS9Window();
|
static QWindow *getFS9Window();
|
||||||
|
|
||||||
//! FSX window
|
//! FSX window
|
||||||
static QWindow *getFSXWindow();
|
static QWindow *getFSXWindow();
|
||||||
|
|
||||||
|
//! P3D window
|
||||||
|
static QWindow *getP3DWindow();
|
||||||
|
|
||||||
//! X-Plane window
|
//! X-Plane window
|
||||||
static QWindow *getXPlaneWindow();
|
static QWindow *getXPlaneWindow();
|
||||||
|
|
||||||
|
//! First simulator window found
|
||||||
|
static QWindow *getFirstFoundSimulatorWindow();
|
||||||
|
|
||||||
|
//! Simulator window
|
||||||
|
static QWindow *getSimulatorWindow(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
|
|
||||||
//! Set simulator as transient parent for child widget
|
//! Set simulator as transient parent for child widget
|
||||||
static void setSimulatorAsParent(QWindow *simulatorWindow, QWidget *child);
|
static bool setSimulatorAsParent(QWindow *simulatorWindow, QWidget *child);
|
||||||
|
|
||||||
|
//! Unset the parent
|
||||||
|
static bool unsetSimulatorAsParent(QWidget *child);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//! Constructor, use static methods only
|
//! Constructor, use static methods only
|
||||||
CForeignWindows() {}
|
CForeignWindows() {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user