De-inline all setters in QWindow
[profile/ivi/qtbase.git] / src / gui / kernel / qwindow.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qwindow.h"
43
44 #include <qpa/qplatformwindow.h>
45 #include <qpa/qplatformintegration.h>
46 #include "qsurfaceformat.h"
47 #ifndef QT_NO_OPENGL
48 #include <qpa/qplatformopenglcontext.h>
49 #include "qopenglcontext.h"
50 #endif
51 #include "qscreen.h"
52
53 #include "qwindow_p.h"
54 #include "qguiapplication_p.h"
55 #ifndef QT_NO_ACCESSIBILITY
56 #  include "qaccessible.h"
57 #endif
58
59 #include <private/qevent_p.h>
60
61 #include <QtCore/QDebug>
62
63 #include <QStyleHints>
64 #include <qpa/qplatformcursor.h>
65
66 QT_BEGIN_NAMESPACE
67
68 /*!
69     \class QWindow
70     \inmodule QtGui
71     \since 5.0
72     \brief The QWindow class represents a window in the underlying windowing system.
73
74     A window that is supplied a parent becomes a native child window of
75     their parent window.
76
77     An application will typically use QWidget or QQuickView for its UI, and not
78     QWindow directly. Still, it is possible to render directly to a QWindow
79     with QBackingStore or QOpenGLContext, when wanting to keep dependencies to
80     a minimum or when wanting to use OpenGL directly. The
81     \l{gui/rasterwindow}{Raster Window} and \l{gui/openglwindow}{OpenGL Window}
82     examples are useful reference examples for how to render to a QWindow using
83     either approach.
84
85     \section1 Resource management
86
87     Windows can potentially use a lot of memory. A usual measurement is
88     width times height times color depth. A window might also include multiple
89     buffers to support double and triple buffering, as well as depth and stencil
90     buffers. To release a window's memory resources, call the destroy() function.
91
92     \section1 Content orientation
93
94     QWindow has reportContentOrientationChange() that can be used to specify
95     the layout of the window contents in relation to the screen. The content
96     orientation is simply a hint to the windowing system about which
97     orientation the window contents are in.  It's useful when you wish to keep
98     the same window size, but rotate the contents instead, especially when
99     doing rotation animations between different orientations. The windowing
100     system might use this value to determine the layout of system popups or
101     dialogs.
102
103     \section1 Visibility and Windowing system exposure.
104
105     By default, the window is not visible, and you must call setVisible(true),
106     or show() or similar to make it visible. To make a window hidden again,
107     call setVisible(false) or hide(). The visible property describes the state
108     the application wants the window to be in. Depending on the underlying
109     system, a visible window might still not be shown on the screen. It could,
110     for instance, be covered by other opaque windows or moved outside the
111     physical area of the screen. On windowing systems that have exposure
112     notifications, the isExposed() accessor describes whether the window should
113     be treated as directly visible on screen. The exposeEvent() function is
114     called whenever the windows exposure in the windowing system changes.  On
115     windowing systems that do not make this information visible to the
116     application, isExposed() will simply return the same value as isVisible().
117
118     \section1 Rendering
119
120     There are two Qt APIs that can be used to render content into a window,
121     QBackingStore for rendering with a QPainter and flushing the contents
122     to a window with type QSurface::RasterSurface, and QOpenGLContext for
123     rendering with OpenGL to a window with type QSurface::OpenGLSurface.
124
125     The application can start rendering as soon as isExposed() returns true,
126     and can keep rendering until it isExposed() returns false. To find out when
127     isExposed() changes, reimplement exposeEvent(). The window will always get
128     a resize event before the first expose event.
129 */
130
131 /*!
132     Creates a window as a top level on the \a targetScreen.
133
134     The window is not shown until setVisible(true), show(), or similar is called.
135
136     \sa setScreen()
137 */
138 QWindow::QWindow(QScreen *targetScreen)
139     : QObject(*new QWindowPrivate(), 0)
140     , QSurface(QSurface::Window)
141 {
142     Q_D(QWindow);
143     d->screen = targetScreen;
144     if (!d->screen)
145         d->screen = QGuiApplication::primaryScreen();
146
147     //if your applications aborts here, then chances are your creating a QWindow before the
148     //screen list is populated.
149     Q_ASSERT(d->screen);
150
151     connect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(screenDestroyed(QObject*)));
152     QGuiApplicationPrivate::window_list.prepend(this);
153 }
154
155 /*!
156     Creates a window as a child of the given \a parent window.
157
158     The window will be embedded inside the parent window, its coordinates
159     relative to the parent.
160
161     The screen is inherited from the parent.
162
163     \sa setParent()
164 */
165 QWindow::QWindow(QWindow *parent)
166     : QObject(*new QWindowPrivate(), parent)
167     , QSurface(QSurface::Window)
168 {
169     Q_D(QWindow);
170     d->parentWindow = parent;
171     if (parent)
172         d->screen = parent->screen();
173     if (!d->screen)
174         d->screen = QGuiApplication::primaryScreen();
175     connect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(screenDestroyed(QObject*)));
176     QGuiApplicationPrivate::window_list.prepend(this);
177 }
178
179 /*!
180     Creates a window as a child of the given \a parent window with the \a dd
181     private implementation.
182
183     The window will be embedded inside the parent window, its coordinates
184     relative to the parent.
185
186     The screen is inherited from the parent.
187
188     \internal
189     \sa setParent()
190 */
191 QWindow::QWindow(QWindowPrivate &dd, QWindow *parent)
192     : QObject(dd, parent)
193     , QSurface(QSurface::Window)
194 {
195     Q_D(QWindow);
196     d->parentWindow = parent;
197     if (parent)
198         d->screen = parent->screen();
199     if (!d->screen)
200         d->screen = QGuiApplication::primaryScreen();
201     connect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(screenDestroyed(QObject*)));
202     QGuiApplicationPrivate::window_list.prepend(this);
203 }
204
205 /*!
206     Destroys the window.
207 */
208 QWindow::~QWindow()
209 {
210     if (QGuiApplicationPrivate::focus_window == this)
211         QGuiApplicationPrivate::focus_window = 0;
212     if (QGuiApplicationPrivate::currentMouseWindow == this)
213         QGuiApplicationPrivate::currentMouseWindow = 0;
214     QGuiApplicationPrivate::window_list.removeAll(this);
215     destroy();
216 }
217
218 /*!
219     Set the \a surfaceType of the window.
220
221     Specifies whether the window is meant for raster rendering with
222     QBackingStore, or OpenGL rendering with QOpenGLContext.
223
224     The surfaceType will be used when the native surface is created
225     in the create() function. Calling this function after the native
226     surface has been created requires calling destroy() and create()
227     to release the old native surface and create a new one.
228
229     \sa QBackingStore, QOpenGLContext, create(), destroy()
230 */
231 void QWindow::setSurfaceType(SurfaceType surfaceType)
232 {
233     Q_D(QWindow);
234     d->surfaceType = surfaceType;
235 }
236
237 /*!
238     Returns the surface type of the window.
239
240     \sa setSurfaceType()
241 */
242 QWindow::SurfaceType QWindow::surfaceType() const
243 {
244     Q_D(const QWindow);
245     return d->surfaceType;
246 }
247
248 /*!
249     \property QWindow::visible
250     \brief whether the window is visible or not
251
252     This property controls the visibility of the window in the windowing system.
253
254     By default, the window is not visible, you must call setVisible(true), or
255     show() or similar to make it visible.
256
257     \sa show()
258 */
259 void QWindow::setVisible(bool visible)
260 {
261     Q_D(QWindow);
262
263     if (d->visible == visible)
264         return;
265     d->visible = visible;
266     emit visibleChanged(visible);
267
268     if (!d->platformWindow)
269         create();
270
271     if (visible) {
272         // remove posted quit events when showing a new window
273         QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
274
275         QShowEvent showEvent;
276         QGuiApplication::sendEvent(this, &showEvent);
277     }
278
279     if (isModal()) {
280         if (visible)
281             QGuiApplicationPrivate::showModalWindow(this);
282         else
283             QGuiApplicationPrivate::hideModalWindow(this);
284     }
285
286 #ifndef QT_NO_CURSOR
287     if (visible)
288         d->applyCursor();
289 #endif
290     d->platformWindow->setVisible(visible);
291
292     if (!visible) {
293         QHideEvent hideEvent;
294         QGuiApplication::sendEvent(this, &hideEvent);
295     }
296 }
297
298 bool QWindow::isVisible() const
299 {
300     Q_D(const QWindow);
301
302     return d->visible;
303 }
304
305 /*!
306     Allocates the platform resources associated with the window.
307
308     It is at this point that the surface format set using setFormat() gets resolved
309     into an actual native surface. However, the window remains hidden until setVisible() is called.
310
311     Note that it is not usually necessary to call this function directly, as it will be implicitly
312     called by show(), setVisible(), and other functions that require access to the platform
313     resources.
314
315     Call destroy() to free the platform resources if necessary.
316
317     \sa destroy()
318 */
319 void QWindow::create()
320 {
321     Q_D(QWindow);
322     if (!d->platformWindow) {
323         d->platformWindow = QGuiApplicationPrivate::platformIntegration()->createPlatformWindow(this);
324         QObjectList childObjects = children();
325         for (int i = 0; i < childObjects.size(); i ++) {
326             QObject *object = childObjects.at(i);
327             if(object->isWindowType()) {
328                 QWindow *window = static_cast<QWindow *>(object);
329                 if (window->d_func()->platformWindow)
330                     window->d_func()->platformWindow->setParent(d->platformWindow);
331             }
332         }
333     }
334 }
335
336 /*!
337     Returns the window's platform id.
338
339     For platforms where this id might be useful, the value returned
340     will uniquely represent the window inside the corresponding screen.
341
342     \sa screen()
343 */
344 WId QWindow::winId() const
345 {
346     Q_D(const QWindow);
347     if(!d->platformWindow)
348         const_cast<QWindow *>(this)->create();
349
350     WId id = d->platformWindow->winId();
351     // See the QPlatformWindow::winId() documentation
352     Q_ASSERT(id != WId(0));
353     return id;
354 }
355
356 /*!
357     Returns the parent window, if any.
358
359     A window without a parent is known as a top level window.
360 */
361 QWindow *QWindow::parent() const
362 {
363     Q_D(const QWindow);
364     return d->parentWindow;
365 }
366
367 /*!
368     Sets the \a parent Window. This will lead to the windowing system managing
369     the clip of the window, so it will be clipped to the \a parent window.
370
371     Setting \a parent to be 0 will make the window become a top level window.
372 */
373
374 void QWindow::setParent(QWindow *parent)
375 {
376     Q_D(QWindow);
377
378     QObject::setParent(parent);
379
380     if (d->platformWindow) {
381         if (parent && parent->d_func()->platformWindow) {
382             d->platformWindow->setParent(parent->d_func()->platformWindow);
383         } else {
384             d->platformWindow->setParent(0);
385         }
386     }
387
388     d->parentWindow = parent;
389
390     QGuiApplicationPrivate::updateBlockedStatus(this);
391 }
392
393 /*!
394     Returns whether the window is top level, i.e. has no parent window.
395 */
396 bool QWindow::isTopLevel() const
397 {
398     Q_D(const QWindow);
399     return d->parentWindow == 0;
400 }
401
402 /*!
403     Returns whether the window is modal.
404
405     A modal window prevents other windows from getting any input.
406
407     \sa QWindow::modality
408 */
409 bool QWindow::isModal() const
410 {
411     Q_D(const QWindow);
412     return d->modality != Qt::NonModal;
413 }
414
415 /*! \property QWindow::modality
416     \brief the modality of the window
417
418     A modal window prevents other windows from receiving input events. Qt
419     supports two types of modality: Qt::WindowModal and Qt::ApplicationModal.
420
421     By default, this property is Qt::NonModal
422
423     \sa Qt::WindowModality
424 */
425
426 Qt::WindowModality QWindow::modality() const
427 {
428     Q_D(const QWindow);
429     return d->modality;
430 }
431
432 void QWindow::setModality(Qt::WindowModality modality)
433 {
434     Q_D(QWindow);
435     if (d->modality == modality)
436         return;
437     d->modality = modality;
438     emit modalityChanged(modality);
439 }
440
441 /*! \fn void QWindow::modalityChanged(Qt::WindowModality modality)
442
443     This signal is emitted when the Qwindow::modality property changes to \a modality.
444 */
445
446 /*!
447     Sets the window's surface \a format.
448
449     The format determines properties such as color depth, alpha, depth and
450     stencil buffer size, etc. For example, to give a window a transparent
451     background (provided that the window system supports compositing, and
452     provided that other content in the window does not make it opaque again):
453
454     \code
455     QSurfaceFormat format;
456     format.setAlphaBufferSize(8);
457     window.setFormat(format);
458     \endcode
459
460     The surface format will be resolved in the create() function. Calling
461     this function after create() has been called will not re-resolve the
462     surface format of the native surface.
463
464     \sa create(), destroy()
465 */
466 void QWindow::setFormat(const QSurfaceFormat &format)
467 {
468     Q_D(QWindow);
469     d->requestedFormat = format;
470 }
471
472 /*!
473     Returns the requested surfaceformat of this window.
474
475     If the requested format was not supported by the platform implementation,
476     the requestedFormat will differ from the actual window format.
477
478     This is the value set with setFormat().
479
480     \sa setFormat(), format()
481  */
482 QSurfaceFormat QWindow::requestedFormat() const
483 {
484     Q_D(const QWindow);
485     return d->requestedFormat;
486 }
487
488 /*!
489     Returns the actual format of this window.
490
491     After the window has been created, this function will return the actual surface format
492     of the window. It might differ from the requested format if the requested format could
493     not be fulfilled by the platform.
494
495     \sa create(), requestedFormat()
496 */
497 QSurfaceFormat QWindow::format() const
498 {
499     Q_D(const QWindow);
500     if (d->platformWindow)
501         return d->platformWindow->format();
502     return d->requestedFormat;
503 }
504
505 /*!
506     \property QWindow::flags
507     \brief the window flags of the window
508
509     The window flags control the window's appearance in the windowing system,
510     whether it's a dialog, popup, or a regular window, and whether it should
511     have a title bar, etc.
512
513     The actual window flags might differ from the flags set with setFlags()
514     if the requested flags could not be fulfilled.
515 */
516 void QWindow::setFlags(Qt::WindowFlags flags)
517 {
518     Q_D(QWindow);
519     if (d->platformWindow)
520         d->platformWindow->setWindowFlags(flags);
521     d->windowFlags = flags;
522 }
523
524 Qt::WindowFlags QWindow::flags() const
525 {
526     Q_D(const QWindow);
527     return d->windowFlags;
528 }
529
530 /*!
531     Returns the type of the window.
532
533     This returns the part of the window flags that represents
534     whether the window is a dialog, tooltip, popup, regular window, etc.
535
536     \sa flags(), setFlags()
537 */
538 Qt::WindowType QWindow::type() const
539 {
540     Q_D(const QWindow);
541     return static_cast<Qt::WindowType>(int(d->windowFlags & Qt::WindowType_Mask));
542 }
543
544 /*!
545     \property QWindow::title
546     \brief the window's title in the windowing system
547
548     The window title might appear in the title area of the window decorations,
549     depending on the windowing system and the window flags. It might also
550     be used by the windowing system to identify the window in other contexts,
551     such as in the task switcher.
552
553     \sa flags()
554 */
555 void QWindow::setTitle(const QString &title)
556 {
557     Q_D(QWindow);
558     d->windowTitle = title;
559     if (d->platformWindow)
560         d->platformWindow->setWindowTitle(title);
561 }
562
563 QString QWindow::title() const
564 {
565     Q_D(const QWindow);
566     return d->windowTitle;
567 }
568
569 /*!
570     \brief set the file name this window is representing.
571
572     The windowing system might use \a filePath to display the
573     path of the document this window is representing in the tile bar.
574
575 */
576 void QWindow::setFilePath(const QString &filePath)
577 {
578     Q_D(QWindow);
579     d->windowFilePath = filePath;
580     if (d->platformWindow)
581         d->platformWindow->setWindowFilePath(filePath);
582 }
583
584 /*!
585     \brief the file name this window is representing.
586
587     \sa setFilePath()
588 */
589 QString QWindow::filePath() const
590 {
591     Q_D(const QWindow);
592     return d->windowFilePath;
593 }
594
595 /*!
596     \brief set the window's \a icon in the windowing system
597
598     The window icon might be used by the windowing system for example to
599     decorate the window, and/or in the task switcher.
600 */
601 void QWindow::setIcon(const QIcon &icon)
602 {
603     Q_D(QWindow);
604     d->windowIcon = icon;
605     if (d->platformWindow)
606         d->platformWindow->setWindowIcon(icon);
607 }
608
609 /*!
610     \brief set the window's icon in the windowing system
611
612     \sa setIcon()
613 */
614 QIcon QWindow::icon() const
615 {
616     Q_D(const QWindow);
617     return d->windowIcon;
618 }
619
620 /*!
621     Raise the window in the windowing system.
622
623     Requests that the window be raised to appear above other windows.
624 */
625 void QWindow::raise()
626 {
627     Q_D(QWindow);
628     if (d->platformWindow)
629         d->platformWindow->raise();
630 }
631
632 /*!
633     Lower the window in the windowing system.
634
635     Requests that the window be lowered to appear below other windows.
636 */
637 void QWindow::lower()
638 {
639     Q_D(QWindow);
640     if (d->platformWindow)
641         d->platformWindow->lower();
642 }
643
644 /*!
645     Sets the window's opacity in the windowing system to \a level.
646
647     If the windowing system supports window opacity, this can be used to fade the
648     window in and out, or to make it semitransparent.
649
650     A value of 1.0 or above is treated as fully opaque, whereas a value of 0.0 or below
651     is treated as fully transparent. Values inbetween represent varying levels of
652     translucency between the two extremes.
653 */
654 void QWindow::setOpacity(qreal level)
655 {
656     Q_D(QWindow);
657     if (d->platformWindow) {
658         d->platformWindow->setOpacity(level);
659     }
660 }
661
662 /*!
663     Requests the window to be activated, i.e. receive keyboard focus.
664
665     \sa isActive(), QGuiApplication::focusWindow()
666 */
667 void QWindow::requestActivate()
668 {
669     Q_D(QWindow);
670     if (d->platformWindow)
671         d->platformWindow->requestActivateWindow();
672 }
673
674 /*!
675     Returns if this window is exposed in the windowing system.
676
677     When the window is not exposed, it is shown by the application
678     but it is still not showing in the windowing system, so the application
679     should minimize rendering and other graphical activities.
680
681     An exposeEvent() is sent every time this value changes.
682
683     \sa exposeEvent()
684 */
685 bool QWindow::isExposed() const
686 {
687     Q_D(const QWindow);
688     return d->exposed;
689 }
690
691 /*!
692     Returns true if the window should appear active from a style perspective.
693
694     This is the case for the window that has input focus as well as windows
695     that are in the same parent / transient parent chain as the focus window.
696
697     To get the window that currently has focus, use QGuiApplication::focusWindow().
698 */
699 bool QWindow::isActive() const
700 {
701     Q_D(const QWindow);
702     if (!d->platformWindow)
703         return false;
704
705     QWindow *focus = QGuiApplication::focusWindow();
706
707     // Means the whole application lost the focus
708     if (!focus)
709         return false;
710
711     if (focus == this)
712         return true;
713
714     if (!parent() && !transientParent()) {
715         return isAncestorOf(focus);
716     } else {
717         return (parent() && parent()->isActive()) || (transientParent() && transientParent()->isActive());
718     }
719 }
720
721 /*!
722     \property QWindow::contentOrientation
723     \brief the orientation of the window's contents
724
725     This is a hint to the window manager in case it needs to display
726     additional content like popups, dialogs, status bars, or similar
727     in relation to the window.
728
729     The recommended orientation is QScreen::orientation() but
730     an application doesn't have to support all possible orientations,
731     and thus can opt to ignore the current screen orientation.
732
733     The difference between the window and the content orientation
734     determines how much to rotate the content by. QScreen::angleBetween(),
735     QScreen::transformBetween(), and QScreen::mapBetween() can be used
736     to compute the necessary transform.
737
738     The default value is Qt::PrimaryOrientation
739 */
740 void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
741 {
742     Q_D(QWindow);
743     if (d->contentOrientation == orientation)
744         return;
745     if (!d->platformWindow)
746         create();
747     Q_ASSERT(d->platformWindow);
748     d->contentOrientation = orientation;
749     d->platformWindow->handleContentOrientationChange(orientation);
750     emit contentOrientationChanged(orientation);
751 }
752
753 Qt::ScreenOrientation QWindow::contentOrientation() const
754 {
755     Q_D(const QWindow);
756     return d->contentOrientation;
757 }
758
759 /*!
760     Returns the ratio between physical pixels and device-independent pixels
761     for the window. This value is dependent on the screen the window is on,
762     and may change when the window is moved.
763
764     Common values are 1.0 on normal displays and 2.0 on Apple "retina" displays.
765
766     \sa QWindow::devicePixelRatio();
767     \sa QGuiApplicaiton::devicePixelRatio();
768 */
769 qreal QWindow::devicePixelRatio() const
770 {
771     Q_D(const QWindow);
772     if (!d->platformWindow)
773         return 1.0;
774     return d->platformWindow->devicePixelRatio();
775 }
776
777 /*!
778     \brief set the screen-occupation state of the window
779
780     The window \a state represents whether the window appears in the
781     windowing system as maximized, minimized, fullscreen, or normal.
782
783     The enum value Qt::WindowActive is not an accepted parameter.
784
785     \sa showNormal(), showFullScreen(), showMinimized(), showMaximized()
786 */
787 void QWindow::setWindowState(Qt::WindowState state)
788 {
789     if (state == Qt::WindowActive) {
790         qWarning() << "QWindow::setWindowState does not accept Qt::WindowActive";
791         return;
792     }
793
794     Q_D(QWindow);
795     if (d->platformWindow)
796         d->platformWindow->setWindowState(state);
797     d->windowState = state;
798     emit windowStateChanged(d->windowState);
799 }
800
801 /*!
802     \brief the screen-occupation state of the window
803
804     \sa setWindowState()
805 */
806 Qt::WindowState QWindow::windowState() const
807 {
808     Q_D(const QWindow);
809     return d->windowState;
810 }
811
812 /*!
813     \fn QWindow::windowStateChanged(Qt::WindowState windowState)
814
815     This signal is emitted when the \a windowState changes, either
816     by being set explicitly with setWindowState(), or automatically when
817     the user clicks one of the titlebar buttons or by other means.
818 */
819
820 /*!
821     Sets the transient \a parent
822
823     This is a hint to the window manager that this window is a dialog or pop-up
824     on behalf of the given window.
825
826     \sa transientParent(), parent()
827 */
828 void QWindow::setTransientParent(QWindow *parent)
829 {
830     Q_D(QWindow);
831     d->transientParent = parent;
832
833     QGuiApplicationPrivate::updateBlockedStatus(this);
834 }
835
836 /*!
837     Returns the transient parent of the window.
838
839     \sa setTransientParent(), parent()
840 */
841 QWindow *QWindow::transientParent() const
842 {
843     Q_D(const QWindow);
844     return d->transientParent.data();
845 }
846
847 /*!
848     \enum QWindow::AncestorMode
849
850     This enum is used to control whether or not transient parents
851     should be considered ancestors.
852
853     \value ExcludeTransients Transient parents are not considered ancestors.
854     \value IncludeTransients Transient parents are considered ancestors.
855 */
856
857 /*!
858     Returns true if the window is an ancestor of the given \a child. If \a mode
859     is IncludeTransients, then transient parents are also considered ancestors.
860 */
861 bool QWindow::isAncestorOf(const QWindow *child, AncestorMode mode) const
862 {
863     if (child->parent() == this || (mode == IncludeTransients && child->transientParent() == this))
864         return true;
865
866     return (child->parent() && isAncestorOf(child->parent(), mode))
867         || (mode == IncludeTransients && child->transientParent() && isAncestorOf(child->transientParent(), mode));
868 }
869
870 /*!
871     Returns the minimum size of the window.
872
873     \sa setMinimumSize()
874 */
875 QSize QWindow::minimumSize() const
876 {
877     Q_D(const QWindow);
878     return d->minimumSize;
879 }
880
881 /*!
882     Returns the maximum size of the window.
883
884     \sa setMaximumSize()
885 */
886 QSize QWindow::maximumSize() const
887 {
888     Q_D(const QWindow);
889     return d->maximumSize;
890 }
891
892 /*!
893     Returns the base size of the window.
894
895     \sa setBaseSize()
896 */
897 QSize QWindow::baseSize() const
898 {
899     Q_D(const QWindow);
900     return d->baseSize;
901 }
902
903 /*!
904     Returns the size increment of the window.
905
906     \sa setSizeIncrement()
907 */
908 QSize QWindow::sizeIncrement() const
909 {
910     Q_D(const QWindow);
911     return d->sizeIncrement;
912 }
913
914 /*!
915     Sets the minimum size of the window.
916
917     This is a hint to the window manager to prevent resizing below the specified \a size.
918
919     \sa setMaximumSize(), minimumSize()
920 */
921 void QWindow::setMinimumSize(const QSize &size)
922 {
923     Q_D(QWindow);
924     QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX));
925     if (d->minimumSize == adjustedSize)
926         return;
927     QSize oldSize = d->minimumSize;
928     d->minimumSize = adjustedSize;
929     if (d->platformWindow && isTopLevel())
930         d->platformWindow->propagateSizeHints();
931     if (d->minimumSize.width() != oldSize.width())
932         emit minimumWidthChanged(d->minimumSize.width());
933     if (d->minimumSize.height() != oldSize.height())
934         emit minimumHeightChanged(d->minimumSize.height());
935 }
936
937 /*!
938     \property QWindow::x
939     \brief the x position of the window's geometry
940 */
941 void QWindow::setX(int arg)
942 {
943     if (x() != arg)
944         setGeometry(QRect(arg, y(), width(), height()));
945 }
946
947 /*!
948     \property QWindow::y
949     \brief the y position of the window's geometry
950 */
951 void QWindow::setY(int arg)
952 {
953     if (y() != arg)
954         setGeometry(QRect(x(), arg, width(), height()));
955 }
956
957 /*!
958     \property QWindow::width
959     \brief the width of the window's geometry
960 */
961 void QWindow::setWidth(int arg)
962 {
963     if (width() != arg)
964         setGeometry(QRect(x(), y(), arg, height()));
965 }
966
967 /*!
968     \property QWindow::height
969     \brief the height of the window's geometry
970 */
971 void QWindow::setHeight(int arg)
972 {
973     if (height() != arg)
974         setGeometry(QRect(x(), y(), width(), arg));
975 }
976
977 /*!
978     \property QWindow::minimumWidth
979     \brief the minimum width of the window's geometry
980 */
981 void QWindow::setMinimumWidth(int w)
982 {
983     setMinimumSize(QSize(w, minimumHeight()));
984 }
985
986 /*!
987     \property QWindow::minimumHeight
988     \brief the minimum height of the window's geometry
989 */
990 void QWindow::setMinimumHeight(int h)
991 {
992     setMinimumSize(QSize(minimumWidth(), h));
993 }
994
995 /*!
996     Sets the maximum size of the window.
997
998     This is a hint to the window manager to prevent resizing above the specified \a size.
999
1000     \sa setMinimumSize(), maximumSize()
1001 */
1002 void QWindow::setMaximumSize(const QSize &size)
1003 {
1004     Q_D(QWindow);
1005     QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX));
1006     if (d->maximumSize == adjustedSize)
1007         return;
1008     QSize oldSize = d->maximumSize;
1009     d->maximumSize = adjustedSize;
1010     if (d->platformWindow && isTopLevel())
1011         d->platformWindow->propagateSizeHints();
1012     if (d->maximumSize.width() != oldSize.width())
1013         emit maximumWidthChanged(d->maximumSize.width());
1014     if (d->maximumSize.height() != oldSize.height())
1015         emit maximumHeightChanged(d->maximumSize.height());
1016 }
1017
1018 /*!
1019     \property QWindow::maximumWidth
1020     \brief the maximum width of the window's geometry
1021 */
1022 void QWindow::setMaximumWidth(int w)
1023 {
1024     setMaximumSize(QSize(w, maximumHeight()));
1025 }
1026
1027 /*!
1028     \property QWindow::maximumHeight
1029     \brief the maximum height of the window's geometry
1030 */
1031 void QWindow::setMaximumHeight(int h)
1032 {
1033     setMaximumSize(QSize(maximumWidth(), h));
1034 }
1035
1036 /*!
1037     Sets the base \a size of the window.
1038
1039     The base size is used to calculate a proper window size if the
1040     window defines sizeIncrement().
1041
1042     \sa setMinimumSize(), setMaximumSize(), setSizeIncrement(), baseSize()
1043 */
1044 void QWindow::setBaseSize(const QSize &size)
1045 {
1046     Q_D(QWindow);
1047     if (d->baseSize == size)
1048         return;
1049     d->baseSize = size;
1050     if (d->platformWindow && isTopLevel())
1051         d->platformWindow->propagateSizeHints();
1052 }
1053
1054 /*!
1055     Sets the size increment (\a size) of the window.
1056
1057     When the user resizes the window, the size will move in steps of
1058     sizeIncrement().width() pixels horizontally and
1059     sizeIncrement().height() pixels vertically, with baseSize() as the
1060     basis.
1061
1062     By default, this property contains a size with zero width and height.
1063
1064     The windowing system might not support size increments.
1065
1066     \sa setBaseSize(), setMinimumSize(), setMaximumSize()
1067 */
1068 void QWindow::setSizeIncrement(const QSize &size)
1069 {
1070     Q_D(QWindow);
1071     if (d->sizeIncrement == size)
1072         return;
1073     d->sizeIncrement = size;
1074     if (d->platformWindow && isTopLevel())
1075         d->platformWindow->propagateSizeHints();
1076 }
1077
1078 /*!
1079     Sets the geometry of the window, excluding its window frame, to a
1080     rectangle constructed from \a posx, \a posy, \a w and \a h.
1081
1082     \sa geometry()
1083 */
1084 void QWindow::setGeometry(int posx, int posy, int w, int h)
1085 {
1086     setGeometry(QRect(posx, posy, w, h));
1087 }
1088
1089 /*!
1090     \brief Sets the geometry of the window, excluding its window frame, to \a rect.
1091
1092     \sa geometry()
1093 */
1094 void QWindow::setGeometry(const QRect &rect)
1095 {
1096     Q_D(QWindow);
1097     if (rect == geometry())
1098         return;
1099     QRect oldRect = geometry();
1100
1101     d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
1102     if (d->platformWindow) {
1103         d->platformWindow->setGeometry(rect);
1104     } else {
1105         d->geometry = rect;
1106     }
1107
1108     if (rect.x() != oldRect.x())
1109         emit xChanged(rect.x());
1110     if (rect.y() != oldRect.y())
1111         emit yChanged(rect.y());
1112     if (rect.width() != oldRect.width())
1113         emit widthChanged(rect.width());
1114     if (rect.height() != oldRect.height())
1115         emit heightChanged(rect.height());
1116 }
1117
1118 /*!
1119     Returns the geometry of the window, excluding its window frame.
1120
1121     \sa frameMargins(), frameGeometry()
1122 */
1123 QRect QWindow::geometry() const
1124 {
1125     Q_D(const QWindow);
1126     if (d->platformWindow)
1127         return d->platformWindow->geometry();
1128     return d->geometry;
1129 }
1130
1131 /*!
1132     Returns the window frame margins surrounding the window.
1133
1134     \sa geometry(), frameGeometry()
1135 */
1136 QMargins QWindow::frameMargins() const
1137 {
1138     Q_D(const QWindow);
1139     if (d->platformWindow)
1140         return d->platformWindow->frameMargins();
1141     return QMargins();
1142 }
1143
1144 /*!
1145     Returns the geometry of the window, including its window frame.
1146
1147     \sa geometry(), frameMargins()
1148 */
1149 QRect QWindow::frameGeometry() const
1150 {
1151     Q_D(const QWindow);
1152     if (d->platformWindow) {
1153         QMargins m = frameMargins();
1154         return d->platformWindow->geometry().adjusted(-m.left(), -m.top(), m.right(), m.bottom());
1155     }
1156     return d->geometry;
1157 }
1158
1159 /*!
1160     Returns the top left position of the window, including its window frame.
1161
1162     This returns the same value as frameGeometry().topLeft().
1163
1164     \sa geometry(), frameGeometry()
1165 */
1166 QPoint QWindow::framePosition() const
1167 {
1168     Q_D(const QWindow);
1169     if (d->platformWindow) {
1170         QMargins margins = frameMargins();
1171         return d->platformWindow->geometry().topLeft() - QPoint(margins.left(), margins.top());
1172     }
1173     return d->geometry.topLeft();
1174 }
1175
1176 /*!
1177     Sets the upper left position of the window (\a point) including its window frame.
1178
1179     \sa setGeometry(), frameGeometry()
1180 */
1181 void QWindow::setFramePosition(const QPoint &point)
1182 {
1183     Q_D(QWindow);
1184     d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
1185     if (d->platformWindow) {
1186         d->platformWindow->setGeometry(QRect(point, size()));
1187     } else {
1188         d->geometry.setTopLeft(point);
1189     }
1190 }
1191
1192 /*!
1193     \brief set the position of the window on the desktop to \a pt
1194
1195     \sa position()
1196 */
1197 void QWindow::setPosition(const QPoint &pt)
1198 {
1199     setGeometry(QRect(pt, size()));
1200 }
1201
1202 /*!
1203     \brief set the position of the window on the desktop to \a posx, \a posy
1204
1205     \sa position()
1206 */
1207 void QWindow::setPosition(int posx, int posy)
1208 {
1209     setPosition(QPoint(posx, posy));
1210 }
1211
1212 /*!
1213     \fn QPoint QWindow::position() const
1214     \brief get the position of the window on the desktop excluding any window frame
1215
1216     \sa setPosition()
1217 */
1218
1219 /*!
1220     \fn QSize QWindow::size() const
1221     \brief get the size of the window excluding any window frame
1222
1223     \sa resize()
1224 */
1225
1226 /*!
1227     set the size of the window, excluding any window frame, to a QSize
1228     constructed from width \a w and height \a h
1229
1230     \sa size(), geometry()
1231 */
1232 void QWindow::resize(int w, int h)
1233 {
1234     resize(QSize(w, h));
1235 }
1236
1237 /*!
1238     \brief set the size of the window, excluding any window frame, to \a newSize
1239
1240     \sa size(), geometry()
1241 */
1242 void QWindow::resize(const QSize &newSize)
1243 {
1244     Q_D(QWindow);
1245     if (d->platformWindow) {
1246         d->platformWindow->setGeometry(QRect(position(), newSize));
1247     } else {
1248         d->geometry.setSize(newSize);
1249     }
1250 }
1251
1252 /*!
1253     Releases the native platform resources associated with this window.
1254
1255     \sa create()
1256 */
1257 void QWindow::destroy()
1258 {
1259     Q_D(QWindow);
1260     QObjectList childrenWindows = children();
1261     for (int i = 0; i < childrenWindows.size(); i++) {
1262         QObject *object = childrenWindows.at(i);
1263         if (object->isWindowType()) {
1264             QWindow *w = static_cast<QWindow*>(object);
1265             QGuiApplicationPrivate::window_list.removeAll(w);
1266             w->destroy();
1267         }
1268     }
1269     setVisible(false);
1270     delete d->platformWindow;
1271     d->resizeEventPending = true;
1272     d->receivedExpose = false;
1273     d->exposed = false;
1274     d->platformWindow = 0;
1275 }
1276
1277 /*!
1278     Returns the platform window corresponding to the window.
1279
1280     \internal
1281 */
1282 QPlatformWindow *QWindow::handle() const
1283 {
1284     Q_D(const QWindow);
1285     return d->platformWindow;
1286 }
1287
1288 /*!
1289     Returns the platform surface corresponding to the window.
1290
1291     \internal
1292 */
1293 QPlatformSurface *QWindow::surfaceHandle() const
1294 {
1295     Q_D(const QWindow);
1296     return d->platformWindow;
1297 }
1298
1299 /*!
1300     Set whether keyboard grab should be enabled or not (\a grab).
1301
1302     If the return value is true, the window receives all key events until
1303     setKeyboardGrabEnabled(false) is called; other windows get no key events at
1304     all. Mouse events are not affected. Use setMouseGrabEnabled() if you want
1305     to grab that.
1306
1307     \sa setMouseGrabEnabled()
1308 */
1309 bool QWindow::setKeyboardGrabEnabled(bool grab)
1310 {
1311     Q_D(QWindow);
1312     if (grab && QGuiApplicationPrivate::noGrab)
1313         return false;
1314     if (d->platformWindow)
1315         return d->platformWindow->setKeyboardGrabEnabled(grab);
1316     return false;
1317 }
1318
1319 /*!
1320     Sets whether mouse grab should be enabled or not (\a grab).
1321
1322     If the return value is true, the window receives all mouse events until setMouseGrabEnabled(false) is
1323     called; other windows get no mouse events at all. Keyboard events are not affected.
1324     Use setKeyboardGrabEnabled() if you want to grab that.
1325
1326     \sa setKeyboardGrabEnabled()
1327 */
1328 bool QWindow::setMouseGrabEnabled(bool grab)
1329 {
1330     Q_D(QWindow);
1331     if (grab && QGuiApplicationPrivate::noGrab)
1332         return false;
1333     if (d->platformWindow)
1334         return d->platformWindow->setMouseGrabEnabled(grab);
1335     return false;
1336 }
1337
1338 /*!
1339     Returns the screen on which the window is shown.
1340
1341     The value returned will not change when the window is moved
1342     between virtual screens (as returned by QScreen::virtualSiblings()).
1343
1344     \sa setScreen(), QScreen::virtualSiblings()
1345 */
1346 QScreen *QWindow::screen() const
1347 {
1348     Q_D(const QWindow);
1349     return d->screen;
1350 }
1351
1352 /*!
1353     Sets the screen on which the window should be shown.
1354
1355     If the window has been created, it will be recreated on the \a newScreen.
1356
1357     Note that if the screen is part of a virtual desktop of multiple screens,
1358     the window can appear on any of the screens returned by QScreen::virtualSiblings().
1359
1360     \sa screen(), QScreen::virtualSiblings()
1361 */
1362 void QWindow::setScreen(QScreen *newScreen)
1363 {
1364     Q_D(QWindow);
1365     if (!newScreen)
1366         newScreen = QGuiApplication::primaryScreen();
1367     if (newScreen != screen()) {
1368         const bool wasCreated = d->platformWindow != 0;
1369         if (wasCreated)
1370             destroy();
1371         if (d->screen)
1372             disconnect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(screenDestroyed(QObject*)));
1373         d->screen = newScreen;
1374         if (newScreen) {
1375             connect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(screenDestroyed(QObject*)));
1376             if (wasCreated)
1377                 create();
1378         }
1379         emit screenChanged(newScreen);
1380     }
1381 }
1382
1383 void QWindow::screenDestroyed(QObject *object)
1384 {
1385     Q_D(QWindow);
1386     if (object == static_cast<QObject *>(d->screen)) {
1387         const bool wasVisible = isVisible();
1388         setScreen(0);
1389         // destroy() might have hidden our window, show it again.
1390         // This might not be the best behavior if the new screen isn't a virtual sibling
1391         // of the old one. This can be removed once platform plugins have the power to
1392         // update the QScreen of its QWindows itself.
1393         if (wasVisible && d->platformWindow)
1394             setVisible(true);
1395     }
1396 }
1397
1398 /*!
1399     \fn QWindow::screenChanged(QScreen *screen)
1400
1401     This signal is emitted when a window's \a screen changes, either
1402     by being set explicitly with setScreen(), or automatically when
1403     the window's screen is removed.
1404 */
1405
1406 /*!
1407   Returns the accessibility interface for the object that the window represents
1408   \internal
1409   \sa QAccessible
1410   */
1411 QAccessibleInterface *QWindow::accessibleRoot() const
1412 {
1413     return 0;
1414 }
1415
1416 /*!
1417     \fn QWindow::focusObjectChanged(QObject *focusObject)
1418
1419     This signal is emitted when final receiver of events tied to focus is
1420     changed to \a focusObject.
1421
1422     \sa focusObject()
1423 */
1424
1425 /*!
1426     Returns the QObject that will be the final receiver of events tied focus, such
1427     as key events.
1428 */
1429 QObject *QWindow::focusObject() const
1430 {
1431     return const_cast<QWindow *>(this);
1432 }
1433
1434 /*!
1435     Shows the window.
1436
1437     This equivalent to calling showFullScreen() or showNormal(), depending
1438     on whether the platform defaults to windows being fullscreen or not.
1439
1440     \sa showFullScreen(), showNormal(), hide(), QStyleHints::showIsFullScreen()
1441 */
1442 void QWindow::show()
1443 {
1444     if (qApp->styleHints()->showIsFullScreen())
1445         showFullScreen();
1446     else
1447         showNormal();
1448 }
1449
1450 /*!
1451     Hides the window.
1452
1453     Equivalent to calling setVisible(false).
1454
1455     \sa show(), setVisible()
1456 */
1457 void QWindow::hide()
1458 {
1459     setVisible(false);
1460 }
1461
1462 /*!
1463     Shows the window as minimized.
1464
1465     Equivalent to calling setWindowState(Qt::WindowMinimized) and then
1466     setVisible(true).
1467
1468     \sa setWindowState(), setVisible()
1469 */
1470 void QWindow::showMinimized()
1471 {
1472     setWindowState(Qt::WindowMinimized);
1473     setVisible(true);
1474 }
1475
1476 /*!
1477     Shows the window as maximized.
1478
1479     Equivalent to calling setWindowState(Qt::WindowMaximized) and then
1480     setVisible(true).
1481
1482     \sa setWindowState(), setVisible()
1483 */
1484 void QWindow::showMaximized()
1485 {
1486     setWindowState(Qt::WindowMaximized);
1487     setVisible(true);
1488 }
1489
1490 /*!
1491     Shows the window as fullscreen.
1492
1493     Equivalent to calling setWindowState(Qt::WindowFullScreen) and then
1494     setVisible(true).
1495
1496     \sa setWindowState(), setVisible()
1497 */
1498 void QWindow::showFullScreen()
1499 {
1500     setWindowState(Qt::WindowFullScreen);
1501     setVisible(true);
1502     requestActivate();
1503 }
1504
1505 /*!
1506     Shows the window as normal, i.e. neither maximized, minimized, nor fullscreen.
1507
1508     Equivalent to calling setWindowState(Qt::WindowNoState) and then
1509     setVisible(true).
1510
1511     \sa setWindowState(), setVisible()
1512 */
1513 void QWindow::showNormal()
1514 {
1515     setWindowState(Qt::WindowNoState);
1516     setVisible(true);
1517 }
1518
1519 /*!
1520     Close the window.
1521
1522     This closes the window, effectively calling destroy(), and potentially
1523     quitting the application. Returns true on success, false if it has a parent
1524     window (in which case the top level window should be closed instead).
1525
1526     \sa destroy(), QGuiApplication::quitOnLastWindowClosed()
1527 */
1528 bool QWindow::close()
1529 {
1530     Q_D(QWindow);
1531
1532     // Do not close non top level windows
1533     if (parent())
1534         return false;
1535
1536     if (QGuiApplicationPrivate::focus_window == this)
1537         QGuiApplicationPrivate::focus_window = 0;
1538     if (QGuiApplicationPrivate::currentMouseWindow == this)
1539         QGuiApplicationPrivate::currentMouseWindow = 0;
1540
1541     QGuiApplicationPrivate::window_list.removeAll(this);
1542     destroy();
1543     d->maybeQuitOnLastWindowClosed();
1544     return true;
1545 }
1546
1547 /*!
1548     The expose event (\a ev) is sent by the window system whenever the window's
1549     exposure on screen changes.
1550
1551     The application can start rendering into the window with QBackingStore
1552     and QOpenGLContext as soon as it gets an exposeEvent() such that
1553     isExposed() is true.
1554
1555     If the window is moved off screen, is made totally obscured by another
1556     window, iconified or similar, this function might be called and the
1557     value of isExposed() might change to false. When this happens,
1558     an application should stop its rendering as it is no longer visible
1559     to the user.
1560
1561     A resize event will always be sent before the expose event the first time
1562     a window is shown.
1563
1564     \sa isExposed()
1565 */
1566 void QWindow::exposeEvent(QExposeEvent *ev)
1567 {
1568     ev->ignore();
1569 }
1570
1571 /*!
1572     Override this to handle mouse events (\a ev).
1573 */
1574 void QWindow::moveEvent(QMoveEvent *ev)
1575 {
1576     ev->ignore();
1577 }
1578
1579 /*!
1580     Override this to handle resize events (\a ev).
1581
1582     The resize event is called whenever the window is resized in the windowing system,
1583     either directly through the windowing system acknowledging a setGeometry() or resize() request,
1584     or indirectly through the user resizing the window manually.
1585 */
1586 void QWindow::resizeEvent(QResizeEvent *ev)
1587 {
1588     ev->ignore();
1589 }
1590
1591 /*!
1592     Override this to handle show events (\a ev).
1593
1594     The function is called when the window has requested becoming visible.
1595
1596     If the window is successfully shown by the windowing system, this will
1597     be followed by a resize and an expose event.
1598 */
1599 void QWindow::showEvent(QShowEvent *ev)
1600 {
1601     ev->ignore();
1602 }
1603
1604 /*!
1605     Override this to handle hide events (\a ev).
1606
1607     The function is called when the window has requested being hidden in the
1608     windowing system.
1609 */
1610 void QWindow::hideEvent(QHideEvent *ev)
1611 {
1612     ev->ignore();
1613 }
1614
1615 /*!
1616     Override this to handle any event (\a ev) sent to the window.
1617     Return \c true if the event was recognized and processed.
1618
1619     Remember to call the base class version if you wish for mouse events,
1620     key events, resize events, etc to be dispatched as usual.
1621 */
1622 bool QWindow::event(QEvent *ev)
1623 {
1624     switch (ev->type()) {
1625     case QEvent::MouseMove:
1626         mouseMoveEvent(static_cast<QMouseEvent*>(ev));
1627         break;
1628
1629     case QEvent::MouseButtonPress:
1630         mousePressEvent(static_cast<QMouseEvent*>(ev));
1631         break;
1632
1633     case QEvent::MouseButtonRelease:
1634         mouseReleaseEvent(static_cast<QMouseEvent*>(ev));
1635         break;
1636
1637     case QEvent::MouseButtonDblClick:
1638         mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev));
1639         break;
1640
1641     case QEvent::TouchBegin:
1642     case QEvent::TouchUpdate:
1643     case QEvent::TouchEnd:
1644     case QEvent::TouchCancel:
1645         touchEvent(static_cast<QTouchEvent *>(ev));
1646         break;
1647
1648     case QEvent::Move:
1649         moveEvent(static_cast<QMoveEvent*>(ev));
1650         break;
1651
1652     case QEvent::Resize:
1653         resizeEvent(static_cast<QResizeEvent*>(ev));
1654         break;
1655
1656     case QEvent::KeyPress:
1657         keyPressEvent(static_cast<QKeyEvent *>(ev));
1658         break;
1659
1660     case QEvent::KeyRelease:
1661         keyReleaseEvent(static_cast<QKeyEvent *>(ev));
1662         break;
1663
1664     case QEvent::FocusIn: {
1665         focusInEvent(static_cast<QFocusEvent *>(ev));
1666 #ifndef QT_NO_ACCESSIBILITY
1667         QAccessible::State state;
1668         state.active = true;
1669         QAccessibleStateChangeEvent event(this, state);
1670         QAccessible::updateAccessibility(&event);
1671 #endif
1672         break; }
1673
1674     case QEvent::FocusOut: {
1675         focusOutEvent(static_cast<QFocusEvent *>(ev));
1676 #ifndef QT_NO_ACCESSIBILITY
1677         QAccessible::State state;
1678         state.active = true;
1679         QAccessibleStateChangeEvent event(this, state);
1680         QAccessible::updateAccessibility(&event);
1681 #endif
1682         break; }
1683
1684 #ifndef QT_NO_WHEELEVENT
1685     case QEvent::Wheel:
1686         wheelEvent(static_cast<QWheelEvent*>(ev));
1687         break;
1688 #endif
1689
1690     case QEvent::Close: {
1691         Q_D(QWindow);
1692         bool wasVisible = isVisible();
1693         destroy();
1694         if (wasVisible)
1695             d->maybeQuitOnLastWindowClosed();
1696         break; }
1697
1698     case QEvent::Expose:
1699         exposeEvent(static_cast<QExposeEvent *>(ev));
1700         break;
1701
1702     case QEvent::Show:
1703         showEvent(static_cast<QShowEvent *>(ev));
1704         break;
1705
1706     case QEvent::Hide:
1707         hideEvent(static_cast<QHideEvent *>(ev));
1708         break;
1709
1710     case QEvent::WindowStateChange: {
1711         Q_D(QWindow);
1712         emit windowStateChanged(d->windowState);
1713         break;
1714     }
1715
1716 #ifndef QT_NO_TABLETEVENT
1717     case QEvent::TabletPress:
1718     case QEvent::TabletMove:
1719     case QEvent::TabletRelease:
1720         tabletEvent(static_cast<QTabletEvent *>(ev));
1721         break;
1722 #endif
1723
1724     default:
1725         return QObject::event(ev);
1726     }
1727     return true;
1728 }
1729
1730 /*!
1731     Override this to handle key press events (\a ev).
1732
1733     \sa keyReleaseEvent()
1734 */
1735 void QWindow::keyPressEvent(QKeyEvent *ev)
1736 {
1737     ev->ignore();
1738 }
1739
1740 /*!
1741     Override this to handle key release events (\a ev).
1742
1743     \sa keyPressEvent()
1744 */
1745 void QWindow::keyReleaseEvent(QKeyEvent *ev)
1746 {
1747     ev->ignore();
1748 }
1749
1750 /*!
1751     Override this to handle focus in events (\a ev).
1752
1753     Focus in events are sent when the window receives keyboard focus.
1754
1755     \sa focusOutEvent()
1756 */
1757 void QWindow::focusInEvent(QFocusEvent *ev)
1758 {
1759     ev->ignore();
1760 }
1761
1762 /*!
1763     Override this to handle focus out events (\a ev).
1764
1765     Focus out events are sent when the window loses keyboard focus.
1766
1767     \sa focusInEvent()
1768 */
1769 void QWindow::focusOutEvent(QFocusEvent *ev)
1770 {
1771     ev->ignore();
1772 }
1773
1774 /*!
1775     Override this to handle mouse press events (\a ev).
1776
1777     \sa mouseReleaseEvent()
1778 */
1779 void QWindow::mousePressEvent(QMouseEvent *ev)
1780 {
1781     ev->ignore();
1782 }
1783
1784 /*!
1785     Override this to handle mouse release events (\a ev).
1786
1787     \sa mousePressEvent()
1788 */
1789 void QWindow::mouseReleaseEvent(QMouseEvent *ev)
1790 {
1791     ev->ignore();
1792 }
1793
1794 /*!
1795     Override this to handle mouse double click events (\a ev).
1796
1797     \sa mousePressEvent(), QStyleHints::mouseDoubleClickInterval()
1798 */
1799 void QWindow::mouseDoubleClickEvent(QMouseEvent *ev)
1800 {
1801     ev->ignore();
1802 }
1803
1804 /*!
1805     Override this to handle mouse move events (\a ev).
1806 */
1807 void QWindow::mouseMoveEvent(QMouseEvent *ev)
1808 {
1809     ev->ignore();
1810 }
1811
1812 #ifndef QT_NO_WHEELEVENT
1813 /*!
1814     Override this to handle mouse wheel or other wheel events (\a ev).
1815 */
1816 void QWindow::wheelEvent(QWheelEvent *ev)
1817 {
1818     ev->ignore();
1819 }
1820 #endif //QT_NO_WHEELEVENT
1821
1822 /*!
1823     Override this to handle touch events (\a ev).
1824 */
1825 void QWindow::touchEvent(QTouchEvent *ev)
1826 {
1827     ev->ignore();
1828 }
1829
1830 #ifndef QT_NO_TABLETEVENT
1831 /*!
1832     Override this to handle tablet press, move, and release events (\a ev).
1833
1834     Proximity enter and leave events are not sent to windows, they are
1835     delivered to the application instance.
1836 */
1837 void QWindow::tabletEvent(QTabletEvent *ev)
1838 {
1839     ev->ignore();
1840 }
1841 #endif
1842
1843 /*!
1844     Override this to handle platform dependent events.
1845     Will be given \a eventType, \a message and \a result.
1846
1847     This might make your application non-portable.
1848
1849     Should return true only if the event was handled.
1850 */
1851 bool QWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
1852 {
1853     Q_UNUSED(eventType);
1854     Q_UNUSED(message);
1855     Q_UNUSED(result);
1856     return false;
1857 }
1858
1859 /*!
1860     \fn QPoint QWindow::mapToGlobal(const QPoint &pos) const
1861
1862     Translates the window coordinate \a pos to global screen
1863     coordinates. For example, \c{mapToGlobal(QPoint(0,0))} would give
1864     the global coordinates of the top-left pixel of the window.
1865
1866     \sa mapFromGlobal()
1867 */
1868 QPoint QWindow::mapToGlobal(const QPoint &pos) const
1869 {
1870     Q_D(const QWindow);
1871     if (d->platformWindow && d->platformWindow->isEmbedded(0))
1872         return d->platformWindow->mapToGlobal(pos);
1873     else
1874         return pos + d_func()->globalPosition();
1875 }
1876
1877
1878 /*!
1879     \fn QPoint QWindow::mapFromGlobal(const QPoint &pos) const
1880
1881     Translates the global screen coordinate \a pos to window
1882     coordinates.
1883
1884     \sa mapToGlobal()
1885 */
1886 QPoint QWindow::mapFromGlobal(const QPoint &pos) const
1887 {
1888     Q_D(const QWindow);
1889     if (d->platformWindow && d->platformWindow->isEmbedded(0))
1890         return d->platformWindow->mapFromGlobal(pos);
1891     else
1892         return pos - d_func()->globalPosition();
1893 }
1894
1895
1896 Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window)
1897 {
1898     return window->d_func();
1899 }
1900
1901 void QWindowPrivate::maybeQuitOnLastWindowClosed()
1902 {
1903     Q_Q(QWindow);
1904
1905     // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent
1906     bool quitOnClose = QGuiApplication::quitOnLastWindowClosed() && !q->parent();
1907
1908     if (quitOnClose) {
1909         QWindowList list = QGuiApplication::topLevelWindows();
1910         bool lastWindowClosed = true;
1911         for (int i = 0; i < list.size(); ++i) {
1912             QWindow *w = list.at(i);
1913             if (!w->isVisible() || w->transientParent())
1914                 continue;
1915             lastWindowClosed = false;
1916             break;
1917         }
1918         if (lastWindowClosed) {
1919             QGuiApplicationPrivate::emitLastWindowClosed();
1920             QCoreApplicationPrivate *applicationPrivate = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(QCoreApplication::instance()));
1921             applicationPrivate->maybeQuit();
1922         }
1923     }
1924
1925 }
1926
1927 #ifndef QT_NO_CURSOR
1928 /*!
1929     \brief set the cursor shape for this window
1930
1931     The mouse \a cursor will assume this shape when it is over this
1932     window, unless an override cursor is set.
1933     See the \l{Qt::CursorShape}{list of predefined cursor objects} for a
1934     range of useful shapes.
1935
1936     By default, the cursor has the Qt::ArrowCursor shape.
1937
1938     Some underlying window implementations will reset the cursor if it
1939     leaves a window even if the mouse is grabbed. If you want to have
1940     a cursor set for all windows, even when outside the window, consider
1941     QGuiApplication::setOverrideCursor().
1942
1943     \sa QGuiApplication::setOverrideCursor()
1944 */
1945 void QWindow::setCursor(const QCursor &cursor)
1946 {
1947     Q_D(QWindow);
1948     d->cursor = cursor;
1949     // Only attempt to set cursor and emit signal if there is an actual platform cursor
1950     if (d->screen->handle()->cursor()) {
1951         d->applyCursor();
1952         QEvent event(QEvent::CursorChange);
1953         QGuiApplication::sendEvent(this, &event);
1954     }
1955 }
1956
1957 /*!
1958   \brief Restores the default arrow cursor for this window.
1959  */
1960 void QWindow::unsetCursor()
1961 {
1962     setCursor(Qt::ArrowCursor);
1963 }
1964
1965 /*!
1966     \brief the cursor shape for this window
1967
1968     \sa setCursor(), unsetCursor()
1969 */
1970 QCursor QWindow::cursor() const
1971 {
1972     Q_D(const QWindow);
1973     return d->cursor;
1974 }
1975
1976 void QWindowPrivate::applyCursor()
1977 {
1978     Q_Q(QWindow);
1979     if (platformWindow) {
1980         if (QPlatformCursor *platformCursor = screen->handle()->cursor()) {
1981             QCursor *oc = QGuiApplication::overrideCursor();
1982             QCursor c = oc ? *oc : cursor;
1983             platformCursor->changeCursor(&c, q);
1984         }
1985     }
1986 }
1987 #endif // QT_NO_CURSOR
1988
1989 QT_END_NAMESPACE