Added QWindow::Visibility convenience API to QWindow.
This finally makes it possible to make windows fullscreen etc from QML by doing "visibility: Window.FullScreen". I don't see any reason from not having the API at the QWindow-level instead of at the QQuickWindow-level since this way it can benefit other use cases too. Change-Id: If27344306eb563bc2ccd83296a46b1f2862e2db1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
This commit is contained in:
parent
fe6add818e
commit
23b11e792c
@ -115,6 +115,9 @@ QT_BEGIN_NAMESPACE
|
||||
windowing systems that do not make this information visible to the
|
||||
application, isExposed() will simply return the same value as isVisible().
|
||||
|
||||
QWindow::Visibility queried through visibility() is a convenience API
|
||||
combining the functions of visible() and windowState().
|
||||
|
||||
\section1 Rendering
|
||||
|
||||
There are two Qt APIs that can be used to render content into a window,
|
||||
@ -215,6 +218,120 @@ QWindow::~QWindow()
|
||||
destroy();
|
||||
}
|
||||
|
||||
/*!
|
||||
\enum QWindow::Visibility
|
||||
\since 5.1
|
||||
|
||||
This enum describes what part of the screen the window occupies or should
|
||||
occupy.
|
||||
|
||||
\value Windowed The window occupies part of the screen, but not necessarily
|
||||
the entire screen. This state will occur only on windowing systems which
|
||||
support showing multiple windows simultaneously. In this state it is
|
||||
possible for the user to move and resize the window manually, if
|
||||
WindowFlags permit it and if it is supported by the windowing system.
|
||||
|
||||
\value Minimized The window is reduced to an entry or icon on the task bar,
|
||||
dock, task list or desktop, depending on how the windowing system handles
|
||||
minimized windows.
|
||||
|
||||
\value Maximized The window occupies one entire screen, and the titlebar is
|
||||
still visible. On most windowing systems this is the state achieved by
|
||||
clicking the maximize button on the toolbar.
|
||||
|
||||
\value FullScreen The window occupies one entire screen, is not resizable,
|
||||
and there is no titlebar. On some platforms which do not support showing
|
||||
multiple simultaneous windows, this can be the usual visibility when the
|
||||
window is not hidden.
|
||||
|
||||
\value AutomaticVisibility This means to give the window a default visible
|
||||
state, which might be fullscreen or windowed depending on the platform.
|
||||
It can be given as a parameter to setVisibility but will never be
|
||||
read back from the visibility accessor.
|
||||
|
||||
\value Hidden The window is not visible in any way, however it may remember
|
||||
a latent visibility which can be restored by setting AutomaticVisibility.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\property QWindow::visibility
|
||||
\brief the screen-occupation state of the window
|
||||
\since 5.1
|
||||
|
||||
Visibility is whether the window should appear in the windowing system as
|
||||
normal, minimized, maximized, fullscreen or hidden.
|
||||
|
||||
To set the visibility to AutomaticVisibility means to give the window
|
||||
a default visible state, which might be fullscreen or windowed depending on
|
||||
the platform.
|
||||
When reading the visibility property you will always get the actual state,
|
||||
never AutomaticVisibility.
|
||||
*/
|
||||
QWindow::Visibility QWindow::visibility() const
|
||||
{
|
||||
Q_D(const QWindow);
|
||||
return d->visibility;
|
||||
}
|
||||
|
||||
void QWindow::setVisibility(Visibility v)
|
||||
{
|
||||
switch (v) {
|
||||
case Hidden:
|
||||
hide();
|
||||
break;
|
||||
case AutomaticVisibility:
|
||||
show();
|
||||
break;
|
||||
case Windowed:
|
||||
showNormal();
|
||||
break;
|
||||
case Minimized:
|
||||
showMinimized();
|
||||
break;
|
||||
case Maximized:
|
||||
showMaximized();
|
||||
break;
|
||||
case FullScreen:
|
||||
showFullScreen();
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void QWindowPrivate::updateVisibility()
|
||||
{
|
||||
Q_Q(QWindow);
|
||||
|
||||
QWindow::Visibility old = visibility;
|
||||
|
||||
if (visible) {
|
||||
switch (windowState) {
|
||||
case Qt::WindowMinimized:
|
||||
visibility = QWindow::Minimized;
|
||||
break;
|
||||
case Qt::WindowMaximized:
|
||||
visibility = QWindow::Maximized;
|
||||
break;
|
||||
case Qt::WindowFullScreen:
|
||||
visibility = QWindow::FullScreen;
|
||||
break;
|
||||
case Qt::WindowNoState:
|
||||
visibility = QWindow::Windowed;
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
visibility = QWindow::Hidden;
|
||||
}
|
||||
|
||||
if (visibility != old)
|
||||
emit q->visibilityChanged(visibility);
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the \a surfaceType of the window.
|
||||
|
||||
@ -264,6 +381,7 @@ void QWindow::setVisible(bool visible)
|
||||
return;
|
||||
d->visible = visible;
|
||||
emit visibleChanged(visible);
|
||||
d->updateVisibility();
|
||||
|
||||
if (!d->platformWindow)
|
||||
create();
|
||||
@ -808,6 +926,7 @@ void QWindow::setWindowState(Qt::WindowState state)
|
||||
d->platformWindow->setWindowState(state);
|
||||
d->windowState = state;
|
||||
emit windowStateChanged(d->windowState);
|
||||
d->updateVisibility();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -1724,6 +1843,7 @@ bool QWindow::event(QEvent *ev)
|
||||
case QEvent::WindowStateChange: {
|
||||
Q_D(QWindow);
|
||||
emit windowStateChanged(d->windowState);
|
||||
d->updateVisibility();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,8 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface
|
||||
Q_OBJECT
|
||||
Q_DECLARE_PRIVATE(QWindow)
|
||||
|
||||
Q_ENUMS(Visibility)
|
||||
|
||||
// All properties which are declared here are inherited by QQuickWindow and therefore available in QML.
|
||||
// So please think carefully about what it does to the QML namespace if you add any new ones,
|
||||
// particularly the possible meanings these names might have in any specializations of Window.
|
||||
@ -109,10 +111,19 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface
|
||||
Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth NOTIFY maximumWidthChanged)
|
||||
Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight NOTIFY maximumHeightChanged)
|
||||
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
|
||||
Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged)
|
||||
Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
|
||||
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
|
||||
|
||||
public:
|
||||
enum Visibility {
|
||||
Hidden = 0,
|
||||
AutomaticVisibility,
|
||||
Windowed,
|
||||
Minimized,
|
||||
Maximized,
|
||||
FullScreen
|
||||
};
|
||||
|
||||
explicit QWindow(QScreen *screen = 0);
|
||||
explicit QWindow(QWindow *parent);
|
||||
@ -123,6 +134,9 @@ public:
|
||||
|
||||
bool isVisible() const;
|
||||
|
||||
Visibility visibility() const;
|
||||
void setVisibility(Visibility v);
|
||||
|
||||
void create();
|
||||
|
||||
WId winId() const;
|
||||
@ -284,6 +298,7 @@ Q_SIGNALS:
|
||||
void maximumHeightChanged(int arg);
|
||||
|
||||
void visibleChanged(bool arg);
|
||||
void visibilityChanged(QWindow::Visibility visibility);
|
||||
void contentOrientationChanged(Qt::ScreenOrientation orientation);
|
||||
|
||||
void focusObjectChanged(QObject *object);
|
||||
|
@ -83,6 +83,7 @@ public:
|
||||
, visible(false)
|
||||
, exposed(false)
|
||||
, windowState(Qt::WindowNoState)
|
||||
, visibility(QWindow::Hidden)
|
||||
, resizeEventPending(true)
|
||||
, receivedExpose(false)
|
||||
, positionPolicy(WindowFrameExclusive)
|
||||
@ -122,6 +123,8 @@ public:
|
||||
|
||||
virtual QWindow *eventReceiver() { Q_Q(QWindow); return q; }
|
||||
|
||||
void updateVisibility();
|
||||
|
||||
QWindow::SurfaceType surfaceType;
|
||||
Qt::WindowFlags windowFlags;
|
||||
QWindow *parentWindow;
|
||||
@ -134,6 +137,7 @@ public:
|
||||
QIcon windowIcon;
|
||||
QRect geometry;
|
||||
Qt::WindowState windowState;
|
||||
QWindow::Visibility visibility;
|
||||
bool resizeEventPending;
|
||||
bool receivedExpose;
|
||||
PositionPolicy positionPolicy;
|
||||
|
@ -49,6 +49,7 @@
|
||||
|
||||
// For QSignalSpy slot connections.
|
||||
Q_DECLARE_METATYPE(Qt::ScreenOrientation)
|
||||
Q_DECLARE_METATYPE(QWindow::Visibility)
|
||||
|
||||
class tst_QWindow: public QObject
|
||||
{
|
||||
@ -75,6 +76,7 @@ private slots:
|
||||
void inputReentrancy();
|
||||
void tabletEvents();
|
||||
void windowModality_QTBUG27039();
|
||||
void visibility();
|
||||
|
||||
void initTestCase()
|
||||
{
|
||||
@ -1075,6 +1077,44 @@ void tst_QWindow::windowModality_QTBUG27039()
|
||||
QCOMPARE(modalA.mousePressedCount, 1);
|
||||
}
|
||||
|
||||
void tst_QWindow::visibility()
|
||||
{
|
||||
qRegisterMetaType<Qt::WindowModality>("QWindow::Visibility");
|
||||
|
||||
QWindow window;
|
||||
QSignalSpy spy(&window, SIGNAL(visibilityChanged(QWindow::Visibility)));
|
||||
|
||||
window.setVisibility(QWindow::AutomaticVisibility);
|
||||
QVERIFY(window.isVisible());
|
||||
QVERIFY(window.visibility() != QWindow::Hidden);
|
||||
QVERIFY(window.visibility() != QWindow::AutomaticVisibility);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
spy.clear();
|
||||
|
||||
window.setVisibility(QWindow::Hidden);
|
||||
QVERIFY(!window.isVisible());
|
||||
QCOMPARE(window.visibility(), QWindow::Hidden);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
spy.clear();
|
||||
|
||||
window.setVisibility(QWindow::FullScreen);
|
||||
QVERIFY(window.isVisible());
|
||||
QCOMPARE(window.windowState(), Qt::WindowFullScreen);
|
||||
QCOMPARE(window.visibility(), QWindow::FullScreen);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
spy.clear();
|
||||
|
||||
window.setWindowState(Qt::WindowNoState);
|
||||
QCOMPARE(window.visibility(), QWindow::Windowed);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
spy.clear();
|
||||
|
||||
window.setVisible(false);
|
||||
QCOMPARE(window.visibility(), QWindow::Hidden);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
spy.clear();
|
||||
}
|
||||
|
||||
#include <tst_qwindow.moc>
|
||||
QTEST_MAIN(tst_QWindow)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user