Popup window tracking helper hooked up
This commit is contained in:
parent
37dc418ce1
commit
fa72d8dd06
5 changed files with 34 additions and 6 deletions
|
@ -48,6 +48,7 @@
|
||||||
#include "QmlAircraftInfo.hxx"
|
#include "QmlAircraftInfo.hxx"
|
||||||
#include "LauncherArgumentTokenizer.hxx"
|
#include "LauncherArgumentTokenizer.hxx"
|
||||||
#include "PathUrlHelper.hxx"
|
#include "PathUrlHelper.hxx"
|
||||||
|
#include "PopupWindowTracker.hxx"
|
||||||
|
|
||||||
#include "ui_Launcher.h"
|
#include "ui_Launcher.h"
|
||||||
|
|
||||||
|
@ -245,6 +246,7 @@ void LauncherMainWindow::initQML()
|
||||||
|
|
||||||
qmlRegisterType<FlickableExtentQuery>("FlightGear.Launcher", 1, 0, "FlickableExtentQuery");
|
qmlRegisterType<FlickableExtentQuery>("FlightGear.Launcher", 1, 0, "FlickableExtentQuery");
|
||||||
qmlRegisterType<QmlAircraftInfo>("FlightGear.Launcher", 1, 0, "AircraftInfo");
|
qmlRegisterType<QmlAircraftInfo>("FlightGear.Launcher", 1, 0, "AircraftInfo");
|
||||||
|
qmlRegisterType<PopupWindowTracker>("FlightGear.Launcher", 1, 0, "PopupWindowTracker");
|
||||||
|
|
||||||
m_config = new LaunchConfig(this);
|
m_config = new LaunchConfig(this);
|
||||||
connect(m_config, &LaunchConfig::collect, this, &LauncherMainWindow::collectAircraftArgs);
|
connect(m_config, &LaunchConfig::collect, this, &LauncherMainWindow::collectAircraftArgs);
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
PopupWindowTracker::PopupWindowTracker(QObject *parent) : QObject(parent)
|
PopupWindowTracker::PopupWindowTracker(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
connect(qGuiApp, &QGuiApplication::applicationStateChanged,
|
||||||
|
this, &PopupWindowTracker::onApplicationStateChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
PopupWindowTracker::~PopupWindowTracker()
|
PopupWindowTracker::~PopupWindowTracker()
|
||||||
|
@ -35,6 +37,14 @@ void PopupWindowTracker::setWindow(QWindow *window)
|
||||||
emit windowChanged(m_window);
|
emit windowChanged(m_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PopupWindowTracker::onApplicationStateChanged(Qt::ApplicationState as)
|
||||||
|
{
|
||||||
|
if (m_window && (as != Qt::ApplicationActive)) {
|
||||||
|
m_window->close();
|
||||||
|
setWindow(nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool PopupWindowTracker::eventFilter(QObject *watched, QEvent *event)
|
bool PopupWindowTracker::eventFilter(QObject *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
if (!m_window)
|
if (!m_window)
|
||||||
|
@ -42,10 +52,16 @@ bool PopupWindowTracker::eventFilter(QObject *watched, QEvent *event)
|
||||||
|
|
||||||
if (event->type() == QEvent::MouseButtonPress) {
|
if (event->type() == QEvent::MouseButtonPress) {
|
||||||
QMouseEvent* me = static_cast<QMouseEvent*>(event);
|
QMouseEvent* me = static_cast<QMouseEvent*>(event);
|
||||||
QPoint windowPos = m_window->mapFromGlobal(me->globalPos());
|
QRect globalGeometry(m_window->mapToGlobal(QPoint(0,0)), m_window->size());
|
||||||
}
|
|
||||||
|
|
||||||
// also check for app loosing focus
|
if (globalGeometry.contains(me->globalPos())) {
|
||||||
|
// click inside the window, process as normal fall through
|
||||||
|
} else {
|
||||||
|
m_window->close();
|
||||||
|
setWindow(nullptr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ signals:
|
||||||
public slots:
|
public slots:
|
||||||
void setWindow(QWindow* window);
|
void setWindow(QWindow* window);
|
||||||
|
|
||||||
|
void onApplicationStateChanged(Qt::ApplicationState as);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,6 +73,7 @@ Rectangle {
|
||||||
popupFrame.x = screenPos.x;
|
popupFrame.x = screenPos.x;
|
||||||
popupFrame.y = screenPos.y;
|
popupFrame.y = screenPos.y;
|
||||||
popupFrame.visible = true
|
popupFrame.visible = true
|
||||||
|
tracker.window = popupFrame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,10 +82,13 @@ Rectangle {
|
||||||
id: aircraftInfo
|
id: aircraftInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PopupWindowTracker {
|
||||||
|
id: tracker
|
||||||
|
}
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
id: popupFrame
|
id: popupFrame
|
||||||
|
|
||||||
modality: Qt.WindowModal
|
|
||||||
width: root.width
|
width: root.width
|
||||||
flags: Qt.Popup
|
flags: Qt.Popup
|
||||||
height: choicesColumn.childrenRect.height
|
height: choicesColumn.childrenRect.height
|
||||||
|
|
|
@ -111,13 +111,17 @@ Item {
|
||||||
popupFrame.x = screenPos.x;
|
popupFrame.x = screenPos.x;
|
||||||
popupFrame.y = screenPos.y;
|
popupFrame.y = screenPos.y;
|
||||||
popupFrame.visible = true
|
popupFrame.visible = true
|
||||||
|
tracker.window = popupFrame
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PopupWindowTracker {
|
||||||
|
id: tracker
|
||||||
|
}
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
id: popupFrame
|
id: popupFrame
|
||||||
|
|
||||||
modality: Qt.WindowModal
|
|
||||||
flags: Qt.Popup
|
flags: Qt.Popup
|
||||||
height: choicesColumn.childrenRect.height + Style.margin * 2
|
height: choicesColumn.childrenRect.height + Style.margin * 2
|
||||||
width: choicesColumn.childrenRect.width + Style.margin * 2
|
width: choicesColumn.childrenRect.width + Style.margin * 2
|
||||||
|
|
Loading…
Add table
Reference in a new issue