summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@digia.com>2013-02-08 10:49:52 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-12 15:02:53 +0100
commit23b11e792cd0bd91afc026b103f55d450cc20fe2 (patch)
tree7e5350921467d267d61e1832c74e73ca77e7d316 /src
parentfe6add818e2ab11fba3d9df12c29dfb29c65b2af (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/gui/kernel/qwindow.cpp120
-rw-r--r--src/gui/kernel/qwindow.h15
-rw-r--r--src/gui/kernel/qwindow_p.h4
3 files changed, 139 insertions, 0 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index db6afe1faa..bf3eb67778 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -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,
@@ -216,6 +219,120 @@ QWindow::~QWindow()
}
/*!
+ \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.
Specifies whether the window is meant for raster rendering with
@@ -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;
}
diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h
index e304fd4c4f..4b8f0ca3e7 100644
--- a/src/gui/kernel/qwindow.h
+++ b/src/gui/kernel/qwindow.h
@@ -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);
diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h
index a5c26e380e..bcbface370 100644
--- a/src/gui/kernel/qwindow_p.h
+++ b/src/gui/kernel/qwindow_p.h
@@ -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;