mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:37:17 +02:00
Merge pull request #4682 from jherico/offscreen
Attempting to fix backspace issue in new UI
This commit is contained in:
commit
dbb1e3c820
3 changed files with 43 additions and 5 deletions
|
@ -1028,6 +1028,11 @@ bool Application::event(QEvent* event) {
|
||||||
bool Application::eventFilter(QObject* object, QEvent* event) {
|
bool Application::eventFilter(QObject* object, QEvent* event) {
|
||||||
|
|
||||||
if (event->type() == QEvent::ShortcutOverride) {
|
if (event->type() == QEvent::ShortcutOverride) {
|
||||||
|
if (DependencyManager::get<OffscreenUi>()->shouldSwallowShortcut(event)) {
|
||||||
|
event->accept();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Filter out captured keys before they're used for shortcut actions.
|
// Filter out captured keys before they're used for shortcut actions.
|
||||||
if (_controllerScriptingInterface.isKeyCaptured(static_cast<QKeyEvent*>(event))) {
|
if (_controllerScriptingInterface.isKeyCaptured(static_cast<QKeyEvent*>(event))) {
|
||||||
event->accept();
|
event->accept();
|
||||||
|
|
|
@ -89,7 +89,15 @@ void OffscreenUi::create(QOpenGLContext* shareContext) {
|
||||||
// is needed too).
|
// is needed too).
|
||||||
connect(_renderControl, &QQuickRenderControl::renderRequested, this, &OffscreenUi::requestRender);
|
connect(_renderControl, &QQuickRenderControl::renderRequested, this, &OffscreenUi::requestRender);
|
||||||
connect(_renderControl, &QQuickRenderControl::sceneChanged, this, &OffscreenUi::requestUpdate);
|
connect(_renderControl, &QQuickRenderControl::sceneChanged, this, &OffscreenUi::requestUpdate);
|
||||||
_quickWindow->focusObject();
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
connect(_quickWindow, &QQuickWindow::focusObjectChanged, [this]{
|
||||||
|
qDebug() << "New focus item " << _quickWindow->focusObject();
|
||||||
|
});
|
||||||
|
connect(_quickWindow, &QQuickWindow::activeFocusItemChanged, [this] {
|
||||||
|
qDebug() << "New active focus item " << _quickWindow->activeFocusItem();
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
_qmlComponent = new QQmlComponent(_qmlEngine);
|
_qmlComponent = new QQmlComponent(_qmlEngine);
|
||||||
// Initialize the render control and our OpenGL resources.
|
// Initialize the render control and our OpenGL resources.
|
||||||
|
@ -257,6 +265,24 @@ QPointF OffscreenUi::mapWindowToUi(const QPointF& sourcePosition, QObject* sourc
|
||||||
return QPointF(offscreenPosition.x, offscreenPosition.y);
|
return QPointF(offscreenPosition.x, offscreenPosition.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This hack allows the QML UI to work with keys that are also bound as
|
||||||
|
// shortcuts at the application level. However, it seems as though the
|
||||||
|
// bound actions are still getting triggered. At least for backspace.
|
||||||
|
// Not sure why.
|
||||||
|
//
|
||||||
|
// However, the problem may go away once we switch to the new menu system,
|
||||||
|
// so I think it's OK for the time being.
|
||||||
|
bool OffscreenUi::shouldSwallowShortcut(QEvent * event) {
|
||||||
|
Q_ASSERT(event->type() == QEvent::ShortcutOverride);
|
||||||
|
QObject * focusObject = _quickWindow->focusObject();
|
||||||
|
if (focusObject != _quickWindow && focusObject != _rootItem) {
|
||||||
|
//qDebug() << "Swallowed shortcut " << static_cast<QKeyEvent*>(event)->key();
|
||||||
|
event->accept();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Event handling customization
|
// Event handling customization
|
||||||
|
@ -268,11 +294,17 @@ bool OffscreenUi::eventFilter(QObject* originalDestination, QEvent* event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
// Don't intercept our own events, or we enter an infinite recursion
|
// Don't intercept our own events, or we enter an infinite recursion
|
||||||
if (originalDestination == _quickWindow) {
|
QObject * recurseTest = originalDestination;
|
||||||
return false;
|
while (recurseTest) {
|
||||||
|
Q_ASSERT(recurseTest != _rootItem && recurseTest != _quickWindow);
|
||||||
|
recurseTest = recurseTest->parent();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
switch (event->type()) {
|
switch (event->type()) {
|
||||||
case QEvent::Resize: {
|
case QEvent::Resize: {
|
||||||
QResizeEvent* resizeEvent = static_cast<QResizeEvent*>(event);
|
QResizeEvent* resizeEvent = static_cast<QResizeEvent*>(event);
|
||||||
|
@ -280,7 +312,7 @@ bool OffscreenUi::eventFilter(QObject* originalDestination, QEvent* event) {
|
||||||
if (widget) {
|
if (widget) {
|
||||||
this->resize(resizeEvent->size());
|
this->resize(resizeEvent->size());
|
||||||
}
|
}
|
||||||
return false;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case QEvent::KeyPress:
|
case QEvent::KeyPress:
|
||||||
|
|
|
@ -73,6 +73,7 @@ public:
|
||||||
void resume();
|
void resume();
|
||||||
bool isPaused() const;
|
bool isPaused() const;
|
||||||
void setProxyWindow(QWindow* window);
|
void setProxyWindow(QWindow* window);
|
||||||
|
bool shouldSwallowShortcut(QEvent* event);
|
||||||
QPointF mapWindowToUi(const QPointF& sourcePosition, QObject* sourceObject);
|
QPointF mapWindowToUi(const QPointF& sourcePosition, QObject* sourceObject);
|
||||||
virtual bool eventFilter(QObject* originalDestination, QEvent* event);
|
virtual bool eventFilter(QObject* originalDestination, QEvent* event);
|
||||||
void setMouseTranslator(MouseTranslator mouseTranslator) {
|
void setMouseTranslator(MouseTranslator mouseTranslator) {
|
||||||
|
|
Loading…
Reference in a new issue