diff options
author | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-05-27 13:38:47 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-05-27 14:27:41 +0200 |
commit | bb2986f165a51b0aee254c3e7217c3912c29e3f3 (patch) | |
tree | 81e08a9b036b4a80994fa6c3f2953297aa6b0a8f /src/widgets | |
parent | 0064dc7bc83cce97d8948ec85ac7788b5b6d7b07 (diff) |
Have subwindows parented properly.
Reviewed-by: Samuel Rødal
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/kernel/qwidget_qpa.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp index c2b60d0387..ae634edeb8 100644 --- a/src/widgets/kernel/qwidget_qpa.cpp +++ b/src/widgets/kernel/qwidget_qpa.cpp @@ -96,6 +96,12 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO QWindowSurface *surface = q->windowSurface(); QWindow *win = topData()->window; + // topData() ensures the extra is created but does not ensure 'window' is non-null + // in case the extra was already valid. + if (!win) { + createTLSysExtra(); + win = topData()->window; + } win->setWindowFlags(data.window_flags); win->setGeometry(q->geometry()); @@ -108,7 +114,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO if (QWidget *nativeParent = q->nativeParentWidget()) { if (nativeParent->windowHandle()) { - if (flags & Qt::Window) { + if (flags.testFlag(Qt::Window) && !flags.testFlag(Qt::SubWindow)) { win->setTransientParent(nativeParent->windowHandle()); win->setParent(0); } else { @@ -190,14 +196,16 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) newparent = 0; } - if (parent != newparent) { + bool subWinChange = f.testFlag(Qt::SubWindow) != oldFlags.testFlag(Qt::SubWindow); + if (parent != newparent || subWinChange) { QObjectPrivate::setParent_helper(newparent); //### why does this have to be done in the _sys function??? + createTLExtra(); if (q->windowHandle()) { q->windowHandle()->setWindowFlags(f); QWidget *parentWithWindow = newparent ? (newparent->windowHandle() ? newparent : newparent->nativeParentWidget()) : 0; if (parentWithWindow) { - if (f & Qt::Window) { + if (f.testFlag(Qt::Window) && !f.testFlag(Qt::SubWindow)) { q->windowHandle()->setTransientParent(parentWithWindow->windowHandle()); q->windowHandle()->setParent(0); } else { @@ -222,7 +230,9 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide); // Reparenting toplevel to child - if (!(f&Qt::Window) && (oldFlags&Qt::Window) && !q->testAttribute(Qt::WA_NativeWindow)) { + bool changedFromWin = !f.testFlag(Qt::Window) && oldFlags.testFlag(Qt::Window); + bool changedToSubWin = subWinChange && f.testFlag(Qt::SubWindow); + if ((changedFromWin || changedToSubWin) && !q->testAttribute(Qt::WA_NativeWindow)) { //qDebug() << "setParent_sys() change from toplevel"; q->destroy(); } @@ -250,24 +260,26 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) QPoint QWidget::mapToGlobal(const QPoint &pos) const { - int x=pos.x(), y=pos.y(); - const QWidget* w = this; + int x = pos.x(); + int y = pos.y(); + const QWidget *w = this; while (w) { x += w->data->crect.x(); y += w->data->crect.y(); - w = w->isWindow() ? 0 : w->parentWidget(); + w = w->parentWidget(); } return QPoint(x, y); } QPoint QWidget::mapFromGlobal(const QPoint &pos) const { - int x=pos.x(), y=pos.y(); - const QWidget* w = this; + int x = pos.x(); + int y = pos.y(); + const QWidget *w = this; while (w) { x -= w->data->crect.x(); y -= w->data->crect.y(); - w = w->isWindow() ? 0 : w->parentWidget(); + w = w->parentWidget(); } return QPoint(x, y); } |