1
0
Fork 0

Popup window tracking helper hooked up

This commit is contained in:
James Turner 2018-03-09 10:07:14 +00:00
parent 37dc418ce1
commit fa72d8dd06
5 changed files with 34 additions and 6 deletions

View file

@ -48,6 +48,7 @@
#include "QmlAircraftInfo.hxx"
#include "LauncherArgumentTokenizer.hxx"
#include "PathUrlHelper.hxx"
#include "PopupWindowTracker.hxx"
#include "ui_Launcher.h"
@ -245,6 +246,7 @@ void LauncherMainWindow::initQML()
qmlRegisterType<FlickableExtentQuery>("FlightGear.Launcher", 1, 0, "FlickableExtentQuery");
qmlRegisterType<QmlAircraftInfo>("FlightGear.Launcher", 1, 0, "AircraftInfo");
qmlRegisterType<PopupWindowTracker>("FlightGear.Launcher", 1, 0, "PopupWindowTracker");
m_config = new LaunchConfig(this);
connect(m_config, &LaunchConfig::collect, this, &LauncherMainWindow::collectAircraftArgs);

View file

@ -3,10 +3,12 @@
#include <QGuiApplication>
#include <QMouseEvent>
#include <QWindow>
#include <QDebug>
PopupWindowTracker::PopupWindowTracker(QObject *parent) : QObject(parent)
{
connect(qGuiApp, &QGuiApplication::applicationStateChanged,
this, &PopupWindowTracker::onApplicationStateChanged);
}
PopupWindowTracker::~PopupWindowTracker()
@ -35,6 +37,14 @@ void PopupWindowTracker::setWindow(QWindow *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)
{
if (!m_window)
@ -42,10 +52,16 @@ bool PopupWindowTracker::eventFilter(QObject *watched, QEvent *event)
if (event->type() == QEvent::MouseButtonPress) {
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;
}

View file

@ -29,6 +29,8 @@ signals:
public slots:
void setWindow(QWindow* window);
void onApplicationStateChanged(Qt::ApplicationState as);
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
};

View file

@ -73,6 +73,7 @@ Rectangle {
popupFrame.x = screenPos.x;
popupFrame.y = screenPos.y;
popupFrame.visible = true
tracker.window = popupFrame
}
}
@ -81,10 +82,13 @@ Rectangle {
id: aircraftInfo
}
PopupWindowTracker {
id: tracker
}
Window {
id: popupFrame
modality: Qt.WindowModal
width: root.width
flags: Qt.Popup
height: choicesColumn.childrenRect.height

View file

@ -111,13 +111,17 @@ Item {
popupFrame.x = screenPos.x;
popupFrame.y = screenPos.y;
popupFrame.visible = true
tracker.window = popupFrame
}
}
PopupWindowTracker {
id: tracker
}
Window {
id: popupFrame
modality: Qt.WindowModal
flags: Qt.Popup
height: choicesColumn.childrenRect.height + Style.margin * 2
width: choicesColumn.childrenRect.width + Style.margin * 2