kernel/qwindow.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/****************************************************************************-
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/****************************************************************************
2** -
3** Copyright (C) 2013 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 -
66QT_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*/ -
138QWindow::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*/ -
165QWindow::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*/ -
191QWindow::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*/ -
208QWindow::~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/*!-
Set the \a surfaceType of the window.
Specifies whether the window is meant for raster rendering with
QBackingStore, or OpenGL rendering with QOpenGLContext.
The surfaceType will be used when the native surface is created
in the create() function. Calling this function after the native
surface has been created requires calling destroy() and create()
to release the old native surface and create a new one.
\sa QBackingStore, QOpenGLContext, create(), destroy()
*/*!
219 Sets 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*/ -
231void 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*/ -
242QWindow::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*/ -
259void 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 -
298bool 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*/ -
319void 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*/ -
344WId 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*/ -
361QWindow *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 -
374void 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*/ -
396bool 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*/ -
409bool 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 -
426Qt::WindowModality QWindow::modality() const -
427{ -
428 Q_D(const QWindow); -
429 return d->modality; -
430} -
431 -
432void 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*/ -
466void 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 */ -
482QSurfaceFormat 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*/ -
497QSurfaceFormat 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*/ -
516void 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 -
524Qt::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*/ -
538Qt::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*/ -
555void 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 -
563QString 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*/ -
576void 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*/ -
589QString QWindow::filePath() const -
590{ -
591 Q_D(const QWindow); -
592 return d->windowFilePath; -
593} -
594 -
595/*!-
\brief set the window's \a icon in the windowing system
The window icon might be used by the windowing system for example to
decorate the window, and/or in the task switcher.
*/*!
596 \brief Sets 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*/ -
601void 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/*!-
\brief set the window's icon in the windowing system
\sa setIcon()
*/*!
610 \brief Sets the window's icon in the windowing system -
611 -
612 \sa setIcon() -
613*/ -
614QIcon 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*/ -
625void 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*/ -
637void 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*/ -
654void QWindow::setOpacity(qreal level) -
655{ -
656 Q_D(QWindow); -
657 if (level == d->opacity) // #fixme: Add property for 5.1 -
658 return; -
659 d->opacity = level; -
660 if (d->platformWindow) -
661 d->platformWindow->setOpacity(level); -
662} -
663 -
664/*! -
665 Requests the window to be activated, i.e. receive keyboard focus. -
666 -
667 \sa isActive(), QGuiApplication::focusWindow() -
668*/ -
669void QWindow::requestActivate() -
670{ -
671 Q_D(QWindow); -
672 if (d->platformWindow) -
673 d->platformWindow->requestActivateWindow(); -
674} -
675 -
676/*! -
677 Returns if this window is exposed in the windowing system. -
678 -
679 When the window is not exposed, it is shown by the application -
680 but it is still not showing in the windowing system, so the application -
681 should minimize rendering and other graphical activities. -
682 -
683 An exposeEvent() is sent every time this value changes. -
684 -
685 \sa exposeEvent() -
686*/ -
687bool QWindow::isExposed() const -
688{ -
689 Q_D(const QWindow); -
690 return d->exposed; -
691} -
692 -
693/*! -
694 Returns true if the window should appear active from a style perspective. -
695 -
696 This is the case for the window that has input focus as well as windows -
697 that are in the same parent / transient parent chain as the focus window. -
698 -
699 To get the window that currently has focus, use QGuiApplication::focusWindow(). -
700*/ -
701bool QWindow::isActive() const -
702{ -
703 Q_D(const QWindow); -
704 if (!d->platformWindow) -
705 return false; -
706 -
707 QWindow *focus = QGuiApplication::focusWindow(); -
708 -
709 // Means the whole application lost the focus -
710 if (!focus) -
711 return false; -
712 -
713 if (focus == this) -
714 return true; -
715 -
716 if (!parent() && !transientParent()) { -
717 return isAncestorOf(focus); -
718 } else { -
719 return (parent() && parent()->isActive()) || (transientParent() && transientParent()->isActive()); -
720 } -
721} -
722 -
723/*! -
724 \property QWindow::contentOrientation -
725 \brief the orientation of the window's contents -
726 -
727 This is a hint to the window manager in case it needs to display -
728 additional content like popups, dialogs, status bars, or similar -
729 in relation to the window. -
730 -
731 The recommended orientation is QScreen::orientation() but -
732 an application doesn't have to support all possible orientations, -
733 and thus can opt to ignore the current screen orientation. -
734 -
735 The difference between the window and the content orientation -
736 determines how much to rotate the content by. QScreen::angleBetween(), -
737 QScreen::transformBetween(), and QScreen::mapBetween() can be used -
738 to compute the necessary transform. -
739 -
740 The default value is Qt::PrimaryOrientation -
741*/ -
742void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation) -
743{ -
744 Q_D(QWindow); -
745 if (d->contentOrientation == orientation) -
746 return; -
747 if (!d->platformWindow) -
748 create(); -
749 Q_ASSERT(d->platformWindow); -
750 d->contentOrientation = orientation; -
751 d->platformWindow->handleContentOrientationChange(orientation); -
752 emit contentOrientationChanged(orientation); -
753} -
754 -
755Qt::ScreenOrientation QWindow::contentOrientation() const -
756{ -
757 Q_D(const QWindow); -
758 return d->contentOrientation; -
759} -
760 -
761/*!-
Returns the ratio between physical pixels and device-independent pixels
for the window. This value is dependent on the screen the window is on,
and may change when the window is moved.
Common values are 1.0 on normal displays and 2.0 on Apple "retina" displays.
\sa QWindow::devicePixelRatio();
\sa QGuiApplicaiton::devicePixelRatio();
*/*!
762 Returns the ratio between physical pixels and device-independent pixels -
763 for the window. This value is dependent on the screen the window is on, -
764 and may change when the window is moved. -
765 -
766 Common values are 1.0 on normal displays and 2.0 on Apple "retina" displays. -
767 -
768 \sa QScreen::devicePixelRatio(), QGuiApplication::devicePixelRatio() -
769*/ -
770qreal QWindow::devicePixelRatio() const -
771{ -
772 Q_D(const QWindow); -
773 if (!d->platformWindow) -
774 return 1.0; -
775 return d->platformWindow->devicePixelRatio(); -
776} -
777 -
778/*! -
779 \brief set the screen-occupation state of the window -
780 -
781 The window \a state represents whether the window appears in the -
782 windowing system as maximized, minimized, fullscreen, or normal. -
783 -
784 The enum value Qt::WindowActive is not an accepted parameter. -
785 -
786 \sa showNormal(), showFullScreen(), showMinimized(), showMaximized() -
787*/ -
788void QWindow::setWindowState(Qt::WindowState state) -
789{ -
790 if (state == Qt::WindowActive) { -
791 qWarning() << "QWindow::setWindowState does not accept Qt::WindowActive"; -
792 return; -
793 } -
794 -
795 Q_D(QWindow); -
796 if (d->platformWindow) -
797 d->platformWindow->setWindowState(state); -
798 d->windowState = state; -
799 emit windowStateChanged(d->windowState); -
800} -
801 -
802/*! -
803 \brief the screen-occupation state of the window -
804 -
805 \sa setWindowState() -
806*/ -
807Qt::WindowState QWindow::windowState() const -
808{ -
809 Q_D(const QWindow); -
810 return d->windowState; -
811} -
812 -
813/*! -
814 \fn QWindow::windowStateChanged(Qt::WindowState windowState) -
815 -
816 This signal is emitted when the \a windowState changes, either -
817 by being set explicitly with setWindowState(), or automatically when -
818 the user clicks one of the titlebar buttons or by other means. -
819*/ -
820 -
821/*! -
822 Sets the transient \a parent -
823 -
824 This is a hint to the window manager that this window is a dialog or pop-up -
825 on behalf of the given window. -
826 -
827 \sa transientParent(), parent() -
828*/ -
829void QWindow::setTransientParent(QWindow *parent) -
830{ -
831 Q_D(QWindow); -
832 d->transientParent = parent; -
833 -
834 QGuiApplicationPrivate::updateBlockedStatus(this); -
835} -
836 -
837/*! -
838 Returns the transient parent of the window. -
839 -
840 \sa setTransientParent(), parent() -
841*/ -
842QWindow *QWindow::transientParent() const -
843{ -
844 Q_D(const QWindow); -
845 return d->transientParent.data(); -
846} -
847 -
848/*! -
849 \enum QWindow::AncestorMode -
850 -
851 This enum is used to control whether or not transient parents -
852 should be considered ancestors. -
853 -
854 \value ExcludeTransients Transient parents are not considered ancestors. -
855 \value IncludeTransients Transient parents are considered ancestors. -
856*/ -
857 -
858/*! -
859 Returns true if the window is an ancestor of the given \a child. If \a mode -
860 is IncludeTransients, then transient parents are also considered ancestors. -
861*/ -
862bool QWindow::isAncestorOf(const QWindow *child, AncestorMode mode) const -
863{ -
864 if (child->parent() == this || (mode == IncludeTransients && child->transientParent() == this)) -
865 return true; -
866 -
867 return (child->parent() && isAncestorOf(child->parent(), mode)) -
868 || (mode == IncludeTransients && child->transientParent() && isAncestorOf(child->transientParent(), mode)); -
869} -
870 -
871/*! -
872 Returns the minimum size of the window. -
873 -
874 \sa setMinimumSize() -
875*/ -
876QSize QWindow::minimumSize() const -
877{ -
878 Q_D(const QWindow); -
879 return d->minimumSize; -
880} -
881 -
882/*! -
883 Returns the maximum size of the window. -
884 -
885 \sa setMaximumSize() -
886*/ -
887QSize QWindow::maximumSize() const -
888{ -
889 Q_D(const QWindow); -
890 return d->maximumSize; -
891} -
892 -
893/*! -
894 Returns the base size of the window. -
895 -
896 \sa setBaseSize() -
897*/ -
898QSize QWindow::baseSize() const -
899{ -
900 Q_D(const QWindow); -
901 return d->baseSize; -
902} -
903 -
904/*! -
905 Returns the size increment of the window. -
906 -
907 \sa setSizeIncrement() -
908*/ -
909QSize QWindow::sizeIncrement() const -
910{ -
911 Q_D(const QWindow); -
912 return d->sizeIncrement; -
913} -
914 -
915/*! -
916 Sets the minimum size of the window. -
917 -
918 This is a hint to the window manager to prevent resizing below the specified \a size. -
919 -
920 \sa setMaximumSize(), minimumSize() -
921*/ -
922void QWindow::setMinimumSize(const QSize &size) -
923{ -
924 Q_D(QWindow); -
925 QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX)); -
926 if (d->minimumSize == adjustedSize) -
927 return; -
928 QSize oldSize = d->minimumSize; -
929 d->minimumSize = adjustedSize; -
930 if (d->platformWindow && isTopLevel()) -
931 d->platformWindow->propagateSizeHints(); -
932 if (d->minimumSize.width() != oldSize.width()) -
933 emit minimumWidthChanged(d->minimumSize.width()); -
934 if (d->minimumSize.height() != oldSize.height()) -
935 emit minimumHeightChanged(d->minimumSize.height()); -
936} -
937 -
938/*! -
939 \property QWindow::x -
940 \brief the x position of the window's geometry -
941*/ -
942void QWindow::setX(int arg) -
943{ -
944 if (x() != arg) -
945 setGeometry(QRect(arg, y(), width(), height())); -
946} -
947 -
948/*! -
949 \property QWindow::y -
950 \brief the y position of the window's geometry -
951*/ -
952void QWindow::setY(int arg) -
953{ -
954 if (y() != arg) -
955 setGeometry(QRect(x(), arg, width(), height())); -
956} -
957 -
958/*! -
959 \property QWindow::width -
960 \brief the width of the window's geometry -
961*/ -
962void QWindow::setWidth(int arg) -
963{ -
964 if (width() != arg) -
965 setGeometry(QRect(x(), y(), arg, height())); -
966} -
967 -
968/*! -
969 \property QWindow::height -
970 \brief the height of the window's geometry -
971*/ -
972void QWindow::setHeight(int arg) -
973{ -
974 if (height() != arg) -
975 setGeometry(QRect(x(), y(), width(), arg)); -
976} -
977 -
978/*! -
979 \property QWindow::minimumWidth -
980 \brief the minimum width of the window's geometry -
981*/ -
982void QWindow::setMinimumWidth(int w) -
983{ -
984 setMinimumSize(QSize(w, minimumHeight())); -
985} -
986 -
987/*! -
988 \property QWindow::minimumHeight -
989 \brief the minimum height of the window's geometry -
990*/ -
991void QWindow::setMinimumHeight(int h) -
992{ -
993 setMinimumSize(QSize(minimumWidth(), h)); -
994} -
995 -
996/*! -
997 Sets the maximum size of the window. -
998 -
999 This is a hint to the window manager to prevent resizing above the specified \a size. -
1000 -
1001 \sa setMinimumSize(), maximumSize() -
1002*/ -
1003void QWindow::setMaximumSize(const QSize &size) -
1004{ -
1005 Q_D(QWindow); -
1006 QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX)); -
1007 if (d->maximumSize == adjustedSize) -
1008 return; -
1009 QSize oldSize = d->maximumSize; -
1010 d->maximumSize = adjustedSize; -
1011 if (d->platformWindow && isTopLevel()) -
1012 d->platformWindow->propagateSizeHints(); -
1013 if (d->maximumSize.width() != oldSize.width()) -
1014 emit maximumWidthChanged(d->maximumSize.width()); -
1015 if (d->maximumSize.height() != oldSize.height()) -
1016 emit maximumHeightChanged(d->maximumSize.height()); -
1017} -
1018 -
1019/*! -
1020 \property QWindow::maximumWidth -
1021 \brief the maximum width of the window's geometry -
1022*/ -
1023void QWindow::setMaximumWidth(int w) -
1024{ -
1025 setMaximumSize(QSize(w, maximumHeight())); -
1026} -
1027 -
1028/*! -
1029 \property QWindow::maximumHeight -
1030 \brief the maximum height of the window's geometry -
1031*/ -
1032void QWindow::setMaximumHeight(int h) -
1033{ -
1034 setMaximumSize(QSize(maximumWidth(), h)); -
1035} -
1036 -
1037/*! -
1038 Sets the base \a size of the window. -
1039 -
1040 The base size is used to calculate a proper window size if the -
1041 window defines sizeIncrement(). -
1042 -
1043 \sa setMinimumSize(), setMaximumSize(), setSizeIncrement(), baseSize() -
1044*/ -
1045void QWindow::setBaseSize(const QSize &size) -
1046{ -
1047 Q_D(QWindow); -
1048 if (d->baseSize == size) -
1049 return; -
1050 d->baseSize = size; -
1051 if (d->platformWindow && isTopLevel()) -
1052 d->platformWindow->propagateSizeHints(); -
1053} -
1054 -
1055/*! -
1056 Sets the size increment (\a size) of the window. -
1057 -
1058 When the user resizes the window, the size will move in steps of -
1059 sizeIncrement().width() pixels horizontally and -
1060 sizeIncrement().height() pixels vertically, with baseSize() as the -
1061 basis. -
1062 -
1063 By default, this property contains a size with zero width and height. -
1064 -
1065 The windowing system might not support size increments. -
1066 -
1067 \sa setBaseSize(), setMinimumSize(), setMaximumSize() -
1068*/ -
1069void QWindow::setSizeIncrement(const QSize &size) -
1070{ -
1071 Q_D(QWindow); -
1072 if (d->sizeIncrement == size) -
1073 return; -
1074 d->sizeIncrement = size; -
1075 if (d->platformWindow && isTopLevel()) -
1076 d->platformWindow->propagateSizeHints(); -
1077} -
1078 -
1079/*! -
1080 Sets the geometry of the window, excluding its window frame, to a -
1081 rectangle constructed from \a posx, \a posy, \a w and \a h. -
1082 -
1083 \sa geometry() -
1084*/ -
1085void QWindow::setGeometry(int posx, int posy, int w, int h) -
1086{ -
1087 setGeometry(QRect(posx, posy, w, h)); -
1088} -
1089 -
1090/*! -
1091 \brief Sets the geometry of the window, excluding its window frame, to \a rect. -
1092 -
1093 \sa geometry() -
1094*/ -
1095void QWindow::setGeometry(const QRect &rect) -
1096{ -
1097 Q_D(QWindow); -
1098 if (rect == geometry()) -
1099 return; -
1100 QRect oldRect = geometry(); -
1101 -
1102 d->positionPolicy = QWindowPrivate::WindowFrameExclusive; -
1103 if (d->platformWindow) { -
1104 d->platformWindow->setGeometry(rect); -
1105 } else { -
1106 d->geometry = rect; -
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/*! -
1120 Returns the geometry of the window, excluding its window frame. -
1121 -
1122 \sa frameMargins(), frameGeometry() -
1123*/ -
1124QRect QWindow::geometry() const -
1125{ -
1126 Q_D(const QWindow); -
1127 if (d->platformWindow) -
1128 return d->platformWindow->geometry(); -
1129 return d->geometry; -
1130} -
1131 -
1132/*! -
1133 Returns the window frame margins surrounding the window. -
1134 -
1135 \sa geometry(), frameGeometry() -
1136*/ -
1137QMargins QWindow::frameMargins() const -
1138{ -
1139 Q_D(const QWindow); -
1140 if (d->platformWindow) -
1141 return d->platformWindow->frameMargins(); -
1142 return QMargins(); -
1143} -
1144 -
1145/*! -
1146 Returns the geometry of the window, including its window frame. -
1147 -
1148 \sa geometry(), frameMargins() -
1149*/ -
1150QRect QWindow::frameGeometry() const -
1151{ -
1152 Q_D(const QWindow); -
1153 if (d->platformWindow) { -
1154 QMargins m = frameMargins(); -
1155 return d->platformWindow->geometry().adjusted(-m.left(), -m.top(), m.right(), m.bottom()); -
1156 } -
1157 return d->geometry; -
1158} -
1159 -
1160/*! -
1161 Returns the top left position of the window, including its window frame. -
1162 -
1163 This returns the same value as frameGeometry().topLeft(). -
1164 -
1165 \sa geometry(), frameGeometry() -
1166*/ -
1167QPoint QWindow::framePosition() const -
1168{ -
1169 Q_D(const QWindow); -
1170 if (d->platformWindow) { -
1171 QMargins margins = frameMargins(); -
1172 return d->platformWindow->geometry().topLeft() - QPoint(margins.left(), margins.top()); -
1173 } -
1174 return d->geometry.topLeft(); -
1175} -
1176 -
1177/*! -
1178 Sets the upper left position of the window (\a point) including its window frame. -
1179 -
1180 \sa setGeometry(), frameGeometry() -
1181*/ -
1182void QWindow::setFramePosition(const QPoint &point) -
1183{ -
1184 Q_D(QWindow);
executed (the execution status of this line is deduced): QWindowPrivate * const d = d_func();
-
1185 d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
executed (the execution status of this line is deduced): d->positionPolicy = QWindowPrivate::WindowFrameInclusive;
-
1186 if (d->platformWindow) {
evaluated: d->platformWindow
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
1187 d->platformWindow->setGeometry(QRect(point, size()));
executed (the execution status of this line is deduced): d->platformWindow->setGeometry(QRect(point, size()));
-
1188 } else {
executed: }
Execution Count:1
1
1189 d->geometry.setTopLeftmoveTopLeft(point);
executed (the execution status of this line is deduced): d->geometry.moveTopLeft(point);
-
1190 }
executed: }
Execution Count:1
1
1191} -
1192 -
1193/*! -
1194 \brief set the position of the window on the desktop to \a pt -
1195 -
1196 \sa position() -
1197*/ -
1198void QWindow::setPosition(const QPoint &pt) -
1199{ -
1200 setGeometry(QRect(pt, size())); -
1201} -
1202 -
1203/*! -
1204 \brief set the position of the window on the desktop to \a posx, \a posy -
1205 -
1206 \sa position() -
1207*/ -
1208void QWindow::setPosition(int posx, int posy) -
1209{ -
1210 setPosition(QPoint(posx, posy)); -
1211} -
1212 -
1213/*!-
\fn QPoint QWindow::position() const
\brief get the position of the window on the desktop excluding any window frame
\sa setPosition()
*/
/*!
\fn QSize QWindow::size() const
\brief get the size of the window excluding any window frame
\sa resize()
*/*!
1214 \fn QPoint QWindow::position() const -
1215 \brief Returns the position of the window on the desktop excluding any window frame -
1216 -
1217 \sa setPosition() -
1218*/ -
1219 -
1220/*! -
1221 \fn QSize QWindow::size() const -
1222 \brief Returns the size of the window excluding any window frame -
1223 -
1224 \sa resize() -
1225*/ -
1226 -
1227/*! -
1228 set the size of the window, excluding any window frame, to a QSize -
1229 constructed from width \a w and height \a h -
1230 -
1231 \sa size(), geometry() -
1232*/ -
1233void QWindow::resize(int w, int h) -
1234{ -
1235 resize(QSize(w, h)); -
1236} -
1237 -
1238/*! -
1239 \brief set the size of the window, excluding any window frame, to \a newSize -
1240 -
1241 \sa size(), geometry() -
1242*/ -
1243void QWindow::resize(const QSize &newSize) -
1244{ -
1245 Q_D(QWindow); -
1246 if (d->platformWindow) { -
1247 d->platformWindow->setGeometry(QRect(position(), newSize)); -
1248 } else { -
1249 d->geometry.setSize(newSize); -
1250 } -
1251} -
1252 -
1253/*! -
1254 Releases the native platform resources associated with this window. -
1255 -
1256 \sa create() -
1257*/ -
1258void QWindow::destroy() -
1259{ -
1260 Q_D(QWindow); -
1261 QObjectList childrenWindows = children(); -
1262 for (int i = 0; i < childrenWindows.size(); i++) { -
1263 QObject *object = childrenWindows.at(i); -
1264 if (object->isWindowType()) { -
1265 QWindow *w = static_cast<QWindow*>(object); -
1266 QGuiApplicationPrivate::window_list.removeAll(w); -
1267 w->destroy(); -
1268 } -
1269 } -
1270 setVisible(false); -
1271 delete d->platformWindow; -
1272 d->resizeEventPending = true; -
1273 d->receivedExpose = false; -
1274 d->exposed = false; -
1275 d->platformWindow = 0; -
1276} -
1277 -
1278/*! -
1279 Returns the platform window corresponding to the window. -
1280 -
1281 \internal -
1282*/ -
1283QPlatformWindow *QWindow::handle() const -
1284{ -
1285 Q_D(const QWindow); -
1286 return d->platformWindow; -
1287} -
1288 -
1289/*! -
1290 Returns the platform surface corresponding to the window. -
1291 -
1292 \internal -
1293*/ -
1294QPlatformSurface *QWindow::surfaceHandle() const -
1295{ -
1296 Q_D(const QWindow); -
1297 return d->platformWindow; -
1298} -
1299 -
1300/*!-
Set whether keyboard grab should be enabled or not (\a grab).
If the return value is true, the window receives all key events until
setKeyboardGrabEnabled(false) is called; other windows get no key events at
all. Mouse events are not affected. Use setMouseGrabEnabled() if you want
to grab that.
\sa setMouseGrabEnabled()
*/*!
1301 Sets whether keyboard grab should be enabled or not (\a grab). -
1302 -
1303 If the return value is true, the window receives all key events until -
1304 setKeyboardGrabEnabled(false) is called; other windows get no key events at -
1305 all. Mouse events are not affected. Use setMouseGrabEnabled() if you want -
1306 to grab that. -
1307 -
1308 \sa setMouseGrabEnabled() -
1309*/ -
1310bool QWindow::setKeyboardGrabEnabled(bool grab) -
1311{ -
1312 Q_D(QWindow); -
1313 if (grab && QGuiApplicationPrivate::noGrab) -
1314 return false; -
1315 if (d->platformWindow) -
1316 return d->platformWindow->setKeyboardGrabEnabled(grab); -
1317 return false; -
1318} -
1319 -
1320/*! -
1321 Sets whether mouse grab should be enabled or not (\a grab). -
1322 -
1323 If the return value is true, the window receives all mouse events until setMouseGrabEnabled(false) is -
1324 called; other windows get no mouse events at all. Keyboard events are not affected. -
1325 Use setKeyboardGrabEnabled() if you want to grab that. -
1326 -
1327 \sa setKeyboardGrabEnabled() -
1328*/ -
1329bool QWindow::setMouseGrabEnabled(bool grab) -
1330{ -
1331 Q_D(QWindow); -
1332 if (grab && QGuiApplicationPrivate::noGrab) -
1333 return false; -
1334 if (d->platformWindow) -
1335 return d->platformWindow->setMouseGrabEnabled(grab); -
1336 return false; -
1337} -
1338 -
1339/*! -
1340 Returns the screen on which the window is shown. -
1341 -
1342 The value returned will not change when the window is moved -
1343 between virtual screens (as returned by QScreen::virtualSiblings()). -
1344 -
1345 \sa setScreen(), QScreen::virtualSiblings() -
1346*/ -
1347QScreen *QWindow::screen() const -
1348{ -
1349 Q_D(const QWindow); -
1350 return d->screen; -
1351} -
1352 -
1353/*! -
1354 Sets the screen on which the window should be shown. -
1355 -
1356 If the window has been created, it will be recreated on the \a newScreen. -
1357 -
1358 Note that if the screen is part of a virtual desktop of multiple screens, -
1359 the window can appear on any of the screens returned by QScreen::virtualSiblings(). -
1360 -
1361 \sa screen(), QScreen::virtualSiblings() -
1362*/ -
1363void QWindow::setScreen(QScreen *newScreen) -
1364{ -
1365 Q_D(QWindow); -
1366 if (!newScreen) -
1367 newScreen = QGuiApplication::primaryScreen(); -
1368 if (newScreen != screen()) { -
1369 const bool wasCreated = d->platformWindow != 0; -
1370 if (wasCreated) -
1371 destroy(); -
1372 if (d->screen) -
1373 disconnect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(screenDestroyed(QObject*))); -
1374 d->screen = newScreen; -
1375 if (newScreen) { -
1376 connect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(screenDestroyed(QObject*))); -
1377 if (wasCreated) -
1378 create(); -
1379 } -
1380 emit screenChanged(newScreen); -
1381 } -
1382} -
1383 -
1384void QWindow::screenDestroyed(QObject *object) -
1385{ -
1386 Q_D(QWindow); -
1387 if (object == static_cast<QObject *>(d->screen)) { -
1388 const bool wasVisible = isVisible(); -
1389 setScreen(0); -
1390 // destroy() might have hidden our window, show it again. -
1391 // This might not be the best behavior if the new screen isn't a virtual sibling -
1392 // of the old one. This can be removed once platform plugins have the power to -
1393 // update the QScreen of its QWindows itself. -
1394 if (wasVisible && d->platformWindow) -
1395 setVisible(true); -
1396 } -
1397} -
1398 -
1399/*! -
1400 \fn QWindow::screenChanged(QScreen *screen) -
1401 -
1402 This signal is emitted when a window's \a screen changes, either -
1403 by being set explicitly with setScreen(), or automatically when -
1404 the window's screen is removed. -
1405*/ -
1406 -
1407/*! -
1408 Returns the accessibility interface for the object that the window represents -
1409 \internal -
1410 \sa QAccessible -
1411 */ -
1412QAccessibleInterface *QWindow::accessibleRoot() const -
1413{ -
1414 return 0; -
1415} -
1416 -
1417/*! -
1418 \fn QWindow::focusObjectChanged(QObject *focusObject) -
1419 -
1420 This signal is emitted when final receiver of events tied to focus is -
1421 changed to \a focusObject. -
1422 -
1423 \sa focusObject() -
1424*/ -
1425 -
1426/*! -
1427 Returns the QObject that will be the final receiver of events tied focus, such -
1428 as key events. -
1429*/ -
1430QObject *QWindow::focusObject() const -
1431{ -
1432 return const_cast<QWindow *>(this); -
1433} -
1434 -
1435/*! -
1436 Shows the window. -
1437 -
1438 This equivalent to calling showFullScreen() or showNormal(), depending -
1439 on whether the platform defaults to windows being fullscreen or not. -
1440 -
1441 \sa showFullScreen(), showNormal(), hide(), QStyleHints::showIsFullScreen() -
1442*/ -
1443void QWindow::show() -
1444{ -
1445 if (qApp->styleHints()->showIsFullScreen()) -
1446 showFullScreen(); -
1447 else -
1448 showNormal(); -
1449} -
1450 -
1451/*! -
1452 Hides the window. -
1453 -
1454 Equivalent to calling setVisible(false). -
1455 -
1456 \sa show(), setVisible() -
1457*/ -
1458void QWindow::hide() -
1459{ -
1460 setVisible(false); -
1461} -
1462 -
1463/*! -
1464 Shows the window as minimized. -
1465 -
1466 Equivalent to calling setWindowState(Qt::WindowMinimized) and then -
1467 setVisible(true). -
1468 -
1469 \sa setWindowState(), setVisible() -
1470*/ -
1471void QWindow::showMinimized() -
1472{ -
1473 setWindowState(Qt::WindowMinimized); -
1474 setVisible(true); -
1475} -
1476 -
1477/*! -
1478 Shows the window as maximized. -
1479 -
1480 Equivalent to calling setWindowState(Qt::WindowMaximized) and then -
1481 setVisible(true). -
1482 -
1483 \sa setWindowState(), setVisible() -
1484*/ -
1485void QWindow::showMaximized() -
1486{ -
1487 setWindowState(Qt::WindowMaximized); -
1488 setVisible(true); -
1489} -
1490 -
1491/*! -
1492 Shows the window as fullscreen. -
1493 -
1494 Equivalent to calling setWindowState(Qt::WindowFullScreen) and then -
1495 setVisible(true). -
1496 -
1497 \sa setWindowState(), setVisible() -
1498*/ -
1499void QWindow::showFullScreen() -
1500{ -
1501 setWindowState(Qt::WindowFullScreen); -
1502 setVisible(true); -
1503 requestActivate(); -
1504} -
1505 -
1506/*! -
1507 Shows the window as normal, i.e. neither maximized, minimized, nor fullscreen. -
1508 -
1509 Equivalent to calling setWindowState(Qt::WindowNoState) and then -
1510 setVisible(true). -
1511 -
1512 \sa setWindowState(), setVisible() -
1513*/ -
1514void QWindow::showNormal() -
1515{ -
1516 setWindowState(Qt::WindowNoState); -
1517 setVisible(true); -
1518} -
1519 -
1520/*! -
1521 Close the window. -
1522 -
1523 This closes the window, effectively calling destroy(), and potentially -
1524 quitting the application. Returns true on success, false if it has a parent -
1525 window (in which case the top level window should be closed instead). -
1526 -
1527 \sa destroy(), QGuiApplication::quitOnLastWindowClosed() -
1528*/ -
1529bool QWindow::close() -
1530{ -
1531 Q_D(QWindow); -
1532 -
1533 // Do not close non top level windows -
1534 if (parent()) -
1535 return false; -
1536 -
1537 if (QGuiApplicationPrivate::focus_window == this) -
1538 QGuiApplicationPrivate::focus_window = 0; -
1539 if (QGuiApplicationPrivate::currentMouseWindow == this) -
1540 QGuiApplicationPrivate::currentMouseWindow = 0; -
1541 -
1542 QGuiApplicationPrivate::window_list.removeAll(this); -
1543 destroy(); -
1544 d->maybeQuitOnLastWindowClosed(); -
1545 return true; -
1546} -
1547 -
1548/*! -
1549 The expose event (\a ev) is sent by the window system whenever the window's -
1550 exposure on screen changes. -
1551 -
1552 The application can start rendering into the window with QBackingStore -
1553 and QOpenGLContext as soon as it gets an exposeEvent() such that -
1554 isExposed() is true. -
1555 -
1556 If the window is moved off screen, is made totally obscured by another -
1557 window, iconified or similar, this function might be called and the -
1558 value of isExposed() might change to false. When this happens, -
1559 an application should stop its rendering as it is no longer visible -
1560 to the user. -
1561 -
1562 A resize event will always be sent before the expose event the first time -
1563 a window is shown. -
1564 -
1565 \sa isExposed() -
1566*/ -
1567void QWindow::exposeEvent(QExposeEvent *ev) -
1568{ -
1569 ev->ignore(); -
1570} -
1571 -
1572/*! -
1573 Override this to handle mouse events (\a ev). -
1574*/ -
1575void QWindow::moveEvent(QMoveEvent *ev) -
1576{ -
1577 ev->ignore(); -
1578} -
1579 -
1580/*! -
1581 Override this to handle resize events (\a ev). -
1582 -
1583 The resize event is called whenever the window is resized in the windowing system, -
1584 either directly through the windowing system acknowledging a setGeometry() or resize() request, -
1585 or indirectly through the user resizing the window manually. -
1586*/ -
1587void QWindow::resizeEvent(QResizeEvent *ev) -
1588{ -
1589 ev->ignore(); -
1590} -
1591 -
1592/*! -
1593 Override this to handle show events (\a ev). -
1594 -
1595 The function is called when the window has requested becoming visible. -
1596 -
1597 If the window is successfully shown by the windowing system, this will -
1598 be followed by a resize and an expose event. -
1599*/ -
1600void QWindow::showEvent(QShowEvent *ev) -
1601{ -
1602 ev->ignore(); -
1603} -
1604 -
1605/*! -
1606 Override this to handle hide events (\a ev). -
1607 -
1608 The function is called when the window has requested being hidden in the -
1609 windowing system. -
1610*/ -
1611void QWindow::hideEvent(QHideEvent *ev) -
1612{ -
1613 ev->ignore(); -
1614} -
1615 -
1616/*! -
1617 Override this to handle any event (\a ev) sent to the window. -
1618 Return \c true if the event was recognized and processed. -
1619 -
1620 Remember to call the base class version if you wish for mouse events, -
1621 key events, resize events, etc to be dispatched as usual. -
1622*/ -
1623bool QWindow::event(QEvent *ev) -
1624{ -
1625 switch (ev->type()) { -
1626 case QEvent::MouseMove: -
1627 mouseMoveEvent(static_cast<QMouseEvent*>(ev)); -
1628 break; -
1629 -
1630 case QEvent::MouseButtonPress: -
1631 mousePressEvent(static_cast<QMouseEvent*>(ev)); -
1632 break; -
1633 -
1634 case QEvent::MouseButtonRelease: -
1635 mouseReleaseEvent(static_cast<QMouseEvent*>(ev)); -
1636 break; -
1637 -
1638 case QEvent::MouseButtonDblClick: -
1639 mouseDoubleClickEvent(static_cast<QMouseEvent*>(ev)); -
1640 break; -
1641 -
1642 case QEvent::TouchBegin: -
1643 case QEvent::TouchUpdate: -
1644 case QEvent::TouchEnd: -
1645 case QEvent::TouchCancel: -
1646 touchEvent(static_cast<QTouchEvent *>(ev)); -
1647 break; -
1648 -
1649 case QEvent::Move: -
1650 moveEvent(static_cast<QMoveEvent*>(ev)); -
1651 break; -
1652 -
1653 case QEvent::Resize: -
1654 resizeEvent(static_cast<QResizeEvent*>(ev)); -
1655 break; -
1656 -
1657 case QEvent::KeyPress: -
1658 keyPressEvent(static_cast<QKeyEvent *>(ev)); -
1659 break; -
1660 -
1661 case QEvent::KeyRelease: -
1662 keyReleaseEvent(static_cast<QKeyEvent *>(ev)); -
1663 break; -
1664 -
1665 case QEvent::FocusIn: { -
1666 focusInEvent(static_cast<QFocusEvent *>(ev)); -
1667#ifndef QT_NO_ACCESSIBILITY -
1668 QAccessible::State state; -
1669 state.active = true; -
1670 QAccessibleStateChangeEvent event(this, state); -
1671 QAccessible::updateAccessibility(&event); -
1672#endif -
1673 break; } -
1674 -
1675 case QEvent::FocusOut: { -
1676 focusOutEvent(static_cast<QFocusEvent *>(ev)); -
1677#ifndef QT_NO_ACCESSIBILITY -
1678 QAccessible::State state; -
1679 state.active = true; -
1680 QAccessibleStateChangeEvent event(this, state); -
1681 QAccessible::updateAccessibility(&event); -
1682#endif -
1683 break; } -
1684 -
1685#ifndef QT_NO_WHEELEVENT -
1686 case QEvent::Wheel: -
1687 wheelEvent(static_cast<QWheelEvent*>(ev)); -
1688 break; -
1689#endif -
1690 -
1691 case QEvent::Close: { -
1692 Q_D(QWindow); -
1693 bool wasVisible = isVisible(); -
1694 destroy(); -
1695 if (wasVisible) -
1696 d->maybeQuitOnLastWindowClosed(); -
1697 break; } -
1698 -
1699 case QEvent::Expose: -
1700 exposeEvent(static_cast<QExposeEvent *>(ev)); -
1701 break; -
1702 -
1703 case QEvent::Show: -
1704 showEvent(static_cast<QShowEvent *>(ev)); -
1705 break; -
1706 -
1707 case QEvent::Hide: -
1708 hideEvent(static_cast<QHideEvent *>(ev)); -
1709 break; -
1710 -
1711 case QEvent::WindowStateChange: { -
1712 Q_D(QWindow); -
1713 emit windowStateChanged(d->windowState); -
1714 break; -
1715 } -
1716 -
1717#ifndef QT_NO_TABLETEVENT -
1718 case QEvent::TabletPress: -
1719 case QEvent::TabletMove: -
1720 case QEvent::TabletRelease: -
1721 tabletEvent(static_cast<QTabletEvent *>(ev)); -
1722 break; -
1723#endif -
1724 -
1725 default: -
1726 return QObject::event(ev); -
1727 } -
1728 return true; -
1729} -
1730 -
1731/*! -
1732 Override this to handle key press events (\a ev). -
1733 -
1734 \sa keyReleaseEvent() -
1735*/ -
1736void QWindow::keyPressEvent(QKeyEvent *ev) -
1737{ -
1738 ev->ignore(); -
1739} -
1740 -
1741/*! -
1742 Override this to handle key release events (\a ev). -
1743 -
1744 \sa keyPressEvent() -
1745*/ -
1746void QWindow::keyReleaseEvent(QKeyEvent *ev) -
1747{ -
1748 ev->ignore(); -
1749} -
1750 -
1751/*! -
1752 Override this to handle focus in events (\a ev). -
1753 -
1754 Focus in events are sent when the window receives keyboard focus. -
1755 -
1756 \sa focusOutEvent() -
1757*/ -
1758void QWindow::focusInEvent(QFocusEvent *ev) -
1759{ -
1760 ev->ignore(); -
1761} -
1762 -
1763/*! -
1764 Override this to handle focus out events (\a ev). -
1765 -
1766 Focus out events are sent when the window loses keyboard focus. -
1767 -
1768 \sa focusInEvent() -
1769*/ -
1770void QWindow::focusOutEvent(QFocusEvent *ev) -
1771{ -
1772 ev->ignore(); -
1773} -
1774 -
1775/*! -
1776 Override this to handle mouse press events (\a ev). -
1777 -
1778 \sa mouseReleaseEvent() -
1779*/ -
1780void QWindow::mousePressEvent(QMouseEvent *ev) -
1781{ -
1782 ev->ignore(); -
1783} -
1784 -
1785/*! -
1786 Override this to handle mouse release events (\a ev). -
1787 -
1788 \sa mousePressEvent() -
1789*/ -
1790void QWindow::mouseReleaseEvent(QMouseEvent *ev) -
1791{ -
1792 ev->ignore(); -
1793} -
1794 -
1795/*! -
1796 Override this to handle mouse double click events (\a ev). -
1797 -
1798 \sa mousePressEvent(), QStyleHints::mouseDoubleClickInterval() -
1799*/ -
1800void QWindow::mouseDoubleClickEvent(QMouseEvent *ev) -
1801{ -
1802 ev->ignore(); -
1803} -
1804 -
1805/*! -
1806 Override this to handle mouse move events (\a ev). -
1807*/ -
1808void QWindow::mouseMoveEvent(QMouseEvent *ev) -
1809{ -
1810 ev->ignore(); -
1811} -
1812 -
1813#ifndef QT_NO_WHEELEVENT -
1814/*! -
1815 Override this to handle mouse wheel or other wheel events (\a ev). -
1816*/ -
1817void QWindow::wheelEvent(QWheelEvent *ev) -
1818{ -
1819 ev->ignore(); -
1820} -
1821#endif //QT_NO_WHEELEVENT -
1822 -
1823/*! -
1824 Override this to handle touch events (\a ev). -
1825*/ -
1826void QWindow::touchEvent(QTouchEvent *ev) -
1827{ -
1828 ev->ignore(); -
1829} -
1830 -
1831#ifndef QT_NO_TABLETEVENT -
1832/*! -
1833 Override this to handle tablet press, move, and release events (\a ev). -
1834 -
1835 Proximity enter and leave events are not sent to windows, they are -
1836 delivered to the application instance. -
1837*/ -
1838void QWindow::tabletEvent(QTabletEvent *ev) -
1839{ -
1840 ev->ignore(); -
1841} -
1842#endif -
1843 -
1844/*! -
1845 Override this to handle platform dependent events. -
1846 Will be given \a eventType, \a message and \a result. -
1847 -
1848 This might make your application non-portable. -
1849 -
1850 Should return true only if the event was handled. -
1851*/ -
1852bool QWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) -
1853{ -
1854 Q_UNUSED(eventType); -
1855 Q_UNUSED(message); -
1856 Q_UNUSED(result); -
1857 return false; -
1858} -
1859 -
1860/*! -
1861 \fn QPoint QWindow::mapToGlobal(const QPoint &pos) const -
1862 -
1863 Translates the window coordinate \a pos to global screen -
1864 coordinates. For example, \c{mapToGlobal(QPoint(0,0))} would give -
1865 the global coordinates of the top-left pixel of the window. -
1866 -
1867 \sa mapFromGlobal() -
1868*/ -
1869QPoint QWindow::mapToGlobal(const QPoint &pos) const -
1870{ -
1871 Q_D(const QWindow); -
1872 if (d->platformWindow && d->platformWindow->isEmbedded(0)) -
1873 return d->platformWindow->mapToGlobal(pos); -
1874 else -
1875 return pos + d_func()->globalPosition(); -
1876} -
1877 -
1878 -
1879/*! -
1880 \fn QPoint QWindow::mapFromGlobal(const QPoint &pos) const -
1881 -
1882 Translates the global screen coordinate \a pos to window -
1883 coordinates. -
1884 -
1885 \sa mapToGlobal() -
1886*/ -
1887QPoint QWindow::mapFromGlobal(const QPoint &pos) const -
1888{ -
1889 Q_D(const QWindow); -
1890 if (d->platformWindow && d->platformWindow->isEmbedded(0)) -
1891 return d->platformWindow->mapFromGlobal(pos); -
1892 else -
1893 return pos - d_func()->globalPosition(); -
1894} -
1895 -
1896 -
1897Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window) -
1898{ -
1899 return window->d_func(); -
1900} -
1901 -
1902void QWindowPrivate::maybeQuitOnLastWindowClosed() -
1903{ -
1904 Q_Q(QWindow); -
1905 -
1906 // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent -
1907 bool quitOnClose = QGuiApplication::quitOnLastWindowClosed() && !q->parent(); -
1908 -
1909 if (quitOnClose) { -
1910 QWindowList list = QGuiApplication::topLevelWindows(); -
1911 bool lastWindowClosed = true; -
1912 for (int i = 0; i < list.size(); ++i) { -
1913 QWindow *w = list.at(i); -
1914 if (!w->isVisible() || w->transientParent()) -
1915 continue; -
1916 lastWindowClosed = false; -
1917 break; -
1918 } -
1919 if (lastWindowClosed) { -
1920 QGuiApplicationPrivate::emitLastWindowClosed(); -
1921 QCoreApplicationPrivate *applicationPrivate = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(QCoreApplication::instance())); -
1922 applicationPrivate->maybeQuit(); -
1923 } -
1924 } -
1925 -
1926} -
1927 -
1928#ifndef QT_NO_CURSOR -
1929/*! -
1930 \brief set the cursor shape for this window -
1931 -
1932 The mouse \a cursor will assume this shape when it is over this -
1933 window, unless an override cursor is set. -
1934 See the \l{Qt::CursorShape}{list of predefined cursor objects} for a -
1935 range of useful shapes. -
1936 -
1937 By default, the cursor has the Qt::ArrowCursor shape. -
1938 -
1939 Some underlying window implementations will reset the cursor if it -
1940 leaves a window even if the mouse is grabbed. If you want to have -
1941 a cursor set for all windows, even when outside the window, consider -
1942 QGuiApplication::setOverrideCursor(). -
1943 -
1944 \sa QGuiApplication::setOverrideCursor() -
1945*/ -
1946void QWindow::setCursor(const QCursor &cursor) -
1947{ -
1948 Q_D(QWindow); -
1949 d->cursor = cursor; -
1950 // Only attempt to set cursor and emit signal if there is an actual platform cursor -
1951 if (d->screen->handle()->cursor()) { -
1952 d->applyCursor(); -
1953 QEvent event(QEvent::CursorChange); -
1954 QGuiApplication::sendEvent(this, &event); -
1955 } -
1956} -
1957 -
1958/*! -
1959 \brief Restores the default arrow cursor for this window. -
1960 */ -
1961void QWindow::unsetCursor() -
1962{ -
1963 setCursor(Qt::ArrowCursor); -
1964} -
1965 -
1966/*! -
1967 \brief the cursor shape for this window -
1968 -
1969 \sa setCursor(), unsetCursor() -
1970*/ -
1971QCursor QWindow::cursor() const -
1972{ -
1973 Q_D(const QWindow); -
1974 return d->cursor; -
1975} -
1976 -
1977void QWindowPrivate::applyCursor() -
1978{ -
1979 Q_Q(QWindow); -
1980 if (platformWindow) { -
1981 if (QPlatformCursor *platformCursor = screen->handle()->cursor()) { -
1982 QCursor *oc = QGuiApplication::overrideCursor(); -
1983 QCursor c = oc ? *oc : cursor; -
1984 platformCursor->changeCursor(&c, q); -
1985 } -
1986 } -
1987} -
1988#endif // QT_NO_CURSOR -
1989 -
1990QT_END_NAMESPACE -
1991 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial