aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2015-11-16 11:21:00 +0100
committerUlf Hermann <ulf.hermann@theqtcompany.com>2015-11-16 11:44:14 +0000
commit561b9323c22a594b402eac343690898d4e9c44d0 (patch)
tree8d41ace82c1397907db0667f2f2a9eed4e376266
parentc71e8aadec7394cbf54fc6d79c3a7076c0c41a48 (diff)
QQuickWidget: Emulate visibility for offscreen window
The "visibility" and "visible" properties are exported to QML and should return useful values. Task-number: QTBUG-49054 Change-Id: I3c474885653c4b57659b02f183293e3186edc972 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
-rw-r--r--src/quickwidgets/qquickwidget.cpp30
-rw-r--r--tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp6
2 files changed, 35 insertions, 1 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index edaa1352ae..7a4c18b579 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -1095,6 +1095,12 @@ void QQuickWidget::showEvent(QShowEvent *)
d->render(true);
else
triggerUpdate();
+ QWindowPrivate *offscreenPrivate = QWindowPrivate::get(d->offscreenWindow);
+ if (!offscreenPrivate->visible) {
+ offscreenPrivate->visible = true;
+ emit d->offscreenWindow->visibleChanged(true);
+ offscreenPrivate->updateVisibility();
+ }
}
/*! \reimp */
@@ -1102,6 +1108,12 @@ void QQuickWidget::hideEvent(QHideEvent *)
{
Q_D(QQuickWidget);
d->invalidateRenderControl();
+ QWindowPrivate *offscreenPrivate = QWindowPrivate::get(d->offscreenWindow);
+ if (offscreenPrivate->visible) {
+ offscreenPrivate->visible = false;
+ emit d->offscreenWindow->visibleChanged(false);
+ offscreenPrivate->updateVisibility();
+ }
}
/*! \reimp */
@@ -1151,6 +1163,20 @@ void QQuickWidget::focusOutEvent(QFocusEvent * event)
d->offscreenWindow->focusOutEvent(event);
}
+static Qt::WindowState resolveWindowState(Qt::WindowStates states)
+{
+ // No more than one of these 3 can be set
+ if (states & Qt::WindowMinimized)
+ return Qt::WindowMinimized;
+ if (states & Qt::WindowMaximized)
+ return Qt::WindowMaximized;
+ if (states & Qt::WindowFullScreen)
+ return Qt::WindowFullScreen;
+
+ // No state means "windowed" - we ignore Qt::WindowActive
+ return Qt::WindowNoState;
+}
+
/*! \reimp */
bool QQuickWidget::event(QEvent *e)
{
@@ -1184,6 +1210,10 @@ bool QQuickWidget::event(QEvent *e)
d->updatePosition();
break;
+ case QEvent::WindowStateChange:
+ d->offscreenWindow->setWindowState(resolveWindowState(windowState()));
+ break;
+
default:
break;
}
diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
index 7cc5dfa7c6..79ff18011d 100644
--- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
+++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
@@ -75,8 +75,12 @@ void tst_qquickwidget::showHide()
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window, 5000));
+ QVERIFY(childView->quickWindow()->isVisible());
+ QVERIFY(childView->quickWindow()->visibility() != QWindow::Hidden);
- childView->hide();
+ window.hide();
+ QVERIFY(!childView->quickWindow()->isVisible());
+ QCOMPARE(childView->quickWindow()->visibility(), QWindow::Hidden);
}
void tst_qquickwidget::reparentAfterShow()