office-gobmx/vcl/qt5/QtInstanceContainer.cxx
Michael Weghorn 028a525986 tdf#130857 qt weld: Signal container focus on window (de)activation
Set QtInstanceWindow as an event filter for it's
QWidget, and call `signal_container_focus_changed`
when receiving a QEvent::WindowActivate or QEvent::WindowDeactivate
event.
This code path got triggered as expected in a
quick test switching between e.g. the "Help" -> "About"
dialog and other windows in KDE Plasma using the Alt+Tab
shortcut.

The VCL implementation does something similar by
handling VclEventId::WindowActivate and
VclEventId::WindowDeactivate events, see
SalInstanceContainer::HandleEventListener.

For non-top-level containers, a different solution
will probably be needed.
For now, adjust the assert in
QtInstanceContainer::connect_container_focus_changed
to only trigger for non-QtInstanceWindow containers.

And call the base class implementation, so that the
handler is actually set for the QtInstanceWindow
case.

A potential solution for QtInstanceContainer
might be to connect to the QApplication::focusChanged
signal in QtInstanceContainer::connect_container_focus_changed
and in the slot check whether exactly one of the old and
new focus widgets has the container's widget in
hierarchy.

Change-Id: I945c8bf0999d93ae91cf25dcffd3fd3ce164d214
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176302
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
2024-11-09 19:04:51 +01:00

65 lines
2 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <QtInstanceContainer.hxx>
#include <QtInstanceContainer.moc>
#include <QtInstanceWindow.hxx>
QtInstanceContainer::QtInstanceContainer(QWidget* pWidget)
: QtInstanceWidget(pWidget)
{
assert(pWidget->layout() && "no layout to use for container");
}
void QtInstanceContainer::move(weld::Widget* pWidget, weld::Container* pNewParent)
{
QtInstanceWidget* pQtInstanceWidget = dynamic_cast<QtInstanceWidget*>(pWidget);
assert(pQtInstanceWidget);
QWidget* pQWidget = pQtInstanceWidget->getQWidget();
assert(pQWidget);
getLayout().removeWidget(pQWidget);
if (!pNewParent)
{
pQWidget->deleteLater();
return;
}
QtInstanceContainer* pNewContainer = dynamic_cast<QtInstanceContainer*>(pNewParent);
assert(pNewContainer);
QLayout& rNewLayout = pNewContainer->getLayout();
rNewLayout.addWidget(pQWidget);
}
css::uno::Reference<css::awt::XWindow> QtInstanceContainer::CreateChildFrame()
{
assert(false && "Not implemented yet");
return css::uno::Reference<css::awt::XWindow>();
}
void QtInstanceContainer::child_grab_focus() { assert(false && "Not implemented yet"); }
void QtInstanceContainer::connect_container_focus_changed(const Link<Container&, void>& rLink)
{
// for QtInstanceWindow, no special handling is needed, activate/deactivate events trigger the signal
if (!qobject_cast<QtInstanceWindow*>(this))
assert(false && "Not implemented yet");
weld::Container::connect_container_focus_changed(rLink);
}
QLayout& QtInstanceContainer::getLayout()
{
QLayout* pLayout = getQWidget()->layout();
assert(pLayout);
return *pLayout;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */