17 InPlaceWidgetHelper::InPlaceWidgetHelper(QWidget *editorWidget, QWidget *parentWidget, QDesignerFormWindowInterface *fw)
19 m_editorWidget(editorWidget),
20 m_parentWidget(parentWidget),
21 m_noChildEvent(m_parentWidget->testAttribute(Qt::WA_NoChildEventsForParent))
23 m_editorWidget->setAttribute(Qt::WA_DeleteOnClose);
24 m_editorWidget->setParent(m_parentWidget->window());
25 m_parentWidget->installEventFilter(
this);
26 m_editorWidget->installEventFilter(
this);
27 connect(m_editorWidget, &QObject::destroyed,
28 fw->mainContainer(), QOverload<>::of(&QWidget::setFocus));
51 if (object == m_parentWidget) {
52 if (e->type() == QEvent::Resize) {
53 const QResizeEvent *event =
static_cast<
const QResizeEvent*>(e);
54 const QPoint localPos = m_parentWidget->geometry().topLeft();
55 const QPoint globalPos = m_parentWidget->parentWidget() ? m_parentWidget->parentWidget()->mapToGlobal(localPos) : localPos;
56 const QPoint newPos = (m_editorWidget->parentWidget() ? m_editorWidget->parentWidget()->mapFromGlobal(globalPos) : globalPos)
58 const QSize newSize = event->size() + m_sizeOffset;
59 m_editorWidget->setGeometry(QRect(newPos, newSize));
61 }
else if (object == m_editorWidget) {
62 if (e->type() == QEvent::ShortcutOverride) {
63 if (
static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
67 }
else if (e->type() == QEvent::KeyPress) {
68 if (
static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
70 m_editorWidget->close();
73 }
else if (e->type() == QEvent::Show) {
74 const QPoint localPos = m_parentWidget->geometry().topLeft();
75 const QPoint globalPos = m_parentWidget->parentWidget() ? m_parentWidget->parentWidget()->mapToGlobal(localPos) : localPos;
76 const QPoint newPos = m_editorWidget->parentWidget() ? m_editorWidget->parentWidget()->mapFromGlobal(globalPos) : globalPos;
77 m_posOffset = m_editorWidget->geometry().topLeft() - newPos;
78 m_sizeOffset = m_editorWidget->size() - m_parentWidget->size();
82 return QObject::eventFilter(object, e);